Print this page
3956 ::vdev -r should work with pipelines
3957 ztest should update the cachefile before killing itself
3958 multiple scans can lead to partial resilvering
3959 ddt entries are not always resilvered
3960 dsl_scan can skip over dedup-ed blocks if physical birth != logical birth
3961 freed gang blocks are not resilvered and can cause pool to suspend
3962 ztest should print out zfs debug buffer before exiting
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>


4429         if (newvd->vdev_ashift > oldvd->vdev_top->vdev_ashift)
4430                 return (spa_vdev_exit(spa, newrootvd, txg, EDOM));
4431 
4432         /*
4433          * If this is an in-place replacement, update oldvd's path and devid
4434          * to make it distinguishable from newvd, and unopenable from now on.
4435          */
4436         if (strcmp(oldvd->vdev_path, newvd->vdev_path) == 0) {
4437                 spa_strfree(oldvd->vdev_path);
4438                 oldvd->vdev_path = kmem_alloc(strlen(newvd->vdev_path) + 5,
4439                     KM_SLEEP);
4440                 (void) sprintf(oldvd->vdev_path, "%s/%s",
4441                     newvd->vdev_path, "old");
4442                 if (oldvd->vdev_devid != NULL) {
4443                         spa_strfree(oldvd->vdev_devid);
4444                         oldvd->vdev_devid = NULL;
4445                 }
4446         }
4447 
4448         /* mark the device being resilvered */
4449         newvd->vdev_resilvering = B_TRUE;
4450 
4451         /*
4452          * If the parent is not a mirror, or if we're replacing, insert the new
4453          * mirror/replacing/spare vdev above oldvd.
4454          */
4455         if (pvd->vdev_ops != pvops)
4456                 pvd = vdev_add_parent(oldvd, pvops);
4457 
4458         ASSERT(pvd->vdev_top->vdev_parent == rvd);
4459         ASSERT(pvd->vdev_ops == pvops);
4460         ASSERT(oldvd->vdev_parent == pvd);
4461 
4462         /*
4463          * Extract the new device from its root and add it to pvd.
4464          */
4465         vdev_remove_child(newrootvd, newvd);
4466         newvd->vdev_id = pvd->vdev_children;
4467         newvd->vdev_crtxg = oldvd->vdev_crtxg;
4468         vdev_add_child(pvd, newvd);
4469 


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 


