From e5a29595c3581ae6b93a82a21c9edaa53cf722dd Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Tue, 30 Nov 2021 13:27:36 +0000 Subject: [PATCH] hotplug.c: add a second switch to parse_args() Add another level of option parsing to allow usage of string values. Currently all values are converted to long (or have to be checked before the switch), which results in errors upon adding a string as a value. This is going to be used in the next patch in the series. Change-Id: Ib874d74b015eee825b5135ef3d49b9cb1c72029b Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10471 Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- examples/nvme/hotplug/hotplug.c | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/examples/nvme/hotplug/hotplug.c b/examples/nvme/hotplug/hotplug.c index 47d2f490d..020715590 100644 --- a/examples/nvme/hotplug/hotplug.c +++ b/examples/nvme/hotplug/hotplug.c @@ -444,31 +444,37 @@ parse_args(int argc, char **argv) return 1; } - if (op == 'm') { - g_iova_mode = optarg; - continue; - } - - val = spdk_strtol(optarg, 10); - if (val < 0) { - fprintf(stderr, "Converting a string to integer failed\n"); - return val; - } switch (op) { case 'c': - g_timeout_in_us = val * SPDK_SEC_TO_USEC; - break; case 'i': - g_shm_id = val; - break; case 'n': - g_expected_insert_times = val; - break; case 'r': - g_expected_removal_times = val; - break; case 't': - g_time_in_sec = val; + val = spdk_strtol(optarg, 10); + if (val < 0) { + fprintf(stderr, "Converting a string to integer failed\n"); + return val; + } + switch (op) { + case 'c': + g_timeout_in_us = val * SPDK_SEC_TO_USEC; + break; + case 'i': + g_shm_id = val; + break; + case 'n': + g_expected_insert_times = val; + break; + case 'r': + g_expected_removal_times = val; + break; + case 't': + g_time_in_sec = val; + break; + } + break; + case 'm': + g_iova_mode = optarg; break; default: usage(argv[0]);