]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
loop: fix LO_FLAGS_PARTSCAN hang
authorOmar Sandoval <osandov@fb.com>
Wed, 1 Mar 2017 18:42:38 +0000 (10:42 -0800)
committerTim Gardner <tim.gardner@canonical.com>
Mon, 13 Mar 2017 21:20:54 +0000 (15:20 -0600)
BugLink: http://bugs.launchpad.net/bugs/1672544
commit e02898b423802b1f3a3aaa7f16e896da069ba8f7 upstream.

loop_reread_partitions() needs to do I/O, but we just froze the queue,
so we end up waiting forever. This can easily be reproduced with losetup
-P. Fix it by moving the reread to after we unfreeze the queue.

Fixes: ecdd09597a57 ("block/loop: fix race between I/O and set_status")
Reported-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Reviewed-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
drivers/block/loop.c

index cb7025ce82ec71c6faca835f25ece33a64f50976..fa7cee0241ca00e94012640cfbd7ab01ddffd988 100644 (file)
@@ -1160,13 +1160,6 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
             (info->lo_flags & LO_FLAGS_AUTOCLEAR))
                lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
 
-       if ((info->lo_flags & LO_FLAGS_PARTSCAN) &&
-            !(lo->lo_flags & LO_FLAGS_PARTSCAN)) {
-               lo->lo_flags |= LO_FLAGS_PARTSCAN;
-               lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN;
-               loop_reread_partitions(lo, lo->lo_device);
-       }
-
        lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
        lo->lo_init[0] = info->lo_init[0];
        lo->lo_init[1] = info->lo_init[1];
@@ -1181,6 +1174,14 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
 
  exit:
        blk_mq_unfreeze_queue(lo->lo_queue);
+
+       if (!err && (info->lo_flags & LO_FLAGS_PARTSCAN) &&
+            !(lo->lo_flags & LO_FLAGS_PARTSCAN)) {
+               lo->lo_flags |= LO_FLAGS_PARTSCAN;
+               lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN;
+               loop_reread_partitions(lo, lo->lo_device);
+       }
+
        return err;
 }