peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame qemu-virtio-serial-bus-Add-a-port-name-property-for-po.patch

amitshah 99a9ef
From ed4daf8c7722562ec05e83ec98a4d4d8adf20f7f Mon Sep 17 00:00:00 2001
amitshah 99a9ef
From: Amit Shah <amit.shah@redhat.com>
amitshah 99a9ef
Date: Wed, 20 Jan 2010 00:36:54 +0530
amitshah 99a9ef
Subject: [PATCH 4/9] virtio-serial-bus: Add a port 'name' property for port discovery in guests
amitshah 99a9ef
amitshah 99a9ef
The port 'id' or number is internal state between the guest kernel and
amitshah 99a9ef
our bus implementation. This is invocation-dependent and isn't part of
amitshah 99a9ef
the guest-host ABI.
amitshah 99a9ef
amitshah 99a9ef
To correcly enumerate and map ports between the host and the guest, the
amitshah 99a9ef
'name' property is used.
amitshah 99a9ef
amitshah 99a9ef
Example:
amitshah 99a9ef
amitshah 99a9ef
    -device virtserialport,name=org.qemu.port.0
amitshah 99a9ef
amitshah 99a9ef
This invocation will get us a char device in the guest at:
amitshah 99a9ef
amitshah 99a9ef
    /dev/virtio-ports/org.qemu.port.0
amitshah 99a9ef
amitshah 99a9ef
which can be a symlink to
amitshah 99a9ef
amitshah 99a9ef
    /dev/vport0p3
amitshah 99a9ef
amitshah 99a9ef
This 'name' property is exposed by the guest kernel in a sysfs
amitshah 99a9ef
attribute:
amitshah 99a9ef
amitshah 99a9ef
    /sys/kernel/virtio-ports/vport0p3/name
amitshah 99a9ef
amitshah 99a9ef
A simple udev script can pick up this name and create the symlink
amitshah 99a9ef
mentioned above.
amitshah 99a9ef
amitshah 99a9ef
Signed-off-by: Amit Shah <amit.shah@redhat.com>
amitshah 99a9ef
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
amitshah 99a9ef
---
amitshah 99a9ef
 hw/virtio-serial-bus.c |   17 +++++++++++++++++
amitshah 99a9ef
 hw/virtio-serial.c     |    1 +
amitshah 99a9ef
 hw/virtio-serial.h     |    8 ++++++++
amitshah 99a9ef
 3 files changed, 26 insertions(+), 0 deletions(-)
amitshah 99a9ef
amitshah 99a9ef
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
amitshah 99a9ef
index 9af21df..6d69c56 100644
amitshah 99a9ef
--- a/hw/virtio-serial-bus.c
amitshah 99a9ef
+++ b/hw/virtio-serial-bus.c
amitshah 99a9ef
@@ -204,6 +204,8 @@ static void handle_control_message(VirtIOSerial *vser, void *buf)
amitshah 99a9ef
 {
amitshah 99a9ef
     struct VirtIOSerialPort *port;
amitshah 99a9ef
     struct virtio_console_control cpkt, *gcpkt;
amitshah 99a9ef
+    uint8_t *buffer;
amitshah 99a9ef
+    size_t buffer_len;
amitshah 99a9ef
 
amitshah 99a9ef
     gcpkt = buf;
amitshah 99a9ef
     port = find_port_by_id(vser, ldl_p(&gcpkt->id));
amitshah 99a9ef
@@ -226,6 +228,21 @@ static void handle_control_message(VirtIOSerial *vser, void *buf)
amitshah 99a9ef
             send_control_event(port, VIRTIO_CONSOLE_CONSOLE_PORT, 1);
amitshah 99a9ef
         }
amitshah 99a9ef
 
amitshah 99a9ef
+        if (port->name) {
amitshah 99a9ef
+            stw_p(&cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
amitshah 99a9ef
+            stw_p(&cpkt.value, 1);
amitshah 99a9ef
+
amitshah 99a9ef
+            buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
amitshah 99a9ef
+            buffer = qemu_malloc(buffer_len);
amitshah 99a9ef
+
amitshah 99a9ef
+            memcpy(buffer, &cpkt, sizeof(cpkt));
amitshah 99a9ef
+            memcpy(buffer + sizeof(cpkt), port->name, strlen(port->name));
amitshah 99a9ef
+            buffer[buffer_len - 1] = 0;
amitshah 99a9ef
+
amitshah 99a9ef
+            send_control_msg(port, buffer, buffer_len);
amitshah 99a9ef
+            qemu_free(buffer);
amitshah 99a9ef
+        }
amitshah 99a9ef
+
amitshah 99a9ef
         if (port->host_connected) {
amitshah 99a9ef
             send_control_event(port, VIRTIO_CONSOLE_PORT_OPEN, 1);
amitshah 99a9ef
         }
amitshah 99a9ef
diff --git a/hw/virtio-serial.c b/hw/virtio-serial.c
amitshah 99a9ef
index 1dc031e..9c2c93c 100644
amitshah 99a9ef
--- a/hw/virtio-serial.c
amitshah 99a9ef
+++ b/hw/virtio-serial.c
amitshah 99a9ef
@@ -100,6 +100,7 @@ static VirtIOSerialPortInfo virtconsole_info = {
amitshah 99a9ef
     .qdev.props = (Property[]) {
amitshah 99a9ef
         DEFINE_PROP_UINT8("is_console", VirtConsole, port.is_console, 1),
amitshah 99a9ef
         DEFINE_PROP_CHR("chardev", VirtConsole, chr),
amitshah 99a9ef
+        DEFINE_PROP_STRING("name", VirtConsole, port.name),
amitshah 99a9ef
         DEFINE_PROP_END_OF_LIST(),
amitshah 99a9ef
     },
amitshah 99a9ef
 };
amitshah 99a9ef
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
amitshah 99a9ef
index d9c7acb..28ea7da 100644
amitshah 99a9ef
--- a/hw/virtio-serial.h
amitshah 99a9ef
+++ b/hw/virtio-serial.h
amitshah 99a9ef
@@ -50,6 +50,7 @@ struct virtio_console_control {
amitshah 99a9ef
 #define VIRTIO_CONSOLE_CONSOLE_PORT	1
amitshah 99a9ef
 #define VIRTIO_CONSOLE_RESIZE		2
amitshah 99a9ef
 #define VIRTIO_CONSOLE_PORT_OPEN	3
amitshah 99a9ef
+#define VIRTIO_CONSOLE_PORT_NAME	4
amitshah 99a9ef
 
amitshah 99a9ef
 /* == In-qemu interface == */
amitshah 99a9ef
 
amitshah 99a9ef
@@ -84,6 +85,13 @@ struct VirtIOSerialPort {
amitshah 99a9ef
     VirtQueue *ivq, *ovq;
amitshah 99a9ef
 
amitshah 99a9ef
     /*
amitshah 99a9ef
+     * This name is sent to the guest and exported via sysfs.
amitshah 99a9ef
+     * The guest could create symlinks based on this information.
amitshah 99a9ef
+     * The name is in the reverse fqdn format, like org.qemu.console.0
amitshah 99a9ef
+     */
amitshah 99a9ef
+    char *name;
amitshah 99a9ef
+
amitshah 99a9ef
+    /*
amitshah 99a9ef
      * This id helps identify ports between the guest and the host.
amitshah 99a9ef
      * The guest sends a "header" with this id with each data packet
amitshah 99a9ef
      * that it sends and the host can then find out which associated
amitshah 99a9ef
-- 
amitshah 99a9ef
1.6.2.5
amitshah 99a9ef