All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] btrfs-progs: fi resize: fix false 0.00B sized output
@ 2021-04-19 13:05 Su Yue
  2021-04-19 17:03 ` David Sterba
  2021-04-19 17:08 ` Boris Burkov
  0 siblings, 2 replies; 5+ messages in thread
From: Su Yue @ 2021-04-19 13:05 UTC (permalink / raw)
  To: linux-btrfs; +Cc: l, Chris Murphy

Resize to nums without sign prefix makes false output:
 btrfs fi resize 1:150g /srv/extra
Resize device id 1 (/dev/sdb1) from 298.09GiB to 0.00B

The resize operation would take effect though.

Fix it by handling the case if mod is 0 in check_resize_args().

Issue: #307
Reported-by: Chris Murphy <lists@colorremedies.com>
Signed-off-by: Su Yue <l@damenly.su>
---
 cmds/filesystem.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

---
Changelog:
    v2:
        Calculate u64 diff using max() and min().
        Calculate mod by comparing new and old size.
diff --git a/cmds/filesystem.c b/cmds/filesystem.c
index 9e3cce687d6e..54d46470c53f 100644
--- a/cmds/filesystem.c
+++ b/cmds/filesystem.c
@@ -1158,6 +1158,16 @@ static int check_resize_args(const char *amount, const char *path) {
 		}
 		old_size = di_args[dev_idx].total_bytes;
 
+		/* For target sizes without '+'/'-' sign prefix(e.g. 1:150g) */
+		if (mod == 0) {
+			new_size = diff;
+			diff = max(old_size, new_size) - min(old_size, new_size);
+			if (new_size > old_size)
+				mod = 1;
+			else if (new_size < old_size)
+				mod = -1;
+		}
+
 		if (mod < 0) {
 			if (diff > old_size) {
 				error("current size is %s which is smaller than %s",
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-20  4:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-19 13:05 [PATCH v2] btrfs-progs: fi resize: fix false 0.00B sized output Su Yue
2021-04-19 17:03 ` David Sterba
2021-04-19 17:08 ` Boris Burkov
2021-04-19 17:28   ` David Sterba
2021-04-20  4:20   ` Su Yue

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.