Thread (149 messages) 149 messages, 6 authors, 2021-01-18

Re: [dpdk-dev] [PATCH 39/40] net/virtio: move Vhost-kernel data to its backend

From: Xia, Chenbo <hidden>
Date: 2021-01-07 06:43:37

Hi Maxime,
-----Original Message-----
From: Maxime Coquelin <redacted>
Sent: Monday, December 21, 2020 5:14 AM
To: dev@dpdk.org; Xia, Chenbo <redacted>; olivier.matz@6wind.com;
amorenoz@redhat.com; david.marchand@redhat.com
Cc: Maxime Coquelin <redacted>
Subject: [PATCH 39/40] net/virtio: move Vhost-kernel data to its backend

As done earlier for Vhost-user, this patch moves the
Vhost-Kernel specific data to its backend file.

Signed-off-by: Maxime Coquelin <redacted>
---
 drivers/net/virtio/virtio_user/vhost_kernel.c | 78 +++++++++++++++----
 .../net/virtio/virtio_user/virtio_user_dev.c  | 43 ++--------
 .../net/virtio/virtio_user/virtio_user_dev.h  |  7 +-
 3 files changed, 72 insertions(+), 56 deletions(-)
<snip>
quoted hunk ↗ jump to hunk
@@ -339,19 +353,37 @@ static int
 vhost_kernel_setup(struct virtio_user_dev *dev)
 {
 	int vhostfd;
-	uint32_t i;
+	uint32_t q, i;
+	struct vhost_kernel_data *data;
+
+	data = malloc(sizeof(*data));
+	if (!data) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to allocate Vhost-kernel data",
dev->path);
+		return -1;
+	}
+
+	data->vhostfds = malloc(dev->max_queue_pairs * sizeof(int));
+	data->tapfds = malloc(dev->max_queue_pairs * sizeof(int));
+	if (!data->vhostfds || !data->tapfds) {
+		PMD_INIT_LOG(ERR, "(%s) Failed to allocate FDs", dev->path);
+		return -1;
+	}
+
+	for (q = 0; q < dev->max_queue_pairs; ++q) {
+		data->vhostfds[q] = -1;
+		data->tapfds[q] = -1;
+	}

 	get_vhost_kernel_max_regions();

 	for (i = 0; i < dev->max_queue_pairs; ++i) {
 		vhostfd = open(dev->path, O_RDWR);
 		if (vhostfd < 0) {
-			PMD_DRV_LOG(ERR, "fail to open %s, %s",
-				    dev->path, strerror(errno));
+			PMD_DRV_LOG(ERR, "fail to open %s, %s", dev->path,
strerror(errno));
 			return -1;
 		}
In this function, should we clean-up malloced resources when error happens?

Thanks,
Chenbo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help