mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-23 19:49:43 +00:00
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 <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6902 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
cef3017cd7
commit
522584a57b
19
cutils.c
19
cutils.c
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
#include "host-utils.h"
|
#include "host-utils.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
void pstrcpy(char *buf, int buf_size, const char *str)
|
void pstrcpy(char *buf, int buf_size, const char *str)
|
||||||
{
|
{
|
||||||
@ -112,8 +113,22 @@ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
|
|||||||
qiov->size = 0;
|
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)
|
void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
|
||||||
{
|
{
|
||||||
|
assert(qiov->nalloc != -1);
|
||||||
|
|
||||||
if (qiov->niov == qiov->nalloc) {
|
if (qiov->niov == qiov->nalloc) {
|
||||||
qiov->nalloc = 2 * qiov->nalloc + 1;
|
qiov->nalloc = 2 * qiov->nalloc + 1;
|
||||||
qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
|
qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
|
||||||
@ -126,11 +141,15 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
|
|||||||
|
|
||||||
void qemu_iovec_destroy(QEMUIOVector *qiov)
|
void qemu_iovec_destroy(QEMUIOVector *qiov)
|
||||||
{
|
{
|
||||||
|
assert(qiov->nalloc != -1);
|
||||||
|
|
||||||
qemu_free(qiov->iov);
|
qemu_free(qiov->iov);
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_iovec_reset(QEMUIOVector *qiov)
|
void qemu_iovec_reset(QEMUIOVector *qiov)
|
||||||
{
|
{
|
||||||
|
assert(qiov->nalloc != -1);
|
||||||
|
|
||||||
qiov->niov = 0;
|
qiov->niov = 0;
|
||||||
qiov->size = 0;
|
qiov->size = 0;
|
||||||
}
|
}
|
||||||
|
@ -194,6 +194,7 @@ typedef struct QEMUIOVector {
|
|||||||
} QEMUIOVector;
|
} QEMUIOVector;
|
||||||
|
|
||||||
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
|
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_add(QEMUIOVector *qiov, void *base, size_t len);
|
||||||
void qemu_iovec_destroy(QEMUIOVector *qiov);
|
void qemu_iovec_destroy(QEMUIOVector *qiov);
|
||||||
void qemu_iovec_reset(QEMUIOVector *qiov);
|
void qemu_iovec_reset(QEMUIOVector *qiov);
|
||||||
|
Loading…
Reference in New Issue
Block a user