From 53471e62159647ea07c88dad1d254dcbe96f322d Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Fri, 21 Feb 2020 11:54:26 +0100 Subject: [PATCH] examples/iscsi-dd: print basic usage information Add additional -h/--help parameters. Signed-off-by: David Disseldorp --- examples/iscsi-dd.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/examples/iscsi-dd.c b/examples/iscsi-dd.c index f02f22e..9a5e3d6 100644 --- a/examples/iscsi-dd.c +++ b/examples/iscsi-dd.c @@ -523,6 +523,23 @@ void readcap(struct iscsi_context *iscsi, int lun, int use_16, return; } +static void usage_exit(int status) +{ + fprintf(stderr, "Usage:\n" +"-s, --src source iSCSI URL (required)\n" +"-d, --dst destination iSCSI URL (required)\n" +"-i, --initiator-name iSCSI initiator name (default=%s)\n" +"-p, --progress show progress while copying\n" +"-6, --16 use READ16 & WRITE16 SCSI commands\n" +"-x, --xcopy offload I/O to the target via XCOPY\n" +"-m, --max maximum requests in flight (default=%u)\n" +"-b, --blocks blocks per I/O (default=%u)\n" +"-n, --ignore-errors ignore any I/O errors\n" +"-h, --help show this usage message\n", + initiator, max_in_flight, blocks_per_io); + exit(status); +} + int main(int argc, char *argv[]) { char *src_url = NULL; @@ -542,13 +559,14 @@ int main(int argc, char *argv[]) {"max", required_argument, NULL, 'm'}, {"blocks", required_argument, NULL, 'b'}, {"ignore-errors", no_argument, NULL, 'n'}, + {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; int option_index; memset(&client, 0, sizeof(client)); - while ((c = getopt_long(argc, argv, "d:s:i:m:b:p6nx", long_options, + while ((c = getopt_long(argc, argv, "d:s:i:m:b:p6nxh", long_options, &option_index)) != -1) { char *endptr; @@ -590,21 +608,24 @@ int main(int argc, char *argv[]) case 'n': client.ignore_errors = 1; break; + case 'h': + usage_exit(0); + break; default: fprintf(stderr, "Unrecognized option '%c'\n\n", c); - exit(1); + usage_exit(1); } } if (src_url == NULL) { - fprintf(stderr, "You must specify source url\n"); - fprintf(stderr, " --src iscsi://[:]//\n"); - exit(10); + fprintf(stderr, "You must specify source url\n" + " --src iscsi://[:]//\n"); + usage_exit(10); } if (dst_url == NULL) { - fprintf(stderr, "You must specify destination url\n"); - fprintf(stderr, " --dst iscsi://[:]//\n"); - exit(10); + fprintf(stderr, "You must specify destination url\n" + " --dst iscsi://[:]//\n"); + usage_exit(10); } client.src_iscsi = iscsi_create_context(initiator);