mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-02 15:23:53 -06:00
iov: Introduce a new file for helpers around iovs, add iov_from_buf()
The virtio-net code uses iov_fill() which fills an iov from a linear buffer. The virtio-serial-bus code does something similar in an open-coded function. Create a new iov.c file that has iov_from_buf(). Convert virtio-net and virtio-serial-bus over to use this functionality. virtio-net used ints to hold sizes, the new function is going to use size_t types. Later commits will add the opposite functionality -- going from an iov to a linear buffer. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
3ecb45f893
commit
e4d5639dbb
6 changed files with 62 additions and 25 deletions
|
@ -11,6 +11,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "iov.h"
|
||||
#include "virtio.h"
|
||||
#include "net.h"
|
||||
#include "net/checksum.h"
|
||||
|
@ -445,21 +446,6 @@ static void work_around_broken_dhclient(struct virtio_net_hdr *hdr,
|
|||
}
|
||||
}
|
||||
|
||||
static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
|
||||
{
|
||||
int offset, i;
|
||||
|
||||
offset = i = 0;
|
||||
while (offset < count && i < iovcnt) {
|
||||
int len = MIN(iov[i].iov_len, count - offset);
|
||||
memcpy(iov[i].iov_base, buf + offset, len);
|
||||
offset += len;
|
||||
i++;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
|
||||
const void *buf, size_t size, size_t hdr_len)
|
||||
{
|
||||
|
@ -595,8 +581,8 @@ static ssize_t virtio_net_receive(VLANClientState *nc, const uint8_t *buf, size_
|
|||
}
|
||||
|
||||
/* copy in packet. ugh */
|
||||
len = iov_fill(sg, elem.in_num,
|
||||
buf + offset, size - offset);
|
||||
len = iov_from_buf(sg, elem.in_num,
|
||||
buf + offset, size - offset);
|
||||
total += len;
|
||||
|
||||
/* signal other side */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue