File xfsprogs-mkfs-validate-extent-size-hint-parameters.patch of Package xfsprogs.35286
From 9cfe71bae43451bf5cc6b6688b94c88336e1ea00 Mon Sep 17 00:00:00 2001
From: "Darrick J. Wong" <darrick.wong@oracle.com>
Date: Thu, 18 Apr 2019 13:19:39 -0500
Subject: [PATCH] mkfs: validate extent size hint parameters
Git-commit: 9cfe71bae43451bf5cc6b6688b94c88336e1ea00
Patch-mainline: v5.0.0-rc1
References: bsc#1138247
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>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
[sandeen: use DIFLAG macros for now to be consistent, fixed later]
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
Acked-by: Anthony Iliopoulos <ailiop@suse.com>
---
mkfs/xfs_mkfs.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 86 insertions(+), 1 deletion(-)
Index: xfsprogs-4.15.0/mkfs/xfs_mkfs.c
===================================================================
--- xfsprogs-4.15.0.orig/mkfs/xfs_mkfs.c
+++ xfsprogs-4.15.0/mkfs/xfs_mkfs.c
@@ -2208,6 +2208,85 @@ validate_rtextsize(
ASSERT(cfg->rtextblocks);
}
+/* Validate the incoming extsize hint. */
+static void
+validate_extsize_hint(
+ struct xfs_mount *mp,
+ struct cli_params *cli)
+{
+ xfs_failaddr_t fa;
+ uint16_t flags = 0;
+
+ /*
+ * First we validate the extent size inherit hint on a directory so
+ * that we know that we'll be propagating a correct hint and flag to
+ * new files on the data device.
+ */
+ if (cli->fsx.fsx_xflags & XFS_DIFLAG_EXTSZINHERIT)
+ flags |= XFS_DIFLAG_EXTSZINHERIT;
+
+ fa = libxfs_inode_validate_extsize(mp, cli->fsx.fsx_extsize, S_IFDIR,
+ flags);
+ if (fa) {
+ 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();
+ }
+
+ /*
+ * Now we do it again with a realtime file so that we know the hint and
+ * flag that get passed on to realtime files will be correct.
+ */
+ if (mp->m_sb.sb_rextsize == 0)
+ return;
+
+ flags = XFS_DIFLAG_REALTIME;
+ if (cli->fsx.fsx_xflags & XFS_DIFLAG_EXTSIZE)
+ flags |= XFS_DIFLAG_EXTSIZE;
+
+ fa = libxfs_inode_validate_extsize(mp, cli->fsx.fsx_extsize, S_IFREG,
+ flags);
+
+ if (fa) {
+ 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);
+ usage();
+ }
+}
+
+/* Validate the incoming CoW extsize hint. */
+static void
+validate_cowextsize_hint(
+ struct xfs_mount *mp,
+ struct cli_params *cli)
+{
+ xfs_failaddr_t fa;
+ uint64_t flags2 = 0;
+
+ /*
+ * Validate the copy on write extent size inherit hint on a directory
+ * so that we know that we'll be propagating a correct hint and flag to
+ * new files on the data device.
+ */
+ if (cli->fsx.fsx_xflags & FS_XFLAG_COWEXTSIZE)
+ flags2 |= XFS_DIFLAG2_COWEXTSIZE;
+
+ fa = libxfs_inode_validate_cowextsize(mp, cli->fsx.fsx_cowextsize,
+ S_IFDIR, 0, flags2);
+ if (fa) {
+ 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.
@@ -3973,12 +4052,18 @@ main(
*/
calculate_log_size(&cfg, &cli, mp);
+ 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) {
print_mkfs_cfg(&cfg, dfile, logfile, rtfile);
if (dry_run)
exit(0);
}
- finish_superblock_setup(&cfg, mp, sbp);
/*
* we need the libxfs buffer cache from here on in.