[PATCH 8/8] virtio: console: Add partial blocking/non-blocking support to write()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If the host port is not open, a write() should either just return if the
file is opened in non-blocking mode, or block till the host port is
opened.

This is just half of the blocking/non-blocking story.

The other half will be addressed when we get rid of the cpu_relax() in
send_buf(). Add a fixme mentioning that case.

Signed-off-by: Amit Shah <amit.shah@xxxxxxxxxx>
---
 drivers/char/virtio_console.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index f33ceaa..fa616aa 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -536,6 +536,24 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
 
 	port = filp->private_data;
 
+	if (!port->host_connected) {
+		/*
+		 * FIXME: Also check if the vq has enough room to send
+		 * this buffer out to the guest.  Return EAGAIN or
+		 * block in case there's no room.  Currently the vq
+		 * always has room because we only use one buffer (and
+		 * cpu_relax()), but when send_buf() becomes
+		 * non-spinning, we'll use more buffers.
+		 */
+		if (filp->f_flags & O_NONBLOCK)
+			return -EAGAIN;
+
+		ret = wait_event_interruptible(port->waitqueue,
+					       port->host_connected);
+		if (ret < 0)
+			return ret;
+	}
+
 	count = min((size_t)(32 * 1024), count);
 
 	buf = kmalloc(count, GFP_KERNEL);
-- 
1.6.2.5

_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linux-foundation.org/mailman/listinfo/virtualization

[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux