diff options
author | Amit Shah <amit.shah@redhat.com> | 2010-01-18 19:15:03 +0530 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-02-24 14:22:38 +1030 |
commit | a3cde44908429e52b2ec052ad5a70ef60e1f2d56 (patch) | |
tree | 5470aabeb5fcb10c5372b4771ea7d4c48746446e /drivers | |
parent | e27b519807e04d950802cb89f7b22933d8d2f837 (diff) | |
download | linux-a3cde44908429e52b2ec052ad5a70ef60e1f2d56.tar.bz2 |
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: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/virtio_console.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index 1dbd46cb1a26..df45e5e9a947 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c @@ -77,6 +77,22 @@ fail: 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. @@ -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; @@ -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! */ |