From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH] mkfs: validate extent size hint parameters
Date: Fri, 15 Feb 2019 16:39:23 -0800 [thread overview]
Message-ID: <20190216003923.GV32253@magnolia> (raw)
From: Darrick J. Wong <darrick.wong@oracle.com>
Validate extent and cow extent size hints that are passed to mkfs so
that we avoid formatting a filesystem that will never mount.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
mkfs/xfs_mkfs.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 46fd7c25..28d91253 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2222,6 +2222,66 @@ validate_rtextsize(
ASSERT(cfg->rtextblocks);
}
+/* Validate the incoming extsize hint as if we were a file. */
+static void
+validate_extsize_hint(
+ struct xfs_mount *mp,
+ struct cli_params *cli)
+{
+ xfs_failaddr_t fa;
+ bool rt;
+ uint16_t flags = 0;
+
+ rt = (cli->fsx.fsx_xflags & XFS_DIFLAG_RTINHERIT);
+
+ if (cli->fsx.fsx_xflags & XFS_DIFLAG_EXTSZINHERIT)
+ flags |= XFS_DIFLAG_EXTSIZE;
+
+ fa = libxfs_inode_validate_extsize(mp, cli->fsx.fsx_extsize, S_IFREG,
+ flags);
+ if (rt && fa == NULL)
+ fa = libxfs_inode_validate_extsize(mp, cli->fsx.fsx_extsize,
+ S_IFREG, flags | XFS_DIFLAG_REALTIME);
+ if (fa == NULL)
+ return;
+
+ if (rt && mp->m_sb.sb_rextsize > 1)
+ fprintf(stderr,
+ _("illegal extent size hint %lld, must be less than %u and a multiple of %u.\n"),
+ (long long)cli->fsx.fsx_extsize,
+ min(MAXEXTLEN, mp->m_sb.sb_agblocks / 2),
+ mp->m_sb.sb_rextsize);
+ else
+ fprintf(stderr,
+ _("illegal extent size hint %lld, must be less than %u.\n"),
+ (long long)cli->fsx.fsx_extsize,
+ min(MAXEXTLEN, mp->m_sb.sb_agblocks / 2));
+ usage();
+}
+
+/* Validate the incoming CoW extsize hint as if we were a file. */
+static void
+validate_cowextsize_hint(
+ struct xfs_mount *mp,
+ struct cli_params *cli)
+{
+ xfs_failaddr_t fa;
+ uint64_t flags2 = 0;
+
+ if (cli->fsx.fsx_xflags & FS_XFLAG_COWEXTSIZE)
+ flags2 |= XFS_DIFLAG2_COWEXTSIZE;
+ fa = libxfs_inode_validate_cowextsize(mp, cli->fsx.fsx_cowextsize,
+ S_IFREG, 0, flags2);
+ if (fa == NULL)
+ return;
+
+ fprintf(stderr,
+_("illegal CoW extent size hint %lld, must be less than %u.\n"),
+ (long long)cli->fsx.fsx_cowextsize,
+ min(MAXEXTLEN, mp->m_sb.sb_agblocks / 2));
+ usage();
+}
+
/*
* Validate the configured stripe geometry, or is none is specified, pull
* the configuration from the underlying device.
@@ -3982,6 +4042,10 @@ main(
finish_superblock_setup(&cfg, mp, sbp);
+ /* Validate the extent size hints now that @mp is fully set up. */
+ validate_extsize_hint(mp, &cli);
+ validate_cowextsize_hint(mp, &cli);
+
/* Print the intended geometry of the fs. */
if (!quiet || dry_run) {
struct xfs_fsop_geom geo;
next reply other threads:[~2019-02-16 0:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-16 0:39 Darrick J. Wong [this message]
2019-02-16 0:41 ` [PATCH] xfs: test mkfs extent size hint validation Darrick J. Wong
2019-02-17 22:07 ` Dave Chinner
2019-02-18 18:03 ` Darrick J. Wong
2019-02-18 21:17 ` Dave Chinner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190216003923.GV32253@magnolia \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox