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: open code the direct I/O flag update in loop_set_dio

loop_set_dio is different from the other (__)loop_update_dio callers in
that it doesn't take any implicit conditions into account and wants to
update the direct I/O flag to the user passed in value and fail if that
can't be done.

Open code the logic here to prepare for simplifying the other direct I/O
flag updates and to make the error handling less convoluted.

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

authored by

Christoph Hellwig and committed by
Jens Axboe
dc909525 09ccf554

+20 -8
+20 -8
drivers/block/loop.c
··· 1455 1455 1456 1456 static int loop_set_dio(struct loop_device *lo, unsigned long arg) 1457 1457 { 1458 - int error = -ENXIO; 1459 - if (lo->lo_state != Lo_bound) 1460 - goto out; 1458 + bool use_dio = !!arg; 1461 1459 1462 - __loop_update_dio(lo, !!arg); 1463 - if (lo->use_dio == !!arg) 1460 + if (lo->lo_state != Lo_bound) 1461 + return -ENXIO; 1462 + if (use_dio == lo->use_dio) 1464 1463 return 0; 1465 - error = -EINVAL; 1466 - out: 1467 - return error; 1464 + 1465 + if (use_dio) { 1466 + if (!lo_can_use_dio(lo)) 1467 + return -EINVAL; 1468 + /* flush dirty pages before starting to use direct I/O */ 1469 + vfs_fsync(lo->lo_backing_file, 0); 1470 + } 1471 + 1472 + blk_mq_freeze_queue(lo->lo_queue); 1473 + lo->use_dio = use_dio; 1474 + if (use_dio) 1475 + lo->lo_flags |= LO_FLAGS_DIRECT_IO; 1476 + else 1477 + lo->lo_flags &= ~LO_FLAGS_DIRECT_IO; 1478 + blk_mq_unfreeze_queue(lo->lo_queue); 1479 + return 0; 1468 1480 } 1469 1481 1470 1482 static int loop_set_block_size(struct loop_device *lo, unsigned long arg)