Date: Fri, 03 Aug 2001 13:22:11 -0700 From: Dima Dorfman <dima@unixfreak.org> To: Maxim Sobolev <sobomax@FreeBSD.org> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, phk@freebsd.org Subject: Re: cvs commit: src/sys/dev/md md.c Message-ID: <20010803202216.30EB13E31@bazooka.unixfreak.org> In-Reply-To: <200108021019.f72AJEw86076@freefall.freebsd.org>; from sobomax@FreeBSD.org on "Thu, 2 Aug 2001 03:19:14 -0700 (PDT)"
next in thread | previous in thread | raw e-mail | index | archive | help
Maxim Sobolev <sobomax@FreeBSD.org> writes:
> sobomax 2001/08/02 03:19:14 PDT
>
> Modified files:
> sys/dev/md md.c
> Log:
> - 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;
When I proposed a similar patch some time ago, phk said that he would
like md(4) to behave "as much like a real disk as possible", which
included being able to go offline at any moment (in md terms, this
would mean detaching). This would be useful for testing such things
as a removable ATA flash drive going away.
That said, detaching an md while it's mounted is only going to bite
more people as more people start using -current (esp. when it comes
closer to being -release), so this safeguard is a good idea. However,
it would still be nice to be able to turn it off when one wishes. I
propose to add a "force" option that will tell the driver to turn off
anti-foot shooting precautions such as this one. Attached is a patch
to do that.
Comments? Thoughts?
Index: sys/sys/mdioctl.h
===================================================================
RCS file: /ref/cvsf/src/sys/sys/mdioctl.h,v
retrieving revision 1.8
diff -u -r1.8 mdioctl.h
--- sys/sys/mdioctl.h 2001/02/25 13:12:54 1.8
+++ sys/sys/mdioctl.h 2001/08/02 12:30:47
@@ -84,5 +84,6 @@
#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_*/
Index: sys/dev/md/md.c
===================================================================
RCS file: /ref/cvsf/src/sys/dev/md/md.c,v
retrieving revision 1.40
diff -u -r1.40 md.c
--- sys/dev/md/md.c 2001/08/02 10:19:13 1.40
+++ sys/dev/md/md.c 2001/08/03 20:02:19
@@ -553,6 +553,7 @@
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 @@
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 @@
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 @@
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 @@
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:
Index: sbin/mdconfig/mdconfig.8
===================================================================
RCS file: /ref/cvsf/src/sbin/mdconfig/mdconfig.8,v
retrieving revision 1.11
diff -u -r1.11 mdconfig.8
--- sbin/mdconfig/mdconfig.8 2001/07/15 07:49:10 1.11
+++ sbin/mdconfig/mdconfig.8 2001/08/03 20:18:31
@@ -129,6 +129,11 @@
.Xc
Enable/Disable compression features to reduce memory usage.
.It Xo
+.Oo Cm no Oc Ns Cm force
+.Xc
+Disable/Enable extra sanity checks to prevent the user from doing something
+that might adversely affect the system.
+.It Xo
.Oo Cm no Oc Ns Cm readonly
.Xc
Enable/Disable readonly mode.
Index: sbin/mdconfig/mdconfig.c
===================================================================
RCS file: /ref/cvsf/src/sbin/mdconfig/mdconfig.c,v
retrieving revision 1.16
diff -u -r1.16 mdconfig.c
--- sbin/mdconfig/mdconfig.c 2001/07/18 13:32:38 1.16
+++ sbin/mdconfig/mdconfig.c 2001/08/03 20:14:43
@@ -120,6 +120,10 @@
mdio.md_options |= MD_COMPRESS;
else if (!strcmp(optarg, "nocompress"))
mdio.md_options &= ~MD_COMPRESS;
+ else if (!strcmp(optarg, "force"))
+ mdio.md_options |= MD_FORCE;
+ else if (!strcmp(optarg, "noforce"))
+ mdio.md_options &= ~MD_FORCE;
else if (!strcmp(optarg, "reserve"))
mdio.md_options |= MD_RESERVE;
else if (!strcmp(optarg, "noreserve"))
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010803202216.30EB13E31>
