From owner-freebsd-bugs@FreeBSD.ORG Tue Jul 10 05:20:03 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6002F16A469 for ; Tue, 10 Jul 2007 05:20:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 4173F13C45A for ; Tue, 10 Jul 2007 05:20:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l6A5K3FM038455 for ; Tue, 10 Jul 2007 05:20:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l6A5K3BV038454; Tue, 10 Jul 2007 05:20:03 GMT (envelope-from gnats) Resent-Date: Tue, 10 Jul 2007 05:20:03 GMT Resent-Message-Id: <200707100520.l6A5K3BV038454@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ighighi Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A624916A400 for ; Tue, 10 Jul 2007 05:16:53 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [69.147.83.33]) by mx1.freebsd.org (Postfix) with ESMTP id 966F913C459 for ; Tue, 10 Jul 2007 05:16:53 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l6A5Gr1Y029706 for ; Tue, 10 Jul 2007 05:16:53 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id l6A5GrHB029705; Tue, 10 Jul 2007 05:16:53 GMT (envelope-from nobody) Message-Id: <200707100516.l6A5GrHB029705@www.freebsd.org> Date: Tue, 10 Jul 2007 05:16:53 GMT From: Ighighi To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: bin/114468: [patch]: add -d option to umount(8) to detach md(4) device X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jul 2007 05:20:03 -0000 >Number: 114468 >Category: bin >Synopsis: [patch]: add -d option to umount(8) to detach md(4) device >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Jul 10 05:20:02 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Ighighi >Release: 6.2-STABLE >Organization: >Environment: FreeBSD orion 6.2-STABLE FreeBSD 6.2-STABLE #3: Mon Jul 9 23:03:53 VET 2007 root@orion:/usr/obj/usr/src/sys/CUSTOM i386 >Description: The attached patch adds a -d option to umount(8) to detach a memory device like mdconfig(8) does. A similar option exists in Linux's umount(8). >How-To-Repeat: >Fix: To apply this patch, run: patch -d /usr < /path/to/patch cd /usr/src/sbin/umount make clean obj depend && make && make install Patch attached with submission follows: # # (c) 2007 by Ighighi # # This patch adds a -d option to umount(8) to detach a memory device like # mdconfig(8) does (in fact, its code was imported and modified somewhat). # The choice of letter is consistent with Linux's umount(8) and mdconfig(8) # --- src/sbin/umount/umount.c.orig Thu Feb 10 05:19:34 2005 +++ src/sbin/umount/umount.c Tue Jul 10 01:06:46 2007 @@ -61,11 +61,21 @@ #include "mounttab.h" +/* used by md_detach() */ +#include +#include +#include +#include + +#define DEV_MD _PATH_DEV MD_NAME +#define DEV_MDCTL _PATH_DEV MDCTL_NAME + typedef enum { FIND, REMOVE, CHECKUNIQUE } dowhat; struct addrinfo *nfshost_ai = NULL; -int fflag, vflag; +int dflag, fflag, vflag; char *nfshost; +int multiple; struct statfs *checkmntlist(char *); int checkvfsname (const char *, char **); @@ -81,6 +91,7 @@ int umountfs(struct statfs *sfs); void usage (void); int xdr_dir (XDR *, char *); +int md_detach(const char *); int main(int argc, char *argv[]) @@ -94,7 +105,7 @@ sync(); all = errs = 0; - while ((ch = getopt(argc, argv, "AaF:fh:t:v")) != -1) + while ((ch = getopt(argc, argv, "AadF:fh:t:v")) != -1) switch (ch) { case 'A': all = 2; @@ -102,6 +113,9 @@ case 'a': all = 1; break; + case 'd': + dflag = 1; + break; case 'F': setfstab(optarg); break; @@ -130,6 +144,8 @@ if ((argc == 0 && !all) || (argc != 0 && all)) usage(); + multiple = all; + /* -h implies "-t nfs" if no -t flag. */ if ((nfshost != NULL) && (typelist == NULL)) typelist = makevfslist("nfs"); @@ -409,6 +425,14 @@ auth_destroy(clp->cl_auth); clnt_destroy(clp); } + + if (dflag) { + if (md_detach(sfs->f_mntfromname) && !multiple) + return -1; + else if (vflag) + (void)printf("%s: detached\n", sfs->f_mntfromname); + } + return (0); } @@ -591,7 +615,60 @@ { (void)fprintf(stderr, "%s\n%s\n", - "usage: umount [-fv] special | node | fsid", - " umount -a | -A [-F fstab] [-fv] [-h host] [-t type]"); + "usage: umount [-dfv] special | node | fsid", + " umount -a | -A [-F fstab] [-dfv] [-h host] [-t type]"); exit(1); } + +/* The following function contains code taken from mdconfig(8) */ + +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): + * wrote this file. As long as you retain this notice you + * can do whatever you want with this stuff. If we meet some day, and you think + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * + * $FreeBSD: src/sbin/mdconfig/mdconfig.c,v 1.43.2.4 2007/02/27 18:59:27 n_hibma Exp $ + */ + +int md_detach(const char *device) +{ + struct md_ioctl mdio; + char *p; + int fd; + + bzero(&mdio, sizeof(mdio)); + + mdio.md_version = MDIOVERSION; + mdio.md_file = (char *) device; + + if (strncmp(device, DEV_MD, sizeof(DEV_MD) - 1)) { + if (!multiple) + warnx("invalid md device: %s", device); + return -1; + } + + mdio.md_unit = strtoul(device + sizeof(DEV_MD) - 1, &p, 0); + if (mdio.md_unit == (unsigned)ULONG_MAX || *p != '\0') { + warnx("invalid md device: %s", device); + return -1; + } + + fd = open(DEV_MDCTL, O_RDWR, 0); + if (fd < 0) { + warn("%s", DEV_MDCTL); + return -1; + } + + if (ioctl(fd, MDIOCDETACH, &mdio) < 0) { + warn("%s", DEV_MD); + close(fd); + return -1; + } + + close(fd); + return 0; +} + --- src/sbin/umount/umount.8.orig Fri Apr 9 15:58:40 2004 +++ src/sbin/umount/umount.8 Tue Jul 10 01:05:02 2007 @@ -36,12 +36,12 @@ .Nd unmount file systems .Sh SYNOPSIS .Nm -.Op Fl fv +.Op Fl dfv .Ar special | node | fsid .Nm .Fl a | A .Op Fl F Ar fstab -.Op Fl fv +.Op Fl dfv .Op Fl h Ar host .Op Fl t Ar type .Sh DESCRIPTION @@ -68,6 +68,9 @@ .It Fl A All the currently mounted file systems except the root are unmounted. +.It Fl d +If the filesystem is mounted on a memory disk (see +.Xr md 4) , detach it after unmount(2). .It Fl F Ar fstab Specify the .Pa fstab @@ -136,7 +139,8 @@ .Sh SEE ALSO .Xr unmount 2 , .Xr fstab 5 , -.Xr mount 8 +.Xr mount 8 , +.Xr mdconfig 8 .Sh HISTORY A .Nm >Release-Note: >Audit-Trail: >Unformatted: