From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D2295A04B5; Thu, 29 Oct 2020 13:57:17 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 87774CCA9; Thu, 29 Oct 2020 13:54:21 +0100 (CET) Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by dpdk.org (Postfix) with ESMTP id DAC72CD2D for ; Thu, 29 Oct 2020 13:54:18 +0100 (CET) Received: by mail-ed1-f65.google.com with SMTP id dn5so2877400edb.10 for ; Thu, 29 Oct 2020 05:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v54L7UD6yejsgEALST3TN0JngpIJRZj5J+lHDtSeOQg=; b=K2lz75wocoF1k2rYRw8IMVZWIjYSIPvCg2ASsXbfpdijFmVMxuu9wedVuWv4vg3Xyo 57HfBpuBHb8UjXx7pIbLRtP4REAX84Z1mourfu1amzv2U1W6xbfBZBBbTK2MAnWhTygQ TnpIcWmgSc7h9Ajvr6I8LE9jDdI9WMOf+KZzoOyNyrsGSUbuuCDbsfr3PVq6D7Wap1eE TcdureytTzBWGW1reN49iqOkz3CUbl2cepVQeS1To/sK9ClFxzYEy4hOVa4Vbdch7rbN 9UB7MMj6Ck6Ke5POwZYpW+gqWLz7bJfpmb6DdWt/NQNfGmh9oVkQN6GCr8bVkNOvaiU7 +NXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v54L7UD6yejsgEALST3TN0JngpIJRZj5J+lHDtSeOQg=; b=Dg1hoKCvzIYVNkbKgEnLtdqdZgEtwUUX+CoXRkoeKJAivtXd/p4vscOp09vXhMXmHs VEaomfGb4uuxh1WHqDxsR2AnjpJgtkJRNGAJnEOdkp+qK2/dKsrjgvQLktsbaU5jKpzK LagvHjrMfkAIN6fSm079lhZu2PG2sBLahzostxHB5IoTssCUx+FYr8IRF72RBFBd62uv 4p5SE+Fv0wHBXrCBUb/EJ9qyUroVqMGWRYIHUNqMpjcUGFocaNjwEv65D6Fofq7olfqD +sGxCHbdM42jmyBYQ4opFe3/+MU5w35aI7pvR8dA9uZ7UFri03Y/9Xp7OHLhAFWGTVue Kgrg== X-Gm-Message-State: AOAM530kuUUpdeFhxEupXSCalnoXC5MYXNKlIhJsd9ggBkYWNRJ7qojV 7kJL1P/x4aKOOMWGkS73FfIHRw== X-Google-Smtp-Source: ABdhPJxsY6tYb9LX3F78HhHLT1e+QGs1Yh7Rh+elu7cx9QHkQXWngxX47pv/4IkzJgjIDN/HC6yang== X-Received: by 2002:a05:6402:945:: with SMTP id h5mr3918399edz.6.1603976057554; Thu, 29 Oct 2020 05:54:17 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:17 -0700 (PDT) From: Ibtisam Tariq 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 , jiayu.hu@intel.com, huawei.xie@intel.com Date: Thu, 29 Oct 2020 12:53:37 +0000 Message-Id: <20201029125339.30916-6-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201029125339.30916-1-ibtisam.tariq@emumba.com> References: <20201029125339.30916-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH 6/8] examples/vhost: enhance getopt_long usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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: d19533e86f ("examples/vhost: copy old vhost example") Fixes: bde19a4d4b ("examples/vhost: rename --dev-basename to --socket-file") Cc: jiayu.hu@intel.com Cc: huawei.xie@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/vhost/main.c | 264 +++++++++++++++++++++++------------------- 1 file changed, 143 insertions(+), 121 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index faa482245..8056cac7a 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -450,6 +450,29 @@ us_vhost_usage(const char *prgname) prgname); } +enum { +#define CMD_LINE_OPT_VM2VM "vm2vm" + CMD_LINE_OPT_VM2VM_NUM = 256, +#define CMD_LINE_OPT_RX_RETRY "rx-retry" + CMD_LINE_OPT_RX_RETRY_NUM, +#define CMD_LINE_OPT_RX_RETRY_DELAY "rx-retry-delay" + CMD_LINE_OPT_RX_RETRY_DELAY_NUM, +#define CMD_LINE_OPT_RX_RETRY_NUMB "rx-retry-num" + CMD_LINE_OPT_RX_RETRY_NUMB_NUM, +#define CMD_LINE_OPT_MERGEABLE "mergeable" + CMD_LINE_OPT_MERGEABLE_NUM, +#define CMD_LINE_OPT_STATS "stats" + CMD_LINE_OPT_STATS_NUM, +#define CMD_LINE_OPT_SOCKET_FILE "socket-file" + CMD_LINE_OPT_SOCKET_FILE_NUM, +#define CMD_LINE_OPT_TX_CSUM "tx-csum" + CMD_LINE_OPT_TX_CSUM_NUM, +#define CMD_LINE_OPT_TSO "tso" + CMD_LINE_OPT_TSO_NUM, +#define CMD_LINE_OPT_CLIENT "client" +#define CMD_LINE_OPT_BUILTIN_NET_DRIVER "builtin-net-driver" +}; + /* * Parse the arguments given in the command line of the application. */ @@ -461,17 +484,27 @@ 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}, + {CMD_LINE_OPT_VM2VM, required_argument, + NULL, CMD_LINE_OPT_VM2VM_NUM}, + {CMD_LINE_OPT_RX_RETRY, required_argument, + NULL, CMD_LINE_OPT_RX_RETRY_NUM}, + {CMD_LINE_OPT_RX_RETRY_DELAY, required_argument, + NULL, CMD_LINE_OPT_RX_RETRY_DELAY_NUM}, + {CMD_LINE_OPT_RX_RETRY_NUMB, required_argument, + NULL, CMD_LINE_OPT_RX_RETRY_NUMB_NUM}, + {CMD_LINE_OPT_MERGEABLE, required_argument, + NULL, CMD_LINE_OPT_MERGEABLE_NUM}, + {CMD_LINE_OPT_STATS, required_argument, + NULL, CMD_LINE_OPT_STATS_NUM}, + {CMD_LINE_OPT_SOCKET_FILE, required_argument, + NULL, CMD_LINE_OPT_SOCKET_FILE_NUM}, + {CMD_LINE_OPT_TX_CSUM, required_argument, + NULL, CMD_LINE_OPT_TX_CSUM_NUM}, + {CMD_LINE_OPT_TSO, required_argument, + NULL, CMD_LINE_OPT_TSO_NUM}, + {CMD_LINE_OPT_CLIENT, no_argument, &client_mode, 1}, + {CMD_LINE_OPT_BUILTIN_NET_DRIVER, no_argument, + &builtin_net_driver, 1}, {NULL, 0, 0, 0}, }; @@ -497,126 +530,115 @@ us_vhost_parse_args(int argc, char **argv) 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 CMD_LINE_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; } - - /* 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; - } + vm2vm_mode = (vm2vm_type)ret; + break; + } + case CMD_LINE_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/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; + enable_retry = ret; + break; + } + case CMD_LINE_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/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; + enable_tx_csum = ret; + break; + } + case CMD_LINE_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; } - - /* 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; - } + enable_tso = ret; + break; + } + case CMD_LINE_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; } - - /* 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; - } + burst_rx_delay_time = ret; + break; + } + case CMD_LINE_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; } - - /* 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; - } - } + burst_rx_retry_num = ret; + break; + } + case CMD_LINE_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; } - - /* 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; - } + break; + } + case CMD_LINE_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; - - /* Invalid option - print options. */ + } + case CMD_LINE_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; + } + /* Invalid option - print options. */ default: us_vhost_usage(prgname); return -1; -- 2.17.1