]> Git Repo - J-linux.git/commitdiff
btrfs: sysfs: fix direct super block member reads
authorQu Wenruo <[email protected]>
Wed, 18 Dec 2024 06:30:56 +0000 (17:00 +1030)
committerDavid Sterba <[email protected]>
Mon, 23 Dec 2024 21:06:44 +0000 (22:06 +0100)
The following sysfs entries are reading super block member directly,
which can have a different endian and cause wrong values:

- sys/fs/btrfs/<uuid>/nodesize
- sys/fs/btrfs/<uuid>/sectorsize
- sys/fs/btrfs/<uuid>/clone_alignment

Thankfully those values (nodesize and sectorsize) are always aligned
inside the btrfs_super_block, so it won't trigger unaligned read errors,
just endian problems.

Fix them by using the native cached members instead.

Fixes: df93589a1737 ("btrfs: export more from FS_INFO to sysfs")
CC: [email protected]
Reviewed-by: Naohiro Aota <[email protected]>
Reviewed-by: Johannes Thumshirn <[email protected]>
Signed-off-by: Qu Wenruo <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: David Sterba <[email protected]>
fs/btrfs/sysfs.c

index fdcbf650ac31f96d9afba6b440d037c9568c2c35..7f09b6c9cc2d3248086f7250a9fa88fd82406a2a 100644 (file)
@@ -1118,7 +1118,7 @@ static ssize_t btrfs_nodesize_show(struct kobject *kobj,
 {
        struct btrfs_fs_info *fs_info = to_fs_info(kobj);
 
-       return sysfs_emit(buf, "%u\n", fs_info->super_copy->nodesize);
+       return sysfs_emit(buf, "%u\n", fs_info->nodesize);
 }
 
 BTRFS_ATTR(, nodesize, btrfs_nodesize_show);
@@ -1128,7 +1128,7 @@ static ssize_t btrfs_sectorsize_show(struct kobject *kobj,
 {
        struct btrfs_fs_info *fs_info = to_fs_info(kobj);
 
-       return sysfs_emit(buf, "%u\n", fs_info->super_copy->sectorsize);
+       return sysfs_emit(buf, "%u\n", fs_info->sectorsize);
 }
 
 BTRFS_ATTR(, sectorsize, btrfs_sectorsize_show);
@@ -1180,7 +1180,7 @@ static ssize_t btrfs_clone_alignment_show(struct kobject *kobj,
 {
        struct btrfs_fs_info *fs_info = to_fs_info(kobj);
 
-       return sysfs_emit(buf, "%u\n", fs_info->super_copy->sectorsize);
+       return sysfs_emit(buf, "%u\n", fs_info->sectorsize);
 }
 
 BTRFS_ATTR(, clone_alignment, btrfs_clone_alignment_show);
This page took 0.051587 seconds and 4 git commands to generate.