Invoke get_device() at the beginning of vhost_user_msg_handler, so that
we could check the return value once. Which could save tons of duplicate
get-and-check device.
Signed-off-by: Yuanhan Liu
---
lib/librte_vhost/vhost_user.c | 160 +-
1 file changed, 47 insertions(+), 113 deletions(-)
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index de3048c..ef4a0c1 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -134,29 +134,17 @@ vhost_backend_cleanup(struct virtio_net *dev)
* the device hasn't been initialised.
*/
static int
-vhost_user_set_owner(int vid)
+vhost_user_set_owner(void)
{
- struct virtio_net *dev;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
return 0;
}
static int
-vhost_user_reset_owner(int vid)
+vhost_user_reset_owner(struct virtio_net *dev)
{
- struct virtio_net *dev;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
if (dev->flags & VIRTIO_DEV_RUNNING) {
dev->flags &= ~VIRTIO_DEV_RUNNING;
- notify_ops->destroy_device(vid);
+ notify_ops->destroy_device(dev->vid);
}
cleanup_device(dev, 0);
@@ -168,15 +156,8 @@ vhost_user_reset_owner(int vid)
* The features that we support are requested.
*/
static int
-vhost_user_get_features(int vid, uint64_t *pu)
+vhost_user_get_features(uint64_t *pu)
{
- struct virtio_net *dev;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
- /* Send our supported features. */
*pu = VHOST_FEATURES;
return 0;
}
@@ -185,13 +166,8 @@ vhost_user_get_features(int vid, uint64_t *pu)
* We receive the negotiated features supported by us and the virtio device.
*/
static int
-vhost_user_set_features(int vid, uint64_t *pu)
+vhost_user_set_features(struct virtio_net *dev, uint64_t *pu)
{
- struct virtio_net *dev;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
if (*pu & ~VHOST_FEATURES)
return -1;
@@ -215,15 +191,9 @@ vhost_user_set_features(int vid, uint64_t *pu)
* The virtio device sends us the size of the descriptor ring.
*/
static int
-vhost_user_set_vring_num(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_num(struct virtio_net *dev,
+struct vhost_vring_state *state)
{
- struct virtio_net *dev;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
- /* State->index refers to the queue index. The txq is 1, rxq is 0. */
dev->virtqueue[state->index]->size = state->num;
return 0;
@@ -343,13 +313,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
* This function then converts these to our address space.
*/
static int
-vhost_user_set_vring_addr(int vid, struct vhost_vring_addr *addr)
+vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr
*addr)
{
- struct virtio_net *dev;
struct vhost_virtqueue *vq;
- dev = get_device(vid);
- if ((dev == NULL) || (dev->mem == NULL))
+ if (dev->mem == NULL)
return -1;
/* addr->index refers to the queue index. The txq 1, rxq is 0. */
@@ -412,40 +380,28 @@ vhost_user_set_vring_addr(int vid, struct
vhost_vring_addr *addr)
* The virtio device sends us the available ring last used index.
*/
static int
-vhost_user_set_vring_base(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_base(struct virtio_net *dev,
+ struct vhost_vring_state *state)
{
- struct virtio_net *dev;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
- /* State->index refers to the queue index. The txq is 1, rxq is 0. */
dev->virtqueue[state->index]->last_used_idx = state->num;
return 0;
}
static int
-vhost_user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
+vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)
{
struct VhostUserMemory memory = pmsg->payload.memory;
struct virtio_memory_regions *pregion;
uint64_t mapped_address, mapped_size;
- struct virtio_net *dev;
unsigned int idx = 0;
struct orig_region_map *pregion_orig;
uint64_t alignment;
- /* unmap old memory regions one by one*/
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
/* Remove from the data plane. */
if (dev->flags & VIRTIO_DEV_RUNNING) {
dev->flags &= ~VIRTIO_DEV_RUNNING;
- notify_ops->destroy_device(vid);
+ notify_ops->destroy_device(dev->vid);
}
if (dev->mem) {
@@ -587,16 +543,12 @@ virtio_is_ready(struct virtio_net *dev)
}
static void
-vhost_user_set_vring_call(int vid, struct VhostUserMsg *pm