xfsprogs: Delay Ready Attributes
v16 cover xfsprogs: Delay Ready Attributes
Hi all,
This set applies the corresponding changes for delayed ready attributes to xfsprogs. I will pick up the reviews from the kernel side series and mirror them here. This set also includes some patches from the kernel side that have not yet been ported. This set also includes patches needed for the user space cli and log printing routines
Lastly, two patches ported from kernel side needed some minor modications to avoid compile errors:
xfsprogs: Introduce error injection to allocate only minlen size extents for files
Amended io/inject.c with error tag name to avoid compiler errors
xfsprogs: Introduce error injection to reduce maximum inode fork extent count
Amended io/inject.c with error tag name to avoid compiler errors
This series can also be viewed on github here:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v16
And also the extended delayed attribute and parent pointer series:
https://github.com/allisonhenderson/xfs_work/tree/delay_ready_attrs_xfsprogs_v16_extended
Thanks all!
Allison
Allison Henderson (11):
xfsprogs: Reverse apply 72b97ea40d
xfsprogs: Add xfs_attr_node_remove_cleanup
xfsprogs: Hoist xfs_attr_set_shortform
xfsprogs: Add helper xfs_attr_set_fmt
xfsprogs: Separate xfs_attr_node_addname and
xfs_attr_node_addname_clear_incomplete
xfsprogs: Add helper xfs_attr_node_addname_find_attr
xfsprogs: Hoist xfs_attr_node_addname
xfsprogs: Hoist xfs_attr_leaf_addname
xfsprogs: Hoist node transaction handling
xfsprogs: Add delay ready attr remove routines
xfsprogs: Add delay ready attr set routines
Chandan Babu R (15):
xfsprogs: Add helper for checking per-inode extent count overflow
xfsprogs: Check for extent overflow when trivally adding a new extent
xfsprogs: Check for extent overflow when punching a hole
xfsprogs: Check for extent overflow when adding dir entries
xfsprogs: Check for extent overflow when removing dir entries
xfsprogs: Check for extent overflow when renaming dir entries
xfsprogs: Check for extent overflow when adding/removing xattrs
xfsprogs: Check for extent overflow when writing to unwritten extent
xfsprogs: Check for extent overflow when moving extent from cow to
data fork
xfsprogs: Check for extent overflow when swapping extents
xfsprogs: Introduce error injection to reduce maximum inode fork
extent count
xfsprogs: Remove duplicate assert statement in xfs_bmap_btalloc()
xfsprogs: Compute bmap extent alignments in a separate function
xfsprogs: Process allocated extent in a separate function
xfsprogs: Introduce error injection to allocate only minlen size
extents for files
Darrick J. Wong (1):
xfsprogs: fix an ABBA deadlock in xfs_rename
Zorro Lang (1):
libxfs: expose inobtcount in xfs geometry
include/libxfs.h | 1 + include/xfs_trace.h | 1 - io/inject.c | 2 + libxfs/xfs_alloc.c | 50 +++ libxfs/xfs_alloc.h | 3 + libxfs/xfs_attr.c | 916 ++++++++++++++++++++++++++++------------------- libxfs/xfs_attr.h | 364 +++++++++++++++++++ libxfs/xfs_attr_leaf.c | 2 +- libxfs/xfs_attr_remote.c | 126 ++++--- libxfs/xfs_attr_remote.h | 7 +- libxfs/xfs_bmap.c | 285 +++++++++++---- libxfs/xfs_dir2.h | 2 - libxfs/xfs_dir2_sf.c | 2 +- libxfs/xfs_errortag.h | 6 +- libxfs/xfs_fs.h | 1 + libxfs/xfs_inode_fork.c | 27 ++ libxfs/xfs_inode_fork.h | 63 ++++ libxfs/xfs_sb.c | 2 + 18 files changed, 1374 insertions(+), 486 deletions(-)
Signature · 1 line
2.7.4
PATCH v16 1/28 xfsprogs: fix an ABBA deadlock in xfs_rename
From: "Darrick J. Wong" <[email protected]>
Source kernel commit: 6da1b4b1ab36d80a3994fd4811c8381de10af604
When overlayfs is running on top of xfs and the user unlinks a file in the overlay, overlayfs will create a whiteout inode and ask xfs to "rename" the whiteout file atop the one being unlinked. If the file being unlinked loses its one nlink, we then have to put the inode on the unlinked list.
This requires us to grab the AGI buffer of the whiteout inode to take it off the unlinked list (which is where whiteouts are created) and to grab the AGI buffer of the file being deleted. If the whiteout was created in a higher numbered AG than the file being deleted, we'll lock the AGIs in the wrong order and deadlock.
Therefore, grab all the AGI locks we think we'll need ahead of time, and in order of increasing AG number per the locking rules.
--- libxfs/xfs_dir2.h | 2 -- libxfs/xfs_dir2_sf.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-)
libxfs/xfs_dir2.h +0 -2
@@ -47,8 +47,6 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp,extern int xfs_dir_removename (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name,xfs_ino_t ino,xfs_extlen_t tot); -extern bool xfs_dir2_sf_replace_needblock (struct xfs_inode *dp, -xfs_ino_t inum);extern int xfs_dir_replace (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name,xfs_ino_t inum,xfs_extlen_t tot);
libxfs/xfs_dir2_sf.c +1 -1
@@ -1018,7 +1018,7 @@ xfs_dir2_sf_removename(/* * Check whether the sf dir replace operation need more blocks. */ -bool +static bool xfs_dir2_sf_replace_needblock (struct xfs_inode *dp,xfs_ino_t inum)
Signature · 1 line
2.7.4
PATCH v16 2/28 xfsprogs: Add helper for checking per-inode extent count overflow
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: b9b7e1dc56c5ca8d6fc37c410b054e9f26737d2e
XFS does not check for possible overflow of per-inode extent counter fields when adding extents to either data or attr fork.
For e.g.
1. Insert 5 million xattrs (each having a value size of 255 bytes) and then delete 50% of them in an alternating manner.
2. On a 4k block sized XFS filesystem instance, the above causes 98511 extents to be created in the attr fork of the inode.
xfsaild/loop0 2008 [003] 1475.127209: probe:xfs_inode_to_disk: (ffffffffa43fb6b0) if_nextents=98511 i_ino=131
3. The incore inode fork extent counter is a signed 32-bit quantity. However the on-disk extent counter is an unsigned 16-bit quantity and hence cannot hold 98511 extents.
4. The following incorrect value is stored in the attr extent counter, core.naextents = -32561
This commit adds a new helper function (i.e. xfs_iext_count_may_overflow()) to check for overflow of the per-inode data and xattr extent counters. Future patches will use this function to make sure that an FS operation won't cause the extent counter to overflow.
--- libxfs/xfs_inode_fork.c | 23 +++++++++++++++++++++++ libxfs/xfs_inode_fork.h | 2 ++ 2 files changed, 25 insertions(+)
libxfs/xfs_inode_fork.c +23 -0
@@ -21,6 +21,7 @@#include "xfs_da_btree.h" #include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" +#include "xfs_types.h" kmem_zone_t *xfs_ifork_zone;
@@ -726,3 +727,25 @@ xfs_ifork_verify_local_attr(return 0 ; } + +int +xfs_iext_count_may_overflow ( +struct xfs_inode *ip, +int whichfork, +int nr_to_add) +{ +struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +uint64_t max_exts; +uint64_t nr_exts; + +if (whichfork ==XFS_COW_FORK ) +return 0 ; + + max_exts = (whichfork ==XFS_ATTR_FORK ) ?MAXAEXTNUM :MAXEXTNUM ; + + nr_exts = ifp->if_nextents + nr_to_add; +if (nr_exts < ifp->if_nextents || nr_exts > max_exts) +return -EFBIG ; + +return 0 ; +}
libxfs/xfs_inode_fork.h +2 -0
@@ -172,5 +172,7 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip);int xfs_ifork_verify_local_data (struct xfs_inode *ip);int xfs_ifork_verify_local_attr (struct xfs_inode *ip); +int xfs_iext_count_may_overflow (struct xfs_inode *ip,int whichfork, +int nr_to_add);#endif /* __XFS_INODE_FORK_H__ */
Signature · 1 line
2.7.4
PATCH v16 3/28 xfsprogs: Check for extent overflow when trivally adding a new extent
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 727e1acd297cae15449607d6e2ee39c71216cf1a
When adding a new data extent (without modifying an inode's existing extents) the extent count increases only by 1. This commit checks for extent count overflow in such cases.
--- libxfs/xfs_bmap.c | 6 ++++++ libxfs/xfs_inode_fork.h | 6 ++++++ 2 files changed, 12 insertions(+)
libxfs/xfs_bmap.c +6 -0
@@ -4520,6 +4520,12 @@ xfs_bmapi_convert_delalloc(return error;xfs_ilock (ip,XFS_ILOCK_EXCL ); + + error =xfs_iext_count_may_overflow (ip, whichfork, +XFS_IEXT_ADD_NOSPLIT_CNT ); +if (error) + goto out_trans_cancel; +xfs_trans_ijoin (tp, ip,0 ); if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) ||
libxfs/xfs_inode_fork.h +6 -0
@@ -35,6 +35,12 @@ struct xfs_ifork {#define XFS_IFBROOT 0x04/* i_broot points to the bmap b-tree root */ /* +* Worst-case increase in the fork extent count when we're adding a single +* extent to a fork and there's no possibility of splitting an existing mapping. +*/ +#define XFS_IEXT_ADD_NOSPLIT_CNT (1) + +/* * Fork handling. */
Signature · 1 line
2.7.4
PATCH v16 4/28 xfsprogs: Check for extent overflow when punching a hole
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 85ef08b5a667615bc7be5058259753dc42a7adcd
The extent mapping the file offset at which a hole has to be inserted will be split into two extents causing extent count to increase by 1.
--- libxfs/xfs_inode_fork.h | 7 +++++++ 1 file changed, 7 insertions(+)
libxfs/xfs_inode_fork.h +7 -0
@@ -41,6 +41,13 @@ struct xfs_ifork {#define XFS_IEXT_ADD_NOSPLIT_CNT (1)/* +* Punching out an extent from the middle of an existing extent can cause the +* extent count to increase by 1. +* i.e. | Old extent | Hole | Old extent | +*/ +#define XFS_IEXT_PUNCH_HOLE_CNT (1) + +/* * Fork handling. */
Signature · 1 line
2.7.4
PATCH v16 5/28 xfsprogs: Check for extent overflow when adding dir entries
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: f5d92749191402c50e32ac83dd9da3b910f5680f
Directory entry addition can cause the following,
1. Data block can be added/removed.
A new extent can cause extent count to increase by 1.
2. Free disk block can be added/removed.
Same behaviour as described above for Data block.
3. Dabtree blocks.XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH.
--- libxfs/xfs_inode_fork.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
libxfs/xfs_inode_fork.h +13 -0
@@ -48,6 +48,19 @@ struct xfs_ifork {#define XFS_IEXT_PUNCH_HOLE_CNT (1)/* +* Directory entry addition can cause the following, +* 1. Data block can be added/removed. +* A new extent can cause extent count to increase by 1. +* 2. Free disk block can be added/removed. +* Same behaviour as described above for Data block. +* 3. Dabtree blocks. +* XFS_DA_NODE_MAXDEPTH blocks can be added. Each of these can be new +* extents. Hence extent count can increase by XFS_DA_NODE_MAXDEPTH. +*/ +#define XFS_IEXT_DIR_MANIP_CNT (mp) \ + ((XFS_DA_NODE_MAXDEPTH + 1 + 1) * (mp)->m_dir_geo->fsbcount) + +/* * Fork handling. */
Signature · 1 line
2.7.4
PATCH v16 6/28 xfsprogs: Check for extent overflow when removing dir entries
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 0dbc5cb1a91cc8c44b1c75429f5b9351837114fd
Directory entry removal must always succeed; Hence XFS does the following during low disk space scenario:
1. Data/Free blocks linger until a future remove operation.
2. Dabtree blocks would be swapped with the last block in the leaf space and then the new last block will be unmapped.
This facility is reused during low inode extent count scenario i.e. this that the above mentioned behaviour is exercised causing no change to the directory's extent count.
--- libxfs/xfs_bmap.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
libxfs/xfs_bmap.c +18 -0
@@ -5144,6 +5144,24 @@ xfs_bmap_del_extent_real(/* * Deleting the middle of the extent. */ + +/* +* For directories, -ENOSPC is returned since a directory entry +* remove operation must not fail due to low extent count +* availability. -ENOSPC will be handled by higher layers of XFS +* by letting the corresponding empty Data/Free blocks to linger +* until a future remove operation. Dabtree blocks would be +* swapped with the last block in the leaf space and then the +* new last block will be unmapped. +*/ + error =xfs_iext_count_may_overflow (ip, whichfork,1 ); +if (error) { +ASSERT (S_ISDIR (VFS_I (ip)->i_mode) && + whichfork ==XFS_DATA_FORK ); + error = -ENOSPC ; + goto done; + } + old = got; got.br_blockcount = del->br_startoff - got.br_startoff;
Signature · 1 line
2.7.4
PATCH v16 7/28 xfsprogs: Check for extent overflow when renaming dir entries
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 02092a2f034fdeabab524ae39c2de86ba9ffa15a
A rename operation is essentially a directory entry remove operation from the perspective of parent directory (i.e. src_dp) of rename's source. Hence the only place where we check for extent count overflow for src_dp is in xfs_bmap_del_extent_real(). xfs_bmap_del_extent_real() returns -ENOSPC when it detects a possible extent count overflow and in response, the higher layers of directory handling code do the following:
1. Data/Free blocks: XFS lets these blocks linger until a future remove operation removes them.
2. Dabtree blocks: XFS swaps the blocks with the last block in the Leaf space and unmaps the last block.
For target_dp, there are two cases depending on whether the destination directory entry exists or not.
When destination directory entry does not exist (i.e. target_ip == NULL), extent count overflow check is performed only when transaction has a non-zero sized space reservation associated with it. With a zero-sized space reservation, XFS allows a rename operation to continue only when the directory has sufficient free space in its data/leaf/free space blocks to hold the new entry.
When destination directory entry exists (i.e. target_ip != NULL), all we need to do is change the inode number associated with the already existing entry. Hence there is no need to perform an extent count overflow check.
--- libxfs/xfs_bmap.c | 3 +++ 1 file changed, 3 insertions(+)
libxfs/xfs_bmap.c +3 -0
@@ -5153,6 +5153,9 @@ xfs_bmap_del_extent_real(* until a future remove operation. Dabtree blocks would be * swapped with the last block in the leaf space and then the * new last block will be unmapped. +* +* The above logic also applies to the source directory entry of +* a rename operation. */ error =xfs_iext_count_may_overflow (ip, whichfork,1 );if (error) {
Signature · 1 line
2.7.4
PATCH v16 8/28 xfsprogs: Check for extent overflow when adding/removing xattrs
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 3a19bb147c72d2e9b77137bf5130b9cfb50a5eef
Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to be added. One extra extent for dabtree in case a local attr is large enough to cause a double split. It can also cause extent count to increase proportional to the size of a remote xattr's value.
--- libxfs/xfs_attr.c | 13 +++++++++++++ libxfs/xfs_inode_fork.h | 10 ++++++++++ 2 files changed, 23 insertions(+)
libxfs/xfs_attr.c +13 -0
@@ -396,6 +396,7 @@ xfs_attr_set(struct xfs_trans_res tres;bool rsvd = (args->attr_filter &XFS_ATTR_ROOT );int error, local; +int rmt_blks =0 ;unsigned int total;if (XFS_FORCED_SHUTDOWN (dp->i_mount))
@@ -442,11 +443,15 @@ xfs_attr_set( tres.tr_logcount =XFS_ATTRSET_LOG_COUNT ; tres.tr_logflags =XFS_TRANS_PERM_LOG_RES ; total = args->total; + +if (!local) + rmt_blks =xfs_attr3_rmt_blocks (mp, args->valuelen); }else {XFS_STATS_INC (mp, xs_attr_remove); tres =M_RES (mp)->tr_attrrm; total =XFS_ATTRRM_SPACE_RES (mp); + rmt_blks =xfs_attr3_rmt_blocks (mp,XFS_XATTR_SIZE_MAX ); }/*
@@ -460,6 +465,14 @@ xfs_attr_set(xfs_ilock (dp,XFS_ILOCK_EXCL );xfs_trans_ijoin (args->trans, dp,0 ); + +if (args->value ||xfs_inode_hasattr (dp)) { + error =xfs_iext_count_may_overflow (dp,XFS_ATTR_FORK , +XFS_IEXT_ATTR_MANIP_CNT (rmt_blks)); +if (error) + goto out_trans_cancel; + } +if (args->value) {unsigned int quota_flags =XFS_QMOPT_RES_REGBLKS ;
libxfs/xfs_inode_fork.h +10 -0
@@ -61,6 +61,16 @@ struct xfs_ifork { ((XFS_DA_NODE_MAXDEPTH +1 +1 ) * (mp)->m_dir_geo->fsbcount)/* +* Adding/removing an xattr can cause XFS_DA_NODE_MAXDEPTH extents to +* be added. One extra extent for dabtree in case a local attr is +* large enough to cause a double split. It can also cause extent +* count to increase proportional to the size of a remote xattr's +* value. + */ +#define XFS_IEXT_ATTR_MANIP_CNT (rmt_blks) \ + (XFS_DA_NODE_MAXDEPTH + max(1, rmt_blks)) + +/* * Fork handling. */
Signature · 1 line
2.7.4
PATCH v16 9/28 xfsprogs: Check for extent overflow when writing to unwritten extent
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: c442f3086d5a108b7ff086c8ade1923a8f389db5
A write to a sub-interval of an existing unwritten extent causes the original extent to be split into 3 extents
i.e. | Unwritten | Real | Unwritten |
Hence extent count can increase by 2.
--- libxfs/xfs_inode_fork.h | 9 +++++++++ 1 file changed, 9 insertions(+)
libxfs/xfs_inode_fork.h +9 -0
@@ -71,6 +71,15 @@ struct xfs_ifork { (XFS_DA_NODE_MAXDEPTH +max (1 , rmt_blks))/* +* A write to a sub-interval of an existing unwritten extent causes the original +* extent to be split into 3 extents +* i.e. | Unwritten | Real | Unwritten | +* Hence extent count can increase by 2. + */ +#define XFS_IEXT_WRITE_UNWRITTEN_CNT (2) + + +/* * Fork handling. */
Signature · 1 line
2.7.4
PATCH v16 10/28 xfsprogs: Check for extent overflow when moving extent from cow to data fork
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 5f1d5bbfb2e674052a9fe542f53678978af20770
Moving an extent to data fork can cause a sub-interval of an existing extent to be unmapped. This will increase extent count by 1. Mapping in the new extent can increase the extent count by 1 again i.e. | Old extent | New extent | Old extent |
Hence number of extents increases by 2.
--- libxfs/xfs_inode_fork.h | 9 +++++++++ 1 file changed, 9 insertions(+)
libxfs/xfs_inode_fork.h +9 -0
@@ -80,6 +80,15 @@ struct xfs_ifork {/* +* Moving an extent to data fork can cause a sub-interval of an existing extent +* to be unmapped. This will increase extent count by 1. Mapping in the new +* extent can increase the extent count by 1 again i.e. +* | Old extent | New extent | Old extent | +* Hence number of extents increases by 2. +*/ +#define XFS_IEXT_REFLINK_END_COW_CNT (2) + +/* * Fork handling. */
Signature · 1 line
2.7.4
PATCH v16 11/28 xfsprogs: Check for extent overflow when swapping extents
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: bcc561f21f115437a010307420fc43d91be91c66
Removing an initial range of source/donor file's extent and adding a new extent (from donor/source file) in its place will cause extent count to increase by 1.
--- libxfs/xfs_inode_fork.h | 7 +++++++ 1 file changed, 7 insertions(+)
libxfs/xfs_inode_fork.h +7 -0
@@ -89,6 +89,13 @@ struct xfs_ifork {#define XFS_IEXT_REFLINK_END_COW_CNT (2)/* +* Removing an initial range of source/donor file's extent and adding a new +* extent (from donor/source file) in its place will cause extent count to +* increase by 1. +*/ +#define XFS_IEXT_SWAP_RMAP_CNT (1) + +/* * Fork handling. */
Signature · 1 line
2.7.4
PATCH v16 12/28 xfsprogs: Introduce error injection to reduce maximum inode fork extent count
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: f9fa87169d2bc1bf55ab42bb6085114378c53b86
This commit adds XFS_ERRTAG_REDUCE_MAX_IEXTENTS error tag which enables userspace programs to test "Inode fork extent count overflow detection" by reducing maximum possible inode fork extent count to 10.
achender:
Amended io/inject.c with error tag name to avoid compiler errors
--- io/inject.c | 1 + libxfs/xfs_errortag.h | 4 +++- libxfs/xfs_inode_fork.c | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-)
io/inject.c +1 -0
@@ -55,6 +55,7 @@ error_tag(char *name) { XFS_ERRTAG_FORCE_SUMMARY_RECALC, "bad_summary" }, { XFS_ERRTAG_IUNLINK_FALLBACK, "iunlink_fallback" }, { XFS_ERRTAG_BUF_IOERROR, "buf_ioerror" }, + { XFS_ERRTAG_REDUCE_MAX_IEXTENTS, "reduce_max_iextents"}, { XFS_ERRTAG_MAX, NULL } };int count;
libxfs/xfs_errortag.h +3 -1
@@ -56,7 +56,8 @@#define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33#define XFS_ERRTAG_IUNLINK_FALLBACK 34#define XFS_ERRTAG_BUF_IOERROR 35 -#define XFS_ERRTAG_MAX 36 +#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 +#define XFS_ERRTAG_MAX 37/* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -97,5 +98,6 @@#define XFS_RANDOM_FORCE_SUMMARY_RECALC 1#define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10)#define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT +#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1#endif /* __XFS_ERRORTAG_H_ */
libxfs/xfs_inode_fork.c +4 -0
@@ -22,6 +22,7 @@#include "xfs_dir2_priv.h" #include "xfs_attr_leaf.h" #include "xfs_types.h" +#include "xfs_errortag.h" kmem_zone_t *xfs_ifork_zone;
@@ -743,6 +744,9 @@ xfs_iext_count_may_overflow( max_exts = (whichfork ==XFS_ATTR_FORK ) ?MAXAEXTNUM :MAXEXTNUM ; +if (XFS_TEST_ERROR (false, ip->i_mount,XFS_ERRTAG_REDUCE_MAX_IEXTENTS )) + max_exts =10 ; + nr_exts = ifp->if_nextents + nr_to_add;if (nr_exts < ifp->if_nextents || nr_exts > max_exts)return -EFBIG ;
Signature · 1 line
2.7.4
PATCH v16 13/28 xfsprogs: Remove duplicate assert statement in xfs_bmap_btalloc()
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: aff4db57d510082f11194ca915d8101463c92d46
The check for verifying if the allocated extent is from an AG whose index is greater than or equal to that of tp->t_firstblock is already done a couple of statements earlier in the same function. Hence this
--- libxfs/xfs_bmap.c | 1 - 1 file changed, 1 deletion(-)
libxfs/xfs_bmap.c +0 -1
@@ -3692,7 +3692,6 @@ xfs_bmap_btalloc( ap->blkno = args.fsbno;if (ap->tp->t_firstblock ==NULLFSBLOCK ) ap->tp->t_firstblock = args.fsbno; -ASSERT (nullfb || fb_agno <= args.agno); ap->length = args.len;/* * If the extent size hint is active, we tried to round the
Signature · 1 line
2.7.4
PATCH v16 14/28 xfsprogs: Compute bmap extent alignments in a separate function
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 0961fddfdd3f8ccd6302af2e7718abbaf18c9fff
This commit moves over the code which computes stripe alignment and extent size hint alignment into a separate function. Apart from xfs_bmap_btalloc(), the new function will be used by another function introduced in a future commit.
--- libxfs/xfs_bmap.c | 89 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 37 deletions(-)
libxfs/xfs_bmap.c +52 -37
@@ -3456,13 +3456,59 @@ xfs_bmap_btalloc_accounting( args->len); } +static int +xfs_bmap_compute_alignments ( +struct xfs_bmalloca *ap, +struct xfs_alloc_arg *args) +{ +struct xfs_mount *mp = args->mp; +xfs_extlen_t align =0 ;/* minimum allocation alignment */ +int stripe_align =0 ; +int error; + +/* stripe alignment for allocation is determined by mount parameters */ +if (mp->m_swidth && (mp->m_flags &XFS_MOUNT_SWALLOC )) + stripe_align = mp->m_swidth; +else if (mp->m_dalign) + stripe_align = mp->m_dalign; + +if (ap->flags &XFS_BMAPI_COWFORK ) + align =xfs_get_cowextsz_hint (ap->ip); +else if (ap->datatype &XFS_ALLOC_USERDATA ) + align =xfs_get_extsz_hint (ap->ip); +if (align) { + error =xfs_bmap_extsize_align (mp, &ap->got, &ap->prev, + align,0 , ap->eof,0 , ap->conv, + &ap->offset, &ap->length); +ASSERT (!error); +ASSERT (ap->length); + } + +/* apply extent size hints if obtained earlier */ +if (align) { + args->prod = align; +div_u64_rem (ap->offset, args->prod, &args->mod); +if (args->mod) + args->mod = args->prod - args->mod; + }else if (mp->m_sb.sb_blocksize >=PAGE_SIZE ) { + args->prod =1 ; + args->mod =0 ; + }else { + args->prod =PAGE_SIZE >> mp->m_sb.sb_blocklog; +div_u64_rem (ap->offset, args->prod, &args->mod); +if (args->mod) + args->mod = args->prod - args->mod; + } + +return stripe_align; +} + STATIC intxfs_bmap_btalloc (struct xfs_bmalloca *ap)/* bmap alloc argument struct */ {xfs_mount_t *mp;/* mount point structure */ xfs_alloctype_t atype =0 ;/* type for allocation routines */ -xfs_extlen_t align =0 ;/* minimum allocation alignment */ xfs_agnumber_t fb_agno;/* ag number of ap->firstblock */ xfs_agnumber_t ag;xfs_alloc_arg_t args;
@@ -3482,25 +3528,11 @@ xfs_bmap_btalloc( mp = ap->ip->i_mount; -/* stripe alignment for allocation is determined by mount parameters */ - stripe_align =0 ; -if (mp->m_swidth && (mp->m_flags &XFS_MOUNT_SWALLOC )) - stripe_align = mp->m_swidth; -else if (mp->m_dalign) - stripe_align = mp->m_dalign; - -if (ap->flags &XFS_BMAPI_COWFORK ) - align =xfs_get_cowextsz_hint (ap->ip); -else if (ap->datatype &XFS_ALLOC_USERDATA ) - align =xfs_get_extsz_hint (ap->ip); -if (align) { - error =xfs_bmap_extsize_align (mp, &ap->got, &ap->prev, - align,0 , ap->eof,0 , ap->conv, - &ap->offset, &ap->length); -ASSERT (!error); -ASSERT (ap->length); - } +memset (&args,0 ,sizeof (args)); + args.tp = ap->tp; + args.mp = mp; + stripe_align =xfs_bmap_compute_alignments (ap, &args); nullfb = ap->tp->t_firstblock ==NULLFSBLOCK ; fb_agno = nullfb ? NULLAGNUMBER : XFS_FSB_TO_AGNO(mp,
@@ -3531,9 +3563,6 @@ xfs_bmap_btalloc(* Normal allocation, done through xfs_alloc_vextent. */ tryagain = isaligned =0 ; -memset (&args,0 ,sizeof (args)); - args.tp = ap->tp; - args.mp = mp; args.fsbno = ap->blkno; args.oinfo =XFS_RMAP_OINFO_SKIP_UPDATE ;
@@ -3564,21 +3593,7 @@ xfs_bmap_btalloc( args.total = ap->total; args.minlen = ap->minlen; } -/* apply extent size hints if obtained earlier */ -if (align) { - args.prod = align; -div_u64_rem (ap->offset, args.prod, &args.mod); -if (args.mod) - args.mod = args.prod - args.mod; - }else if (mp->m_sb.sb_blocksize >=PAGE_SIZE ) { - args.prod =1 ; - args.mod =0 ; - }else { - args.prod =PAGE_SIZE >> mp->m_sb.sb_blocklog; -div_u64_rem (ap->offset, args.prod, &args.mod); -if (args.mod) - args.mod = args.prod - args.mod; - } +/* * If we are not low on available data blocks, and the underlying * logical volume manager is a stripe, and the file offset is zero then
Signature · 1 line
2.7.4
PATCH v16 15/28 xfsprogs: Process allocated extent in a separate function
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 07c72e556299a7fea448912b1330b9ebfd418662
This commit moves over the code in xfs_bmap_btalloc() which is responsible for processing an allocated extent to a new function. Apart from xfs_bmap_btalloc(), the new function will be invoked by another function introduced in a future commit.
--- libxfs/xfs_bmap.c | 74 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 29 deletions(-)
libxfs/xfs_bmap.c +45 -29
@@ -3503,6 +3503,48 @@ xfs_bmap_compute_alignments(return stripe_align; } +static void +xfs_bmap_process_allocated_extent ( +struct xfs_bmalloca *ap, +struct xfs_alloc_arg *args, +xfs_fileoff_t orig_offset, +xfs_extlen_t orig_length) +{ +int nullfb; + + nullfb = ap->tp->t_firstblock ==NULLFSBLOCK ; + +/* +* check the allocation happened at the same or higher AG than +* the first block that was allocated. +*/ +ASSERT (nullfb || +XFS_FSB_TO_AGNO (args->mp, ap->tp->t_firstblock) <= +XFS_FSB_TO_AGNO (args->mp, args->fsbno)); + + ap->blkno = args->fsbno; +if (nullfb) + ap->tp->t_firstblock = args->fsbno; + ap->length = args->len; +/* +* If the extent size hint is active, we tried to round the +* caller's allocation request offset down to extsz and the +* length up to another extsz boundary. If we found a free +* extent we mapped it in starting at this new offset. If the +* newly mapped space isn't long enough to cover any of the +* range of offsets that was originally requested, move the +* mapping up so that we can fill as much of the caller's +* original request as possible. Free space is apparently +* very fragmented so we're unlikely to be able to satisfy the +* hints anyway. +*/ +if (ap->length <= orig_length) + ap->offset = orig_offset; +else if (ap->offset + ap->length < orig_offset + orig_length) + ap->offset = orig_offset + orig_length - ap->length; +xfs_bmap_btalloc_accounting (ap, args); +} + STATIC intxfs_bmap_btalloc (struct xfs_bmalloca *ap)/* bmap alloc argument struct */
@@ -3695,36 +3737,10 @@ xfs_bmap_btalloc(return error; ap->tp->t_flags |=XFS_TRANS_LOWMODE ; } +if (args.fsbno !=NULLFSBLOCK ) { -/* -* check the allocation happened at the same or higher AG than -* the first block that was allocated. -*/ -ASSERT (ap->tp->t_firstblock ==NULLFSBLOCK || -XFS_FSB_TO_AGNO (mp, ap->tp->t_firstblock) <= -XFS_FSB_TO_AGNO (mp, args.fsbno)); - - ap->blkno = args.fsbno; -if (ap->tp->t_firstblock ==NULLFSBLOCK ) - ap->tp->t_firstblock = args.fsbno; - ap->length = args.len; -/* -* If the extent size hint is active, we tried to round the -* caller's allocation request offset down to extsz and the -* length up to another extsz boundary. If we found a free -* extent we mapped it in starting at this new offset. If the -* newly mapped space isn't long enough to cover any of the -* range of offsets that was originally requested, move the -* mapping up so that we can fill as much of the caller's -* original request as possible. Free space is apparently -* very fragmented so we're unlikely to be able to satisfy the -* hints anyway. -*/ -if (ap->length <= orig_length) - ap->offset = orig_offset; -else if (ap->offset + ap->length < orig_offset + orig_length) - ap->offset = orig_offset + orig_length - ap->length; -xfs_bmap_btalloc_accounting (ap, &args); +xfs_bmap_process_allocated_extent (ap, &args, orig_offset, + orig_length); }else { ap->blkno =NULLFSBLOCK ; ap->length =0 ;
Signature · 1 line
2.7.4
PATCH v16 16/28 xfsprogs: Introduce error injection to allocate only minlen size extents for files
In reply to Allison HendersonFrom: Chandan Babu R <[email protected]>
Source kernel commit: 301519674699aa9b80a15b2b2165e08532b176e6
This commit adds XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag which helps userspace test programs to get xfs_bmap_btalloc() to always allocate minlen sized extents.
This is required for test programs which need a guarantee that minlen extents allocated for a file do not get merged with their existing neighbours in the inode's BMBT. "Inode fork extent overflow check" for Directories, Xattrs and extension of realtime inodes need this since the file offset at which the extents are being allocated cannot be explicitly controlled from userspace.
One way to use this error tag is to,
1. Consume all of the free space by sequentially writing to a file.
2. Punch alternate blocks of the file. This causes CNTBT to contain sufficient number of one block sized extent records.
3. Inject XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT error tag. After step 3, xfs_bmap_btalloc() will issue space allocation requests for minlen sized extents only.
ENOSPC error code is returned to userspace when there aren't any "one block sized" extents left in any of the AGs.
achender:
Amended io/inject.c with error tag name to avoid compiler errors
--- io/inject.c | 1 + libxfs/xfs_alloc.c | 50 ++++++++++++++++++++ libxfs/xfs_alloc.h | 3 ++ libxfs/xfs_bmap.c | 124 ++++++++++++++++++++++++++++++++++++++++---------- libxfs/xfs_errortag.h | 4 +- 5 files changed, 157 insertions(+), 25 deletions(-)
io/inject.c +1 -0
@@ -56,6 +56,7 @@ error_tag(char *name) { XFS_ERRTAG_IUNLINK_FALLBACK, "iunlink_fallback" }, { XFS_ERRTAG_BUF_IOERROR, "buf_ioerror" }, { XFS_ERRTAG_REDUCE_MAX_IEXTENTS, "reduce_max_iextents"}, + { XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT, "bmap_min_extent"}, { XFS_ERRTAG_MAX, NULL } };int count;
libxfs/xfs_alloc.c +50 -0
62 lines not on this page · raw message
libxfs/xfs_alloc.h +3 -0
@@ -75,6 +75,9 @@ typedef struct xfs_alloc_arg {char wasfromfl;/* set if allocation is from freelist */ struct xfs_owner_info oinfo;/* owner of blocks being allocated */ enum xfs_ag_resv_type resv;/* block reservation to use */ +#ifdef DEBUG +bool alloc_minlen_only;/* allocate exact minlen extent */ +#endif } xfs_alloc_arg_t;/*
libxfs/xfs_bmap.c +100 -24
150 lines not on this page · raw message
libxfs/xfs_errortag.h +3 -1
@@ -57,7 +57,8 @@#define XFS_ERRTAG_IUNLINK_FALLBACK 34#define XFS_ERRTAG_BUF_IOERROR 35#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 -#define XFS_ERRTAG_MAX 37 +#define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37 +#define XFS_ERRTAG_MAX 38/* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -99,5 +100,6 @@#define XFS_RANDOM_IUNLINK_FALLBACK (XFS_RANDOM_DEFAULT/10)#define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 +#define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1#endif /* __XFS_ERRORTAG_H_ */
Signature · 1 line
2.7.4
PATCH v16 17/28 libxfs: expose inobtcount in xfs geometry
In reply to Allison HendersonFrom: Zorro Lang <[email protected]>
Source kernel commit: bc41fa5321f93ecbabec177f888451cfc17ad66d
As xfs supports the feature of inode btree block counters now, expose this feature flag in xfs geometry, for userspace can check if the inobtcnt is enabled or not.
--- libxfs/xfs_fs.h | 1 + libxfs/xfs_sb.c | 2 ++ 2 files changed, 3 insertions(+)
libxfs/xfs_fs.h +1 -0
@@ -250,6 +250,7 @@ typedef struct xfs_fsop_resblks {#define XFS_FSOP_GEOM_FLAGS_RMAPBT (1 << 19)/* reverse mapping btree */ #define XFS_FSOP_GEOM_FLAGS_REFLINK (1 << 20)/* files can share blocks */ #define XFS_FSOP_GEOM_FLAGS_BIGTIME (1 << 21)/* 64-bit nsec timestamps */ +#define XFS_FSOP_GEOM_FLAGS_INOBTCNT (1 << 22)/* inobt btree counter */ /* * Minimum and maximum sizes need for growth checks.
libxfs/xfs_sb.c +2 -0
@@ -1135,6 +1135,8 @@ xfs_fs_geometry( geo->flags |=XFS_FSOP_GEOM_FLAGS_REFLINK ;if (xfs_sb_version_hasbigtime (sbp)) geo->flags |=XFS_FSOP_GEOM_FLAGS_BIGTIME ; +if (xfs_sb_version_hasinobtcounts (sbp)) + geo->flags |=XFS_FSOP_GEOM_FLAGS_INOBTCNT ;if (xfs_sb_version_hassector (sbp)) geo->logsectsize = sbp->sb_logsectsize;else
Signature · 1 line
2.7.4
PATCH v16 18/28 xfsprogs: Reverse apply 72b97ea40d
In reply to Allison HendersonOriginally we added this patch to help modularize the attr code in preparation for delayed attributes and the state machine it requires. However, later reviews found that this slightly alters the transaction handling as the helper function is ambiguous as to whether the transaction is diry or clean. This may cause a dirty transaction to be included in the next roll, where previously it had not. To preserve the existing code flow, we reverse apply this commit.
--- libxfs/xfs_attr.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
libxfs/xfs_attr.c +9 -19
@@ -1215,24 +1215,6 @@ int xfs_attr_node_removename_setup(return 0 ; } -STATIC int -xfs_attr_node_remove_rmt ( -struct xfs_da_args *args, -struct xfs_da_state *state) -{ -int error =0 ; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - -/* -* Refill the state structure with buffers, the prior calls released our -* buffers. -*/ -return xfs_attr_refillstate (state); -} -/* * Remove a name from a B-tree attribute list. *
@@ -1261,7 +1243,15 @@ xfs_attr_node_removename(* overflow the maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_node_remove_rmt (args, state); + error =xfs_attr_rmtval_remove (args); +if (error) + goto out; + +/* +* Refill the state structure with buffers, the prior calls +* released our buffers. +*/ + error =xfs_attr_refillstate (state);if (error) goto out; }
Signature · 1 line
2.7.4
PATCH v16 19/28 xfsprogs: Add xfs_attr_node_remove_cleanup
In reply to Allison HendersonSource kernel commit: 4078af18570ef0f89fce18e9ed9c1fa0c827f37b
This patch pulls a new helper function xfs_attr_node_remove_cleanup out of xfs_attr_node_remove_step. This helps to modularize xfs_attr_node_remove_step which will help make the delayed attribute code easier to follow
--- libxfs/xfs_attr.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
libxfs/xfs_attr.c +20 -9
@@ -1215,6 +1215,25 @@ int xfs_attr_node_removename_setup(return 0 ; } +STATIC int +xfs_attr_node_remove_cleanup ( +struct xfs_da_args *args, +struct xfs_da_state *state) +{ +struct xfs_da_state_blk *blk; +int retval; + +/* +* Remove the name and update the hashvals in the tree. +*/ + blk = &state->path.blk[state->path.active-1 ]; +ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + retval =xfs_attr3_leaf_remove (blk->bp, args); +xfs_da3_fixhashpath (state, &state->path); + +return retval; +} +/* * Remove a name from a B-tree attribute list. *
@@ -1227,7 +1246,6 @@ xfs_attr_node_removename( struct xfs_da_args *args) {struct xfs_da_state *state; -struct xfs_da_state_blk *blk;int retval, error;struct xfs_inode *dp = args->dp;
@@ -1255,14 +1273,7 @@ xfs_attr_node_removename(if (error) goto out; } - -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr3_leaf_remove (blk->bp, args); -xfs_da3_fixhashpath (state, &state->path); + retval =xfs_attr_node_remove_cleanup (args, state);/* * Check to see if the tree needs to be collapsed.
Signature · 1 line
2.7.4
PATCH v16 20/28 xfsprogs: Hoist xfs_attr_set_shortform
In reply to Allison HendersonThis patch hoists xfs_attr_set_shortform into the calling function. This will help keep all state management code in the same scope.
--- libxfs/xfs_attr.c | 81 +++++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 54 deletions(-)
libxfs/xfs_attr.c +27 -54
@@ -217,53 +217,6 @@ xfs_attr_is_shortform( }/* -* Attempts to set an attr in shortform, or converts short form to leaf form if -* there is not enough room. If the attr is set, the transaction is committed -* and set to NULL. -*/ -STATIC int -xfs_attr_set_shortform ( -struct xfs_da_args *args, -struct xfs_buf **leaf_bp) -{ -struct xfs_inode *dp = args->dp; -int error, error2 =0 ; - -/* -* Try to add the attr to the attribute list in the inode. -*/ - error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; - } -/* -* It won't fit in the shortform, transform to a leaf block. GROT: -* another possible req'mt for a double-split btree op. -*/ - error =xfs_attr_shortform_to_leaf (args, leaf_bp); -if (error) -return error; - -/* -* Prevent the leaf buffer from being unlocked so that a concurrent AIL -* push cannot grab the half-baked leaf buffer and run into problems -* with the write verifier. Once we're done rolling the transaction we -* can release the hold and add the attr to the leaf. -*/ -xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, *leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, *leaf_bp); -return error; - } - -return 0 ; -} - -/* * Set the attribute specified in @args. */ int
@@ -272,7 +225,7 @@ xfs_attr_set_args( {struct xfs_inode *dp = args->dp;struct xfs_buf *leaf_bp =NULL ; -int error =0 ; +int error2, error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -281,16 +234,36 @@ xfs_attr_set_args(* again. */ if (xfs_attr_is_shortform (dp)) { +/* +* Try to add the attr to the attribute list in the inode. +*/ + error =xfs_attr_try_sf_addname (dp, args); +if (error != -ENOSPC ) { + error2 =xfs_trans_commit (args->trans); + args->trans =NULL ; +return error ? error : error2; + } + +/* +* It won't fit in the shortform, transform to a leaf block. +* GROT: another possible req'mt for a double-split btree op. +*/ + error =xfs_attr_shortform_to_leaf (args, &leaf_bp); +if (error) +return error;/* -* If the attr was successfully set in shortform, the -* transaction is committed and set to NULL. Otherwise, is it -* converted from shortform to leaf, and the transaction is -* retained. +* Prevent the leaf buffer from being unlocked so that a +* concurrent AIL push cannot grab the half-baked leaf buffer +* and run into problems with the write verifier. */ - error =xfs_attr_set_shortform (args, &leaf_bp); -if (error || !args->trans) +xfs_trans_bhold (args->trans, leaf_bp); + error =xfs_defer_finish (&args->trans); +xfs_trans_bhold_release (args->trans, leaf_bp); +if (error) { +xfs_trans_brelse (args->trans, leaf_bp);return error; + } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {
Signature · 1 line
2.7.4
PATCH v16 21/28 xfsprogs: Add helper xfs_attr_set_fmt
In reply to Allison HendersonSource kernel commit: 45b71a4f3fd8bc8d47adcbdfd859ed736a54e66b
This patch adds a helper function xfs_attr_set_fmt. This will help isolate the code that will require state management from the portions that do not. xfs_attr_set_fmt returns 0 when the attr has been set and no further action is needed. It returns -EAGAIN when shortform has been transformed to leaf, and the calling function should proceed the set the attr in leaf form.
--- libxfs/xfs_attr.c | 79 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 33 deletions(-)
libxfs/xfs_attr.c +46 -33
@@ -216,6 +216,48 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } +STATIC int +xfs_attr_set_fmt ( +struct xfs_da_args *args) +{ +struct xfs_buf *leaf_bp =NULL ; +struct xfs_inode *dp = args->dp; +int error2, error =0 ; + +/* +* Try to add the attr to the attribute list in the inode. +*/ + error =xfs_attr_try_sf_addname (dp, args); +if (error != -ENOSPC ) { + error2 =xfs_trans_commit (args->trans); + args->trans =NULL ; +return error ? error : error2; + } + +/* +* It won't fit in the shortform, transform to a leaf block. +* GROT: another possible req'mt for a double-split btree op. +*/ + error =xfs_attr_shortform_to_leaf (args, &leaf_bp); +if (error) +return error; + +/* +* Prevent the leaf buffer from being unlocked so that a +* concurrent AIL push cannot grab the half-baked leaf buffer +* and run into problems with the write verifier. +*/ +xfs_trans_bhold (args->trans, leaf_bp); + error =xfs_defer_finish (&args->trans); +xfs_trans_bhold_release (args->trans, leaf_bp); +if (error) { +xfs_trans_brelse (args->trans, leaf_bp); +return error; + } + +return -EAGAIN ; +} +/* * Set the attribute specified in @args. */
@@ -224,8 +266,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error2, error =0 ; +int error;/* * If the attribute list is already in leaf format, jump straight to
@@ -234,36 +275,9 @@ xfs_attr_set_args(* again. */ if (xfs_attr_is_shortform (dp)) { -/* -* Try to add the attr to the attribute list in the inode. -*/ - error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) { - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; - } - -/* -* It won't fit in the shortform, transform to a leaf block. -* GROT: another possible req'mt for a double-split btree op. -*/ - error =xfs_attr_shortform_to_leaf (args, &leaf_bp); -if (error) -return error; - -/* -* Prevent the leaf buffer from being unlocked so that a -* concurrent AIL push cannot grab the half-baked leaf buffer -* and run into problems with the write verifier. -*/ -xfs_trans_bhold (args->trans, leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, leaf_bp); + error =xfs_attr_set_fmt (args); +if (error != -EAGAIN )return error; - } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {
@@ -297,8 +311,7 @@ xfs_attr_set_args(return error; } - error =xfs_attr_node_addname (args); -return error; +return xfs_attr_node_addname (args); }/*
Signature · 1 line
2.7.4
PATCH v16 22/28 xfsprogs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete
In reply to Allison HendersonSource kernel commit: 392a7ea8080e3753aa179d4daaa2ad413d0ff441
This patch separate xfs_attr_node_addname into two functions. This will help to make it easier to hoist parts of xfs_attr_node_addname that need state management
--- libxfs/xfs_attr.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
libxfs/xfs_attr.c +20 -0
@@ -54,6 +54,7 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC int xfs_attr_node_addname(xfs_da_args_t *args); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,struct xfs_da_state **state); STATIC int xfs_attr_fillstate(xfs_da_state_t *state);
@@ -1074,6 +1075,25 @@ restart:return error; } + error =xfs_attr_node_addname_clear_incomplete (args); +out: +if (state) +xfs_da_state_free (state); +if (error) +return error; +return retval; +} + + +STATIC +int xfs_attr_node_addname_clear_incomplete( +struct xfs_da_args *args) +{ +struct xfs_da_state *state =NULL ; +struct xfs_da_state_blk *blk; +int retval =0 ; +int error =0 ; +/* * Re-find the "old" attribute entry after any split ops. The INCOMPLETE * flag means that we will find the "old" attr, not the "new" one.
Signature · 1 line
2.7.4
PATCH v16 23/28 xfsprogs: Add helper xfs_attr_node_addname_find_attr
In reply to Allison HendersonSource kernel commit: 1aeec98c3f70bff14cc0e65ef898e91c2c554d41
This patch separates the first half of xfs_attr_node_addname into a helper function xfs_attr_node_addname_find_attr. It also replaces the restart goto with with an EAGAIN return code driven by a loop in the calling function. This looks odd now, but will clean up nicly once we introduce the state machine. It will also enable hoisting the last state out of xfs_attr_node_addname with out having to plumb in a "done" parameter to know if we need to move to the next state or not.
--- libxfs/xfs_attr.c | 86 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 32 deletions(-)
libxfs/xfs_attr.c +54 -32
@@ -52,7 +52,10 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(struct xfs_da_args *args, +struct xfs_da_state *state); +STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args, +struct xfs_da_state **state); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_da_args *args); STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
@@ -267,6 +270,7 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_da_state *state;int error;/*
@@ -312,7 +316,14 @@ xfs_attr_set_args(return error; } -return xfs_attr_node_addname (args); +do { + error =xfs_attr_node_addname_find_attr (args, &state); +if (error) +return error; + error =xfs_attr_node_addname (args, state); + }while (error == -EAGAIN ); + +return error; }/*
@@ -898,47 +909,26 @@ xfs_attr_node_hasname(* External routines when attribute list size > geo->blksize *========================================================================*/ -/* -* Add a name to a Btree-format attribute list. -* -* This will involve walking down the Btree, and may involve splitting -* leaf nodes and even splitting intermediate nodes up to and including -* the root node (a special case of an intermediate node). -* -* "Remote" attribute values confuse the issue and atomic rename operations -* add a whole extra layer of confusion on top of that. -*/ STATIC int -xfs_attr_node_addname ( -struct xfs_da_args *args) +xfs_attr_node_addname_find_attr ( +struct xfs_da_args *args, +struct xfs_da_state **state) { -struct xfs_da_state *state; -struct xfs_da_state_blk *blk; -struct xfs_inode *dp; -int retval, error; - -trace_xfs_attr_node_addname (args); +int retval;/* -* Fill in bucket of arguments/results/context to carry around. -*/ - dp = args->dp; -restart: -/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - retval =xfs_attr_node_hasname (args, &state); + retval =xfs_attr_node_hasname (args, state);if (retval != -ENOATTR && retval != -EEXIST ) - goto out; + goto error; - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC );if (retval == -ENOATTR && (args->attr_flags &XATTR_REPLACE )) - goto out; + goto error;if (retval == -EEXIST ) {if (args->attr_flags &XATTR_CREATE ) - goto out; + goto error;trace_xfs_attr_node_replace (args);
@@ -956,6 +946,38 @@ restart: args->rmtvaluelen =0 ; } +return 0 ; +error: +if (*state) +xfs_da_state_free (*state); +return retval; +} + +/* +* Add a name to a Btree-format attribute list. +* +* This will involve walking down the Btree, and may involve splitting +* leaf nodes and even splitting intermediate nodes up to and including +* the root node (a special case of an intermediate node). +* +* "Remote" attribute values confuse the issue and atomic rename operations +* add a whole extra layer of confusion on top of that. +*/ +STATIC int +xfs_attr_node_addname ( +struct xfs_da_args *args, +struct xfs_da_state *state) +{ +struct xfs_da_state_blk *blk; +struct xfs_inode *dp; +int retval, error; + +trace_xfs_attr_node_addname (args); + + dp = args->dp; + blk = &state->path.blk[state->path.active-1 ]; +ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + retval =xfs_attr3_leaf_add (blk->bp, state->args);if (retval == -ENOSPC ) {if (state->path.active ==1 ) {
@@ -981,7 +1003,7 @@ restart:if (error) goto out; - goto restart; +return -EAGAIN ; }/*
Signature · 1 line
2.7.4
PATCH v16 24/28 xfsprogs: Hoist xfs_attr_node_addname
In reply to Allison HendersonSource kernel commit: 8e7db2a154cf8889319a4d6e5f987998ed21fa1b
This patch hoists the later half of xfs_attr_node_addname into the calling function. We do this because it is this area that will need the most state management, and we want to keep such code in the same scope as much as possible
--- libxfs/xfs_attr.c | 161 ++++++++++++++++++++++++++---------------------------- 1 file changed, 78 insertions(+), 83 deletions(-)
libxfs/xfs_attr.c +78 -83
@@ -52,6 +52,7 @@ STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);* Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); +STATIC void xfs_attr_restore_rmt_blk(struct xfs_da_args *args); STATIC int xfs_attr_node_addname(struct xfs_da_args *args,struct xfs_da_state *state); STATIC int xfs_attr_node_addname_find_attr(struct xfs_da_args *args,
@@ -270,8 +271,8 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_da_state *state; -int error; +struct xfs_da_state *state =NULL ; +int error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -322,8 +323,79 @@ xfs_attr_set_args(return error; error =xfs_attr_node_addname (args, state); }while (error == -EAGAIN ); +if (error) +return error; + +/* +* Commit the leaf addition or btree split and start the next +* trans in the chain. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + goto out; + } + +/* +* If this is an atomic rename operation, we must "flip" the incomplete +* flags on the "new" and "old" attribute/value pairs so that one +* disappears and one appears atomically. Then we must remove the "old" +* attribute/value pair. +* +* In a separate transaction, set the incomplete flag on the "old" attr +* and clear the incomplete flag on the "new" attr. +*/ + error =xfs_attr3_leaf_flipflags (args); +if (error) + goto out; +/* +* Commit the flag value change and start the next trans in series +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; +/* +* Dismantle the "old" attribute/value pair by removing a "remote" value +* (if it exists). +*/ +xfs_attr_restore_rmt_blk (args); + +if (args->rmtblkno) { + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + + error =xfs_attr_rmtval_remove (args); +if (error) +return error; + } + + error =xfs_attr_node_addname_clear_incomplete (args); +out: +if (state) +xfs_da_state_free (state);return error; + }/*
@@ -970,7 +1042,7 @@ xfs_attr_node_addname( {struct xfs_da_state_blk *blk;struct xfs_inode *dp; -int retval, error; +int error;trace_xfs_attr_node_addname (args);
@@ -978,8 +1050,8 @@ xfs_attr_node_addname( blk = &state->path.blk[state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr3_leaf_add (blk->bp, state->args); -if (retval == -ENOSPC ) { + error =xfs_attr3_leaf_add (blk->bp, state->args); +if (error == -ENOSPC ) {if (state->path.active ==1 ) {/* * Its really a single leaf node, but it had
@@ -1025,85 +1097,8 @@ xfs_attr_node_addname(xfs_da3_fixhashpath (state, &state->path); } -/* -* Kill the state structure, we're done with it and need to -* allow the buffers to come back later. -*/ -xfs_da_state_free (state); - state =NULL ; - -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - retval = error; - goto out; - } - -/* -* If this is an atomic rename operation, we must "flip" the incomplete -* flags on the "new" and "old" attribute/value pairs so that one -* disappears and one appears atomically. Then we must remove the "old" -* attribute/value pair. -* -* In a separate transaction, set the incomplete flag on the "old" attr -* and clear the incomplete flag on the "new" attr. -*/ - error =xfs_attr3_leaf_flipflags (args); -if (error) - goto out; -/* -* Commit the flag value change and start the next trans in series -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; - -/* -* Dismantle the "old" attribute/value pair by removing a "remote" value -* (if it exists). -*/ -xfs_attr_restore_rmt_blk (args); - -if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } - - error =xfs_attr_node_addname_clear_incomplete (args); out: -if (state) -xfs_da_state_free (state); -if (error) -return error; -return retval; +return error; }
Signature · 1 line
2.7.4
PATCH v16 25/28 xfsprogs: Hoist xfs_attr_leaf_addname
In reply to Allison HendersonSource kernel commit: 45adc55591f5d91b9b6c7752fa4253bf3de33886
This patch hoists xfs_attr_leaf_addname into the calling function. The goal being to get all the code that will require state management into the same scope. This isn't particuarly aesthetic right away, but it is a preliminary step to merging in the state machine code.
--- libxfs/xfs_attr.c | 209 +++++++++++++++++++++++++----------------------------- 1 file changed, 96 insertions(+), 113 deletions(-)
libxfs/xfs_attr.c +96 -113
@@ -44,9 +44,9 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp); +STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);/* * Internal routines when attribute list is more than one block.
@@ -271,8 +271,9 @@ xfs_attr_set_args( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; +struct xfs_buf *bp =NULL ;struct xfs_da_state *state =NULL ; -int error =0 ; +int forkoff, error =0 ;/* * If the attribute list is already in leaf format, jump straight to
@@ -287,10 +288,101 @@ xfs_attr_set_args( }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_addname (args); -if (error != -ENOSPC ) + error =xfs_attr_leaf_try_add (args, bp); +if (error == -ENOSPC ) + goto node; +else if (error) +return error; + +/* +* Commit the transaction that added the attr name so that +* later routines can manage their own transactions. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + +/* +* If there was an out-of-line value, allocate the blocks we +* identified for its storage and copy the value. This is done +* after we create the attribute so that we don't overflow the +* maximum size of a transaction and/or hit a deadlock. +*/ +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_set (args); +if (error) +return error; + } + +if (!(args->op_flags &XFS_DA_OP_RENAME )) { +/* +* Added a "remote" value, just clear the incomplete +*flag. +*/ +if (args->rmtblkno >0 ) + error =xfs_attr3_leaf_clearflag (args); + +return error; + } + +/* +* If this is an atomic rename operation, we must "flip" the +* incomplete flags on the "new" and "old" attribute/value pairs +* so that one disappears and one appears atomically. Then we +* must remove the "old" attribute/value pair. +* +* In a separate transaction, set the incomplete flag on the +* "old" attr and clear the incomplete flag on the "new" attr. +*/ + + error =xfs_attr3_leaf_flipflags (args); +if (error) +return error; +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) +return error; + +/* +* Dismantle the "old" attribute/value pair by removing a +* "remote" value (if it exists). +*/ +xfs_attr_restore_rmt_blk (args); + +if (args->rmtblkno) { + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error; + + error =xfs_attr_rmtval_remove (args); +if (error) +return error; + } + +/* +* Read in the block containing the "old" attr, then remove the +* "old" attr from that block (neat, huh!) +*/ + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, + &bp); +if (error)return error; +xfs_attr3_leaf_remove (bp, args); + +/* +* If the result is small enough, shrink it all into the inode. +*/ + forkoff =xfs_attr_shortform_allfit (bp, dp); +if (forkoff) + error =xfs_attr3_leaf_to_shortform (bp, args, forkoff); +/* bp is gone due to xfs_da_shrink_inode */ + +return error; +node:/* * Promote the attribute list to the Btree format. */
@@ -742,115 +834,6 @@ out_brelse:return retval; } - -/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ -STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) -{ -int error, forkoff; -struct xfs_buf *bp =NULL ; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; - -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - -/* -* If there was an out-of-line value, allocate the blocks we -* identified for its storage and copy the value. This is done -* after we create the attribute so that we don't overflow the -* maximum size of a transaction and/or hit a deadlock. -*/ -if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } - -if (!(args->op_flags &XFS_DA_OP_RENAME )) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ -if (args->rmtblkno >0 ) - error =xfs_attr3_leaf_clearflag (args); - -return error; - } - -/* -* If this is an atomic rename operation, we must "flip" the incomplete -* flags on the "new" and "old" attribute/value pairs so that one -* disappears and one appears atomically. Then we must remove the "old" -* attribute/value pair. -* -* In a separate transaction, set the incomplete flag on the "old" attr -* and clear the incomplete flag on the "new" attr. -*/ - - error =xfs_attr3_leaf_flipflags (args); -if (error) -return error; -/* -* Commit the flag value change and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - -/* -* Dismantle the "old" attribute/value pair by removing a "remote" value -* (if it exists). -*/ -xfs_attr_restore_rmt_blk (args); - -if (args->rmtblkno) { - error =xfs_attr_rmtval_invalidate (args); -if (error) -return error; - - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } - -/* -* Read in the block containing the "old" attr, then remove the "old" -* attr from that block (neat, huh!) -*/ - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, - &bp); -if (error) -return error; - -xfs_attr3_leaf_remove (bp, args); - -/* -* If the result is small enough, shrink it all into the inode. -*/ - forkoff =xfs_attr_shortform_allfit (bp, dp); -if (forkoff) - error =xfs_attr3_leaf_to_shortform (bp, args, forkoff); -/* bp is gone due to xfs_da_shrink_inode */ - -return error; -} -/* * Return EEXIST if attr is found, or ENOATTR if not */
Signature · 1 line
2.7.4
PATCH v16 26/28 xfsprogs: Hoist node transaction handling
In reply to Allison HendersonSource kernel commit: cb9e8e1fb89d84c77c8035b2391359f9cbf209e6
This patch basically hoists the node transaction handling around the leaf code we just hoisted. This will helps setup this area for the state machine since the goto is easily replaced with a state since it ends with a transaction roll.
--- libxfs/xfs_attr.c | 56 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-)
libxfs/xfs_attr.c +30 -26
@@ -289,10 +289,37 @@ xfs_attr_set_args(if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_try_add (args, bp); -if (error == -ENOSPC ) +if (error == -ENOSPC ) { +/* +* Promote the attribute list to the Btree format. +*/ + error =xfs_attr3_leaf_to_node (args); +if (error) +return error; + +/* +* Finish any deferred work items and roll the transaction once +* more. The goal here is to call node_addname with the inode +* and transaction in the same state (inode locked and joined, +* transaction clean) no matter how we got to this step. +*/ + error =xfs_defer_finish (&args->trans); +if (error) +return error; + +/* +* Commit the current trans (including the inode) and +* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + goto node; -else if (error) + } +else if (error) {return error; + }/* * Commit the transaction that added the attr name so that
@@ -382,32 +409,9 @@ xfs_attr_set_args(/* bp is gone due to xfs_da_shrink_inode */ return error; + } node: -/* -* Promote the attribute list to the Btree format. -*/ - error =xfs_attr3_leaf_to_node (args); -if (error) -return error; - -/* -* Finish any deferred work items and roll the transaction once -* more. The goal here is to call node_addname with the inode -* and transaction in the same state (inode locked and joined, -* transaction clean) no matter how we got to this step. -*/ - error =xfs_defer_finish (&args->trans); -if (error) -return error; -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - } do { error = xfs_attr_node_addname_find_attr(args, &state);
Signature · 1 line
2.7.4
PATCH v16 27/28 xfsprogs: Add delay ready attr remove routines
In reply to Allison HendersonThis patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args is merged with xfs_attr_node_removename become a new function, xfs_attr_remove_iter. This new version uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. A new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed. A new XFS_DAC_DEFER_FINISH flag is used to finish the transaction where ever the existing code used to.
Calls to xfs_attr_rmtval_remove are replaced with the delay ready version __xfs_attr_rmtval_remove. We will rename __xfs_attr_rmtval_remove back to xfs_attr_rmtval_remove when we are done.
xfs_attr_rmtval_remove itself is still in use by the set routines (used during a rename). For reasons of preserving existing function, we modify xfs_attr_rmtval_remove to call xfs_defer_finish when the flag is set. Similar to how xfs_attr_remove_args does here. Once we transition the set routines to be delay ready, xfs_attr_rmtval_remove is no longer used and will be removed.
This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls. See xfs_attr.h for a more detailed diagram of the states.
--- include/libxfs.h | 1 + libxfs/xfs_attr.c | 206 ++++++++++++++++++++++++++++++++--------------- libxfs/xfs_attr.h | 125 ++++++++++++++++++++++++++++ libxfs/xfs_attr_leaf.c | 2 +- libxfs/xfs_attr_remote.c | 48 ++++++----- libxfs/xfs_attr_remote.h | 2 +- 6 files changed, 297 insertions(+), 87 deletions(-)
include/libxfs.h +1 -0
@@ -168,6 +168,7 @@ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };#include "xfs_ialloc.h" #include "xfs_attr_leaf.h" +#include "xfs_attr.h" #include "xfs_attr_remote.h" #include "xfs_trans_space.h"
libxfs/xfs_attr.c +141 -65
269 lines not on this page · raw message
libxfs/xfs_attr.h +125 -0
137 lines not on this page · raw message
libxfs/xfs_attr_leaf.c +1 -1
@@ -19,8 +19,8 @@#include "xfs_bmap_btree.h" #include "xfs_bmap.h" #include "xfs_attr_sf.h" -#include "xfs_attr_remote.h" #include "xfs_attr.h" +#include "xfs_attr_remote.h" #include "xfs_attr_leaf.h" #include "xfs_trace.h" #include "xfs_dir2.h"
libxfs/xfs_attr_remote.c +28 -20
81 lines not on this page · raw message
libxfs/xfs_attr_remote.h +1 -1
@@ -14,5 +14,5 @@ int xfs_attr_rmtval_remove(struct xfs_da_args *args);int xfs_attr_rmtval_stale (struct xfs_inode *ip,struct xfs_bmbt_irec *map,xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args); -int __xfs_attr_rmtval_remove (struct xfs_da_args *args); +int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
PATCH v16 28/28 xfsprogs: Add delay ready attr set routines
In reply to Allison HendersonSource kernel commit: 45e46c998cd75749f6975ffdeeb9a59768e4fcd3
This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_set_args has become xfs_attr_set_iter, which uses a state machine like switch to keep track of where it was when EAGAIN was returned. See xfs_attr.h for a more detailed diagram of the states.
Two new helper functions have been added: xfs_attr_rmtval_find_space and xfs_attr_rmtval_set_blk. They provide a subset of logic similar to xfs_attr_rmtval_set, but they store the current block in the delay attr context to allow the caller to roll the transaction between allocations. This helps to simplify and consolidate code used by xfs_attr_leaf_addname and xfs_attr_node_addname. xfs_attr_set_args has now become a simple loop to refresh the transaction until the operation is completed. Lastly, xfs_attr_rmtval_remove is no longer used, and is removed.
--- include/xfs_trace.h | 1 - libxfs/xfs_attr.c | 446 +++++++++++++++++++++++++++++------------------ libxfs/xfs_attr.h | 241 ++++++++++++++++++++++++- libxfs/xfs_attr_remote.c | 100 +++++++---- libxfs/xfs_attr_remote.h | 5 +- 5 files changed, 582 insertions(+), 211 deletions(-)
include/xfs_trace.h +0 -1
@@ -160,7 +160,6 @@#define trace_xfs_attr_node_get (a) ((void) 0)#define trace_xfs_attr_rmtval_get (a) ((void) 0)#define trace_xfs_attr_rmtval_set (a) ((void) 0) -#define trace_xfs_attr_rmtval_remove (a) ((void) 0)#define trace_xfs_bmap_pre_update (a,b,c,d) ((void) 0)#define trace_xfs_bmap_post_update (a,b,c,d) ((void) 0)
libxfs/xfs_attr.c +272 -174
612 lines not on this page · raw message
libxfs/xfs_attr.h +240 -1
271 lines not on this page · raw message
libxfs/xfs_attr_remote.c +66 -34
125 lines not on this page · raw message
libxfs/xfs_attr_remote.h +4 -1
@@ -10,9 +10,12 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args); -int xfs_attr_rmtval_remove (struct xfs_da_args *args);int xfs_attr_rmtval_stale (struct xfs_inode *ip,struct xfs_bmbt_irec *map,xfs_buf_flags_t incore_flags);int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int __xfs_attr_rmtval_remove (struct xfs_delattr_context *dac); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args); +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmtval_set_blk (struct xfs_delattr_context *dac); +int xfs_attr_rmtval_find_space (struct xfs_delattr_context *dac);#endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4