Skip to contentSkip to conversation

loop devices from NFS broken in recent 2.5

PATCH New Werner Almesberger 1 participant 1 message Jun 25, 2002 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 loop devices from NFS broken in recent 2.5

Recent 2.5 kernels break loop devices using files on NFS, because inode->i_sb->s_bdev is NULL, so you get an oops in loop_set_fd.

The patch below fixes this. Note that I'm not entirely sure whether using i_blksize is really correct. The patch is for 2.5.24.

This patch also removes redundant setting of LO_FLAGS_READ_ONLY

- Werner

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

block/loop.c renamed from block/loop.c.orig +6 -6
@@ -336,7 +336,10 @@ lo_receive(struct loop_device *lo, struc
 
 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);
+	/* @@@ is this correct ? */
+	return lo->lo_backing_file->f_dentry->d_inode->i_blksize;
 }
 
 static inline unsigned long loop_get_iv(struct loop_device *lo,
@@ -662,9 +665,6 @@ static int loop_set_fd(struct loop_devic
 	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 +691,7 @@ static int loop_set_fd(struct loop_devic
 
 	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 +706,7 @@ static int loop_set_fd(struct loop_devic
 	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;
 	kernel_thread(loop_thread, lo, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
Signature · 3 lines
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina         [email protected] /
/_http://icapeople.epfl.ch/almesber/_____________________________________/