diff mbox series

[6/7] examples/vhost: enhance getopt_long usage

Message ID 20201124123249.14451-6-ibtisam.tariq@emumba.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers show
Series [1/7] examples/fips_validation: enhance getopt_long usage | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ibtisam Tariq Nov. 24, 2020, 12:32 p.m. UTC
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. This is to improve readability and consistency in
all examples.

Bugzilla ID: 238
Cc: jiayu.hu@intel.com
Cc: huawei.xie@intel.com

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
v3:
* None.

v2:
* Remove extra indentations.
* Remove extra block brackets in switch statement.
* Change enum names to start with OPT_ and remove KEYWORD from enum names.

v1:
* enhance getopt_long usage.
---
 examples/vhost/main.c | 283 ++++++++++++++++++++++--------------------
 1 file changed, 150 insertions(+), 133 deletions(-)

Comments

David Marchand Dec. 7, 2020, 10:51 a.m. UTC | #1
On Tue, Nov 24, 2020 at 1:35 PM Ibtisam Tariq <ibtisam.tariq@emumba.com> wrote:
> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
> index 8d8c3038b..ce8b64035 100644
> --- a/examples/vhost/main.c
> +++ b/examples/vhost/main.c
> @@ -466,6 +466,33 @@ us_vhost_usage(const char *prgname)
>                prgname);
>  }
>
> +enum {
> +#define OPT_VM2VM               "vm2vm"
> +       OPT_VM2VM_NUM = 256,
> +#define OPT_RX_RETRY            "rx-retry"
> +       OPT_RX_RETRY_NUM,
> +#define OPT_RX_RETRY_DELAY      "rx-retry-delay"
> +       OPT_RX_RETRY_DELAY_NUM,
> +#define OPT_RX_RETRY_NUMB        "rx-retry-num"
> +       OPT_RX_RETRY_NUMB_NUM,
> +#define OPT_MERGEABLE           "mergeable"
> +       OPT_MERGEABLE_NUM,
> +#define OPT_STATS               "stats"
> +       OPT_STATS_NUM,
> +#define OPT_SOCKET_FILE         "socket-file"
> +       OPT_SOCKET_FILE_NUM,
> +#define OPT_TX_CSUM             "tx-csum"
> +       OPT_TX_CSUM_NUM,
> +#define OPT_TSO                 "tso"
> +       OPT_TSO_NUM,
> +#define OPT_CLIENT              "client"
> +#define OPT_BUILTIN_NET_DRIVER  "builtin-net-driver"
> +#define OPT_DMA_TYPE                   "dma-type"
> +       OPT_DMA_TYPE_NUM,
> +#define OPT_DMAS                               "dmas"
> +       OPT_DMAS_NUM,

Nit: could you align those last two strings?


> +};
> +
>  /*
>   * Parse the arguments given in the command line of the application.
>   */
> @@ -477,19 +504,31 @@ us_vhost_parse_args(int argc, char **argv)
>         unsigned i;
>         const char *prgname = argv[0];
>         static struct option long_option[] = {
> -               {"vm2vm", required_argument, NULL, 0},
> -               {"rx-retry", required_argument, NULL, 0},
> -               {"rx-retry-delay", required_argument, NULL, 0},
> -               {"rx-retry-num", required_argument, NULL, 0},
> -               {"mergeable", required_argument, NULL, 0},
> -               {"stats", required_argument, NULL, 0},
> -               {"socket-file", required_argument, NULL, 0},
> -               {"tx-csum", required_argument, NULL, 0},
> -               {"tso", required_argument, NULL, 0},
> -               {"client", no_argument, &client_mode, 1},
> -               {"builtin-net-driver", no_argument, &builtin_net_driver, 1},
> -               {"dma-type", required_argument, NULL, 0},
> -               {"dmas", required_argument, NULL, 0},
> +               {OPT_VM2VM, required_argument,
> +                               NULL, OPT_VM2VM_NUM},
> +               {OPT_RX_RETRY, required_argument,
> +                               NULL, OPT_RX_RETRY_NUM},
> +               {OPT_RX_RETRY_DELAY, required_argument,
> +                               NULL, OPT_RX_RETRY_DELAY_NUM},
> +               {OPT_RX_RETRY_NUMB, required_argument,
> +                               NULL, OPT_RX_RETRY_NUMB_NUM},
> +               {OPT_MERGEABLE, required_argument,
> +                               NULL, OPT_MERGEABLE_NUM},
> +               {OPT_STATS, required_argument,
> +                               NULL, OPT_STATS_NUM},
> +               {OPT_SOCKET_FILE, required_argument,
> +                               NULL, OPT_SOCKET_FILE_NUM},
> +               {OPT_TX_CSUM, required_argument,
> +                               NULL, OPT_TX_CSUM_NUM},
> +               {OPT_TSO, required_argument,
> +                               NULL, OPT_TSO_NUM},
> +               {OPT_CLIENT, no_argument, &client_mode, 1},
> +               {OPT_BUILTIN_NET_DRIVER, no_argument,
> +                               &builtin_net_driver, 1},

We will have an issue here.

Quoting the manual:
"""
       flag   specifies  how  results are returned for a long option.
If flag is NULL, then getopt_long() returns val.  (For example, the
calling program may set val to the equivalent short option charac‐
              ter.)  Otherwise, getopt_long() returns 0, and flag
points to a variable which is set to val if the option is found, but
left unchanged if the option is not found.
"""

$ build/examples/dpdk-vhost --no-huge -m 1024 -l 0,1 -a 0:0.0 --
--builtin-net-driver --socket-file /tmp/sock0 -p 0x1
EAL: Detected 8 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /run/user/114840/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'VA'
EAL: Probing VFIO support...
VHOST_CONFIG: build/examples/dpdk-vhost [EAL options] -- -p PORTMASK
        --vm2vm [0|1|2]
        --rx_retry [0|1] --mergeable [0|1] --stats [0-N]
        --socket-file <path>
        --nb-devices ND
        -p PORTMASK: Set mask for ports to be used by application
        --vm2vm [0|1|2]: disable/software(default)/hardware vm2vm comms
        --rx-retry [0|1]: disable/enable(default) retries on rx.
Enable retry if destintation queue is full
        --rx-retry-delay [0-N]: timeout(in usecond) between retries on
RX. This makes effect only if retries on rx enabled
        --rx-retry-num [0-N]: the number of retries on rx. This makes
effect only if retries on rx enabled
        --mergeable [0|1]: disable(default)/enable RX mergeable buffers
        --stats [0-N]: 0: Disable stats, N: Time in seconds to print stats
        --socket-file: The path of the socket file.
        --tx-csum [0|1] disable/enable TX checksum offload.
        --tso [0|1] disable/enable TCP segment offload.
        --client register a vhost-user socket as client mode.
        --dma-type register dma type for your vhost async driver. For
example "ioat" for now.
        --dmas register dma channel for specific vhost device.
EAL: Error - exiting with code: 1
  Cause: Invalid argument

This is because getopt_long returned 0.

We have two solutions:
- we keep this &builtin_net_driver flag use, but we must accept a 0
return value from getopt_long.
- we convert this option to the same scheme as the other and add a
OPT_BUILTIN_NET_DRIVER_NUM like other options in this example,

Maxime, opinion?
Ibtisam Tariq Dec. 31, 2020, 7 a.m. UTC | #2
Hi,
Sorry, for the late reply.

We have two solutions:
> - we keep this &builtin_net_driver flag use, but we must accept a 0
> return value from getopt_long.
> - we convert this option to the same scheme as the other and add a
> OPT_BUILTIN_NET_DRIVER_NUM like other options in this example,
>
What should I do for built_net_driver. The convention used in eal is the
2nd option.

On Mon, Dec 7, 2020 at 3:51 PM David Marchand <david.marchand@redhat.com>
wrote:

> On Tue, Nov 24, 2020 at 1:35 PM Ibtisam Tariq <ibtisam.tariq@emumba.com>
> wrote:
> > diff --git a/examples/vhost/main.c b/examples/vhost/main.c
> > index 8d8c3038b..ce8b64035 100644
> > --- a/examples/vhost/main.c
> > +++ b/examples/vhost/main.c
> > @@ -466,6 +466,33 @@ us_vhost_usage(const char *prgname)
> >                prgname);
> >  }
> >
> > +enum {
> > +#define OPT_VM2VM               "vm2vm"
> > +       OPT_VM2VM_NUM = 256,
> > +#define OPT_RX_RETRY            "rx-retry"
> > +       OPT_RX_RETRY_NUM,
> > +#define OPT_RX_RETRY_DELAY      "rx-retry-delay"
> > +       OPT_RX_RETRY_DELAY_NUM,
> > +#define OPT_RX_RETRY_NUMB        "rx-retry-num"
> > +       OPT_RX_RETRY_NUMB_NUM,
> > +#define OPT_MERGEABLE           "mergeable"
> > +       OPT_MERGEABLE_NUM,
> > +#define OPT_STATS               "stats"
> > +       OPT_STATS_NUM,
> > +#define OPT_SOCKET_FILE         "socket-file"
> > +       OPT_SOCKET_FILE_NUM,
> > +#define OPT_TX_CSUM             "tx-csum"
> > +       OPT_TX_CSUM_NUM,
> > +#define OPT_TSO                 "tso"
> > +       OPT_TSO_NUM,
> > +#define OPT_CLIENT              "client"
> > +#define OPT_BUILTIN_NET_DRIVER  "builtin-net-driver"
> > +#define OPT_DMA_TYPE                   "dma-type"
> > +       OPT_DMA_TYPE_NUM,
> > +#define OPT_DMAS                               "dmas"
> > +       OPT_DMAS_NUM,
>
> Nit: could you align those last two strings?
>
>
> > +};
> > +
> >  /*
> >   * Parse the arguments given in the command line of the application.
> >   */
> > @@ -477,19 +504,31 @@ us_vhost_parse_args(int argc, char **argv)
> >         unsigned i;
> >         const char *prgname = argv[0];
> >         static struct option long_option[] = {
> > -               {"vm2vm", required_argument, NULL, 0},
> > -               {"rx-retry", required_argument, NULL, 0},
> > -               {"rx-retry-delay", required_argument, NULL, 0},
> > -               {"rx-retry-num", required_argument, NULL, 0},
> > -               {"mergeable", required_argument, NULL, 0},
> > -               {"stats", required_argument, NULL, 0},
> > -               {"socket-file", required_argument, NULL, 0},
> > -               {"tx-csum", required_argument, NULL, 0},
> > -               {"tso", required_argument, NULL, 0},
> > -               {"client", no_argument, &client_mode, 1},
> > -               {"builtin-net-driver", no_argument, &builtin_net_driver,
> 1},
> > -               {"dma-type", required_argument, NULL, 0},
> > -               {"dmas", required_argument, NULL, 0},
> > +               {OPT_VM2VM, required_argument,
> > +                               NULL, OPT_VM2VM_NUM},
> > +               {OPT_RX_RETRY, required_argument,
> > +                               NULL, OPT_RX_RETRY_NUM},
> > +               {OPT_RX_RETRY_DELAY, required_argument,
> > +                               NULL, OPT_RX_RETRY_DELAY_NUM},
> > +               {OPT_RX_RETRY_NUMB, required_argument,
> > +                               NULL, OPT_RX_RETRY_NUMB_NUM},
> > +               {OPT_MERGEABLE, required_argument,
> > +                               NULL, OPT_MERGEABLE_NUM},
> > +               {OPT_STATS, required_argument,
> > +                               NULL, OPT_STATS_NUM},
> > +               {OPT_SOCKET_FILE, required_argument,
> > +                               NULL, OPT_SOCKET_FILE_NUM},
> > +               {OPT_TX_CSUM, required_argument,
> > +                               NULL, OPT_TX_CSUM_NUM},
> > +               {OPT_TSO, required_argument,
> > +                               NULL, OPT_TSO_NUM},
> > +               {OPT_CLIENT, no_argument, &client_mode, 1},
> > +               {OPT_BUILTIN_NET_DRIVER, no_argument,
> > +                               &builtin_net_driver, 1},
>
> We will have an issue here.
>
> Quoting the manual:
> """
>        flag   specifies  how  results are returned for a long option.
> If flag is NULL, then getopt_long() returns val.  (For example, the
> calling program may set val to the equivalent short option charac‐
>               ter.)  Otherwise, getopt_long() returns 0, and flag
> points to a variable which is set to val if the option is found, but
> left unchanged if the option is not found.
> """
>
> $ build/examples/dpdk-vhost --no-huge -m 1024 -l 0,1 -a 0:0.0 --
> --builtin-net-driver --socket-file /tmp/sock0 -p 0x1
> EAL: Detected 8 lcore(s)
> EAL: Detected 1 NUMA nodes
> EAL: Multi-process socket /run/user/114840/dpdk/rte/mp_socket
> EAL: Selected IOVA mode 'VA'
> EAL: Probing VFIO support...
> VHOST_CONFIG: build/examples/dpdk-vhost [EAL options] -- -p PORTMASK
>         --vm2vm [0|1|2]
>         --rx_retry [0|1] --mergeable [0|1] --stats [0-N]
>         --socket-file <path>
>         --nb-devices ND
>         -p PORTMASK: Set mask for ports to be used by application
>         --vm2vm [0|1|2]: disable/software(default)/hardware vm2vm comms
>         --rx-retry [0|1]: disable/enable(default) retries on rx.
> Enable retry if destintation queue is full
>         --rx-retry-delay [0-N]: timeout(in usecond) between retries on
> RX. This makes effect only if retries on rx enabled
>         --rx-retry-num [0-N]: the number of retries on rx. This makes
> effect only if retries on rx enabled
>         --mergeable [0|1]: disable(default)/enable RX mergeable buffers
>         --stats [0-N]: 0: Disable stats, N: Time in seconds to print stats
>         --socket-file: The path of the socket file.
>         --tx-csum [0|1] disable/enable TX checksum offload.
>         --tso [0|1] disable/enable TCP segment offload.
>         --client register a vhost-user socket as client mode.
>         --dma-type register dma type for your vhost async driver. For
> example "ioat" for now.
>         --dmas register dma channel for specific vhost device.
> EAL: Error - exiting with code: 1
>   Cause: Invalid argument
>
> This is because getopt_long returned 0.
>
> We have two solutions:
> - we keep this &builtin_net_driver flag use, but we must accept a 0
> return value from getopt_long.
> - we convert this option to the same scheme as the other and add a
> OPT_BUILTIN_NET_DRIVER_NUM like other options in this example,
>
> Maxime, opinion?
>
>
> --
> David Marchand
>
>
diff mbox series

Patch

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 8d8c3038b..ce8b64035 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -466,6 +466,33 @@  us_vhost_usage(const char *prgname)
 	       prgname);
 }
 
