diff mbox

[v2,2/2] virtio-console: Notify resize to the guest.

Message ID 20100430081220.2178A6AC03A@msa102.auone-net.jp
State New
Headers show

Commit Message

Kusanagi Kouichi April 30, 2010, 8:12 a.m. UTC
I tested this patch as follows:
I put printf()s into involved functions. Then ran qemu on a terminal
emulator, and resized it.
The guest kernel gets initial size. However, it doesn't update the size.
It seems to need to enable multiport for resize.

v2:
 Rename virtio_serial_resize to virtio_serial_resize_console.

Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
---
 hw/virtio-console.c    |    3 +++
 hw/virtio-serial-bus.c |    8 ++++++++
 hw/virtio-serial.h     |    9 +++++++--
 3 files changed, 18 insertions(+), 2 deletions(-)

Comments

Amit Shah April 30, 2010, 10:43 a.m. UTC | #1
On (Fri) Apr 30 2010 [17:12:19], Kusanagi Kouichi wrote:
> I tested this patch as follows:
> I put printf()s into involved functions. Then ran qemu on a terminal
> emulator, and resized it.
> The guest kernel gets initial size. However, it doesn't update the size.
> It seems to need to enable multiport for resize.

If the guest kernel supports multiport, you should send the control
event.

If the guest kernel doesn't support multiport, then you should send a
config space update so that the console size is updated for the only
port that exists.

Sorry for not catching this earlier.

Can you test both the possibilities and let me know? This patch will
have to be updated, of course, to support resize over the config space
in the following function:

> +void virtio_serial_resize_console(VirtIOSerialPort *port, int rows, int cols)
> +{
> +    port->vser->config.rows = rows;
> +    port->vser->config.cols = cols;
> +    send_control_event(port, VIRTIO_CONSOLE_RESIZE, 0);
> +}
> +

...

>  struct virtio_console_config {
>      /*
> -     * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
> -     * isn't implemented here yet
> +     * These two fields are used by VIRTIO_CONSOLE_F_SIZE

This comment could be expanded to explain when we use the config space
for size updates (!multiport) and when we use control messages
(multiport).

Thanks!
		Amit
diff mbox

Patch

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index caea11f..58246d1 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -55,6 +55,9 @@  static void chr_event(void *opaque, int event)
     case CHR_EVENT_CLOSED:
         virtio_serial_close(&vcon->port);
         break;
+    case CHR_EVENT_RESIZE:
+        virtio_serial_resize_console(&vcon->port, vcon->chr->rows, vcon->chr->cols);
+        break;
     }
 }
 
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 97694d5..72fbf3e 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -205,6 +205,13 @@  int virtio_serial_close(VirtIOSerialPort *port)
     return 0;
 }
 
+void virtio_serial_resize_console(VirtIOSerialPort *port, int rows, int cols)
+{
+    port->vser->config.rows = rows;
+    port->vser->config.cols = cols;
+    send_control_event(port, VIRTIO_CONSOLE_RESIZE, 0);
+}
+
 /* Individual ports/apps call this function to write to the guest. */
 ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
                             size_t size)
@@ -425,6 +432,7 @@  static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
 
     vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
 
+    features |= (1 << VIRTIO_CONSOLE_F_SIZE);
     if (vser->bus->max_nr_ports > 1) {
         features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT);
     }
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index a93b545..6a00d0c 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -25,14 +25,14 @@ 
 #define VIRTIO_ID_CONSOLE		3
 
 /* Features supported */
+#define VIRTIO_CONSOLE_F_SIZE		0
 #define VIRTIO_CONSOLE_F_MULTIPORT	1
 
 #define VIRTIO_CONSOLE_BAD_ID           (~(uint32_t)0)
 
 struct virtio_console_config {
     /*
-     * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
-     * isn't implemented here yet
+     * These two fields are used by VIRTIO_CONSOLE_F_SIZE
      */
     uint16_t cols;
     uint16_t rows;
@@ -165,6 +165,11 @@  int virtio_serial_open(VirtIOSerialPort *port);
 int virtio_serial_close(VirtIOSerialPort *port);
 
 /*
+ * Notify resize to the guest
+ */
+void virtio_serial_resize_console(VirtIOSerialPort *port, int rows, int cols);
+
+/*
  * Send data to Guest
  */
 ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,