losetup: support ioctl cmd of LOOP_SET_DIRECT_IO

From v4.4, linux kernel starts to support direct I/O and
AIO to backing file for loop driver, so allow losetup to
enable the feature by using LOOP_SET_DIRECT_IO ioctl cmd.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
This commit is contained in:
Ming Lei 2015-11-17 22:32:47 +08:00 committed by Karel Zak
parent 710dd49239
commit 64c3bb3cb7
3 changed files with 45 additions and 2 deletions

View file

@ -1315,6 +1315,24 @@ int loopcxt_set_capacity(struct loopdev_cxt *lc)
return 0;
}
int loopcxt_set_dio(struct loopdev_cxt *lc, unsigned long use_dio)
{
int fd = loopcxt_get_fd(lc);
if (fd < 0)
return -EINVAL;
/* Kernels prior to v4.4 don't support this ioctl */
if (ioctl(fd, LOOP_SET_DIRECT_IO, use_dio) < 0) {
int rc = -errno;
DBG(CXT, ul_debugobj(lc, "LOOP_SET_DIRECT_IO failed: %m"));
return rc;
}
DBG(CXT, ul_debugobj(lc, "direct io set"));
return 0;
}
int loopcxt_delete_device(struct loopdev_cxt *lc)
{
int fd = loopcxt_get_fd(lc);