Add the exisiting %pid based readmirror policy as an attribute
/sys/fs/btrfs/UUID/readmirror/by_pid
When read, this returns 0 or 1. 1 indicates the currently active policy.
When written with 1, it sets pid as the current active policy and when
written 0 it resets to the default readmirror policy which as of now is
pid as well. For any other value it returns EINVAL.
Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
---
fs/btrfs/sysfs.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index da5e1938e9b9..5a09cf868328 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -355,7 +355,59 @@ static ssize_t supported_checksums_show(struct kobject *kobj,
#endif
+#define readmirror_to_fs_devices(_kobj) to_fs_devs((_kobj)->parent)
+/*
+ * Set the readmirror type to BTRFS_READMIRROR_BY_PID
+ */
+static ssize_t btrfs_sysfs_readmirror_by_pid_store(struct kobject *kobj,
+ struct kobj_attribute *a,
+ const char *buf, size_t count)
+{
+ int ret;
+ unsigned long val;
+ struct btrfs_fs_devices *fs_devices;
+
+ fs_devices = readmirror_to_fs_devices(kobj);
+
+ ret = kstrtoul(skip_spaces(buf), 0, &val);
+ if (ret)
+ return ret;
+
+ switch (val) {
+ case 0:
+ atomic_set(&fs_devices->readmirror, BTRFS_READMIRROR_DEFAULT);
+ break;
+ case 1:
+ atomic_set(&fs_devices->readmirror, BTRFS_READMIRROR_BY_PID);
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return count;
+}
+
+static ssize_t btrfs_sysfs_readmirror_by_pid_show(struct kobject *kobj,
+ struct kobj_attribute *a,
+ char *buf)
+{
+ int val;
+ struct btrfs_fs_devices *fs_devices;
+
+ fs_devices = readmirror_to_fs_devices(kobj);
+
+ if (atomic_read(&fs_devices->readmirror) == BTRFS_READMIRROR_BY_PID)
+ val = 1;
+ else
+ val = 0;
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+BTRFS_ATTR_RW(readmirror, by_pid, btrfs_sysfs_readmirror_by_pid_show,
+ btrfs_sysfs_readmirror_by_pid_store);
+
static const struct attribute *btrfs_readmirror_attrs[] = {
+ BTRFS_ATTR_PTR(readmirror, by_pid),
NULL,
};
@@ -1241,7 +1293,7 @@ int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
error = -ENOMEM;
goto failure;
}
- error = sysfs_create_files(fs_info->readmirror_kobj,
+ error = sysfs_create_files(fs_devs->readmirror_kobj,
btrfs_readmirror_attrs);
if (error)
goto failure;
--
1.8.3.1