From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lncbk-00013q-Tw for qemu-devel@nongnu.org; Sat, 28 Mar 2009 13:46:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lncbk-00013O-8W for qemu-devel@nongnu.org; Sat, 28 Mar 2009 13:46:12 -0400 Received: from [199.232.76.173] (port=48770 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lncbk-00013I-2e for qemu-devel@nongnu.org; Sat, 28 Mar 2009 13:46:12 -0400 Received: from savannah.gnu.org ([199.232.41.3]:43363 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lncbj-0000eE-NZ for qemu-devel@nongnu.org; Sat, 28 Mar 2009 13:46:11 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Lncbj-0008J7-1i for qemu-devel@nongnu.org; Sat, 28 Mar 2009 17:46:11 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1Lncbi-0008J3-Os for qemu-devel@nongnu.org; Sat, 28 Mar 2009 17:46:10 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Sat, 28 Mar 2009 17:46:10 +0000 Subject: [Qemu-devel] [6902] add qemu_iovec_init_external (Christoph Hellwig) 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 Revision: 6902 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6902 Author: aliguori Date: 2009-03-28 17:46:10 +0000 (Sat, 28 Mar 2009) Log Message: ----------- add qemu_iovec_init_external (Christoph Hellwig) 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 Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/cutils.c trunk/qemu-common.h Modified: trunk/cutils.c =================================================================== --- trunk/cutils.c 2009-03-28 17:29:07 UTC (rev 6901) +++ trunk/cutils.c 2009-03-28 17:46:10 UTC (rev 6902) @@ -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 @@ 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_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; } Modified: trunk/qemu-common.h =================================================================== --- trunk/qemu-common.h 2009-03-28 17:29:07 UTC (rev 6901) +++ trunk/qemu-common.h 2009-03-28 17:46:10 UTC (rev 6902) @@ -194,6 +194,7 @@ } 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);