+enum {
+#define OPT_VM2VM               "vm2vm"
+	OPT_VM2VM_NUM = 256,
+#define OPT_RX_RETRY            "rx-retry"
+	OPT_RX_RETRY_NUM,
+#define OPT_RX_RETRY_DELAY      "rx-retry-delay"
+	OPT_RX_RETRY_DELAY_NUM,
+#define OPT_RX_RETRY_NUMB        "rx-retry-num"
+	OPT_RX_RETRY_NUMB_NUM,
+#define OPT_MERGEABLE           "mergeable"
+	OPT_MERGEABLE_NUM,
+#define OPT_STATS               "stats"
+	OPT_STATS_NUM,
+#define OPT_SOCKET_FILE         "socket-file"
+	OPT_SOCKET_FILE_NUM,
+#define OPT_TX_CSUM             "tx-csum"
+	OPT_TX_CSUM_NUM,
+#define OPT_TSO                 "tso"
+	OPT_TSO_NUM,
+#define OPT_CLIENT              "client"
+#define OPT_BUILTIN_NET_DRIVER  "builtin-net-driver"
+#define OPT_DMA_TYPE			"dma-type"
+	OPT_DMA_TYPE_NUM,
+#define OPT_DMAS				"dmas"
+	OPT_DMAS_NUM,
+};
+
 /*
  * Parse the arguments given in the command line of the application.
  */
