From owner-svn-src-all@freebsd.org Fri Aug 25 22:58:55 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 45D45DE33D8; Fri, 25 Aug 2017 22:58:55 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1FF4F73F3E; Fri, 25 Aug 2017 22:58:55 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7PMwsIc021292; Fri, 25 Aug 2017 22:58:54 GMT (envelope-from rmacklem@FreeBSD.org) Received: (from rmacklem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7PMwsRb021290; Fri, 25 Aug 2017 22:58:54 GMT (envelope-from rmacklem@FreeBSD.org) Message-Id: <201708252258.v7PMwsRb021290@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: rmacklem set sender to rmacklem@FreeBSD.org using -f From: Rick Macklem Date: Fri, 25 Aug 2017 22:58:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r322910 - stable/11/sbin/umount X-SVN-Group: stable-11 X-SVN-Commit-Author: rmacklem X-SVN-Commit-Paths: stable/11/sbin/umount X-SVN-Commit-Revision: 322910 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Aug 2017 22:58:55 -0000 Author: rmacklem Date: Fri Aug 25 22:58:54 2017 New Revision: 322910 URL: https://svnweb.freebsd.org/changeset/base/322910 Log: MFC: r321689 Add a new "-N" option to umount(8), that does a forced dismount of an NFS mount point. The new "-N" option does a forced dismount of an NFS mount point, but avoids doing any checking of the mounted-on path, so that it will not get hung when a vnode lock is held by another hung process on the mounted-on vnode. The most common case of this is a "umount" with the "-f" option. Other than avoiding checking the mounted-on path, it performs the same forced dismount as a successful "umount -f" would do. This commit includes a content change to the man page. Modified: stable/11/sbin/umount/umount.8 stable/11/sbin/umount/umount.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sbin/umount/umount.8 ============================================================================== --- stable/11/sbin/umount/umount.8 Fri Aug 25 22:52:40 2017 (r322909) +++ stable/11/sbin/umount/umount.8 Fri Aug 25 22:58:54 2017 (r322910) @@ -28,7 +28,7 @@ .\" @(#)umount.8 8.2 (Berkeley) 5/8/95 .\" $FreeBSD$ .\" -.Dd July 7, 2016 +.Dd July 25, 2017 .Dt UMOUNT 8 .Os .Sh NAME @@ -36,7 +36,7 @@ .Nd unmount file systems .Sh SYNOPSIS .Nm -.Op Fl fnv +.Op Fl fNnv .Ar special ... | node ... | fsid ... .Nm .Fl a | A @@ -81,6 +81,15 @@ The root file system cannot be forcibly unmounted. For NFS, a forced dismount can take up to 1 minute or more to complete against an unresponsive server and may throw away data not yet written to the server for this case. +If a process, such as +.Nm +without the +.Fl f +flag is hung on an +.Tn NFS +mount point, use the +.Fl N +flag instead. Also, doing a forced dismount of an NFSv3 mount when .Xr rpc.lockd 8 is running is unsafe and can result in a crash. @@ -94,6 +103,24 @@ option and, unless otherwise specified with the option, will only unmount .Tn NFS file systems. +.It Fl N +Do a forced dismount of an +.Tn NFS +mount point without checking the mount path. +This option can only be used with the path to the mount point +.Ar node +and the path must be specified exactly as it was at mount time. +This option is useful when a process is hung waiting for an unresponsive +.Tn NFS +server while holding a vnode lock on the mounted-on vnode, such that +.Nm +with the +.Fl f +flag can't complete. +Using this option can result in a loss of file updates that have not been +flushed to the +.Tn NFS +server. .It Fl n Unless the .Fl f Modified: stable/11/sbin/umount/umount.c ============================================================================== --- stable/11/sbin/umount/umount.c Fri Aug 25 22:52:40 2017 (r322909) +++ stable/11/sbin/umount/umount.c Fri Aug 25 22:58:54 2017 (r322910) @@ -86,13 +86,13 @@ int xdr_dir (XDR *, char *); int main(int argc, char *argv[]) { - int all, errs, ch, mntsize, error; + int all, errs, ch, mntsize, error, nfsforce, ret; char **typelist = NULL; struct statfs *mntbuf, *sfs; struct addrinfo hints; - all = errs = 0; - while ((ch = getopt(argc, argv, "AaF:fh:nt:v")) != -1) + nfsforce = all = errs = 0; + while ((ch = getopt(argc, argv, "AaF:fh:Nnt:v")) != -1) switch (ch) { case 'A': all = 2; @@ -110,6 +110,9 @@ main(int argc, char *argv[]) all = 2; nfshost = optarg; break; + case 'N': + nfsforce = 1; + break; case 'n': fflag |= MNT_NONBUSY; break; @@ -132,12 +135,15 @@ main(int argc, char *argv[]) err(1, "-f and -n are mutually exclusive"); /* Start disks transferring immediately. */ - if ((fflag & (MNT_FORCE | MNT_NONBUSY)) == 0) + if ((fflag & (MNT_FORCE | MNT_NONBUSY)) == 0 && nfsforce == 0) sync(); if ((argc == 0 && !all) || (argc != 0 && all)) usage(); + if (nfsforce != 0 && (argc == 0 || nfshost != NULL || typelist != NULL)) + usage(); + /* -h implies "-t nfs" if no -t flag. */ if ((nfshost != NULL) && (typelist == NULL)) typelist = makevfslist("nfs"); @@ -175,7 +181,20 @@ main(int argc, char *argv[]) break; case 0: for (errs = 0; *argv != NULL; ++argv) - if (checkname(*argv, typelist) != 0) + if (nfsforce != 0) { + /* + * First do the nfssvc() syscall to shut down + * the mount point and then do the forced + * dismount. + */ + ret = nfssvc(NFSSVC_FORCEDISM, *argv); + if (ret >= 0) + ret = unmount(*argv, MNT_FORCE); + if (ret < 0) { + warn("%s", *argv); + errs = 1; + } + } else if (checkname(*argv, typelist) != 0) errs = 1; break; } @@ -635,7 +654,7 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: umount [-fnv] special ... | node ... | fsid ...", + "usage: umount [-fNnv] special ... | node ... | fsid ...", " umount -a | -A [-F fstab] [-fnv] [-h host] [-t type]"); exit(1); }