Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/umount If an external unmount program of the form "umou...



details:   https://anonhg.NetBSD.org/src/rev/4869be611253
branches:  trunk
changeset: 816246:4869be611253
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Jun 26 03:40:39 2016 +0000

description:
If an external unmount program of the form "umount_TYPE" exists
(e.g. umount_ffs, umount_nfs, etc.) exec it instead of calling
unmount(2).

Closes PR 698.

Note that the original plan for the PR also involved adding a generic
facility to store an alternate FS type name in the kernel to use when
unmounting. This was intended to support filesystems implemented as
loopback nfs servers, where the visible mount would be of type "nfs"
pointing at localhost; in that case one would want to be able to
provide an additional string in order to run an unmount program that
would both remove that mount and also shut down the loopback nfs
server daemon.

However, in the 21+ years since the PR was filed, loopback nfs servers
have gone out of favor (for good reasons) so I don't see any need to
worry about this case at present, especially since the PR has been
hanging around this long anyway. (If anyone still has a loopback nfs
server that they want to use a custom unmount program with, file a new
PR and assign it to me and I'll deal with it specifically in the nfs
mount args structure, which unmount already knows how to retrieve and
examine.)

It is my understanding that filesystems implemented with fuse (which
has displaced the loopback nfs server model) can already set the FS
type field so no further work is needed to allow them to use a custom
unmount program. If this is not the case, please let me know and I'll
attend to it.

There is no longer any need that I see to provide a general facility
for storing an alternate filesystem type name.

(One might also ask whether there's any real need for this
functionality at all any more; this is a fair question, but (a) the
change is small and (b) there are certainly cases when doing FS
research where you want a custom unmount program; been there & done
that.)

diffstat:

 sbin/umount/umount.c |  45 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 41 insertions(+), 4 deletions(-)

diffs (86 lines):

diff -r d06bea4a5078 -r 4869be611253 sbin/umount/umount.c
--- a/sbin/umount/umount.c      Sun Jun 26 03:05:52 2016 +0000
+++ b/sbin/umount/umount.c      Sun Jun 26 03:40:39 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umount.c,v 1.49 2016/06/26 03:05:52 dholland Exp $     */
+/*     $NetBSD: umount.c,v 1.50 2016/06/26 03:40:39 dholland Exp $     */
 
 /*-
  * Copyright (c) 1980, 1989, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)umount.c   8.8 (Berkeley) 5/8/95";
 #else
-__RCSID("$NetBSD: umount.c,v 1.49 2016/06/26 03:05:52 dholland Exp $");
+__RCSID("$NetBSD: umount.c,v 1.50 2016/06/26 03:40:39 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,6 +59,7 @@
 #endif /* !SMALL */
 
 #include <err.h>
+#include <errno.h>
 #include <fstab.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -183,7 +184,7 @@
        const char *proto = NULL;
 #endif /* !SMALL */
        const char *mntpt;
-       char *type, rname[MAXPATHLEN];
+       char *type, rname[MAXPATHLEN], umountprog[MAXPATHLEN];
        mntwhat what;
        struct stat sb;
 
@@ -260,13 +261,49 @@
 #endif /* ! SMALL */
        }
 
+       snprintf(umountprog, sizeof(umountprog), "umount_%s", type);
+
 #ifndef SMALL
-       if (verbose)
+       if (verbose) {
                (void)printf("%s: unmount from %s\n", name, mntpt);
+               /* put this before the test of FAKE */ 
+               if (!raw) {
+                       (void)printf("Trying unmount program %s\n",
+                           umountprog);
+               }
+       }
        if (fake)
                return 0;
 #endif /* ! SMALL */
 
+       if (!raw) {
+               /*
+                * The only options that need to be passed on are -f
+                * and -v.
+                */
+               char *args[3];
+               unsigned nargs = 0;
+
+               args[nargs++] = umountprog;
+               if (fflag == MNT_FORCE) {
+                       args[nargs++] = __UNCONST("-f");
+               }
+#ifndef SMALL
+               if (verbose) {
+                       args[nargs++] = __UNCONST("-v");
+               }
+#endif
+               execvp(umountprog, args);
+               if (errno != ENOENT) {
+                       warn("%s: execvp", umountprog);
+               }
+       }
+
+#ifndef SMALL
+       if (verbose)
+               (void)printf("(No separate unmount program.)\n");
+#endif
+
        if (unmount(mntpt, fflag) == -1) {
                warn("%s", mntpt);
                return 1;



Home | Main Index | Thread Index | Old Index