diff mbox series

[v2,4/5] shmem: Add a shmem-specific dir_emit helper

Message ID 168331196437.20728.1655558228044135552.stgit@oracle-102.nfsv4bat.org (mailing list archive)
State New
Headers show
Series shmemfs stable directory cookies | expand

Commit Message

Chuck Lever May 5, 2023, 6:39 p.m. UTC
From: Chuck Lever <chuck.lever@oracle.com>

Clean up to improve the readability of shmem_readdir().

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 mm/shmem.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/mm/shmem.c b/mm/shmem.c
index b78253996108..733b98ca8517 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3329,6 +3329,15 @@  static loff_t shmem_dir_llseek(struct file *file, loff_t offset, int whence)
 	return offset;
 }
 
+static bool shmem_dir_emit(struct dir_context *ctx, struct dentry *dentry)
+{
+	struct inode *inode = d_inode(dentry);
+
+	return ctx->actor(ctx, dentry->d_name.name, dentry->d_name.len,
+			  ctx->pos, inode->i_ino,
+			  fs_umode_to_dtype(inode->i_mode));
+}
+
 /**
  * shmem_readdir - Emit entries starting at offset @ctx->pos
  * @file: an open directory to iterate over
@@ -3369,9 +3378,7 @@  static int shmem_readdir(struct file *file, struct dir_context *ctx)
 		return 0;
 
 	while ((next = scan_positives(cursor, p, 1, next)) != NULL) {
-		if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
-			      d_inode(next)->i_ino,
-			      fs_umode_to_dtype(d_inode(next)->i_mode)))
+		if (!shmem_dir_emit(ctx, dentry))
 			break;
 		ctx->pos++;
 		p = &next->d_child;