Print this page
3742 zfs comments need cleaner, more consistent style
Submitted by:   Will Andrews <willa@spectralogic.com>
Submitted by:   Alan Somers <alans@spectralogic.com>
Reviewed by:    Matthew Ahrens <mahrens@delphix.com>
Reviewed by:    George Wilson <george.wilson@delphix.com>
Reviewed by:    Eric Schrock <eric.schrock@delphix.com>


4499          */
4500         (void) spa_vdev_exit(spa, newrootvd, dtl_max_txg, 0);
4501 
4502         spa_history_log_internal(spa, "vdev attach", NULL,
4503             "%s vdev=%s %s vdev=%s",
4504             replacing && newvd_isspare ? "spare in" :
4505             replacing ? "replace" : "attach", newvdpath,
4506             replacing ? "for" : "to", oldvdpath);
4507 
4508         spa_strfree(oldvdpath);
4509         spa_strfree(newvdpath);
4510 
4511         if (spa->spa_bootfs)
4512                 spa_event_notify(spa, newvd, ESC_ZFS_BOOTFS_VDEV_ATTACH);
4513 
4514         return (0);
4515 }
4516 
4517 /*
4518  * Detach a device from a mirror or replacing vdev.

4519  * If 'replace_done' is specified, only detach if the parent
4520  * is a replacing vdev.
4521  */
4522 int
4523 spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
4524 {
4525         uint64_t txg;
4526         int error;
4527         vdev_t *rvd = spa->spa_root_vdev;
4528         vdev_t *vd, *pvd, *cvd, *tvd;
4529         boolean_t unspare = B_FALSE;
4530         uint64_t unspare_guid = 0;
4531         char *vdpath;
4532 
4533         ASSERT(spa_writeable(spa));
4534 
4535         txg = spa_vdev_enter(spa);
4536 
4537         vd = spa_lookup_by_guid(spa, guid, B_FALSE);
4538 


5153         } else {
5154                 vd = vdev_alloc_common(spa, id, 0, &vdev_hole_ops);
5155                 vdev_add_child(rvd, vd);
5156         }
5157         vdev_config_dirty(rvd);
5158 
5159         /*
5160          * Reassess the health of our root vdev.
5161          */
5162         vdev_reopen(rvd);
5163 }
5164 
5165 /*
5166  * Remove a device from the pool -
5167  *
5168  * Removing a device from the vdev namespace requires several steps
5169  * and can take a significant amount of time.  As a result we use
5170  * the spa_vdev_config_[enter/exit] functions which allow us to
5171  * grab and release the spa_config_lock while still holding the namespace
5172  * lock.  During each step the configuration is synced out.
5173  */
5174 
5175 /*
5176  * Remove a device from the pool.  Currently, this supports removing only hot
5177  * spares, slogs, and level 2 ARC devices.
5178  */
5179 int
5180 spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare)
5181 {
5182         vdev_t *vd;
5183         metaslab_group_t *mg;
5184         nvlist_t **spares, **l2cache, *nv;
5185         uint64_t txg = 0;
5186         uint_t nspares, nl2cache;
5187         int error = 0;
5188         boolean_t locked = MUTEX_HELD(&spa_namespace_lock);
5189 
5190         ASSERT(spa_writeable(spa));
5191 
5192         if (!locked)
5193                 txg = spa_vdev_enter(spa);
5194 
5195         vd = spa_lookup_by_guid(spa, guid, B_FALSE);
5196 
5197         if (spa->spa_spares.sav_vdevs != NULL &&


5267         } else if (vd != NULL) {
5268                 /*
5269                  * Normal vdevs cannot be removed (yet).
5270                  */
5271                 error = SET_ERROR(ENOTSUP);
5272         } else {
5273                 /*
5274                  * There is no vdev of any kind with the specified guid.
5275                  */
5276                 error = SET_ERROR(ENOENT);
5277         }
5278 
5279         if (!locked)
5280                 return (spa_vdev_exit(spa, NULL, txg, error));
5281 
5282         return (error);
5283 }
5284 
5285 /*
5286  * Find any device that's done replacing, or a vdev marked 'unspare' that's
5287  * current spared, so we can detach it.
5288  */
5289 static vdev_t *
5290 spa_vdev_resilver_done_hunt(vdev_t *vd)
5291 {
5292         vdev_t *newvd, *oldvd;
5293 
5294         for (int c = 0; c < vd->vdev_children; c++) {
5295                 oldvd = spa_vdev_resilver_done_hunt(vd->vdev_child[c]);
5296                 if (oldvd != NULL)
5297                         return (oldvd);
5298         }
5299 
5300         /*
5301          * Check for a completed replacement.  We always consider the first
5302          * vdev in the list to be the oldest vdev, and the last one to be
5303          * the newest (see spa_vdev_attach() for how that works).  In
5304          * the case where the newest vdev is faulted, we will not automatically
5305          * remove it after a resilver completes.  This is OK as it will require
5306          * user intervention to determine which disk the admin wishes to keep.
5307          */




4499          */
4500         (void) spa_vdev_exit(spa, newrootvd, dtl_max_txg, 0);
4501 
4502         spa_history_log_internal(spa, "vdev attach", NULL,
4503             "%s vdev=%s %s vdev=%s",
4504             replacing && newvd_isspare ? "spare in" :
4505             replacing ? "replace" : "attach", newvdpath,
4506             replacing ? "for" : "to", oldvdpath);
4507 
4508         spa_strfree(oldvdpath);
4509         spa_strfree(newvdpath);
4510 
4511         if (spa->spa_bootfs)
4512                 spa_event_notify(spa, newvd, ESC_ZFS_BOOTFS_VDEV_ATTACH);
4513 
4514         return (0);
4515 }
4516 
4517 /*
4518  * Detach a device from a mirror or replacing vdev.
4519  *
4520  * If 'replace_done' is specified, only detach if the parent
4521  * is a replacing vdev.
4522  */
4523 int
4524 spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
4525 {
4526         uint64_t txg;
4527         int error;
4528         vdev_t *rvd = spa->spa_root_vdev;
4529         vdev_t *vd, *pvd, *cvd, *tvd;
4530         boolean_t unspare = B_FALSE;
4531         uint64_t unspare_guid = 0;
4532         char *vdpath;
4533 
4534         ASSERT(spa_writeable(spa));
4535 
4536         txg = spa_vdev_enter(spa);
4537 
4538         vd = spa_lookup_by_guid(spa, guid, B_FALSE);
4539 


5154         } else {
5155                 vd = vdev_alloc_common(spa, id, 0, &vdev_hole_ops);
5156                 vdev_add_child(rvd, vd);
5157         }
5158         vdev_config_dirty(rvd);
5159 
5160         /*
5161          * Reassess the health of our root vdev.
5162          */
5163         vdev_reopen(rvd);
5164 }
5165 
5166 /*
5167  * Remove a device from the pool -
5168  *
5169  * Removing a device from the vdev namespace requires several steps
5170  * and can take a significant amount of time.  As a result we use
5171  * the spa_vdev_config_[enter/exit] functions which allow us to
5172  * grab and release the spa_config_lock while still holding the namespace
5173  * lock.  During each step the configuration is synced out.
5174  *
5175  * Currently, this supports removing only hot spares, slogs, and level 2 ARC
5176  * devices.


5177  */
5178 int
5179 spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare)
5180 {
5181         vdev_t *vd;
5182         metaslab_group_t *mg;
5183         nvlist_t **spares, **l2cache, *nv;
5184         uint64_t txg = 0;
5185         uint_t nspares, nl2cache;
5186         int error = 0;
5187         boolean_t locked = MUTEX_HELD(&spa_namespace_lock);
5188 
5189         ASSERT(spa_writeable(spa));
5190 
5191         if (!locked)
5192                 txg = spa_vdev_enter(spa);
5193 
5194         vd = spa_lookup_by_guid(spa, guid, B_FALSE);
5195 
5196         if (spa->spa_spares.sav_vdevs != NULL &&


5266         } else if (vd != NULL) {
5267                 /*
5268                  * Normal vdevs cannot be removed (yet).
5269                  */
5270                 error = SET_ERROR(ENOTSUP);
5271         } else {
5272                 /*
5273                  * There is no vdev of any kind with the specified guid.
5274                  */
5275                 error = SET_ERROR(ENOENT);
5276         }
5277 
5278         if (!locked)
5279                 return (spa_vdev_exit(spa, NULL, txg, error));
5280 
5281         return (error);
5282 }
5283 
5284 /*
5285  * Find any device that's done replacing, or a vdev marked 'unspare' that's
5286  * currently spared, so we can detach it.
5287  */
5288 static vdev_t *
5289 spa_vdev_resilver_done_hunt(vdev_t *vd)
5290 {
5291         vdev_t *newvd, *oldvd;
5292 
5293         for (int c = 0; c < vd->vdev_children; c++) {
5294                 oldvd = spa_vdev_resilver_done_hunt(vd->vdev_child[c]);
5295                 if (oldvd != NULL)
5296                         return (oldvd);
5297         }
5298 
5299         /*
5300          * Check for a completed replacement.  We always consider the first
5301          * vdev in the list to be the oldest vdev, and the last one to be
5302          * the newest (see spa_vdev_attach() for how that works).  In
5303          * the case where the newest vdev is faulted, we will not automatically
5304          * remove it after a resilver completes.  This is OK as it will require
5305          * user intervention to determine which disk the admin wishes to keep.
5306          */