Skip to content

Commit a68dfdb

Browse files
ixhamzabehlendorf
authored andcommitted
Fix "Detach spare vdev in case if resilvering does not happen"
Spare vdev should detach from the pool when a disk is reinserted. However, spare detachment depends on the completion of resilvering, and if resilver does not schedule, the spare vdev keeps attached to the pool until the next resilvering. When a zfs pool contains several disks (25+ mirror), resilvering does not always happen when a disk is reinserted. In this patch, spare vdev is manually detached from the pool when resilvering does not occur and it has been tested on both Linux and FreeBSD. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #14722
1 parent 4a5950a commit a68dfdb

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

include/sys/spa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ extern int bpobj_enqueue_free_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
785785
#define SPA_ASYNC_L2CACHE_REBUILD 0x800
786786
#define SPA_ASYNC_L2CACHE_TRIM 0x1000
787787
#define SPA_ASYNC_REBUILD_DONE 0x2000
788+
#define SPA_ASYNC_DETACH_SPARE 0x4000
788789

789790
/* device manipulation */
790791
extern int spa_vdev_add(spa_t *spa, nvlist_t *nvroot);

module/zfs/spa.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6987,7 +6987,7 @@ spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing,
69876987
* Detach a device from a mirror or replacing vdev.
69886988
*
69896989
* If 'replace_done' is specified, only detach if the parent
6990-
* is a replacing vdev.
6990+
* is a replacing or a spare vdev.
69916991
*/
69926992
int
69936993
spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
@@ -8210,7 +8210,8 @@ spa_async_thread(void *arg)
82108210
* If any devices are done replacing, detach them.
82118211
*/
82128212
if (tasks & SPA_ASYNC_RESILVER_DONE ||
8213-
tasks & SPA_ASYNC_REBUILD_DONE) {
8213+
tasks & SPA_ASYNC_REBUILD_DONE ||
8214+
tasks & SPA_ASYNC_DETACH_SPARE) {
82148215
spa_vdev_resilver_done(spa);
82158216
}
82168217

module/zfs/vdev.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4085,9 +4085,19 @@ vdev_online(spa_t *spa, uint64_t guid, uint64_t flags, vdev_state_t *newstate)
40854085

40864086
if (wasoffline ||
40874087
(oldstate < VDEV_STATE_DEGRADED &&
4088-
vd->vdev_state >= VDEV_STATE_DEGRADED))
4088+
vd->vdev_state >= VDEV_STATE_DEGRADED)) {
40894089
spa_event_notify(spa, vd, NULL, ESC_ZFS_VDEV_ONLINE);
40904090

4091+
/*
4092+
* Asynchronously detach spare vdev if resilver or
4093+
* rebuild is not required
4094+
*/
4095+
if (vd->vdev_unspare &&
4096+
!dsl_scan_resilvering(spa->spa_dsl_pool) &&
4097+
!dsl_scan_resilver_scheduled(spa->spa_dsl_pool) &&
4098+
!vdev_rebuild_active(tvd))
4099+
spa_async_request(spa, SPA_ASYNC_DETACH_SPARE);
4100+
}
40914101
return (spa_vdev_state_exit(spa, vd, 0));
40924102
}
40934103

0 commit comments

Comments
 (0)