From nobody Thu Nov 11 20:44:13 2021 X-Original-To: dev-commits-src-branches@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 CD14E184F1A2; Thu, 11 Nov 2021 20:44:13 +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 4Hqtx95Qg0z4xY1; Thu, 11 Nov 2021 20:44:13 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 9AB9D12BEC; Thu, 11 Nov 2021 20:44:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1ABKiDKT057136; Thu, 11 Nov 2021 20:44:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1ABKiDLP057135; Thu, 11 Nov 2021 20:44:13 GMT (envelope-from git) Date: Thu, 11 Nov 2021 20:44:13 GMT Message-Id: <202111112044.1ABKiDLP057135@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 6b94990f7019 - stable/12 - Allocate extra inodes in makefs when leaving free space in UFS images. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 6b94990f701982d8469a6915fa94e234005090f5 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=6b94990f701982d8469a6915fa94e234005090f5 commit 6b94990f701982d8469a6915fa94e234005090f5 Author: Nathan Whitehorn AuthorDate: 2021-04-06 17:43:29 +0000 Commit: Ed Maste CommitDate: 2021-11-11 20:01:27 +0000 Allocate extra inodes in makefs when leaving free space in UFS images. By default, makefs(8) has very few spare inodes in its output images, which is fine for static filesystems, but not so great for VM images where many more files will be added. Make makefs(8) use the same default settings as newfs(8) when creating images with free space -- there isn't much point to leaving free space on the image if you can't put files there. If no free space is requested, use current behavior of a minimal number of available inodes. Reviewed by: manu MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D29492 (cherry picked from commit afb6a168f8ee08ac74769464726c396fbef83d0b) --- usr.sbin/makefs/ffs.c | 8 +++++++- usr.sbin/makefs/ffs.h | 2 ++ usr.sbin/makefs/ffs/mkfs.c | 18 +++++++++++++++++- usr.sbin/makefs/makefs.8 | 5 ++++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/usr.sbin/makefs/ffs.c b/usr.sbin/makefs/ffs.c index 99b5ba06159d..7a4c31c7dbda 100644 --- a/usr.sbin/makefs/ffs.c +++ b/usr.sbin/makefs/ffs.c @@ -190,6 +190,7 @@ ffs_prep_opts(fsinfo_t *fsopts) ffs_opts->fsize= -1; ffs_opts->cpg= -1; ffs_opts->density= -1; + ffs_opts->min_inodes= false; ffs_opts->minfree= -1; ffs_opts->optimization= -1; ffs_opts->maxcontig= -1; @@ -266,6 +267,11 @@ ffs_makefs(const char *image, const char *dir, fsnode *root, fsinfo_t *fsopts) printf("ffs_makefs: image %s directory %s root %p\n", image, dir, root); + /* if user wants no free space, use minimum number of inodes */ + if (fsopts->minsize == 0 && fsopts->freeblockpc == 0 && + fsopts->freeblocks == 0) + ((ffs_opt_t *)fsopts->fs_specific)->min_inodes = true; + /* validate tree and options */ TIMER_START(start); ffs_validate(dir, root, fsopts); @@ -424,7 +430,7 @@ ffs_validate(const char *dir, fsnode *root, fsinfo_t *fsopts) if (fsopts->roundup > 0) fsopts->size = roundup(fsopts->size, fsopts->roundup); - /* calculate density if necessary */ + /* calculate density to just fit inodes if no free space */ if (ffs_opts->density == -1) ffs_opts->density = fsopts->size / fsopts->inodes + 1; diff --git a/usr.sbin/makefs/ffs.h b/usr.sbin/makefs/ffs.h index 8b4fbc33dc83..e1dda429ff26 100644 --- a/usr.sbin/makefs/ffs.h +++ b/usr.sbin/makefs/ffs.h @@ -44,6 +44,7 @@ #include #include +#include typedef struct { char label[MAXVOLLEN]; /* volume name/label */ @@ -52,6 +53,7 @@ typedef struct { int cpg; /* cylinders per group */ int cpgflg; /* cpg was specified by user */ int density; /* bytes per inode */ + bool min_inodes; /* allocate minimum number of inodes */ int ntracks; /* number of tracks */ int nsectors; /* number of sectors */ int rpm; /* rpm */ diff --git a/usr.sbin/makefs/ffs/mkfs.c b/usr.sbin/makefs/ffs/mkfs.c index 0c8447150f0e..572a19a44f02 100644 --- a/usr.sbin/makefs/ffs/mkfs.c +++ b/usr.sbin/makefs/ffs/mkfs.c @@ -117,10 +117,13 @@ static int avgfpdir; /* expected number of files per directory */ struct fs * ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) { - int fragsperinode, optimalfpg, origdensity, minfpg, lastminfpg; + int fragsperinode, optimalfpg, origdensity, mindensity; + int minfpg, lastminfpg; int32_t csfrags; uint32_t i, cylno; long long sizepb; + ino_t maxinum; + int minfragsperinode; /* minimum ratio of frags to inodes */ void *space; int size; int nprintcols, printcolwidth; @@ -311,7 +314,20 @@ ffs_mkfs(const char *fsys, const fsinfo_t *fsopts, time_t tstamp) * can put into each cylinder group. If this is too big, we reduce * the density until it fits. */ + maxinum = (((int64_t)(1)) << 32) - INOPB(&sblock); + minfragsperinode = 1 + fssize / maxinum; + mindensity = minfragsperinode * fsize; + if (density == 0) + density = MAX(2, minfragsperinode) * fsize; + if (density < mindensity) { + origdensity = density; + density = mindensity; + fprintf(stderr, "density increased from %d to %d\n", + origdensity, density); + } origdensity = density; + if (!ffs_opts->min_inodes) + density = MIN(density, MAX(2, minfragsperinode) * fsize); for (;;) { fragsperinode = MAX(numfrags(&sblock, density), 1); minfpg = fragsperinode * INOPB(&sblock); diff --git a/usr.sbin/makefs/makefs.8 b/usr.sbin/makefs/makefs.8 index 8c4fbcb7b322..4a4c69b06946 100644 --- a/usr.sbin/makefs/makefs.8 +++ b/usr.sbin/makefs/makefs.8 @@ -312,7 +312,10 @@ Expected number of files per directory. .It Sy bsize Block size. .It Sy density -Bytes per inode. +Bytes per inode. If unset, will allocate the minimum number of inodes to +represent the filesystem if no free space has been requested (free blocks +or minimum size set); otherwise the larger of the newfs defaults or what +is required by the free inode parameters if set. .It Sy fsize Fragment size. .It Sy label