]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: fix --direct-io
authorKarel Zak <kzak@redhat.com>
Wed, 9 Mar 2022 10:13:26 +0000 (11:13 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 9 Mar 2022 10:30:22 +0000 (11:30 +0100)
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 <kzak@redhat.com>
sys-utils/losetup.8.adoc
sys-utils/losetup.c

index 075d079fd14472e53d57e440b917179c6d47a737..0dc58fe65be1c8a5514429afad933396bcdfec1d 100644 (file)
@@ -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.
index 1d81b117ac16d234332fe8a45f9c2b577f71052f..29bb785ab0780ac6d4b894cf8b2837983cbc6555 100644 (file)
@@ -796,12 +796,14 @@ int main(int argc, char **argv)
                 * OR
                 * losetup {--direct-io[=off]|--logical-blocksize=size}... <device>
                 */
-               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"),