Skip to contentSkip to conversation

Btrfs: Don't error on resizing FS to same size

PATCH Superseded Mike Fleetwood 2 participants 3 messages Nov 17, 2011 – Nov 18, 2011 Btrfs file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: Don't error on resizing FS to same size

It seems overly harsh to fail a resize of a btrfs file system to the same size when a shrink or grow would succeed. User app GParted trips over this error. Allow it by bypassing the shrink or grow operation.

---

Example failed resize:

    # strace -e trace=ioctl btrfs filesystem resize max /mnt/0
    Resize '/mnt/0' of 'max'
    ioctl(3, 0x50009403, 0xbfa5029c)        = -1 EINVAL (Invalid argument)
    ERROR: unable to resize '/mnt/0' - Invalid argument
    # echo $?
    30
    # dmesg | tail -1
    [426094.235018] new size for /dev/loop1 is 1073741824
---
 fs/btrfs/ioctl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/btrfs/ioctl.c +1 -1
index dae5dfe..00b7024 100644
@@ -1251,7 +1251,7 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
 		}
 		ret = btrfs_grow_device(trans, device, new_size);
 		btrfs_commit_transaction(trans, root);
-	} else {
+	} else if (new_size > old_size) {
 		ret = btrfs_shrink_device(device, new_size);
 	}
 
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 3 lines · Mike Fleetwood

It seems overly harsh to fail a resize of a btrfs file system to the same size when a shrink or grow would succeed. User app GParted trips over this error. Allow it by bypassing the shrink or grow operation.

OK - I'm a newbie with the code (and I'm looking at Linus's current git rather than any dev tree of Chris's), but...

Quoted 2 lines

---

[...]

Quoted 9 lines
---
 fs/btrfs/ioctl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/btrfs/ioctl.c +0 -0
index dae5dfe..00b7024 100644

fs/btrfs/ioctl.c static noinline int btrfs_ioctl_resize(struct btrfs_root *root, · line 1254

Quoted 5 lines
fs/btrfs/ioctl.c +1 -1
@@ -1251,7 +1251,7 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
 		}
 		ret = btrfs_grow_device(trans, device, new_size);
 		btrfs_commit_transaction(trans, root);
-	} else {
+	} else if (new_size > old_size) {

shouldn't that be:

+ } else if (new_size < old_size) {

otherwise you'll never try and shrink if new_size is < old_size..

Quoted 3 lines
fs/btrfs/ioctl.c +0 -0
 		ret = btrfs_shrink_device(device, new_size);
 	}
 
Signature · 1 line
 Chris Samuel  :  http://www.csamuel.org/  :  Melbourne, VIC
#2 lore raw
Quoted 31 lines · Chris Samuel
Quoted 3 lines · Mike Fleetwood

It seems overly harsh to fail a resize of a btrfs file system to the same size when a shrink or grow would succeed. User app GParted trips over this error. Allow it by bypassing the shrink or grow operation.

OK - I'm a newbie with the code (and I'm looking at Linus's current git rather than any dev tree of Chris's), but...

Quoted 2 lines

---

[...]

Quoted 9 lines
---
 fs/btrfs/ioctl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/btrfs/ioctl.c +0 -0
index dae5dfe..00b7024 100644

fs/btrfs/ioctl.c static noinline int btrfs_ioctl_resize(struct btrfs_root *root, · line 1254

Quoted 5 lines
fs/btrfs/ioctl.c +1 -1
@@ -1251,7 +1251,7 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
 		}
 		ret = btrfs_grow_device(trans, device, new_size);
 		btrfs_commit_transaction(trans, root);
-	} else {
+	} else if (new_size > old_size) {

shouldn't that be:

(quoted diff) +1 -0
+	} else if (new_size < old_size) {
Quoted 5 lines

otherwise you'll never try and shrink if new_size is < old_size..

Quoted 3 lines
fs/btrfs/ioctl.c +0 -0
 		ret = btrfs_shrink_device(device, new_size);
 	}
 

Chris, you're correct. I have messed up a 1 line patch by rushing. Will send corrected patch after some more testing!

Embarrassed,
Mike