From fec04e1c56b48a30bf2c2d4f151c1de88e938a7d Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Mon, 5 Dec 2022 15:22:09 -0800 Subject: [PATCH] ANDROID: fuse-bpf: Add /sys/fs flags for fuse-bpf version Note that this is specific for the non-upstreamed version Bug: 202785178 Test: cat /sys/fs/fuse/fuse_bpf_major_version Change-Id: I68f9ca56778874975428839dfc1fd8f48b11bd75 Signed-off-by: Paul Lawrence --- Documentation/ABI/testing/sysfs-fs-fuse | 19 +++++++++++++ fs/fuse/inode.c | 36 +++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-fs-fuse diff --git a/Documentation/ABI/testing/sysfs-fs-fuse b/Documentation/ABI/testing/sysfs-fs-fuse new file mode 100644 index 000000000000..b9956842b36f --- /dev/null +++ b/Documentation/ABI/testing/sysfs-fs-fuse @@ -0,0 +1,19 @@ +What: /sys/fs/fuse/features/fuse_bpf +Date: December 2022 +Contact: Paul Lawrence +Description: + Read-only file that contains the word 'supported' if fuse-bpf is + supported, does not exist otherwise + +What: /sys/fs/fuse/bpf_prog_type_fuse +Date: December 2022 +Contact: Paul Lawrence +Description: + bpf_prog_type_fuse defines the program type of bpf programs that + may be passed to fuse-bpf. For upstream bpf program types, this + is a constant defined in a contiguous array of constants. + bpf_prog_type_fuse is appended to the end of the list, so it may + change and therefore its value must be read from this file. + + Contents is ASCII decimal representation of bpf_prog_type_fuse + diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index dca4b42fad16..1278988518ab 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -2027,7 +2027,31 @@ static void fuse_fs_cleanup(void) static struct kobject *fuse_kobj; -/* TODO Remove this once BPF_PROG_TYPE_FUSE is upstreamed */ +static ssize_t fuse_bpf_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buff) +{ + return sysfs_emit(buff, "supported\n"); +} + +static struct kobj_attribute fuse_bpf_attr = + __ATTR_RO(fuse_bpf); + +static struct attribute *bpf_features[] = { + &fuse_bpf_attr.attr, + NULL, +}; + +static const struct attribute_group bpf_features_group = { + .name = "features", + .attrs = bpf_features, +}; + +/* + * TODO Remove this once fuse-bpf is upstreamed + * + * bpf_prog_type_fuse exports the bpf_prog_type_fuse 'constant', which cannot be + * constant until the code is upstreamed + */ static ssize_t bpf_prog_type_fuse_show(struct kobject *kobj, struct kobj_attribute *attr, char *buff) { @@ -2045,6 +2069,13 @@ static struct attribute *bpf_attributes[] = { static const struct attribute_group bpf_attr_group = { .attrs = bpf_attributes, }; + +static const struct attribute_group *attribute_groups[] = { + &bpf_features_group, + &bpf_attr_group, + NULL +}; + /* TODO remove to here */ static int fuse_sysfs_init(void) @@ -2062,7 +2093,7 @@ static int fuse_sysfs_init(void) goto out_fuse_unregister; /* TODO Remove when BPF_PROG_TYPE_FUSE is upstreamed */ - err = sysfs_create_group(fuse_kobj, &bpf_attr_group); + err = sysfs_create_groups(fuse_kobj, attribute_groups); if (err) goto out_fuse_remove_mount_point; @@ -2078,6 +2109,7 @@ static int fuse_sysfs_init(void) static void fuse_sysfs_cleanup(void) { + sysfs_remove_groups(fuse_kobj, attribute_groups); sysfs_remove_mount_point(fuse_kobj, "connections"); kobject_put(fuse_kobj); }