From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id E8E65A0471 for ; Wed, 19 Jun 2019 17:25:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CBD861C43E; Wed, 19 Jun 2019 17:16:44 +0200 (CEST) Received: from mx0.arrikto.com (mx0.arrikto.com [212.71.252.59]) by dpdk.org (Postfix) with ESMTP id 5154C1C3A0 for ; Wed, 19 Jun 2019 17:15:47 +0200 (CEST) Received: from troi.prod.arr (mail.arr [10.99.0.5]) by mx0.arrikto.com (Postfix) with ESMTP id 21CD018201C; Wed, 19 Jun 2019 18:15:47 +0300 (EEST) Received: from localhost.localdomain (unknown [10.89.50.133]) by troi.prod.arr (Postfix) with ESMTPSA id BD9052B2; Wed, 19 Jun 2019 18:15:46 +0300 (EEST) From: Nikos Dragazis To: dev@dpdk.org Cc: Maxime Coquelin , Tiwei Bie , Zhihong Wang , Stefan Hajnoczi , Wei Wang , Stojaczyk Dariusz , Vangelis Koukis Date: Wed, 19 Jun 2019 18:14:49 +0300 Message-Id: <1560957293-17294-25-git-send-email-ndragazis@arrikto.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560957293-17294-1-git-send-email-ndragazis@arrikto.com> References: <1560957293-17294-1-git-send-email-ndragazis@arrikto.com> Subject: [dpdk-dev] [PATCH 24/28] examples/vhost_scsi: add --socket-file argument 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" From: Stefan Hajnoczi The default filename built into examples/vhost_scsi may not be convenient. Allow the user to specify the full UNIX domain socket path on the command-line. Signed-off-by: Stefan Hajnoczi --- examples/vhost_scsi/vhost_scsi.c | 93 ++++++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 18 deletions(-) diff --git a/examples/vhost_scsi/vhost_scsi.c b/examples/vhost_scsi/vhost_scsi.c index 513af0c..d2d02fd 100644 --- a/examples/vhost_scsi/vhost_scsi.c +++ b/examples/vhost_scsi/vhost_scsi.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2017 Intel Corporation */ +#include #include #include #include @@ -402,26 +403,10 @@ static const struct vhost_device_ops vhost_scsi_device_ops = { }; static struct vhost_scsi_ctrlr * -vhost_scsi_ctrlr_construct(const char *ctrlr_name) +vhost_scsi_ctrlr_construct(void) { int ret; struct vhost_scsi_ctrlr *ctrlr; - char *path; - char cwd[PATH_MAX]; - - /* always use current directory */ - path = getcwd(cwd, PATH_MAX); - if (!path) { - fprintf(stderr, "Cannot get current working directory\n"); - return NULL; - } - snprintf(dev_pathname, sizeof(dev_pathname), "%s/%s", path, ctrlr_name); - - if (access(dev_pathname, F_OK) != -1) { - if (unlink(dev_pathname) != 0) - rte_exit(EXIT_FAILURE, "Cannot remove %s.\n", - dev_pathname); - } if (rte_vhost_driver_register(dev_pathname, 0) != 0) { fprintf(stderr, "socket %s already exists\n", dev_pathname); @@ -455,6 +440,71 @@ signal_handler(__rte_unused int signum) exit(0); } +static void +set_dev_pathname(const char *path) +{ + if (dev_pathname[0]) + rte_exit(EXIT_FAILURE, "--socket-file can only be given once.\n"); + + snprintf(dev_pathname, sizeof(dev_pathname), "%s", path); +} + +static void +vhost_scsi_usage(const char *prgname) +{ + fprintf(stderr, "%s [EAL options] --\n" + " --socket-file PATH: The path of the UNIX domain socket\n", + prgname); +} + +static void +vhost_scsi_parse_args(int argc, char **argv) +{ + int opt; + int option_index; + const char *prgname = argv[0]; + static struct option long_option[] = { + {"socket-file", required_argument, NULL, 0}, + {NULL, 0, 0, 0}, + }; + + while ((opt = getopt_long(argc, argv, "", long_option, + &option_index)) != -1) { + switch (opt) { + case 0: + if (!strcmp(long_option[option_index].name, + "socket-file")) { + set_dev_pathname(optarg); + } + break; + default: + vhost_scsi_usage(prgname); + rte_exit(EXIT_FAILURE, "Invalid argument\n"); + } + } +} + +static void +vhost_scsi_set_default_dev_pathname(void) +{ + char *path; + char cwd[PATH_MAX]; + + /* always use current directory */ + path = getcwd(cwd, PATH_MAX); + if (!path) { + rte_exit(EXIT_FAILURE, + "Cannot get current working directory\n"); + } + snprintf(dev_pathname, sizeof(dev_pathname), "%s/vhost.socket", path); + + if (access(dev_pathname, F_OK) != -1) { + if (unlink(dev_pathname) != 0) + rte_exit(EXIT_FAILURE, "Cannot remove %s.\n", + dev_pathname); + } +} + int main(int argc, char *argv[]) { int ret; @@ -465,8 +515,15 @@ int main(int argc, char *argv[]) ret = rte_eal_init(argc, argv); if (ret < 0) rte_exit(EXIT_FAILURE, "Error with EAL initialization\n"); + argc -= ret; + argv += ret; + + vhost_scsi_parse_args(argc, argv); + + if (!dev_pathname[0]) + vhost_scsi_set_default_dev_pathname(); - g_vhost_ctrlr = vhost_scsi_ctrlr_construct("vhost.socket"); + g_vhost_ctrlr = vhost_scsi_ctrlr_construct(); if (g_vhost_ctrlr == NULL) { fprintf(stderr, "Construct vhost scsi controller failed\n"); return 0; -- 2.7.4