Skip to content

Commit 42386fb

Browse files
tangyoulingKent Overstreet
authored andcommitted
bcachefs: Simplify bch2_xattr_emit() implementation
Use helper functions to make code more readable. Similar to commit a5488f2 ("fs: simplify ->listxattr() implementation") Signed-off-by: Youling Tang <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent d3f30f1 commit 42386fb

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

fs/bcachefs/xattr.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,27 @@ static int __bch2_xattr_emit(const char *prefix,
250250
return 0;
251251
}
252252

253+
static inline const char *bch2_xattr_prefix(unsigned type, struct dentry *dentry)
254+
{
255+
const struct xattr_handler *handler = bch2_xattr_type_to_handler(type);
256+
257+
if (!xattr_handler_can_list(handler, dentry))
258+
return NULL;
259+
260+
return xattr_prefix(handler);
261+
}
262+
253263
static int bch2_xattr_emit(struct dentry *dentry,
254264
const struct bch_xattr *xattr,
255265
struct xattr_buf *buf)
256266
{
257-
const struct xattr_handler *handler =
258-
bch2_xattr_type_to_handler(xattr->x_type);
267+
const char *prefix;
268+
269+
prefix = bch2_xattr_prefix(xattr->x_type, dentry);
270+
if (!prefix)
271+
return 0;
259272

260-
return handler && (!handler->list || handler->list(dentry))
261-
? __bch2_xattr_emit(handler->prefix ?: handler->name,
262-
xattr->x_name, xattr->x_name_len, buf)
263-
: 0;
273+
return __bch2_xattr_emit(prefix, xattr->x_name, xattr->x_name_len, buf);
264274
}
265275

266276
static int bch2_xattr_list_bcachefs(struct bch_fs *c,

0 commit comments

Comments
 (0)