linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] loop device broken in 2.5.38
@ 2002-09-25 17:35 tytso
  2002-09-25 18:03 ` Andreas Dilger
  0 siblings, 1 reply; 3+ messages in thread
From: tytso @ 2002-09-25 17:35 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel


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 =====
--- 1.57/drivers/block/loop.c	Sat Sep 21 02:08:48 2002
+++ edited/drivers/block/loop.c	Wed Sep 25 13:28:37 2002
@@ -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,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] loop device broken in 2.5.38
  2002-09-25 17:35 [PATCH] loop device broken in 2.5.38 tytso
@ 2002-09-25 18:03 ` Andreas Dilger
  2002-09-25 20:12   ` Theodore Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Dilger @ 2002-09-25 18:03 UTC (permalink / raw)
  To: tytso; +Cc: torvalds, linux-kernel

On Sep 25, 2002  13:35 -0400, tytso@mit.edu 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 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().

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/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] loop device broken in 2.5.38
  2002-09-25 18:03 ` Andreas Dilger
@ 2002-09-25 20:12   ` Theodore Ts'o
  0 siblings, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2002-09-25 20:12 UTC (permalink / raw)
  To: torvalds, linux-kernel

On Wed, Sep 25, 2002 at 12:03:55PM -0600, Andreas Dilger wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-09-25 20:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-25 17:35 [PATCH] loop device broken in 2.5.38 tytso
2002-09-25 18:03 ` Andreas Dilger
2002-09-25 20:12   ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).