summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2001-08-02 10:19:13 +0000
committersobomax <sobomax@FreeBSD.org>2001-08-02 10:19:13 +0000
commit4de8e0e1a0b3240f877fcd6be5933e8e49e03e1c (patch)
treecfc2f28f24c5395a918df2ea93e1bfc16876f13a
parentc98910abd5b0b1b0f9f60a1a03c87108d570ecfb (diff)
downloadFreeBSD-src-4de8e0e1a0b3240f877fcd6be5933e8e49e03e1c.zip
FreeBSD-src-4de8e0e1a0b3240f877fcd6be5933e8e49e03e1c.tar.gz
- Deny detaching requests until device is still open, otherwise it is possible
to hang or panic kernel by detaching disk from which fs is mounted; - replace "md" with MD_NAME in yet another place. Reviewed by: phk Approved by: phk
-rw-r--r--sys/dev/md/md.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index 3f03be4..ec82b33 100644
--- a/sys/dev/md/md.c
+++ b/sys/dev/md/md.c
@@ -114,11 +114,12 @@ static dev_t status_dev = 0;
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,
@@ -159,6 +160,7 @@ struct md_s {
int busy;
enum md_types type;
unsigned nsect;
+ unsigned opencount;
unsigned secsize;
unsigned flags;
@@ -197,6 +199,16 @@ mdopen(dev_t dev, int flag, int fmt, struct proc *p)
dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
dl->d_secperunit = sc->nsect;
dl->d_ncylinders = dl->d_secperunit / dl->d_secpercyl;
+ sc->opencount++;
+ return (0);
+}
+
+static int
+mdclose(dev_t dev, int flags, int fmt, struct proc *p)
+{
+ struct md_s *sc = dev->si_drv1;
+
+ sc->opencount--;
return (0);
}
@@ -815,6 +827,8 @@ mdctlioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
sc = mdfind(mdio->md_unit);
if (sc == NULL)
return (ENOENT);
+ if (sc->opencount != 0)
+ return (EBUSY);
switch(sc->type) {
case MD_VNODE:
case MD_SWAP:
@@ -898,8 +912,8 @@ md_drvinit(void *unused)
ptr = *(u_char **)c;
c = preload_search_info(mod, MODINFO_SIZE);
len = *(unsigned *)c;
- printf("md%d: Preloaded image <%s> %d bytes at %p\n",
- mdunits, name, len, ptr);
+ printf("%s%d: Preloaded image <%s> %d bytes at %p\n",
+ MD_NAME, mdunits, name, len, ptr);
md_preloaded(ptr, len);
}
status_dev = make_dev(&mdctl_cdevsw, 0xffff00ff, UID_ROOT, GID_WHEEL,
OpenPOWER on IntegriCloud