+ for (i = 1; i < dev->max_queue_pairs; i++) {
+ data->tapfds[i] = tap_open(dev->ifname, true);
+ if (data->tapfds[i] < 0)
+ goto err_tapfds;
+ }
+
+ dev->backend_data = data;
+
+ return 0;
+
+err_tapfds:
+ for (i = 0; i < dev->max_queue_pairs; i++) {
+ if (data->vhostfds[i] >= 0)
+ close(data->vhostfds[i]);
+ if (data->tapfds[i] >= 0)
+ close(data->tapfds[i]);
+ }
+
+ free(data->tapfds);
+err_vhostfds:
+ free(data->vhostfds);
+err_data:
+ free(data);
+
+ return -1;
+}
+
+static int
+vhost_kernel_destroy(struct virtio_user_dev *dev)
+{
+ struct vhost_kernel_data *data = dev->backend_data;
+ uint32_t i;
+
+ if (!data)
+ return 0;
+
+ for (i = 0; i < dev->max_queue_pairs; ++i) {
+ if (data->vhostfds[i] >= 0)
+ close(data->vhostfds[i]);
+ if (data->tapfds[i] >= 0)
+ close(data->tapfds[i]);
+ }
+
+ free(data->vhostfds);
+ free(data->tapfds);
+ free(data);
+ dev->backend_data = NULL;
+