Date: Mon, 12 Mar 2001 23:17:44 -0800 From: Dima Dorfman <dima@unixfreak.org> To: hackers@freebsd.org Subject: Patch to fix panic when detaching a mounted md device Message-ID: <20010313071744.C988C3E09@bazooka.unixfreak.org>
next in thread | raw e-mail | index | archive | help
Hello -hackers
Right now, if you try to detach an md device that's currently mounted,
you will get a panic (maybe not immedietely, but it will come, esp. if
you ever try to use that mountpoint again). I'm pretty sure this is a
known problem, with the solution--or workaround--being, "then don't do
that." The problem is, someone will invariably do it. The fix is to
make md complain if you try to detach a device that's currently
opened. Below is a patch that implements this by keeping track of the
number of times a device has been opened.
Comments?
Thanks
Dima Dorfman
dima@unixfreak.org
Index: md.c
===================================================================
RCS file: /st/src/FreeBSD/src/sys/dev/md/md.c,v
retrieving revision 1.26
diff -u -r1.26 md.c
--- md.c 2001/03/09 20:06:30 1.26
+++ md.c 2001/03/13 07:04:43
@@ -122,11 +122,12 @@
static d_strategy_t mdstrategy;
static d_open_t mdopen;
+static d_close_t mdclose;
static d_ioctl_t mdioctl, mdctlioctl;
static struct cdevsw md_cdevsw = {
/* open */ mdopen,
- /* close */ nullclose,
+ /* close */ mdclose,
/* read */ physread,
/* write */ physwrite,
/* ioctl */ mdioctl,
@@ -169,6 +170,7 @@
unsigned nsect;
unsigned secsize;
unsigned flags;
+ unsigned opencnt;
/* MD_MALLOC related fields */
u_char **secp;
@@ -205,6 +207,18 @@
dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
dl->d_secperunit = sc->nsect;
dl->d_ncylinders = dl->d_secperunit / dl->d_secpercyl;
+ sc->opencnt++;
+ return (0);
+}
+
+static int
+mdclose(dev_t dev, int flag, int fmt, struct proc *p)
+{
+ struct md_s *sc;
+
+ sc = dev->si_drv1;
+ KASSERT(sc->opencnt > 0, ("md: closing an unopened device"));
+ sc->opencnt--;
return (0);
}
@@ -824,6 +838,8 @@
sc = mdfind(mdio->md_unit);
if (sc == NULL)
return (ENOENT);
+ if (sc->opencnt != 0)
+ return (EBUSY);
switch(sc->type) {
case MD_VNODE:
case MD_SWAP:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010313071744.C988C3E09>
