summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2015-10-18 14:34:13 +0000
committertrasz <trasz@FreeBSD.org>2015-10-18 14:34:13 +0000
commit43f70df8998af40bd659a3123e2ea855d798c4c4 (patch)
treeef386a207a76d5a8d6ce74e375ab104b07fb2ae5
parent2f6e19044af1dd669f4e0a638b251f9104874f02 (diff)
downloadFreeBSD-src-43f70df8998af40bd659a3123e2ea855d798c4c4.zip
FreeBSD-src-43f70df8998af40bd659a3123e2ea855d798c4c4.tar.gz
MFC r286237:
Fix panic that would happen on forcibly unmounting devfs (note that as it is now, devfs ignores MNT_FORCE anyway, so it needs to be modified to trigger the panic) with consumers still opened. Note that this still results in a leak of r/w/e counters. It seems to be harmless, though. If anyone knows a better way to approach this - please tell. Sponsored by: The FreeBSD Foundation
-rw-r--r--sys/geom/geom_dev.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/geom/geom_dev.c b/sys/geom/geom_dev.c
index 621a037..bf2ba9e 100644
--- a/sys/geom/geom_dev.c
+++ b/sys/geom/geom_dev.c
@@ -399,6 +399,20 @@ g_dev_close(struct cdev *dev, int flags, int fmt, struct thread *td)
#else
e = 0;
#endif
+
+ /*
+ * The vgonel(9) - caused by eg. forced unmount of devfs - calls
+ * VOP_CLOSE(9) on devfs vnode without any FREAD or FWRITE flags,
+ * which would result in zero deltas, which in turn would cause
+ * panic in g_access(9).
+ *
+ * Note that we cannot zero the counters (ie. do "r = cp->acr"
+ * etc) instead, because the consumer might be opened in another
+ * devfs instance.
+ */
+ if (r + w + e == 0)
+ return (EINVAL);
+
sc = cp->private;
mtx_lock(&sc->sc_mtx);
sc->sc_open += r + w + e;
OpenPOWER on IntegriCloud