Skip to content

Commit f319ff3

Browse files
authored
vdev_disk_close: take disk write lock before destroying it
Many IO operations are submitted to the kernel async, and so the zio can complete and followup actions before the submission call returns. If one of the followup actions closes the disk (eg during pool create/import), the initiator may be left holding a lock on the disk at destruction. Instead, take the write lock before finishing up and decoupling the disk state from the vdev proper. The caller will hold until all IO is submitted and locks released. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com> Signed-off-by: Rob Norris <rob.norris@klarasystems.com> Closes #17719
1 parent 3f4312a commit f319ff3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

module/os/linux/zfs/vdev_disk.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,17 @@ vdev_disk_close(vdev_t *v)
471471
if (v->vdev_reopening || vd == NULL)
472472
return;
473473

474+
rw_enter(&vd->vd_lock, RW_WRITER);
475+
474476
if (vd->vd_bdh != NULL)
475477
vdev_blkdev_put(vd->vd_bdh, spa_mode(v->vdev_spa),
476478
zfs_vdev_holder);
477479

480+
v->vdev_tsd = NULL;
481+
482+
rw_exit(&vd->vd_lock);
478483
rw_destroy(&vd->vd_lock);
479484
kmem_free(vd, sizeof (vdev_disk_t));
480-
v->vdev_tsd = NULL;
481485
}
482486

483487
/*

0 commit comments

Comments
 (0)