Parent Pointers v9
v9 cover Parent Pointers v9
Hi all,
This is the 9th version of parent pointer attributes for xfs. The goal of this patch set is to add a parent pointer attribute to each inode. The attribute name containing the parent inode, generation, and directory offset, while the attribute value contains the file name. This feature will enable future optimizations for online scrub, or any other feature that could make use of quickly deriving an inodes path from the mount point.
Some points of interest since v8:
I've integrated the feed back from v8 and reworked the xfs_parent_add routine in patch 20 which is used in the corresponding xfsprogs set. I try to push all three sets at once since sometimes changes in one set can affect the others. Most of the activity this time is in xfsprogs and xfstests. So feedback there appreciated! As usual folks are welcome to go through any part of it, but I know it's a lot. Thanks again everyone!
Allison
Allison Henderson (19):
xfs: Move fs/xfs/xfs_attr.h to fs/xfs/libxfs/xfs_attr.h
xfs: Add helper function xfs_attr_try_sf_addname
xfs: Add attibute set and helper functions
xfs: Add attibute remove and helper functions
xfs: Hold inode locks in xfs_ialloc
xfs: Add trans toggle to attr routines
xfs: Set up infastructure for deferred attribute operations
xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
xfs: Add xfs_has_attr and subroutines
xfs: Add attr context to log item
xfs: Roll delayed attr operations by returning EAGAIN
xfs: Remove roll_trans boolean
xfs: Remove all strlen calls in all xfs_attr_* functions for attr
names.
xfs: Add parent pointers to rename
xfs: Add the parent pointer support to the superblock version 5.
xfs: Add helper function xfs_attr_list_context_init
xfs: Increase XFS_DEFER_OPS_NR_INODES to 4
xfs: Add parent pointer ioctl
xfs: Add delayed attributes error tag
Dave Chinner (5):
xfs: define parent pointer xattr format
xfs: extent transaction reservations for parent attributes
xfs: parent pointer attribute creation
xfs: add parent attributes to link
xfs: remove parent pointers in unlink
Mark Tinguely (4):
xfs: get directory offset when adding directory name
xfs: get directory offset when removing directory name
xfs: get directory offset when replacing a directory name
xfs: add parent pointer support to attribute code
fs/xfs/Makefile | 4 + fs/xfs/libxfs/xfs_attr.c | 495 ++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 205 ++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.c | 48 +++- fs/xfs/libxfs/xfs_attr_leaf.h | 3 +- fs/xfs/libxfs/xfs_attr_remote.c | 20 -- fs/xfs/libxfs/xfs_bmap.c | 49 ++-- fs/xfs/libxfs/xfs_bmap.h | 1 + fs/xfs/libxfs/xfs_da_btree.h | 1 + fs/xfs/libxfs/xfs_da_format.h | 37 ++- fs/xfs/libxfs/xfs_defer.h | 1 + fs/xfs/libxfs/xfs_dir2.c | 21 +- fs/xfs/libxfs/xfs_dir2.h | 7 +- fs/xfs/libxfs/xfs_dir2_block.c | 9 +- fs/xfs/libxfs/xfs_dir2_leaf.c | 8 +- fs/xfs/libxfs/xfs_dir2_node.c | 8 +- fs/xfs/libxfs/xfs_dir2_sf.c | 6 + fs/xfs/libxfs/xfs_errortag.h | 4 +- fs/xfs/libxfs/xfs_format.h | 10 +- fs/xfs/libxfs/xfs_fs.h | 46 ++++ fs/xfs/libxfs/xfs_log_format.h | 44 ++- fs/xfs/libxfs/xfs_parent.c | 197 +++++++++++++ fs/xfs/libxfs/xfs_parent.h | 37 +++ fs/xfs/libxfs/xfs_sb.c | 2 + fs/xfs/libxfs/xfs_trans_resv.c | 111 ++++++-- fs/xfs/libxfs/xfs_trans_resv.h | 1 + fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/scrub/common.c | 2 + fs/xfs/xfs_acl.c | 14 +- fs/xfs/xfs_attr.h | 148 ---------- fs/xfs/xfs_attr_item.c | 598 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 114 ++++++++ fs/xfs/xfs_attr_list.c | 75 +++-- fs/xfs/xfs_error.c | 3 + fs/xfs/xfs_inode.c | 150 +++++++--- fs/xfs/xfs_ioctl.c | 101 ++++++- fs/xfs/xfs_ioctl32.c | 2 + fs/xfs/xfs_iops.c | 7 +- fs/xfs/xfs_log_recover.c | 172 ++++++++++++ fs/xfs/xfs_ondisk.h | 6 + fs/xfs/xfs_parent_utils.c | 154 +++++++++++ fs/xfs/xfs_parent_utils.h | 32 +++ fs/xfs/xfs_qm.c | 1 + fs/xfs/xfs_super.c | 5 + fs/xfs/xfs_symlink.c | 6 +- fs/xfs/xfs_trans.h | 16 +- fs/xfs/xfs_trans_attr.c | 275 ++++++++++++++++++ fs/xfs/xfs_xattr.c | 11 +- 48 files changed, 2781 insertions(+), 487 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_attr.h create mode 100644 fs/xfs/libxfs/xfs_parent.c create mode 100644 fs/xfs/libxfs/xfs_parent.h delete mode 100644 fs/xfs/xfs_attr.h create mode 100644 fs/xfs/xfs_attr_item.c create mode 100644 fs/xfs/xfs_attr_item.h create mode 100644 fs/xfs/xfs_parent_utils.c create mode 100644 fs/xfs/xfs_parent_utils.h create mode 100644 fs/xfs/xfs_trans_attr.c
Signature · 1 line
2.7.4
PATCH v9 1/28 xfs: Move fs/xfs/xfs_attr.h to fs/xfs/libxfs/xfs_attr.h
This patch moves fs/xfs/xfs_attr.h to fs/xfs/libxfs/xfs_attr.h since xfs_attr.c is in libxfs. We will need these later in xfsprogs.
--- fs/xfs/libxfs/xfs_attr.h | 148 +++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr.h | 148 ----------------------------------------------- 2 files changed, 148 insertions(+), 148 deletions(-)
fs/xfs/libxfs/xfs_attr.h new file +148 -0
@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2000,2002-2003,2005 Silicon Graphics, Inc. +* All Rights Reserved. +*/ +#ifndef __XFS_ATTR_H__ +#define __XFS_ATTR_H__ + +struct xfs_inode ; +struct xfs_da_args ; +struct xfs_attr_list_context ; + +/* +* Large attribute lists are structured around Btrees where all the data +* elements are in the leaf nodes. Attribute names are hashed into an int, +* then that int is used as the index into the Btree. Since the hashval +* of an attribute name may not be unique, we may have duplicate keys. +* The internal links in the Btree are logical block offsets into the file. +* +* Small attribute lists use a different format and are packed as tightly +* as possible so as to fit into the literal area of the inode. +*/ + +/*======================================================================== +* External interfaces +*========================================================================*/ + + +#define ATTR_DONTFOLLOW 0x0001/* -- unused, from IRIX -- */ +#define ATTR_ROOT 0x0002/* use attrs in root (trusted) namespace */ +#define ATTR_TRUST 0x0004/* -- unused, from IRIX -- */ +#define ATTR_SECURE 0x0008/* use attrs in security namespace */ +#define ATTR_CREATE 0x0010/* pure create: fail if attr already exists */ +#define ATTR_REPLACE 0x0020/* pure set: fail if attr does not exist */ + +#define ATTR_KERNOTIME 0x1000/* [kernel] don't update inode timestamps */ +#define ATTR_KERNOVAL 0x2000/* [kernel] get attr size only, not value */ + +#define ATTR_INCOMPLETE 0x4000/* [kernel] return INCOMPLETE attr keys */ + +#define XFS_ATTR_FLAGS \ + { ATTR_DONTFOLLOW, "DONTFOLLOW" }, \ + { ATTR_ROOT, "ROOT" }, \ + { ATTR_TRUST, "TRUST" }, \ + { ATTR_SECURE, "SECURE" }, \ + { ATTR_CREATE, "CREATE" }, \ + { ATTR_REPLACE, "REPLACE" }, \ + { ATTR_KERNOTIME, "KERNOTIME" }, \ + { ATTR_KERNOVAL, "KERNOVAL" }, \ + { ATTR_INCOMPLETE, "INCOMPLETE" } + +/* +* The maximum size (into the kernel or returned from the kernel) of an +* attribute value or the buffer used for an attr_list() call. Larger +* sizes will result in an ERANGE return code. +*/ +#define ATTR_MAX_VALUELEN (64*1024)/* max length of a value */ + +/* +* Define how lists of attribute names are returned to the user from +* the attr_list() call. A large, 32bit aligned, buffer is passed in +* along with its size. We put an array of offsets at the top that each +* reference an attrlist_ent_t and pack the attrlist_ent_t's at the bottom. +*/ +typedef struct attrlist { +__s32 al_count;/* number of entries in attrlist */ +__s32 al_more;/* T/F: more attrs (do call again) */ +__s32 al_offset[1 ];/* byte offsets of attrs [var-sized] */ +}attrlist_t ; + +/* +* Show the interesting info about one attribute. This is what the +* al_offset[i] entry points to. +*/ +typedef struct attrlist_ent {/* data from attr_list() */ +__u32 a_valuelen;/* number bytes in value of attr */ +char a_name[1 ];/* attr name (NULL terminated) */ +}attrlist_ent_t ; + +/* +* Given a pointer to the (char*) buffer containing the attr_list() result, +* and an index, return a pointer to the indicated attribute in the buffer. +*/ +#define ATTR_ENTRY (buffer, index) \ + ((attrlist_ent_t *) \ + &((char *)buffer)[ ((attrlist_t *)(buffer))->al_offset[index] ]) + +/* +* Kernel-internal version of the attrlist cursor. +*/ +typedef struct attrlist_cursor_kern { +__u32 hashval;/* hash value of next entry to add */ +__u32 blkno;/* block containing entry (suggestion) */ +__u32 offset;/* offset in list of equal-hashvals */ +__u16 pad1;/* padding to match user-level */ +__u8 pad2;/* padding to match user-level */ +__u8 initted;/* T/F: cursor has been initialized */ +}attrlist_cursor_kern_t ; + + +/*======================================================================== +* Structure used to pass context around among the routines. +*========================================================================*/ + + +/* void; state communicated via *context */ +typedef void (*put_listent_func_t )(struct xfs_attr_list_context *,int , +unsigned char *,int ,int ); + +typedef struct xfs_attr_list_context { +struct xfs_trans *tp; +struct xfs_inode *dp;/* inode */ +struct attrlist_cursor_kern *cursor;/* position in list */ +char *alist;/* output buffer */ +int seen_enough;/* T/F: seen enough of list? */ +ssize_t count;/* num used entries */ +int dupcnt;/* count dup hashvals seen */ +int bufsize;/* total buffer size */ +int firstu;/* first used byte in buffer */ +int flags;/* from VOP call */ +int resynch;/* T/F: resynch with cursor */ +put_listent_func_t put_listent;/* list output fmt function */ +int index;/* index into output buffer */ +}xfs_attr_list_context_t ; + + +/*======================================================================== +* Function prototypes for the kernel. +*========================================================================*/ + +/* +* Overall external interface routines. +*/ +int xfs_attr_inactive (struct xfs_inode *dp); +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, +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); +int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name,int flags); +int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize, +int flags,struct attrlist_cursor_kern *cursor); + + +#endif /* __XFS_ATTR_H__ */
fs/xfs/xfs_attr.h deleted +0 -148
148 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v9 2/28 xfs: Add helper function xfs_attr_try_sf_addname
In reply to Allison HendersonThis patch adds a subroutine xfs_attr_try_sf_addname used by xfs_attr_set. This subrotine will attempt to add the attribute name specified in args in shortform, as well and perform error handling previously done in xfs_attr_set.
This patch helps to pre-simplify xfs_attr_set for reviewing purposes and reduce indentation. New function will be added in the next patch.
--- fs/xfs/libxfs/xfs_attr.c | 61 +++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 21 deletions(-)
fs/xfs/libxfs/xfs_attr.c +40 -21
@@ -191,6 +191,42 @@ 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; + + 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). +*/ +ASSERT (args->trans !=NULL ); + +/* +* If this is a synchronous mount, make sure +* that the transaction goes to disk before +* returning to the user. +*/ +if (mp->m_flags &XFS_MOUNT_WSYNC ) +xfs_trans_set_sync (args->trans); + +if (!error && (args->flags &ATTR_KERNOTIME ) ==0 ) { +xfs_trans_ichgtime (args->trans, dp, +XFS_ICHGTIME_CHG ); + } + +return error; +} + int xfs_attr_set( struct xfs_inode *dp,
@@ -281,30 +317,13 @@ xfs_attr_set(* Try to add the attr to the attribute list in * the inode. */ - error =xfs_attr_shortform_addname (&args); + error =xfs_attr_try_sf_addname (dp, &args);if (error != -ENOSPC ) { -/* -* Commit the shortform mods, and we're done. -* NOTE: this is also the error path (EEXIST, etc). -*/ -ASSERT (args.trans !=NULL ); - -/* -* If this is a synchronous mount, make sure that -* the transaction goes to disk before returning -* to the user. -*/ -if (mp->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args.trans); - -if (!error && (flags &ATTR_KERNOTIME ) ==0 ) { -xfs_trans_ichgtime (args.trans, dp, -XFS_ICHGTIME_CHG ); - } err2 =xfs_trans_commit (args.trans); -xfs_iunlock (dp,XFS_ILOCK_EXCL ); + error = error ? error : err2; -return error ? error : err2; +xfs_iunlock (dp,XFS_ILOCK_EXCL ); +return error; }/*
Signature · 1 line
2.7.4
Re: [PATCH v9 02/28] xfs: Add helper function xfs_attr_try_sf_addname
Quoted 23 lines · Allison Henderson
This patch adds a subroutine
xfs_attr_try_sf_addnameused byxfs_attr_set. This subrotine will attempt to add the attribute name specified in args in shortform, as well and perform error handling previously done inxfs_attr_set.This patch helps to pre-simplify
xfs_attr_setfor reviewing purposes and reduce indentation. New function will be added in the next patch.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 61 +++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 21 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0@@ -191,6 +191,42 @@ xfs_attr_calc_size(return nblks; }
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 203
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+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; + + error =xfs_attr_shortform_addname (args);
I wonder, what error codes can come out of this function? -ENOSPC, -EEXIST, zero...?
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 212
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+if (error == -ENOSPC ) +return error; + +/* +* Commit the shortform mods, and we're done. +* NOTE: this is also the error path +* (EEXIST, etc). +*/ +ASSERT (args->trans !=NULL );
<urk> Um... I get that this is just mechanical code refactoring, but...
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 220
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +8
-0+ +/* +* If this is a synchronous mount, make sure +* that the transaction goes to disk before +* returning to the user. +*/ +if (mp->m_flags &XFS_MOUNT_WSYNC ) +xfs_trans_set_sync (args->trans);
...let's say we're on the error path. Why would we care about making the transaction synchronous?
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 225
Quoted 5 lines
fs/xfs/libxfs/xfs_attr.c +5
-0+ +if (!error && (args->flags &ATTR_KERNOTIME ) ==0 ) { +xfs_trans_ichgtime (args->trans, dp, +XFS_ICHGTIME_CHG ); + }
And what's the point of updating ctime if we do?
And can we restructure this to follow the usual pattern:
error = xfs_blabhablhablah(...);
if (error)
bail out;
<keep going>
Quoted 29 lines
fs/xfs/libxfs/xfs_attr.c +5
-16+ +return error; +} + int xfs_attr_set( struct xfs_inode *dp,@@ -281,30 +317,13 @@ xfs_attr_set(* Try to add the attr to the attribute list in * the inode. */ - error =xfs_attr_shortform_addname (&args); + error =xfs_attr_try_sf_addname (dp, &args);if (error != -ENOSPC ) { -/* -* Commit the shortform mods, and we're done. -* NOTE: this is also the error path (EEXIST, etc). -*/ -ASSERT (args.trans !=NULL ); - -/* -* If this is a synchronous mount, make sure that -* the transaction goes to disk before returning -* to the user. -*/ -if (mp->m_flags &XFS_MOUNT_WSYNC ) -xfs_trans_set_sync (args.trans); - -if (!error && (flags &ATTR_KERNOTIME ) ==0 ) {
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 326
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +3
-5-xfs_trans_ichgtime (args.trans, dp, -XFS_ICHGTIME_CHG ); - } err2 =xfs_trans_commit (args.trans); -xfs_iunlock (dp,XFS_ILOCK_EXCL ); + error = error ? error : err2; -return error ? error : err2; +xfs_iunlock (dp,XFS_ILOCK_EXCL ); +return error;
Huh, so we commit the transaction on error?? Why?
/me runs away
--D
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c +0
-0}/* Signature · 1 line
2.7.4
Re: [PATCH v9 02/28] xfs: Add helper function xfs_attr_try_sf_addname
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Allison Henderson
This patch adds a subroutine
xfs_attr_try_sf_addnameused byxfs_attr_set. This subrotine will attempt to add the attribute name specified in args in shortform, as well and perform error handling previously done inxfs_attr_set.This patch helps to pre-simplify
xfs_attr_setfor reviewing purposes and reduce indentation. New function will be added in the next patch.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 61 +++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 21 deletions(-)fs/xfs/libxfs/xfs_attr.c +0
-0@@ -191,6 +191,42 @@ xfs_attr_calc_size(return nblks; }
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 203
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+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; + + error =xfs_attr_shortform_addname (args);I wonder, what error codes can come out of this function?
-ENOSPC,-EEXIST, zero...?
-ENOATTR, -EFSCORRUPTED, -EIO, etc.
ENOSPC here says "attr doesn't fit in shortform, try leaf format", while every other error needs to be handled as a shortform addition error.
Quoted 13 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 212
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +9
-0+if (error == -ENOSPC ) +return error; + +/* +* Commit the shortform mods, and we're done. +* NOTE: this is also the error path +* (EEXIST, etc). +*/ +ASSERT (args->trans !=NULL );<urk> Um... I get that this is just mechanical code refactoring, but...
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 220
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +8
-0+ +/* +* If this is a synchronous mount, make sure +* that the transaction goes to disk before +* returning to the user. +*/ +if (mp->m_flags &XFS_MOUNT_WSYNC ) +xfs_trans_set_sync (args->trans);...let's say we're on the error path. Why would we care about making the transaction synchronous?
Because we've already modified the inode to add an attr fork, and we have to obey WSYNC rules for inode changes whether the attr was added or not.
Quoted 6 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_calc_size( · line 225
Quoted 4 lines
fs/xfs/libxfs/xfs_attr.c +4
-0+if (!error && (args->flags &ATTR_KERNOTIME ) ==0 ) { +xfs_trans_ichgtime (args->trans, dp, +XFS_ICHGTIME_CHG ); + }And what's the point of updating ctime if we do?
This is only run if there wasn't an error - it's skipped if we didn't add the attribute to the inode.
Quoted 7 lines
And can we restructure this to follow the usual pattern:
error =
xfs_blabhablhablah(...);
if (error)bail out;<keep going>
Not quite that simple, some errors still require us to commit the transaction. And if we've got a fatal error, then the commit will fail anyway.
Quoted 9 lines
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 326
Quoted 7 lines
fs/xfs/libxfs/xfs_attr.c +3
-2err2 =xfs_trans_commit (args.trans); -xfs_iunlock (dp,XFS_ILOCK_EXCL ); + error = error ? error : err2; -return error ? error : err2; +xfs_iunlock (dp,XFS_ILOCK_EXCL ); +return error;Huh, so we commit the transaction on error?? Why?
So we don't shut down the filesystem by cancelling a dirty transaction on an -EEXIST or -ENOATTR error after we added the attr fork to the inode.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v9 3/28 xfs: Add attibute set and helper functions
In reply to Allison HendersonThis patch adds xfs_attr_set_args and xfs_bmap_set_attrforkoff. These sub-routines set the attributes specified in @args. We will use this later for setting parent pointers as a deferred attribute operation.
--- fs/xfs/libxfs/xfs_attr.c | 152 ++++++++++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_bmap.c | 49 +++++++++------ fs/xfs/libxfs/xfs_bmap.h | 1 + 4 files changed, 122 insertions(+), 81 deletions(-)
fs/xfs/libxfs/xfs_attr.c +90 -62
@@ -227,6 +227,94 @@ xfs_attr_try_sf_addname(return error; } +/* +* Set the attribute specified in @args. +*/ +int +xfs_attr_set_args ( +struct xfs_da_args *args, +struct xfs_buf **leaf_bp) +{ +struct xfs_inode *dp = args->dp; +int error; +int sf_size; + +/* +* New inodes setting the parent pointer attr will +* not have an attribute fork yet. So set the attribute +* fork appropriately +*/ +if (XFS_IFORK_Q ((args->dp)) ==0 ) { + sf_size =sizeof (struct xfs_attr_sf_hdr ) + +XFS_ATTR_SF_ENTSIZE_BYNAME (args->namelen, args->valuelen); +xfs_bmap_set_attrforkoff (args->dp, sf_size,NULL ); + args->dp->i_afp =kmem_zone_zalloc (xfs_ifork_zone,KM_SLEEP ); + args->dp->i_afp->if_flags =XFS_IFEXTENTS ; + } + +/* +* If the attribute list is non-existent or a shortform list, +* upgrade it to a single-leaf-block attribute list. +*/ +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 )) { + +/* +* 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_try_sf_addname (dp, args); +if (error != -ENOSPC ) + goto out; + +/* +* 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) + goto out; + +/* +* Prevent the leaf buffer from being unlocked so that a +* concurrent AIL push cannot grab the half-baked leaf +* buffer and run into problems with the write verifier. +*/ +xfs_trans_bhold (args->trans, *leaf_bp); + + error =xfs_defer_finish (&args->trans); +if (error) + goto out; + +/* +* Commit the leaf transformation. We'll need another +* (linked) transaction to add the new attribute to the +* leaf. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; +xfs_trans_bjoin (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } + +if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_attr_leaf_addname (args); +else + error =xfs_attr_node_addname (args); +if (error) + goto out; + +out: +return error; +} + int xfs_attr_set( struct xfs_inode *dp,
@@ -240,7 +328,7 @@ xfs_attr_set(struct xfs_da_args args;struct xfs_trans_res tres;int rsvd = (flags &ATTR_ROOT ) !=0 ; -int error, err2, local; +int error, local;XFS_STATS_INC (mp, xs_attr_set);
@@ -298,67 +386,7 @@ xfs_attr_set( }xfs_trans_ijoin (args.trans, dp,0 ); - -/* -* If the attribute list is non-existent or a shortform list, -* upgrade it to a single-leaf-block attribute list. -*/ -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 )) { - -/* -* 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_try_sf_addname (dp, &args); -if (error != -ENOSPC ) { - err2 =xfs_trans_commit (args.trans); - error = error ? error : err2; - -xfs_iunlock (dp,XFS_ILOCK_EXCL ); -return error; - } - -/* -* It won't fit in the shortform, transform to a leaf block. -* GROT: another possible req'mt for a double-split btree op. -*/ - error =xfs_attr_shortform_to_leaf (&args, &leaf_bp); -if (error) - goto out; -/* -* Prevent the leaf buffer from being unlocked so that a -* concurrent AIL push cannot grab the half-baked leaf -* buffer and run into problems with the write verifier. -*/ -xfs_trans_bhold (args.trans, leaf_bp); - error =xfs_defer_finish (&args.trans); -if (error) - goto out; - -/* -* Commit the leaf transformation. We'll need another (linked) -* transaction to add the new attribute to the leaf, which -* means that we have to hold & join the leaf buffer here too. -*/ - error =xfs_trans_roll_inode (&args.trans, dp); -if (error) - goto out; -xfs_trans_bjoin (args.trans, leaf_bp); - leaf_bp =NULL ; - } - -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_leaf_addname (&args); -else - error =xfs_attr_node_addname (&args); + error =xfs_attr_set_args (&args, &leaf_bp);if (error) goto out;
fs/xfs/libxfs/xfs_attr.h +1 -0
@@ -140,6 +140,7 @@ int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name, 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); +int xfs_attr_set_args (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name,int flags);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor);
fs/xfs/libxfs/xfs_bmap.c +30 -19
62 lines not on this page · raw message
fs/xfs/libxfs/xfs_bmap.h +1 -0
@@ -183,6 +183,7 @@ void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno, xfs_filblks_t len);void xfs_trim_extent_eof (struct xfs_bmbt_irec *,struct xfs_inode *);int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd); +int xfs_bmap_set_attrforkoff (struct xfs_inode *ip,int size,int *version);void xfs_bmap_local_to_extents_empty (struct xfs_inode *ip,int whichfork); void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno, xfs_filblks_t len, struct xfs_owner_info *oinfo,
Signature · 1 line
2.7.4
Re: [PATCH v9 03/28] xfs: Add attibute set and helper functions
Quoted 35 lines · Allison Henderson
This patch adds
xfs_attr_set_argsandxfs_bmap_set_attrforkoff. These sub-routines set the attributes specified in @args. We will use this later for setting parent pointers as a deferred attribute operation.Signed-off-by Allison Henderson <[email protected]>--- fs/xfs/libxfs/xfs_attr.c | 152 ++++++++++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_bmap.c | 49 +++++++++------ fs/xfs/libxfs/xfs_bmap.h | 1 + 4 files changed, 122 insertions(+), 81 deletions(-)fs/xfs/libxfs/xfs_attr.c +14
-0@@ -227,6 +227,94 @@ xfs_attr_try_sf_addname(return error; } +/* +* Set the attribute specified in @args. +*/ +int +xfs_attr_set_args ( +struct xfs_da_args *args, +struct xfs_buf **leaf_bp) +{ +struct xfs_inode *dp = args->dp; +int error; +int sf_size; + +/* +* New inodes setting the parent pointer attr will
fs/xfs/libxfs/xfs_attr.c xfs_attr_try_sf_addname( · line 253
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+* not have an attribute fork yet. So set the attribute +* fork appropriately +*/ +if (XFS_IFORK_Q ((args->dp)) ==0 ) { + sf_size =sizeof (struct xfs_attr_sf_hdr ) + +XFS_ATTR_SF_ENTSIZE_BYNAME (args->namelen, args->valuelen); +xfs_bmap_set_attrforkoff (args->dp, sf_size,NULL ); + args->dp->i_afp =kmem_zone_zalloc (xfs_ifork_zone,KM_SLEEP ); + args->dp->i_afp->if_flags =XFS_IFEXTENTS ; + }
This is new code. It is essentially trying to duplicate what xfs_attr_set() has arelady done with a call to xfs_bmap_add_attrfork(). It's also not correct, because we don't know we are adding a sf attr yet, and won't know until xfs_attr_try_sf_addname() is called.
Quoted 11 lines
fs/xfs/libxfs/xfs_attr.c +11
-0+ +/* +* If the attribute list is non-existent or a shortform list, +* upgrade it to a single-leaf-block attribute list. +*/ +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 )) { + +/* +* Build initial attribute list (if required).
fs/xfs/libxfs/xfs_attr.c xfs_attr_try_sf_addname( · line 274
Quoted 10 lines
fs/xfs/libxfs/xfs_attr.c +10
-0+*/ +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_try_sf_addname (dp, args); +if (error != -ENOSPC ) + goto out;
This changes EEXIST or ENOENT error handling after creating the attr fork (which modifies the inode and dirties the transaction). The current code commits the attr fork changes on error (which is harmless), but after this change we....
[...]
fs/xfs/libxfs/xfs_attr.c xfs_attr_set( · line 391
Quoted 8 lines
fs/xfs/libxfs/xfs_attr.c +1
-5- -if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_leaf_addname (&args); -else - error =xfs_attr_node_addname (&args); + error =xfs_attr_set_args (&args, &leaf_bp);if (error) goto out;
End up jumping to the transaction cancelling code. IOWs, if we get an error other than ENOSPC, we'll shut the filesystem down now, instead of handling it gracefully and returning the error to userspace.
I've got fixes for all this - I'll test them first before posting updates for you...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v9 4/28 xfs: Add attibute remove and helper functions
In reply to Allison HendersonThis patch adds xfs_attr_remove_args. These sub-routines remove the attributes specified in @args. We will use this later for setting parent pointers as a deferred attribute operation.
--- fs/xfs/libxfs/xfs_attr.c | 36 +++++++++++++++++++++++++----------- fs/xfs/libxfs/xfs_attr.h | 1 + 2 files changed, 26 insertions(+), 11 deletions(-)
fs/xfs/libxfs/xfs_attr.c +25 -11
@@ -315,6 +315,30 @@ xfs_attr_set_args(return error; } +/* +* Remove the attribute specified in @args. +*/ +int +xfs_attr_remove_args ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +int error; + +if (!xfs_inode_hasattr (dp)) { + error = -ENOATTR ; + }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_attr_shortform_remove (args); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { + error =xfs_attr_leaf_removename (args); + }else { + error =xfs_attr_node_removename (args); + } + +return error; +} + int xfs_attr_set( struct xfs_inode *dp,
@@ -470,17 +494,7 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); -if (!xfs_inode_hasattr (dp)) { - error = -ENOATTR ; - }else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { -ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); - error =xfs_attr_shortform_remove (&args); - }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (&args); - }else { - error =xfs_attr_node_removename (&args); - } - + error =xfs_attr_remove_args (&args);if (error) goto out;
fs/xfs/libxfs/xfs_attr.h +1 -0
@@ -142,6 +142,7 @@ int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name, unsigned char *value, int valuelen, int flags);int xfs_attr_set_args (struct xfs_da_args *args,struct xfs_buf **leaf_bp);int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *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);
Signature · 1 line
2.7.4
PATCH v9 5/28 xfs: Hold inode locks in xfs_ialloc
In reply to Allison HendersonModify xfs_ialloc to hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operations
--- fs/xfs/xfs_inode.c | 6 +++++- fs/xfs/xfs_qm.c | 1 + fs/xfs/xfs_symlink.c | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-)
fs/xfs/xfs_inode.c +5 -1
@@ -744,6 +744,8 @@ xfs_lookup(* to attach to or associate with (i.e. pip == NULL) because they * are not linked into the directory structure - they are attached * directly to the superblock - and so have no parent. +* +* Caller is responsible for unlocking the inode manually upon return */ static int xfs_ialloc(
@@ -942,7 +944,7 @@ xfs_ialloc(/* * Log the new values stuffed into the inode. */ -xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, ip,0 );xfs_trans_log_inode (tp, ip, flags);/* now that we have an i_mode we can setup the inode structure */
@@ -1264,6 +1266,7 @@ xfs_create(xfs_qm_dqrele (pdqp); *ipp = ip; +xfs_iunlock (ip,XFS_ILOCK_EXCL );return 0 ; out_trans_cancel:
@@ -1359,6 +1362,7 @@ xfs_create_tmpfile(xfs_qm_dqrele (pdqp); *ipp = ip; +xfs_iunlock (ip,XFS_ILOCK_EXCL );return 0 ; out_trans_cancel:
fs/xfs/xfs_qm.c +1 -0
@@ -820,6 +820,7 @@ xfs_qm_qino_alloc( }if (need_alloc)xfs_finish_inode_setup (*ip); +xfs_iunlock (*ip,XFS_ILOCK_EXCL );return error; }
fs/xfs/xfs_symlink.c +3 -0
@@ -352,6 +352,7 @@ xfs_symlink(xfs_qm_dqrele (pdqp); *ipp = ip; +xfs_iunlock (ip,XFS_ILOCK_EXCL );return 0 ; out_trans_cancel:
@@ -373,6 +374,8 @@ xfs_symlink(if (unlock_dp_on_error)xfs_iunlock (dp,XFS_ILOCK_EXCL ); +if (ip) +xfs_iunlock (ip,XFS_ILOCK_EXCL );return error; }
Signature · 1 line
2.7.4
Re: [PATCH v9 05/28] xfs: Hold inode locks in xfs_ialloc
Quoted 42 lines · Allison Henderson
Modify
xfs_iallocto hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operationsSigned-off-by Allison Henderson <[email protected]>--- fs/xfs/xfs_inode.c | 6 +++++- fs/xfs/xfs_qm.c | 1 + fs/xfs/xfs_symlink.c | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-)fs/xfs/xfs_inode.c +4
-1@@ -744,6 +744,8 @@ xfs_lookup(* to attach to or associate with (i.e. pip == NULL) because they * are not linked into the directory structure - they are attached * directly to the superblock - and so have no parent. +* +* Caller is responsible for unlocking the inode manually upon return */ static int xfs_ialloc(@@ -942,7 +944,7 @@ xfs_ialloc(/* * Log the new values stuffed into the inode. */ -xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, ip,0 );xfs_trans_log_inode (tp, ip, flags);/* now that we have an i_mode we can setup the inode structure */ @@ -1264,6 +1266,7 @@ xfs_create(xfs_qm_dqrele (pdqp); *ipp = ip; +xfs_iunlock (ip,XFS_ILOCK_EXCL );return 0 ; out_trans_cancel:
fs/xfs/xfs_inode.c xfs_create_tmpfile( · line 1368
Quoted 7 lines
fs/xfs/xfs_inode.c +1
-0@@ -1359,6 +1362,7 @@ xfs_create_tmpfile(xfs_qm_dqrele (pdqp); *ipp = ip; +xfs_iunlock (ip,XFS_ILOCK_EXCL );return 0 ; out_trans_cancel:
It looks like the error paths that get run after a successful call to xfs_dir_ialloc() don't unlock the inode correctly.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH v9 6/28 xfs: Add trans toggle to attr routines
In reply to Allison HendersonThis patch adds a roll_trans parameter to all attribute routines that may roll a transaction. Calling functions may pass true to roll transactions as normal, or false to hold them.
This patch is temporary and will be removed later when all code paths have been made to pass a false value. The temporary boolean assists us to introduce changes across multiple smaller patches instead of handling all affected code paths in one large patch.
--- fs/xfs/libxfs/xfs_attr.c | 244 +++++++++++++++++++++++----------------- fs/xfs/libxfs/xfs_attr.h | 5 +- fs/xfs/libxfs/xfs_attr_leaf.c | 20 +++- fs/xfs/libxfs/xfs_attr_leaf.h | 8 +- fs/xfs/libxfs/xfs_attr_remote.c | 50 ++++---- fs/xfs/libxfs/xfs_attr_remote.h | 4 +- 6 files changed, 195 insertions(+), 136 deletions(-)
fs/xfs/libxfs/xfs_attr.c +142 -102
@@ -49,15 +49,15 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args); +STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args, bool roll_trans); +STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args, bool roll_trans);/* * Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args); -STATIC int xfs_attr_node_removename(xfs_da_args_t *args); +STATIC int xfs_attr_node_addname(xfs_da_args_t *args, bool roll_trans); +STATIC int xfs_attr_node_removename(xfs_da_args_t *args, bool roll_trans); STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
@@ -233,10 +233,11 @@ xfs_attr_try_sf_addname(int xfs_attr_set_args (struct xfs_da_args *args, -struct xfs_buf **leaf_bp) +struct xfs_buf **leaf_bp, +bool roll_trans) {struct xfs_inode *dp = args->dp; -int error; +int error =0 ;int sf_size;/*
@@ -281,33 +282,35 @@ xfs_attr_set_args(if (error) goto out; -/* -* 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); +if (roll_trans) { +/* +* Prevent the leaf buffer from being unlocked so that a +* concurrent AIL push cannot grab the half-baked leaf +* buffer and run into problems with the write verifier. +*/ +xfs_trans_bhold (args->trans, *leaf_bp); - error =xfs_defer_finish (&args->trans); -if (error) - goto out; + error =xfs_defer_finish (&args->trans); +if (error) + goto out; -/* -* Commit the leaf transformation. We'll need another -* (linked) transaction to add the new attribute to the -* leaf. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; -xfs_trans_bjoin (args->trans, *leaf_bp); - *leaf_bp =NULL ; +/* +* Commit the leaf transformation. We'll need another +* (linked) transaction to add the new attribute to the +* leaf. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; +xfs_trans_bjoin (args->trans, *leaf_bp); + *leaf_bp =NULL ; + } }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_leaf_addname (args); + error =xfs_attr_leaf_addname (args, roll_trans);else - error =xfs_attr_node_addname (args); + error =xfs_attr_node_addname (args, roll_trans);if (error) goto out;
@@ -320,7 +323,8 @@ xfs_attr_set_args(*/ int xfs_attr_remove_args ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_inode *dp = args->dp;int error;
@@ -331,9 +335,9 @@ xfs_attr_remove_args(ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); error =xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args); + error =xfs_attr_leaf_removename (args, roll_trans); }else { - error =xfs_attr_node_removename (args); + error =xfs_attr_node_removename (args, roll_trans); }return error;
@@ -410,7 +414,7 @@ xfs_attr_set( }xfs_trans_ijoin (args.trans, dp,0 ); - error =xfs_attr_set_args (&args, &leaf_bp); + error =xfs_attr_set_args (&args, &leaf_bp, true);if (error) goto out;
@@ -494,7 +498,8 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); - error =xfs_attr_remove_args (&args); + error =xfs_attr_remove_args (&args, true); +if (error) goto out;
@@ -584,7 +589,8 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)*/ STATIC intxfs_attr_leaf_addname ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_inode *dp;struct xfs_buf *bp;
@@ -649,32 +655,39 @@ xfs_attr_leaf_addname( error =xfs_attr3_leaf_to_node (args);if (error) goto out_defer_cancel; - 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; +if (roll_trans) { + error =xfs_defer_finish (&args->trans); +if (error) +return error; + +/* +* Commit the current trans (including the inode) and +* start a new one. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + }/* * Fob the whole rest of the problem off on the Btree code. */ - error =xfs_attr_node_addname (args); + error =xfs_attr_node_addname (args, roll_trans); +return error; } -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; + +if (roll_trans) { +/* +* Commit the transaction that added the attr name so that +* later routines can manage their own transactions. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) +return error; + }/* * If there was an out-of-line value, allocate the blocks we
@@ -683,7 +696,7 @@ xfs_attr_leaf_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + error =xfs_attr_rmtval_set (args, roll_trans);if (error)return error; }
@@ -699,7 +712,7 @@ xfs_attr_leaf_addname(* In a separate transaction, set the incomplete flag on the * "old" attr and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args); + error =xfs_attr3_leaf_flipflags (args, roll_trans);if (error)return error;
@@ -713,7 +726,7 @@ xfs_attr_leaf_addname( args->rmtblkcnt = args->rmtblkcnt2; args->rmtvaluelen = args->rmtvaluelen2;if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args); + error =xfs_attr_rmtval_remove (args, roll_trans);if (error)return error; }
@@ -737,21 +750,25 @@ xfs_attr_leaf_addname(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out_defer_cancel; - error =xfs_defer_finish (&args->trans); -if (error) -return error; + +if (roll_trans) { + 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); +if (roll_trans) + 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); + error =xfs_attr3_leaf_clearflag (args, roll_trans); }return error; out_defer_cancel:
@@ -767,7 +784,8 @@ xfs_attr_leaf_addname(*/ STATIC intxfs_attr_leaf_removename ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_inode *dp;struct xfs_buf *bp;
@@ -800,9 +818,11 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out_defer_cancel; - error =xfs_defer_finish (&args->trans); -if (error) -return error; +if (roll_trans) { + error =xfs_defer_finish (&args->trans); +if (error) +return error; + } }return 0 ; out_defer_cancel:
@@ -858,7 +878,8 @@ xfs_attr_leaf_get(xfs_da_args_t *args)*/ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_da_state *state;struct xfs_da_state_blk *blk;
@@ -923,20 +944,24 @@ xfs_attr_node_addname(*/ xfs_da_state_free (state); state =NULL ; + error =xfs_attr3_leaf_to_node (args);if (error) goto out_defer_cancel; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; -/* -* Commit the node conversion and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; +if (roll_trans) { + error =xfs_defer_finish (&args->trans); +if (error) + goto out; + +/* +* Commit the node conversion and start the next +* trans in the chain. +*/ + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + } goto restart; }
@@ -950,9 +975,12 @@ xfs_attr_node_addname( error =xfs_da3_split (state);if (error) goto out_defer_cancel; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; + +if (roll_trans) { + error =xfs_defer_finish (&args->trans); +if (error) + goto out; + } }else {/* * Addition succeeded, update Btree hashvals.
@@ -971,9 +999,11 @@ xfs_attr_node_addname(* Commit the leaf addition or btree split and start the next * trans in the chain. */ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; +if (roll_trans) { + error =xfs_trans_roll_inode (&args->trans, dp); +if (error) + goto out; + }/* * If there was an out-of-line value, allocate the blocks we
@@ -982,7 +1012,7 @@ xfs_attr_node_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args); + error =xfs_attr_rmtval_set (args, roll_trans);if (error)return error; }
@@ -998,7 +1028,7 @@ xfs_attr_node_addname(* In a separate transaction, set the incomplete flag on the * "old" attr and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args); + error =xfs_attr3_leaf_flipflags (args, roll_trans);if (error) goto out;
@@ -1012,7 +1042,7 @@ xfs_attr_node_addname( args->rmtblkcnt = args->rmtblkcnt2; args->rmtvaluelen = args->rmtvaluelen2;if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args); + error =xfs_attr_rmtval_remove (args, roll_trans);if (error)return error; }
@@ -1046,9 +1076,11 @@ xfs_attr_node_addname( error =xfs_da3_join (state);if (error) goto out_defer_cancel; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; +if (roll_trans) { + error =xfs_defer_finish (&args->trans); +if (error) + goto out; + } }/*
@@ -1062,7 +1094,7 @@ xfs_attr_node_addname(/* * Added a "remote" value, just clear the incomplete flag. */ - error =xfs_attr3_leaf_clearflag (args); + error =xfs_attr3_leaf_clearflag (args, roll_trans);if (error) goto out; }
@@ -1088,7 +1120,8 @@ xfs_attr_node_addname(*/ STATIC intxfs_attr_node_removename ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_da_state *state;struct xfs_da_state_blk *blk;
@@ -1138,10 +1171,10 @@ xfs_attr_node_removename(* Mark the attribute as INCOMPLETE, then bunmapi() the * remote value. */ - error =xfs_attr3_leaf_setflag (args); + error =xfs_attr3_leaf_setflag (args, roll_trans);if (error) goto out; - error =xfs_attr_rmtval_remove (args); + error =xfs_attr_rmtval_remove (args, roll_trans);if (error) goto out;
@@ -1169,15 +1202,19 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out_defer_cancel; - 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; + +if (roll_trans) { + 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; + } }/*
@@ -1200,9 +1237,12 @@ xfs_attr_node_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out_defer_cancel; - error =xfs_defer_finish (&args->trans); -if (error) - goto out; + +if (roll_trans) { + error =xfs_defer_finish (&args->trans); +if (error) + goto out; + } }else xfs_trans_brelse (args->trans, bp); }
fs/xfs/libxfs/xfs_attr.h +3 -2
@@ -140,9 +140,10 @@ int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name, 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); -int xfs_attr_set_args (struct xfs_da_args *args,struct xfs_buf **leaf_bp); +int xfs_attr_set_args (struct xfs_da_args *args,struct xfs_buf **leaf_bp, +bool roll_trans);int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name,int flags); -int xfs_attr_remove_args (struct xfs_da_args *args); +int xfs_attr_remove_args (struct xfs_da_args *args,bool roll_trans);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 +14 -6
@@ -2639,7 +2639,8 @@ xfs_attr_leaf_newentsize(*/ int xfs_attr3_leaf_clearflag ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_attr_leafblock *leaf;struct xfs_attr_leaf_entry *entry;
@@ -2700,7 +2701,9 @@ xfs_attr3_leaf_clearflag(/* * Commit the flag value change and start the next trans in series. */ -return xfs_trans_roll_inode (&args->trans, args->dp); +if (roll_trans) + error =xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/*
@@ -2708,7 +2711,8 @@ xfs_attr3_leaf_clearflag(*/ int xfs_attr3_leaf_setflag ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_attr_leafblock *leaf;struct xfs_attr_leaf_entry *entry;
@@ -2751,7 +2755,9 @@ xfs_attr3_leaf_setflag(/* * Commit the flag value change and start the next trans in series. */ -return xfs_trans_roll_inode (&args->trans, args->dp); +if (roll_trans) + error =xfs_trans_roll_inode (&args->trans, args->dp); +return error; }/*
@@ -2763,7 +2769,8 @@ xfs_attr3_leaf_setflag(*/ int xfs_attr3_leaf_flipflags ( -struct xfs_da_args *args) +struct xfs_da_args *args, +bool roll_trans) {struct xfs_attr_leafblock *leaf1;struct xfs_attr_leafblock *leaf2;
@@ -2869,7 +2876,8 @@ xfs_attr3_leaf_flipflags(/* * Commit the flag value change and start the next trans in series. */ - error =xfs_trans_roll_inode (&args->trans, args->dp); +if (roll_trans) + error =xfs_trans_roll_inode (&args->trans, args->dp);return error; }
fs/xfs/libxfs/xfs_attr_leaf.h +4 -4
@@ -49,10 +49,10 @@ void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);*/ int xfs_attr3_leaf_to_node (struct xfs_da_args *args);int xfs_attr3_leaf_to_shortform (struct xfs_buf *bp, -struct xfs_da_args *args,int forkoff); -int xfs_attr3_leaf_clearflag (struct xfs_da_args *args); -int xfs_attr3_leaf_setflag (struct xfs_da_args *args); -int xfs_attr3_leaf_flipflags (struct xfs_da_args *args); +struct xfs_da_args *args,int forkoff); +int xfs_attr3_leaf_clearflag (struct xfs_da_args *args,bool roll_trans); +int xfs_attr3_leaf_setflag (struct xfs_da_args *args,bool roll_trans); +int xfs_attr3_leaf_flipflags (struct xfs_da_args *args,bool roll_trans);/* * Routines used for growing the Btree.
fs/xfs/libxfs/xfs_attr_remote.c +30 -20
81 lines not on this page · raw message
fs/xfs/libxfs/xfs_attr_remote.h +2 -2
@@ -9,7 +9,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_set (struct xfs_da_args *args,bool roll_trans); +int xfs_attr_rmtval_remove (struct xfs_da_args *args,bool roll_trans);#endif /* __XFS_ATTR_REMOTE_H__ */
Signature · 1 line
2.7.4
PATCH v9 7/28 xfs: Set up infastructure for deferred attribute operations
In reply to Allison HendersonThis patch adds two new log item types for setting or removing attributes as deferred operations. The xfs_attri_log_item logs an intent to set or remove an attribute. The corresponding xfs_attrd_log_item holds a reference to the xfs_attri_log_item and is freed once the transaction is done. Both log items use a generic xfs_attr_log_format structure that contains the attribute name, value, flags, inode, and an op_flag that indicates if the operations is a set or remove.
--- fs/xfs/Makefile | 2 + fs/xfs/libxfs/xfs_attr.c | 5 +- fs/xfs/libxfs/xfs_attr.h | 26 +- fs/xfs/libxfs/xfs_defer.h | 1 + fs/xfs/libxfs/xfs_log_format.h | 44 +++- fs/xfs/libxfs/xfs_types.h | 1 + fs/xfs/xfs_attr_item.c | 569 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_attr_item.h | 114 +++++++++ fs/xfs/xfs_log_recover.c | 172 +++++++++++++ fs/xfs/xfs_ondisk.h | 2 + fs/xfs/xfs_super.c | 1 + fs/xfs/xfs_trans.h | 12 + fs/xfs/xfs_trans_attr.c | 258 +++++++++++++++++++ 13 files changed, 1202 insertions(+), 5 deletions(-)
fs/xfs/Makefile +2 -0
@@ -97,6 +97,7 @@ xfs-y += xfs_log.o \ xfs_bmap_item.o \ xfs_buf_item.o \ xfs_extfree_item.o \ + xfs_attr_item.o \ xfs_icreate_item.o \ xfs_inode_item.o \ xfs_refcount_item.o \
@@ -106,6 +107,7 @@ xfs-y += xfs_log.o \ xfs_trans_bmap.o \ xfs_trans_buf.o \ xfs_trans_extfree.o \ + xfs_trans_attr.o \ xfs_trans_inode.o \ xfs_trans_refcount.o \ xfs_trans_rmap.o \
fs/xfs/libxfs/xfs_attr.c +3 -2
@@ -29,6 +29,7 @@#include "xfs_quota.h" #include "xfs_trans_space.h" #include "xfs_trace.h" +#include "xfs_attr_item.h" /* * xfs_attr.c
@@ -62,7 +63,7 @@ STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state); -STATIC int +int xfs_attr_args_init( struct xfs_da_args *args, struct xfs_inode *dp,
@@ -158,7 +159,7 @@ xfs_attr_get(/* * Calculate how many blocks we need for the new attribute, */ -STATIC int +int xfs_attr_calc_size (struct xfs_da_args *args,int *local)
fs/xfs/libxfs/xfs_attr.h +25 -1
@@ -78,6 +78,28 @@ typedef struct attrlist_ent { /* data from attr_list() */ } attrlist_ent_t;/* +* List of attrs to commit later. +*/ +struct xfs_attr_item { +struct xfs_inode *xattri_ip; +uint32_t xattri_op_flags; +void * xattri_value;/* attr value */ +uint32_t xattri_value_len;/* length of value */ +void * xattri_name;/* attr name */ +uint32_t xattri_name_len;/* length of name */ +uint32_t xattri_flags;/* attr flags */ +struct list_head xattri_list; + +/* +* A byte array follows the header containing the file name and +* attribute value. +*/ +}; + +#define XFS_ATTR_ITEM_SIZEOF (namelen, valuelen) \ + (sizeof(struct xfs_attr_item) + (namelen) + (valuelen)) + +/* * Given a pointer to the (char*) buffer containing the attr_list() result, * and an index, return a pointer to the indicated attribute in the buffer. */
@@ -146,6 +168,8 @@ int xfs_attr_remove(struct xfs_inode *dp, const unsigned char *name, int flags);int xfs_attr_remove_args (struct xfs_da_args *args,bool roll_trans);int xfs_attr_list (struct xfs_inode *dp,char *buffer,int bufsize,int flags,struct attrlist_cursor_kern *cursor); - +int xfs_attr_args_init (struct xfs_da_args *args,struct xfs_inode *dp, +const unsigned char *name,int flags); +int xfs_attr_calc_size (struct xfs_da_args *args,int *local);#endif /* __XFS_ATTR_H__ */
fs/xfs/libxfs/xfs_defer.h +1 -0
@@ -31,6 +31,7 @@ enum xfs_defer_ops_type {XFS_DEFER_OPS_TYPE_RMAP ,XFS_DEFER_OPS_TYPE_FREE ,XFS_DEFER_OPS_TYPE_AGFL_FREE , +XFS_DEFER_OPS_TYPE_ATTR , XFS_DEFER_OPS_TYPE_MAX, };
fs/xfs/libxfs/xfs_log_format.h +42 -2
66 lines not on this page · raw message
fs/xfs/libxfs/xfs_types.h +1 -0
@@ -11,6 +11,7 @@ typedef uint32_t prid_t; /* project ID */typedef uint32_t xfs_agblock_t ;/* blockno in alloc. group */ typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ +typedef uint32_t xfs_attrlen_t ;/* attr length */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ typedef int32_t xfs_extnum_t ;/* # of extents in a file */ typedef int16_t xfs_aextnum_t ;/* # extents in an attribute fork */
fs/xfs/xfs_attr_item.c new file +569 -0
569 lines not on this page · raw message
fs/xfs/xfs_attr_item.h new file +114 -0
114 lines not on this page · raw message
fs/xfs/xfs_log_recover.c +172 -0
232 lines not on this page · raw message
fs/xfs/xfs_ondisk.h +2 -0
@@ -125,6 +125,8 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_inode_log_format, 56); XFS_CHECK_STRUCT_SIZE(struct xfs_qoff_logformat, 20); XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16); + XFS_CHECK_STRUCT_SIZE(struct xfs_attri_log_format, 40); + XFS_CHECK_STRUCT_SIZE(struct xfs_attrd_log_format, 16); }#endif /* __XFS_ONDISK_H */
fs/xfs/xfs_super.c +1 -0
@@ -2057,6 +2057,7 @@ init_xfs_fs(void)xfs_rmap_update_init_defer_op ();xfs_refcount_update_init_defer_op ();xfs_bmap_update_init_defer_op (); +xfs_attr_init_defer_op ();xfs_dir_startup ();
fs/xfs/xfs_trans.h +12 -0
@@ -26,6 +26,9 @@ struct xfs_cui_log_item;struct xfs_cud_log_item ;struct xfs_bui_log_item ;struct xfs_bud_log_item ; +struct xfs_attrd_log_item ; +struct xfs_attri_log_item ; +struct xfs_da_args ; typedef struct xfs_log_item { struct list_head li_ail; /* AIL pointers */
@@ -223,6 +226,8 @@ void xfs_trans_dirty_buf(struct xfs_trans *, struct xfs_buf *);void xfs_trans_log_inode (xfs_trans_t *,struct xfs_inode *,uint );void xfs_extent_free_init_defer_op (void ); +void xfs_attr_init_defer_op (void ); +struct xfs_efd_log_item *xfs_trans_get_efd (struct xfs_trans *,struct xfs_efi_log_item *,uint );
@@ -230,6 +235,13 @@ int xfs_trans_free_extent(struct xfs_trans *, struct xfs_efd_log_item *, xfs_fsblock_t, xfs_extlen_t, struct xfs_owner_info *, bool); +struct xfs_attrd_log_item * +xfs_trans_get_attrd (struct xfs_trans *tp, +struct xfs_attri_log_item *attrip); +int xfs_trans_attr (struct xfs_da_args *args, +struct xfs_attrd_log_item *attrdp, +uint32_t attr_op_flags); +int xfs_trans_commit (struct xfs_trans *);int xfs_trans_roll (struct xfs_trans **);int xfs_trans_roll_inode (struct xfs_trans **,struct xfs_inode *);
fs/xfs/xfs_trans_attr.c new file +258 -0
258 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v9 8/28 xfs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred
In reply to Allison HendersonThese routines set up set and start a new deferred attribute operation. These functions are meant to be called by other code needing to initiate a deferred attribute operation. We will use these routines later in the parent pointer patches.
--- fs/xfs/libxfs/xfs_attr.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr.h | 7 +++++ 2 files changed, 87 insertions(+)
fs/xfs/libxfs/xfs_attr.c +80 -0
@@ -30,6 +30,7 @@#include "xfs_trans_space.h" #include "xfs_trace.h" #include "xfs_attr_item.h" +#include "xfs_attr.h" /* * xfs_attr.c
@@ -447,6 +448,52 @@ xfs_attr_set(return error; } +/* Sets an attribute for an inode as a deferred operation */ +int +xfs_attr_set_deferred ( +struct xfs_inode *dp, +struct xfs_trans *tp, +const unsigned char *name, +unsigned int namelen, +const unsigned char *value, +unsigned int valuelen, +int flags) +{ + +struct xfs_attr_item *new; +char *name_value; + +/* +* All set operations must have a name +* but not necessarily a value. +* Generic 062 +*/ +if (!namelen) { +ASSERT (0 ); +return -EFSCORRUPTED ; + } + + new =kmem_alloc (XFS_ATTR_ITEM_SIZEOF (namelen, valuelen), +KM_SLEEP |KM_NOFS ); + name_value = ((char *)new) +sizeof (struct xfs_attr_item ); +memset (new,0 ,XFS_ATTR_ITEM_SIZEOF (namelen, valuelen)); + new->xattri_ip = dp; + new->xattri_op_flags =XFS_ATTR_OP_FLAGS_SET ; + new->xattri_name_len = namelen; + new->xattri_value_len = valuelen; + new->xattri_flags = flags; +memcpy (&name_value[0 ], name, namelen); + new->xattri_name = name_value; + new->xattri_value = name_value + namelen; + +if (valuelen >0 ) +memcpy (&name_value[namelen], value, valuelen); + +xfs_defer_add (tp,XFS_DEFER_OPS_TYPE_ATTR , &new->xattri_list); + +return 0 ; +} +/* * Generic handler routine to remove a name from an attribute list. * Transitions attribute list from Btree to shortform as necessary.
@@ -530,6 +577,39 @@ xfs_attr_remove(return error; } +/* Removes an attribute for an inode as a deferred operation */ +int +xfs_attr_remove_deferred ( +struct xfs_inode *dp, +struct xfs_trans *tp, +const unsigned char *name, +unsigned int namelen, +int flags) +{ + +struct xfs_attr_item *new; +char *name_value; + +if (!namelen) { +ASSERT (0 ); +return -EFSCORRUPTED ; + } + + new =kmem_alloc (XFS_ATTR_ITEM_SIZEOF (namelen,0 ),KM_SLEEP |KM_NOFS ); + name_value = ((char *)new) +sizeof (struct xfs_attr_item ); +memset (new,0 ,XFS_ATTR_ITEM_SIZEOF (namelen,0 )); + new->xattri_ip = dp; + new->xattri_op_flags =XFS_ATTR_OP_FLAGS_REMOVE ; + new->xattri_name_len = namelen; + new->xattri_value_len =0 ; + new->xattri_flags = flags; +memcpy (name_value, name, namelen); + +xfs_defer_add (tp,XFS_DEFER_OPS_TYPE_ATTR , &new->xattri_list); + +return 0 ; +} +/*======================================================================== * External routines when attribute list is inside the inode *========================================================================*/
fs/xfs/libxfs/xfs_attr.h +7 -0
@@ -171,5 +171,12 @@ int xfs_attr_list(struct xfs_inode *dp, char *buffer, int bufsize,int xfs_attr_args_init (struct xfs_da_args *args,struct xfs_inode *dp,const unsigned char *name,int flags);int xfs_attr_calc_size (struct xfs_da_args *args,int *local); +int xfs_attr_set_deferred (struct xfs_inode *dp,struct xfs_trans *tp, +const unsigned char *name,unsigned int name_len, +const unsigned char *value,unsigned int valuelen, +int flags); +int xfs_attr_remove_deferred (struct xfs_inode *dp,struct xfs_trans *tp, +const unsigned char *name,unsigned int namelen, +int flags);#endif /* __XFS_ATTR_H__ */
Signature · 1 line
2.7.4
PATCH v9 9/28 xfs: Add xfs_has_attr and subroutines
In reply to Allison HendersonThis 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. We will need this later for delayed attributes since delayed operations cannot return error codes.
--- fs/xfs/libxfs/xfs_attr.c | 78 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 33 ++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.h | 1 + 4 files changed, 113 insertions(+)
fs/xfs/libxfs/xfs_attr.c +78 -0
@@ -53,6 +53,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, bool roll_trans); STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args, bool roll_trans); +STATIC int xfs_leaf_has_attr(xfs_da_args_t *args);/* * Internal routines when attribute list is more than one block.
@@ -60,6 +61,7 @@ STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args, bool roll_trans); STATIC int xfs_attr_node_get(xfs_da_args_t *args); STATIC int xfs_attr_node_addname(xfs_da_args_t *args, bool roll_trans); STATIC int xfs_attr_node_removename(xfs_da_args_t *args, bool roll_trans); +STATIC int xfs_attr_node_hasname(xfs_da_args_t *args); STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
@@ -321,6 +323,29 @@ xfs_attr_set_args( }/* +* Return successful if attr is found, or ENOATTR if not +*/ +int +xfs_has_attr ( +struct xfs_da_args *args) +{ +struct xfs_inode *dp = args->dp; +int error; + +if (!xfs_inode_hasattr (dp)) + error = -ENOATTR ; +else if (dp->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); + error =xfs_shortform_has_attr (args); + }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) + error =xfs_leaf_has_attr (args); +else + error =xfs_attr_node_hasname (args); + +return error; +} + +/* * Remove the attribute specified in @args. */ int
@@ -858,6 +883,29 @@ xfs_attr_leaf_addname( }/* +* Return successful if attr is found, or ENOATTR if not +*/ +STATIC int +xfs_leaf_has_attr ( +struct xfs_da_args *args) +{ +struct xfs_buf *bp; +int error =0 ; + + args->blkno =0 ; + error =xfs_attr3_leaf_read (args->trans, args->dp, + args->blkno,-1 , &bp); +if (error) +return error; + + error =xfs_attr3_leaf_lookup_int (bp, args); + error = (error == -ENOATTR ) ? -ENOATTR :0 ; +xfs_trans_brelse (args->trans, bp); + +return error; +} + +/* * Remove a name from the leaf attribute list structure * * This leaf block cannot have a "remote" value, we only call this routine
@@ -1193,6 +1241,36 @@ xfs_attr_node_addname( }/* +* Return successful if attr is found, or ENOATTR if not +*/ +STATIC int +xfs_attr_node_hasname ( +struct xfs_da_args *args) +{ +struct xfs_da_state *state; +struct xfs_inode *dp; +int retval, error; + +/* +* 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; + } +return error; +} + +/* * Remove a name from a B-tree attribute list. * * This will involve walking down the Btree, and may involve joining
fs/xfs/libxfs/xfs_attr.h +1 -0
@@ -165,6 +165,7 @@ int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,int xfs_attr_set_args (struct xfs_da_args *args,struct xfs_buf **leaf_bp,bool roll_trans);int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name,int flags); +int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args,bool roll_trans);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 +33 -0
@@ -624,6 +624,39 @@ xfs_attr_fork_remove( }/* +* Return successful if attr is found, or ENOATTR if not +*/ +int +xfs_shortform_has_attr ( +struct xfs_da_args *args) +{ +struct xfs_attr_shortform *sf; +struct xfs_attr_sf_entry *sfe; +int base =sizeof (struct xfs_attr_sf_hdr ); +int size =0 ; +int end; +int i; + + 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->namelen) +continue ; +if (memcmp (sfe->nameval, args->name, args->namelen) !=0 ) +continue ; +if (!xfs_attr_namesp_match (args->flags, sfe->flags)) +continue ; +break ; + } +if (i == end) +return -ENOATTR ; +return 0 ; +} + +/* * Remove an attribute from the shortform attribute list structure. */ int
fs/xfs/libxfs/xfs_attr_leaf.h +1 -0
@@ -39,6 +39,7 @@ 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_shortform_has_attr (struct xfs_da_args *args);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
PATCH v9 10/28 xfs: Add attr context to log item
In reply to Allison HendersonThis patch modifies xfs_attr_item to store a xfs_da_args, a xfs_buf pointer and a new state type. We will use these in the next patch when we modify xfs_set_attr_args to roll transactions by returning EAGAIN. Because the subroutines of this function modify the contents of these structures, we need to find a place to store them where they remain instantiated across multiple calls to xfs_set_attr_args.
--- fs/xfs/libxfs/xfs_attr.h | 17 ++++++++++++++++- fs/xfs/scrub/common.c | 2 ++ fs/xfs/xfs_acl.c | 2 ++ fs/xfs/xfs_attr_item.c | 2 +- fs/xfs/xfs_ioctl.c | 2 ++ fs/xfs/xfs_ioctl32.c | 2 ++ fs/xfs/xfs_iops.c | 1 + fs/xfs/xfs_xattr.c | 1 + 8 files changed, 27 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_attr.h +16 -1
@@ -77,6 +77,12 @@ typedef struct attrlist_ent { /* data from attr_list() */char a_name[1 ];/* attr name (NULL terminated) */ } attrlist_ent_t; +/* Attr state machine types */ +typedef enum { +XFS_ATTR_STATE1 =1 , +XFS_ATTR_STATE2 =2 , +}xfs_attr_state_t ; +/* * List of attrs to commit later. */
@@ -88,7 +94,16 @@ struct xfs_attr_item {void * xattri_name;/* attr name */ uint32_t xattri_name_len;/* length of name */ uint32_t xattri_flags;/* attr flags */ -struct list_head xattri_list; + +/* +* Delayed attr parameters that need to remain instantiated +* across transaction rolls during the defer finish +*/ +struct xfs_buf *xattri_leaf_bp;/* Leaf buf to release */ +xfs_attr_state_t xattri_state;/* state machine marker */ +struct xfs_da_args xattri_args;/* args context */ + +struct list_head xattri_list;/* * A byte array follows the header containing the file name and
fs/xfs/scrub/common.c +2 -0
@@ -30,6 +30,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/xfs_scrub.h"
fs/xfs/xfs_acl.c +2 -0
@@ -10,6 +10,8 @@#include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_acl.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_trace.h" #include <linux/slab.h>
fs/xfs/xfs_attr_item.c +1 -1
@@ -30,10 +30,10 @@#include "xfs_rmap.h" #include "xfs_inode.h" #include "xfs_icache.h" -#include "xfs_attr.h" #include "xfs_shared.h" #include "xfs_da_format.h" #include "xfs_da_btree.h" +#include "xfs_attr.h" static inline struct xfs_attri_log_item *ATTRI_ITEM (struct xfs_log_item *lip) {
fs/xfs/xfs_ioctl.c +2 -0
@@ -16,6 +16,8 @@#include "xfs_rtalloc.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
@@ -21,6 +21,8 @@#include "xfs_fsops.h" #include "xfs_alloc.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 +1 -0
@@ -17,6 +17,7 @@#include "xfs_acl.h" #include "xfs_quota.h" #include "xfs_error.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
@@ -11,6 +11,7 @@#include "xfs_mount.h" #include "xfs_da_format.h" #include "xfs_inode.h" +#include "xfs_da_btree.h" #include "xfs_attr.h" #include "xfs_attr_leaf.h" #include "xfs_acl.h"
Signature · 1 line
2.7.4
PATCH v9 11/28 xfs: Roll delayed attr operations by returning EAGAIN
In reply to Allison HendersonThis patch modifies xfs_attr_set_args to return -EAGAIN when a transaction needs to be rolled. All functions currently calling xfs_attr_set_args are modified to use the deferred attr operation, or handle the -EAGAIN return code
--- fs/xfs/libxfs/xfs_attr.c | 43 ++++++++++++++++++++++++++++--------- fs/xfs/libxfs/xfs_attr.h | 2 +- fs/xfs/xfs_attr_item.c | 41 ++++++++++++++++++++++++++++++------ fs/xfs/xfs_trans.h | 2 ++ fs/xfs/xfs_trans_attr.c | 55 ++++++++++++++++++++++++++++-------------------- 5 files changed, 103 insertions(+), 40 deletions(-)
fs/xfs/libxfs/xfs_attr.c +33 -10
@@ -238,12 +238,20 @@ intxfs_attr_set_args ( struct xfs_da_args *args, struct xfs_buf **leaf_bp, + xfs_attr_state_t *state, bool roll_trans) { struct xfs_inode *dp = args->dp;int error =0 ;int sf_size; +switch (*state) { +case (XFS_ATTR_STATE1 ): + goto state1; +case (XFS_ATTR_STATE2 ): + goto state2; + } +/* * New inodes setting the parent pointer attr will * not have an attribute fork yet. So set the attribute
@@ -264,7 +272,6 @@ xfs_attr_set_args(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 )) { -/* * Build initial attribute list (if required). */
@@ -278,6 +285,9 @@ xfs_attr_set_args(if (error != -ENOSPC ) goto out; + *state =XFS_ATTR_STATE1 ; +return -EAGAIN ; +state1:/* * It won't fit in the shortform, transform to a leaf block. * GROT: another possible req'mt for a double-split btree op.
@@ -286,14 +296,14 @@ xfs_attr_set_args(if (error) goto out; -if (roll_trans) { -/* -* 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); +/* +* 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); +if (roll_trans) { error =xfs_defer_finish (&args->trans);if (error) goto out;
@@ -309,6 +319,12 @@ xfs_attr_set_args(xfs_trans_bjoin (args->trans, *leaf_bp); *leaf_bp =NULL ; } + + *state =XFS_ATTR_STATE2 ; +return -EAGAIN ; +state2: +if (*leaf_bp !=NULL ) +xfs_trans_brelse (args->trans, *leaf_bp); }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK ))
@@ -441,7 +457,9 @@ xfs_attr_set( }xfs_trans_ijoin (args.trans, dp,0 ); - error =xfs_attr_set_args (&args, &leaf_bp, true); + + error =xfs_attr_set_deferred (dp, args.trans, name,strlen (name), + value, valuelen, flags);if (error) goto out;
@@ -571,8 +589,13 @@ xfs_attr_remove(*/ xfs_trans_ijoin (args.trans, dp,0 ); - error =xfs_attr_remove_args (&args, true); + error =xfs_has_attr (&args); +if (error) + goto out; + + error =xfs_attr_remove_deferred (dp, args.trans, + name,strlen (name), flags);if (error) goto out;
fs/xfs/libxfs/xfs_attr.h +1 -1
@@ -178,7 +178,7 @@ int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,int xfs_attr_set (struct xfs_inode *dp,const unsigned char *name,unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args,struct xfs_buf **leaf_bp, -bool roll_trans); +xfs_attr_state_t *state,bool roll_trans);int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name,int flags);int xfs_has_attr (struct xfs_da_args *args);int xfs_attr_remove_args (struct xfs_da_args *args,bool roll_trans);
fs/xfs/xfs_attr_item.c +35 -6
57 lines not on this page · raw message
fs/xfs/xfs_trans.h +2 -0
@@ -240,6 +240,8 @@ xfs_trans_get_attrd(struct xfs_trans *tp, struct xfs_attri_log_item *attrip);int xfs_trans_attr (struct xfs_da_args *args,struct xfs_attrd_log_item *attrdp, +struct xfs_buf **leaf_bp, +void *state,uint32_t attr_op_flags);int xfs_trans_commit (struct xfs_trans *);
fs/xfs/xfs_trans_attr.c +32 -23
87 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v9 12/28 xfs: Remove roll_trans boolean
In reply to Allison HendersonAll calls to functions using this parameter are now passing a false value. We can now remove the boolean and all affected code
--- fs/xfs/libxfs/xfs_attr.c | 168 ++++++---------------------------------- fs/xfs/libxfs/xfs_attr.h | 4 +- fs/xfs/libxfs/xfs_attr_leaf.c | 25 +----- fs/xfs/libxfs/xfs_attr_leaf.h | 6 +- fs/xfs/libxfs/xfs_attr_remote.c | 34 +------- fs/xfs/libxfs/xfs_attr_remote.h | 4 +- fs/xfs/xfs_trans_attr.c | 4 +- 7 files changed, 39 insertions(+), 206 deletions(-)
fs/xfs/libxfs/xfs_attr.c +25 -143
@@ -51,16 +51,16 @@ STATIC int xfs_attr_shortform_addname(xfs_da_args_t *args);* Internal routines when attribute list is one block. */ STATIC int xfs_attr_leaf_get(xfs_da_args_t *args); -STATIC int xfs_attr_leaf_addname(xfs_da_args_t *args, bool roll_trans); -STATIC int xfs_attr_leaf_removename(xfs_da_args_t *args, bool roll_trans); +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_leaf_has_attr(xfs_da_args_t *args);/* * Internal routines when attribute list is more than one block. */ STATIC int xfs_attr_node_get(xfs_da_args_t *args); -STATIC int xfs_attr_node_addname(xfs_da_args_t *args, bool roll_trans); -STATIC int xfs_attr_node_removename(xfs_da_args_t *args, bool roll_trans); +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); STATIC int xfs_attr_fillstate(xfs_da_state_t *state); STATIC int xfs_attr_refillstate(xfs_da_state_t *state);
@@ -238,8 +238,7 @@ intxfs_attr_set_args ( struct xfs_da_args *args, struct xfs_buf **leaf_bp, - xfs_attr_state_t *state, - bool roll_trans) + xfs_attr_state_t *state) { struct xfs_inode *dp = args->dp;int error =0 ;
@@ -303,23 +302,6 @@ xfs_attr_set_args(*/ xfs_trans_bhold (args->trans, *leaf_bp); -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) - goto out; - -/* -* Commit the leaf transformation. We'll need another -* (linked) transaction to add the new attribute to the -* leaf. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; -xfs_trans_bjoin (args->trans, *leaf_bp); - *leaf_bp =NULL ; - } - *state =XFS_ATTR_STATE2 ;return -EAGAIN ; state2:
@@ -328,9 +310,9 @@ xfs_attr_set_args( }if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) - error =xfs_attr_leaf_addname (args, roll_trans); + error =xfs_attr_leaf_addname (args);else - error =xfs_attr_node_addname (args, roll_trans); + error =xfs_attr_node_addname (args);if (error) goto out;
@@ -366,8 +348,7 @@ xfs_has_attr(*/ int xfs_attr_remove_args ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_inode *dp = args->dp;int error;
@@ -378,9 +359,9 @@ xfs_attr_remove_args(ASSERT (dp->i_afp->if_flags &XFS_IFINLINE ); error =xfs_attr_shortform_remove (args); }else if (xfs_bmap_one_block (dp,XFS_ATTR_FORK )) { - error =xfs_attr_leaf_removename (args, roll_trans); + error =xfs_attr_leaf_removename (args); }else { - error =xfs_attr_node_removename (args, roll_trans); + error =xfs_attr_node_removename (args); }return error;
@@ -718,8 +699,7 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)*/ STATIC intxfs_attr_leaf_addname ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_inode *dp;struct xfs_buf *bp;
@@ -785,39 +765,14 @@ xfs_attr_leaf_addname(if (error) goto out_defer_cancel; -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -/* -* Commit the current trans (including the inode) and -* start a new one. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - } -/* * Fob the whole rest of the problem off on the Btree code. */ - error =xfs_attr_node_addname (args, roll_trans); + error =xfs_attr_node_addname (args);return error; } - -if (roll_trans) { -/* -* Commit the transaction that added the attr name so that -* later routines can manage their own transactions. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - } -/* * If there was an out-of-line value, allocate the blocks we * identified for its storage and copy the value. This is done
@@ -825,7 +780,7 @@ xfs_attr_leaf_addname(* maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args, roll_trans); + error =xfs_attr_rmtval_set (args);if (error)return error; }
@@ -841,7 +796,7 @@ xfs_attr_leaf_addname(* In a separate transaction, set the incomplete flag on the * "old" attr and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args, roll_trans); + error =xfs_attr3_leaf_flipflags (args);if (error)return error;
@@ -855,7 +810,7 @@ xfs_attr_leaf_addname( args->rmtblkcnt = args->rmtblkcnt2; args->rmtvaluelen = args->rmtvaluelen2;if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args, roll_trans); + error =xfs_attr_rmtval_remove (args);if (error)return error; }
@@ -879,25 +834,13 @@ xfs_attr_leaf_addname(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out_defer_cancel; - -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) -return error; - } } -/* -* Commit the remove and start the next trans in series. -*/ -if (roll_trans) - 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, roll_trans); + error =xfs_attr3_leaf_clearflag (args); }return error; out_defer_cancel:
@@ -936,8 +879,7 @@ xfs_leaf_has_attr(*/ STATIC intxfs_attr_leaf_removename ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_inode *dp;struct xfs_buf *bp;
@@ -970,11 +912,6 @@ xfs_attr_leaf_removename(/* bp is gone due to xfs_da_shrink_inode */ if (error) goto out_defer_cancel; -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) -return error; - } }return 0 ; out_defer_cancel:
@@ -1030,8 +967,7 @@ xfs_attr_leaf_get(xfs_da_args_t *args)*/ STATIC intxfs_attr_node_addname ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_da_state *state;struct xfs_da_state_blk *blk;
@@ -1101,20 +1037,6 @@ xfs_attr_node_addname(if (error) goto out_defer_cancel; -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) - goto out; - -/* -* Commit the node conversion and start the next -* trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } - goto restart; }
@@ -1127,12 +1049,6 @@ xfs_attr_node_addname( error =xfs_da3_split (state);if (error) goto out_defer_cancel; - -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) - goto out; - } }else {/* * Addition succeeded, update Btree hashvals.
@@ -1148,23 +1064,13 @@ xfs_attr_node_addname( state =NULL ;/* -* Commit the leaf addition or btree split and start the next -* trans in the chain. -*/ -if (roll_trans) { - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) - goto out; - } - -/* * If there was an out-of-line value, allocate the blocks we * identified for its storage and copy the value. This is done * after we create the attribute so that we don't overflow the * maximum size of a transaction and/or hit a deadlock. */ if (args->rmtblkno >0 ) { - error =xfs_attr_rmtval_set (args, roll_trans); + error =xfs_attr_rmtval_set (args);if (error)return error; }
@@ -1180,7 +1086,7 @@ xfs_attr_node_addname(* In a separate transaction, set the incomplete flag on the * "old" attr and clear the incomplete flag on the "new" attr. */ - error =xfs_attr3_leaf_flipflags (args, roll_trans); + error =xfs_attr3_leaf_flipflags (args);if (error) goto out;
@@ -1194,7 +1100,7 @@ xfs_attr_node_addname( args->rmtblkcnt = args->rmtblkcnt2; args->rmtvaluelen = args->rmtvaluelen2;if (args->rmtblkno) { - error =xfs_attr_rmtval_remove (args, roll_trans); + error =xfs_attr_rmtval_remove (args);if (error)return error; }
@@ -1228,11 +1134,6 @@ xfs_attr_node_addname( error =xfs_da3_join (state);if (error) goto out_defer_cancel; -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) - goto out; - } }/*
@@ -1246,7 +1147,7 @@ xfs_attr_node_addname(/* * Added a "remote" value, just clear the incomplete flag. */ - error =xfs_attr3_leaf_clearflag (args, roll_trans); + error =xfs_attr3_leaf_clearflag (args);if (error) goto out; }
@@ -1302,8 +1203,7 @@ xfs_attr_node_hasname(*/ STATIC intxfs_attr_node_removename ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_da_state *state;struct xfs_da_state_blk *blk;
@@ -1353,10 +1253,10 @@ xfs_attr_node_removename(* Mark the attribute as INCOMPLETE, then bunmapi() the * remote value. */ - error =xfs_attr3_leaf_setflag (args, roll_trans); + error =xfs_attr3_leaf_setflag (args);if (error) goto out; - error =xfs_attr_rmtval_remove (args, roll_trans); + error =xfs_attr_rmtval_remove (args);if (error) goto out;
@@ -1384,19 +1284,6 @@ xfs_attr_node_removename( error =xfs_da3_join (state);if (error) goto out_defer_cancel; - -if (roll_trans) { - 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; - } }/*
@@ -1420,11 +1307,6 @@ xfs_attr_node_removename(if (error) goto out_defer_cancel; -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) - goto out; - } }else xfs_trans_brelse (args->trans, bp); }
fs/xfs/libxfs/xfs_attr.h +2 -2
@@ -178,10 +178,10 @@ int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,int xfs_attr_set (struct xfs_inode *dp,const unsigned char *name,unsigned char *value,int valuelen,int flags);int xfs_attr_set_args (struct xfs_da_args *args,struct xfs_buf **leaf_bp, -xfs_attr_state_t *state,bool roll_trans); +xfs_attr_state_t *state);int xfs_attr_remove (struct xfs_inode *dp,const unsigned char *name,int flags);int xfs_has_attr (struct xfs_da_args *args); -int xfs_attr_remove_args (struct xfs_da_args *args,bool roll_trans); +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); int xfs_attr_args_init(struct xfs_da_args *args, struct xfs_inode *dp,
fs/xfs/libxfs/xfs_attr_leaf.c +3 -22
@@ -2672,8 +2672,7 @@ xfs_attr_leaf_newentsize(*/ int xfs_attr3_leaf_clearflag ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_attr_leafblock *leaf;struct xfs_attr_leaf_entry *entry;
@@ -2731,11 +2730,6 @@ 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. -*/ -if (roll_trans) - error =xfs_trans_roll_inode (&args->trans, args->dp);return error; }
@@ -2744,8 +2738,7 @@ xfs_attr3_leaf_clearflag(*/ int xfs_attr3_leaf_setflag ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_attr_leafblock *leaf;struct xfs_attr_leaf_entry *entry;
@@ -2785,11 +2778,6 @@ 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. -*/ -if (roll_trans) - error =xfs_trans_roll_inode (&args->trans, args->dp);return error; }
@@ -2802,8 +2790,7 @@ xfs_attr3_leaf_setflag(*/ int xfs_attr3_leaf_flipflags ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_attr_leafblock *leaf1;struct xfs_attr_leafblock *leaf2;
@@ -2906,11 +2893,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. -*/ -if (roll_trans) - error =xfs_trans_roll_inode (&args->trans, args->dp); -return error; }
fs/xfs/libxfs/xfs_attr_leaf.h +3 -3
@@ -51,9 +51,9 @@ void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);int xfs_attr3_leaf_to_node (struct xfs_da_args *args);int xfs_attr3_leaf_to_shortform (struct xfs_buf *bp,struct xfs_da_args *args,int forkoff); -int xfs_attr3_leaf_clearflag (struct xfs_da_args *args,bool roll_trans); -int xfs_attr3_leaf_setflag (struct xfs_da_args *args,bool roll_trans); -int xfs_attr3_leaf_flipflags (struct xfs_da_args *args,bool roll_trans); +int xfs_attr3_leaf_clearflag (struct xfs_da_args *args); +int xfs_attr3_leaf_setflag (struct xfs_da_args *args); +int xfs_attr3_leaf_flipflags (struct xfs_da_args *args);/* * Routines used for growing the Btree.
fs/xfs/libxfs/xfs_attr_remote.c +2 -32
@@ -433,8 +433,7 @@ xfs_attr_rmtval_get(*/ int xfs_attr_rmtval_set ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_inode *dp = args->dp;struct xfs_mount *mp = dp->i_mount;
@@ -488,26 +487,11 @@ xfs_attr_rmtval_set(if (error) goto out_defer_cancel; -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) -return error; - } -ASSERT (nmap ==1 );ASSERT ((map.br_startblock !=DELAYSTARTBLOCK ) && (map.br_startblock !=HOLESTARTBLOCK )); lblkno += map.br_blockcount; blkcnt -= map.br_blockcount; - -if (roll_trans) { -/* -* Start the next trans in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, dp); -if (error) -return error; - } }/*
@@ -570,8 +554,7 @@ xfs_attr_rmtval_set(*/ int xfs_attr_rmtval_remove ( -struct xfs_da_args *args, -bool roll_trans) +struct xfs_da_args *args) {struct xfs_mount *mp = args->dp->i_mount;xfs_dablk_t lblkno;
@@ -633,19 +616,6 @@ xfs_attr_rmtval_remove( XFS_BMAPI_ATTRFORK, 1, &done);if (error) goto out_defer_cancel; - -if (roll_trans) { - error =xfs_defer_finish (&args->trans); -if (error) -return error; - -/* -* Close out trans and start the next one in the chain. -*/ - error =xfs_trans_roll_inode (&args->trans, args->dp); -if (error) -return error; - } }return 0 ; out_defer_cancel:
fs/xfs/libxfs/xfs_attr_remote.h +2 -2
@@ -9,7 +9,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,bool roll_trans); -int xfs_attr_rmtval_remove (struct xfs_da_args *args,bool roll_trans); +int xfs_attr_rmtval_set (struct xfs_da_args *args); +int xfs_attr_rmtval_remove (struct xfs_da_args *args);#endif /* __XFS_ATTR_REMOTE_H__ */
fs/xfs/xfs_trans_attr.c +2 -2
@@ -81,11 +81,11 @@ xfs_trans_attr(case XFS_ATTR_OP_FLAGS_SET : args->op_flags |=XFS_DA_OP_ADDNAME ; error =xfs_attr_set_args (args, leaf_bp, - (xfs_attr_state_t *)state, false); + (xfs_attr_state_t *)state);break ;case XFS_ATTR_OP_FLAGS_REMOVE :ASSERT (XFS_IFORK_Q ((args->dp))); - error =xfs_attr_remove_args (args, false); + error =xfs_attr_remove_args (args);break ;default : error = -EFSCORRUPTED ;
Signature · 1 line
2.7.4
PATCH v9 13/28 xfs: Remove all strlen calls in all xfs_attr_* functions for attr names.
In reply to Allison HendersonParent pointer attributes use a binary name, so strlen will not work. Calling functions will need to pass in the name length
--- fs/xfs/libxfs/xfs_attr.c | 16 ++++++++++------ fs/xfs/libxfs/xfs_attr.h | 10 ++++++---- fs/xfs/xfs_acl.c | 12 +++++++----- fs/xfs/xfs_attr_item.c | 2 +- fs/xfs/xfs_ioctl.c | 13 ++++++++++--- fs/xfs/xfs_iops.c | 6 ++++-- fs/xfs/xfs_trans_attr.c | 2 +- fs/xfs/xfs_xattr.c | 10 ++++++---- 8 files changed, 45 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_attr.c +10 -6
@@ -71,6 +71,7 @@ xfs_attr_args_init(struct xfs_da_args *args, struct xfs_inode *dp, const unsigned char *name, + size_t namelen, int flags) {
@@ -83,7 +84,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 */
@@ -129,6 +130,7 @@ intxfs_attr_get ( struct xfs_inode *ip, const unsigned char *name, + size_t namelen, unsigned char *value, int *valuelenp, int flags)
@@ -142,7 +144,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;
@@ -371,6 +373,7 @@ intxfs_attr_set ( struct xfs_inode *dp, const unsigned char *name, + size_t namelen, unsigned char *value, int valuelen, int flags)
@@ -387,7 +390,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;
@@ -439,7 +442,7 @@ xfs_attr_set(xfs_trans_ijoin (args.trans, dp,0 ); - error =xfs_attr_set_deferred (dp, args.trans, name,strlen (name), + error =xfs_attr_set_deferred (dp, args.trans, name, namelen, value, valuelen, flags);if (error) goto out;
@@ -526,6 +529,7 @@ intxfs_attr_remove ( struct xfs_inode *dp, const unsigned char *name, + size_t namelen, int flags) { struct xfs_mount *mp = dp->i_mount;
@@ -537,7 +541,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;
@@ -576,7 +580,7 @@ xfs_attr_remove( error =xfs_attr_remove_deferred (dp, args.trans, - name,strlen (name), flags); + name, namelen, flags);if (error) goto out;
fs/xfs/libxfs/xfs_attr.h +6 -4
@@ -174,18 +174,20 @@ 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,struct xfs_buf **leaf_bp,xfs_attr_state_t *state); -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_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);int xfs_attr_args_init (struct xfs_da_args *args,struct xfs_inode *dp, -const unsigned char *name,int flags); +const unsigned char *name,size_t namelen,int flags);int xfs_attr_calc_size (struct xfs_da_args *args,int *local); int xfs_attr_set_deferred(struct xfs_inode *dp, struct xfs_trans *tp, const unsigned char *name, unsigned int name_len,
fs/xfs/xfs_acl.c +7 -5
@@ -143,8 +143,8 @@ xfs_get_acl(struct inode *inode, int type)if (!xfs_acl)return ERR_PTR (-ENOMEM ); - error =xfs_attr_get (ip, ea_name, (unsigned char *)xfs_acl, - &len,ATTR_ROOT ); + error =xfs_attr_get (ip, ea_name,strlen (ea_name), + (unsigned char *)xfs_acl, &len,ATTR_ROOT );if (error) {/* * If the attribute doesn't exist make sure we have a negative
@@ -194,15 +194,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_attr_item.c +1 -1
@@ -530,7 +530,7 @@ xfs_attri_recover(return error; error =xfs_attr_args_init (&args, ip, attrip->name, - attrp->alfi_attr_flags); + attrp->alfi_name_len, attrp->alfi_attr_flags);if (error)return error;
fs/xfs/xfs_ioctl.c +10 -3
@@ -439,6 +439,7 @@ xfs_attrmulti_attr_get( {unsigned char *kbuf;int error = -EFAULT ; +size_t namelen;if (*len >XFS_XATTR_SIZE_MAX )return -EINVAL ;
@@ -446,7 +447,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;
@@ -468,6 +471,7 @@ xfs_attrmulti_attr_set( {unsigned char *kbuf;int error; +size_t namelen;if (IS_IMMUTABLE (inode) ||IS_APPEND (inode))return -EPERM ;
@@ -478,7 +482,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);
@@ -492,10 +497,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
@@ -60,8 +60,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_trans_attr.c +1 -1
@@ -201,7 +201,7 @@ xfs_attr_finish_item(/* Only need to initialize args context once */ name_value = ((char *)attr) +sizeof (struct xfs_attr_item ); error =xfs_attr_args_init (args, attr->xattri_ip, name_value, - attr->xattri_flags); + attr->xattri_name_len, attr->xattri_flags);if (error) goto out;
fs/xfs/xfs_xattr.c +6 -4
@@ -27,6 +27,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) {
@@ -34,7 +35,7 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, value =NULL ; } - error =xfs_attr_get (ip, (unsigned char *)name, value, &asize, xflags); + error =xfs_attr_get (ip, name, namelen, value, &asize, xflags);if (error)return error;return asize;
@@ -70,6 +71,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 )
@@ -78,9 +80,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 v9 14/28 xfs: get directory offset when adding directory name
In reply to Allison HendersonFrom: Mark Tinguely <[email protected]>
Return the directory offset information when adding an entry to the directory.
This offset will be used as the parent pointer offset in xfs_create, xfs_symlink, xfs_link and xfs_rename.
[dchinner: forward ported and cleaned up] [dchinner: no s-o-b from Mark]
[bfoster: rebased, use args->geo in dir code] [achender: rebased, chaged __uint32_t to xfs_dir2_dataptr_t]
--- fs/xfs/libxfs/xfs_da_btree.h | 1 + fs/xfs/libxfs/xfs_dir2.c | 9 +++++++-- fs/xfs/libxfs/xfs_dir2.h | 2 +- fs/xfs/libxfs/xfs_dir2_block.c | 1 + fs/xfs/libxfs/xfs_dir2_leaf.c | 2 ++ fs/xfs/libxfs/xfs_dir2_node.c | 2 ++ fs/xfs/libxfs/xfs_dir2_sf.c | 2 ++ fs/xfs/xfs_inode.c | 7 ++++--- fs/xfs/xfs_symlink.c | 3 ++- 9 files changed, 22 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_da_btree.h +1 -0
@@ -71,6 +71,7 @@ typedef struct xfs_da_args {int rmtvaluelen2;/* remote attr value length in bytes */ int op_flags;/* operation flags */ enum xfs_dacmp cmpresult;/* name compare result for lookups */ +xfs_dir2_dataptr_t offset;/* OUT: offset in directory */ } xfs_da_args_t;/*
fs/xfs/libxfs/xfs_dir2.c +7 -2
@@ -243,7 +243,8 @@ xfs_dir_createname(struct xfs_inode *dp, struct xfs_name *name, xfs_ino_t inum, /* new entry inode number */ - xfs_extlen_t total) /* bmap's total block count */ + xfs_extlen_t total, /* bmap's total block count */ + xfs_dir2_dataptr_t *offset) /* OUT entry's dir offset */ { struct xfs_da_args *args;int rval;
@@ -298,6 +299,10 @@ xfs_dir_createname( rval =xfs_dir2_node_addname (args); out_free: +/* return the location that this entry was place in the parent inode */ +if (offset) + *offset = args->offset; +kmem_free (args);return rval; }
@@ -536,7 +541,7 @@ xfs_dir_canenter(xfs_inode_t *dp, struct xfs_name *name) /* name of entry to add */ { - return xfs_dir_createname(tp, dp, name, 0, 0); + return xfs_dir_createname(tp, dp, name, 0, 0, NULL); }/*
fs/xfs/libxfs/xfs_dir2.h +1 -1
@@ -117,7 +117,7 @@ extern int xfs_dir_init(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_inode *pdp);extern int xfs_dir_createname (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name,xfs_ino_t inum, -xfs_extlen_t tot); +xfs_extlen_t tot,xfs_dir2_dataptr_t *offset);extern int xfs_dir_lookup (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name,xfs_ino_t *inum,struct xfs_name *ci_name);
fs/xfs/libxfs/xfs_dir2_block.c +1 -0
@@ -547,6 +547,7 @@ xfs_dir2_block_addname( dp->d_ops->data_put_ftype (dep, args->filetype); tagp = dp->d_ops->data_entry_tag_p (dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr); + args->offset =xfs_dir2_byte_to_dataptr ((char *)dep - (char *)hdr);/* * Clean up the bestfree array and log the header, tail, and entry. */
fs/xfs/libxfs/xfs_dir2_leaf.c +2 -0
@@ -882,6 +882,8 @@ xfs_dir2_leaf_addname( dp->d_ops->data_put_ftype (dep, args->filetype); tagp = dp->d_ops->data_entry_tag_p (dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr); + args->offset =xfs_dir2_db_off_to_dataptr (args->geo, use_block, + (char *)dep - (char *)hdr);/* * Need to scan fix up the bestfree table. */
fs/xfs/libxfs/xfs_dir2_node.c +2 -0
@@ -2027,6 +2027,8 @@ xfs_dir2_node_addname_int( dp->d_ops->data_put_ftype (dep, args->filetype); tagp = dp->d_ops->data_entry_tag_p (dep); *tagp =cpu_to_be16 ((char *)dep - (char *)hdr); + args->offset =xfs_dir2_db_off_to_dataptr (args->geo, dbno, + (char *)dep - (char *)hdr);xfs_dir2_data_log_entry (args, dbp, dep);/* * Rescan the block for bestfree if needed.
fs/xfs/libxfs/xfs_dir2_sf.c +2 -0
@@ -393,6 +393,7 @@ xfs_dir2_sf_addname_easy(memcpy (sfep->name, args->name, sfep->namelen); dp->d_ops->sf_put_ino (sfp, sfep, args->inumber); dp->d_ops->sf_put_ftype (sfep, args->filetype); + args->offset =xfs_dir2_byte_to_dataptr (offset);/* * Update the header and inode.
@@ -484,6 +485,7 @@ xfs_dir2_sf_addname_hard(memcpy (sfep->name, args->name, sfep->namelen); dp->d_ops->sf_put_ino (sfp, sfep, args->inumber); dp->d_ops->sf_put_ftype (sfep, args->filetype); + args->offset =xfs_dir2_byte_to_dataptr (offset); sfp->count++;if (args->inumber >XFS_DIR2_MAX_SHORT_INUM && !objchange) sfp->i8count++;
fs/xfs/xfs_inode.c +4 -3
@@ -1224,7 +1224,8 @@ xfs_create( error =xfs_dir_createname (tp, dp, name, ip->i_ino, resblks ? - resblks -XFS_IALLOC_SPACE_RES (mp) :0 ); + resblks -XFS_IALLOC_SPACE_RES (mp) :0 , +NULL );if (error) {ASSERT (error != -ENOSPC ); goto out_trans_cancel;
@@ -1452,7 +1453,7 @@ xfs_link( } error =xfs_dir_createname (tp, tdp, target_name, sip->i_ino, - resblks); + resblks,NULL );if (error) goto error_return;xfs_trans_ichgtime (tp, tdp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG );
@@ -2983,7 +2984,7 @@ xfs_rename(* to account for the ".." reference from the new entry. */ error =xfs_dir_createname (tp, target_dp, target_name, - src_ip->i_ino, spaceres); + src_ip->i_ino, spaceres,NULL );if (error) goto out_trans_cancel;
fs/xfs/xfs_symlink.c +2 -1
@@ -328,7 +328,8 @@ xfs_symlink(/* * Create the directory entry for the symlink. */ - error =xfs_dir_createname (tp, dp, link_name, ip->i_ino, resblks); + error =xfs_dir_createname (tp, dp, link_name, + ip->i_ino, resblks,NULL );if (error) goto out_trans_cancel;xfs_trans_ichgtime (tp, dp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG );
Signature · 1 line
2.7.4
PATCH v9 15/28 xfs: get directory offset when removing directory name
In reply to Allison HendersonFrom: Mark Tinguely <[email protected]>
Return the directory offset information when removing an entry to the directory.
This offset will be used as the parent pointer offset in xfs_remove.
[dchinner: forward ported and cleaned up]
[achender: rebased, changed __unint32_t to xfs_dir2_dataptr_t,
Changed typedefs to raw struct types]
--- fs/xfs/libxfs/xfs_dir2.c | 6 +++++- fs/xfs/libxfs/xfs_dir2.h | 3 ++- fs/xfs/libxfs/xfs_dir2_block.c | 4 ++-- fs/xfs/libxfs/xfs_dir2_leaf.c | 5 +++-- fs/xfs/libxfs/xfs_dir2_node.c | 5 +++-- fs/xfs/libxfs/xfs_dir2_sf.c | 2 ++ fs/xfs/xfs_inode.c | 4 ++-- 7 files changed, 19 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +5 -1
@@ -422,7 +422,8 @@ xfs_dir_removename(struct xfs_inode *dp, struct xfs_name *name, xfs_ino_t ino, - xfs_extlen_t total) /* bmap's total block count */ + xfs_extlen_t total, /* bmap's total block count */ + xfs_dir2_dataptr_t *offset) /* OUT: offset in directory */ { struct xfs_da_args *args;int rval;
@@ -467,6 +468,9 @@ xfs_dir_removename(else rval =xfs_dir2_node_removename (args); out_free: +if (offset) + *offset = args->offset; +kmem_free (args);return rval; }
fs/xfs/libxfs/xfs_dir2.h +2 -1
@@ -123,7 +123,8 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *ci_name);extern int xfs_dir_removename (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name,xfs_ino_t ino, -xfs_extlen_t tot); +xfs_extlen_t tot, +xfs_dir2_dataptr_t *offset);extern int xfs_dir_replace (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name,xfs_ino_t inum,xfs_extlen_t tot);
fs/xfs/libxfs/xfs_dir2_block.c +2 -2
@@ -786,9 +786,9 @@ xfs_dir2_block_removename(/* * Point to the data entry using the leaf entry. */ + args->offset =be32_to_cpu (blp[ent].address); dep = (xfs_dir2_data_entry_t *)((char *)hdr + -xfs_dir2_dataptr_to_off (args->geo, -be32_to_cpu (blp[ent].address))); +xfs_dir2_dataptr_to_off (args->geo, args->offset));/* * Mark the data entry's space free. */
fs/xfs/libxfs/xfs_dir2_leaf.c +3 -2
@@ -1402,9 +1402,10 @@ xfs_dir2_leaf_removename(* Point to the leaf entry, use that to point to the data entry. */ lep = &ents[index]; - db =xfs_dir2_dataptr_to_db (args->geo,be32_to_cpu (lep->address)); + args->offset =be32_to_cpu (lep->address); + db =xfs_dir2_dataptr_to_db (args->geo, args->offset); dep = (xfs_dir2_data_entry_t *)((char *)hdr + -xfs_dir2_dataptr_to_off (args->geo,be32_to_cpu (lep->address))); +xfs_dir2_dataptr_to_off (args->geo, args->offset)); needscan = needlog =0 ; oldbest =be16_to_cpu (bf[0 ].length); ltp =xfs_dir2_leaf_tail_p (args->geo, leaf);
fs/xfs/libxfs/xfs_dir2_node.c +3 -2
@@ -1238,9 +1238,10 @@ xfs_dir2_leafn_remove(/* * Extract the data block and offset from the entry. */ - db =xfs_dir2_dataptr_to_db (args->geo,be32_to_cpu (lep->address)); + args->offset =be32_to_cpu (lep->address); + db =xfs_dir2_dataptr_to_db (args->geo, args->offset);ASSERT (dblk->blkno == db); - off =xfs_dir2_dataptr_to_off (args->geo,be32_to_cpu (lep->address)); + off =xfs_dir2_dataptr_to_off (args->geo, args->offset);ASSERT (dblk->index == off);/*
fs/xfs/libxfs/xfs_dir2_sf.c +2 -0
@@ -905,6 +905,8 @@ xfs_dir2_sf_removename( XFS_CMP_EXACT) {ASSERT (dp->d_ops->sf_get_ino (sfp, sfep) == args->inumber); + args->offset =xfs_dir2_byte_to_dataptr ( +xfs_dir2_sf_get_offset (sfep));break ; } }
fs/xfs/xfs_inode.c +2 -2
@@ -2621,7 +2621,7 @@ xfs_remove(if (error) goto out_trans_cancel; - error =xfs_dir_removename (tp, dp, name, ip->i_ino, resblks); + error =xfs_dir_removename (tp, dp, name, ip->i_ino, resblks,NULL );if (error) {ASSERT (error != -ENOENT ); goto out_trans_cancel;
@@ -3099,7 +3099,7 @@ xfs_rename( spaceres); }else error =xfs_dir_removename (tp, src_dp, src_name, src_ip->i_ino, - spaceres); + spaceres,NULL );if (error) goto out_trans_cancel;
Signature · 1 line
2.7.4
PATCH v9 16/28 xfs: get directory offset when replacing a directory name
In reply to Allison HendersonFrom: Mark Tinguely <[email protected]>
Return the directory offset information when replacing an entry to the directory.
This offset will be used as the parent pointer offset in xfs_rename.
[dchinner: forward ported and cleaned up]
[achender: rebased, changed __unint32_t to xfs_dir2_dataptr_t,
Changed typedefs to raw struct types]
--- fs/xfs/libxfs/xfs_dir2.c | 8 ++++++-- fs/xfs/libxfs/xfs_dir2.h | 2 +- fs/xfs/libxfs/xfs_dir2_block.c | 4 ++-- fs/xfs/libxfs/xfs_dir2_leaf.c | 1 + fs/xfs/libxfs/xfs_dir2_node.c | 1 + fs/xfs/libxfs/xfs_dir2_sf.c | 2 ++ fs/xfs/xfs_inode.c | 14 +++++++------- 7 files changed, 20 insertions(+), 12 deletions(-)
fs/xfs/libxfs/xfs_dir2.c +6 -2
@@ -468,7 +468,7 @@ xfs_dir_removename(else rval =xfs_dir2_node_removename (args); out_free: -if (offset) +if (!rval && offset) *offset = args->offset;kmem_free (args);
@@ -484,7 +484,8 @@ xfs_dir_replace(struct xfs_inode *dp, struct xfs_name *name, /* name of entry to replace */ xfs_ino_t inum, /* new inode number */ - xfs_extlen_t total) /* bmap's total block count */ + xfs_extlen_t total, /* bmap's total block count */ + xfs_dir2_dataptr_t *offset) /* OUT: offset in directory */ { struct xfs_da_args *args;int rval;
@@ -532,6 +533,9 @@ xfs_dir_replace(else rval =xfs_dir2_node_replace (args); out_free: +if (offset) + *offset = args->offset; +kmem_free (args);return rval; }
fs/xfs/libxfs/xfs_dir2.h +1 -1
@@ -127,7 +127,7 @@ extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp, xfs_dir2_dataptr_t *offset);extern int xfs_dir_replace (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name,xfs_ino_t inum, -xfs_extlen_t tot); +xfs_extlen_t tot,xfs_dir2_dataptr_t *offset);extern int xfs_dir_canenter (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_name *name);
fs/xfs/libxfs/xfs_dir2_block.c +2 -2
@@ -860,9 +860,9 @@ xfs_dir2_block_replace(/* * Point to the data entry we need to change. */ + args->offset =be32_to_cpu (blp[ent].address); dep = (xfs_dir2_data_entry_t *)((char *)hdr + -xfs_dir2_dataptr_to_off (args->geo, -be32_to_cpu (blp[ent].address))); +xfs_dir2_dataptr_to_off (args->geo, args->offset));ASSERT (be64_to_cpu (dep->inumber) != args->inumber);/* * Change the inode number to the new value.
fs/xfs/libxfs/xfs_dir2_leaf.c +1 -0
@@ -1538,6 +1538,7 @@ xfs_dir2_leaf_replace(/* * Point to the data entry. */ + args->offset =be32_to_cpu (lep->address); dep = (xfs_dir2_data_entry_t *) ((char *)dbp->b_addr +xfs_dir2_dataptr_to_off (args->geo,be32_to_cpu (lep->address)));
fs/xfs/libxfs/xfs_dir2_node.c +1 -0
@@ -2242,6 +2242,7 @@ xfs_dir2_node_replace( hdr = state->extrablk.bp->b_addr;ASSERT (hdr->magic ==cpu_to_be32 (XFS_DIR2_DATA_MAGIC ) || hdr->magic ==cpu_to_be32 (XFS_DIR3_DATA_MAGIC )); + args->offset =be32_to_cpu (lep->address); dep = (xfs_dir2_data_entry_t *) ((char *)hdr + xfs_dir2_dataptr_to_off(args->geo,
fs/xfs/libxfs/xfs_dir2_sf.c +2 -0
@@ -1031,6 +1031,8 @@ xfs_dir2_sf_replace(ASSERT (args->inumber != ino); dp->d_ops->sf_put_ino (sfp, sfep, args->inumber); dp->d_ops->sf_put_ftype (sfep, args->filetype); + args->offset =xfs_dir2_byte_to_dataptr ( +xfs_dir2_sf_get_offset (sfep));break ; } }
fs/xfs/xfs_inode.c +7 -7
@@ -2737,12 +2737,12 @@ xfs_cross_rename(int dp2_flags =0 ;/* Swap inode number for dirent in first parent */ - error =xfs_dir_replace (tp, dp1, name1, ip2->i_ino, spaceres); + error =xfs_dir_replace (tp, dp1, name1, ip2->i_ino, spaceres,NULL );if (error) goto out_trans_abort;/* Swap inode number for dirent in second parent */ - error =xfs_dir_replace (tp, dp2, name2, ip1->i_ino, spaceres); + error =xfs_dir_replace (tp, dp2, name2, ip1->i_ino, spaceres,NULL );if (error) goto out_trans_abort;
@@ -2756,7 +2756,7 @@ xfs_cross_rename(if (S_ISDIR (VFS_I (ip2)->i_mode)) { error =xfs_dir_replace (tp, ip2, &xfs_name_dotdot, - dp1->i_ino, spaceres); + dp1->i_ino, spaceres,NULL );if (error) goto out_trans_abort;
@@ -2782,7 +2782,7 @@ xfs_cross_rename(if (S_ISDIR (VFS_I (ip1)->i_mode)) { error =xfs_dir_replace (tp, ip1, &xfs_name_dotdot, - dp2->i_ino, spaceres); + dp2->i_ino, spaceres,NULL );if (error) goto out_trans_abort;
@@ -3023,7 +3023,7 @@ xfs_rename(* name at the destination directory, remove it first. */ error =xfs_dir_replace (tp, target_dp, target_name, - src_ip->i_ino, spaceres); + src_ip->i_ino, spaceres,NULL );if (error) goto out_trans_cancel;
@@ -3057,7 +3057,7 @@ xfs_rename(* directory. */ error =xfs_dir_replace (tp, src_ip, &xfs_name_dotdot, - target_dp->i_ino, spaceres); + target_dp->i_ino, spaceres,NULL );ASSERT (error != -EEXIST );if (error) goto out_trans_cancel;
@@ -3096,7 +3096,7 @@ xfs_rename(*/ if (wip) { error =xfs_dir_replace (tp, src_dp, src_name, wip->i_ino, - spaceres); + spaceres,NULL ); }else error =xfs_dir_removename (tp, src_dp, src_name, src_ip->i_ino, spaceres,NULL );
Signature · 1 line
2.7.4
PATCH v9 17/28 xfs: add parent pointer support to attribute code
In reply to Allison HendersonFrom: Mark Tinguely <[email protected]>
Add the new parent attribute type. XFS_ATTR_PARENT is used only for parent pointer entries; it uses reserved blocks like XFS_ATTR_ROOT.
[dchinner: forward ported and cleaned up]
[achender: rebased]
--- fs/xfs/libxfs/xfs_attr.c | 4 +++- fs/xfs/libxfs/xfs_attr.h | 2 ++ fs/xfs/libxfs/xfs_da_format.h | 12 ++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_attr.c +3 -1
@@ -382,11 +382,13 @@ xfs_attr_set(struct xfs_buf *leaf_bp =NULL ;struct xfs_da_args args;struct xfs_trans_res tres; -int rsvd = (flags &ATTR_ROOT ) !=0 ; +int rsvd;int error, local;XFS_STATS_INC (mp, xs_attr_set); + rsvd = ((flags &ATTR_ROOT ) |ATTR_PARENT ) !=0 ; +if (XFS_FORCED_SHUTDOWN (dp->i_mount))return -EIO ;
fs/xfs/libxfs/xfs_attr.h +2 -0
@@ -32,6 +32,7 @@ struct xfs_attr_list_context;#define ATTR_SECURE 0x0008/* use attrs in security namespace */ #define ATTR_CREATE 0x0010/* pure create: fail if attr already exists */ #define ATTR_REPLACE 0x0020/* pure set: fail if attr does not exist */ +#define ATTR_PARENT 0x0040/* use attrs in parent namespace */ #define ATTR_KERNOTIME 0x1000/* [kernel] don't update inode timestamps */ #define ATTR_KERNOVAL 0x2000/* [kernel] get attr size only, not value */
@@ -45,6 +46,7 @@ struct xfs_attr_list_context; { ATTR_SECURE, "SECURE" }, \ { ATTR_CREATE, "CREATE" }, \ { ATTR_REPLACE, "REPLACE" }, \ + { ATTR_PARENT, "PARENT" }, \ { ATTR_KERNOTIME, "KERNOTIME" }, \ { ATTR_KERNOVAL, "KERNOVAL" }, \ { ATTR_INCOMPLETE, "INCOMPLETE" }
fs/xfs/libxfs/xfs_da_format.h +8 -4
@@ -746,24 +746,28 @@ struct xfs_attr3_icleaf_hdr {#define XFS_ATTR_LOCAL_BIT 0/* attr is stored locally */ #define XFS_ATTR_ROOT_BIT 1/* limit access to trusted attrs */ #define XFS_ATTR_SECURE_BIT 2/* limit access to secure attrs */ +#define XFS_ATTR_PARENT_BIT 3/* parent pointer secure attrs */ #define XFS_ATTR_INCOMPLETE_BIT 7/* attr in middle of create/delete */ #define XFS_ATTR_LOCAL (1 << XFS_ATTR_LOCAL_BIT)#define XFS_ATTR_ROOT (1 << XFS_ATTR_ROOT_BIT)#define XFS_ATTR_SECURE (1 << XFS_ATTR_SECURE_BIT) +#define XFS_ATTR_PARENT (1 << XFS_ATTR_PARENT_BIT)#define XFS_ATTR_INCOMPLETE (1 << XFS_ATTR_INCOMPLETE_BIT)/* * Conversion macros for converting namespace bits from argument flags * to ondisk flags. */ -#define XFS_ATTR_NSP_ARGS_MASK (ATTR_ROOT | ATTR_SECURE) -#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_NSP_ARGS_MASK (ATTR_ROOT | ATTR_SECURE | XFS_ATTR_PARENT) +#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT)#define XFS_ATTR_NSP_ONDISK (flags) ((flags) & XFS_ATTR_NSP_ONDISK_MASK)#define XFS_ATTR_NSP_ARGS (flags) ((flags) & XFS_ATTR_NSP_ARGS_MASK)#define XFS_ATTR_NSP_ARGS_TO_ONDISK (x) (((x) & ATTR_ROOT ? XFS_ATTR_ROOT : 0) |\ - ((x) & ATTR_SECURE ? XFS_ATTR_SECURE : 0)) + ((x) & ATTR_SECURE ? XFS_ATTR_SECURE : 0) | \ + ((x) & ATTR_PARENT ? XFS_ATTR_PARENT : 0))#define XFS_ATTR_NSP_ONDISK_TO_ARGS (x) (((x) & XFS_ATTR_ROOT ? ATTR_ROOT : 0) |\ - ((x) & XFS_ATTR_SECURE ? ATTR_SECURE : 0)) + ((x) & XFS_ATTR_SECURE ? ATTR_SECURE : 0) | \ + ((x) & XFS_ATTR_PARENT ? ATTR_PARENT : 0))/* * Alignment for namelist and valuelist entries (since they are mixed
Signature · 1 line
2.7.4
PATCH v9 18/28 xfs: define parent pointer xattr format
In reply to Allison HendersonFrom: Dave Chinner <[email protected]>
We need to define the parent pointer attribute format before we start adding support for it into all the code that needs to use it. The EA format we will use encodes the following information:
name={parent inode #, parent inode generation, dirent offset}
value={dirent filename}The inode/gen gives all the information we need to reliably identify the parent without requiring child->parent lock ordering, and allows userspace to do pathname component level reconstruction without the kernel ever needing to verify the parent itself as part of ioctl calls.
By using the dirent offset in the EA name, we have a method of knowing the exact parent pointer EA we need to modify/remove in rename/unlink without an unbound EA name search.
By keeping the dirent name in the value, we have enough information to be able to validate and reconstruct damaged directory trees. While the diroffset of a filename alone is not unique enough to identify the child, the {diroffset,filename,child_inode} tuple is sufficient. That is, if the diroffset gets reused and points to a different filename, we can detect that from the contents of EA. If a link of the same name is created, then we can check whether it points at the same inode as the parent EA we current have.
[achender: rebased, changed __unint32_t to xfs_dir2_dataptr_t,
changed p_ino to xfs_ino_t and p_namelen to uint8_t, moved to xfs_da_format for xfs_dir2_dataptr_t]
--- fs/xfs/libxfs/xfs_da_format.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
fs/xfs/libxfs/xfs_da_format.h +25 -0
@@ -873,4 +873,29 @@ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp) return 1 << (sbp->sb_blocklog + sbp->sb_dirblklog); } +/* +* Parent pointer attribute format definition +* +* EA name encodes the parent inode number, generation and the offset of +* the dirent that points to the child inode. The EA value contains the +* same name as the dirent in the parent directory. +*/ +struct xfs_parent_name_rec { +__be64 p_ino; +__be32 p_gen; +__be32 p_diroffset; +}; + +/* +* incore version of the above, also contains name pointers so callers +* can pass/obtain all the parent pointer information in a single structure +*/ +struct xfs_parent_name_irec { +xfs_ino_t p_ino; +uint32_t p_gen; +xfs_dir2_dataptr_t p_diroffset; +const char *p_name; +uint8_t p_namelen; +}; +#endif /* __XFS_DA_FORMAT_H__ */
Signature · 1 line
2.7.4
PATCH v9 19/28 xfs: extent transaction reservations for parent attributes
In reply to Allison HendersonFrom: Dave Chinner <[email protected]>
We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the parent directories being modified. This means they need to be modified in the same transaction as the parent directories, and so we need to add the required space for the attribute modifications to the transaction reservations.
[achender: rebased, added xfs_sb_version_hasparent stub]
--- fs/xfs/libxfs/xfs_format.h | 5 ++ fs/xfs/libxfs/xfs_trans_resv.c | 111 ++++++++++++++++++++++++++++++++--------- fs/xfs/libxfs/xfs_trans_resv.h | 1 + 3 files changed, 94 insertions(+), 23 deletions(-)
fs/xfs/libxfs/xfs_format.h +5 -0
@@ -550,6 +550,11 @@ static inline bool xfs_sb_version_hasreflink(struct xfs_sb *sbp) (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_REFLINK ); } +static inline bool xfs_sb_version_hasparent (struct xfs_sb *sbp) +{ +return false;/* We'll enable this at the end of the set */ +} +/* * end of superblock version macros */
fs/xfs/libxfs/xfs_trans_resv.c +88 -23
138 lines not on this page · raw message
fs/xfs/libxfs/xfs_trans_resv.h +1 -0
@@ -93,5 +93,6 @@ struct xfs_trans_resv {void xfs_trans_resv_calc (struct xfs_mount *mp,struct xfs_trans_resv *resp);uint xfs_allocfree_log_count (struct xfs_mount *mp,uint num_ops); +void xfs_calc_parent_ptr_reservations (struct xfs_mount *mp);#endif /* __XFS_TRANS_RESV_H__ */
Signature · 1 line
2.7.4
PATCH v9 20/28 xfs: parent pointer attribute creation
In reply to Allison HendersonFrom: Dave Chinner <[email protected]>
Add parent pointer attribute during xfs_create, and subroutines to initialize attributes
[bfoster: rebase, use VFS inode generation]
[achender: rebased, changed __unint32_t to xfs_dir2_dataptr_t,
fixed some null pointer bugs,
merged error handling patch,
added subroutines to handle attribute initialization, remove unnecessary ENOSPC handling in xfs_attr_set_first_parent]
--- fs/xfs/Makefile | 2 + fs/xfs/libxfs/xfs_parent.c | 187 +++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_parent.h | 35 +++++++++ fs/xfs/xfs_inode.c | 17 ++++- fs/xfs/xfs_parent_utils.c | 52 +++++++++++++ fs/xfs/xfs_parent_utils.h | 26 +++++++ 6 files changed, 317 insertions(+), 2 deletions(-)
fs/xfs/Makefile +2 -0
@@ -42,6 +42,7 @@ xfs-y += $(addprefix libxfs/, \ xfs_inode_fork.o \ xfs_inode_buf.o \ xfs_log_rlimit.o \ + xfs_parent.o \ xfs_ag_resv.o \ xfs_rmap.o \ xfs_rmap_btree.o \
@@ -82,6 +83,7 @@ xfs-y += xfs_aops.o \ xfs_message.o \ xfs_mount.o \ xfs_mru_cache.o \ + xfs_parent_utils.o \ xfs_reflink.o \ xfs_stats.o \ xfs_super.o \
fs/xfs/libxfs/xfs_parent.c new file +187 -0
187 lines not on this page · raw message
fs/xfs/libxfs/xfs_parent.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2018 Oracle, Inc. +* All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation Inc. +*/ +#ifndef __XFS_PARENT_H__ +#define __XFS_PARENT_H__ + +#include "xfs_da_format.h" +#include "xfs_format.h" + +/* +* Parent pointer attribute prototypes +*/ +void xfs_init_parent_name_rec (struct xfs_parent_name_rec *rec, +struct xfs_inode *ip, +uint32_t p_diroffset); +void xfs_init_parent_name_irec (struct xfs_parent_name_irec *irec, +struct xfs_parent_name_rec *rec); + +int xfs_parent_add (struct xfs_inode *parent, +struct xfs_inode *child,struct xfs_name *child_name, +uint32_t diroffset); +#endif /* __XFS_PARENT_H__ */
fs/xfs/xfs_inode.c +15 -2
@@ -41,6 +41,7 @@#include "xfs_bmap_btree.h" #include "xfs_reflink.h" #include "xfs_dir2_priv.h" +#include "xfs_parent_utils.h" kmem_zone_t *xfs_inode_zone;
@@ -1151,6 +1152,7 @@ xfs_create(struct xfs_dquot *pdqp =NULL ;struct xfs_trans_res *tres;uint resblks; +xfs_dir2_dataptr_t diroffset;trace_xfs_create (dp, name);
@@ -1219,13 +1221,13 @@ xfs_create(* the transaction cancel unlocking dp so don't do it explicitly in the * error path. */ -xfs_trans_ijoin (tp, dp,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, dp,0 ); unlock_dp_on_error = false; error =xfs_dir_createname (tp, dp, name, ip->i_ino, resblks ? resblks -XFS_IALLOC_SPACE_RES (mp) :0 , -NULL ); + &diroffset);if (error) {ASSERT (error != -ENOSPC ); goto out_trans_cancel;
@@ -1244,6 +1246,16 @@ xfs_create( }/* +* If we have parent pointers, we need to add the attribute containing +* the parent information now. +*/ +if (xfs_sb_version_hasparent (&mp->m_sb)) { + error =xfs_parent_add_deferred (dp, tp, ip, name, diroffset); +if (error) + goto out_trans_cancel; + } + +/* * If this is a synchronous mount, make sure that the * create transaction goes to disk before returning to * the user.
@@ -1268,6 +1280,7 @@ xfs_create( *ipp = ip;xfs_iunlock (ip,XFS_ILOCK_EXCL ); +xfs_iunlock (dp,XFS_ILOCK_EXCL |XFS_ILOCK_PARENT );return 0 ; out_trans_cancel:
fs/xfs/xfs_parent_utils.c new file +52 -0
52 lines not on this page · raw message
fs/xfs/xfs_parent_utils.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (c) 2017 Oracle, Inc. +* All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation Inc. +*/ +#ifndef __XFS_PARENT_UTILS_H__ +#define __XFS_PARENT_UTILS_H__ + +/* +* Parent pointer attribute prototypes +*/ +int xfs_parent_add_deferred (struct xfs_inode *parent,struct xfs_trans *tp, +struct xfs_inode *child,struct xfs_name *child_name, +uint32_t diroffset); +#endif /* __XFS_PARENT_UTILS_H__ */
Signature · 1 line
2.7.4
PATCH v9 21/28 xfs: add parent attributes to link
In reply to Allison HendersonFrom: Dave Chinner <[email protected]>
This patch modifies xfs_link to add a parent pointer to the inode. xfs_link will also need to create an attribute fork if the inode does not already have one.
[bfoster: rebase, use VFS inode fields, fix xfs_bmap_finish() usage] [achender: rebased, changed __unint32_t to xfs_dir2_dataptr_t,
fixed null pointer bugs]
--- fs/xfs/xfs_inode.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-)
fs/xfs/xfs_inode.c +29 -8
@@ -1409,6 +1409,7 @@ xfs_link(xfs_trans_t *tp;int error;int resblks; +xfs_dir2_dataptr_t diroffset;trace_xfs_link (tdp, target_name);
@@ -1436,8 +1437,8 @@ xfs_link(xfs_lock_two_inodes (sip,XFS_ILOCK_EXCL , tdp,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, sip,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, tdp,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, sip,0 ); +xfs_trans_ijoin (tp, tdp,0 );/* * If we are using project inheritance, we only allow hard link
@@ -1466,15 +1467,28 @@ xfs_link( } error =xfs_dir_createname (tp, tdp, target_name, sip->i_ino, - resblks,NULL ); + resblks, &diroffset);if (error) - goto error_return; + goto out_defer_cancel;xfs_trans_ichgtime (tp, tdp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG );xfs_trans_log_inode (tp, tdp,XFS_ILOG_CORE ); error =xfs_bumplink (tp, sip);if (error) - goto error_return; + goto out_defer_cancel; + +/* +* If we have parent pointers, we now need to add the parent record to +* the attribute fork of the inode. If this is the initial parent +* attribute, we need to create it correctly, otherwise we can just add +* the parent to the inode. +*/ +if (xfs_sb_version_hasparent (&mp->m_sb)) { + error =xfs_parent_add_deferred (tdp, tp, sip, target_name, + diroffset); +if (error) + goto out_defer_cancel; + }/* * If this is a synchronous mount, make sure that the
@@ -1484,11 +1498,18 @@ xfs_link(if (mp->m_flags & (XFS_MOUNT_WSYNC |XFS_MOUNT_DIRSYNC ))xfs_trans_set_sync (tp); -return xfs_trans_commit (tp); + error =xfs_trans_commit (tp); +xfs_iunlock (tdp,XFS_ILOCK_EXCL ); +xfs_iunlock (sip,XFS_ILOCK_EXCL ); +return error; - error_return: +out_defer_cancel: +xfs_defer_cancel (tp); +error_return:xfs_trans_cancel (tp); - std_return: +xfs_iunlock (tdp,XFS_ILOCK_EXCL ); +xfs_iunlock (sip,XFS_ILOCK_EXCL ); +std_return:return error; }
Signature · 1 line
2.7.4
PATCH v9 22/28 xfs: remove parent pointers in unlink
In reply to Allison HendersonFrom: Dave Chinner <[email protected]>
This patch removes the parent pointer attribute during unlink
[bfoster: rebase, use VFS inode generation] [achender: rebased, changed __unint32_t to xfs_dir2_dataptr_t
implemented xfs_attr_remove_parent]
--- fs/xfs/xfs_inode.c | 20 ++++++++++++++++---- fs/xfs/xfs_parent_utils.c | 18 ++++++++++++++++++ fs/xfs/xfs_parent_utils.h | 4 ++++ 3 files changed, 38 insertions(+), 4 deletions(-)
fs/xfs/xfs_inode.c +16 -4
@@ -2577,6 +2577,7 @@ xfs_remove(int is_dir =S_ISDIR (VFS_I (ip)->i_mode);int error =0 ;uint resblks; +xfs_dir2_dataptr_t dir_offset;trace_xfs_remove (dp, name);
@@ -2614,8 +2615,8 @@ xfs_remove(xfs_lock_two_inodes (dp,XFS_ILOCK_EXCL , ip,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, dp,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, dp,0 ); +xfs_trans_ijoin (tp, ip,0 );/* * If we're removing a directory perform some additional validation.
@@ -2655,12 +2656,18 @@ xfs_remove(if (error) goto out_trans_cancel; - error =xfs_dir_removename (tp, dp, name, ip->i_ino, resblks,NULL ); + error =xfs_dir_removename (tp, dp, name, ip->i_ino, resblks, &dir_offset);if (error) {ASSERT (error != -ENOENT ); goto out_trans_cancel; } +if (xfs_sb_version_hasparent (&mp->m_sb)) { + error =xfs_parent_remove_deferred (dp, tp, ip, dir_offset); +if (error) + goto out_trans_cancel; + } +/* * If this is a synchronous mount, make sure that the * remove transaction goes to disk before returning to
@@ -2671,15 +2678,20 @@ xfs_remove( error =xfs_trans_commit (tp);if (error) - goto std_return; + goto out_unlock;if (is_dir &&xfs_inode_is_filestream (ip))xfs_filestream_deassociate (ip); +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +xfs_iunlock (dp,XFS_ILOCK_EXCL );return 0 ; out_trans_cancel:xfs_trans_cancel (tp); +out_unlock: +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +xfs_iunlock (dp,XFS_ILOCK_EXCL ); std_return:return error; }
fs/xfs/xfs_parent_utils.c +18 -0
@@ -50,3 +50,21 @@ xfs_parent_add_deferred( child_name->name, child_name->len, ATTR_PARENT); } +/* +* Remove a parent record from a child inode. +*/ +int +xfs_parent_remove_deferred ( +struct xfs_inode *parent, +struct xfs_trans *tp, +struct xfs_inode *child, +xfs_dir2_dataptr_t diroffset) +{ +struct xfs_parent_name_rec rec; + +xfs_init_parent_name_rec (&rec, parent, diroffset); + +return xfs_attr_remove_deferred (child, tp, (const char *)&rec, +sizeof (rec),ATTR_PARENT ); +} +
fs/xfs/xfs_parent_utils.h +4 -0
@@ -23,4 +23,8 @@int xfs_parent_add_deferred (struct xfs_inode *parent,struct xfs_trans *tp,struct xfs_inode *child,struct xfs_name *child_name,uint32_t diroffset); +int xfs_parent_remove_deferred (struct xfs_inode *parent, +struct xfs_trans *tp, +struct xfs_inode *child, +xfs_dir2_dataptr_t diroffset);#endif /* __XFS_PARENT_UTILS_H__ */
Signature · 1 line
2.7.4
PATCH v9 23/28 xfs: Add parent pointers to rename
In reply to Allison HendersonThis patch removes the old parent pointer attribute during the rename operation, and re-adds the updated parent pointer. In the case of xfs_cross_rename, we modify the routine not to roll the transaction just yet. We will do this after the parent pointer is added in the calling xfs_rename function.
--- fs/xfs/xfs_inode.c | 61 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 17 deletions(-)
fs/xfs/xfs_inode.c +44 -17
@@ -2867,7 +2867,7 @@ xfs_cross_rename( }xfs_trans_ichgtime (tp, dp1,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG );xfs_trans_log_inode (tp, dp1,XFS_ILOG_CORE ); -return xfs_finish_rename (tp); +return 0 ; out_trans_abort:xfs_trans_cancel (tp);
@@ -2931,6 +2931,8 @@ xfs_rename(bool src_is_directory =S_ISDIR (VFS_I (src_ip)->i_mode);int spaceres;int error; +xfs_dir2_dataptr_t new_diroffset; +xfs_dir2_dataptr_t old_diroffset;trace_xfs_rename (src_dp, target_dp, src_name, target_name);
@@ -2985,14 +2987,14 @@ xfs_rename(* we can rely on either trans_commit or trans_cancel to unlock * them. */ -xfs_trans_ijoin (tp, src_dp,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, src_dp,0 );if (new_parent) -xfs_trans_ijoin (tp, target_dp,XFS_ILOCK_EXCL ); -xfs_trans_ijoin (tp, src_ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, target_dp,0 ); +xfs_trans_ijoin (tp, src_ip,0 );if (target_ip) -xfs_trans_ijoin (tp, target_ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, target_ip,0 );if (wip) -xfs_trans_ijoin (tp, wip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, wip,0 );/* * If we are using project inheritance, we only allow renames
@@ -3002,15 +3004,16 @@ xfs_rename(if (unlikely ((target_dp->i_d.di_flags &XFS_DIFLAG_PROJINHERIT ) && (xfs_get_projid (target_dp) !=xfs_get_projid (src_ip)))) { error = -EXDEV ; - goto out_trans_cancel; + goto out_unlock; }/* RENAME_EXCHANGE is unique from here on. */ -if (flags &RENAME_EXCHANGE ) -return xfs_cross_rename (tp, src_dp, src_name, src_ip, +if (flags &RENAME_EXCHANGE ) { + error =xfs_cross_rename (tp, src_dp, src_name, src_ip, target_dp, target_name, target_ip, spaceres); - + goto out_pptr; + }/* * Set up the target. */
@@ -3022,7 +3025,7 @@ xfs_rename(if (!spaceres) { error =xfs_dir_canenter (tp, target_dp, target_name);if (error) - goto out_trans_cancel; + goto out_unlock; }/* * If target does not exist and the rename crosses
@@ -3030,7 +3033,7 @@ xfs_rename(* to account for the ".." reference from the new entry. */ error =xfs_dir_createname (tp, target_dp, target_name, - src_ip->i_ino, spaceres,NULL ); + src_ip->i_ino, spaceres, &new_diroffset);if (error) goto out_trans_cancel;
@@ -3055,7 +3058,7 @@ xfs_rename(if (!(xfs_dir_isempty (target_ip)) || (VFS_I (target_ip)->i_nlink >2 )) { error = -EEXIST ; - goto out_trans_cancel; + goto out_unlock; } }
@@ -3069,7 +3072,7 @@ xfs_rename(* name at the destination directory, remove it first. */ error =xfs_dir_replace (tp, target_dp, target_name, - src_ip->i_ino, spaceres,NULL ); + src_ip->i_ino, spaceres, &new_diroffset);if (error) goto out_trans_cancel;
@@ -3103,7 +3106,7 @@ xfs_rename(* directory. */ error =xfs_dir_replace (tp, src_ip, &xfs_name_dotdot, - target_dp->i_ino, spaceres,NULL ); + target_dp->i_ino, spaceres, &new_diroffset);ASSERT (error != -EEXIST );if (error) goto out_trans_cancel;
@@ -3142,10 +3145,10 @@ xfs_rename(*/ if (wip) { error =xfs_dir_replace (tp, src_dp, src_name, wip->i_ino, - spaceres,NULL ); + spaceres, &old_diroffset); }else error =xfs_dir_removename (tp, src_dp, src_name, src_ip->i_ino, - spaceres,NULL ); + spaceres, &old_diroffset);if (error) goto out_trans_cancel;
@@ -3175,14 +3178,38 @@ xfs_rename(VFS_I (wip)->i_state &= ~I_LINKABLE ; } +out_pptr: +if (xfs_sb_version_hasparent (&mp->m_sb)) { + error =xfs_parent_add_deferred (target_dp, tp, src_ip, target_name, + new_diroffset); +if (error) + goto out_trans_cancel; + + error =xfs_parent_remove_deferred (src_dp, tp, src_ip, + old_diroffset); +if (error) + goto out_trans_cancel; + } +xfs_trans_ichgtime (tp, src_dp,XFS_ICHGTIME_MOD |XFS_ICHGTIME_CHG );xfs_trans_log_inode (tp, src_dp,XFS_ILOG_CORE );if (new_parent)xfs_trans_log_inode (tp, target_dp,XFS_ILOG_CORE ); error =xfs_finish_rename (tp); + +out_unlock:if (wip)xfs_irele (wip); +if (wip) +xfs_iunlock (wip,XFS_ILOCK_EXCL ); +if (target_ip) +xfs_iunlock (target_ip,XFS_ILOCK_EXCL ); +xfs_iunlock (src_ip,XFS_ILOCK_EXCL ); +if (new_parent) +xfs_iunlock (target_dp,XFS_ILOCK_EXCL ); +xfs_iunlock (src_dp,XFS_ILOCK_EXCL ); +return error; out_trans_cancel:
Signature · 1 line
2.7.4
PATCH v9 24/28 xfs: Add the parent pointer support to the superblock version 5.
In reply to Allison Henderson[dchinner: forward ported and cleaned up] [achender: rebased and added parent pointer attribute to
compatible attributes mask]
--- fs/xfs/libxfs/xfs_format.h | 7 +++++-- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/libxfs/xfs_sb.c | 2 ++ fs/xfs/xfs_super.c | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_format.h +5 -2
@@ -453,10 +453,12 @@ xfs_sb_has_compat_feature(#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */ #define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ #define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ +#define XFS_SB_FEAT_RO_COMPAT_PARENT (1 << 3)/* parent inode ptr */ #define XFS_SB_FEAT_RO_COMPAT_ALL \ (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ XFS_SB_FEAT_RO_COMPAT_RMAPBT | \ - XFS_SB_FEAT_RO_COMPAT_REFLINK) + XFS_SB_FEAT_RO_COMPAT_REFLINK| \ + XFS_SB_FEAT_RO_COMPAT_PARENT)#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALLstatic inline bool xfs_sb_has_ro_compat_feature(
@@ -552,7 +554,8 @@ static inline bool xfs_sb_version_hasreflink(struct xfs_sb *sbp)static inline bool xfs_sb_version_hasparent (struct xfs_sb *sbp) { -return false;/* We'll enable this at the end of the set */ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 && + (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_PARENT )); }/*
fs/xfs/libxfs/xfs_fs.h +1 -0
@@ -210,6 +210,7 @@ typedef struct xfs_fsop_resblks {#define XFS_FSOP_GEOM_FLAGS_SPINODES 0x40000/* sparse inode chunks */ #define XFS_FSOP_GEOM_FLAGS_RMAPBT 0x80000/* reverse mapping btree */ #define XFS_FSOP_GEOM_FLAGS_REFLINK 0x100000/* files can share blocks */ +#define XFS_FSOP_GEOM_FLAGS_PARENT 0x200000/* parent pointers */ /* * Minimum and maximum sizes need for growth checks.
fs/xfs/libxfs/xfs_sb.c +2 -0
@@ -1148,6 +1148,8 @@ xfs_fs_geometry( geo->flags |=XFS_FSOP_GEOM_FLAGS_RMAPBT ;if (xfs_sb_version_hasreflink (sbp)) geo->flags |=XFS_FSOP_GEOM_FLAGS_REFLINK ; +if (xfs_sb_version_hasparent (sbp)) + geo->flags |=XFS_FSOP_GEOM_FLAGS_PARENT ;if (xfs_sb_version_hassector (sbp)) geo->logsectsize = sbp->sb_logsectsize;else
fs/xfs/xfs_super.c +4 -0
@@ -1710,6 +1710,10 @@ xfs_fs_fill_super( goto out_filestream_unmount; } +if (xfs_sb_version_hasparent (&mp->m_sb)) +xfs_alert (mp, +"EXPERIMENTAL parent pointer feature enabled. Use at your own risk!" ); + error =xfs_mountfs (mp);if (error) goto out_filestream_unmount;
Signature · 1 line
2.7.4
PATCH v9 25/28 xfs: Add helper function xfs_attr_list_context_init
In reply to Allison HendersonThis patch adds a helper function xfs_attr_list_context_init used by xfs_attr_list. This function initializes the xfs_attr_list_context structure passed to xfs_attr_list_int. We will need this later to call xfs_attr_list_int_ilocked when the node is already locked.
--- fs/xfs/libxfs/xfs_attr.h | 3 ++ fs/xfs/xfs_attr_list.c | 72 +++++++++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 25 deletions(-)
fs/xfs/libxfs/xfs_attr.h +3 -0
@@ -188,6 +188,9 @@ 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); +int xfs_attr_list_context_init (struct xfs_inode *dp,char *buffer,int bufsize, +int flags,struct attrlist_cursor_kern *cursor, +struct xfs_attr_list_context *context);int xfs_attr_args_init (struct xfs_da_args *args,struct xfs_inode *dp,const unsigned char *name,size_t namelen,int flags);int xfs_attr_calc_size (struct xfs_da_args *args,int *local);
fs/xfs/xfs_attr_list.c +47 -25
90 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v9 26/28 xfs: Increase XFS_DEFER_OPS_NR_INODES to 4
In reply to Allison HendersonRenames that generate parent pointer updates will need to 2 extra defer operations. One for the rmap update and another for the parent pointer update
--- fs/xfs/xfs_trans.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_trans.h +1 -1
@@ -95,7 +95,7 @@ void xfs_log_item_init(struct xfs_mount *mp, struct xfs_log_item *item,/* * Deferred operation item relogging limits. */ -#define XFS_DEFER_OPS_NR_INODES 2/* join up to two inodes */ +#define XFS_DEFER_OPS_NR_INODES 4/* join up to four inodes */ #define XFS_DEFER_OPS_NR_BUFS 2/* join up to two buffers */ /*
Signature · 1 line
2.7.4
PATCH v9 27/28 xfs: Add parent pointer ioctl
In reply to Allison HendersonThis patch adds a new file ioctl to retrieve the parent pointer of a given inode
--- fs/xfs/libxfs/xfs_fs.h | 45 ++++++++++++++++++++++++ fs/xfs/libxfs/xfs_parent.c | 10 ++++++ fs/xfs/libxfs/xfs_parent.h | 2 ++ fs/xfs/xfs_attr_list.c | 3 ++ fs/xfs/xfs_ioctl.c | 86 +++++++++++++++++++++++++++++++++++++++++++++- fs/xfs/xfs_ondisk.h | 4 +++ fs/xfs/xfs_parent_utils.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_parent_utils.h | 2 ++ 8 files changed, 235 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_fs.h +45 -0
@@ -547,6 +547,50 @@ struct xfs_scrub_metadata { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED)#define XFS_SCRUB_FLAGS_ALL (XFS_SCRUB_FLAGS_IN | XFS_SCRUB_FLAGS_OUT) +#define XFS_PPTR_MAXNAMELEN 256 + +/* return parents of the handle, not the open fd */ +#define XFS_PPTR_IFLAG_HANDLE (1U << 0) + +/* target was the root directory */ +#define XFS_PPTR_OFLAG_ROOT (1U << 1) + +/* Cursor is done iterating pptrs */ +#define XFS_PPTR_OFLAG_DONE (1U << 2) + +/* Get an inode parent pointer through ioctl */ +struct xfs_parent_ptr { +__u64 xpp_ino;/* Inode */ +__u32 xpp_gen;/* Inode generation */ +__u32 xpp_diroffset;/* Directory offset */ +__u32 xpp_namelen;/* File name length */ +__u32 xpp_pad; +__u8 xpp_name[XFS_PPTR_MAXNAMELEN ];/* File name */ +}; + +/* Iterate through an inodes parent pointers */ +struct xfs_pptr_info { +struct xfs_handle pi_handle; +struct xfs_attrlist_cursor pi_cursor; +__u32 pi_flags; +__u32 pi_reserved; +__u32 pi_ptrs_size; +__u32 pi_ptrs_used; +__u64 pi_reserved2[6 ]; + +/* +* An array of struct xfs_parent_ptr follows the header +* information. Use XFS_PPINFO_TO_PP() to access the +* parent pointer array entries. +*/ +}; + +#define XFS_PPTR_INFO_SIZEOF (nr_ptrs) sizeof (struct xfs_pptr_info) + \ + nr_ptrs * sizeof(struct xfs_parent_ptr) + +#define XFS_PPINFO_TO_PP (info, idx) \ + (&(((struct xfs_parent_ptr *)((char *)(info) + sizeof(*(info))))[(idx)])) +/* * ioctl limits */
@@ -591,6 +635,7 @@ struct xfs_scrub_metadata {#define XFS_IOC_FREE_EOFBLOCKS _IOR ('X', 58, struct xfs_fs_eofblocks)/* XFS_IOC_GETFSMAP ------ hoisted 59 */ #define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata) +#define XFS_IOC_GETPPOINTER _IOR ('X', 61, struct xfs_parent_ptr)/* * ioctl commands that replace IRIX syssgi()'s
fs/xfs/libxfs/xfs_parent.c +10 -0
@@ -33,6 +33,16 @@#include "xfs_attr_sf.h" #include "xfs_bmap.h" +/* Initializes a xfs_parent_ptr from an xfs_parent_name_rec */ +void +xfs_init_parent_ptr (struct xfs_parent_ptr *xpp, +struct xfs_parent_name_rec *rec) +{ + xpp->xpp_ino =be64_to_cpu (rec->p_ino); + xpp->xpp_gen =be32_to_cpu (rec->p_gen); + xpp->xpp_diroffset =be32_to_cpu (rec->p_diroffset); +} +/* * Parent pointer attribute handling. *
fs/xfs/libxfs/xfs_parent.h +2 -0
@@ -32,4 +32,6 @@ void xfs_init_parent_name_irec(struct xfs_parent_name_irec *irec,int xfs_parent_add (struct xfs_inode *parent,struct xfs_inode *child,struct xfs_name *child_name,uint32_t diroffset); +void xfs_init_parent_ptr (struct xfs_parent_ptr *xpp, +struct xfs_parent_name_rec *rec);#endif /* __XFS_PARENT_H__ */
fs/xfs/xfs_attr_list.c +3 -0
@@ -570,6 +570,9 @@ xfs_attr_put_listent(if (((context->flags &ATTR_ROOT ) ==0 ) != ((flags &XFS_ATTR_ROOT ) ==0 ))return ; +if (((context->flags &ATTR_PARENT ) ==0 ) != + ((flags &XFS_ATTR_PARENT ) ==0 )) +return ; arraytop =sizeof (*alist) + context->count *sizeof (alist->al_offset[0 ]);
fs/xfs/xfs_ioctl.c +85 -1
104 lines not on this page · raw message
fs/xfs/xfs_ondisk.h +4 -0
@@ -127,6 +127,10 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_trans_header, 16); XFS_CHECK_STRUCT_SIZE(struct xfs_attri_log_format, 40); XFS_CHECK_STRUCT_SIZE(struct xfs_attrd_log_format, 16); + +/* parent pointer ioctls */ + XFS_CHECK_STRUCT_SIZE(struct xfs_parent_ptr, 280); + XFS_CHECK_STRUCT_SIZE(struct xfs_pptr_info, 104); }#endif /* __XFS_ONDISK_H */
fs/xfs/xfs_parent_utils.c +84 -0
93 lines not on this page · raw message
fs/xfs/xfs_parent_utils.h +2 -0
@@ -27,4 +27,6 @@ int xfs_parent_remove_deferred(struct xfs_inode *parent,struct xfs_trans *tp, struct xfs_inode *child, xfs_dir2_dataptr_t diroffset); +int xfs_attr_get_parent_pointer (struct xfs_inode *ip, +struct xfs_pptr_info *ppi);#endif /* __XFS_PARENT_UTILS_H__ */
Signature · 1 line
2.7.4
PATCH v9 28/28 xfs: Add delayed attributes error tag
In reply to Allison HendersonThis patch adds an error tag that we can use to test delayed attribute recovery and replay
--- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 3 +++ fs/xfs/xfs_trans_attr.c | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_errortag.h +3 -1
@@ -54,7 +54,8 @@#define XFS_ERRTAG_BUF_LRU_REF 31#define XFS_ERRTAG_FORCE_SCRUB_REPAIR 32#define XFS_ERRTAG_FORCE_SUMMARY_RECALC 33 -#define XFS_ERRTAG_MAX 34 +#define XFS_ERRTAG_DELAYED_ATTR 34 +#define XFS_ERRTAG_MAX 35/* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc.
@@ -93,5 +94,6 @@#define XFS_RANDOM_BUF_LRU_REF 2#define XFS_RANDOM_FORCE_SCRUB_REPAIR 1#define XFS_RANDOM_FORCE_SUMMARY_RECALC 1 +#define XFS_RANDOM_DELAYED_ATTR 1#endif /* __XFS_ERRORTAG_H_ */
fs/xfs/xfs_error.c +3 -0
@@ -51,6 +51,7 @@ static unsigned int xfs_errortag_random_default[] = {XFS_RANDOM_BUF_LRU_REF ,XFS_RANDOM_FORCE_SCRUB_REPAIR ,XFS_RANDOM_FORCE_SUMMARY_RECALC , + XFS_RANDOM_DELAYED_ATTR, }; struct xfs_errortag_attr {
@@ -159,6 +160,7 @@ XFS_ERRORTAG_ATTR_RW(log_item_pin, XFS_ERRTAG_LOG_ITEM_PIN);XFS_ERRORTAG_ATTR_RW (buf_lru_ref,XFS_ERRTAG_BUF_LRU_REF );XFS_ERRORTAG_ATTR_RW (force_repair,XFS_ERRTAG_FORCE_SCRUB_REPAIR );XFS_ERRORTAG_ATTR_RW (bad_summary,XFS_ERRTAG_FORCE_SUMMARY_RECALC ); +XFS_ERRORTAG_ATTR_RW (delayed_attr,XFS_ERRTAG_DELAYED_ATTR );static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (noerror),
@@ -195,6 +197,7 @@ static struct attribute *xfs_errortag_attrs[] = {XFS_ERRORTAG_ATTR_LIST (buf_lru_ref),XFS_ERRORTAG_ATTR_LIST (force_repair),XFS_ERRORTAG_ATTR_LIST (bad_summary), +XFS_ERRORTAG_ATTR_LIST (delayed_attr), NULL, };
fs/xfs/xfs_trans_attr.c +8 -0
@@ -35,6 +35,8 @@#include "xfs_inode.h" #include "xfs_icache.h" #include "xfs_quota.h" +#include "xfs_errortag.h" +#include "xfs_error.h" /* * This routine is called to allocate an "attr free done"
@@ -77,6 +79,11 @@ xfs_trans_attr(if (error)return error; +if (XFS_TEST_ERROR (false, args->dp->i_mount,XFS_ERRTAG_DELAYED_ATTR )) { + error = -EIO ; + goto out; + } +switch (op_flags) {case XFS_ATTR_OP_FLAGS_SET : args->op_flags |=XFS_DA_OP_ADDNAME ;
@@ -91,6 +98,7 @@ xfs_trans_attr( error = -EFSCORRUPTED ; } +out:/* * Mark the transaction dirty, even on error. This ensures the * transaction is aborted, which:
Signature · 1 line
2.7.4