loop device broken in 2.5.38
PATCH 1/1 loop device broken in 2.5.38
The loop device driver was broken in 2.5.38 when it was converted over to use gendisk. I discovered this while doing final regression testing on the ext3 htree code.
The problem is that figure_loop_size() is setting the capacity of the loop device in kilobytes (because that's what compute_loop_size() returns), but set_capacity() expects the size in 512 byte sectors.
I've enclosed a patch which fixes the problem, as well as simplifying the code by eliminating compute_loop_size(), since it is a static function is only used once by figure_loop_size().
- Ted
===== drivers/block/loop.c 1.57 vs edited =====
drivers/block/loop.c +4 -10
@@ -157,18 +157,12 @@#define MAX_DISK_SIZE 1024*1024*1024 -static unsigned long -compute_loop_size (struct loop_device *lo,struct dentry * lo_dentry) -{ -loff_t size = lo_dentry->d_inode->i_mapping->host->i_size; -return (size - lo->lo_offset) >>BLOCK_SIZE_BITS ; -} -static void figure_loop_size (struct loop_device *lo) { -set_capacity (disks + lo->lo_number,compute_loop_size (lo, - lo->lo_backing_file->f_dentry)); - +loff_t size = lo->lo_backing_file->f_dentry->d_inode->i_size; + +set_capacity (disks + lo->lo_number, + (size - lo->lo_offset) >> (BLOCK_SIZE_BITS -1 )); } static inline int lo_do_transfer(struct loop_device *lo, int cmd, char *rbuf,
Quoted 11 lines · On Sep 25, 2002 13:35 -0400, [email protected] wrote:
The loop device driver was broken in 2.5.38 when it was converted over to use gendisk. I discovered this while doing final regression testing on the ext3 htree code.
The problem is that
figure_loop_size()is setting the capacity of the loop device in kilobytes (because that's whatcompute_loop_size()returns), butset_capacity()expects the size in 512 byte sectors.I've enclosed a patch which fixes the problem, as well as simplifying the code by eliminating
compute_loop_size(), since it is a static function is only used once byfigure_loop_size().
Is there a historic reason why we pre-compute and store the loop device size instead of re-calculating it each time we do a BLKGETSZ ioctl? Re-calculating it each time allows you to increase the size of the backing file if needed while it is in use, and I don't think we actually get the size of the loop device very often, so it is not a big deal, especially given the simple calculation needed.
Cheers, Andreas
--
Andreas Dilger
http://www-mddsp.enel.ucalgary.ca/People/adilger/
http://sourceforge.net/projects/ext2resize/
Quoted 6 lines · Andreas Dilger
Is there a historic reason why we pre-compute and store the loop device size instead of re-calculating it each time we do a BLKGETSZ ioctl? Re-calculating it each time allows you to increase the size of the backing file if needed while it is in use, and I don't think we actually get the size of the loop device very often, so it is not a big deal, especially given the simple calculation needed.
We need to pre-compute the size because the block device layer wants to know how big devices were so it can do sanity checking on the incoming requests. This was done in the historically by setting blk_size[MAJOR_NR] to point to an array which contained the size of the minor devices in kilobytes, and in the new world order, via the set_capacity() call.
- Ted