From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC v2] btrfs-progs: add readmirror property and ioctl to set get readmirror
Date: Mon, 26 Aug 2019 17:04:38 +0800 [thread overview]
Message-ID: <20190826090438.7044-3-anand.jain@oracle.com> (raw)
In-Reply-To: <20190826090438.7044-1-anand.jain@oracle.com>
This patch adds readmirror property to be applied at the filesystem object.
And uses ioctl BTRFS_IOC_GET_READMIRROR and BTRFS_IOC_SET_READMIRROR to get
and set the property respectively.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v1->RFC v2:
. Changed format specifier from devid1,2,3.. to devid:1,2,3..
ioctl.h | 14 +++++++++
props.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 112 insertions(+)
diff --git a/ioctl.h b/ioctl.h
index 66ee599f7a82..ccdf600bae77 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -765,6 +765,16 @@ struct btrfs_ioctl_get_subvol_rootref_args {
};
BUILD_ASSERT(sizeof(struct btrfs_ioctl_get_subvol_rootref_args) == 4096);
+enum btrfs_readmirror_policy {
+ BTRFS_READMIRROR_DEFAULT = 0,
+ BTRFS_READMIRROR_DEVID,
+};
+
+struct btrfs_ioctl_readmirror_args {
+ __u64 type; /* RW */
+ __u64 device_bitmap; /* RW */
+};
+
/* Error codes as returned by the kernel */
enum btrfs_err_code {
notused,
@@ -929,6 +939,10 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code)
struct btrfs_ioctl_get_subvol_rootref_args)
#define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \
struct btrfs_ioctl_ino_lookup_user_args)
+#define BTRFS_IOC_GET_READMIRROR _IOWR(BTRFS_IOCTL_MAGIC, 63, \
+ struct btrfs_ioctl_readmirror_args)
+#define BTRFS_IOC_SET_READMIRROR _IOWR(BTRFS_IOCTL_MAGIC, 64, \
+ struct btrfs_ioctl_readmirror_args)
#ifdef __cplusplus
}
#endif
diff --git a/props.c b/props.c
index 004022600d51..f077e55e2274 100644
--- a/props.c
+++ b/props.c
@@ -166,6 +166,98 @@ out:
return ret;
}
+static int prop_readmirror(enum prop_object_type type, const char *object,
+ const char *name, const char *value)
+{
+ int fd;
+ int ret;
+ DIR *dirstream = NULL;
+
+ fd = open_file_or_dir3(object, &dirstream, value ? O_RDWR : O_RDONLY);
+ if (fd < 0) {
+ ret = -errno;
+ error("failed to open %s: %m", object);
+ return ret;
+ }
+
+ if (value) {
+ int ret;
+ int final_ret;
+ size_t len = strlen(value);
+ char *value_dup;
+ char *devid_str;
+ struct btrfs_ioctl_readmirror_args readmirror;
+
+ if (len > 0 && (len <= 6 || strncmp("devid:", value, 6)))
+ return -EINVAL;
+
+ /* value format - an example: readmirror devid:1,2,3,.. */
+ value_dup = strndup(value + 6, len - 6);
+ if (!value_dup)
+ return -ENOMEM;
+
+ final_ret = 0;
+ if (len == 0) {
+ readmirror.type = BTRFS_READMIRROR_DEFAULT;
+ final_ret = ioctl(fd, BTRFS_IOC_SET_READMIRROR, &readmirror);
+ if (final_ret < 0)
+ error("failed to reset readmirror: (%m)");
+ } else {
+ __u64 device_bitmap = 0;
+
+ while ((devid_str = strsep(&value_dup, ",")) != NULL)
+ device_bitmap = device_bitmap |
+ (1ULL << arg_strtou64(devid_str));
+
+ readmirror.type = BTRFS_READMIRROR_DEVID;
+ readmirror.device_bitmap = device_bitmap;
+ ret = ioctl(fd, BTRFS_IOC_SET_READMIRROR, &readmirror);
+ if (ret < 0) {
+ error("failed to set readmirror: (%m)");
+ final_ret = ret;
+ }
+ }
+ return final_ret;
+ } else {
+ struct btrfs_ioctl_readmirror_args readmirror;
+ struct btrfs_ioctl_dev_info_args *device;
+ struct btrfs_ioctl_fs_info_args fs_devices;
+
+ ret = get_fs_info(object, &fs_devices, &device);
+ if (ret)
+ return ret;
+
+ free(device);
+ if (fs_devices.num_devices > 63) {
+ error("can't set readmirror for device id more than 63");
+ return -EOPNOTSUPP;
+ }
+
+ ret = ioctl(fd, BTRFS_IOC_GET_READMIRROR, &readmirror);
+ if (ret) {
+ error("readmirror ioctl failed: %m");
+ return ret;
+ }
+ if (readmirror.type == BTRFS_READMIRROR_DEFAULT) {
+ printf("readmirror default\n");
+ } else if (readmirror.type == BTRFS_READMIRROR_DEVID) {
+ u64 cnt;
+
+ printf("readmirror devid:");
+ for (cnt = 0; cnt < 64; cnt++) {
+ if ((1ULL << cnt) & readmirror.device_bitmap)
+ printf("%llu ", cnt);
+ }
+ printf("\n");
+ }
+ return 0;
+ }
+
+ close_file_or_dir(fd, dirstream);
+
+ return ret;
+}
+
const struct prop_handler prop_handlers[] = {
{
.name ="ro",
@@ -187,5 +279,11 @@ const struct prop_handler prop_handlers[] = {
.read_only = 0,
.types = prop_object_inode, prop_compression
},
+ {
+ .name = "readmirror",
+ .desc = "specify the device to be used for read",
+ .read_only = 0,
+ .types = prop_object_root, prop_readmirror
+ },
{NULL, NULL, 0, 0, NULL}
};
--
2.21.0 (Apple Git-120)
next prev parent reply other threads:[~2019-08-26 9:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-26 9:04 [PATCH RFC v2 0/2] readmirror feature Anand Jain
2019-08-26 9:04 ` [PATCH RFC v2] btrfs: add readmirror framework and policy devid Anand Jain
2019-08-26 9:04 ` Anand Jain [this message]
2019-08-29 3:39 ` [PATCH RFC v2.1] btrfs-progs: add readmirror property and ioctl to set get Anand Jain
2019-09-11 16:37 ` [PATCH RFC v2 0/2] readmirror feature David Sterba
2019-09-12 7:48 ` Anand Jain
2019-09-11 18:42 ` Josef Bacik
2019-09-11 19:13 ` Eli V
2019-09-11 19:16 ` Josef Bacik
2019-09-12 7:41 ` Anand Jain
2019-09-12 9:50 ` Josef Bacik
2019-09-12 10:00 ` Anand Jain
2019-09-12 10:03 ` Josef Bacik
2019-09-12 10:10 ` Anand Jain
2019-09-12 10:13 ` Josef Bacik
2019-09-16 8:19 ` Anand Jain
2019-09-24 14:27 ` 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=20190826090438.7044-3-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;
as well as URLs for NNTP newsgroup(s).