@@ -477,19 +504,31 @@  us_vhost_parse_args(int argc, char **argv)
 	unsigned i;
 	const char *prgname = argv[0];
 	static struct option long_option[] = {
-		{"vm2vm", required_argument, NULL, 0},
-		{"rx-retry", required_argument, NULL, 0},
-		{"rx-retry-delay", required_argument, NULL, 0},
-		{"rx-retry-num", required_argument, NULL, 0},
-		{"mergeable", required_argument, NULL, 0},
-		{"stats", required_argument, NULL, 0},
-		{"socket-file", required_argument, NULL, 0},
-		{"tx-csum", required_argument, NULL, 0},
-		{"tso", required_argument, NULL, 0},
-		{"client", no_argument, &client_mode, 1},
-		{"builtin-net-driver", no_argument, &builtin_net_driver, 1},
-		{"dma-type", required_argument, NULL, 0},
-		{"dmas", required_argument, NULL, 0},
+		{OPT_VM2VM, required_argument,
+				NULL, OPT_VM2VM_NUM},
+		{OPT_RX_RETRY, required_argument,
+				NULL, OPT_RX_RETRY_NUM},
+		{OPT_RX_RETRY_DELAY, required_argument,
+				NULL, OPT_RX_RETRY_DELAY_NUM},
+		{OPT_RX_RETRY_NUMB, required_argument,
+				NULL, OPT_RX_RETRY_NUMB_NUM},
+		{OPT_MERGEABLE, required_argument,
+				NULL, OPT_MERGEABLE_NUM},
+		{OPT_STATS, required_argument,
+				NULL, OPT_STATS_NUM},
+		{OPT_SOCKET_FILE, required_argument,
+				NULL, OPT_SOCKET_FILE_NUM},
+		{OPT_TX_CSUM, required_argument,
+				NULL, OPT_TX_CSUM_NUM},
+		{OPT_TSO, required_argument,
+				NULL, OPT_TSO_NUM},
+		{OPT_CLIENT, no_argument, &client_mode, 1},
+		{OPT_BUILTIN_NET_DRIVER, no_argument,
+				&builtin_net_driver, 1},
+		{OPT_DMA_TYPE, required_argument,
+				NULL, OPT_DMA_TYPE_NUM},
+		{OPT_DMAS, required_argument,
+				NULL, OPT_DMAS_NUM},
 		{NULL, 0, 0, 0},
 	};
 
