From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LjqZt-0003jL-E3 for qemu-devel@nongnu.org; Wed, 18 Mar 2009 03:52:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LjqZo-0003j9-Gm for qemu-devel@nongnu.org; Wed, 18 Mar 2009 03:52:40 -0400 Received: from [199.232.76.173] (port=47790 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LjqZo-0003j6-BO for qemu-devel@nongnu.org; Wed, 18 Mar 2009 03:52:36 -0400 Received: from verein.lst.de ([213.95.11.210]:45828) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1LjqZn-0005Yc-Oj for qemu-devel@nongnu.org; Wed, 18 Mar 2009 03:52:36 -0400 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id n2I7qWIF013587 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 18 Mar 2009 08:52:32 +0100 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-6.6) id n2I7qWKc013585 for qemu-devel@nongnu.org; Wed, 18 Mar 2009 08:52:32 +0100 Date: Wed, 18 Mar 2009 08:52:32 +0100 From: Christoph Hellwig Message-ID: <20090318075232.GA13571@lst.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH 1/2] add qemu_iovec_init_external 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 Allow to initialize a QEMUIOVector from an externally allocated iovec. qiov->nalloc is initialized to -1 to indicate external storage for qiov->iov and all functions dealing with memory management assert on the iovec beeing an internally managed first. Signed-off-by: Christoph Hellwig Index: qemu/cutils.c =================================================================== --- qemu.orig/cutils.c 2009-03-18 08:23:25.412987454 +0100 +++ qemu/cutils.c 2009-03-18 08:43:25.521856132 +0100 @@ -23,6 +23,7 @@ */ #include "qemu-common.h" #include "host-utils.h" +#include void pstrcpy(char *buf, int buf_size, const char *str) { @@ -112,8 +113,22 @@ void qemu_iovec_init(QEMUIOVector *qiov, qiov->size = 0; } +void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov) +{ + int i; + + qiov->iov = iov; + qiov->niov = niov; + qiov->nalloc = -1; + qiov->size = 0; + for (i = 0; i < niov; i++) + qiov->size += iov[i].iov_len; +} + void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len) { + assert(qiov->nalloc != -1); + if (qiov->niov == qiov->nalloc) { qiov->nalloc = 2 * qiov->nalloc + 1; qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec)); @@ -126,11 +141,15 @@ void qemu_iovec_add(QEMUIOVector *qiov, void qemu_iovec_destroy(QEMUIOVector *qiov) { + assert(qiov->nalloc != -1); + qemu_free(qiov->iov); } void qemu_iovec_reset(QEMUIOVector *qiov) { + assert(qiov->nalloc != -1); + qiov->niov = 0; qiov->size = 0; } Index: qemu/qemu-common.h =================================================================== --- qemu.orig/qemu-common.h 2009-03-18 08:25:11.505853329 +0100 +++ qemu/qemu-common.h 2009-03-18 08:34:34.075854099 +0100 @@ -194,6 +194,7 @@ typedef struct QEMUIOVector { } QEMUIOVector; void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint); +void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov); void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len); void qemu_iovec_destroy(QEMUIOVector *qiov); void qemu_iovec_reset(QEMUIOVector *qiov);