From 6a5d41afb94bbdce304b952fd08543dc075fbcb2 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 31 Jan 2022 16:28:10 +0000 Subject: [PATCH 28/39] specfs: Wait for last close in spec_node_revoke. Otherwise, revoke -- and vdevgone, in the detach path of removable devices -- may complete while I/O operations are still running concurrently. --- sys/miscfs/specfs/spec_vnops.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index d9e492a0ba12..5c7b1cda7791 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -597,6 +597,16 @@ spec_node_revoke(vnode_t *vp) mutex_enter(&device_lock); KASSERT(sn->sn_opencnt == 0); } + + /* + * We may have revoked the vnode in this thread while another + * thread was in the middle of spec_close, in the window when + * spec_close releases the vnode lock to call .d_close for the + * last close. In that case, wait for the concurrent + * spec_close to complete. + */ + while (sd->sd_closing) + cv_wait(&specfs_iocv, &device_lock); mutex_exit(&device_lock); }