@@ -512,151 +551,129 @@  us_vhost_parse_args(int argc, char **argv)
 			vmdq_conf_default.rx_adv_conf.vmdq_rx_conf.rx_mode =
 				ETH_VMDQ_ACCEPT_BROADCAST |
 				ETH_VMDQ_ACCEPT_MULTICAST;
-
 			break;
 
-		case 0:
-			/* Enable/disable vm2vm comms. */
-			if (!strncmp(long_option[option_index].name, "vm2vm",
-				MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, (VM2VM_LAST - 1));
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG,
-						"Invalid argument for "
-						"vm2vm [0|1|2]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else {
-					vm2vm_mode = (vm2vm_type)ret;
-				}
+		case OPT_VM2VM_NUM:
+			ret = parse_num_opt(optarg, (VM2VM_LAST - 1));
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG,
+					"Invalid argument for "
+					"vm2vm [0|1|2]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			vm2vm_mode = (vm2vm_type)ret;
+			break;
 
-			/* Enable/disable retries on RX. */
-			if (!strncmp(long_option[option_index].name, "rx-retry", MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, 1);
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry [0|1]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else {
-					enable_retry = ret;
-				}
+		case OPT_RX_RETRY_NUM:
+			ret = parse_num_opt(optarg, 1);
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry [0|1]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			enable_retry = ret;
+			break;
 
-			/* Enable/disable TX checksum offload. */
-			if (!strncmp(long_option[option_index].name, "tx-csum", MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, 1);
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tx-csum [0|1]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else
-					enable_tx_csum = ret;
+		case OPT_TX_CSUM_NUM:
+			ret = parse_num_opt(optarg, 1);
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tx-csum [0|1]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			enable_tx_csum = ret;
+			break;
 
-			/* Enable/disable TSO offload. */
-			if (!strncmp(long_option[option_index].name, "tso", MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, 1);
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tso [0|1]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else
-					enable_tso = ret;
+		case OPT_TSO_NUM:
+			ret = parse_num_opt(optarg, 1);
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tso [0|1]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			enable_tso = ret;
+			break;
 
-			/* Specify the retries delay time (in useconds) on RX. */
-			if (!strncmp(long_option[option_index].name, "rx-retry-delay", MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, INT32_MAX);
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry-delay [0-N]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else {
-					burst_rx_delay_time = ret;
-				}
+		case OPT_RX_RETRY_DELAY_NUM:
+			ret = parse_num_opt(optarg, INT32_MAX);
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry-delay [0-N]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			burst_rx_delay_time = ret;
+			break;
 
-			/* Specify the retries number on RX. */
-			if (!strncmp(long_option[option_index].name, "rx-retry-num", MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, INT32_MAX);
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry-num [0-N]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else {
-					burst_rx_retry_num = ret;
-				}
+		case OPT_RX_RETRY_NUMB_NUM:
+			ret = parse_num_opt(optarg, INT32_MAX);
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for rx-retry-num [0-N]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			burst_rx_retry_num = ret;
+			break;
 
-			/* Enable/disable RX mergeable buffers. */
-			if (!strncmp(long_option[option_index].name, "mergeable", MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, 1);
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for mergeable [0|1]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else {
-					mergeable = !!ret;
-					if (ret) {
-						vmdq_conf_default.rxmode.offloads |=
-							DEV_RX_OFFLOAD_JUMBO_FRAME;
-						vmdq_conf_default.rxmode.max_rx_pkt_len
-							= JUMBO_FRAME_MAX_SIZE;
-					}
-				}
+		case OPT_MERGEABLE_NUM:
+			ret = parse_num_opt(optarg, 1);
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for mergeable [0|1]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
-
-			/* Enable/disable stats. */
-			if (!strncmp(long_option[option_index].name, "stats", MAX_LONG_OPT_SZ)) {
-				ret = parse_num_opt(optarg, INT32_MAX);
-				if (ret == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG,
-						"Invalid argument for stats [0..N]\n");
-					us_vhost_usage(prgname);
-					return -1;
-				} else {
-					enable_stats = ret;
-				}
+			mergeable = !!ret;
+			if (ret) {
+				vmdq_conf_default.rxmode.offloads |=
+					DEV_RX_OFFLOAD_JUMBO_FRAME;
+				vmdq_conf_default.rxmode.max_rx_pkt_len
+					= JUMBO_FRAME_MAX_SIZE;
 			}
+			break;
 
-			/* Set socket file path. */
-			if (!strncmp(long_option[option_index].name,
-						"socket-file", MAX_LONG_OPT_SZ)) {
-				if (us_vhost_parse_socket_path(optarg) == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG,
-					"Invalid argument for socket name (Max %d characters)\n",
-					PATH_MAX);
-					us_vhost_usage(prgname);
-					return -1;
-				}
+		case OPT_STATS_NUM:
+			ret = parse_num_opt(optarg, INT32_MAX);
+			if (ret == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG,
+					"Invalid argument for stats [0..N]\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			enable_stats = ret;
+			break;
 
-			if (!strncmp(long_option[option_index].name,
-						"dma-type", MAX_LONG_OPT_SZ)) {
-				if (strlen(optarg) >= MAX_LONG_OPT_SZ) {
-					RTE_LOG(INFO, VHOST_CONFIG,
-						"Wrong DMA type\n");
-					us_vhost_usage(prgname);
-					return -1;
-				}
-				strcpy(dma_type, optarg);
+		/* Set socket file path. */
+		case OPT_SOCKET_FILE_NUM:
+			if (us_vhost_parse_socket_path(optarg) == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG,
+				"Invalid argument for socket name (Max %d characters)\n",
+				PATH_MAX);
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			break;
 
-			if (!strncmp(long_option[option_index].name,
-						"dmas", MAX_LONG_OPT_SZ)) {
-				if (open_dma(optarg) == -1) {
-					RTE_LOG(INFO, VHOST_CONFIG,
-						"Wrong DMA args\n");
-					us_vhost_usage(prgname);
-					return -1;
-				}
-				async_vhost_driver = 1;
+		case OPT_DMA_TYPE_NUM:
+			if (strlen(optarg) >= MAX_LONG_OPT_SZ) {
+				RTE_LOG(INFO, VHOST_CONFIG,
+					"Wrong DMA type\n");
+				us_vhost_usage(prgname);
+				return -1;
 			}
+			strcpy(dma_type, optarg);
+			break;
 
+		case OPT_DMAS_NUM:
+			if (open_dma(optarg) == -1) {
+				RTE_LOG(INFO, VHOST_CONFIG,
+					"Wrong DMA args\n");
+				us_vhost_usage(prgname);
+				return -1;
+			}
+			async_vhost_driver = 1;
 			break;
 
-			/* Invalid option - print options. */
+		/* Invalid option - print options. */
 		default:
 			us_vhost_usage(prgname);
 			return -1;