From f98d9641a371421640a8f1cfe497030758f86dca Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 19 Nov 2015 11:57:05 +0100 Subject: [PATCH] losetup: clean up --direct-io Signed-off-by: Karel Zak --- sys-utils/losetup.8 | 4 ++++ sys-utils/losetup.c | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sys-utils/losetup.8 b/sys-utils/losetup.8 index 41661e553..90fcb9d06 100644 --- a/sys-utils/losetup.8 +++ b/sys-utils/losetup.8 @@ -91,6 +91,10 @@ Detach the file or device associated with the specified loop device(s). .BR \-D , " \-\-detach\-all" Detach all associated loop devices. .TP +.BR "\-\-direct\-io"[\fI=on|off\fR] +Enable or disable direct I/O for the backing file. The optional argument can be +\fIon\fR or \fIoff\fR. If the optional argument is omitted, it defaults to \fIon\fR. +.TP .BR \-f , " \-\-find" Find the first unused loop device. If a .I file diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c index 918c34da6..1d57ab341 100644 --- a/sys-utils/losetup.c +++ b/sys-utils/losetup.c @@ -399,7 +399,7 @@ static void usage(FILE *out) fputs(_(" --sizelimit device is limited to bytes of the file\n"), out); fputs(_(" -P, --partscan create a partitioned loop device\n"), out); fputs(_(" -r, --read-only set up a read-only loop device\n"), out); - fputs(_(" --direct-io open backing file with O_DIRECT\n"), out); + fputs(_(" --direct-io[=] open backing file with O_DIRECT\n"), out); fputs(_(" --show print device name after setup (with -f)\n"), out); fputs(_(" -v, --verbose verbose mode\n"), out); @@ -477,7 +477,7 @@ int main(int argc, char **argv) { "sizelimit", 1, 0, OPT_SIZELIMIT }, { "partscan", 0, 0, 'P' }, { "read-only", 0, 0, 'r' }, - { "direct-io", 1, 0, OPT_DIO }, + { "direct-io", 2, 0, OPT_DIO }, { "raw", 0, 0, OPT_RAW }, { "show", 0, 0, OPT_SHOW }, { "verbose", 0, 0, 'v' }, @@ -568,8 +568,9 @@ int main(int argc, char **argv) showdev = 1; break; case OPT_DIO: - set_dio = 1; - use_dio = strtoul_or_err(optarg, _("failed to parse dio")); + use_dio = set_dio = 1; + if (optarg) + use_dio = parse_switch(optarg, _("argument error"), "on", "off", NULL); break; case 'v': break;