From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: josef@toxicpanda.com, dsterba@suse.com
Subject: [PATCH v5 4/5] btrfs: introduce new device-state read_preferred
Date: Mon, 17 Feb 2020 19:12:44 +0800 [thread overview]
Message-ID: <1581937965-16569-5-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1581937965-16569-1-git-send-email-anand.jain@oracle.com>
Preparatory patch to add new read_policy type 'device'.
Provides a sysfs interface to set the device state as read_preferred.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v5: born
fs/btrfs/sysfs.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/volumes.h | 1 +
2 files changed, 50 insertions(+)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index c9a8850b186a..638ce3f4abe3 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1317,11 +1317,60 @@ static ssize_t btrfs_devinfo_writeable_show(struct kobject *kobj,
}
BTRFS_ATTR(devid, writeable, btrfs_devinfo_writeable_show);
+static ssize_t btrfs_devinfo_read_pref_show(struct kobject *kobj,
+ struct kobj_attribute *a, char *buf)
+{
+ int val;
+ struct btrfs_device *device = container_of(kobj, struct btrfs_device,
+ devid_kobj);
+
+ val = !!test_bit(BTRFS_DEV_STATE_READ_PREFERRED, &device->dev_state);
+
+ return snprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+
+static ssize_t btrfs_devinfo_read_pref_store(struct kobject *kobj,
+ struct kobj_attribute *a,
+ const char *buf, size_t len)
+{
+ int ret;
+ unsigned long val;
+ struct btrfs_device *device;
+
+ ret = kstrtoul(skip_spaces(buf), 0, &val);
+ if (ret)
+ return ret;
+
+ if (val != 0 && val != 1)
+ return -EINVAL;
+
+ /*
+ * lock is not required, the btrfs_device struct can't be freed while
+ * its kobject btrfs_device::devid_kobj is still open.
+ */
+ device = container_of(kobj, struct btrfs_device, devid_kobj);
+
+ if (val) {
+ set_bit(BTRFS_DEV_STATE_READ_PREFERRED, &device->dev_state);
+ btrfs_info(device->fs_devices->fs_info,
+ "set read preferred on devid %llu", device->devid);
+ } else {
+ clear_bit(BTRFS_DEV_STATE_READ_PREFERRED, &device->dev_state);
+ btrfs_info(device->fs_devices->fs_info,
+ "reset read preferred on devid %llu", device->devid);
+ }
+
+ return len;
+}
+BTRFS_ATTR_RW(devid, read_preferred, btrfs_devinfo_read_pref_show,
+ btrfs_devinfo_read_pref_store);
+
static struct attribute *devid_attrs[] = {
BTRFS_ATTR_PTR(devid, in_fs_metadata),
BTRFS_ATTR_PTR(devid, missing),
BTRFS_ATTR_PTR(devid, replace_target),
BTRFS_ATTR_PTR(devid, writeable),
+ BTRFS_ATTR_PTR(devid, read_preferred),
NULL
};
ATTRIBUTE_GROUPS(devid);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index ed2bba741b6e..07962a0ce898 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -52,6 +52,7 @@ struct btrfs_io_geometry {
#define BTRFS_DEV_STATE_MISSING (2)
#define BTRFS_DEV_STATE_REPLACE_TGT (3)
#define BTRFS_DEV_STATE_FLUSH_SENT (4)
+#define BTRFS_DEV_STATE_READ_PREFERRED (5)
struct btrfs_device {
struct list_head dev_list; /* device_list_mutex */
--
1.8.3.1
next prev parent reply other threads:[~2020-02-17 11:13 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-17 11:12 [PATCH v5 0/5] readmirror feature (sysfs and in-memory only approach; with new read_policy device) Anand Jain
2020-02-17 11:12 ` [PATCH v5 1/5] btrfs: add btrfs_strmatch helper Anand Jain
2020-02-17 11:12 ` [PATCH v5 2/5] btrfs: create read policy framework Anand Jain
2020-02-19 7:41 ` kbuild test robot
2020-02-19 11:40 ` Anand Jain
2020-02-19 12:35 ` David Sterba
2020-02-17 11:12 ` [PATCH v5 3/5] btrfs: create read policy sysfs attribute, pid Anand Jain
2020-02-17 11:12 ` Anand Jain [this message]
2020-02-17 11:12 ` [PATCH v5 5/5] btrfs: introduce new read_policy device Anand Jain
2020-02-18 16:35 ` [PATCH v5 0/5] readmirror feature (sysfs and in-memory only approach; with new read_policy device) David Sterba
2020-02-19 11:42 ` Anand Jain
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=1581937965-16569-5-git-send-email-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.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;
as well as URLs for NNTP newsgroup(s).