diff options
| author | hannken <hannken@NetBSD.org> | 2017-06-24 12:14:21 +0000 |
|---|---|---|
| committer | hannken <hannken@NetBSD.org> | 2017-06-24 12:14:21 +0000 |
| commit | 9dffe559a7a533a3db99b4e5678f4efb49f759db (patch) | |
| tree | fcaf77b936b64086c81b780ca844a3c745c54f26 /sys/miscfs | |
| parent | 0277227eed7371634150e18963f193cae91d1a73 (diff) | |
Refuse to open a block device with zero open count when it has
a mountpoint set. This may happen after forced detach or unplug
of a mounted block device.
Diffstat (limited to 'sys/miscfs')
| -rw-r--r-- | sys/miscfs/specfs/spec_vnops.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/miscfs/specfs/spec_vnops.c b/sys/miscfs/specfs/spec_vnops.c index 9ca6086472a..dc26c4ac74f 100644 --- a/sys/miscfs/specfs/spec_vnops.c +++ b/sys/miscfs/specfs/spec_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: spec_vnops.c,v 1.173 2017/06/01 02:45:14 chs Exp $ */ +/* $NetBSD: spec_vnops.c,v 1.174 2017/06/24 12:14:21 hannken Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.173 2017/06/01 02:45:14 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.174 2017/06/24 12:14:21 hannken Exp $"); #include <sys/param.h> #include <sys/proc.h> @@ -580,13 +580,16 @@ spec_open(void *v) * For block devices, permit only one open. The buffer * cache cannot remain self-consistent with multiple * vnodes holding a block device open. + * + * Treat zero opencnt with non-NULL mountpoint as open. + * This may happen after forced detach of a mounted device. */ mutex_enter(&device_lock); if (sn->sn_gone) { mutex_exit(&device_lock); return (EBADF); } - if (sd->sd_opencnt != 0) { + if (sd->sd_opencnt != 0 || sd->sd_mountpoint != NULL) { mutex_exit(&device_lock); return EBUSY; } |
