Commit 249aa745fb133be47d3fea1cdecec55af7589919

Authored by aliguori
1 parent 28c699a2

qemu iovec: keep track of total size, allow partial copies (Gerd Hoffman)

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6448 c046a42c-6fe2-441c-8c8c-71466251a162
... ... @@ -1265,7 +1265,7 @@ static void bdrv_aio_rw_vector_cb(void *opaque, int ret)
1265 1265 VectorTranslationState *s = opaque;
1266 1266  
1267 1267 if (!s->is_write) {
1268   - qemu_iovec_from_buffer(s->iov, s->bounce);
  1268 + qemu_iovec_from_buffer(s->iov, s->bounce, s->iov->size);
1269 1269 }
1270 1270 qemu_free(s->bounce);
1271 1271 s->this_aiocb->cb(s->this_aiocb->opaque, ret);
... ...
cutils.c
... ... @@ -109,6 +109,7 @@ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
109 109 qiov->iov = qemu_malloc(alloc_hint * sizeof(struct iovec));
110 110 qiov->niov = 0;
111 111 qiov->nalloc = alloc_hint;
  112 + qiov->size = 0;
112 113 }
113 114  
114 115 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
... ... @@ -119,6 +120,7 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
119 120 }
120 121 qiov->iov[qiov->niov].iov_base = base;
121 122 qiov->iov[qiov->niov].iov_len = len;
  123 + qiov->size += len;
122 124 ++qiov->niov;
123 125 }
124 126  
... ... @@ -138,13 +140,18 @@ void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf)
138 140 }
139 141 }
140 142  
141   -void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf)
  143 +void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count)
142 144 {
143 145 const uint8_t *p = (const uint8_t *)buf;
  146 + size_t copy;
144 147 int i;
145 148  
146   - for (i = 0; i < qiov->niov; ++i) {
147   - memcpy(qiov->iov[i].iov_base, p, qiov->iov[i].iov_len);
148   - p += qiov->iov[i].iov_len;
  149 + for (i = 0; i < qiov->niov && count; ++i) {
  150 + copy = count;
  151 + if (copy > qiov->iov[i].iov_len)
  152 + copy = qiov->iov[i].iov_len;
  153 + memcpy(qiov->iov[i].iov_base, p, copy);
  154 + p += copy;
  155 + count -= copy;
149 156 }
150 157 }
... ...
qemu-common.h
... ... @@ -195,13 +195,14 @@ typedef struct QEMUIOVector {
195 195 struct iovec *iov;
196 196 int niov;
197 197 int nalloc;
  198 + size_t size;
198 199 } QEMUIOVector;
199 200  
200 201 void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint);
201 202 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len);
202 203 void qemu_iovec_destroy(QEMUIOVector *qiov);
203 204 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf);
204   -void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf);
  205 +void qemu_iovec_from_buffer(QEMUIOVector *qiov, const void *buf, size_t count);
205 206  
206 207 #endif /* dyngen-exec.h hack */
207 208  
... ...