Skip to content

Commit

Permalink
virtio: console: introduce a get_inbuf helper to fetch bufs from in_vq
Browse files Browse the repository at this point in the history
This makes taking locks around the get_buf vq operation easier, as well
as complements the add_inbuf() operation.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
Amit Shah authored and Rusty Russell committed Feb 24, 2010
1 parent e27b519 commit a3cde44
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ static struct port_buffer *alloc_buf(size_t buf_size)
return NULL;
}

/* Callers should take appropriate locks */
static void *get_inbuf(struct port *port)
{
struct port_buffer *buf;
struct virtqueue *vq;
unsigned int len;

vq = port->in_vq;
buf = vq->vq_ops->get_buf(vq, &len);
if (buf) {
buf->len = len;
buf->offset = 0;
}
return buf;
}

/*
* Create a scatter-gather list representing our input buffer and put
* it in the queue.
Expand Down Expand Up @@ -138,7 +154,6 @@ static int put_chars(u32 vtermno, const char *buf, int count)
static int get_chars(u32 vtermno, char *buf, int count)
{
struct port *port;
unsigned int len;

port = &console;

Expand All @@ -147,10 +162,8 @@ static int get_chars(u32 vtermno, char *buf, int count)

/* No more in buffer? See if they've (re)used it. */
if (port->inbuf->offset == port->inbuf->len) {
if (!port->in_vq->vq_ops->get_buf(port->in_vq, &len))
if (!get_inbuf(port))
return 0;
port->inbuf->offset = 0;
port->inbuf->len = len;
}

/* You want more than we have to give? Well, try wanting less! */
Expand Down

0 comments on commit a3cde44

Please sign in to comment.