*/
int loopcxt_setup_device(struct loopdev_cxt *lc)
{
- int file_fd, dev_fd, mode = O_RDWR, rc = -1, cnt = 0, err, again;
+ int file_fd, dev_fd, mode = O_RDWR, flags = O_CLOEXEC;
+ int rc = -1, cnt = 0, err, again;
int errsv = 0;
int fallback = 0;
if (lc->config.info.lo_flags & LO_FLAGS_READ_ONLY)
mode = O_RDONLY;
- if ((file_fd = open(lc->filename, mode | O_CLOEXEC)) < 0) {
+ if (lc->config.info.lo_flags & LO_FLAGS_DIRECT_IO)
+ flags |= O_DIRECT;
+
+ if ((file_fd = open(lc->filename, mode | flags)) < 0) {
if (mode != O_RDONLY && (errno == EROFS || errno == EACCES))
- file_fd = open(lc->filename, mode = O_RDONLY);
+ file_fd = open(lc->filename, (mode = O_RDONLY) | flags);
if (file_fd < 0) {
DBG(SETUP, ul_debugobj(lc, "open backing file failed: %m"));
use_dio = set_dio = 1;
if (optarg)
use_dio = parse_switch(optarg, _("argument error"), "on", "off", NULL);
+ if (use_dio)
+ lo_flags |= LO_FLAGS_DIRECT_IO;
break;
case 'v':
break;
if (showdev)
printf("%s\n", loopcxt_get_device(&lc));
warn_size(file, sizelimit, offset, flags);
- if (set_dio)
- goto lo_set_dio;
}
break;
case A_DELETE:
loopcxt_get_device(&lc));
break;
case A_SET_DIRECT_IO:
-lo_set_dio:
res = loopcxt_ioctl_dio(&lc, use_dio);
if (res)
warn(_("%s: set direct io failed"),