All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 3/3] btrfs: sysfs, create by_pid readmirror attribute
Date: Thu,  2 Jan 2020 18:12:48 +0800	[thread overview]
Message-ID: <1577959968-19427-4-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1577959968-19427-1-git-send-email-anand.jain@oracle.com>

Add existing %pid based readmirror policy as an attribute

 /sys/fs/btrfs/UUID/readmirror/by_pid

When read, this returns 0 or 1. 1 indicates currently active policy.
When written with 1, it sets by_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 returns EINVAL.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: fs_devs::readmirror is no more atomic_t so update accordingly.

 fs/btrfs/sysfs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index e604f292b42b..123d1ef72059 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:
+		fs_devices->readmirror = BTRFS_READMIRROR_DEFAULT;
+		break;
+	case 1:
+		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 (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,
 };
 
-- 
1.8.3.1


      parent reply	other threads:[~2020-01-02 10:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-02 10:12 [PATCH v2 0/3] readmirror feature (sysfs and in-memory only approach) Anand Jain
2020-01-02 10:12 ` [PATCH v2 1/3] btrfs: add readmirror type framework Anand Jain
2020-01-02 16:24   ` Josef Bacik
2020-01-03  9:57     ` Anand Jain
2020-01-02 19:32   ` Steven Davies
2020-01-03 10:28     ` Anand Jain
2020-01-03 14:51       ` Steven Davies
2020-01-03 10:31   ` [PATCH v3 " Anand Jain
2020-01-02 10:12 ` [PATCH v2 2/3] btrfs: sysfs, add readmirror kobject Anand Jain
2020-01-02 10:12 ` 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=1577959968-19427-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.