Skip to content

Commit

Permalink
util: add qemu_iovec_is_zero
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
plieven authored and kevmw committed May 19, 2014
1 parent d66e5ce commit 43f35cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/qemu-common.h
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions util/iov.c
Expand Up @@ -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);
Expand Down

0 comments on commit 43f35cb

Please sign in to comment.