vhost: export device id as the interface to applications
[dpdk.git] / lib / librte_vhost / vhost_user / virtio-net-user.c
index ae405e8..a3b707e 100644 (file)
@@ -117,7 +117,7 @@ user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
        /* Remove from the data plane. */
        if (dev->flags & VIRTIO_DEV_RUNNING) {
                dev->flags &= ~VIRTIO_DEV_RUNNING;
-               notify_ops->destroy_device(dev);
+               notify_ops->destroy_device(vid);
        }
 
        if (dev->mem) {
@@ -279,6 +279,9 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
        struct vhost_vring_file file;
        struct virtio_net *dev = get_device(vid);
 
+       if (!dev)
+               return;
+
        file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
        if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
                file.fd = VIRTIO_INVALID_EVENTFD;
@@ -289,7 +292,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
        vhost_set_vring_kick(vid, &file);
 
        if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
-               if (notify_ops->new_device(dev) == 0)
+               if (notify_ops->new_device(vid) == 0)
                        dev->flags |= VIRTIO_DEV_RUNNING;
        }
 }
@@ -306,7 +309,7 @@ user_get_vring_base(int vid, struct vhost_vring_state *state)
                return -1;
        /* We have to stop the queue (virtio) if it is running. */
        if (dev->flags & VIRTIO_DEV_RUNNING)
-               notify_ops->destroy_device(dev);
+               notify_ops->destroy_device(vid);
 
        /* Here we are safe to get the last used index */
        vhost_get_vring_base(vid, state->index, state);
@@ -340,9 +343,8 @@ user_set_vring_enable(int vid, struct vhost_vring_state *state)
                "set queue enable: %d to qp idx: %d\n",
                enable, state->index);
 
-       if (notify_ops->vring_state_changed) {
-               notify_ops->vring_state_changed(dev, state->index, enable);
-       }
+       if (notify_ops->vring_state_changed)
+               notify_ops->vring_state_changed(vid, state->index, enable);
 
        dev->virtqueue[state->index]->enabled = enable;