Discussion:
ensure device revoke unmounts
Alexander Bluhm
2016-01-29 14:50:43 UTC
Permalink
Hi,

When removing an umass USB stick with a mounted file system, it
must get unmounted. Otherwise the kernel will crash later. While
reading the code, I discovered that vfs_busy() is using RW_SLEEPFAIL.
So if another regular non-forced unmount is unsuccessful while
vop_generic_revoke() does not unmount because the mount point is
busy, this will result in a mount point without a valid device.

So I think it is better to check and sleep in a loop, although I
did not see this problem in practice.

ok?

bluhm

Index: kern/vfs_default.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/kern/vfs_default.c,v
retrieving revision 1.41
diff -u -p -r1.41 vfs_default.c
--- kern/vfs_default.c 14 Mar 2015 03:38:51 -0000 1.41
+++ kern/vfs_default.c 27 Jan 2016 17:53:10 -0000
@@ -66,7 +66,8 @@ vop_generic_revoke(void *v)

vp = ap->a_vp;

- if (vp->v_type == VBLK && vp->v_specinfo != 0) {
+ while (vp->v_type == VBLK && vp->v_specinfo != NULL &&
+ vp->v_specmountpoint != NULL) {
struct mount *mp = vp->v_specmountpoint;

/*
@@ -74,8 +75,10 @@ vop_generic_revoke(void *v)
* flush it out now, as to not leave a dangling zombie mount
* point laying around in VFS.
*/
- if (mp != NULL && !vfs_busy(mp, VB_WRITE|VB_WAIT))
+ if (!vfs_busy(mp, VB_WRITE|VB_WAIT)) {
dounmount(mp, MNT_FORCE | MNT_DOOMED, p, NULL);
+ break;
+ }
}

if (vp->v_flag & VALIASED) {

Loading...