[PATCH v2 16/25] fs: add inode operations to get/set/remove fscaps

Seth Forshee (DigitalOcean)
2024-02-21T21:25:07Z

Add inode operations for getting, setting and removing filesystem
capabilities rather than passing around raw xattr data. This provides
better type safety for ids contained within xattrs.

Signed-off-by: Seth Forshee (DigitalOcean) <sforshee@kernel.org>
---
Documentation/filesystems/locking.rst | 4 ++++
Documentation/filesystems/vfs.rst | 17 +++++++++++++++++
include/linux/fs.h | 4 ++++
3 files changed, 25 insertions(+)

diff --git a/Documentation/filesystems/locking.rst b/Documentation/filesystems/locking.rst
index d5bf4b6b7509..d208dd9f75ae 100644
--- a/Documentation/filesystems/locking.rst
+++ b/Documentation/filesystems/locking.rst
@@ -81,6 +81,8 @@ prototypes::
umode_t create_mode);
int (*tmpfile) (struct mnt_idmap *, struct inode *,
struct file *, umode_t);
+ int (*get_fscaps)(struct mnt_idmap *, struct dentry *, struct vfs_caps *);
+ int (*set_fscaps)(struct mnt_idmap *, struct dentry *, const struct vfs_caps *, int setxattr_flags);
int (*fileattr_set)(struct mnt_idmap *idmap,
struct dentry *dentry, struct fileattr *fa);
int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa);
@@ -114,6 +116,8 @@ fiemap: no
update_time: no
atomic_open: shared (exclusive if O_CREAT is set in open flags)
tmpfile: no
+get_fscaps: no
+set_fscaps: exclusive
fileattr_get: no or exclusive
fileattr_set: exclusive
get_offset_ctx no
diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst
index eebcc0f9e2bc..ed1cb03f271e 100644
--- a/Documentation/filesystems/vfs.rst
+++ b/Documentation/filesystems/vfs.rst
@@ -514,6 +514,8 @@ As of kernel 2.6.22, the following members are defined:
int (*tmpfile) (struct mnt_idmap *, struct inode *, struct file *, umode_t);
struct posix_acl * (*get_acl)(struct mnt_idmap *, struct dentry *, int);
int (*set_acl)(struct mnt_idmap *, struct dentry *, struct posix_acl *, int);
+ int (*get_fscaps)(struct mnt_idmap *, struct dentry *, struct vfs_caps *);
+ int (*set_fscaps)(struct mnt_idmap *, struct dentry *, const struct vfs_caps *, int setxattr_flags);
int (*fileattr_set)(struct mnt_idmap *idmap,
struct dentry *dentry, struct fileattr *fa);
int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa);
@@ -667,6 +669,21 @@ otherwise noted.
open; this can be done by calling finish_open_simple() right at
the end.

+``get_fscaps``
+
+ called to get filesystem capabilites of an inode. If unset,
+ xattr handlers will be used to get the raw xattr data. Most
+ filesystems can rely on the generic handler.
+
+``set_fscaps``
+
+ called to set filesystem capabilites of an inode. If unset,
+ xattr handlers will be used to set the raw xattr data. Most
+ filesystems can rely on the generic handler.
+
+ If the new fscaps value is NULL the filesystem must remove any
+ fscaps from the inode.
+
``fileattr_get``
called on ioctl(FS_IOC_GETFLAGS) and ioctl(FS_IOC_FSGETXATTR) to
retrieve miscellaneous file flags and attributes. Also called
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ed5966a70495..89163e0f7aad 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2067,6 +2067,10 @@ struct inode_operations {
int);
int (*set_acl)(struct mnt_idmap *, struct dentry *,
struct posix_acl *, int);
+ int (*get_fscaps)(struct mnt_idmap *, struct dentry *,
+ struct vfs_caps *);
+ int (*set_fscaps)(struct mnt_idmap *, struct dentry *,
+ const struct vfs_caps *, int setxattr_flags);
int (*fileattr_set)(struct mnt_idmap *idmap,
struct dentry *dentry, struct fileattr *fa);
int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa);

--
2.43.0