Btrfs-progs: Initialize stripesize to the value of sectorsize
PATCH 1/1 Btrfs-progs: Initialize stripesize to the value of sectorsize
stripesize should ideally be set to the value of sectorsize. However previous versions of btrfs-progs/mkfs.btrfs had set stripesize to a value of 4096. On machines with PAGE_SIZE other than 4096, This could lead to the following scenario,
- /dev/loop0, /dev/loop1 and /dev/loop2 are mounted as a single filesystem. The filesystem was created by an older version of mkfs.btrfs which set stripesize to 4k.
- losetup -a
/dev/loop0: [0030]:19477 (/root/disk-imgs/file-0.img) /dev/loop1: [0030]:16577 (/root/disk-imgs/file-1.img) /dev/loop2: [64770]:3423229 (/root/disk-imgs/file-2.img)
- /etc/mtab lists only /dev/loop0
- losetup /dev/loop4 /root/disk-imgs/file-1.img
The new mkfs.btrfs invoked as 'mkfs.btrfs -f /dev/loop4' succeeds even though /dev/loop1 has already been mounted and has /root/disk-imgs/file-1.img as its backing file.
The above behaviour occurs because check_super() function returns an error code (due to stripesize not being set to 4096) and hence check_mounted_where() function treats /dev/loop1 as a disk containing a filesystem other than Btrfs.
Hence as a workaround this commit allows 4096 as a valid stripesize.
--- disk-io.c | 4 +++- mkfs.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
disk-io.c +3 -1
@@ -1476,7 +1476,9 @@ static int check_super(struct btrfs_super_block *sb)error ("invalid bytes_used %llu" ,btrfs_super_bytes_used (sb)); goto error_out; } -if (btrfs_super_stripesize (sb) !=4096 ) { + +if ((btrfs_super_stripesize (sb) !=4096 ) + && (btrfs_super_stripesize (sb) !=btrfs_super_sectorsize (sb))) {error ("invalid stripesize %u" ,btrfs_super_stripesize (sb)); goto error_out; }
mkfs.c +1 -0
@@ -1482,6 +1482,7 @@ int main(int argc, char **argv) } sectorsize =max (sectorsize, (u32 )sysconf (_SC_PAGESIZE)); + stripesize = sectorsize; saved_optind = optind; dev_cnt = argc - optind;if (dev_cnt ==0 )
Signature · 1 line
2.5.5
Quoted 36 lines · Chandan Rajendra
stripesize should ideally be set to the value of sectorsize. However previous versions of btrfs-progs/mkfs.btrfs had set stripesize to a value of 4096. On machines with
PAGE_SIZEother than 4096, This could lead to the following scenario,-
/dev/loop0,/dev/loop1and/dev/loop2are mounted as a single filesystem. The filesystem was created by an older version of mkfs.btrfs which set stripesize to 4k.
- losetup -a
/dev/loop0: [0030]:19477 (/root/disk-imgs/file-0.img)/dev/loop1: [0030]:16577 (/root/disk-imgs/file-1.img)/dev/loop2: [64770]:3423229 (/root/disk-imgs/file-2.img)
-/etc/mtablists only/dev/loop0
- losetup/dev/loop4/root/disk-imgs/file-1.img
The new mkfs.btrfs invoked as 'mkfs.btrfs -f/dev/loop4' succeeds even though/dev/loop1has already been mounted and has/root/disk-imgs/file-1.imgas its backing file.The above behaviour occurs because
check_super()function returns an error code (due to stripesize not being set to 4096) and hencecheck_mounted_where()function treats/dev/loop1as a disk containing a filesystem other than Btrfs.Hence as a workaround this commit allows 4096 as a valid stripesize.
Signed-off-by Chandan Rajendra <[email protected]>--- disk-io.c | 4 +++- mkfs.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)disk-io.c +0
-0
disk-io.c static int check_super(struct btrfs_super_block *sb) · line 1480
Quoted 6 lines
disk-io.c +2
-1@@ -1476,7 +1476,9 @@ static int check_super(struct btrfs_super_block *sb)error ("invalid bytes_used %llu" ,btrfs_super_bytes_used (sb)); goto error_out; } -if (btrfs_super_stripesize (sb) !=4096 ) { + + if ((btrfs_super_stripesize(sb) != 4096)
Just one trivial comment. Tab was converted to some spaces.
Thanks,
Satoru
Quoted 17 lines
disk-io.c +1
-0+ && (btrfs_super_stripesize(sb) != btrfs_super_sectorsize(sb))) {error ("invalid stripesize %u" ,btrfs_super_stripesize (sb)); goto error_out; }mkfs.c +1
-0@@ -1482,6 +1482,7 @@ int main(int argc, char **argv) } sectorsize =max (sectorsize, (u32 )sysconf (_SC_PAGESIZE)); + stripesize = sectorsize; saved_optind = optind; dev_cnt = argc - optind;if (dev_cnt ==0 )