Skip to content

Commit 3d8cc17

Browse files
asjkdave
authored andcommitted
btrfs: sysfs: add per-fs attribute for read policy
Add /sys/fs/btrfs/UUID/read_policy attribute so that the read policy for the raid1, raid1c34 and raid10 can be tuned. When this attribute is read, it will show all available policies, with active policy in [ ]. The read_policy attribute can be written using one of the items listed in there. For example: $ cat /sys/fs/btrfs/UUID/read_policy [pid] $ echo pid > /sys/fs/btrfs/UUID/read_policy Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Anand Jain <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 33fd2f7 commit 3d8cc17

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

fs/btrfs/sysfs.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,54 @@ static bool strmatch(const char *buffer, const char *string)
907907
return false;
908908
}
909909

910+
static const char * const btrfs_read_policy_name[] = { "pid" };
911+
912+
static ssize_t btrfs_read_policy_show(struct kobject *kobj,
913+
struct kobj_attribute *a, char *buf)
914+
{
915+
struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
916+
ssize_t ret = 0;
917+
int i;
918+
919+
for (i = 0; i < BTRFS_NR_READ_POLICY; i++) {
920+
if (fs_devices->read_policy == i)
921+
ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s[%s]",
922+
(ret == 0 ? "" : " "),
923+
btrfs_read_policy_name[i]);
924+
else
925+
ret += scnprintf(buf + ret, PAGE_SIZE - ret, "%s%s",
926+
(ret == 0 ? "" : " "),
927+
btrfs_read_policy_name[i]);
928+
}
929+
930+
ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n");
931+
932+
return ret;
933+
}
934+
935+
static ssize_t btrfs_read_policy_store(struct kobject *kobj,
936+
struct kobj_attribute *a,
937+
const char *buf, size_t len)
938+
{
939+
struct btrfs_fs_devices *fs_devices = to_fs_devs(kobj);
940+
int i;
941+
942+
for (i = 0; i < BTRFS_NR_READ_POLICY; i++) {
943+
if (strmatch(buf, btrfs_read_policy_name[i])) {
944+
if (i != fs_devices->read_policy) {
945+
fs_devices->read_policy = i;
946+
btrfs_info(fs_devices->fs_info,
947+
"read policy set to '%s'",
948+
btrfs_read_policy_name[i]);
949+
}
950+
return len;
951+
}
952+
}
953+
954+
return -EINVAL;
955+
}
956+
BTRFS_ATTR_RW(, read_policy, btrfs_read_policy_show, btrfs_read_policy_store);
957+
910958
static const struct attribute *btrfs_attrs[] = {
911959
BTRFS_ATTR_PTR(, label),
912960
BTRFS_ATTR_PTR(, nodesize),
@@ -917,6 +965,7 @@ static const struct attribute *btrfs_attrs[] = {
917965
BTRFS_ATTR_PTR(, checksum),
918966
BTRFS_ATTR_PTR(, exclusive_operation),
919967
BTRFS_ATTR_PTR(, generation),
968+
BTRFS_ATTR_PTR(, read_policy),
920969
NULL,
921970
};
922971

0 commit comments

Comments
 (0)