From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: dev@dpdk.org
Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [dpdk-dev] [PATCH 4/7] vhost: fold common message handlers
Date: Thu, 18 Aug 2016 16:48:40 +0800 [thread overview]
Message-ID: <1471510123-4984-5-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1471510123-4984-1-git-send-email-yuanhan.liu@linux.intel.com>
Due to history reason (that we have 2 vhost implementations), some
messages are handled in two calls: vhost specific implementation
handles it first and then invoke the common one to do another handling.
We have one implementation only now, we could write one method for
each message. Here fold those common handles to corresponding vhost
user handler.
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
lib/librte_vhost/vhost_user.c | 115 ++++++++++++------------------------------
1 file changed, 31 insertions(+), 84 deletions(-)
diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index c4714b7..ada0a63 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -426,87 +426,6 @@ vhost_set_vring_base(int vid, struct vhost_vring_state *state)
return 0;
}
-/*
- * We send the virtio device our available ring last used index.
- */
-static int
-vhost_get_vring_base(int vid, uint32_t index,
- struct vhost_vring_state *state)
-{
- struct virtio_net *dev;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
- state->index = index;
- /* State->index refers to the queue index. The txq is 1, rxq is 0. */
- state->num = dev->virtqueue[state->index]->last_used_idx;
-
- return 0;
-}
-
-/*
- * The virtio device sends an eventfd to interrupt the guest. This fd gets
- * copied into our process space.
- */
-static int
-vhost_set_vring_call(int vid, struct vhost_vring_file *file)
-{
- struct virtio_net *dev;
- struct vhost_virtqueue *vq;
- uint32_t cur_qp_idx = file->index / VIRTIO_QNUM;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
- /*
- * FIXME: VHOST_SET_VRING_CALL is the first per-vring message
- * we get, so we do vring queue pair allocation here.
- */
- if (cur_qp_idx + 1 > dev->virt_qp_nb) {
- if (alloc_vring_queue_pair(dev, cur_qp_idx) < 0)
- return -1;
- }
-
- /* file->index refers to the queue index. The txq is 1, rxq is 0. */
- vq = dev->virtqueue[file->index];
- assert(vq != NULL);
-
- if (vq->callfd >= 0)
- close(vq->callfd);
-
- vq->callfd = file->fd;
-
- return 0;
-}
-
-/*
- * The virtio device sends an eventfd that it can use to notify us.
- * This fd gets copied into our process space.
- */
-static int
-vhost_set_vring_kick(int vid, struct vhost_vring_file *file)
-{
- struct virtio_net *dev;
- struct vhost_virtqueue *vq;
-
- dev = get_device(vid);
- if (dev == NULL)
- return -1;
-
- /* file->index refers to the queue index. The txq is 1, rxq is 0. */
- vq = dev->virtqueue[file->index];
-
- if (vq->kickfd >= 0)
- close(vq->kickfd);
-
- vq->kickfd = file->fd;
-
- return 0;
-}
-
static int
user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
{
@@ -671,6 +590,12 @@ static void
user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
{
struct vhost_vring_file file;
+ struct virtio_net *dev = get_device(vid);
+ struct vhost_virtqueue *vq;
+ uint32_t cur_qp_idx;
+
+ if (!dev)
+ return;
file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
@@ -679,7 +604,24 @@ user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring call idx:%d file:%d\n", file.index, file.fd);
- vhost_set_vring_call(vid, &file);
+
+ /*
+ * FIXME: VHOST_SET_VRING_CALL is the first per-vring message
+ * we get, so we do vring queue pair allocation here.
+ */
+ cur_qp_idx = file.index / VIRTIO_QNUM;
+ if (cur_qp_idx + 1 > dev->virt_qp_nb) {
+ if (alloc_vring_queue_pair(dev, cur_qp_idx) < 0)
+ return;
+ }
+
+ vq = dev->virtqueue[file.index];
+ assert(vq != NULL);
+
+ if (vq->callfd >= 0)
+ close(vq->callfd);
+
+ vq->callfd = file.fd;
}
/*
@@ -691,6 +633,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
{
struct vhost_vring_file file;
struct virtio_net *dev = get_device(vid);
+ struct vhost_virtqueue *vq;
if (!dev)
return;
@@ -702,7 +645,11 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring kick idx:%d file:%d\n", file.index, file.fd);
- vhost_set_vring_kick(vid, &file);
+
+ vq = dev->virtqueue[file.index];
+ if (vq->kickfd >= 0)
+ close(vq->kickfd);
+ vq->kickfd = file.fd;
if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
if (notify_ops->new_device(vid) == 0)
@@ -727,7 +674,7 @@ user_get_vring_base(int vid, struct vhost_vring_state *state)
}
/* Here we are safe to get the last used index */
- vhost_get_vring_base(vid, state->index, state);
+ state->num = dev->virtqueue[state->index]->last_used_idx;
RTE_LOG(INFO, VHOST_CONFIG,
"vring base idx:%d file:%d\n", state->index, state->num);
--
1.9.0
next prev parent reply other threads:[~2016-08-18 8:40 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-18 8:48 [dpdk-dev] [PATCH 0/7] vhost: vhost-cuse removal and code path refactoring Yuanhan Liu
2016-08-18 8:48 ` [dpdk-dev] [PATCH 1/7] vhost: remove vhost-cuse Yuanhan Liu
2016-08-22 13:46 ` Thomas Monjalon
2016-08-22 14:09 ` Yuanhan Liu
2016-08-29 6:45 ` Yuanhan Liu
2016-08-24 7:42 ` Maxime Coquelin
2016-08-18 8:48 ` [dpdk-dev] [PATCH 2/7] vhost: remove sub source dir Yuanhan Liu
2016-08-24 7:44 ` Maxime Coquelin
2016-08-18 8:48 ` [dpdk-dev] [PATCH 3/7] vhost: refactor source code structure Yuanhan Liu
2016-08-24 7:53 ` Maxime Coquelin
2016-08-18 8:48 ` Yuanhan Liu [this message]
2016-08-24 8:01 ` [dpdk-dev] [PATCH 4/7] vhost: fold common message handlers Maxime Coquelin
2016-08-18 8:48 ` [dpdk-dev] [PATCH 5/7] vhost: unify function names Yuanhan Liu
2016-08-24 8:02 ` Maxime Coquelin
2016-08-18 8:48 ` [dpdk-dev] [PATCH 6/7] vhost: get device once Yuanhan Liu
2016-08-24 8:04 ` Maxime Coquelin
2016-08-18 8:48 ` [dpdk-dev] [PATCH 7/7] vhost: simplify features set/get Yuanhan Liu
2016-08-24 8:11 ` Maxime Coquelin
2016-08-25 3:03 ` Yuanhan Liu
2016-08-25 7:18 ` Maxime Coquelin
2016-08-25 8:36 ` Xu, Qian Q
2016-08-25 9:10 ` Maxime Coquelin
2016-08-26 4:15 ` Yuanhan Liu
2016-08-24 7:30 ` [dpdk-dev] [PATCH 0/7] vhost: vhost-cuse removal and code path refactoring Xu, Qian Q
2016-08-24 7:47 ` Yuanhan Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1471510123-4984-5-git-send-email-yuanhan.liu@linux.intel.com \
--to=yuanhan.liu@linux.intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).