diff options
author | Youling Tang <tangyouling@kylinos.cn> | 2024-08-15 16:57:44 +0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-09-09 09:41:49 -0400 |
commit | 42386fbaee1dd41f2c1ad41301a43454e808322c (patch) | |
tree | 7f8bf97da708d71e8efb35617e7cede570167c9b /fs/bcachefs/xattr.c | |
parent | d3f30f16294cc8e58ef14f934874ed7b3ec15b71 (diff) | |
download | lwn-42386fbaee1dd41f2c1ad41301a43454e808322c.tar.gz lwn-42386fbaee1dd41f2c1ad41301a43454e808322c.zip |
bcachefs: Simplify bch2_xattr_emit() implementation
Use helper functions to make code more readable.
Similar to commit a5488f29835c ("fs: simplify ->listxattr() implementation")
Signed-off-by: Youling Tang <tangyouling@kylinos.cn>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/xattr.c')
-rw-r--r-- | fs/bcachefs/xattr.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/fs/bcachefs/xattr.c b/fs/bcachefs/xattr.c index 7b3d9fdae244..56c8d3fe55a4 100644 --- a/fs/bcachefs/xattr.c +++ b/fs/bcachefs/xattr.c @@ -250,17 +250,27 @@ static int __bch2_xattr_emit(const char *prefix, return 0; } +static inline const char *bch2_xattr_prefix(unsigned type, struct dentry *dentry) +{ + const struct xattr_handler *handler = bch2_xattr_type_to_handler(type); + + if (!xattr_handler_can_list(handler, dentry)) + return NULL; + + return xattr_prefix(handler); +} + static int bch2_xattr_emit(struct dentry *dentry, const struct bch_xattr *xattr, struct xattr_buf *buf) { - const struct xattr_handler *handler = - bch2_xattr_type_to_handler(xattr->x_type); + const char *prefix; + + prefix = bch2_xattr_prefix(xattr->x_type, dentry); + if (!prefix) + return 0; - return handler && (!handler->list || handler->list(dentry)) - ? __bch2_xattr_emit(handler->prefix ?: handler->name, - xattr->x_name, xattr->x_name_len, buf) - : 0; + return __bch2_xattr_emit(prefix, xattr->x_name, xattr->x_name_len, buf); } static int bch2_xattr_list_bcachefs(struct bch_fs *c, |