Lines Matching full:lo

102  * @lo: struct loop_device
103 * @global: true if @lo is about to bind another "struct loop_device", false otherwise
111 static int loop_global_lock_killable(struct loop_device *lo, bool global) in loop_global_lock_killable() argument
120 err = mutex_lock_killable(&lo->lo_mutex); in loop_global_lock_killable()
129 * @lo: struct loop_device
130 * @global: true if @lo was about to bind another "struct loop_device", false otherwise
132 static void loop_global_unlock(struct loop_device *lo, bool global) in loop_global_unlock() argument
134 mutex_unlock(&lo->lo_mutex); in loop_global_unlock()
163 static loff_t get_loop_size(struct loop_device *lo, struct file *file) in get_loop_size() argument
165 return get_size(lo->lo_offset, lo->lo_sizelimit, file); in get_loop_size()
173 static bool lo_bdev_can_use_dio(struct loop_device *lo, in lo_bdev_can_use_dio() argument
178 if (queue_logical_block_size(lo->lo_queue) < sb_bsize) in lo_bdev_can_use_dio()
180 if (lo->lo_offset & (sb_bsize - 1)) in lo_bdev_can_use_dio()
185 static void __loop_update_dio(struct loop_device *lo, bool dio) in __loop_update_dio() argument
187 struct file *file = lo->lo_backing_file; in __loop_update_dio()
198 (!backing_bdev || lo_bdev_can_use_dio(lo, backing_bdev)); in __loop_update_dio()
200 if (lo->use_dio == use_dio) in __loop_update_dio()
211 if (lo->lo_state == Lo_bound) in __loop_update_dio()
212 blk_mq_freeze_queue(lo->lo_queue); in __loop_update_dio()
213 lo->use_dio = use_dio; in __loop_update_dio()
215 lo->lo_flags |= LO_FLAGS_DIRECT_IO; in __loop_update_dio()
217 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; in __loop_update_dio()
218 if (lo->lo_state == Lo_bound) in __loop_update_dio()
219 blk_mq_unfreeze_queue(lo->lo_queue); in __loop_update_dio()
224 * @lo: struct loop_device to set the size for
230 static void loop_set_size(struct loop_device *lo, loff_t size) in loop_set_size() argument
232 if (!set_capacity_and_notify(lo->lo_disk, size)) in loop_set_size()
233 kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE); in loop_set_size()
256 static int lo_write_simple(struct loop_device *lo, struct request *rq, in lo_write_simple() argument
264 ret = lo_write_bvec(lo->lo_backing_file, &bvec, &pos); in lo_write_simple()
273 static int lo_read_simple(struct loop_device *lo, struct request *rq, in lo_read_simple() argument
283 len = vfs_iter_read(lo->lo_backing_file, &i, &pos, 0); in lo_read_simple()
302 static void loop_clear_limits(struct loop_device *lo, int mode) in loop_clear_limits() argument
304 struct queue_limits lim = queue_limits_start_update(lo->lo_queue); in loop_clear_limits()
314 queue_limits_commit_update(lo->lo_queue, &lim); in loop_clear_limits()
317 static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos, in lo_fallocate() argument
324 struct file *file = lo->lo_backing_file; in lo_fallocate()
329 if (!bdev_max_discard_sectors(lo->lo_device)) in lo_fallocate()
341 loop_clear_limits(lo, mode); in lo_fallocate()
346 static int lo_req_flush(struct loop_device *lo, struct request *rq) in lo_req_flush() argument
348 int ret = vfs_fsync(lo->lo_backing_file, 0); in lo_req_flush()
410 static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, in lo_rw_aio() argument
418 struct file *file = lo->lo_backing_file; in lo_rw_aio()
479 static int do_req_filebacked(struct loop_device *lo, struct request *rq) in do_req_filebacked() argument
482 loff_t pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset; in do_req_filebacked()
495 return lo_req_flush(lo, rq); in do_req_filebacked()
501 return lo_fallocate(lo, rq, pos, in do_req_filebacked()
506 return lo_fallocate(lo, rq, pos, FALLOC_FL_PUNCH_HOLE); in do_req_filebacked()
509 return lo_rw_aio(lo, cmd, pos, ITER_SOURCE); in do_req_filebacked()
511 return lo_write_simple(lo, rq, pos); in do_req_filebacked()
514 return lo_rw_aio(lo, cmd, pos, ITER_DEST); in do_req_filebacked()
516 return lo_read_simple(lo, rq, pos); in do_req_filebacked()
523 static inline void loop_update_dio(struct loop_device *lo) in loop_update_dio() argument
525 __loop_update_dio(lo, (lo->lo_backing_file->f_flags & O_DIRECT) | in loop_update_dio()
526 lo->use_dio); in loop_update_dio()
529 static void loop_reread_partitions(struct loop_device *lo) in loop_reread_partitions() argument
533 mutex_lock(&lo->lo_disk->open_mutex); in loop_reread_partitions()
534 rc = bdev_disk_changed(lo->lo_disk, false); in loop_reread_partitions()
535 mutex_unlock(&lo->lo_disk->open_mutex); in loop_reread_partitions()
538 __func__, lo->lo_number, lo->lo_file_name, rc); in loop_reread_partitions()
564 /* Order wrt setting lo->lo_backing_file in loop_configure(). */ in loop_validate_file()
581 static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, in loop_change_fd() argument
594 dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1); in loop_change_fd()
597 error = loop_global_lock_killable(lo, is_loop); in loop_change_fd()
601 if (lo->lo_state != Lo_bound) in loop_change_fd()
606 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY)) in loop_change_fd()
613 old_file = lo->lo_backing_file; in loop_change_fd()
618 if (get_loop_size(lo, file) != get_loop_size(lo, old_file)) in loop_change_fd()
622 disk_force_media_change(lo->lo_disk); in loop_change_fd()
623 blk_mq_freeze_queue(lo->lo_queue); in loop_change_fd()
624 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); in loop_change_fd()
625 lo->lo_backing_file = file; in loop_change_fd()
626 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping); in loop_change_fd()
628 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); in loop_change_fd()
629 loop_update_dio(lo); in loop_change_fd()
630 blk_mq_unfreeze_queue(lo->lo_queue); in loop_change_fd()
631 partscan = lo->lo_flags & LO_FLAGS_PARTSCAN; in loop_change_fd()
632 loop_global_unlock(lo, is_loop); in loop_change_fd()
649 loop_reread_partitions(lo); in loop_change_fd()
654 dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0); in loop_change_fd()
658 loop_global_unlock(lo, is_loop); in loop_change_fd()
670 struct loop_device *lo = disk->private_data; in loop_attr_show() local
672 return callback(lo, page); in loop_attr_show()
685 static ssize_t loop_attr_backing_file_show(struct loop_device *lo, char *buf) in loop_attr_backing_file_show() argument
690 spin_lock_irq(&lo->lo_lock); in loop_attr_backing_file_show()
691 if (lo->lo_backing_file) in loop_attr_backing_file_show()
692 p = file_path(lo->lo_backing_file, buf, PAGE_SIZE - 1); in loop_attr_backing_file_show()
693 spin_unlock_irq(&lo->lo_lock); in loop_attr_backing_file_show()
707 static ssize_t loop_attr_offset_show(struct loop_device *lo, char *buf) in loop_attr_offset_show() argument
709 return sysfs_emit(buf, "%llu\n", (unsigned long long)lo->lo_offset); in loop_attr_offset_show()
712 static ssize_t loop_attr_sizelimit_show(struct loop_device *lo, char *buf) in loop_attr_sizelimit_show() argument
714 return sysfs_emit(buf, "%llu\n", (unsigned long long)lo->lo_sizelimit); in loop_attr_sizelimit_show()
717 static ssize_t loop_attr_autoclear_show(struct loop_device *lo, char *buf) in loop_attr_autoclear_show() argument
719 int autoclear = (lo->lo_flags & LO_FLAGS_AUTOCLEAR); in loop_attr_autoclear_show()
724 static ssize_t loop_attr_partscan_show(struct loop_device *lo, char *buf) in loop_attr_partscan_show() argument
726 int partscan = (lo->lo_flags & LO_FLAGS_PARTSCAN); in loop_attr_partscan_show()
731 static ssize_t loop_attr_dio_show(struct loop_device *lo, char *buf) in loop_attr_dio_show() argument
733 int dio = (lo->lo_flags & LO_FLAGS_DIRECT_IO); in loop_attr_dio_show()
760 static void loop_sysfs_init(struct loop_device *lo) in loop_sysfs_init() argument
762 lo->sysfs_inited = !sysfs_create_group(&disk_to_dev(lo->lo_disk)->kobj, in loop_sysfs_init()
766 static void loop_sysfs_exit(struct loop_device *lo) in loop_sysfs_exit() argument
768 if (lo->sysfs_inited) in loop_sysfs_exit()
769 sysfs_remove_group(&disk_to_dev(lo->lo_disk)->kobj, in loop_sysfs_exit()
773 static void loop_config_discard(struct loop_device *lo, in loop_config_discard() argument
776 struct file *file = lo->lo_backing_file; in loop_config_discard()
817 struct loop_device *lo; member
836 static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd) in loop_queue_work() argument
843 spin_lock_irq(&lo->lo_work_lock); in loop_queue_work()
848 node = &lo->worker_tree.rb_node; in loop_queue_work()
883 worker->lo = lo; in loop_queue_work()
885 rb_insert_color(&worker->rb_node, &lo->worker_tree); in loop_queue_work()
898 work = &lo->rootcg_work; in loop_queue_work()
899 cmd_list = &lo->rootcg_cmd_list; in loop_queue_work()
902 queue_work(lo->workqueue, work); in loop_queue_work()
903 spin_unlock_irq(&lo->lo_work_lock); in loop_queue_work()
906 static void loop_set_timer(struct loop_device *lo) in loop_set_timer() argument
908 timer_reduce(&lo->timer, jiffies + LOOP_IDLE_WORKER_TIMEOUT); in loop_set_timer()
911 static void loop_free_idle_workers(struct loop_device *lo, bool delete_all) in loop_free_idle_workers() argument
915 spin_lock_irq(&lo->lo_work_lock); in loop_free_idle_workers()
916 list_for_each_entry_safe(worker, pos, &lo->idle_worker_list, in loop_free_idle_workers()
923 rb_erase(&worker->rb_node, &lo->worker_tree); in loop_free_idle_workers()
927 if (!list_empty(&lo->idle_worker_list)) in loop_free_idle_workers()
928 loop_set_timer(lo); in loop_free_idle_workers()
929 spin_unlock_irq(&lo->lo_work_lock); in loop_free_idle_workers()
934 struct loop_device *lo = container_of(timer, struct loop_device, timer); in loop_free_idle_workers_timer() local
936 return loop_free_idle_workers(lo, false); in loop_free_idle_workers_timer()
941 * @lo: struct loop_device to configure
948 loop_set_status_from_info(struct loop_device *lo, in loop_set_status_from_info() argument
971 lo->lo_offset = info->lo_offset; in loop_set_status_from_info()
972 lo->lo_sizelimit = info->lo_sizelimit; in loop_set_status_from_info()
974 memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); in loop_set_status_from_info()
975 lo->lo_file_name[LO_NAME_SIZE-1] = 0; in loop_set_status_from_info()
976 lo->lo_flags = info->lo_flags; in loop_set_status_from_info()
980 static unsigned short loop_default_blocksize(struct loop_device *lo, in loop_default_blocksize() argument
984 if ((lo->lo_backing_file->f_flags & O_DIRECT) && backing_bdev) in loop_default_blocksize()
989 static int loop_reconfigure_limits(struct loop_device *lo, unsigned short bsize) in loop_reconfigure_limits() argument
991 struct file *file = lo->lo_backing_file; in loop_reconfigure_limits()
1002 bsize = loop_default_blocksize(lo, backing_bdev); in loop_reconfigure_limits()
1004 lim = queue_limits_start_update(lo->lo_queue); in loop_reconfigure_limits()
1009 if (file->f_op->fsync && !(lo->lo_flags & LO_FLAGS_READ_ONLY)) in loop_reconfigure_limits()
1013 loop_config_discard(lo, &lim); in loop_reconfigure_limits()
1014 return queue_limits_commit_update(lo->lo_queue, &lim); in loop_reconfigure_limits()
1017 static int loop_configure(struct loop_device *lo, blk_mode_t mode, in loop_configure() argument
1045 error = loop_global_lock_killable(lo, is_loop); in loop_configure()
1050 if (lo->lo_state != Lo_unbound) in loop_configure()
1064 error = loop_set_status_from_info(lo, &config->info); in loop_configure()
1070 lo->lo_flags |= LO_FLAGS_READ_ONLY; in loop_configure()
1072 if (!lo->workqueue) { in loop_configure()
1073 lo->workqueue = alloc_workqueue("loop%d", in loop_configure()
1075 0, lo->lo_number); in loop_configure()
1076 if (!lo->workqueue) { in loop_configure()
1083 dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 1); in loop_configure()
1085 disk_force_media_change(lo->lo_disk); in loop_configure()
1086 set_disk_ro(lo->lo_disk, (lo->lo_flags & LO_FLAGS_READ_ONLY) != 0); in loop_configure()
1088 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO; in loop_configure()
1089 lo->lo_device = bdev; in loop_configure()
1090 lo->lo_backing_file = file; in loop_configure()
1091 lo->old_gfp_mask = mapping_gfp_mask(mapping); in loop_configure()
1092 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); in loop_configure()
1094 error = loop_reconfigure_limits(lo, config->block_size); in loop_configure()
1098 loop_update_dio(lo); in loop_configure()
1099 loop_sysfs_init(lo); in loop_configure()
1101 size = get_loop_size(lo, file); in loop_configure()
1102 loop_set_size(lo, size); in loop_configure()
1107 lo->lo_state = Lo_bound; in loop_configure()
1109 lo->lo_flags |= LO_FLAGS_PARTSCAN; in loop_configure()
1110 partscan = lo->lo_flags & LO_FLAGS_PARTSCAN; in loop_configure()
1112 clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state); in loop_configure()
1115 dev_set_uevent_suppress(disk_to_dev(lo->lo_disk), 0); in loop_configure()
1117 loop_global_unlock(lo, is_loop); in loop_configure()
1119 loop_reread_partitions(lo); in loop_configure()
1127 loop_global_unlock(lo, is_loop); in loop_configure()
1138 static void __loop_clr_fd(struct loop_device *lo) in __loop_clr_fd() argument
1142 gfp_t gfp = lo->old_gfp_mask; in __loop_clr_fd()
1144 spin_lock_irq(&lo->lo_lock); in __loop_clr_fd()
1145 filp = lo->lo_backing_file; in __loop_clr_fd()
1146 lo->lo_backing_file = NULL; in __loop_clr_fd()
1147 spin_unlock_irq(&lo->lo_lock); in __loop_clr_fd()
1149 lo->lo_device = NULL; in __loop_clr_fd()
1150 lo->lo_offset = 0; in __loop_clr_fd()
1151 lo->lo_sizelimit = 0; in __loop_clr_fd()
1152 memset(lo->lo_file_name, 0, LO_NAME_SIZE); in __loop_clr_fd()
1155 lim = queue_limits_start_update(lo->lo_queue); in __loop_clr_fd()
1159 queue_limits_commit_update(lo->lo_queue, &lim); in __loop_clr_fd()
1161 invalidate_disk(lo->lo_disk); in __loop_clr_fd()
1162 loop_sysfs_exit(lo); in __loop_clr_fd()
1164 kobject_uevent(&disk_to_dev(lo->lo_disk)->kobj, KOBJ_CHANGE); in __loop_clr_fd()
1169 disk_force_media_change(lo->lo_disk); in __loop_clr_fd()
1171 if (lo->lo_flags & LO_FLAGS_PARTSCAN) { in __loop_clr_fd()
1182 err = bdev_disk_changed(lo->lo_disk, false); in __loop_clr_fd()
1185 __func__, lo->lo_number, err); in __loop_clr_fd()
1190 * lo->lo_state is set to Lo_unbound here after above partscan has in __loop_clr_fd()
1193 * change the 'lo' device. in __loop_clr_fd()
1195 lo->lo_flags = 0; in __loop_clr_fd()
1197 set_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state); in __loop_clr_fd()
1198 mutex_lock(&lo->lo_mutex); in __loop_clr_fd()
1199 lo->lo_state = Lo_unbound; in __loop_clr_fd()
1200 mutex_unlock(&lo->lo_mutex); in __loop_clr_fd()
1210 static int loop_clr_fd(struct loop_device *lo) in loop_clr_fd() argument
1223 err = loop_global_lock_killable(lo, true); in loop_clr_fd()
1226 if (lo->lo_state != Lo_bound) { in loop_clr_fd()
1227 loop_global_unlock(lo, true); in loop_clr_fd()
1236 lo->lo_flags |= LO_FLAGS_AUTOCLEAR; in loop_clr_fd()
1237 if (disk_openers(lo->lo_disk) == 1) in loop_clr_fd()
1238 lo->lo_state = Lo_rundown; in loop_clr_fd()
1239 loop_global_unlock(lo, true); in loop_clr_fd()
1245 loop_set_status(struct loop_device *lo, const struct loop_info64 *info) in loop_set_status() argument
1252 err = mutex_lock_killable(&lo->lo_mutex); in loop_set_status()
1255 if (lo->lo_state != Lo_bound) { in loop_set_status()
1260 if (lo->lo_offset != info->lo_offset || in loop_set_status()
1261 lo->lo_sizelimit != info->lo_sizelimit) { in loop_set_status()
1263 sync_blockdev(lo->lo_device); in loop_set_status()
1264 invalidate_bdev(lo->lo_device); in loop_set_status()
1268 blk_mq_freeze_queue(lo->lo_queue); in loop_set_status()
1270 prev_lo_flags = lo->lo_flags; in loop_set_status()
1272 err = loop_set_status_from_info(lo, info); in loop_set_status()
1277 lo->lo_flags &= LOOP_SET_STATUS_SETTABLE_FLAGS; in loop_set_status()
1279 lo->lo_flags |= prev_lo_flags & ~LOOP_SET_STATUS_SETTABLE_FLAGS; in loop_set_status()
1281 lo->lo_flags |= prev_lo_flags & ~LOOP_SET_STATUS_CLEARABLE_FLAGS; in loop_set_status()
1284 loff_t new_size = get_size(lo->lo_offset, lo->lo_sizelimit, in loop_set_status()
1285 lo->lo_backing_file); in loop_set_status()
1286 loop_set_size(lo, new_size); in loop_set_status()
1290 __loop_update_dio(lo, lo->use_dio); in loop_set_status()
1293 blk_mq_unfreeze_queue(lo->lo_queue); in loop_set_status()
1295 if (!err && (lo->lo_flags & LO_FLAGS_PARTSCAN) && in loop_set_status()
1297 clear_bit(GD_SUPPRESS_PART_SCAN, &lo->lo_disk->state); in loop_set_status()
1301 mutex_unlock(&lo->lo_mutex); in loop_set_status()
1303 loop_reread_partitions(lo); in loop_set_status()
1309 loop_get_status(struct loop_device *lo, struct loop_info64 *info) in loop_get_status() argument
1315 ret = mutex_lock_killable(&lo->lo_mutex); in loop_get_status()
1318 if (lo->lo_state != Lo_bound) { in loop_get_status()
1319 mutex_unlock(&lo->lo_mutex); in loop_get_status()
1324 info->lo_number = lo->lo_number; in loop_get_status()
1325 info->lo_offset = lo->lo_offset; in loop_get_status()
1326 info->lo_sizelimit = lo->lo_sizelimit; in loop_get_status()
1327 info->lo_flags = lo->lo_flags; in loop_get_status()
1328 memcpy(info->lo_file_name, lo->lo_file_name, LO_NAME_SIZE); in loop_get_status()
1331 path = lo->lo_backing_file->f_path; in loop_get_status()
1333 mutex_unlock(&lo->lo_mutex); in loop_get_status()
1381 loop_set_status_old(struct loop_device *lo, const struct loop_info __user *arg) in loop_set_status_old() argument
1389 return loop_set_status(lo, &info64); in loop_set_status_old()
1393 loop_set_status64(struct loop_device *lo, const struct loop_info64 __user *arg) in loop_set_status64() argument
1399 return loop_set_status(lo, &info64); in loop_set_status64()
1403 loop_get_status_old(struct loop_device *lo, struct loop_info __user *arg) { in loop_get_status_old() argument
1410 err = loop_get_status(lo, &info64); in loop_get_status_old()
1420 loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) { in loop_get_status64() argument
1426 err = loop_get_status(lo, &info64); in loop_get_status64()
1433 static int loop_set_capacity(struct loop_device *lo) in loop_set_capacity() argument
1437 if (unlikely(lo->lo_state != Lo_bound)) in loop_set_capacity()
1440 size = get_loop_size(lo, lo->lo_backing_file); in loop_set_capacity()
1441 loop_set_size(lo, size); in loop_set_capacity()
1446 static int loop_set_dio(struct loop_device *lo, unsigned long arg) in loop_set_dio() argument
1449 if (lo->lo_state != Lo_bound) in loop_set_dio()
1452 __loop_update_dio(lo, !!arg); in loop_set_dio()
1453 if (lo->use_dio == !!arg) in loop_set_dio()
1460 static int loop_set_block_size(struct loop_device *lo, unsigned long arg) in loop_set_block_size() argument
1464 if (lo->lo_state != Lo_bound) in loop_set_block_size()
1467 if (lo->lo_queue->limits.logical_block_size == arg) in loop_set_block_size()
1470 sync_blockdev(lo->lo_device); in loop_set_block_size()
1471 invalidate_bdev(lo->lo_device); in loop_set_block_size()
1473 blk_mq_freeze_queue(lo->lo_queue); in loop_set_block_size()
1474 err = loop_reconfigure_limits(lo, arg); in loop_set_block_size()
1475 loop_update_dio(lo); in loop_set_block_size()
1476 blk_mq_unfreeze_queue(lo->lo_queue); in loop_set_block_size()
1481 static int lo_simple_ioctl(struct loop_device *lo, unsigned int cmd, in lo_simple_ioctl() argument
1486 err = mutex_lock_killable(&lo->lo_mutex); in lo_simple_ioctl()
1491 err = loop_set_capacity(lo); in lo_simple_ioctl()
1494 err = loop_set_dio(lo, arg); in lo_simple_ioctl()
1497 err = loop_set_block_size(lo, arg); in lo_simple_ioctl()
1502 mutex_unlock(&lo->lo_mutex); in lo_simple_ioctl()
1509 struct loop_device *lo = bdev->bd_disk->private_data; in lo_ioctl() local
1525 return loop_configure(lo, mode, bdev, &config); in lo_ioctl()
1533 return loop_configure(lo, mode, bdev, &config); in lo_ioctl()
1536 return loop_change_fd(lo, bdev, arg); in lo_ioctl()
1538 return loop_clr_fd(lo); in lo_ioctl()
1542 err = loop_set_status_old(lo, argp); in lo_ioctl()
1545 return loop_get_status_old(lo, argp); in lo_ioctl()
1549 err = loop_set_status64(lo, argp); in lo_ioctl()
1552 return loop_get_status64(lo, argp); in lo_ioctl()
1560 err = lo_simple_ioctl(lo, cmd, arg); in lo_ioctl()
1640 loop_set_status_compat(struct loop_device *lo, in loop_set_status_compat() argument
1649 return loop_set_status(lo, &info64); in loop_set_status_compat()
1653 loop_get_status_compat(struct loop_device *lo, in loop_get_status_compat() argument
1661 err = loop_get_status(lo, &info64); in loop_get_status_compat()
1670 struct loop_device *lo = bdev->bd_disk->private_data; in lo_compat_ioctl() local
1675 err = loop_set_status_compat(lo, in lo_compat_ioctl()
1679 err = loop_get_status_compat(lo, in lo_compat_ioctl()
1705 struct loop_device *lo = disk->private_data; in lo_open() local
1708 err = mutex_lock_killable(&lo->lo_mutex); in lo_open()
1712 if (lo->lo_state == Lo_deleting || lo->lo_state == Lo_rundown) in lo_open()
1714 mutex_unlock(&lo->lo_mutex); in lo_open()
1720 struct loop_device *lo = disk->private_data; in lo_release() local
1731 mutex_lock(&lo->lo_mutex); in lo_release()
1732 if (lo->lo_state == Lo_bound && (lo->lo_flags & LO_FLAGS_AUTOCLEAR)) in lo_release()
1733 lo->lo_state = Lo_rundown; in lo_release()
1735 need_clear = (lo->lo_state == Lo_rundown); in lo_release()
1736 mutex_unlock(&lo->lo_mutex); in lo_release()
1739 __loop_clr_fd(lo); in lo_release()
1744 struct loop_device *lo = disk->private_data; in lo_free_disk() local
1746 if (lo->workqueue) in lo_free_disk()
1747 destroy_workqueue(lo->workqueue); in lo_free_disk()
1748 loop_free_idle_workers(lo, true); in lo_free_disk()
1749 timer_shutdown_sync(&lo->timer); in lo_free_disk()
1750 mutex_destroy(&lo->lo_mutex); in lo_free_disk()
1751 kfree(lo); in lo_free_disk()
1844 struct loop_device *lo = rq->q->queuedata; in loop_queue_rq() local
1848 if (lo->lo_state != Lo_bound) in loop_queue_rq()
1858 cmd->use_aio = lo->use_dio; in loop_queue_rq()
1877 loop_queue_work(lo, cmd); in loop_queue_rq()
1888 struct loop_device *lo = rq->q->queuedata; in loop_handle_cmd() local
1893 if (write && (lo->lo_flags & LO_FLAGS_READ_ONLY)) { in loop_handle_cmd()
1910 ret = do_req_filebacked(lo, rq); in loop_handle_cmd()
1932 struct list_head *cmd_list, struct loop_device *lo) in loop_process_work() argument
1938 spin_lock_irq(&lo->lo_work_lock); in loop_process_work()
1943 spin_unlock_irq(&lo->lo_work_lock); in loop_process_work()
1948 spin_lock_irq(&lo->lo_work_lock); in loop_process_work()
1958 list_add_tail(&worker->idle_list, &lo->idle_worker_list); in loop_process_work()
1959 loop_set_timer(lo); in loop_process_work()
1961 spin_unlock_irq(&lo->lo_work_lock); in loop_process_work()
1969 loop_process_work(worker, &worker->cmd_list, worker->lo); in loop_workfn()
1974 struct loop_device *lo = in loop_rootcg_workfn() local
1976 loop_process_work(NULL, &lo->rootcg_cmd_list, lo); in loop_rootcg_workfn()
1992 struct loop_device *lo; in loop_add() local
1997 lo = kzalloc(sizeof(*lo), GFP_KERNEL); in loop_add()
1998 if (!lo) in loop_add()
2000 lo->worker_tree = RB_ROOT; in loop_add()
2001 INIT_LIST_HEAD(&lo->idle_worker_list); in loop_add()
2002 timer_setup(&lo->timer, loop_free_idle_workers_timer, TIMER_DEFERRABLE); in loop_add()
2003 lo->lo_state = Lo_unbound; in loop_add()
2011 err = idr_alloc(&loop_index_idr, lo, i, i + 1, GFP_KERNEL); in loop_add()
2015 err = idr_alloc(&loop_index_idr, lo, 0, 0, GFP_KERNEL); in loop_add()
2022 lo->tag_set.ops = &loop_mq_ops; in loop_add()
2023 lo->tag_set.nr_hw_queues = 1; in loop_add()
2024 lo->tag_set.queue_depth = hw_queue_depth; in loop_add()
2025 lo->tag_set.numa_node = NUMA_NO_NODE; in loop_add()
2026 lo->tag_set.cmd_size = sizeof(struct loop_cmd); in loop_add()
2027 lo->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_STACKING | in loop_add()
2029 lo->tag_set.driver_data = lo; in loop_add()
2031 err = blk_mq_alloc_tag_set(&lo->tag_set); in loop_add()
2035 disk = lo->lo_disk = blk_mq_alloc_disk(&lo->tag_set, &lim, lo); in loop_add()
2040 lo->lo_queue = lo->lo_disk->queue; in loop_add()
2062 mutex_init(&lo->lo_mutex); in loop_add()
2063 lo->lo_number = i; in loop_add()
2064 spin_lock_init(&lo->lo_lock); in loop_add()
2065 spin_lock_init(&lo->lo_work_lock); in loop_add()
2066 INIT_WORK(&lo->rootcg_work, loop_rootcg_workfn); in loop_add()
2067 INIT_LIST_HEAD(&lo->rootcg_cmd_list); in loop_add()
2072 disk->private_data = lo; in loop_add()
2073 disk->queue = lo->lo_queue; in loop_add()
2084 lo->idr_visible = true; in loop_add()
2092 blk_mq_free_tag_set(&lo->tag_set); in loop_add()
2098 kfree(lo); in loop_add()
2103 static void loop_remove(struct loop_device *lo) in loop_remove() argument
2106 del_gendisk(lo->lo_disk); in loop_remove()
2107 blk_mq_free_tag_set(&lo->tag_set); in loop_remove()
2110 idr_remove(&loop_index_idr, lo->lo_number); in loop_remove()
2113 put_disk(lo->lo_disk); in loop_remove()
2131 struct loop_device *lo; in loop_control_remove() local
2143 lo = idr_find(&loop_index_idr, idx); in loop_control_remove()
2144 if (!lo || !lo->idr_visible) in loop_control_remove()
2147 lo->idr_visible = false; in loop_control_remove()
2153 ret = mutex_lock_killable(&lo->lo_mutex); in loop_control_remove()
2156 if (lo->lo_state != Lo_unbound || disk_openers(lo->lo_disk) > 0) { in loop_control_remove()
2157 mutex_unlock(&lo->lo_mutex); in loop_control_remove()
2162 lo->lo_state = Lo_deleting; in loop_control_remove()
2163 mutex_unlock(&lo->lo_mutex); in loop_control_remove()
2165 loop_remove(lo); in loop_control_remove()
2171 lo->idr_visible = true; in loop_control_remove()
2178 struct loop_device *lo; in loop_control_get_free() local
2184 idr_for_each_entry(&loop_index_idr, lo, id) { in loop_control_get_free()
2186 if (lo->idr_visible && data_race(lo->lo_state) == Lo_unbound) in loop_control_get_free()
2283 struct loop_device *lo; in loop_exit() local
2295 idr_for_each_entry(&loop_index_idr, lo, id) in loop_exit()
2296 loop_remove(lo); in loop_exit()