From: Asias He <asias.hejun@gmail.com>
To: Pekka Enberg <penberg@kernel.org>, Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>,
Prasad Joshi <prasadjoshi124@gmail.com>,
kvm@vger.kernel.org, Asias He <asias.hejun@gmail.com>
Subject: [PATCH 2/3] kvm tools: add some helper functions for virt_queue
Date: Fri, 8 Apr 2011 10:05:08 +0800 [thread overview]
Message-ID: <1302228309-6583-2-git-send-email-asias.hejun@gmail.com> (raw)
In-Reply-To: <1302228309-6583-1-git-send-email-asias.hejun@gmail.com>
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/virtqueue.h | 42 +++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/virtqueue.h b/tools/kvm/include/kvm/virtqueue.h
index 83f5293..de360ae 100644
--- a/tools/kvm/include/kvm/virtqueue.h
+++ b/tools/kvm/include/kvm/virtqueue.h
@@ -4,6 +4,9 @@
#include <linux/virtio_ring.h>
#include <stdint.h>
+#include <sys/uio.h>
+
+#include "kvm/kvm.h"
struct virt_queue {
struct vring vring;
@@ -28,4 +31,43 @@ static inline struct vring_used_elem *virt_queue__get_used_elem(struct virt_queu
return &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
}
+static inline struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len)
+{
+ struct vring_used_elem *used_elem;
+ used_elem = &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
+ used_elem->id = head;
+ used_elem->len = len;
+ return used_elem;
+}
+
+static inline bool virt_queue__available(struct virt_queue *vq)
+{
+ return vq->vring.avail->idx != vq->last_avail_idx;
+}
+
+static inline uint16_t virt_queue__get_iov(struct virt_queue *queue, struct iovec iov[], uint16_t *out, uint16_t *in, struct kvm *kvm)
+{
+ struct vring_desc *desc;
+ uint16_t head, idx;
+
+ idx = head = virt_queue__pop(queue);
+ *out = *in = 0;
+
+ do {
+ desc = virt_queue__get_desc(queue, idx);
+ iov[*out + *in].iov_base = guest_flat_to_host(kvm, desc->addr);
+ iov[*out + *in].iov_len = desc->len;
+ if (desc->flags & VRING_DESC_F_WRITE)
+ (*in)++;
+ else
+ (*out)++;
+ if (desc->flags & VRING_DESC_F_NEXT)
+ idx = desc->next;
+ else
+ break;
+ } while (1);
+
+ return head;
+}
+
#endif /* KVM__VIRTQUEUE_H */
--
1.7.4.1
next prev parent reply other threads:[~2011-04-07 2:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-08 2:05 [PATCH 1/3] kvm tools: define marcros for virtio device io space size and pci device number Asias He
2011-04-07 3:56 ` David Ahern
2011-04-07 4:40 ` Pekka Enberg
2011-04-07 7:38 ` Avi Kivity
2011-04-08 2:05 ` Asias He [this message]
2011-04-08 2:05 ` [PATCH 3/3] kvm tools: add virtio console support v2 Asias He
2011-04-07 5:50 ` Pekka Enberg
2011-04-08 14:18 ` Asias He
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=1302228309-6583-2-git-send-email-asias.hejun@gmail.com \
--to=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.com \
/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