DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jiayu Hu <jiayu.hu@intel.com>
To: dev@dpdk.org
Cc: maxime.coquelin@redhat.com, yuanhan.liu@intel.com,
	Jiayu Hu <jiayu.hu@intel.com>
Subject: [dpdk-dev] [PATCH 2/2] examples/vhost: support multiple socket files
Date: Sat, 20 Aug 2016 06:11:36 -0400	[thread overview]
Message-ID: <1471687896-17889-1-git-send-email-jiayu.hu@intel.com> (raw)
In-Reply-To: <1471364079-116217-3-git-send-email-jiayu.hu@intel.com>

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 <jiayu.hu@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 examples/vhost/main.c | 45 +++++++++++++++++++++++++++++++++------------
 1 file changed, 33 insertions(+), 12 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index a718577..71f6d92 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";
+/* Socket file paths. Can be set by user */
+static char *socket_files;
+static int nb_sockets;
 
 /* 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,27 @@ print_stats(void)
 	}
 }
 
+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,7 +1427,7 @@ 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];
@@ -1511,9 +1526,15 @@ main(int argc, char *argv[])
 		flags |= RTE_VHOST_USER_CLIENT;
 
 	/* Register vhost user driver to handle vhost messages. */
-	ret = rte_vhost_driver_register(socket_file, flags);
-	if (ret != 0)
-		rte_exit(EXIT_FAILURE, "vhost driver register failure.\n");
+	for (i = 0; i < nb_sockets; i++) {
+		ret = rte_vhost_driver_register
+				(socket_files + i * PATH_MAX, flags);
+		if (ret != 0) {
+			unregister_drivers(i);
+			rte_exit(EXIT_FAILURE,
+				"vhost driver register failure.\n");
+		}
+	}
 
 	rte_vhost_driver_callback_register(&virtio_net_device_ops);
 
-- 
2.7.4

  parent reply	other threads:[~2016-08-21  2:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-16 16:14 [dpdk-dev] [PATCH 0/2] examples/vhost: rename a CLI option and " Jiayu Hu
2016-08-16 16:14 ` [dpdk-dev] [PATCH 1/2] examples/vhost: rename dev-basename Jiayu Hu
2016-08-18  8:22   ` Maxime Coquelin
2016-08-18  8:35     ` Yuanhan Liu
2016-08-18  8:29       ` Maxime Coquelin
2016-08-20 10:10   ` Jiayu Hu
2016-08-23  6:01     ` Yuanhan Liu
2016-08-16 16:14 ` [dpdk-dev] [PATCH 2/2] examples/vhost: support multiple socket files Jiayu Hu
2016-08-18  8:01   ` Yuanhan Liu
2016-08-18  8:27   ` Maxime Coquelin
2016-08-18  8:43     ` Yuanhan Liu
2016-08-20 10:11   ` Jiayu Hu [this message]
2016-08-23  6:05     ` Yuanhan Liu
2016-08-20 10:08 ` [dpdk-dev] [PATCH 0/2] examples/vhost: rename a CLI option and " Jiayu Hu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471687896-17889-1-git-send-email-jiayu.hu@intel.com \
    --to=jiayu.hu@intel.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=yuanhan.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).