From: Karel Zak Date: Wed, 9 Mar 2022 10:13:26 +0000 (+0100) Subject: losetup: fix --direct-io X-Git-Tag: v2.38-rc3~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b3bb7da681abfcbbbd2cf75f23ab527ce5c8d51;p=thirdparty%2Futil-linux.git losetup: fix --direct-io losetup checks for empty lo_flags when A_CREATE (action) is not requested, otherwise it prints "the options %s are allowed during loop device setup only" error message. We need to cleanup lo_flags when alone --direct-io requested. Fix also typo in man page, "losetup --direct-io" is the same as "losetup --direct-io=on". Signed-off-by: Karel Zak --- diff --git a/sys-utils/losetup.8.adoc b/sys-utils/losetup.8.adoc index 075d079fd1..0dc58fe65b 100644 --- a/sys-utils/losetup.8.adoc +++ b/sys-utils/losetup.8.adoc @@ -90,7 +90,7 @@ Force the kernel to scan the partition table on a newly created loop device. Not Set up a read-only loop device. *--direct-io*[**=on**|*off*]:: -Enable or disable direct I/O for the backing file. The optional argument can be either *on* or *off*. If the argument is omitted, it defaults to *off*. +Enable or disable direct I/O for the backing file. The optional argument can be either *on* or *off*. If the optional argument is omitted, it defaults to *on*. *-v*, *--verbose*:: Verbose mode. diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 1d81b117ac..29bb785ab0 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -796,12 +796,14 @@ int main(int argc, char **argv) * OR * losetup {--direct-io[=off]|--logical-blocksize=size}... */ - if (!(set_dio || set_blocksize)) - act = A_SHOW_ONE; - if (set_dio) + if (set_dio) { act = A_SET_DIRECT_IO; - if (set_blocksize) + lo_flags &= ~LO_FLAGS_DIRECT_IO; + } else if (set_blocksize) act = A_SET_BLOCKSIZE; + else + act = A_SHOW_ONE; + if (!is_loopdev(argv[optind]) || loopcxt_set_device(&lc, argv[optind])) err(EXIT_FAILURE, _("%s: failed to use device"),