From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 3/3] btrfs: sysfs, create by_pid readmirror attribute
Date: Fri, 20 Dec 2019 13:06:05 +0800 [thread overview]
Message-ID: <1576818365-20286-4-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1576818365-20286-1-git-send-email-anand.jain@oracle.com>
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@oracle.com>
---
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
prev parent reply other threads:[~2019-12-20 5:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-20 5:06 [PATCH 0/3] readmirror feature (sysfs and in-memory only approach) Anand Jain
2019-12-20 5:06 ` [PATCH 1/3] btrfs: add readmirror type framework Anand Jain
2019-12-20 14:44 ` Josef Bacik
2020-01-02 10:12 ` Anand Jain
2019-12-20 5:06 ` [PATCH 2/3] btrfs: sysfs, add readmirror kobject Anand Jain
2019-12-20 5:06 ` Anand Jain [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1576818365-20286-4-git-send-email-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox