From: Ibtisam Tariq <ibtisam.tariq@emumba.com>
To: marko.kovacevic@intel.com, konstantin.ananyev@intel.com,
reshma.pattan@intel.com, john.mcnamara@intel.com,
cristian.dumitrescu@intel.com, jasvinder.singh@intel.com,
chenbo.xia@intel.com, maxime.coquelin@redhat.com,
xiaoyun.li@intel.com
Cc: dev@dpdk.org, Ibtisam Tariq <ibtisam.tariq@emumba.com>,
roy.fan.zhang@intel.com
Subject: [dpdk-dev] [PATCH 7/8] examples/vhost_crypto: enhance getopt_long usage
Date: Thu, 29 Oct 2020 12:53:38 +0000 [thread overview]
Message-ID: <20201029125339.30916-7-ibtisam.tariq@emumba.com> (raw)
In-Reply-To: <20201029125339.30916-1-ibtisam.tariq@emumba.com>
Instead of using getopt_long return value, strcmp was used to
compare the input parameters with the struct option array. This
patch get rid of all those strcmp by directly binding each longopt
with an int enum.
Bugzilla ID: 238
Fixes: f5188211c7 ("examples/vhost_crypto: add sample application")
Cc: roy.fan.zhang@intel.com
Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
examples/vhost_crypto/main.c | 78 ++++++++++++++++++++++--------------
1 file changed, 49 insertions(+), 29 deletions(-)
diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c
index 11ad49159..c68b409b3 100644
--- a/examples/vhost_crypto/main.c
+++ b/examples/vhost_crypto/main.c
@@ -62,10 +62,16 @@ struct vhost_crypto_options {
uint32_t guest_polling;
} options;
+enum {
#define CONFIG_KEYWORD "config"
+ CONFIG_KEYWORD_NUM = 256,
#define SOCKET_FILE_KEYWORD "socket-file"
+ SOCKET_FILE_KEYWORD_NUM,
#define ZERO_COPY_KEYWORD "zero-copy"
+ ZERO_COPY_KEYWORD_NUM,
#define POLLING_KEYWORD "guest-polling"
+ POLLING_KEYWORD_NUM,
+};
#define NB_SOCKET_FIELDS (2)
@@ -210,10 +216,14 @@ vhost_crypto_parse_args(int argc, char **argv)
char **argvopt;
int option_index;
struct option lgopts[] = {
- {SOCKET_FILE_KEYWORD, required_argument, 0, 0},
- {CONFIG_KEYWORD, required_argument, 0, 0},
- {ZERO_COPY_KEYWORD, no_argument, 0, 0},
- {POLLING_KEYWORD, no_argument, 0, 0},
+ {SOCKET_FILE_KEYWORD, required_argument,
+ NULL, SOCKET_FILE_KEYWORD_NUM},
+ {CONFIG_KEYWORD, required_argument,
+ NULL, CONFIG_KEYWORD_NUM},
+ {ZERO_COPY_KEYWORD, no_argument,
+ NULL, ZERO_COPY_KEYWORD_NUM},
+ {POLLING_KEYWORD, no_argument,
+ NULL, POLLING_KEYWORD_NUM},
{NULL, 0, 0, 0}
};
@@ -222,36 +232,46 @@ vhost_crypto_parse_args(int argc, char **argv)
while ((opt = getopt_long(argc, argvopt, "s:",
lgopts, &option_index)) != EOF) {
+ if (opt == '?') {
+ vhost_crypto_usage(prgname);
+ return -1;
+ }
+
switch (opt) {
- case 0:
- if (strcmp(lgopts[option_index].name,
- SOCKET_FILE_KEYWORD) == 0) {
- ret = parse_socket_arg(optarg);
- if (ret < 0) {
- vhost_crypto_usage(prgname);
- return ret;
- }
- } else if (strcmp(lgopts[option_index].name,
- CONFIG_KEYWORD) == 0) {
- ret = parse_config(optarg);
- if (ret < 0) {
- vhost_crypto_usage(prgname);
- return ret;
- }
- } else if (strcmp(lgopts[option_index].name,
- ZERO_COPY_KEYWORD) == 0) {
- options.zero_copy =
- RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE;
- } else if (strcmp(lgopts[option_index].name,
- POLLING_KEYWORD) == 0) {
- options.guest_polling = 1;
- } else {
+ case SOCKET_FILE_KEYWORD_NUM:
+ {
+ ret = parse_socket_arg(optarg);
+ if (ret < 0) {
vhost_crypto_usage(prgname);
- return -EINVAL;
+ return ret;
}
break;
+ }
+ case CONFIG_KEYWORD_NUM:
+ {
+ ret = parse_config(optarg);
+ if (ret < 0) {
+ vhost_crypto_usage(prgname);
+ return ret;
+ }
+ break;
+ }
+ case ZERO_COPY_KEYWORD_NUM:
+ {
+ options.zero_copy =
+ RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE;
+ break;
+ }
+ case POLLING_KEYWORD_NUM:
+ {
+ options.guest_polling = 1;
+ break;
+ }
default:
- return -1;
+ {
+ vhost_crypto_usage(prgname);
+ return -EINVAL;
+ }
}
}
--
2.17.1
next prev parent reply other threads:[~2020-10-29 12:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-29 12:53 [dpdk-dev] [PATCH 1/8] examples/fips_validation: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 2/8] examples/l3fwd-acl: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 3/8] examples/packet_ordering: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 4/8] examples/performance-thread/l3fwd-thread: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 5/8] examples/qos_sched: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 6/8] examples/vhost: " Ibtisam Tariq
2020-10-29 12:53 ` Ibtisam Tariq [this message]
2020-10-29 12:53 ` [dpdk-dev] [PATCH 8/8] examples/tep_termination: " Ibtisam Tariq
2020-10-29 13:16 ` David Marchand
2020-11-02 8:18 ` Ibtisam Tariq
2020-10-29 22:07 ` [dpdk-dev] [PATCH 1/8] examples/fips_validation: " David Marchand
2020-11-02 8:32 ` Ibtisam Tariq
2020-11-04 10:00 ` Ibtisam Tariq
2020-11-05 8:59 ` David Marchand
2020-11-10 6:10 ` Ibtisam Tariq
2020-11-10 8:23 ` David Marchand
2020-11-10 9:03 ` Ibtisam Tariq
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201029125339.30916-7-ibtisam.tariq@emumba.com \
--to=ibtisam.tariq@emumba.com \
--cc=chenbo.xia@intel.com \
--cc=cristian.dumitrescu@intel.com \
--cc=dev@dpdk.org \
--cc=jasvinder.singh@intel.com \
--cc=john.mcnamara@intel.com \
--cc=konstantin.ananyev@intel.com \
--cc=marko.kovacevic@intel.com \
--cc=maxime.coquelin@redhat.com \
--cc=reshma.pattan@intel.com \
--cc=roy.fan.zhang@intel.com \
--cc=xiaoyun.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).