xfs: Delay Ready Attributes
v4 cover xfs: Delay Ready Attributes
Hi all,
This set is a subset of a larger series for delayed attributes. Which is a subset of an even 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 either a delayed operation or a inline operation since older filesystems will not be able to use the new log entries. This means that they cannot roll, commit, or finish transactions. Instead, they return EAGAIN an allow the calling function to handle the transaction. In this series, we focus on only the clean up and refactoring needed to accomplish this. We will introduce delayed attrs and parent pointers in a later set.
Changes since v3:
Mostly review updates collected since v3. Patches 15, 16, and 17 are new and apply most of the new code flow changes. No new function is added at this time.
I've also made the corresponding updates to the user space side, and xfstests as well.
Question, comment and feedback appreciated!
Thanks all!
Allison
Allison Collins (15):
xfs: Replace attribute parameters with struct xfs_name
xfs: Embed struct xfs_name in xfs_da_args
xfs: Add xfs_dabuf defines
xfs: Factor out new helper functions xfs_attr_rmtval_set
xfs: Factor up trans handling in xfs_attr3_leaf_flipflags
xfs: Factor out xfs_attr_leaf_addname helper
xfs: Factor up commit from xfs_attr_try_sf_addname
xfs: Factor up trans roll from xfs_attr3_leaf_setflag
xfs: Add xfs_attr3_leaf helper functions
xfs: Factor out xfs_attr_rmtval_invalidate
xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
xfs: Add delay context to xfs_da_args
xfs: Check for -ENOATTR or -EEXIST
xfs: Add delay ready attr remove routines
xfs: Add delay ready attr set routines
Allison Henderson (2):
xfs: Remove all strlen in all xfs_attr_* functions for attr names.
xfs: Add xfs_has_attr and subroutines
fs/xfs/libxfs/xfs_attr.c | 771 +++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 9 +- fs/xfs/libxfs/xfs_attr_leaf.c | 329 +++++++++++------ fs/xfs/libxfs/xfs_attr_leaf.h | 7 + fs/xfs/libxfs/xfs_attr_remote.c | 103 ++++-- fs/xfs/libxfs/xfs_attr_remote.h | 4 +- fs/xfs/libxfs/xfs_da_btree.c | 55 ++- fs/xfs/libxfs/xfs_da_btree.h | 32 +- fs/xfs/libxfs/xfs_dir2.c | 18 +- fs/xfs/libxfs/xfs_dir2_block.c | 12 +- fs/xfs/libxfs/xfs_dir2_data.c | 3 +- fs/xfs/libxfs/xfs_dir2_leaf.c | 15 +- fs/xfs/libxfs/xfs_dir2_node.c | 18 +- fs/xfs/libxfs/xfs_dir2_sf.c | 30 +- fs/xfs/scrub/attr.c | 12 +- fs/xfs/scrub/common.c | 2 + fs/xfs/scrub/dabtree.c | 6 +- fs/xfs/scrub/dir.c | 4 +- fs/xfs/xfs_acl.c | 26 +- fs/xfs/xfs_attr_inactive.c | 6 +- fs/xfs/xfs_attr_list.c | 17 +- fs/xfs/xfs_ioctl.c | 20 +- fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 11 +- fs/xfs/xfs_trace.h | 20 +- fs/xfs/xfs_xattr.c | 23 +- 26 files changed, 1016 insertions(+), 539 deletions(-)
Signature · 1 line
2.7.4
PATCH v4 1/17 xfs: Remove all strlen in all xfs_attr_* functions for attr names.
From: Allison Henderson <[email protected]>
This helps to pre-simplify the extra handling of the null terminator in delayed operations which use memcpy rather than strlen. Later when we introduce parent pointers, attribute names will become binary, so strlen will not work at all. Removing uses of strlen now will help reduce complexities later
--- fs/xfs/libxfs/xfs_attr.c | 12 ++++++++---- fs/xfs/libxfs/xfs_attr.h | 8 +++++--- fs/xfs/xfs_acl.c | 11 +++++++---- fs/xfs/xfs_ioctl.c | 13 ++++++++++--- fs/xfs/xfs_iops.c | 6 ++++-- fs/xfs/xfs_xattr.c | 11 +++++++---- 6 files changed, 41 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +8 -4
@@ -62,6 +62,7 @@ xfs_attr_args_init(struct xfs_da_args *args, struct xfs_inode *dp, const unsigned char *name, + size_t namelen, int flags) {
@@ -74,7 +75,7 @@ xfs_attr_args_init( args->dp = dp; args->flags = flags; args->name = name; - args->namelen =strlen ((const char *)name); + args->namelen = namelen;if (args->namelen >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */
@@ -139,6 +140,7 @@ intxfs_attr_get ( struct xfs_inode *ip, const unsigned char *name, + size_t namelen, unsigned char **value, int *valuelenp, int flags)
@@ -154,7 +156,7 @@ xfs_attr_get(if (XFS_FORCED_SHUTDOWN (ip->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, ip, name, flags); + error =xfs_attr_args_init (&args, ip, name, namelen, flags);if (error)return error;
@@ -338,6 +340,7 @@ intxfs_attr_set ( struct xfs_inode *dp, const unsigned char *name, + size_t namelen, unsigned char *value, int valuelen, int flags)
@@ -353,7 +356,7 @@ xfs_attr_set(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, flags); + error =xfs_attr_args_init (&args, dp, name, namelen, flags);if (error)return error;
@@ -442,6 +445,7 @@ intxfs_attr_remove ( struct xfs_inode *dp, const unsigned char *name, + size_t namelen, int flags) { struct xfs_mount *mp = dp->i_mount;
@@ -453,7 +457,7 @@ xfs_attr_remove(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, flags); + error =xfs_attr_args_init (&args, dp, name, namelen, flags);if (error)return error;
fs/xfs/libxfs/xfs_attr.h +5 -3
@@ -145,11 +145,13 @@ int xfs_attr_list_int(struct xfs_attr_list_context *);int xfs_inode_hasattr (struct xfs_inode *ip);int xfs_attr_get_ilocked (struct xfs_inode *ip,struct xfs_da_args *args);int xfs_attr_get (struct xfs_inode *ip,const unsigned char *name, -unsigned char **value,int *valuelenp,int flags); +size_t namelen,unsigned char **value,int *valuelenp, +int flags);int xfs_attr_set (struct xfs_inode *dp,const unsigned char *name, -unsigned char *value,int valuelen,int flags); +size_t namelen,unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args); -int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name,int flags); +int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name, +size_t namelen,int flags);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);
fs/xfs/xfs_acl.c +7 -4
@@ -135,7 +135,8 @@ xfs_get_acl(struct inode *inode, int type)* go out to the disk. */ len =XFS_ACL_MAX_SIZE (ip->i_mount); - error =xfs_attr_get (ip, ea_name, (unsigned char **)&xfs_acl, &len, + error =xfs_attr_get (ip, ea_name,strlen (ea_name), + (unsigned char **)&xfs_acl, &len,ATTR_ALLOC |ATTR_ROOT );if (error) {/*
@@ -186,15 +187,17 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) len -=sizeof (struct xfs_acl_entry ) * (XFS_ACL_MAX_ENTRIES (ip->i_mount) - acl->a_count); - error =xfs_attr_set (ip, ea_name, (unsigned char *)xfs_acl, - len,ATTR_ROOT ); + error =xfs_attr_set (ip, ea_name,strlen (ea_name), + (unsigned char *)xfs_acl, len,ATTR_ROOT );kmem_free (xfs_acl); }else {/* * A NULL ACL argument means we want to remove the ACL. */ - error =xfs_attr_remove (ip, ea_name,ATTR_ROOT ); + error =xfs_attr_remove (ip, ea_name, +strlen (ea_name), +ATTR_ROOT );/* * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +10 -3
@@ -432,6 +432,7 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; +size_t namelen;if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;
@@ -439,7 +440,9 @@ xfs_attrmulti_attr_get(if (!kbuf)return -ENOMEM ; - error =xfs_attr_get (XFS_I (inode), name, &kbuf, (int *)len, flags); + namelen =strlen (name); + error =xfs_attr_get (XFS_I (inode), name, namelen, &kbuf, (int *)len, + flags);if (error) goto out_kfree;
@@ -461,6 +464,7 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; +size_t namelen;if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;
@@ -471,7 +475,8 @@ xfs_attrmulti_attr_set(if (IS_ERR (kbuf))return PTR_ERR (kbuf); - error =xfs_attr_set (XFS_I (inode), name, kbuf, len, flags); + namelen =strlen (name); + error =xfs_attr_set (XFS_I (inode), name, namelen, kbuf, len, flags);if (!error)xfs_forget_acl (inode, name, flags);kfree (kbuf);
@@ -485,10 +490,12 @@ xfs_attrmulti_attr_remove( uint32_t flags) {int error; +size_t namelen;if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ; - error =xfs_attr_remove (XFS_I (inode), name, flags); + namelen =strlen (name); + error =xfs_attr_remove (XFS_I (inode), name, namelen, flags);if (!error)xfs_forget_acl (inode, name, flags);return error;
fs/xfs/xfs_iops.c +4 -2
@@ -49,8 +49,10 @@ xfs_initxattrs(int error =0 ;for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { - error =xfs_attr_set (ip, xattr->name, xattr->value, - xattr->value_len,ATTR_SECURE ); + error =xfs_attr_set (ip, xattr->name, +strlen (xattr->name), + xattr->value, xattr->value_len, +ATTR_SECURE );if (error <0 )break ; }
fs/xfs/xfs_xattr.c +7 -4
@@ -23,6 +23,7 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,int xflags = handler->flags;struct xfs_inode *ip =XFS_I (inode);int error, asize = size; +size_t namelen =strlen (name);/* Convert Linux syscall to XFS internal ATTR flags */ if (!size) {
@@ -30,7 +31,8 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, value =NULL ; } - error =xfs_attr_get (ip, name, (unsigned char **)&value, &asize, xflags); + error =xfs_attr_get (ip, name, namelen, (unsigned char **)&value, + &asize, xflags);if (error)return error;return asize;
@@ -66,6 +68,7 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,int xflags = handler->flags;struct xfs_inode *ip =XFS_I (inode);int error; +size_t namelen =strlen (name);/* Convert Linux syscall to XFS internal ATTR flags */ if (flags &XATTR_CREATE )
@@ -74,9 +77,9 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused, xflags |=ATTR_REPLACE ;if (!value) -return xfs_attr_remove (ip, (unsigned char *)name, xflags); - error =xfs_attr_set (ip, (unsigned char *)name, - (void *)value, size, xflags); +return xfs_attr_remove (ip, name, + namelen, xflags); + error =xfs_attr_set (ip, name, namelen, (void *)value, size, xflags);if (!error)xfs_forget_acl (inode, name, xflags);
Signature · 1 line
2.7.4
Re: [PATCH v4 01/17] xfs: Remove all strlen in all xfs_attr_* functions for attr names.
Looks good,
Re: [PATCH v4 01/17] xfs: Remove all strlen in all xfs_attr_* functions for attr names.
Quoted 4 lines · Christoph Hellwig
Looks good,
Reviewed-by Christoph Hellwig <[email protected]>
Great! Thanks for the review!
Allison
PATCH v4 2/17 xfs: Replace attribute parameters with struct xfs_name
In reply to Allison CollinsThis patch replaces the attribute name and length parameters with a single struct xfs_name parameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.
--- fs/xfs/libxfs/xfs_attr.c | 22 +++++++++------------- fs/xfs/libxfs/xfs_attr.h | 12 +++++------- fs/xfs/xfs_acl.c | 27 +++++++++++++-------------- fs/xfs/xfs_ioctl.c | 25 +++++++++++++++---------- fs/xfs/xfs_iops.c | 9 ++++++--- fs/xfs/xfs_xattr.c | 25 +++++++++++++++---------- 6 files changed, 63 insertions(+), 57 deletions(-)
fs/xfs/libxfs/xfs_attr.c +9 -13
@@ -61,8 +61,7 @@ STATIC intxfs_attr_args_init ( struct xfs_da_args *args, struct xfs_inode *dp, - const unsigned char *name, - size_t namelen, + struct xfs_name *name, int flags) {
@@ -74,8 +73,8 @@ xfs_attr_args_init( args->whichfork =XFS_ATTR_FORK ; args->dp = dp; args->flags = flags; - args->name = name; - args->namelen = namelen; + args->name = name->name; + args->namelen = name->len;if (args->namelen >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */
@@ -139,8 +138,7 @@ xfs_attr_get_ilocked(int xfs_attr_get (struct xfs_inode *ip, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,unsigned char **value,int *valuelenp,int flags)
@@ -156,7 +154,7 @@ xfs_attr_get(if (XFS_FORCED_SHUTDOWN (ip->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, ip, name, namelen, flags); + error =xfs_attr_args_init (&args, ip, name, flags);if (error)return error;
@@ -339,8 +337,7 @@ xfs_attr_remove_args(int xfs_attr_set (struct xfs_inode *dp, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,unsigned char *value,int valuelen,int flags)
@@ -356,7 +353,7 @@ xfs_attr_set(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, namelen, flags); + error =xfs_attr_args_init (&args, dp, name, flags);if (error)return error;
@@ -444,8 +441,7 @@ xfs_attr_set(int xfs_attr_remove (struct xfs_inode *dp, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,int flags) {struct xfs_mount *mp = dp->i_mount;
@@ -457,7 +453,7 @@ xfs_attr_remove(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, namelen, flags); + error =xfs_attr_args_init (&args, dp, name, flags);if (error)return error;
fs/xfs/libxfs/xfs_attr.h +5 -7
@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);int xfs_attr_list_int (struct xfs_attr_list_context *);int xfs_inode_hasattr (struct xfs_inode *ip);int xfs_attr_get_ilocked (struct xfs_inode *ip,struct xfs_da_args *args); -int xfs_attr_get (struct xfs_inode *ip,const unsigned char *name, -size_t namelen,unsigned char **value,int *valuelenp, -int flags); -int xfs_attr_set (struct xfs_inode *dp,const unsigned char *name, -size_t namelen,unsigned char *value,int valuelen,int flags); +int xfs_attr_get (struct xfs_inode *ip,struct xfs_name *name, +unsigned char **value,int *valuelenp,int flags); +int xfs_attr_set (struct xfs_inode *dp,struct xfs_name *name, +unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args); -int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name, -size_t namelen,int flags); +int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);
fs/xfs/xfs_acl.c +13 -14
@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)struct xfs_inode *ip =XFS_I (inode);struct posix_acl *acl =NULL ;struct xfs_acl *xfs_acl =NULL ; -unsigned char *ea_name; +struct xfs_name name;int error;int len;
@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)switch (type) {case ACL_TYPE_ACCESS : - ea_name =SGI_ACL_FILE ; + name.name =SGI_ACL_FILE ;break ;case ACL_TYPE_DEFAULT : - ea_name =SGI_ACL_DEFAULT ; + name.name =SGI_ACL_DEFAULT ;break ;default :BUG ();
@@ -135,9 +135,9 @@ xfs_get_acl(struct inode *inode, int type)* go out to the disk. */ len =XFS_ACL_MAX_SIZE (ip->i_mount); - error =xfs_attr_get (ip, ea_name,strlen (ea_name), - (unsigned char **)&xfs_acl, &len, -ATTR_ALLOC |ATTR_ROOT ); + name.len =strlen (name.name); + error =xfs_attr_get (ip, &name, (unsigned char **)&xfs_acl, &len, +ATTR_ALLOC |ATTR_ROOT );if (error) {/* * If the attribute doesn't exist make sure we have a negative
@@ -157,17 +157,17 @@ int __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) { struct xfs_inode *ip = XFS_I(inode); -unsigned char *ea_name; +struct xfs_name name;int error;switch (type) {case ACL_TYPE_ACCESS : - ea_name =SGI_ACL_FILE ; + name.name =SGI_ACL_FILE ;break ;case ACL_TYPE_DEFAULT :if (!S_ISDIR (inode->i_mode))return acl ? -EACCES :0 ; - ea_name =SGI_ACL_DEFAULT ; + name.name =SGI_ACL_DEFAULT ;break ;default :return -EINVAL ;
@@ -187,17 +187,16 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) len -=sizeof (struct xfs_acl_entry ) * (XFS_ACL_MAX_ENTRIES (ip->i_mount) - acl->a_count); - error =xfs_attr_set (ip, ea_name,strlen (ea_name), - (unsigned char *)xfs_acl, len,ATTR_ROOT ); + name.len =strlen (name.name); + error =xfs_attr_set (ip, &name, (unsigned char *)xfs_acl, len, +ATTR_ROOT );kmem_free (xfs_acl); }else {/* * A NULL ACL argument means we want to remove the ACL. */ - error =xfs_attr_remove (ip, ea_name, -strlen (ea_name), -ATTR_ROOT ); + error =xfs_attr_remove (ip, &name,ATTR_ROOT );/* * If the attribute didn't exist to start with that's fine.
fs/xfs/xfs_ioctl.c +15 -10
@@ -432,7 +432,10 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; -size_t namelen; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;
@@ -440,9 +443,7 @@ xfs_attrmulti_attr_get(if (!kbuf)return -ENOMEM ; - namelen =strlen (name); - error =xfs_attr_get (XFS_I (inode), name, namelen, &kbuf, (int *)len, - flags); + error =xfs_attr_get (XFS_I (inode), &xname, &kbuf, (int *)len, flags);if (error) goto out_kfree;
@@ -464,7 +465,7 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; -size_t namelen; +struct xfs_name xname;if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;
@@ -475,8 +476,9 @@ xfs_attrmulti_attr_set(if (IS_ERR (kbuf))return PTR_ERR (kbuf); - namelen =strlen (name); - error =xfs_attr_set (XFS_I (inode), name, namelen, kbuf, len, flags); + xname.name = name; + xname.len =strlen (name); + error =xfs_attr_set (XFS_I (inode), &xname, kbuf, len, flags);if (!error)xfs_forget_acl (inode, name, flags);kfree (kbuf);
@@ -490,12 +492,15 @@ xfs_attrmulti_attr_remove( uint32_t flags) {int error; -size_t namelen; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ; - namelen =strlen (name); - error =xfs_attr_remove (XFS_I (inode), name, namelen, flags); + + error =xfs_attr_remove (XFS_I (inode), &xname, flags);if (!error)xfs_forget_acl (inode, name, flags);return error;
fs/xfs/xfs_iops.c +6 -3
@@ -49,9 +49,12 @@ xfs_initxattrs(int error =0 ;for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { - error =xfs_attr_set (ip, xattr->name, -strlen (xattr->name), - xattr->value, xattr->value_len, +struct xfs_name name = { + .name = xattr->name, + .len =strlen (xattr->name), + }; + + error =xfs_attr_set (ip, &name, xattr->value, xattr->value_len,ATTR_SECURE );if (error <0 )break ;
fs/xfs/xfs_xattr.c +15 -10
@@ -20,10 +20,13 @@ static int xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *value, size_t size) { - int xflags = handler->flags; -struct xfs_inode *ip =XFS_I (inode); -int error, asize = size; -size_t namelen =strlen (name); + int xflags = handler->flags; +struct xfs_inode *ip =XFS_I (inode); +int error, asize = size; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };/* Convert Linux syscall to XFS internal ATTR flags */ if (!size) {
@@ -31,8 +34,8 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, value =NULL ; } - error =xfs_attr_get (ip, name, namelen, (unsigned char **)&value, - &asize, xflags); + error =xfs_attr_get (ip, &xname, (unsigned char **)&value, &asize, + xflags);if (error)return error;return asize;
@@ -68,7 +71,10 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,int xflags = handler->flags;struct xfs_inode *ip =XFS_I (inode);int error; -size_t namelen =strlen (name); +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };/* Convert Linux syscall to XFS internal ATTR flags */ if (flags &XATTR_CREATE )
@@ -77,9 +83,8 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused, xflags |=ATTR_REPLACE ;if (!value) -return xfs_attr_remove (ip, name, - namelen, xflags); - error =xfs_attr_set (ip, name, namelen, (void *)value, size, xflags); +return xfs_attr_remove (ip, &xname, xflags); + error =xfs_attr_set (ip, &xname, (void *)value, size, xflags);if (!error)xfs_forget_acl (inode, name, xflags);
Signature · 1 line
2.7.4
Re: [PATCH v4 02/17] xfs: Replace attribute parameters with struct xfs_name
Quoted 181 lines · Allison Collins
This patch replaces the attribute name and length parameters with a single struct
xfs_nameparameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 22 +++++++++------------- fs/xfs/libxfs/xfs_attr.h | 12 +++++------- fs/xfs/xfs_acl.c | 27 +++++++++++++-------------- fs/xfs/xfs_ioctl.c | 25 +++++++++++++++---------- fs/xfs/xfs_iops.c | 9 ++++++--- fs/xfs/xfs_xattr.c | 25 +++++++++++++++---------- 6 files changed, 63 insertions(+), 57 deletions(-)fs/xfs/libxfs/xfs_attr.c +9
-13@@ -61,8 +61,7 @@ STATIC intxfs_attr_args_init ( struct xfs_da_args *args, struct xfs_inode *dp, - const unsigned char *name, - size_t namelen, + struct xfs_name *name, int flags) {@@ -74,8 +73,8 @@ xfs_attr_args_init( args->whichfork =XFS_ATTR_FORK ; args->dp = dp; args->flags = flags; - args->name = name; - args->namelen = namelen; + args->name = name->name; + args->namelen = name->len;if (args->namelen >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */ @@ -139,8 +138,7 @@ xfs_attr_get_ilocked(int xfs_attr_get (struct xfs_inode *ip, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,unsigned char **value,int *valuelenp,int flags)@@ -156,7 +154,7 @@ xfs_attr_get(if (XFS_FORCED_SHUTDOWN (ip->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, ip, name, namelen, flags); + error =xfs_attr_args_init (&args, ip, name, flags);if (error)return error;@@ -339,8 +337,7 @@ xfs_attr_remove_args(int xfs_attr_set (struct xfs_inode *dp, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,unsigned char *value,int valuelen,int flags)@@ -356,7 +353,7 @@ xfs_attr_set(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, namelen, flags); + error =xfs_attr_args_init (&args, dp, name, flags);if (error)return error;@@ -444,8 +441,7 @@ xfs_attr_set(int xfs_attr_remove (struct xfs_inode *dp, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,int flags) {struct xfs_mount *mp = dp->i_mount;@@ -457,7 +453,7 @@ xfs_attr_remove(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, namelen, flags); + error =xfs_attr_args_init (&args, dp, name, flags);if (error)return error;fs/xfs/libxfs/xfs_attr.h +5
-7@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);int xfs_attr_list_int (struct xfs_attr_list_context *);int xfs_inode_hasattr (struct xfs_inode *ip);int xfs_attr_get_ilocked (struct xfs_inode *ip,struct xfs_da_args *args); -int xfs_attr_get (struct xfs_inode *ip,const unsigned char *name, -size_t namelen,unsigned char **value,int *valuelenp, -int flags); -int xfs_attr_set (struct xfs_inode *dp,const unsigned char *name, -size_t namelen,unsigned char *value,int valuelen,int flags); +int xfs_attr_get (struct xfs_inode *ip,struct xfs_name *name, +unsigned char **value,int *valuelenp,int flags); +int xfs_attr_set (struct xfs_inode *dp,struct xfs_name *name, +unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args); -int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name, -size_t namelen,int flags); +int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);fs/xfs/xfs_acl.c +9
-9@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)struct xfs_inode *ip =XFS_I (inode);struct posix_acl *acl =NULL ;struct xfs_acl *xfs_acl =NULL ; -unsigned char *ea_name; +struct xfs_name name;int error;int len;@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)switch (type) {case ACL_TYPE_ACCESS : - ea_name =SGI_ACL_FILE ; + name.name =SGI_ACL_FILE ;break ;case ACL_TYPE_DEFAULT : - ea_name =SGI_ACL_DEFAULT ; + name.name =SGI_ACL_DEFAULT ;break ;default :BUG ();@@ -135,9 +135,9 @@ xfs_get_acl(struct inode *inode, int type)* go out to the disk. */ len =XFS_ACL_MAX_SIZE (ip->i_mount); - error =xfs_attr_get (ip, ea_name,strlen (ea_name), - (unsigned char **)&xfs_acl, &len, -ATTR_ALLOC |ATTR_ROOT ); + name.len =strlen (name.name); + error =xfs_attr_get (ip, &name, (unsigned char **)&xfs_acl, &len, +ATTR_ALLOC |ATTR_ROOT );if (error) {/* * If the attribute doesn't exist make sure we have a negative @@ -157,17 +157,17 @@ int __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) { struct xfs_inode *ip = XFS_I(inode); -unsigned char *ea_name; +struct xfs_name name;int error;switch (type) {case ACL_TYPE_ACCESS : - ea_name =SGI_ACL_FILE ; + name.name =SGI_ACL_FILE ;break ;case ACL_TYPE_DEFAULT :if (!S_ISDIR (inode->i_mode))return acl ? -EACCES :0 ; - ea_name =SGI_ACL_DEFAULT ; + name.name =SGI_ACL_DEFAULT ;break ;default :return -EINVAL ;
fs/xfs/xfs_acl.c __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) · line 190
Quoted 6 lines
fs/xfs/xfs_acl.c +1
-2@@ -187,17 +187,16 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) len -=sizeof (struct xfs_acl_entry ) * (XFS_ACL_MAX_ENTRIES (ip->i_mount) - acl->a_count); - error =xfs_attr_set (ip, ea_name,strlen (ea_name), - (unsigned char *)xfs_acl, len,ATTR_ROOT ); + name.len =strlen (name.name);
/me wonders if you ought to write a helper function to initialize an xfs_name and calculate name->len instead of open coding it here because...
fs/xfs/xfs_acl.c __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) · line 199
Quoted 12 lines
fs/xfs/xfs_acl.c +3
-3+ error =xfs_attr_set (ip, &name, (unsigned char *)xfs_acl, len, +ATTR_ROOT );kmem_free (xfs_acl); }else {/* * A NULL ACL argument means we want to remove the ACL. */ - error =xfs_attr_remove (ip, ea_name, -strlen (ea_name), -ATTR_ROOT ); + error =xfs_attr_remove (ip, &name,ATTR_ROOT );
..I think name.len is uninitialized here?
--D
Quoted 150 lines
fs/xfs/xfs_acl.c +0
-0/* * If the attribute didn't exist to start with that's fine. fs/xfs/xfs_ioctl.c +15
-10@@ -432,7 +432,10 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; -size_t namelen; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;@@ -440,9 +443,7 @@ xfs_attrmulti_attr_get(if (!kbuf)return -ENOMEM ; - namelen =strlen (name); - error =xfs_attr_get (XFS_I (inode), name, namelen, &kbuf, (int *)len, - flags); + error =xfs_attr_get (XFS_I (inode), &xname, &kbuf, (int *)len, flags);if (error) goto out_kfree;@@ -464,7 +465,7 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; -size_t namelen; +struct xfs_name xname;if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;@@ -475,8 +476,9 @@ xfs_attrmulti_attr_set(if (IS_ERR (kbuf))return PTR_ERR (kbuf); - namelen =strlen (name); - error =xfs_attr_set (XFS_I (inode), name, namelen, kbuf, len, flags); + xname.name = name; + xname.len =strlen (name); + error =xfs_attr_set (XFS_I (inode), &xname, kbuf, len, flags);if (!error)xfs_forget_acl (inode, name, flags);kfree (kbuf);@@ -490,12 +492,15 @@ xfs_attrmulti_attr_remove( uint32_t flags) {int error; -size_t namelen; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ; - namelen =strlen (name); - error =xfs_attr_remove (XFS_I (inode), name, namelen, flags); + + error =xfs_attr_remove (XFS_I (inode), &xname, flags);if (!error)xfs_forget_acl (inode, name, flags);return error;fs/xfs/xfs_iops.c +6
-3@@ -49,9 +49,12 @@ xfs_initxattrs(int error =0 ;for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { - error =xfs_attr_set (ip, xattr->name, -strlen (xattr->name), - xattr->value, xattr->value_len, +struct xfs_name name = { + .name = xattr->name, + .len =strlen (xattr->name), + }; + + error =xfs_attr_set (ip, &name, xattr->value, xattr->value_len,ATTR_SECURE );if (error <0 )break ;fs/xfs/xfs_xattr.c +15
-10@@ -20,10 +20,13 @@ static int xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *value, size_t size) { - int xflags = handler->flags; -struct xfs_inode *ip =XFS_I (inode); -int error, asize = size; -size_t namelen =strlen (name); + int xflags = handler->flags; +struct xfs_inode *ip =XFS_I (inode); +int error, asize = size; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };/* Convert Linux syscall to XFS internal ATTR flags */ if (!size) {@@ -31,8 +34,8 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, value =NULL ; } - error =xfs_attr_get (ip, name, namelen, (unsigned char **)&value, - &asize, xflags); + error =xfs_attr_get (ip, &xname, (unsigned char **)&value, &asize, + xflags);if (error)return error;return asize;@@ -68,7 +71,10 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,int xflags = handler->flags;struct xfs_inode *ip =XFS_I (inode);int error; -size_t namelen =strlen (name); +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };/* Convert Linux syscall to XFS internal ATTR flags */ if (flags &XATTR_CREATE )@@ -77,9 +83,8 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused, xflags |=ATTR_REPLACE ;if (!value) -return xfs_attr_remove (ip, name, - namelen, xflags); - error =xfs_attr_set (ip, name, namelen, (void *)value, size, xflags); +return xfs_attr_remove (ip, &xname, xflags); + error =xfs_attr_set (ip, &xname, (void *)value, size, xflags);if (!error)xfs_forget_acl (inode, name, xflags);Signature · 1 line
2.7.4
Re: [PATCH v4 02/17] xfs: Replace attribute parameters with struct xfs_name
Quoted 185 lines · Darrick J. Wong
Quoted 184 lines · Allison Collins
This patch replaces the attribute name and length parameters with a single struct
xfs_nameparameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 22 +++++++++------------- fs/xfs/libxfs/xfs_attr.h | 12 +++++------- fs/xfs/xfs_acl.c | 27 +++++++++++++-------------- fs/xfs/xfs_ioctl.c | 25 +++++++++++++++---------- fs/xfs/xfs_iops.c | 9 ++++++--- fs/xfs/xfs_xattr.c | 25 +++++++++++++++---------- 6 files changed, 63 insertions(+), 57 deletions(-)fs/xfs/libxfs/xfs_attr.c +9
-13@@ -61,8 +61,7 @@ STATIC intxfs_attr_args_init ( struct xfs_da_args *args, struct xfs_inode *dp, - const unsigned char *name, - size_t namelen, + struct xfs_name *name, int flags) {@@ -74,8 +73,8 @@ xfs_attr_args_init( args->whichfork =XFS_ATTR_FORK ; args->dp = dp; args->flags = flags; - args->name = name; - args->namelen = namelen; + args->name = name->name; + args->namelen = name->len;if (args->namelen >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */ @@ -139,8 +138,7 @@ xfs_attr_get_ilocked(int xfs_attr_get (struct xfs_inode *ip, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,unsigned char **value,int *valuelenp,int flags)@@ -156,7 +154,7 @@ xfs_attr_get(if (XFS_FORCED_SHUTDOWN (ip->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, ip, name, namelen, flags); + error =xfs_attr_args_init (&args, ip, name, flags);if (error)return error;@@ -339,8 +337,7 @@ xfs_attr_remove_args(int xfs_attr_set (struct xfs_inode *dp, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,unsigned char *value,int valuelen,int flags)@@ -356,7 +353,7 @@ xfs_attr_set(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, namelen, flags); + error =xfs_attr_args_init (&args, dp, name, flags);if (error)return error;@@ -444,8 +441,7 @@ xfs_attr_set(int xfs_attr_remove (struct xfs_inode *dp, -const unsigned char *name, -size_t namelen, +struct xfs_name *name,int flags) {struct xfs_mount *mp = dp->i_mount;@@ -457,7 +453,7 @@ xfs_attr_remove(if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ; - error =xfs_attr_args_init (&args, dp, name, namelen, flags); + error =xfs_attr_args_init (&args, dp, name, flags);if (error)return error;fs/xfs/libxfs/xfs_attr.h +5
-7@@ -144,14 +144,12 @@ int xfs_attr_list_int_ilocked(struct xfs_attr_list_context *);int xfs_attr_list_int (struct xfs_attr_list_context *);int xfs_inode_hasattr (struct xfs_inode *ip);int xfs_attr_get_ilocked (struct xfs_inode *ip,struct xfs_da_args *args); -int xfs_attr_get (struct xfs_inode *ip,const unsigned char *name, -size_t namelen,unsigned char **value,int *valuelenp, -int flags); -int xfs_attr_set (struct xfs_inode *dp,const unsigned char *name, -size_t namelen,unsigned char *value,int valuelen,int flags); +int xfs_attr_get (struct xfs_inode *ip,struct xfs_name *name, +unsigned char **value,int *valuelenp,int flags); +int xfs_attr_set (struct xfs_inode *dp,struct xfs_name *name, +unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args); -int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name, -size_t namelen,int flags); +int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);fs/xfs/xfs_acl.c +9
-9@@ -113,7 +113,7 @@ xfs_get_acl(struct inode *inode, int type)struct xfs_inode *ip =XFS_I (inode);struct posix_acl *acl =NULL ;struct xfs_acl *xfs_acl =NULL ; -unsigned char *ea_name; +struct xfs_name name;int error;int len;@@ -121,10 +121,10 @@ xfs_get_acl(struct inode *inode, int type)switch (type) {case ACL_TYPE_ACCESS : - ea_name =SGI_ACL_FILE ; + name.name =SGI_ACL_FILE ;break ;case ACL_TYPE_DEFAULT : - ea_name =SGI_ACL_DEFAULT ; + name.name =SGI_ACL_DEFAULT ;break ;default :BUG ();@@ -135,9 +135,9 @@ xfs_get_acl(struct inode *inode, int type)* go out to the disk. */ len =XFS_ACL_MAX_SIZE (ip->i_mount); - error =xfs_attr_get (ip, ea_name,strlen (ea_name), - (unsigned char **)&xfs_acl, &len, -ATTR_ALLOC |ATTR_ROOT ); + name.len =strlen (name.name); + error =xfs_attr_get (ip, &name, (unsigned char **)&xfs_acl, &len, +ATTR_ALLOC |ATTR_ROOT );if (error) {/* * If the attribute doesn't exist make sure we have a negative @@ -157,17 +157,17 @@ int __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) { struct xfs_inode *ip = XFS_I(inode); -unsigned char *ea_name; +struct xfs_name name;int error;switch (type) {case ACL_TYPE_ACCESS : - ea_name =SGI_ACL_FILE ; + name.name =SGI_ACL_FILE ;break ;case ACL_TYPE_DEFAULT :if (!S_ISDIR (inode->i_mode))return acl ? -EACCES :0 ; - ea_name =SGI_ACL_DEFAULT ; + name.name =SGI_ACL_DEFAULT ;break ;default :return -EINVAL ;@@ -187,17 +187,16 @@ __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) len -=sizeof (struct xfs_acl_entry ) * (XFS_ACL_MAX_ENTRIES (ip->i_mount) - acl->a_count);
Quoted 7 lines
fs/xfs/xfs_acl.c __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) · line 190
Quoted 3 lines
fs/xfs/xfs_acl.c +1
-2- error =xfs_attr_set (ip, ea_name,strlen (ea_name), - (unsigned char *)xfs_acl, len,ATTR_ROOT ); + name.len =strlen (name.name);/me wonders if you ought to write a helper function to initialize an
xfs_nameand calculatename->leninstead of open coding it here because...
Ok, I think in one of the previous reviews we decided on an explicit struct initialization. It works in most cases, but just couldn't be applied here because of the case handling. I'm not sure how opinionated people really are about though?
Quoted 4 lines
Quoted 4 lines
fs/xfs/xfs_acl.c +2
-0+ error =xfs_attr_set (ip, &name, (unsigned char *)xfs_acl, len, +ATTR_ROOT );
Quoted 10 lines
fs/xfs/xfs_acl.c __xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) · line 199
Quoted 9 lines
fs/xfs/xfs_acl.c +1
-3kmem_free (xfs_acl); }else {/* * A NULL ACL argument means we want to remove the ACL. */ - error =xfs_attr_remove (ip, ea_name, -strlen (ea_name), -ATTR_ROOT ); + error =xfs_attr_remove (ip, &name,ATTR_ROOT );
Ok, will fix. Thanks for catch!
Allison
Quoted 154 lines
..I think name.len is uninitialized here?
--D
Quoted 150 lines
fs/xfs/xfs_acl.c +0
-0/* * If the attribute didn't exist to start with that's fine. fs/xfs/xfs_ioctl.c +15
-10@@ -432,7 +432,10 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; -size_t namelen; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;@@ -440,9 +443,7 @@ xfs_attrmulti_attr_get(if (!kbuf)return -ENOMEM ; - namelen =strlen (name); - error =xfs_attr_get (XFS_I (inode), name, namelen, &kbuf, (int *)len, - flags); + error =xfs_attr_get (XFS_I (inode), &xname, &kbuf, (int *)len, flags);if (error) goto out_kfree;@@ -464,7 +465,7 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; -size_t namelen; +struct xfs_name xname;if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;@@ -475,8 +476,9 @@ xfs_attrmulti_attr_set(if (IS_ERR (kbuf))return PTR_ERR (kbuf); - namelen =strlen (name); - error =xfs_attr_set (XFS_I (inode), name, namelen, kbuf, len, flags); + xname.name = name; + xname.len =strlen (name); + error =xfs_attr_set (XFS_I (inode), &xname, kbuf, len, flags);if (!error)xfs_forget_acl (inode, name, flags);kfree (kbuf);@@ -490,12 +492,15 @@ xfs_attrmulti_attr_remove( uint32_t flags) {int error; -size_t namelen; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ; - namelen =strlen (name); - error =xfs_attr_remove (XFS_I (inode), name, namelen, flags); + + error =xfs_attr_remove (XFS_I (inode), &xname, flags);if (!error)xfs_forget_acl (inode, name, flags);return error;fs/xfs/xfs_iops.c +6
-3@@ -49,9 +49,12 @@ xfs_initxattrs(int error =0 ;for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { - error =xfs_attr_set (ip, xattr->name, -strlen (xattr->name), - xattr->value, xattr->value_len, +struct xfs_name name = { + .name = xattr->name, + .len =strlen (xattr->name), + }; + + error =xfs_attr_set (ip, &name, xattr->value, xattr->value_len,ATTR_SECURE );if (error <0 )break ;fs/xfs/xfs_xattr.c +15
-10@@ -20,10 +20,13 @@ static int xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *value, size_t size) { - int xflags = handler->flags; -struct xfs_inode *ip =XFS_I (inode); -int error, asize = size; -size_t namelen =strlen (name); + int xflags = handler->flags; +struct xfs_inode *ip =XFS_I (inode); +int error, asize = size; +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };/* Convert Linux syscall to XFS internal ATTR flags */ if (!size) {@@ -31,8 +34,8 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, value =NULL ; } - error =xfs_attr_get (ip, name, namelen, (unsigned char **)&value, - &asize, xflags); + error =xfs_attr_get (ip, &xname, (unsigned char **)&value, &asize, + xflags);if (error)return error;return asize;@@ -68,7 +71,10 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused,int xflags = handler->flags;struct xfs_inode *ip =XFS_I (inode);int error; -size_t namelen =strlen (name); +struct xfs_name xname = { + .name = name, + .len =strlen (name), + };/* Convert Linux syscall to XFS internal ATTR flags */ if (flags &XATTR_CREATE )@@ -77,9 +83,8 @@ xfs_xattr_set(const struct xattr_handler *handler, struct dentry *unused, xflags |=ATTR_REPLACE ;if (!value) -return xfs_attr_remove (ip, name, - namelen, xflags); - error =xfs_attr_set (ip, name, namelen, (void *)value, size, xflags); +return xfs_attr_remove (ip, &xname, xflags); + error =xfs_attr_set (ip, &xname, (void *)value, size, xflags);if (!error)xfs_forget_acl (inode, name, xflags);Signature · 1 line
2.7.4
Re: [PATCH v4 02/17] xfs: Replace attribute parameters with struct xfs_name
In reply to Allison CollinsQuoted 3 lines · Allison Collins
This patch replaces the attribute name and length parameters with a single struct
xfs_nameparameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.
Does it? As-is the patch doesn't look too bad, although it adds more lines than it removes. But together with the next patch that embedds an xfs_name into the xfs_da_args structure and the now added memcpys it doesn't really look very helpful to me.
Re: [PATCH v4 02/17] xfs: Replace attribute parameters with struct xfs_name
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Allison Collins
This patch replaces the attribute name and length parameters with a single struct
xfs_nameparameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.Does it? As-is the patch doesn't look too bad, although it adds more lines than it removes. But together with the next patch that embedds an
xfs_nameinto thexfs_da_argsstructure and the now added memcpys it doesn't really look very helpful to me.
It has evolved a bit since its initial proposition. Maybe it would help to raise the question of: is patch 2 or 3 alone more helpful than the combination of them? I think initially Dave had suggested the clean up in one of the earlier reviews a while ago, so he may have an opinion here.
Personally I'm not super opinionated about it if people have strong feelings toward keeping or pitching it. I will say after having worked with it as it is, I'm not sure I'm particularly fond of having a name struct in the param, and another in the args. I think eventually someones going to forget that args supersedes the param after the init routine. People will probably figure it out pretty quick if they get bit I suppose, but I do think it's a sort of wart to consider.
Allison
Re: [PATCH v4 02/17] xfs: Replace attribute parameters with struct xfs_name
Quoted 13 lines · Allison Collins
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Allison Collins
This patch replaces the attribute name and length parameters with a single struct
xfs_nameparameter. This helps to clean up the numbers of parameters being passed around and pre-simplifies the code some.Does it? As-is the patch doesn't look too bad, although it adds more lines than it removes. But together with the next patch that embedds an
xfs_nameinto thexfs_da_argsstructure and the now added memcpys it doesn't really look very helpful to me.
Quoted 5 lines
It has evolved a bit since its initial proposition. Maybe it would help to raise the question of: is patch 2 or 3 alone more helpful than the combination of them? I think initially Dave had suggested the clean up in one of the earlier reviews a while ago, so he may have an opinion here.
Personally I'm not super opinionated about it if people have strong feelings toward keeping or pitching it. I will say after having worked with it as it is, I'm not sure I'm particularly fond of having a name struct in the param, and another in the args. I think eventually someones going to forget that args supersedes the param after the init routine. People will probably figure it out pretty quick if they get bit I suppose, but I do think it's a sort of wart to consider.
Allison
What if I added an xfs_name_init to reduce LOC. and then dropped patch 3? What would people think of that?
Allison
Re: [PATCH v4 02/17] xfs: Replace attribute parameters with struct xfs_name
Quoted 2 lines · Allison Collins
What if I added an
xfs_name_initto reduce LOC. and then dropped patch 3? What would people think of that?
I think we should just pass the da_args to the attr ops from the highest level and remove the churn of passing the xfs_name there.
I've pushed out a compile tested only series here to illustrate what I mean:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-attr-cleanup
PATCH v4 3/17 xfs: Embed struct xfs_name in xfs_da_args
In reply to Allison CollinsThis patch embeds an xfs_name in xfs_da_args, replacing the name, namelen, and flags members. This helps to clean up the xfs_da_args structure and make it more uniform with the new xfs_name parameter being passed around.
--- fs/xfs/libxfs/xfs_attr.c | 36 +++++++------- fs/xfs/libxfs/xfs_attr_leaf.c | 106 +++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_da_btree.c | 5 +- fs/xfs/libxfs/xfs_da_btree.h | 4 +- fs/xfs/libxfs/xfs_dir2.c | 18 +++---- fs/xfs/libxfs/xfs_dir2_block.c | 6 +-- fs/xfs/libxfs/xfs_dir2_leaf.c | 6 +-- fs/xfs/libxfs/xfs_dir2_node.c | 8 +-- fs/xfs/libxfs/xfs_dir2_sf.c | 30 ++++++------ fs/xfs/scrub/attr.c | 12 ++--- fs/xfs/xfs_trace.h | 20 ++++---- 12 files changed, 128 insertions(+), 125 deletions(-)
fs/xfs/libxfs/xfs_attr.c +19 -17
@@ -72,13 +72,12 @@ xfs_attr_args_init( args->geo = dp->i_mount->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->dp = dp; - args->flags = flags; - args->name = name->name; - args->namelen = name->len; -if (args->namelen >=MAXNAMELEN ) + name->type = flags; +memcpy (&args->name, name,sizeof (struct xfs_name )); +if (args->name.len >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */ - args->hashval =xfs_da_hashname (args->name, args->namelen); + args->hashval =xfs_da_hashname (args->name.name, args->name.len);return 0 ; }
@@ -236,7 +235,7 @@ xfs_attr_try_sf_addname(* Commit the shortform mods, and we're done. * NOTE: this is also the error path (EEXIST, etc). */ -if (!error && (args->flags &ATTR_KERNOTIME ) ==0 ) +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 )xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );if (mp->m_flags &XFS_MOUNT_WSYNC )
@@ -357,6 +356,9 @@ xfs_attr_set(if (error)return error; +/* Use name now stored in args */ + name = &args.name; + args.value = value; args.valuelen = valuelen; args.op_flags =XFS_DA_OP_ADDNAME |XFS_DA_OP_OKNOENT ;
@@ -372,7 +374,7 @@ xfs_attr_set(*/ if (XFS_IFORK_Q (dp) ==0 ) {int sf_size =sizeof (xfs_attr_sf_hdr_t) + -XFS_ATTR_SF_ENTSIZE_BYNAME (args.namelen, valuelen); +XFS_ATTR_SF_ENTSIZE_BYNAME (args.name.len, valuelen); error =xfs_bmap_add_attrfork (dp, sf_size, rsvd);if (error)
@@ -532,10 +534,10 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)trace_xfs_attr_sf_addname (args); retval =xfs_attr_shortform_lookup (args); -if ((args->flags &ATTR_REPLACE ) && (retval == -ENOATTR )) { +if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) {return retval; }else if (retval == -EEXIST ) { -if (args->flags &ATTR_CREATE ) +if (args->name.type &ATTR_CREATE )return retval; retval =xfs_attr_shortform_remove (args);if (retval)
@@ -545,15 +547,15 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)* that the leaf format add routine won't trip over the attr * not being around. */ - args->flags &= ~ATTR_REPLACE ; + args->name.type &= ~ATTR_REPLACE ; } -if (args->namelen >=XFS_ATTR_SF_ENTSIZE_MAX || +if (args->name.len >=XFS_ATTR_SF_ENTSIZE_MAX || args->valuelen >=XFS_ATTR_SF_ENTSIZE_MAX )return -ENOSPC ; newsize =XFS_ATTR_SF_TOTSIZE (args->dp); - newsize +=XFS_ATTR_SF_ENTSIZE_BYNAME (args->namelen, args->valuelen); + newsize +=XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen); forkoff =xfs_attr_shortform_bytesfit (args->dp, newsize);if (!forkoff)
@@ -598,11 +600,11 @@ xfs_attr_leaf_addname(* the given flags produce an error or call for an atomic rename. */ retval =xfs_attr3_leaf_lookup_int (bp, args); -if ((args->flags &ATTR_REPLACE ) && (retval == -ENOATTR )) { +if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) {xfs_trans_brelse (args->trans, bp);return retval; }else if (retval == -EEXIST ) { -if (args->flags &ATTR_CREATE ) {/* pure create op */ +if (args->name.type &ATTR_CREATE ) {/* pure create op */ xfs_trans_brelse (args->trans, bp);return retval; }
@@ -872,10 +874,10 @@ xfs_attr_node_addname( goto out; blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); -if ((args->flags &ATTR_REPLACE ) && (retval == -ENOATTR )) { +if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) { goto out; }else if (retval == -EEXIST ) { -if (args->flags &ATTR_CREATE ) +if (args->name.type &ATTR_CREATE ) goto out;trace_xfs_attr_node_replace (args);
@@ -1007,7 +1009,7 @@ xfs_attr_node_addname(* The INCOMPLETE flag means that we will find the "old" * attr, not the "new" one. */ - args->flags |=XFS_ATTR_INCOMPLETE ; + args->name.type |=XFS_ATTR_INCOMPLETE ; state =xfs_da_state_alloc (); state->args = args; state->mp = mp;
fs/xfs/libxfs/xfs_attr_leaf.c +55 -51
238 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.c +1 -1
@@ -379,7 +379,7 @@ xfs_attr_rmtval_get(trace_xfs_attr_rmtval_get (args); -ASSERT (!(args->flags &ATTR_KERNOVAL )); +ASSERT (!(args->name.type &ATTR_KERNOVAL ));ASSERT (args->rmtvaluelen == args->valuelen); valuelen = args->rmtvaluelen;
fs/xfs/libxfs/xfs_da_btree.c +3 -2
@@ -2040,8 +2040,9 @@ xfs_da_compname( const unsigned char *name, int len) { - return (args->namelen == len && memcmp(args->name, name, len) == 0) ? - XFS_CMP_EXACT : XFS_CMP_DIFFERENT; + return (args->name.len == len && + memcmp(args->name.name, name, len) == 0) ? XFS_CMP_EXACT : + XFS_CMP_DIFFERENT; } static xfs_dahash_t
fs/xfs/libxfs/xfs_da_btree.h +1 -3
@@ -47,12 +47,10 @@ enum xfs_dacmp {*/ typedef struct xfs_da_args { struct xfs_da_geometry *geo; /* da block geometry */ - const uint8_t *name; /* string (maybe not NULL terminated) */ - int namelen; /* length of string (maybe no NULL) */ + struct xfs_name name; /* name, length and argument flags*/ uint8_t filetype; /* filetype of inode for directories */ uint8_t *value; /* set of bytes (maybe contain NULLs) */ int valuelen; /* length of value */ - int flags; /* argument flags (eg: ATTR_NOCREATE) */ xfs_dahash_t hashval; /* hash value of name */ xfs_ino_t inumber; /* input/output inode number */ struct xfs_inode *dp; /* directory inode to manipulate */
fs/xfs/libxfs/xfs_dir2.c +7 -11
@@ -74,14 +74,14 @@ xfs_ascii_ci_compname(enum xfs_dacmp result;int i; -if (args->namelen != len) +if (args->name.len != len)return XFS_CMP_DIFFERENT ; result =XFS_CMP_EXACT ;for (i =0 ; i < len; i++) { -if (args->name[i] == name[i]) +if (args->name.name[i] == name[i])continue ; -if (tolower (args->name[i]) !=tolower (name[i])) +if (tolower (args->name.name[i]) !=tolower (name[i]))return XFS_CMP_DIFFERENT ; result =XFS_CMP_CASE ; }
@@ -259,8 +259,7 @@ xfs_dir_createname(return -ENOMEM ; args->geo = dp->i_mount->m_dir_geo; - args->name = name->name; - args->namelen = name->len; +memcpy (&args->name, name,sizeof (struct xfs_name )); args->filetype = name->type; args->hashval = dp->i_mount->m_dirnameops->hashname (name); args->inumber = inum;
@@ -355,8 +354,7 @@ xfs_dir_lookup(*/ args =kmem_zalloc (sizeof (*args),KM_NOFS ); args->geo = dp->i_mount->m_dir_geo; - args->name = name->name; - args->namelen = name->len; +memcpy (&args->name, name,sizeof (struct xfs_name )); args->filetype = name->type; args->hashval = dp->i_mount->m_dirnameops->hashname (name); args->dp = dp;
@@ -427,8 +425,7 @@ xfs_dir_removename(return -ENOMEM ; args->geo = dp->i_mount->m_dir_geo; - args->name = name->name; - args->namelen = name->len; +memcpy (&args->name, name,sizeof (struct xfs_name )); args->filetype = name->type; args->hashval = dp->i_mount->m_dirnameops->hashname (name); args->inumber = ino;
@@ -488,8 +485,7 @@ xfs_dir_replace(return -ENOMEM ; args->geo = dp->i_mount->m_dir_geo; - args->name = name->name; - args->namelen = name->len; +memcpy (&args->name, name,sizeof (struct xfs_name )); args->filetype = name->type; args->hashval = dp->i_mount->m_dirnameops->hashname (name); args->inumber = inum;
fs/xfs/libxfs/xfs_dir2_block.c +3 -3
@@ -355,7 +355,7 @@ xfs_dir2_block_addname(if (error)return error; - len = dp->d_ops->data_entsize (args->namelen); + len = dp->d_ops->data_entsize (args->name.len);/* * Set up pointers to parts of the block.
@@ -539,8 +539,8 @@ xfs_dir2_block_addname(* Create the new data entry. */ dep->inumber =cpu_to_be64 (args->inumber); - dep->namelen = args->namelen; -memcpy (dep->name, args->name, args->namelen); + dep->namelen = args->name.len; +memcpy (dep->name, args->name.name, args->name.len); dp->d_ops->data_put_ftype (dep, args->filetype); tagp = dp->d_ops->data_entry_tag_p (dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_leaf.c +3 -3
@@ -610,7 +610,7 @@ xfs_dir2_leaf_addname( ents = dp->d_ops->leaf_ents_p (leaf); dp->d_ops->leaf_hdr_from_disk (&leafhdr, leaf); bestsp =xfs_dir2_leaf_bests_p (ltp); - length = dp->d_ops->data_entsize (args->namelen); + length = dp->d_ops->data_entsize (args->name.len);/* * See if there are any entries with the same hash value
@@ -813,8 +813,8 @@ xfs_dir2_leaf_addname(*/ dep = (xfs_dir2_data_entry_t *)dup; dep->inumber =cpu_to_be64 (args->inumber); - dep->namelen = args->namelen; -memcpy (dep->name, args->name, dep->namelen); + dep->namelen = args->name.len; +memcpy (dep->name, args->name.name, dep->namelen); dp->d_ops->data_put_ftype (dep, args->filetype); tagp = dp->d_ops->data_entry_tag_p (dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_node.c +4 -4
@@ -604,7 +604,7 @@ xfs_dir2_leafn_lookup_for_addname(ASSERT (free->hdr.magic ==cpu_to_be32 (XFS_DIR2_FREE_MAGIC ) || free->hdr.magic ==cpu_to_be32 (XFS_DIR3_FREE_MAGIC )); } - length = dp->d_ops->data_entsize (args->namelen); + length = dp->d_ops->data_entsize (args->name.len);/* * Loop over leaf entries with the right hash value. */
@@ -1869,7 +1869,7 @@ xfs_dir2_node_addname_int(__be16 *tagp;/* data entry tag pointer */ __be16 *bests; - length = dp->d_ops->data_entsize (args->namelen); + length = dp->d_ops->data_entsize (args->name.len); error =xfs_dir2_node_find_freeblk (args, fblk, &dbno, &fbp, &findex, length);if (error)
@@ -1924,8 +1924,8 @@ xfs_dir2_node_addname_int(/* Fill in the new entry and log it. */ dep = (xfs_dir2_data_entry_t *)dup; dep->inumber =cpu_to_be64 (args->inumber); - dep->namelen = args->namelen; -memcpy (dep->name, args->name, dep->namelen); + dep->namelen = args->name.len; +memcpy (dep->name, args->name.name, dep->namelen); dp->d_ops->data_put_ftype (dep, args->filetype); tagp = dp->d_ops->data_entry_tag_p (dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_sf.c +15 -15
@@ -291,7 +291,7 @@ xfs_dir2_sf_addname(/* * Compute entry (and change in) size. */ - incr_isize = dp->d_ops->sf_entsize (sfp, args->namelen); + incr_isize = dp->d_ops->sf_entsize (sfp, args->name.len); objchange =0 ;/*
@@ -375,7 +375,7 @@ xfs_dir2_sf_addname_easy(/* * Grow the in-inode space. */ -xfs_idata_realloc (dp, dp->d_ops->sf_entsize (sfp, args->namelen), +xfs_idata_realloc (dp, dp->d_ops->sf_entsize (sfp, args->name.len),XFS_DATA_FORK );/* * Need to set up again due to realloc of the inode data.
@@ -385,9 +385,9 @@ xfs_dir2_sf_addname_easy(/* * Fill in the new entry. */ - sfep->namelen = args->namelen; + sfep->namelen = args->name.len;xfs_dir2_sf_put_offset (sfep, offset); -memcpy (sfep->name, args->name, sfep->namelen); +memcpy (sfep->name, args->name.name, sfep->namelen); dp->d_ops->sf_put_ino (sfp, sfep, args->inumber); dp->d_ops->sf_put_ftype (sfep, args->filetype);
@@ -446,7 +446,7 @@ xfs_dir2_sf_addname_hard(*/ for (offset = dp->d_ops->data_first_offset, oldsfep = xfs_dir2_sf_firstentry(oldsfp), - add_datasize = dp->d_ops->data_entsize(args->namelen), + add_datasize = dp->d_ops->data_entsize(args->name.len), eof = (char *)oldsfep == &buf[old_isize]; !eof; offset = new_offset + dp->d_ops->data_entsize(oldsfep->namelen),
@@ -476,9 +476,9 @@ xfs_dir2_sf_addname_hard(/* * Fill in the new entry, and update the header counts. */ - sfep->namelen = args->namelen; + sfep->namelen = args->name.len;xfs_dir2_sf_put_offset (sfep, offset); -memcpy (sfep->name, args->name, sfep->namelen); +memcpy (sfep->name, args->name.name, sfep->namelen); dp->d_ops->sf_put_ino (sfp, sfep, args->inumber); dp->d_ops->sf_put_ftype (sfep, args->filetype); sfp->count++;
@@ -522,7 +522,7 @@ xfs_dir2_sf_addname_pick( dp = args->dp; sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; - size = dp->d_ops->data_entsize (args->namelen); + size = dp->d_ops->data_entsize (args->name.len); offset = dp->d_ops->data_first_offset; sfep =xfs_dir2_sf_firstentry (sfp); holefit =0 ;
@@ -807,7 +807,7 @@ xfs_dir2_sf_lookup(/* * Special case for . */ -if (args->namelen ==1 && args->name[0 ] =='.' ) { +if (args->name.len ==1 && args->name.name[0 ] =='.' ) { args->inumber = dp->i_ino; args->cmpresult =XFS_CMP_EXACT ; args->filetype =XFS_DIR3_FT_DIR ;
@@ -816,8 +816,8 @@ xfs_dir2_sf_lookup(/* * Special case for .. */ -if (args->namelen ==2 && - args->name[0 ] =='.' && args->name[1 ] =='.' ) { +if (args->name.len ==2 && + args->name.name[0 ] =='.' && args->name.name[1 ] =='.' ) { args->inumber = dp->d_ops->sf_get_parent_ino (sfp); args->cmpresult =XFS_CMP_EXACT ; args->filetype =XFS_DIR3_FT_DIR ;
@@ -912,7 +912,7 @@ xfs_dir2_sf_removename(* Calculate sizes. */ byteoff = (int )((char *)sfep - (char *)sfp); - entsize = dp->d_ops->sf_entsize (sfp, args->namelen); + entsize = dp->d_ops->sf_entsize (sfp, args->name.len); newsize = oldsize - entsize;/* * Copy the part if any after the removed entry, sliding it down.
@@ -1002,12 +1002,12 @@ xfs_dir2_sf_replace( }else i8elevated =0 ; -ASSERT (args->namelen !=1 || args->name[0 ] !='.' ); +ASSERT (args->name.len !=1 || args->name.name[0 ] !='.' );/* * Replace ..'s entry. */ -if (args->namelen ==2 && - args->name[0 ] =='.' && args->name[1 ] =='.' ) { +if (args->name.len ==2 && + args->name.name[0 ] =='.' && args->name.name[1 ] =='.' ) { ino = dp->d_ops->sf_get_parent_ino (sfp);ASSERT (args->inumber != ino); dp->d_ops->sf_put_parent_ino (sfp, args->inumber);
fs/xfs/scrub/attr.c +6 -6
@@ -147,17 +147,17 @@ xchk_xattr_listent(return ; } - args.flags =ATTR_KERNOTIME ; + args.name.type =ATTR_KERNOTIME ;if (flags &XFS_ATTR_ROOT ) - args.flags |=ATTR_ROOT ; + args.name.type |=ATTR_ROOT ;else if (flags &XFS_ATTR_SECURE ) - args.flags |=ATTR_SECURE ; + args.name.type |=ATTR_SECURE ; args.geo = context->dp->i_mount->m_attr_geo; args.whichfork =XFS_ATTR_FORK ; args.dp = context->dp; - args.name = name; - args.namelen = namelen; - args.hashval =xfs_da_hashname (args.name, args.namelen); + args.name.name = name; + args.name.len = namelen; + args.hashval =xfs_da_hashname (args.name.name, args.name.len); args.trans = context->tp; args.value =xchk_xattr_valuebuf (sx->sc); args.valuelen = valuelen;
fs/xfs/xfs_trace.h +11 -9
@@ -1633,7 +1633,7 @@ DECLARE_EVENT_CLASS(xfs_da_class,TP_STRUCT__entry (__field (dev_t ,dev )__field (xfs_ino_t, ino) - __dynamic_array(char, name, args->namelen) + __dynamic_array(char, name, args->name.len)__field (int, namelen)__field (xfs_dahash_t, hashval) __field(xfs_ino_t, inumber)
@@ -1642,9 +1642,10 @@ DECLARE_EVENT_CLASS(xfs_da_class,TP_fast_assign ( __entry->dev = VFS_I(args->dp)->i_sb->s_dev; __entry->ino = args->dp->i_ino; -if (args->namelen) -memcpy (__get_str (name), args->name, args->namelen); - __entry->namelen = args->namelen; +if (args->name.len) +memcpy (__get_str (name), args->name.name, + args->name.len); + __entry->namelen = args->name.len; __entry->hashval = args->hashval; __entry->inumber = args->inumber; __entry->op_flags = args->op_flags;
@@ -1697,7 +1698,7 @@ DECLARE_EVENT_CLASS(xfs_attr_class,TP_STRUCT__entry (__field (dev_t ,dev )__field (xfs_ino_t, ino) - __dynamic_array(char, name, args->namelen) + __dynamic_array(char, name, args->name.len)__field (int, namelen)__field (int, valuelen) __field(xfs_dahash_t, hashval)
@@ -1707,12 +1708,13 @@ DECLARE_EVENT_CLASS(xfs_attr_class,TP_fast_assign ( __entry->dev = VFS_I(args->dp)->i_sb->s_dev; __entry->ino = args->dp->i_ino; -if (args->namelen) -memcpy (__get_str (name), args->name, args->namelen); - __entry->namelen = args->namelen; +if (args->name.len) +memcpy (__get_str (name), args->name.name, + args->name.len); + __entry->namelen = args->name.len; __entry->valuelen = args->valuelen; __entry->hashval = args->hashval; - __entry->flags = args->flags; + __entry->flags = args->name.type; __entry->op_flags = args->op_flags; ), TP_printk("dev %d:%d ino 0x%llx name %.*s namelen %d valuelen %d "
Signature · 1 line
2.7.4
Re: [PATCH v4 03/17] xfs: Embed struct xfs_name in xfs_da_args
Quoted 27 lines · Allison Collins
This patch embeds an
xfs_nameinxfs_da_args, replacing the name, namelen, and flags members. This helps to clean up thexfs_da_argsstructure and make it more uniform with the newxfs_nameparameter being passed around.Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 36 +++++++------- fs/xfs/libxfs/xfs_attr_leaf.c | 106 +++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_da_btree.c | 5 +- fs/xfs/libxfs/xfs_da_btree.h | 4 +- fs/xfs/libxfs/xfs_dir2.c | 18 +++---- fs/xfs/libxfs/xfs_dir2_block.c | 6 +-- fs/xfs/libxfs/xfs_dir2_leaf.c | 6 +-- fs/xfs/libxfs/xfs_dir2_node.c | 8 +-- fs/xfs/libxfs/xfs_dir2_sf.c | 30 ++++++------ fs/xfs/scrub/attr.c | 12 ++--- fs/xfs/xfs_trace.h | 20 ++++---- 12 files changed, 128 insertions(+), 125 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
fs/xfs/libxfs/xfs_attr.c xfs_attr_args_init( · line 75
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +1
-4@@ -72,13 +72,12 @@ xfs_attr_args_init( args->geo = dp->i_mount->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->dp = dp; - args->flags = flags; - args->name = name->name; - args->namelen = name->len; -if (args->namelen >=MAXNAMELEN ) + name->type = flags;
Is there a purpose for modifying the caller's @name, instead of setting args.name.type = flags after the memcpy?
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +4
-2+memcpy (&args->name, name,sizeof (struct xfs_name )); +if (args->name.len >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */ - args->hashval =xfs_da_hashname (args->name, args->namelen); + args->hashval =xfs_da_hashname (args->name.name, args->name.len);return 0 ; }@@ -236,7 +235,7 @@ xfs_attr_try_sf_addname(* Commit the shortform mods, and we're done. * NOTE: this is also the error path (EEXIST, etc). */ -if (!error && (args->flags &ATTR_KERNOTIME ) ==0 ) +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 )xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );if (mp->m_flags &XFS_MOUNT_WSYNC )
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 360
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +2
-0@@ -357,6 +356,9 @@ xfs_attr_set(if (error)return error; +/* Use name now stored in args */ + name = &args.name;
You could probably set this as part of the variable declaration, e.g.
struct xfs_name *name = &args.name;
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 377
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-1+ args.value = value; args.valuelen = valuelen; args.op_flags =XFS_DA_OP_ADDNAME |XFS_DA_OP_OKNOENT ;@@ -372,7 +374,7 @@ xfs_attr_set(*/ if (XFS_IFORK_Q (dp) ==0 ) {int sf_size =sizeof (xfs_attr_sf_hdr_t) + -XFS_ATTR_SF_ENTSIZE_BYNAME (args.namelen, valuelen); +XFS_ATTR_SF_ENTSIZE_BYNAME (args.name.len, valuelen);
If you're going to keep the convenience variable @name, then please use it throughout the function.
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0
-0error =xfs_bmap_add_attrfork (dp, sf_size, rsvd);if (error)
<snip>
fs/xfs/libxfs/xfs_da_btree.c xfs_da_compname( · line 2044
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.c +0
-2@@ -2040,8 +2040,9 @@ xfs_da_compname(const unsigned char *name, int len) { - return (args->namelen == len && memcmp(args->name, name, len) == 0) ? - XFS_CMP_EXACT : XFS_CMP_DIFFERENT;
Wow that's gross. :)
if (args->name.len == len && !memcmp(args->name.name, name, len)) return XFS_CMP_EXACT; return XFS_CMP_DIFFERENT;
Hmm, is that better?
The rest looks reasonable...
--D
Re: [PATCH v4 03/17] xfs: Embed struct xfs_name in xfs_da_args
Quoted 23 lines · Darrick J. Wong
Quoted 22 lines · Allison Collins
This patch embeds an
xfs_nameinxfs_da_args, replacing the name, namelen, and flags members. This helps to clean up thexfs_da_argsstructure and make it more uniform with the newxfs_nameparameter being passed around.Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 36 +++++++------- fs/xfs/libxfs/xfs_attr_leaf.c | 106 +++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_da_btree.c | 5 +- fs/xfs/libxfs/xfs_da_btree.h | 4 +- fs/xfs/libxfs/xfs_dir2.c | 18 +++---- fs/xfs/libxfs/xfs_dir2_block.c | 6 +-- fs/xfs/libxfs/xfs_dir2_leaf.c | 6 +-- fs/xfs/libxfs/xfs_dir2_node.c | 8 +-- fs/xfs/libxfs/xfs_dir2_sf.c | 30 ++++++------ fs/xfs/scrub/attr.c | 12 ++--- fs/xfs/xfs_trace.h | 20 ++++---- 12 files changed, 128 insertions(+), 125 deletions(-)
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_args_init( · line 75
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +1
-4@@ -72,13 +72,12 @@ xfs_attr_args_init( args->geo = dp->i_mount->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->dp = dp; - args->flags = flags; - args->name = name->name; - args->namelen = name->len; -if (args->namelen >=MAXNAMELEN ) + name->type = flags;Is there a purpose for modifying the caller's @name, instead of setting args.name.type = flags after the memcpy?
Not really other than to just make them consistent so that the mem copy would cover all three members. I think initially they were set individually, but people preferred the memcpy, and then later we decided to break the flags variable out of the name struct. I can explicitly set args.name.type if folks prefer.
A subtle pitfall I noticed about using the name struct like this now: callers need to take care to abandon the original name struct or update the original pointer to this struct. It's kind of easy to continue using the original struct like it's a convenience pointer, but it not the same memory so if args gets passed into some subroutine that modifies it, now you're out of sync. If it doesnt get passed around or modified, it doesnt matter, but we've created a sort of usage rule about how to handle the name param which may not be entirely obvious to other developers.
Quoted 23 lines
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +4
-2+memcpy (&args->name, name,sizeof (struct xfs_name )); +if (args->name.len >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */ - args->hashval =xfs_da_hashname (args->name, args->namelen); + args->hashval =xfs_da_hashname (args->name.name, args->name.len);return 0 ; }@@ -236,7 +235,7 @@ xfs_attr_try_sf_addname(* Commit the shortform mods, and we're done. * NOTE: this is also the error path (EEXIST, etc). */ -if (!error && (args->flags &ATTR_KERNOTIME ) ==0 ) +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 )xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );if (mp->m_flags &XFS_MOUNT_WSYNC )@@ -357,6 +356,9 @@ xfs_attr_set(if (error)return error;
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 360
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+/* Use name now stored in args */ + name = &args.name;You could probably set this as part of the variable declaration, e.g.
struct
xfs_name*name = &args.name;
No, because name is a parameter here, so you would loose the contents at the start of the function if we did this. And then args init would memcopy and empty struct onto itself. And then confusion would ensue.... :-(
Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 377
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +2
-1+ args.value = value; args.valuelen = valuelen; args.op_flags =XFS_DA_OP_ADDNAME |XFS_DA_OP_OKNOENT ;@@ -372,7 +374,7 @@ xfs_attr_set(*/ if (XFS_IFORK_Q (dp) ==0 ) {int sf_size =sizeof (xfs_attr_sf_hdr_t) + -XFS_ATTR_SF_ENTSIZE_BYNAME (args.namelen, valuelen); +XFS_ATTR_SF_ENTSIZE_BYNAME (args.name.len, valuelen);If you're going to keep the convenience variable @name, then please use it throughout the function.
I think this is the only place it's used for this function at this time.
I use it later in patch 15 though. I think I stumbled across the name
sync bug then, and corrected it with the parameter pointer assignment above just because it seemed like the right place to fix it.
Do you want the function to uniformly use an explicit reference, or the param? Seems like a bit of a wart unfortunately :-(
Quoted 20 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-0error =xfs_bmap_add_attrfork (dp, sf_size, rsvd);if (error)<snip>
fs/xfs/libxfs/xfs_da_btree.c xfs_da_compname( · line 2044
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.c +0
-2@@ -2040,8 +2040,9 @@ xfs_da_compname(const unsigned char *name, int len) { - return (args->namelen == len && memcmp(args->name, name, len) == 0) ? - XFS_CMP_EXACT : XFS_CMP_DIFFERENT;Wow that's gross. :)
Quoted 6 lines
if (args->name.len == len && !memcmp(args->name.name, name, len)) return XFS_CMP_EXACT; return XFS_CMP_DIFFERENT;Hmm, is that better?
Sure, will fix.
Allison
Quoted 5 lines
The rest looks reasonable...
--D
Re: [PATCH v4 03/17] xfs: Embed struct xfs_name in xfs_da_args
Quoted 46 lines · Allison Collins
Quoted 23 lines · Darrick J. Wong
Quoted 22 lines · Allison Collins
This patch embeds an
xfs_nameinxfs_da_args, replacing the name, namelen, and flags members. This helps to clean up thexfs_da_argsstructure and make it more uniform with the newxfs_nameparameter being passed around.Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 36 +++++++------- fs/xfs/libxfs/xfs_attr_leaf.c | 106 +++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_da_btree.c | 5 +- fs/xfs/libxfs/xfs_da_btree.h | 4 +- fs/xfs/libxfs/xfs_dir2.c | 18 +++---- fs/xfs/libxfs/xfs_dir2_block.c | 6 +-- fs/xfs/libxfs/xfs_dir2_leaf.c | 6 +-- fs/xfs/libxfs/xfs_dir2_node.c | 8 +-- fs/xfs/libxfs/xfs_dir2_sf.c | 30 ++++++------ fs/xfs/scrub/attr.c | 12 ++--- fs/xfs/xfs_trace.h | 20 ++++---- 12 files changed, 128 insertions(+), 125 deletions(-)Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_args_init( · line 75
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +1
-4@@ -72,13 +72,12 @@ xfs_attr_args_init( args->geo = dp->i_mount->m_attr_geo; args->whichfork =XFS_ATTR_FORK ; args->dp = dp; - args->flags = flags; - args->name = name->name; - args->namelen = name->len; -if (args->namelen >=MAXNAMELEN ) + name->type = flags;Is there a purpose for modifying the caller's @name, instead of setting args.name.type = flags after the memcpy?
Not really other than to just make them consistent so that the mem copy would cover all three members. I think initially they were set individually, but people preferred the memcpy, and then later we decided to break the flags variable out of the name struct. I can explicitly set args.name.type if folks prefer.
Quoted 8 lines
A subtle pitfall I noticed about using the name struct like this now:
callers need to take care to abandon the original name struct or update the original pointer to this struct. It's kind of easy to continue using the original struct like it's a convenience pointer, but it not the same memory so if args gets passed into some subroutine that modifies it, now you're out of sync. If it doesnt get passed around or modified, it doesnt matter, but we've created a sort of usage rule about how to handle the name param which may not be entirely obvious to other developers.
Hm, maybe the da_args should keep a pointer to the caller's name, if you're worried about coherency between different xfs_names?
Though, the only state that changes is the type field, right? Maybe we don't care and that should stay internal to the da_args anyway...
Quoted 43 lines
Quoted 24 lines
Quoted 17 lines
fs/xfs/libxfs/xfs_attr.c +4
-2+memcpy (&args->name, name,sizeof (struct xfs_name )); +if (args->name.len >=MAXNAMELEN )return -EFAULT ;/* match IRIX behaviour */ - args->hashval =xfs_da_hashname (args->name, args->namelen); + args->hashval =xfs_da_hashname (args->name.name, args->name.len);return 0 ; }@@ -236,7 +235,7 @@ xfs_attr_try_sf_addname(* Commit the shortform mods, and we're done. * NOTE: this is also the error path (EEXIST, etc). */ -if (!error && (args->flags &ATTR_KERNOTIME ) ==0 ) +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 )xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );if (mp->m_flags &XFS_MOUNT_WSYNC )fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 359
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +2
-0@@ -357,6 +356,9 @@ xfs_attr_set(if (error)return error; +/* Use name now stored in args */ + name = &args.name;You could probably set this as part of the variable declaration, e.g.
Quoted 1 line
struct
xfs_name*name = &args.name;No, because name is a parameter here, so you would loose the contents at the start of the function if we did this. And then args init would memcopy and empty struct onto itself. And then confusion would ensue.... :-(
Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 377
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +2
-1+ args.value = value; args.valuelen = valuelen; args.op_flags =XFS_DA_OP_ADDNAME |XFS_DA_OP_OKNOENT ;@@ -372,7 +374,7 @@ xfs_attr_set(*/ if (XFS_IFORK_Q (dp) ==0 ) {int sf_size =sizeof (xfs_attr_sf_hdr_t) + -XFS_ATTR_SF_ENTSIZE_BYNAME (args.namelen, valuelen); +XFS_ATTR_SF_ENTSIZE_BYNAME (args.name.len, valuelen);If you're going to keep the convenience variable @name, then please use it throughout the function.
Quoted 7 lines
I think this is the only place it's used for this function at this time. I use it later in patch 15 though. I think I stumbled across the name sync bug then, and corrected it with the parameter pointer assignment above just because it seemed like the right place to fix it.
Do you want the function to uniformly use an explicit reference, or the param? Seems like a bit of a wart unfortunately :-(
One or the other, just not both mixed in the same function.
--D
Quoted 34 lines
Quoted 19 lines
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0
-0error =xfs_bmap_add_attrfork (dp, sf_size, rsvd);if (error)<snip>
fs/xfs/libxfs/xfs_da_btree.c xfs_da_compname( · line 2044
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.c +0
-2@@ -2040,8 +2040,9 @@ xfs_da_compname(const unsigned char *name, int len) { - return (args->namelen == len && memcmp(args->name, name, len) == 0) ? - XFS_CMP_EXACT : XFS_CMP_DIFFERENT;Wow that's gross. :)
Quoted 6 lines
if (args->name.len == len && !memcmp(args->name.name, name, len)) return XFS_CMP_EXACT; return XFS_CMP_DIFFERENT;Hmm, is that better?
Sure, will fix.
Allison
Quoted 5 lines
The rest looks reasonable...
--D
PATCH v4 4/17 xfs: Add xfs_dabuf defines
In reply to Allison CollinsThis patch adds two new defines XFS_DABUF_MAP_NOMAPPING and XFS_DABUF_MAP_HOLE_OK. This helps to clean up hard numbers and makes the code easier to read
--- fs/xfs/libxfs/xfs_attr.c | 14 +++++++----- fs/xfs/libxfs/xfs_attr_leaf.c | 23 +++++++++++-------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++ fs/xfs/libxfs/xfs_da_btree.c | 50 ++++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_dir2_block.c | 6 +++-- fs/xfs/libxfs/xfs_dir2_data.c | 3 ++- fs/xfs/libxfs/xfs_dir2_leaf.c | 9 +++++--- fs/xfs/libxfs/xfs_dir2_node.c | 10 +++++---- fs/xfs/scrub/dabtree.c | 6 ++--- fs/xfs/scrub/dir.c | 4 +++- fs/xfs/xfs_attr_inactive.c | 6 +++-- fs/xfs/xfs_attr_list.c | 16 +++++++++----- 12 files changed, 97 insertions(+), 53 deletions(-)
fs/xfs/libxfs/xfs_attr.c +9 -5
@@ -591,7 +591,8 @@ xfs_attr_leaf_addname(*/ dp = args->dp; args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
@@ -717,7 +718,7 @@ xfs_attr_leaf_addname(* remove the "old" attr from that block (neat, huh!) */ error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, --1 , &bp); +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
@@ -771,7 +772,8 @@ xfs_attr_leaf_removename(*/ dp = args->dp; args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
@@ -815,7 +817,8 @@ xfs_attr_leaf_get(xfs_da_args_t *args)trace_xfs_attr_leaf_get (args); args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
@@ -1175,7 +1178,8 @@ xfs_attr_node_removename(ASSERT (state->path.blk[0 ].bp); state->path.blk[0 ].bp =NULL ; - error =xfs_attr3_leaf_read (args->trans, args->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp,0 , +XFS_DABUF_MAP_NOMAPPING , &bp);if (error) goto out;
fs/xfs/libxfs/xfs_attr_leaf.c +14 -9
@@ -1160,11 +1160,13 @@ xfs_attr3_leaf_to_node( error =xfs_da_grow_inode (args, &blkno);if (error) goto out; - error =xfs_attr3_leaf_read (args->trans, dp,0 ,-1 , &bp1); + error =xfs_attr3_leaf_read (args->trans, dp,0 ,XFS_DABUF_MAP_NOMAPPING , + &bp1);if (error) goto out; - error =xfs_da_get_buf (args->trans, dp, blkno,-1 , &bp2,XFS_ATTR_FORK ); + error =xfs_da_get_buf (args->trans, dp, blkno,XFS_DABUF_MAP_NOMAPPING , + &bp2,XFS_ATTR_FORK );if (error) goto out;
@@ -1226,8 +1228,8 @@ xfs_attr3_leaf_create(trace_xfs_attr_leaf_create (args); - error =xfs_da_get_buf (args->trans, args->dp, blkno,-1 , &bp, -XFS_ATTR_FORK ); + error =xfs_da_get_buf (args->trans, args->dp, blkno, +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_ATTR_FORK );if (error)return error; bp->b_ops = &xfs_attr3_leaf_buf_ops;
@@ -1997,7 +1999,7 @@ xfs_attr3_leaf_toosmall(if (blkno ==0 )continue ; error =xfs_attr3_leaf_read (state->args->trans, state->args->dp, - blkno,-1 , &bp); + blkno,XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
@@ -2730,7 +2732,8 @@ xfs_attr3_leaf_clearflag(/* * Set up the operation. */ - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
@@ -2797,7 +2800,8 @@ xfs_attr3_leaf_setflag(/* * Set up the operation. */ - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
@@ -2859,7 +2863,8 @@ xfs_attr3_leaf_flipflags(/* * Read the block containing the "old" attr */ - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp1); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp1);if (error)return error;
@@ -2868,7 +2873,7 @@ xfs_attr3_leaf_flipflags(*/ if (args->blkno2 != args->blkno) { error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno2, --1 , &bp2); +XFS_DABUF_MAP_NOMAPPING , &bp2);if (error)return error; }else {
fs/xfs/libxfs/xfs_attr_leaf.h +3 -0
@@ -16,6 +16,9 @@ struct xfs_da_state_blk;struct xfs_inode ;struct xfs_trans ; +#define XFS_DABUF_MAP_NOMAPPING (-1)/* Caller doesn't have a mapping. */ +#define XFS_DABUF_MAP_HOLE_OK (-2)/* don't complain if we land in a hole. */ +/* * Used to keep a list of "remote value" extents when unlinking an inode. */
fs/xfs/libxfs/xfs_da_btree.c +33 -17
146 lines not on this page · raw message
fs/xfs/libxfs/xfs_dir2_block.c +4 -2
@@ -20,6 +20,7 @@#include "xfs_error.h" #include "xfs_trace.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Local function prototypes.
@@ -123,8 +124,9 @@ xfs_dir3_block_read(struct xfs_mount *mp = dp->i_mount;int err; - err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk,-1 , bpp, -XFS_DATA_FORK , &xfs_dir3_block_buf_ops); + err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk, +XFS_DABUF_MAP_NOMAPPING , bpp,XFS_DATA_FORK , + &xfs_dir3_block_buf_ops);if (!err && tp && *bpp)xfs_trans_buf_set_type (tp, *bpp,XFS_BLFT_DIR_BLOCK_BUF );return err;
fs/xfs/libxfs/xfs_dir2_data.c +2 -1
@@ -17,6 +17,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" static xfs_failaddr_t xfs_dir2_data_freefind_verify( struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,
@@ -653,7 +654,7 @@ xfs_dir3_data_init(* Get the buffer set up for the block. */ error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, blkno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error; bp->b_ops = &xfs_dir3_data_buf_ops;
fs/xfs/libxfs/xfs_dir2_leaf.c +6 -3
@@ -19,6 +19,7 @@#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_buf_item.h" +#include "xfs_attr_leaf.h" /* * Local function declarations.
@@ -311,7 +312,7 @@ xfs_dir3_leaf_get_buf( bno < xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET)); error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, bno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;
@@ -594,7 +595,8 @@ xfs_dir2_leaf_addname(trace_xfs_dir2_leaf_addname (args); - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;
@@ -1189,7 +1191,8 @@ xfs_dir2_leaf_lookup_int( tp = args->trans; mp = dp->i_mount; - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;
fs/xfs/libxfs/xfs_dir2_node.c +6 -4
@@ -20,6 +20,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Function declarations.
@@ -227,7 +228,7 @@ xfs_dir2_free_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -1, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_NOMAPPING, bpp); } static int
@@ -237,7 +238,7 @@ xfs_dir2_free_try_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_HOLE_OK, bpp); } static int
@@ -254,7 +255,7 @@ xfs_dir3_free_get_buf(struct xfs_dir3_icfree_hdr hdr; error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, fbno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;
@@ -1495,7 +1496,8 @@ xfs_dir2_leafn_toosmall(* Read the sibling leaf block. */ error =xfs_dir3_leafn_read (state->args->trans, dp, - blkno,-1 , &bp); + blkno,XFS_DABUF_MAP_NOMAPPING , + &bp);if (error)return error;
fs/xfs/scrub/dabtree.c +3 -3
@@ -355,9 +355,9 @@ xchk_da_btree_block( goto out_nobuf;/* Read the buffer. */ - error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno,-2 , - &blk->bp, dargs->whichfork, - &xchk_da_btree_buf_ops); + error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno, +XFS_DABUF_MAP_HOLE_OK , &blk->bp, + dargs->whichfork, &xchk_da_btree_buf_ops);if (!xchk_da_process_error (ds, level, &error)) goto out_nobuf;if (blk->bp)
fs/xfs/scrub/dir.c +3 -1
@@ -18,6 +18,7 @@#include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/dabtree.h" +#include "xfs_attr_leaf.h" /* Set us up to scrub directories. */ int
@@ -492,7 +493,8 @@ xchk_directory_leaf1_bestfree(int error;/* Read the free space block. */ - error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk,-1 , &bp); + error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk, +XFS_DABUF_MAP_NOMAPPING , &bp);if (!xchk_fblock_process_error (sc,XFS_DATA_FORK , lblk, &error)) goto out;xchk_buffer_recheck (sc, bp);
fs/xfs/xfs_attr_inactive.c +4 -2
@@ -235,7 +235,8 @@ xfs_attr3_node_inactive(* traversal of the tree so we may deal with many blocks * before we come back to this one. */ - error =xfs_da3_node_read (*trans, dp, child_fsb,-1 , &child_bp, + error =xfs_da3_node_read (*trans, dp, child_fsb, +XFS_DABUF_MAP_NOMAPPING , &child_bp,XFS_ATTR_FORK );if (error)return error;
@@ -321,7 +322,8 @@ xfs_attr3_root_inactive(* the extents in reverse order the extent containing * block 0 must still be there. */ - error =xfs_da3_node_read (*trans, dp,0 ,-1 , &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (*trans, dp,0 ,XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; blkno = bp->b_bn;
fs/xfs/xfs_attr_list.c +10 -6
@@ -224,8 +224,9 @@ xfs_attr_node_list_lookup(ASSERT (*pbp ==NULL ); cursor->blkno =0 ;for (;;) { - error =xfs_da3_node_read (tp, dp, cursor->blkno,-1 , &bp, -XFS_ATTR_FORK ); + error =xfs_da3_node_read (tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; node = bp->b_addr;
@@ -309,8 +310,9 @@ xfs_attr_node_list(*/ bp =NULL ;if (cursor->blkno >0 ) { - error =xfs_da3_node_read (context->tp, dp, cursor->blkno,-1 , - &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if ((error !=0 ) && (error != -EFSCORRUPTED ))return error;if (bp) {
@@ -377,7 +379,8 @@ xfs_attr_node_list(break ; cursor->blkno = leafhdr.forw;xfs_trans_brelse (context->tp, bp); - error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error; }
@@ -497,7 +500,8 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)trace_xfs_attr_leaf_list (context); context->cursor->blkno =0 ; - error =xfs_attr3_leaf_read (context->tp, context->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, context->dp,0 , +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
Signature · 1 line
2.7.4
Re: [PATCH v4 04/17] xfs: Add xfs_dabuf defines
Quoted 19 lines · Allison Collins
This patch adds two new defines
XFS_DABUF_MAP_NOMAPPINGandXFS_DABUF_MAP_HOLE_OK. This helps to clean up hard numbers and makes the code easier to readSigned-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 14 +++++++----- fs/xfs/libxfs/xfs_attr_leaf.c | 23 +++++++++++-------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++ fs/xfs/libxfs/xfs_da_btree.c | 50 ++++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_dir2_block.c | 6 +++-- fs/xfs/libxfs/xfs_dir2_data.c | 3 ++- fs/xfs/libxfs/xfs_dir2_leaf.c | 9 +++++--- fs/xfs/libxfs/xfs_dir2_node.c | 10 +++++---- fs/xfs/scrub/dabtree.c | 6 ++--- fs/xfs/scrub/dir.c | 4 +++- fs/xfs/xfs_attr_inactive.c | 6 +++-- fs/xfs/xfs_attr_list.c | 16 +++++++++----- 12 files changed, 97 insertions(+), 53 deletions(-)
<snip>
fs/xfs/libxfs/xfs_attr_leaf.h struct xfs_da_state_blk; · line 20
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -16,6 +16,9 @@ struct xfs_da_state_blk;struct xfs_inode ;struct xfs_trans ; +#define XFS_DABUF_MAP_NOMAPPING (-1)/* Caller doesn't have a mapping. */ +#define XFS_DABUF_MAP_HOLE_OK (-2)/* don't complain if we land in a hole. */
These are parameters to xfs_da_{get,read,reada}_buf, please put them next to the declarations for those functions.
Also they probably ought to be explicitly cast to xfs_daddr_t, e.g.
/* Force a fresh lookup for the dir/attr mapping. */
#define XFS_DABUF_MAP_NOMAPPING ((xfs_daddr_t)-1)
/* Don't complain if we land in a hole. */
#define XFS_DABUF_MAP_HOLE_OK ((xfs_daddr_t)-2)
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.h +1
-0+/* * Used to keep a list of "remote value" extents when unlinking an inode. */
<snip>
Quoted 14 lines
fs/xfs/libxfs/xfs_dir2_block.c +1
-0@@ -20,6 +20,7 @@#include "xfs_error.h" #include "xfs_trace.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Local function prototypes. @@ -123,8 +124,9 @@ xfs_dir3_block_read(struct xfs_mount *mp = dp->i_mount;
fs/xfs/libxfs/xfs_dir2_block.c xfs_dir3_block_read( · line 132
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_block.c +3
-2int err; - err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk,-1 , bpp, -XFS_DATA_FORK , &xfs_dir3_block_buf_ops); + err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk, +XFS_DABUF_MAP_NOMAPPING , bpp,XFS_DATA_FORK , + &xfs_dir3_block_buf_ops);if (!err && tp && *bpp)xfs_trans_buf_set_type (tp, *bpp,XFS_BLFT_DIR_BLOCK_BUF );return err;
I think this misses the xfs_dir3_data_read call in xfs_dir2_leaf_to_block?
Quoted 43 lines
fs/xfs/libxfs/xfs_dir2_data.c +2
-1@@ -17,6 +17,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" static xfs_failaddr_t xfs_dir2_data_freefind_verify( struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,@@ -653,7 +654,7 @@ xfs_dir3_data_init(* Get the buffer set up for the block. */ error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, blkno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error; bp->b_ops = &xfs_dir3_data_buf_ops;fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -19,6 +19,7 @@#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_buf_item.h" +#include "xfs_attr_leaf.h" /* * Local function declarations. @@ -311,7 +312,7 @@ xfs_dir3_leaf_get_buf( bno < xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET)); error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, bno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;
fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_addname( · line 602
Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -594,7 +595,8 @@ xfs_dir2_leaf_addname(trace_xfs_dir2_leaf_addname (args); - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;
I think there are some missing conversions for xfs_dir3_data_read calls in xfs_dir2_leaf_addname...
fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_lookup_int( · line 1198
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -1189,7 +1191,8 @@ xfs_dir2_leaf_lookup_int( tp = args->trans; mp = dp->i_mount; - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;
...and two more dir3_leaf_read calls further down in this function...
...and one more in xfs_dir2_leaf_trim_data...
Quoted 31 lines
fs/xfs/libxfs/xfs_dir2_node.c +3
-2@@ -20,6 +20,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Function declarations. @@ -227,7 +228,7 @@ xfs_dir2_free_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -1, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_NOMAPPING, bpp); } static int@@ -237,7 +238,7 @@ xfs_dir2_free_try_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_HOLE_OK, bpp); } static int
fs/xfs/libxfs/xfs_dir2_node.c xfs_dir3_free_get_buf( · line 261
Quoted 8 lines
fs/xfs/libxfs/xfs_dir2_node.c +1
-1@@ -254,7 +255,7 @@ xfs_dir3_free_get_buf(struct xfs_dir3_icfree_hdr hdr; error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, fbno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;
...there's also a missing call in xfs_dir2_leafn_lookup_for_entry...
fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leafn_toosmall( · line 1503
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_node.c +2
-1@@ -1495,7 +1496,8 @@ xfs_dir2_leafn_toosmall(* Read the sibling leaf block. */ error =xfs_dir3_leafn_read (state->args->trans, dp, - blkno,-1 , &bp); + blkno,XFS_DABUF_MAP_NOMAPPING , + &bp);if (error)return error;
...and another one in xfs_dir2_node_addname_int.
Quoted 22 lines
fs/xfs/scrub/dabtree.c +3
-3@@ -355,9 +355,9 @@ xchk_da_btree_block( goto out_nobuf;/* Read the buffer. */ - error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno,-2 , - &blk->bp, dargs->whichfork, - &xchk_da_btree_buf_ops); + error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno, +XFS_DABUF_MAP_HOLE_OK , &blk->bp, + dargs->whichfork, &xchk_da_btree_buf_ops);if (!xchk_da_process_error (ds, level, &error)) goto out_nobuf;if (blk->bp)fs/xfs/scrub/dir.c +0
-0
fs/xfs/scrub/dir.c line 24
Quoted 7 lines
fs/xfs/scrub/dir.c +1
-0@@ -18,6 +18,7 @@#include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/dabtree.h" +#include "xfs_attr_leaf.h" /* Set us up to scrub directories. */ int
I also noticed missing conversions for xfs_dir3_data_read in xchk_dir_rec, xchk_directory_data_bestfree, xchk_directory_leaf1_bestfree, and xchk_directory_free_bestfree.
fs/xfs/scrub/dir.c xchk_directory_leaf1_bestfree( · line 500
Quoted 10 lines
fs/xfs/scrub/dir.c +2
-1@@ -492,7 +493,8 @@ xchk_directory_leaf1_bestfree(int error;/* Read the free space block. */ - error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk,-1 , &bp); + error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk, +XFS_DABUF_MAP_NOMAPPING , &bp);if (!xchk_fblock_process_error (sc,XFS_DATA_FORK , lblk, &error)) goto out;xchk_buffer_recheck (sc, bp);
There's also a missing xfs_dir3_data_readahead conversion in xchk_parent_count_parent_dentries in fs/xfs/scrub/parent.c.
Quoted 63 lines
fs/xfs/xfs_attr_inactive.c +4
-2@@ -235,7 +235,8 @@ xfs_attr3_node_inactive(* traversal of the tree so we may deal with many blocks * before we come back to this one. */ - error =xfs_da3_node_read (*trans, dp, child_fsb,-1 , &child_bp, + error =xfs_da3_node_read (*trans, dp, child_fsb, +XFS_DABUF_MAP_NOMAPPING , &child_bp,XFS_ATTR_FORK );if (error)return error;@@ -321,7 +322,8 @@ xfs_attr3_root_inactive(* the extents in reverse order the extent containing * block 0 must still be there. */ - error =xfs_da3_node_read (*trans, dp,0 ,-1 , &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (*trans, dp,0 ,XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; blkno = bp->b_bn;fs/xfs/xfs_attr_list.c +8
-5@@ -224,8 +224,9 @@ xfs_attr_node_list_lookup(ASSERT (*pbp ==NULL ); cursor->blkno =0 ;for (;;) { - error =xfs_da3_node_read (tp, dp, cursor->blkno,-1 , &bp, -XFS_ATTR_FORK ); + error =xfs_da3_node_read (tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; node = bp->b_addr;@@ -309,8 +310,9 @@ xfs_attr_node_list(*/ bp =NULL ;if (cursor->blkno >0 ) { - error =xfs_da3_node_read (context->tp, dp, cursor->blkno,-1 , - &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if ((error !=0 ) && (error != -EFSCORRUPTED ))return error;if (bp) {@@ -377,7 +379,8 @@ xfs_attr_node_list(break ; cursor->blkno = leafhdr.forw;xfs_trans_brelse (context->tp, bp); - error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error; }
fs/xfs/xfs_attr_list.c xfs_attr_leaf_list(xfs_attr_list_context_t *context) · line 507
Quoted 9 lines
fs/xfs/xfs_attr_list.c +2
-1@@ -497,7 +500,8 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)trace_xfs_attr_leaf_list (context); context->cursor->blkno =0 ; - error =xfs_attr3_leaf_read (context->tp, context->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, context->dp,0 , +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;
...more missing conversions of xfs_dir3_data_read in xfs_dir2_leaf_readbuf; and of xfs_dir3_data_readahead in xfs_dir2_leaf_readbuf...
...and a missing conversion of xfs_dir3_data_readahead in xfs_dir_open in fs/xfs/xfs_file.c.
--D
Quoted 3 lines
Signature · 1 line
2.7.4
Re: [PATCH v4 04/17] xfs: Add xfs_dabuf defines
Quoted 31 lines · Darrick J. Wong
Quoted 19 lines · Allison Collins
This patch adds two new defines
XFS_DABUF_MAP_NOMAPPINGandXFS_DABUF_MAP_HOLE_OK. This helps to clean up hard numbers and makes the code easier to readSigned-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 14 +++++++----- fs/xfs/libxfs/xfs_attr_leaf.c | 23 +++++++++++-------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++ fs/xfs/libxfs/xfs_da_btree.c | 50 ++++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_dir2_block.c | 6 +++-- fs/xfs/libxfs/xfs_dir2_data.c | 3 ++- fs/xfs/libxfs/xfs_dir2_leaf.c | 9 +++++--- fs/xfs/libxfs/xfs_dir2_node.c | 10 +++++---- fs/xfs/scrub/dabtree.c | 6 ++--- fs/xfs/scrub/dir.c | 4 +++- fs/xfs/xfs_attr_inactive.c | 6 +++-- fs/xfs/xfs_attr_list.c | 16 +++++++++----- 12 files changed, 97 insertions(+), 53 deletions(-)<snip>
Quoted 8 lines
fs/xfs/libxfs/xfs_attr_leaf.h +0
-0@@ -16,6 +16,9 @@ struct xfs_da_state_blk;struct xfs_inode ;struct xfs_trans ;
Quoted 5 lines
fs/xfs/libxfs/xfs_attr_leaf.h struct xfs_da_state_blk; · line 20
Quoted 2 lines
fs/xfs/libxfs/xfs_attr_leaf.h +2
-0+#define XFS_DABUF_MAP_NOMAPPING (-1)/* Caller doesn't have a mapping. */ +#define XFS_DABUF_MAP_HOLE_OK (-2)/* don't complain if we land in a hole. */ These are parameters to xfs_da_{get,read,reada}_buf, please put them next to the declarations for those functions.
Hmm, I dont see that these are declared in a header file, but how about fs/xfs/libxfs/xfs_da_btree.h ? Did I miss them somewhere?
Allison
Quoted 303 lines
Also they probably ought to be explicitly cast to
xfs_daddr_t, e.g./* Force a fresh lookup for the dir/attr mapping. */
#defineXFS_DABUF_MAP_NOMAPPING((xfs_daddr_t)-1)/* Don't complain if we land in a hole. */
#defineXFS_DABUF_MAP_HOLE_OK((xfs_daddr_t)-2)Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.h +1
-0+/* * Used to keep a list of "remote value" extents when unlinking an inode. */ <snip>
Quoted 14 lines
fs/xfs/libxfs/xfs_dir2_block.c +1
-0@@ -20,6 +20,7 @@#include "xfs_error.h" #include "xfs_trace.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Local function prototypes. @@ -123,8 +124,9 @@ xfs_dir3_block_read(struct xfs_mount *mp = dp->i_mount;fs/xfs/libxfs/xfs_dir2_block.c xfs_dir3_block_read( · line 132
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_block.c +3
-2int err; - err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk,-1 , bpp, -XFS_DATA_FORK , &xfs_dir3_block_buf_ops); + err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk, +XFS_DABUF_MAP_NOMAPPING , bpp,XFS_DATA_FORK , + &xfs_dir3_block_buf_ops);if (!err && tp && *bpp)xfs_trans_buf_set_type (tp, *bpp,XFS_BLFT_DIR_BLOCK_BUF );return err;I think this misses the
xfs_dir3_data_readcall inxfs_dir2_leaf_to_block?Quoted 43 lines
fs/xfs/libxfs/xfs_dir2_data.c +2
-1@@ -17,6 +17,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" static xfs_failaddr_t xfs_dir2_data_freefind_verify( struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,@@ -653,7 +654,7 @@ xfs_dir3_data_init(* Get the buffer set up for the block. */ error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, blkno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error; bp->b_ops = &xfs_dir3_data_buf_ops;fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -19,6 +19,7 @@#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_buf_item.h" +#include "xfs_attr_leaf.h" /* * Local function declarations. @@ -311,7 +312,7 @@ xfs_dir3_leaf_get_buf( bno < xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET)); error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, bno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_addname( · line 602
Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -594,7 +595,8 @@ xfs_dir2_leaf_addname(trace_xfs_dir2_leaf_addname (args); - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;I think there are some missing conversions for
xfs_dir3_data_readcalls inxfs_dir2_leaf_addname...fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_lookup_int( · line 1198
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -1189,7 +1191,8 @@ xfs_dir2_leaf_lookup_int( tp = args->trans; mp = dp->i_mount; - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;...and two more
dir3_leaf_readcalls further down in this function......and one more in
xfs_dir2_leaf_trim_data...Quoted 31 lines
fs/xfs/libxfs/xfs_dir2_node.c +3
-2@@ -20,6 +20,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Function declarations. @@ -227,7 +228,7 @@ xfs_dir2_free_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -1, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_NOMAPPING, bpp); } static int@@ -237,7 +238,7 @@ xfs_dir2_free_try_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_HOLE_OK, bpp); } static intfs/xfs/libxfs/xfs_dir2_node.c xfs_dir3_free_get_buf( · line 261
Quoted 8 lines
fs/xfs/libxfs/xfs_dir2_node.c +1
-1@@ -254,7 +255,7 @@ xfs_dir3_free_get_buf(struct xfs_dir3_icfree_hdr hdr; error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, fbno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;...there's also a missing call in
xfs_dir2_leafn_lookup_for_entry...fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leafn_toosmall( · line 1503
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_node.c +2
-1@@ -1495,7 +1496,8 @@ xfs_dir2_leafn_toosmall(* Read the sibling leaf block. */ error =xfs_dir3_leafn_read (state->args->trans, dp, - blkno,-1 , &bp); + blkno,XFS_DABUF_MAP_NOMAPPING , + &bp);if (error)return error;...and another one in
xfs_dir2_node_addname_int.Quoted 22 lines
fs/xfs/scrub/dabtree.c +3
-3@@ -355,9 +355,9 @@ xchk_da_btree_block( goto out_nobuf;/* Read the buffer. */ - error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno,-2 , - &blk->bp, dargs->whichfork, - &xchk_da_btree_buf_ops); + error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno, +XFS_DABUF_MAP_HOLE_OK , &blk->bp, + dargs->whichfork, &xchk_da_btree_buf_ops);if (!xchk_da_process_error (ds, level, &error)) goto out_nobuf;if (blk->bp)fs/xfs/scrub/dir.c +0
-0fs/xfs/scrub/dir.c line 24
Quoted 7 lines
fs/xfs/scrub/dir.c +1
-0@@ -18,6 +18,7 @@#include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/dabtree.h" +#include "xfs_attr_leaf.h" /* Set us up to scrub directories. */ int I also noticed missing conversions for
xfs_dir3_data_readinxchk_dir_rec,xchk_directory_data_bestfree,xchk_directory_leaf1_bestfree, andxchk_directory_free_bestfree.fs/xfs/scrub/dir.c xchk_directory_leaf1_bestfree( · line 500
Quoted 10 lines
fs/xfs/scrub/dir.c +2
-1@@ -492,7 +493,8 @@ xchk_directory_leaf1_bestfree(int error;/* Read the free space block. */ - error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk,-1 , &bp); + error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk, +XFS_DABUF_MAP_NOMAPPING , &bp);if (!xchk_fblock_process_error (sc,XFS_DATA_FORK , lblk, &error)) goto out;xchk_buffer_recheck (sc, bp);There's also a missing
xfs_dir3_data_readaheadconversion inxchk_parent_count_parent_dentriesinfs/xfs/scrub/parent.c.Quoted 63 lines
fs/xfs/xfs_attr_inactive.c +4
-2@@ -235,7 +235,8 @@ xfs_attr3_node_inactive(* traversal of the tree so we may deal with many blocks * before we come back to this one. */ - error =xfs_da3_node_read (*trans, dp, child_fsb,-1 , &child_bp, + error =xfs_da3_node_read (*trans, dp, child_fsb, +XFS_DABUF_MAP_NOMAPPING , &child_bp,XFS_ATTR_FORK );if (error)return error;@@ -321,7 +322,8 @@ xfs_attr3_root_inactive(* the extents in reverse order the extent containing * block 0 must still be there. */ - error =xfs_da3_node_read (*trans, dp,0 ,-1 , &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (*trans, dp,0 ,XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; blkno = bp->b_bn;fs/xfs/xfs_attr_list.c +8
-5@@ -224,8 +224,9 @@ xfs_attr_node_list_lookup(ASSERT (*pbp ==NULL ); cursor->blkno =0 ;for (;;) { - error =xfs_da3_node_read (tp, dp, cursor->blkno,-1 , &bp, -XFS_ATTR_FORK ); + error =xfs_da3_node_read (tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; node = bp->b_addr;@@ -309,8 +310,9 @@ xfs_attr_node_list(*/ bp =NULL ;if (cursor->blkno >0 ) { - error =xfs_da3_node_read (context->tp, dp, cursor->blkno,-1 , - &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if ((error !=0 ) && (error != -EFSCORRUPTED ))return error;if (bp) {@@ -377,7 +379,8 @@ xfs_attr_node_list(break ; cursor->blkno = leafhdr.forw;xfs_trans_brelse (context->tp, bp); - error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error; }fs/xfs/xfs_attr_list.c xfs_attr_leaf_list(xfs_attr_list_context_t *context) · line 507
Quoted 9 lines
fs/xfs/xfs_attr_list.c +2
-1@@ -497,7 +500,8 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)trace_xfs_attr_leaf_list (context); context->cursor->blkno =0 ; - error =xfs_attr3_leaf_read (context->tp, context->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, context->dp,0 , +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;...more missing conversions of
xfs_dir3_data_readinxfs_dir2_leaf_readbuf; and ofxfs_dir3_data_readaheadinxfs_dir2_leaf_readbuf......and a missing conversion of
xfs_dir3_data_readaheadinxfs_dir_openinfs/xfs/xfs_file.c.--D
Quoted 3 lines
Signature · 1 line
2.7.4
Re: [PATCH v4 04/17] xfs: Add xfs_dabuf defines
Quoted 36 lines · Allison Collins
Quoted 23 lines · Darrick J. Wong
Quoted 19 lines · Allison Collins
This patch adds two new defines
XFS_DABUF_MAP_NOMAPPINGandXFS_DABUF_MAP_HOLE_OK. This helps to clean up hard numbers and makes the code easier to readSigned-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 14 +++++++----- fs/xfs/libxfs/xfs_attr_leaf.c | 23 +++++++++++-------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++ fs/xfs/libxfs/xfs_da_btree.c | 50 ++++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_dir2_block.c | 6 +++-- fs/xfs/libxfs/xfs_dir2_data.c | 3 ++- fs/xfs/libxfs/xfs_dir2_leaf.c | 9 +++++--- fs/xfs/libxfs/xfs_dir2_node.c | 10 +++++---- fs/xfs/scrub/dabtree.c | 6 ++--- fs/xfs/scrub/dir.c | 4 +++- fs/xfs/xfs_attr_inactive.c | 6 +++-- fs/xfs/xfs_attr_list.c | 16 +++++++++----- 12 files changed, 97 insertions(+), 53 deletions(-)<snip>
Quoted 12 lines
fs/xfs/libxfs/xfs_attr_leaf.h struct xfs_da_state_blk; · line 19
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -16,6 +16,9 @@ struct xfs_da_state_blk;struct xfs_inode ;struct xfs_trans ; +#define XFS_DABUF_MAP_NOMAPPING (-1)/* Caller doesn't have a mapping. */ +#define XFS_DABUF_MAP_HOLE_OK (-2)/* don't complain if we land in a hole. */ These are parameters to xfs_da_{get,read,reada}_buf, please put them next to the declarations for those functions.
Quoted 2 lines
Hmm, I dont see that these are declared in a header file, but how about
fs/xfs/libxfs/xfs_da_btree.h? Did I miss them somewhere?
They should be declared around line 200 in that very file.
--D
Quoted 284 lines
Allison
Quoted 281 lines
Also they probably ought to be explicitly cast to
xfs_daddr_t, e.g./* Force a fresh lookup for the dir/attr mapping. */
#defineXFS_DABUF_MAP_NOMAPPING((xfs_daddr_t)-1)/* Don't complain if we land in a hole. */
#defineXFS_DABUF_MAP_HOLE_OK((xfs_daddr_t)-2)Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.h +1
-0+/* * Used to keep a list of "remote value" extents when unlinking an inode. */ <snip>
Quoted 12 lines
fs/xfs/libxfs/xfs_dir2_block.c +1
-0@@ -20,6 +20,7 @@#include "xfs_error.h" #include "xfs_trace.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Local function prototypes. fs/xfs/libxfs/xfs_dir2_block.c xfs_dir3_block_read( · line 131
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_block.c +3
-2@@ -123,8 +124,9 @@ xfs_dir3_block_read(struct xfs_mount *mp = dp->i_mount;int err; - err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk,-1 , bpp, -XFS_DATA_FORK , &xfs_dir3_block_buf_ops); + err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk, +XFS_DABUF_MAP_NOMAPPING , bpp,XFS_DATA_FORK , + &xfs_dir3_block_buf_ops);if (!err && tp && *bpp)xfs_trans_buf_set_type (tp, *bpp,XFS_BLFT_DIR_BLOCK_BUF );return err;I think this misses the
xfs_dir3_data_readcall inxfs_dir2_leaf_to_block?Quoted 39 lines
fs/xfs/libxfs/xfs_dir2_data.c +2
-1@@ -17,6 +17,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" static xfs_failaddr_t xfs_dir2_data_freefind_verify( struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,@@ -653,7 +654,7 @@ xfs_dir3_data_init(* Get the buffer set up for the block. */ error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, blkno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error; bp->b_ops = &xfs_dir3_data_buf_ops;fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -19,6 +19,7 @@#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_buf_item.h" +#include "xfs_attr_leaf.h" /* * Local function declarations. @@ -311,7 +312,7 @@ xfs_dir3_leaf_get_buf( bno < xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET)); error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, bno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_addname( · line 599
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -594,7 +595,8 @@ xfs_dir2_leaf_addname(trace_xfs_dir2_leaf_addname (args); - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;I think there are some missing conversions for
xfs_dir3_data_readcalls inxfs_dir2_leaf_addname...fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_lookup_int( · line 1196
Quoted 8 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -1189,7 +1191,8 @@ xfs_dir2_leaf_lookup_int( tp = args->trans; mp = dp->i_mount; - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;...and two more
dir3_leaf_readcalls further down in this function......and one more in
xfs_dir2_leaf_trim_data...Quoted 28 lines
fs/xfs/libxfs/xfs_dir2_node.c +3
-2@@ -20,6 +20,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Function declarations. @@ -227,7 +228,7 @@ xfs_dir2_free_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -1, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_NOMAPPING, bpp); } static int@@ -237,7 +238,7 @@ xfs_dir2_free_try_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_HOLE_OK, bpp); } static intfs/xfs/libxfs/xfs_dir2_node.c xfs_dir3_free_get_buf( · line 259
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_node.c +1
-1@@ -254,7 +255,7 @@ xfs_dir3_free_get_buf(struct xfs_dir3_icfree_hdr hdr; error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, fbno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;...there's also a missing call in
xfs_dir2_leafn_lookup_for_entry...fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leafn_toosmall( · line 1502
Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_node.c +2
-1@@ -1495,7 +1496,8 @@ xfs_dir2_leafn_toosmall(* Read the sibling leaf block. */ error =xfs_dir3_leafn_read (state->args->trans, dp, - blkno,-1 , &bp); + blkno,XFS_DABUF_MAP_NOMAPPING , + &bp);if (error)return error;...and another one in
xfs_dir2_node_addname_int.Quoted 21 lines
fs/xfs/scrub/dabtree.c +3
-3@@ -355,9 +355,9 @@ xchk_da_btree_block( goto out_nobuf;/* Read the buffer. */ - error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno,-2 , - &blk->bp, dargs->whichfork, - &xchk_da_btree_buf_ops); + error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno, +XFS_DABUF_MAP_HOLE_OK , &blk->bp, + dargs->whichfork, &xchk_da_btree_buf_ops);if (!xchk_da_process_error (ds, level, &error)) goto out_nobuf;if (blk->bp)fs/xfs/scrub/dir.c +0
-0fs/xfs/scrub/dir.c line 23
Quoted 6 lines
fs/xfs/scrub/dir.c +1
-0@@ -18,6 +18,7 @@#include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/dabtree.h" +#include "xfs_attr_leaf.h" /* Set us up to scrub directories. */ int I also noticed missing conversions for
xfs_dir3_data_readinxchk_dir_rec,xchk_directory_data_bestfree,xchk_directory_leaf1_bestfree, andxchk_directory_free_bestfree.fs/xfs/scrub/dir.c xchk_directory_leaf1_bestfree( · line 499
Quoted 9 lines
fs/xfs/scrub/dir.c +2
-1@@ -492,7 +493,8 @@ xchk_directory_leaf1_bestfree(int error;/* Read the free space block. */ - error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk,-1 , &bp); + error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk, +XFS_DABUF_MAP_NOMAPPING , &bp);if (!xchk_fblock_process_error (sc,XFS_DATA_FORK , lblk, &error)) goto out;xchk_buffer_recheck (sc, bp);There's also a missing
xfs_dir3_data_readaheadconversion inxchk_parent_count_parent_dentriesinfs/xfs/scrub/parent.c.Quoted 63 lines
fs/xfs/xfs_attr_inactive.c +4
-2@@ -235,7 +235,8 @@ xfs_attr3_node_inactive(* traversal of the tree so we may deal with many blocks * before we come back to this one. */ - error =xfs_da3_node_read (*trans, dp, child_fsb,-1 , &child_bp, + error =xfs_da3_node_read (*trans, dp, child_fsb, +XFS_DABUF_MAP_NOMAPPING , &child_bp,XFS_ATTR_FORK );if (error)return error;@@ -321,7 +322,8 @@ xfs_attr3_root_inactive(* the extents in reverse order the extent containing * block 0 must still be there. */ - error =xfs_da3_node_read (*trans, dp,0 ,-1 , &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (*trans, dp,0 ,XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; blkno = bp->b_bn;fs/xfs/xfs_attr_list.c +8
-5@@ -224,8 +224,9 @@ xfs_attr_node_list_lookup(ASSERT (*pbp ==NULL ); cursor->blkno =0 ;for (;;) { - error =xfs_da3_node_read (tp, dp, cursor->blkno,-1 , &bp, -XFS_ATTR_FORK ); + error =xfs_da3_node_read (tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; node = bp->b_addr;@@ -309,8 +310,9 @@ xfs_attr_node_list(*/ bp =NULL ;if (cursor->blkno >0 ) { - error =xfs_da3_node_read (context->tp, dp, cursor->blkno,-1 , - &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if ((error !=0 ) && (error != -EFSCORRUPTED ))return error;if (bp) {@@ -377,7 +379,8 @@ xfs_attr_node_list(break ; cursor->blkno = leafhdr.forw;xfs_trans_brelse (context->tp, bp); - error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error; }fs/xfs/xfs_attr_list.c xfs_attr_leaf_list(xfs_attr_list_context_t *context) · line 505
Quoted 7 lines
fs/xfs/xfs_attr_list.c +2
-1@@ -497,7 +500,8 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)trace_xfs_attr_leaf_list (context); context->cursor->blkno =0 ; - error =xfs_attr3_leaf_read (context->tp, context->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, context->dp,0 , +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;...more missing conversions of
xfs_dir3_data_readinxfs_dir2_leaf_readbuf; and ofxfs_dir3_data_readaheadinxfs_dir2_leaf_readbuf......and a missing conversion of
xfs_dir3_data_readaheadinxfs_dir_openinfs/xfs/xfs_file.c.--D
Quoted 3 lines
Signature · 1 line
2.7.4
Re: [PATCH v4 04/17] xfs: Add xfs_dabuf defines
Quoted 37 lines · Darrick J. Wong
Quoted 36 lines · Allison Collins
Quoted 35 lines · Darrick J. Wong
Quoted 19 lines · Allison Collins
This patch adds two new defines
XFS_DABUF_MAP_NOMAPPINGandXFS_DABUF_MAP_HOLE_OK. This helps to clean up hard numbers and makes the code easier to readSigned-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 14 +++++++----- fs/xfs/libxfs/xfs_attr_leaf.c | 23 +++++++++++-------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 +++ fs/xfs/libxfs/xfs_da_btree.c | 50 ++++++++++++++++++++++++++++-------------- fs/xfs/libxfs/xfs_dir2_block.c | 6 +++-- fs/xfs/libxfs/xfs_dir2_data.c | 3 ++- fs/xfs/libxfs/xfs_dir2_leaf.c | 9 +++++--- fs/xfs/libxfs/xfs_dir2_node.c | 10 +++++---- fs/xfs/scrub/dabtree.c | 6 ++--- fs/xfs/scrub/dir.c | 4 +++- fs/xfs/xfs_attr_inactive.c | 6 +++-- fs/xfs/xfs_attr_list.c | 16 +++++++++----- 12 files changed, 97 insertions(+), 53 deletions(-)<snip>
fs/xfs/libxfs/xfs_attr_leaf.h struct xfs_da_state_blk; · line 19
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -16,6 +16,9 @@ struct xfs_da_state_blk;struct xfs_inode ;struct xfs_trans ; +#define XFS_DABUF_MAP_NOMAPPING (-1)/* Caller doesn't have a mapping. */ +#define XFS_DABUF_MAP_HOLE_OK (-2)/* don't complain if we land in a hole. */ These are parameters to xfs_da_{get,read,reada}_buf, please put them next to the declarations for those functions.
Quoted 4 lines
Quoted 2 lines
Hmm, I dont see that these are declared in a header file, but how about
fs/xfs/libxfs/xfs_da_btree.h? Did I miss them somewhere?They should be declared around line 200 in that very file.
Ok, I found it... I foo-bared search command. Will update then. Thx!
Allison
Quoted 287 lines
--D
Quoted 284 lines
Allison
Quoted 281 lines
Also they probably ought to be explicitly cast to
xfs_daddr_t, e.g./* Force a fresh lookup for the dir/attr mapping. */
#defineXFS_DABUF_MAP_NOMAPPING((xfs_daddr_t)-1)/* Don't complain if we land in a hole. */
#defineXFS_DABUF_MAP_HOLE_OK((xfs_daddr_t)-2)Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.h +1
-0+/* * Used to keep a list of "remote value" extents when unlinking an inode. */ <snip>
Quoted 12 lines
fs/xfs/libxfs/xfs_dir2_block.c +1
-0@@ -20,6 +20,7 @@#include "xfs_error.h" #include "xfs_trace.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Local function prototypes. fs/xfs/libxfs/xfs_dir2_block.c xfs_dir3_block_read( · line 131
Quoted 10 lines
fs/xfs/libxfs/xfs_dir2_block.c +3
-2@@ -123,8 +124,9 @@ xfs_dir3_block_read(struct xfs_mount *mp = dp->i_mount;int err; - err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk,-1 , bpp, -XFS_DATA_FORK , &xfs_dir3_block_buf_ops); + err =xfs_da_read_buf (tp, dp, mp->m_dir_geo->datablk, +XFS_DABUF_MAP_NOMAPPING , bpp,XFS_DATA_FORK , + &xfs_dir3_block_buf_ops);if (!err && tp && *bpp)xfs_trans_buf_set_type (tp, *bpp,XFS_BLFT_DIR_BLOCK_BUF );return err;I think this misses the
xfs_dir3_data_readcall inxfs_dir2_leaf_to_block?Quoted 39 lines
fs/xfs/libxfs/xfs_dir2_data.c +2
-1@@ -17,6 +17,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" static xfs_failaddr_t xfs_dir2_data_freefind_verify( struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,@@ -653,7 +654,7 @@ xfs_dir3_data_init(* Get the buffer set up for the block. */ error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, blkno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error; bp->b_ops = &xfs_dir3_data_buf_ops;fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -19,6 +19,7 @@#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_buf_item.h" +#include "xfs_attr_leaf.h" /* * Local function declarations. @@ -311,7 +312,7 @@ xfs_dir3_leaf_get_buf( bno < xfs_dir2_byte_to_db(args->geo, XFS_DIR2_FREE_OFFSET)); error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, bno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_addname( · line 599
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -594,7 +595,8 @@ xfs_dir2_leaf_addname(trace_xfs_dir2_leaf_addname (args); - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;I think there are some missing conversions for
xfs_dir3_data_readcalls inxfs_dir2_leaf_addname...fs/xfs/libxfs/xfs_dir2_leaf.c xfs_dir2_leaf_lookup_int( · line 1196
Quoted 8 lines
fs/xfs/libxfs/xfs_dir2_leaf.c +2
-1@@ -1189,7 +1191,8 @@ xfs_dir2_leaf_lookup_int( tp = args->trans; mp = dp->i_mount; - error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk,-1 , &lbp); + error =xfs_dir3_leaf_read (tp, dp, args->geo->leafblk, +XFS_DABUF_MAP_NOMAPPING , &lbp);if (error)return error;...and two more
dir3_leaf_readcalls further down in this function......and one more in
xfs_dir2_leaf_trim_data...Quoted 28 lines
fs/xfs/libxfs/xfs_dir2_node.c +3
-2@@ -20,6 +20,7 @@#include "xfs_trans.h" #include "xfs_buf_item.h" #include "xfs_log.h" +#include "xfs_attr_leaf.h" /* * Function declarations. @@ -227,7 +228,7 @@ xfs_dir2_free_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -1, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_NOMAPPING, bpp); } static int@@ -237,7 +238,7 @@ xfs_dir2_free_try_read(xfs_dablk_t fbno, struct xfs_buf **bpp) { - return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp); + return __xfs_dir3_free_read(tp, dp, fbno, XFS_DABUF_MAP_HOLE_OK, bpp); } static intfs/xfs/libxfs/xfs_dir2_node.c xfs_dir3_free_get_buf( · line 259
Quoted 6 lines
fs/xfs/libxfs/xfs_dir2_node.c +1
-1@@ -254,7 +255,7 @@ xfs_dir3_free_get_buf(struct xfs_dir3_icfree_hdr hdr; error =xfs_da_get_buf (tp, dp,xfs_dir2_db_to_da (args->geo, fbno), --1 , &bp,XFS_DATA_FORK ); +XFS_DABUF_MAP_NOMAPPING , &bp,XFS_DATA_FORK );if (error)return error;...there's also a missing call in
xfs_dir2_leafn_lookup_for_entry...fs/xfs/libxfs/xfs_dir2_node.c xfs_dir2_leafn_toosmall( · line 1502
Quoted 9 lines
fs/xfs/libxfs/xfs_dir2_node.c +2
-1@@ -1495,7 +1496,8 @@ xfs_dir2_leafn_toosmall(* Read the sibling leaf block. */ error =xfs_dir3_leafn_read (state->args->trans, dp, - blkno,-1 , &bp); + blkno,XFS_DABUF_MAP_NOMAPPING , + &bp);if (error)return error;...and another one in
xfs_dir2_node_addname_int.Quoted 21 lines
fs/xfs/scrub/dabtree.c +3
-3@@ -355,9 +355,9 @@ xchk_da_btree_block( goto out_nobuf;/* Read the buffer. */ - error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno,-2 , - &blk->bp, dargs->whichfork, - &xchk_da_btree_buf_ops); + error =xfs_da_read_buf (dargs->trans, dargs->dp, blk->blkno, +XFS_DABUF_MAP_HOLE_OK , &blk->bp, + dargs->whichfork, &xchk_da_btree_buf_ops);if (!xchk_da_process_error (ds, level, &error)) goto out_nobuf;if (blk->bp)fs/xfs/scrub/dir.c +0
-0fs/xfs/scrub/dir.c line 23
Quoted 6 lines
fs/xfs/scrub/dir.c +1
-0@@ -18,6 +18,7 @@#include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/dabtree.h" +#include "xfs_attr_leaf.h" /* Set us up to scrub directories. */ int I also noticed missing conversions for
xfs_dir3_data_readinxchk_dir_rec,xchk_directory_data_bestfree,xchk_directory_leaf1_bestfree, andxchk_directory_free_bestfree.fs/xfs/scrub/dir.c xchk_directory_leaf1_bestfree( · line 499
Quoted 9 lines
fs/xfs/scrub/dir.c +2
-1@@ -492,7 +493,8 @@ xchk_directory_leaf1_bestfree(int error;/* Read the free space block. */ - error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk,-1 , &bp); + error =xfs_dir3_leaf_read (sc->tp, sc->ip, lblk, +XFS_DABUF_MAP_NOMAPPING , &bp);if (!xchk_fblock_process_error (sc,XFS_DATA_FORK , lblk, &error)) goto out;xchk_buffer_recheck (sc, bp);There's also a missing
xfs_dir3_data_readaheadconversion inxchk_parent_count_parent_dentriesinfs/xfs/scrub/parent.c.Quoted 63 lines
fs/xfs/xfs_attr_inactive.c +4
-2@@ -235,7 +235,8 @@ xfs_attr3_node_inactive(* traversal of the tree so we may deal with many blocks * before we come back to this one. */ - error =xfs_da3_node_read (*trans, dp, child_fsb,-1 , &child_bp, + error =xfs_da3_node_read (*trans, dp, child_fsb, +XFS_DABUF_MAP_NOMAPPING , &child_bp,XFS_ATTR_FORK );if (error)return error;@@ -321,7 +322,8 @@ xfs_attr3_root_inactive(* the extents in reverse order the extent containing * block 0 must still be there. */ - error =xfs_da3_node_read (*trans, dp,0 ,-1 , &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (*trans, dp,0 ,XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; blkno = bp->b_bn;fs/xfs/xfs_attr_list.c +8
-5@@ -224,8 +224,9 @@ xfs_attr_node_list_lookup(ASSERT (*pbp ==NULL ); cursor->blkno =0 ;for (;;) { - error =xfs_da3_node_read (tp, dp, cursor->blkno,-1 , &bp, -XFS_ATTR_FORK ); + error =xfs_da3_node_read (tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if (error)return error; node = bp->b_addr;@@ -309,8 +310,9 @@ xfs_attr_node_list(*/ bp =NULL ;if (cursor->blkno >0 ) { - error =xfs_da3_node_read (context->tp, dp, cursor->blkno,-1 , - &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp, +XFS_ATTR_FORK );if ((error !=0 ) && (error != -EFSCORRUPTED ))return error;if (bp) {@@ -377,7 +379,8 @@ xfs_attr_node_list(break ; cursor->blkno = leafhdr.forw;xfs_trans_brelse (context->tp, bp); - error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, dp, cursor->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error; }fs/xfs/xfs_attr_list.c xfs_attr_leaf_list(xfs_attr_list_context_t *context) · line 505
Quoted 7 lines
fs/xfs/xfs_attr_list.c +2
-1@@ -497,7 +500,8 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)trace_xfs_attr_leaf_list (context); context->cursor->blkno =0 ; - error =xfs_attr3_leaf_read (context->tp, context->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (context->tp, context->dp,0 , +XFS_DABUF_MAP_NOMAPPING , &bp);if (error)return error;...more missing conversions of
xfs_dir3_data_readinxfs_dir2_leaf_readbuf; and ofxfs_dir3_data_readaheadinxfs_dir2_leaf_readbuf......and a missing conversion of
xfs_dir3_data_readaheadinxfs_dir_openinfs/xfs/xfs_file.c.--D
Quoted 3 lines
Signature · 1 line
2.7.4
PATCH v4 5/17 xfs: Add xfs_has_attr and subroutines
In reply to Allison CollinsFrom: Allison Henderson <[email protected]>
This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
--- fs/xfs/libxfs/xfs_attr.c | 154 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 107 ++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 4 files changed, 171 insertions(+), 93 deletions(-)
fs/xfs/libxfs/xfs_attr.c +100 -54
@@ -46,6 +46,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);/* * Internal routines when attribute list is more than one block.
@@ -53,6 +54,8 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC int xfs_attr_node_addname(xfs_da_args_t *args); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); +STATIC int xfs_attr_node_hasname(xfs_da_args_t *args, +struct xfs_da_state **state); STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
@@ -310,6 +313,34 @@ xfs_attr_set_args( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +int +xfs_has_attr ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp; +int error; + +if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_hasname (args,NULL ,NULL ); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST ) + goto out; +xfs_trans_brelse (args->trans, bp); + }else { + error =xfs_attr_node_hasname (args,NULL ); + } +out: +return error; +} + +/* * Remove the attribute specified in @args. */ int
@@ -580,27 +611,20 @@ STATIC intxfs_attr_leaf_addname ( struct xfs_da_args *args) { -struct xfs_inode *dp;struct xfs_buf *bp;int retval, error, forkoff; +struct xfs_inode *dp = args->dp;trace_xfs_attr_leaf_addname (args);/* -* Read the (only) block in the attribute list in. -*/ - dp = args->dp; - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) -return error; - -/* * Look up the given attribute in the leaf block. Figure out if * the given flags produce an error or call for an atomic rename. */ - retval =xfs_attr3_leaf_lookup_int (bp, args); + retval =xfs_attr_leaf_hasname (args, &bp); +if (retval != -ENOATTR && retval != -EEXIST ) +return retval; +if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) {xfs_trans_brelse (args->trans, bp);return retval;
@@ -752,6 +776,24 @@ xfs_attr_leaf_addname( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +STATIC int +xfs_attr_leaf_hasname ( +struct xfs_da_args *args, +struct xfs_buf **bp) +{ +int error =0 ; + + error =xfs_attr3_leaf_read (args->trans, args->dp,0 , +XFS_DABUF_MAP_NOMAPPING , bp); +if (error) +return error; + +return xfs_attr3_leaf_lookup_int (*bp, args); +} + +/* * Remove a name from the leaf attribute list structure * * This leaf block cannot have a "remote" value, we only call this routine
@@ -771,13 +813,11 @@ xfs_attr_leaf_removename(* Remove the attribute. */ dp = args->dp; - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) + + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST )return error; - error =xfs_attr3_leaf_lookup_int (bp, args);if (error == -ENOATTR ) {xfs_trans_brelse (args->trans, bp);return error;
@@ -816,13 +856,10 @@ xfs_attr_leaf_get(xfs_da_args_t *args)trace_xfs_attr_leaf_get (args); - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST )return error; - error =xfs_attr3_leaf_lookup_int (bp, args);if (error != -EEXIST ) {xfs_trans_brelse (args->trans, bp);return error;
@@ -832,6 +869,38 @@ xfs_attr_leaf_get(xfs_da_args_t *args)return error; } +/* +* Return EEXIST if attr is found, or ENOATTR if not +* statep: If not null is set to point at the found state. Caller will +* be responsible for freeing the state in this case. +*/ +STATIC int +xfs_attr_node_hasname ( +struct xfs_da_args *args, +struct xfs_da_state **statep) +{ +struct xfs_da_state *state; +int retval, error; + + state =xfs_da_state_alloc (); + state->args = args; + state->mp = args->dp->i_mount; + +/* +* Search to see if name exists, and get back a pointer to it. +*/ + error =xfs_da3_node_lookup_int (state, &retval); +if (error ==0 ) + error = retval; + +if (statep !=NULL ) + *statep = state; +else +xfs_da_state_free (state); + +return error; +} +/*======================================================================== * External routines when attribute list size > geo->blksize *========================================================================*/
@@ -864,20 +933,17 @@ xfs_attr_node_addname( dp = args->dp; mp = dp->i_mount; restart: - state =xfs_da_state_alloc (); - state->args = args; - state->mp = mp; -/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) + retval =xfs_attr_node_hasname (args, &state); +if (retval != -ENOATTR ) goto out; + blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); -if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) { +if (args->name.type &ATTR_REPLACE ) { goto out; }else if (retval == -EEXIST ) {if (args->name.type &ATTR_CREATE )
@@ -1079,29 +1145,15 @@ xfs_attr_node_removename( {struct xfs_da_state *state;struct xfs_da_state_blk *blk; -struct xfs_inode *dp;struct xfs_buf *bp;int retval, error, forkoff; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); -/* -* Tie a string around our finger to remind us where we are. -*/ - dp = args->dp; - state =xfs_da_state_alloc (); - state->args = args; - state->mp = dp->i_mount; - -/* -* Search to see if name exists, and get back a pointer to it. -*/ - error =xfs_da3_node_lookup_int (state, &retval); -if (error || (retval != -EEXIST )) { -if (error ==0 ) - error = retval; + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) goto out; - }/* * If there is an out-of-line value, de-allocate the blocks.
@@ -1324,20 +1376,14 @@ xfs_attr_node_get(xfs_da_args_t *args)trace_xfs_attr_node_get (args); - state =xfs_da_state_alloc (); - state->args = args; - state->mp = args->dp->i_mount; -/* * Search to see if name exists, and get back a pointer to it. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) { + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) { retval = error; goto out_release; } -if (retval != -EEXIST ) - goto out_release;/* * Get the value, local or "remote"
fs/xfs/libxfs/xfs_attr.h +1 -0
@@ -150,6 +150,7 @@ int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name, unsigned char *value, int valuelen, int flags);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags); +int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);
fs/xfs/libxfs/xfs_attr_leaf.c +68 -39
137 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
@@ -42,6 +42,8 @@ int xfs_attr_shortform_getvalue(struct xfs_da_args *args);int xfs_attr_shortform_to_leaf (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_shortform_remove (struct xfs_da_args *args); +int xfs_attr_shortform_hasname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep,int *basep);int xfs_attr_shortform_allfit (struct xfs_buf *bp,struct xfs_inode *dp);int xfs_attr_shortform_bytesfit (struct xfs_inode *dp,int bytes);xfs_failaddr_t xfs_attr_shortform_verify (struct xfs_inode *ip);
Signature · 1 line
2.7.4
Re: [PATCH v4 05/17] xfs: Add xfs_has_attr and subroutines
Quoted 40 lines · Allison Collins
From: Allison Henderson <[email protected]>
This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 154 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 107 ++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 4 files changed, 171 insertions(+), 93 deletions(-)fs/xfs/libxfs/xfs_attr.c +3
-0@@ -46,6 +46,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);/* * Internal routines when attribute list is more than one block. @@ -53,6 +54,8 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC int xfs_attr_node_addname(xfs_da_args_t *args); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); +STATIC int xfs_attr_node_hasname(xfs_da_args_t *args, +struct xfs_da_state **state); STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 320
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +5
-0@@ -310,6 +313,34 @@ xfs_attr_set_args( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +int +xfs_has_attr ( +struct xfs_da_args *args)
I was really hoping for a "replace ENOATTR/EEXIST with a boolean" cleanup at the end of this series, though as a straight hoisting and refactoring, this patch is ok for leaving the existing error code overloading. :)
Quoted 260 lines
fs/xfs/libxfs/xfs_attr.c +92
-54+{ +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp; +int error; + +if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_hasname (args,NULL ,NULL ); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST ) + goto out; +xfs_trans_brelse (args->trans, bp); + }else { + error =xfs_attr_node_hasname (args,NULL ); + } +out: +return error; +} + +/* * Remove the attribute specified in @args. */ int @@ -580,27 +611,20 @@ STATIC intxfs_attr_leaf_addname ( struct xfs_da_args *args) { -struct xfs_inode *dp;struct xfs_buf *bp;int retval, error, forkoff; +struct xfs_inode *dp = args->dp;trace_xfs_attr_leaf_addname (args);/* -* Read the (only) block in the attribute list in. -*/ - dp = args->dp; - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) -return error; - -/* * Look up the given attribute in the leaf block. Figure out if * the given flags produce an error or call for an atomic rename. */ - retval =xfs_attr3_leaf_lookup_int (bp, args); + retval =xfs_attr_leaf_hasname (args, &bp); +if (retval != -ENOATTR && retval != -EEXIST ) +return retval; +if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) {xfs_trans_brelse (args->trans, bp);return retval;@@ -752,6 +776,24 @@ xfs_attr_leaf_addname( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +STATIC int +xfs_attr_leaf_hasname ( +struct xfs_da_args *args, +struct xfs_buf **bp) +{ +int error =0 ; + + error =xfs_attr3_leaf_read (args->trans, args->dp,0 , +XFS_DABUF_MAP_NOMAPPING , bp); +if (error) +return error; + +return xfs_attr3_leaf_lookup_int (*bp, args); +} + +/* * Remove a name from the leaf attribute list structure * * This leaf block cannot have a "remote" value, we only call this routine @@ -771,13 +813,11 @@ xfs_attr_leaf_removename(* Remove the attribute. */ dp = args->dp; - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) + + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST )return error; - error =xfs_attr3_leaf_lookup_int (bp, args);if (error == -ENOATTR ) {xfs_trans_brelse (args->trans, bp);return error;@@ -816,13 +856,10 @@ xfs_attr_leaf_get(xfs_da_args_t *args)trace_xfs_attr_leaf_get (args); - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST )return error; - error =xfs_attr3_leaf_lookup_int (bp, args);if (error != -EEXIST ) {xfs_trans_brelse (args->trans, bp);return error;@@ -832,6 +869,38 @@ xfs_attr_leaf_get(xfs_da_args_t *args)return error; } +/* +* Return EEXIST if attr is found, or ENOATTR if not +* statep: If not null is set to point at the found state. Caller will +* be responsible for freeing the state in this case. +*/ +STATIC int +xfs_attr_node_hasname ( +struct xfs_da_args *args, +struct xfs_da_state **statep) +{ +struct xfs_da_state *state; +int retval, error; + + state =xfs_da_state_alloc (); + state->args = args; + state->mp = args->dp->i_mount; + +/* +* Search to see if name exists, and get back a pointer to it. +*/ + error =xfs_da3_node_lookup_int (state, &retval); +if (error ==0 ) + error = retval; + +if (statep !=NULL ) + *statep = state; +else +xfs_da_state_free (state); + +return error; +} +/*======================================================================== * External routines when attribute list size > geo->blksize *========================================================================*/ @@ -864,20 +933,17 @@ xfs_attr_node_addname( dp = args->dp; mp = dp->i_mount; restart: - state =xfs_da_state_alloc (); - state->args = args; - state->mp = mp; -/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) + retval =xfs_attr_node_hasname (args, &state); +if (retval != -ENOATTR ) goto out; + blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); -if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) { +if (args->name.type &ATTR_REPLACE ) { goto out; }else if (retval == -EEXIST ) {if (args->name.type &ATTR_CREATE )@@ -1079,29 +1145,15 @@ xfs_attr_node_removename( {struct xfs_da_state *state;struct xfs_da_state_blk *blk; -struct xfs_inode *dp;struct xfs_buf *bp;int retval, error, forkoff; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); -/* -* Tie a string around our finger to remind us where we are. -*/ - dp = args->dp; - state =xfs_da_state_alloc (); - state->args = args; - state->mp = dp->i_mount; - -/* -* Search to see if name exists, and get back a pointer to it. -*/ - error =xfs_da3_node_lookup_int (state, &retval); -if (error || (retval != -EEXIST )) { -if (error ==0 ) - error = retval; + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) goto out; - }/* * If there is an out-of-line value, de-allocate the blocks. @@ -1324,20 +1376,14 @@ xfs_attr_node_get(xfs_da_args_t *args)trace_xfs_attr_node_get (args); - state =xfs_da_state_alloc (); - state->args = args; - state->mp = args->dp->i_mount; -/* * Search to see if name exists, and get back a pointer to it. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) { + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) { retval = error; goto out_release; } -if (retval != -EEXIST ) - goto out_release;/* * Get the value, local or "remote" fs/xfs/libxfs/xfs_attr.h +1
-0@@ -150,6 +150,7 @@ int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name, unsigned char *value, int valuelen, int flags);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags); +int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);fs/xfs/libxfs/xfs_attr_leaf.c +3
-0@@ -655,18 +655,67 @@ xfs_attr_shortform_create(xfs_da_args_t *args) }/* +* Return -EEXIST if attr is found, or -ENOATTR if not +* args: args containing attribute name and namelen +* sfep: If not null, pointer will be set to the last attr entry found on
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 670
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10
-0+-EEXIST. On -ENOATTR pointer is left at the last entry in the list +* basep: If not null, pointer is set to the byte offset of the entry in the +* list on -EEXIST. On -ENOATTR, pointer is left at the byte offset of +* the last entry in the list +*/ +int +xfs_attr_shortform_hasname ( +struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep, +int *basep)
Byte offsets can't be negative, so this should be unsigned int.
Seeing as we also return the location of the sf entry and byte offset, maybe this ought to be called xfs_attr_sf_findname ?
Quoted 65 lines
fs/xfs/libxfs/xfs_attr_leaf.c +42
-10+{ +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base =sizeof (struct xfs_attr_sf_hdr ); +int size =0 ; +int end; +int i; + + base =sizeof (struct xfs_attr_sf_hdr ); + sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; + sfe = &sf->list[0 ]; + end = sf->hdr.count; +for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), + base += size, i++) { + size =XFS_ATTR_SF_ENTSIZE (sfe); +if (sfe->namelen != args->name.len) +continue ; +if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) +continue ; +if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) +continue ; +break ; + } + +if (sfep !=NULL ) + *sfep = sfe; + +if (basep !=NULL ) + *basep = base; + +if (i == end) +return -ENOATTR ; +return -EEXIST ; +} + +/* * Add a name/value pair to the shortform attribute list. * Overflow from the inode has already been checked for. */ void xfs_attr_shortform_add (xfs_da_args_t *args,int forkoff) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe; -int i, offset, size; -xfs_mount_t *mp; -xfs_inode_t *dp; -struct xfs_ifork *ifp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int offset, size, error; +struct xfs_mount *mp; +struct xfs_inode *dp; +struct xfs_ifork *ifp;trace_xfs_attr_sf_add (args);@@ -677,18 +726,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) ifp = dp->i_afp;ASSERT (ifp->if_flags &XFS_IFINLINE ); sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; - sfe = &sf->list[0 ]; -for (i =0 ; i < sf->hdr.count; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), i++) { -#ifdef DEBUG -if (sfe->namelen != args->name.len)
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 730
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +2
-8-continue ; -if (memcmp (args->name.name, sfe->nameval, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -ASSERT (0 ); -#endif - } + error =xfs_attr_shortform_hasname (args, &sfe,NULL ); +ASSERT (error != -EEXIST );
If this assertion triggers, the fs is corrupt and we need to log something and bail out. 5.5 for-next will soon have a new XFS_IS_CORRUPT macro that takes care of this, so you can do:
error = xfs_attr_shortform_hasname(args, &sfe, NULL); if (XFS_IS_CORRUPT(mp, error != -EEXIST)) return -EFSCORRUPTED;
--D
Quoted 64 lines
fs/xfs/libxfs/xfs_attr_leaf.c +11
-21offset = (char *)sfe - (char *)sf; size =XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen);@@ -733,33 +772,23 @@ xfs_attr_fork_remove(int xfs_attr_shortform_remove (xfs_da_args_t *args) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe; -int base, size=0 , end, totsize, i; -xfs_mount_t *mp; -xfs_inode_t *dp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base, size =0 , end, totsize; +struct xfs_mount *mp; +struct xfs_inode *dp; +int error;trace_xfs_attr_sf_remove (args); dp = args->dp; mp = dp->i_mount; - base =sizeof (xfs_attr_sf_hdr_t); sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data; - sfe = &sf->list[0 ]; - end = sf->hdr.count; -for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), - base += size, i++) { - size =XFS_ATTR_SF_ENTSIZE (sfe); -if (sfe->namelen != args->name.len) -continue ; -if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -break ; - } -if (i == end) -return -ENOATTR ; + + error =xfs_attr_shortform_hasname (args, &sfe, &base); +if (error != -EEXIST ) +return error; + size =XFS_ATTR_SF_ENTSIZE (sfe);/* * Fix up the attribute fork data, covering the hole fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -42,6 +42,8 @@ int xfs_attr_shortform_getvalue(struct xfs_da_args *args);int xfs_attr_shortform_to_leaf (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_shortform_remove (struct xfs_da_args *args); +int xfs_attr_shortform_hasname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep,int *basep);int xfs_attr_shortform_allfit (struct xfs_buf *bp,struct xfs_inode *dp);int xfs_attr_shortform_bytesfit (struct xfs_inode *dp,int bytes);xfs_failaddr_t xfs_attr_shortform_verify (struct xfs_inode *ip);Signature · 1 line
2.7.4
Re: [PATCH v4 05/17] xfs: Add xfs_has_attr and subroutines
Quoted 328 lines · Darrick J. Wong
Quoted 40 lines · Allison Collins
From: Allison Henderson <[email protected]>
This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 154 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 107 ++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 4 files changed, 171 insertions(+), 93 deletions(-)fs/xfs/libxfs/xfs_attr.c +3
-0@@ -46,6 +46,7 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_hasname(struct xfs_da_args *args, struct xfs_buf **bp);/* * Internal routines when attribute list is more than one block. @@ -53,6 +54,8 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC int xfs_attr_node_addname(xfs_da_args_t *args); STATIC int xfs_attr_node_removename(xfs_da_args_t *args); +STATIC int xfs_attr_node_hasname(xfs_da_args_t *args, +struct xfs_da_state **state); STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state);fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 320
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +5
-0@@ -310,6 +313,34 @@ xfs_attr_set_args( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +int +xfs_has_attr ( +struct xfs_da_args *args)I was really hoping for a "replace ENOATTR/EEXIST with a boolean" cleanup at the end of this series, though as a straight hoisting and refactoring, this patch is ok for leaving the existing error code overloading. :)
Quoted 260 lines
fs/xfs/libxfs/xfs_attr.c +92
-54+{ +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp; +int error; + +if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_hasname (args,NULL ,NULL ); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST ) + goto out; +xfs_trans_brelse (args->trans, bp); + }else { + error =xfs_attr_node_hasname (args,NULL ); + } +out: +return error; +} + +/* * Remove the attribute specified in @args. */ int @@ -580,27 +611,20 @@ STATIC intxfs_attr_leaf_addname ( struct xfs_da_args *args) { -struct xfs_inode *dp;struct xfs_buf *bp;int retval, error, forkoff; +struct xfs_inode *dp = args->dp;trace_xfs_attr_leaf_addname (args);/* -* Read the (only) block in the attribute list in. -*/ - dp = args->dp; - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) -return error; - -/* * Look up the given attribute in the leaf block. Figure out if * the given flags produce an error or call for an atomic rename. */ - retval =xfs_attr3_leaf_lookup_int (bp, args); + retval =xfs_attr_leaf_hasname (args, &bp); +if (retval != -ENOATTR && retval != -EEXIST ) +return retval; +if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) {xfs_trans_brelse (args->trans, bp);return retval;@@ -752,6 +776,24 @@ xfs_attr_leaf_addname( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +STATIC int +xfs_attr_leaf_hasname ( +struct xfs_da_args *args, +struct xfs_buf **bp) +{ +int error =0 ; + + error =xfs_attr3_leaf_read (args->trans, args->dp,0 , +XFS_DABUF_MAP_NOMAPPING , bp); +if (error) +return error; + +return xfs_attr3_leaf_lookup_int (*bp, args); +} + +/* * Remove a name from the leaf attribute list structure * * This leaf block cannot have a "remote" value, we only call this routine @@ -771,13 +813,11 @@ xfs_attr_leaf_removename(* Remove the attribute. */ dp = args->dp; - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) + + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST )return error; - error =xfs_attr3_leaf_lookup_int (bp, args);if (error == -ENOATTR ) {xfs_trans_brelse (args->trans, bp);return error;@@ -816,13 +856,10 @@ xfs_attr_leaf_get(xfs_da_args_t *args)trace_xfs_attr_leaf_get (args); - args->blkno =0 ; - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); -if (error) + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST )return error; - error =xfs_attr3_leaf_lookup_int (bp, args);if (error != -EEXIST ) {xfs_trans_brelse (args->trans, bp);return error;@@ -832,6 +869,38 @@ xfs_attr_leaf_get(xfs_da_args_t *args)return error; } +/* +* Return EEXIST if attr is found, or ENOATTR if not +* statep: If not null is set to point at the found state. Caller will +* be responsible for freeing the state in this case. +*/ +STATIC int +xfs_attr_node_hasname ( +struct xfs_da_args *args, +struct xfs_da_state **statep) +{ +struct xfs_da_state *state; +int retval, error; + + state =xfs_da_state_alloc (); + state->args = args; + state->mp = args->dp->i_mount; + +/* +* Search to see if name exists, and get back a pointer to it. +*/ + error =xfs_da3_node_lookup_int (state, &retval); +if (error ==0 ) + error = retval; + +if (statep !=NULL ) + *statep = state; +else +xfs_da_state_free (state); + +return error; +} +/*======================================================================== * External routines when attribute list size > geo->blksize *========================================================================*/ @@ -864,20 +933,17 @@ xfs_attr_node_addname( dp = args->dp; mp = dp->i_mount; restart: - state =xfs_da_state_alloc (); - state->args = args; - state->mp = mp; -/* * Search to see if name already exists, and get back a pointer * to where it should go. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) + retval =xfs_attr_node_hasname (args, &state); +if (retval != -ENOATTR ) goto out; + blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); -if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) { +if (args->name.type &ATTR_REPLACE ) { goto out; }else if (retval == -EEXIST ) {if (args->name.type &ATTR_CREATE )@@ -1079,29 +1145,15 @@ xfs_attr_node_removename( {struct xfs_da_state *state;struct xfs_da_state_blk *blk; -struct xfs_inode *dp;struct xfs_buf *bp;int retval, error, forkoff; +struct xfs_inode *dp = args->dp;trace_xfs_attr_node_removename (args); -/* -* Tie a string around our finger to remind us where we are. -*/ - dp = args->dp; - state =xfs_da_state_alloc (); - state->args = args; - state->mp = dp->i_mount; - -/* -* Search to see if name exists, and get back a pointer to it. -*/ - error =xfs_da3_node_lookup_int (state, &retval); -if (error || (retval != -EEXIST )) { -if (error ==0 ) - error = retval; + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) goto out; - }/* * If there is an out-of-line value, de-allocate the blocks. @@ -1324,20 +1376,14 @@ xfs_attr_node_get(xfs_da_args_t *args)trace_xfs_attr_node_get (args); - state =xfs_da_state_alloc (); - state->args = args; - state->mp = args->dp->i_mount; -/* * Search to see if name exists, and get back a pointer to it. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) { + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) { retval = error; goto out_release; } -if (retval != -EEXIST ) - goto out_release;/* * Get the value, local or "remote" fs/xfs/libxfs/xfs_attr.h +1
-0@@ -150,6 +150,7 @@ int xfs_attr_set(struct xfs_inode *dp, struct xfs_name *name, unsigned char *value, int valuelen, int flags);int xfs_attr_set_args (struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags); +int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);fs/xfs/libxfs/xfs_attr_leaf.c +3
-0@@ -655,18 +655,67 @@ xfs_attr_shortform_create(xfs_da_args_t *args) }/* +* Return -EEXIST if attr is found, or -ENOATTR if not +* args: args containing attribute name and namelen +* sfep: If not null, pointer will be set to the last attr entry found on fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 670
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10
-0+-EEXIST. On -ENOATTR pointer is left at the last entry in the list +* basep: If not null, pointer is set to the byte offset of the entry in the +* list on -EEXIST. On -ENOATTR, pointer is left at the byte offset of +* the last entry in the list +*/ +int +xfs_attr_shortform_hasname ( +struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep, +int *basep)Byte offsets can't be negative, so this should be unsigned int.
Quoted 2 lines
Seeing as we also return the location of the sf entry and byte offset, maybe this ought to be called
xfs_attr_sf_findname?
Sure, will fix.
Quoted 81 lines
Quoted 66 lines
fs/xfs/libxfs/xfs_attr_leaf.c +42
-10+{ +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base =sizeof (struct xfs_attr_sf_hdr ); +int size =0 ; +int end; +int i; + + base =sizeof (struct xfs_attr_sf_hdr ); + sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; + sfe = &sf->list[0 ]; + end = sf->hdr.count; +for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), + base += size, i++) { + size =XFS_ATTR_SF_ENTSIZE (sfe); +if (sfe->namelen != args->name.len) +continue ; +if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) +continue ; +if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) +continue ; +break ; + } + +if (sfep !=NULL ) + *sfep = sfe; + +if (basep !=NULL ) + *basep = base; + +if (i == end) +return -ENOATTR ; +return -EEXIST ; +} + +/* * Add a name/value pair to the shortform attribute list. * Overflow from the inode has already been checked for. */ void xfs_attr_shortform_add (xfs_da_args_t *args,int forkoff) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe; -int i, offset, size; -xfs_mount_t *mp; -xfs_inode_t *dp; -struct xfs_ifork *ifp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int offset, size, error; +struct xfs_mount *mp; +struct xfs_inode *dp; +struct xfs_ifork *ifp;trace_xfs_attr_sf_add (args);@@ -677,18 +726,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) ifp = dp->i_afp;ASSERT (ifp->if_flags &XFS_IFINLINE ); sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; - sfe = &sf->list[0 ]; -for (i =0 ; i < sf->hdr.count; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), i++) { -#ifdef DEBUG -if (sfe->namelen != args->name.len)fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) · line 730
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +2
-8-continue ; -if (memcmp (args->name.name, sfe->nameval, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -ASSERT (0 ); -#endif - } + error =xfs_attr_shortform_hasname (args, &sfe,NULL ); +ASSERT (error != -EEXIST );If this assertion triggers, the fs is corrupt and we need to log something and bail out. 5.5 for-next will soon have a new
XFS_IS_CORRUPTmacro that takes care of this, so you can do:
Quoted 5 lines
error = xfs_attr_shortform_hasname(args, &sfe, NULL); if (XFS_IS_CORRUPT(mp, error != -EEXIST)) return -EFSCORRUPTED;--D
Ok, I will keep an eye out for that then. Thanks! Allison
Quoted 66 lines
Quoted 66 lines
fs/xfs/libxfs/xfs_attr_leaf.c +11
-21offset = (char *)sfe - (char *)sf; size =XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen);@@ -733,33 +772,23 @@ xfs_attr_fork_remove(int xfs_attr_shortform_remove (xfs_da_args_t *args) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe; -int base, size=0 , end, totsize, i; -xfs_mount_t *mp; -xfs_inode_t *dp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base, size =0 , end, totsize; +struct xfs_mount *mp; +struct xfs_inode *dp; +int error;trace_xfs_attr_sf_remove (args); dp = args->dp; mp = dp->i_mount; - base =sizeof (xfs_attr_sf_hdr_t); sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data; - sfe = &sf->list[0 ]; - end = sf->hdr.count; -for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), - base += size, i++) { - size =XFS_ATTR_SF_ENTSIZE (sfe); -if (sfe->namelen != args->name.len) -continue ; -if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -break ; - } -if (i == end) -return -ENOATTR ; + + error =xfs_attr_shortform_hasname (args, &sfe, &base); +if (error != -EEXIST ) +return error; + size =XFS_ATTR_SF_ENTSIZE (sfe);/* * Fix up the attribute fork data, covering the hole fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -42,6 +42,8 @@ int xfs_attr_shortform_getvalue(struct xfs_da_args *args);int xfs_attr_shortform_to_leaf (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_shortform_remove (struct xfs_da_args *args); +int xfs_attr_shortform_hasname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep,int *basep);int xfs_attr_shortform_allfit (struct xfs_buf *bp,struct xfs_inode *dp);int xfs_attr_shortform_bytesfit (struct xfs_inode *dp,int bytes);xfs_failaddr_t xfs_attr_shortform_verify (struct xfs_inode *ip);Signature · 1 line
2.7.4
Re: [PATCH v4 05/17] xfs: Add xfs_has_attr and subroutines
In reply to Allison CollinsQuoted 10 lines · Allison Collins
From: Allison Henderson <[email protected]>
This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>---
This mostly looks good to me. Just some small nits..
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c | 154 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 107 ++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 4 files changed, 171 insertions(+), 93 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +9
-0@@ -310,6 +313,34 @@ xfs_attr_set_args( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +int +xfs_has_attr ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp; +int error;
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 334
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ +if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_hasname (args,NULL ,NULL ); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST ) + goto out;
Hmm.. is this basically an indirect check for whether bp is set? If so, I think doing bp = NULL above and:
if (bp) xfs_trans_brelse(args->trans, bp);
... is more straightforward.
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+xfs_trans_brelse (args->trans, bp); + }else { + error =xfs_attr_node_hasname (args,NULL ); + } +out: +return error; +} + +/* * Remove the attribute specified in @args. */ int
...
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +21
-0@@ -832,6 +869,38 @@ xfs_attr_leaf_get(xfs_da_args_t *args)return error; } +/* +* Return EEXIST if attr is found, or ENOATTR if not +* statep: If not null is set to point at the found state. Caller will +* be responsible for freeing the state in this case. +*/ +STATIC int +xfs_attr_node_hasname ( +struct xfs_da_args *args, +struct xfs_da_state **statep) +{ +struct xfs_da_state *state; +int retval, error; + + state =xfs_da_state_alloc (); + state->args = args; + state->mp = args->dp->i_mount; + +/* +* Search to see if name exists, and get back a pointer to it. +*/ + error =xfs_da3_node_lookup_int (state, &retval);
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_get(xfs_da_args_t *args) · line 902
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+if (error ==0 ) + error = retval; + +if (statep !=NULL ) + *statep = state; +else +xfs_da_state_free (state); + +return error; +}
The state allocation handling is a little wonky here in the error scenario. I think precedent is that if we're returning an unexpected error, we should probably just free state directly rather than rely on the caller to do so. If the function returns "success" (meaning -EEXIST or -ENOATTR), then the caller owns the state memory. It might also make sense to NULL init the pointer either at the top of this helper or the caller.
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +1
-0+/*======================================================================== * External routines when attribute list size > geo->blksize *========================================================================*/
...
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-2@@ -1324,20 +1376,14 @@ xfs_attr_node_get(xfs_da_args_t *args)trace_xfs_attr_node_get (args); - state =xfs_da_state_alloc (); - state->args = args;
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_get(xfs_da_args_t *args) · line 1384
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-4- state->mp = args->dp->i_mount; -/* * Search to see if name exists, and get back a pointer to it. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) { + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) { retval = error;
Can we kill retval in this function now? The only use is to assign error to it.
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0
-2goto out_release; } -if (retval != -EEXIST ) - goto out_release;/* * Get the value, local or "remote"
...
Quoted 20 lines
fs/xfs/libxfs/xfs_attr_leaf.c +12
-0@@ -655,18 +655,67 @@ xfs_attr_shortform_create(xfs_da_args_t *args) }/* +* Return -EEXIST if attr is found, or -ENOATTR if not +* args: args containing attribute name and namelen +* sfep: If not null, pointer will be set to the last attr entry found on +-EEXIST. On -ENOATTR pointer is left at the last entry in the list +* basep: If not null, pointer is set to the byte offset of the entry in the +* list on -EEXIST. On -ENOATTR, pointer is left at the byte offset of +* the last entry in the list +*/ +int +xfs_attr_shortform_hasname( + struct xfs_da_args *args, + struct xfs_attr_sf_entry **sfep,
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 679
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10
-0+ int *basep) +{ +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base =sizeof (struct xfs_attr_sf_hdr ); +int size =0 ; +int end; +int i; + + base =sizeof (struct xfs_attr_sf_hdr );
Double init.
Quoted 35 lines
fs/xfs/libxfs/xfs_attr_leaf.c +27
-2+ sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; + sfe = &sf->list[0 ]; + end = sf->hdr.count; +for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), + base += size, i++) { + size =XFS_ATTR_SF_ENTSIZE (sfe); +if (sfe->namelen != args->name.len) +continue ; +if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) +continue ; +if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) +continue ; +break ; + } + +if (sfep !=NULL ) + *sfep = sfe; + +if (basep !=NULL ) + *basep = base; + +if (i == end) +return -ENOATTR ; +return -EEXIST ; +} + +/* * Add a name/value pair to the shortform attribute list. * Overflow from the inode has already been checked for. */ void xfs_attr_shortform_add (xfs_da_args_t *args,int forkoff) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe;
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 718
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +6
-4-int i, offset, size; -xfs_mount_t *mp; -xfs_inode_t *dp; -struct xfs_ifork *ifp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int offset, size, error; +struct xfs_mount *mp; +struct xfs_inode *dp; +struct xfs_ifork *ifp;
Might as well fix up the typedef in the function signature (here and below) as well.
Brian
Quoted 85 lines
fs/xfs/libxfs/xfs_attr_leaf.c +13
-33trace_xfs_attr_sf_add (args);@@ -677,18 +726,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) ifp = dp->i_afp;ASSERT (ifp->if_flags &XFS_IFINLINE ); sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; - sfe = &sf->list[0 ]; -for (i =0 ; i < sf->hdr.count; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), i++) { -#ifdef DEBUG -if (sfe->namelen != args->name.len) -continue ; -if (memcmp (args->name.name, sfe->nameval, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -ASSERT (0 ); -#endif - } + error =xfs_attr_shortform_hasname (args, &sfe,NULL ); +ASSERT (error != -EEXIST ); offset = (char *)sfe - (char *)sf; size =XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen);@@ -733,33 +772,23 @@ xfs_attr_fork_remove(int xfs_attr_shortform_remove (xfs_da_args_t *args) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe; -int base, size=0 , end, totsize, i; -xfs_mount_t *mp; -xfs_inode_t *dp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base, size =0 , end, totsize; +struct xfs_mount *mp; +struct xfs_inode *dp; +int error;trace_xfs_attr_sf_remove (args); dp = args->dp; mp = dp->i_mount; - base =sizeof (xfs_attr_sf_hdr_t); sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data; - sfe = &sf->list[0 ]; - end = sf->hdr.count; -for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), - base += size, i++) { - size =XFS_ATTR_SF_ENTSIZE (sfe); -if (sfe->namelen != args->name.len) -continue ; -if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -break ; - } -if (i == end) -return -ENOATTR ; + + error =xfs_attr_shortform_hasname (args, &sfe, &base); +if (error != -EEXIST ) +return error; + size =XFS_ATTR_SF_ENTSIZE (sfe);/* * Fix up the attribute fork data, covering the hole fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -42,6 +42,8 @@ int xfs_attr_shortform_getvalue(struct xfs_da_args *args);int xfs_attr_shortform_to_leaf (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_shortform_remove (struct xfs_da_args *args); +int xfs_attr_shortform_hasname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep,int *basep);int xfs_attr_shortform_allfit (struct xfs_buf *bp,struct xfs_inode *dp);int xfs_attr_shortform_bytesfit (struct xfs_inode *dp,int bytes);xfs_failaddr_t xfs_attr_shortform_verify (struct xfs_inode *ip);Signature · 1 line
2.7.4
Re: [PATCH v4 05/17] xfs: Add xfs_has_attr and subroutines
Quoted 231 lines · Brian Foster
Quoted 10 lines · Allison Collins
From: Allison Henderson <[email protected]>
This patch adds a new functions to check for the existence of an attribute. Subroutines are also added to handle the cases of leaf blocks, nodes or shortform. Common code that appears in existing attr add and remove functions have been factored out to help reduce the appearence of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>---
This mostly looks good to me. Just some small nits..
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c | 154 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 107 ++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 4 files changed, 171 insertions(+), 93 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c +9
-0@@ -310,6 +313,34 @@ xfs_attr_set_args( }/* +* Return EEXIST if attr is found, or ENOATTR if not +*/ +int +xfs_has_attr ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_buf *bp; +int error;fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 334
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ +if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_hasname (args,NULL ,NULL ); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST ) + goto out;Hmm.. is this basically an indirect check for whether bp is set? If so, I think doing bp = NULL above and:
if (bp) xfs_trans_brelse(args->trans, bp);... is more straightforward.
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+xfs_trans_brelse (args->trans, bp); + }else { + error =xfs_attr_node_hasname (args,NULL ); + } +out: +return error; +} + +/* * Remove the attribute specified in @args. */ int ...
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +21
-0@@ -832,6 +869,38 @@ xfs_attr_leaf_get(xfs_da_args_t *args)return error; } +/* +* Return EEXIST if attr is found, or ENOATTR if not +* statep: If not null is set to point at the found state. Caller will +* be responsible for freeing the state in this case. +*/ +STATIC int +xfs_attr_node_hasname ( +struct xfs_da_args *args, +struct xfs_da_state **statep) +{ +struct xfs_da_state *state; +int retval, error; + + state =xfs_da_state_alloc (); + state->args = args; + state->mp = args->dp->i_mount; + +/* +* Search to see if name exists, and get back a pointer to it. +*/ + error =xfs_da3_node_lookup_int (state, &retval);fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_get(xfs_da_args_t *args) · line 902
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+if (error ==0 ) + error = retval; + +if (statep !=NULL ) + *statep = state; +else +xfs_da_state_free (state); + +return error; +}The state allocation handling is a little wonky here in the error scenario. I think precedent is that if we're returning an unexpected error, we should probably just free state directly rather than rely on the caller to do so. If the function returns "success" (meaning
-EEXISTor-ENOATTR), then the caller owns the state memory. It might also make sense to NULL init the pointer either at the top of this helper or the caller.Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +1
-0+/*======================================================================== * External routines when attribute list size > geo->blksize *========================================================================*/ ...
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-2@@ -1324,20 +1376,14 @@ xfs_attr_node_get(xfs_da_args_t *args)trace_xfs_attr_node_get (args); - state =xfs_da_state_alloc (); - state->args = args;fs/xfs/libxfs/xfs_attr.c xfs_attr_node_get(xfs_da_args_t *args) · line 1384
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-4- state->mp = args->dp->i_mount; -/* * Search to see if name exists, and get back a pointer to it. */ - error =xfs_da3_node_lookup_int (state, &retval); -if (error) { + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) { retval = error;Can we kill retval in this function now? The only use is to assign error to it.
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0
-2goto out_release; } -if (retval != -EEXIST ) - goto out_release;/* * Get the value, local or "remote" ...
Quoted 20 lines
fs/xfs/libxfs/xfs_attr_leaf.c +12
-0@@ -655,18 +655,67 @@ xfs_attr_shortform_create(xfs_da_args_t *args) }/* +* Return -EEXIST if attr is found, or -ENOATTR if not +* args: args containing attribute name and namelen +* sfep: If not null, pointer will be set to the last attr entry found on +-EEXIST. On -ENOATTR pointer is left at the last entry in the list +* basep: If not null, pointer is set to the byte offset of the entry in the +* list on -EEXIST. On -ENOATTR, pointer is left at the byte offset of +* the last entry in the list +*/ +int +xfs_attr_shortform_hasname( + struct xfs_da_args *args, + struct xfs_attr_sf_entry **sfep,fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 679
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10
-0+ int *basep) +{ +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base =sizeof (struct xfs_attr_sf_hdr ); +int size =0 ; +int end; +int i; + + base =sizeof (struct xfs_attr_sf_hdr );Double init.
Quoted 35 lines
fs/xfs/libxfs/xfs_attr_leaf.c +27
-2+ sf = (struct xfs_attr_shortform *)args->dp->i_afp->if_u1.if_data; + sfe = &sf->list[0 ]; + end = sf->hdr.count; +for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), + base += size, i++) { + size =XFS_ATTR_SF_ENTSIZE (sfe); +if (sfe->namelen != args->name.len) +continue ; +if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) +continue ; +if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) +continue ; +break ; + } + +if (sfep !=NULL ) + *sfep = sfe; + +if (basep !=NULL ) + *basep = base; + +if (i == end) +return -ENOATTR ; +return -EEXIST ; +} + +/* * Add a name/value pair to the shortform attribute list. * Overflow from the inode has already been checked for. */ void xfs_attr_shortform_add (xfs_da_args_t *args,int forkoff) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe;fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr_shortform_create(xfs_da_args_t *args) · line 718
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +6
-4-int i, offset, size; -xfs_mount_t *mp; -xfs_inode_t *dp; -struct xfs_ifork *ifp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int offset, size, error; +struct xfs_mount *mp; +struct xfs_inode *dp; +struct xfs_ifork *ifp;Might as well fix up the typedef in the function signature (here and below) as well.
Quoted 1 line
Brian
Sure, all the nits sound reasonable I will update them in the next version. Thanks for the review!
Allison
Quoted 87 lines
Quoted 86 lines
fs/xfs/libxfs/xfs_attr_leaf.c +13
-33trace_xfs_attr_sf_add (args);@@ -677,18 +726,8 @@ xfs_attr_shortform_add(xfs_da_args_t *args, int forkoff) ifp = dp->i_afp;ASSERT (ifp->if_flags &XFS_IFINLINE ); sf = (xfs_attr_shortform_t *)ifp->if_u1.if_data; - sfe = &sf->list[0 ]; -for (i =0 ; i < sf->hdr.count; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), i++) { -#ifdef DEBUG -if (sfe->namelen != args->name.len) -continue ; -if (memcmp (args->name.name, sfe->nameval, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -ASSERT (0 ); -#endif - } + error =xfs_attr_shortform_hasname (args, &sfe,NULL ); +ASSERT (error != -EEXIST ); offset = (char *)sfe - (char *)sf; size =XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen);@@ -733,33 +772,23 @@ xfs_attr_fork_remove(int xfs_attr_shortform_remove (xfs_da_args_t *args) { -xfs_attr_shortform_t *sf; -xfs_attr_sf_entry_t *sfe; -int base, size=0 , end, totsize, i; -xfs_mount_t *mp; -xfs_inode_t *dp; +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base, size =0 , end, totsize; +struct xfs_mount *mp; +struct xfs_inode *dp; +int error;trace_xfs_attr_sf_remove (args); dp = args->dp; mp = dp->i_mount; - base =sizeof (xfs_attr_sf_hdr_t); sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data; - sfe = &sf->list[0 ]; - end = sf->hdr.count; -for (i =0 ; i < end; sfe =XFS_ATTR_SF_NEXTENTRY (sfe), - base += size, i++) { - size =XFS_ATTR_SF_ENTSIZE (sfe); -if (sfe->namelen != args->name.len) -continue ; -if (memcmp (sfe->nameval, args->name.name, args->name.len) !=0 ) -continue ; -if (!xfs_attr_namesp_match (args->name.type, sfe->flags)) -continue ; -break ; - } -if (i == end) -return -ENOATTR ; + + error =xfs_attr_shortform_hasname (args, &sfe, &base); +if (error != -EEXIST ) +return error; + size =XFS_ATTR_SF_ENTSIZE (sfe);/* * Fix up the attribute fork data, covering the hole fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -42,6 +42,8 @@ int xfs_attr_shortform_getvalue(struct xfs_da_args *args);int xfs_attr_shortform_to_leaf (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_shortform_remove (struct xfs_da_args *args); +int xfs_attr_shortform_hasname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep,int *basep);int xfs_attr_shortform_allfit (struct xfs_buf *bp,struct xfs_inode *dp);int xfs_attr_shortform_bytesfit (struct xfs_inode *dp,int bytes);xfs_failaddr_t xfs_attr_shortform_verify (struct xfs_inode *ip);Signature · 1 line
2.7.4
Re: [PATCH v4 05/17] xfs: Add xfs_has_attr and subroutines
In reply to Allison CollinsQuoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_hasname (args,NULL ,NULL ); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 341
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST ) + goto out; +xfs_trans_brelse (args->trans, bp); + }else { + error =xfs_attr_node_hasname (args,NULL ); + } +out: +return error; +}
I think a lot of this would be much simpler without the goto out, e.g.:
if (!xfs_inode_hasattr(dp))
return -ENOATTR;
if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
return xfs_attr_shortform_hasname(args, NULL, NULL);
}
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
struct xfs_buf *bp;
int error = xfs_attr_leaf_hasname(args, &bp);
if (error == -ENOATTR || error == -EEXIST)
xfs_trans_brelse(args->trans, bp);
return error;
}
return xfs_attr_node_hasname(args, NULL);Re: [PATCH v4 05/17] xfs: Add xfs_has_attr and subroutines
Quoted 29 lines · Christoph Hellwig
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_hasname (args,NULL ,NULL ); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) {fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 341
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ error =xfs_attr_leaf_hasname (args, &bp); +if (error != -ENOATTR && error != -EEXIST ) + goto out; +xfs_trans_brelse (args->trans, bp); + }else { + error =xfs_attr_node_hasname (args,NULL ); + } +out: +return error; +}I think a lot of this would be much simpler without the goto out, e.g.:
if (!xfs_inode_hasattr(dp)) return -ENOATTR; if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) { ASSERT(dp->i_afp->if_flags & XFS_IFINLINE); return xfs_attr_shortform_hasname(args, NULL, NULL); } if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) { struct xfs_buf *bp;
Quoted 9 lines
int error = xfs_attr_leaf_hasname(args, &bp); if (error == -ENOATTR || error == -EEXIST) xfs_trans_brelse(args->trans, bp); return error; } return xfs_attr_node_hasname(args, NULL);
Sure, will fix this along with Brians suggestions too. Thanks! Allison
PATCH v4 6/17 xfs: Factor out new helper functions xfs_attr_rmtval_set
In reply to Allison CollinsBreak xfs_attr_rmtval_set into two helper functions xfs_attr_rmt_find_hole and xfs_attr_rmtval_set_value. xfs_attr_rmtval_set rolls the transaction between the helpers, but delayed operations cannot. We will use the helpers later when constructing new delayed attribute routines.
--- fs/xfs/libxfs/xfs_attr_remote.c | 71 +++++++++++++++++++++++++++++++---------- fs/xfs/libxfs/xfs_attr_remote.h | 3 +- 2 files changed, 56 insertions(+), 18 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +54 -17
@@ -21,6 +21,7 @@#include "xfs_attr.h" #include "xfs_trace.h" #include "xfs_error.h" +#include "xfs_attr_remote.h" #define ATTR_RMTVALUE_MAPSIZE 1/* # of map entries at once */
@@ -432,34 +433,20 @@ xfs_attr_rmtval_set( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_mount *mp = dp->i_mount;struct xfs_bmbt_irec map;xfs_dablk_t lblkno; -xfs_fileoff_t lfileoff =0 ; -uint8_t *src = args->value;int blkcnt; -int valuelen;int nmap;int error; -int offset =0 ;trace_xfs_attr_rmtval_set (args); -/* -* Find a "hole" in the attribute address space large enough for -* us to drop the new attribute's value into. Because CRC enable -* attributes have headers, we can't just do a straight byte to FSB -* conversion and have to take the header space into account. -*/ - blkcnt =xfs_attr3_rmt_blocks (mp, args->rmtvaluelen); - error =xfs_bmap_first_unused (args->trans, args->dp, blkcnt, &lfileoff, -XFS_ATTR_FORK ); + error =xfs_attr_rmt_find_hole (args);if (error)return error; - args->rmtblkno = lblkno = (xfs_dablk_t )lfileoff; - args->rmtblkcnt = blkcnt; - + blkcnt = args->rmtblkcnt; + lblkno = (xfs_dablk_t )args->rmtblkno;/* * Roll through the "value", allocating blocks on disk as required. */
@@ -500,6 +487,56 @@ xfs_attr_rmtval_set(return error; } +return xfs_attr_rmtval_set_value (args); +} + + +/* +* Find a "hole" in the attribute address space large enough for us to drop the +* new attribute's value into +*/ +int +xfs_attr_rmt_find_hole ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_mount *mp = dp->i_mount; +int error; +int blkcnt; +xfs_fileoff_t lfileoff =0 ; + +/* +* Because CRC enable attributes have headers, we can't just do a +* straight byte to FSB conversion and have to take the header space +* into account. +*/ + blkcnt =xfs_attr3_rmt_blocks (mp, args->rmtvaluelen); + error =xfs_bmap_first_unused (args->trans, args->dp, blkcnt, &lfileoff, +XFS_ATTR_FORK ); +if (error) +return error; + + args->rmtblkno = (xfs_dablk_t )lfileoff; + args->rmtblkcnt = blkcnt; + +return 0 ; +} + +int +xfs_attr_rmtval_set_value ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_mount *mp = dp->i_mount; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +uint8_t *src = args->value; +int blkcnt; +int valuelen; +int nmap; +int error; +int offset =0 ; +/* * Roll through the "value", copying the attribute value to the * already-allocated blocks. Blocks are written synchronously
fs/xfs/libxfs/xfs_attr_remote.h +2 -1
@@ -11,5 +11,6 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args);int xfs_attr_rmtval_remove (struct xfs_da_args *args); - +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args);#endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
Re: [PATCH v4 06/17] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 9 lines · Allison Collins
Break
xfs_attr_rmtval_setinto two helper functionsxfs_attr_rmt_find_holeandxfs_attr_rmtval_set_value.xfs_attr_rmtval_setrolls the transaction between the helpers, but delayed operations cannot. We will use the helpers later when constructing new delayed attribute routines.Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>
Looks good,
--D
Quoted 127 lines
--- fs/xfs/libxfs/xfs_attr_remote.c | 71 +++++++++++++++++++++++++++++++---------- fs/xfs/libxfs/xfs_attr_remote.h | 3 +- 2 files changed, 56 insertions(+), 18 deletions(-)fs/xfs/libxfs/xfs_attr_remote.c +54
-17@@ -21,6 +21,7 @@#include "xfs_attr.h" #include "xfs_trace.h" #include "xfs_error.h" +#include "xfs_attr_remote.h" #define ATTR_RMTVALUE_MAPSIZE 1/* # of map entries at once */ @@ -432,34 +433,20 @@ xfs_attr_rmtval_set( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_mount *mp = dp->i_mount;struct xfs_bmbt_irec map;xfs_dablk_t lblkno; -xfs_fileoff_t lfileoff =0 ; -uint8_t *src = args->value;int blkcnt; -int valuelen;int nmap;int error; -int offset =0 ;trace_xfs_attr_rmtval_set (args); -/* -* Find a "hole" in the attribute address space large enough for -* us to drop the new attribute's value into. Because CRC enable -* attributes have headers, we can't just do a straight byte to FSB -* conversion and have to take the header space into account. -*/ - blkcnt =xfs_attr3_rmt_blocks (mp, args->rmtvaluelen); - error =xfs_bmap_first_unused (args->trans, args->dp, blkcnt, &lfileoff, -XFS_ATTR_FORK ); + error =xfs_attr_rmt_find_hole (args);if (error)return error; - args->rmtblkno = lblkno = (xfs_dablk_t )lfileoff; - args->rmtblkcnt = blkcnt; - + blkcnt = args->rmtblkcnt; + lblkno = (xfs_dablk_t )args->rmtblkno;/* * Roll through the "value", allocating blocks on disk as required. */ @@ -500,6 +487,56 @@ xfs_attr_rmtval_set(return error; } +return xfs_attr_rmtval_set_value (args); +} + + +/* +* Find a "hole" in the attribute address space large enough for us to drop the +* new attribute's value into +*/ +int +xfs_attr_rmt_find_hole ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_mount *mp = dp->i_mount; +int error; +int blkcnt; +xfs_fileoff_t lfileoff =0 ; + +/* +* Because CRC enable attributes have headers, we can't just do a +* straight byte to FSB conversion and have to take the header space +* into account. +*/ + blkcnt =xfs_attr3_rmt_blocks (mp, args->rmtvaluelen); + error =xfs_bmap_first_unused (args->trans, args->dp, blkcnt, &lfileoff, +XFS_ATTR_FORK ); +if (error) +return error; + + args->rmtblkno = (xfs_dablk_t )lfileoff; + args->rmtblkcnt = blkcnt; + +return 0 ; +} + +int +xfs_attr_rmtval_set_value ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_mount *mp = dp->i_mount; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +uint8_t *src = args->value; +int blkcnt; +int valuelen; +int nmap; +int error; +int offset =0 ; +/* * Roll through the "value", copying the attribute value to the * already-allocated blocks. Blocks are written synchronously fs/xfs/libxfs/xfs_attr_remote.h +2
-1@@ -11,5 +11,6 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args);int xfs_attr_rmtval_remove (struct xfs_da_args *args); - +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args);#endif /* __XFS_ATTR_REMOTE_H__ */ Signature · 1 line
2.7.4
Re: [PATCH v4 06/17] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 8 lines · Darrick J. Wong
Quoted 7 lines · Allison Collins
Break
xfs_attr_rmtval_setinto two helper functionsxfs_attr_rmt_find_holeandxfs_attr_rmtval_set_value.xfs_attr_rmtval_setrolls the transaction between the helpers, but delayed operations cannot. We will use the helpers later when constructing new delayed attribute routines.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>Looks good,
Reviewed-by Darrick J. Wong <[email protected]>--D
Alrighty, thanks for the reviews!
Allison
Quoted 128 lines
Quoted 128 lines
--- fs/xfs/libxfs/xfs_attr_remote.c | 71 +++++++++++++++++++++++++++++++---------- fs/xfs/libxfs/xfs_attr_remote.h | 3 +- 2 files changed, 56 insertions(+), 18 deletions(-)fs/xfs/libxfs/xfs_attr_remote.c +54
-17@@ -21,6 +21,7 @@#include "xfs_attr.h" #include "xfs_trace.h" #include "xfs_error.h" +#include "xfs_attr_remote.h" #define ATTR_RMTVALUE_MAPSIZE 1/* # of map entries at once */ @@ -432,34 +433,20 @@ xfs_attr_rmtval_set( struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -struct xfs_mount *mp = dp->i_mount;struct xfs_bmbt_irec map;xfs_dablk_t lblkno; -xfs_fileoff_t lfileoff =0 ; -uint8_t *src = args->value;int blkcnt; -int valuelen;int nmap;int error; -int offset =0 ;trace_xfs_attr_rmtval_set (args); -/* -* Find a "hole" in the attribute address space large enough for -* us to drop the new attribute's value into. Because CRC enable -* attributes have headers, we can't just do a straight byte to FSB -* conversion and have to take the header space into account. -*/ - blkcnt =xfs_attr3_rmt_blocks (mp, args->rmtvaluelen); - error =xfs_bmap_first_unused (args->trans, args->dp, blkcnt, &lfileoff, -XFS_ATTR_FORK ); + error =xfs_attr_rmt_find_hole (args);if (error)return error; - args->rmtblkno = lblkno = (xfs_dablk_t )lfileoff; - args->rmtblkcnt = blkcnt; - + blkcnt = args->rmtblkcnt; + lblkno = (xfs_dablk_t )args->rmtblkno;/* * Roll through the "value", allocating blocks on disk as required. */ @@ -500,6 +487,56 @@ xfs_attr_rmtval_set(return error; } +return xfs_attr_rmtval_set_value (args); +} + + +/* +* Find a "hole" in the attribute address space large enough for us to drop the +* new attribute's value into +*/ +int +xfs_attr_rmt_find_hole ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_mount *mp = dp->i_mount; +int error; +int blkcnt; +xfs_fileoff_t lfileoff =0 ; + +/* +* Because CRC enable attributes have headers, we can't just do a +* straight byte to FSB conversion and have to take the header space +* into account. +*/ + blkcnt =xfs_attr3_rmt_blocks (mp, args->rmtvaluelen); + error =xfs_bmap_first_unused (args->trans, args->dp, blkcnt, &lfileoff, +XFS_ATTR_FORK ); +if (error) +return error; + + args->rmtblkno = (xfs_dablk_t )lfileoff; + args->rmtblkcnt = blkcnt; + +return 0 ; +} + +int +xfs_attr_rmtval_set_value ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +struct xfs_mount *mp = dp->i_mount; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +uint8_t *src = args->value; +int blkcnt; +int valuelen; +int nmap; +int error; +int offset =0 ; +/* * Roll through the "value", copying the attribute value to the * already-allocated blocks. Blocks are written synchronously fs/xfs/libxfs/xfs_attr_remote.h +2
-1@@ -11,5 +11,6 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args);int xfs_attr_rmtval_remove (struct xfs_da_args *args); - +int xfs_attr_rmtval_set_value (struct xfs_da_args *args); +int xfs_attr_rmt_find_hole (struct xfs_da_args *args);#endif /* __XFS_ATTR_REMOTE_H__ */ Signature · 1 line
2.7.4
PATCH v4 7/17 xfs: Factor up trans handling in xfs_attr3_leaf_flipflags
In reply to Allison CollinsSince delayed operations cannot roll transactions, factor up the transaction handling into the calling function
--- fs/xfs/libxfs/xfs_attr.c | 14 ++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 ----- 2 files changed, 14 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_attr.c +14 -0
@@ -721,6 +721,13 @@ xfs_attr_leaf_addname( error =xfs_attr3_leaf_flipflags (args);if (error)return error; +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) +return error;/* * Dismantle the "old" attribute/value pair by removing
@@ -1057,6 +1064,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_flipflags (args);if (error) goto out; +/* +* Commit the flag value change and start the next trans in +* series +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out;/* * Dismantle the "old" attribute/value pair by removing
fs/xfs/libxfs/xfs_attr_leaf.c +0 -5
@@ -2973,10 +2973,5 @@ xfs_attr3_leaf_flipflags( XFS_DA_LOGRANGE(leaf2, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -return error; }
Signature · 1 line
2.7.4
Re: [PATCH v4 07/17] xfs: Factor up trans handling in xfs_attr3_leaf_flipflags
Quoted 5 lines · Allison Collins
Since delayed operations cannot roll transactions, factor up the transaction handling into the calling function
Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>
Looks ok,
--D
Quoted 55 lines
--- fs/xfs/libxfs/xfs_attr.c | 14 ++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 ----- 2 files changed, 14 insertions(+), 5 deletions(-)fs/xfs/libxfs/xfs_attr.c +14
-0@@ -721,6 +721,13 @@ xfs_attr_leaf_addname( error =xfs_attr3_leaf_flipflags (args);if (error)return error; +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) +return error;/* * Dismantle the "old" attribute/value pair by removing @@ -1057,6 +1064,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_flipflags (args);if (error) goto out; +/* +* Commit the flag value change and start the next trans in +* series +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out;/* * Dismantle the "old" attribute/value pair by removing fs/xfs/libxfs/xfs_attr_leaf.c +0
-5@@ -2973,10 +2973,5 @@ xfs_attr3_leaf_flipflags( XFS_DA_LOGRANGE(leaf2, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -return error; }Signature · 1 line
2.7.4
Re: [PATCH v4 07/17] xfs: Factor up trans handling in xfs_attr3_leaf_flipflags
Quoted 11 lines · Darrick J. Wong
Quoted 5 lines · Allison Collins
Since delayed operations cannot roll transactions, factor up the transaction handling into the calling function
Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>Looks ok,
Reviewed-by Darrick J. Wong <[email protected]>--D
Thank you!
Allison
Quoted 56 lines
Quoted 56 lines
--- fs/xfs/libxfs/xfs_attr.c | 14 ++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 ----- 2 files changed, 14 insertions(+), 5 deletions(-)fs/xfs/libxfs/xfs_attr.c +14
-0@@ -721,6 +721,13 @@ xfs_attr_leaf_addname( error =xfs_attr3_leaf_flipflags (args);if (error)return error; +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) +return error;/* * Dismantle the "old" attribute/value pair by removing @@ -1057,6 +1064,13 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_flipflags (args);if (error) goto out; +/* +* Commit the flag value change and start the next trans in +* series +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out;/* * Dismantle the "old" attribute/value pair by removing fs/xfs/libxfs/xfs_attr_leaf.c +0
-5@@ -2973,10 +2973,5 @@ xfs_attr3_leaf_flipflags( XFS_DA_LOGRANGE(leaf2, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -return error; }Signature · 1 line
2.7.4
PATCH v4 8/17 xfs: Factor out xfs_attr_leaf_addname helper
In reply to Allison CollinsFactor out new helper function xfs_attr_leaf_try_add. Because new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_leaf_addname that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.
--- fs/xfs/libxfs/xfs_attr.c | 84 +++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 33 deletions(-)
fs/xfs/libxfs/xfs_attr.c +51 -33
@@ -305,10 +305,33 @@ xfs_attr_set_args( } } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_addname (args); -else +if (error == -ENOSPC ) { +/* +* Commit that transaction so that the node_addname() +* call can manage its own transactions. +*/ + error =xfs_defer_finish (&args->trans); +if (error) +return error; + +/* +* Commit the current trans (including the inode) and +* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + +/* +* Fob the rest of the problem off on the Btree code. +*/ + error =xfs_attr_node_addname (args); + } + }else { error =xfs_attr_node_addname (args); + }return error; }
@@ -601,21 +624,12 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)* External routines when attribute list is one block *========================================================================*/ -/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) +xfs_attr_leaf_try_add ( +struct xfs_da_args *args, +struct xfs_buf *bp) { -struct xfs_buf *bp; -int retval, error, forkoff; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); +int retval, error;/* * Look up the given attribute in the leaf block. Figure out if
@@ -661,31 +675,35 @@ xfs_attr_leaf_addname( retval =xfs_attr3_leaf_add (bp, args);if (retval == -ENOSPC ) {/* -* Promote the attribute list to the Btree format, then -* Commit that transaction so that the node_addname() call -* can manage its own transactions. +* Promote the attribute list to the Btree format. +* Unless an error occurs, retain the -ENOSPC retval */ error =xfs_attr3_leaf_to_node (args);if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; + } +return retval; +} -/* -* Commit the current trans (including the inode) and start -* a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; -/* -* Fob the whole rest of the problem off on the Btree code. -*/ - error =xfs_attr_node_addname (args); +/* +* Add a name to the leaf attribute list structure +* +* This leaf block cannot have a "remote" value, we only call this routine +* if bmap_one_block() says there is only one block (ie: no remote blks). +*/ +STATIC int +xfs_attr_leaf_addname (struct xfs_da_args *args) +{ +int error, forkoff; +struct xfs_buf *bp =NULL ; +struct xfs_inode *dp = args->dp; + +trace_xfs_attr_leaf_addname (args); + + error =xfs_attr_leaf_try_add (args, bp); +if (error)return error; - }/* * Commit the transaction that added the attr name so that
Signature · 1 line
2.7.4
Re: [PATCH v4 08/17] xfs: Factor out xfs_attr_leaf_addname helper
Quoted 58 lines · Allison Collins
Factor out new helper function
xfs_attr_leaf_try_add. Because new delayed attribute routines cannot roll transactions, we carve off the parts ofxfs_attr_leaf_addnamethat we can use. This will help to reduce repetitive code later when we introduce delayed attributes.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 84 +++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 33 deletions(-)fs/xfs/libxfs/xfs_attr.c +25
-2@@ -305,10 +305,33 @@ xfs_attr_set_args( } } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_addname (args); -else +if (error == -ENOSPC ) { +/* +* Commit that transaction so that the node_addname() +* call can manage its own transactions. +*/ + error =xfs_defer_finish (&args->trans); +if (error) +return error; + +/* +* Commit the current trans (including the inode) and +* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + +/* +* Fob the rest of the problem off on the Btree code. +*/ + error =xfs_attr_node_addname (args); + } + }else { error =xfs_attr_node_addname (args); + }return error;}
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -601,21 +624,12 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)* External routines when attribute list is one block *========================================================================*/
fs/xfs/libxfs/xfs_attr.c xfs_attr_shortform_addname(xfs_da_args_t *args) · line 628
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1
-8-/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) +xfs_attr_leaf_try_add(
(total stream of consciousness here...)
AFAICT the old _addname function's responsibilities were:
1 Try to add a new attr key entry to the leaf block, with INCOMPLETE set
if it's a rename op or we need to set a remote value.
2 If there wasn't space in the leaf block, convert to node format, call
the node version of this function, and exit.
3 Allocating blocks for the remote attr value and writing them, if
applicable
4 If it's a rename operation, clearing the INCOMPLETE flag on the new
entry; setting it on the old entry; and then removing the old entry.
5 Clearing the INCOMPLETE flag on the new entry when we're done writing
a remote value (if applicable)
I think we arrive at this split so that we don't have a transaction roll in the middle of the function, right? And also to make the "convert to node format and roll" bits go elsewhere?
The way I'm thinking about how to accomplish this is...
xfs_attr_leaf_addname should be renamed xfs_attr_leaf_setname, and then hoist (1) into a separate function, move (2) into xfs_attr_set_args, and hoist (4) into a separate function.
...ok, so let's test how closely my understanding fits the changes made in this patch:
_try_add is basically (1).
Most of (2) happened, though the call to xfs_attr3_leaf_to_node ought to go into the caller so that the conversion stays with the defer_finish and roll.
(4) could still be done, maybe as a separate prep patch.
Hm, ok, I think I understand what this patch does. The call site in xfs_attr_set_args would be clearer (and less indenty) if it looked like:
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
error = xfs_attr_leaf_addname(args);
if (error == 0 || error != -ENOSPC)
return error;
/* Promote the attribute list to node format. */
error = xfs_attr3_leaf_to_node(args);
if (error)
return error;
/*
* Commit that transaction so that the node_addname()
* call can manage its own transactions.
*/
error = xfs_defer_finish(&args->trans);
if (error)
return error;
/*
* Commit the current trans (including the inode) and
* start a new one.
*/
error = xfs_trans_roll_inode(&args->trans, dp);
if (error)
return error;
}
return xfs_attr_node_addname(args);But otherwise it looks decent, assuming I understood any of it. :)
--D
Quoted 69 lines
fs/xfs/libxfs/xfs_attr.c +25
-23+struct xfs_da_args *args, + struct xfs_buf *bp) { -struct xfs_buf *bp; -int retval, error, forkoff; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); + int retval, error;/* * Look up the given attribute in the leaf block. Figure out if @@ -661,31 +675,35 @@ xfs_attr_leaf_addname( retval =xfs_attr3_leaf_add (bp, args);if (retval == -ENOSPC ) {/* -* Promote the attribute list to the Btree format, then -* Commit that transaction so that the node_addname() call -* can manage its own transactions. +* Promote the attribute list to the Btree format. +* Unless an error occurs, retain the -ENOSPC retval */ error =xfs_attr3_leaf_to_node (args);if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; + } +return retval; +} -/* -* Commit the current trans (including the inode) and start -* a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; -/* -* Fob the whole rest of the problem off on the Btree code. -*/ - error =xfs_attr_node_addname (args); +/* +* Add a name to the leaf attribute list structure +* +* This leaf block cannot have a "remote" value, we only call this routine +* if bmap_one_block() says there is only one block (ie: no remote blks). +*/ +STATIC int +xfs_attr_leaf_addname (struct xfs_da_args *args) +{ +int error, forkoff; +struct xfs_buf *bp =NULL ; +struct xfs_inode *dp = args->dp; + +trace_xfs_attr_leaf_addname (args); + + error =xfs_attr_leaf_try_add (args, bp); +if (error)return error; - }/* * Commit the transaction that added the attr name so that Signature · 1 line
2.7.4
Re: [PATCH v4 08/17] xfs: Factor out xfs_attr_leaf_addname helper
Quoted 98 lines · Darrick J. Wong
Quoted 58 lines · Allison Collins
Factor out new helper function
xfs_attr_leaf_try_add. Because new delayed attribute routines cannot roll transactions, we carve off the parts ofxfs_attr_leaf_addnamethat we can use. This will help to reduce repetitive code later when we introduce delayed attributes.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 84 +++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 33 deletions(-)fs/xfs/libxfs/xfs_attr.c +25
-2@@ -305,10 +305,33 @@ xfs_attr_set_args( } } -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_addname (args); -else +if (error == -ENOSPC ) { +/* +* Commit that transaction so that the node_addname() +* call can manage its own transactions. +*/ + error =xfs_defer_finish (&args->trans); +if (error) +return error; + +/* +* Commit the current trans (including the inode) and +* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + +/* +* Fob the rest of the problem off on the Btree code. +*/ + error =xfs_attr_node_addname (args); + } + }else { error =xfs_attr_node_addname (args); + }return error;}fs/xfs/libxfs/xfs_attr.c +0
-0@@ -601,21 +624,12 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)* External routines when attribute list is one block *========================================================================*/ fs/xfs/libxfs/xfs_attr.c xfs_attr_shortform_addname(xfs_da_args_t *args) · line 628
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1
-8-/* -* Add a name to the leaf attribute list structure -* -* This leaf block cannot have a "remote" value, we only call this routine -* if bmap_one_block() says there is only one block (ie: no remote blks). -*/ STATIC int -xfs_attr_leaf_addname ( -struct xfs_da_args *args) +xfs_attr_leaf_try_add((total stream of consciousness here...)
AFAICT the old
_addnamefunction's responsibilities were:1 Try to add a new attr key entry to the leaf block, with INCOMPLETE set
if it's a rename op or we need to set a remote value.
2 If there wasn't space in the leaf block, convert to node format, call
the node version of this function, and exit.
3 Allocating blocks for the remote attr value and writing them, if
applicable
4 If it's a rename operation, clearing the INCOMPLETE flag on the new
entry; setting it on the old entry; and then removing the old entry.
5 Clearing the INCOMPLETE flag on the new entry when we're done writing
a remote value (if applicable)I think we arrive at this split so that we don't have a transaction roll in the middle of the function, right? And also to make the "convert to node format and roll" bits go elsewhere?
The way I'm thinking about how to accomplish this is...
xfs_attr_leaf_addnameshould be renamedxfs_attr_leaf_setname, and then hoist (1) into a separate function, move (2) intoxfs_attr_set_args, and hoist (4) into a separate function....ok, so let's test how closely my understanding fits the changes made in this patch:
Quoted 8 lines
_try_addis basically (1).Most of (2) happened, though the call to
xfs_attr3_leaf_to_nodeought to go into the caller so that the conversion stays with thedefer_finishand roll.(4) could still be done, maybe as a separate prep patch.
I think you're on the right track. Perhaps the diff made it look a little crazier than it seems. Maybe its easier to describe it as this:
I renamed xfs_attr_leaf_addname to xfs_attr_leaf_try_add,
and then deleted (2) out of the body of the function. The upper half (1) became the helper function, and lower half (3, 4, and 5) became the new xfs_attr_leaf_addname, which now calls the helper at the start of the routine. Finally (2) got factored up into the caller.
Hope that helps some :-) The point of all this being to jigsaw out (1) into a stand alone routine that we can use later in delayed attrs.
Quoted 12 lines
Hm, ok, I think I understand what this patch does. The call site in
xfs_attr_set_argswould be clearer (and less indenty) if it looked like:if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) { error = xfs_attr_leaf_addname(args); if (error == 0 || error != -ENOSPC) return error; /* Promote the attribute list to node format. */ error = xfs_attr3_leaf_to_node(args); if (error) return error;
I think this part here is already taken care of in xfs_attr_leaf_addname, but otherwise, I think the rest of this is equivalent. Will update in the next set.
Thanks for the reviews!
Allison
Quoted 93 lines
/* * Commit that transaction so that the node_addname() * call can manage its own transactions. */ error = xfs_defer_finish(&args->trans); if (error) return error; /* * Commit the current trans (including the inode) and * start a new one. */ error = xfs_trans_roll_inode(&args->trans, dp); if (error) return error; } return xfs_attr_node_addname(args);But otherwise it looks decent, assuming I understood any of it. :)
--D
Quoted 69 lines
fs/xfs/libxfs/xfs_attr.c +25
-23+struct xfs_da_args *args, + struct xfs_buf *bp) { -struct xfs_buf *bp; -int retval, error, forkoff; -struct xfs_inode *dp = args->dp; - -trace_xfs_attr_leaf_addname (args); + int retval, error;/* * Look up the given attribute in the leaf block. Figure out if @@ -661,31 +675,35 @@ xfs_attr_leaf_addname( retval =xfs_attr3_leaf_add (bp, args);if (retval == -ENOSPC ) {/* -* Promote the attribute list to the Btree format, then -* Commit that transaction so that the node_addname() call -* can manage its own transactions. +* Promote the attribute list to the Btree format. +* Unless an error occurs, retain the -ENOSPC retval */ error =xfs_attr3_leaf_to_node (args);if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; + } +return retval; +} -/* -* Commit the current trans (including the inode) and start -* a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; -/* -* Fob the whole rest of the problem off on the Btree code. -*/ - error =xfs_attr_node_addname (args); +/* +* Add a name to the leaf attribute list structure +* +* This leaf block cannot have a "remote" value, we only call this routine +* if bmap_one_block() says there is only one block (ie: no remote blks). +*/ +STATIC int +xfs_attr_leaf_addname (struct xfs_da_args *args) +{ +int error, forkoff; +struct xfs_buf *bp =NULL ; +struct xfs_inode *dp = args->dp; + +trace_xfs_attr_leaf_addname (args); + + error =xfs_attr_leaf_try_add (args, bp); +if (error)return error; - }/* * Commit the transaction that added the attr name so that Signature · 1 line
2.7.4
PATCH v4 9/17 xfs: Factor up commit from xfs_attr_try_sf_addname
In reply to Allison CollinsNew delayed attribute routines cannot handle transactions, so factor this up to the calling function.
--- fs/xfs/libxfs/xfs_attr.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_attr.c +12 -11
@@ -227,8 +227,7 @@ xfs_attr_try_sf_addname( struct xfs_da_args *args) { -struct xfs_mount *mp = dp->i_mount; -int error, error2; +int error; error =xfs_attr_shortform_addname (args);if (error == -ENOSPC )
@@ -241,12 +240,7 @@ xfs_attr_try_sf_addname(if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 )xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG ); -if (mp->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args->trans); - - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/*
@@ -258,7 +252,7 @@ xfs_attr_set_args( {struct xfs_inode *dp = args->dp;struct xfs_buf *leaf_bp =NULL ; -int error; +int error, error2 =0 ;;/* * If the attribute list is non-existent or a shortform list,
@@ -278,8 +272,15 @@ xfs_attr_set_args(* Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) -return error; +if (error != -ENOSPC ) { +if (dp->i_mount->m_flags &XFS_MOUNT_WSYNC ) +xfs_trans_set_sync (args->trans); + + error2 =xfs_trans_commit (args->trans); + args->trans =NULL ; +return error ? error : error2; + } +/* * It won't fit in the shortform, transform to a leaf block.
Signature · 1 line
2.7.4
Re: [PATCH v4 09/17] xfs: Factor up commit from xfs_attr_try_sf_addname
Quoted 23 lines · Allison Collins
New delayed attribute routines cannot handle transactions, so factor this up to the calling function.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)fs/xfs/libxfs/xfs_attr.c +1
-2@@ -227,8 +227,7 @@ xfs_attr_try_sf_addname( struct xfs_da_args *args) { -struct xfs_mount *mp = dp->i_mount; -int error, error2; +int error; error =xfs_attr_shortform_addname (args);if (error == -ENOSPC )
fs/xfs/libxfs/xfs_attr.c xfs_attr_try_sf_addname( · line 241
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +0
-0@@ -241,12 +240,7 @@ xfs_attr_try_sf_addname(if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 )xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );
What if you moved this part (the conditional ichgtime) into xfs_attr_shortform_addname? Then this function can just go away.
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +2
-7-if (mp->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args->trans); - - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* @@ -258,7 +252,7 @@ xfs_attr_set_args( {struct xfs_inode *dp = args->dp;struct xfs_buf *leaf_bp =NULL ; -int error; +int error, error2 =0 ;;/* * If the attribute list is non-existent or a shortform list, @@ -278,8 +272,15 @@ xfs_attr_set_args(* Try to add the attr to the attribute list in the inode. */
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 281
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-2error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) -return error; +if (error != -ENOSPC ) { +if (dp->i_mount->m_flags &XFS_MOUNT_WSYNC ) +xfs_trans_set_sync (args->trans); + + error2 =xfs_trans_commit (args->trans); + args->trans =NULL ; +return error ? error : error2;
Can error be something other than 0 or EEXIST? If so, does it make sense to commit even in those cases? (Have I asked this before...?) It looks odd to me that we'd commit the transaction even if something handed back EFSCORRUPTED.
Hm, it's a local attr fork so I guess the only possible error is ENOSPC? If that's true then please add a comment/ASSERT to that effect.
--D
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+ } +/* * It won't fit in the shortform, transform to a leaf block. Signature · 1 line
2.7.4
Re: [PATCH v4 09/17] xfs: Factor up commit from xfs_attr_try_sf_addname
Quoted 21 lines · Darrick J. Wong
Quoted 20 lines · Allison Collins
New delayed attribute routines cannot handle transactions, so factor this up to the calling function.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)fs/xfs/libxfs/xfs_attr.c +1
-2@@ -227,8 +227,7 @@ xfs_attr_try_sf_addname( struct xfs_da_args *args) { -struct xfs_mount *mp = dp->i_mount; -int error, error2; +int error;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_try_sf_addname( · line 241
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +0
-0error =xfs_attr_shortform_addname (args);if (error == -ENOSPC )@@ -241,12 +240,7 @@ xfs_attr_try_sf_addname(if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 )xfs_trans_ichgtime (args->trans, dp,XFS_ICHGTIME_CHG );What if you moved this part (the conditional ichgtime) into
xfs_attr_shortform_addname? Then this function can just go away.
Sure, I may do that in a separate patch though just to make it easier to review.
Quoted 29 lines
Quoted 29 lines
fs/xfs/libxfs/xfs_attr.c +4
-9-if (mp->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args->trans); - - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; +return error; }/* @@ -258,7 +252,7 @@ xfs_attr_set_args( {struct xfs_inode *dp = args->dp;struct xfs_buf *leaf_bp =NULL ; -int error; +int error, error2 =0 ;;/* * If the attribute list is non-existent or a shortform list, @@ -278,8 +272,15 @@ xfs_attr_set_args(* Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) -return error; +if (error != -ENOSPC ) { +if (dp->i_mount->m_flags &XFS_MOUNT_WSYNC )
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 281
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+xfs_trans_set_sync (args->trans); + + error2 =xfs_trans_commit (args->trans); + args->trans =NULL ; +return error ? error : error2;Can error be something other than 0 or EEXIST? If so, does it make sense to commit even in those cases? (Have I asked this before...?)
Yeah, this came up once before:
https://patchwork.kernel.org/patch/11087647/
So I simplified it, but then I think people were more comfortable with a straight refactor with no function change:
https://patchwork.kernel.org/patch/11134023/
So I put it back. :-)
It
Quoted 5 lines
looks odd to me that we'd commit the transaction even if something handed back EFSCORRUPTED.
Hm, it's a local attr fork so I guess the only possible error is ENOSPC? If that's true then please add a comment/ASSERT to that effect.
Ok, how about a comment. Something like
/* Should only be 0, EEXIST or ENOSPC */
Sound good?
Allison
Quoted 11 lines
--D
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+ } +/* * It won't fit in the shortform, transform to a leaf block. Signature · 1 line
2.7.4
PATCH v4 10/17 xfs: Factor up trans roll from xfs_attr3_leaf_setflag
In reply to Allison CollinsNew delayed allocation routines cannot be handling transactions so factor them up into the calling functions
--- fs/xfs/libxfs/xfs_attr.c | 5 +++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_attr.c +5 -0
@@ -1213,6 +1213,11 @@ xfs_attr_node_removename( error =xfs_attr3_leaf_setflag (args);if (error) goto out; + + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; + error =xfs_attr_rmtval_remove (args);if (error) goto out;
fs/xfs/libxfs/xfs_attr_leaf.c +1 -4
@@ -2854,10 +2854,7 @@ xfs_attr3_leaf_setflag( XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ -return xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/*
Signature · 1 line
2.7.4
PATCH v4 11/17 xfs: Add xfs_attr3_leaf helper functions
In reply to Allison CollinsAnd new helper functions xfs_attr3_leaf_flag_is_set and xfs_attr3_leaf_flagsflipped. These routines check to see if xfs_attr3_leaf_setflag or xfs_attr3_leaf_flipflags have already been run. We will need this later for delayed attributes since routines may be recalled several times when -EAGAIN is returned.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 94 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 2 files changed, 96 insertions(+)
fs/xfs/libxfs/xfs_attr_leaf.c +94 -0
@@ -2809,6 +2809,40 @@ xfs_attr3_leaf_clearflag( }/* +* Check if the INCOMPLETE flag on an entry in a leaf block is set. This +* function can be used to check if xfs_attr3_leaf_setflag has already been +* called. The INCOMPLETE flag is used during attr rename operations to mark +* entries that are being renamed. Since renames should be atomic, only one of +* them should appear as a completed attribute. +* +* isset is set to true if the flag is set or false otherwise +*/ +int +xfs_attr3_leaf_flag_is_set ( +struct xfs_da_args *args, +bool *isset) +{ +struct xfs_attr_leafblock *leaf; +struct xfs_attr_leaf_entry *entry; +struct xfs_buf *bp; +struct xfs_inode *dp = args->dp; +int error =0 ; + + error =xfs_attr3_leaf_read (args->trans, dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp); +if (error) +return error; + + leaf = bp->b_addr; + entry = &xfs_attr3_leaf_entryp (leaf)[args->index]; + + *isset = ((entry->flags &XFS_ATTR_INCOMPLETE ) !=0 ); +xfs_trans_brelse (args->trans, bp); + +return 0 ; +} + +/* * Set the INCOMPLETE flag on an entry in a leaf block. */ int
@@ -2972,3 +3006,63 @@ xfs_attr3_leaf_flipflags(return error; } + +/* +* On a leaf entry, check to see if the INCOMPLETE flag is cleared +* in args->blkno/index and set in args->blkno2/index2. Note that they could be +* in different blocks, or in the same block. This function can be used to +* check if xfs_attr3_leaf_flipflags has already been called. The INCOMPLETE +* flag is used during attr rename operations to mark entries that are being +* renamed. Since renames should be atomic, only one of them should appear as a +* completed attribute. +* +* isflipped is set to true if flags are flipped or false otherwise +*/ +int +xfs_attr3_leaf_flagsflipped ( +struct xfs_da_args *args, +bool *isflipped) +{ +struct xfs_attr_leafblock *leaf1; +struct xfs_attr_leafblock *leaf2; +struct xfs_attr_leaf_entry *entry1; +struct xfs_attr_leaf_entry *entry2; +struct xfs_buf *bp1; +struct xfs_buf *bp2; +struct xfs_inode *dp = args->dp; +int error =0 ; + +/* +* Read the block containing the "old" attr +*/ + error =xfs_attr3_leaf_read (args->trans, dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp1); +if (error) +return error; + +/* +* Read the block containing the "new" attr, if it is different +*/ +if (args->blkno2 != args->blkno) { + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno2, +-1 , &bp2); +if (error) +return error; + }else { + bp2 = bp1; + } + + leaf1 = bp1->b_addr; + entry1 = &xfs_attr3_leaf_entryp (leaf1)[args->index]; + + leaf2 = bp2->b_addr; + entry2 = &xfs_attr3_leaf_entryp (leaf2)[args->index2]; + + *isflipped = (((entry1->flags &XFS_ATTR_INCOMPLETE ) ==0 ) && + (entry2->flags &XFS_ATTR_INCOMPLETE )); + +xfs_trans_brelse (args->trans, bp1); +xfs_trans_brelse (args->trans, bp2); + +return 0 ; +}
fs/xfs/libxfs/xfs_attr_leaf.h +2 -0
@@ -57,7 +57,9 @@ int xfs_attr3_leaf_to_shortform(struct xfs_buf *bp, struct xfs_da_args *args, int forkoff);int xfs_attr3_leaf_clearflag (struct xfs_da_args *args);int xfs_attr3_leaf_setflag (struct xfs_da_args *args); +int xfs_attr3_leaf_flag_is_set (struct xfs_da_args *args,bool *isset);int xfs_attr3_leaf_flipflags (struct xfs_da_args *args); +int xfs_attr3_leaf_flagsflipped (struct xfs_da_args *args,bool *isflipped);/* * Routines used for growing the Btree.
Signature · 1 line
2.7.4
Re: [PATCH v4 11/17] xfs: Add xfs_attr3_leaf helper functions
Quoted 18 lines · Allison Collins
And new helper functions
xfs_attr3_leaf_flag_is_setandxfs_attr3_leaf_flagsflipped. These routines check to see ifxfs_attr3_leaf_setflagorxfs_attr3_leaf_flipflagshave already been run. We will need this later for delayed attributes since routines may be recalled several times when-EAGAINis returned.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr_leaf.c | 94 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 2 files changed, 96 insertions(+)fs/xfs/libxfs/xfs_attr_leaf.c +0
-0
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2815
Quoted 7 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4
-0@@ -2809,6 +2809,40 @@ xfs_attr3_leaf_clearflag( }/* +* Check if the INCOMPLETE flag on an entry in a leaf block is set. This +* function can be used to check if xfs_attr3_leaf_setflag has already been +* called. The INCOMPLETE flag is used during attr rename operations to mark +* entries that are being renamed. Since renames should be atomic, only one of
It's also used when creating an xattr with a value stored in a remote block so that we can commit the name entry to the log (with INCOMPLETE set), allocate/write the remote value with ordered buffers, and then commit a second transaction clearing the INCOMPLETE flag.
Now that I think about it ... this predicate is for non-rename setting of attrs with remote values, and the "flagsflipped" predicate is for rename operations, aren't they?
Quoted 34 lines
fs/xfs/libxfs/xfs_attr_leaf.c +30
-0+* them should appear as a completed attribute. +* +* isset is set to true if the flag is set or false otherwise +*/ +int +xfs_attr3_leaf_flag_is_set ( +struct xfs_da_args *args, +bool *isset) +{ +struct xfs_attr_leafblock *leaf; +struct xfs_attr_leaf_entry *entry; +struct xfs_buf *bp; +struct xfs_inode *dp = args->dp; +int error =0 ; + + error =xfs_attr3_leaf_read (args->trans, dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp); +if (error) +return error; + + leaf = bp->b_addr; + entry = &xfs_attr3_leaf_entryp (leaf)[args->index]; + + *isset = ((entry->flags &XFS_ATTR_INCOMPLETE ) !=0 ); +xfs_trans_brelse (args->trans, bp); + +return 0 ; +} + +/* * Set the INCOMPLETE flag on an entry in a leaf block. */ int
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3012
Quoted 7 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4
-0@@ -2972,3 +3006,63 @@ xfs_attr3_leaf_flipflags(return error; } + +/* +* On a leaf entry, check to see if the INCOMPLETE flag is cleared +* in args->blkno/index and set in args->blkno2/index2.
Might be worth mentioning here that args->blkno is the old entry and args->blkno2 is the new entry. This predicate will be used (by the deferred attr item recovery code) to decide if we have to finish that part of a rename operation, right?
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3022
Quoted 11 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10
-0Note that they could be +* in different blocks, or in the same block. This function can be used to +* check if xfs_attr3_leaf_flipflags has already been called. The INCOMPLETE +* flag is used during attr rename operations to mark entries that are being +* renamed. Since renames should be atomic, only one of them should appear as a +* completed attribute. +* +* isflipped is set to true if flags are flipped or false otherwise +*/ +int +xfs_attr3_leaf_flagsflipped(
I don't like "flagsflipped" because it's not clear to me what "flipped" means.
xfs_attr3_leaf_rename_is_incomplete() ?
Quoted 17 lines
fs/xfs/libxfs/xfs_attr_leaf.c +17
-0+struct xfs_da_args *args, + bool *isflipped) +{ + struct xfs_attr_leafblock *leaf1; +struct xfs_attr_leafblock *leaf2; +struct xfs_attr_leaf_entry *entry1; +struct xfs_attr_leaf_entry *entry2; +struct xfs_buf *bp1; +struct xfs_buf *bp2; +struct xfs_inode *dp = args->dp; +int error =0 ; + +/* +* Read the block containing the "old" attr +*/ + error =xfs_attr3_leaf_read (args->trans, dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp1);
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3049
Quoted 10 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10
-0+if (error) +return error; + +/* +* Read the block containing the "new" attr, if it is different +*/ +if (args->blkno2 != args->blkno) { + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno2, +-1 , &bp2); +if (error)
bp1 leaks here, I think.
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3061
Quoted 12 lines
fs/xfs/libxfs/xfs_attr_leaf.c +12
-0+return error; + }else { + bp2 = bp1; + } + + leaf1 = bp1->b_addr; + entry1 = &xfs_attr3_leaf_entryp (leaf1)[args->index]; + + leaf2 = bp2->b_addr; + entry2 = &xfs_attr3_leaf_entryp (leaf2)[args->index2]; + + *isflipped = (((entry1->flags & XFS_ATTR_INCOMPLETE) == 0) &&
Nit: ((entry1->flags & XFS_ATTR_INCOMPLETE) == 0) could be written as !(entry1->flags & XFS_ATTR_INCOMPLETE)
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3065
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4
-0+ (entry2->flags & XFS_ATTR_INCOMPLETE)); + +xfs_trans_brelse (args->trans, bp1); +xfs_trans_brelse (args->trans, bp2);
This double-frees bp2 if bp1 == bp2.
--D
Quoted 20 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3
-0+ +return 0 ; +}fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -57,7 +57,9 @@ int xfs_attr3_leaf_to_shortform(struct xfs_buf *bp, struct xfs_da_args *args, int forkoff);int xfs_attr3_leaf_clearflag (struct xfs_da_args *args);int xfs_attr3_leaf_setflag (struct xfs_da_args *args); +int xfs_attr3_leaf_flag_is_set (struct xfs_da_args *args,bool *isset);int xfs_attr3_leaf_flipflags (struct xfs_da_args *args); +int xfs_attr3_leaf_flagsflipped (struct xfs_da_args *args,bool *isflipped);/* * Routines used for growing the Btree. Signature · 1 line
2.7.4
Re: [PATCH v4 11/17] xfs: Add xfs_attr3_leaf helper functions
Quoted 32 lines · Darrick J. Wong
Quoted 18 lines · Allison Collins
And new helper functions
xfs_attr3_leaf_flag_is_setandxfs_attr3_leaf_flagsflipped. These routines check to see ifxfs_attr3_leaf_setflagorxfs_attr3_leaf_flipflagshave already been run. We will need this later for delayed attributes since routines may be recalled several times when-EAGAINis returned.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr_leaf.c | 94 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.h | 2 + 2 files changed, 96 insertions(+)fs/xfs/libxfs/xfs_attr_leaf.c +0
-0fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2815
Quoted 7 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4
-0@@ -2809,6 +2809,40 @@ xfs_attr3_leaf_clearflag( }/* +* Check if the INCOMPLETE flag on an entry in a leaf block is set. This +* function can be used to check if xfs_attr3_leaf_setflag has already been +* called. The INCOMPLETE flag is used during attr rename operations to mark +* entries that are being renamed. Since renames should be atomic, only one of It's also used when creating an xattr with a value stored in a remote block so that we can commit the name entry to the log (with INCOMPLETE set), allocate/write the remote value with ordered buffers, and then commit a second transaction clearing the INCOMPLETE flag.
Quoted 3 lines
Now that I think about it ... this predicate is for non-rename setting of attrs with remote values, and the "flagsflipped" predicate is for rename operations, aren't they?\
Yes, but I'm realizing now, that we may not need these helpers if we continue to move forward with the state machine. With the state machine, we can simply flip the flag, set the next state, and move on since that region of code will not execute again. The state switch will jump us forward to where we were without having to check if we already did it.
Quoted 36 lines
Quoted 36 lines
fs/xfs/libxfs/xfs_attr_leaf.c +30
-0+* them should appear as a completed attribute. +* +* isset is set to true if the flag is set or false otherwise +*/ +int +xfs_attr3_leaf_flag_is_set ( +struct xfs_da_args *args, +bool *isset) +{ +struct xfs_attr_leafblock *leaf; +struct xfs_attr_leaf_entry *entry; +struct xfs_buf *bp; +struct xfs_inode *dp = args->dp; +int error =0 ; + + error =xfs_attr3_leaf_read (args->trans, dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp); +if (error) +return error; + + leaf = bp->b_addr; + entry = &xfs_attr3_leaf_entryp (leaf)[args->index]; + + *isset = ((entry->flags &XFS_ATTR_INCOMPLETE ) !=0 ); +xfs_trans_brelse (args->trans, bp); + +return 0 ; +} + +/* * Set the INCOMPLETE flag on an entry in a leaf block. */ int @@ -2972,3 +3006,63 @@ xfs_attr3_leaf_flipflags(
Quoted 11 lines
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags(
Quoted 6 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4
-0return error; } + +/* +* On a leaf entry, check to see if the INCOMPLETE flag is cleared +* in args->blkno/index and set in args->blkno2/index2. Might be worth mentioning here that
args->blknois the old entry andargs->blkno2is the new entry. This predicate will be used (by the deferred attr item recovery code) to decide if we have to finish that part of a rename operation, right?
No, it was used in the previous series xfs_attr_set_later where I was aiming to rely more on the state of the fork rather than the state machine. But with the new state machine in this series, I may be able to just drop this patch.
Quoted 16 lines
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3022
Quoted 12 lines
fs/xfs/libxfs/xfs_attr_leaf.c +10
-0Note that they could be +* in different blocks, or in the same block. This function can be used to +* check if xfs_attr3_leaf_flipflags has already been called. The INCOMPLETE +* flag is used during attr rename operations to mark entries that are being +* renamed. Since renames should be atomic, only one of them should appear as a +* completed attribute. +* +* isflipped is set to true if flags are flipped or false otherwise +*/ +int +xfs_attr3_leaf_flagsflipped(I don't like "flagsflipped" because it's not clear to me what "flipped" means.
Quoted 2 lines
xfs_attr3_leaf_rename_is_incomplete()?
Sure, if I keep this patch in the set I will update it. Things are still pretty wiggly, so i may still find a use for it, but hopefully I can let it go.
Quoted 21 lines
Quoted 21 lines
fs/xfs/libxfs/xfs_attr_leaf.c +21
-0+struct xfs_da_args *args, + bool *isflipped) +{ + struct xfs_attr_leafblock *leaf1; +struct xfs_attr_leafblock *leaf2; +struct xfs_attr_leaf_entry *entry1; +struct xfs_attr_leaf_entry *entry2; +struct xfs_buf *bp1; +struct xfs_buf *bp2; +struct xfs_inode *dp = args->dp; +int error =0 ; + +/* +* Read the block containing the "old" attr +*/ + error =xfs_attr3_leaf_read (args->trans, dp, args->blkno, +XFS_DABUF_MAP_NOMAPPING , &bp1); +if (error) +return error; + +/*
Quoted 8 lines
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3049
Quoted 6 lines
fs/xfs/libxfs/xfs_attr_leaf.c +6
-0+* Read the block containing the "new" attr, if it is different +*/ +if (args->blkno2 != args->blkno) { + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno2, +-1 , &bp2); +if (error)bp1 leaks here, I think.
ok, will make a note.
Quoted 17 lines
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3061
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_leaf.c +12
-0+return error; + }else { + bp2 = bp1; + } + + leaf1 = bp1->b_addr; + entry1 = &xfs_attr3_leaf_entryp (leaf1)[args->index]; + + leaf2 = bp2->b_addr; + entry2 = &xfs_attr3_leaf_entryp (leaf2)[args->index2]; + + *isflipped = (((entry1->flags & XFS_ATTR_INCOMPLETE) == 0) &&Nit: ((
entry1->flags&XFS_ATTR_INCOMPLETE) == 0) could be written as !(entry1->flags &XFS_ATTR_INCOMPLETE)
Quoted 6 lines
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 3065
Quoted 4 lines
fs/xfs/libxfs/xfs_attr_leaf.c +4
-0+ (entry2->flags & XFS_ATTR_INCOMPLETE)); + +xfs_trans_brelse (args->trans, bp1); +xfs_trans_brelse (args->trans, bp2);This double-frees bp2 if bp1 == bp2.
Ok, will fix if needed. Thanks for the review! Sorry for the stray patch!
Allison
Quoted 24 lines
--D
Quoted 20 lines
fs/xfs/libxfs/xfs_attr_leaf.c +3
-0+ +return 0 ; +}fs/xfs/libxfs/xfs_attr_leaf.h +2
-0@@ -57,7 +57,9 @@ int xfs_attr3_leaf_to_shortform(struct xfs_buf *bp, struct xfs_da_args *args, int forkoff);int xfs_attr3_leaf_clearflag (struct xfs_da_args *args);int xfs_attr3_leaf_setflag (struct xfs_da_args *args); +int xfs_attr3_leaf_flag_is_set (struct xfs_da_args *args,bool *isset);int xfs_attr3_leaf_flipflags (struct xfs_da_args *args); +int xfs_attr3_leaf_flagsflipped (struct xfs_da_args *args,bool *isflipped);/* * Routines used for growing the Btree. Signature · 1 line
2.7.4
PATCH v4 12/17 xfs: Factor out xfs_attr_rmtval_invalidate
In reply to Allison CollinsBecause new delayed attribute routines cannot roll transactions, we carve off the parts of xfs_attr_rmtval_remove that we can use. This will help to reduce repetitive code later when we introduce delayed attributes.
--- fs/xfs/libxfs/xfs_attr_remote.c | 30 +++++++++++++++++++++--------- fs/xfs/libxfs/xfs_attr_remote.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_attr_remote.c +21 -9
@@ -588,21 +588,14 @@ xfs_attr_rmtval_set_value(return 0 ; } -/* -* Remove the value associated with an attribute by deleting the -* out-of-line buffer that it is stored on. -*/ int -xfs_attr_rmtval_remove ( +xfs_attr_rmtval_invalidate (struct xfs_da_args *args) {struct xfs_mount *mp = args->dp->i_mount;xfs_dablk_t lblkno;int blkcnt;int error; -int done; - -trace_xfs_attr_rmtval_remove (args);/* * Roll through the "value", invalidating the attribute value's blocks.
@@ -644,13 +637,32 @@ xfs_attr_rmtval_remove( lblkno += map.br_blockcount; blkcnt -= map.br_blockcount; } +return 0 ; +} +/* +* Remove the value associated with an attribute by deleting the +* out-of-line buffer that it is stored on. +*/ +int +xfs_attr_rmtval_remove ( +struct xfs_da_args *args) +{ +xfs_dablk_t lblkno; +int blkcnt; +int error =0 ; +int done =0 ; + +trace_xfs_attr_rmtval_remove (args); + + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error;/* * Keep de-allocating extents until the remote-value region is gone. */ lblkno = args->rmtblkno; blkcnt = args->rmtblkcnt; - done =0 ;while (!done) { error =xfs_bunmapi (args->trans, args->dp, lblkno, blkcnt,XFS_BMAPI_ATTRFORK ,1 , &done);
fs/xfs/libxfs/xfs_attr_remote.h +1 -0
@@ -11,6 +11,7 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args);int xfs_attr_rmtval_remove (struct xfs_da_args *args); +int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int xfs_attr_rmtval_set_value (struct xfs_da_args *args);int xfs_attr_rmt_find_hole (struct xfs_da_args *args);#endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
Re: [PATCH v4 12/17] xfs: Factor out xfs_attr_rmtval_invalidate
Quoted 5 lines · Allison Collins
Because new delayed attribute routines cannot roll transactions, we carve off the parts of
xfs_attr_rmtval_removethat we can use. This will help to reduce repetitive code later when we introduce delayed attributes.
Looks good.
--D
Quoted 83 lines
Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr_remote.c | 30 +++++++++++++++++++++--------- fs/xfs/libxfs/xfs_attr_remote.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_attr_remote.c +21
-9@@ -588,21 +588,14 @@ xfs_attr_rmtval_set_value(return 0 ; } -/* -* Remove the value associated with an attribute by deleting the -* out-of-line buffer that it is stored on. -*/ int -xfs_attr_rmtval_remove ( +xfs_attr_rmtval_invalidate (struct xfs_da_args *args) {struct xfs_mount *mp = args->dp->i_mount;xfs_dablk_t lblkno;int blkcnt;int error; -int done; - -trace_xfs_attr_rmtval_remove (args);/* * Roll through the "value", invalidating the attribute value's blocks. @@ -644,13 +637,32 @@ xfs_attr_rmtval_remove( lblkno += map.br_blockcount; blkcnt -= map.br_blockcount; } +return 0 ; +} +/* +* Remove the value associated with an attribute by deleting the +* out-of-line buffer that it is stored on. +*/ +int +xfs_attr_rmtval_remove ( +struct xfs_da_args *args) +{ +xfs_dablk_t lblkno; +int blkcnt; +int error =0 ; +int done =0 ; + +trace_xfs_attr_rmtval_remove (args); + + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error;/* * Keep de-allocating extents until the remote-value region is gone. */ lblkno = args->rmtblkno; blkcnt = args->rmtblkcnt; - done =0 ;while (!done) { error =xfs_bunmapi (args->trans, args->dp, lblkno, blkcnt,XFS_BMAPI_ATTRFORK ,1 , &done);fs/xfs/libxfs/xfs_attr_remote.h +1
-0@@ -11,6 +11,7 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args);int xfs_attr_rmtval_remove (struct xfs_da_args *args); +int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int xfs_attr_rmtval_set_value (struct xfs_da_args *args);int xfs_attr_rmt_find_hole (struct xfs_da_args *args);#endif /* __XFS_ATTR_REMOTE_H__ */ Signature · 1 line
2.7.4
Re: [PATCH v4 12/17] xfs: Factor out xfs_attr_rmtval_invalidate
Quoted 11 lines · Darrick J. Wong
Quoted 5 lines · Allison Collins
Because new delayed attribute routines cannot roll transactions, we carve off the parts of
xfs_attr_rmtval_removethat we can use. This will help to reduce repetitive code later when we introduce delayed attributes.Looks good.
Reviewed-by Darrick J. Wong <[email protected]>--D
Ok, thank you!
Allison
Quoted 85 lines
Quoted 85 lines
Signed-off-by Allison Collins <[email protected]>Reviewed-by Brian Foster <[email protected]>--- fs/xfs/libxfs/xfs_attr_remote.c | 30 +++++++++++++++++++++--------- fs/xfs/libxfs/xfs_attr_remote.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_attr_remote.c +21
-9@@ -588,21 +588,14 @@ xfs_attr_rmtval_set_value(return 0 ; } -/* -* Remove the value associated with an attribute by deleting the -* out-of-line buffer that it is stored on. -*/ int -xfs_attr_rmtval_remove ( +xfs_attr_rmtval_invalidate (struct xfs_da_args *args) {struct xfs_mount *mp = args->dp->i_mount;xfs_dablk_t lblkno;int blkcnt;int error; -int done; - -trace_xfs_attr_rmtval_remove (args);/* * Roll through the "value", invalidating the attribute value's blocks. @@ -644,13 +637,32 @@ xfs_attr_rmtval_remove( lblkno += map.br_blockcount; blkcnt -= map.br_blockcount; } +return 0 ; +} +/* +* Remove the value associated with an attribute by deleting the +* out-of-line buffer that it is stored on. +*/ +int +xfs_attr_rmtval_remove ( +struct xfs_da_args *args) +{ +xfs_dablk_t lblkno; +int blkcnt; +int error =0 ; +int done =0 ; + +trace_xfs_attr_rmtval_remove (args); + + error =xfs_attr_rmtval_invalidate (args); +if (error) +return error;/* * Keep de-allocating extents until the remote-value region is gone. */ lblkno = args->rmtblkno; blkcnt = args->rmtblkcnt; - done =0 ;while (!done) { error =xfs_bunmapi (args->trans, args->dp, lblkno, blkcnt,XFS_BMAPI_ATTRFORK ,1 , &done);fs/xfs/libxfs/xfs_attr_remote.h +1
-0@@ -11,6 +11,7 @@ int xfs_attr3_rmt_blocks(struct xfs_mount *mp, int attrlen);int xfs_attr_rmtval_get (struct xfs_da_args *args);int xfs_attr_rmtval_set (struct xfs_da_args *args);int xfs_attr_rmtval_remove (struct xfs_da_args *args); +int xfs_attr_rmtval_invalidate (struct xfs_da_args *args);int xfs_attr_rmtval_set_value (struct xfs_da_args *args);int xfs_attr_rmt_find_hole (struct xfs_da_args *args);#endif /* __XFS_ATTR_REMOTE_H__ */ Signature · 1 line
2.7.4
PATCH v4 13/17 xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
In reply to Allison CollinsNew delayed allocation routines cannot be handling transactions so factor them up into the calling functions
--- fs/xfs/libxfs/xfs_attr.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-)
fs/xfs/libxfs/xfs_attr.c +16 -0
@@ -797,6 +797,14 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)* Added a "remote" value, just clear the incomplete flag. */ error =xfs_attr3_leaf_clearflag (args); +if (error) +return error; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); }return error; }
@@ -1154,6 +1162,14 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_clearflag (args);if (error) goto out; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; } retval = error =0 ;
fs/xfs/libxfs/xfs_attr_leaf.c +1 -4
@@ -2802,10 +2802,7 @@ xfs_attr3_leaf_clearflag( XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ -return xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/*
Signature · 1 line
2.7.4
Re: [PATCH v4 13/17] xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
Quoted 4 lines · Allison Collins
New delayed allocation routines cannot be handling transactions so factor them up into the calling functions
Signed-off-by Allison Collins <[email protected]>
Looks pretty straightforward,
--D
Quoted 58 lines
--- fs/xfs/libxfs/xfs_attr.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-0@@ -797,6 +797,14 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)* Added a "remote" value, just clear the incomplete flag. */ error =xfs_attr3_leaf_clearflag (args); +if (error) +return error; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); }return error; }@@ -1154,6 +1162,14 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_clearflag (args);if (error) goto out; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; } retval = error =0 ;fs/xfs/libxfs/xfs_attr_leaf.c +1
-4@@ -2802,10 +2802,7 @@ xfs_attr3_leaf_clearflag( XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ -return xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/* Signature · 1 line
2.7.4
Re: [PATCH v4 13/17] xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
Quoted 11 lines · Darrick J. Wong
Quoted 4 lines · Allison Collins
New delayed allocation routines cannot be handling transactions so factor them up into the calling functions
Signed-off-by Allison Collins <[email protected]>Looks pretty straightforward,
Reviewed-by Darrick J. Wong <[email protected]>--D
Thanks!
Allison
Quoted 59 lines
Quoted 59 lines
--- fs/xfs/libxfs/xfs_attr.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-0@@ -797,6 +797,14 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)* Added a "remote" value, just clear the incomplete flag. */ error =xfs_attr3_leaf_clearflag (args); +if (error) +return error; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); }return error; }@@ -1154,6 +1162,14 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_clearflag (args);if (error) goto out; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; } retval = error =0 ;fs/xfs/libxfs/xfs_attr_leaf.c +1
-4@@ -2802,10 +2802,7 @@ xfs_attr3_leaf_clearflag( XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ -return xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/* Signature · 1 line
2.7.4
Re: [PATCH v4 13/17] xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
In reply to Allison CollinsQuoted 5 lines · Allison Collins
New delayed allocation routines cannot be handling transactions so factor them up into the calling functions
Signed-off-by Allison Collins <[email protected]>---
Quoted 57 lines
fs/xfs/libxfs/xfs_attr.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-0@@ -797,6 +797,14 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)* Added a "remote" value, just clear the incomplete flag. */ error =xfs_attr3_leaf_clearflag (args); +if (error) +return error; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); }return error; }@@ -1154,6 +1162,14 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_clearflag (args);if (error) goto out; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; } retval = error =0 ;fs/xfs/libxfs/xfs_attr_leaf.c +1
-4@@ -2802,10 +2802,7 @@ xfs_attr3_leaf_clearflag( XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ -return xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/* Signature · 1 line
2.7.4
Re: [PATCH v4 13/17] xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
Quoted 8 lines · Brian Foster
Quoted 5 lines · Allison Collins
New delayed allocation routines cannot be handling transactions so factor them up into the calling functions
Signed-off-by Allison Collins <[email protected]>---
Reviewed-by Brian Foster <[email protected]>
Thank you!
Allison
Quoted 59 lines
Quoted 58 lines
fs/xfs/libxfs/xfs_attr.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 5 +---- 2 files changed, 17 insertions(+), 4 deletions(-)fs/xfs/libxfs/xfs_attr.c +16
-0@@ -797,6 +797,14 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)* Added a "remote" value, just clear the incomplete flag. */ error =xfs_attr3_leaf_clearflag (args); +if (error) +return error; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); }return error; }@@ -1154,6 +1162,14 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_clearflag (args);if (error) goto out; + +/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp); +if (error) + goto out; } retval = error =0 ;fs/xfs/libxfs/xfs_attr_leaf.c +1
-4@@ -2802,10 +2802,7 @@ xfs_attr3_leaf_clearflag( XFS_DA_LOGRANGE(leaf, name_rmt, sizeof(*name_rmt))); } -/* -* Commit the flag value change and start the next trans in series. -*/ -return xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/* Signature · 1 line
2.7.4
PATCH v4 14/17 xfs: Add delay context to xfs_da_args
In reply to Allison CollinsThis patch adds a new struct xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.
The new enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.
--- fs/xfs/libxfs/xfs_da_btree.h | 28 ++++++++++++++++++++++++++++ fs/xfs/scrub/common.c | 2 ++ fs/xfs/xfs_acl.c | 2 ++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ fs/xfs/xfs_iops.c | 2 ++ fs/xfs/xfs_xattr.c | 1 + 8 files changed, 40 insertions(+)
fs/xfs/libxfs/xfs_da_btree.h +28 -0
@@ -42,6 +42,33 @@ enum xfs_dacmp { XFS_CMP_CASE /* names are same but differ in case */ }; +enum xfs_attr_state { +XFS_DC_INIT =1 ,/* Init delay info */ +XFS_DC_SF_TO_LEAF =2 ,/* Converted short form to leaf */ +XFS_DC_FOUND_LBLK =3 ,/* We found leaf blk for attr */ +XFS_DC_LEAF_TO_NODE =4 ,/* Converted leaf to node */ +XFS_DC_FOUND_NBLK =5 ,/* We found node blk for attr */ +XFS_DC_ALLOC_LEAF =6 ,/* We are allocating leaf blocks */ +XFS_DC_ALLOC_NODE =7 ,/* We are allocating node blocks */ +XFS_DC_RM_INVALIDATE =8 ,/* We are invalidating blocks */ +XFS_DC_RM_SHRINK =9 ,/* We are shrinking the tree */ +XFS_DC_RM_NODE_BLKS =10 ,/* We are removing node blocks */ +}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delay_context { +enum xfs_attr_state dc_state; +struct xfs_buf *leaf_bp; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +xfs_fileoff_t lfileoff; +int blkcnt; +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +}; +/* * Structure to ease passing around component names. */
@@ -69,6 +96,7 @@ typedef struct xfs_da_args {int rmtvaluelen2;/* remote attr value length in bytes */ int op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ +struct xfs_delay_context dc;/* context used for delay attr ops */ } xfs_da_args_t;/*
fs/xfs/scrub/common.c +2 -0
@@ -24,6 +24,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 "scrub/scrub.h"
fs/xfs/xfs_acl.c +2 -0
@@ -10,6 +10,8 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include <linux/posix_acl_xattr.h>
fs/xfs/xfs_attr_list.c +1 -0
@@ -12,6 +12,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h"
fs/xfs/xfs_ioctl.c +2 -0
@@ -15,6 +15,8 @@#include "xfs_iwalk.h" #include "xfs_itable.h" #include "xfs_error.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_bmap.h" #include "xfs_bmap_util.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_xattr.c +1 -0
@@ -10,6 +10,7 @@#include "xfs_log_format.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include <linux/posix_acl_xattr.h>
Signature · 1 line
2.7.4
Re: [PATCH v4 14/17] xfs: Add delay context to xfs_da_args
Quoted 28 lines · Allison Collins
This patch adds a new struct
xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.The new enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_da_btree.h | 28 ++++++++++++++++++++++++++++ fs/xfs/scrub/common.c | 2 ++ fs/xfs/xfs_acl.c | 2 ++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ fs/xfs/xfs_iops.c | 2 ++ fs/xfs/xfs_xattr.c | 1 + 8 files changed, 40 insertions(+)fs/xfs/libxfs/xfs_da_btree.h +0
-0
fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 45
Quoted 4 lines
fs/xfs/libxfs/xfs_da_btree.h +1
-0@@ -42,6 +42,33 @@ enum xfs_dacmp {XFS_CMP_CASE /* names are same but differ in case */ }; +enum xfs_attr_state {
enum xfs_dc_state ?
Hm, "dc" seems a little short.
enum xfs_delattr_state?
Quoted 6 lines
fs/xfs/libxfs/xfs_da_btree.h +6
-0+XFS_DC_INIT =1 ,/* Init delay info */ +XFS_DC_SF_TO_LEAF =2 ,/* Converted short form to leaf */ +XFS_DC_FOUND_LBLK =3 ,/* We found leaf blk for attr */ +XFS_DC_LEAF_TO_NODE =4 ,/* Converted leaf to node */ +XFS_DC_FOUND_NBLK =5 ,/* We found node blk for attr */ + XFS_DC_ALLOC_LEAF = 6, /* We are allocating leaf blocks */
fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 61
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.h +10
-0+XFS_DC_ALLOC_NODE =7 ,/* We are allocating node blocks */ +XFS_DC_RM_INVALIDATE =8 ,/* We are invalidating blocks */ +XFS_DC_RM_SHRINK =9 ,/* We are shrinking the tree */ + XFS_DC_RM_NODE_BLKS = 10,/* We are removing node blocks */ +}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delay_context {
struct xfs_delattr_context ?
fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 70
Quoted 9 lines
fs/xfs/libxfs/xfs_da_btree.h +9
-0+enum xfs_attr_state dc_state; +struct xfs_buf *leaf_bp; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +xfs_fileoff_t lfileoff; +int blkcnt; +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +};
Would be kinda nice to keep this structure size to a minimum by reordering these in order of decreasing size. pahole is your friend for doing that (or shouting me down). ;)
But otherwise this seems ok.
--D
Quoted 104 lines
fs/xfs/libxfs/xfs_da_btree.h +2
-0+/* * Structure to ease passing around component names. */ @@ -69,6 +96,7 @@ typedef struct xfs_da_args {int rmtvaluelen2;/* remote attr value length in bytes */ int op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ +struct xfs_delay_context dc;/* context used for delay attr ops */ } xfs_da_args_t;/* fs/xfs/scrub/common.c +2
-0@@ -24,6 +24,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 "scrub/scrub.h" fs/xfs/xfs_acl.c +2
-0@@ -10,6 +10,8 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include <linux/posix_acl_xattr.h> fs/xfs/xfs_attr_list.c +1
-0@@ -12,6 +12,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h" fs/xfs/xfs_ioctl.c +2
-0@@ -15,6 +15,8 @@#include "xfs_iwalk.h" #include "xfs_itable.h" #include "xfs_error.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_bmap.h" #include "xfs_bmap_util.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_xattr.c +1
-0@@ -10,6 +10,7 @@#include "xfs_log_format.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include <linux/posix_acl_xattr.h> Signature · 1 line
2.7.4
Re: [PATCH v4 14/17] xfs: Add delay context to xfs_da_args
Quoted 32 lines · Darrick J. Wong
Quoted 31 lines · Allison Collins
This patch adds a new struct
xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.The new enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_da_btree.h | 28 ++++++++++++++++++++++++++++ fs/xfs/scrub/common.c | 2 ++ fs/xfs/xfs_acl.c | 2 ++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ fs/xfs/xfs_iops.c | 2 ++ fs/xfs/xfs_xattr.c | 1 + 8 files changed, 40 insertions(+)fs/xfs/libxfs/xfs_da_btree.h +0
-0@@ -42,6 +42,33 @@ enum xfs_dacmp { XFS_CMP_CASE /* names are same but differ in case */ };
Quoted 8 lines
fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 45
Quoted 1 line
fs/xfs/libxfs/xfs_da_btree.h +1
-0+enum xfs_attr_state {enum
xfs_dc_state?Hm, "dc" seems a little short.
enum
xfs_delattr_state?
Sure. Maybe instead of XFS_DC_* we could do XFS_DAS_*?
Quoted 10 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.h +10
-0+XFS_DC_INIT =1 ,/* Init delay info */ +XFS_DC_SF_TO_LEAF =2 ,/* Converted short form to leaf */ +XFS_DC_FOUND_LBLK =3 ,/* We found leaf blk for attr */ +XFS_DC_LEAF_TO_NODE =4 ,/* Converted leaf to node */ +XFS_DC_FOUND_NBLK =5 ,/* We found node blk for attr */ +XFS_DC_ALLOC_LEAF =6 ,/* We are allocating leaf blocks */ +XFS_DC_ALLOC_NODE =7 ,/* We are allocating node blocks */ +XFS_DC_RM_INVALIDATE =8 ,/* We are invalidating blocks */ +XFS_DC_RM_SHRINK =9 ,/* We are shrinking the tree */ + XFS_DC_RM_NODE_BLKS = 10,/* We are removing node blocks */
Quoted 8 lines
fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 61
Quoted 6 lines
fs/xfs/libxfs/xfs_da_btree.h +6
-0+}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delay_context {struct
xfs_delattr_context?
Sure, I'm not too particular on the names.
Quoted 15 lines
fs/xfs/libxfs/xfs_da_btree.h enum xfs_dacmp { · line 70
Quoted 10 lines
fs/xfs/libxfs/xfs_da_btree.h +9
-0+enum xfs_attr_state dc_state; +struct xfs_buf *leaf_bp; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +xfs_fileoff_t lfileoff; +int blkcnt; +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +};Would be kinda nice to keep this structure size to a minimum by reordering these in order of decreasing size. pahole is your friend for doing that (or shouting me down). ;)
Ok, I'll check that. Thanks for the review!
Allison
Quoted 108 lines
But otherwise this seems ok.
--D
Quoted 104 lines
fs/xfs/libxfs/xfs_da_btree.h +2
-0+/* * Structure to ease passing around component names. */ @@ -69,6 +96,7 @@ typedef struct xfs_da_args {int rmtvaluelen2;/* remote attr value length in bytes */ int op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ +struct xfs_delay_context dc;/* context used for delay attr ops */ } xfs_da_args_t;/* fs/xfs/scrub/common.c +2
-0@@ -24,6 +24,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 "scrub/scrub.h" fs/xfs/xfs_acl.c +2
-0@@ -10,6 +10,8 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include <linux/posix_acl_xattr.h> fs/xfs/xfs_attr_list.c +1
-0@@ -12,6 +12,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h" fs/xfs/xfs_ioctl.c +2
-0@@ -15,6 +15,8 @@#include "xfs_iwalk.h" #include "xfs_itable.h" #include "xfs_error.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_bmap.h" #include "xfs_bmap_util.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_xattr.c +1
-0@@ -10,6 +10,7 @@#include "xfs_log_format.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include <linux/posix_acl_xattr.h> Signature · 1 line
2.7.4
Re: [PATCH v4 14/17] xfs: Add delay context to xfs_da_args
In reply to Allison CollinsQuoted 4 lines · Allison Collins
This patch adds a new struct
xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.
Technically, this should track delayed or non-delayed attr operations, right? IIRC, the goal is that the difference between the two is that the former is driven by the dfops mechanism while the latter executes the same code with a higher level hack to roll transactions and loop through the state machine...
Brian
Quoted 157 lines
The new enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_da_btree.h | 28 ++++++++++++++++++++++++++++ fs/xfs/scrub/common.c | 2 ++ fs/xfs/xfs_acl.c | 2 ++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ fs/xfs/xfs_iops.c | 2 ++ fs/xfs/xfs_xattr.c | 1 + 8 files changed, 40 insertions(+)fs/xfs/libxfs/xfs_da_btree.h +28
-0@@ -42,6 +42,33 @@ enum xfs_dacmp { XFS_CMP_CASE /* names are same but differ in case */ }; +enum xfs_attr_state { +XFS_DC_INIT =1 ,/* Init delay info */ +XFS_DC_SF_TO_LEAF =2 ,/* Converted short form to leaf */ +XFS_DC_FOUND_LBLK =3 ,/* We found leaf blk for attr */ +XFS_DC_LEAF_TO_NODE =4 ,/* Converted leaf to node */ +XFS_DC_FOUND_NBLK =5 ,/* We found node blk for attr */ +XFS_DC_ALLOC_LEAF =6 ,/* We are allocating leaf blocks */ +XFS_DC_ALLOC_NODE =7 ,/* We are allocating node blocks */ +XFS_DC_RM_INVALIDATE =8 ,/* We are invalidating blocks */ +XFS_DC_RM_SHRINK =9 ,/* We are shrinking the tree */ +XFS_DC_RM_NODE_BLKS =10 ,/* We are removing node blocks */ +}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delay_context { +enum xfs_attr_state dc_state; +struct xfs_buf *leaf_bp; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +xfs_fileoff_t lfileoff; +int blkcnt; +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +}; +/* * Structure to ease passing around component names. */ @@ -69,6 +96,7 @@ typedef struct xfs_da_args {int rmtvaluelen2;/* remote attr value length in bytes */ int op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ +struct xfs_delay_context dc;/* context used for delay attr ops */ } xfs_da_args_t;/* fs/xfs/scrub/common.c +2
-0@@ -24,6 +24,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 "scrub/scrub.h" fs/xfs/xfs_acl.c +2
-0@@ -10,6 +10,8 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include <linux/posix_acl_xattr.h> fs/xfs/xfs_attr_list.c +1
-0@@ -12,6 +12,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h" fs/xfs/xfs_ioctl.c +2
-0@@ -15,6 +15,8 @@#include "xfs_iwalk.h" #include "xfs_itable.h" #include "xfs_error.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_bmap.h" #include "xfs_bmap_util.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_xattr.c +1
-0@@ -10,6 +10,7 @@#include "xfs_log_format.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include <linux/posix_acl_xattr.h> Signature · 1 line
2.7.4
Re: [PATCH v4 14/17] xfs: Add delay context to xfs_da_args
Quoted 6 lines · Brian Foster
Quoted 4 lines · Allison Collins
This patch adds a new struct
xfs_delay_context, which we will use to keep track of the current state of a delayed attribute operation.
Quoted 7 lines
Technically, this should track delayed or non-delayed attr operations, right? IIRC, the goal is that the difference between the two is that the former is driven by the dfops mechanism while the latter executes the same code with a higher level hack to roll transactions and loop through the state machine...
Brian
Yep, I will update the commit message. Thanks!
Allison
Quoted 159 lines
Quoted 158 lines
The new enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_da_btree.h | 28 ++++++++++++++++++++++++++++ fs/xfs/scrub/common.c | 2 ++ fs/xfs/xfs_acl.c | 2 ++ fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ fs/xfs/xfs_iops.c | 2 ++ fs/xfs/xfs_xattr.c | 1 + 8 files changed, 40 insertions(+)fs/xfs/libxfs/xfs_da_btree.h +28
-0@@ -42,6 +42,33 @@ enum xfs_dacmp { XFS_CMP_CASE /* names are same but differ in case */ }; +enum xfs_attr_state { +XFS_DC_INIT =1 ,/* Init delay info */ +XFS_DC_SF_TO_LEAF =2 ,/* Converted short form to leaf */ +XFS_DC_FOUND_LBLK =3 ,/* We found leaf blk for attr */ +XFS_DC_LEAF_TO_NODE =4 ,/* Converted leaf to node */ +XFS_DC_FOUND_NBLK =5 ,/* We found node blk for attr */ +XFS_DC_ALLOC_LEAF =6 ,/* We are allocating leaf blocks */ +XFS_DC_ALLOC_NODE =7 ,/* We are allocating node blocks */ +XFS_DC_RM_INVALIDATE =8 ,/* We are invalidating blocks */ +XFS_DC_RM_SHRINK =9 ,/* We are shrinking the tree */ +XFS_DC_RM_NODE_BLKS =10 ,/* We are removing node blocks */ +}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delay_context { +enum xfs_attr_state dc_state; +struct xfs_buf *leaf_bp; +struct xfs_bmbt_irec map; +xfs_dablk_t lblkno; +xfs_fileoff_t lfileoff; +int blkcnt; +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +}; +/* * Structure to ease passing around component names. */ @@ -69,6 +96,7 @@ typedef struct xfs_da_args {int rmtvaluelen2;/* remote attr value length in bytes */ int op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ +struct xfs_delay_context dc;/* context used for delay attr ops */ } xfs_da_args_t;/* fs/xfs/scrub/common.c +2
-0@@ -24,6 +24,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 "scrub/scrub.h" fs/xfs/xfs_acl.c +2
-0@@ -10,6 +10,8 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_inode.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include <linux/posix_acl_xattr.h> fs/xfs/xfs_attr_list.c +1
-0@@ -12,6 +12,7 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_bmap.h" fs/xfs/xfs_ioctl.c +2
-0@@ -15,6 +15,8 @@#include "xfs_iwalk.h" #include "xfs_itable.h" #include "xfs_error.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_bmap.h" #include "xfs_bmap_util.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_xattr.c +1
-0@@ -10,6 +10,7 @@#include "xfs_log_format.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include <linux/posix_acl_xattr.h> Signature · 1 line
2.7.4
PATCH v4 15/17 xfs: Check for -ENOATTR or -EEXIST
In reply to Allison CollinsDelayed operations cannot return error codes. So we must check for these conditions first before starting set or remove operations
--- fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
fs/xfs/libxfs/xfs_attr.c +25 -0
@@ -458,6 +458,27 @@ xfs_attr_set( goto out_trans_cancel;xfs_trans_ijoin (args.trans, dp,0 ); + + error =xfs_has_attr (&args); +if (error == -EEXIST ) { +if (name->type &ATTR_CREATE ) + goto out_trans_cancel; +else + name->type |=ATTR_REPLACE ; + } + +if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel; + +if (name->type &ATTR_REPLACE ) { + name->type &= ~ATTR_REPLACE ; + error =xfs_attr_remove_args (&args); +if (error) + goto out_trans_cancel; + + name->type |=ATTR_CREATE ; + } + error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;
@@ -543,6 +564,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error == -ENOATTR ) + goto out; + error =xfs_attr_remove_args (&args);if (error) goto out;
Signature · 1 line
2.7.4
Re: [PATCH v4 15/17] xfs: Check for -ENOATTR or -EEXIST
Quoted 25 lines · Allison Collins
Delayed operations cannot return error codes. So we must check for these conditions first before starting set or remove operations
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)fs/xfs/libxfs/xfs_attr.c +9
-0@@ -458,6 +458,27 @@ xfs_attr_set( goto out_trans_cancel;xfs_trans_ijoin (args.trans, dp,0 ); + + error =xfs_has_attr (&args); +if (error == -EEXIST ) { +if (name->type &ATTR_CREATE ) + goto out_trans_cancel; +else + name->type |=ATTR_REPLACE ; + } +
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 479
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel; + +if (name->type &ATTR_REPLACE ) { + name->type &= ~ATTR_REPLACE ; + error =xfs_attr_remove_args (&args); +if (error) + goto out_trans_cancel; + + name->type |=ATTR_CREATE ;
I thought _set_args already handled the remove part of replacing an attr? And I thought that it did this with an atomic rename? Won't this break the atomicity of attr replacement?
--D
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+ } + error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;@@ -543,6 +564,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error == -ENOATTR ) + goto out; + error =xfs_attr_remove_args (&args);if (error) goto out;Signature · 1 line
2.7.4
Re: [PATCH v4 15/17] xfs: Check for -ENOATTR or -EEXIST
Quoted 31 lines · Darrick J. Wong
Quoted 30 lines · Allison Collins
Delayed operations cannot return error codes. So we must check for these conditions first before starting set or remove operations
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)fs/xfs/libxfs/xfs_attr.c +14
-0@@ -458,6 +458,27 @@ xfs_attr_set( goto out_trans_cancel;xfs_trans_ijoin (args.trans, dp,0 ); + + error =xfs_has_attr (&args); +if (error == -EEXIST ) { +if (name->type &ATTR_CREATE ) + goto out_trans_cancel; +else + name->type |=ATTR_REPLACE ; + } + +if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel; + +if (name->type &ATTR_REPLACE ) { + name->type &= ~ATTR_REPLACE ;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 479
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+ error =xfs_attr_remove_args (&args); +if (error) + goto out_trans_cancel; + + name->type |=ATTR_CREATE ;I thought
_set_argsalready handled the remove part of replacing an attr?
No, IIRC in one of the other reviews we decided to break the rename into a set and then a remove. That way the error handling moves up here instead of trying to deal with it in the middle of the delayed operation
And I thought that it did this with an atomic rename? Won't this
Quoted 1 line
break the atomicity of attr replacement?
Hmm, think this worked for delayed operations, but not anymore since we're going back to supporting both delayed and inline in one code path.
I think what this means is that the flip flag has to get moved in
here, right? We flip on the incomplete flag before the remove and then set it when the rename is done?
Quoted 22 lines
--D
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+ } + error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;@@ -543,6 +564,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error == -ENOATTR ) + goto out; + error =xfs_attr_remove_args (&args);if (error) goto out;Signature · 1 line
2.7.4
Re: [PATCH v4 15/17] xfs: Check for -ENOATTR or -EEXIST
Quoted 39 lines · Allison Collins
Quoted 30 lines · Darrick J. Wong
Quoted 29 lines · Allison Collins
Delayed operations cannot return error codes. So we must check for these conditions first before starting set or remove operations
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)fs/xfs/libxfs/xfs_attr.c +14
-0@@ -458,6 +458,27 @@ xfs_attr_set( goto out_trans_cancel;xfs_trans_ijoin (args.trans, dp,0 ); + + error =xfs_has_attr (&args); +if (error == -EEXIST ) { +if (name->type &ATTR_CREATE ) + goto out_trans_cancel; +else + name->type |=ATTR_REPLACE ; + } + +if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel; + +if (name->type &ATTR_REPLACE ) { + name->type &= ~ATTR_REPLACE ;Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 479
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+ error =xfs_attr_remove_args (&args); +if (error) + goto out_trans_cancel; + + name->type |=ATTR_CREATE ;I thought
_set_argsalready handled the remove part of replacing an attr?
Quoted 2 lines
No, IIRC in one of the other reviews we decided to break the rename into a set and then a remove.
But this looks like we remove the old attr before setting the new one, which means that if we crash right here we'll come back up with no attr at all. The INCOMPLETE flag flipping trick only works for ATTR_REPLACE if you add the new attr before removing the old one.
(Or am I misreading something here?)
Quoted 2 lines
That way the error handling moves up here instead of trying to deal with it in the middle of the delayed operation
Sounds good.
Quoted 8 lines
Quoted 2 lines
And I thought that it did this with an atomic rename? Won't this break the atomicity of attr replacement?
Hmm, think this worked for delayed operations, but not anymore since we're going back to supporting both delayed and inline in one code path. I think what this means is that the flip flag has to get moved in here, right? We flip on the incomplete flag before the remove and then set it when the rename is done?
Yeah.
--D
Quoted 22 lines
Quoted 22 lines
--D
Quoted 18 lines
fs/xfs/libxfs/xfs_attr.c +6
-0+ } + error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;@@ -543,6 +564,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error == -ENOATTR ) + goto out; + error =xfs_attr_remove_args (&args);if (error) goto out;Signature · 1 line
2.7.4
Re: [PATCH v4 15/17] xfs: Check for -ENOATTR or -EEXIST
In reply to Allison CollinsQuoted 27 lines · Allison Collins
Delayed operations cannot return error codes. So we must check for these conditions first before starting set or remove operations
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)fs/xfs/libxfs/xfs_attr.c +11
-0@@ -458,6 +458,27 @@ xfs_attr_set( goto out_trans_cancel;xfs_trans_ijoin (args.trans, dp,0 ); + + error =xfs_has_attr (&args); +if (error == -EEXIST ) { +if (name->type &ATTR_CREATE ) + goto out_trans_cancel; +else + name->type |=ATTR_REPLACE ; + } + +if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel;
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 481
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ +if (name->type &ATTR_REPLACE ) { + name->type &= ~ATTR_REPLACE ; + error =xfs_attr_remove_args (&args); +if (error) + goto out_trans_cancel; + + name->type |=ATTR_CREATE ; + } +
I see Darrick already commented on this.. I think the behavior of the existing rename code is to essentially create the new xattr with the INCOMPLETE flag set so we can roll transactions, etc. without any observable behavior to userspace. Once the new xattr is fully in place, the rename is performed atomically from the userspace perspective by flipping the INCOMPLETE flag from the newly constructed xattr to the old one and we can then remove the old xattr from there.
fs/xfs/libxfs/xfs_attr.c xfs_attr_remove( · line 570
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +4
-0error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;@@ -543,6 +564,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error == -ENOATTR ) + goto out; +
Wouldn't we want to return any error that might occur here (except -EEXIST), not just -ENOATTR if there's actually no xattr?
Brian
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-0error =xfs_attr_remove_args (&args);if (error) goto out;Signature · 1 line
2.7.4
Re: [PATCH v4 15/17] xfs: Check for -ENOATTR or -EEXIST
Quoted 39 lines · Brian Foster
Quoted 27 lines · Allison Collins
Delayed operations cannot return error codes. So we must check for these conditions first before starting set or remove operations
Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)fs/xfs/libxfs/xfs_attr.c +11
-0@@ -458,6 +458,27 @@ xfs_attr_set( goto out_trans_cancel;xfs_trans_ijoin (args.trans, dp,0 ); + + error =xfs_has_attr (&args); +if (error == -EEXIST ) { +if (name->type &ATTR_CREATE ) + goto out_trans_cancel; +else + name->type |=ATTR_REPLACE ; + } + +if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel;fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 481
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ +if (name->type &ATTR_REPLACE ) { + name->type &= ~ATTR_REPLACE ; + error =xfs_attr_remove_args (&args); +if (error) + goto out_trans_cancel; + + name->type |=ATTR_CREATE ; + } +
Quoted 7 lines
I see Darrick already commented on this.. I think the behavior of the existing rename code is to essentially create the new xattr with the INCOMPLETE flag set so we can roll transactions, etc. without any observable behavior to userspace. Once the new xattr is fully in place, the rename is performed atomically from the userspace perspective by flipping the INCOMPLETE flag from the newly constructed xattr to the old one and we can then remove the old xattr from there.
Yes, I will add this logic in the next revision
Quoted 16 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_remove( · line 570
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c +4
-0error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;@@ -543,6 +564,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error == -ENOATTR ) + goto out; +Wouldn't we want to return any error that might occur here (except
-EEXIST), not just-ENOATTRif there's actually no xattr?
Quoted 1 line
Brian
Ok, I will change this to (error != -EEXIST)
Thanks for the reviews!
Allison
Quoted 8 lines
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0
-0error =xfs_attr_remove_args (&args);if (error) goto out;Signature · 1 line
2.7.4
PATCH v4 16/17 xfs: Add delay ready attr remove routines
In reply to Allison CollinsThis patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_remove_args has become xfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the state machine, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed.
--- fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_attr.c +103 -20
@@ -369,10 +369,56 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( +struct xfs_da_args *args) +{ +int error =0 ; +int err2 =0 ; + +do { + error =xfs_attr_remove_later (args); +if (error && error != -EAGAIN ) + goto out; + +xfs_trans_log_inode (args->trans, args->dp, +XFS_ILOG_CORE |XFS_ILOG_ADATA ); + + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2; + goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;
@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }
@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }
@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(
@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ; + } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks.
@@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure
@@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks: +/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls
@@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */
@@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }
fs/xfs/libxfs/xfs_attr.h +1 -0
@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);
Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
Quoted 26 lines · Allison Collins
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argshas becomexfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the state machine, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)fs/xfs/libxfs/xfs_attr.c +2
-0@@ -369,10 +369,56 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( +struct xfs_da_args *args) +{
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 383
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+int error =0 ; +int err2 =0 ; + + do { + error = xfs_attr_remove_later(args); + if (error && error != -EAGAIN) + goto out; + + xfs_trans_log_inode(args->trans, args->dp, + XFS_ILOG_CORE | XFS_ILOG_ADATA);
Don't the individual pieces of attr removal log ADATA on their own, when needed?
If it weren't for that, this could just be xfs_trans_roll_inode, right?
--D
Quoted 199 lines
fs/xfs/libxfs/xfs_attr.c +91
-20+ + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2; + goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ; + } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure @@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks: +/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
Quoted 41 lines · Darrick J. Wong
Quoted 26 lines · Allison Collins
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argshas becomexfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the state machine, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)fs/xfs/libxfs/xfs_attr.c +2
-0@@ -369,10 +369,56 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( +struct xfs_da_args *args) +{fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 383
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+int error =0 ; +int err2 =0 ; + + do { + error = xfs_attr_remove_later(args); + if (error && error != -EAGAIN) + goto out; + + xfs_trans_log_inode(args->trans, args->dp, + XFS_ILOG_CORE | XFS_ILOG_ADATA);Don't the individual pieces of attr removal log ADATA on their own, when needed?
Quoted 1 line
If it weren't for that, this could just be
xfs_trans_roll_inode, right?
Oh i see. I will see if I can simplify that. Thanks! Allison
Quoted 202 lines
--D
Quoted 199 lines
fs/xfs/libxfs/xfs_attr.c +91
-20+ + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2; + goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ; + } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure @@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks: +/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
In reply to Allison CollinsQuoted 10 lines · Allison Collins
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argshas becomexfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the state machine, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.
Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>---
On a cursory look, this is definitely more along the lines of what I was thinking on the previous revisions. I would like to see if we can get a bit more refactoring/cleanup before this point though. Further thoughts inline..
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0@@ -369,10 +369,56 @@ xfs_has_attr(*/ int
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 380
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0xfs_attr_remove_args ( + struct xfs_da_args *args) +{ +int error =0 ; +int err2 =0 ; + + do { + error = xfs_attr_remove_later(args); + if (error && error != -EAGAIN) + goto out;
xfs_attr_remove_later() strikes me as an odd name with respect to the functionality. Perhaps something like xfs_attr_remove_step() is (slightly) more accurate..?
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 387
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ +xfs_trans_log_inode (args->trans, args->dp, +XFS_ILOG_CORE |XFS_ILOG_ADATA ); + + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2;
Also do we really need two error codes in this function? It seems like we should be able to write this with one, but I haven't tried it..
Quoted 78 lines
fs/xfs/libxfs/xfs_attr.c +41
-4+ goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; +
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1289
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ;
I wonder if it's worth having an explicit state for the initial path. That could be useful for readability and debuggability in the future.
Quoted 27 lines
fs/xfs/libxfs/xfs_attr.c +11
-0+ } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure @@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error)
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1338
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-1goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks:
While I think the design is the right idea, jumping down into a function like this is pretty hairy. I think we should try to further break this function down into smaller elements one way or another that model the steps defined by the state structure. There's probably multiple ways to do that. For example, the remote attr bits could be broken down into a subfunction that processes the couple of states associated with remote blocks. That said, ISTM it might be wiser to try and keep the state processing in one place if possible. That would imply to break the remote processing loop down into a couple functions. All in all, this function might end up looking something like:
xfs_attr_node_removename()
{
/* switch statement and comment to document each state */
error = xfs_attr_node_hasname(args, &state);
...
if (remote) {
error = do_setflag();
if (error)
return error;
/* roll */
state = INVALIDATE;
return -EAGAIN;
}rmt_invalidate:
state = INVALIDATE; if (remote) do_invalidate(); /* fallthru */
rmt_rm_blks:
state = RM_NODE_BLKS;
if (remote) {
/* loops and returns -EAGAIN until we fallthru */
error = rmt_remove_step();
if (error)
return error;
xfs_attr_refillstate();
}/* maybe worth a new state here? */
removename:
state = REMOVENAME;
xfs_attr3_leaf_remove();
...
if (...) {
state = SHRINK;
return -EAGAIN;
}shrink:
state = SHRINK; error = do_shrink(); return 0; }
I'm not totally sold on the idea of rolling the state forward explicitly like this, but it seems like it could be a bit more maintainable. All in all this is still fairly ugly, but this is mostly a mechanical attempt to keep state management isolated and we can polish it up from there. Thoughts?
Brian
Quoted 70 lines
fs/xfs/libxfs/xfs_attr.c +20
-15+/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
Quoted 36 lines · Brian Foster
Quoted 10 lines · Allison Collins
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argshas becomexfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the state machine, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>---
On a cursory look, this is definitely more along the lines of what I was thinking on the previous revisions. I would like to see if we can get a bit more refactoring/cleanup before this point though. Further thoughts inline..
Quoted 17 lines
fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)fs/xfs/libxfs/xfs_attr.c +5
-0@@ -369,10 +369,56 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( +struct xfs_da_args *args) +{ +int error =0 ; +int err2 =0 ; +
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 380
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ do { + error = xfs_attr_remove_later(args); + if (error && error != -EAGAIN) + goto out;
xfs_attr_remove_later()strikes me as an odd name with respect to the functionality. Perhaps something likexfs_attr_remove_step()is (slightly) more accurate..?
Sure that's fine. I think Darrick had proposed the *_later scheme in an earlier review but that was when the code paths were split. Darrick, does the *_step scheme work for you?
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 387
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ +xfs_trans_log_inode (args->trans, args->dp, +XFS_ILOG_CORE |XFS_ILOG_ADATA ); + + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2;Also do we really need two error codes in this function? It seems like we should be able to write this with one, but I haven't tried it..
No, because then we'll loose the xfs_attr_remove_later return code, which is either 0 or EAGAIN at this point. And we need that to drive the loop. To get rid of err2, we'd need another "not_done" variable or something. Like:
do {
...
not_done = (error == -EAGAIN);
...
} while (not_done)Not sure if not_done is really preferable to err2?
Quoted 84 lines
Quoted 84 lines
fs/xfs/libxfs/xfs_attr.c +46
-4+ goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE :
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1289
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+ goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ;I wonder if it's worth having an explicit state for the initial path. That could be useful for readability and debuggability in the future.
We could, it will just require to the calling function to set that before state calling it.
Mechanically, I dont think it would hurt anything, but it may lead to developer wonderments like... "Where's the EAGAIN for this state?" "Shouldnt this state appear in the switch up top too?" Or if it does "Why do we have it here, if it never executes?" "I wonder if i should sent a patch to take it out..." :-)
Puzzlement aside though, I cant quite think of what condition it would help to debug? It's not an error for the statemachine to hold a value outside of the helpers scope. It just means the caller was using it up to this point. Helpers really shouldnt have enough context about their callers to know or care what the caller states mean. If we added a special init state, all the default statement would really mean is: "The caller forgot to set the init state".
Thoughts?
Quoted 94 lines
Quoted 28 lines
fs/xfs/libxfs/xfs_attr.c +11
-0+ } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure @@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error)fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1338
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-1goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks:While I think the design is the right idea, jumping down into a function like this is pretty hairy. I think we should try to further break this function down into smaller elements one way or another that model the steps defined by the state structure. There's probably multiple ways to do that. For example, the remote attr bits could be broken down into a subfunction that processes the couple of states associated with remote blocks. That said, ISTM it might be wiser to try and keep the state processing in one place if possible. That would imply to break the remote processing loop down into a couple functions. All in all, this function might end up looking something like:
xfs_attr_node_removename(){ /* switch statement and comment to document each state */ error = xfs_attr_node_hasname(args, &state); ... if (remote) { error = do_setflag(); if (error) return error; /* roll */ state = INVALIDATE; return -EAGAIN; }
rmt_invalidate:state = INVALIDATE; if (remote) do_invalidate(); /* fallthru */
rmt_rm_blks:state = RM_NODE_BLKS; if (remote) { /* loops and returns -EAGAIN until we fallthru */ error = rmt_remove_step(); if (error) return error; xfs_attr_refillstate(); }/* maybe worth a new state here? */
removename:state = REMOVENAME; xfs_attr3_leaf_remove(); ... if (...) { state = SHRINK; return -EAGAIN; }
Quoted 6 lines
shrink:
state = SHRINK; error = do_shrink(); return 0; }
Ok, I had to go over this a few times, but I think I understand what you're describing. Will update in the next version
Quoted 3 lines
I'm not totally sold on the idea of rolling the state forward explicitly like this, but it seems like it could be a bit more maintainable.
I think it is. Having a dedicated struct just for this purpose alleviates a lot of struggle with trying to grab onto things like the fork or the incomplete flags to represent what we're trying to do here. Doing so also overloads their original intent in that if these structures ever change in the future, it may break something that the state machine depends on. In this solution, they remain disjoint concepts dedicated to their purpose. And anyway, I couldn't completely escape the state machine in the previous set. I still had to add the extra flag space which functioned more or less like "i was here" tick marks. If we have to have it, we may as well leverage what it can do. For example I can drop patch 11 from this set because I don't need the extra isset helpers to see if it's already been done.
All in
Quoted 3 lines
all this is still fairly ugly, but this is mostly a mechanical attempt to keep state management isolated and we can polish it up from there. Thoughts?
Yes, at this point, I do kind of feel like it's the least of the ugly prototypes. So I'm just kind of proceeding, with caution. :-)
Thanks for the in depths reviews!! I know its a lot! Much appreciated!!
Allison
Quoted 74 lines
Brian
Quoted 70 lines
fs/xfs/libxfs/xfs_attr.c +20
-15+/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
Quoted 47 lines · Allison Collins
Quoted 36 lines · Brian Foster
Quoted 10 lines · Allison Collins
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argshas becomexfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the state machine, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>---
On a cursory look, this is definitely more along the lines of what I was thinking on the previous revisions. I would like to see if we can get a bit more refactoring/cleanup before this point though. Further thoughts inline..
Quoted 17 lines
fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)fs/xfs/libxfs/xfs_attr.c +5
-0@@ -369,10 +369,56 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( +struct xfs_da_args *args) +{ +int error =0 ; +int err2 =0 ; +Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 380
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+ do { + error = xfs_attr_remove_later(args); + if (error && error != -EAGAIN) + goto out;
xfs_attr_remove_later()strikes me as an odd name with respect to the functionality. Perhaps something likexfs_attr_remove_step()is (slightly) more accurate..?
Quoted 4 lines
Sure that's fine. I think Darrick had proposed the
*_laterscheme in an earlier review but that was when the code paths were split. Darrick, does the*_stepscheme work for you?
FWIW, xfs_attr_remove_iter() also came to mind after sending the previous mail.
Quoted 15 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 387
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ +xfs_trans_log_inode (args->trans, args->dp, +XFS_ILOG_CORE |XFS_ILOG_ADATA ); + + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2;Also do we really need two error codes in this function? It seems like we should be able to write this with one, but I haven't tried it..
No, because then we'll loose the
xfs_attr_remove_laterreturn code, which is either 0 or EAGAIN at this point. And we need that to drive the loop. To get rid of err2, we'd need another "not_done" variable or something. Like:
Quoted 9 lines
do { ... not_done = (error == -EAGAIN); ... } while (not_done)Not sure if
not_doneis really preferable to err2?
Eh, NBD. It just looked like potentially verbose logic on a quick scan. On a closer look, I see that we want to handle both error == 0 and error == -EAGAIN, so this seems fine as is to me.
Quoted 89 lines
Quoted 81 lines
Quoted 81 lines
fs/xfs/libxfs/xfs_attr.c +46
-4+ goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE :Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1289
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+ goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ;I wonder if it's worth having an explicit state for the initial path. That could be useful for readability and debuggability in the future.
Quoted 3 lines
We could, it will just require to the calling function to set that before state calling it.
Looking back, I see we have XFS_DC_INIT in the enum, but it isn't used. What is that particular state for? Any reason the enum doesn't start with a value of 0?
Quoted 6 lines
Mechanically, I dont think it would hurt anything, but it may lead to developer wonderments like... "Where's the EAGAIN for this state?" "Shouldnt this state appear in the switch up top too?" Or if it does "Why do we have it here, if it never executes?" "I wonder if i should sent a patch to take it out..." :-)
Perhaps, though some of those questions already exist with the current code. Not every function cares about every state from what I can tell. Also, not every state that can return -EAGAIN is guaranteed to do so.
Quoted 8 lines
Puzzlement aside though, I cant quite think of what condition it would help to debug? It's not an error for the statemachine to hold a value outside of the helpers scope. It just means the caller was using it up to this point. Helpers really shouldnt have enough context about their callers to know or care what the caller states mean. If we added a special init state, all the default statement would really mean is: "The caller forgot to set the init state".
See my question above around the existing init state. However that is intended to be used is not really clear to me. BTW, it might be better to introduce the core structures in one patch and add the individual states as they are used by the subsequent patches that use them.
WRT to readability/debuggability, I suppose a simple example would be to consider if we had a tracepoint somewhere in the higher level code that printed state and error code and we wanted to use that to identify an unexpected error that occurs during an attr op. With the current code, if that printed something like:
state INVALIDATE error -EIO
... that doesn't tell us a whole lot about what happened beyond something failed sometime after the setflag state. The attr itself might not even have remote blocks to invalidate, which is slightly confusing. This is handwavy/subjective, of course..
Quoted 104 lines
Thoughts?
Quoted 91 lines
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +11
-0+ } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1337
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-1@@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks:While I think the design is the right idea, jumping down into a function like this is pretty hairy. I think we should try to further break this function down into smaller elements one way or another that model the steps defined by the state structure. There's probably multiple ways to do that. For example, the remote attr bits could be broken down into a subfunction that processes the couple of states associated with remote blocks. That said, ISTM it might be wiser to try and keep the state processing in one place if possible. That would imply to break the remote processing loop down into a couple functions. All in all, this function might end up looking something like:
xfs_attr_node_removename(){ /* switch statement and comment to document each state */ error = xfs_attr_node_hasname(args, &state); ... if (remote) { error = do_setflag(); if (error) return error; /* roll */ state = INVALIDATE; return -EAGAIN; }
rmt_invalidate:state = INVALIDATE; if (remote) do_invalidate(); /* fallthru */
rmt_rm_blks:state = RM_NODE_BLKS; if (remote) { /* loops and returns -EAGAIN until we fallthru */ error = rmt_remove_step(); if (error) return error; xfs_attr_refillstate(); }/* maybe worth a new state here? */
removename:state = REMOVENAME; xfs_attr3_leaf_remove(); ... if (...) { state = SHRINK; return -EAGAIN; }Quoted 6 lines
shrink:
state = SHRINK; error = do_shrink(); return 0; }Ok, I had to go over this a few times, but I think I understand what you're describing. Will update in the next version
Quoted 3 lines
I'm not totally sold on the idea of rolling the state forward explicitly like this, but it seems like it could be a bit more maintainable.
Quoted 13 lines
I think it is. Having a dedicated struct just for this purpose alleviates a lot of struggle with trying to grab onto things like the fork or the incomplete flags to represent what we're trying to do here. Doing so also overloads their original intent in that if these structures ever change in the future, it may break something that the state machine depends on. In this solution, they remain disjoint concepts dedicated to their purpose. And anyway, I couldn't completely escape the state machine in the previous set. I still had to add the extra flag space which functioned more or less like "i was here" tick marks. If we have to have it, we may as well leverage what it can do. For example I can drop patch 11 from this set because I don't need the extra isset helpers to see if it's already been done.
Right.. I agree that the "bookmark" like approach in the current scheme makes the state implementation (and not necessarily the operational implementation) a little hard to follow and review. Note again that what I wrote up here was just a quick example for that higher level feedback of somehow or another trying to isolate state updates from state implementation, so I'm not necessarily tied to that specific approach if there are other ways to similarly simplify things.
I do think fixing up the code to avoid jumping into loops and whatnot is more important. It could also be that just continuing to break things down into as small functions as possible (i.e. with a goal of 1 function per state) kind of forces a natural separation.
Brian
Quoted 84 lines
All in
Quoted 3 lines
all this is still fairly ugly, but this is mostly a mechanical attempt to keep state management isolated and we can polish it up from there. Thoughts?
Yes, at this point, I do kind of feel like it's the least of the ugly prototypes. So I'm just kind of proceeding, with caution. :-)
Thanks for the in depths reviews!! I know its a lot! Much appreciated!!
Allison
Quoted 71 lines
Brian
Quoted 67 lines
fs/xfs/libxfs/xfs_attr.c +20
-15+/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
Quoted 48 lines · Brian Foster
Quoted 47 lines · Allison Collins
Quoted 44 lines · Brian Foster
Quoted 10 lines · Allison Collins
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argshas becomexfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the state machine, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>---
On a cursory look, this is definitely more along the lines of what I was thinking on the previous revisions. I would like to see if we can get a bit more refactoring/cleanup before this point though. Further thoughts inline..
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0@@ -369,10 +369,56 @@ xfs_has_attr(*/ int fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 380
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0xfs_attr_remove_args ( + struct xfs_da_args *args) +{ +int error =0 ; +int err2 =0 ; + + do { + error = xfs_attr_remove_later(args); + if (error && error != -EAGAIN) + goto out;
xfs_attr_remove_later()strikes me as an odd name with respect to the functionality. Perhaps something likexfs_attr_remove_step()is (slightly) more accurate..?
Quoted 7 lines
Quoted 4 lines
Sure that's fine. I think Darrick had proposed the
*_laterscheme in an earlier review but that was when the code paths were split. Darrick, does the*_stepscheme work for you?FWIW,
xfs_attr_remove_iter()also came to mind after sending the previous mail.
Alrighty, I am fine with a *_iter scheme then
Quoted 119 lines
Quoted 16 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 387
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ +xfs_trans_log_inode (args->trans, args->dp, +XFS_ILOG_CORE |XFS_ILOG_ADATA ); + + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2;Also do we really need two error codes in this function? It seems like we should be able to write this with one, but I haven't tried it..
No, because then we'll loose the
xfs_attr_remove_laterreturn code, which is either 0 or EAGAIN at this point. And we need that to drive the loop. To get rid of err2, we'd need another "not_done" variable or something. Like:Quoted 9 lines
do { ... not_done = (error == -EAGAIN); ... } while (not_done)Not sure if
not_doneis really preferable to err2?Eh, NBD. It just looked like potentially verbose logic on a quick scan. On a closer look, I see that we want to handle both error == 0 and error ==
-EAGAIN, so this seems fine as is to me.Quoted 89 lines
Quoted 89 lines
Quoted 76 lines
fs/xfs/libxfs/xfs_attr.c +41
-4+ goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; +fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1288
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ;I wonder if it's worth having an explicit state for the initial path. That could be useful for readability and debuggability in the future.
Quoted 7 lines
Quoted 3 lines
We could, it will just require to the calling function to set that before state calling it.
Looking back, I see we have
XFS_DC_INITin the enum, but it isn't used. What is that particular state for? Any reason the enum doesn't start with a value of 0?
Yes, sorry, it's used in the next patch series when we get into to the real delayed attr infrastructure. I just forgot to take it out of the smaller subset here.
Basically all the use cases thus far already have args initialized, but in the log replay, we have to construct args from the log entry. So we need the extra state to not re-initialize it every time and wipe out the state. That use case is little more unique in that we have to set up the state machine after the ping pong has already started.
Quoted 21 lines
Quoted 7 lines
Mechanically, I dont think it would hurt anything, but it may lead to developer wonderments like... "Where's the EAGAIN for this state?" "Shouldnt this state appear in the switch up top too?" Or if it does "Why do we have it here, if it never executes?" "I wonder if i should sent a patch to take it out..." :-)
Perhaps, though some of those questions already exist with the current code. Not every function cares about every state from what I can tell. Also, not every state that can return
-EAGAINis guaranteed to do so.Quoted 8 lines
Puzzlement aside though, I cant quite think of what condition it would help to debug? It's not an error for the statemachine to hold a value outside of the helpers scope. It just means the caller was using it up to this point. Helpers really shouldnt have enough context about their callers to know or care what the caller states mean. If we added a special init state, all the default statement would really mean is: "The caller forgot to set the init state".
Quoted 4 lines
See my question above around the existing init state. However that is intended to be used is not really clear to me. BTW, it might be better to introduce the core structures in one patch and add the individual states as they are used by the subsequent patches that use them.
Ok, I will introduce the states progressively then, I think that caused the confusion
Quoted 7 lines
WRT to readability/debuggability, I suppose a simple example would be to consider if we had a tracepoint somewhere in the higher level code that printed state and error code and we wanted to use that to identify an unexpected error that occurs during an attr op. With the current code, if that printed something like:
Quoted 6 lines
state INVALIDATE error
-EIO... that doesn't tell us a whole lot about what happened beyond something failed sometime after the setflag state. The attr itself might not even have remote blocks to invalidate, which is slightly confusing. This is handwavy/subjective, of course..
Yes, as it is, it doesn't really have any way of detecting a corrupt state. Really though, if we want to do that what we need is another layer of modeling where we enforce the sequence of the states. So for example, some sort of mapping or tree that defines: XFS_DC_LEAF_TO_NODE and XFS_DC_FOUND_LBLK as being children (or mappings) of XFS_DC_SF_TO_LEAF.
In other words, if the state is XFS_DC_SF_TO_LEAF, you can change it to XFS_DC_FOUND_LBLK or XFS_DC_LEAF_TO_NODE, but you can't go to say XFS_DC_RM_SHRINK, that would generate an error. And then we have some sort of set_state() routine to enforce these rules.
That's a lot of extra overhead though, and could be more of a burden than a help. But it's something we could explore if people think it's worth the pursuit.
Allison
Quoted 219 lines
Quoted 105 lines
Thoughts?
Quoted 91 lines
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +11
-0+ } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1337
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-1@@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks:While I think the design is the right idea, jumping down into a function like this is pretty hairy. I think we should try to further break this function down into smaller elements one way or another that model the steps defined by the state structure. There's probably multiple ways to do that. For example, the remote attr bits could be broken down into a subfunction that processes the couple of states associated with remote blocks. That said, ISTM it might be wiser to try and keep the state processing in one place if possible. That would imply to break the remote processing loop down into a couple functions. All in all, this function might end up looking something like:
xfs_attr_node_removename(){ /* switch statement and comment to document each state */ error = xfs_attr_node_hasname(args, &state); ... if (remote) { error = do_setflag(); if (error) return error; /* roll */ state = INVALIDATE; return -EAGAIN; }
rmt_invalidate:state = INVALIDATE; if (remote) do_invalidate(); /* fallthru */
rmt_rm_blks:state = RM_NODE_BLKS; if (remote) { /* loops and returns -EAGAIN until we fallthru */ error = rmt_remove_step(); if (error) return error; xfs_attr_refillstate(); }/* maybe worth a new state here? */
removename:state = REMOVENAME; xfs_attr3_leaf_remove(); ... if (...) { state = SHRINK; return -EAGAIN; }Quoted 6 lines
shrink:
state = SHRINK; error = do_shrink(); return 0; }Ok, I had to go over this a few times, but I think I understand what you're describing. Will update in the next version
Quoted 3 lines
I'm not totally sold on the idea of rolling the state forward explicitly like this, but it seems like it could be a bit more maintainable.
Quoted 13 lines
I think it is. Having a dedicated struct just for this purpose alleviates a lot of struggle with trying to grab onto things like the fork or the incomplete flags to represent what we're trying to do here. Doing so also overloads their original intent in that if these structures ever change in the future, it may break something that the state machine depends on. In this solution, they remain disjoint concepts dedicated to their purpose. And anyway, I couldn't completely escape the state machine in the previous set. I still had to add the extra flag space which functioned more or less like "i was here" tick marks. If we have to have it, we may as well leverage what it can do. For example I can drop patch 11 from this set because I don't need the extra isset helpers to see if it's already been done.
Right.. I agree that the "bookmark" like approach in the current scheme makes the state implementation (and not necessarily the operational implementation) a little hard to follow and review. Note again that what I wrote up here was just a quick example for that higher level feedback of somehow or another trying to isolate state updates from state implementation, so I'm not necessarily tied to that specific approach if there are other ways to similarly simplify things.
I do think fixing up the code to avoid jumping into loops and whatnot is more important. It could also be that just continuing to break things down into as small functions as possible (i.e. with a goal of 1 function per state) kind of forces a natural separation.
Brian
Quoted 84 lines
All in
Quoted 3 lines
all this is still fairly ugly, but this is mostly a mechanical attempt to keep state management isolated and we can polish it up from there. Thoughts?
Yes, at this point, I do kind of feel like it's the least of the ugly prototypes. So I'm just kind of proceeding, with caution. :-)
Thanks for the in depths reviews!! I know its a lot! Much appreciated!!
Allison
Quoted 71 lines
Brian
Quoted 67 lines
fs/xfs/libxfs/xfs_attr.c +20
-15+/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
Quoted 243 lines · Allison Collins
Quoted 48 lines · Brian Foster
Quoted 47 lines · Allison Collins
Quoted 44 lines · Brian Foster
Quoted 10 lines · Allison Collins
This patch modifies the attr remove routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_remove_argshas becomexfs_attr_remove_later, which uses a state machine to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the state machine, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.Quoted 2 lines
Signed-off-by Allison Collins <[email protected]>---
On a cursory look, this is definitely more along the lines of what I was thinking on the previous revisions. I would like to see if we can get a bit more refactoring/cleanup before this point though. Further thoughts inline..
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c | 123 +++++++++++++++++++++++++++++++++++++++-------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 104 insertions(+), 20 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0@@ -369,10 +369,56 @@ xfs_has_attr(*/ int fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 380
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0xfs_attr_remove_args ( + struct xfs_da_args *args) +{ +int error =0 ; +int err2 =0 ; + + do { + error = xfs_attr_remove_later(args); + if (error && error != -EAGAIN) + goto out;
xfs_attr_remove_later()strikes me as an odd name with respect to the functionality. Perhaps something likexfs_attr_remove_step()is (slightly) more accurate..?Quoted 7 lines
Quoted 4 lines
Sure that's fine. I think Darrick had proposed the
*_laterscheme in an earlier review but that was when the code paths were split. Darrick, does the*_stepscheme work for you?FWIW,
xfs_attr_remove_iter()also came to mind after sending the previous mail.Alrighty, I am fine with a
*_iterscheme thenQuoted 119 lines
Quoted 16 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c xfs_has_attr( · line 387
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +7
-0+ +xfs_trans_log_inode (args->trans, args->dp, +XFS_ILOG_CORE |XFS_ILOG_ADATA ); + + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2;Also do we really need two error codes in this function? It seems like we should be able to write this with one, but I haven't tried it..
No, because then we'll loose the
xfs_attr_remove_laterreturn code, which is either 0 or EAGAIN at this point. And we need that to drive the loop. To get rid of err2, we'd need another "not_done" variable or something. Like:Quoted 9 lines
do { ... not_done = (error == -EAGAIN); ... } while (not_done)Not sure if
not_doneis really preferable to err2?Eh, NBD. It just looked like potentially verbose logic on a quick scan. On a closer look, I see that we want to handle both error == 0 and error ==
-EAGAIN, so this seems fine as is to me.Quoted 89 lines
Quoted 89 lines
Quoted 76 lines
fs/xfs/libxfs/xfs_attr.c +41
-4+ goto out; + } + +/* Rejoin inode */ +xfs_trans_ijoin (args->trans, args->dp,0 ); + + }while (error == -EAGAIN ); +out: +return error; +} + +/* +* Remove the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_remove_later (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_INVALIDATE : +case XFS_DC_RM_SHRINK : +case XFS_DC_RM_NODE_BLKS : + goto node; +default : +break ; + }if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ;@@ -382,6 +428,7 @@ xfs_attr_remove_args( }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { error =xfs_attr_leaf_removename (args); }else { +node: error =xfs_attr_node_removename (args); }@@ -892,9 +939,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error)return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; }return 0 ; }@@ -1212,6 +1256,11 @@ xfs_attr_node_addname(* This will involve walking down the Btree, and may involve joining * leaf nodes and even joining intermediate nodes up to and including * the root node (a special case of an intermediate node). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions +* will need to handle this, and recall the function until a successful error +* code is returned. */ STATIC int xfs_attr_node_removename(@@ -1222,12 +1271,29 @@ xfs_attr_node_removename(struct xfs_buf *bp;int retval, error, forkoff;struct xfs_inode *dp = args->dp; +int done =0 ;trace_xfs_attr_node_removename (args); + state = args->dc.da_state; + blk = args->dc.blk; +fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1288
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DC_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DC_RM_SHRINK : + goto rm_shrink; +default : +break ;I wonder if it's worth having an explicit state for the initial path. That could be useful for readability and debuggability in the future.
Quoted 7 lines
Quoted 3 lines
We could, it will just require to the calling function to set that before state calling it.
Looking back, I see we have
XFS_DC_INITin the enum, but it isn't used. What is that particular state for? Any reason the enum doesn't start with a value of 0?Yes, sorry, it's used in the next patch series when we get into to the real delayed attr infrastructure. I just forgot to take it out of the smaller subset here.
Basically all the use cases thus far already have args initialized, but in the log replay, we have to construct args from the log entry. So we need the extra state to not re-initialize it every time and wipe out the state. That use case is little more unique in that we have to set up the state machine after the ping pong has already started.
Quoted 21 lines
Quoted 7 lines
Mechanically, I dont think it would hurt anything, but it may lead to developer wonderments like... "Where's the EAGAIN for this state?" "Shouldnt this state appear in the switch up top too?" Or if it does "Why do we have it here, if it never executes?" "I wonder if i should sent a patch to take it out..." :-)
Perhaps, though some of those questions already exist with the current code. Not every function cares about every state from what I can tell. Also, not every state that can return
-EAGAINis guaranteed to do so.Quoted 8 lines
Puzzlement aside though, I cant quite think of what condition it would help to debug? It's not an error for the statemachine to hold a value outside of the helpers scope. It just means the caller was using it up to this point. Helpers really shouldnt have enough context about their callers to know or care what the caller states mean. If we added a special init state, all the default statement would really mean is: "The caller forgot to set the init state".
Quoted 4 lines
See my question above around the existing init state. However that is intended to be used is not really clear to me. BTW, it might be better to introduce the core structures in one patch and add the individual states as they are used by the subsequent patches that use them.
Ok, I will introduce the states progressively then, I think that caused the confusion
Quoted 7 lines
WRT to readability/debuggability, I suppose a simple example would be to consider if we had a tracepoint somewhere in the higher level code that printed state and error code and we wanted to use that to identify an unexpected error that occurs during an attr op. With the current code, if that printed something like:
Quoted 6 lines
state INVALIDATE error
-EIO... that doesn't tell us a whole lot about what happened beyond something failed sometime after the setflag state. The attr itself might not even have remote blocks to invalidate, which is slightly confusing. This is handwavy/subjective, of course..
Yes, as it is, it doesn't really have any way of detecting a corrupt state. Really though, if we want to do that what we need is another layer of modeling where we enforce the sequence of the states. So for example, some sort of mapping or tree that defines:
XFS_DC_LEAF_TO_NODEandXFS_DC_FOUND_LBLKas being children (or mappings) ofXFS_DC_SF_TO_LEAF.
Quoted 9 lines
In other words, if the state is
XFS_DC_SF_TO_LEAF, you can change it toXFS_DC_FOUND_LBLKorXFS_DC_LEAF_TO_NODE, but you can't go to sayXFS_DC_RM_SHRINK, that would generate an error. And then we have some sort ofset_state()routine to enforce these rules.That's a lot of extra overhead though, and could be more of a burden than a help. But it's something we could explore if people think it's worth the pursuit.
Yeah, I don't think it's necessary to go so far as to create a complex set of rules and whatnot purely for the purpose of validating state management. I'm just handwaving about potentially structuring the code such that the state management is clear and easy to follow. :)
Brian
Quoted 221 lines
Allison
Quoted 219 lines
Quoted 105 lines
Thoughts?
Quoted 91 lines
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +11
-0+ } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1337
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-1@@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks:While I think the design is the right idea, jumping down into a function like this is pretty hairy. I think we should try to further break this function down into smaller elements one way or another that model the steps defined by the state structure. There's probably multiple ways to do that. For example, the remote attr bits could be broken down into a subfunction that processes the couple of states associated with remote blocks. That said, ISTM it might be wiser to try and keep the state processing in one place if possible. That would imply to break the remote processing loop down into a couple functions. All in all, this function might end up looking something like:
xfs_attr_node_removename(){ /* switch statement and comment to document each state */ error = xfs_attr_node_hasname(args, &state); ... if (remote) { error = do_setflag(); if (error) return error; /* roll */ state = INVALIDATE; return -EAGAIN; }
rmt_invalidate:state = INVALIDATE; if (remote) do_invalidate(); /* fallthru */
rmt_rm_blks:state = RM_NODE_BLKS; if (remote) { /* loops and returns -EAGAIN until we fallthru */ error = rmt_remove_step(); if (error) return error; xfs_attr_refillstate(); }/* maybe worth a new state here? */
removename:state = REMOVENAME; xfs_attr3_leaf_remove(); ... if (...) { state = SHRINK; return -EAGAIN; }Quoted 6 lines
shrink:
state = SHRINK; error = do_shrink(); return 0; }Ok, I had to go over this a few times, but I think I understand what you're describing. Will update in the next version
Quoted 3 lines
I'm not totally sold on the idea of rolling the state forward explicitly like this, but it seems like it could be a bit more maintainable.
Quoted 13 lines
I think it is. Having a dedicated struct just for this purpose alleviates a lot of struggle with trying to grab onto things like the fork or the incomplete flags to represent what we're trying to do here. Doing so also overloads their original intent in that if these structures ever change in the future, it may break something that the state machine depends on. In this solution, they remain disjoint concepts dedicated to their purpose. And anyway, I couldn't completely escape the state machine in the previous set. I still had to add the extra flag space which functioned more or less like "i was here" tick marks. If we have to have it, we may as well leverage what it can do. For example I can drop patch 11 from this set because I don't need the extra isset helpers to see if it's already been done.
Right.. I agree that the "bookmark" like approach in the current scheme makes the state implementation (and not necessarily the operational implementation) a little hard to follow and review. Note again that what I wrote up here was just a quick example for that higher level feedback of somehow or another trying to isolate state updates from state implementation, so I'm not necessarily tied to that specific approach if there are other ways to similarly simplify things.
I do think fixing up the code to avoid jumping into loops and whatnot is more important. It could also be that just continuing to break things down into as small functions as possible (i.e. with a goal of 1 function per state) kind of forces a natural separation.
Brian
Quoted 84 lines
All in
Quoted 3 lines
all this is still fairly ugly, but this is mostly a mechanical attempt to keep state management isolated and we can polish it up from there. Thoughts?
Yes, at this point, I do kind of feel like it's the least of the ugly prototypes. So I'm just kind of proceeding, with caution. :-)
Thanks for the in depths reviews!! I know its a lot! Much appreciated!!
Allison
Quoted 71 lines
Brian
Quoted 67 lines
fs/xfs/libxfs/xfs_attr.c +20
-15+/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
Re: [PATCH v4 16/17] xfs: Add delay ready attr remove routines
Quoted 4 lines · Brian Foster
Quoted 3 lines · Allison Collins
On 11/13/19 4:54 AM, Brian Foster wrote:
<snip>
Quoted 16 lines
Quoted 6 lines
Yes, as it is, it doesn't really have any way of detecting a corrupt state. Really though, if we want to do that what we need is another layer of modeling where we enforce the sequence of the states. So for example, some sort of mapping or tree that defines:
XFS_DC_LEAF_TO_NODEandXFS_DC_FOUND_LBLKas being children (or mappings) ofXFS_DC_SF_TO_LEAF.Quoted 9 lines
In other words, if the state is
XFS_DC_SF_TO_LEAF, you can change it toXFS_DC_FOUND_LBLKorXFS_DC_LEAF_TO_NODE, but you can't go to sayXFS_DC_RM_SHRINK, that would generate an error. And then we have some sort ofset_state()routine to enforce these rules.That's a lot of extra overhead though, and could be more of a burden than a help. But it's something we could explore if people think it's worth the pursuit.
Quoted 6 lines
Yeah, I don't think it's necessary to go so far as to create a complex set of rules and whatnot purely for the purpose of validating state management. I'm just handwaving about potentially structuring the code such that the state management is clear and easy to follow. :)
Brian
Yeah, that's kinda how I felt too. Maybe later we could come back and reconsider it depending on how the refactoring goes. I've done a little research online around about state machine designs, and usually what I see is some sort of mapping of state codes to function pointers. So if it's possible to modularize everything into helpers, then an extra layer of abstraction starts to make a lot more sense. But what we wouldn't want is so much refactoring that we have a bunch of little helpers so small and fragmented that the code flow is a headache to follow. So I figure maybe for now we could just stick to refactoring snippets under the switch approach, and if it starts to look like something that could really benefit from a fully formed state machine model, we can consider it then :-)
Allison
Quoted 223 lines
Quoted 222 lines
Allison
Quoted 219 lines
Quoted 105 lines
Thoughts?
Quoted 91 lines
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +11
-0+ } error =xfs_attr_node_hasname (args, &state);if (error != -EEXIST ) goto out; +else + error =0 ;/* * If there is an out-of-line value, de-allocate the blocks. @@ -1237,6 +1303,14 @@ xfs_attr_node_removename( blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->bp !=NULL );ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); + +/* +* Store blk and state in the context incase we need to cycle out the +* transaction +*/ + args->dc.blk = blk; + args->dc.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1337
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +5
-1@@ -1255,13 +1329,30 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); + args->dc.dc_state =XFS_DC_RM_INVALIDATE ; +return -EAGAIN ; +rm_invalidate: + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; +rm_node_blks:While I think the design is the right idea, jumping down into a function like this is pretty hairy. I think we should try to further break this function down into smaller elements one way or another that model the steps defined by the state structure. There's probably multiple ways to do that. For example, the remote attr bits could be broken down into a subfunction that processes the couple of states associated with remote blocks. That said, ISTM it might be wiser to try and keep the state processing in one place if possible. That would imply to break the remote processing loop down into a couple functions. All in all, this function might end up looking something like:
xfs_attr_node_removename(){ /* switch statement and comment to document each state */ error = xfs_attr_node_hasname(args, &state); ... if (remote) { error = do_setflag(); if (error) return error; /* roll */ state = INVALIDATE; return -EAGAIN; }
rmt_invalidate:state = INVALIDATE; if (remote) do_invalidate(); /* fallthru */
rmt_rm_blks:state = RM_NODE_BLKS; if (remote) { /* loops and returns -EAGAIN until we fallthru */ error = rmt_remove_step(); if (error) return error; xfs_attr_refillstate(); }/* maybe worth a new state here? */
removename:state = REMOVENAME; xfs_attr3_leaf_remove(); ... if (...) { state = SHRINK; return -EAGAIN; }Quoted 6 lines
shrink:
state = SHRINK; error = do_shrink(); return 0; }Ok, I had to go over this a few times, but I think I understand what you're describing. Will update in the next version
Quoted 3 lines
I'm not totally sold on the idea of rolling the state forward explicitly like this, but it seems like it could be a bit more maintainable.
Quoted 13 lines
I think it is. Having a dedicated struct just for this purpose alleviates a lot of struggle with trying to grab onto things like the fork or the incomplete flags to represent what we're trying to do here. Doing so also overloads their original intent in that if these structures ever change in the future, it may break something that the state machine depends on. In this solution, they remain disjoint concepts dedicated to their purpose. And anyway, I couldn't completely escape the state machine in the previous set. I still had to add the extra flag space which functioned more or less like "i was here" tick marks. If we have to have it, we may as well leverage what it can do. For example I can drop patch 11 from this set because I don't need the extra isset helpers to see if it's already been done.
Right.. I agree that the "bookmark" like approach in the current scheme makes the state implementation (and not necessarily the operational implementation) a little hard to follow and review. Note again that what I wrote up here was just a quick example for that higher level feedback of somehow or another trying to isolate state updates from state implementation, so I'm not necessarily tied to that specific approach if there are other ways to similarly simplify things.
I do think fixing up the code to avoid jumping into loops and whatnot is more important. It could also be that just continuing to break things down into as small functions as possible (i.e. with a goal of 1 function per state) kind of forces a natural separation.
Brian
Quoted 84 lines
All in
Quoted 3 lines
all this is still fairly ugly, but this is mostly a mechanical attempt to keep state management isolated and we can polish it up from there. Thoughts?
Yes, at this point, I do kind of feel like it's the least of the ugly prototypes. So I'm just kind of proceeding, with caution. :-)
Thanks for the in depths reviews!! I know its a lot! Much appreciated!!
Allison
Quoted 71 lines
Brian
Quoted 67 lines
fs/xfs/libxfs/xfs_attr.c +20
-15+/* +* Unmap value blocks for this attr. This is similar to +* xfs_attr_rmtval_remove, but open coded here to return EAGAIN +* for new transactions +*/ +while (!done && !error) { + error =xfs_bunmapi (args->trans, args->dp, + args->rmtblkno, args->rmtblkcnt, +XFS_BMAPI_ATTRFORK ,1 , &done); +if (error) +return error; - error =xfs_attr_rmtval_remove (args); -if (error) - goto out; +if (!done) { + args->dc.dc_state =XFS_DC_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls @@ -1287,17 +1378,12 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dc.dc_state =XFS_DC_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink:/* * If the result is small enough, push it all into the inode. */ @@ -1319,9 +1405,6 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else xfs_trans_brelse (args->trans, bp); }fs/xfs/libxfs/xfs_attr.h +1
-0@@ -152,6 +152,7 @@ int xfs_attr_set_args(struct xfs_da_args *args);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_later (struct xfs_da_args *args);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);bool xfs_attr_namecheck (const void *name,size_t length);Signature · 1 line
2.7.4
PATCH v4 17/17 xfs: Add delay ready attr set routines
In reply to Allison CollinsThis patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return -EAGAIN to have the calling routine roll and refresh the transaction. In this series, xfs_attr_set_args has become xfs_attr_set_later, which uses a state machine to keep track of where it was when EAGAIN was returned. Part of xfs_attr_leaf_addname has been factored out into a new helper function xfs_attr_leaf_try_add to allow transaction cycling between the two routines, and the flipflags logic has been removed since we can simply cancel the transaction upon error. xfs_attr_set_args consists of a simple loop to refresh the transaction until the operation is completed.
--- fs/xfs/libxfs/xfs_attr.c | 435 +++++++++++++++++++++++------------------------ fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 211 insertions(+), 225 deletions(-)
fs/xfs/libxfs/xfs_attr.c +210 -225
@@ -58,6 +58,7 @@ 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); STATIC int xfs_attr_refillstate(xfs_da_state_t *state); +STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);STATIC int
@@ -250,9 +251,79 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { +int error =0 ; +int err2 =0 ; +struct xfs_buf *leaf_bp =NULL ; + +do { + error =xfs_attr_set_later (args, &leaf_bp); +if (error && error != -EAGAIN ) + goto out; + +xfs_trans_log_inode (args->trans, args->dp, +XFS_ILOG_CORE |XFS_ILOG_ADATA ); + + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2; + goto out; + } + +/* Rejoin inode and leaf if needed */ +xfs_trans_ijoin (args->trans, args->dp,0 ); +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + } + + }while (error == -EAGAIN ); + +out: +return error; +} + +/* +* Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_set_later ( +struct xfs_da_args *args, +struct xfs_buf **leaf_bp) +{struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error, error2 =0 ;; +int error =0 ; +int sf_size; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_SF_TO_LEAF : + goto sf_to_leaf; +case XFS_DC_ALLOC_LEAF : +case XFS_DC_FOUND_LBLK : + goto leaf; +case XFS_DC_FOUND_NBLK : +case XFS_DC_ALLOC_NODE : +case XFS_DC_LEAF_TO_NODE : + goto node; +default : +break ; + } + +/* +* New inodes may not have an attribute fork yet. So set the attribute +* fork appropriately +*/ +if (XFS_IFORK_Q ((args->dp)) ==0 ) { + sf_size =sizeof (struct xfs_attr_sf_hdr ) + +XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen); +xfs_bmap_set_attrforkoff (args->dp, sf_size,NULL ); + args->dp->i_afp =kmem_zone_zalloc (xfs_ifork_zone,0 ); + args->dp->i_afp->if_flags =XFS_IFEXTENTS ; + }/* * If the attribute list is non-existent or a shortform list,
@@ -272,21 +343,14 @@ xfs_attr_set_args(* Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) { -if (dp->i_mount->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args->trans); - - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; - } - +if (error != -ENOSPC ) +return error;/* * 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, leaf_bp);if (error)return error;
@@ -294,43 +358,42 @@ xfs_attr_set_args(* Prevent the leaf buffer from being unlocked so that a * concurrent AIL push cannot grab the half-baked leaf * buffer and run into problems with the write verifier. -* Once we're done rolling the transaction we can release -* the hold and add the attr to the leaf. */ -xfs_trans_bhold (args->trans, leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, leaf_bp); -return error; - } + +xfs_trans_bhold (args->trans, *leaf_bp); + args->dc.dc_state =XFS_DC_SF_TO_LEAF ; +return -EAGAIN ; + } +sf_to_leaf: + +/* +* After a shortform to leaf conversion, we need to hold the leaf and +* cylce out the transaction. When we get back, we need to release +* the leaf. +*/ +if (*leaf_bp !=NULL ) { +xfs_trans_brelse (args->trans, *leaf_bp); + *leaf_bp =NULL ; }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +if (error == -ENOSPC ) + args->dc.dc_state =XFS_DC_LEAF_TO_NODE ; +else if (error) +return error; +else + args->dc.dc_state =XFS_DC_FOUND_LBLK ; +return -EAGAIN ; +leaf: error =xfs_attr_leaf_addname (args);if (error == -ENOSPC ) { -/* -* Commit that transaction so that the node_addname() -* call can manage its own transactions. -*/ - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - -/* -* Fob the rest of the problem off on the Btree code. -*/ - error =xfs_attr_node_addname (args); + args->dc.dc_state =XFS_DC_LEAF_TO_NODE ; +return -EAGAIN ; } }else { + args->dc.dc_state =XFS_DC_LEAF_TO_NODE ; +node: error =xfs_attr_node_addname (args); }return error;
@@ -764,27 +827,26 @@ xfs_attr_leaf_try_add(* * This leaf block cannot have a "remote" value, we only call this routine * if bmap_one_block() says there is only one block (ie: no remote blks). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ STATIC intxfs_attr_leaf_addname (struct xfs_da_args *args) { -int error, forkoff; -struct xfs_buf *bp =NULL ; +int error, nmap;struct xfs_inode *dp = args->dp; +struct xfs_bmbt_irec *map = &args->dc.map; -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; - -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_ALLOC_LEAF : + goto alloc_leaf; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we
@@ -793,90 +855,58 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } -/* -* If this is an atomic rename operation, we must "flip" the -* incomplete flags on the "new" and "old" attribute/value pairs -* so that one disappears and one appears atomically. Then we -* must remove the "old" attribute/value pair. -*/ -if (args->op_flags &XFS_DA_OP_RENAME ) { -/* -* In a separate transaction, set the incomplete flag on the -* "old" attr and clear the incomplete flag on the "new" attr. -*/ - error =xfs_attr3_leaf_flipflags (args); -if (error) -return error; -/* -* Commit the flag value change and start the next trans in -* series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; +/* Open coded xfs_attr_rmtval_set without trans handling */ -/* -* Dismantle the "old" attribute/value pair by removing -* a "remote" value (if it exists). -*/ - args->index = args->index2; - args->blkno = args->blkno2; - args->rmtblkno = args->rmtblkno2; - args->rmtblkcnt = args->rmtblkcnt2; - args->rmtvaluelen = args->rmtvaluelen2; -if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } + args->dc.lfileoff =0 ; + args->dc.lblkno =0 ; + args->dc.blkcnt =0 ; + args->rmtblkcnt =0 ; + args->rmtblkno =0 ; +memset (map,0 ,sizeof (struct xfs_bmbt_irec )); -/* -* Read in the block containing the "old" attr, then -* remove the "old" attr from that block (neat, huh!) -*/ - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); + error =xfs_attr_rmt_find_hole (args);if (error)return error; -xfs_attr3_leaf_remove (bp, args); + args->dc.blkcnt = args->rmtblkcnt; + args->dc.lblkno = args->rmtblkno;/* -* If the result is small enough, shrink it all into the inode. +* Roll through the "value", allocating blocks on disk as +* required. */ -if ((forkoff =xfs_attr_shortform_allfit (bp, dp))) { - error =xfs_attr3_leaf_to_shortform (bp, args, forkoff); -/* bp is gone due to xfs_da_shrink_inode */ -if (error) -return error; - error =xfs_defer_finish (&args->trans); +alloc_leaf: +while (args->dc.blkcnt >0 ) { + nmap =1 ; + error =xfs_bmapi_write (args->trans, dp, + (xfs_fileoff_t )args->dc.lblkno, + args->dc.blkcnt,XFS_BMAPI_ATTRFORK , + args->total, map, &nmap);if (error)return error; - } +ASSERT (nmap ==1 ); +ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && + (map->br_startblock !=HOLESTARTBLOCK )); -/* -* Commit the remove and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); +/* roll attribute extent map forwards */ + args->dc.lblkno += map->br_blockcount; + args->dc.blkcnt -= map->br_blockcount; - }else if (args->rmtblkno >0 ) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ - error =xfs_attr3_leaf_clearflag (args); + args->dc.dc_state =XFS_DC_ALLOC_LEAF ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; + } +if (args->rmtblkno >0 ) {/* -* Commit the flag value change and start the next trans in -* series. +* Added a "remote" value, just clear the incomplete flag. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr3_leaf_clearflag (args); }return error; }
@@ -1017,16 +1047,23 @@ xfs_attr_node_hasname(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname (struct xfs_da_args *args) { -struct xfs_da_state *state; +struct xfs_da_state *state =NULL ;struct xfs_da_state_blk *blk;struct xfs_inode *dp; -struct xfs_mount *mp; -int retval, error; +int retval =0 ; +int error =0 ; +int nmap; +struct xfs_bmbt_irec *map = &args->dc.map;trace_xfs_attr_node_addname (args);
@@ -1034,8 +1071,17 @@ xfs_attr_node_addname(* Fill in bucket of arguments/results/context to carry around. */ dp = args->dp; - mp = dp->i_mount; -restart: + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_FOUND_NBLK : + goto found_nblk; +case XFS_DC_ALLOC_NODE : + goto alloc_node; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go.
@@ -1085,19 +1131,12 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;/* -* Commit the node conversion and start the next -* trans in the chain. +* Restart routine from the top. No need to set the +* state */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - - goto restart; +return -EAGAIN ; }/*
@@ -1109,9 +1148,6 @@ xfs_attr_node_addname( error =xfs_da3_split (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else {/* * Addition succeeded, update Btree hashvals.
@@ -1126,13 +1162,9 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + args->dc.dc_state =XFS_DC_FOUND_NBLK ; +return -EAGAIN ; +found_nblk:/* * If there was an out-of-line value, allocate the blocks we
@@ -1141,104 +1173,57 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } +/* Open coded xfs_attr_rmtval_set without trans handling */ + args->dc.lblkno =0 ; + args->dc.lfileoff =0 ; + args->dc.blkcnt =0 ; + args->rmtblkcnt =0 ; + args->rmtblkno =0 ; +memset (map,0 ,sizeof (struct xfs_bmbt_irec )); -/* -* If this is an atomic rename operation, we must "flip" the -* incomplete flags on the "new" and "old" attribute/value pairs -* so that one disappears and one appears atomically. Then we -* must remove the "old" attribute/value pair. -*/ -if (args->op_flags &XFS_DA_OP_RENAME ) { -/* -* In a separate transaction, set the incomplete flag on the -* "old" attr and clear the incomplete flag on the "new" attr. -*/ - error =xfs_attr3_leaf_flipflags (args); -if (error) - goto out; -/* -* Commit the flag value change and start the next trans in -* series -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_rmt_find_hole (args);if (error) - goto out; +return error; + args->dc.blkcnt = args->rmtblkcnt; + args->dc.lblkno = args->rmtblkno;/* -* Dismantle the "old" attribute/value pair by removing -* a "remote" value (if it exists). +* Roll through the "value", allocating blocks on disk as +* required. */ - args->index = args->index2; - args->blkno = args->blkno2; - args->rmtblkno = args->rmtblkno2; - args->rmtblkcnt = args->rmtblkcnt2; - args->rmtvaluelen = args->rmtvaluelen2; -if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args); +alloc_node: +while (args->dc.blkcnt >0 ) { + nmap =1 ; + error =xfs_bmapi_write (args->trans, dp, + (xfs_fileoff_t )args->dc.lblkno, args->dc.blkcnt, +XFS_BMAPI_ATTRFORK , args->total, map, &nmap);if (error)return error; - } -/* -* 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->name.type |=XFS_ATTR_INCOMPLETE ; - state =xfs_da_state_alloc (); - state->args = args; - state->mp = mp; - state->inleaf =0 ; - error =xfs_da3_node_lookup_int (state, &retval); -if (error) - goto out; +ASSERT (nmap ==1 ); +ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && + (map->br_startblock !=HOLESTARTBLOCK )); -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - error =xfs_attr3_leaf_remove (blk->bp, args); -xfs_da3_fixhashpath (state, &state->path); +/* roll attribute extent map forwards */ + args->dc.lblkno += map->br_blockcount; + args->dc.blkcnt -= map->br_blockcount; -/* -* Check to see if the tree needs to be collapsed. -*/ -if (retval && (state->path.active >1 )) { - error =xfs_da3_join (state); -if (error) - goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; + args->dc.dc_state =XFS_DC_ALLOC_NODE ; +return -EAGAIN ; } -/* -* Commit and start the next trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_rmtval_set_value (args);if (error) - goto out; +return error; + } - }else if (args->rmtblkno >0 ) { +if (args->rmtblkno >0 ) {/* * Added a "remote" value, just clear the incomplete flag. */ error =xfs_attr3_leaf_clearflag (args);if (error) goto out; - -/* -* Commit the flag value change and start the next trans in -* series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; } retval = error =0 ;
fs/xfs/libxfs/xfs_attr.h +1 -0
@@ -149,6 +149,7 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,int xfs_attr_set (struct xfs_inode *dp,struct xfs_name *name,unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args); +int xfs_attr_set_later (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);
Signature · 1 line
2.7.4
Re: [PATCH v4 17/17] xfs: Add delay ready attr set routines
Quoted 36 lines · Allison Collins
This patch modifies the attr set routines to be delay ready. This means they no longer roll or commit transactions, but instead return
-EAGAINto have the calling routine roll and refresh the transaction. In this series,xfs_attr_set_argshas becomexfs_attr_set_later, which uses a state machine to keep track of where it was when EAGAIN was returned. Part ofxfs_attr_leaf_addnamehas been factored out into a new helper functionxfs_attr_leaf_try_addto allow transaction cycling between the two routines, and the flipflags logic has been removed since we can simply cancel the transaction upon error.xfs_attr_set_argsconsists of a simple loop to refresh the transaction until the operation is completed.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 435 +++++++++++++++++++++++------------------------ fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 211 insertions(+), 225 deletions(-)fs/xfs/libxfs/xfs_attr.c +2
-0@@ -58,6 +58,7 @@ 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); STATIC int xfs_attr_refillstate(xfs_da_state_t *state); +STATIC int xfs_attr_leaf_try_add(struct xfs_da_args *args, struct xfs_buf *bp);STATIC int@@ -250,9 +251,79 @@ intxfs_attr_set_args ( struct xfs_da_args *args) { +int error =0 ;
fs/xfs/libxfs/xfs_attr.c int · line 264
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+int err2 =0 ; +struct xfs_buf *leaf_bp =NULL ; + + do { + error = xfs_attr_set_later(args, &leaf_bp); + if (error && error != -EAGAIN) + goto out; + + xfs_trans_log_inode(args->trans, args->dp, + XFS_ILOG_CORE | XFS_ILOG_ADATA);
Same question as the last patch about ADATA.
Quoted 68 lines
fs/xfs/libxfs/xfs_attr.c +61
-2+ + err2 =xfs_trans_roll (&args->trans); +if (err2) { + error = err2; + goto out; + } + +/* Rejoin inode and leaf if needed */ +xfs_trans_ijoin (args->trans, args->dp,0 ); +if (leaf_bp) { +xfs_trans_bjoin (args->trans, leaf_bp); +xfs_trans_bhold (args->trans, leaf_bp); + } + + }while (error == -EAGAIN ); + +out: +return error; +} + +/* +* Set the attribute specified in @args. +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. +*/ +int +xfs_attr_set_later ( +struct xfs_da_args *args, +struct xfs_buf **leaf_bp) +{struct xfs_inode *dp = args->dp; -struct xfs_buf *leaf_bp =NULL ; -int error, error2 =0 ;; +int error =0 ; +int sf_size; + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_SF_TO_LEAF : + goto sf_to_leaf; +case XFS_DC_ALLOC_LEAF : +case XFS_DC_FOUND_LBLK : + goto leaf; +case XFS_DC_FOUND_NBLK : +case XFS_DC_ALLOC_NODE : +case XFS_DC_LEAF_TO_NODE : + goto node; +default : +break ; + } + +/* +* New inodes may not have an attribute fork yet. So set the attribute +* fork appropriately +*/ +if (XFS_IFORK_Q ((args->dp)) ==0 ) { + sf_size =sizeof (struct xfs_attr_sf_hdr ) + +XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen); +xfs_bmap_set_attrforkoff (args->dp, sf_size,NULL ); + args->dp->i_afp =kmem_zone_zalloc (xfs_ifork_zone,0 ); + args->dp->i_afp->if_flags =XFS_IFEXTENTS ; + }/* * If the attribute list is non-existent or a shortform list,
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 277
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-3@@ -272,21 +343,14 @@ xfs_attr_set_args(* Try to add the attr to the attribute list in the inode. */ error =xfs_attr_try_sf_addname (dp, args); -if (error != -ENOSPC ) { -if (dp->i_mount->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args->trans);
Where does the xfs_trans_set_sync call go? Do we not need it anymore?
Quoted 31 lines
fs/xfs/libxfs/xfs_attr.c +3
-15- error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; - } - +if (error != -ENOSPC ) +return error;/* * 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, leaf_bp);if (error)return error;@@ -294,43 +358,42 @@ xfs_attr_set_args(* Prevent the leaf buffer from being unlocked so that a * concurrent AIL push cannot grab the half-baked leaf * buffer and run into problems with the write verifier. -* Once we're done rolling the transaction we can release -* the hold and add the attr to the leaf. */ -xfs_trans_bhold (args->trans, leaf_bp); - error =xfs_defer_finish (&args->trans); -xfs_trans_bhold_release (args->trans, leaf_bp); -if (error) { -xfs_trans_brelse (args->trans, leaf_bp); -return error; - }
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 371
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ +xfs_trans_bhold (args->trans, *leaf_bp); + args->dc.dc_state =XFS_DC_SF_TO_LEAF ; +return -EAGAIN ; + } +sf_to_leaf: + +/* +* After a shortform to leaf conversion, we need to hold the leaf and +* cylce out the transaction. When we get back, we need to release
"cycle"
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+* the leaf. +*/ +if (*leaf_bp !=NULL ) { +xfs_trans_brelse (args->trans, *leaf_bp); + *leaf_bp =NULL ; }
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 387
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +8
-0if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_try_add (args, *leaf_bp); +if (error == -ENOSPC ) + args->dc.dc_state =XFS_DC_LEAF_TO_NODE ; +else if (error) +return error; +else + args->dc.dc_state =XFS_DC_FOUND_LBLK ; +return -EAGAIN ;
Please use a switch statement here...
switch (error) {
case -ENOSPC:
dc_state = LEAF_TO_NODE; return -EAGAIN; case 0: dc_state = FOUND_LBLK; return -EAGAIN; default: return error; }
Quoted 95 lines
fs/xfs/libxfs/xfs_attr.c +19
-51+leaf: error =xfs_attr_leaf_addname (args);if (error == -ENOSPC ) { -/* -* Commit that transaction so that the node_addname() -* call can manage its own transactions. -*/ - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - -/* -* Fob the rest of the problem off on the Btree code. -*/ - error =xfs_attr_node_addname (args); + args->dc.dc_state =XFS_DC_LEAF_TO_NODE ; +return -EAGAIN ; } }else { + args->dc.dc_state =XFS_DC_LEAF_TO_NODE ; +node: error =xfs_attr_node_addname (args); }return error;@@ -764,27 +827,26 @@ xfs_attr_leaf_try_add(* * This leaf block cannot have a "remote" value, we only call this routine * if bmap_one_block() says there is only one block (ie: no remote blks). +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +* returned. */ STATIC intxfs_attr_leaf_addname (struct xfs_da_args *args) { -int error, forkoff; -struct xfs_buf *bp =NULL ; +int error, nmap;struct xfs_inode *dp = args->dp; +struct xfs_bmbt_irec *map = &args->dc.map; -trace_xfs_attr_leaf_addname (args); - - error =xfs_attr_leaf_try_add (args, bp); -if (error) -return error; - -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_ALLOC_LEAF : + goto alloc_leaf; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we @@ -793,90 +855,58 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } -/* -* If this is an atomic rename operation, we must "flip" the -* incomplete flags on the "new" and "old" attribute/value pairs -* so that one disappears and one appears atomically. Then we -* must remove the "old" attribute/value pair. -*/ -if (args->op_flags &XFS_DA_OP_RENAME ) { -/* -* 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);
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname(struct xfs_da_args *args) · line 859
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +1
-9-if (error) -return error; -/* -* Commit the flag value change and start the next trans in -* series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; +/* Open coded xfs_attr_rmtval_set without trans handling */
Can't we just fix that instead of reproducing it here?
Especially because I think I see it twice in this patch?
Also, do you have a git tree handy? I /think/ I see how this works but oh man is it difficult to see that from patches alone.
--D
Quoted 342 lines
fs/xfs/libxfs/xfs_attr.c +91
-144-/* -* Dismantle the "old" attribute/value pair by removing -* a "remote" value (if it exists). -*/ - args->index = args->index2; - args->blkno = args->blkno2; - args->rmtblkno = args->rmtblkno2; - args->rmtblkcnt = args->rmtblkcnt2; - args->rmtvaluelen = args->rmtvaluelen2; -if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args); -if (error) -return error; - } + args->dc.lfileoff =0 ; + args->dc.lblkno =0 ; + args->dc.blkcnt =0 ; + args->rmtblkcnt =0 ; + args->rmtblkno =0 ; +memset (map,0 ,sizeof (struct xfs_bmbt_irec )); -/* -* Read in the block containing the "old" attr, then -* remove the "old" attr from that block (neat, huh!) -*/ - error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno, -XFS_DABUF_MAP_NOMAPPING , &bp); + error =xfs_attr_rmt_find_hole (args);if (error)return error; -xfs_attr3_leaf_remove (bp, args); + args->dc.blkcnt = args->rmtblkcnt; + args->dc.lblkno = args->rmtblkno;/* -* If the result is small enough, shrink it all into the inode. +* Roll through the "value", allocating blocks on disk as +* required. */ -if ((forkoff =xfs_attr_shortform_allfit (bp, dp))) { - error =xfs_attr3_leaf_to_shortform (bp, args, forkoff); -/* bp is gone due to xfs_da_shrink_inode */ -if (error) -return error; - error =xfs_defer_finish (&args->trans); +alloc_leaf: +while (args->dc.blkcnt >0 ) { + nmap =1 ; + error =xfs_bmapi_write (args->trans, dp, + (xfs_fileoff_t )args->dc.lblkno, + args->dc.blkcnt,XFS_BMAPI_ATTRFORK , + args->total, map, &nmap);if (error)return error; - } +ASSERT (nmap ==1 ); +ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && + (map->br_startblock !=HOLESTARTBLOCK )); -/* -* Commit the remove and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); +/* roll attribute extent map forwards */ + args->dc.lblkno += map->br_blockcount; + args->dc.blkcnt -= map->br_blockcount; - }else if (args->rmtblkno >0 ) { -/* -* Added a "remote" value, just clear the incomplete flag. -*/ - error =xfs_attr3_leaf_clearflag (args); + args->dc.dc_state =XFS_DC_ALLOC_LEAF ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; + } +if (args->rmtblkno >0 ) {/* -* Commit the flag value change and start the next trans in -* series. +* Added a "remote" value, just clear the incomplete flag. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr3_leaf_clearflag (args); }return error; }@@ -1017,16 +1047,23 @@ xfs_attr_node_hasname(* * "Remote" attribute values confuse the issue and atomic rename operations * add a whole extra layer of confusion on top of that. +* +* This routine is meant to function as a delayed operation, and may return +* -EAGAIN when the transaction needs to be rolled. Calling functions will need +* to handle this, and recall the function until a successful error code is +*returned. */ STATIC intxfs_attr_node_addname (struct xfs_da_args *args) { -struct xfs_da_state *state; +struct xfs_da_state *state =NULL ;struct xfs_da_state_blk *blk;struct xfs_inode *dp; -struct xfs_mount *mp; -int retval, error; +int retval =0 ; +int error =0 ; +int nmap; +struct xfs_bmbt_irec *map = &args->dc.map;trace_xfs_attr_node_addname (args);@@ -1034,8 +1071,17 @@ xfs_attr_node_addname(* Fill in bucket of arguments/results/context to carry around. */ dp = args->dp; - mp = dp->i_mount; -restart: + +/* State machine switch */ +switch (args->dc.dc_state) { +case XFS_DC_FOUND_NBLK : + goto found_nblk; +case XFS_DC_ALLOC_NODE : + goto alloc_node; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go. @@ -1085,19 +1131,12 @@ xfs_attr_node_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;/* -* Commit the node conversion and start the next -* trans in the chain. +* Restart routine from the top. No need to set the +* state */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - - goto restart; +return -EAGAIN ; }/* @@ -1109,9 +1148,6 @@ xfs_attr_node_addname( error =xfs_da3_split (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; }else {/* * Addition succeeded, update Btree hashvals. @@ -1126,13 +1162,9 @@ xfs_attr_node_addname(xfs_da_state_free (state); state =NULL ; -/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + args->dc.dc_state =XFS_DC_FOUND_NBLK ; +return -EAGAIN ; +found_nblk:/* * If there was an out-of-line value, allocate the blocks we @@ -1141,104 +1173,57 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); -if (error) -return error; - } +/* Open coded xfs_attr_rmtval_set without trans handling */ + args->dc.lblkno =0 ; + args->dc.lfileoff =0 ; + args->dc.blkcnt =0 ; + args->rmtblkcnt =0 ; + args->rmtblkno =0 ; +memset (map,0 ,sizeof (struct xfs_bmbt_irec )); -/* -* If this is an atomic rename operation, we must "flip" the -* incomplete flags on the "new" and "old" attribute/value pairs -* so that one disappears and one appears atomically. Then we -* must remove the "old" attribute/value pair. -*/ -if (args->op_flags &XFS_DA_OP_RENAME ) { -/* -* In a separate transaction, set the incomplete flag on the -* "old" attr and clear the incomplete flag on the "new" attr. -*/ - error =xfs_attr3_leaf_flipflags (args); -if (error) - goto out; -/* -* Commit the flag value change and start the next trans in -* series -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); + error =xfs_attr_rmt_find_hole (args);if (error) - goto out; +return error; + args->dc.blkcnt = args->rmtblkcnt; + args->dc.lblkno = args->rmtblkno;/* -* Dismantle the "old" attribute/value pair by removing -* a "remote" value (if it exists). +* Roll through the "value", allocating blocks on disk as +* required. */ - args->index = args->index2; - args->blkno = args->blkno2; - args->rmtblkno = args->rmtblkno2; - args->rmtblkcnt = args->rmtblkcnt2; - args->rmtvaluelen = args->rmtvaluelen2; -if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args); +alloc_node: +while (args->dc.blkcnt >0 ) { + nmap =1 ; + error =xfs_bmapi_write (args->trans, dp, + (xfs_fileoff_t )args->dc.lblkno, args->dc.blkcnt, +XFS_BMAPI_ATTRFORK , args->total, map, &nmap);if (error)return error; - } -/* -* 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->name.type |=XFS_ATTR_INCOMPLETE ; - state =xfs_da_state_alloc (); - state->args = args; - state->mp = mp; - state->inleaf =0 ; - error =xfs_da3_node_lookup_int (state, &retval); -if (error) - goto out; +ASSERT (nmap ==1 ); +ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && + (map->br_startblock !=HOLESTARTBLOCK )); -/* -* Remove the name and update the hashvals in the tree. -*/ - blk = &state->path.blk[ state->path.active-1 ]; -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - error =xfs_attr3_leaf_remove (blk->bp, args); -xfs_da3_fixhashpath (state, &state->path); +/* roll attribute extent map forwards */ + args->dc.lblkno += map->br_blockcount; + args->dc.blkcnt -= map->br_blockcount; -/* -* Check to see if the tree needs to be collapsed. -*/ -if (retval && (state->path.active >1 )) { - error =xfs_da3_join (state); -if (error) - goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; + args->dc.dc_state =XFS_DC_ALLOC_NODE ; +return -EAGAIN ; } -/* -* Commit and start the next trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); + error =xfs_attr_rmtval_set_value (args);if (error) - goto out; +return error; + } - }else if (args->rmtblkno >0 ) { +if (args->rmtblkno >0 ) {/* * Added a "remote" value, just clear the incomplete flag. */ error =xfs_attr3_leaf_clearflag (args);if (error) goto out; - -/* -* Commit the flag value change and start the next trans in -* series. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; } retval = error =0 ;fs/xfs/libxfs/xfs_attr.h +1
-0@@ -149,6 +149,7 @@ int xfs_attr_get(struct xfs_inode *ip, struct xfs_name *name,int xfs_attr_set (struct xfs_inode *dp,struct xfs_name *name,unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args); +int xfs_attr_set_later (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_remove (struct xfs_inode *dp,struct xfs_name *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args);Signature · 1 line
2.7.4