xfs: Log Attribute Replay
v28 cover xfs: Log Attribute Replay
Hi all,
This set is a subset of a larger series parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This allows more complex operations (like parent pointers) to be broken up into multiple smaller transactions. To do this, the existing attr operations must be modified to operate as a delayed operation. This means that they cannot roll, commit, or finish transactions. Instead, they return -EAGAIN to allow the calling function to handle the transaction. In this series, we focus on only the delayed attribute portion. We will introduce parent pointers in a later set.
The set as a whole is a bit much to digest at once, so I usually send out the smaller sub series to reduce reviewer burn out. But the entire extended series is visible through the included github links.
Updates since v27:
xfs: don't commit the first deferred transaction without intents
Comment update
xfs: Add helper function xfs_init_attr_trans
Added new line for function name
This series can be viewed on github here:
https://github.com/allisonhenderson/xfs_work/tree/delayed_attrs_v28
As well as the extended delayed attribute and parent pointer series:
https://github.com/allisonhenderson/xfs_work/tree/delayed_attrs_v28_extended
Thanks all!
Allison
Allison Henderson (15):
xfs: Fix double unlock in defer capture code
xfs: don't commit the first deferred transaction without intents
xfs: Return from xfs_attr_set_iter if there are no more rmtblks to
process
xfs: Set up infrastructure for log attribute replay
xfs: Implement attr logging and replay
xfs: Skip flip flags for delayed attrs
xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
xfs: Remove unused xfs_attr_*_args
xfs: Add log attribute error tag
xfs: Add larp debug option
xfs: Merge xfs_delattr_context into xfs_attr_item
xfs: Add helper function xfs_attr_leaf_addname
xfs: Add helper function xfs_init_attr_trans
xfs: add leaf split error tag
xfs: add leaf to node error tag
fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 524 +++++++++++---------- fs/xfs/libxfs/xfs_attr.h | 70 ++- fs/xfs/libxfs/xfs_attr_leaf.c | 9 +- fs/xfs/libxfs/xfs_attr_remote.c | 37 +- fs/xfs/libxfs/xfs_attr_remote.h | 6 +- fs/xfs/libxfs/xfs_da_btree.c | 4 + fs/xfs/libxfs/xfs_defer.c | 35 +- fs/xfs/libxfs/xfs_defer.h | 3 + fs/xfs/libxfs/xfs_errortag.h | 8 +- fs/xfs/libxfs/xfs_format.h | 9 +- fs/xfs/libxfs/xfs_log_format.h | 44 +- fs/xfs/libxfs/xfs_log_recover.h | 2 + fs/xfs/scrub/common.c | 2 + fs/xfs/xfs_attr_item.c | 795 ++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 46 ++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_error.c | 9 + fs/xfs/xfs_globals.c | 1 + fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 2 + fs/xfs/xfs_log.c | 45 ++ fs/xfs/xfs_log.h | 12 + fs/xfs/xfs_log_recover.c | 2 + fs/xfs/xfs_ondisk.h | 2 + fs/xfs/xfs_sysctl.h | 1 + fs/xfs/xfs_sysfs.c | 24 + fs/xfs/xfs_trace.h | 1 + 28 files changed, 1418 insertions(+), 279 deletions(-) create mode 100644 fs/xfs/xfs_attr_item.c create mode 100644 fs/xfs/xfs_attr_item.h
Signature · 1 line
2.25.1
PATCH v28 1/15 xfs: Fix double unlock in defer capture code
The new deferred attr patch set uncovered a double unlock in the recent port of the defer ops capture and continue code. During log recovery, we're allowed to hold buffers to a transaction that's being used to replay an intent item. When we capture the resources as part of scheduling a continuation of an intent chain, we call xfs_buf_hold to retain our reference to the buffer beyond the transaction commit, but we do /not/ call xfs_trans_bhold to maintain the buffer lock. This means that xfs_defer_ops_continue needs to relock the buffers before xfs_defer_restore_resources joins then tothe new transaction.
Additionally, the buffers should not be passed back via the dres structure since they need to remain locked unlike the inodes. So simply set dr_bufs to zero after populating the dres structure.
--- fs/xfs/libxfs/xfs_defer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_defer.c +10 -1
@@ -22,6 +22,7 @@#include "xfs_refcount.h" #include "xfs_bmap.h" #include "xfs_alloc.h" +#include "xfs_buf.h" static struct kmem_cache *xfs_defer_pending_cache;
@@ -774,17 +775,25 @@ xfs_defer_ops_continue(struct xfs_trans *tp, struct xfs_defer_resources *dres) { + unsigned int i; +ASSERT (tp->t_flags &XFS_TRANS_PERM_LOG_RES );ASSERT (!(tp->t_flags &XFS_TRANS_DIRTY )); -/* Lock and join the captured inode to the new transaction. */ +/* Lock the captured resources to the new transaction. */ if (dfc->dfc_held.dr_inos ==2 )xfs_lock_two_inodes (dfc->dfc_held.dr_ip[0 ],XFS_ILOCK_EXCL , dfc->dfc_held.dr_ip[1 ],XFS_ILOCK_EXCL );else if (dfc->dfc_held.dr_inos ==1 )xfs_ilock (dfc->dfc_held.dr_ip[0 ],XFS_ILOCK_EXCL ); + +for (i =0 ; i < dfc->dfc_held.dr_bufs; i++) +xfs_buf_lock (dfc->dfc_held.dr_bp[i]); + +/* Join the captured resources to the new transaction. */ xfs_defer_restore_resources (tp, &dfc->dfc_held);memcpy (dres, &dfc->dfc_held,sizeof (struct xfs_defer_resources )); + dres->dr_bufs =0 ;/* Move captured dfops chain and state to the transaction. */ list_splice_init (&dfc->dfc_dfops, &tp->t_dfops);
Signature · 1 line
2.25.1
PATCH v28 2/15 xfs: don't commit the first deferred transaction without intents
In reply to Allison HendersonIf the first operation in a string of defer ops has no intents, then there is no reason to commit it before running the first call to xfs_defer_finish_one(). This allows the defer ops to be used effectively for non-intent based operations without requiring an unnecessary extra transaction commit when first called.
This fixes a regression in per-attribute modification transaction count when delayed attributes are not being used.
--- fs/xfs/libxfs/xfs_defer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_defer.c +10 -3
@@ -510,9 +510,16 @@ xfs_defer_finish_noroll(xfs_defer_create_intents (*tp);list_splice_init (&(*tp)->t_dfops, &dop_pending); - error =xfs_defer_trans_roll (tp); -if (error) - goto out_shutdown; +/* +* We must ensure the transaction is clean before we try to +* finish the next deferred item by committing logged intent +* items and anything else that dirtied the transaction. +*/ +if ((*tp)->t_flags &XFS_TRANS_DIRTY ) { + error =xfs_defer_trans_roll (tp); +if (error) + goto out_shutdown; + }/* Possibly relog intent items to keep the log moving. */ error =xfs_defer_relog (tp, &dop_pending);
Signature · 1 line
2.25.1
PATCH v28 3/15 xfs: Return from xfs_attr_set_iter if there are no more rmtblks to process
In reply to Allison HendersonDuring an attr rename operation, blocks are saved for later removal as rmtblkno2. The rmtblkno is used in the case of needing to alloc more blocks if not enough were available. However, in the case that no further blocks need to be added or removed, we can return as soon as xfs_attr_node_addname completes, rather than rolling the transaction with an -EAGAIN return. This extra loop does not hurt anything right now, but it will be a problem later when we get into log items because we end up with an empty log transaction. So, add a simple check to cut out the unneeded iteration.
--- fs/xfs/libxfs/xfs_attr.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/xfs/libxfs/xfs_attr.c +8 -0
@@ -412,6 +412,14 @@ xfs_attr_set_iter(if (error)return error; +/* +* If addname was successful, and we dont need to alloc +* or remove anymore blks, we're done. +*/ +if (!args->rmtblkno && + !(args->op_flags &XFS_DA_OP_RENAME )) +return 0 ; + dac->dela_state =XFS_DAS_FOUND_NBLK ; }trace_xfs_attr_set_iter_return (dac->dela_state, args->dp);
Signature · 1 line
2.25.1
PATCH v28 4/15 xfs: Set up infrastructure for log attribute replay
In reply to Allison HendersonCurrently attributes are modified directly across one or more transactions. But they are not logged or replayed in the event of an error. The goal of log attr replay is to enable logging and replaying of attribute operations using the existing delayed operations infrastructure. This will later enable the attributes to become part of larger multi part operations that also must first be recorded to the log. This is mostly of interest in the scheme of parent pointers which would need to maintain an attribute containing parent inode information any time an inode is moved, created, or removed. Parent pointers would then be of interest to any feature that would need to quickly derive an inode path from the mount point. Online scrub, nfs lookups and fs grow or shrink operations are all features that could take advantage of this.
This patch adds two new log item types for setting or removing attributes as deferred operations. The xfs_attri_log_item will log an intent to set or remove an attribute. The corresponding xfs_attrd_log_item holds a reference to the xfs_attri_log_item and is freed once the transaction is done. Both log items use a generic xfs_attr_log_format structure that contains the attribute name, value, flags, inode, and an op_flag that indicates if the operations is a set or remove.
--- fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_attr.c | 42 ++- fs/xfs/libxfs/xfs_attr.h | 38 +++ fs/xfs/libxfs/xfs_defer.c | 10 +- fs/xfs/libxfs/xfs_defer.h | 2 + fs/xfs/libxfs/xfs_log_format.h | 44 +++- fs/xfs/libxfs/xfs_log_recover.h | 2 + fs/xfs/scrub/common.c | 2 + fs/xfs/xfs_attr_item.c | 441 ++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 46 ++++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 2 + fs/xfs/xfs_log.c | 4 + fs/xfs/xfs_log.h | 11 + fs/xfs/xfs_log_recover.c | 2 + fs/xfs/xfs_ondisk.h | 2 + 17 files changed, 646 insertions(+), 6 deletions(-)
fs/xfs/Makefile +1 -0
@@ -102,6 +102,7 @@ xfs-y += xfs_log.o \ xfs_buf_item_recover.o \ xfs_dquot_item_recover.o \ xfs_extfree_item.o \ + xfs_attr_item.o \ xfs_icreate_item.o \ xfs_inode_item.o \ xfs_inode_item_recover.o \
fs/xfs/libxfs/xfs_attr.c +39 -3
66 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr.h +38 -0
@@ -28,6 +28,11 @@ struct xfs_attr_list_context;*/ #define ATTR_MAX_VALUELEN (64*1024)/* max length of a value */ +static inline bool xfs_has_larp (struct xfs_mount *mp) +{ +return false; +} +/* * Kernel-internal version of the attrlist cursor. */
@@ -461,6 +466,11 @@ enum xfs_delattr_state {struct xfs_delattr_context {struct xfs_da_args *da_args; +/* +* Used by xfs_attr_set to hold a leaf buffer across a transaction roll +*/ +struct xfs_buf *leaf_bp; +/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ struct xfs_bmbt_irec map;xfs_dablk_t lblkno;
@@ -474,6 +484,23 @@ struct xfs_delattr_context {enum xfs_delattr_state dela_state; }; +/* +* List of attrs to commit later. +*/ +struct xfs_attr_item { +struct xfs_delattr_context xattri_dac; + +/* +* Indicates if the attr operation is a set or a remove +* XFS_ATTR_OP_FLAGS_{SET,REMOVE} +*/ +unsigned int xattri_op_flags; + +/* used to log this item to an intent */ +struct list_head xattri_list; +}; + +/*======================================================================== * Function prototypes for the kernel. *========================================================================*/
@@ -490,10 +517,21 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args);int xfs_attr_get (struct xfs_da_args *args);int xfs_attr_set (struct xfs_da_args *args);int xfs_attr_set_args (struct xfs_da_args *args); +int xfs_attr_set_iter (struct xfs_delattr_context *dac, +struct xfs_buf **leaf_bp);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_remove_iter (struct xfs_delattr_context *dac);bool xfs_attr_namecheck (const void *name,size_t length);void xfs_delattr_context_init (struct xfs_delattr_context *dac,struct xfs_da_args *args); +int xfs_attr_calc_size (struct xfs_da_args *args,int *local); + +extern struct kmem_cache *xfs_attri_cache; +extern struct kmem_cache *xfs_attrd_cache; + +int __init xfs_attri_init_cache (void ); +void xfs_attri_destroy_cache (void ); +int __init xfs_attrd_init_cache (void ); +void xfs_attrd_destroy_cache (void );#endif /* __XFS_ATTR_H__ */
fs/xfs/libxfs/xfs_defer.c +9 -1
@@ -23,6 +23,7 @@#include "xfs_bmap.h" #include "xfs_alloc.h" #include "xfs_buf.h" +#include "xfs_attr.h" static struct kmem_cache *xfs_defer_pending_cache;
@@ -870,7 +871,12 @@ xfs_defer_init_item_caches(void) error =xfs_extfree_intent_init_cache ();if (error) goto err; - + error =xfs_attri_init_cache (); +if (error) + goto err; + error =xfs_attrd_init_cache (); +if (error) + goto err;return 0 ; err:xfs_defer_destroy_item_caches ();
@@ -881,6 +887,8 @@ xfs_defer_init_item_caches(void)void xfs_defer_destroy_item_caches (void ) { +xfs_attri_destroy_cache (); +xfs_attrd_destroy_cache ();xfs_extfree_intent_destroy_cache ();xfs_bmap_intent_destroy_cache ();xfs_refcount_intent_destroy_cache ();
fs/xfs/libxfs/xfs_defer.h +2 -0
@@ -63,6 +63,8 @@ extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;extern const struct xfs_defer_op_type xfs_extent_free_defer_type;extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; +extern const struct xfs_defer_op_type xfs_attr_defer_type; +/* * Deferred operation item relogging limits.
fs/xfs/libxfs/xfs_log_format.h +42 -2
66 lines not on this page · raw message
fs/xfs/libxfs/xfs_log_recover.h +2 -0
@@ -72,6 +72,8 @@ extern const struct xlog_recover_item_ops xlog_rui_item_ops;extern const struct xlog_recover_item_ops xlog_rud_item_ops;extern const struct xlog_recover_item_ops xlog_cui_item_ops;extern const struct xlog_recover_item_ops xlog_cud_item_ops; +extern const struct xlog_recover_item_ops xlog_attri_item_ops; +extern const struct xlog_recover_item_ops xlog_attrd_item_ops;/* * Macros, structures, prototypes for internal log manager use.
fs/xfs/scrub/common.c +2 -0
@@ -23,6 +23,8 @@#include "xfs_rmap_btree.h" #include "xfs_log.h" #include "xfs_trans_priv.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_reflink.h" #include "xfs_ag.h"
fs/xfs/xfs_attr_item.c new file +441 -0
441 lines not on this page · raw message
fs/xfs/xfs_attr_item.h new file +46 -0
46 lines not on this page · raw message
fs/xfs/xfs_attr_list.c +1 -0
@@ -15,6 +15,7 @@#include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_attr_sf.h" #include "xfs_attr_leaf.h"
fs/xfs/xfs_ioctl32.c +2 -0
@@ -17,6 +17,8 @@#include "xfs_itable.h" #include "xfs_fsops.h" #include "xfs_rtalloc.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_ioctl.h" #include "xfs_ioctl32.h"
fs/xfs/xfs_iops.c +2 -0
@@ -13,6 +13,8 @@#include "xfs_inode.h" #include "xfs_acl.h" #include "xfs_quota.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trans.h" #include "xfs_trace.h"
fs/xfs/xfs_log.c +4 -0
@@ -2157,6 +2157,10 @@ xlog_print_tic_res(REG_TYPE_STR (CUD_FORMAT ,"cud_format" ),REG_TYPE_STR (BUI_FORMAT ,"bui_format" ),REG_TYPE_STR (BUD_FORMAT ,"bud_format" ), +REG_TYPE_STR (ATTRI_FORMAT ,"attri_format" ), +REG_TYPE_STR (ATTRD_FORMAT ,"attrd_format" ), +REG_TYPE_STR (ATTR_NAME ,"attr name" ), +REG_TYPE_STR (ATTR_VALUE ,"attr value" ), };BUILD_BUG_ON (ARRAY_SIZE (res_type_str) !=XLOG_REG_TYPE_MAX +1 );#undef REG_TYPE_STR
fs/xfs/xfs_log.h +11 -0
@@ -21,6 +21,17 @@ struct xfs_log_vec {#define XFS_LOG_VEC_ORDERED (-1) +/* +* Calculate the log iovec length for a given user buffer length. Intended to be +* used by ->iop_size implementations when sizing buffers of arbitrary +* alignments. +*/ +static inline int +xlog_calc_iovec_len (int len) +{ +return roundup (len,sizeof (int32_t )); +} +static inline void *xlog_prepare_iovec (struct xfs_log_vec *lv,struct xfs_log_iovec **vecp,uint type)
fs/xfs/xfs_log_recover.c +2 -0
@@ -1800,6 +1800,8 @@ static const struct xlog_recover_item_ops *xlog_recover_item_ops[] = { &xlog_cud_item_ops, &xlog_bui_item_ops, &xlog_bud_item_ops, + &xlog_attri_item_ops, + &xlog_attrd_item_ops, }; static const struct xlog_recover_item_ops *
fs/xfs/xfs_ondisk.h +2 -0
@@ -132,6 +132,8 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format, 56); XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat, 20); XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_attri_log_format, 40); + XFS_CHECK_STRUCT_SIZE(struct xfs_attrd_log_format, 16);/* * The v5 superblock format extended several v4 header structures with
Signature · 1 line
2.25.1
PATCH v28 5/15 xfs: Implement attr logging and replay
In reply to Allison HendersonThis patch adds the needed routines to create, log and recover logged extended attribute intents.
--- fs/xfs/libxfs/xfs_defer.c | 1 + fs/xfs/libxfs/xfs_defer.h | 1 + fs/xfs/libxfs/xfs_format.h | 9 +- fs/xfs/xfs_attr_item.c | 360 +++++++++++++++++++++++++++++++++++++ 4 files changed, 370 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_defer.c +1 -0
@@ -186,6 +186,7 @@ static const struct xfs_defer_op_type *defer_op_types[] = { [XFS_DEFER_OPS_TYPE_RMAP] = &xfs_rmap_update_defer_type, [XFS_DEFER_OPS_TYPE_FREE] = &xfs_extent_free_defer_type, [XFS_DEFER_OPS_TYPE_AGFL_FREE] = &xfs_agfl_free_defer_type, + [XFS_DEFER_OPS_TYPE_ATTR] = &xfs_attr_defer_type, }; static void
fs/xfs/libxfs/xfs_defer.h +1 -0
@@ -19,6 +19,7 @@ enum xfs_defer_ops_type {XFS_DEFER_OPS_TYPE_RMAP ,XFS_DEFER_OPS_TYPE_FREE ,XFS_DEFER_OPS_TYPE_AGFL_FREE , +XFS_DEFER_OPS_TYPE_ATTR , XFS_DEFER_OPS_TYPE_MAX, };
fs/xfs/libxfs/xfs_format.h +8 -1
@@ -388,7 +388,9 @@ xfs_sb_has_incompat_feature(return (sbp->sb_features_incompat & feature) !=0 ; } -#define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0 +#define XFS_SB_FEAT_INCOMPAT_LOG_XATTRS (1 << 0)/* Delayed Attributes */ +#define XFS_SB_FEAT_INCOMPAT_LOG_ALL \ + (XFS_SB_FEAT_INCOMPAT_LOG_XATTRS)#define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_LOG_ALLstatic inline bool xfs_sb_has_incompat_log_feature(
@@ -413,6 +415,11 @@ xfs_sb_add_incompat_log_features( sbp->sb_features_log_incompat |= features; } +static inline bool xfs_sb_version_haslogxattrs (struct xfs_sb *sbp) +{ +return xfs_sb_is_v5 (sbp) && (sbp->sb_features_log_incompat & +XFS_SB_FEAT_INCOMPAT_LOG_XATTRS ); +}static inline bool xfs_is_quota_inode (struct xfs_sb *sbp,xfs_ino_t ino)
fs/xfs/xfs_attr_item.c +360 -0
397 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v28 6/15 xfs: Skip flip flags for delayed attrs
In reply to Allison HendersonThis is a clean up patch that skips the flip flag logic for delayed attr renames. Since the log replay keeps the inode locked, we do not need to worry about race windows with attr lookups. So we can skip over flipping the flag and the extra transaction roll for it
--- fs/xfs/libxfs/xfs_attr.c | 54 +++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_attr_leaf.c | 3 +- 2 files changed, 35 insertions(+), 22 deletions(-)
fs/xfs/libxfs/xfs_attr.c +33 -21
@@ -358,6 +358,7 @@ xfs_attr_set_iter(struct xfs_inode *dp = args->dp;struct xfs_buf *bp =NULL ;int forkoff, error =0 ; +struct xfs_mount *mp = args->dp->i_mount;/* State machine switch */ switch (dac->dela_state) {
@@ -480,16 +481,21 @@ xfs_attr_set_iter(* 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. -*/ - dac->dela_state =XFS_DAS_FLIP_LFLAG ; -trace_xfs_attr_set_iter_return (dac->dela_state, args->dp); -return -EAGAIN ; +if (!xfs_has_larp (mp)) { + error =xfs_attr3_leaf_flipflags (args); +if (error) +return error; +/* +* Commit the flag value change and start the next trans +* in series. +*/ + dac->dela_state =XFS_DAS_FLIP_LFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp); +return -EAGAIN ; + } + + fallthrough;case XFS_DAS_FLIP_LFLAG :/* * Dismantle the "old" attribute/value pair by removing a
@@ -592,17 +598,21 @@ xfs_attr_set_iter(* 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 -*/ - dac->dela_state =XFS_DAS_FLIP_NFLAG ; -trace_xfs_attr_set_iter_return (dac->dela_state, args->dp); -return -EAGAIN ; +if (!xfs_has_larp (mp)) { + error =xfs_attr3_leaf_flipflags (args); +if (error) + goto out; +/* +* Commit the flag value change and start the next trans +* in series +*/ + dac->dela_state =XFS_DAS_FLIP_NFLAG ; +trace_xfs_attr_set_iter_return (dac->dela_state, + args->dp); +return -EAGAIN ; + } + fallthrough;case XFS_DAS_FLIP_NFLAG :/* * Dismantle the "old" attribute/value pair by removing a
@@ -1270,6 +1280,7 @@ xfs_attr_node_addname_clear_incomplete( {struct xfs_da_args *args = dac->da_args;struct xfs_da_state *state =NULL ; +struct xfs_mount *mp = args->dp->i_mount;int retval =0 ;int error =0 ;
@@ -1277,7 +1288,8 @@ xfs_attr_node_addname_clear_incomplete(* 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. */ - args->attr_filter |=XFS_ATTR_INCOMPLETE ; +if (!xfs_has_larp (mp)) + args->attr_filter |=XFS_ATTR_INCOMPLETE ; state =xfs_da_state_alloc (args); state->inleaf =0 ; error =xfs_da3_node_lookup_int (state, &retval);
fs/xfs/libxfs/xfs_attr_leaf.c +2 -1
@@ -1487,7 +1487,8 @@ xfs_attr3_leaf_add_work(if (tmp) entry->flags |=XFS_ATTR_LOCAL ;if (args->op_flags &XFS_DA_OP_RENAME ) { - entry->flags |=XFS_ATTR_INCOMPLETE ; +if (!xfs_has_larp (mp)) + entry->flags |=XFS_ATTR_INCOMPLETE ;if ((args->blkno2 == args->blkno) && (args->index2 <= args->index)) { args->index2++;
Signature · 1 line
2.25.1
PATCH v28 7/15 xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
In reply to Allison HendersonThese routines set up and queue a new deferred attribute operations. These functions are meant to be called by any routine needing to initiate a deferred attribute operation as opposed to the existing inline operations. New helper function xfs_attr_item_init also added.
Finally enable delayed attributes in xfs_attr_set and xfs_attr_remove.
--- fs/xfs/libxfs/xfs_attr.c | 71 ++++++++++++++++++++++++++++++++++++++-- fs/xfs/libxfs/xfs_attr.h | 2 ++ fs/xfs/xfs_log.c | 41 +++++++++++++++++++++++ fs/xfs/xfs_log.h | 1 + 4 files changed, 112 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr.c +68 -3
@@ -25,6 +25,8 @@#include "xfs_trans_space.h" #include "xfs_trace.h" #include "xfs_attr_item.h" +#include "xfs_attr.h" +#include "xfs_log.h" struct kmem_cache *xfs_attri_cache;struct kmem_cache *xfs_attrd_cache;
@@ -729,6 +731,7 @@ xfs_attr_set(int error, local;int rmt_blks =0 ;unsigned int total; +int delayed =xfs_has_larp (mp);if (xfs_is_shutdown (dp->i_mount))return -EIO ;
@@ -785,13 +788,19 @@ xfs_attr_set( rmt_blks =xfs_attr3_rmt_blocks (mp,XFS_XATTR_SIZE_MAX ); } +if (delayed) { + error =xfs_attr_use_log_assist (mp); +if (error) +return error; + } +/* * Root fork attributes can use reserved data blocks for this * operation if necessary */ error =xfs_trans_alloc_inode (dp, &tres, total,0 , rsvd, &args->trans);if (error) -return error; + goto drop_incompat;if (args->value ||xfs_inode_hasattr (dp)) { error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK,
@@ -809,9 +818,10 @@ xfs_attr_set(if (error != -ENOATTR && error != -EEXIST ) goto out_trans_cancel; - error =xfs_attr_set_args (args); + error =xfs_attr_set_deferred (args);if (error) goto out_trans_cancel; +/* shortform attribute has already been committed */ if (!args->trans) goto out_unlock;
@@ -819,7 +829,7 @@ xfs_attr_set(if (error != -EEXIST ) goto out_trans_cancel; - error =xfs_attr_remove_args (args); + error =xfs_attr_remove_deferred (args);if (error) goto out_trans_cancel; }
@@ -841,6 +851,9 @@ xfs_attr_set( error =xfs_trans_commit (args->trans); out_unlock:xfs_iunlock (dp,XFS_ILOCK_EXCL ); +drop_incompat: +if (delayed) +xlog_drop_incompat_feat (mp->m_log);return error; out_trans_cancel:
@@ -883,6 +896,58 @@ xfs_attrd_destroy_cache(void) xfs_attrd_cache =NULL ; } +STATIC int +xfs_attr_item_init ( +struct xfs_da_args *args, +unsigned int op_flags,/* op flag (set or remove) */ +struct xfs_attr_item **attr)/* new xfs_attr_item */ +{ + +struct xfs_attr_item *new; + + new =kmem_zalloc (sizeof (struct xfs_attr_item ),KM_NOFS ); + new->xattri_op_flags = op_flags; + new->xattri_dac.da_args = args; + + *attr = new; +return 0 ; +} + +/* Sets an attribute for an inode as a deferred operation */ +int +xfs_attr_set_deferred ( +struct xfs_da_args *args) +{ +struct xfs_attr_item *new; +int error =0 ; + + error =xfs_attr_item_init (args,XFS_ATTR_OP_FLAGS_SET , &new); +if (error) +return error; + +xfs_defer_add (args->trans,XFS_DEFER_OPS_TYPE_ATTR , &new->xattri_list); + +return 0 ; +} + +/* Removes an attribute for an inode as a deferred operation */ +int +xfs_attr_remove_deferred ( +struct xfs_da_args *args) +{ + +struct xfs_attr_item *new; +int error; + + error =xfs_attr_item_init (args,XFS_ATTR_OP_FLAGS_REMOVE , &new); +if (error) +return error; + +xfs_defer_add (args->trans,XFS_DEFER_OPS_TYPE_ATTR , &new->xattri_list); + +return 0 ; +} +/*======================================================================== * External routines when attribute list is inside the inode *========================================================================*/
fs/xfs/libxfs/xfs_attr.h +2 -0
@@ -525,6 +525,8 @@ bool xfs_attr_namecheck(const void *name, size_t length);void xfs_delattr_context_init (struct xfs_delattr_context *dac,struct xfs_da_args *args);int xfs_attr_calc_size (struct xfs_da_args *args,int *local); +int xfs_attr_set_deferred (struct xfs_da_args *args); +int xfs_attr_remove_deferred (struct xfs_da_args *args);extern struct kmem_cache *xfs_attri_cache;extern struct kmem_cache *xfs_attrd_cache;
fs/xfs/xfs_log.c +41 -0
44 lines not on this page · raw message
fs/xfs/xfs_log.h +1 -0
@@ -155,5 +155,6 @@ bool xlog_force_shutdown(struct xlog *log, int shutdown_flags);void xlog_use_incompat_feat (struct xlog *log);void xlog_drop_incompat_feat (struct xlog *log); +int xfs_attr_use_log_assist (struct xfs_mount *mp);#endif /* __XFS_LOG_H__ */
Signature · 1 line
2.25.1
PATCH v28 8/15 xfs: Remove unused xfs_attr_*_args
In reply to Allison HendersonRemove xfs_attr_set_args, xfs_attr_remove_args, and xfs_attr_trans_roll. These high level loops are now driven by the delayed operations code, and can be removed.
Additionally collapse in the leaf_bp parameter of xfs_attr_set_iter since we only have one caller that passes dac->leaf_bp
--- fs/xfs/libxfs/xfs_attr.c | 106 +++----------------------------- fs/xfs/libxfs/xfs_attr.h | 8 +-- fs/xfs/libxfs/xfs_attr_remote.c | 1 - fs/xfs/xfs_attr_item.c | 9 +-- 4 files changed, 14 insertions(+), 110 deletions(-)
fs/xfs/libxfs/xfs_attr.c +9 -97
@@ -247,64 +247,9 @@ xfs_attr_is_shortform( ip->i_afp->if_nextents == 0); } -/* -* Checks to see if a delayed attribute transaction should be rolled. If so, -* transaction is finished or rolled as needed. -*/ -STATIC int -xfs_attr_trans_roll ( -struct xfs_delattr_context *dac) -{ -struct xfs_da_args *args = dac->da_args; -int error; - -if (dac->flags &XFS_DAC_DEFER_FINISH ) { -/* -* The caller wants us to finish all the deferred ops so that we -* avoid pinning the log tail with a large number of deferred -* ops. -*/ - dac->flags &= ~XFS_DAC_DEFER_FINISH ; - error =xfs_defer_finish (&args->trans); - }else - error =xfs_trans_roll_inode (&args->trans, args->dp); - -return error; -} - -/* -* Set the attribute specified in @args. -*/ -int -xfs_attr_set_args ( -struct xfs_da_args *args) -{ -struct xfs_buf *leaf_bp =NULL ; -int error =0 ; -struct xfs_delattr_context dac = { - .da_args = args, - }; - -do { - error =xfs_attr_set_iter (&dac, &leaf_bp); -if (error != -EAGAIN ) -break ; - - error =xfs_attr_trans_roll (&dac); -if (error) { -if (leaf_bp) -xfs_trans_brelse (args->trans, leaf_bp); -return error; - } - }while (true); - -return error; -} - STATIC intxfs_attr_sf_addname ( -struct xfs_delattr_context *dac, -struct xfs_buf **leaf_bp) +struct xfs_delattr_context *dac) {struct xfs_da_args *args = dac->da_args;struct xfs_inode *dp = args->dp;
@@ -323,7 +268,7 @@ xfs_attr_sf_addname(* 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); + error =xfs_attr_shortform_to_leaf (args, &dac->leaf_bp);if (error)return error;
@@ -332,7 +277,7 @@ xfs_attr_sf_addname(* push cannot grab the half-baked leaf buffer and run into problems * with the write verifier. */ -xfs_trans_bhold (args->trans, *leaf_bp); +xfs_trans_bhold (args->trans, dac->leaf_bp);/* * We're still in XFS_DAS_UNINIT state here. We've converted
@@ -340,7 +285,6 @@ xfs_attr_sf_addname(* add. */ trace_xfs_attr_sf_addname_return (XFS_DAS_UNINIT , args->dp); - dac->flags |=XFS_DAC_DEFER_FINISH ;return -EAGAIN ; }
@@ -353,8 +297,7 @@ xfs_attr_sf_addname(*/ int xfs_attr_set_iter ( -struct xfs_delattr_context *dac, -struct xfs_buf **leaf_bp) +struct xfs_delattr_context *dac) {struct xfs_da_args *args = dac->da_args;struct xfs_inode *dp = args->dp;
@@ -373,14 +316,14 @@ xfs_attr_set_iter(* release the hold once we return with a clean transaction. */ if (xfs_attr_is_shortform (dp)) -return xfs_attr_sf_addname (dac, leaf_bp); -if (*leaf_bp !=NULL ) { -xfs_trans_bhold_release (args->trans, *leaf_bp); - *leaf_bp =NULL ; +return xfs_attr_sf_addname (dac); +if (dac->leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, dac->leaf_bp); + dac->leaf_bp =NULL ; }if (xfs_attr_is_leaf (dp)) { - error =xfs_attr_leaf_try_add (args, *leaf_bp); + error =xfs_attr_leaf_try_add (args, dac->leaf_bp);if (error == -ENOSPC ) { error =xfs_attr3_leaf_to_node (args);if (error)
@@ -399,7 +342,6 @@ xfs_attr_set_iter(* be a node, so we'll fall down into the node * handling code below */ - dac->flags |=XFS_DAC_DEFER_FINISH ;trace_xfs_attr_set_iter_return ( dac->dela_state, args->dp);return -EAGAIN ;
@@ -690,32 +632,6 @@ xfs_attr_lookup(return xfs_attr_node_hasname (args,NULL ); } -/* -* Remove the attribute specified in @args. -*/ -int -xfs_attr_remove_args ( -struct xfs_da_args *args) -{ -int error; -struct xfs_delattr_context dac = { - .da_args = args, - }; - -do { - error =xfs_attr_remove_iter (&dac); -if (error != -EAGAIN ) -break ; - - error =xfs_attr_trans_roll (&dac); -if (error) -return error; - - }while (true); - -return error; -} -/* * Note: If args->value is NULL the attribute will be removed, just like the * Linux ->setattr API.
@@ -1309,7 +1225,6 @@ xfs_attr_node_addname(* this. dela_state is still unset by this function at * this point. */ - dac->flags |=XFS_DAC_DEFER_FINISH ;trace_xfs_attr_node_addname_return ( dac->dela_state, args->dp);return -EAGAIN ;
@@ -1324,7 +1239,6 @@ xfs_attr_node_addname( error =xfs_da3_split (state);if (error) goto out; - dac->flags |=XFS_DAC_DEFER_FINISH ; }else {/* * Addition succeeded, update Btree hashvals.
@@ -1578,7 +1492,6 @@ xfs_attr_remove_iter(if (error) goto out; dac->dela_state =XFS_DAS_RM_NAME ; - dac->flags |=XFS_DAC_DEFER_FINISH ;trace_xfs_attr_remove_iter_return (dac->dela_state, args->dp);return -EAGAIN ; }
@@ -1606,7 +1519,6 @@ xfs_attr_remove_iter(if (error) goto out; - dac->flags |=XFS_DAC_DEFER_FINISH ; dac->dela_state =XFS_DAS_RM_SHRINK ;trace_xfs_attr_remove_iter_return ( dac->dela_state, args->dp);
fs/xfs/libxfs/xfs_attr.h +2 -6
@@ -457,8 +457,7 @@ enum xfs_delattr_state {/* * Defines for xfs_delattr_context.flags */ -#define XFS_DAC_DEFER_FINISH 0x01/* finish the transaction */ -#define XFS_DAC_LEAF_ADDNAME_INIT 0x02/* xfs_attr_leaf_addname init*/ +#define XFS_DAC_LEAF_ADDNAME_INIT 0x01/* xfs_attr_leaf_addname init*/ /* * Context used for keeping track of delayed attribute operations
@@ -516,10 +515,7 @@ bool xfs_attr_is_leaf(struct xfs_inode *ip);int xfs_attr_get_ilocked (struct xfs_da_args *args);int xfs_attr_get (struct xfs_da_args *args);int xfs_attr_set (struct xfs_da_args *args); -int xfs_attr_set_args (struct xfs_da_args *args); -int xfs_attr_set_iter (struct xfs_delattr_context *dac, -struct xfs_buf **leaf_bp); -int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_set_iter (struct xfs_delattr_context *dac);int xfs_attr_remove_iter (struct xfs_delattr_context *dac);bool xfs_attr_namecheck (const void *name,size_t length); void xfs_delattr_context_init(struct xfs_delattr_context *dac,
fs/xfs/libxfs/xfs_attr_remote.c +0 -1
@@ -695,7 +695,6 @@ xfs_attr_rmtval_remove(* the parent */ if (!done) { - dac->flags |=XFS_DAC_DEFER_FINISH ;trace_xfs_attr_rmtval_remove_return (dac->dela_state, args->dp);return -EAGAIN ; }
fs/xfs/xfs_attr_item.c +3 -6
@@ -270,7 +270,6 @@ STATIC intxfs_xattri_finish_update ( struct xfs_delattr_context *dac, struct xfs_attrd_log_item *attrdp, - struct xfs_buf **leaf_bp, uint32_t op_flags) { struct xfs_da_args *args = dac->da_args;
@@ -280,7 +279,7 @@ xfs_xattri_finish_update(switch (op) {case XFS_ATTR_OP_FLAGS_SET : - error =xfs_attr_set_iter (dac, leaf_bp); + error =xfs_attr_set_iter (dac);break ;case XFS_ATTR_OP_FLAGS_REMOVE :ASSERT (XFS_IFORK_Q (args->dp));
@@ -390,8 +389,7 @@ xfs_attr_finish_item(*/ dac->da_args->trans = tp; - error =xfs_xattri_finish_update (dac, done_item, &dac->leaf_bp, - attr->xattri_op_flags); + error =xfs_xattri_finish_update (dac, done_item, attr->xattri_op_flags);if (error != -EAGAIN )kmem_free (attr);
@@ -550,8 +548,7 @@ xfs_attri_item_recover(xfs_trans_ijoin (tp, ip,0 ); ret =xfs_xattri_finish_update (&attr->xattri_dac, done_item, - &attr->xattri_dac.leaf_bp, - attrp->alfi_op_flags); + attrp->alfi_op_flags);if (ret == -EAGAIN ) {/* There's more work to do, so add it to this transaction */ xfs_defer_add (tp,XFS_DEFER_OPS_TYPE_ATTR , &attr->xattri_list);
Signature · 1 line
2.25.1
PATCH v28 9/15 xfs: Add log attribute error tag
In reply to Allison HendersonThis patch adds an error tag that we can use to test log attribute recovery and replay
--- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_attr_item.c | 7 +++++++ fs/xfs/xfs_error.c | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_errortag.h +3 -1
@@ -59,7 +59,8 @@#define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36#define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37#define XFS_ERRTAG_AG_RESV_FAIL 38 -#define XFS_ERRTAG_MAX 39 +#define XFS_ERRTAG_LARP 39 +#define XFS_ERRTAG_MAX 40/* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -103,5 +104,6 @@#define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1#define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1#define XFS_RANDOM_AG_RESV_FAIL 1 +#define XFS_RANDOM_LARP 1#endif /* __XFS_ERRORTAG_H_ */
fs/xfs/xfs_attr_item.c +7 -0
@@ -24,6 +24,7 @@#include "xfs_trace.h" #include "xfs_inode.h" #include "xfs_trans_space.h" +#include "xfs_errortag.h" #include "xfs_error.h" #include "xfs_log_priv.h" #include "xfs_log_recover.h"
@@ -277,6 +278,11 @@ xfs_xattri_finish_update(XFS_ATTR_OP_FLAGS_TYPE_MASK ;int error; +if (XFS_TEST_ERROR (false, args->dp->i_mount,XFS_ERRTAG_LARP )) { + error = -EIO ; + goto out; + } +switch (op) {case XFS_ATTR_OP_FLAGS_SET : error =xfs_attr_set_iter (dac);
@@ -290,6 +296,7 @@ xfs_xattri_finish_update(break ; } +out:/* * Mark the transaction dirty, even on error. This ensures the * transaction is aborted, which:
fs/xfs/xfs_error.c +3 -0
@@ -57,6 +57,7 @@ static unsigned int xfs_errortag_random_default[] = {XFS_RANDOM_REDUCE_MAX_IEXTENTS ,XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT ,XFS_RANDOM_AG_RESV_FAIL , + XFS_RANDOM_LARP, }; struct xfs_errortag_attr {
@@ -170,6 +171,7 @@ XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR);XFS_ERRORTAG_ATTR_RW (reduce_max_iextents,XFS_ERRTAG_REDUCE_MAX_IEXTENTS );XFS_ERRORTAG_ATTR_RW (bmap_alloc_minlen_extent,XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT );XFS_ERRORTAG_ATTR_RW (ag_resv_fail,XFS_ERRTAG_AG_RESV_FAIL ); +XFS_ERRORTAG_ATTR_RW (larp,XFS_ERRTAG_LARP );static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (noerror),
@@ -211,6 +213,7 @@ static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (reduce_max_iextents),XFS_ERRORTAG_ATTR_LIST (bmap_alloc_minlen_extent),XFS_ERRORTAG_ATTR_LIST (ag_resv_fail), +XFS_ERRORTAG_ATTR_LIST (larp),NULL , };ATTRIBUTE_GROUPS (xfs_errortag);
Signature · 1 line
2.25.1
PATCH v28 10/15 xfs: Add larp debug option
In reply to Allison HendersonThis patch adds a debug option to enable log attribute replay. Eventually this can be removed when delayed attrs becomes permanent.
--- fs/xfs/libxfs/xfs_attr.h | 4 ++++ fs/xfs/xfs_globals.c | 1 + fs/xfs/xfs_sysctl.h | 1 + fs/xfs/xfs_sysfs.c | 24 ++++++++++++++++++++++++ 4 files changed, 30 insertions(+)
fs/xfs/libxfs/xfs_attr.h +4 -0
@@ -30,7 +30,11 @@ struct xfs_attr_list_context;static inline bool xfs_has_larp (struct xfs_mount *mp) { +#ifdef DEBUG +return xfs_globals.larp; +#else return false; +#endif }/*
fs/xfs/xfs_globals.c +1 -0
@@ -41,5 +41,6 @@ struct xfs_globals xfs_globals = {#endif #ifdef DEBUG .pwork_threads = -1, /* automatic thread detection */ + .larp = false, /* log attribute replay */#endif };
fs/xfs/xfs_sysctl.h +1 -0
@@ -83,6 +83,7 @@ extern xfs_param_t xfs_params;struct xfs_globals {#ifdef DEBUG int pwork_threads;/* parallel workqueue threads */ +bool larp;/* log attribute replay */ #endif int log_recovery_delay;/* log recovery delay (secs) */ int mount_delay;/* mount setup delay (secs) */
fs/xfs/xfs_sysfs.c +24 -0
@@ -228,6 +228,29 @@ pwork_threads_show(return sysfs_emit (buf,"%d\n" , xfs_globals.pwork_threads); }XFS_SYSFS_ATTR_RW (pwork_threads); + +static ssize_t +larp_store ( +struct kobject *kobject, +const char *buf, +size_t count) +{ +ssize_t ret; + + ret =kstrtobool (buf, &xfs_globals.larp); +if (ret <0 ) +return ret; +return count; +} + +STATIC ssize_t +larp_show ( +struct kobject *kobject, +char *buf) +{ +return snprintf (buf,PAGE_SIZE ,"%d\n" , xfs_globals.larp); +} +XFS_SYSFS_ATTR_RW (larp);#endif /* DEBUG */ static struct attribute *xfs_dbg_attrs[] = {
@@ -237,6 +260,7 @@ static struct attribute *xfs_dbg_attrs[] = { ATTR_LIST(always_cow),#ifdef DEBUG ATTR_LIST (pwork_threads), +ATTR_LIST (larp), #endif NULL, };
Signature · 1 line
2.25.1
PATCH v28 11/15 xfs: Merge xfs_delattr_context into xfs_attr_item
In reply to Allison HendersonThis is a clean up patch that merges xfs_delattr_context into xfs_attr_item. Now that the refactoring is complete and the delayed operation infrastructure is in place, we can combine these to eliminate the extra struct
--- fs/xfs/libxfs/xfs_attr.c | 162 +++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 40 ++++---- fs/xfs/libxfs/xfs_attr_remote.c | 36 +++---- fs/xfs/libxfs/xfs_attr_remote.h | 6 +- fs/xfs/xfs_attr_item.c | 42 ++++----- 5 files changed, 143 insertions(+), 143 deletions(-)
fs/xfs/libxfs/xfs_attr.c +84 -78
@@ -59,10 +59,9 @@ STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);*/ 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_delattr_context *dac); -STATIC int xfs_attr_node_addname_find_attr(struct xfs_delattr_context *dac); -STATIC int xfs_attr_node_addname_clear_incomplete( -struct xfs_delattr_context *dac); +STATIC int xfs_attr_node_addname(struct xfs_attr_item *attr); +STATIC int xfs_attr_node_addname_find_attr(struct xfs_attr_item *attr); +STATIC int xfs_attr_node_addname_clear_incomplete(struct xfs_attr_item *attr); 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);
@@ -249,9 +248,9 @@ xfs_attr_is_shortform( STATIC intxfs_attr_sf_addname ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; +struct xfs_da_args *args = attr->xattri_da_args;struct xfs_inode *dp = args->dp;int error =0 ;
@@ -268,7 +267,7 @@ xfs_attr_sf_addname(* 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, &dac->leaf_bp); + error =xfs_attr_shortform_to_leaf (args, &attr->xattri_leaf_bp);if (error)return error;
@@ -277,7 +276,7 @@ xfs_attr_sf_addname(* push cannot grab the half-baked leaf buffer and run into problems * with the write verifier. */ -xfs_trans_bhold (args->trans, dac->leaf_bp); +xfs_trans_bhold (args->trans, attr->xattri_leaf_bp);/* * We're still in XFS_DAS_UNINIT state here. We've converted
@@ -297,16 +296,16 @@ xfs_attr_sf_addname(*/ int xfs_attr_set_iter ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; +struct xfs_da_args *args = attr->xattri_da_args;struct xfs_inode *dp = args->dp;struct xfs_buf *bp =NULL ;int forkoff, error =0 ;struct xfs_mount *mp = args->dp->i_mount;/* State machine switch */ -switch (dac->dela_state) { +switch (attr->xattri_dela_state) {case XFS_DAS_UNINIT :/* * If the fork is shortform, attempt to add the attr. If there
@@ -316,14 +315,16 @@ xfs_attr_set_iter(* release the hold once we return with a clean transaction. */ if (xfs_attr_is_shortform (dp)) -return xfs_attr_sf_addname (dac); -if (dac->leaf_bp !=NULL ) { -xfs_trans_bhold_release (args->trans, dac->leaf_bp); - dac->leaf_bp =NULL ; +return xfs_attr_sf_addname (attr); +if (attr->xattri_leaf_bp !=NULL ) { +xfs_trans_bhold_release (args->trans, + attr->xattri_leaf_bp); + attr->xattri_leaf_bp =NULL ; }if (xfs_attr_is_leaf (dp)) { - error =xfs_attr_leaf_try_add (args, dac->leaf_bp); + error =xfs_attr_leaf_try_add (args, + attr->xattri_leaf_bp);if (error == -ENOSPC ) { error =xfs_attr3_leaf_to_node (args);if (error)
@@ -343,19 +344,19 @@ xfs_attr_set_iter(* handling code below */ trace_xfs_attr_set_iter_return ( - dac->dela_state, args->dp); + attr->xattri_dela_state, args->dp);return -EAGAIN ; }else if (error) {return error; } - dac->dela_state =XFS_DAS_FOUND_LBLK ; + attr->xattri_dela_state =XFS_DAS_FOUND_LBLK ; }else { - error =xfs_attr_node_addname_find_attr (dac); + error =xfs_attr_node_addname_find_attr (attr);if (error)return error; - error =xfs_attr_node_addname (dac); + error =xfs_attr_node_addname (attr);if (error)return error;
@@ -367,9 +368,10 @@ xfs_attr_set_iter( !(args->op_flags & XFS_DA_OP_RENAME))return 0 ; - dac->dela_state =XFS_DAS_FOUND_NBLK ; + attr->xattri_dela_state =XFS_DAS_FOUND_NBLK ; } -trace_xfs_attr_set_iter_return (dac->dela_state, args->dp); +trace_xfs_attr_set_iter_return (attr->xattri_dela_state, + args->dp);return -EAGAIN ;case XFS_DAS_FOUND_LBLK :/*
@@ -380,10 +382,10 @@ xfs_attr_set_iter(*/ /* Open coded xfs_attr_rmtval_set without trans handling */ -if ((dac->flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { - dac->flags |=XFS_DAC_LEAF_ADDNAME_INIT ; +if ((attr->xattri_flags &XFS_DAC_LEAF_ADDNAME_INIT ) ==0 ) { + attr->xattri_flags |=XFS_DAC_LEAF_ADDNAME_INIT ;if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_find_space (dac); + error =xfs_attr_rmtval_find_space (attr);if (error)return error; }
@@ -393,11 +395,11 @@ xfs_attr_set_iter(* Repeat allocating remote blocks for the attr value until * blkcnt drops to zero. */ -if (dac->blkcnt >0 ) { - error =xfs_attr_rmtval_set_blk (dac); +if (attr->xattri_blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (attr);if (error)return error; -trace_xfs_attr_set_iter_return (dac->dela_state, +trace_xfs_attr_set_iter_return (attr->xattri_dela_state, args->dp);return -EAGAIN ; }
@@ -433,8 +435,8 @@ xfs_attr_set_iter(* Commit the flag value change and start the next trans * in series. */ - dac->dela_state =XFS_DAS_FLIP_LFLAG ; -trace_xfs_attr_set_iter_return (dac->dela_state, + attr->xattri_dela_state =XFS_DAS_FLIP_LFLAG ; +trace_xfs_attr_set_iter_return (attr->xattri_dela_state, args->dp);return -EAGAIN ; }
@@ -453,17 +455,18 @@ xfs_attr_set_iter( fallthrough;case XFS_DAS_RM_LBLK :/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ - dac->dela_state =XFS_DAS_RM_LBLK ; + attr->xattri_dela_state =XFS_DAS_RM_LBLK ;if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (dac); + error =xfs_attr_rmtval_remove (attr);if (error == -EAGAIN )trace_xfs_attr_set_iter_return ( - dac->dela_state, args->dp); + attr->xattri_dela_state, args->dp);if (error)return error; - dac->dela_state =XFS_DAS_RD_LEAF ; -trace_xfs_attr_set_iter_return (dac->dela_state, args->dp); + attr->xattri_dela_state =XFS_DAS_RD_LEAF ; +trace_xfs_attr_set_iter_return (attr->xattri_dela_state, + args->dp);return -EAGAIN ; }
@@ -494,7 +497,7 @@ xfs_attr_set_iter(* state. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_find_space (dac); + error =xfs_attr_rmtval_find_space (attr);if (error)return error; }
@@ -507,14 +510,14 @@ xfs_attr_set_iter(* after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ - dac->dela_state =XFS_DAS_ALLOC_NODE ; + attr->xattri_dela_state =XFS_DAS_ALLOC_NODE ;if (args->rmtblkno >0 ) { -if (dac->blkcnt >0 ) { - error =xfs_attr_rmtval_set_blk (dac); +if (attr->xattri_blkcnt >0 ) { + error =xfs_attr_rmtval_set_blk (attr);if (error)return error;trace_xfs_attr_set_iter_return ( - dac->dela_state, args->dp); + attr->xattri_dela_state, args->dp);return -EAGAIN ; }
@@ -550,8 +553,8 @@ xfs_attr_set_iter(* Commit the flag value change and start the next trans * in series */ - dac->dela_state =XFS_DAS_FLIP_NFLAG ; -trace_xfs_attr_set_iter_return (dac->dela_state, + attr->xattri_dela_state =XFS_DAS_FLIP_NFLAG ; +trace_xfs_attr_set_iter_return (attr->xattri_dela_state, args->dp);return -EAGAIN ; }
@@ -571,18 +574,19 @@ xfs_attr_set_iter( fallthrough;case XFS_DAS_RM_NBLK :/* Set state in case xfs_attr_rmtval_remove returns -EAGAIN */ - dac->dela_state =XFS_DAS_RM_NBLK ; + attr->xattri_dela_state =XFS_DAS_RM_NBLK ;if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (dac); + error =xfs_attr_rmtval_remove (attr);if (error == -EAGAIN )trace_xfs_attr_set_iter_return ( - dac->dela_state, args->dp); + attr->xattri_dela_state, args->dp);if (error)return error; - dac->dela_state =XFS_DAS_CLR_FLAG ; -trace_xfs_attr_set_iter_return (dac->dela_state, args->dp); + attr->xattri_dela_state =XFS_DAS_CLR_FLAG ; +trace_xfs_attr_set_iter_return (attr->xattri_dela_state, + args->dp);return -EAGAIN ; }
@@ -592,7 +596,7 @@ xfs_attr_set_iter(* The last state for node format. Look up the old attr and * remove it. */ - error =xfs_attr_node_addname_clear_incomplete (dac); + error =xfs_attr_node_addname_clear_incomplete (attr);break ;default :ASSERT (0 );
@@ -823,7 +827,7 @@ xfs_attr_item_init( new =kmem_zalloc (sizeof (struct xfs_attr_item ),KM_NOFS ); new->xattri_op_flags = op_flags; - new->xattri_dac.da_args = args; + new->xattri_da_args = args; *attr = new;return 0 ;
@@ -1133,16 +1137,16 @@ xfs_attr_node_hasname( STATIC intxfs_attr_node_addname_find_attr ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; +struct xfs_da_args *args = attr->xattri_da_args;int retval;/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - retval =xfs_attr_node_hasname (args, &dac->da_state); + retval =xfs_attr_node_hasname (args, &attr->xattri_da_state);if (retval != -ENOATTR && retval != -EEXIST ) goto error;
@@ -1170,8 +1174,8 @@ xfs_attr_node_addname_find_attr(return 0 ; error: -if (dac->da_state) -xfs_da_state_free (dac->da_state); +if (attr->xattri_da_state) +xfs_da_state_free (attr->xattri_da_state);return retval; }
@@ -1192,10 +1196,10 @@ xfs_attr_node_addname_find_attr(*/ STATIC intxfs_attr_node_addname ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; -struct xfs_da_state *state = dac->da_state; +struct xfs_da_args *args = attr->xattri_da_args; +struct xfs_da_state *state = attr->xattri_da_state;struct xfs_da_state_blk *blk;int error;
@@ -1226,7 +1230,7 @@ xfs_attr_node_addname(* this point. */ trace_xfs_attr_node_addname_return ( - dac->dela_state, args->dp); + attr->xattri_dela_state, args->dp);return -EAGAIN ; }
@@ -1255,9 +1259,9 @@ xfs_attr_node_addname( STATIC intxfs_attr_node_addname_clear_incomplete ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; +struct xfs_da_args *args = attr->xattri_da_args;struct xfs_da_state *state =NULL ;struct xfs_mount *mp = args->dp->i_mount;int retval =0 ;
@@ -1361,10 +1365,10 @@ xfs_attr_leaf_mark_incomplete(*/ STATIC int xfs_attr_node_removename_setup( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; -struct xfs_da_state **state = &dac->da_state; +struct xfs_da_args *args = attr->xattri_da_args; +struct xfs_da_state **state = &attr->xattri_da_state;int error; error =xfs_attr_node_hasname (args, state);
@@ -1423,16 +1427,16 @@ xfs_attr_node_removename(*/ int xfs_attr_remove_iter ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; -struct xfs_da_state *state = dac->da_state; +struct xfs_da_args *args = attr->xattri_da_args; +struct xfs_da_state *state = attr->xattri_da_state;int retval, error =0 ;struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); -switch (dac->dela_state) { +switch (attr->xattri_dela_state) {case XFS_DAS_UNINIT :if (!xfs_inode_hasattr (dp))return -ENOATTR ;
@@ -1451,16 +1455,16 @@ xfs_attr_remove_iter(* Node format may require transaction rolls. Set up the * state context and fall into the state machine. */ -if (!dac->da_state) { - error =xfs_attr_node_removename_setup (dac); +if (!attr->xattri_da_state) { + error =xfs_attr_node_removename_setup (attr);if (error)return error; - state = dac->da_state; + state = attr->xattri_da_state; } fallthrough;case XFS_DAS_RMTBLK : - dac->dela_state =XFS_DAS_RMTBLK ; + attr->xattri_dela_state =XFS_DAS_RMTBLK ;/* * If there is an out-of-line value, de-allocate the blocks.
@@ -1473,10 +1477,10 @@ xfs_attr_remove_iter(* May return -EAGAIN. Roll and repeat until all remote * blocks are removed. */ - error =xfs_attr_rmtval_remove (dac); + error =xfs_attr_rmtval_remove (attr);if (error == -EAGAIN ) {trace_xfs_attr_remove_iter_return ( - dac->dela_state, args->dp); + attr->xattri_dela_state, args->dp);return error; }else if (error) { goto out;
@@ -1491,8 +1495,10 @@ xfs_attr_remove_iter( error =xfs_attr_refillstate (state);if (error) goto out; - dac->dela_state =XFS_DAS_RM_NAME ; -trace_xfs_attr_remove_iter_return (dac->dela_state, args->dp); + + attr->xattri_dela_state =XFS_DAS_RM_NAME ; +trace_xfs_attr_remove_iter_return ( + attr->xattri_dela_state, args->dp);return -EAGAIN ; }
@@ -1502,7 +1508,7 @@ xfs_attr_remove_iter(* If we came here fresh from a transaction roll, reattach all * the buffers to the current transaction. */ -if (dac->dela_state ==XFS_DAS_RM_NAME ) { +if (attr->xattri_dela_state ==XFS_DAS_RM_NAME ) { error =xfs_attr_refillstate (state);if (error) goto out;
@@ -1519,9 +1525,9 @@ xfs_attr_remove_iter(if (error) goto out; - dac->dela_state =XFS_DAS_RM_SHRINK ; + attr->xattri_dela_state =XFS_DAS_RM_SHRINK ;trace_xfs_attr_remove_iter_return ( - dac->dela_state, args->dp); + attr->xattri_dela_state, args->dp);return -EAGAIN ; }
fs/xfs/libxfs/xfs_attr.h +17 -23
@@ -434,7 +434,7 @@ struct xfs_attr_list_context {*/ /* -* Enum values for xfs_delattr_context.da_state +* Enum values for xfs_attr_item.xattri_da_state * * These values are used by delayed attribute operations to keep track of where * they were before they returned -EAGAIN. A return code of -EAGAIN signals the
@@ -459,39 +459,32 @@ enum xfs_delattr_state { };/* -* Defines for xfs_delattr_context.flags +* Defines for xfs_attr_item.xattri_flags */ #define XFS_DAC_LEAF_ADDNAME_INIT 0x01/* xfs_attr_leaf_addname init*/ /* * Context used for keeping track of delayed attribute operations */ -struct xfs_delattr_context { -struct xfs_da_args *da_args; +struct xfs_attr_item { +struct xfs_da_args *xattri_da_args;/* * Used by xfs_attr_set to hold a leaf buffer across a transaction roll */ -struct xfs_buf *leaf_bp; +struct xfs_buf *xattri_leaf_bp;/* Used in xfs_attr_rmtval_set_blk to roll through allocating blocks */ -struct xfs_bmbt_irec map; -xfs_dablk_t lblkno; -int blkcnt; +struct xfs_bmbt_irec xattri_map; +xfs_dablk_t xattri_lblkno; +int xattri_blkcnt;/* Used in xfs_attr_node_removename to roll through removing blocks */ -struct xfs_da_state *da_state; +struct xfs_da_state *xattri_da_state;/* Used to keep track of current state of delayed operation */ -unsigned int flags; -enum xfs_delattr_state dela_state; -}; - -/* -* List of attrs to commit later. -*/ -struct xfs_attr_item { -struct xfs_delattr_context xattri_dac; +unsigned int xattri_flags; +enum xfs_delattr_state xattri_dela_state;/* * Indicates if the attr operation is a set or a remove
@@ -499,7 +492,10 @@ struct xfs_attr_item {*/ unsigned int xattri_op_flags; -/* used to log this item to an intent */ +/* +* used to log this item to an intent containing a list of attrs to +* commit later +*/ struct list_head xattri_list; };
@@ -519,11 +515,9 @@ bool xfs_attr_is_leaf(struct xfs_inode *ip);int xfs_attr_get_ilocked (struct xfs_da_args *args);int xfs_attr_get (struct xfs_da_args *args);int xfs_attr_set (struct xfs_da_args *args); -int xfs_attr_set_iter (struct xfs_delattr_context *dac); -int xfs_attr_remove_iter (struct xfs_delattr_context *dac); +int xfs_attr_set_iter (struct xfs_attr_item *attr); +int xfs_attr_remove_iter (struct xfs_attr_item *attr);bool xfs_attr_namecheck (const void *name,size_t length); -void xfs_delattr_context_init (struct xfs_delattr_context *dac, -struct xfs_da_args *args);int xfs_attr_calc_size (struct xfs_da_args *args,int *local);int xfs_attr_set_deferred (struct xfs_da_args *args);int xfs_attr_remove_deferred (struct xfs_da_args *args);
fs/xfs/libxfs/xfs_attr_remote.c +19 -17
@@ -568,14 +568,14 @@ xfs_attr_rmtval_stale(*/ int xfs_attr_rmtval_find_space ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; -struct xfs_bmbt_irec *map = &dac->map; +struct xfs_da_args *args = attr->xattri_da_args; +struct xfs_bmbt_irec *map = &attr->xattri_map;int error; - dac->lblkno =0 ; - dac->blkcnt =0 ; + attr->xattri_lblkno =0 ; + attr->xattri_blkcnt =0 ; args->rmtblkcnt =0 ; args->rmtblkno =0 ;memset (map,0 ,sizeof (struct xfs_bmbt_irec ));
@@ -584,8 +584,8 @@ xfs_attr_rmtval_find_space(if (error)return error; - dac->blkcnt = args->rmtblkcnt; - dac->lblkno = args->rmtblkno; + attr->xattri_blkcnt = args->rmtblkcnt; + attr->xattri_lblkno = args->rmtblkno;return 0 ; }
@@ -598,17 +598,18 @@ xfs_attr_rmtval_find_space(*/ int xfs_attr_rmtval_set_blk ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; +struct xfs_da_args *args = attr->xattri_da_args;struct xfs_inode *dp = args->dp; -struct xfs_bmbt_irec *map = &dac->map; +struct xfs_bmbt_irec *map = &attr->xattri_map;int nmap;int error; nmap =1 ; - error =xfs_bmapi_write (args->trans, dp, (xfs_fileoff_t )dac->lblkno, - dac->blkcnt,XFS_BMAPI_ATTRFORK , args->total, + error =xfs_bmapi_write (args->trans, dp, + (xfs_fileoff_t )attr->xattri_lblkno, + attr->xattri_blkcnt,XFS_BMAPI_ATTRFORK , args->total, map, &nmap);if (error)return error;
@@ -618,8 +619,8 @@ xfs_attr_rmtval_set_blk( (map->br_startblock != HOLESTARTBLOCK));/* roll attribute extent map forwards */ - dac->lblkno += map->br_blockcount; - dac->blkcnt -= map->br_blockcount; + attr->xattri_lblkno += map->br_blockcount; + attr->xattri_blkcnt -= map->br_blockcount;return 0 ; }
@@ -673,9 +674,9 @@ xfs_attr_rmtval_invalidate(*/ int xfs_attr_rmtval_remove ( -struct xfs_delattr_context *dac) +struct xfs_attr_item *attr) { -struct xfs_da_args *args = dac->da_args; +struct xfs_da_args *args = attr->xattri_da_args;int error, done;/*
@@ -695,7 +696,8 @@ xfs_attr_rmtval_remove(* the parent */ if (!done) { -trace_xfs_attr_rmtval_remove_return (dac->dela_state, args->dp); +trace_xfs_attr_rmtval_remove_return (attr->xattri_dela_state, + args->dp);return -EAGAIN ; }
fs/xfs/libxfs/xfs_attr_remote.h +3 -3
@@ -12,9 +12,9 @@ int xfs_attr_rmtval_get(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_rmtval_remove (struct xfs_attr_item *attr);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); +int xfs_attr_rmtval_set_blk (struct xfs_attr_item *attr); +int xfs_attr_rmtval_find_space (struct xfs_attr_item *attr);#endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_attr_item.c +20 -22
100 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v28 12/15 xfs: Add helper function xfs_attr_leaf_addname
In reply to Allison HendersonThis patch adds a helper function xfs_attr_leaf_addname. While this does help to break down xfs_attr_set_iter, it does also hoist out some of the state management. This patch has been moved to the end of the clean up series for further discussion.
--- fs/xfs/libxfs/xfs_attr.c | 110 +++++++++++++++++++++------------------ fs/xfs/xfs_trace.h | 1 + 2 files changed, 61 insertions(+), 50 deletions(-)
fs/xfs/libxfs/xfs_attr.c +60 -50
@@ -287,6 +287,65 @@ xfs_attr_sf_addname(return -EAGAIN ; } +STATIC int +xfs_attr_leaf_addname ( +struct xfs_attr_item *attr) +{ +struct xfs_da_args *args = attr->xattri_da_args; +struct xfs_inode *dp = args->dp; +int error; + +if (xfs_attr_is_leaf (dp)) { + error =xfs_attr_leaf_try_add (args, attr->xattri_leaf_bp); +if (error == -ENOSPC ) { + 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. +* +* At this point, we are still in XFS_DAS_UNINIT, but +* when we come back, we'll be a node, so we'll fall +* down into the node handling code below +*/ +trace_xfs_attr_set_iter_return ( + attr->xattri_dela_state, args->dp); +return -EAGAIN ; + } + +if (error) +return error; + + attr->xattri_dela_state =XFS_DAS_FOUND_LBLK ; + }else { + error =xfs_attr_node_addname_find_attr (attr); +if (error) +return error; + + error =xfs_attr_node_addname (attr); +if (error) +return error; + +/* +* If addname was successful, and we dont need to alloc or +* remove anymore blks, we're done. +*/ +if (!args->rmtblkno && + !(args->op_flags &XFS_DA_OP_RENAME )) +return 0 ; + + attr->xattri_dela_state =XFS_DAS_FOUND_NBLK ; + } + +trace_xfs_attr_leaf_addname_return (attr->xattri_dela_state, args->dp); +return -EAGAIN ; +} +/* * Set the attribute specified in @args. * This routine is meant to function as a delayed operation, and may return
@@ -322,57 +381,8 @@ xfs_attr_set_iter( attr->xattri_leaf_bp =NULL ; } -if (xfs_attr_is_leaf (dp)) { - error =xfs_attr_leaf_try_add (args, - attr->xattri_leaf_bp); -if (error == -ENOSPC ) { - 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. -* -* At this point, we are still in -* XFS_DAS_UNINIT, but when we come back, we'll -* be a node, so we'll fall down into the node -* handling code below -*/ -trace_xfs_attr_set_iter_return ( - attr->xattri_dela_state, args->dp); -return -EAGAIN ; - }else if (error) { -return error; - } - - attr->xattri_dela_state =XFS_DAS_FOUND_LBLK ; - }else { - error =xfs_attr_node_addname_find_attr (attr); -if (error) -return error; +return xfs_attr_leaf_addname (attr); - error =xfs_attr_node_addname (attr); -if (error) -return error; - -/* -* If addname was successful, and we dont need to alloc -* or remove anymore blks, we're done. -*/ -if (!args->rmtblkno && - !(args->op_flags &XFS_DA_OP_RENAME )) -return 0 ; - - attr->xattri_dela_state =XFS_DAS_FOUND_NBLK ; - } -trace_xfs_attr_set_iter_return (attr->xattri_dela_state, - args->dp); -return -EAGAIN ;case XFS_DAS_FOUND_LBLK :/* * If there was an out-of-line value, allocate the blocks we
fs/xfs/xfs_trace.h +1 -0
@@ -4132,6 +4132,7 @@ DEFINE_EVENT(xfs_das_state_class, name, \ TP_ARGS(das, ip))DEFINE_DAS_STATE_EVENT (xfs_attr_sf_addname_return);DEFINE_DAS_STATE_EVENT (xfs_attr_set_iter_return); +DEFINE_DAS_STATE_EVENT (xfs_attr_leaf_addname_return);DEFINE_DAS_STATE_EVENT (xfs_attr_node_addname_return);DEFINE_DAS_STATE_EVENT (xfs_attr_remove_iter_return);DEFINE_DAS_STATE_EVENT (xfs_attr_rmtval_remove_return);
Signature · 1 line
2.25.1
PATCH v28 13/15 xfs: Add helper function xfs_init_attr_trans
In reply to Allison HendersonQuick helper function to collapse duplicate code to initialize transactions for attributes
--- fs/xfs/libxfs/xfs_attr.c | 33 +++++++++++++++++++++++---------- fs/xfs/libxfs/xfs_attr.h | 2 ++ fs/xfs/xfs_attr_item.c | 12 ++---------- 3 files changed, 27 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +23 -10
@@ -202,6 +202,28 @@ xfs_attr_calc_size(return nblks; } +/* Initialize transaction reservation for attr operations */ +void +xfs_init_attr_trans ( +struct xfs_da_args *args, +struct xfs_trans_res *tres, +unsigned int *total) +{ +struct xfs_mount *mp = args->dp->i_mount; + +if (args->value) { + tres->tr_logres =M_RES (mp)->tr_attrsetm.tr_logres + +M_RES (mp)->tr_attrsetrt.tr_logres * + args->total; + tres->tr_logcount =XFS_ATTRSET_LOG_COUNT ; + tres->tr_logflags =XFS_TRANS_PERM_LOG_RES ; + *total = args->total; + }else { + *tres =M_RES (mp)->tr_attrrm; + *total =XFS_ATTRRM_SPACE_RES (mp); + } +} + STATIC int xfs_attr_try_sf_addname( struct xfs_inode *dp,
@@ -701,20 +723,10 @@ xfs_attr_set(return error; } - tres.tr_logres =M_RES (mp)->tr_attrsetm.tr_logres + -M_RES (mp)->tr_attrsetrt.tr_logres * - args->total; - 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 ); }
@@ -728,6 +740,7 @@ xfs_attr_set(* Root fork attributes can use reserved data blocks for this * operation if necessary */ +xfs_init_attr_trans (args, &tres, &total); error =xfs_trans_alloc_inode (dp, &tres, total,0 , rsvd, &args->trans);if (error) goto drop_incompat;
fs/xfs/libxfs/xfs_attr.h +2 -0
@@ -519,6 +519,8 @@ int xfs_attr_set_iter(struct xfs_attr_item *attr);int xfs_attr_remove_iter (struct xfs_attr_item *attr);bool xfs_attr_namecheck (const void *name,size_t length);int xfs_attr_calc_size (struct xfs_da_args *args,int *local); +void xfs_init_attr_trans (struct xfs_da_args *args,struct xfs_trans_res *tres, +unsigned int *total);int xfs_attr_set_deferred (struct xfs_da_args *args);int xfs_attr_remove_deferred (struct xfs_da_args *args);
fs/xfs/xfs_attr_item.c +2 -10
@@ -532,17 +532,9 @@ xfs_attri_item_recover( args->value = attrip->attri_value; args->valuelen = attrp->alfi_value_len; args->total =xfs_attr_calc_size (args, &local); - - tres.tr_logres =M_RES (mp)->tr_attrsetm.tr_logres + -M_RES (mp)->tr_attrsetrt.tr_logres * - args->total; - tres.tr_logcount =XFS_ATTRSET_LOG_COUNT ; - tres.tr_logflags =XFS_TRANS_PERM_LOG_RES ; - total = args->total; - }else { - tres =M_RES (mp)->tr_attrrm; - total =XFS_ATTRRM_SPACE_RES (mp); } + +xfs_init_attr_trans (args, &tres, &total); error =xfs_trans_alloc (mp, &tres, total,0 ,XFS_TRANS_RESERVE , &tp);if (error) goto out;
Signature · 1 line
2.25.1
PATCH v28 14/15 xfs: add leaf split error tag
In reply to Allison HendersonAdd an error tag on xfs_da3_split to test log attribute recovery and replay.
--- fs/xfs/libxfs/xfs_da_btree.c | 4 ++++ fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_da_btree.c +4 -0
@@ -22,6 +22,7 @@#include "xfs_trace.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_errortag.h" /* * xfs_da_btree.c
@@ -482,6 +483,9 @@ xfs_da3_split(trace_xfs_da_split (state->args); +if (XFS_TEST_ERROR (false, state->mp,XFS_ERRTAG_DA_LEAF_SPLIT )) +return -EIO ; +/* * Walk back up the tree splitting/inserting/adjusting as necessary. * If we need to insert and there isn't room, split the node, then
fs/xfs/libxfs/xfs_errortag.h +3 -1
@@ -60,7 +60,8 @@#define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37#define XFS_ERRTAG_AG_RESV_FAIL 38#define XFS_ERRTAG_LARP 39 -#define XFS_ERRTAG_MAX 40 +#define XFS_ERRTAG_DA_LEAF_SPLIT 40 +#define XFS_ERRTAG_MAX 41/* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -105,5 +106,6 @@#define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1#define XFS_RANDOM_AG_RESV_FAIL 1#define XFS_RANDOM_LARP 1 +#define XFS_RANDOM_DA_LEAF_SPLIT 1#endif /* __XFS_ERRORTAG_H_ */
fs/xfs/xfs_error.c +3 -0
@@ -58,6 +58,7 @@ static unsigned int xfs_errortag_random_default[] = {XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT ,XFS_RANDOM_AG_RESV_FAIL ,XFS_RANDOM_LARP , + XFS_RANDOM_DA_LEAF_SPLIT, }; struct xfs_errortag_attr {
@@ -172,6 +173,7 @@ XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS);XFS_ERRORTAG_ATTR_RW (bmap_alloc_minlen_extent,XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT );XFS_ERRORTAG_ATTR_RW (ag_resv_fail,XFS_ERRTAG_AG_RESV_FAIL );XFS_ERRORTAG_ATTR_RW (larp,XFS_ERRTAG_LARP ); +XFS_ERRORTAG_ATTR_RW (da_leaf_split,XFS_ERRTAG_DA_LEAF_SPLIT );static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (noerror),
@@ -214,6 +216,7 @@ static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (bmap_alloc_minlen_extent),XFS_ERRORTAG_ATTR_LIST (ag_resv_fail),XFS_ERRORTAG_ATTR_LIST (larp), +XFS_ERRORTAG_ATTR_LIST (da_leaf_split),NULL , };ATTRIBUTE_GROUPS (xfs_errortag);
Signature · 1 line
2.25.1
PATCH v28 15/15 xfs: add leaf to node error tag
In reply to Allison HendersonAdd an error tag on xfs_attr3_leaf_to_node to test log attribute recovery and replay.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 6 ++++++ fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_attr_leaf.c +6 -0
@@ -28,6 +28,7 @@#include "xfs_dir2.h" #include "xfs_log.h" #include "xfs_ag.h" +#include "xfs_errortag.h" /*
@@ -1189,6 +1190,11 @@ xfs_attr3_leaf_to_node(trace_xfs_attr_leaf_to_node (args); +if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_ATTR_LEAF_TO_NODE )) { + error = -EIO ; + goto out; + } + error =xfs_da_grow_inode (args, &blkno);if (error) goto out;
fs/xfs/libxfs/xfs_errortag.h +3 -1
@@ -61,7 +61,8 @@#define XFS_ERRTAG_AG_RESV_FAIL 38#define XFS_ERRTAG_LARP 39#define XFS_ERRTAG_DA_LEAF_SPLIT 40 -#define XFS_ERRTAG_MAX 41 +#define XFS_ERRTAG_ATTR_LEAF_TO_NODE 41 +#define XFS_ERRTAG_MAX 42/* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -107,5 +108,6 @@#define XFS_RANDOM_AG_RESV_FAIL 1#define XFS_RANDOM_LARP 1#define XFS_RANDOM_DA_LEAF_SPLIT 1 +#define XFS_RANDOM_ATTR_LEAF_TO_NODE 1#endif /* __XFS_ERRORTAG_H_ */
fs/xfs/xfs_error.c +3 -0
@@ -59,6 +59,7 @@ static unsigned int xfs_errortag_random_default[] = {XFS_RANDOM_AG_RESV_FAIL ,XFS_RANDOM_LARP ,XFS_RANDOM_DA_LEAF_SPLIT , + XFS_RANDOM_ATTR_LEAF_TO_NODE, }; struct xfs_errortag_attr {
@@ -174,6 +175,7 @@ XFS_ERRORTAG_ATTR_RW(bmap_alloc_minlen_extent, XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTEXFS_ERRORTAG_ATTR_RW (ag_resv_fail,XFS_ERRTAG_AG_RESV_FAIL );XFS_ERRORTAG_ATTR_RW (larp,XFS_ERRTAG_LARP );XFS_ERRORTAG_ATTR_RW (da_leaf_split,XFS_ERRTAG_DA_LEAF_SPLIT ); +XFS_ERRORTAG_ATTR_RW (attr_leaf_to_node,XFS_ERRTAG_ATTR_LEAF_TO_NODE );static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (noerror),
@@ -217,6 +219,7 @@ static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (ag_resv_fail),XFS_ERRORTAG_ATTR_LIST (larp),XFS_ERRORTAG_ATTR_LIST (da_leaf_split), +XFS_ERRORTAG_ATTR_LIST (attr_leaf_to_node),NULL , };ATTRIBUTE_GROUPS (xfs_errortag);
Signature · 1 line
2.25.1
Quoted 12 lines · Allison Henderson
Hi all,
This set is a subset of a larger series parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This allows more complex operations (like parent pointers) to be broken up into multiple smaller transactions. To do this, the existing attr operations must be modified to operate as a delayed operation. This means that they cannot roll, commit, or finish transactions. Instead, they return
-EAGAINto allow the calling function to handle the transaction. In this series, we focus on only the delayed attribute portion. We will introduce parent pointers in a later set.
Quoted 7 lines
The set as a whole is a bit much to digest at once, so I usually send out the smaller sub series to reduce reviewer burn out. But the entire extended series is visible through the included github links.
Updates since v27:
xfs: don't commit the first deferred transaction without intents
Comment update
I applied this to 5.16-rc6, and turned on larp mode. generic/476 tripped over something, and this is what kasan had to say:
[ 835.381655] run fstests generic/476 at 2022-02-28 18:22:04 [ 838.008485] XFS (sdb): Mounting V5 Filesystem [ 838.035529] XFS (sdb): Ending clean mount [ 838.040528] XFS (sdb): Quotacheck needed: Please wait. [ 838.050866] XFS (sdb): Quotacheck: Done. [ 838.092369] XFS (sdb): EXPERIMENTAL logged extended attributes feature added. Use at your own risk! [ 838.092938] general protection fault, probably for non-canonical address 0xe012f573e6000046: 0000 [#1] PREEMPT SMP KASAN [ 838.099085] KASAN: maybe wild-memory-access in range [0x0097cb9f30000230-0x0097cb9f30000237] [ 838.101148] CPU: 2 PID: 4403 Comm: fsstress Not tainted 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 838.103757] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 838.105811] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs]
FWIW, gdb says this address is:
0xffffffffa06e0739 is in xlog_cil_commit (fs/xfs/xfs_log_cil.c:237). 232
233 /*
234 * if we have no shadow buffer, or it is too small, we need to 235 * reallocate it. 236 */
237 if (!lip->li_lv_shadow ||
238 buf_size > lip->li_lv_shadow->lv_size) {
239 /*
240 * We free and allocate here as a realloc would copy
241 * unnecessary data. We don't use kvzalloc() for the
I don't know what this is about, but my guess is that we freed something we weren't supposed to...?
(An overnight fstests run with v27 and larp=0 ran fine, though...)
--D
[ 838.107443] Code: 00 00 4c 89 f8 48 c1 e8 03 80 3c 28 00 0f 85 81 1c 00 00 4c 8b 83 80 00 00 00 4d 85 c0 74 25 49 8d 78 30 48 89 f8 48 c1 e8 03 <0f> b6 04 28 84 c0 74 08 3c 03 0f 8e 46 1c 00 00 45 39 70 30 0f 8d [ 838.111216] RSP: 0018:ffffc900050af2c0 EFLAGS: 00010202 [ 838.112339] RAX: 0012f973e6000046 RBX: ffff888047078d20 RCX: 0000000000000070 [ 838.113761] RDX: 000000000000006f RSI: ffffc900050af378 RDI: 0097cb9f30000230 [ 838.115141] RBP: dffffc0000000000 R08: 0097cb9f30000200 R09: ffff888047078d67 [ 838.116471] R10: ffffed1008e0f1ac R11: ffffc900050aef88 R12: 0000000000000000 [ 838.117796] R13: ffffffffa07f4200 R14: 00000000000000d8 R15: ffff888047078da0 [ 838.119085] FS: 00007fb959518740(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000 [ 838.120506] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 838.121516] CR2: 00007fb959581070 CR3: 0000000043ba2005 CR4: 00000000001706a0 [ 838.122743] Call Trace: [ 838.123214] <TASK> [ 838.123651] ? __mutex_lock_slowpath+0x10/0x10 [ 838.124426] ? kasan_save_stack+0x1e/0x40 [ 838.125120] ? __kasan_slab_alloc+0x66/0x80 [ 838.125835] ? xlog_cil_empty+0x90/0x90 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.127287] ? xfs_trans_log_dquot+0xe8/0x170 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.128806] ? xfs_trans_apply_dquot_deltas+0x275/0xf40 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.130405] __xfs_trans_commit+0x52b/0xc00 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.131830] ? __kasan_slab_alloc+0x66/0x80 [ 838.132503] ? xfs_trans_free_items+0x220/0x220 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.133906] ? kmem_cache_alloc+0x2c9/0x400 [ 838.134534] ? xfs_trans_dup+0x512/0x830 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.135845] ? xfs_defer_trans_roll+0x126/0x360 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.137163] ? xfs_defer_finish_noroll+0x271/0x17e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.138482] xfs_trans_roll+0x118/0x290 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.139665] ? xfs_trans_alloc_empty+0xa0/0xa0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.140933] ? xfs_defer_save_resources+0x247/0x4d0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.142175] ? xfs_attri_init+0xef/0x120 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.143320] xfs_defer_trans_roll+0x126/0x360 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.144475] ? xfs_defer_trans_abort+0x3b0/0x3b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.145636] ? xfs_attr_log_item+0x54/0x4b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.146764] ? xfs_attr_log_item+0x4b0/0x4b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.147909] ? xfs_defer_create_intents+0x145/0x2c0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.149068] xfs_defer_finish_noroll+0x271/0x17e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.150606] ? xfs_mod_fdblocks+0x18d/0x3e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.151838] ? xfs_trans_reserve_quota_bydquots+0xef/0x1b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.153239] ? xfs_defer_cancel+0x110/0x110 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.154446] ? do_raw_spin_lock+0x125/0x270 [ 838.155008] ? rwlock_bug.part.0+0x90/0x90 [ 838.155564] __xfs_trans_commit+0x3f9/0xc00 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.156795] ? xfs_trans_free_items+0x220/0x220 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.158062] ? __kasan_kmalloc+0x81/0xa0 [ 838.158594] ? xfs_trans_ichgtime+0x190/0x190 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.159823] ? xfs_trans_ichgtime+0x49/0x190 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.161040] xfs_attr_set+0xc15/0x1110 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.162195] ? xfs_attr_set_iter+0xf30/0xf30 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.163412] ? is_bpf_text_address+0x1f/0x30 [ 838.163984] ? __kernel_text_address+0x62/0xb0 [ 838.164584] ? arch_stack_walk+0x98/0xf0 [ 838.165113] xfs_xattr_set+0xec/0x190 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.166280] ? xfs_trans_alloc_ichange+0x410/0x410 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.167587] ? kasan_save_stack+0x2e/0x40 [ 838.168119] ? kasan_save_stack+0x1e/0x40 [ 838.168662] __vfs_setxattr+0xe0/0x130 [ 838.169171] ? xattr_resolve_name+0x3f0/0x3f0 [ 838.169762] __vfs_setxattr_noperm+0xec/0x2d0 [ 838.170348] vfs_setxattr+0x116/0x2d0 [ 838.170845] ? __vfs_setxattr_locked+0x200/0x200 [ 838.171469] ? __might_fault+0x4d/0x70 [ 838.171984] setxattr+0x15c/0x270 [ 838.172451] ? vfs_setxattr+0x2d0/0x2d0 [ 838.172971] ? xfs_vn_getattr+0xad/0xea0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.174144] ? __check_object_size+0x113/0x4c0 [ 838.174731] ? kasan_quarantine_put+0x21/0x1b0 [ 838.175302] ? preempt_count_add+0x7f/0x150 [ 838.175852] ? __mnt_want_write+0x155/0x230 [ 838.176420] path_setxattr+0x141/0x170 [ 838.176889] ? setxattr+0x270/0x270 [ 838.177330] __x64_sys_setxattr+0xc0/0x160 [ 838.177847] ? syscall_exit_to_user_mode+0x1d/0x40 [ 838.178441] do_syscall_64+0x35/0x80 [ 838.178893] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 838.179523] RIP: 0033:0x7fb95963b10e [ 838.179963] Code: 48 8b 0d 85 ad 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 bc 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 52 ad 0c 00 f7 d8 64 89 01 48 [ 838.182010] RSP: 002b:00007fff0d57c118 EFLAGS: 00000206 ORIG_RAX: 00000000000000bc [ 838.182874] RAX: ffffffffffffffda RBX: 00007fff0d57c160 RCX: 00007fb95963b10e [ 838.183687] RDX: 000055949a4d6670 RSI: 00007fff0d57c160 RDI: 000055949a4d6410 [ 838.184470] RBP: 000055949a4d6670 R08: 0000000000000000 R09: 00007fff0d57bfb0 [ 838.185248] R10: 000000000000002b R11: 0000000000000206 R12: 000000000000002b [ 838.186036] R13: 000055949a4d669b R14: 000055949a4d669b R15: 0000559498b43b80 [ 838.186816] </TASK> [ 838.187078] Modules linked in: xfs libcrc32c ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 xt_tcpudp ip_set_hash_ip ip_set_hash_net xt_set bfq ip_set_hash_mac ip_set nfnetlink ip6table_filter ip6_tables iptable_filter pvpanic_mmio pvpanic sch_fq_codel ip_tables x_tables overlay nfsv4 af_packet [ 838.189804] Dumping ftrace buffer: [ 838.190191] (ftrace buffer empty) [ 838.191667] ---[ end trace 0000000000000000 ]--- [ 838.192204] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs] [ 838.192978] Code: 00 00 4c 89 f8 48 c1 e8 03 80 3c 28 00 0f 85 81 1c 00 00 4c 8b 83 80 00 00 00 4d 85 c0 74 25 49 8d 78 30 48 89 f8 48 c1 e8 03 <0f> b6 04 28 84 c0 74 08 3c 03 0f 8e 46 1c 00 00 45 39 70 30 0f 8d [ 838.195051] RSP: 0018:ffffc900050af2c0 EFLAGS: 00010202 [ 838.195652] RAX: 0012f973e6000046 RBX: ffff888047078d20 RCX: 0000000000000070 [ 838.196436] RDX: 000000000000006f RSI: ffffc900050af378 RDI: 0097cb9f30000230 [ 838.197265] RBP: dffffc0000000000 R08: 0097cb9f30000200 R09: ffff888047078d67 [ 838.198062] R10: ffffed1008e0f1ac R11: ffffc900050aef88 R12: 0000000000000000 [ 838.198842] R13: ffffffffa07f4200 R14: 00000000000000d8 R15: ffff888047078da0 [ 838.199626] FS: 00007fb959518740(0000) GS:ffff88802e700000(0000) knlGS:0000000000000000 [ 838.200509] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 838.201180] CR2: 00007f8f5400c038 CR3: 0000000043ba2003 CR4: 00000000001706a0 [ 853.182840] ================================================================== [ 853.184795] BUG: KASAN: use-after-free in __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.186684] Read of size 4 at addr ffff888048148034 by task 1:1/48 [ 853.188233] [ 853.188709] CPU: 1 PID: 48 Comm: 1:1 Tainted: G D 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 853.191490] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 853.193669] Workqueue: xfs-conv/sdb xfs_end_io [xfs] [ 853.195301] Call Trace: [ 853.195993] <TASK> [ 853.196614] dump_stack_lvl+0x34/0x44 [ 853.197605] print_address_description.constprop.0+0x1f/0x160 [ 853.199079] ? __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.200387] kasan_report.cold+0x83/0xdf [ 853.201452] ? __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.202763] __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.204033] ? xfs_trans_alloc_inode+0x118/0x2c0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.206551] ? xfs_iomap_write_unwritten+0x263/0x660 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.209136] ? xfs_end_io+0x1ed/0x300 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.211404] ? process_one_work+0x688/0x1080 [ 853.212582] ? kthread+0x29e/0x340 [ 853.213506] ? ret_from_fork+0x1f/0x30 [ 853.214500] ? mutex_trylock+0x340/0x340 [ 853.215545] ? xlog_space_left+0x55/0x2e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.217905] ? kasan_unpoison+0x23/0x50 [ 853.218926] ? __kasan_slab_alloc+0x66/0x80 [ 853.220026] mutex_lock+0xdf/0xf0 [ 853.220925] ? __mutex_lock_slowpath+0x10/0x10 [ 853.222084] ? __mutex_unlock_slowpath.constprop.0+0x5e0/0x5e0 [ 853.223571] ? preempt_count_add+0x7f/0x150 [ 853.224686] ? xfs_trans_mod_dquot+0xc5/0x740 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.227057] xfs_trans_dqresv+0x6a/0xe30 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.229214] ? xfs_mod_fdblocks+0x18d/0x3e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.231277] xfs_trans_reserve_quota_bydquots+0xef/0x1b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.233588] xfs_trans_reserve_quota_nblks+0x1e7/0x4f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.235711] ? xfs_qm_dqattach_locked+0x1c/0x3f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.237611] xfs_trans_alloc_inode+0x167/0x2c0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.239483] ? xfs_trans_roll+0x290/0x290 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.241156] xfs_iomap_write_unwritten+0x263/0x660 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.242882] ? xfs_buffered_write_iomap_begin+0x2070/0x2070 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.244699] ? psi_task_switch+0x186/0x4a0 [ 853.245429] ? sgl_alloc+0x10/0x10 [ 853.246021] xfs_end_ioend+0x3b2/0x5f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.247479] xfs_end_io+0x1ed/0x300 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.248817] ? do_raw_spin_lock+0x125/0x270 [ 853.249484] ? xfs_end_ioend+0x5f0/0x5f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.250874] ? read_word_at_a_time+0xe/0x20 [ 853.251557] ? strscpy+0xa1/0x2a0 [ 853.252067] process_one_work+0x688/0x1080 [ 853.252689] worker_thread+0x5a3/0xf60 [ 853.253257] ? rescuer_thread+0xce0/0xce0 [ 853.253860] ? rescuer_thread+0xce0/0xce0 [ 853.254481] kthread+0x29e/0x340 [ 853.254959] ? kthread_complete_and_exit+0x20/0x20 [ 853.255647] ret_from_fork+0x1f/0x30 [ 853.256166] </TASK> [ 853.256514] [ 853.256767] Allocated by task 4401: [ 853.257271] kasan_save_stack+0x1e/0x40 [ 853.257826] __kasan_slab_alloc+0x66/0x80 [ 853.258375] kmem_cache_alloc_node+0x107/0x420 [ 853.258988] copy_process+0x466/0x6180 [ 853.259515] kernel_clone+0xbd/0x860 [ 853.260011] __do_sys_clone+0xaf/0xf0 [ 853.260538] do_syscall_64+0x35/0x80 [ 853.261010] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 853.261662] [ 853.261889] Freed by task 0: [ 853.262276] kasan_save_stack+0x1e/0x40 [ 853.262795] kasan_set_track+0x21/0x30 [ 853.263286] kasan_set_free_info+0x20/0x30 [ 853.263826] __kasan_slab_free+0xfc/0x140 [ 853.264343] kmem_cache_free+0xfc/0x420 [ 853.264837] rcu_core+0x562/0x12e0 [ 853.265279] __do_softirq+0x1b4/0x5c7 [ 853.265758] [ 853.265975] Last potentially related work creation: [ 853.266582] kasan_save_stack+0x1e/0x40 [ 853.267081] __kasan_record_aux_stack+0x9f/0xb0 [ 853.267665] call_rcu+0x7a/0x740 [ 853.268068] wait_consider_task+0x28a4/0x3f70 [ 853.268606] do_wait+0x5fd/0x9a0 [ 853.269010] kernel_wait4+0xf3/0x1c0 [ 853.269456] __do_sys_wait4+0xe8/0x100 [ 853.269915] do_syscall_64+0x35/0x80 [ 853.270357] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 853.270954] [ 853.271157] Second to last potentially related work creation: [ 853.271809] kasan_save_stack+0x1e/0x40 [ 853.272253] __kasan_record_aux_stack+0x9f/0xb0 [ 853.272780] call_rcu+0x7a/0x740 [ 853.273162] wait_consider_task+0x28a4/0x3f70 [ 853.273672] do_wait+0x5fd/0x9a0 [ 853.274059] kernel_wait4+0xf3/0x1c0 [ 853.274499] __do_sys_wait4+0xe8/0x100 [ 853.274925] do_syscall_64+0x35/0x80 [ 853.275334] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 853.275896] [ 853.276091] The buggy address belongs to the object at ffff888048148000 [ 853.276091] which belongs to the cache task_struct of size 8192 [ 853.277404] The buggy address is located 52 bytes inside of [ 853.277404] 8192-byte region [ffff888048148000, ffff88804814a000) [ 853.278635] The buggy address belongs to the page: [ 853.279167] page:ffffea0001205200 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x48148 [ 853.280170] head:ffffea0001205200 order:3 compound_mapcount:0 compound_pincount:0 [ 853.280971] memcg:ffff888041943881 [ 853.281364] flags: 0x4fff80000010200(slab|head|node=1|zone=1|lastcpupid=0xfff) [ 853.282145] raw: 04fff80000010200 0000000000000000 dead000000000001 ffff888004057cc0 [ 853.282979] raw: 0000000000000000 0000000000030003 00000001ffffffff ffff888041943881 [ 853.283803] page dumped because: kasan: bad access detected [ 853.284408] [ 853.284618] Memory state around the buggy address: [ 853.285148] ffff888048147f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.285940] ffff888048147f80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc [ 853.286715] >ffff888048148000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.287485] ^ [ 853.288009] ffff888048148080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.288784] ffff888048148100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.289566] ==================================================================
Quoted 51 lines · Darrick J. Wong
Quoted 12 lines · Allison Henderson
Hi all,
This set is a subset of a larger series parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This allows more complex operations (like parent pointers) to be broken up into multiple smaller transactions. To do this, the existing attr operations must be modified to operate as a delayed operation. This means that they cannot roll, commit, or finish transactions. Instead, they return
-EAGAINto allow the calling function to handle the transaction. In this series, we focus on only the delayed attribute portion. We will introduce parent pointers in a later set.Quoted 7 lines
The set as a whole is a bit much to digest at once, so I usually send out the smaller sub series to reduce reviewer burn out. But the entire extended series is visible through the included github links.
Updates since v27:
xfs: don't commit the first deferred transaction without intents
Comment updateI applied this to 5.16-rc6, and turned on larp mode. generic/476 tripped over something, and this is what kasan had to say:
[ 835.381655] run fstests generic/476 at 2022-02-28 18:22:04 [ 838.008485] XFS (sdb): Mounting V5 Filesystem [ 838.035529] XFS (sdb): Ending clean mount [ 838.040528] XFS (sdb): Quotacheck needed: Please wait. [ 838.050866] XFS (sdb): Quotacheck: Done. [ 838.092369] XFS (sdb): EXPERIMENTAL logged extended attributes feature added. Use at your own risk! [ 838.092938] general protection fault, probably for non-canonical address 0xe012f573e6000046: 0000 [#1] PREEMPT SMP KASAN [ 838.099085] KASAN: maybe wild-memory-access in range [0x0097cb9f30000230-0x0097cb9f30000237] [ 838.101148] CPU: 2 PID: 4403 Comm: fsstress Not tainted 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 838.103757] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 838.105811] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs]FWIW, gdb says this address is:
0xffffffffa06e0739is inxlog_cil_commit(fs/xfs/xfs_log_cil.c:237). 232
233 /*234 * if we have no shadow buffer, or it is too small, we need to 235 * reallocate it. 236 */237 if (!lip->li_lv_shadow ||
238buf_size>lip->li_lv_shadow->lv_size) {
239 /*
240 * We free and allocate here as a realloc would copy
241 * unnecessary data. We don't usekvzalloc()for the
Quoted 6 lines
I don't know what this is about, but my guess is that we freed something we weren't supposed to...?
(An overnight fstests run with v27 and larp=0 ran fine, though...)
--D
Hmm, ok, I will dig into this then. I dont see anything between v27 and v28 that would have cause this though, so I'm thinking what ever it is must by intermittent. I'll stick it in a loop and see if I can get a recreate today. Thanks!
Allison
Quoted 216 lines
[ 838.107443] Code: 00 00 4c 89 f8 48 c1 e8 03 80 3c 28 00 0f 85 81 1c 00 00 4c 8b 83 80 00 00 00 4d 85 c0 74 25 49 8d 78 30 48 89 f8 48 c1 e8 03 <0f> b6 04 28 84 c0 74 08 3c 03 0f 8e 46 1c 00 00 45 39 70 30 0f 8d [ 838.111216] RSP: 0018:ffffc900050af2c0 EFLAGS: 00010202 [ 838.112339] RAX: 0012f973e6000046 RBX: ffff888047078d20 RCX: 0000000000000070 [ 838.113761] RDX: 000000000000006f RSI: ffffc900050af378 RDI: 0097cb9f30000230 [ 838.115141] RBP: dffffc0000000000 R08: 0097cb9f30000200 R09: ffff888047078d67 [ 838.116471] R10: ffffed1008e0f1ac R11: ffffc900050aef88 R12: 0000000000000000 [ 838.117796] R13: ffffffffa07f4200 R14: 00000000000000d8 R15: ffff888047078da0 [ 838.119085] FS: 00007fb959518740(0000) GS:ffff88807dc00000(0000) knlGS:0000000000000000 [ 838.120506] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 838.121516] CR2: 00007fb959581070 CR3: 0000000043ba2005 CR4: 00000000001706a0 [ 838.122743] Call Trace: [ 838.123214] <TASK> [ 838.123651] ? __mutex_lock_slowpath+0x10/0x10 [ 838.124426] ? kasan_save_stack+0x1e/0x40 [ 838.125120] ? __kasan_slab_alloc+0x66/0x80 [ 838.125835] ? xlog_cil_empty+0x90/0x90 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.127287] ? xfs_trans_log_dquot+0xe8/0x170 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.128806] ? xfs_trans_apply_dquot_deltas+0x275/0xf40 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.130405] __xfs_trans_commit+0x52b/0xc00 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.131830] ? __kasan_slab_alloc+0x66/0x80 [ 838.132503] ? xfs_trans_free_items+0x220/0x220 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.133906] ? kmem_cache_alloc+0x2c9/0x400 [ 838.134534] ? xfs_trans_dup+0x512/0x830 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.135845] ? xfs_defer_trans_roll+0x126/0x360 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.137163] ? xfs_defer_finish_noroll+0x271/0x17e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.138482] xfs_trans_roll+0x118/0x290 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.139665] ? xfs_trans_alloc_empty+0xa0/0xa0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.140933] ? xfs_defer_save_resources+0x247/0x4d0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.142175] ? xfs_attri_init+0xef/0x120 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.143320] xfs_defer_trans_roll+0x126/0x360 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.144475] ? xfs_defer_trans_abort+0x3b0/0x3b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.145636] ? xfs_attr_log_item+0x54/0x4b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.146764] ? xfs_attr_log_item+0x4b0/0x4b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.147909] ? xfs_defer_create_intents+0x145/0x2c0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.149068] xfs_defer_finish_noroll+0x271/0x17e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.150606] ? xfs_mod_fdblocks+0x18d/0x3e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.151838] ? xfs_trans_reserve_quota_bydquots+0xef/0x1b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.153239] ? xfs_defer_cancel+0x110/0x110 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.154446] ? do_raw_spin_lock+0x125/0x270 [ 838.155008] ? rwlock_bug.part.0+0x90/0x90 [ 838.155564] __xfs_trans_commit+0x3f9/0xc00 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.156795] ? xfs_trans_free_items+0x220/0x220 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.158062] ? __kasan_kmalloc+0x81/0xa0 [ 838.158594] ? xfs_trans_ichgtime+0x190/0x190 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.159823] ? xfs_trans_ichgtime+0x49/0x190 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.161040] xfs_attr_set+0xc15/0x1110 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.162195] ? xfs_attr_set_iter+0xf30/0xf30 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.163412] ? is_bpf_text_address+0x1f/0x30 [ 838.163984] ? __kernel_text_address+0x62/0xb0 [ 838.164584] ? arch_stack_walk+0x98/0xf0 [ 838.165113] xfs_xattr_set+0xec/0x190 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.166280] ? xfs_trans_alloc_ichange+0x410/0x410 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.167587] ? kasan_save_stack+0x2e/0x40 [ 838.168119] ? kasan_save_stack+0x1e/0x40 [ 838.168662] __vfs_setxattr+0xe0/0x130 [ 838.169171] ? xattr_resolve_name+0x3f0/0x3f0 [ 838.169762] __vfs_setxattr_noperm+0xec/0x2d0 [ 838.170348] vfs_setxattr+0x116/0x2d0 [ 838.170845] ? __vfs_setxattr_locked+0x200/0x200 [ 838.171469] ? __might_fault+0x4d/0x70 [ 838.171984] setxattr+0x15c/0x270 [ 838.172451] ? vfs_setxattr+0x2d0/0x2d0 [ 838.172971] ? xfs_vn_getattr+0xad/0xea0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 838.174144] ? __check_object_size+0x113/0x4c0 [ 838.174731] ? kasan_quarantine_put+0x21/0x1b0 [ 838.175302] ? preempt_count_add+0x7f/0x150 [ 838.175852] ? __mnt_want_write+0x155/0x230 [ 838.176420] path_setxattr+0x141/0x170 [ 838.176889] ? setxattr+0x270/0x270 [ 838.177330] __x64_sys_setxattr+0xc0/0x160 [ 838.177847] ? syscall_exit_to_user_mode+0x1d/0x40 [ 838.178441] do_syscall_64+0x35/0x80 [ 838.178893] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 838.179523] RIP: 0033:0x7fb95963b10e [ 838.179963] Code: 48 8b 0d 85 ad 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 bc 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 52 ad 0c 00 f7 d8 64 89 01 48 [ 838.182010] RSP: 002b:00007fff0d57c118 EFLAGS: 00000206 ORIG_RAX: 00000000000000bc [ 838.182874] RAX: ffffffffffffffda RBX: 00007fff0d57c160 RCX: 00007fb95963b10e [ 838.183687] RDX: 000055949a4d6670 RSI: 00007fff0d57c160 RDI: 000055949a4d6410 [ 838.184470] RBP: 000055949a4d6670 R08: 0000000000000000 R09: 00007fff0d57bfb0 [ 838.185248] R10: 000000000000002b R11: 0000000000000206 R12: 000000000000002b [ 838.186036] R13: 000055949a4d669b R14: 000055949a4d669b R15: 0000559498b43b80 [ 838.186816] </TASK> [ 838.187078] Modules linked in: xfs libcrc32c ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 xt_tcpudp ip_set_hash_ip ip_set_hash_net xt_set bfq ip_set_hash_mac ip_set nfnetlink ip6table_filter ip6_tables iptable_filter pvpanic_mmio pvpanic sch_fq_codel ip_tables x_tables overlay nfsv4 af_packet [ 838.189804] Dumping ftrace buffer: [ 838.190191] (ftrace buffer empty) [ 838.191667] ---[ end trace 0000000000000000 ]--- [ 838.192204] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs] [ 838.192978] Code: 00 00 4c 89 f8 48 c1 e8 03 80 3c 28 00 0f 85 81 1c 00 00 4c 8b 83 80 00 00 00 4d 85 c0 74 25 49 8d 78 30 48 89 f8 48 c1 e8 03 <0f> b6 04 28 84 c0 74 08 3c 03 0f 8e 46 1c 00 00 45 39 70 30 0f 8d [ 838.195051] RSP: 0018:ffffc900050af2c0 EFLAGS: 00010202 [ 838.195652] RAX: 0012f973e6000046 RBX: ffff888047078d20 RCX: 0000000000000070 [ 838.196436] RDX: 000000000000006f RSI: ffffc900050af378 RDI: 0097cb9f30000230 [ 838.197265] RBP: dffffc0000000000 R08: 0097cb9f30000200 R09: ffff888047078d67 [ 838.198062] R10: ffffed1008e0f1ac R11: ffffc900050aef88 R12: 0000000000000000 [ 838.198842] R13: ffffffffa07f4200 R14: 00000000000000d8 R15: ffff888047078da0 [ 838.199626] FS: 00007fb959518740(0000) GS:ffff88802e700000(0000) knlGS:0000000000000000 [ 838.200509] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 838.201180] CR2: 00007f8f5400c038 CR3: 0000000043ba2003 CR4: 00000000001706a0 [ 853.182840] ================================================================== [ 853.184795] BUG: KASAN: use-after-free in __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.186684] Read of size 4 at addr ffff888048148034 by task 1:1/48 [ 853.188233] [ 853.188709] CPU: 1 PID: 48 Comm: 1:1 Tainted: G D 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 853.191490] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 853.193669] Workqueue: xfs-conv/sdb xfs_end_io [xfs] [ 853.195301] Call Trace: [ 853.195993] <TASK> [ 853.196614] dump_stack_lvl+0x34/0x44 [ 853.197605] print_address_description.constprop.0+0x1f/0x160 [ 853.199079] ? __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.200387] kasan_report.cold+0x83/0xdf [ 853.201452] ? __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.202763] __mutex_lock.constprop.0+0x133b/0x13c0 [ 853.204033] ? xfs_trans_alloc_inode+0x118/0x2c0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.206551] ? xfs_iomap_write_unwritten+0x263/0x660 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.209136] ? xfs_end_io+0x1ed/0x300 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.211404] ? process_one_work+0x688/0x1080 [ 853.212582] ? kthread+0x29e/0x340 [ 853.213506] ? ret_from_fork+0x1f/0x30 [ 853.214500] ? mutex_trylock+0x340/0x340 [ 853.215545] ? xlog_space_left+0x55/0x2e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.217905] ? kasan_unpoison+0x23/0x50 [ 853.218926] ? __kasan_slab_alloc+0x66/0x80 [ 853.220026] mutex_lock+0xdf/0xf0 [ 853.220925] ? __mutex_lock_slowpath+0x10/0x10 [ 853.222084] ? __mutex_unlock_slowpath.constprop.0+0x5e0/0x5e0 [ 853.223571] ? preempt_count_add+0x7f/0x150 [ 853.224686] ? xfs_trans_mod_dquot+0xc5/0x740 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.227057] xfs_trans_dqresv+0x6a/0xe30 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.229214] ? xfs_mod_fdblocks+0x18d/0x3e0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.231277] xfs_trans_reserve_quota_bydquots+0xef/0x1b0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.233588] xfs_trans_reserve_quota_nblks+0x1e7/0x4f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.235711] ? xfs_qm_dqattach_locked+0x1c/0x3f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.237611] xfs_trans_alloc_inode+0x167/0x2c0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.239483] ? xfs_trans_roll+0x290/0x290 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.241156] xfs_iomap_write_unwritten+0x263/0x660 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.242882] ? xfs_buffered_write_iomap_begin+0x2070/0x2070 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.244699] ? psi_task_switch+0x186/0x4a0 [ 853.245429] ? sgl_alloc+0x10/0x10 [ 853.246021] xfs_end_ioend+0x3b2/0x5f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.247479] xfs_end_io+0x1ed/0x300 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.248817] ? do_raw_spin_lock+0x125/0x270 [ 853.249484] ? xfs_end_ioend+0x5f0/0x5f0 [xfs ff7a0bfdb9d791b76ca0bad2f24d8adae3cf8c9d] [ 853.250874] ? read_word_at_a_time+0xe/0x20 [ 853.251557] ? strscpy+0xa1/0x2a0 [ 853.252067] process_one_work+0x688/0x1080 [ 853.252689] worker_thread+0x5a3/0xf60 [ 853.253257] ? rescuer_thread+0xce0/0xce0 [ 853.253860] ? rescuer_thread+0xce0/0xce0 [ 853.254481] kthread+0x29e/0x340 [ 853.254959] ? kthread_complete_and_exit+0x20/0x20 [ 853.255647] ret_from_fork+0x1f/0x30 [ 853.256166] </TASK> [ 853.256514] [ 853.256767] Allocated by task 4401: [ 853.257271] kasan_save_stack+0x1e/0x40 [ 853.257826] __kasan_slab_alloc+0x66/0x80 [ 853.258375] kmem_cache_alloc_node+0x107/0x420 [ 853.258988] copy_process+0x466/0x6180 [ 853.259515] kernel_clone+0xbd/0x860 [ 853.260011] __do_sys_clone+0xaf/0xf0 [ 853.260538] do_syscall_64+0x35/0x80 [ 853.261010] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 853.261662] [ 853.261889] Freed by task 0: [ 853.262276] kasan_save_stack+0x1e/0x40 [ 853.262795] kasan_set_track+0x21/0x30 [ 853.263286] kasan_set_free_info+0x20/0x30 [ 853.263826] __kasan_slab_free+0xfc/0x140 [ 853.264343] kmem_cache_free+0xfc/0x420 [ 853.264837] rcu_core+0x562/0x12e0 [ 853.265279] __do_softirq+0x1b4/0x5c7 [ 853.265758] [ 853.265975] Last potentially related work creation: [ 853.266582] kasan_save_stack+0x1e/0x40 [ 853.267081] __kasan_record_aux_stack+0x9f/0xb0 [ 853.267665] call_rcu+0x7a/0x740 [ 853.268068] wait_consider_task+0x28a4/0x3f70 [ 853.268606] do_wait+0x5fd/0x9a0 [ 853.269010] kernel_wait4+0xf3/0x1c0 [ 853.269456] __do_sys_wait4+0xe8/0x100 [ 853.269915] do_syscall_64+0x35/0x80 [ 853.270357] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 853.270954] [ 853.271157] Second to last potentially related work creation: [ 853.271809] kasan_save_stack+0x1e/0x40 [ 853.272253] __kasan_record_aux_stack+0x9f/0xb0 [ 853.272780] call_rcu+0x7a/0x740 [ 853.273162] wait_consider_task+0x28a4/0x3f70 [ 853.273672] do_wait+0x5fd/0x9a0 [ 853.274059] kernel_wait4+0xf3/0x1c0 [ 853.274499] __do_sys_wait4+0xe8/0x100 [ 853.274925] do_syscall_64+0x35/0x80 [ 853.275334] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 853.275896] [ 853.276091] The buggy address belongs to the object at ffff888048148000 [ 853.276091] which belongs to the cache task_struct of size 8192 [ 853.277404] The buggy address is located 52 bytes inside of [ 853.277404] 8192-byte region [ffff888048148000, ffff88804814a000) [ 853.278635] The buggy address belongs to the page: [ 853.279167] page:ffffea0001205200 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x48148 [ 853.280170] head:ffffea0001205200 order:3 compound_mapcount:0 compound_pincount:0 [ 853.280971] memcg:ffff888041943881 [ 853.281364] flags: 0x4fff80000010200(slab|head|node=1|zone=1|lastcpupid=0xfff) [ 853.282145] raw: 04fff80000010200 0000000000000000 dead000000000001 ffff888004057cc0 [ 853.282979] raw: 0000000000000000 0000000000030003 00000001ffffffff ffff888041943881 [ 853.283803] page dumped because: kasan: bad access detected [ 853.284408] [ 853.284618] Memory state around the buggy address: [ 853.285148] ffff888048147f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.285940] ffff888048147f80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc [ 853.286715] >ffff888048148000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.287485] ^ [ 853.288009] ffff888048148080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.288784] ffff888048148100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 853.289566] ==================================================================
Quoted 57 lines · Allison Henderson
Quoted 54 lines · Darrick J. Wong
Quoted 12 lines · Allison Henderson
Hi all,
This set is a subset of a larger series parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This allows more complex operations (like parent pointers) to be broken up into multiple smaller transactions. To do this, the existing attr operations must be modified to operate as a delayed operation. This means that they cannot roll, commit, or finish transactions. Instead, they return
-EAGAINto allow the calling function to handle the transaction. In this series, we focus on only the delayed attribute portion. We will introduce parent pointers in a later set.Quoted 7 lines
The set as a whole is a bit much to digest at once, so I usually send out the smaller sub series to reduce reviewer burn out. But the entire extended series is visible through the included github links.
Updates since v27:
xfs: don't commit the first deferred transaction without intents
Comment updateI applied this to 5.16-rc6, and turned on larp mode. generic/476 tripped over something, and this is what kasan had to say:
[ 835.381655] run fstests generic/476 at 2022-02-28 18:22:04 [ 838.008485] XFS (sdb): Mounting V5 Filesystem [ 838.035529] XFS (sdb): Ending clean mount [ 838.040528] XFS (sdb): Quotacheck needed: Please wait. [ 838.050866] XFS (sdb): Quotacheck: Done. [ 838.092369] XFS (sdb): EXPERIMENTAL logged extended attributes feature added. Use at your own risk! [ 838.092938] general protection fault, probably for non-canonical address 0xe012f573e6000046: 0000 [#1] PREEMPT SMP KASAN [ 838.099085] KASAN: maybe wild-memory-access in range [0x0097cb9f30000230-0x0097cb9f30000237] [ 838.101148] CPU: 2 PID: 4403 Comm: fsstress Not tainted 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 838.103757] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 838.105811] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs]FWIW, gdb says this address is:
0xffffffffa06e0739is inxlog_cil_commit(fs/xfs/xfs_log_cil.c:237). 232
233 /*234 * if we have no shadow buffer, or it is too small, we need to 235 * reallocate it. 236 */237 if (!lip->li_lv_shadow ||
238buf_size>lip->li_lv_shadow->lv_size) {
239 /*
240 * We free and allocate here as a realloc would copy
241 * unnecessary data. We don't usekvzalloc()for theI don't know what this is about, but my guess is that we freed something we weren't supposed to...?
Quoted 8 lines
Quoted 3 lines
(An overnight fstests run with v27 and larp=0 ran fine, though...)
--D
Hmm, ok, I will dig into this then. I dont see anything between v27 and v28 that would have cause this though, so I'm thinking what ever it is must by intermittent. I'll stick it in a loop and see if I can get a recreate today. Thanks!
I think I've figured out two of the problems here --
The biggest problem is that xfs_attri_init isn't fully initializing the xattr log item structure, which is why the CIL would crash on my system when it tried to resize what it thought was the lv_shadow buffer attached to the log item. I changed it to kmem_cache_zalloc and the problems went away; you might want to check if your kernel has some debugging kconfig feature enabled that auto-zeroes everything.
The other KASAN report has to do with the log iovec code -- it assumes that any buffer passed in has a size that is congruent with 4(?) bytes. This isn't necessarily true for the xattr name (and in principle also the value) buffer that we get from the VFS; if either is (say) 37 bytes long, you'll get 37 bytes, and KASAN will expect you to stick to that. I think with the way the slab works this isn't a real memory corruption vector, but I wouldn't put it past slob or someone to actually pack things in tightly.
Also, I'm not sure what's going on with the name/value buffers in the relog function. I patched it to try to track the buffer references, but maybe you have a better idea for why we allocate new name/value buffers for a log item relog? I wasn't sure where those new buffers ever got freed, so I <cough> ran it over with a backhoe, and it shows. :/
The following shabby patch helps us to pass generic/475 and generic/624 in LARP mode, though I have no idea if it's correct. You might want to pay attention to the "XXX:" comments I added, since that's where I got stuck.
--D
fs/xfs/libxfs/xfs_attr.c +39 -0
@@ -678,6 +678,9 @@ xfs_attr_set( {struct xfs_inode *dp = args->dp;struct xfs_mount *mp = dp->i_mount; +void *fakename =NULL , *fakeval =NULL ; +const void *oldname = args->name; +void *oldval = args->value;struct xfs_trans_res tres;bool rsvd = (args->attr_filter &XFS_ATTR_ROOT );int error, local;
@@ -692,6 +695,34 @@ xfs_attr_set(if (error)return error; +/* +* XXX: the log iovec code requires that every buffer it's given has a +* size that's an even multiple of four. If this isn't the case, create +* a shadow buffers so that we don't read past the end of the name and +* value buffers and trip KASAN. +*/ +if (xfs_has_larp (mp) && (args->namelen &3 )) { + fakename =kzalloc (roundup (args->namelen,4 ), +GFP_KERNEL |GFP_NOFS ); +if (!fakename) +return -ENOMEM ; +memcpy (fakename, args->name, args->namelen); + args->name = fakename; + } + +if (xfs_has_larp (mp) && (args->valuelen &3 )) { + fakeval =kzalloc (roundup (args->valuelen,4 ), +GFP_KERNEL |GFP_NOFS ); +if (!fakeval) { +if (fakename) +kvfree (fakename); +return -ENOMEM ; + } +memcpy (fakeval, args->value, args->valuelen); + args->value = fakeval; + } + +//trace_printk("start name 0x%px len 0x%x val 0x%px len 0x%x", args->name, args->namelen, args->value, args->valuelen); args->geo = mp->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->hashval =xfs_da_hashname (args->name, args->namelen);
@@ -797,6 +828,13 @@ xfs_attr_set( drop_incompat:if (delayed)xlog_drop_incompat_feat (mp->m_log); +//trace_printk("end name 0x%px val 0x%px", args->name, args->value); +if (fakename) +kvfree (fakename); +if (fakeval) +kvfree (fakeval); + args->value = oldval; + args->name = oldname;return error; out_trans_cancel:
@@ -852,6 +890,7 @@ xfs_attr_item_init( new->xattri_op_flags = op_flags; new->xattri_da_args = args; +//trace_printk("name 0x%px val 0x%px", args->name, args->value); *attr = new;return 0 ; }
fs/xfs/xfs_attr_item.c +75 -38
211 lines not on this page · raw message
fs/xfs/xfs_attr_item.h +3 -0
@@ -31,6 +31,9 @@ struct xfs_attri_log_item {void *attri_name;void *attri_value;struct xfs_attri_log_format attri_format; + +/* Do we actually own attri_name/value? */ +bool attri_own_buffers; };/*
Quoted 95 lines · Darrick J. Wong
Quoted 84 lines · Allison Henderson
Quoted 73 lines · Darrick J. Wong
Quoted 26 lines · Allison Henderson
Hi all,
This set is a subset of a larger series parent pointers. Delayed attributes allow
attribute operations (set and remove) to be logged and committed in the same
way that other delayed operations do. This allows more complex operations (like
parent pointers) to be broken up into multiple smaller transactions. To do
this, the existing attr operations must be modified to operate as a delayed
operation. This means that they cannot roll, commit, or finish transactions.
Instead, they return-EAGAINto allow the calling function to handle the
transaction. In this series, we focus on only the delayed attribute portion.
We will introduce parent pointers in a later set.The set as a whole is a bit much to digest at once, so I usually send out the
smaller sub series to reduce reviewer burn out. But the entire extended series
is visible through the included github links.Quoted 4 lines
Updates since v27:
xfs: don't commit the first deferred transaction without intents
Comment updateI applied this to 5.16-rc6, and turned on larp mode. generic/476 tripped over something, and this is what kasan had to say:
[ 835.381655] run fstests generic/476 at 2022-02-28 18:22:04 [ 838.008485] XFS (sdb): Mounting V5 Filesystem [ 838.035529] XFS (sdb): Ending clean mount [ 838.040528] XFS (sdb): Quotacheck needed: Please wait. [ 838.050866] XFS (sdb): Quotacheck: Done. [ 838.092369] XFS (sdb): EXPERIMENTAL logged extended attributes feature added. Use at your own risk! [ 838.092938] general protection fault, probably for non- canonical address 0xe012f573e6000046: 0000 [#1] PREEMPT SMP KASAN [ 838.099085] KASAN: maybe wild-memory-access in range [0x0097cb9f30000230-0x0097cb9f30000237] [ 838.101148] CPU: 2 PID: 4403 Comm: fsstress Not tainted 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 838.103757] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 838.105811] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs]FWIW, gdb says this address is:
0xffffffffa06e0739is inxlog_cil_commit
(fs/xfs/xfs_log_cil.c:237).
232
233 /*
234 * if we have no shadow buffer, or it is
too small, we need to
235 * reallocate it.
236 */
237 if (!lip->li_lv_shadow ||
238buf_size> lip->li_lv_shadow-Quoted 1 line
lv_size) {239 /*
240 * We free and allocate here as a
realloc would copy
241 * unnecessary data. We don't usekvzalloc()for theQuoted 8 lines
I don't know what this is about, but my guess is that we freed something
we weren't supposed to...?(An overnight fstests run with v27 and larp=0 ran fine, though...)
--D
Quoted 7 lines
Hmm, ok, I will dig into this then. I dont see anything between v27 and v28
that would have cause this though, so I'm thinking what ever it is must by
intermittent. I'll stick it in a loop and see if I can get a recreate
today. Thanks!I think I've figured out two of the problems here --
Quoted 9 lines
The biggest problem is that
xfs_attri_initisn't fully initializing the
xattr log item structure, which is why the CIL would crash on my system
when it tried to resize what it thought was thelv_shadowbuffer attached to the log item. I changed it tokmem_cache_zallocand the problems went away; you might want to check if your kernel has some debugging kconfig feature enabled that auto-zeroes everything.
Ah, ok. When ever you get a moment, would you mind shooting me a copy of your kernel config? That might be an easy way to bring together some of the differences between our testing environments.
Quoted 30 lines
The other KASAN report has to do with the log iovec code -- it assumes
that any buffer passed in has a size that is congruent with 4(?) bytes.
This isn't necessarily true for the xattr name (and in principle also the value) buffer that we get from the VFS; if either is (say) 37 bytes
long, you'll get 37 bytes, and KASAN will expect you to stick to that.
I think with the way the slab works this isn't a real memory corruption
vector, but I wouldn't put it past slob or someone to actually pack things in tightly.Also, I'm not sure what's going on with the name/value buffers in the relog function. I patched it to try to track the buffer references, but
maybe you have a better idea for why we allocate new name/value buffers
for a log item relog? I wasn't sure where those new buffers ever got freed, so I <cough> ran it over with a backhoe, and it shows. :/The following shabby patch helps us to pass generic/475 and generic/624
in LARP mode, though I have no idea if it's correct. You might want to
pay attention to the "XXX:" comments I added, since that's where I got
stuck.
Quoted 2 lines
--D
Ok, I'll dig through what you have here. Most of what youre saying makes sense, though you shouldnt have to go through all this leg work with the iovec sizes. That's supposed to be handled in xfs_attri_item_format. What ever arbitrary sized buffers are in the xfs_attri_log_item are supposed to be adjusted there.
In most cases, the name/val buffers are owned by the calling function, and in fact usually point back to the name/val pointers in the xfs_da_args. So in that case, the larp code doesnt own that. The idea is that the calling function just passes the args struct into the xfs_attr_(set/remove)_deferred which will then create a new xfs_attr_item, and stores a refrence to the xfs_da_args there. Once the calling routine finishes up the transaction, it is the callers responsibility clean up where ever the name/value pair comes from.
When the calling function invokes the defer finish routines, the defer ops code creates the intent (via the xfs_defer_op_type) which calls xfs_attr_create_intent. THis initializes and populates the xfs_attri_log_item with the name/value pointers in the xfs_attr_item
Later the iop code creates the vectors using the xfs_attri_item_size (referenced through the xfs_item_ops). Once created, it then uses the xfs_attri_item_format callback to appropriately populate those vectors.
So, it's complex, but mostly I'm just trying to adhere to what the interfaces expect
NOW.... during a replay or relog this changes slightly. These routines need to recreate the log items, but unlike the calling function in the above example, they dont span the transaction from creation to completion. THey just recreate one item and exit. SO they cant just use a xfs_da_args on the stack, nor will they be around to free anything they allocate. In this case, we simply allocate extra space off the end of the xfs_attri_log_item, store the name/val buffers there, and adjust the name/val pointers to point to this location. This is really the only reason why xfs_attri_init has an extra buffsize parameter at all. So in this case, the name/val buffers are released at the same time as the item through xfs_attri_item_free.
At least thats how it's supposed to work. Clearly something isnt following the theory, so I'll go through what you have here and maybe shoot you back another patch. Thanks for all your help here :-)
Allison
Quoted 345 lines
fs/xfs/libxfs/xfs_attr.c +3
-0@@ -678,6 +678,9 @@ xfs_attr_set( {struct xfs_inode *dp = args->dp;struct xfs_mount *mp = dp->i_mount; +void *fakename =NULL , *fakeval =NULL ; +const void *oldname = args->name; +void *oldval = args->value;struct xfs_trans_res tres;bool rsvd = (args->attr_filter &XFS_ATTR_ROOT );fs/xfs/libxfs/xfs_attr.c +2
-0int error, local;@@ -692,6 +695,34 @@ xfs_attr_set(if (error)return error; +/* +* XXX: the log iovec code requires that every buffer it's given has a
fs/xfs/libxfs/xfs_attr.c +1
-0+* size that's an even multiple of four. If this isn't the case, create
fs/xfs/libxfs/xfs_attr.c +1
-0+* a shadow buffers so that we don't read past the end of the name and
fs/xfs/libxfs/xfs_attr.c +24
-0+* value buffers and trip KASAN. +*/ +if (xfs_has_larp (mp) && (args->namelen &3 )) { + fakename =kzalloc (roundup (args->namelen,4 ), +GFP_KERNEL |GFP_NOFS ); +if (!fakename) +return -ENOMEM ; +memcpy (fakename, args->name, args->namelen); + args->name = fakename; + } + +if (xfs_has_larp (mp) && (args->valuelen &3 )) { + fakeval =kzalloc (roundup (args->valuelen,4 ), +GFP_KERNEL |GFP_NOFS ); +if (!fakeval) { +if (fakename) +kvfree (fakename); +return -ENOMEM ; + } +memcpy (fakeval, args->value, args->valuelen); + args->value = fakeval; + } + +//trace_printk("start name 0x%px len 0x%x val 0x%px len 0x%x",
args->name,args->namelen,args->value,args->valuelen);fs/xfs/libxfs/xfs_attr.c +7
-0args->geo = mp->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->hashval =xfs_da_hashname (args->name, args->namelen);@@ -797,6 +828,13 @@ xfs_attr_set( drop_incompat:if (delayed)xlog_drop_incompat_feat (mp->m_log); +//trace_printk("end name 0x%px val 0x%px", args->name, args- >value); +if (fakename) +kvfree (fakename); +if (fakeval) +kvfree (fakeval); + args->value = oldval; + args->name = oldname;return error;
out_trans_cancel:fs/xfs/libxfs/xfs_attr.c +1
-0@@ -852,6 +890,7 @@ xfs_attr_item_init( new->xattri_op_flags = op_flags; new->xattri_da_args = args; +//trace_printk("name 0x%px val 0x%px", args->name, args- >value); *attr = new;return 0 ;}
fs/xfs/xfs_attr_item.c +8
-0@@ -43,6 +43,12 @@ STATIC voidxfs_attri_item_free ( struct xfs_attri_log_item *attrip) { +if (attrip->attri_own_buffers) { +kvfree (attrip->attri_name); +if (attrip->attri_value) +kvfree (attrip->attri_value); + attrip->attri_own_buffers = false; + }kmem_free (attrip->attri_item.li_lv_shadow);kmem_free (attrip); }@@ -114,6 +120,8 @@ xfs_attri_item_format(if (attrip->attri_value_len >0 ) attrip->attri_format.alfi_size++; +//trace_printk("fmt 0x%px name 0x%px val 0x%px", &attrip- >attri_format, attrip->attri_name, attrip->attri_value); + xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ATTRI_FORMAT, &attrip->attri_format,fs/xfs/xfs_attr_item.c +28
-8sizeof(struct xfs_attri_log_format));@@ -158,19 +166,39 @@ xfs_attri_item_release( STATIC struct xfs_attri_log_item *xfs_attri_init (struct xfs_mount *mp, -int buffer_size) +unsigned int namelen, +unsigned int valuelen) {struct xfs_attri_log_item *attrip; +unsigned int buffer_size; -if (buffer_size) { - attrip =kmem_alloc (sizeof (struct xfs_attri_log_item ) + - buffer_size,KM_NOFS ); -if (attrip ==NULL ) + attrip =kmem_cache_zalloc (xfs_attri_cache,GFP_NOFS | __GFP_NOFAIL); + +if (valuelen) +ASSERT (namelen !=0 ); + +if (namelen) { + buffer_size =roundup (namelen,4 ); + attrip->attri_name =kzalloc (buffer_size, +GFP_KERNEL |GFP_NOFS | __GFP_RETRY_MAYFAIL); +if (!attrip->attri_name) { +kmem_cache_free (xfs_attri_cache, attrip); +return NULL ; + } + attrip->attri_own_buffers = true; + } + +if (valuelen) { + buffer_size =roundup (valuelen,4 ); + attrip->attri_value =kzalloc (buffer_size, +GFP_KERNEL |GFP_NOFS |__GFP_RETRY_MAYFAIL); +if (!attrip->attri_value) { +if (attrip->attri_name) +kvfree (attrip->attri_name); +kmem_cache_free (xfs_attri_cache, attrip);return NULL ; - }else { - attrip =kmem_cache_alloc (xfs_attri_cache, -GFP_NOFS | __GFP_NOFAIL); + }fs/xfs/xfs_attr_item.c +2
-0} xfs_log_item_init(mp, &attrip->attri_item, XFS_LI_ATTRI,@@ -343,6 +371,8 @@ xfs_attr_log_item( attrip->attri_value = attr->xattri_da_args->value; attrip->attri_name_len = attr->xattri_da_args->namelen; attrip->attri_value_len = attr->xattri_da_args->valuelen; + +//trace_printk("lip 0x%px fmt 0x%px name 0x%px val 0x%px", &attrip->attri_item, &attrip->attri_format, attrip->attri_name, attrip->attri_value); }/* Get an ATTRI. */
fs/xfs/xfs_attr_item.c +1
-1@@ -362,7 +392,7 @@ xfs_attr_create_intent(if (!xfs_sb_version_haslogxattrs (&mp->m_sb))return NULL ; - attrip =xfs_attri_init (mp,0 ); + attrip =xfs_attri_init (mp,0 ,0 );if (attrip ==NULL )return NULL ;@@ -434,6 +464,13 @@ xfs_attri_item_committed(* committed so these fields are no longer accessed. Clear them out of
fs/xfs/xfs_attr_item.c +1
-0* caution since we're about to free the xfs_attr_item. */ +//trace_printk("fmt 0x%px name 0x%px val 0x%px", &attrip- Quoted 1 line
attri_format,attrip->attri_name,attrip->attri_value);fs/xfs/xfs_attr_item.c +7
-3+if (attrip->attri_own_buffers) { +kvfree (attrip->attri_name); +if (attrip->attri_value) +kvfree (attrip->attri_value); + attrip->attri_own_buffers = false; + } attrip->attri_name =NULL ; attrip->attri_value =NULL ;@@ -582,17 +619,15 @@ xfs_attri_item_relog(struct xfs_attri_log_item *new_attrip;struct xfs_attri_log_format *new_attrp;struct xfs_attri_log_format *old_attrp; -int buffer_size; old_attrip =ATTRI_ITEM (intent); old_attrp = &old_attrip->attri_format; - buffer_size = old_attrp->alfi_value_len + old_attrp- >alfi_name_len; tp->t_flags |=XFS_TRANS_DIRTY ; attrdp =xfs_trans_get_attrd (tp, old_attrip);set_bit (XFS_LI_DIRTY , &attrdp->attrd_item.li_flags); - new_attrip =xfs_attri_init (tp->t_mountp, buffer_size); + new_attrip =xfs_attri_init (tp->t_mountp,0 ,0 ); new_attrp = &new_attrip->attri_format;fs/xfs/xfs_attr_item.c +5
-10new_attrp->alfi_ino = old_attrp->alfi_ino;@@ -602,19 +637,30 @@ xfs_attri_item_relog( new_attrp->alfi_attr_flags = old_attrp->alfi_attr_flags; new_attrip->attri_name_len = old_attrip->attri_name_len; - new_attrip->attri_name = ((char *)new_attrip) + -sizeof (struct xfs_attri_log_item ); -memcpy (new_attrip->attri_name, old_attrip->attri_name, - new_attrip->attri_name_len); + new_attrip->attri_name = old_attrip->attri_name; new_attrip->attri_value_len = old_attrip->attri_value_len; -if (new_attrip->attri_value_len >0 ) { - new_attrip->attri_value = new_attrip->attri_name + - new_attrip->attri_name_len; +if (new_attrip->attri_value_len >0 ) + new_attrip->attri_value = old_attrip->attri_value; -memcpy (new_attrip->attri_value, old_attrip- >attri_value, - new_attrip->attri_value_len); - } +/* +* XXX Err... so who owns the name/value buffer references, anyway?
fs/xfs/xfs_attr_item.c +1
-0+* Is it safe to drop them during ->iop_commmitted? Do we ever want to
fs/xfs/xfs_attr_item.c +1
-0+* relog a log item after _committed, in which case we no longer have
fs/xfs/xfs_attr_item.c +3
-0+* the buffer attached to the new log item. +* +* If we don't need the name and value after the first commit of the
fs/xfs/xfs_attr_item.c +1
-0+* attrip then it's ok to drop the references in _committed... but that
fs/xfs/xfs_attr_item.c +1
-0+* doesn't make sense, since most of the tx rolling is to prepare the
fs/xfs/xfs_attr_item.c +3
-0+* xattr structure to receive the name and value. +* +* OTOH -- _committed is called to write things into the AIL. By that
fs/xfs/xfs_attr_item.c +11
-11+* time we are well past formatting things into buffers, right? +* +* <zzzz tired, brain dead> +*/ + new_attrip->attri_own_buffers = old_attrip->attri_own_buffers; + old_attrip->attri_own_buffers = false;xfs_trans_add_item (tp, &new_attrip->attri_item);set_bit (XFS_LI_DIRTY , &new_attrip->attri_item.li_flags);@@ -633,10 +679,7 @@ xlog_recover_attri_commit_pass2(struct xfs_mount *mp = log->l_mp;struct xfs_attri_log_item *attrip;struct xfs_attri_log_format *attri_formatp; -char *name =NULL ; -char *value =NULL ;int region =0 ; -int buffer_size; attri_formatp = item->ri_buf[region].i_addr;@@ -646,11 +689,9 @@ xlog_recover_attri_commit_pass2(return -EFSCORRUPTED ; } - buffer_size = attri_formatp->alfi_name_len + - attri_formatp->alfi_value_len; -/* memory alloc failure will cause replay to abort */ - attrip =xfs_attri_init (mp, buffer_size); + attrip =xfs_attri_init (mp, attri_formatp->alfi_name_len, + attri_formatp->alfi_value_len);if (attrip ==NULL )return -ENOMEM ;@@ -662,11 +703,10 @@ xlog_recover_attri_commit_pass2( attrip->attri_name_len = attri_formatp->alfi_name_len; attrip->attri_value_len = attri_formatp->alfi_value_len; region++; - name = ((char *)attrip) +sizeof (struct xfs_attri_log_item ); -memcpy (name, item->ri_buf[region].i_addr, attrip- >attri_name_len); - attrip->attri_name = name; +memcpy (attrip->attri_name, item->ri_buf[region].i_addr, + attrip->attri_name_len); -if (!xfs_attr_namecheck (name, attrip->attri_name_len)) { +if (!xfs_attr_namecheck (attrip->attri_name, attrip- >attri_name_len)) {XFS_ERROR_REPORT (__func__,XFS_ERRLEVEL_LOW , mp);fs/xfs/xfs_attr_item.c +0
-1error = -EFSCORRUPTED ; goto out;@@ -674,11 +714,8 @@ xlog_recover_attri_commit_pass2(if (attrip->attri_value_len >0 ) { region++; - value = ((char *)attrip) + sizeof(struct
xfs_attri_log_item) +fs/xfs/xfs_attr_item.c +1
-2- attrip->attri_name_len; - memcpy(value, item->ri_buf[region].i_addr, + memcpy(attrip->attri_value, item-Quoted 1 line
ri_buf[region].i_addr,
fs/xfs/xfs_attr_item.c +1
-2attrip->attri_value_len); - attrip->attri_value = value; }/* @@ -706,7 +743,7 @@ xfs_trans_get_attrd(struct xfs_trans *tp,ASSERT (tp !=NULL ); - attrdp =kmem_cache_alloc (xfs_attrd_cache,GFP_NOFS | __GFP_NOFAIL); + attrdp =kmem_cache_zalloc (xfs_attrd_cache,GFP_NOFS | __GFP_NOFAIL);xfs_log_item_init(tp->t_mountp,
&attrdp->attrd_item,XFS_LI_ATTRD,fs/xfs/xfs_attr_item.c +0
-0&xfs_attrd_item_ops);fs/xfs/xfs_attr_item.h +3
-0@@ -31,6 +31,9 @@ struct xfs_attri_log_item {void *attri_name;void *attri_value;struct xfs_attri_log_format attri_format; + +/* Do we actually own attri_name/value? */ +bool attri_own_buffers; };/*
Quoted 76 lines · Darrick J. Wong
Quoted 57 lines · Allison Henderson
Quoted 54 lines · Darrick J. Wong
Quoted 12 lines · Allison Henderson
Hi all,
This set is a subset of a larger series parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This allows more complex operations (like parent pointers) to be broken up into multiple smaller transactions. To do this, the existing attr operations must be modified to operate as a delayed operation. This means that they cannot roll, commit, or finish transactions. Instead, they return
-EAGAINto allow the calling function to handle the transaction. In this series, we focus on only the delayed attribute portion. We will introduce parent pointers in a later set.Quoted 7 lines
The set as a whole is a bit much to digest at once, so I usually send out the smaller sub series to reduce reviewer burn out. But the entire extended series is visible through the included github links.
Updates since v27:
xfs: don't commit the first deferred transaction without intents
Comment updateI applied this to 5.16-rc6, and turned on larp mode. generic/476 tripped over something, and this is what kasan had to say:
[ 835.381655] run fstests generic/476 at 2022-02-28 18:22:04 [ 838.008485] XFS (sdb): Mounting V5 Filesystem [ 838.035529] XFS (sdb): Ending clean mount [ 838.040528] XFS (sdb): Quotacheck needed: Please wait. [ 838.050866] XFS (sdb): Quotacheck: Done. [ 838.092369] XFS (sdb): EXPERIMENTAL logged extended attributes feature added. Use at your own risk! [ 838.092938] general protection fault, probably for non-canonical address 0xe012f573e6000046: 0000 [#1] PREEMPT SMP KASAN [ 838.099085] KASAN: maybe wild-memory-access in range [0x0097cb9f30000230-0x0097cb9f30000237] [ 838.101148] CPU: 2 PID: 4403 Comm: fsstress Not tainted 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 838.103757] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 838.105811] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs]FWIW, gdb says this address is:
0xffffffffa06e0739is inxlog_cil_commit(fs/xfs/xfs_log_cil.c:237). 232
233 /*234 * if we have no shadow buffer, or it is too small, we need to 235 * reallocate it. 236 */237 if (!lip->li_lv_shadow ||
238buf_size>lip->li_lv_shadow->lv_size) {
239 /*
240 * We free and allocate here as a realloc would copy
241 * unnecessary data. We don't usekvzalloc()for theI don't know what this is about, but my guess is that we freed something we weren't supposed to...?
Quoted 8 lines
Quoted 3 lines
(An overnight fstests run with v27 and larp=0 ran fine, though...)
--D
Hmm, ok, I will dig into this then. I dont see anything between v27 and v28 that would have cause this though, so I'm thinking what ever it is must by intermittent. I'll stick it in a loop and see if I can get a recreate today. Thanks!
I think I've figured out two of the problems here --
The biggest problem is that
xfs_attri_initisn't fully initializing the xattr log item structure, which is why the CIL would crash on my system when it tried to resize what it thought was thelv_shadowbuffer attached to the log item. I changed it tokmem_cache_zallocand the problems went away; you might want to check if your kernel has some debugging kconfig feature enabled that auto-zeroes everything.
Quoted 8 lines
The other KASAN report has to do with the log iovec code -- it assumes that any buffer passed in has a size that is congruent with 4(?) bytes. This isn't necessarily true for the xattr name (and in principle also the value) buffer that we get from the VFS; if either is (say) 37 bytes long, you'll get 37 bytes, and KASAN will expect you to stick to that. I think with the way the slab works this isn't a real memory corruption vector, but I wouldn't put it past slob or someone to actually pack things in tightly.
This seems ... familiar. ISTR I fixed this issue and send out patches to address it some time ago.
Ah, yes, I did - for v24 of the LARP patchset.
https://lore.kernel.org/linux-xfs/[email protected]/
Patch 3 fixed the log iovec rounding constraint:
https://lore.kernel.org/linux-xfs/[email protected]/
and patch 4 fixed the iovec sizing problems for attribute intents:
https://lore.kernel.org/linux-xfs/[email protected]/
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 93 lines · Dave Chinner
Quoted 76 lines · Darrick J. Wong
Quoted 57 lines · Allison Henderson
Quoted 54 lines · Darrick J. Wong
Quoted 12 lines · Allison Henderson
Hi all,
This set is a subset of a larger series parent pointers. Delayed attributes allow attribute operations (set and remove) to be logged and committed in the same way that other delayed operations do. This allows more complex operations (like parent pointers) to be broken up into multiple smaller transactions. To do this, the existing attr operations must be modified to operate as a delayed operation. This means that they cannot roll, commit, or finish transactions. Instead, they return
-EAGAINto allow the calling function to handle the transaction. In this series, we focus on only the delayed attribute portion. We will introduce parent pointers in a later set.Quoted 7 lines
The set as a whole is a bit much to digest at once, so I usually send out the smaller sub series to reduce reviewer burn out. But the entire extended series is visible through the included github links.
Updates since v27:
xfs: don't commit the first deferred transaction without intents
Comment updateI applied this to 5.16-rc6, and turned on larp mode. generic/476 tripped over something, and this is what kasan had to say:
[ 835.381655] run fstests generic/476 at 2022-02-28 18:22:04 [ 838.008485] XFS (sdb): Mounting V5 Filesystem [ 838.035529] XFS (sdb): Ending clean mount [ 838.040528] XFS (sdb): Quotacheck needed: Please wait. [ 838.050866] XFS (sdb): Quotacheck: Done. [ 838.092369] XFS (sdb): EXPERIMENTAL logged extended attributes feature added. Use at your own risk! [ 838.092938] general protection fault, probably for non-canonical address 0xe012f573e6000046: 0000 [#1] PREEMPT SMP KASAN [ 838.099085] KASAN: maybe wild-memory-access in range [0x0097cb9f30000230-0x0097cb9f30000237] [ 838.101148] CPU: 2 PID: 4403 Comm: fsstress Not tainted 5.17.0-rc5-djwx #rc5 63f7e400b85b2245f2d4d3033e82ec8bc95c49fd [ 838.103757] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 838.105811] RIP: 0010:xlog_cil_commit+0x2f9/0x2800 [xfs]FWIW, gdb says this address is:
0xffffffffa06e0739is inxlog_cil_commit(fs/xfs/xfs_log_cil.c:237). 232
233 /*234 * if we have no shadow buffer, or it is too small, we need to 235 * reallocate it. 236 */237 if (!lip->li_lv_shadow ||
238buf_size>lip->li_lv_shadow->lv_size) {
239 /*
240 * We free and allocate here as a realloc would copy
241 * unnecessary data. We don't usekvzalloc()for theI don't know what this is about, but my guess is that we freed something we weren't supposed to...?
Quoted 8 lines
Quoted 3 lines
(An overnight fstests run with v27 and larp=0 ran fine, though...)
--D
Hmm, ok, I will dig into this then. I dont see anything between v27 and v28 that would have cause this though, so I'm thinking what ever it is must by intermittent. I'll stick it in a loop and see if I can get a recreate today. Thanks!
I think I've figured out two of the problems here --
The biggest problem is that
xfs_attri_initisn't fully initializing the xattr log item structure, which is why the CIL would crash on my system when it tried to resize what it thought was thelv_shadowbuffer attached to the log item. I changed it tokmem_cache_zallocand the problems went away; you might want to check if your kernel has some debugging kconfig feature enabled that auto-zeroes everything.Quoted 8 lines
The other KASAN report has to do with the log iovec code -- it assumes that any buffer passed in has a size that is congruent with 4(?) bytes. This isn't necessarily true for the xattr name (and in principle also the value) buffer that we get from the VFS; if either is (say) 37 bytes long, you'll get 37 bytes, and KASAN will expect you to stick to that. I think with the way the slab works this isn't a real memory corruption vector, but I wouldn't put it past slob or someone to actually pack things in tightly.
This seems ... familiar. ISTR I fixed this issue and send out patches to address it some time ago.
Ah, yes, I did - for v24 of the LARP patchset.
Quoted 7 lines
Patch 3 fixed the log iovec rounding constraint:
https://lore.kernel.org/linux-xfs/[email protected]/
and patch 4 fixed the iovec sizing problems for attribute intents:
And in starting a forward port of the intent whiteout series that contains these fixes, I realised that these atches are also dependent on the xlog-write-rework series I just reposted a day ago.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]