From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: linux-efi@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>
Subject: [RFC PATCH 1/3] libfs: rework dcache_readdir to use an internal function with callback
Date: Tue, 18 Mar 2025 15:41:09 -0400 [thread overview]
Message-ID: <20250318194111.19419-2-James.Bottomley@HansenPartnership.com> (raw)
In-Reply-To: <20250318194111.19419-1-James.Bottomley@HansenPartnership.com>
No functional change. Preparatory to using the internal function to
iterate a directory with just a dentry not a file.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
fs/libfs.c | 41 +++++++++++++++++++++++++++++------------
1 file changed, 29 insertions(+), 12 deletions(-)
diff --git a/fs/libfs.c b/fs/libfs.c
index 8444f5cc4064..816bfe6c0430 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -189,28 +189,21 @@ EXPORT_SYMBOL(dcache_dir_lseek);
* for ramfs-type trees they can't go away without unlink() or rmdir(),
* both impossible due to the lock on directory.
*/
-
-int dcache_readdir(struct file *file, struct dir_context *ctx)
+static void internal_readdir(struct dentry *dentry, struct dentry *cursor,
+ void *data, bool start,
+ bool (*callback)(void *, struct dentry *))
{
- struct dentry *dentry = file->f_path.dentry;
- struct dentry *cursor = file->private_data;
struct dentry *next = NULL;
struct hlist_node **p;
- if (!dir_emit_dots(file, ctx))
- return 0;
-
- if (ctx->pos == 2)
+ if (start)
p = &dentry->d_children.first;
else
p = &cursor->d_sib.next;
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 (!callback(data, next))
break;
- ctx->pos++;
p = &next->d_sib.next;
}
spin_lock(&dentry->d_lock);
@@ -219,6 +212,30 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
hlist_add_before(&cursor->d_sib, &next->d_sib);
spin_unlock(&dentry->d_lock);
dput(next);
+}
+
+static bool dcache_readdir_callback(void *data, struct dentry *entry)
+{
+ struct dir_context *ctx = data;
+
+ if (!dir_emit(ctx, entry->d_name.name, entry->d_name.len,
+ d_inode(entry)->i_ino,
+ fs_umode_to_dtype(d_inode(entry)->i_mode)))
+ return false;
+ ctx->pos++;
+ return true;
+}
+
+int dcache_readdir(struct file *file, struct dir_context *ctx)
+{
+ struct dentry *dentry = file->f_path.dentry;
+ struct dentry *cursor = file->private_data;
+
+ if (!dir_emit_dots(file, ctx))
+ return 0;
+
+ internal_readdir(dentry, cursor, ctx, ctx->pos == 2,
+ dcache_readdir_callback);
return 0;
}
--
2.43.0
next prev parent reply other threads:[~2025-03-18 19:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 19:41 [RFC PATCH 0/3] create simple libfs directory iterator and make efivarfs use it James Bottomley
2025-03-18 19:41 ` James Bottomley [this message]
2025-03-18 21:32 ` [RFC PATCH 1/3] libfs: rework dcache_readdir to use an internal function with callback Ard Biesheuvel
2025-03-18 21:49 ` James Bottomley
2025-03-18 19:41 ` [RFC PATCH 2/3] libfs: add simple directory iteration " James Bottomley
2025-03-18 21:33 ` Ard Biesheuvel
2025-03-18 21:50 ` James Bottomley
2025-03-18 19:41 ` [RFC PATCH 3/3] efivarfs: replace iterate_dir with libfs function simple_iterate_call James Bottomley
2025-03-18 21:34 ` Ard Biesheuvel
2025-03-18 23:45 ` [RFC PATCH 0/3] create simple libfs directory iterator and make efivarfs use it Al Viro
2025-03-18 23:49 ` Al Viro
2025-03-19 16:46 ` James Bottomley
2025-03-19 18:45 ` James Bottomley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250318194111.19419-2-James.Bottomley@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=ardb@kernel.org \
--cc=brauner@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox