xfs: Delay Ready Attributes
v5 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 v4:
Mostly review updates and nits collected since v4. I've added an xfs_name_init to patch 2 to consolidate some of the initialization. The state machine is introduced in patch 13 and then expanded as needed 14. I've also adjusted some of the conditional logic in the delay ready routines such that we avoid nested gotos.
I've also made the corresponding updates to the user space side, and xfstests as well.
Questions, comment and feedback appreciated!
Thanks all!
Allison
Allison Collins (12):
xfs: Replace attribute parameters with struct xfs_name
xfs: Embed struct xfs_name in xfs_da_args
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 xfs_attr_try_sf_addname
xfs: Factor up trans roll from xfs_attr3_leaf_setflag
xfs: Factor out xfs_attr_rmtval_invalidate
xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
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 | 802 ++++++++++++++++++++++++++++------------ fs/xfs/libxfs/xfs_attr.h | 9 +- fs/xfs/libxfs/xfs_attr_leaf.c | 219 ++++++----- fs/xfs/libxfs/xfs_attr_leaf.h | 3 + fs/xfs/libxfs/xfs_attr_remote.c | 103 ++++-- fs/xfs/libxfs/xfs_attr_remote.h | 4 +- fs/xfs/libxfs/xfs_da_btree.c | 6 +- fs/xfs/libxfs/xfs_da_btree.h | 33 +- 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/libxfs/xfs_types.c | 10 + fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/scrub/attr.c | 12 +- fs/xfs/scrub/common.c | 2 + fs/xfs/xfs_acl.c | 26 +- fs/xfs/xfs_attr_list.c | 1 + fs/xfs/xfs_ioctl.c | 18 +- fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 8 +- fs/xfs/xfs_trace.h | 20 +- fs/xfs/xfs_xattr.c | 21 +- 24 files changed, 918 insertions(+), 450 deletions(-)
Signature · 1 line
2.7.4
PATCH v5 1/14 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
@@ -145,7 +145,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) {/*
@@ -196,15 +197,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
@@ -357,6 +357,7 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; +size_t namelen;if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;
@@ -364,7 +365,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;
@@ -386,6 +389,7 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; +size_t namelen;if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;
@@ -396,7 +400,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);
@@ -410,10 +415,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
@@ -50,8 +50,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
@@ -24,6 +24,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) {
@@ -31,7 +32,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;
@@ -67,6 +69,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 )
@@ -75,9 +78,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
PATCH v5 2/14 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/libxfs/xfs_types.c | 10 ++++++++++ fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/xfs_acl.c | 27 +++++++++++++-------------- fs/xfs/xfs_ioctl.c | 23 +++++++++++++---------- fs/xfs/xfs_iops.c | 6 +++--- fs/xfs/xfs_xattr.c | 23 +++++++++++++---------- 8 files changed, 67 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/libxfs/xfs_types.c +10 -0
@@ -12,6 +12,16 @@#include "xfs_bit.h" #include "xfs_mount.h" +/* Initialize a struct xfs_name with a null terminated string name */ +void +xfs_name_init ( +struct xfs_name *xname, +const char *name) +{ + xname->name = name; + xname->len = (strlen (name)); +} +/* Find the size of the AG, in blocks. */ xfs_agblock_t xfs_ag_block_count(
fs/xfs/libxfs/xfs_types.h +1 -0
@@ -180,6 +180,7 @@ enum xfs_ag_resv_type {*/ struct xfs_mount ; +void xfs_name_init (struct xfs_name *xname,const char *name);xfs_agblock_t xfs_ag_block_count (struct xfs_mount *mp,xfs_agnumber_t agno);bool xfs_verify_agbno (struct xfs_mount *mp,xfs_agnumber_t agno,xfs_agblock_t agbno);
fs/xfs/xfs_acl.c +13 -14
@@ -123,7 +123,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;
@@ -131,10 +131,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 ();
@@ -145,9 +145,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 ); +xfs_name_init (&name, 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
@@ -167,17 +167,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 ;
@@ -197,17 +197,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 ); +xfs_name_init (&name, 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 +13 -10
@@ -357,7 +357,9 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, name);if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;
@@ -365,9 +367,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;
@@ -389,7 +389,9 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, name);if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;
@@ -400,8 +402,7 @@ 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); + error =xfs_attr_set (XFS_I (inode), &xname, kbuf, len, flags);if (!error)xfs_forget_acl (inode, name, flags);kfree (kbuf);
@@ -415,12 +416,14 @@ xfs_attrmulti_attr_remove( uint32_t flags) {int error; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, 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 +3 -3
@@ -48,11 +48,11 @@ xfs_initxattrs(const struct xattr *xattr;struct xfs_inode *ip =XFS_I (inode);int error =0 ; +struct xfs_name name;for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { - error =xfs_attr_set (ip, xattr->name, -strlen (xattr->name), - xattr->value, xattr->value_len, +xfs_name_init (&name, xattr->name); + error =xfs_attr_set (ip, &name, xattr->value, xattr->value_len,ATTR_SECURE );if (error <0 )break ;
fs/xfs/xfs_xattr.c +13 -10
@@ -21,10 +21,12 @@ 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; + +xfs_name_init (&xname, name);/* Convert Linux syscall to XFS internal ATTR flags */ if (!size) {
@@ -32,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;
@@ -69,7 +71,9 @@ 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; + +xfs_name_init (&xname, name);/* Convert Linux syscall to XFS internal ATTR flags */ if (flags &XATTR_CREATE )
@@ -78,9 +82,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 v5 02/14] xfs: Replace attribute parameters with struct xfs_name
Quoted 16 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/libxfs/xfs_types.c | 10 ++++++++++ fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/xfs_acl.c | 27 +++++++++++++-------------- fs/xfs/xfs_ioctl.c | 23 +++++++++++++---------- fs/xfs/xfs_iops.c | 6 +++--- fs/xfs/xfs_xattr.c | 23 +++++++++++++---------- 8 files changed, 67 insertions(+), 57 deletions(-)
...
Quoted 6 lines
fs/xfs/libxfs/xfs_types.c +0
-0@@ -12,6 +12,16 @@#include "xfs_bit.h"
fs/xfs/libxfs/xfs_types.c line 22
Quoted 10 lines
fs/xfs/libxfs/xfs_types.c +8
-0#include "xfs_mount.h" +/* Initialize a struct xfs_name with a null terminated string name */ +void +xfs_name_init ( +struct xfs_name *xname, +const char *name) +{ + xname->name = name; + xname->len = (strlen (name));
Are the extra braces necessary here? Also, perhaps we should initialize ->type to zero or something so it doesn't carry garbage data.
Quoted 5 lines
fs/xfs/libxfs/xfs_types.c +2
-0+} +/* Find the size of the AG, in blocks. */ xfs_agblock_t xfs_ag_block_count(
...
Quoted 27 lines
fs/xfs/xfs_acl.c +3
-3@@ -123,7 +123,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;@@ -131,10 +131,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 ();
fs/xfs/xfs_acl.c xfs_get_acl(struct inode *inode, int type) · line 148
Quoted 7 lines
fs/xfs/xfs_acl.c +1
-3@@ -145,9 +145,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 ); +xfs_name_init (&name, name.name);
Could we call xfs_name_init() in the switch branches above to avoid this partial init weirdness? Same question applies below, otherwise looks Ok to me.
Brian
Quoted 190 lines
fs/xfs/xfs_acl.c +9
-8+ 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 @@ -167,17 +167,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 ;@@ -197,17 +197,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 ); +xfs_name_init (&name, 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 +13
-10@@ -357,7 +357,9 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, name);if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;@@ -365,9 +367,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;@@ -389,7 +389,9 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, name);if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;@@ -400,8 +402,7 @@ 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); + error =xfs_attr_set (XFS_I (inode), &xname, kbuf, len, flags);if (!error)xfs_forget_acl (inode, name, flags);kfree (kbuf);@@ -415,12 +416,14 @@ xfs_attrmulti_attr_remove( uint32_t flags) {int error; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, 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 +3
-3@@ -48,11 +48,11 @@ xfs_initxattrs(const struct xattr *xattr;struct xfs_inode *ip =XFS_I (inode);int error =0 ; +struct xfs_name name;for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { - error =xfs_attr_set (ip, xattr->name, -strlen (xattr->name), - xattr->value, xattr->value_len, +xfs_name_init (&name, xattr->name); + error =xfs_attr_set (ip, &name, xattr->value, xattr->value_len,ATTR_SECURE );if (error <0 )break ;fs/xfs/xfs_xattr.c +13
-10@@ -21,10 +21,12 @@ 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; + +xfs_name_init (&xname, name);/* Convert Linux syscall to XFS internal ATTR flags */ if (!size) {@@ -32,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;@@ -69,7 +71,9 @@ 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; + +xfs_name_init (&xname, name);/* Convert Linux syscall to XFS internal ATTR flags */ if (flags &XATTR_CREATE )@@ -78,9 +82,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 v5 02/14] xfs: Replace attribute parameters with struct xfs_name
Quoted 26 lines · Brian Foster
Quoted 16 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/libxfs/xfs_types.c | 10 ++++++++++ fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/xfs_acl.c | 27 +++++++++++++-------------- fs/xfs/xfs_ioctl.c | 23 +++++++++++++---------- fs/xfs/xfs_iops.c | 6 +++--- fs/xfs/xfs_xattr.c | 23 +++++++++++++---------- 8 files changed, 67 insertions(+), 57 deletions(-)...
Quoted 8 lines
fs/xfs/libxfs/xfs_types.c +0
-0@@ -12,6 +12,16 @@#include "xfs_bit.h" #include "xfs_mount.h"
Quoted 11 lines
fs/xfs/libxfs/xfs_types.c line 22
Quoted 8 lines
fs/xfs/libxfs/xfs_types.c +8
-0+/* Initialize a struct xfs_name with a null terminated string name */ +void +xfs_name_init ( +struct xfs_name *xname, +const char *name) +{ + xname->name = name; + xname->len = (strlen (name));Are the extra braces necessary here? Also, perhaps we should initialize ->type to zero or something so it doesn't carry garbage data.
I may have borrowed the extra braces from somewhere else in the code. Will clean out and also add the type init.
Quoted 46 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_types.c +2
-0+} +/* Find the size of the AG, in blocks. */ xfs_agblock_t xfs_ag_block_count(...
Quoted 27 lines
fs/xfs/xfs_acl.c +3
-3@@ -123,7 +123,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;@@ -131,10 +131,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 ();fs/xfs/xfs_acl.c xfs_get_acl(struct inode *inode, int type) · line 148
Quoted 7 lines
fs/xfs/xfs_acl.c +1
-3@@ -145,9 +145,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 ); +xfs_name_init (&name, name.name);Could we call
xfs_name_init()in the switch branches above to avoid this partial init weirdness? Same question applies below, otherwise looks Ok to me.
Quoted 1 line
Brian
Sure, I will scoot that up. Thx!
Allison
Quoted 192 lines
Quoted 191 lines
fs/xfs/xfs_acl.c +9
-8+ 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 @@ -167,17 +167,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 ;@@ -197,17 +197,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 ); +xfs_name_init (&name, 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 +13
-10@@ -357,7 +357,9 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, name);if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;@@ -365,9 +367,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;@@ -389,7 +389,9 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, name);if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;@@ -400,8 +402,7 @@ 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); + error =xfs_attr_set (XFS_I (inode), &xname, kbuf, len, flags);if (!error)xfs_forget_acl (inode, name, flags);kfree (kbuf);@@ -415,12 +416,14 @@ xfs_attrmulti_attr_remove( uint32_t flags) {int error; -size_t namelen; +struct xfs_name xname; + +xfs_name_init (&xname, 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 +3
-3@@ -48,11 +48,11 @@ xfs_initxattrs(const struct xattr *xattr;struct xfs_inode *ip =XFS_I (inode);int error =0 ; +struct xfs_name name;for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { - error =xfs_attr_set (ip, xattr->name, -strlen (xattr->name), - xattr->value, xattr->value_len, +xfs_name_init (&name, xattr->name); + error =xfs_attr_set (ip, &name, xattr->value, xattr->value_len,ATTR_SECURE );if (error <0 )break ;fs/xfs/xfs_xattr.c +13
-10@@ -21,10 +21,12 @@ 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; + +xfs_name_init (&xname, name);/* Convert Linux syscall to XFS internal ATTR flags */ if (!size) {@@ -32,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;@@ -69,7 +71,9 @@ 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; + +xfs_name_init (&xname, name);/* Convert Linux syscall to XFS internal ATTR flags */ if (flags &XATTR_CREATE )@@ -78,9 +82,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
PATCH v5 3/14 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 | 39 ++++++++------- fs/xfs/libxfs/xfs_attr_leaf.c | 106 +++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_attr_remote.c | 2 +- fs/xfs/libxfs/xfs_da_btree.c | 6 ++- 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, 132 insertions(+), 125 deletions(-)
fs/xfs/libxfs/xfs_attr.c +22 -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 ) +memcpy (&args->name, name,sizeof (struct xfs_name )); + args->name.type = flags; +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 (name->len, valuelen); error =xfs_bmap_add_attrfork (dp, sf_size, rsvd);if (error)
@@ -457,6 +459,9 @@ xfs_attr_remove(if (error)return error; +/* Use name now stored in args */ + name = &args.name; +/* * we have no control over the attribute names that userspace passes us * to remove, so we have to allow the name lookup prior to attribute
@@ -532,10 +537,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 +550,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 +603,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 +877,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 +1012,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
@@ -380,7 +380,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 +4 -2
@@ -2125,8 +2125,10 @@ 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; + if (args->name.len == len && !memcmp(args->name.name, name, len)) + return XFS_CMP_EXACT; + +return XFS_CMP_DIFFERENT ; }int
fs/xfs/libxfs/xfs_da_btree.h +1 -3
@@ -54,12 +54,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 ; }
@@ -265,8 +265,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 =xfs_dir2_hashname (dp->i_mount, name); args->inumber = inum;
@@ -361,8 +360,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 =xfs_dir2_hashname (dp->i_mount, name); args->dp = dp;
@@ -433,8 +431,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 =xfs_dir2_hashname (dp->i_mount, name); args->inumber = ino;
@@ -494,8 +491,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 =xfs_dir2_hashname (dp->i_mount, 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 =xfs_dir2_data_entsize (dp->i_mount, args->namelen); + len =xfs_dir2_data_entsize (dp->i_mount, 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);xfs_dir2_data_put_ftype (dp->i_mount, dep, args->filetype); tagp =xfs_dir2_data_entry_tag_p (dp->i_mount, dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_leaf.c +3 -3
@@ -653,7 +653,7 @@ xfs_dir2_leaf_addname(xfs_dir2_leaf_hdr_from_disk (dp->i_mount, &leafhdr, leaf); ents = leafhdr.ents; bestsp =xfs_dir2_leaf_bests_p (ltp); - length =xfs_dir2_data_entsize (dp->i_mount, args->namelen); + length =xfs_dir2_data_entsize (dp->i_mount, args->name.len);/* * See if there are any entries with the same hash value
@@ -856,8 +856,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);xfs_dir2_data_put_ftype (dp->i_mount, dep, args->filetype); tagp =xfs_dir2_data_entry_tag_p (dp->i_mount, dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_node.c +4 -4
@@ -666,7 +666,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 =xfs_dir2_data_entsize (mp, args->namelen); + length =xfs_dir2_data_entsize (mp, args->name.len);/* * Loop over leaf entries with the right hash value. */
@@ -1911,7 +1911,7 @@ xfs_dir2_node_addname_int(int needscan =0 ;/* need to rescan data frees */ __be16 *tagp;/* data entry tag pointer */ - length =xfs_dir2_data_entsize (dp->i_mount, args->namelen); + length =xfs_dir2_data_entsize (dp->i_mount, args->name.len); error =xfs_dir2_node_find_freeblk (args, fblk, &dbno, &fbp, &freehdr, &findex, length);if (error)
@@ -1966,8 +1966,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);xfs_dir2_data_put_ftype (dp->i_mount, dep, args->filetype); tagp =xfs_dir2_data_entry_tag_p (dp->i_mount, dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr);
fs/xfs/libxfs/xfs_dir2_sf.c +15 -15
@@ -387,7 +387,7 @@ xfs_dir2_sf_addname(/* * Compute entry (and change in) size. */ - incr_isize =xfs_dir2_sf_entsize (dp->i_mount, sfp, args->namelen); + incr_isize =xfs_dir2_sf_entsize (dp->i_mount, sfp, args->name.len); objchange =0 ;/*
@@ -470,7 +470,7 @@ xfs_dir2_sf_addname_easy(/* * Grow the in-inode space. */ -xfs_idata_realloc (dp,xfs_dir2_sf_entsize (mp, sfp, args->namelen), +xfs_idata_realloc (dp,xfs_dir2_sf_entsize (mp, sfp, args->name.len),XFS_DATA_FORK );/* * Need to set up again due to realloc of the inode data.
@@ -480,9 +480,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);xfs_dir2_sf_put_ino (mp, sfp, sfep, args->inumber);xfs_dir2_sf_put_ftype (mp, sfep, args->filetype);
@@ -540,7 +540,7 @@ xfs_dir2_sf_addname_hard(*/ for (offset = args->geo->data_first_offset, oldsfep = xfs_dir2_sf_firstentry(oldsfp), - add_datasize = xfs_dir2_data_entsize(mp, args->namelen), + add_datasize = xfs_dir2_data_entsize(mp, args->name.len), eof = (char *)oldsfep == &buf[old_isize]; !eof; offset = new_offset + xfs_dir2_data_entsize(mp, oldsfep->namelen),
@@ -570,9 +570,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);xfs_dir2_sf_put_ino (mp, sfp, sfep, args->inumber);xfs_dir2_sf_put_ftype (mp, sfep, args->filetype); sfp->count++;
@@ -615,7 +615,7 @@ xfs_dir2_sf_addname_pick(int used;/* data bytes used */ sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; - size =xfs_dir2_data_entsize (mp, args->namelen); + size =xfs_dir2_data_entsize (mp, args->name.len); offset = args->geo->data_first_offset; sfep =xfs_dir2_sf_firstentry (sfp); holefit =0 ;
@@ -887,7 +887,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 ;
@@ -896,8 +896,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 =xfs_dir2_sf_get_parent_ino (sfp); args->cmpresult =XFS_CMP_EXACT ; args->filetype =XFS_DIR3_FT_DIR ;
@@ -984,7 +984,7 @@ xfs_dir2_sf_removename(* Calculate sizes. */ byteoff = (int )((char *)sfep - (char *)sfp); - entsize =xfs_dir2_sf_entsize (mp, sfp, args->namelen); + entsize =xfs_dir2_sf_entsize (mp, sfp, args->name.len); newsize = oldsize - entsize;/* * Copy the part if any after the removed entry, sliding it down.
@@ -1085,12 +1085,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 =xfs_dir2_sf_get_parent_ino (sfp);ASSERT (args->inumber != ino);xfs_dir2_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
PATCH v5 4/14 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 appearance 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 | 166 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 110 +++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 + 4 files changed, 182 insertions(+), 98 deletions(-)
fs/xfs/libxfs/xfs_attr.c +109 -57
@@ -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,36 @@ 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; + +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_sf_findname (args,NULL ,NULL ); + } + +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { +struct xfs_buf *bp =NULL ; +int error =xfs_attr_leaf_hasname (args, &bp); + +if (bp) +xfs_trans_brelse (args->trans, bp); + +return error; + } + +return xfs_attr_node_hasname (args,NULL ); +} + +/* * Remove the attribute specified in @args. */ int
@@ -583,26 +616,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, &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;
@@ -754,6 +781,23 @@ 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 , 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
@@ -773,12 +817,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, &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;
@@ -817,12 +860,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, &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 +873,41 @@ 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; + +if (statep !=NULL ) + *statep =NULL ; + +/* +* Search to see if name exists, and get back a pointer to it. +*/ + error =xfs_da3_node_lookup_int (state, &retval); +if (error ==0 ) { +if (statep !=NULL ) + *statep = state; +return retval; + } + +xfs_da_state_free (state); + +return error; +} +/*======================================================================== * External routines when attribute list size > geo->blksize *========================================================================*/
@@ -864,20 +940,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 +1152,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.
@@ -1196,7 +1255,8 @@ xfs_attr_node_removename( error =0 ; out: -xfs_da_state_free (state); +if (state) +xfs_da_state_free (state);return error; }
@@ -1316,31 +1376,23 @@ xfs_attr_node_get(xfs_da_args_t *args) {xfs_da_state_t *state;xfs_da_state_blk_t *blk; -int error, retval; +int error;int i;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) { - retval = error; - goto out_release; - } -if (retval != -EEXIST ) + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) goto out_release;/* * Get the value, local or "remote" */ blk = &state->path.blk[state->path.active -1 ]; - retval =xfs_attr3_leaf_getvalue (blk->bp, args); + error =xfs_attr3_leaf_getvalue (blk->bp, args);/* * If not in a transaction, we have to release all the buffers.
@@ -1352,7 +1404,7 @@ xfs_attr_node_get(xfs_da_args_t *args) }xfs_da_state_free (state); -return retval; +return error; }/* Returns true if the attribute entry name is valid. */
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 +69 -41
140 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_leaf.h +3 -0
@@ -62,6 +62,9 @@ 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_sf_findname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep, +unsigned 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 v5 04/14] xfs: Add xfs_has_attr and subroutines
Quoted 22 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 appearance 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 | 166 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 110 +++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 + 4 files changed, 182 insertions(+), 98 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 14 lines
fs/xfs/libxfs/xfs_attr.c +10
-0@@ -310,6 +313,36 @@ 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; + +if (!xfs_inode_hasattr (dp)) +return -ENOATTR ;
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 335
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ +if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); +return xfs_attr_sf_findname (args,NULL ,NULL ); + } + +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { +struct xfs_buf *bp =NULL ; +int error =xfs_attr_leaf_hasname (args, &bp); +
I'd prefer to not obfuscate function calls in variable declarations like this. I'd say just declare bp and error at the top and let this be:
error = xfs_attr_leaf_hasname(...)
Quoted 32 lines
fs/xfs/libxfs/xfs_attr.c +11
-8+if (bp) +xfs_trans_brelse (args->trans, bp); + +return error; + } + +return xfs_attr_node_hasname (args,NULL ); +} + +/* * Remove the attribute specified in @args. */ int @@ -583,26 +616,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, &bp); -if (error) -return error;
fs/xfs/libxfs/xfs_attr.c STATIC int · line 632
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +4
-3- -/* * 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; +
Do we need to call xfs_trans_brelse() in certain cases before we return? For example, consider if the read succeeds but the lookup returns something other than -ENOATTR or -EEXIST. Perhaps the _hasname() func should just call brelse() itself if it's returning an unexpected error after reading in the buf so the caller doesn't need to care about it..
Quoted 3 lines
fs/xfs/libxfs/xfs_attr.c +0
-0if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) {xfs_trans_brelse (args->trans, bp);return retval;
...
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0
-3@@ -864,20 +940,17 @@ xfs_attr_node_addname( dp = args->dp; mp = dp->i_mount; restart: - state =xfs_da_state_alloc (); - state->args = args; - state->mp = mp;
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 949
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-3-/* * 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;
The else case below checks for -EEXIST, but it looks like we'd return here..
Brian
Quoted 272 lines
fs/xfs/libxfs/xfs_attr.c +12
-32+ 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 +1152,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. @@ -1196,7 +1255,8 @@ xfs_attr_node_removename( error =0 ; out: -xfs_da_state_free (state); +if (state) +xfs_da_state_free (state);return error; }@@ -1316,31 +1376,23 @@ xfs_attr_node_get(xfs_da_args_t *args) {xfs_da_state_t *state;xfs_da_state_blk_t *blk; -int error, retval; +int error;int i;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) { - retval = error; - goto out_release; - } -if (retval != -EEXIST ) + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) goto out_release;/* * Get the value, local or "remote" */ blk = &state->path.blk[state->path.active -1 ]; - retval =xfs_attr3_leaf_getvalue (blk->bp, args); + error =xfs_attr3_leaf_getvalue (blk->bp, args);/* * If not in a transaction, we have to release all the buffers. @@ -1352,7 +1404,7 @@ xfs_attr_node_get(xfs_da_args_t *args) }xfs_da_state_free (state); -return retval; +return error; }/* Returns true if the attribute entry name is valid. */ 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 +69
-41@@ -654,18 +654,66 @@ 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_sf_findname ( +struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep, +unsigned int *basep) +{ +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +unsigned int base =sizeof (struct xfs_attr_sf_hdr ); +int size =0 ; +int end; +int i; + + 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_add (struct xfs_da_args *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);@@ -676,18 +724,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_sf_findname (args, &sfe,NULL ); +ASSERT (error != -EEXIST ); offset = (char *)sfe - (char *)sf; size =XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen);@@ -730,35 +768,25 @@ xfs_attr_fork_remove(* Remove an attribute from the shortform attribute list structure. */ int -xfs_attr_shortform_remove (xfs_da_args_t *args) +xfs_attr_shortform_remove (struct xfs_da_args *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_sf_findname (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 +3
-0@@ -62,6 +62,9 @@ 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_sf_findname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep, +unsigned 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 v5 04/14] xfs: Add xfs_has_attr and subroutines
Quoted 43 lines · Brian Foster
Quoted 22 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 appearance 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 | 166 +++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 110 +++++++++++++++++----------- fs/xfs/libxfs/xfs_attr_leaf.h | 3 + 4 files changed, 182 insertions(+), 98 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +15
-0@@ -310,6 +313,36 @@ 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; + +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_sf_findname (args,NULL ,NULL ); + }
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 335
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+ +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { +struct xfs_buf *bp =NULL ; +int error =xfs_attr_leaf_hasname (args, &bp); +I'd prefer to not obfuscate function calls in variable declarations like this. I'd say just declare bp and error at the top and let this be:
Sure, this style was a suggestion from Christoph in the last review so I tried to combine everyones requests as best as possible. I'm not very particular about the aesthetics, so I don't mind moving things around, but if people feel strongly one way or another, please chime in.
Quoted 43 lines
error = xfs_attr_leaf_hasname(...)Quoted 40 lines
fs/xfs/libxfs/xfs_attr.c +13
-11+if (bp) +xfs_trans_brelse (args->trans, bp); + +return error; + } + +return xfs_attr_node_hasname (args,NULL ); +} + +/* * Remove the attribute specified in @args. */ int @@ -583,26 +616,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, &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 )
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c STATIC int · line 632
Quoted 2 lines
fs/xfs/libxfs/xfs_attr.c +2
-0+return retval; +Do we need to call
xfs_trans_brelse()in certain cases before we return? For example, consider if the read succeeds but the lookup returns something other than-ENOATTRor-EEXIST. Perhaps the_hasname()func should just callbrelse()itself if it's returning an unexpected error after reading in the buf so the caller doesn't need to care about it..
Generally it should be released at some point if the call is successful (so on -EEXIST). Later when we get into the state machine, we don't release right away, because we need to hold it across the transaction rolls.
I think though I might be able to factor up releasing the buffer on error though. I'll see if I can work that into the next version.
Quoted 26 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +0
-0if ((args->name.type &ATTR_REPLACE ) && (retval == -ENOATTR )) {xfs_trans_brelse (args->trans, bp);return retval;...
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +0
-3@@ -864,20 +940,17 @@ xfs_attr_node_addname( dp = args->dp; mp = dp->i_mount; restart: - state =xfs_da_state_alloc (); - state->args = args; - state->mp = mp;fs/xfs/libxfs/xfs_attr.c xfs_attr_node_addname( · line 949
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +2
-3-/* * 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;The else case below checks for
-EEXIST, but it looks like we'd return here..
Quoted 1 line
Brian
Ok, will clean out. Thx!
Allison
Quoted 274 lines
Quoted 273 lines
fs/xfs/libxfs/xfs_attr.c +12
-32+ 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 +1152,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. @@ -1196,7 +1255,8 @@ xfs_attr_node_removename( error =0 ; out: -xfs_da_state_free (state); +if (state) +xfs_da_state_free (state);return error; }@@ -1316,31 +1376,23 @@ xfs_attr_node_get(xfs_da_args_t *args) {xfs_da_state_t *state;xfs_da_state_blk_t *blk; -int error, retval; +int error;int i;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) { - retval = error; - goto out_release; - } -if (retval != -EEXIST ) + error =xfs_attr_node_hasname (args, &state); +if (error != -EEXIST ) goto out_release;/* * Get the value, local or "remote" */ blk = &state->path.blk[state->path.active -1 ]; - retval =xfs_attr3_leaf_getvalue (blk->bp, args); + error =xfs_attr3_leaf_getvalue (blk->bp, args);/* * If not in a transaction, we have to release all the buffers. @@ -1352,7 +1404,7 @@ xfs_attr_node_get(xfs_da_args_t *args) }xfs_da_state_free (state); -return retval; +return error; }/* Returns true if the attribute entry name is valid. */ 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 +69
-41@@ -654,18 +654,66 @@ 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_sf_findname ( +struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep, +unsigned int *basep) +{ +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +unsigned int base =sizeof (struct xfs_attr_sf_hdr ); +int size =0 ; +int end; +int i; + + 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_add (struct xfs_da_args *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);@@ -676,18 +724,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_sf_findname (args, &sfe,NULL ); +ASSERT (error != -EEXIST ); offset = (char *)sfe - (char *)sf; size =XFS_ATTR_SF_ENTSIZE_BYNAME (args->name.len, args->valuelen);@@ -730,35 +768,25 @@ xfs_attr_fork_remove(* Remove an attribute from the shortform attribute list structure. */ int -xfs_attr_shortform_remove (xfs_da_args_t *args) +xfs_attr_shortform_remove (struct xfs_da_args *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_sf_findname (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 +3
-0@@ -62,6 +62,9 @@ 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_sf_findname (struct xfs_da_args *args, +struct xfs_attr_sf_entry **sfep, +unsigned 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 v5 04/14] xfs: Add xfs_has_attr and subroutines
In reply to Allison CollinsQuoted 9 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 appearance of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Can you explain why we need the ahead of time check? The first operation should be able to still return an error, and doing a separate check instead of letting the actual operation fail gracefully is more expensive, and also creates a lot of additional code. As is I can't say I like the direction at all.
Re: [PATCH v5 04/14] xfs: Add xfs_has_attr and subroutines
Quoted 11 lines · Christoph Hellwig
Quoted 9 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 appearance of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Quoted 6 lines
Can you explain why we need the ahead of time check? The first operation should be able to still return an error, and doing a separate check instead of letting the actual operation fail gracefully is more expensive, and also creates a lot of additional code. As is I can't say I like the direction at all.
This one I can answer quickly: later when we get into delayed attributes, this will get called from xfs_defer_finish_noroll as part of a .finish_item call back. If these callbacks return anything other than 0 or -EAGAIN, it causes a shutdown. Which is not what we would want for example: when the user tries to rename a non-existent attribute. The error code needs to go back up. So we check for things like that before starting a delayed operation. Hope that helps. Thanks!
Allison
Re: [PATCH v5 04/14] xfs: Add xfs_has_attr and subroutines
Quoted 19 lines · Allison Collins
Quoted 11 lines · Christoph Hellwig
Quoted 9 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 appearance of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Quoted 6 lines
Can you explain why we need the ahead of time check? The first operation should be able to still return an error, and doing a separate check instead of letting the actual operation fail gracefully is more expensive, and also creates a lot of additional code. As is I can't say I like the direction at all.
Quoted 4 lines
This one I can answer quickly: later when we get into delayed attributes, this will get called from
xfs_defer_finish_norollas part of a .finish_item call back. If these callbacks return anything other than 0 or-EAGAIN, it causes a shutdown.
When does this happen, exactly? Are you saying that during log recovery, we can end up replaying a delayed attr log item that hits ENOATTR/EEXIST somewhere and passes that out, which causes log recovery to fail?
Quoted 4 lines
Which is not what we would want for example: when the
user tries to rename a non-existent attribute. The error code needs to go back up. So we check for things like that before starting a delayed operation. Hope that helps. Thanks!
...because as far as requests from user programs goes, we should be doing all these precondition checks after allocating a transaction and ILOCKing the inode, so that we can send the error code back to userspace without cancelling a dirty transaction.
(I dunno, am I misunderstanding here?)
Quoted 1 line
Allison
Re: [PATCH v5 04/14] xfs: Add xfs_has_attr and subroutines
Quoted 20 lines · Darrick J. Wong
Quoted 19 lines · Allison Collins
Quoted 17 lines · Christoph Hellwig
Quoted 9 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 appearance of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Can you explain why we need the ahead of time check? The first operation should be able to still return an error, and doing a separate check instead of letting the actual operation fail gracefully is more expensive, and also creates a lot of additional code. As is I can't say I like the direction at all.
Quoted 6 lines
Quoted 4 lines
This one I can answer quickly: later when we get into delayed attributes, this will get called from
xfs_defer_finish_norollas part of a .finish_item call back. If these callbacks return anything other than 0 or-EAGAIN, it causes a shutdown.When does this happen, exactly?
Sure, lets take a look at fs/xfs/libxfs/xfs_defer.c line 399 We have the callback invocation:
error = ops->finish_item(*tp, li, dfp->dfp_done, &state);
This is where the intent items get to finish out their operations. If they return -EAGAIN, they get get put back in the list, but if they error out, we jump to the error handler (line 445), where we abort the transaction and do a shutdown.
Now, if we peek ahead at the first patch that belongs to the next delayed attribute series:
https://github.com/allisonhenderson/xfs_work/commit/7d5b7395fe3b1df7739089c0643e20b09de2e0b0
If you expand the diff for fs/xfs/xfs_attr_item.c, and zip down to line 269, you'll see a ".finish_item = xfs_attr_finish_item". This callback will do some leg work to unwrap the log item and feed the appropriate parameters back into xfs_attr_set_iter. So this is why we go through all the trouble to check for any expected errors ahead of time.
Are you saying that during log
Quoted 3 lines
recovery, we can end up replaying a delayed attr log item that hits ENOATTR/EEXIST somewhere and passes that out, which causes log recovery to fail?
Well, the idea is to avoid that with this helper function. Reading ahead, it looks like you've already connected the two :-)
Quoted 10 lines
Quoted 5 lines
Which is not what we would want for example: when the
user tries to rename a non-existent attribute. The error code needs to go back up. So we check for things like that before starting a delayed operation. Hope that helps. Thanks!...because as far as requests from user programs goes, we should be doing all these precondition checks after allocating a transaction and ILOCKing the inode, so that we can send the error code back to userspace without cancelling a dirty transaction.
Yes, we do that later in the set, but I think you've got it ;-)
Allison
Quoted 4 lines
(I dunno, am I misunderstanding here?)
Quoted 1 line
Allison
Re: [PATCH v5 04/14] xfs: Add xfs_has_attr and subroutines
I was thinking of adapting this patch to be part of a 3 patch series including one of Chistophs. Something like this:
[PATCH v6 11/16] xfs: Check for -ENOATTR or -EEXIST [PATCH v6 03/16] xfs: Add xfs_has_attr and subroutines [PATCH 02/29] xfs: merge xfs_attr_remove into xfs_attr_set
What would people think of that? I figured this would be better than the two of us bombarding the mailing list with giant conflicting sets? Also, was I able to answer everyones questions on this patch?
Thanks!
Allison
Quoted 70 lines · Allison Collins
Quoted 20 lines · Darrick J. Wong
Quoted 19 lines · Allison Collins
Quoted 17 lines · Christoph Hellwig
Quoted 9 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 appearance of duplicated code. We will need these routines later for delayed attributes since delayed operations cannot return error codes.
Can you explain why we need the ahead of time check? The first operation should be able to still return an error, and doing a separate check instead of letting the actual operation fail gracefully is more expensive, and also creates a lot of additional code. As is I can't say I like the direction at all.
Quoted 7 lines
Quoted 5 lines
This one I can answer quickly: later when we get into delayed attributes, this will get called from
xfs_defer_finish_norollas part of a .finish_item call back. If these callbacks return anything other than 0 or-EAGAIN, it
causes a shutdown.When does this happen, exactly?
Sure, lets take a look at
fs/xfs/libxfs/xfs_defer.cline 399 We have the callback invocation:
error =ops->finish_item(*tp, li, dfp->dfp_done, &state);This is where the intent items get to finish out their operations. If they return
-EAGAIN, they get get put back in the list, but if they error out, we jump to the error handler (line 445), where we abort the transaction and do a shutdown.Now, if we peek ahead at the first patch that belongs to the next delayed attribute series:
https://github.com/allisonhenderson/xfs_work/commit/7d5b7395fe3b1df7739089c0643e20b09de2e0b0
If you expand the diff for
fs/xfs/xfs_attr_item.c, and zip down to line 269, you'll see a ".finish_item = xfs_attr_finish_item". This callback will do some leg work to unwrap the log item and feed the appropriate parameters back into xfs_attr_set_iter. So this is why we go through all the trouble to check for any expected errors ahead of time.Are you saying that during log
Quoted 3 lines
recovery, we can end up replaying a delayed attr log item that hits ENOATTR/EEXIST somewhere and passes that out, which causes log recovery to fail?
Well, the idea is to avoid that with this helper function. Reading ahead, it looks like you've already connected the two :-)
Quoted 10 lines
Quoted 5 lines
Which is not what we would want for example: when the
user tries to rename a non-existent attribute. The error code needs to go back up. So we check for things like that before starting a delayed operation. Hope that helps. Thanks!...because as far as requests from user programs goes, we should be doing all these precondition checks after allocating a transaction and ILOCKing the inode, so that we can send the error code back to userspace without cancelling a dirty transaction.
Yes, we do that later in the set, but I think you've got it ;-)
Allison
Quoted 4 lines
(I dunno, am I misunderstanding here?)
Quoted 1 line
Allison
Re: [PATCH v5 04/14] xfs: Add xfs_has_attr and subroutines
Quoted 10 lines · Allison Collins
I was thinking of adapting this patch to be part of a 3 patch series including one of Chistophs. Something like this:
[PATCH v6 11/16] xfs: Check for
-ENOATTRor-EEXIST[PATCH v6 03/16] xfs: Addxfs_has_attrand subroutines [PATCH 02/29] xfs: mergexfs_attr_removeintoxfs_attr_setWhat would people think of that? I figured this would be better than the two of us bombarding the mailing list with giant conflicting sets? Also, was I able to answer everyones questions on this patch?
I'm still not sold at all on this series. It adds a lot of code and makes it much harder to understand. So I'd much rather go back and figuring out how we can do delayed attrs in a more streamlined way. The has_attr and co changes are some of exactly that kind of logic that is just making things worse in the standalone patch set, so even if we must end up with it they absolutely belong into a series actually adding functionality, as they have no use on their own.
Independent of that we'll need to clean up the flags mess, so I'd rather just go ahead with that for now.
Re: [PATCH v5 04/14] xfs: Add xfs_has_attr and subroutines
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Allison Collins
I was thinking of adapting this patch to be part of a 3 patch series including one of Chistophs. Something like this:
[PATCH v6 11/16] xfs: Check for
-ENOATTRor-EEXIST[PATCH v6 03/16] xfs: Addxfs_has_attrand subroutines [PATCH 02/29] xfs: mergexfs_attr_removeintoxfs_attr_set
Quoted 7 lines
Quoted 3 lines
What would people think of that? I figured this would be better than the two of us bombarding the mailing list with giant conflicting sets? Also, was I able to answer everyones questions on this patch?
I'm still not sold at all on this series. It adds a lot of code and makes it much harder to understand. So I'd much rather go back and figuring out how we can do delayed attrs in a more streamlined way.
I had something like that quite a long time ago. Instead of the EAGAIN ping pong, we had a boolean that just sort of turned the transactions off in the delayed attrs path:
https://www.spinics.net/lists/linux-xfs/msg18114.html
The trouble with this is that it creates one large transaction rather than breaking them up. So while the new method is a lot more complex, it seemed to be the direction folks preferred.
Quoted 4 lines
The
has_attrand co changes are some of exactly that kind of logic that is just making things worse in the standalone patch set, so even if we must end up with it they absolutely belong into a series actually adding functionality, as they have no use on their own. >
Well, in an earlier discussion though we had come together with a plan of implementing the new feature through a series of sub sets. First of which being pure refactor with no functional change.
https://www.spinics.net/lists/linux-xfs/msg32035.html
I do try to keep the extended set up to date though. Mostly for my own sanity and to make sure things are still on track for the long term goals we are aiming for.
Quoted 3 lines
Independent of that we'll need to clean up the flags mess, so I'd rather just go ahead with that for now.
PATCH v5 5/14 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
@@ -22,6 +22,7 @@#include "xfs_attr_remote.h" #include "xfs_trace.h" #include "xfs_error.h" +#include "xfs_attr_remote.h" #define ATTR_RMTVALUE_MAPSIZE 1/* # of map entries at once */
@@ -433,34 +434,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. */
@@ -501,6 +488,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 v5 05/14] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 6 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.
Please use up the foll 72-ish characters for the changelog (also for various other patches).
For the actual patch: can you keep the code in the order of the calling conventions, that is the lower level functions up and xfs_attr_rmtval_set at the bottom? Also please keep the functions static until callers show up (which nicely leads to the above order).
Re: [PATCH v5 05/14] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 10 lines · Christoph Hellwig
Quoted 6 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.Please use up the foll 72-ish characters for the changelog (also for various other patches).
Hmm, in one of my older reviews, we thought the standard line wrap length was 68. Maybe when more folks get back from holiday break, we can have more chime in here.
Quoted 6 lines
For the actual patch: can you keep the code in the order of the calling conventions, that is the lower level functions up and
xfs_attr_rmtval_setat the bottom? Also please keep the functions static until callers show up (which nicely leads to the above order).
Sure, will do.
Allison
Re: [PATCH v5 05/14] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 11 lines · Allison Collins
Quoted 8 lines · Christoph Hellwig
Quoted 6 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 6 lines
Quoted 2 lines
Please use up the foll 72-ish characters for the changelog (also for various other patches).
Hmm, in one of my older reviews, we thought the standard line wrap length was 68. Maybe when more folks get back from holiday break, we can have more chime in here.
I thought it was 68 as well (I think that qualifies as 72-ish" at least), but the current commit logs still look short of that at a glance. ;P
Brian
Quoted 11 lines
Quoted 6 lines
For the actual patch: can you keep the code in the order of the calling conventions, that is the lower level functions up and
xfs_attr_rmtval_setat the bottom? Also please keep the functions static until callers show up (which nicely leads to the above order).Sure, will do.
Allison
Re: [PATCH v5 05/14] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 19 lines · Brian Foster
Quoted 11 lines · Allison Collins
Quoted 8 lines · Christoph Hellwig
Quoted 6 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 6 lines
Quoted 2 lines
Please use up the foll 72-ish characters for the changelog (also for various other patches).
Hmm, in one of my older reviews, we thought the standard line wrap length was 68. Maybe when more folks get back from holiday break, we can have more chime in here.
Quoted 5 lines
I thought it was 68 as well (I think that qualifies as 72-ish" at least), but the current commit logs still look short of that at a glance. ;P
Brian
Ok I doubled checked, the last few lines do wrap a little early, but the rest is correct for 68 because of the function names. We should probably establish a number though. In perusing around some of the other patches on the list, it looks to me like people are using 81?
Allison
Quoted 13 lines
Quoted 12 lines
Quoted 7 lines
For the actual patch: can you keep the code in the order of the calling conventions, that is the lower level functions up and
xfs_attr_rmtval_setat the bottom? Also please keep the functions static until callers show up (which nicely leads to the above order).Sure, will do.
Allison
Re: [PATCH v5 05/14] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 26 lines · Allison Collins
Quoted 23 lines · Brian Foster
Quoted 11 lines · Allison Collins
Quoted 8 lines · Christoph Hellwig
Quoted 6 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 6 lines
Quoted 2 lines
Please use up the foll 72-ish characters for the changelog (also for various other patches).
Hmm, in one of my older reviews, we thought the standard line wrap length was 68. Maybe when more folks get back from holiday break, we can have more chime in here.
I thought it was 68 as well (I think that qualifies as 72-ish" at least), but the current commit logs still look short of that at a glance. ;P
Quoted 5 lines
Quoted 1 line
Brian
Ok I doubled checked, the last few lines do wrap a little early, but the rest is correct for 68 because of the function names. We should probably establish a number though. In perusing around some of the other patches on the list, it looks to me like people are using 81?
I use 72 columns for emails and commit messages, and 79 for code.
Though to be honest that's just my editor settings; I'm sure interested parties could find plenty of instances where my enforcement of even that is totally lax --
I have enough of a difficult time finding all the subtle bugs and corner case design problems in the kernel code (which will cause problems in our users' lives) that so long as you're not obviously going past the flaming red stripe that I told vim to put at column 80, I don't really care (because maxcolumns errors don't usually cause data loss). :)
(Not trying to say that peoples' code is crap, I'm just laying out where I put maxcolumns in my priority barrel.)
--D
Quoted 16 lines
Allison
Quoted 13 lines
Quoted 12 lines
Quoted 7 lines
For the actual patch: can you keep the code in the order of the calling conventions, that is the lower level functions up and
xfs_attr_rmtval_setat the bottom? Also please keep the functions static until callers show up (which nicely leads to the above order).Sure, will do.
Allison
Re: [PATCH v5 05/14] xfs: Factor out new helper functions xfs_attr_rmtval_set
Quoted 27 lines · Darrick J. Wong
Quoted 26 lines · Allison Collins
Quoted 23 lines · Brian Foster
Quoted 11 lines · Allison Collins
Quoted 8 lines · Christoph Hellwig
Quoted 6 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 6 lines
Quoted 2 lines
Please use up the foll 72-ish characters for the changelog (also for various other patches).
Hmm, in one of my older reviews, we thought the standard line wrap length was 68. Maybe when more folks get back from holiday break, we can have more chime in here.
I thought it was 68 as well (I think that qualifies as 72-ish" at least), but the current commit logs still look short of that at a glance. ;P
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Brian
Ok I doubled checked, the last few lines do wrap a little early, but the rest is correct for 68 because of the function names. We should probably establish a number though. In perusing around some of the other patches on the list, it looks to me like people are using 81?
I use 72 columns for emails and commit messages, and 79 for code.
Typically 68-72 columns for commit messages, often 68 because git log output adds a 4 space indent to the commit message and that often gets quoted directly in email...
Quoted 9 lines
Though to be honest that's just my editor settings; I'm sure interested parties could find plenty of instances where my enforcement of even that is totally lax --
I have enough of a difficult time finding all the subtle bugs and corner case design problems in the kernel code (which will cause problems in our users' lives) that so long as you're not obviously going past the flaming red stripe that I told vim to put at column 80, I don't really care (because maxcolumns errors don't usually cause data loss). :)
Yeah, I have the flaming red column set to 80 by default, 68 for email and commit messages...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v5 6/14 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
@@ -726,6 +726,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
@@ -1064,6 +1071,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
@@ -2972,10 +2972,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 v5 06/14] xfs: Factor up trans handling in xfs_attr3_leaf_flipflags
What does "factor up" mean? Basically this moves the xfs_trans_roll_inode from xfs_attr3_leaf_flipflags to the callers, so I'd expect the subject to mention that.
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 733
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp);
Do we really still need these comments?
Quoted 5 lines
fs/xfs/libxfs/xfs_attr_leaf.c +0
-0
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 2975
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.c +0
-5@@ -2972,10 +2972,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;
This can become a
return 0;
now.
Re: [PATCH v5 06/14] xfs: Factor up trans handling in xfs_attr3_leaf_flipflags
Quoted 3 lines · Christoph Hellwig
What does "factor up" mean? Basically this moves the
xfs_trans_roll_inodefromxfs_attr3_leaf_flipflagsto the callers, so I'd expect the subject to mention that.
Yes, that is what I meant for it to mean. I guess I've been on a few other projects that used that terminology, so I didn't think much of it, and this is the first time someone has indicated confusion over it. I can certainly change the verbiage if people prefer. How about "Move up"? "Pull up"?
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_leaf_addname( · line 733
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+/* +* Commit the flag value change and start the next trans in +* series. +*/ + error =xfs_trans_roll_inode (&args->trans, args->dp);Do we really still need these comments?
I guess I brought it with the corresponding code because I wasn't sure if people would miss it or not. It does seem to be explaining why we're doing a roll right now. We may need to wait for after the holiday break for more people to chime in.
Quoted 18 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr_leaf.c +0
-0fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_flipflags( · line 2975
Quoted 9 lines
fs/xfs/libxfs/xfs_attr_leaf.c +0
-5@@ -2972,10 +2972,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;This can become a
Quoted 4 lines
return 0;now.
Sure, will change. Thanks!
Allison
PATCH v5 7/14 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 | 83 ++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 34 deletions(-)
fs/xfs/libxfs/xfs_attr.c +49 -34
@@ -305,10 +305,30 @@ 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 - error =xfs_attr_node_addname (args); +if (error ==0 || error != -ENOSPC ) +return 0 ; + +/* +* 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; + + } + + error =xfs_attr_node_addname (args);return error; }
@@ -606,21 +626,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
@@ -666,31 +677,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 v5 07/14] xfs: Factor out xfs_attr_leaf_addname helper
Quoted 17 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 | 83 ++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 34 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 311
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-3@@ -305,10 +305,30 @@ 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 - error =xfs_attr_node_addname (args); +if (error ==0 || error != -ENOSPC ) +return 0 ;
No need to check for 0 since 0 != -ENOSPC. We also probably want to return error instead of zero. With that fixed up:
Quoted 106 lines
fs/xfs/libxfs/xfs_attr.c +46
-31+ +/* +* 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; + + } + + error =xfs_attr_node_addname (args);return error; }@@ -606,21 +626,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 @@ -666,31 +677,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 v5 07/14] xfs: Factor out xfs_attr_leaf_addname helper
Quoted 32 lines · Brian Foster
Quoted 17 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 | 83 ++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 34 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 311
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-3@@ -305,10 +305,30 @@ 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 - error =xfs_attr_node_addname (args); +if (error ==0 || error != -ENOSPC ) +return 0 ;No need to check for 0 since 0 !=
-ENOSPC. We also probably want to return error instead of zero. With that fixed up:
Quoted 1 line
Reviewed-by Brian Foster <[email protected]>
Ok will fix. Thank you!!
Allison
Quoted 108 lines
Quoted 107 lines
fs/xfs/libxfs/xfs_attr.c +46
-31+ +/* +* 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; + + } + + error =xfs_attr_node_addname (args);return error; }@@ -606,21 +626,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 @@ -666,31 +677,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 v5 07/14] xfs: Factor out xfs_attr_leaf_addname helper
In reply to Allison CollinsQuoted 6 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.
I have a hard time relating the subject to what is happening here, maybe because the patch does too many things at once. One thing is plitting a xfs_attr_leaf_try_add from xfs_attr_leaf_addname, which seems pretty sensible, but then it also moves code from xfs_attr_node_addname into the only caller. That probably should be a separate patch with a proper description.
Re: [PATCH v5 07/14] xfs: Factor out xfs_attr_leaf_addname helper
Quoted 8 lines · Christoph Hellwig
Quoted 6 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.
Quoted 7 lines
I have a hard time relating the subject to what is happening here, maybe because the patch does too many things at once. One thing is plitting a
xfs_attr_leaf_try_addfromxfs_attr_leaf_addname, which seems pretty sensible, but then it also moves code fromxfs_attr_node_addnameinto the only caller. That probably should be a separate patch with a proper description.
Sure, maybe it might help to look at it this way though: the goal of all this refactoring is to get all the transactions up into the xfs_attr_*_args routines. Once we have them pretty much corralled, we replace them with a sort of state machine like mechanic. This produces the "return EAGAIN for new a transaction" behavior that we need for the .finish_item callback.
In this case, xfs_attr_leaf_addname is a subroutine with a transaction in the middle. So we split it into two functions. Kind of like a top half and bottom half, and then the transaction moves up. While I can separate the split and the move into separate patches, it didnt really feel to me like the transaction or the node logic really fit with either of the helpers. They are supposed to be about leaves, not nodes. It's not a big deal I suppose to split up the patches, but I thought doing so creates a sort of transient patch with functions that have logic not particularly appropriate for their scope. Thoughts?
Also, perhaps I need to remove the line in the commit header about reducing repetitive code. It might be misleading you (apologies). This is left over from an earlier version of the series where I tried to avoid "monster function" by having two code paths: one for inline attrs and a separate one for delayed attrs. It generated a lot of repetitive code with subtle differences though, and i think folks preferred the code paths to stay merged. The goal being to first establish what "monster function" even looks like, and then simplify it into new helpers from there.
This is admittedly a very difficult series to review. People need to understand patches 1 - 12 to really understand what 13 and 14 are doing.
But really, 13 and 14 are kind of driving the rest of the series.
Like literally an entire patch fell out of the last set because of some changes we made in the end of the series. I know 13 and 14 are the hardest to look at, but they very much dictate what the lower patches end up doing. So I encourage people to try and focus attention there before loosing to much sanity on scaffolding. Certainty it all needs to get reviewed of course, but it may help to make more efficient use of peoples review time. :-)
Hope that helps! Thanks for looking at it!
Allison
PATCH v5 8/14 xfs: Factor up xfs_attr_try_sf_addname
In reply to Allison CollinsNew delayed attribute routines cannot handle transactions. We can factor up the commit, but there is little left in this function other than some error handling and an ichgtime. So hoist all of xfs_attr_try_sf_addname up at this time. We will remove all the commits in this set.
--- fs/xfs/libxfs/xfs_attr.c | 54 ++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 32 deletions(-)
fs/xfs/libxfs/xfs_attr.c +22 -32
@@ -221,34 +221,6 @@ xfs_attr_calc_size(return nblks; } -STATIC int -xfs_attr_try_sf_addname ( -struct xfs_inode *dp, -struct xfs_da_args *args) -{ - -struct xfs_mount *mp = dp->i_mount; -int error, error2; - - error =xfs_attr_shortform_addname (args); -if (error == -ENOSPC ) -return error; - -/* -* Commit the shortform mods, and we're done. -* NOTE: this is also the error path (EEXIST, etc). -*/ -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; -} -/* * Set the attribute specified in @args. */
@@ -258,7 +230,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,
@@ -277,9 +249,27 @@ 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; + + error =xfs_attr_shortform_addname (args); + +/* Should only be 0, -EEXIST or ENOSPC */ +if (error != -ENOSPC ) { +/* +* Commit the shortform mods, and we're done. +* NOTE: this is also the error path (EEXIST, etc). +*/ +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 ) +xfs_trans_ichgtime (args->trans, dp, +XFS_ICHGTIME_CHG ); + +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 v5 08/14] xfs: Factor up xfs_attr_try_sf_addname
Quoted 15 lines · Allison Collins
New delayed attribute routines cannot handle transactions. We can factor up the commit, but there is little left in this function other than some error handling and an ichgtime. So hoist all of
xfs_attr_try_sf_addnameup at this time. We will remove all the commits in this set.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 54 ++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 32 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 233
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-1@@ -258,7 +230,7 @@ xfs_attr_set_args( {struct xfs_inode *dp = args->dp;struct xfs_buf *leaf_bp =NULL ; -int error; +int error, error2 =0 ;;
Extra semicolon on the above line.
Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +11
-3/* * If the attribute list is non-existent or a shortform list, @@ -277,9 +249,27 @@ 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; + + error =xfs_attr_shortform_addname (args); + +/* Should only be 0, -EEXIST or ENOSPC */ +if (error != -ENOSPC ) { +/* +* Commit the shortform mods, and we're done. +* NOTE: this is also the error path (EEXIST, etc). +*/ +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 ) + xfs_trans_ichgtime(args->trans, dp,
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 272
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ XFS_ICHGTIME_CHG); + +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; + } +
And extra whitespace here. With those nits fixed:
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-0/* * It won't fit in the shortform, transform to a leaf block. Signature · 1 line
2.7.4
Re: [PATCH v5 08/14] xfs: Factor up xfs_attr_try_sf_addname
Quoted 60 lines · Brian Foster
Quoted 15 lines · Allison Collins
New delayed attribute routines cannot handle transactions. We can factor up the commit, but there is little left in this function other than some error handling and an ichgtime. So hoist all of
xfs_attr_try_sf_addnameup at this time. We will remove all the commits in this set.Signed-off-by Allison Collins <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 54 ++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 32 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 233
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +1
-1@@ -258,7 +230,7 @@ xfs_attr_set_args( {struct xfs_inode *dp = args->dp;struct xfs_buf *leaf_bp =NULL ; -int error; +int error, error2 =0 ;;Extra semicolon on the above line.
Quoted 21 lines
fs/xfs/libxfs/xfs_attr.c +11
-3/* * If the attribute list is non-existent or a shortform list, @@ -277,9 +249,27 @@ 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; + + error =xfs_attr_shortform_addname (args); + +/* Should only be 0, -EEXIST or ENOSPC */ +if (error != -ENOSPC ) { +/* +* Commit the shortform mods, and we're done. +* NOTE: this is also the error path (EEXIST, etc). +*/ +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 ) + xfs_trans_ichgtime(args->trans, dp,fs/xfs/libxfs/xfs_attr.c xfs_attr_set_args( · line 272
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+ XFS_ICHGTIME_CHG); + +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; + } +And extra whitespace here. With those nits fixed:
Quoted 2 lines
Reviewed-by Brian Foster <[email protected]>
Ok, will do. Thank you!
Allison
Quoted 7 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-0/* * It won't fit in the shortform, transform to a leaf block. Signature · 1 line
2.7.4
Re: [PATCH v5 08/14] xfs: Factor up xfs_attr_try_sf_addname
In reply to Allison CollinsQuoted 5 lines · Allison Collins
New delayed attribute routines cannot handle transactions. We can factor up the commit, but there is little left in this function other than some error handling and an ichgtime. So hoist all of
xfs_attr_try_sf_addnameup at this time. We will remove all the commits in this set.
I really don't like this one. xfs_attr_try_sf_addname is a nice abstration, so merging it into the caller makes the code much harder to understand. If that is different after changes to the transaction change it can be removed at that point, but merging all the different attr formats into one big monster function is a bad idea.
Also Factor up still sounds very, very strange to me. I would have worded it as "merge xfs_attr_try_sf_addname into its only caller"
Re: [PATCH v5 08/14] xfs: Factor up xfs_attr_try_sf_addname
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Allison Collins
New delayed attribute routines cannot handle transactions. We can factor up the commit, but there is little left in this function other than some error handling and an ichgtime. So hoist all of
xfs_attr_try_sf_addnameup at this time. We will remove all the commits in this set.
Quoted 5 lines
I really don't like this one.
xfs_attr_try_sf_addnameis a nice abstration, so merging it into the caller makes the code much harder to understand. If that is different after changes to the transaction change it can be removed at that point, but merging all the different attr formats into one big monster function is a bad idea.
Well, in the last version of the set, I did keep it around, but it was so small, Darrick suggested cleaning it out all together. Here is the same patch in the last set:
https://patchwork.kernel.org/patch/11231511/
Maybe when more folks get back from break they can chime in about keeping it or not. I think I commented pretty well on "monster function" in the last patch. It is in all in the pursuit of pulling things up and then breaking them back down again.
Quoted 4 lines
Also Factor up still sounds very, very strange to me. I would have worded it as "merge
xfs_attr_try_sf_addnameinto its only caller"
I always assumed it to be a figure of speech in reference to factoring out common code, sort of like how one might factor out a common denominator or common multiple from an algebraic expression. If it really bothers folks though, I don't mind changing it.
Allison
PATCH v5 9/14 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
@@ -1206,6 +1206,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
Re: [PATCH v5 09/14] xfs: Factor up trans roll from xfs_attr3_leaf_setflag
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_setflag( · line 2857
Quoted 9 lines
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;
error is always 0 here.
PATCH v5 10/14 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
@@ -589,21 +589,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.
@@ -645,13 +638,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 v5 11/14 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
@@ -788,6 +788,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; }
@@ -1147,6 +1155,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
@@ -2803,10 +2803,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 v5 11/14] xfs: Factor up trans roll in xfs_attr3_leaf_clearflag
fs/xfs/libxfs/xfs_attr_leaf.c xfs_attr3_leaf_clearflag( · line 2806
Quoted 13 lines
fs/xfs/libxfs/xfs_attr_leaf.c +1
-4@@ -2803,10 +2803,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;
error is always 0 here.
PATCH v5 12/14 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/xfs/libxfs/xfs_attr.c +16 -0
@@ -446,6 +446,18 @@ 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; + error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;
@@ -534,6 +546,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error != -EEXIST ) + goto out; + error =xfs_attr_remove_args (&args);if (error) goto out;
Signature · 1 line
2.7.4
Re: [PATCH v5 12/14] xfs: Check for -ENOATTR or -EEXIST
Quoted 13 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)fs/xfs/libxfs/xfs_attr.c +0
-0
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 455
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-0@@ -446,6 +446,18 @@ 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 ;
Hmm.. this bit looks funny to me. Shouldn't this already be set by userspace? What's the reason for setting it here?
Brian
Quoted 22 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+ } + +if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel; + error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;@@ -534,6 +546,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error != -EEXIST ) + goto out; + error =xfs_attr_remove_args (&args);if (error) goto out;Signature · 1 line
2.7.4
Re: [PATCH v5 12/14] xfs: Check for -ENOATTR or -EEXIST
Quoted 28 lines · Brian Foster
Quoted 13 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)fs/xfs/libxfs/xfs_attr.c +0
-0fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 455
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +7
-0@@ -446,6 +446,18 @@ 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 ;Hmm.. this bit looks funny to me. Shouldn't this already be set by userspace? What's the reason for setting it here?
Quoted 1 line
Brian
There was a reason I did this, and now i'm trying to remember what it was. I'm pretty sure it's reminiscent of an earlier series that handled a replace with explicit remove and set to avoid in flight error codes with delayed operations. I think I can take it out at this point though, the set has gone through a lot of changes since.
Allison
Quoted 24 lines
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+ } + +if (error == -ENOATTR && (name->type &ATTR_REPLACE )) + goto out_trans_cancel; + error =xfs_attr_set_args (&args);if (error) goto out_trans_cancel;@@ -534,6 +546,10 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); + error =xfs_has_attr (&args); +if (error != -EEXIST ) + goto out; + error =xfs_attr_remove_args (&args);if (error) goto out;Signature · 1 line
2.7.4
PATCH v5 13/14 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_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned. xfs_attr_node_removename has also been modified to use the switch, and a new version of xfs_attr_remove_args consists of a simple loop to refresh the transaction until the operation is completed.
This patch also adds a new struct xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The new xfs_delattr_state enum is used to track various operations that are in progress so that we know not to repeat them, and resume where we left off before EAGAIN was returned to cycle out the transaction. Other members take the place of local variables that need to retain their values across multiple function recalls.
--- fs/xfs/libxfs/xfs_attr.c | 127 ++++++++++++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_da_btree.h | 16 ++++++ 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 + 10 files changed, 137 insertions(+), 19 deletions(-)
fs/xfs/libxfs/xfs_attr.c +108 -19
@@ -357,11 +357,51 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( +struct xfs_da_args *args) +{ +int error =0 ; +int err2 =0 ; + +do { + error =xfs_attr_remove_iter (args); +if (error && error != -EAGAIN ) + goto out; + + err2 =xfs_trans_roll_inode (&args->trans, args->dp); +if (err2) { + error = err2; + goto out; + } + + }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_iter (struct xfs_da_args *args) {struct xfs_inode *dp = args->dp;int error; +/* State machine switch */ +switch (args->dac.dela_state) { +case XFS_DAS_RM_INVALIDATE : +case XFS_DAS_RM_SHRINK : +case XFS_DAS_RM_NODE_BLKS : + goto node; +default : +break ; + } +if (!xfs_inode_hasattr (dp)) { error = -ENOATTR ; }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) {
@@ -370,6 +410,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); }
@@ -873,9 +914,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 ; }
@@ -1196,6 +1234,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 either an inline or 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(
@@ -1206,12 +1249,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->dac.da_state; + blk = args->dac.blk; + +/* State machine switch */ +switch (args->dac.dela_state) { +case XFS_DAS_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DAS_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DAS_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.
@@ -1221,6 +1281,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->dac.blk = blk; + args->dac.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure
@@ -1239,13 +1307,40 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; + args->dac.dela_state =XFS_DAS_RM_INVALIDATE ; +return -EAGAIN ; + } + +rm_invalidate: + args->dac.dela_state =XFS_DAS_RM_INVALIDATE ; - error =xfs_attr_rmtval_remove (args); +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; + } + +rm_node_blks: + + args->dac.dela_state =XFS_DAS_RM_NODE_BLKS ; +if (args->rmtblkno >0 ) { +/* +* 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; + +if (!done) { + args->dac.dela_state =XFS_DAS_RM_NODE_BLKS ; +return -EAGAIN ; + } + }/* * Refill the state structure with buffers, the prior calls
@@ -1271,17 +1366,14 @@ 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->dac.dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink: + args->dac.dela_state =XFS_DAS_RM_SHRINK ; +/* * If the result is small enough, push it all into the inode. */
@@ -1302,9 +1394,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_iter (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);
fs/xfs/libxfs/xfs_da_btree.h +16 -0
@@ -49,10 +49,26 @@ enum xfs_dacmp {XFS_CMP_CASE /* names are same but differ in case */ }; +enum xfs_delattr_state { +XFS_DAS_RM_INVALIDATE =1 ,/* We are invalidating blocks */ +XFS_DAS_RM_SHRINK =2 ,/* We are shrinking the tree */ +XFS_DAS_RM_NODE_BLKS =3 ,/* We are removing node blocks */ +}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +enum xfs_delattr_state dela_state; +}; +/* * Structure to ease passing around component names. */ typedef struct xfs_da_args { + struct xfs_delattr_context dac;/* context used for delay attr ops */ struct xfs_da_geometry *geo; /* da block geometry */ struct xfs_name name; /* name, length and argument flags*/ uint8_t filetype; /* filetype of inode for directories */
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 "xfs_error.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 "xfs_acl.h"
Signature · 1 line
2.7.4
Re: [PATCH v5 13/14] xfs: Add delay ready attr remove routines
Quoted 36 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_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.This patch also adds a new struct
xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The newxfs_delattr_stateenum 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_attr.c | 127 ++++++++++++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_da_btree.h | 16 ++++++ 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 + 10 files changed, 137 insertions(+), 19 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0
...
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +5
-0@@ -1206,12 +1249,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->dac.da_state; + blk = args->dac.blk; + +/* State machine switch */
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1268
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+switch (args->dac.dela_state) { +case XFS_DAS_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DAS_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DAS_RM_SHRINK : + goto rm_shrink; +default : +break ; + }
I think this function could use at least a couple more prepatory refactoring patches before we introduce the state machine...
Quoted 25 lines
fs/xfs/libxfs/xfs_attr.c +10
-0error =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. @@ -1221,6 +1281,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->dac.blk = blk; + args->dac.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 1312
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +3
-3@@ -1239,13 +1307,40 @@ xfs_attr_node_removename(if (error) goto out; - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; + args->dac.dela_state =XFS_DAS_RM_INVALIDATE ; +return -EAGAIN ; + }
The entire (args->rmtblkno > 0) branch above could be reduced into a helper function. BTW, does it matter whether the invalidate occurs before or after this particular transaction roll? It looks to me it just makes in-core changes. I'm wondering if we could just fold that in as well and eliminate that state entirely.
Quoted 23 lines
fs/xfs/libxfs/xfs_attr.c +19
-1+ +rm_invalidate: + args->dac.dela_state =XFS_DAS_RM_INVALIDATE ; - error =xfs_attr_rmtval_remove (args); +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; + } + +rm_node_blks: + + args->dac.dela_state =XFS_DAS_RM_NODE_BLKS ; +if (args->rmtblkno >0 ) { +/* +* 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,
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1344
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+ XFS_BMAPI_ATTRFORK, 1, &done); +if (error) +return error; + +if (!done) { + args->dac.dela_state =XFS_DAS_RM_NODE_BLKS ; +return -EAGAIN ; + } + }
The above could use the helper function treatment as well. E.g., something like xfs_attr_rmtval_unmap() that has a *done param this function can check to determine whether to return -EAGAIN or proceed.
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1276
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +0
-3/* * Refill the state structure with buffers, the prior calls @@ -1271,17 +1366,14 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;
Hmm.. I think we might want to lift the xfs_defer_finish() call up into the iter() function rather than just drop it. Otherwise this changes behavior in that the transaction roll doesn't complete pending deferred operations.
Quoted 18 lines
fs/xfs/libxfs/xfs_attr.c +6
-6-/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dac.dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink: + args->dac.dela_state =XFS_DAS_RM_SHRINK ; +/* * If the result is small enough, push it all into the inode. */
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1399
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +0
-3@@ -1302,9 +1394,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); }
Same deal here (and same fundamental comment for the next patch).. create a xfs_attr_node_shrink() or some such helper to make functions that handle state smaller and easier to follow once the state bits are introduced.
Brian
Quoted 135 lines
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_iter (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);fs/xfs/libxfs/xfs_da_btree.h +16
-0@@ -49,10 +49,26 @@ enum xfs_dacmp {XFS_CMP_CASE /* names are same but differ in case */ }; +enum xfs_delattr_state { +XFS_DAS_RM_INVALIDATE =1 ,/* We are invalidating blocks */ +XFS_DAS_RM_SHRINK =2 ,/* We are shrinking the tree */ +XFS_DAS_RM_NODE_BLKS =3 ,/* We are removing node blocks */ +}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +enum xfs_delattr_state dela_state; +}; +/* * Structure to ease passing around component names. */ typedef struct xfs_da_args { + struct xfs_delattr_context dac;/* context used for delay attr ops */ struct xfs_da_geometry *geo; /* da block geometry */ struct xfs_name name; /* name, length and argument flags*/ uint8_t filetype; /* filetype of inode for directories */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 "xfs_error.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 "xfs_acl.h" Signature · 1 line
2.7.4
Re: [PATCH v5 13/14] xfs: Add delay ready attr remove routines
Quoted 91 lines · Brian Foster
Quoted 36 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_iter, which uses a sort of state machine like switch to keep track of where it was when EAGAIN was returned.xfs_attr_node_removenamehas also been modified to use the switch, and a new version ofxfs_attr_remove_argsconsists of a simple loop to refresh the transaction until the operation is completed.This patch also adds a new struct
xfs_delattr_context, which we will use to keep track of the current state of an attribute operation. The newxfs_delattr_stateenum 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_attr.c | 127 ++++++++++++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_da_btree.h | 16 ++++++ 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 + 10 files changed, 137 insertions(+), 19 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0...
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +5
-0@@ -1206,12 +1249,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->dac.da_state; + blk = args->dac.blk; + +/* State machine switch */ fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1268
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+switch (args->dac.dela_state) { +case XFS_DAS_RM_NODE_BLKS : + goto rm_node_blks; +case XFS_DAS_RM_INVALIDATE : + goto rm_invalidate; +case XFS_DAS_RM_SHRINK : + goto rm_shrink; +default : +break ; + }I think this function could use at least a couple more prepatory refactoring patches before we introduce the state machine...
Quoted 28 lines
fs/xfs/libxfs/xfs_attr.c +10
-0error =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. @@ -1221,6 +1281,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->dac.blk = blk; + args->dac.da_state = state; +if (args->rmtblkno >0 ) {/* * Fill in disk block numbers in the state structure @@ -1239,13 +1307,40 @@ xfs_attr_node_removename(if (error) goto out;
Quoted 12 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1312
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +3
-3- error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) - goto out; + args->dac.dela_state =XFS_DAS_RM_INVALIDATE ; +return -EAGAIN ; + }The entire (
args->rmtblkno> 0) branch above could be reduced into a helper function. BTW, does it matter whether the invalidate occurs before or after this particular transaction roll? It looks to me it just makes in-core changes. I'm wondering if we could just fold that in as well and eliminate that state entirely.
I assumed the reason for the roll here was the invalidate? But I suppose if we only have in-core changes maybe it's not needed. I'll see if I can remove this state, and tuck the above logic into a helper.
Quoted 30 lines
Quoted 30 lines
fs/xfs/libxfs/xfs_attr.c +25
-1+ +rm_invalidate: + args->dac.dela_state =XFS_DAS_RM_INVALIDATE ; - error =xfs_attr_rmtval_remove (args); +if (args->rmtblkno >0 ) { + error =xfs_attr_rmtval_invalidate (args);if (error) goto out; + } + +rm_node_blks: + + args->dac.dela_state =XFS_DAS_RM_NODE_BLKS ; +if (args->rmtblkno >0 ) { +/* +* 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; + +if (!done) { + args->dac.dela_state =XFS_DAS_RM_NODE_BLKS ;
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1344
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +3
-0+return -EAGAIN ; + } + }The above could use the helper function treatment as well. E.g., something like
xfs_attr_rmtval_unmap()that has a *done param this function can check to determine whether to return-EAGAINor proceed.
Sure, will do
Quoted 15 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1276
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +0
-3/* * Refill the state structure with buffers, the prior calls @@ -1271,17 +1366,14 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out;Hmm.. I think we might want to lift the
xfs_defer_finish()call up into theiter()function rather than just drop it. Otherwise this changes behavior in that the transaction roll doesn't complete pending deferred operations.
Ok, I'll tack that on then
Quoted 34 lines
Quoted 19 lines
fs/xfs/libxfs/xfs_attr.c +6
-6-/* -* Commit the Btree join operation and start a new trans. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; + + args->dac.dela_state =XFS_DAS_RM_SHRINK ; +return -EAGAIN ; } +rm_shrink: + args->dac.dela_state =XFS_DAS_RM_SHRINK ; +/* * If the result is small enough, push it all into the inode. */ fs/xfs/libxfs/xfs_attr.c xfs_attr_node_removename( · line 1399
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +0
-3@@ -1302,9 +1394,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); }Same deal here (and same fundamental comment for the next patch).. create a
xfs_attr_node_shrink()or some such helper to make functions that handle state smaller and easier to follow once the state bits are introduced.
Quoted 1 line
Brian
Ok then, sounds good. Thanks again for all the reviews, I know it's been a lot! I'll get all this stuff updated in the next version.
Allison
Quoted 137 lines
Quoted 136 lines
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_iter (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);fs/xfs/libxfs/xfs_da_btree.h +16
-0@@ -49,10 +49,26 @@ enum xfs_dacmp {XFS_CMP_CASE /* names are same but differ in case */ }; +enum xfs_delattr_state { +XFS_DAS_RM_INVALIDATE =1 ,/* We are invalidating blocks */ +XFS_DAS_RM_SHRINK =2 ,/* We are shrinking the tree */ +XFS_DAS_RM_NODE_BLKS =3 ,/* We are removing node blocks */ +}; + +/* +* Context used for keeping track of delayed attribute operations +*/ +struct xfs_delattr_context { +struct xfs_da_state *da_state; +struct xfs_da_state_blk *blk; +enum xfs_delattr_state dela_state; +}; +/* * Structure to ease passing around component names. */ typedef struct xfs_da_args { + struct xfs_delattr_context dac;/* context used for delay attr ops */ struct xfs_da_geometry *geo; /* da block geometry */ struct xfs_name name; /* name, length and argument flags*/ uint8_t filetype; /* filetype of inode for directories */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 "xfs_error.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 "xfs_acl.h" Signature · 1 line
2.7.4
Re: [PATCH v5 13/14] xfs: Add delay ready attr remove routines
In reply to Allison CollinsThis code looks pretty scary, mostly because it adds hard to parse monster functions. Also as-is it seems totally pointless as no user of the change appears. In fact this series adds almost 500 lines of code without adding any code or speeding operations up (in fact I think it will cause minor slow downs). So to me it is a very hard sell.
Re: [PATCH v5 13/14] xfs: Add delay ready attr remove routines
I'll have to come back and respond to your other reviews in depth later when I have a little more time, but I think responding to this one quickly will help answer a lot of questions. The set actually has a lot more history as a delayed attributes series, and even more as parent pointers. I try to keep the whole set up to date because parent pointers is sort of a good test case for the rest it. And also because I want to make sure things still work for the future uses they are intended for.
To give you an idea, this is the same series + delayed attrs + parent pptrs:
https://github.com/allisonhenderson/xfs_work/tree/pptrs_restart41
I usually just send out the "delay ready" portion of it just to cut down on the amount of code that people have to review (because I know people are swamped with review backlog). And also because some time ago, folks felt that trying to push it in all at once was a little unwieldy, so they requested that I chop it down to this sub series that focuses on refactor only with no functional change. And then that would give it time to stabilize before proceeding too.
I hope the history of it helps a bit. Otherwise I can see where it looks like a whole bunch of craziness for nothing, but that's the long term plan for it. And while I think people agree that it's not the prettiest at the moment, the function that we are trying to achieve with it isn't simplest either, so people have been pretty active in shaping it as it goes along. I'll go through your set and see which bits I can pick up and sort of integrate so that we don't have so much conflict. Thanks!
Allison
Quoted 7 lines · Christoph Hellwig
This code looks pretty scary, mostly because it adds hard to parse monster functions. Also as-is it seems totally pointless as no user of the change appears. In fact this series adds almost 500 lines of code without adding any code or speeding operations up (in fact I think it will cause minor slow downs). So to me it is a very hard sell.
PATCH v5 14/14 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_iter, which uses a state machine like switch 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. xfs_attr_set_args consists of a simple loop to refresh the transaction until the operation is completed.
--- fs/xfs/libxfs/xfs_attr.c | 440 +++++++++++++++++++++++++++---------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_da_btree.h | 13 ++ 3 files changed, 293 insertions(+), 161 deletions(-)
fs/xfs/libxfs/xfs_attr.c +279 -161
@@ -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
@@ -228,96 +229,166 @@ 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_iter (args, &leaf_bp); +if (error && error != -EAGAIN ) + goto out; + + err2 =xfs_trans_roll_inode (&args->trans, args->dp); +if (err2) { + error = err2; + goto out; + } + +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_iter ( +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->dac.dela_state) { +case XFS_DAS_SF_TO_LEAF : + goto sf_to_leaf; +case XFS_DAS_ALLOC_LEAF : +case XFS_DAS_FLIP_LFLAG : +case XFS_DAS_FOUND_LBLK : + goto leaf; +case XFS_DAS_FOUND_NBLK : +case XFS_DAS_FLIP_NFLAG : +case XFS_DAS_ALLOC_NODE : +case XFS_DAS_LEAF_TO_NODE : + goto node; +default : +break ; + }/* -* If the attribute list is non-existent or a shortform list, -* upgrade it to a single-leaf-block attribute list. +* New inodes may not have an attribute fork yet. So set the attribute +* fork appropriately */ -if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL || +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, proceed to +* upgrade it to a single-leaf-block attribute list. Otherwise jump +* straight to leaf handling +*/ +if (!(dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL || (dp->i_d.di_aformat ==XFS_DINODE_FMT_EXTENTS && - dp->i_d.di_anextents ==0 )) { + dp->i_d.di_anextents ==0 ))) + goto sf_to_leaf; -/* -* Build initial attribute list (if required). -*/ -if (dp->i_d.di_aformat ==XFS_DINODE_FMT_EXTENTS ) -xfs_attr_shortform_create (args); +/* +* Build initial attribute list (if required). +*/ +if (dp->i_d.di_aformat ==XFS_DINODE_FMT_EXTENTS ) +xfs_attr_shortform_create (args); + +/* +* Try to add the attr to the attribute list in the inode. +*/ + error =xfs_attr_shortform_addname (args); +/* Should only be 0, -EEXIST or ENOSPC */ +if (error != -ENOSPC ) {/* -* Try to add the attr to the attribute list in the inode. +* Commit the shortform mods, and we're done. +* NOTE: this is also the error path (EEXIST, etc). */ +if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 ) +xfs_trans_ichgtime (args->trans, dp, +XFS_ICHGTIME_CHG ); - error =xfs_attr_shortform_addname (args); +if (dp->i_mount->m_flags &XFS_MOUNT_WSYNC ) +xfs_trans_set_sync (args->trans); -/* Should only be 0, -EEXIST or ENOSPC */ -if (error != -ENOSPC ) { -/* -* Commit the shortform mods, and we're done. -* NOTE: this is also the error path (EEXIST, etc). -*/ -if (!error && (args->name.type &ATTR_KERNOTIME ) ==0 ) -xfs_trans_ichgtime (args->trans, dp, -XFS_ICHGTIME_CHG ); +return error; + } -if (dp->i_mount->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args->trans); +/* +* It won't fit in the shortform, transform to a leaf block. +* GROT: another possible req'mt for a double-split btree op. +*/ + error =xfs_attr_shortform_to_leaf (args, leaf_bp); +if (error) +return error; - error2 =xfs_trans_commit (args->trans); - args->trans =NULL ; -return error ? error : error2; - } +/* +* Prevent the leaf buffer from being unlocked so that a +* concurrent AIL push cannot grab the half-baked leaf +* buffer and run into problems with the write verifier. +*/ +xfs_trans_bhold (args->trans, *leaf_bp); + args->dac.dela_state =XFS_DAS_SF_TO_LEAF ; +return -EAGAIN ; -/* -* It won't fit in the shortform, transform to a leaf block. -* GROT: another possible req'mt for a double-split btree op. -*/ - error =xfs_attr_shortform_to_leaf (args, &leaf_bp); -if (error) -return error; +sf_to_leaf: -/* -* 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; - } +/* +* 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_addname (args); -if (error ==0 || error != -ENOSPC ) -return 0 ; - -/* -* 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) + error =xfs_attr_leaf_try_add (args, *leaf_bp); +switch (error) { +case -ENOSPC : + args->dac.dela_state =XFS_DAS_LEAF_TO_NODE ; +return -EAGAIN ; +case 0 : + args->dac.dela_state =XFS_DAS_FOUND_LBLK ; +return -EAGAIN ; +default :return error; - + } +leaf: + error =xfs_attr_leaf_addname (args); +if (error == -ENOSPC ) { + args->dac.dela_state =XFS_DAS_LEAF_TO_NODE ; +return -EAGAIN ; + } +return error; } - + args->dac.dela_state =XFS_DAS_LEAF_TO_NODE ; +node: error =xfs_attr_node_addname (args);return error; }
@@ -740,27 +811,29 @@ 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, forkoff, nmap;struct xfs_inode *dp = args->dp; +struct xfs_bmbt_irec *map = &args->dac.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->dac.dela_state) { +case XFS_DAS_FLIP_LFLAG : + goto flip_flag; +case XFS_DAS_ALLOC_LEAF : + goto alloc_leaf; +default : +break ; + }/* * If there was an out-of-line value, allocate the blocks we
@@ -769,7 +842,49 @@ 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); + +/* Open coded xfs_attr_rmtval_set without trans handling */ + + args->dac.lfileoff =0 ; + args->dac.lblkno =0 ; + args->dac.blkcnt =0 ; + args->rmtblkcnt =0 ; + args->rmtblkno =0 ; +memset (map,0 ,sizeof (struct xfs_bmbt_irec )); + + error =xfs_attr_rmt_find_hole (args); +if (error) +return error; + + args->dac.blkcnt = args->rmtblkcnt; + args->dac.lblkno = args->rmtblkno; + +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +alloc_leaf: +while (args->dac.blkcnt >0 ) { + nmap =1 ; + error =xfs_bmapi_write (args->trans, dp, + (xfs_fileoff_t )args->dac.lblkno, + args->dac.blkcnt,XFS_BMAPI_ATTRFORK , + args->total, map, &nmap); +if (error) +return error; +ASSERT (nmap ==1 ); +ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && + (map->br_startblock !=HOLESTARTBLOCK )); + +/* roll attribute extent map forwards */ + args->dac.lblkno += map->br_blockcount; + args->dac.blkcnt -= map->br_blockcount; + + args->dac.dela_state =XFS_DAS_ALLOC_LEAF ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; }
@@ -788,13 +903,10 @@ xfs_attr_leaf_addname(struct xfs_da_args *args) 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; + + args->dac.dela_state =XFS_DAS_FLIP_LFLAG ; +return -EAGAIN ; +flip_flag:/* * Dismantle the "old" attribute/value pair by removing
@@ -825,34 +937,15 @@ xfs_attr_leaf_addname(struct xfs_da_args *args)/* * If the result is small enough, shrink it all into the inode. */ -if ((forkoff =xfs_attr_shortform_allfit (bp, dp))) { + forkoff =xfs_attr_shortform_allfit (bp, dp); +if (forkoff) error =xfs_attr3_leaf_to_shortform (bp, args, forkoff); -/* bp is gone due to xfs_da_shrink_inode */ -if (error) -return error; - error =xfs_defer_finish (&args->trans); -if (error) -return error; - } - -/* -* Commit the remove and start the next trans in series. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); }else if (args->rmtblkno >0 ) {/* * 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; }
@@ -995,16 +1088,24 @@ 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->dac.map;trace_xfs_attr_node_addname (args);
@@ -1013,7 +1114,19 @@ xfs_attr_node_addname(*/ dp = args->dp; mp = dp->i_mount; -restart: + +/* State machine switch */ +switch (args->dac.dela_state) { +case XFS_DAS_FLIP_NFLAG : + goto flip_flag; +case XFS_DAS_FOUND_NBLK : + goto found_nblk; +case XFS_DAS_ALLOC_NODE : + goto alloc_node; +default : +break ; + } +/* * Search to see if name already exists, and get back a pointer * to where it should go.
@@ -1063,19 +1176,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 ; }/*
@@ -1087,9 +1193,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.
@@ -1104,13 +1207,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->dac.dela_state =XFS_DAS_FOUND_NBLK ; +return -EAGAIN ; +found_nblk:/* * If there was an out-of-line value, allocate the blocks we
@@ -1119,7 +1218,48 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); +/* Open coded xfs_attr_rmtval_set without trans handling */ + args->dac.lblkno =0 ; + args->dac.lfileoff =0 ; + args->dac.blkcnt =0 ; + args->rmtblkcnt =0 ; + args->rmtblkno =0 ; +memset (map,0 ,sizeof (struct xfs_bmbt_irec )); + + error =xfs_attr_rmt_find_hole (args); +if (error) +return error; + + args->dac.blkcnt = args->rmtblkcnt; + args->dac.lblkno = args->rmtblkno; +/* +* Roll through the "value", allocating blocks on disk as +* required. +*/ +alloc_node: +while (args->dac.blkcnt >0 ) { + nmap =1 ; + error =xfs_bmapi_write (args->trans, dp, + (xfs_fileoff_t )args->dac.lblkno, + args->dac.blkcnt, +XFS_BMAPI_ATTRFORK , + args->total, map, &nmap); +if (error) +return error; + +ASSERT (nmap ==1 ); +ASSERT ((map->br_startblock !=DELAYSTARTBLOCK ) && + (map->br_startblock !=HOLESTARTBLOCK )); + +/* roll attribute extent map forwards */ + args->dac.lblkno += map->br_blockcount; + args->dac.blkcnt -= map->br_blockcount; + + args->dac.dela_state =XFS_DAS_ALLOC_NODE ; +return -EAGAIN ; + } + + error =xfs_attr_rmtval_set_value (args);if (error)return error; }
@@ -1142,10 +1282,9 @@ xfs_attr_node_addname(* 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; - + args->dac.dela_state =XFS_DAS_FLIP_NFLAG ; +return -EAGAIN ; +flip_flag:/* * Dismantle the "old" attribute/value pair by removing * a "remote" value (if it exists).
@@ -1174,7 +1313,6 @@ xfs_attr_node_addname( error =xfs_da3_node_lookup_int (state, &retval);if (error) goto out; -/* * Remove the name and update the hashvals in the tree. */
@@ -1182,7 +1320,6 @@ xfs_attr_node_addname(ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); error =xfs_attr3_leaf_remove (blk->bp, args);xfs_da3_fixhashpath (state, &state->path); -/* * Check to see if the tree needs to be collapsed. */
@@ -1190,18 +1327,7 @@ xfs_attr_node_addname( error =xfs_da3_join (state);if (error) goto out; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; } - -/* -* Commit and start the next trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - }else if (args->rmtblkno >0 ) {/* * Added a "remote" value, just clear the incomplete flag.
@@ -1209,14 +1335,6 @@ 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.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_iter (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);
fs/xfs/libxfs/xfs_da_btree.h +13 -0
@@ -53,14 +53,27 @@ enum xfs_delattr_state {XFS_DAS_RM_INVALIDATE =1 ,/* We are invalidating blocks */ XFS_DAS_RM_SHRINK =2 ,/* We are shrinking the tree */ XFS_DAS_RM_NODE_BLKS =3 ,/* We are removing node blocks */ +XFS_DAS_SF_TO_LEAF =4 ,/* Converted short form to leaf */ +XFS_DAS_FOUND_LBLK =5 ,/* We found leaf blk for attr */ +XFS_DAS_LEAF_TO_NODE =6 ,/* Converted leaf to node */ +XFS_DAS_FOUND_NBLK =7 ,/* We found node blk for attr */ +XFS_DAS_ALLOC_LEAF =8 ,/* We are allocating leaf blocks */ +XFS_DAS_FLIP_LFLAG =9 ,/* Flipped leaf INCOMPLETE attr flag */ +XFS_DAS_ALLOC_NODE =10 ,/* We are allocating node blocks */ + XFS_DAS_FLIP_NFLAG = 11,/* Flipped node INCOMPLETE attr flag */ };/* * Context used for keeping track of delayed attribute operations */ struct xfs_delattr_context { +struct xfs_bmbt_irec map; +struct xfs_buf *leaf_bp; +xfs_fileoff_t lfileoff;struct xfs_da_state *da_state;struct xfs_da_state_blk *blk; +xfs_dablk_t lblkno; +int blkcnt;enum xfs_delattr_state dela_state; };
Signature · 1 line
2.7.4
So as seen by the series I sent I think the existing interface to the attr routines is pretty much garbage, and this series doesn't improve it all that much (but at least doesn't make it worse). Can you take a look at my series to expose the da_args to the callers? We could still embedded the xfs_name into that on top if that really helps.