diff mbox series

[02/12] xattr, posix acl: add listxattr helpers

Message ID 20230125-fs-acl-remove-generic-xattr-handlers-v1-2-6cf155b492b6@kernel.org (mailing list archive)
State New, archived
Headers show
Series acl: remove remaining posix acl handlers | expand

Commit Message

Christian Brauner Jan. 25, 2023, 11:28 a.m. UTC
Add two tiny helpers to determine whether a given dentry supports
listing the requested xattr or posix acl. We will use this helper in
various filesystems in later commits.

Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
---
 include/linux/posix_acl_xattr.h | 5 +++++
 include/linux/xattr.h           | 6 ++++++
 2 files changed, 11 insertions(+)

Comments

Christoph Hellwig Jan. 30, 2023, 6:37 a.m. UTC | #1
On Wed, Jan 25, 2023 at 12:28:47PM +0100, Christian Brauner wrote:
> +static inline bool posix_acl_dentry_list(struct dentry *dentry)
> +{
> +	return IS_POSIXACL(d_backing_inode(dentry));
> +}

I find the open coded IS_POSIXACL much easier to read then this.
But if you want this helpers please add a comment on why it exists
and should be used.

> +static inline bool xattr_dentry_list(const struct xattr_handler *handler,
> +				     struct dentry *dentry)
> +{
> +	return handler && (!handler->list || handler->list(dentry));
> +}

This one could also benefit from a comment explaining what it does.
Also the name seems wrong, should be be something like
xattr_handler_can_list?
diff mbox series

Patch

diff --git a/include/linux/posix_acl_xattr.h b/include/linux/posix_acl_xattr.h
index 54cd7a14330d..905d532ccd6e 100644
--- a/include/linux/posix_acl_xattr.h
+++ b/include/linux/posix_acl_xattr.h
@@ -68,6 +68,11 @@  static inline int posix_acl_type(const char *name)
 	return -1;
 }
 
+static inline bool posix_acl_dentry_list(struct dentry *dentry)
+{
+	return IS_POSIXACL(d_backing_inode(dentry));
+}
+
 extern const struct xattr_handler posix_acl_access_xattr_handler;
 extern const struct xattr_handler posix_acl_default_xattr_handler;
 
diff --git a/include/linux/xattr.h b/include/linux/xattr.h
index 2e7dd44926e4..d1150b7ba8d0 100644
--- a/include/linux/xattr.h
+++ b/include/linux/xattr.h
@@ -47,6 +47,12 @@  struct xattr_handler {
 		   size_t size, int flags);
 };
 
+static inline bool xattr_dentry_list(const struct xattr_handler *handler,
+				     struct dentry *dentry)
+{
+	return handler && (!handler->list || handler->list(dentry));
+}
+
 const char *xattr_full_name(const struct xattr_handler *, const char *);
 
 struct xattr {