From owner-cvs-all Fri Aug 3 13:22:46 2001 Delivered-To: cvs-all@freebsd.org Received: from bazooka.unixfreak.org (bazooka.unixfreak.org [63.198.170.138]) by hub.freebsd.org (Postfix) with ESMTP id 9AA8737B403; Fri, 3 Aug 2001 13:22:16 -0700 (PDT) (envelope-from dima@unixfreak.org) Received: by bazooka.unixfreak.org (Postfix, from userid 1000) id 30EB13E31; Fri, 3 Aug 2001 13:22:16 -0700 (PDT) Received: from bazooka.unixfreak.org (localhost [127.0.0.1]) by bazooka.unixfreak.org (Postfix) with ESMTP id 246D73C12B; Fri, 3 Aug 2001 13:22:16 -0700 (PDT) To: Maxim Sobolev Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, phk@freebsd.org Subject: Re: cvs commit: src/sys/dev/md md.c In-Reply-To: <200108021019.f72AJEw86076@freefall.freebsd.org>; from sobomax@FreeBSD.org on "Thu, 2 Aug 2001 03:19:14 -0700 (PDT)" Date: Fri, 03 Aug 2001 13:22:11 -0700 From: Dima Dorfman Message-Id: <20010803202216.30EB13E31@bazooka.unixfreak.org> Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Maxim Sobolev 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