diff options
author | Christian Brauner <brauner@kernel.org> | 2023-02-01 16:14:56 +0300 |
---|---|---|
committer | Christian Brauner (Microsoft) <brauner@kernel.org> | 2023-03-06 11:57:12 +0300 |
commit | a5488f29835c0eb5561b46e71c23f6c39aab6c83 (patch) | |
tree | 72f17e309903875f8296d483d535126d505d1ec5 /fs/erofs | |
parent | 0c95c025a02e477b2d112350e1c78bb0cc994c51 (diff) | |
download | linux-a5488f29835c0eb5561b46e71c23f6c39aab6c83.tar.xz |
fs: simplify ->listxattr() implementation
The ext{2,4}, erofs, f2fs, and jffs2 filesystems use the same logic to
check whether a given xattr can be listed. Simplify them and avoid
open-coding the same check by calling the helper we introduced earlier.
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: linux-f2fs-devel@lists.sourceforge.net
Cc: linux-erofs@lists.ozlabs.org
Cc: linux-ext4@vger.kernel.org
Cc: linux-mtd@lists.infradead.org
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Diffstat (limited to 'fs/erofs')
-rw-r--r-- | fs/erofs/xattr.c | 8 | ||||
-rw-r--r-- | fs/erofs/xattr.h | 14 |
2 files changed, 13 insertions, 9 deletions
diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 3de058f17428..015462763bdd 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -486,13 +486,9 @@ static int xattr_entrylist(struct xattr_iter *_it, unsigned int prefix_len; const char *prefix; - const struct xattr_handler *h = - erofs_xattr_handler(entry->e_name_index); - - if (!h || (h->list && !h->list(it->dentry))) + prefix = erofs_xattr_prefix(entry->e_name_index, it->dentry); + if (!prefix) return 1; - - prefix = xattr_prefix(h); prefix_len = strlen(prefix); if (!it->buffer) { diff --git a/fs/erofs/xattr.h b/fs/erofs/xattr.h index 0a43c9ee9f8f..08658e414c33 100644 --- a/fs/erofs/xattr.h +++ b/fs/erofs/xattr.h @@ -41,8 +41,11 @@ extern const struct xattr_handler erofs_xattr_user_handler; extern const struct xattr_handler erofs_xattr_trusted_handler; extern const struct xattr_handler erofs_xattr_security_handler; -static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) +static inline const char *erofs_xattr_prefix(unsigned int idx, + struct dentry *dentry) { + const struct xattr_handler *handler = NULL; + static const struct xattr_handler *xattr_handler_map[] = { [EROFS_XATTR_INDEX_USER] = &erofs_xattr_user_handler, #ifdef CONFIG_EROFS_FS_POSIX_ACL @@ -57,8 +60,13 @@ static inline const struct xattr_handler *erofs_xattr_handler(unsigned int idx) #endif }; - return idx && idx < ARRAY_SIZE(xattr_handler_map) ? - xattr_handler_map[idx] : NULL; + if (idx && idx < ARRAY_SIZE(xattr_handler_map)) + handler = xattr_handler_map[idx]; + + if (!xattr_handler_can_list(handler, dentry)) + return NULL; + + return xattr_prefix(handler); } extern const struct xattr_handler *erofs_xattr_handlers[]; |