From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CB6D1A0A0E; Thu, 4 Feb 2021 08:35:15 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9B6C52405BB; Thu, 4 Feb 2021 08:35:00 +0100 (CET) Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by mails.dpdk.org (Postfix) with ESMTP id 80588240581 for ; Thu, 4 Feb 2021 08:34:59 +0100 (CET) Received: by mail-wr1-f45.google.com with SMTP id v15so2277923wrx.4 for ; Wed, 03 Feb 2021 23:34:59 -0800 (PST) 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=v2aa+4+YUf8WV7rnmTdvFLYMbKyOLWBq8ATGNNvybCs=; b=XgoH18bpmx+mnnMJjn72q76V1eKnsQYSZVegnY9uAlCSd0QMloSlfmi0GhseQ9vT8R 0SykWiMRtAJW3obaY1C15jj4FmurMB5Gigha6YYFRYY5VKL3lt7t8zNjt4Qt2lK/An4r OGtuofw5KrYCx6OLGlHVaPive51CdGQMH9ilvAG/A68VrqieEEeoFWKYeXvbLTaidAQi kf7hOmwy4w41DC712YBVd9XqJjn/d2dCy7OGdixzB+SdxbMEH5Hwg/pS/iFMDmN39JYj dlnto1bEtnr8M+OgFceGhkG7M3q/dEJ1jsR1X5PxOW58kXb+xLNfAX+cXv8vQVQNviQ8 DYrA== 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=v2aa+4+YUf8WV7rnmTdvFLYMbKyOLWBq8ATGNNvybCs=; b=EPz9Ti9vzhNBzVrzBsNCIWazh2QbdHdGxsuZcPwpo11C5/YgRGWsQ/b8TE+oAq1K60 9odRUP/SwMntymN0dlOMhdO3x/GoPpr8FgA3r5MdBwu0h/Qll99CTa991MfANaMbCGqB f3ff3Xt/Akb05mTYtzSKKYjnAG6MSktS9cWoRrzozT41kpGxa42tp8z4dI0b9gNi77/F j7yDijuXkiibsRGW5OcRebdHZVzyHZvUgLt2ELzECn0bntpZ9d6hi9J8t1N5TZv4FPo3 706jRPP/n8MODWJcJgwZ8LuS/dcA7DiabqwJD7hkD9ecRRwl2kCNS7HElfGGK1eGebfb FU6Q== X-Gm-Message-State: AOAM533Ofb2WdTLjH+DCIuynHEuDvKIaQ2TTdSnQJlmg4bTmA+OgDAF4 VMPGKRxHYv/+YiaEDBfQVQVE5A== X-Google-Smtp-Source: ABdhPJyGSbWfJACczpmHQvDTlmOpqWPL0xE5+GxDpEPrS6ym7xvPkMre+Ia962hHZsWreyNzfiBWgw== X-Received: by 2002:a5d:5686:: with SMTP id f6mr7555870wrv.257.1612424099129; Wed, 03 Feb 2021 23:34:59 -0800 (PST) Received: from localhost.localdomain ([39.33.143.135]) by smtp.gmail.com with ESMTPSA id j11sm7082604wrt.26.2021.02.03.23.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 23:34:58 -0800 (PST) From: Ibtisam Tariq To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, cristian.dumitrescu@intel.com, jasvinder.singh@intel.com, john.mcnamara@intel.com, reshma.pattan@intel.com, konstantin.ananyev@intel.com, marko.kovacevic@intel.com Cc: dev@dpdk.org, Ibtisam Tariq , jiayu.hu@intel.com, huawei.xie@intel.com Date: Thu, 4 Feb 2021 07:34:19 +0000 Message-Id: <20210204073420.2421-6-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210204073420.2421-1-ibtisam.tariq@emumba.com> References: <20210204073420.2421-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH v4 6/7] examples/vhost: enhance getopt_long usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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. 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 Signed-off-by: Ibtisam Tariq --- v4: * Set indentation of preprocessor directives. * Add enums for OPT_BUILTIN_NET_DRIVER and OPT_CLIENT in getopt_long. 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 | 288 +++++++++++++++++++++++------------------- 1 file changed, 155 insertions(+), 133 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 233a2dc6e..465981ac3 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -478,6 +478,35 @@ 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" + OPT_CLIENT_NUM, +#define OPT_BUILTIN_NET_DRIVER "builtin-net-driver" + OPT_BUILTIN_NET_DRIVER_NUM, +#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. */ @@ -489,19 +518,32 @@ 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, + NULL, OPT_CLIENT_NUM}, + {OPT_BUILTIN_NET_DRIVER, no_argument, + NULL, OPT_BUILTIN_NET_DRIVER_NUM}, + {OPT_DMA_TYPE, required_argument, + NULL, OPT_DMA_TYPE_NUM}, + {OPT_DMAS, required_argument, + NULL, OPT_DMAS_NUM}, {NULL, 0, 0, 0}, }; @@ -524,151 +566,131 @@ 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: + 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; + + case OPT_CLIENT_NUM: + client_mode = 1; + break; + case OPT_BUILTIN_NET_DRIVER_NUM: + builtin_net_driver = 1; break; - /* Invalid option - print options. */ + /* Invalid option - print options. */ default: us_vhost_usage(prgname); return -1; -- 2.17.1