Skip to content

Commit 4d0cdd2

Browse files
Darrick J. Wongdchinner
authored andcommitted
xfs: clean up xfs_attr_node_hasname
The calling conventions of this function are a mess -- callers /can/ provide a pointer to a pointer to a state structure, but it's not required, and as evidenced by the last two patches, the callers that do weren't be careful enough about how to deal with an existing da state. Push the allocation and freeing responsibilty to the callers, which means that callers from the xattr node state machine steps now have the visibility to allocate or free the da state structure as they please. As a bonus, the node remove/add paths for larp-mode replaces can reset the da state structure instead of freeing and immediately reallocating it. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Allison Henderson <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Signed-off-by: Dave Chinner <[email protected]>
1 parent 2fe3ffc commit 4d0cdd2

File tree

3 files changed

+44
-31
lines changed

3 files changed

+44
-31
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ STATIC void xfs_attr_restore_rmt_blk(struct xfs_da_args *args);
6161
static int xfs_attr_node_try_addname(struct xfs_attr_item *attr);
6262
STATIC int xfs_attr_node_addname_find_attr(struct xfs_attr_item *attr);
6363
STATIC int xfs_attr_node_remove_attr(struct xfs_attr_item *attr);
64-
STATIC int xfs_attr_node_hasname(xfs_da_args_t *args,
65-
struct xfs_da_state **state);
64+
STATIC int xfs_attr_node_lookup(struct xfs_da_args *args,
65+
struct xfs_da_state *state);
6666

