From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LOdi7-0005Jj-3f for qemu-devel@nongnu.org; Sun, 18 Jan 2009 14:53:31 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LOdi6-0005J7-12 for qemu-devel@nongnu.org; Sun, 18 Jan 2009 14:53:30 -0500 Received: from [199.232.76.173] (port=52590 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LOdi5-0005If-AM for qemu-devel@nongnu.org; Sun, 18 Jan 2009 14:53:29 -0500 Received: from mx2.redhat.com ([66.187.237.31]:57972) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LOdi4-0000K6-DS for qemu-devel@nongnu.org; Sun, 18 Jan 2009 14:53:28 -0500 From: Avi Kivity Date: Sun, 18 Jan 2009 21:53:18 +0200 Message-Id: <1232308399-21679-5-git-send-email-avi@redhat.com> In-Reply-To: <1232308399-21679-1-git-send-email-avi@redhat.com> References: <1232308399-21679-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH 4/5] I/O vector helpers Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Anthony Liguori In general, it is not possible to predict the size of of an I/O vector since a contiguous guest region may map to a disconiguous host region. Add some helpers to manage I/O vector growth. Signed-off-by: Avi Kivity --- qemu-common.h | 10 ++++++++++ vl.c | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 0 deletions(-) diff --git a/qemu-common.h b/qemu-common.h index d83e61b..1a746f9 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -191,6 +191,16 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id); /* Force QEMU to stop what it's doing and service IO */ void qemu_service_io(void); +typedef struct QEMUIOVector { + struct iovec *iov; + int niov; + int nalloc; +} QEMUIOVector; + +void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); +void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); +void qemu_iovec_destroy(QEMUIOVector *qiov); + #endif /* dyngen-exec.h hack */ #endif diff --git a/vl.c b/vl.c index 34ddc07..7ceedd4 100644 --- a/vl.c +++ b/vl.c @@ -3344,6 +3344,31 @@ static void qemu_bh_update_timeout(int *timeout) } } +/* io vectors */ + +void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint) +{ + qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec)); + qiov->niov = 0; + qiov->nalloc = alloc_hint; +} + +void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len) +{ + if (qiov->niov == qiov->nalloc) { + qiov->nalloc = 2 * qiov->nalloc + 1; + qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec)); + } + qiov->iov[qiov->niov].iov_base = base; + qiov->iov[qiov->niov].iov_len = len; + ++qiov->niov; +} + +void qemu_iovec_destroy(QEMUIOVector *qiov) +{ + qemu_free(qiov->iov); +} + /***********************************************************/ /* machine registration */ -- 1.6.0.6