From c15cf907680e1a4a9af3fa1ae5543cebc13fae00 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 31 Jan 2022 16:28:10 +0000 Subject: [PATCH 29/37] 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index 43b27a7eb375..d614f8f74d0b 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -595,6 +595,13 @@ spec_node_revoke(vnode_t *vp) mutex_enter(&device_lock); KASSERT(sn->sn_opencnt == 0); } + + /* + * In case the revoke happened concurrently with the last + * close, wait for the last close to complete. + */ + while (sd->sd_closing) + cv_wait(&specfs_iocv, &device_lock); mutex_exit(&device_lock); }