@@ -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);
@@ -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 */
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(+)