So far a data placement policy can only be bound to a whole mount. Allow binding a policy to a project ID as well, so that files of different projects can use different policies without the BPF program having to filter on the project ID itself. Keep per-project-ID policies in an xarray on the mount, indexed by project ID. In xfs_file_open(), look up the file's project ID first and fall back to the mount-wide policy if none is bound for it. Each bound policy holds a reference, dropped when it is replaced or at unmount. The ioctl to actually bind a per-project-ID policy comes in the next patch. Signed-off-by: Naohiro Aota --- fs/xfs/xfs_bpf.c | 14 ++++++++++++-- fs/xfs/xfs_mount.h | 3 ++- fs/xfs/xfs_super.c | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_bpf.c b/fs/xfs/xfs_bpf.c index 71f7e3a463e3..ced985c219c6 100644 --- a/fs/xfs/xfs_bpf.c +++ b/fs/xfs/xfs_bpf.c @@ -55,7 +55,7 @@ xfs_bpf_file_open( if (!(file->f_mode & FMODE_WRITE)) return; - if (!rcu_access_pointer(mp->m_dp_ops)) + if (!rcu_access_pointer(mp->m_dp_ops) && xa_empty(&mp->m_dp_ops_by_projid)) return; xfs_fileattr_get(file->f_path.dentry, &fa); @@ -65,7 +65,10 @@ xfs_bpf_file_open( dput(parent); rcu_read_lock(); - ops = rcu_dereference(mp->m_dp_ops); + /* A per-project-ID policy overrides the mount-wide one. */ + ops = xa_load(&mp->m_dp_ops_by_projid, fa.fsx_projid); + if (!ops) + ops = rcu_dereference(mp->m_dp_ops); if (ops) ops->file_open(file, parent_ino, &fa, &res); rcu_read_unlock(); @@ -140,5 +143,12 @@ void xfs_bpf_unmount( struct xfs_mount *mp) { + struct fs_dp_ops *ops; + unsigned long projid; + xfs_dp_ops_set(mp, NULL); + + xa_for_each(&mp->m_dp_ops_by_projid, projid, ops) + fs_dp_ops_put(ops); + xa_destroy(&mp->m_dp_ops_by_projid); } diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index 055454c6a86a..ce07d92158c2 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -356,8 +356,9 @@ typedef struct xfs_mount { /* Private data referring to a health monitor object. */ struct xfs_healthmon __rcu *m_healthmon; - /* BPF data placement policy in use. */ + /* BPF data placement policy in use, and per-project-ID overrides. */ struct fs_dp_ops __rcu *m_dp_ops; + struct xarray m_dp_ops_by_projid; /* Index of uuid record in the uuid xarray. */ unsigned int m_uuid_table_index; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index ff7cb09532e7..f1c2e5b13a03 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -2300,6 +2300,7 @@ xfs_init_fs_context( spin_lock_init(&mp->m_sb_lock); for (i = 0; i < XG_TYPE_MAX; i++) xa_init(&mp->m_groups[i].xa); + xa_init(&mp->m_dp_ops_by_projid); mutex_init(&mp->m_growlock); mutex_init(&mp->m_metafile_resv_lock); INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker); -- 2.56.1