[PATCH 6/6] xfs: let XFS_IOC_{SET,GET}_DP_OPS act on a project ID

From: Naohiro Aota

Date: Mon Nov 30 2026 - 23:35:53 EST


Define XFS_DP_OPS_F_PROJID in the flags field of struct xfs_dp_ops_name.
When set, XFS_IOC_SET_DP_OPS binds the named policy to the project ID of
the file the ioctl is issued on instead of the whole file system (an empty
name unbinds it), and XFS_IOC_GET_DP_OPS returns the policy bound to that
project ID. Per-project-ID bindings override the mount-wide one.

Without the flag the behaviour is unchanged: the policy is bound to / read
from the whole file system and the ioctl must be issued on its root
directory.

Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx>
---
fs/xfs/libxfs/xfs_fs.h | 3 +++
fs/xfs/xfs_bpf.c | 59 ++++++++++++++++++++++++++++++++++++------
2 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index a6c05ce9bc6d..868704a17e10 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -1193,6 +1193,9 @@ struct xfs_verify_media {

#define XFS_DP_OPS_NAME_MAX 16

+/* Bind to the project ID of the ioctl'd file, not the whole file system. */
+#define XFS_DP_OPS_F_PROJID (1u << 0)
+
/*
* Name of a BPF data placement policy, i.e. a registered struct fs_dp_ops
* struct_ops, for XFS_IOC_{SET,GET}_DP_OPS.
diff --git a/fs/xfs/xfs_bpf.c b/fs/xfs/xfs_bpf.c
index ced985c219c6..e730161337dc 100644
--- a/fs/xfs/xfs_bpf.c
+++ b/fs/xfs/xfs_bpf.c
@@ -15,6 +15,7 @@
#include "xfs_format.h"
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
+#include "xfs_inode.h"
#include "xfs_ioctl.h"
#include "xfs_bpf.h"

@@ -39,6 +40,35 @@ xfs_dp_ops_set(
}
}

+/* Make @mp use @ops for files of @projid, taking over its reference. */
+static int
+xfs_dp_ops_set_projid(
+ struct xfs_mount *mp,
+ prid_t projid,
+ struct fs_dp_ops *ops)
+{
+ struct fs_dp_ops *old;
+
+ mutex_lock(&xfs_dp_set_lock);
+ if (ops)
+ old = xa_store(&mp->m_dp_ops_by_projid, projid, ops, GFP_KERNEL);
+ else
+ old = xa_erase(&mp->m_dp_ops_by_projid, projid);
+ mutex_unlock(&xfs_dp_set_lock);
+
+ if (xa_is_err(old)) {
+ if (ops)
+ fs_dp_ops_put(ops);
+ return xa_err(old);
+ }
+ if (old) {
+ /* Synchronize with xfs_bpf_file_open(). */
+ synchronize_rcu();
+ fs_dp_ops_put(old);
+ }
+ return 0;
+}
+
void
xfs_bpf_file_open(
struct inode *inode,
@@ -91,13 +121,17 @@ xfs_ioc_set_dp_ops(
return -EPERM;
if (copy_from_user(&dn, arg, sizeof(dn)))
return -EFAULT;
- /* No flags defined yet; reject non-zero for forward compatibility. */
- if (dn.flags ||
+ if ((dn.flags & ~XFS_DP_OPS_F_PROJID) ||
memchr_inv(dn.pad, 0, sizeof(dn.pad)) ||
!memchr(dn.name, 0, sizeof(dn.name)))
return -EINVAL;
- /* Only for the whole file system, via its root directory. */
- if (filp->f_path.dentry != mp->m_super->s_root)
+ /*
+ * Binding to the whole file system is only allowed via its root
+ * directory. A per-project-ID binding uses the file's own project ID,
+ * so any file of the file system will do.
+ */
+ if (!(dn.flags & XFS_DP_OPS_F_PROJID) &&
+ filp->f_path.dentry != mp->m_super->s_root)
return -EINVAL;

if (dn.name[0]) {
@@ -105,6 +139,9 @@ xfs_ioc_set_dp_ops(
if (!ops)
return -ENOENT;
}
+ if (dn.flags & XFS_DP_OPS_F_PROJID)
+ return xfs_dp_ops_set_projid(mp,
+ XFS_I(file_inode(filp))->i_projid, ops);
xfs_dp_ops_set(mp, ops);
return 0;
}
@@ -120,15 +157,21 @@ xfs_ioc_get_dp_ops(

if (copy_from_user(&dn, arg, sizeof(dn)))
return -EFAULT;
- /* No flags defined yet; reject non-zero for forward compatibility. */
- if (dn.flags || memchr_inv(dn.pad, 0, sizeof(dn.pad)))
+ if ((dn.flags & ~XFS_DP_OPS_F_PROJID) ||
+ memchr_inv(dn.pad, 0, sizeof(dn.pad)))
return -EINVAL;
- if (filp->f_path.dentry != mp->m_super->s_root)
+ /* The whole file system, via its root directory, unless F_PROJID. */
+ if (!(dn.flags & XFS_DP_OPS_F_PROJID) &&
+ filp->f_path.dentry != mp->m_super->s_root)
return -EINVAL;

memset(dn.name, 0, sizeof(dn.name));
rcu_read_lock();
- ops = rcu_dereference(mp->m_dp_ops);
+ if (dn.flags & XFS_DP_OPS_F_PROJID)
+ ops = xa_load(&mp->m_dp_ops_by_projid,
+ XFS_I(file_inode(filp))->i_projid);
+ else
+ ops = rcu_dereference(mp->m_dp_ops);
if (ops)
strscpy(dn.name, ops->name);
rcu_read_unlock();
--
2.56.1