Skip to content

Commit 14ee22f

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: factor out a xfs_dir_lookup_args helper
Add a helper to switch between the different directory formats for lookup and to handle the -EEXIST return for a successful lookup. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 08e012a commit 14ee22f

File tree

3 files changed

+43
-60
lines changed

3 files changed

+43
-60
lines changed

fs/xfs/libxfs/xfs_dir2.c

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,45 @@ xfs_dir_cilookup_result(
352352
return -EEXIST;
353353
}
354354

355+
int
356+
xfs_dir_lookup_args(
357+
struct xfs_da_args *args)
358+
{
359+
bool is_block, is_leaf;
360+
int error;
361+
362+
if (args->dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
363+
error = xfs_dir2_sf_lookup(args);
364+
goto out;
365+
}
366+
367+
/* dir2 functions require that the data fork is loaded */
368+
error = xfs_iread_extents(args->trans, args->dp, XFS_DATA_FORK);
369+
if (error)
370+
goto out;
371+
372+
error = xfs_dir2_isblock(args, &is_block);
373+
if (error)
374+
goto out;
375+
376+
if (is_block) {
377+
error = xfs_dir2_block_lookup(args);
378+
goto out;
379+
}
380+
381+
error = xfs_dir2_isleaf(args, &is_leaf);
382+
if (error)
383+
goto out;
384+
if (is_leaf)
385+
error = xfs_dir2_leaf_lookup(args);
386+
else
387+
error = xfs_dir2_node_lookup(args);
388+
out:
389+
if (error != -EEXIST)
390+
return error;
391+
return 0;
392+
}
393+
355394
/*
356395
* Lookup a name in a directory, give back the inode number.
357396
* If ci_name is not NULL, returns the actual name in ci_name if it differs
@@ -368,7 +407,6 @@ xfs_dir_lookup(
368407
{
369408
struct xfs_da_args *args;
370409
int rval;
371-
bool v;
372410
int lock_mode;
373411

374412
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
@@ -390,38 +428,14 @@ xfs_dir_lookup(
390428
args->op_flags |= XFS_DA_OP_CILOOKUP;
391429

392430
lock_mode = xfs_ilock_data_map_shared(dp);
393-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
394-
rval = xfs_dir2_sf_lookup(args);
395-
goto out_check_rval;
396-
}
397-
398-
rval = xfs_dir2_isblock(args, &v);
399-
if (rval)
400-
goto out_free;
401-
if (v) {
402-
rval = xfs_dir2_block_lookup(args);
403-
goto out_check_rval;
404-
}
405-
406-
rval = xfs_dir2_isleaf(args, &v);
407-
if (rval)
408-
goto out_free;
409-
if (v)
410-
rval = xfs_dir2_leaf_lookup(args);
411-
else
412-
rval = xfs_dir2_node_lookup(args);
413-
414-
out_check_rval:
415-
if (rval == -EEXIST)
416-
rval = 0;
431+
rval = xfs_dir_lookup_args(args);
417432
if (!rval) {
418433
*inum = args->inumber;
419434
if (ci_name) {
420435
ci_name->name = args->value;
421436
ci_name->len = args->valuelen;
422437
}
423438
}
424-
out_free:
425439
xfs_iunlock(dp, lock_mode);
426440
kfree(args);
427441
return rval;

fs/xfs/libxfs/xfs_dir2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp,
6666
extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp,
6767
struct xfs_name *name);
6868

69+
int xfs_dir_lookup_args(struct xfs_da_args *args);
70+
6971
/*
7072
* Direct call from the bmap code, bypassing the generic directory layer.
7173
*/

fs/xfs/scrub/readdir.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ xchk_dir_lookup(
328328
.op_flags = XFS_DA_OP_OKNOENT,
329329
.owner = dp->i_ino,
330330
};
331-
bool isblock, isleaf;
332331
int error;
333332

334333
if (xfs_is_shutdown(dp->i_mount))
@@ -344,39 +343,7 @@ xchk_dir_lookup(
344343
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
345344
xfs_assert_ilocked(dp, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL);
346345

347-
if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) {
348-
error = xfs_dir2_sf_lookup(&args);
349-
goto out_check_rval;
350-
}
351-
352-
/* dir2 functions require that the data fork is loaded */
353-
error = xfs_iread_extents(sc->tp, dp, XFS_DATA_FORK);
354-
if (error)
355-
return error;
356-
357-
error = xfs_dir2_isblock(&args, &isblock);
358-
if (error)
359-
return error;
360-
361-
if (isblock) {
362-
error = xfs_dir2_block_lookup(&args);
363-
goto out_check_rval;
364-
}
365-
366-
error = xfs_dir2_isleaf(&args, &isleaf);
367-
if (error)
368-
return error;
369-
370-
if (isleaf) {
371-
error = xfs_dir2_leaf_lookup(&args);
372-
goto out_check_rval;
373-
}
374-
375-
error = xfs_dir2_node_lookup(&args);
376-
377-
out_check_rval:
378-
if (error == -EEXIST)
379-
error = 0;
346+
error = xfs_dir_lookup_args(&args);
380347
if (!error)
381348
*ino = args.inumber;
382349
return error;

0 commit comments

Comments
 (0)