Skip to contentSkip to conversation

btrfs-progs: fi resize: fix false 0.00B sized output

PATCH In review Su Yue 3 participants 3 messages Apr 20, 2021 – May 6, 2021 Btrfs file system

lore
Share & tools
lore

Su Yue

author
#0 lore raw

PATCH v3 1/1 btrfs-progs: fi resize: fix false 0.00B sized output

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.

check_resize_args() does not handle the mod 0 case and new_size is 0. Simply assigning @diff to @new_size to fix this.

Issue: #307

---
Changelog:
v3:
Just assign @diff to @new_size. (Boris Burkov)
v2:
Calculate u64 diff using max() and min().
Calculate mod by comparing new and old size.

---
 cmds/filesystem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
cmds/filesystem.c +4 -1
index 9e3cce687d6e..b4c09768235c 100644
@@ -1158,7 +1158,10 @@ static int check_resize_args(const char *amount, const char *path) {
 		}
 		old_size = di_args[dev_idx].total_bytes;
 
-		if (mod < 0) {
+		/* For target sizes without '+'/'-' sign prefix(e.g. 1:150g) */
+		if (mod == 0) {
+			new_size = diff;
+		} else if (mod < 0) {
 			if (diff > old_size) {
 				error("current size is %s which is smaller than %s",
 				      pretty_size_mode(old_size, UNITS_DEFAULT),
Signature · 1 line
2.30.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 4 lines · Su Yue

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

Quoted 8 lines

The resize operation would take effect though.

check_resize_args() does not handle the mod 0 case and new_size is 0. Simply assigning @diff to @new_size to fix this.

Issue: #307

Quoted 30 lines

---
Changelog:
v3:
Just assign @diff to @new_size. (Boris Burkov)
v2:
Calculate u64 diff using max() and min().
Calculate mod by comparing new and old size.

---
 cmds/filesystem.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
cmds/filesystem.c +4 -1
index 9e3cce687d6e..b4c09768235c 100644
@@ -1158,7 +1158,10 @@ static int check_resize_args(const char *amount, const char *path) {
 		}
 		old_size = di_args[dev_idx].total_bytes;
 
-		if (mod < 0) {
+		/* For target sizes without '+'/'-' sign prefix(e.g. 1:150g) */
+		if (mod == 0) {
+			new_size = diff;
+		} else if (mod < 0) {
 			if (diff > old_size) {
 				error("current size is %s which is smaller than %s",
 				      pretty_size_mode(old_size, UNITS_DEFAULT),
Signature · 1 line
2.30.1
#2 lore raw
In reply to Su Yue
Quoted 9 lines · Su Yue

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.

check_resize_args() does not handle the mod 0 case and new_size is 0. Simply assigning @diff to @new_size to fix this.

Quoted 7 lines

Issue: #307

---
Changelog:
v3:
Just assign @diff to @new_size. (Boris Burkov)

Patch replaced in devel, thanks.