Skip to content

Commit 346c1d4

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: return bool from xfs_attr3_leaf_add
xfs_attr3_leaf_add only has two potential return values, indicating if the entry could be added or not. Replace the errno return with a bool so that ENOSPC from it can't easily be confused with a real ENOSPC. Remove the return value from the xfs_attr3_leaf_add_work helper entirely, as it always return 0. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent b1c649d commit 346c1d4

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,7 @@ xfs_attr_leaf_addname(
557557
* or perform more xattr manipulations. Otherwise there is nothing more
558558
* to do and we can return success.
559559
*/
560-
error = xfs_attr3_leaf_add(bp, args);
561-
if (error) {
562-
if (error != -ENOSPC)
563-
return error;
560+
if (!xfs_attr3_leaf_add(bp, args)) {
564561
error = xfs_attr3_leaf_to_node(args);
565562
if (error)
566563
return error;
@@ -574,7 +571,7 @@ xfs_attr_leaf_addname(
574571
}
575572

576573
trace_xfs_attr_leaf_addname_return(attr->xattri_dela_state, args->dp);
577-
return error;
574+
return 0;
578575

579576
out_brelse:
580577
xfs_trans_brelse(args->trans, bp);
@@ -1399,21 +1396,21 @@ xfs_attr_node_try_addname(
13991396
{
14001397
struct xfs_da_state *state = attr->xattri_da_state;
14011398
struct xfs_da_state_blk *blk;
1402-
int error;
1399+
int error = 0;
14031400

14041401
trace_xfs_attr_node_addname(state->args);
14051402

14061403
blk = &state->path.blk[state->path.active-1];
14071404
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
14081405

1409-
error = xfs_attr3_leaf_add(blk->bp, state->args);
1410-
if (error == -ENOSPC) {
1406+
if (!xfs_attr3_leaf_add(blk->bp, state->args)) {
14111407
if (state->path.active == 1) {
14121408
/*
14131409
* Its really a single leaf node, but it had
14141410
* out-of-line values so it looked like it *might*
14151411
* have been a b-tree. Let the caller deal with this.
14161412
*/
1413+
error = -ENOSPC;
14171414
goto out;
14181415
}
14191416

fs/xfs/libxfs/xfs_attr_leaf.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*/
4848
STATIC int xfs_attr3_leaf_create(struct xfs_da_args *args,
4949
xfs_dablk_t which_block, struct xfs_buf **bpp);
50-
STATIC int xfs_attr3_leaf_add_work(struct xfs_buf *leaf_buffer,
50+
STATIC void xfs_attr3_leaf_add_work(struct xfs_buf *leaf_buffer,
5151
struct xfs_attr3_icleaf_hdr *ichdr,
5252
struct xfs_da_args *args, int freemap_index);
5353
STATIC void xfs_attr3_leaf_compact(struct xfs_da_args *args,
@@ -995,10 +995,8 @@ xfs_attr_shortform_to_leaf(
995995
xfs_attr_sethash(&nargs);
996996
error = xfs_attr3_leaf_lookup_int(bp, &nargs); /* set a->index */
997997
ASSERT(error == -ENOATTR);
998-
error = xfs_attr3_leaf_add(bp, &nargs);
999-
ASSERT(error != -ENOSPC);
1000-
if (error)
1001-
goto out;
998+
if (!xfs_attr3_leaf_add(bp, &nargs))
999+
ASSERT(0);
10021000
sfe = xfs_attr_sf_nextentry(sfe);
10031001
}
10041002
error = 0;
@@ -1340,8 +1338,9 @@ xfs_attr3_leaf_split(
13401338
struct xfs_da_state_blk *oldblk,
13411339
struct xfs_da_state_blk *newblk)
13421340
{
1343-
xfs_dablk_t blkno;
1344-
int error;
1341+
bool added;
1342+
xfs_dablk_t blkno;
1343+
int error;
13451344

13461345
trace_xfs_attr_leaf_split(state->args);
13471346

@@ -1376,24 +1375,26 @@ xfs_attr3_leaf_split(
13761375
*/
13771376
if (state->inleaf) {
13781377
trace_xfs_attr_leaf_add_old(state->args);
1379-
error = xfs_attr3_leaf_add(oldblk->bp, state->args);
1378+
added = xfs_attr3_leaf_add(oldblk->bp, state->args);
13801379
} else {
13811380
trace_xfs_attr_leaf_add_new(state->args);
1382-
error = xfs_attr3_leaf_add(newblk->bp, state->args);
1381+
added = xfs_attr3_leaf_add(newblk->bp, state->args);
13831382
}
13841383

13851384
/*
13861385
* Update last hashval in each block since we added the name.
13871386
*/
13881387
oldblk->hashval = xfs_attr_leaf_lasthash(oldblk->bp, NULL);
13891388
newblk->hashval = xfs_attr_leaf_lasthash(newblk->bp, NULL);
1390-
return error;
1389+
if (!added)
1390+
return -ENOSPC;
1391+
return 0;
13911392
}
13921393

13931394
/*
13941395
* Add a name to the leaf attribute list structure.
13951396
*/
1396-
int
1397+
bool
13971398
xfs_attr3_leaf_add(
13981399
struct xfs_buf *bp,
13991400
struct xfs_da_args *args)
@@ -1402,6 +1403,7 @@ xfs_attr3_leaf_add(
14021403
struct xfs_attr3_icleaf_hdr ichdr;
14031404
int tablesize;
14041405
int entsize;
1406+
bool added = true;
14051407
int sum;
14061408
int tmp;
14071409
int i;
@@ -1430,7 +1432,7 @@ xfs_attr3_leaf_add(
14301432
if (ichdr.freemap[i].base < ichdr.firstused)
14311433
tmp += sizeof(xfs_attr_leaf_entry_t);
14321434
if (ichdr.freemap[i].size >= tmp) {
1433-
tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, i);
1435+
xfs_attr3_leaf_add_work(bp, &ichdr, args, i);
14341436
goto out_log_hdr;
14351437
}
14361438
sum += ichdr.freemap[i].size;
@@ -1442,7 +1444,7 @@ xfs_attr3_leaf_add(
14421444
* no good and we should just give up.
14431445
*/
14441446
if (!ichdr.holes && sum < entsize)
1445-
return -ENOSPC;
1447+
return false;
14461448

14471449
/*
14481450
* Compact the entries to coalesce free space.
@@ -1455,24 +1457,24 @@ xfs_attr3_leaf_add(
14551457
* free region, in freemap[0]. If it is not big enough, give up.
14561458
*/
14571459
if (ichdr.freemap[0].size < (entsize + sizeof(xfs_attr_leaf_entry_t))) {
1458-
tmp = -ENOSPC;
1460+
added = false;
14591461
goto out_log_hdr;
14601462
}
14611463

1462-
tmp = xfs_attr3_leaf_add_work(bp, &ichdr, args, 0);
1464+
xfs_attr3_leaf_add_work(bp, &ichdr, args, 0);
14631465

14641466
out_log_hdr:
14651467
xfs_attr3_leaf_hdr_to_disk(args->geo, leaf, &ichdr);
14661468
xfs_trans_log_buf(args->trans, bp,
14671469
XFS_DA_LOGRANGE(leaf, &leaf->hdr,
14681470
xfs_attr3_leaf_hdr_size(leaf)));
1469-
return tmp;
1471+
return added;
14701472
}
14711473

14721474
/*
14731475
* Add a name to a leaf attribute list structure.
14741476
*/
1475-
STATIC int
1477+
STATIC void
14761478
xfs_attr3_leaf_add_work(
14771479
struct xfs_buf *bp,
14781480
struct xfs_attr3_icleaf_hdr *ichdr,
@@ -1590,7 +1592,6 @@ xfs_attr3_leaf_add_work(
15901592
}
15911593
}
15921594
ichdr->usedbytes += xfs_attr_leaf_entsize(leaf, args->index);
1593-
return 0;
15941595
}
15951596

15961597
/*

fs/xfs/libxfs/xfs_attr_leaf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int xfs_attr3_leaf_split(struct xfs_da_state *state,
7676
int xfs_attr3_leaf_lookup_int(struct xfs_buf *leaf,
7777
struct xfs_da_args *args);
7878
int xfs_attr3_leaf_getvalue(struct xfs_buf *bp, struct xfs_da_args *args);
79-
int xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
79+
bool xfs_attr3_leaf_add(struct xfs_buf *leaf_buffer,
8080
struct xfs_da_args *args);
8181
int xfs_attr3_leaf_remove(struct xfs_buf *leaf_buffer,
8282
struct xfs_da_args *args);

0 commit comments

Comments
 (0)