Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 331393
b: refs/heads/master
c: efe75d2
h: refs/heads/master
i:
  331391: 4dafa54
v: v3
  • Loading branch information
Masami Hiramatsu authored and Rusty Russell committed Sep 28, 2012
1 parent 581d156 commit 1747508
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ec8fc870156b2b144f55b6a5a7d135018f04b30e
refs/heads/master: efe75d24a69fc39bb09d882ca2d5b90d4da02afe
39 changes: 27 additions & 12 deletions trunk/drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,26 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
return fill_readbuf(port, ubuf, count, true);
}

static int wait_port_writable(struct port *port, bool nonblock)
{
int ret;

if (will_write_block(port)) {
if (nonblock)
return -EAGAIN;

ret = wait_event_freezable(port->waitqueue,
!will_write_block(port));
if (ret < 0)
return ret;
}
/* Port got hot-unplugged. */
if (!port->guest_connected)
return -ENODEV;

return 0;
}

static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
size_t count, loff_t *offp)
{
Expand All @@ -740,18 +760,9 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,

nonblock = filp->f_flags & O_NONBLOCK;

if (will_write_block(port)) {
if (nonblock)
return -EAGAIN;

ret = wait_event_freezable(port->waitqueue,
!will_write_block(port));
if (ret < 0)
return ret;
}
/* Port got hot-unplugged. */
if (!port->guest_connected)
return -ENODEV;
ret = wait_port_writable(port, nonblock);
if (ret < 0)
return ret;

count = min((size_t)(32 * 1024), count);

Expand Down Expand Up @@ -851,6 +862,10 @@ static ssize_t port_fops_splice_write(struct pipe_inode_info *pipe,
.u.data = &sgl,
};

ret = wait_port_writable(port, filp->f_flags & O_NONBLOCK);
if (ret < 0)
return ret;

sgl.n = 0;
sgl.len = 0;
sgl.sg = kmalloc(sizeof(struct scatterlist) * MAX_SPLICE_PAGES,
Expand Down

0 comments on commit 1747508

Please sign in to comment.