[PATCH 1/2] fs_dp: let a policy pick a write stream

From: Naohiro Aota

Date: Mon Nov 30 2026 - 23:37:32 EST


An unmodified application cannot use write streams: a stream is
reserved through FS_IOC_WRITE_STREAM_ALLOC, which needs CAP_SYS_ADMIN,
and has to be set on each file with FS_IOC_WRITE_STREAM_SET.

Let a data placement policy assign them instead. file_open() picks a
stream by setting fs_dp_file_open_res.write_stream to a slot number.
Which stream a slot names is up to the filesystem, which binds a set of
streams along with the policy: streams belong to a filesystem, while one
policy can be bound to several filesystems.

As for the hint, write_stream holds the file's current stream on entry,
so that a policy that leaves it alone keeps it. A file can also be on a
stream that is not bound with the policy, set through
FS_IOC_WRITE_STREAM_SET; that is FS_DP_WRITE_STREAM_OTHER, which is not
a slot a policy can pick. A file on no stream has
FS_DP_WRITE_STREAM_NONE. A stream and a write lifetime hint are
exclusive, so a policy may set one or the other.

Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx>
---
fs/fs_dp.c | 14 ++++++++++++--
include/linux/fs_dp.h | 12 ++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/fs/fs_dp.c b/fs/fs_dp.c
index 5b0aba2c182a..41bf58884457 100644
--- a/fs/fs_dp.c
+++ b/fs/fs_dp.c
@@ -46,9 +46,18 @@ static int bpf_fs_dp_btf_struct_access(struct bpf_verifier_log *log,
if (t != res_type)
return -EACCES;

- if (off != offsetof(struct fs_dp_file_open_res, i_write_hint) ||
- size != sizeof_field(struct fs_dp_file_open_res, i_write_hint))
+ switch (off) {
+ case offsetof(struct fs_dp_file_open_res, i_write_hint):
+ if (size != sizeof_field(struct fs_dp_file_open_res, i_write_hint))
+ return -EACCES;
+ break;
+ case offsetof(struct fs_dp_file_open_res, write_stream):
+ if (size != sizeof_field(struct fs_dp_file_open_res, write_stream))
+ return -EACCES;
+ break;
+ default:
return -EACCES;
+ }

return SCALAR_VALUE;
}
@@ -61,6 +70,7 @@ static const struct bpf_verifier_ops bpf_fs_dp_verifier_ops = {

static int bpf_fs_dp_init(struct btf *btf)
{
+ BTF_TYPE_EMIT_ENUM(FS_DP_WRITE_STREAM_OTHER);
return 0;
}

diff --git a/include/linux/fs_dp.h b/include/linux/fs_dp.h
index e3a65dedd940..9304365646c1 100644
--- a/include/linux/fs_dp.h
+++ b/include/linux/fs_dp.h
@@ -18,6 +18,13 @@ struct file_kattr;
/* Result a data placement policy returns from its file_open() callback. */
struct fs_dp_file_open_res {
enum rw_hint i_write_hint;
+ u16 write_stream;
+};
+
+/* write_stream values other than a slot */
+enum {
+ FS_DP_WRITE_STREAM_NONE = (u16)-1, /* not on a write stream */
+ FS_DP_WRITE_STREAM_OTHER = (u16)-2, /* on a stream not bound */
};

/*
@@ -31,6 +38,11 @@ struct fs_dp_file_open_res {
* @parent_ino is the inode number of the parent directory.
* @fa carries the file's attributes (project ID, xflags, ...) and may be NULL
* if the filesystem does not provide them.
+ * @res holds the file's current placement on entry: its write lifetime hint,
+ * and as write_stream the slot of its write stream among those the filesystem
+ * bound along with the policy, FS_DP_WRITE_STREAM_OTHER if it is on another
+ * one, or FS_DP_WRITE_STREAM_NONE. A policy may set a hint or a bound stream,
+ * not both.
*/
struct fs_dp_ops {
char name[FS_DP_OPS_NAME_MAX];
--
2.56.1