740
741 spa_history_log_internal(spa, "guid change", tx, "old=%llu new=%llu",
742 oldguid, *newguid);
743 }
744
745 /*
746 * Change the GUID for the pool. This is done so that we can later
747 * re-import a pool built from a clone of our own vdevs. We will modify
748 * the root vdev's guid, our own pool guid, and then mark all of our
749 * vdevs dirty. Note that we must make sure that all our vdevs are
750 * online when we do this, or else any vdevs that weren't present
751 * would be orphaned from our pool. We are also going to issue a
752 * sysevent to update any watchers.
753 */
754 int
755 spa_change_guid(spa_t *spa)
756 {
757 int error;
758 uint64_t guid;
759
760 mutex_enter(&spa_namespace_lock);
761 guid = spa_generate_guid(NULL);
762
763 error = dsl_sync_task(spa->spa_name, spa_change_guid_check,
764 spa_change_guid_sync, &guid, 5);
765
766 if (error == 0) {
767 spa_config_sync(spa, B_FALSE, B_TRUE);
768 spa_event_notify(spa, NULL, ESC_ZFS_POOL_REGUID);
769 }
770
771 mutex_exit(&spa_namespace_lock);
772
773 return (error);
774 }
775
776 /*
777 * ==========================================================================
778 * SPA state manipulation (open/create/destroy/import/export)
779 * ==========================================================================
780 */
781
782 static int
783 spa_error_entry_compare(const void *a, const void *b)
784 {
785 spa_error_entry_t *sa = (spa_error_entry_t *)a;
786 spa_error_entry_t *sb = (spa_error_entry_t *)b;
787 int ret;
788
789 ret = bcmp(&sa->se_bookmark, &sb->se_bookmark,
790 sizeof (zbookmark_t));
791
4657 * reason, we must remove the spare now, in the same txg as the detach;
4658 * otherwise someone could attach a new sibling, change the GUID, and
4659 * the subsequent attempt to spa_vdev_remove(unspare_guid) would fail.
4660 */
4661 if (unspare) {
4662 ASSERT(cvd->vdev_isspare);
4663 spa_spare_remove(cvd);
4664 unspare_guid = cvd->vdev_guid;
4665 (void) spa_vdev_remove(spa, unspare_guid, B_TRUE);
4666 cvd->vdev_unspare = B_TRUE;
4667 }
4668
4669 /*
4670 * If the parent mirror/replacing vdev only has one child,
4671 * the parent is no longer needed. Remove it from the tree.
4672 */
4673 if (pvd->vdev_children == 1) {
4674 if (pvd->vdev_ops == &vdev_spare_ops)
4675 cvd->vdev_unspare = B_FALSE;
4676 vdev_remove_parent(cvd);
4677 cvd->vdev_resilvering = B_FALSE;
4678 }
4679
4680
4681 /*
4682 * We don't set tvd until now because the parent we just removed
4683 * may have been the previous top-level vdev.
4684 */
4685 tvd = cvd->vdev_top;
4686 ASSERT(tvd->vdev_parent == rvd);
4687
4688 /*
4689 * Reevaluate the parent vdev state.
4690 */
4691 vdev_propagate_state(cvd);
4692
4693 /*
4694 * If the 'autoexpand' property is set on the pool then automatically
4695 * try to expand the size of the pool. For example if the device we
4696 * just detached was smaller than the others, it may be possible to
4697 * add metaslabs (i.e. grow the pool). We need to reopen the vdev
5285 return (spa_vdev_exit(spa, NULL, txg, error));
5286
5287 return (error);
5288 }
5289
5290 /*
5291 * Find any device that's done replacing, or a vdev marked 'unspare' that's
5292 * currently spared, so we can detach it.
5293 */
5294 static vdev_t *
5295 spa_vdev_resilver_done_hunt(vdev_t *vd)
5296 {
5297 vdev_t *newvd, *oldvd;
5298
5299 for (int c = 0; c < vd->vdev_children; c++) {
5300 oldvd = spa_vdev_resilver_done_hunt(vd->vdev_child[c]);
5301 if (oldvd != NULL)
5302 return (oldvd);
5303 }
5304
5305 /*
5306 * Check for a completed replacement. We always consider the first
5307 * vdev in the list to be the oldest vdev, and the last one to be
5308 * the newest (see spa_vdev_attach() for how that works). In
5309 * the case where the newest vdev is faulted, we will not automatically
5310 * remove it after a resilver completes. This is OK as it will require
5311 * user intervention to determine which disk the admin wishes to keep.
5312 */
5313 if (vd->vdev_ops == &vdev_replacing_ops) {
5314 ASSERT(vd->vdev_children > 1);
5315
5316 newvd = vd->vdev_child[vd->vdev_children - 1];
5317 oldvd = vd->vdev_child[0];
5318
5319 if (vdev_dtl_empty(newvd, DTL_MISSING) &&
5320 vdev_dtl_empty(newvd, DTL_OUTAGE) &&
5321 !vdev_dtl_required(oldvd))
5322 return (oldvd);
5323 }
5324
|
740
741 spa_history_log_internal(spa, "guid change", tx, "old=%llu new=%llu",
742 oldguid, *newguid);
743 }
744
745 /*
746 * Change the GUID for the pool. This is done so that we can later
747 * re-import a pool built from a clone of our own vdevs. We will modify
748 * the root vdev's guid, our own pool guid, and then mark all of our
749 * vdevs dirty. Note that we must make sure that all our vdevs are
750 * online when we do this, or else any vdevs that weren't present
751 * would be orphaned from our pool. We are also going to issue a
752 * sysevent to update any watchers.
753 */
754 int
755 spa_change_guid(spa_t *spa)
756 {
757 int error;
758 uint64_t guid;
759
760 mutex_enter(&spa->spa_vdev_top_lock);
761 mutex_enter(&spa_namespace_lock);
762 guid = spa_generate_guid(NULL);
763
764 error = dsl_sync_task(spa->spa_name, spa_change_guid_check,
765 spa_change_guid_sync, &guid, 5);
766
767 if (error == 0) {
768 spa_config_sync(spa, B_FALSE, B_TRUE);
769 spa_event_notify(spa, NULL, ESC_ZFS_POOL_REGUID);
770 }
771
772 mutex_exit(&spa_namespace_lock);
773 mutex_exit(&spa->spa_vdev_top_lock);
774
775 return (error);
776 }
777
778 /*
779 * ==========================================================================
780 * SPA state manipulation (open/create/destroy/import/export)
781 * ==========================================================================
782 */
783
784 static int
785 spa_error_entry_compare(const void *a, const void *b)
786 {
787 spa_error_entry_t *sa = (spa_error_entry_t *)a;
788 spa_error_entry_t *sb = (spa_error_entry_t *)b;
789 int ret;
790
791 ret = bcmp(&sa->se_bookmark, &sb->se_bookmark,
792 sizeof (zbookmark_t));
793
4659 * reason, we must remove the spare now, in the same txg as the detach;
4660 * otherwise someone could attach a new sibling, change the GUID, and
4661 * the subsequent attempt to spa_vdev_remove(unspare_guid) would fail.
4662 */
4663 if (unspare) {
4664 ASSERT(cvd->vdev_isspare);
4665 spa_spare_remove(cvd);
4666 unspare_guid = cvd->vdev_guid;
4667 (void) spa_vdev_remove(spa, unspare_guid, B_TRUE);
4668 cvd->vdev_unspare = B_TRUE;
4669 }
4670
4671 /*
4672 * If the parent mirror/replacing vdev only has one child,
4673 * the parent is no longer needed. Remove it from the tree.
4674 */
4675 if (pvd->vdev_children == 1) {
4676 if (pvd->vdev_ops == &vdev_spare_ops)
4677 cvd->vdev_unspare = B_FALSE;
4678 vdev_remove_parent(cvd);
4679 }
4680
4681
4682 /*
4683 * We don't set tvd until now because the parent we just removed
4684 * may have been the previous top-level vdev.
4685 */
4686 tvd = cvd->vdev_top;
4687 ASSERT(tvd->vdev_parent == rvd);
4688
4689 /*
4690 * Reevaluate the parent vdev state.
4691 */
4692 vdev_propagate_state(cvd);
4693
4694 /*
4695 * If the 'autoexpand' property is set on the pool then automatically
4696 * try to expand the size of the pool. For example if the device we
4697 * just detached was smaller than the others, it may be possible to
4698 * add metaslabs (i.e. grow the pool). We need to reopen the vdev
5286 return (spa_vdev_exit(spa, NULL, txg, error));
5287
5288 return (error);
5289 }
5290
5291 /*
5292 * Find any device that's done replacing, or a vdev marked 'unspare' that's
5293 * currently spared, so we can detach it.
5294 */
5295 static vdev_t *
5296 spa_vdev_resilver_done_hunt(vdev_t *vd)
5297 {
5298 vdev_t *newvd, *oldvd;
5299
5300 for (int c = 0; c < vd->vdev_children; c++) {
5301 oldvd = spa_vdev_resilver_done_hunt(vd->vdev_child[c]);
5302 if (oldvd != NULL)
5303 return (oldvd);
5304 }
5305
5306 if (vd->vdev_resilvering && vdev_dtl_empty(vd, DTL_MISSING) &&
5307 vdev_dtl_empty(vd, DTL_OUTAGE)) {
5308 ASSERT(vd->vdev_ops->vdev_op_leaf);
5309 vd->vdev_resilvering = B_FALSE;
5310 vdev_config_dirty(vd->vdev_top);
5311 }
5312
5313 /*
5314 * Check for a completed replacement. We always consider the first
5315 * vdev in the list to be the oldest vdev, and the last one to be
5316 * the newest (see spa_vdev_attach() for how that works). In
5317 * the case where the newest vdev is faulted, we will not automatically
5318 * remove it after a resilver completes. This is OK as it will require
5319 * user intervention to determine which disk the admin wishes to keep.
5320 */
5321 if (vd->vdev_ops == &vdev_replacing_ops) {
5322 ASSERT(vd->vdev_children > 1);
5323
5324 newvd = vd->vdev_child[vd->vdev_children - 1];
5325 oldvd = vd->vdev_child[0];
5326
5327 if (vdev_dtl_empty(newvd, DTL_MISSING) &&
5328 vdev_dtl_empty(newvd, DTL_OUTAGE) &&
5329 !vdev_dtl_required(oldvd))
5330 return (oldvd);
5331 }
5332
|