/* * Function is called from the CUSE open function. The device structure is * initialised and a new entry is added to the device configuration linked * list. */ static int new_device(struct vhost_device_ctx ctx) { struct virtio_net_config_ll *new_ll_dev; struct vhost_virtqueue *virtqueue_rx, *virtqueue_tx; /* Setup device and virtqueues. */ new_ll_dev = malloc(sizeof(struct virtio_net_config_ll)); if (new_ll_dev == NULL) { RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for dev.\n", ctx.fh); return -1; } virtqueue_rx = malloc(sizeof(struct vhost_virtqueue)); if (virtqueue_rx == NULL) { free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for rxq.\n", ctx.fh); return -1; } virtqueue_tx = malloc(sizeof(struct vhost_virtqueue)); if (virtqueue_tx == NULL) { free(virtqueue_rx); free(new_ll_dev); RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for txq.\n", ctx.fh); return -1; } new_ll_dev->dev.virtqueue[VIRTIO_RXQ] = virtqueue_rx; new_ll_dev->dev.virtqueue[VIRTIO_TXQ] = virtqueue_tx; /* Initialise device and virtqueues. */ init_device(&new_ll_dev->dev); new_ll_dev->next = NULL; /* Add entry to device configuration linked list. */ add_config_ll_entry(new_ll_dev); return new_ll_dev->dev.device_fh; }
/* * Function is called from the CUSE open function. The device structure is * initialised and a new entry is added to the device configuration linked * list. */ static int new_device(struct vhost_device_ctx ctx) { struct virtio_net_config_ll *new_ll_dev; /* Setup device and virtqueues. */ new_ll_dev = rte_zmalloc(NULL, sizeof(struct virtio_net_config_ll), 0); if (new_ll_dev == NULL) { RTE_LOG(ERR, VHOST_CONFIG, "(%"PRIu64") Failed to allocate memory for dev.\n", ctx.fh); return -1; } new_ll_dev->next = NULL; /* Add entry to device configuration linked list. */ add_config_ll_entry(new_ll_dev); return new_ll_dev->dev.device_fh; }