From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 427981B38D for ; Fri, 19 Jan 2018 14:48:07 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A8BE6C0272F6; Fri, 19 Jan 2018 13:48:06 +0000 (UTC) Received: from localhost (ovpn-116-254.ams2.redhat.com [10.36.116.254]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B8385D6B2; Fri, 19 Jan 2018 13:47:59 +0000 (UTC) From: Stefan Hajnoczi To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, Yuanhan Liu , wei.w.wang@intel.com, mst@redhat.com, zhiyong.yang@intel.com, jasowang@redhat.com, Stefan Hajnoczi Date: Fri, 19 Jan 2018 13:44:40 +0000 Message-Id: <20180119134444.24927-21-stefanha@redhat.com> In-Reply-To: <20180119134444.24927-1-stefanha@redhat.com> References: <20180119134444.24927-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jan 2018 13:48:06 +0000 (UTC) Subject: [dpdk-dev] [RFC 20/24] 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: , X-List-Received-Date: Fri, 19 Jan 2018 13:48:07 -0000 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 da01ad378..0a8302e02 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 @@ -359,26 +360,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); @@ -412,6 +397,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; @@ -422,8 +472,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; - g_vhost_ctrlr = vhost_scsi_ctrlr_construct("vhost.socket"); + vhost_scsi_parse_args(argc, argv); + + if (!dev_pathname[0]) + vhost_scsi_set_default_dev_pathname(); + + g_vhost_ctrlr = vhost_scsi_ctrlr_construct(); if (g_vhost_ctrlr == NULL) { fprintf(stderr, "Construct vhost scsi controller failed\n"); return 0; -- 2.14.3