6767
int
6868
xfs_inode_hasattr(
@@ -594,6 +594,19 @@ xfs_attr_leaf_mark_incomplete(
594594
return xfs_attr3_leaf_setflag(args);
595595
}
596596

597+
/* Ensure the da state of an xattr deferred work item is ready to go. */
598+
static inline void
599+
xfs_attr_item_init_da_state(
600+
struct xfs_attr_item *attr)
601+
{
602+
struct xfs_da_args *args = attr->xattri_da_args;
603+
604+
if (!attr->xattri_da_state)
605+
attr->xattri_da_state = xfs_da_state_alloc(args);
606+
else
607+
xfs_da_state_reset(attr->xattri_da_state, args);
608+
}
609+
597610
/*
598611
* Initial setup for xfs_attr_node_removename. Make sure the attr is there and
599612
* the blocks are valid. Attr keys with remote blocks will be marked
@@ -607,7 +620,8 @@ int xfs_attr_node_removename_setup(
607620
struct xfs_da_state *state;
608621
int error;
609622

610-
error = xfs_attr_node_hasname(args, &attr->xattri_da_state);
623+
xfs_attr_item_init_da_state(attr);
624+
error = xfs_attr_node_lookup(args, attr->xattri_da_state);
611625
if (error != -EEXIST)
612626
goto out;
613627
error = 0;
@@ -855,6 +869,7 @@ xfs_attr_lookup(
855869
{
856870
struct xfs_inode *dp = args->dp;
857871
struct xfs_buf *bp = NULL;
872+
struct xfs_da_state *state;
858873
int error;
859874

860875
if (!xfs_inode_hasattr(dp))
@@ -872,7 +887,10 @@ xfs_attr_lookup(
872887
return error;
873888
}
874889

875-
return xfs_attr_node_hasname(args, NULL);
890+
state = xfs_da_state_alloc(args);
891+
error = xfs_attr_node_lookup(args, state);
892+
xfs_da_state_free(state);
893+
return error;
876894
}
877895

878896
static int
@@ -1387,34 +1405,20 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
13871405
return error;
13881406
}
13891407

1390-
/*
1391-
* Return EEXIST if attr is found, or ENOATTR if not
1392-
* statep: If not null is set to point at the found state. Caller will
1393-
* be responsible for freeing the state in this case.
1394-
*/
1408+
/* Return EEXIST if attr is found, or ENOATTR if not. */
13951409
STATIC int
1396-
xfs_attr_node_hasname(
1410+
xfs_attr_node_lookup(
13971411
struct xfs_da_args *args,
1398-
struct xfs_da_state **statep)
1412+
struct xfs_da_state *state)
13991413
{
1400-
struct xfs_da_state *state;
14011414
int retval, error;
14021415

1403-
state = xfs_da_state_alloc(args);
1404-
if (statep != NULL) {
1405-
ASSERT(*statep == NULL);
1406-
*statep = state;
1407-
}
1408-
14091416
/*
14101417
* Search to see if name exists, and get back a pointer to it.
14111418
*/
14121419
error = xfs_da3_node_lookup_int(state, &retval);
14131420
if (error)
1414-
retval = error;
1415-
1416-
if (!statep)
1417-
xfs_da_state_free(state);
1421+
return error;
14181422

14191423
return retval;
14201424
}
@@ -1430,15 +1434,12 @@ xfs_attr_node_addname_find_attr(
14301434
struct xfs_da_args *args = attr->xattri_da_args;
14311435
int error;
14321436

1433-
if (attr->xattri_da_state)
1434-
xfs_da_state_free(attr->xattri_da_state);
1435-
attr->xattri_da_state = NULL;
1436-
14371437
/*
14381438
* Search to see if name already exists, and get back a pointer
14391439
* to where it should go.
14401440
*/
1441-
error = xfs_attr_node_hasname(args, &attr->xattri_da_state);
1441+
xfs_attr_item_init_da_state(attr);
1442+
error = xfs_attr_node_lookup(args, attr->xattri_da_state);
14421443
switch (error) {
14431444
case -ENOATTR:
14441445
if (args->op_flags & XFS_DA_OP_REPLACE)
@@ -1599,7 +1600,7 @@ STATIC int
15991600
xfs_attr_node_get(
16001601
struct xfs_da_args *args)
16011602
{
1602-
struct xfs_da_state *state = NULL;
1603+
struct xfs_da_state *state;
16031604
struct xfs_da_state_blk *blk;
16041605
int i;
16051606
int error;
@@ -1609,7 +1610,8 @@ xfs_attr_node_get(
16091610
/*
16101611
* Search to see if name exists, and get back a pointer to it.
16111612
*/
1612-
error = xfs_attr_node_hasname(args, &state);
1613+
state = xfs_da_state_alloc(args);
1614+
error = xfs_attr_node_lookup(args, state);
16131615
if (error != -EEXIST)
16141616
goto out_release;
16151617

@@ -1628,8 +1630,7 @@ xfs_attr_node_get(
16281630
state->path.blk[i].bp = NULL;
16291631
}
16301632

1631-
if (state)
1632-
xfs_da_state_free(state);
1633+
xfs_da_state_free(state);
16331634
return error;
16341635
}
16351636

fs/xfs/libxfs/xfs_da_btree.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ xfs_da_state_free(xfs_da_state_t *state)
117117
kmem_cache_free(xfs_da_state_cache, state);
118118
}
119119

120+
void
121+
xfs_da_state_reset(
122+
struct xfs_da_state *state,
123+
struct xfs_da_args *args)
124+
{
125+
xfs_da_state_kill_altpath(state);
126+
memset(state, 0, sizeof(struct xfs_da_state));
127+
state->args = args;
128+
state->mp = state->args->dp->i_mount;
129+
}
130+
120131
static inline int xfs_dabuf_nfsb(struct xfs_mount *mp, int whichfork)
121132
{
122133
if (whichfork == XFS_DATA_FORK)

fs/xfs/libxfs/xfs_da_btree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ enum xfs_dacmp xfs_da_compname(struct xfs_da_args *args,
225225

226226
struct xfs_da_state *xfs_da_state_alloc(struct xfs_da_args *args);
227227
void xfs_da_state_free(xfs_da_state_t *state);
228+
void xfs_da_state_reset(struct xfs_da_state *state, struct xfs_da_args *args);
228229

229230
void xfs_da3_node_hdr_from_disk(struct xfs_mount *mp,
230231
struct xfs_da3_icnode_hdr *to, struct xfs_da_intnode *from);

0 commit comments

Comments
 (0)