Skip to content

Commit ab1cb27

Browse files
Ming Leiaxboe
authored andcommitted
block: loop: introduce ioctl command of LOOP_SET_DIRECT_IO
If loop block is mounted via 'mount -o loop', it isn't easy to pass file descriptor opened as O_DIRECT, so this patch introduces a new command to support direct IO for this case. Cc: [email protected] Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 2e5ab5f commit ab1cb27

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

drivers/block/loop.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,20 @@ static int loop_set_capacity(struct loop_device *lo, struct block_device *bdev)
12281228
return figure_loop_size(lo, lo->lo_offset, lo->lo_sizelimit);
12291229
}
12301230

1231+
static int loop_set_dio(struct loop_device *lo, unsigned long arg)
1232+
{
1233+
int error = -ENXIO;
1234+
if (lo->lo_state != Lo_bound)
1235+
goto out;
1236+
1237+
__loop_update_dio(lo, !!arg);
1238+
if (lo->use_dio == !!arg)
1239+
return 0;
1240+
error = -EINVAL;
1241+
out:
1242+
return error;
1243+
}
1244+
12311245
static int lo_ioctl(struct block_device *bdev, fmode_t mode,
12321246
unsigned int cmd, unsigned long arg)
12331247
{
@@ -1271,6 +1285,11 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
12711285
if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN))
12721286
err = loop_set_capacity(lo, bdev);
12731287
break;
1288+
case LOOP_SET_DIRECT_IO:
1289+
err = -EPERM;
1290+
if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN))
1291+
err = loop_set_dio(lo, arg);
1292+
break;
12741293
default:
12751294
err = lo->ioctl ? lo->ioctl(lo, cmd, arg) : -EINVAL;
12761295
}

include/uapi/linux/loop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct loop_info64 {
8787
#define LOOP_GET_STATUS64 0x4C05
8888
#define LOOP_CHANGE_FD 0x4C06
8989
#define LOOP_SET_CAPACITY 0x4C07
90+
#define LOOP_SET_DIRECT_IO 0x4C08
9091

9192
/* /dev/loop-control interface */
9293
#define LOOP_CTL_ADD 0x4C80

0 commit comments

Comments
 (0)