Skip to content

Commit bf4a5cf

Browse files
allisonhendersondjwong
authored andcommitted
xfs: Simplify xfs_attr_node_addname
Invert the rename logic in xfs_attr_node_addname to simplify the delayed attr logic later. Signed-off-by: Allison Collins <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]> Acked-by: Dave Chinner <[email protected]>
1 parent 5fdca0a commit bf4a5cf

File tree

1 file changed

+59
-63
lines changed

1 file changed

+59
-63
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,79 +1025,75 @@ xfs_attr_node_addname(
10251025
return error;
10261026
}
10271027

1028-
/*
1029-
* If this is an atomic rename operation, we must "flip" the
1030-
* incomplete flags on the "new" and "old" attribute/value pairs
1031-
* so that one disappears and one appears atomically. Then we
1032-
* must remove the "old" attribute/value pair.
1033-
*/
1034-
if (args->op_flags & XFS_DA_OP_RENAME) {
1035-
/*
1036-
* In a separate transaction, set the incomplete flag on the
1037-
* "old" attr and clear the incomplete flag on the "new" attr.
1038-
*/
1039-
error = xfs_attr3_leaf_flipflags(args);
1040-
if (error)
1041-
goto out;
1042-
/*
1043-
* Commit the flag value change and start the next trans in
1044-
* series
1045-
*/
1046-
error = xfs_trans_roll_inode(&args->trans, args->dp);
1047-
if (error)
1048-
goto out;
1049-
1028+
if (!(args->op_flags & XFS_DA_OP_RENAME)) {
10501029
/*
1051-
* Dismantle the "old" attribute/value pair by removing
1052-
* a "remote" value (if it exists).
1030+
* Added a "remote" value, just clear the incomplete flag.
10531031
*/
1054-
xfs_attr_restore_rmt_blk(args);
1032+
if (args->rmtblkno > 0)
1033+
error = xfs_attr3_leaf_clearflag(args);
1034+
retval = error;
1035+
goto out;
1036+
}
10551037

1056-
if (args->rmtblkno) {
1057-
error = xfs_attr_rmtval_invalidate(args);
1058-
if (error)
1059-
return error;
1038+
/*
1039+
* If this is an atomic rename operation, we must "flip" the incomplete
1040+
* flags on the "new" and "old" attribute/value pairs so that one
1041+
* disappears and one appears atomically. Then we must remove the "old"
1042+
* attribute/value pair.
1043+
*
1044+
* In a separate transaction, set the incomplete flag on the "old" attr
1045+
* and clear the incomplete flag on the "new" attr.
1046+
*/
1047+
error = xfs_attr3_leaf_flipflags(args);
1048+
if (error)
1049+
goto out;
1050+
/*
1051+
* Commit the flag value change and start the next trans in series
1052+
*/
1053+
error = xfs_trans_roll_inode(&args->trans, args->dp);
1054+
if (error)
1055+
goto out;
10601056

1061-
error = xfs_attr_rmtval_remove(args);
1062-
if (error)
1063-
return error;
1064-
}
1057+
/*
1058+
* Dismantle the "old" attribute/value pair by removing a "remote" value
1059+
* (if it exists).
1060+
*/
1061+
xfs_attr_restore_rmt_blk(args);
10651062

1066-
/*
1067-
* Re-find the "old" attribute entry after any split ops.
1068-
* The INCOMPLETE flag means that we will find the "old"
1069-
* attr, not the "new" one.
1070-
*/
1071-
args->attr_filter |= XFS_ATTR_INCOMPLETE;
1072-
state = xfs_da_state_alloc(args);
1063+
if (args->rmtblkno) {
1064+
error = xfs_attr_rmtval_invalidate(args);
1065+
if (error)
1066+
return error;
10731067

1074-
state->inleaf = 0;
1075-
error = xfs_da3_node_lookup_int(state, &retval);
1068+
error = xfs_attr_rmtval_remove(args);
10761069
if (error)
1077-
goto out;
1070+
return error;
1071+
}
10781072

1079-
/*
1080-
* Remove the name and update the hashvals in the tree.
1081-
*/
1082-
blk = &state->path.blk[ state->path.active-1 ];
1083-
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1084-
error = xfs_attr3_leaf_remove(blk->bp, args);
1085-
xfs_da3_fixhashpath(state, &state->path);
1073+
/*
1074+
* Re-find the "old" attribute entry after any split ops. The INCOMPLETE
1075+
* flag means that we will find the "old" attr, not the "new" one.
1076+
*/
1077+
args->attr_filter |= XFS_ATTR_INCOMPLETE;
1078+
state = xfs_da_state_alloc(args);
1079+
state->inleaf = 0;
1080+
error = xfs_da3_node_lookup_int(state, &retval);
1081+
if (error)
1082+
goto out;
10861083

1087-
/*
1088-
* Check to see if the tree needs to be collapsed.
1089-
*/
1090-
if (retval && (state->path.active > 1)) {
1091-
error = xfs_da3_join(state);
1092-
if (error)
1093-
goto out;
1094-
}
1084+
/*
1085+
* Remove the name and update the hashvals in the tree.
1086+
*/
1087+
blk = &state->path.blk[state->path.active-1];
1088+
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1089+
error = xfs_attr3_leaf_remove(blk->bp, args);
1090+
xfs_da3_fixhashpath(state, &state->path);
10951091

1096-
} else if (args->rmtblkno > 0) {
1097-
/*
1098-
* Added a "remote" value, just clear the incomplete flag.
1099-
*/
1100-
error = xfs_attr3_leaf_clearflag(args);
1092+
/*
1093+
* Check to see if the tree needs to be collapsed.
1094+
*/
1095+
if (retval && (state->path.active > 1)) {
1096+
error = xfs_da3_join(state);
11011097
if (error)
11021098
goto out;
11031099
}

0 commit comments

Comments
 (0)