loop.c (c6380ecd8e9bee7aba3d9a5a94b58168244c4a61) loop.c (8b904b5b6b58b9a29dcf3f82d936d9e7fd69fda6)
1/*
2 * linux/drivers/block/loop.c
3 *
4 * Written by Theodore Ts'o, 3/29/93
5 *
6 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is
7 * permitted under the GNU General Public License.
8 *

--- 200 unchanged lines hidden (view full) ---

209 /*
210 * The flag of LO_FLAGS_DIRECT_IO is handled similarly with
211 * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup
212 * will get updated by ioctl(LOOP_GET_STATUS)
213 */
214 blk_mq_freeze_queue(lo->lo_queue);
215 lo->use_dio = use_dio;
216 if (use_dio) {
1/*
2 * linux/drivers/block/loop.c
3 *
4 * Written by Theodore Ts'o, 3/29/93
5 *
6 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is
7 * permitted under the GNU General Public License.
8 *

--- 200 unchanged lines hidden (view full) ---

209 /*
210 * The flag of LO_FLAGS_DIRECT_IO is handled similarly with
211 * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup
212 * will get updated by ioctl(LOOP_GET_STATUS)
213 */
214 blk_mq_freeze_queue(lo->lo_queue);
215 lo->use_dio = use_dio;
216 if (use_dio) {
217 queue_flag_clear_unlocked(QUEUE_FLAG_NOMERGES, lo->lo_queue);
217 blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, lo->lo_queue);
218 lo->lo_flags |= LO_FLAGS_DIRECT_IO;
219 } else {
218 lo->lo_flags |= LO_FLAGS_DIRECT_IO;
219 } else {
220 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, lo->lo_queue);
220 blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue);
221 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
222 }
223 blk_mq_unfreeze_queue(lo->lo_queue);
224}
225
226static int
227figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit)
228{

--- 583 unchanged lines hidden (view full) ---

812 * useful information.
813 */
814 if ((!file->f_op->fallocate) ||
815 lo->lo_encrypt_key_size) {
816 q->limits.discard_granularity = 0;
817 q->limits.discard_alignment = 0;
818 blk_queue_max_discard_sectors(q, 0);
819 blk_queue_max_write_zeroes_sectors(q, 0);
221 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
222 }
223 blk_mq_unfreeze_queue(lo->lo_queue);
224}
225
226static int
227figure_loop_size(struct loop_device *lo, loff_t offset, loff_t sizelimit)
228{

--- 583 unchanged lines hidden (view full) ---

812 * useful information.
813 */
814 if ((!file->f_op->fallocate) ||
815 lo->lo_encrypt_key_size) {
816 q->limits.discard_granularity = 0;
817 q->limits.discard_alignment = 0;
818 blk_queue_max_discard_sectors(q, 0);
819 blk_queue_max_write_zeroes_sectors(q, 0);
820 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
820 blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
821 return;
822 }
823
824 q->limits.discard_granularity = inode->i_sb->s_blocksize;
825 q->limits.discard_alignment = 0;
826
827 blk_queue_max_discard_sectors(q, UINT_MAX >> 9);
828 blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> 9);
821 return;
822 }
823
824 q->limits.discard_granularity = inode->i_sb->s_blocksize;
825 q->limits.discard_alignment = 0;
826
827 blk_queue_max_discard_sectors(q, UINT_MAX >> 9);
828 blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> 9);
829 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
829 blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
830}
831
832static void loop_unprepare_queue(struct loop_device *lo)
833{
834 kthread_flush_worker(&lo->worker);
835 kthread_stop(lo->worker_task);
836}
837

--- 965 unchanged lines hidden (view full) ---

1803 blk_queue_max_hw_sectors(lo->lo_queue, BLK_DEF_MAX_SECTORS);
1804
1805 /*
1806 * By default, we do buffer IO, so it doesn't make sense to enable
1807 * merge because the I/O submitted to backing file is handled page by
1808 * page. For directio mode, merge does help to dispatch bigger request
1809 * to underlayer disk. We will enable merge once directio is enabled.
1810 */
830}
831
832static void loop_unprepare_queue(struct loop_device *lo)
833{
834 kthread_flush_worker(&lo->worker);
835 kthread_stop(lo->worker_task);
836}
837

--- 965 unchanged lines hidden (view full) ---

1803 blk_queue_max_hw_sectors(lo->lo_queue, BLK_DEF_MAX_SECTORS);
1804
1805 /*
1806 * By default, we do buffer IO, so it doesn't make sense to enable
1807 * merge because the I/O submitted to backing file is handled page by
1808 * page. For directio mode, merge does help to dispatch bigger request
1809 * to underlayer disk. We will enable merge once directio is enabled.
1810 */
1811 queue_flag_set_unlocked(QUEUE_FLAG_NOMERGES, lo->lo_queue);
1811 blk_queue_flag_set(QUEUE_FLAG_NOMERGES, lo->lo_queue);
1812
1813 err = -ENOMEM;
1814 disk = lo->lo_disk = alloc_disk(1 << part_shift);
1815 if (!disk)
1816 goto out_free_queue;
1817
1818 /*
1819 * Disable partition scanning by default. The in-kernel partition

--- 39 unchanged lines hidden (view full) ---

1859out_free_dev:
1860 kfree(lo);
1861out:
1862 return err;
1863}
1864
1865static void loop_remove(struct loop_device *lo)
1866{
1812
1813 err = -ENOMEM;
1814 disk = lo->lo_disk = alloc_disk(1 << part_shift);
1815 if (!disk)
1816 goto out_free_queue;
1817
1818 /*
1819 * Disable partition scanning by default. The in-kernel partition

--- 39 unchanged lines hidden (view full) ---

1859out_free_dev:
1860 kfree(lo);
1861out:
1862 return err;
1863}
1864
1865static void loop_remove(struct loop_device *lo)
1866{
1867 blk_cleanup_queue(lo->lo_queue);
1868 del_gendisk(lo->lo_disk);
1867 del_gendisk(lo->lo_disk);
1868 blk_cleanup_queue(lo->lo_queue);
1869 blk_mq_free_tag_set(&lo->tag_set);
1870 put_disk(lo->lo_disk);
1871 kfree(lo);
1872}
1873
1874static int find_free_cb(int id, void *ptr, void *data)
1875{
1876 struct loop_device *lo = ptr;

--- 230 unchanged lines hidden ---
1869 blk_mq_free_tag_set(&lo->tag_set);
1870 put_disk(lo->lo_disk);
1871 kfree(lo);
1872}
1873
1874static int find_free_cb(int id, void *ptr, void *data)
1875{
1876 struct loop_device *lo = ptr;

--- 230 unchanged lines hidden ---