From: Sidong Yang <realwakka@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Sidong Yang <realwakka@gmail.com>
Subject: [PATCH] btrfs-progs: filesystem-resize: make output more readable
Date: Wed, 16 Dec 2020 03:42:40 +0000 [thread overview]
Message-ID: <20201216034240.2029-1-realwakka@gmail.com> (raw)
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>
---
cmds/filesystem.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 60 insertions(+), 1 deletion(-)
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index fac612b2..53e775b7 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -1084,6 +1084,14 @@ static int cmd_filesystem_resize(const struct cmd_struct *cmd,
int ret;
struct stat st;
bool enqueue = false;
+ struct btrfs_ioctl_fs_info_args fi_args;
+ struct btrfs_ioctl_dev_info_args *di_args = NULL;
+ char newsize[256];
+ char sign;
+ u64 inc_bytes;
+ u64 res_bytes;
+ int i, devid, dev_idx;
+ const char *res_str;
optind = 0;
while (1) {
@@ -1142,7 +1150,58 @@ static int cmd_filesystem_resize(const struct cmd_struct *cmd,
return 1;
}
- printf("Resize '%s' of '%s'\n", path, amount);
+ ret = get_fs_info(path, &fi_args, &di_args);
+ if (ret)
+ error("unable to retrieve fs info");
+
+ if (!fi_args.num_devices)
+ error("num_devices = 0");
+
+ ret = sscanf(amount, "%d:%255s", &devid, newsize);
+
+ if (ret != 2)
+ error("invalid format");
+
+ dev_idx = -1;
+ for(i = 0; i < fi_args.num_devices; i++) {
+ if (di_args[i].devid == devid) {
+ dev_idx = i;
+ break;
+ }
+ }
+
+ if (dev_idx < 0)
+ error("cannot find devid : %d", devid);
+
+ if (!strcmp(newsize, "max")) {
+ res_str = "max";
+ } else {
+ if (strlen(newsize) < 3)
+ error("invalid format");
+
+ sign = newsize[0];
+ if (sign != '-' && sign != '+')
+ error("invalid format");
+
+ inc_bytes = parse_size(&newsize[1]);
+
+ res_bytes = 0;
+ if (sign == '+')
+ res_bytes = di_args[0].total_bytes + inc_bytes;
+ else if (sign == '-')
+ res_bytes = di_args[0].total_bytes - inc_bytes;
+ else
+ error("invalid format");
+
+ res_str = pretty_size_mode(res_bytes, UNITS_DEFAULT);
+ }
+
+ printf("Resize device id %d (%s) from %s to %s\n", devid, di_args[dev_idx].path,
+ pretty_size_mode(di_args[dev_idx].total_bytes, UNITS_DEFAULT),
+ res_str);
+
+ free(di_args);
+
memset(&args, 0, sizeof(args));
strncpy_null(args.name, amount);
res = ioctl(fd, BTRFS_IOC_RESIZE, &args);
--
2.25.1
next reply other threads:[~2020-12-16 3:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-16 3:42 Sidong Yang [this message]
2021-01-14 23:48 ` [PATCH] btrfs-progs: filesystem-resize: make output more readable David Sterba
2021-01-20 16:03 ` Sidong Yang
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=20201216034240.2029-1-realwakka@gmail.com \
--to=realwakka@gmail.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