From eefe85ee350ece1bdf3e9a61e941d3394a528660 Mon Sep 17 00:00:00 2001 From: Constantine Sapuntzakis Date: Fri, 23 Jun 2006 02:06:08 -0700 Subject: [PATCH] drivers/block/loop.c: don't return garbage if LOOP_SET_STATUS not called While writing a version of losetup, I ran into the problem that the loop device was returning total garbage. It turns out the problem was that this losetup was only issuing the LOOP_SET_FD ioctl and not issuing a subsequent LOOP_SET_STATUS ioctl. This losetup didn't have any special status to set, so it left out the call. The deeper cause is that loop_set_fd sets the transfer function to NULL, which causes no transfer to happen lo_do_transfer. This patch fixes the problem by setting transfer to transfer_none in loop_set_fd. Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 9c3b94e8f03..3c74ea729fc 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -818,7 +818,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, lo->lo_device = bdev; lo->lo_flags = lo_flags; lo->lo_backing_file = file; - lo->transfer = NULL; + lo->transfer = transfer_none; lo->ioctl = NULL; lo->lo_sizelimit = 0; lo->old_gfp_mask = mapping_gfp_mask(mapping); -- cgit v1.2.3-18-g5258 From c7b2eff059fcc2d1b7085ee3d84b79fd657a537b Mon Sep 17 00:00:00 2001 From: "Serge E. Hallyn" Date: Sun, 25 Jun 2006 05:48:59 -0700 Subject: [PATCH] kthread: update loop.c to use kthread Update loop.c to use a kthread instead of a deprecated kernel_thread for loop devices. [akpm@osdl.org: don't change the thread's name] Signed-off-by: Serge E. Hallyn Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/loop.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 3c74ea729fc..9dc294a7495 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -74,6 +74,7 @@ #include #include #include +#include #include @@ -578,8 +579,6 @@ static int loop_thread(void *data) struct loop_device *lo = data; struct bio *bio; - daemonize("loop%d", lo->lo_number); - /* * loop can be used in an encrypted device, * hence, it mustn't be stopped at all @@ -592,11 +591,6 @@ static int loop_thread(void *data) lo->lo_state = Lo_bound; lo->lo_pending = 1; - /* - * complete it, we are running - */ - complete(&lo->lo_done); - for (;;) { int pending; @@ -629,7 +623,6 @@ static int loop_thread(void *data) break; } - complete(&lo->lo_done); return 0; } @@ -746,6 +739,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, unsigned lo_blocksize; int lo_flags = 0; int error; + struct task_struct *tsk; loff_t size; /* This is safe, since we have a reference from open(). */ @@ -839,10 +833,11 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, set_blocksize(bdev, lo_blocksize); - error = kernel_thread(loop_thread, lo, CLONE_KERNEL); - if (error < 0) + tsk = kthread_run(loop_thread, lo, "loop%d", lo->lo_number); + if (IS_ERR(tsk)) { + error = PTR_ERR(tsk); goto out_putf; - wait_for_completion(&lo->lo_done); + } return 0; out_putf: @@ -898,6 +893,9 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) if (lo->lo_state != Lo_bound) return -ENXIO; + if (!lo->lo_thread) + return -EINVAL; + if (lo->lo_refcnt > 1) /* we needed one fd for the ioctl */ return -EBUSY; @@ -911,7 +909,7 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) complete(&lo->lo_bh_done); spin_unlock_irq(&lo->lo_lock); - wait_for_completion(&lo->lo_done); + kthread_stop(lo->lo_thread); lo->lo_backing_file = NULL; @@ -924,6 +922,7 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) lo->lo_sizelimit = 0; lo->lo_encrypt_key_size = 0; lo->lo_flags = 0; + lo->lo_thread = NULL; memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); memset(lo->lo_file_name, 0, LO_NAME_SIZE); @@ -1288,7 +1287,6 @@ static int __init loop_init(void) if (!lo->lo_queue) goto out_mem4; mutex_init(&lo->lo_ctl_mutex); - init_completion(&lo->lo_done); init_completion(&lo->lo_bh_done); lo->lo_number = i; spin_lock_init(&lo->lo_lock); -- cgit v1.2.3-18-g5258 From 09c0dc68625c06f5b1e786aad0d5369b592179e6 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Mon, 26 Jun 2006 11:55:42 -0700 Subject: Revert "[PATCH] kthread: update loop.c to use kthread" This reverts commit c7b2eff059fcc2d1b7085ee3d84b79fd657a537b. Hugh Dickins explains: "It seems too little tested: "losetup -d /dev/loop0" fails with EINVAL because nothing sets lo_thread; but even when you patch loop_thread() to set lo->lo_thread = current, it can't survive more than a few dozen iterations of the loop below (with a tmpfs mounted on /tst): j=0 cp /dev/zero /tst while : do let j=j+1 echo "Doing pass $j" losetup /dev/loop0 /tst/zero mkfs -t ext2 -b 1024 /dev/loop0 >/dev/null 2>&1 mount -t ext2 /dev/loop0 /mnt umount /mnt losetup -d /dev/loop0 done it collapses with failed ioctl then BUG_ON(!bio). I think the original lo_done completion was more subtle and safe than the kthread conversion has allowed for." Signed-off-by: Linus Torvalds --- drivers/block/loop.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 9dc294a7495..3c74ea729fc 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -74,7 +74,6 @@ #include #include #include -#include #include @@ -579,6 +578,8 @@ static int loop_thread(void *data) struct loop_device *lo = data; struct bio *bio; + daemonize("loop%d", lo->lo_number); + /* * loop can be used in an encrypted device, * hence, it mustn't be stopped at all @@ -591,6 +592,11 @@ static int loop_thread(void *data) lo->lo_state = Lo_bound; lo->lo_pending = 1; + /* + * complete it, we are running + */ + complete(&lo->lo_done); + for (;;) { int pending; @@ -623,6 +629,7 @@ static int loop_thread(void *data) break; } + complete(&lo->lo_done); return 0; } @@ -739,7 +746,6 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, unsigned lo_blocksize; int lo_flags = 0; int error; - struct task_struct *tsk; loff_t size; /* This is safe, since we have a reference from open(). */ @@ -833,11 +839,10 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, set_blocksize(bdev, lo_blocksize); - tsk = kthread_run(loop_thread, lo, "loop%d", lo->lo_number); - if (IS_ERR(tsk)) { - error = PTR_ERR(tsk); + error = kernel_thread(loop_thread, lo, CLONE_KERNEL); + if (error < 0) goto out_putf; - } + wait_for_completion(&lo->lo_done); return 0; out_putf: @@ -893,9 +898,6 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) if (lo->lo_state != Lo_bound) return -ENXIO; - if (!lo->lo_thread) - return -EINVAL; - if (lo->lo_refcnt > 1) /* we needed one fd for the ioctl */ return -EBUSY; @@ -909,7 +911,7 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) complete(&lo->lo_bh_done); spin_unlock_irq(&lo->lo_lock); - kthread_stop(lo->lo_thread); + wait_for_completion(&lo->lo_done); lo->lo_backing_file = NULL; @@ -922,7 +924,6 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) lo->lo_sizelimit = 0; lo->lo_encrypt_key_size = 0; lo->lo_flags = 0; - lo->lo_thread = NULL; memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); memset(lo->lo_file_name, 0, LO_NAME_SIZE); @@ -1287,6 +1288,7 @@ static int __init loop_init(void) if (!lo->lo_queue) goto out_mem4; mutex_init(&lo->lo_ctl_mutex); + init_completion(&lo->lo_done); init_completion(&lo->lo_bh_done); lo->lo_number = i; spin_lock_init(&lo->lo_lock); -- cgit v1.2.3-18-g5258 From 95dc112a5770dc670a1b45a3d9ee346fdd2b2697 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 20 Jun 2005 21:15:16 -0700 Subject: [PATCH] devfs: Remove devfs_mk_dir() function from the kernel tree Removes the devfs_mk_dir() function and all callers of it. Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 3c74ea729fc..f650d20f2a1 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1277,8 +1277,6 @@ static int __init loop_init(void) goto out_mem3; } - devfs_mk_dir("loop"); - for (i = 0; i < max_loop; i++) { struct loop_device *lo = &loop_dev[i]; struct gendisk *disk = disks[i]; -- cgit v1.2.3-18-g5258 From 8ab5e4c15b53e147c08031a959d9f776823dbe73 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 20 Jun 2005 21:15:16 -0700 Subject: [PATCH] devfs: Remove devfs_remove() function from the kernel tree Removes the devfs_remove() function and all callers of it. Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index f650d20f2a1..0319b096b55 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1308,7 +1308,6 @@ static int __init loop_init(void) out_mem4: while (i--) blk_cleanup_queue(loop_dev[i].lo_queue); - devfs_remove("loop"); i = max_loop; out_mem3: while (i--) @@ -1331,7 +1330,6 @@ static void loop_exit(void) blk_cleanup_queue(loop_dev[i].lo_queue); put_disk(disks[i]); } - devfs_remove("loop"); if (unregister_blkdev(LOOP_MAJOR, "loop")) printk(KERN_WARNING "loop: cannot unregister blkdev\n"); -- cgit v1.2.3-18-g5258 From ff23eca3e8f613034e0d20ff86f6a89b62f5a14e Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 20 Jun 2005 21:15:16 -0700 Subject: [PATCH] devfs: Remove the devfs_fs_kernel.h file from the tree Also fixes up all files that #include it. Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 0319b096b55..dbf905ce024 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -63,7 +63,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3-18-g5258 From ce7b0f46bbf4bff8daab2dd3d878b9e72a623d09 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 20 Jun 2005 21:15:16 -0700 Subject: [PATCH] devfs: Remove the gendisk devfs_name field as it's no longer needed And remove the now unneeded number field. Also fixes all drivers that set these fields. Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index dbf905ce024..9983e720021 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1293,7 +1293,6 @@ static int __init loop_init(void) disk->first_minor = i; disk->fops = &lo_fops; sprintf(disk->disk_name, "loop%d", i); - sprintf(disk->devfs_name, "loop/%d", i); disk->private_data = lo; disk->queue = lo->lo_queue; } -- cgit v1.2.3-18-g5258 From f5e54d6e53a20cef45af7499e86164f0e0d16bb2 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 28 Jun 2006 04:26:44 -0700 Subject: [PATCH] mark address_space_operations const Same as with already do with the file operations: keep them in .rodata and prevents people from doing runtime patching. Signed-off-by: Christoph Hellwig Cc: Steven French Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/loop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 3c74ea729fc..18dd026f470 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -210,7 +210,7 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec, { struct file *file = lo->lo_backing_file; /* kudos to NFsckingS */ struct address_space *mapping = file->f_mapping; - struct address_space_operations *aops = mapping->a_ops; + const struct address_space_operations *aops = mapping->a_ops; pgoff_t index; unsigned offset, bv_offs; int len, ret; @@ -784,7 +784,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file, error = -EINVAL; if (S_ISREG(inode->i_mode) || S_ISBLK(inode->i_mode)) { - struct address_space_operations *aops = mapping->a_ops; + const struct address_space_operations *aops = mapping->a_ops; /* * If we can't read - sorry. If we only can't write - well, * it's going to be read-only. -- cgit v1.2.3-18-g5258 From 6ab3d5624e172c553004ecc862bfeac16d9d68b7 Mon Sep 17 00:00:00 2001 From: Jörn Engel Date: Fri, 30 Jun 2006 19:25:36 +0200 Subject: Remove obsolete #include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Engel Signed-off-by: Adrian Bunk --- drivers/block/loop.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/block/loop.c') diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 013c5daddb0..7b3b94ddddc 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -50,7 +50,6 @@ * */ -#include #include #include #include -- cgit v1.2.3-18-g5258