diff --git a/include/iscsi.h b/include/iscsi.h index a890fc2..a350596 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -21,6 +21,14 @@ struct iscsi_context; struct sockaddr; +/* + * Syntax for normal and portal/discovery URLs. + */ +#define ISCSI_URL_SYNTAX "\"iscsi://[[%]@]" \ + "[:]//\"" +#define ISCSI_PORTAL_URL_SYNTAX "\"iscsi://[[%]@]" \ + "[:]\"" + /* * The following three functions are used to integrate libiscsi in an event diff --git a/lib/init.c b/lib/init.c index c2dfce2..d1dc6f2 100644 --- a/lib/init.c +++ b/lib/init.c @@ -29,11 +29,6 @@ #include "iscsi-private.h" #include "slist.h" -#define ISCSI_URL_SYNTAX "\"iscsi://[[%]@]" \ - "[:]//\"" -#define ISCSI_PURL_SYNTAX "\"iscsi://[[%]@]" \ - "[:]\"" - struct iscsi_context * iscsi_create_context(const char *initiator_name) { @@ -431,7 +426,7 @@ iscsi_parse_portal_url(struct iscsi_context *iscsi, const char *url) iscsi_set_error(iscsi, "Invalid URL %s\niSCSI Portal URL must be of " "the form: %s", url, - ISCSI_PURL_SYNTAX); + ISCSI_PORTAL_URL_SYNTAX); return NULL; } diff --git a/src/iscsi-inq.c b/src/iscsi-inq.c index aeb6c24..9979662 100644 --- a/src/iscsi-inq.c +++ b/src/iscsi-inq.c @@ -150,6 +150,30 @@ void do_inquiry(struct iscsi_context *iscsi, int lun, int evpd, int pc) } +void print_usage(void) +{ + fprintf(stderr, "Usage: iscsi-inq [-?] [-?|--help] [--usage] [-i|--initiator-name=iqn-name]\n" + "\t\t[-e|--evpd=integer] [-c|--pagecode=integer] \n"); +} + +void print_help(void) +{ + fprintf(stderr, "Usage: iscsi-inq [OPTION...] \n"); + fprintf(stderr, " -i, --initiator-name=iqn-name Initiatorname to use\n"); + fprintf(stderr, " -e, --evpd=integer evpd\n"); + fprintf(stderr, " -c, --pagecode=integer page code\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Help options:\n"); + fprintf(stderr, " -?, --help Show this help message\n"); + fprintf(stderr, " --usage Display brief usage message\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "iSCSI URL format : %s\n", ISCSI_URL_SYNTAX); + fprintf(stderr, "\n"); + fprintf(stderr, " is either of:\n"); + fprintf(stderr, " \"hostname\" iscsi.example\n"); + fprintf(stderr, " \"ipv4-address\" 10.1.1.27\n"); + fprintf(stderr, " \"ipv6-address\" [fce0::1]\n"); +} int main(int argc, const char *argv[]) { @@ -160,10 +184,12 @@ int main(int argc, const char *argv[]) const char *url = NULL; struct iscsi_url *iscsi_url = NULL; int evpd = 0, pagecode = 0; + int show_help = 0, show_usage = 0; int res; struct poptOption popt_options[] = { - POPT_AUTOHELP + { "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL }, + { "usage", 0, POPT_ARG_NONE, &show_usage, 0, "Display brief usage message", NULL }, { "initiator-name", 'i', POPT_ARG_STRING, &initiator, 0, "Initiatorname to use", "iqn-name" }, { "evpd", 'e', POPT_ARG_INT, &evpd, 0, "evpd", "integer" }, { "pagecode", 'c', POPT_ARG_INT, &pagecode, 0, "page code", "integer" }, @@ -184,6 +210,17 @@ int main(int argc, const char *argv[]) extra_argc++; } } + + if (show_help != 0) { + print_help(); + exit(0); + } + + if (show_usage != 0) { + print_usage(); + exit(0); + } + poptFreeContext(pc); iscsi = iscsi_create_context(initiator); @@ -194,8 +231,7 @@ int main(int argc, const char *argv[]) if (url == NULL) { fprintf(stderr, "You must specify the URL\n"); - fprintf(stderr, " iscsi://[[%%]@]" - "[:]//\n"); + print_usage(); exit(10); } iscsi_url = iscsi_parse_full_url(iscsi, url); diff --git a/src/iscsi-ls.c b/src/iscsi-ls.c index 3553971..0e91d4c 100644 --- a/src/iscsi-ls.c +++ b/src/iscsi-ls.c @@ -270,6 +270,29 @@ void discoveryconnect_cb(struct iscsi_context *iscsi, int status, void *command_ } } +void print_usage(void) +{ + fprintf(stderr, "Usage: iscsi-ls [-?s] [-?|--help] [--usage] [-i|--initiator-name=iqn-name]\n" + "\t\t[-s|--show-luns] \n"); +} + +void print_help(void) +{ + fprintf(stderr, "Usage: iscsi-ls [OPTION...] \n"); + fprintf(stderr, " -i, --initiator-name=iqn-name Initiatorname to use\n"); + fprintf(stderr, " -s, --show-luns Show the luns for each target\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "Help options:\n"); + fprintf(stderr, " -?, --help Show this help message\n"); + fprintf(stderr, " --usage Display brief usage message\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "iSCSI Portal URL format : %s\n", ISCSI_PORTAL_URL_SYNTAX); + fprintf(stderr, "\n"); + fprintf(stderr, " is either of:\n"); + fprintf(stderr, " \"hostname\" iscsi.example\n"); + fprintf(stderr, " \"ipv4-address\" 10.1.1.27\n"); + fprintf(stderr, " \"ipv6-address\" [fce0::1]\n"); +} int main(int argc, const char *argv[]) { @@ -281,9 +304,11 @@ int main(int argc, const char *argv[]) const char *url = NULL; poptContext pc; int res; + int show_help = 0, show_usage = 0; struct poptOption popt_options[] = { - POPT_AUTOHELP + { "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL }, + { "usage", 0, POPT_ARG_NONE, &show_usage, 0, "Display brief usage message", NULL }, { "initiator-name", 'i', POPT_ARG_STRING, &initiator, 0, "Initiatorname to use", "iqn-name" }, { "show-luns", 's', POPT_ARG_NONE, &showluns, 0, "Show the luns for each target", NULL }, POPT_TABLEEND @@ -305,11 +330,23 @@ int main(int argc, const char *argv[]) extra_argc++; } } + + if (show_help != 0) { + print_help(); + exit(0); + } + + if (show_usage != 0) { + print_usage(); + exit(0); + } + poptFreeContext(pc); + if (url == NULL) { fprintf(stderr, "You must specify iscsi target portal.\n"); - fprintf(stderr, "%s [options] iscsi://[%%@][:]\n", argv[0]); + print_usage(); exit(10); }