Skip to content

Commit 3f6e011

Browse files
allisonhendersondjwong
authored andcommitted
xfs: Add helper function xfs_attr_node_shrink
This patch adds a new helper function xfs_attr_node_shrink used to shrink an attr name into an inode if it is small enough. This helps to modularize the greater calling function xfs_attr_node_removename. Signed-off-by: Allison Collins <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Reviewed-by: Brian Foster <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Acked-by: Dave Chinner <[email protected]>
1 parent d4034c4 commit 3f6e011

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,45 @@ xfs_attr_node_addname(
11021102
return retval;
11031103
}
11041104

1105+
/*
1106+
* Shrink an attribute from leaf to shortform
1107+
*/
1108+
STATIC int
1109+
xfs_attr_node_shrink(
1110+
struct xfs_da_args *args,
1111+
struct xfs_da_state *state)
1112+
{
1113+
struct xfs_inode *dp = args->dp;
1114+
int error, forkoff;
1115+
struct xfs_buf *bp;
1116+
1117+
/*
1118+
* Have to get rid of the copy of this dabuf in the state.
1119+
*/
1120+
ASSERT(state->path.active == 1);
1121+
ASSERT(state->path.blk[0].bp);
1122+
state->path.blk[0].bp = NULL;
1123+
1124+
error = xfs_attr3_leaf_read(args->trans, args->dp, 0, &bp);
1125+
if (error)
1126+
return error;
1127+
1128+
forkoff = xfs_attr_shortform_allfit(bp, dp);
1129+
if (forkoff) {
1130+
error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
1131+
/* bp is gone due to xfs_da_shrink_inode */
1132+
if (error)
1133+
return error;
1134+
1135+
error = xfs_defer_finish(&args->trans);
1136+
if (error)
1137+
return error;
1138+
} else
1139+
xfs_trans_brelse(args->trans, bp);
1140+
1141+
return 0;
1142+
}
1143+
11051144
/*
11061145
* Remove a name from a B-tree attribute list.
11071146
*
@@ -1115,8 +1154,7 @@ xfs_attr_node_removename(
11151154
{
11161155
struct xfs_da_state *state;
11171156
struct xfs_da_state_blk *blk;
1118-
struct xfs_buf *bp;
1119-
int retval, error, forkoff;
1157+
int retval, error;
11201158
struct xfs_inode *dp = args->dp;
11211159

11221160
trace_xfs_attr_node_removename(args);
@@ -1201,30 +1239,8 @@ xfs_attr_node_removename(
12011239
/*
12021240
* If the result is small enough, push it all into the inode.
12031241
*/
1204-
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
1205-
/*
1206-
* Have to get rid of the copy of this dabuf in the state.
1207-
*/
1208-
ASSERT(state->path.active == 1);
1209-
ASSERT(state->path.blk[0].bp);
1210-
state->path.blk[0].bp = NULL;
1211-
1212-
error = xfs_attr3_leaf_read(args->trans, args->dp, 0, &bp);
1213-
if (error)
1214-
goto out;
1215-
1216-
if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) {
1217-
error = xfs_attr3_leaf_to_shortform(bp, args, forkoff);
1218-
/* bp is gone due to xfs_da_shrink_inode */
1219-
if (error)
1220-
goto out;
1221-
error = xfs_defer_finish(&args->trans);
1222-
if (error)
1223-
goto out;
1224-
} else
1225-
xfs_trans_brelse(args->trans, bp);
1226-
}
1227-
error = 0;
1242+
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
1243+
error = xfs_attr_node_shrink(args, state);
12281244

12291245
out:
12301246
if (state)

0 commit comments

Comments
 (0)