bin/114468: [patch]: add -d option to umount(8) to detach md(4)
device
Ighighi
ighighi at gmail.com
Tue Jul 10 05:20:03 UTC 2007
>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 at 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 <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/mdioctl.h>
+#include <paths.h>
+
+#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):
+ * <phk at FreeBSD.ORG> 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:
More information about the freebsd-bugs
mailing list