summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2001-08-07 19:23:16 +0000
committerdd <dd@FreeBSD.org>2001-08-07 19:23:16 +0000
commit045a8bbdf3d204f9af49aeba72bc5c7d309b57ec (patch)
treea89d9c90f75b5523685db7844d5fb94cba02cc76 /sys
parentb80b9bc08636427818bc7ee7ac20841643ad1025 (diff)
downloadFreeBSD-src-045a8bbdf3d204f9af49aeba72bc5c7d309b57ec.zip
FreeBSD-src-045a8bbdf3d204f9af49aeba72bc5c7d309b57ec.tar.gz
Introduce a force option, MD_FORCE, that instructs the driver to
bypass some extra anti-foot-shooting measures. Currently, its only effect is to allow detaching a device while it's still open (e.g., mounted). This is useful for testing how the system reacts to a disk suddenly going away, which can happen with some removeable media. At this point, the force option is only checked on detach, so it would've been possible to allow the option to be passed with the MDIOCDETACH operation. This was not done to allow the possibility of having the force flag influence other tests in the future, which may not necessarily deal with detaching the device. Reviewed by: sobomax Approved by: phk
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/md/md.c7
-rw-r--r--sys/sys/mdioctl.h1
2 files changed, 6 insertions, 2 deletions
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index ec82b33..dbec37a3 100644
--- a/sys/dev/md/md.c
+++ b/sys/dev/md/md.c
@@ -553,6 +553,7 @@ mdcreate_preload(struct md_ioctl *mdio)
sc->type = MD_PRELOAD;
sc->secsize = DEV_BSIZE;
sc->nsect = mdio->md_size;
+ sc->flags = mdio->md_options & MD_FORCE;
/* Cast to pointer size, then to pointer to avoid warning */
sc->pl_ptr = (u_char *)(uintptr_t)mdio->md_base;
sc->pl_len = (mdio->md_size << DEV_BSHIFT);
@@ -587,7 +588,7 @@ mdcreate_malloc(struct md_ioctl *mdio)
sc->type = MD_MALLOC;
sc->secsize = DEV_BSIZE;
sc->nsect = mdio->md_size;
- sc->flags = mdio->md_options & MD_COMPRESS;
+ sc->flags = mdio->md_options & (MD_COMPRESS | MD_FORCE);
MALLOC(sc->secp, u_char **, sc->nsect * sizeof(u_char *), M_MD, M_WAITOK | M_ZERO);
if (mdio->md_options & MD_RESERVE) {
for (u = 0; u < sc->nsect; u++)
@@ -658,6 +659,7 @@ mdcreate_vnode(struct md_ioctl *mdio, struct proc *p)
return (EBUSY);
sc->type = MD_VNODE;
+ sc->flags = mdio->md_options & MD_FORCE;
flags = FREAD|FWRITE;
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, mdio->md_file, p);
@@ -776,6 +778,7 @@ mdcreate_swap(struct md_ioctl *mdio, struct proc *p)
sc->secsize = PAGE_SIZE;
sc->nsect = mdio->md_size / (PAGE_SIZE / DEV_BSIZE);
sc->object = vm_pager_allocate(OBJT_SWAP, NULL, sc->secsize * (vm_offset_t)sc->nsect, VM_PROT_DEFAULT, 0);
+ sc->flags = mdio->md_options & MD_FORCE;
if (mdio->md_options & MD_RESERVE) {
if (swap_pager_reserve(sc->object, 0, sc->nsect) < 0) {
vm_pager_deallocate(sc->object);
@@ -827,7 +830,7 @@ 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)
+ if (sc->opencount != 0 && !(sc->flags & MD_FORCE))
return (EBUSY);
switch(sc->type) {
case MD_VNODE:
diff --git a/sys/sys/mdioctl.h b/sys/sys/mdioctl.h
index 6ebda6b..6b16fde 100644
--- a/sys/sys/mdioctl.h
+++ b/sys/sys/mdioctl.h
@@ -84,5 +84,6 @@ struct md_ioctl {
#define MD_AUTOUNIT 0x04 /* Assign next free unit */
#define MD_READONLY 0x08 /* Readonly mode */
#define MD_COMPRESS 0x10 /* Compression mode */
+#define MD_FORCE 0x20 /* Don't try to prevent foot-shooting */
#endif /* _SYS_MDIOCTL_H_*/
OpenPOWER on IntegriCloud