From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53711) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmOTH-0005ee-ER for qemu-devel@nongnu.org; Mon, 19 May 2014 10:23:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WmOTB-0004Ey-Ji for qemu-devel@nongnu.org; Mon, 19 May 2014 10:23:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmOTB-0004Eh-An for qemu-devel@nongnu.org; Mon, 19 May 2014 10:23:13 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s4JENCJ4024881 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 19 May 2014 10:23:12 -0400 From: Kevin Wolf Date: Mon, 19 May 2014 16:22:38 +0200 Message-Id: <1400509360-25470-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1400509360-25470-1-git-send-email-kwolf@redhat.com> References: <1400509360-25470-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 20/22] util: add qemu_iovec_is_zero List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Peter Lieven Signed-off-by: Peter Lieven Signed-off-by: Kevin Wolf --- include/qemu-common.h | 1 + util/iov.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/qemu-common.h b/include/qemu-common.h index 3f3fd60..66ceceb 100644 --- a/include/qemu-common.h +++ b/include/qemu-common.h @@ -318,6 +318,7 @@ void qemu_iovec_concat(QEMUIOVector *dst, void qemu_iovec_concat_iov(QEMUIOVector *dst, struct iovec *src_iov, unsigned int src_cnt, size_t soffset, size_t sbytes); +bool qemu_iovec_is_zero(QEMUIOVector *qiov); void qemu_iovec_destroy(QEMUIOVector *qiov); void qemu_iovec_reset(QEMUIOVector *qiov); size_t qemu_iovec_to_buf(QEMUIOVector *qiov, size_t offset, diff --git a/util/iov.c b/util/iov.c index 6569b5a..49f8838 100644 --- a/util/iov.c +++ b/util/iov.c @@ -335,6 +335,27 @@ void qemu_iovec_concat(QEMUIOVector *dst, qemu_iovec_concat_iov(dst, src->iov, src->niov, soffset, sbytes); } +/* + * Check if the contents of the iovecs are all zero + */ +bool qemu_iovec_is_zero(QEMUIOVector *qiov) +{ + int i; + for (i = 0; i < qiov->niov; i++) { + size_t offs = QEMU_ALIGN_DOWN(qiov->iov[i].iov_len, 4 * sizeof(long)); + uint8_t *ptr = qiov->iov[i].iov_base; + if (offs && !buffer_is_zero(qiov->iov[i].iov_base, offs)) { + return false; + } + for (; offs < qiov->iov[i].iov_len; offs++) { + if (ptr[offs]) { + return false; + } + } + } + return true; +} + void qemu_iovec_destroy(QEMUIOVector *qiov) { assert(qiov->nalloc != -1); -- 1.8.3.1