All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Misono, Tomohiro" <misono.tomohiro@jp.fujitsu.com>
To: Omar Sandoval <osandov@osandov.com>, <linux-btrfs@vger.kernel.org>
Cc: <kernel-team@fb.com>
Subject: Re: [PATCH v2 16/27] btrfs-progs: use libbtrfsutil for read-only property
Date: Thu, 22 Feb 2018 13:23:45 +0900	[thread overview]
Message-ID: <954ea177-da85-ae8f-41d0-3e7d46b69158@jp.fujitsu.com> (raw)
In-Reply-To: <f906d40f5464b26fc9707a145254a48efac2ff50.1518720598.git.osandov@fb.com>



On 2018/02/16 4:05, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
>  messages.h | 13 ++++++++++++
>  props.c    | 69 +++++++++++++++++++++++---------------------------------------
>  2 files changed, 38 insertions(+), 44 deletions(-)
> 
> diff --git a/messages.h b/messages.h
> index 4999c7b9..004d5167 100644
> --- a/messages.h
> +++ b/messages.h
> @@ -54,6 +54,19 @@
>  			DO_ABORT_ON_ERROR;				\
>  	} while (0)
>  
> +#define error_btrfs_util(err)						\
> +	do {								\
> +		const char *errno_str = strerror(errno);		\
> +		const char *lib_str = btrfs_util_strerror(err)		\

"make D=trace" fails because ";" is missing here.

> +		PRINT_TRACE_ON_ERROR;					\
> +		PRINT_VERBOSE_ERROR;					\
> +		if (lib_str && strcmp(errno_str, lib_str) != 0)		\
> +			__btrfs_error("%s: %s", lib_str, errno_str);	\
> +		else							\
> +			__btrfs_error("%s", errno_str);			\
> +		DO_ABORT_ON_ERROR;					\
> +	} while (0)
> +
>  #define warning(fmt, ...)						\
>  	do {								\
>  		PRINT_TRACE_ON_ERROR;					\
> diff --git a/props.c b/props.c
> index cddbd927..e4edba06 100644
> --- a/props.c
> +++ b/props.c
> @@ -21,6 +21,8 @@
>  #include <fcntl.h>
>  #include <unistd.h>
>  
> +#include <btrfsutil.h>
> +
>  #include "ctree.h"
>  #include "commands.h"
>  #include "utils.h"
> @@ -41,56 +43,35 @@ static int prop_read_only(enum prop_object_type type,
>  			  const char *name,
>  			  const char *value)
>  {
> -	int ret = 0;
> -	int fd = -1;
> -	u64 flags = 0;
> -
> -	fd = open(object, O_RDONLY);
> -	if (fd < 0) {
> -		ret = -errno;
> -		error("failed to open %s: %s", object, strerror(-ret));
> -		goto out;
> -	}
> +	enum btrfs_util_error err;
> +	bool read_only;
>  
> -	ret = ioctl(fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags);
> -	if (ret < 0) {
> -		ret = -errno;
> -		error("failed to get flags for %s: %s", object,
> -				strerror(-ret));
> -		goto out;
> -	}
> -
> -	if (!value) {
> -		if (flags & BTRFS_SUBVOL_RDONLY)
> -			fprintf(stdout, "ro=true\n");
> -		else
> -			fprintf(stdout, "ro=false\n");
> -		ret = 0;
> -		goto out;
> -	}
> +	if (value) {
> +		if (!strcmp(value, "true")) {
> +			read_only = true;
> +		} else if (!strcmp(value, "false")) {
> +			read_only = false;
> +		} else {
> +			error("invalid value for property: %s", value);
> +			return -EINVAL;
> +		}
>  
> -	if (!strcmp(value, "true")) {
> -		flags |= BTRFS_SUBVOL_RDONLY;
> -	} else if (!strcmp(value, "false")) {
> -		flags = flags & ~BTRFS_SUBVOL_RDONLY;
> +		err = btrfs_util_set_subvolume_read_only(object, read_only);
> +		if (err) {
> +			error_btrfs_util(err);
> +			return -errno;
> +		}
>  	} else {
> -		ret = -EINVAL;
> -		error("invalid value for property: %s", value);
> -		goto out;
> -	}
> +		err = btrfs_util_get_subvolume_read_only(object, &read_only);
> +		if (err) {
> +			error_btrfs_util(err);
> +			return -errno;
> +		}
>  
> -	ret = ioctl(fd, BTRFS_IOC_SUBVOL_SETFLAGS, &flags);
> -	if (ret < 0) {
> -		ret = -errno;
> -		error("failed to set flags for %s: %s", object,
> -				strerror(-ret));
> -		goto out;
> +		printf("ro=%s\n", read_only ? "true" : "false");
>  	}
>  
> -out:
> -	if (fd != -1)
> -		close(fd);
> -	return ret;
> +	return 0;
>  }
>  
>  static int prop_label(enum prop_object_type type,
> 


  reply	other threads:[~2018-02-22  4:23 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15 19:04 [PATCH v2 00/27] btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library" Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 01/27] btrfs-progs: get rid of undocumented qgroup inheritance options Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 02/27] Add libbtrfsutil Omar Sandoval
2018-02-20 17:32   ` Liu Bo
2018-02-20 18:34     ` David Sterba
2018-02-15 19:04 ` [PATCH v2 03/27] libbtrfsutil: add Python bindings Omar Sandoval
2018-02-21 13:47   ` David Sterba
2018-02-21 18:08     ` Omar Sandoval
2018-02-22  1:44   ` Misono, Tomohiro
2018-02-15 19:04 ` [PATCH v2 04/27] libbtrfsutil: add btrfs_util_is_subvolume() and btrfs_util_subvolume_id() Omar Sandoval
2018-02-21 11:43   ` David Sterba
2018-02-21 13:02     ` David Sterba
2018-02-21 18:13       ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 05/27] libbtrfsutil: add qgroup inheritance helpers Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 06/27] libbtrfsutil: add btrfs_util_create_subvolume() Omar Sandoval
2018-02-23  8:24   ` Misono, Tomohiro
2018-02-23 22:58     ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 07/27] libbtrfsutil: add btrfs_util_subvolume_path() Omar Sandoval
2018-02-23  6:27   ` Misono, Tomohiro
2018-02-23 22:44     ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 08/27] libbtrfsutil: add btrfs_util_subvolume_info() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 09/27] libbtrfsutil: add btrfs_util_[gs]et_read_only() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 10/27] libbtrfsutil: add btrfs_util_[gs]et_default_subvolume() Omar Sandoval
2018-02-22  1:55   ` Misono, Tomohiro
2018-02-23 22:40     ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 11/27] libbtrfsutil: add subvolume iterator helpers Omar Sandoval
2018-02-23  7:40   ` Misono, Tomohiro
2018-02-23 22:49     ` Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 12/27] libbtrfsutil: add btrfs_util_create_snapshot() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 13/27] libbtrfsutil: add btrfs_util_delete_subvolume() Omar Sandoval
2018-02-15 19:04 ` [PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes() Omar Sandoval
2018-02-23  2:12   ` Misono, Tomohiro
2018-02-23 23:33     ` Omar Sandoval
2018-02-28  4:11       ` Misono, Tomohiro
2018-02-15 19:05 ` [PATCH v2 15/27] libbtrfsutil: add filesystem sync helpers Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 16/27] btrfs-progs: use libbtrfsutil for read-only property Omar Sandoval
2018-02-22  4:23   ` Misono, Tomohiro [this message]
2018-02-23 22:41     ` Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 17/27] btrfs-progs: use libbtrfsutil for sync ioctls Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 18/27] btrfs-progs: use libbtrfsutil for set-default Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 19/27] btrfs-progs: use libbtrfsutil for get-default Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 20/27] btrfs-progs: use libbtrfsutil for subvol create and snapshot Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 21/27] btrfs-progs: use libbtrfsutil for subvol delete Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 22/27] btrfs-progs: use libbtrfsutil for subvol show Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 23/27] btrfs-progs: use libbtrfsutil for subvol sync Omar Sandoval
2018-02-22  2:03   ` Misono, Tomohiro
2018-02-23 22:41     ` Omar Sandoval
2018-02-23 23:22       ` David Sterba
2018-02-22  2:09   ` Misono, Tomohiro
2018-02-15 19:05 ` [PATCH v2 24/27] btrfs-progs: replace test_issubvolume() with btrfs_util_is_subvolume() Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 25/27] btrfs-progs: add recursive snapshot/delete using libbtrfsutil Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 26/27] btrfs-progs: use libbtrfsutil for subvolume list Omar Sandoval
2018-02-23  2:26   ` Misono, Tomohiro
2018-02-23 23:05     ` Omar Sandoval
2018-02-15 19:05 ` [PATCH v2 27/27] btrfs-progs: deprecate libbtrfs helpers Omar Sandoval
2018-02-21 15:04   ` David Sterba
2018-02-21 18:19     ` Omar Sandoval
2018-02-20 18:50 ` [PATCH v2 00/27] btrfs-progs: introduce libbtrfsutil, "btrfs-progs as a library" David Sterba
2018-02-21 15:13   ` David Sterba
2018-02-21 18:50     ` Omar Sandoval
2018-02-23 20:28       ` David Sterba
2018-02-26 23:36         ` Omar Sandoval
2018-02-27 15:04           ` David Sterba
2018-02-27 20:48             ` Omar Sandoval

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=954ea177-da85-ae8f-41d0-3e7d46b69158@jp.fujitsu.com \
    --to=misono.tomohiro@jp.fujitsu.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=osandov@osandov.com \
    /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.