xfsprogs: Enable extent forcealign feature
cover xfsprogs: Enable extent forcealign feature
This series enables a new feature to always honour the extent size hint.
It is required for atomic writes support.
It is possible to enable this feature at mkfs time or by changing the attribute of regular file or directory. For extszhint, it is inherited by descenent files/directories.
Associated kernel atomic writes patches to follow. We are sending this support now so that people can try out the kernel support. More testing is required.
Based on origin/for-next_2023-09-25
Darrick J. Wong (7):
xfs: create a new inode flag to require extsize alignment of file data
space
xfs: allow files to require data mappings to be aligned to extszhint
xfs_db: expose force_align feature and flags
xfs_io: implement lsattr and chattr support for forcealign
xfs_repair: check the force-align flag
mkfs: add an extsize= option that allows units
mkfs: enable the new force-align feature
db/inode.c | 3 + db/sb.c | 2 + include/linux.h | 5 + include/xfs_inode.h | 5 + include/xfs_mount.h | 2 + io/attr.c | 5 +- libxfs/util.c | 2 + libxfs/xfs_bmap.c | 26 ++++- libxfs/xfs_format.h | 9 +- libxfs/xfs_inode_buf.c | 40 ++++++++ libxfs/xfs_inode_buf.h | 3 + libxfs/xfs_sb.c | 3 + man/man2/ioctl_xfs_fsgetxattr.2 | 6 ++ man/man8/mkfs.xfs.8.in | 29 ++++++ mkfs/xfs_mkfs.c | 175 ++++++++++++++++++++++++++++++-- repair/dinode.c | 66 ++++++++++++ 16 files changed, 367 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/7 xfs: create a new inode flag to require extsize alignment of file data space
From: "Darrick J. Wong" <[email protected]>
Add a new inode flag to require that all file data extent mappings must be aligned (both the file offset range and the allocated space itself) to the extent size hint. Having a separate COW extent size hint is no longer allowed.
The goal here is to enable sysadmins and users to mandate that all space mappings in a file must have a startoff/blockcount that are aligned to (say) a 2MB alignment and that the startblock/blockcount will follow the same alignment.
--- include/linux.h | 5 +++++ include/xfs_inode.h | 5 +++++ include/xfs_mount.h | 2 ++ libxfs/util.c | 2 ++ libxfs/xfs_format.h | 6 +++++- libxfs/xfs_inode_buf.c | 40 ++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_inode_buf.h | 3 +++ libxfs/xfs_sb.c | 3 +++ 8 files changed, 65 insertions(+), 1 deletion(-)
include/linux.h +5 -0
@@ -251,6 +251,11 @@ struct fsxattr {#define FS_XFLAG_COWEXTSIZE 0x00010000/* CoW extent size allocator hint */ #endif +/* data extent mappings for regular files must be aligned to extent size hint */ +#ifndef FS_XFLAG_FORCEALIGN +#define FS_XFLAG_FORCEALIGN 0x00020000 +#endif +/* * Reminder: anything added to this file will be compiled into downstream * userspace projects!
include/xfs_inode.h +5 -0
@@ -233,6 +233,11 @@ static inline bool xfs_inode_has_large_extent_counts(struct xfs_inode *ip)return ip->i_diflags2 &XFS_DIFLAG2_NREXT64 ; } +static inline bool xfs_inode_forcealign (struct xfs_inode *ip) +{ +return ip->i_diflags2 &XFS_DIFLAG2_FORCEALIGN ; +} +/* Always set the child's GID to this value, even if the parent is setgid. */ #define CRED_FORCE_GID (1U << 0)struct cred {
include/xfs_mount.h +2 -0
@@ -166,6 +166,7 @@ typedef struct xfs_mount {#define XFS_FEAT_BIGTIME (1ULL << 24)/* large timestamps */ #define XFS_FEAT_NEEDSREPAIR (1ULL << 25)/* needs xfs_repair */ #define XFS_FEAT_NREXT64 (1ULL << 26)/* large extent counters */ +#define XFS_FEAT_FORCEALIGN (1ULL << 27)/* aligned file data extents */ #define __XFS_HAS_FEAT (name,NAME ) \ static inline bool xfs_has_ ## name (struct xfs_mount *mp) \
@@ -210,6 +211,7 @@ __XFS_HAS_FEAT(inobtcounts, INOBTCNT) __XFS_HAS_FEAT(bigtime, BIGTIME) __XFS_HAS_FEAT(needsrepair, NEEDSREPAIR) __XFS_HAS_FEAT(large_extent_counts, NREXT64) +__XFS_HAS_FEAT (forcealign,FORCEALIGN ) /* Kernel mount features that we don't support */#define __XFS_UNSUPP_FEAT (name) \
libxfs/util.c +2 -0
@@ -206,6 +206,8 @@ xfs_flags2diflags2( di_flags2 |=XFS_DIFLAG2_DAX ;if (xflags &FS_XFLAG_COWEXTSIZE ) di_flags2 |=XFS_DIFLAG2_COWEXTSIZE ; +if (xflags &FS_XFLAG_FORCEALIGN ) + di_flags2 |=XFS_DIFLAG2_FORCEALIGN ;return di_flags2; }
libxfs/xfs_format.h +5 -1
@@ -353,6 +353,7 @@ xfs_sb_has_compat_feature(#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ #define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ +#define XFS_SB_FEAT_RO_COMPAT_FORCEALIGN (1 << 30)/* aligned file data extents */ #define XFS_SB_FEAT_RO_COMPAT_ALL \ (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
@@ -1069,16 +1070,19 @@ static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)#define XFS_DIFLAG2_COWEXTSIZE_BIT 2/* copy on write extent size hint */ #define XFS_DIFLAG2_BIGTIME_BIT 3/* big timestamps */ #define XFS_DIFLAG2_NREXT64_BIT 4/* large extent counters */ +/* data extent mappings for regular files must be aligned to extent size hint */ +#define XFS_DIFLAG2_FORCEALIGN_BIT 5#define XFS_DIFLAG2_DAX (1 << XFS_DIFLAG2_DAX_BIT)#define XFS_DIFLAG2_REFLINK (1 << XFS_DIFLAG2_REFLINK_BIT)#define XFS_DIFLAG2_COWEXTSIZE (1 << XFS_DIFLAG2_COWEXTSIZE_BIT)#define XFS_DIFLAG2_BIGTIME (1 << XFS_DIFLAG2_BIGTIME_BIT)#define XFS_DIFLAG2_NREXT64 (1 << XFS_DIFLAG2_NREXT64_BIT) +#define XFS_DIFLAG2_FORCEALIGN (1 << XFS_DIFLAG2_FORCEALIGN_BIT)#define XFS_DIFLAG2_ANY \ (XFS_DIFLAG2_DAX | XFS_DIFLAG2_REFLINK | XFS_DIFLAG2_COWEXTSIZE | \ - XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64) + XFS_DIFLAG2_BIGTIME | XFS_DIFLAG2_NREXT64 | XFS_DIFLAG2_FORCEALIGN)static inline bool xfs_dinode_has_bigtime (const struct xfs_dinode *dip) {
libxfs/xfs_inode_buf.c +40 -0
@@ -601,6 +601,14 @@ xfs_dinode_verify( !xfs_has_bigtime(mp))return __this_address; +if (flags2 &XFS_DIFLAG2_FORCEALIGN ) { + fa =xfs_inode_validate_forcealign (mp, mode, flags, +be32_to_cpu (dip->di_extsize), +be32_to_cpu (dip->di_cowextsize)); +if (fa) +return fa; + } +return NULL ; }
@@ -768,3 +776,35 @@ xfs_inode_validate_cowextsize(return NULL ; } + +/* Validate the forcealign inode flag */ +xfs_failaddr_t +xfs_inode_validate_forcealign ( +struct xfs_mount *mp, +uint16_t mode, +uint16_t flags, +uint32_t extsize, +uint32_t cowextsize) +{ +/* superblock rocompat feature flag */ +if (!xfs_has_forcealign (mp)) +return __this_address; + +/* Only regular files and directories */ +if (!S_ISDIR (mode) && !S_ISREG (mode)) +return __this_address; + +/* Doesn't apply to realtime files */ +if (flags &XFS_DIFLAG_REALTIME ) +return __this_address; + +/* Requires a nonzero extent size hint */ +if (extsize ==0 ) +return __this_address; + +/* Requires no cow extent size hint */ +if (cowextsize !=0 ) +return __this_address; + +return NULL ; +}
libxfs/xfs_inode_buf.h +3 -0
@@ -33,6 +33,9 @@ xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp,xfs_failaddr_t xfs_inode_validate_cowextsize (struct xfs_mount *mp,uint32_t cowextsize,uint16_t mode,uint16_t flags,uint64_t flags2); +xfs_failaddr_t xfs_inode_validate_forcealign (struct xfs_mount *mp, +uint16_t mode,uint16_t flags,uint32_t extsize, +uint32_t cowextsize);static inline uint64_t xfs_inode_encode_bigtime (struct timespec64 tv) {
libxfs/xfs_sb.c +3 -0
@@ -160,6 +160,9 @@ xfs_sb_version_to_features( features |=XFS_FEAT_REFLINK ;if (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_INOBTCNT ) features |=XFS_FEAT_INOBTCNT ; +if (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_FORCEALIGN ) + features |=XFS_FEAT_FORCEALIGN ; +if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_FTYPE ) features |=XFS_FEAT_FTYPE ;if (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_SPINODES )
Signature · 1 line
2.34.1
PATCH 2/7 xfs: allow files to require data mappings to be aligned to extszhint
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Add a new inode flag to require that all file data extent mappings must be aligned (both the file offset range and the allocated space itself) to the extent size hint. Having a separate COW extent size hint is no longer allowed.
--- libxfs/xfs_bmap.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
libxfs/xfs_bmap.c +21 -5
@@ -3321,6 +3321,19 @@ xfs_bmap_compute_alignments( align =xfs_get_cowextsz_hint (ap->ip); else if (ap->datatype & XFS_ALLOC_USERDATA) align =xfs_get_extsz_hint (ap->ip); + +/* +* xfs_get_cowextsz_hint() returns extsz_hint for when forcealign is +* set as forcealign and cowextsz_hint are mutually exclusive +*/ +if (xfs_inode_forcealign (ap->ip) && align) { + args->alignment = align; +if (stripe_align % align) + stripe_align = align; + }else { + args->alignment =1 ; + } +if (align) { if (xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, align, 0, ap->eof, 0, ap->conv, &ap->offset,
@@ -3416,7 +3429,6 @@ xfs_bmap_exact_minlen_extent_alloc( args.minlen = args.maxlen = ap->minlen; args.total = ap->total; - args.alignment =1 ; args.minalignslop =0 ; args.minleft = ap->minleft;
@@ -3462,6 +3474,7 @@ xfs_bmap_btalloc_at_eof( {struct xfs_mount *mp = args->mp;struct xfs_perag *caller_pag = args->pag; +int orig_alignment = args->alignment;int error;/*
@@ -3536,10 +3549,10 @@ xfs_bmap_btalloc_at_eof(/* * Allocation failed, so turn return the allocation args to their -* original non-aligned state so the caller can proceed on allocation -* failure as if this function was never called. +* original state so the caller can proceed on allocation failure as +* if this function was never called. */ - args->alignment =1 ; + args->alignment = orig_alignment;return 0 ; }
@@ -3562,6 +3575,10 @@ xfs_bmap_btalloc_low_space( {int error; +/* The allocator doesn't honour args->alignment */ +if (args->alignment >1 ) +return 0 ; +if (args->minlen > ap->minlen) { args->minlen = ap->minlen; error =xfs_alloc_vextent_start_ag (args, ap->blkno);
@@ -3683,7 +3700,6 @@ xfs_bmap_btalloc( .wasdel = ap->wasdel, .resv = XFS_AG_RESV_NONE, .datatype = ap->datatype, - .alignment = 1, .minalignslop = 0, };xfs_fileoff_t orig_offset;
Signature · 1 line
2.34.1
PATCH 3/7 xfs_db: expose force_align feature and flags
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Expose the superblock feature and inode flags.
--- db/inode.c | 3 +++ db/sb.c | 2 ++ 2 files changed, 5 insertions(+)
db/inode.c +3 -0
@@ -207,6 +207,9 @@ const field_t inode_v3_flds[] = { {"nrext64" ,FLDT_UINT1 ,OI (COFF (flags2) +bitsz (uint64_t) -XFS_DIFLAG2_NREXT64_BIT -1 ),C1 , 0, TYP_NONE }, + { "forcealign", FLDT_UINT1, +OI (COFF (flags2) +bitsz (uint64_t) -XFS_DIFLAG2_FORCEALIGN_BIT -1 ),C1 , + 0, TYP_NONE }, { NULL } };
db/sb.c +2 -0
@@ -706,6 +706,8 @@ version_string(strcat (s,",NEEDSREPAIR" );if (xfs_has_large_extent_counts (mp))strcat (s,",NREXT64" ); +if (xfs_has_forcealign (mp)) +strcat (s,",FORCEALIGN" );return s; }
Signature · 1 line
2.34.1
PATCH 4/7 xfs_io: implement lsattr and chattr support for forcealign
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Make it so that we can adjust the forcealign flag at runtime.
--- io/attr.c | 5 ++++- man/man2/ioctl_xfs_fsgetxattr.2 | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
io/attr.c +4 -1
@@ -38,9 +38,10 @@ static struct xflags { { FS_XFLAG_DAX, "x", "dax" }, { FS_XFLAG_COWEXTSIZE, "C", "cowextsize" }, { FS_XFLAG_HASATTR, "X", "has-xattr" }, + { FS_XFLAG_FORCEALIGN, "F", "force-align" }, { 0, NULL, NULL } }; -#define CHATTR_XFLAG_LIST "r"/*p*/ "iasAdtPneEfSxC" /*X*/ +#define CHATTR_XFLAG_LIST "r"/*p*/ "iasAdtPneEfSxC" /*X*/ "F" static void lsattr_help(void)
@@ -67,6 +68,7 @@ lsattr_help(void)" x -- Use direct access (DAX) for data in this file\n" " C -- for files with shared blocks, observe the inode CoW extent size value\n" " X -- file has extended attributes (cannot be changed using chattr)\n" +" F -- data extent mappings must be aligned to extent size hint\n" "\n" " Options:\n" " -R -- recursively descend (useful when current file is a directory)\n"
@@ -104,6 +106,7 @@ chattr_help(void)" +/-S -- set/clear the filestreams allocator flag\n" " +/-x -- set/clear the direct access (DAX) flag\n" " +/-C -- set/clear the CoW extent-size flag\n" +" +/-F -- set/clear the forcealign flag\n" " Note1: user must have certain capabilities to modify immutable/append-only.\n" " Note2: immutable/append-only files cannot be deleted; removing these files\n" " requires the immutable/append-only flag to be cleared first.\n"
man/man2/ioctl_xfs_fsgetxattr.2 +6 -0
@@ -200,6 +200,12 @@ below). If set on a directory, new files and subdirectories created in the directory will have both the flag and the CoW extent size value set. .TP +.B XFS_XFLAG_FORCEALIGN +Force Alignment bit - requires that all file data extents must be aligned +to the extent size hint value. +If set on a directory, new files and subdirectories created in the directory +will have the flag set. +.TP .B XFS_XFLAG_HASATTR The file has extended attributes associated with it.
Signature · 1 line
2.34.1
PATCH 5/7 xfs_repair: check the force-align flag
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Make sure the flag isn't set incorrectly.
--- repair/dinode.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
repair/dinode.c +66 -0
@@ -2262,6 +2262,69 @@ _("Bad extent size hint %u on inode %" PRIu64 ", "), } } +static void +validate_forcealign ( +struct xfs_mount *mp, +struct xfs_dinode *dino, +xfs_ino_t lino, +int *dirty) +{ +uint16_t mode; +uint16_t flags; +uint64_t flags2; + + mode =be16_to_cpu (dino->di_mode); + flags =be16_to_cpu (dino->di_flags); + flags2 =be64_to_cpu (dino->di_flags2); + +if (!(flags2 &XFS_DIFLAG2_FORCEALIGN )) +return ; + +if (!xfs_has_forcealign (mp)) { +do_warn ( +_ ("Filesystem does not support forcealign flag set on inode %" PRIu64", " ), + lino); + goto zap; + } + +if (!S_ISDIR (mode) && !S_ISREG (mode)) { +do_warn ( +_ ("Cannot have forcealign inode flag set on non-dir non-regular file inode %" PRIu64"\n" ), + lino); + goto zap; + } + +if (flags &XFS_DIFLAG_REALTIME ) { +do_warn ( +_ ("Cannot have forcealign inode flag set on realtime inode %" PRIu64"\n" ), + lino); + goto zap; + } + +if (dino->di_extsize ==0 ) { +do_warn ( +_ ("Cannot have forcealign inode flag set without an extent size hint on inode %" PRIu64"\n" ), + lino); + goto zap; + } + +if (dino->di_cowextsize !=0 ) { +do_warn ( +_ ("Cannot have forcealign inode flag set with nonzero CoW extent size hint on inode %" PRIu64"\n" ), + lino); + goto zap; + } + +return ; +zap: +if (!no_modify) { +do_warn (_ ("clearing flag\n" )); + dino->di_flags2 &= ~cpu_to_be64 (XFS_DIFLAG2_FORCEALIGN ); + *dirty =1 ; + }else +do_warn (_ ("would clear flag\n" )); +} +/* * returns 0 if the inode is ok, 1 if the inode is corrupt * check_dups can be set to 1 *only* when called by the
@@ -2833,6 +2896,9 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "),do_warn (_ ("would reset to zero\n" )); } +if (dino->di_version >=3 ) +validate_forcealign (mp, dino, lino, dirty); +/* nsec fields cannot be larger than 1 billion */ check_nsec ("atime" , lino, dino, &dino->di_atime, dirty);check_nsec ("mtime" , lino, dino, &dino->di_mtime, dirty);
Signature · 1 line
2.34.1
PATCH 6/7 mkfs: add an extsize= option that allows units
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Add a new mkfs option that allows the user to specify an extent size hint with units. This removes the need to specify the option in filesystem block size, which eases the computation requirements in deployment scripts.
# mkfs.xfs -d extsize=2m /dev/sda
--- man/man8/mkfs.xfs.8.in | 15 +++++++++++++ mkfs/xfs_mkfs.c | 48 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-)
man/man8/mkfs.xfs.8.in +15 -0
@@ -482,6 +482,18 @@ will be assigned the project quota id provided in Directories will pass on the project id to newly created regular files and directories. .TP +.BI extsize= num +All inodes created by +.B mkfs.xfs +will have this +.I value +extent size hint applied. +Directories will pass on this hint to newly created regular files and +directories. +This option cannot be combined with the +.B extszinherit +option. +.TP .BI extszinherit= value All inodes created by .B mkfs.xfs
@@ -491,6 +503,9 @@ extent size hint applied. The value must be provided in units of filesystem blocks. Directories will pass on this hint to newly created regular files and directories. +This option cannot be combined with the +.B extsize +option. .TP .BI daxinherit= value If
mkfs/xfs_mkfs.c +46 -2
97 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 7/7 mkfs: enable the new force-align feature
In reply to John GarryFrom: "Darrick J. Wong" <[email protected]>
Make it so that we can create filesystems with the forcealign feature turned on.
#jpg: set .forcealign = true in SB
--- libxfs/xfs_format.h | 3 +- man/man8/mkfs.xfs.8.in | 14 +++++ mkfs/xfs_mkfs.c | 127 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 139 insertions(+), 5 deletions(-)
libxfs/xfs_format.h +2 -1
@@ -358,7 +358,8 @@ xfs_sb_has_compat_feature( (XFS_SB_FEAT_RO_COMPAT_FINOBT | \XFS_SB_FEAT_RO_COMPAT_RMAPBT | \XFS_SB_FEAT_RO_COMPAT_REFLINK | \ - XFS_SB_FEAT_RO_COMPAT_INOBTCNT) +XFS_SB_FEAT_RO_COMPAT_INOBTCNT | \ + XFS_SB_FEAT_RO_COMPAT_FORCEALIGN)#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALLstatic inline bool xfs_sb_has_ro_compat_feature(
man/man8/mkfs.xfs.8.in +14 -0
@@ -657,6 +657,20 @@ Extend maximum values of inode data and attr fork extent counters from 2^31 - omitted, 1 is assumed. This feature is disabled by default. This feature is only available for filesystems formatted with -m crc=1. .TP +.BI forcealign[= value] +If +.B value +is 1, mark the root directory so that all file data extent allocations will be +aligned to the extent size hint. +These allocations will be mapped into the file range at offsets that are +aligned to the extent size hint. +The +.B extszinherit +option must be specified. +The +.B cowextsize +option must not be specified. +This feature is only available for filesystems formatted with -m crc=1. .RE .PP .PD 0
mkfs/xfs_mkfs.c +123 -4
215 lines not on this page · raw message
Signature · 1 line
2.34.1