5382 
5383         spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
5384 
5385         while ((vd = spa_vdev_resilver_done_hunt(spa->spa_root_vdev)) != NULL) {
5386                 pvd = vd->vdev_parent;
5387                 ppvd = pvd->vdev_parent;
5388                 guid = vd->vdev_guid;
5389                 pguid = pvd->vdev_guid;
5390                 ppguid = ppvd->vdev_guid;
5391                 sguid = 0;
5392                 /*
5393                  * If we have just finished replacing a hot spared device, then
5394                  * we need to detach the parent's first child (the original hot
5395                  * spare) as well.
5396                  */
5397                 if (ppvd->vdev_ops == &vdev_spare_ops && pvd->vdev_id == 0 &&
5398                     ppvd->vdev_children == 2) {
5399                         ASSERT(pvd->vdev_ops == &vdev_replacing_ops);
5400                         sguid = ppvd->vdev_child[1]->vdev_guid;
5401                 }


5402                 spa_config_exit(spa, SCL_ALL, FTAG);
5403                 if (spa_vdev_detach(spa, guid, pguid, B_TRUE) != 0)
5404                         return;
5405                 if (sguid && spa_vdev_detach(spa, sguid, ppguid, B_TRUE) != 0)
5406                         return;
5407                 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
5408         }
5409 
5410         spa_config_exit(spa, SCL_ALL, FTAG);
5411 }
5412 
5413 /*
5414  * Update the stored path or FRU for this vdev.
5415  */
5416 int
5417 spa_vdev_set_common(spa_t *spa, uint64_t guid, const char *value,
5418     boolean_t ispath)
5419 {
5420         vdev_t *vd;
5421         boolean_t sync = B_FALSE;




4429         if (newvd->vdev_ashift > oldvd->vdev_top->vdev_ashift)
4430                 return (spa_vdev_exit(spa, newrootvd, txg, EDOM));
4431 
4432         /*
4433          * If this is an in-place replacement, update oldvd's path and devid
4434          * to make it distinguishable from newvd, and unopenable from now on.
4435          */
4436         if (strcmp(oldvd->vdev_path, newvd->vdev_path) == 0) {
4437                 spa_strfree(oldvd->vdev_path);
4438                 oldvd->vdev_path = kmem_alloc(strlen(newvd->vdev_path) + 5,
4439                     KM_SLEEP);
4440                 (void) sprintf(oldvd->vdev_path, "%s/%s",
4441                     newvd->vdev_path, "old");
4442                 if (oldvd->vdev_devid != NULL) {
4443                         spa_strfree(oldvd->vdev_devid);
4444                         oldvd->vdev_devid = NULL;
4445                 }
4446         }
4447 
4448         /* mark the device being resilvered */
4449         newvd->vdev_resilver_txg = txg;
4450 
4451         /*
4452          * If the parent is not a mirror, or if we're replacing, insert the new
4453          * mirror/replacing/spare vdev above oldvd.
4454          */
4455         if (pvd->vdev_ops != pvops)
4456                 pvd = vdev_add_parent(oldvd, pvops);
4457 
4458         ASSERT(pvd->vdev_top->vdev_parent == rvd);
4459         ASSERT(pvd->vdev_ops == pvops);
4460         ASSERT(oldvd->vdev_parent == pvd);
4461 
4462         /*
4463          * Extract the new device from its root and add it to pvd.
4464          */
4465         vdev_remove_child(newrootvd, newvd);
4466         newvd->vdev_id = pvd->vdev_children;
4467         newvd->vdev_crtxg = oldvd->vdev_crtxg;
4468         vdev_add_child(pvd, newvd);
4469 


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         /*
5307          * Check for a completed replacement.  We always consider the first
5308          * vdev in the list to be the oldest vdev, and the last one to be
5309          * the newest (see spa_vdev_attach() for how that works).  In
5310          * the case where the newest vdev is faulted, we will not automatically
5311          * remove it after a resilver completes.  This is OK as it will require
5312          * user intervention to determine which disk the admin wishes to keep.
5313          */
5314         if (vd->vdev_ops == &vdev_replacing_ops) {
5315                 ASSERT(vd->vdev_children > 1);
5316 
5317                 newvd = vd->vdev_child[vd->vdev_children - 1];
5318                 oldvd = vd->vdev_child[0];
5319 
5320                 if (vdev_dtl_empty(newvd, DTL_MISSING) &&
5321                     vdev_dtl_empty(newvd, DTL_OUTAGE) &&
5322                     !vdev_dtl_required(oldvd))
5323                         return (oldvd);
5324         }
5325 


5375 
5376         spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
5377 
5378         while ((vd = spa_vdev_resilver_done_hunt(spa->spa_root_vdev)) != NULL) {
5379                 pvd = vd->vdev_parent;
5380                 ppvd = pvd->vdev_parent;
5381                 guid = vd->vdev_guid;
5382                 pguid = pvd->vdev_guid;
5383                 ppguid = ppvd->vdev_guid;
5384                 sguid = 0;
5385                 /*
5386                  * If we have just finished replacing a hot spared device, then
5387                  * we need to detach the parent's first child (the original hot
5388                  * spare) as well.
5389                  */
5390                 if (ppvd->vdev_ops == &vdev_spare_ops && pvd->vdev_id == 0 &&
5391                     ppvd->vdev_children == 2) {
5392                         ASSERT(pvd->vdev_ops == &vdev_replacing_ops);
5393                         sguid = ppvd->vdev_child[1]->vdev_guid;
5394                 }
5395                 ASSERT(vd->vdev_resilver_txg == 0 || !vdev_dtl_required(vd));
5396 
5397                 spa_config_exit(spa, SCL_ALL, FTAG);
5398                 if (spa_vdev_detach(spa, guid, pguid, B_TRUE) != 0)
5399                         return;
5400                 if (sguid && spa_vdev_detach(spa, sguid, ppguid, B_TRUE) != 0)
5401                         return;
5402                 spa_config_enter(spa, SCL_ALL, FTAG, RW_WRITER);
5403         }
5404 
5405         spa_config_exit(spa, SCL_ALL, FTAG);
5406 }
5407 
5408 /*
5409  * Update the stored path or FRU for this vdev.
5410  */
5411 int
5412 spa_vdev_set_common(spa_t *spa, uint64_t guid, const char *value,
5413     boolean_t ispath)
5414 {
5415         vdev_t *vd;
5416         boolean_t sync = B_FALSE;