All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Sidong Yang <realwakka@gmail.com>
Cc: linux-btrfs <linux-btrfs@vger.kernel.org>, dsterba@suse.cz
Subject: Re: [PATCH v4] btrfs-progs: filesystem-resize: make output more readable
Date: Tue, 9 Mar 2021 16:38:44 +0100	[thread overview]
Message-ID: <20210309153844.GK7604@twin.jikos.cz> (raw)
In-Reply-To: <20210220124117.11444-1-realwakka@gmail.com>

On Sat, Feb 20, 2021 at 12:41:17PM +0000, Sidong Yang wrote:
> This patch make output of filesystem-resize command more readable and
> give detail information for users. This patch provides more information
> about filesystem like below.
> 
> Before:
> Resize '/mnt' of '1:-1G'
> 
> After:
> Resize device id 1 (/dev/vdb) from 4.00GiB to 3.00GiB
> 
> Signed-off-by: Sidong Yang <realwakka@gmail.com>
> ---
> v2:
>   - print more detailed error
>   - covers all the possibilities format provides
> v3:
>   - use snprintf than strcpy for safety
>   - add diff variable for code readability
> v4:
>   - fix bugs for argument that has no devid
> ---
>  cmds/filesystem.c | 120 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 119 insertions(+), 1 deletion(-)
> 
> diff --git a/cmds/filesystem.c b/cmds/filesystem.c
> index 0d23daf4..7ddf5880 100644
> --- a/cmds/filesystem.c
> +++ b/cmds/filesystem.c
> @@ -28,6 +28,7 @@
>  #include <linux/limits.h>
>  #include <linux/version.h>
>  #include <getopt.h>
> +#include <limits.h>
>  
>  #include <btrfsutil.h>
>  
> @@ -1074,6 +1075,117 @@ static const char * const cmd_filesystem_resize_usage[] = {
>  	NULL
>  };
>  
> +static int check_resize_args(const char *amount, const char *path) {
> +	struct btrfs_ioctl_fs_info_args fi_args;
> +	struct btrfs_ioctl_dev_info_args *di_args = NULL;
> +	int ret, i, dev_idx = -1;
> +	u64 devid = 1;
> +	const char *res_str = NULL;
> +	char *devstr = NULL, *sizestr = NULL;
> +	u64 new_size = 0, old_size = 0, diff = 0;
> +	int mod = 0;
> +	char amount_dup[BTRFS_VOL_NAME_MAX];
> +
> +	ret = get_fs_info(path, &fi_args, &di_args);
> +
> +	if (ret) {
> +		error("unable to retrieve fs info");
> +		return 1;
> +	}
> +
> +	if (!fi_args.num_devices) {
> +		error("no devices found");
> +		free(di_args);
> +		return 1;

Btw I changed all the free/return to ret = 1/goto out pattern so the
cleanup does not need to repeated next to each return.

      parent reply	other threads:[~2021-03-09 15:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-20 12:41 [PATCH v4] btrfs-progs: filesystem-resize: make output more readable Sidong Yang
2021-03-09 15:37 ` David Sterba
2021-03-09 15:38 ` David Sterba [this message]

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=20210309153844.GK7604@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=realwakka@gmail.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.