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 059D9591F for ; Thu, 18 Aug 2016 10:27:58 +0200 (CEST) Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 694C63B70C; Thu, 18 Aug 2016 08:27:57 +0000 (UTC) Received: from [10.36.4.244] (vpn1-4-244.ams2.redhat.com [10.36.4.244]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7I8RtwR029072 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 18 Aug 2016 04:27:56 -0400 To: Jiayu Hu , dev@dpdk.org References: <1471364079-116217-1-git-send-email-jiayu.hu@intel.com> <1471364079-116217-3-git-send-email-jiayu.hu@intel.com> From: Maxime Coquelin Message-ID: Date: Thu, 18 Aug 2016 10:27:55 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1471364079-116217-3-git-send-email-jiayu.hu@intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 18 Aug 2016 08:27:57 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH 2/2] examples/vhost: support multiple socket files X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2016 08:27:58 -0000 On 08/16/2016 06:14 PM, Jiayu Hu wrote: > When examples/vhost runs in client mode, only one QEMU can be connected. > This is because that examples/vhost just supports one socket file. This > patch is to add multiple sockets support for examples/vhost. > > Signed-off-by: Jiayu Hu > --- > examples/vhost/main.c | 50 ++++++++++++++++++++++++++++++++++++++------------ > 1 file changed, 38 insertions(+), 12 deletions(-) > > diff --git a/examples/vhost/main.c b/examples/vhost/main.c > index a718577..9974f0b 100644 > --- a/examples/vhost/main.c > +++ b/examples/vhost/main.c > @@ -136,8 +136,9 @@ static uint32_t burst_rx_delay_time = BURST_RX_WAIT_US; > /* Specify the number of retries on RX. */ > static uint32_t burst_rx_retry_num = BURST_RX_RETRIES; > > -/* Socket file path. Can be set by user */ > -static char socket_file[PATH_MAX] = "vhost-net"; Default name being removed, you can drop my comment on patch 1. :) > +/* Socket file paths. Can be set by user */ > +static char *socket_files; > +int nb_sockets; Any reason not to make it static? > /* empty vmdq configuration structure. Filled in programatically */ > static struct rte_eth_conf vmdq_conf_default = { > @@ -395,11 +396,12 @@ static int > us_vhost_parse_socket_path(const char *q_arg) > { > /* parse number string */ > - > if (strnlen(q_arg, PATH_MAX) > PATH_MAX) > return -1; > - else > - snprintf((char *)&socket_file, PATH_MAX, "%s", q_arg); > + > + socket_files = realloc(socket_files, PATH_MAX * (nb_sockets + 1)); > + snprintf(socket_files + nb_sockets * PATH_MAX, PATH_MAX, "%s", q_arg); > + nb_sockets++; > > return 0; > } > @@ -1341,14 +1343,30 @@ print_stats(void) > } > } > > +/* > + * This function is used to unregister drivers. > + */ > +static void > +unregister_drivers(int socket_num) > +{ > + int i, ret; > + > + for (i = 0; i < socket_num; i++) { > + ret = rte_vhost_driver_unregister(socket_files + i * PATH_MAX); > + if (ret != 0) > + RTE_LOG(ERR, VHOST_CONFIG, > + "Fail to unregister vhost driver for %s.\n", > + socket_files + i * PATH_MAX); > + } > +} > + > /* When we receive a INT signal, unregister vhost driver */ > static void > sigint_handler(__rte_unused int signum) > { > /* Unregister vhost driver. */ > - int ret = rte_vhost_driver_unregister((char *)&socket_file); > - if (ret != 0) > - rte_exit(EXIT_FAILURE, "vhost driver unregister failure.\n"); > + unregister_drivers(nb_sockets); > + > exit(0); > } > > @@ -1412,12 +1430,15 @@ main(int argc, char *argv[]) > { > unsigned lcore_id, core_id = 0; > unsigned nb_ports, valid_num_ports; > - int ret; > + int ret, i; > uint8_t portid; > static pthread_t tid; > char thread_name[RTE_MAX_THREAD_NAME_LEN]; > uint64_t flags = 0; > > + nb_sockets = 0; > + socket_files = NULL; Since socket_files is static, no need to initialize it to NULL. If you staticize nb_sockets, same remark will apply.