From 5a9302bab9c9bb3d1577f04678d074fb7af4115f Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Wed, 15 May 2024 08:49:56 +0200 Subject: Add fsetxattr(), fremovexattr(), open_by_handle_at(), and "virtiofsd demo" Mostly assorted fixes, a new FDGET operation (get a copy of the target file descriptor via pidfd_getfd()) and a new "FD" flag that means we have to do that on direct tag reference. Signed-off-by: Stefano Brivio --- cooker/calls/fs.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) (limited to 'cooker/calls') diff --git a/cooker/calls/fs.c b/cooker/calls/fs.c index 4135be9..29c653a 100644 --- a/cooker/calls/fs.c +++ b/cooker/calls/fs.c @@ -60,6 +60,7 @@ swapoff #define _GNU_SOURCE #include +#include #include #include @@ -200,10 +201,199 @@ static struct arg chown_args[] = { { 0 } }; +static struct num xattr_flags[] = { + { "create", XATTR_CREATE }, + { "replace", XATTR_REPLACE }, + { 0 }, +}; + +static struct arg fsetxattr_args[] = { + { 0, + { + "fd", INT, FD, 0, 0, + { 0 } + } + }, + { 0, + { + "path", FDPATH, FD, 0, 0, + { 0 } + } + }, + { 1, + { + "name", STRING, 0, 0, + XATTR_NAME_MAX, + { 0 } + } + }, + { 2, + { + "value", STRING, WBUF, 0, + XATTR_SIZE_MAX, + { 0 } + } + }, + { 3, + { + "size", LONG, 0, 0, 0, + { 0 } + } + }, + { 4, + { + "flags", INT, FLAGS, 0, 0, + { .d_num = xattr_flags } + } + }, + { 0 }, +}; + +static struct arg fremovexattr_args[] = { + { 0, + { + "fd", INT, FD, 0, 0, + { 0 } + } + }, + { 0, + { + "path", FDPATH, FD, 0, 0, + { 0 } + } + }, + { 1, + { + "name", STRING, 0, 0, + XATTR_NAME_MAX, + { 0 } + } + }, + { 0 }, +}; + +/* enum fid_type copied (without comments) from include/linux/exportfs.h of + * Linux 6.9. Just copied and pasted like that? Is that an acceptable practice? + * Well then, let's say I _vendored_ it. + */ +enum fid_type { + FILEID_ROOT = 0, + FILEID_INO32_GEN = 1, + FILEID_INO32_GEN_PARENT = 2, + FILEID_BTRFS_WITHOUT_PARENT = 0x4d, + FILEID_BTRFS_WITH_PARENT = 0x4e, + FILEID_BTRFS_WITH_PARENT_ROOT = 0x4f, + FILEID_UDF_WITHOUT_PARENT = 0x51, + FILEID_UDF_WITH_PARENT = 0x52, + FILEID_NILFS_WITHOUT_PARENT = 0x61, + FILEID_NILFS_WITH_PARENT = 0x62, + FILEID_FAT_WITHOUT_PARENT = 0x71, + FILEID_FAT_WITH_PARENT = 0x72, + FILEID_INO64_GEN = 0x81, + FILEID_INO64_GEN_PARENT = 0x82, + FILEID_LUSTRE = 0x97, + FILEID_BCACHEFS_WITHOUT_PARENT = 0xb1, + FILEID_BCACHEFS_WITH_PARENT = 0xb2, + FILEID_KERNFS = 0xfe, + FILEID_INVALID = 0xff, +}; + +static struct num handle_types[] = { + { "root", FILEID_ROOT }, + { "ino32_gen", FILEID_INO32_GEN }, + { "ino32_gen_parent", FILEID_INO32_GEN_PARENT }, + { "btrfs_with_parent", FILEID_BTRFS_WITH_PARENT }, + { "btrfs_without_parent", FILEID_BTRFS_WITHOUT_PARENT }, + { "udf_with_parent", FILEID_UDF_WITH_PARENT }, + { "udf_without_parent", FILEID_UDF_WITHOUT_PARENT }, + { "fat_with_parent", FILEID_FAT_WITH_PARENT }, + { "fat_without_parent", FILEID_FAT_WITHOUT_PARENT }, + { "ino64_gen", FILEID_INO64_GEN }, + { "ino64_gen_parent", FILEID_INO64_GEN_PARENT }, + { "lustre", FILEID_LUSTRE }, + { "bcachefs_with_parent", FILEID_BCACHEFS_WITH_PARENT }, + { "bcachefs_without_parent", FILEID_BCACHEFS_WITHOUT_PARENT }, + { "kernfs", FILEID_KERNFS }, + { "invalid", FILEID_INVALID }, + { 0 }, +}; + +static struct field file_handle[] = { + { + "handle_bytes", LONG, SIZE, + offsetof(struct file_handle, handle_bytes), + 0, + { .d_size = (intptr_t)&file_handle[2] }, + }, + { + "handle_type", INT, FLAGS, + offsetof(struct file_handle, handle_type), + 0, + { .d_num = handle_types }, + }, + + { + "f_handle", STRING, 0, + offsetof(struct file_handle, f_handle), + MAX_HANDLE_SZ, + { 0 }, + }, + { 0 } +}; + +static struct num open_flags[] = { + { "rdonly", O_RDONLY }, + { "wronly", O_WRONLY }, + { "rdwr", O_RDWR }, + { 0 }, +}; + +static struct arg open_by_handle_at_args[] = { + { 0, + { + "mount", FDMOUNT, 0, 0, + 0, + { 0 } + } + }, + { 0, + { + "mount_fd", INT, 0, 0, + 0, + { 0 } + } + }, + { 1, + { + "handle", STRUCT, 0, 0, + sizeof(struct file_handle) + MAX_HANDLE_SZ, + { .d_struct = file_handle } + } + }, + { 2, + { + "flags", INT, MASK | FLAGS, 0, + 0, + { .d_num = open_flags } + } + }, + { 0 }, +}; + struct call syscalls_fs[] = { { __NR_mknod, "mknod", mknod_args }, { __NR_mknodat, "mknodat", mknodat_args }, + { __NR_chown, "chown", chown_args }, { __NR_lchown, "lchown", chown_args }, + + { __NR_fsetxattr, "fsetxattr", fsetxattr_args }, + /* fd, name, value, size, flags */ + + { __NR_fremovexattr, "fremovexattr", fremovexattr_args }, + /* fd, name */ + + { __NR_open_by_handle_at, "open_by_handle_at", open_by_handle_at_args }, + { 0 }, }; -- cgit v1.2.3