linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] loop devices from NFS broken in 2.5
@ 2002-10-06 22:36 Werner Almesberger
  0 siblings, 0 replies; only message in thread
From: Werner Almesberger @ 2002-10-06 22:36 UTC (permalink / raw)
  To: linux-kernel

2.5 kernels from ~2.5.24 up to 2.5.40 break loop devices using
files on NFS, because inode->i_sb->s_bdev is NULL, so you get
an oops in loop_set_fd, and recently also in loop_get_status.

The patch below fixes this, and I haven't found any ill
side-effects for non-NFS use. The patch is for 2.5.40.

This patch also removes redundant setting of LO_FLAGS_READ_ONLY

(I've posted a similar patch about three months ago. The only
new things now are the loop_get_status change, and that I'm a
little more confident that my solution works :-)

- Werner

---------------------------------- cut here -----------------------------------

--- linux-2.5.40.orig/drivers/block/loop.c	Tue Oct  1 04:07:04 2002
+++ linux-2.5.40/drivers/block/loop.c	Sun Oct  6 19:18:37 2002
@@ -333,7 +333,9 @@
 
 static inline int loop_get_bs(struct loop_device *lo)
 {
-	return block_size(lo->lo_device);
+	if (lo->lo_device)
+		return block_size(lo->lo_device);
+	return lo->lo_backing_file->f_dentry->d_inode->i_blksize;
 }
 
 static inline unsigned long loop_get_iv(struct loop_device *lo,
@@ -662,9 +664,6 @@
 	error = -EINVAL;
 	inode = file->f_dentry->d_inode;
 
-	if (!(file->f_mode & FMODE_WRITE))
-		lo_flags |= LO_FLAGS_READ_ONLY;
-
 	if (S_ISBLK(inode->i_mode)) {
 		lo_device = inode->i_bdev;
 		if (lo_device == bdev) {
@@ -691,7 +690,7 @@
 
 	get_file(file);
 
-	if (IS_RDONLY (inode) || bdev_read_only(lo_device)
+	if (IS_RDONLY (inode) || (lo_device && bdev_read_only(lo_device))
 	    || !(lo_file->f_mode & FMODE_WRITE))
 		lo_flags |= LO_FLAGS_READ_ONLY;
 
@@ -706,7 +705,7 @@
 	lo->old_gfp_mask = inode->i_mapping->gfp_mask;
 	inode->i_mapping->gfp_mask = GFP_NOIO;
 
-	set_blocksize(bdev, block_size(lo_device));
+	set_blocksize(bdev, loop_get_bs(lo));
 
 	lo->lo_bio = lo->lo_biotail = NULL;
 
@@ -878,7 +877,7 @@
 	info.lo_number = lo->lo_number;
 	info.lo_device = stat.dev;
 	info.lo_inode = stat.ino;
-	info.lo_rdevice = lo->lo_device->bd_dev;
+	info.lo_rdevice = lo->lo_device ? lo->lo_device->bd_dev : 0;
 	info.lo_offset = lo->lo_offset;
 	info.lo_flags = lo->lo_flags;
 	strncpy(info.lo_name, lo->lo_name, LO_NAME_SIZE);

-- 
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina         wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-06 22:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-06 22:36 [PATCH] loop devices from NFS broken in 2.5 Werner Almesberger

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).