From: David Sterba <dsterba@suse.cz>
To: Anand Jain <anand.jain@oracle.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/2 RESEND Rebased] btrfs-progs: add readmirror policy
Date: Tue, 23 Jul 2019 15:53:30 +0200 [thread overview]
Message-ID: <20190723135330.GC2868@twin.jikos.cz> (raw)
In-Reply-To: <20190626083723.2094-2-anand.jain@oracle.com>
On Wed, Jun 26, 2019 at 04:37:23PM +0800, Anand Jain wrote:
> This sets the readmirror=<parm> as a btrfs.<attr> extentded attribute.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> props.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 49 insertions(+)
>
> diff --git a/props.c b/props.c
> index 3a498bd9e904..1d1a2c7f9d14 100644
> --- a/props.c
> +++ b/props.c
> @@ -178,6 +178,53 @@ 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;
> + char buf[256] = {0};
> + char *xattr_name;
> + 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;
> + }
> +
> + xattr_name = alloc_xattr_name(name);
> + if (IS_ERR(xattr_name)) {
> + error("failed to alloc xattr_name %s: %m", object);
> + return PTR_ERR(xattr_name);
> + }
> +
> + ret = 0;
> + if (value) {
> + if (fsetxattr(fd, xattr_name, value, strlen(value), 0) < 0) {
> + ret = -errno;
> + error("failed to set readmirror for %s: %m", object);
> + }
> + } else {
> + if (fgetxattr(fd, xattr_name, buf, 256) < 0) {
> + if (errno != ENOATTR) {
> + ret = -errno;
> + error("failed to get readmirror for %s: %m",
> + object);
> + }
> + } else {
> + fprintf(stdout, "readmirror=%.*s\n", (int) strlen(buf),
> + buf);
> + }
> + }
> +
> + free(xattr_name);
> + close_file_or_dir(fd, dirstream);
> +
> + return ret;
> +}
> +
> const struct prop_handler prop_handlers[] = {
> {"ro", "Set/get read-only flag of subvolume.", 0, prop_object_subvol,
> prop_read_only},
> @@ -185,5 +232,7 @@ const struct prop_handler prop_handlers[] = {
> prop_object_dev | prop_object_root, prop_label},
> {"compression", "Set/get compression for a file or directory", 0,
> prop_object_inode, prop_compression},
> + {"readmirror", "set/get readmirror policy for filesystem", 0,
> + prop_object_root, prop_readmirror},
For some unknown reason the object type for filesystem-wide props is
called prop_object_root, which is correct, but it got me confused first.
So the most reliable way to set it is
$ btrfs prop set -t filesystem /path readmirror <VALUE>
and
$ btrfs prop set /path readmirror <VALUE>
will auto-detect the object type by /path, but I'm not sure what exactly
does it do in case it's a mount point but not the toplevel subvolume.
next prev parent reply other threads:[~2019-07-23 13:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-26 8:33 [PATCH 0/3 RESEND Rebased] readmirror feature Anand Jain
2019-06-26 8:34 ` [PATCH 1/3 RESEND Rebased] btrfs: add inode pointer to prop_handler::validate() Anand Jain
2019-06-26 8:34 ` [PATCH 2/3 RESEND Rebased] btrfs: add readmirror property framework Anand Jain
2019-07-23 14:57 ` David Sterba
2019-07-24 2:42 ` Anand Jain
2019-06-26 8:34 ` [PATCH 3/3 RESEND Rebased] btrfs: add readmirror devid property Anand Jain
2019-07-23 14:55 ` David Sterba
2019-07-23 15:25 ` David Sterba
2019-06-26 8:37 ` [PATCH 1/2 RESEND Rebased] btrfs-progs: add helper to create xattr name Anand Jain
2019-06-26 8:37 ` [PATCH 2/2 RESEND Rebased] btrfs-progs: add readmirror policy Anand Jain
2019-07-23 13:53 ` David Sterba [this message]
2019-07-24 3:11 ` Anand Jain
2019-07-23 13:55 ` David Sterba
2019-07-02 8:09 ` [PATCH 0/3 RESEND Rebased] readmirror feature Anand Jain
2019-07-24 0:20 ` Qu Wenruo
2019-07-24 2:26 ` Anand Jain
2019-07-24 3:05 ` Qu Wenruo
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=20190723135330.GC2868@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=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).