Skip to contentSkip to conversation

loop device broken in 2.4.6-pre5

DISCUSSION [email protected] 3 participants 4 messages Jun 21, 2001 – Jun 26, 2001 Block layer

lore
Share & tools
lore
#0 lore raw

From: Jari Ruusu <[email protected]>

File backed loop device on 4k block size ext2 filesystem:

# dd if=/dev/zero of=file1 bs=1024 count=10
10+0 records in
10+0 records out
# losetup /dev/loop0 file1
# dd if=/dev/zero of=/dev/loop0 bs=1024 count=10 conv=notrunc
dd: /dev/loop0: No space left on device
9+0 records in
8+0 records out
# tune2fs -l /dev/hda1 2>&1| grep "Block size"
Block size: 4096
# uname -a
Linux debian 2.4.6-pre5 #1 Thu Jun 21 14:27:25 EEST 2001 i686 unknown

Stock 2.4.5 and 2.4.5-ac15 don't have this problem.

I am not sure there is an error here.

The default block size of a loop device is that of the underlying device. There was a kernel bug that was recently fixed, where the block size of a file backed loop device could be essentially random.
So, earlier you happened to get blocksize 1024, and you had room for 10 blocks of size 1024.
Now you have blocksize 4096, and you have room for 2 blocks of size 4096. There are no fractional blocks at the end of a block device.

Andries

#1 lore raw
Quoted 21 lines · [email protected] wrote:

From: Jari Ruusu <[email protected]>

File backed loop device on 4k block size ext2 filesystem:

# dd if=/dev/zero of=file1 bs=1024 count=10
10+0 records in
10+0 records out
# losetup /dev/loop0 file1
# dd if=/dev/zero of=/dev/loop0 bs=1024 count=10 conv=notrunc
dd: /dev/loop0: No space left on device
9+0 records in
8+0 records out
# tune2fs -l /dev/hda1 2>&1| grep "Block size"
Block size: 4096
# uname -a
Linux debian 2.4.6-pre5 #1 Thu Jun 21 14:27:25 EEST 2001 i686 unknown

Stock 2.4.5 and 2.4.5-ac15 don't have this problem.

I am not sure there is an error here.

Quoted 7 lines

The default block size of a loop device is that of the underlying device. There was a kernel bug that was recently fixed, where the block size of a file backed loop device could be essentially random.
So, earlier you happened to get blocksize 1024, and you had room for 10 blocks of size 1024.
Now you have blocksize 4096, and you have room for 2 blocks of size 4096. There are no fractional blocks at the end of a block device.

Why can't we keep the default at 1024 regardless of what the block size of underlying device is. There are some situations where all of loop device must be accessed before it is mounted (at which point the block size is set to desired value).

Regards,
Jari Ruusu <[email protected]>

#2 lore raw
In reply to [email protected]
Quoted 17 lines · [email protected] wrote:

From: Jari Ruusu <[email protected]>

File backed loop device on 4k block size ext2 filesystem:

# dd if=/dev/zero of=file1 bs=1024 count=10
10+0 records in
10+0 records out
# losetup /dev/loop0 file1
# dd if=/dev/zero of=/dev/loop0 bs=1024 count=10 conv=notrunc
dd: /dev/loop0: No space left on device
9+0 records in
8+0 records out
# tune2fs -l /dev/hda1 2>&1| grep "Block size"
Block size: 4096
# uname -a
Linux debian 2.4.6-pre5 #1 Thu Jun 21 14:27:25 EEST 2001 i686 unknown

Quoted 3 lines

Stock 2.4.5 and 2.4.5-ac15 don't have this problem.

I am not sure there is an error here.

How about:

dd if=/dev/hda1 of=disk.img bs=1k
mount disk.img /mnt/d1 -o loop

If the filesystem on hda1 happens to use the last 2k of the partition, and the partition size is 2k mod 4k, then I get a non-working disk.img if I don't pad the disk.img file with another 2k. And then I might trip up the "how big is this partition" code in the fs-driver....

Roger.

Signature · 4 lines
** [email protected] ** http://www.BitWizard.nl/ ** +31-15-2137555 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
* There are old pilots, and there are bold pilots. 
* There are also old, bald pilots. 
#3 lore raw
In reply to [email protected]

This patch fixes the problem. Please consider applying.

drivers/block/loop.c +1 -1
@@ -653,7 +653,7 @@
 	bs = 0;
 	if (blksize_size[MAJOR(lo_device)])
 		bs = blksize_size[MAJOR(lo_device)][MINOR(lo_device)];
-	if (!bs)
+	if (!bs || S_ISREG(inode->i_mode))
 		bs = BLOCK_SIZE;
 
 	set_blocksize(dev, bs);
Quoted 30 lines · Jari Ruusu
Quoted 21 lines · [email protected] wrote:

From: Jari Ruusu <[email protected]>

File backed loop device on 4k block size ext2 filesystem:

# dd if=/dev/zero of=file1 bs=1024 count=10
10+0 records in
10+0 records out
# losetup /dev/loop0 file1
# dd if=/dev/zero of=/dev/loop0 bs=1024 count=10 conv=notrunc
dd: /dev/loop0: No space left on device
9+0 records in
8+0 records out
# tune2fs -l /dev/hda1 2>&1| grep "Block size"
Block size: 4096
# uname -a
Linux debian 2.4.6-pre5 #1 Thu Jun 21 14:27:25 EEST 2001 i686 unknown

Stock 2.4.5 and 2.4.5-ac15 don't have this problem.

I am not sure there is an error here.

Quoted 7 lines

The default block size of a loop device is that of the underlying device. There was a kernel bug that was recently fixed, where the block size of a file backed loop device could be essentially random.
So, earlier you happened to get blocksize 1024, and you had room for 10 blocks of size 1024.
Now you have blocksize 4096, and you have room for 2 blocks of size 4096. There are no fractional blocks at the end of a block device.

Quoted 4 lines

Why can't we keep the default at 1024 regardless of what the block size of underlying device is. There are some situations where all of loop device must be accessed before it is mounted (at which point the block size is set to desired value).

Regards,
Jari Ruusu <[email protected]>