Skip to content

Commit

Permalink
lguest: clean up length-used value in example launcher
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rustyrussell committed Jun 12, 2009
1 parent f086122 commit e606490
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Documentation/lguest/lguest.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,15 +830,14 @@ static bool handle_console_input(struct device *dev)
static void handle_console_output(struct virtqueue *vq, bool timeout)
{
unsigned int head, out, in;
int len;
struct iovec iov[vq->vring.num];

/* Keep getting output buffers from the Guest until we run out. */
while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
if (in)
errx(1, "Input buffers in output queue?");
len = writev(STDOUT_FILENO, iov, out);
add_used_and_trigger(vq, head, len);
writev(STDOUT_FILENO, iov, out);
add_used_and_trigger(vq, head, 0);
}
}

Expand Down Expand Up @@ -870,18 +869,16 @@ static void block_vq(struct virtqueue *vq)
static void handle_net_output(struct virtqueue *vq, bool timeout)
{
unsigned int head, out, in, num = 0;
int len;
struct iovec iov[vq->vring.num];
static int last_timeout_num;

/* Keep getting output buffers from the Guest until we run out. */
while ((head = get_vq_desc(vq, iov, &out, &in)) != vq->vring.num) {
if (in)
errx(1, "Input buffers in output queue?");
len = writev(vq->dev->fd, iov, out);
if (len < 0)
if (writev(vq->dev->fd, iov, out) < 0)
err(1, "Writing network packet to tun");
add_used_and_trigger(vq, head, len);
add_used_and_trigger(vq, head, 0);
num++;
}

Expand Down

0 comments on commit e606490

Please sign in to comment.