Skip to contentSkip to conversation

virtio: console: async notifications for host connect / disconnect

PATCH In review Amit Shah 2 participants 5 messages Sep 2, 2010 – Sep 6, 2010

Subsystems (3)
lore
Share & tools
lore

Amit Shah

author
#0 lore raw

cover virtio: console: async notifications for host connect / disconnect

Hey Rusty,

This patchset is on top of the previous one.

It sends a SIGIO signal to apps that request signals for host activity. SIGIO is sent on host connect, disconnect as well as hot-unplug (which can be seen as a special case of host disconnect).

Tested using several testcases in the test-virtserial repo:
http://fedorapeople.org/gitweb?p=amitshah/public_git/test-virtserial.git

Please apply.

Thanks,
Amit.

Amit Shah (3):
virtio: console: Send SIGIO to processes that request it for host
events
virtio: console: Send SIGIO on new data arrival on ports
virtio: console: Send SIGIO in case of port unplug

 drivers/char/virtio_console.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.2.2
author
#1 lore raw

PATCH 1/3 virtio: console: Send SIGIO to processes that request it for host events

A process can request for SIGIO on host connect / disconnect events using the O_ASYNC file flag using fcntl().

If that's requested, and if the guest-side connection for the port is open, any host-side open/close events for that port will raise a SIGIO. The process can then use poll() within the signal handler to find out which port triggered the signal.

---
 drivers/char/virtio_console.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
drivers/char/virtio_console.c +25 -0
index 793817b..afbbc54 100644
@@ -196,6 +196,9 @@ struct port {
 	/* The 'name' of the port that we expose via sysfs properties */
 	char *name;
 
+	/* We can notify apps of host connect / disconnect events via SIGIO */
+	struct fasync_struct *async_queue;
+
 	/* The 'id' to identify the port with the Host */
 	u32 id;
 
@@ -800,6 +803,14 @@ out:
 	return ret;
 }
 
+static int port_fops_fasync(int fd, struct file *filp, int mode)
+{
+	struct port *port;
+
+	port = filp->private_data;
+	return fasync_helper(fd, filp, mode, &port->async_queue);
+}
+
 /*
  * The file operations that we support: programs in the guest can open
  * a console device, read from it, write to it, poll for data and
@@ -813,6 +824,7 @@ static const struct file_operations port_fops = {
 	.write = port_fops_write,
 	.poll  = port_fops_poll,
 	.release = port_fops_release,
+	.fasync = port_fops_fasync,
 };
 
 /*
@@ -1071,6 +1083,12 @@ static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock)
 	return nr_added_bufs;
 }
 
+static void send_sigio_to_port(struct port *port)
+{
+	if (port->async_queue && port->guest_connected)
+		kill_fasync(&port->async_queue, SIGIO, POLL_OUT);
+}
+
 static int add_port(struct ports_device *portdev, u32 id)
 {
 	char debugfs_name[16];
@@ -1093,6 +1111,7 @@ static int add_port(struct ports_device *portdev, u32 id)
 	port->name = NULL;
 	port->inbuf = NULL;
 	port->cons.hvc = NULL;
+	port->async_queue = NULL;
 
 	port->cons.ws.ws_row = port->cons.ws.ws_col = 0;
 
@@ -1347,6 +1366,12 @@ static void handle_control_message(struct ports_device *portdev,
 		spin_lock_irq(&port->outvq_lock);
 		reclaim_consumed_buffers(port);
 		spin_unlock_irq(&port->outvq_lock);
+
+		/*
+		 * If the guest is connected, it'll be interested in
+		 * knowing the host connection state changed.
+		 */
+		send_sigio_to_port(port);
 		break;
 	case VIRTIO_CONSOLE_PORT_NAME:
 		/*
Signature · 1 line
1.7.2.2
author
#2 lore raw

PATCH 2/3 virtio: console: Send SIGIO on new data arrival on ports

In reply to Amit Shah

Send a SIGIO signal when new data arrives on a port. This is sent only when the process has requested for the signal to be sent using fcntl().

---
 drivers/char/virtio_console.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/char/virtio_console.c +3 -0
index afbbc54..a750d2b 100644
@@ -1468,6 +1468,9 @@ static void in_intr(struct virtqueue *vq)
 
 	wake_up_interruptible(&port->waitqueue);
 
+	/* Send a SIGIO indicating new data in case the process asked for it */
+	send_sigio_to_port(port);
+
 	if (is_console_port(port) && hvc_poll(port->cons.hvc))
 		hvc_kick();
 }
Signature · 1 line
1.7.2.2
author
#3 lore raw

PATCH 3/3 virtio: console: Send SIGIO in case of port unplug

In reply to Amit Shah

If a port has registered for SIGIO signals, let the application know that the port is getting unplugged.

---
 drivers/char/virtio_console.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/char/virtio_console.c +3 -0
index a750d2b..f7adfd3 100644
@@ -1244,6 +1244,9 @@ static void unplug_port(struct port *port)
 		port->guest_connected = false;
 		port->host_connected = false;
 		wake_up_interruptible(&port->waitqueue);
+
+		/* Let the app know the port is going down. */
+		send_sigio_to_port(port);
 	}
 
 	if (is_console_port(port)) {
Signature · 1 line
1.7.2.2
#4 lore raw

Re: [PATCH 3/3] virtio: console: Send SIGIO in case of port unplug

Quoted 4 lines · Amit Shah

If a port has registered for SIGIO signals, let the application know that the port is getting unplugged.

Thanks Amit, these patches were really well organized and nice to read.

Applied them all...
Rusty.