Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

loop: remove the use_dio field in struct loop_device

This field duplicate the LO_FLAGS_DIRECT_IO flag in lo_flags. Remove it
to have a single source of truth about using direct I/O.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250110073750.1582447-9-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
afd69d5c 0cd719aa

+17 -22
+17 -22
drivers/block/loop.c
··· 68 68 struct list_head idle_worker_list; 69 69 struct rb_root worker_tree; 70 70 struct timer_list timer; 71 - bool use_dio; 72 71 bool sysfs_inited; 73 72 74 73 struct request_queue *lo_queue; ··· 195 196 return true; 196 197 } 197 198 199 + /* 200 + * Direct I/O can be enabled either by using an O_DIRECT file descriptor, or by 201 + * passing in the LO_FLAGS_DIRECT_IO flag from userspace. It will be silently 202 + * disabled when the device block size is too small or the offset is unaligned. 203 + * 204 + * loop_get_status will always report the effective LO_FLAGS_DIRECT_IO flag and 205 + * not the originally passed in one. 206 + */ 198 207 static inline void loop_update_dio(struct loop_device *lo) 199 208 { 200 - bool dio = lo->use_dio || (lo->lo_backing_file->f_flags & O_DIRECT); 201 - bool use_dio = dio && lo_can_use_dio(lo); 209 + bool dio_in_use = lo->lo_flags & LO_FLAGS_DIRECT_IO; 202 210 203 211 lockdep_assert_held(&lo->lo_mutex); 204 212 WARN_ON_ONCE(lo->lo_state == Lo_bound && 205 213 lo->lo_queue->mq_freeze_depth == 0); 206 214 207 - if (lo->use_dio == use_dio) 208 - return; 209 - 210 - /* flush dirty pages before starting to use direct I/O */ 211 - if (use_dio) 212 - vfs_fsync(lo->lo_backing_file, 0); 213 - 214 - /* 215 - * The flag of LO_FLAGS_DIRECT_IO is handled similarly with 216 - * LO_FLAGS_READ_ONLY, both are set from kernel, and losetup 217 - * will get updated by ioctl(LOOP_GET_STATUS) 218 - */ 219 - lo->use_dio = use_dio; 220 - if (use_dio) 215 + if (lo->lo_backing_file->f_flags & O_DIRECT) 221 216 lo->lo_flags |= LO_FLAGS_DIRECT_IO; 222 - else 217 + if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !lo_can_use_dio(lo)) 223 218 lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; 219 + 220 + /* flush dirty pages before starting to issue direct I/O */ 221 + if ((lo->lo_flags & LO_FLAGS_DIRECT_IO) && !dio_in_use) 222 + vfs_fsync(lo->lo_backing_file, 0); 224 223 } 225 224 226 225 /** ··· 1086 1089 disk_force_media_change(lo->lo_disk); 1087 1090 set_disk_ro(lo->lo_disk, (lo->lo_flags & LO_FLAGS_READ_ONLY) != 0); 1088 1091 1089 - lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO; 1090 1092 lo->lo_device = bdev; 1091 1093 lo->lo_backing_file = file; 1092 1094 lo->old_gfp_mask = mapping_gfp_mask(mapping); ··· 1450 1454 1451 1455 if (lo->lo_state != Lo_bound) 1452 1456 return -ENXIO; 1453 - if (use_dio == lo->use_dio) 1457 + if (use_dio == !!(lo->lo_flags & LO_FLAGS_DIRECT_IO)) 1454 1458 return 0; 1455 1459 1456 1460 if (use_dio) { ··· 1461 1465 } 1462 1466 1463 1467 blk_mq_freeze_queue(lo->lo_queue); 1464 - lo->use_dio = use_dio; 1465 1468 if (use_dio) 1466 1469 lo->lo_flags |= LO_FLAGS_DIRECT_IO; 1467 1470 else ··· 1871 1876 cmd->use_aio = false; 1872 1877 break; 1873 1878 default: 1874 - cmd->use_aio = lo->use_dio; 1879 + cmd->use_aio = lo->lo_flags & LO_FLAGS_DIRECT_IO; 1875 1880 break; 1876 1881 } 1877 1882