From: Amir Goldstein <amir73il@gmail.com>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: "Pali Rohár" <pali@kernel.org>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>,
linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH 2/2] fs: add support for custom fsx_xflags_mask
Date: Sat, 29 Mar 2025 15:33:12 +0100 [thread overview]
Message-ID: <20250329143312.1350603-3-amir73il@gmail.com> (raw)
In-Reply-To: <20250329143312.1350603-1-amir73il@gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=true, Size: 4740 bytes --]
With getfsxattrat() syscall, filesystem may use this field to report
its supported xflags. Zero mask value means that supported flags are
not advertized.
With setfsxattrat() syscall, userspace may use this field to declare
which xflags and fields are being set. Zero mask value means that
all known xflags and fields are being set.
Programs that call getfsxattrat() to fill struct fsxattr before calling
setfsxattrat() will not be affected by this change, but it allows
programs that call setfsxattrat() without calling getfsxattrat() to make
changes to some xflags and fields without knowing or changing the values
of unrelated xflags and fields.
Link: https://lore.kernel.org/linux-fsdevel/20250216164029.20673-4-pali@kernel.org/
Cc: Pali Rohár <pali@kernel.org>
Cc: Andrey Albershteyn <aalbersh@redhat.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/ioctl.c | 35 +++++++++++++++++++++++++++++------
include/linux/fileattr.h | 1 +
include/uapi/linux/fs.h | 3 ++-
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/fs/ioctl.c b/fs/ioctl.c
index b19858db4c432..a4838b3e7de90 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -540,10 +540,13 @@ EXPORT_SYMBOL(vfs_fileattr_get);
void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx)
{
- __u32 mask = FS_XFALGS_MASK;
+ /* Filesystem may or may not advertize supported xflags */
+ __u32 fs_mask = fa->fsx_xflags_mask & FS_XFALGS_MASK;
+ __u32 mask = fs_mask ?: FS_XFALGS_MASK;
memset(fsx, 0, sizeof(struct fsxattr));
fsx->fsx_xflags = fa->fsx_xflags & mask;
+ fsx->fsx_xflags_mask = fs_mask;
fsx->fsx_extsize = fa->fsx_extsize;
fsx->fsx_nextents = fa->fsx_nextents;
fsx->fsx_projid = fa->fsx_projid;
@@ -562,6 +565,8 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa)
struct fsxattr xfa;
fileattr_to_fsxattr(fa, &xfa);
+ /* FS_IOC_FSGETXATTR ioctl does not report supported fsx_xflags_mask */
+ xfa.fsx_xflags_mask = 0;
if (copy_to_user(ufa, &xfa, sizeof(xfa)))
return -EFAULT;
@@ -572,16 +577,30 @@ EXPORT_SYMBOL(copy_fsxattr_to_user);
int fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa)
{
- __u32 mask = FS_XFALGS_MASK;
+ /* User may or may not provide custom xflags mask */
+ __u32 mask = fsx->fsx_xflags_mask ?: FS_XFALGS_MASK;
- if (fsx->fsx_xflags & ~mask)
+ if ((fsx->fsx_xflags & ~mask) || (mask & ~FS_XFALGS_MASK))
return -EINVAL;
fileattr_fill_xflags(fa, fsx->fsx_xflags);
fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK;
- fa->fsx_extsize = fsx->fsx_extsize;
- fa->fsx_projid = fsx->fsx_projid;
- fa->fsx_cowextsize = fsx->fsx_cowextsize;
+ fa->fsx_xflags_mask = fsx->fsx_xflags_mask;
+ /*
+ * If flags mask is specified, we copy the fields value only if the
+ * relevant flag is set in the mask.
+ */
+ if (!mask || (mask & (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT)))
+ fa->fsx_extsize = fsx->fsx_extsize;
+ if (!mask || (mask & FS_XFLAG_COWEXTSIZE))
+ fa->fsx_cowextsize = fsx->fsx_cowextsize;
+ /*
+ * To save a mask flag (i.e. FS_XFLAG_PROJID), require setting values
+ * of fsx_projid and FS_XFLAG_PROJINHERIT flag values together.
+ * For a non-directory, FS_XFLAG_PROJINHERIT flag value should be 0.
+ */
+ if (!mask || (mask & FS_XFLAG_PROJINHERIT))
+ fa->fsx_projid = fsx->fsx_projid;
return 0;
}
@@ -594,6 +613,10 @@ static int copy_fsxattr_from_user(struct fileattr *fa,
if (copy_from_user(&xfa, ufa, sizeof(xfa)))
return -EFAULT;
+ /* FS_IOC_FSSETXATTR ioctl does not support user fsx_xflags_mask */
+ if (xfa.fsx_xflags_mask)
+ return -EINVAL;
+
return fsxattr_to_fileattr(&xfa, fa);
}
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index f682bfc7749dd..93102423b7c95 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -44,6 +44,7 @@ struct fileattr {
u32 flags; /* flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS) */
/* struct fsxattr: */
u32 fsx_xflags; /* xflags field value (get/set) */
+ u32 fsx_xflags_mask;/* xflags valid mask (get/set) */
u32 fsx_extsize; /* extsize field value (get/set)*/
u32 fsx_nextents; /* nextents field value (get) */
u32 fsx_projid; /* project identifier (get/set) */
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 0ae21596e25a5..5c35c415ca8fa 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -145,7 +145,8 @@ struct fsxattr {
__u32 fsx_nextents; /* nextents field value (get) */
__u32 fsx_projid; /* project identifier (get/set) */
__u32 fsx_cowextsize; /* CoW extsize field value (get/set)*/
- unsigned char fsx_pad[8];
+ __u32 fsx_xflags_mask;/* xflags valid mask (get/set) */
+ unsigned char fsx_pad[4];
};
#define FSXATTR_SIZE_VER0 28
--
2.34.1
next prev parent reply other threads:[~2025-03-29 14:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-29 14:33 [RFC PATCH 0/2] [gs]etfsxattrat() followup patches Amir Goldstein
2025-03-29 14:33 ` [RFC PATCH 1/2] fs: prepare for extending [gs]etfsxattrat() Amir Goldstein
2025-03-31 14:43 ` Andrey Albershteyn
2025-03-31 15:06 ` Amir Goldstein
2025-03-31 20:58 ` Dave Chinner
2025-03-29 14:33 ` Amir Goldstein [this message]
2025-03-29 14:43 ` [RFC PATCH 2/2] fs: add support for custom fsx_xflags_mask Amir Goldstein
2025-03-29 14:44 ` Pali Rohár
2025-03-29 15:23 ` Amir Goldstein
2025-04-01 10:45 ` [RFC PATCH 0/2] [gs]etfsxattrat() followup patches Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250329143312.1350603-3-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=aalbersh@redhat.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=pali@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.