| 3809 | } |
| 3810 | |
| 3811 | static int |
| 3812 | vdev_offline_locked(spa_t *spa, uint64_t guid, uint64_t flags) |
| 3813 | { |
| 3814 | vdev_t *vd, *tvd; |
| 3815 | int error = 0; |
| 3816 | uint64_t generation; |
| 3817 | metaslab_group_t *mg; |
| 3818 | |
| 3819 | top: |
| 3820 | spa_vdev_state_enter(spa, SCL_ALLOC); |
| 3821 | |
| 3822 | if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL) |
| 3823 | return (spa_vdev_state_exit(spa, NULL, SET_ERROR(ENODEV))); |
| 3824 | |
| 3825 | if (!vd->vdev_ops->vdev_op_leaf) |
| 3826 | return (spa_vdev_state_exit(spa, NULL, SET_ERROR(ENOTSUP))); |
| 3827 | |
| 3828 | if (vd->vdev_ops == &vdev_draid_spare_ops) |
| 3829 | return (spa_vdev_state_exit(spa, NULL, ENOTSUP)); |
| 3830 | |
| 3831 | tvd = vd->vdev_top; |
| 3832 | mg = tvd->vdev_mg; |
| 3833 | generation = spa->spa_config_generation + 1; |
| 3834 | |
| 3835 | /* |
| 3836 | * If the device isn't already offline, try to offline it. |
| 3837 | */ |
| 3838 | if (!vd->vdev_offline) { |
| 3839 | /* |
| 3840 | * If this device has the only valid copy of some data, |
| 3841 | * don't allow it to be offlined. Log devices are always |
| 3842 | * expendable. |
| 3843 | */ |
| 3844 | if (!tvd->vdev_islog && vd->vdev_aux == NULL && |
| 3845 | vdev_dtl_required(vd)) |
| 3846 | return (spa_vdev_state_exit(spa, NULL, |
| 3847 | SET_ERROR(EBUSY))); |
| 3848 | |
| 3849 | /* |
| 3850 | * If the top-level is a slog and it has had allocations |
| 3851 | * then proceed. We check that the vdev's metaslab group |
| 3852 | * is not NULL since it's possible that we may have just |
| 3853 | * added this vdev but not yet initialized its metaslabs. |
| 3854 | */ |
| 3855 | if (tvd->vdev_islog && mg != NULL) { |
| 3856 | /* |
| 3857 | * Prevent any future allocations. |
| 3858 | */ |
| 3859 | metaslab_group_passivate(mg); |
| 3860 | (void) spa_vdev_state_exit(spa, vd, 0); |
| 3861 | |
| 3862 | error = spa_reset_logs(spa); |
| 3863 | |
| 3864 | /* |
| 3865 | * If the log device was successfully reset but has |
| 3866 | * checkpointed data, do not offline it. |
| 3867 | */ |
| 3868 | if (error == 0 && |
no test coverage detected