btrfs: add sysfs interface for supported sectorsize
authorQu Wenruo <wqu@suse.com>
Thu, 25 Mar 2021 07:14:33 +0000 (15:14 +0800)
committerDavid Sterba <dsterba@suse.com>
Mon, 19 Apr 2021 15:25:18 +0000 (17:25 +0200)
Export supported sector sizes in /sys/fs/btrfs/features/supported_sectorsizes.

Currently all architectures have PAGE_SIZE, There's some disparity
between read-only and read-write support but that will be unified in the
future so there's only one file exporting the size.

The read-only support for systems with 64K pages also works for 4K
sector size.

This new sysfs interface would help eg. mkfs.btrfs to print more
accurate warnings about potentially incompatible option combinations.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/sysfs.c

index 6eb1c50fa98c1ac9c1c69cd01f121fdca77f1746..a99d1f415a7f7d68921d153063c51824daeab849 100644 (file)
@@ -360,11 +360,26 @@ static ssize_t supported_rescue_options_show(struct kobject *kobj,
 BTRFS_ATTR(static_feature, supported_rescue_options,
           supported_rescue_options_show);
 
+static ssize_t supported_sectorsizes_show(struct kobject *kobj,
+                                         struct kobj_attribute *a,
+                                         char *buf)
+{
+       ssize_t ret = 0;
+
+       /* Only sectorsize == PAGE_SIZE is now supported */
+       ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%lu\n", PAGE_SIZE);
+
+       return ret;
+}
+BTRFS_ATTR(static_feature, supported_sectorsizes,
+          supported_sectorsizes_show);
+
 static struct attribute *btrfs_supported_static_feature_attrs[] = {
        BTRFS_ATTR_PTR(static_feature, rmdir_subvol),
        BTRFS_ATTR_PTR(static_feature, supported_checksums),
        BTRFS_ATTR_PTR(static_feature, send_stream_version),
        BTRFS_ATTR_PTR(static_feature, supported_rescue_options),
+       BTRFS_ATTR_PTR(static_feature, supported_sectorsizes),
        NULL
 };