Skip to content

Commit 2ac131d

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: rename and simplify xfs_bmap_one_block
xfs_bmap_one_block is only called for the attribute fork. Move it to xfs_attr.c, drop the unused whichfork argument and code only executed for the data fork and rename the result to xfs_attr_is_leaf. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Brian Foster <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 862a804 commit 2ac131d

File tree

5 files changed

+27
-39
lines changed

5 files changed

+27
-39
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ xfs_inode_hasattr(
7070
return 1;
7171
}
7272

73+
/*
74+
* Returns true if the there is exactly only block in the attr fork, in which
75+
* case the attribute fork consists of a single leaf block entry.
76+
*/
77+
bool
78+
xfs_attr_is_leaf(
79+
struct xfs_inode *ip)
80+
{
81+
struct xfs_ifork *ifp = ip->i_afp;
82+
struct xfs_iext_cursor icur;
83+
struct xfs_bmbt_irec imap;
84+
85+
if (ifp->if_nextents != 1 || ifp->if_format != XFS_DINODE_FMT_EXTENTS)
86+
return false;
87+
88+
xfs_iext_first(ifp, &icur);
89+
xfs_iext_get_extent(ifp, &icur, &imap);
90+
return imap.br_startoff == 0 && imap.br_blockcount == 1;
91+
}
92+
7393
/*========================================================================
7494
* Overall external interface routines.
7595
*========================================================================*/
@@ -89,7 +109,7 @@ xfs_attr_get_ilocked(
89109

90110
if (args->dp->i_afp->if_format == XFS_DINODE_FMT_LOCAL)
91111
return xfs_attr_shortform_getvalue(args);
92-
if (xfs_bmap_one_block(args->dp, XFS_ATTR_FORK))
112+
if (xfs_attr_is_leaf(args->dp))
93113
return xfs_attr_leaf_get(args);
94114
return xfs_attr_node_get(args);
95115
}
@@ -293,7 +313,7 @@ xfs_attr_set_args(
293313
return error;
294314
}
295315

296-
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
316+
if (xfs_attr_is_leaf(dp)) {
297317
error = xfs_attr_leaf_addname(args);
298318
if (error != -ENOSPC)
299319
return error;
@@ -347,7 +367,7 @@ xfs_has_attr(
347367
return xfs_attr_sf_findname(args, NULL, NULL);
348368
}
349369

350-
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
370+
if (xfs_attr_is_leaf(dp)) {
351371
error = xfs_attr_leaf_hasname(args, &bp);
352372

353373
if (bp)
@@ -374,7 +394,7 @@ xfs_attr_remove_args(
374394
} else if (dp->i_afp->if_format == XFS_DINODE_FMT_LOCAL) {
375395
ASSERT(dp->i_afp->if_flags & XFS_IFINLINE);
376396
error = xfs_attr_shortform_remove(args);
377-
} else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
397+
} else if (xfs_attr_is_leaf(dp)) {
378398
error = xfs_attr_leaf_removename(args);
379399
} else {
380400
error = xfs_attr_node_removename(args);
@@ -1283,7 +1303,7 @@ xfs_attr_node_removename(
12831303
/*
12841304
* If the result is small enough, push it all into the inode.
12851305
*/
1286-
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
1306+
if (xfs_attr_is_leaf(dp))
12871307
error = xfs_attr_node_shrink(args, state);
12881308

12891309
out:

fs/xfs/libxfs/xfs_attr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ int xfs_attr_inactive(struct xfs_inode *dp);
8585
int xfs_attr_list_ilocked(struct xfs_attr_list_context *);
8686
int xfs_attr_list(struct xfs_attr_list_context *);
8787
int xfs_inode_hasattr(struct xfs_inode *ip);
88+
bool xfs_attr_is_leaf(struct xfs_inode *ip);
8889
int xfs_attr_get_ilocked(struct xfs_da_args *args);
8990
int xfs_attr_get(struct xfs_da_args *args);
9091
int xfs_attr_set(struct xfs_da_args *args);

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,38 +1441,6 @@ xfs_bmap_last_offset(
14411441
return 0;
14421442
}
14431443

1444-
/*
1445-
* Returns whether the selected fork of the inode has exactly one
1446-
* block or not. For the data fork we check this matches i_disk_size,
1447-
* implying the file's range is 0..bsize-1.
1448-
*/
1449-
int /* 1=>1 block, 0=>otherwise */
1450-
xfs_bmap_one_block(
1451-
struct xfs_inode *ip, /* incore inode */
1452-
int whichfork) /* data or attr fork */
1453-
{
1454-
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
1455-
int rval; /* return value */
1456-
struct xfs_bmbt_irec s; /* internal version of extent */
1457-
struct xfs_iext_cursor icur;
1458-
1459-
#ifndef DEBUG
1460-
if (whichfork == XFS_DATA_FORK)
1461-
return XFS_ISIZE(ip) == ip->i_mount->m_sb.sb_blocksize;
1462-
#endif /* !DEBUG */
1463-
if (ifp->if_nextents != 1)
1464-
return 0;
1465-
if (ifp->if_format != XFS_DINODE_FMT_EXTENTS)
1466-
return 0;
1467-
ASSERT(ifp->if_flags & XFS_IFEXTENTS);
1468-
xfs_iext_first(ifp, &icur);
1469-
xfs_iext_get_extent(ifp, &icur, &s);
1470-
rval = s.br_startoff == 0 && s.br_blockcount == 1;
1471-
if (rval && whichfork == XFS_DATA_FORK)
1472-
ASSERT(XFS_ISIZE(ip) == ip->i_mount->m_sb.sb_blocksize);
1473-
return rval;
1474-
}
1475-
14761444
/*
14771445
* Extent tree manipulation functions used during allocation.
14781446
*/

fs/xfs/libxfs/xfs_bmap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ int xfs_bmap_last_before(struct xfs_trans *tp, struct xfs_inode *ip,
200200
xfs_fileoff_t *last_block, int whichfork);
201201
int xfs_bmap_last_offset(struct xfs_inode *ip, xfs_fileoff_t *unused,
202202
int whichfork);
203-
int xfs_bmap_one_block(struct xfs_inode *ip, int whichfork);
204203
int xfs_bmapi_read(struct xfs_inode *ip, xfs_fileoff_t bno,
205204
xfs_filblks_t len, struct xfs_bmbt_irec *mval,
206205
int *nmap, int flags);

fs/xfs/xfs_attr_list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ xfs_attr_list_ilocked(
514514
return 0;
515515
if (dp->i_afp->if_format == XFS_DINODE_FMT_LOCAL)
516516
return xfs_attr_shortform_list(context);
517-
if (xfs_bmap_one_block(dp, XFS_ATTR_FORK))
517+
if (xfs_attr_is_leaf(dp))
518518
return xfs_attr_leaf_list(context);
519519
return xfs_attr_node_list(context);
520520
}

0 commit comments

Comments
 (0)