From owner-svn-src-all@freebsd.org Fri Nov 1 03:10:53 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id DDA941A1679; Fri, 1 Nov 2019 03:10:53 +0000 (UTC) (envelope-from kevans@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4746dn5cLBz4CZd; Fri, 1 Nov 2019 03:10:53 +0000 (UTC) (envelope-from kevans@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A39DE4B9A; Fri, 1 Nov 2019 03:10:53 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xA13ArMb061758; Fri, 1 Nov 2019 03:10:53 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xA13ArC0061756; Fri, 1 Nov 2019 03:10:53 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201911010310.xA13ArC0061756@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 1 Nov 2019 03:10:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354236 - head/sbin/mdmfs X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sbin/mdmfs X-SVN-Commit-Revision: 354236 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.29 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, 01 Nov 2019 03:10:53 -0000 Author: kevans Date: Fri Nov 1 03:10:53 2019 New Revision: 354236 URL: https://svnweb.freebsd.org/changeset/base/354236 Log: mdmfs(8): add -k skel option to populate fs from a skeleton mdmfs(8) lacks the ability to populate throwaway memory filesystems from an existing directory. This features permits an interesting setup where /var for instance lives on a device where wear-leveling is something you want to avoid as much as possible and nonetheless you don't want to lose your logs, ports metadata, etc. Here are the steps: 1. Copy /var to /var.bak; 2. Mount an mfs into /var using -k /var.bak at startup; 3. Synchronize /var to /var.bak weekly and on shutdown. Note that this more or less mimics OpenBSD's mount_mfs(8) -P flag. PR: 146254 Submitted by: jlh (many moons ago) MFC after: 1 week Modified: head/sbin/mdmfs/mdmfs.8 head/sbin/mdmfs/mdmfs.c Modified: head/sbin/mdmfs/mdmfs.8 ============================================================================== --- head/sbin/mdmfs/mdmfs.8 Fri Nov 1 02:55:58 2019 (r354235) +++ head/sbin/mdmfs/mdmfs.8 Fri Nov 1 03:10:53 2019 (r354236) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 9, 2017 +.Dd October 31, 2019 .Dt MDMFS 8 .Os .Sh NAME @@ -48,6 +48,7 @@ filesystem .Op Fl F Ar file .Op Fl f Ar frag-size .Op Fl i Ar bytes +.Op Fl k Ar skel .Op Fl m Ar percent-free .Op Fl O Ar optimization .Op Fl o Ar mount-options @@ -193,6 +194,11 @@ memory disk backed by The fragment size of the file system in bytes. .It Fl i Ar bytes Number of bytes per inode. +.It Fl k Ar skel +Copy the content of directory +.Ar skel +into +.Ar mount-point . .It Fl l Enable multilabel MAC on the new file system. .It Fl L Modified: head/sbin/mdmfs/mdmfs.c ============================================================================== --- head/sbin/mdmfs/mdmfs.c Fri Nov 1 02:55:58 2019 (r354235) +++ head/sbin/mdmfs/mdmfs.c Fri Nov 1 03:10:53 2019 (r354236) @@ -88,6 +88,7 @@ static void do_mount_md(const char *, const char *); static void do_mount_tmpfs(const char *, const char *); static void do_mtptsetup(const char *, struct mtpt_info *); static void do_newfs(const char *); +static void do_copy(const char *, const char *); static void extract_ugid(const char *, struct mtpt_info *); static int run(int *, const char *, ...) __printflike(2, 3); static const char *run_exitstr(int); @@ -104,7 +105,7 @@ main(int argc, char **argv) enum md_types mdtype; /* The type of our memory disk. */ bool have_mdtype, mlmac; bool detach, softdep, autounit, newfs; - const char *mtpoint, *size_arg, *unitstr; + const char *mtpoint, *size_arg, *skel, *unitstr; char *p; int ch, idx; void *set; @@ -118,6 +119,7 @@ main(int argc, char **argv) mlmac = false; newfs = true; have_mdtype = false; + skel = NULL; mdtype = MD_SWAP; mdname = MD_NAME; mdnamelen = strlen(mdname); @@ -142,7 +144,7 @@ main(int argc, char **argv) } while ((ch = getopt(argc, argv, - "a:b:Cc:Dd:E:e:F:f:hi:LlMm:NnO:o:Pp:Ss:tT:Uv:w:X")) != -1) + "a:b:Cc:Dd:E:e:F:f:hi:k:LlMm:NnO:o:Pp:Ss:tT:Uv:w:X")) != -1) switch (ch) { case 'a': argappend(&newfs_arg, "-a %s", optarg); @@ -184,6 +186,9 @@ main(int argc, char **argv) case 'i': argappend(&newfs_arg, "-i %s", optarg); break; + case 'k': + skel = optarg; + break; case 'L': loudsubs = true; break; @@ -359,6 +364,8 @@ main(int argc, char **argv) } do_mtptsetup(mtpoint, &mi); + if (skel != NULL) + do_copy(mtpoint, skel); return (0); } @@ -615,7 +622,24 @@ do_newfs(const char *args) run_exitnumber(rv)); } + /* + * Copy skel into the mountpoint. + */ +static void +do_copy(const char *mtpoint, const char *skel) +{ + int rv; + + rv = chdir(skel); + if (rv != 0) + err(1, "chdir to %s", skel); + rv = run(NULL, "/bin/pax -rw -pe . %s", mtpoint); + if (rv != 0) + errx(1, "skel copy failed"); +} + +/* * 'str' should be a user and group name similar to the last argument * to chown(1); i.e., a user, followed by a colon, followed by a * group. The user and group in 'str' may be either a [ug]id or a @@ -822,8 +846,8 @@ usage(void) fprintf(stderr, "usage: %s [-DLlMNnPStUX] [-a maxcontig] [-b block-size]\n" "\t[-c blocks-per-cylinder-group][-d max-extent-size] [-E path-mdconfig]\n" -"\t[-e maxbpg] [-F file] [-f frag-size] [-i bytes] [-m percent-free]\n" -"\t[-O optimization] [-o mount-options]\n" +"\t[-e maxbpg] [-F file] [-f frag-size] [-i bytes] [-k skel]\n" +"\t[-m percent-free] [-O optimization] [-o mount-options]\n" "\t[-p permissions] [-s size] [-v version] [-w user:group]\n" "\tmd-device mount-point\n", getprogname()); exit(1);