Commit a3cde449 authored by Amit Shah's avatar Amit Shah Committed by Rusty Russell

virtio: console: introduce a get_inbuf helper to fetch bufs from in_vq

This makes taking locks around the get_buf vq operation easier, as well
as complements the add_inbuf() operation.
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent e27b5198
...@@ -77,6 +77,22 @@ static struct port_buffer *alloc_buf(size_t buf_size) ...@@ -77,6 +77,22 @@ static struct port_buffer *alloc_buf(size_t buf_size)
return NULL; 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 * Create a scatter-gather list representing our input buffer and put
* it in the queue. * it in the queue.
...@@ -138,7 +154,6 @@ static int put_chars(u32 vtermno, const char *buf, int count) ...@@ -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) static int get_chars(u32 vtermno, char *buf, int count)
{ {
struct port *port; struct port *port;
unsigned int len;
port = &console; port = &console;
...@@ -147,10 +162,8 @@ static int get_chars(u32 vtermno, char *buf, int count) ...@@ -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. */ /* No more in buffer? See if they've (re)used it. */
if (port->inbuf->offset == port->inbuf->len) { 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; return 0;
port->inbuf->offset = 0;
port->inbuf->len = len;
} }
/* You want more than we have to give? Well, try wanting less! */ /* You want more than we have to give? Well, try wanting less! */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment