From nobody Tue May 21 22:50:21 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VkV595Zklz5L0pG; Tue, 21 May 2024 22:50:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VkV5952Djz4YVg; Tue, 21 May 2024 22:50:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716331821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RJtUjCndpQF2Jd7qJAOmiPto/0XF7U98OARfb7hlIkQ=; b=isWZCSqTTUtQpf+oyVv6DmjjNMrQedPuu+QwWAlFw+zFBxGampVsaee4J/JwKF/1pgbD7w 1PJGV0RQLv3VqY3s59113vnGz3McmK4RddjrFRMzYFehSKOnU37U08BW9a1t5ifGVdUfwv sNYpwsPVbulm6/0mDFCYdImUX3bTRZEQbLXdMxZGZAHsuVZXcHR4pEmtjYcrCKughh8s27 XI+zawPZK+B2yidWAoskbEv0t8uzQg8/jauqS5WwIa2x75cZo7T08HP02XcM9d3xChd/nu iGeTvVkgAyScSUnpC9SBiDle5gFbxXXmQ//YGNIGbFK0fPzQq9n7d/XNcRZbVg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716331821; a=rsa-sha256; cv=none; b=Hm7pWyBC417vDdozGzOWbUsnyh1HV+8JQF3S6J37AD/KSXHr5zC8W2ylC5rdDRxpNjNjEG Rb+Y1Dqjq7WpJqwvHqauMDWkfUotI4Y8IZ7tlQKsAIumjwn/ASfF7PjOPHYIWsLbU/1akA yRWriepWlMrJHv/KG3pChtkpJFtpskKQDqPWU0QVS34JINuZpoWnLcC/+C3XrbaGocpq4M pBG9rbCti23TSclc37nAp0dQZWY0S2MBb7OXusSLolhiF+XVhWW0nMrrzIjWO+4OD1IOZl TzqdxK9gY+l25Gq8BQ9QO7fZ/O7KIu5vH9lkaqLki0Wfpb55DTCRSEhP+wM7RQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716331821; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RJtUjCndpQF2Jd7qJAOmiPto/0XF7U98OARfb7hlIkQ=; b=aNuUlh0HCfQB0cifCPKKreHD52Yun22qRw4zrKUOXz3AW7PZty65Ddpw8TgajM4jTtefQC Cnb202T06SxAD/15Yprlw/ZKbNbCekK/lCijQGrEbuEJvWYENinC9BJEqTiiC7/srx49rs Gvj2sFBEWVkNVkgV6oB9y2i8LGjBceQaeN7LsiY287KCxn4NKAmppH/Xs3AAIjrt5QrvsY BA/zr2s+Oe3lUuLpYjIvobPw7SWT3gCvT5xCCNcLBA/kzV3RkQJrezjTEb6ZWUtbW+CybH AgV0+wY0HG1quMDL+uF7BQVRhXdKcPWU79eZ/LBjz1Ozs1EAbDxH+CkzGvv5zQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VkV594Kdjzh1N; Tue, 21 May 2024 22:50:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44LMoLVc021509; Tue, 21 May 2024 22:50:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44LMoLEI021506; Tue, 21 May 2024 22:50:21 GMT (envelope-from git) Date: Tue, 21 May 2024 22:50:21 GMT Message-Id: <202405212250.44LMoLEI021506@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: f9b66c0040bf - stable/14 - umount: Add -d option to detach md devices List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f9b66c0040bf03e5abe96df21690c51e881d72ed Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f9b66c0040bf03e5abe96df21690c51e881d72ed commit f9b66c0040bf03e5abe96df21690c51e881d72ed Author: Ricardo Branco AuthorDate: 2024-02-03 00:29:48 +0000 Commit: Warner Losh CommitDate: 2024-05-21 22:49:52 +0000 umount: Add -d option to detach md devices Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/972 (cherry picked from commit 840a802750a464355c52b314c17fb067b317da8c) --- sbin/umount/umount.8 | 14 ++++++---- sbin/umount/umount.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/sbin/umount/umount.8 b/sbin/umount/umount.8 index b5a7d7230269..086980151d60 100644 --- a/sbin/umount/umount.8 +++ b/sbin/umount/umount.8 @@ -25,9 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)umount.8 8.2 (Berkeley) 5/8/95 -.\" -.Dd June 19, 2020 +.Dd January 16, 2024 .Dt UMOUNT 8 .Os .Sh NAME @@ -35,7 +33,7 @@ .Nd unmount file systems .Sh SYNOPSIS .Nm -.Op Fl fNnv +.Op Fl dfNnv .Ar special ... | node ... | fsid ... .Nm .Fl a | A @@ -73,6 +71,11 @@ except for those mounted at .Pa / or .Pa /dev . +.It Fl d +If the filesystem is mounted on an +.Xr md 4 +device (a memory disk), detach it after +.Xr unmount 2 . .It Fl F Ar fstab Specify the .Pa fstab @@ -184,7 +187,8 @@ file system table .Xr unmount 2 , .Xr fstab 5 , .Xr autounmountd 8 , -.Xr mount 8 +.Xr mount 8 , +.Xr mdconfig 8 .Sh HISTORY A .Nm diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c index aca7c201bc9b..d1471076359c 100644 --- a/sbin/umount/umount.c +++ b/sbin/umount/umount.c @@ -62,10 +62,20 @@ static char sccsid[] = "@(#)umount.c 8.8 (Berkeley) 5/8/95"; #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; static struct addrinfo *nfshost_ai = NULL; -static int fflag, vflag; +static int dflag, fflag, vflag; +static int all; static char *nfshost; struct statfs *checkmntlist(char *); @@ -82,17 +92,18 @@ int checkname (char *, char **); int umountfs(struct statfs *sfs); void usage (void); int xdr_dir (XDR *, char *); +int md_detach(const char *); int main(int argc, char *argv[]) { - int all, errs, ch, mntsize, error, nfsforce, ret; + int errs, ch, mntsize, error, nfsforce, ret; char **typelist = NULL; struct statfs *mntbuf, *sfs; struct addrinfo hints; nfsforce = all = errs = 0; - while ((ch = getopt(argc, argv, "AaF:fh:Nnt:v")) != -1) + while ((ch = getopt(argc, argv, "AadF:fh:Nnt:v")) != -1) switch (ch) { case 'A': all = 2; @@ -100,6 +111,9 @@ main(int argc, char *argv[]) case 'a': all = 1; break; + case 'd': + dflag = 1; + break; case 'F': setfstab(optarg); break; @@ -467,6 +481,16 @@ umountfs(struct statfs *sfs) clnt_destroy(clp); } free(orignfsdirname); + + if (dflag) { + if (md_detach(sfs->f_mntfromname) == 0) { + if (vflag) + (void)printf("%s: detached\n", + sfs->f_mntfromname); + } else if (!all) + return (-1); + } + return (0); } @@ -649,7 +673,47 @@ usage(void) { (void)fprintf(stderr, "%s\n%s\n", - "usage: umount [-fNnv] special ... | node ... | fsid ...", - " umount -a | -A [-F fstab] [-fnv] [-h host] [-t type]"); + "usage: umount [-dfNnv] special ... | node ... | fsid ...", + " umount -a | -A [-F fstab] [-dfnv] [-h host] [-t type]"); exit(1); } + +int +md_detach(const char *device) +{ + struct md_ioctl mdio; + char *eptr; + int fd; + + memset(&mdio, 0, sizeof(mdio)); + + mdio.md_version = MDIOVERSION; + mdio.md_options = fflag ? MD_FORCE : 0; + + if (strncmp(device, DEV_MD, sizeof(DEV_MD) - 1)) { + if (!all) + warnx("invalid md device: %s", device); + return (-1); + } + + mdio.md_unit = strtoul(device + sizeof(DEV_MD) - 1, &eptr, 0); + if (mdio.md_unit == (unsigned)ULONG_MAX || *eptr != '\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); +}