Skip to content

Commit 781fc49

Browse files
Christoph Hellwigaxboe
authored andcommitted
loop: create a lo_can_use_dio helper
Factor out a part of __loop_update_dio in preparation for further refactoring. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20250110073750.1582447-4-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 4155adb commit 781fc49

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/block/loop.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,29 @@ static bool lo_bdev_can_use_dio(struct loop_device *lo,
182182
return true;
183183
}
184184

185-
static void __loop_update_dio(struct loop_device *lo, bool dio)
185+
static bool lo_can_use_dio(struct loop_device *lo)
186186
{
187-
struct file *file = lo->lo_backing_file;
188-
struct inode *inode = file->f_mapping->host;
189-
struct block_device *backing_bdev = NULL;
190-
bool use_dio;
187+
struct inode *inode = lo->lo_backing_file->f_mapping->host;
188+
189+
if (!(lo->lo_backing_file->f_mode & FMODE_CAN_ODIRECT))
190+
return false;
191191

192192
if (S_ISBLK(inode->i_mode))
193-
backing_bdev = I_BDEV(inode);
194-
else if (inode->i_sb->s_bdev)
195-
backing_bdev = inode->i_sb->s_bdev;
193+
return lo_bdev_can_use_dio(lo, I_BDEV(inode));
194+
if (inode->i_sb->s_bdev)
195+
return lo_bdev_can_use_dio(lo, inode->i_sb->s_bdev);
196+
return true;
197+
}
196198

197-
use_dio = dio && (file->f_mode & FMODE_CAN_ODIRECT) &&
198-
(!backing_bdev || lo_bdev_can_use_dio(lo, backing_bdev));
199+
static void __loop_update_dio(struct loop_device *lo, bool dio)
200+
{
201+
bool use_dio = dio && lo_can_use_dio(lo);
199202

200203
if (lo->use_dio == use_dio)
201204
return;
202205

203206
/* flush dirty pages before changing direct IO */
204-
vfs_fsync(file, 0);
207+
vfs_fsync(lo->lo_backing_file, 0);
205208

206209
/*
207210
* The flag of LO_FLAGS_DIRECT_IO is handled similarly with

0 commit comments

Comments
 (0)