Skip to content

Commit

Permalink
xfs: rearrange the logic and remove the broken comment for xfs_dir2_isxx
Browse files Browse the repository at this point in the history
xfs_dir2_isleaf is used to see if the directory is a single-leaf
form directory instead, as commented right above the function.

Besides getting rid of the broken comment, we rearrange the logic by
converting everything over to standard formatting and conventions,
at the same time, to make it easier to understand and self documenting.

Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Dave Chinner <david@fromorbit.com>
  • Loading branch information
Shida Zhang authored and Dave Chinner committed Oct 4, 2022
1 parent 4415965 commit c098576
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
50 changes: 30 additions & 20 deletions fs/xfs/libxfs/xfs_dir2.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ xfs_dir_createname(
{
struct xfs_da_args *args;
int rval;
int v; /* type-checking value */
bool v;

ASSERT(S_ISDIR(VFS_I(dp)->i_mode));

Expand Down Expand Up @@ -357,7 +357,7 @@ xfs_dir_lookup(
{
struct xfs_da_args *args;
int rval;
int v; /* type-checking value */
bool v;
int lock_mode;

ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
Expand Down Expand Up @@ -435,7 +435,7 @@ xfs_dir_removename(
{
struct xfs_da_args *args;
int rval;
int v; /* type-checking value */
bool v;

ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
XFS_STATS_INC(dp->i_mount, xs_dir_remove);
Expand Down Expand Up @@ -493,7 +493,7 @@ xfs_dir_replace(
{
struct xfs_da_args *args;
int rval;
int v; /* type-checking value */
bool v;

ASSERT(S_ISDIR(VFS_I(dp)->i_mode));

Expand Down Expand Up @@ -610,19 +610,23 @@ xfs_dir2_grow_inode(
int
xfs_dir2_isblock(
struct xfs_da_args *args,
int *vp) /* out: 1 is block, 0 is not block */
bool *isblock)
{
xfs_fileoff_t last; /* last file offset */
int rval;
struct xfs_mount *mp = args->dp->i_mount;
xfs_fileoff_t eof;
int error;

if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK)))
return rval;
rval = XFS_FSB_TO_B(args->dp->i_mount, last) == args->geo->blksize;
if (XFS_IS_CORRUPT(args->dp->i_mount,
rval != 0 &&
args->dp->i_disk_size != args->geo->blksize))
error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK);
if (error)
return error;

*isblock = false;
if (XFS_FSB_TO_B(mp, eof) != args->geo->blksize)
return 0;

*isblock = true;
if (XFS_IS_CORRUPT(mp, args->dp->i_disk_size != args->geo->blksize))
return -EFSCORRUPTED;
*vp = rval;
return 0;
}

Expand All @@ -632,14 +636,20 @@ xfs_dir2_isblock(
int
xfs_dir2_isleaf(
struct xfs_da_args *args,
int *vp) /* out: 1 is block, 0 is not block */
bool *isleaf)
{
xfs_fileoff_t last; /* last file offset */
int rval;
xfs_fileoff_t eof;
int error;

if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK)))
return rval;
*vp = last == args->geo->leafblk + args->geo->fsbcount;
error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK);
if (error)
return error;

*isleaf = false;
if (eof != args->geo->leafblk + args->geo->fsbcount)
return 0;

*isleaf = true;
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions fs/xfs/libxfs/xfs_dir2.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ extern int xfs_dir2_sf_to_block(struct xfs_da_args *args);
/*
* Interface routines used by userspace utilities
*/
extern int xfs_dir2_isblock(struct xfs_da_args *args, int *r);
extern int xfs_dir2_isleaf(struct xfs_da_args *args, int *r);
extern int xfs_dir2_isblock(struct xfs_da_args *args, bool *isblock);
extern int xfs_dir2_isleaf(struct xfs_da_args *args, bool *isleaf);
extern int xfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db,
struct xfs_buf *bp);

Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/scrub/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ xchk_directory_blocks(
xfs_dablk_t dabno;
xfs_dir2_db_t last_data_db = 0;
bool found;
int is_block = 0;
bool is_block = false;
int error;

/* Ignore local format directories. */
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/xfs_dir2_readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ xfs_readdir(
{
struct xfs_da_args args = { NULL };
unsigned int lock_mode;
int isblock;
bool isblock;
int error;

trace_xfs_readdir(dp);
Expand Down

0 comments on commit c098576

Please sign in to comment.