MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vhost_new_device

Function vhost_new_device

dpdk/lib/vhost/vhost.c:693–744  ·  view source on GitHub ↗

* Invoked when there is a new vhost-user connection established (when * there is a new virtio device being attached). */

Source from the content-addressed store, hash-verified

691 * there is a new virtio device being attached).
692 */
693int
694vhost_new_device(struct vhost_backend_ops *ops)
695{
696 struct virtio_net *dev;
697 int i;
698
699 if (ops == NULL) {
700 VHOST_LOG_CONFIG("device", ERR, "missing backend ops.\n");
701 return -1;
702 }
703
704 if (ops->iotlb_miss == NULL) {
705 VHOST_LOG_CONFIG("device", ERR, "missing IOTLB miss backend op.\n");
706 return -1;
707 }
708
709 if (ops->inject_irq == NULL) {
710 VHOST_LOG_CONFIG("device", ERR, "missing IRQ injection backend op.\n");
711 return -1;
712 }
713
714 pthread_mutex_lock(&vhost_dev_lock);
715 for (i = 0; i < RTE_MAX_VHOST_DEVICE; i++) {
716 if (vhost_devices[i] == NULL)
717 break;
718 }
719
720 if (i == RTE_MAX_VHOST_DEVICE) {
721 VHOST_LOG_CONFIG("device", ERR, "failed to find a free slot for new device.\n");
722 pthread_mutex_unlock(&vhost_dev_lock);
723 return -1;
724 }
725
726 dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0);
727 if (dev == NULL) {
728 VHOST_LOG_CONFIG("device", ERR, "failed to allocate memory for new device.\n");
729 pthread_mutex_unlock(&vhost_dev_lock);
730 return -1;
731 }
732
733 vhost_devices[i] = dev;
734 pthread_mutex_unlock(&vhost_dev_lock);
735
736 dev->vid = i;
737 dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET;
738 dev->backend_req_fd = -1;
739 dev->postcopy_ufd = -1;
740 rte_spinlock_init(&dev->backend_req_lock);
741 dev->backend_ops = ops;
742
743 return i;
744}
745
746void
747vhost_destroy_device_notify(struct virtio_net *dev)

Callers 2

vduse_device_createFunction · 0.85
vhost_user_new_deviceFunction · 0.85

Calls 4

pthread_mutex_lockFunction · 0.85
pthread_mutex_unlockFunction · 0.85
rte_zmallocFunction · 0.85
rte_spinlock_initFunction · 0.85

Tested by

no test coverage detected