mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
lguest: clean up length-used value in example launcher
The "len" field in the used ring for virtio indicates the number of bytes *written* to the buffer. This means the guest doesn't have to zero the buffers in advance as it always knows the used length. Erroneously, the console and network example code puts the length *read* into that field. The guest ignores it, but it's wrong. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
f086122bb6
commit
e606490c44
1 changed files with 4 additions and 7 deletions
|
@ -830,15 +830,14 @@ static bool handle_console_input(struct device *dev)
|
||||||
static void handle_console_output(struct virtqueue *vq, bool timeout)
|
static void handle_console_output(struct virtqueue *vq, bool timeout)
|
||||||
{
|
{
|
||||||
unsigned int head, out, in;
|
unsigned int head, out, in;
|
||||||
int len;
|
|
||||||
struct iovec iov[vq->vring.num];
|
struct iovec iov[vq->vring.num];
|
||||||
|
|
||||||
/* Keep getting output buffers from the Guest until we run out. */
|
/* Keep getting output buffers from the Guest until we run out. */
|
||||||
while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
|
while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
|
||||||
if (in)
|
if (in)
|
||||||
errx(1, "Input buffers in output queue?");
|
errx(1, "Input buffers in output queue?");
|
||||||
len = writev(STDOUT_FILENO, iov, out);
|
writev(STDOUT_FILENO, iov, out);
|
||||||
add_used_and_trigger(vq, head, len);
|
add_used_and_trigger(vq, head, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -870,7 +869,6 @@ static void block_vq(struct virtqueue *vq)
|
||||||
static void handle_net_output(struct virtqueue *vq, bool timeout)
|
static void handle_net_output(struct virtqueue *vq, bool timeout)
|
||||||
{
|
{
|
||||||
unsigned int head, out, in, num = 0;
|
unsigned int head, out, in, num = 0;
|
||||||
int len;
|
|
||||||
struct iovec iov[vq->vring.num];
|
struct iovec iov[vq->vring.num];
|
||||||
static int last_timeout_num;
|
static int last_timeout_num;
|
||||||
|
|
||||||
|
@ -878,10 +876,9 @@ static void handle_net_output(struct virtqueue *vq, bool timeout)
|
||||||
while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
|
while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
|
||||||
if (in)
|
if (in)
|
||||||
errx(1, "Input buffers in output queue?");
|
errx(1, "Input buffers in output queue?");
|
||||||
len = writev(vq->dev->fd, iov, out);
|
if (writev(vq->dev->fd, iov, out) < 0)
|
||||||
if (len < 0)
|
|
||||||
err(1, "Writing network packet to tun");
|
err(1, "Writing network packet to tun");
|
||||||
add_used_and_trigger(vq, head, len);
|
add_used_and_trigger(vq, head, 0);
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue