Skip to contentSkip to conversation

qemu-ga: isa-serial support on Windows

PATCH Superseded Miki Mishael 2 participants 4 messages Jan 15, 2014 – Feb 24, 2014

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qemu-ga: isa-serial support on Windows

Add support for isa-serial method for qemu-ga on Windows, Added -p command line parameter for serial port name specification, e.g. "-p COM15".

Changes since V1:
* define default path for isa-serial for linux, "/dev/ttyS0".
* replaced static void ga_serial_path_correction function for path correction with snprintf.
* minor indentation fix.
* fixed error output when setting timeout for com port fails.

Miki Mishael (1):
qemu-ga: isa-serial support on Windows

 qga/channel-win32.c | 20 ++++++++++++++++++--
 qga/main.c          | 12 +++++++++---
 2 files changed, 27 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/1 qemu-ga: isa-serial support on Windows

Add support for isa-serial method for qemu-ga on Windows, Added -p command line parameter for serial port name specification, e.g. "-p COM15".

---
 qga/channel-win32.c | 20 ++++++++++++++++++--
 qga/main.c          | 12 +++++++++---
 2 files changed, 27 insertions(+), 5 deletions(-)
qga/channel-win32.c +18 -2
index 8a303f3..0d5e5f5 100644
@@ -287,12 +287,22 @@ GIOStatus ga_channel_write_all(GAChannel *c, const char *buf, size_t size)
 static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
                                 const gchar *path)
 {
-    if (method != GA_CHANNEL_VIRTIO_SERIAL) {
+    COMMTIMEOUTS comTimeOut = {0};
+    gchar newpath[MAXPATHLEN] = {0};
+    comTimeOut.ReadIntervalTimeout = 1;
+
+    if (method != GA_CHANNEL_VIRTIO_SERIAL && method != GA_CHANNEL_ISA_SERIAL) {
         g_critical("unsupported communication method");
         return false;
     }
 
-    c->handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
+    if (method == GA_CHANNEL_ISA_SERIAL){
+        snprintf(newpath, sizeof(newpath), "\\\\.\\%s", path);
+    }else {
+        g_strlcpy(newpath, path, sizeof(newpath));
+    }
+
+    c->handle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                            OPEN_EXISTING,
                            FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL);
     if (c->handle == INVALID_HANDLE_VALUE) {
@@ -300,6 +310,12 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
         return false;
     }
 
+    if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
+        g_critical("error setting timeout for com port: %lu",GetLastError());
+        CloseHandle(c->handle);
+        return false;
+    }
+
     return true;
 }
 
qga/main.c +9 -3
index c58b26a..c0b09ad 100644
@@ -47,9 +47,11 @@
 #ifndef _WIN32
 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
 #define QGA_STATE_RELATIVE_DIR  "run"
+#define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0"
 #else
 #define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0"
 #define QGA_STATE_RELATIVE_DIR  "qemu-ga"
+#define QGA_SERIAL_PATH_DEFAULT "COM1"
 #endif
 #ifdef CONFIG_FSFREEZE
 #define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook"
@@ -659,12 +661,16 @@ static gboolean channel_init(GAState *s, const gchar *method, const gchar *path)
     }
 
     if (path == NULL) {
-        if (strcmp(method, "virtio-serial") != 0) {
+        if (strcmp(method, "virtio-serial") == 0 ) {
+            /* try the default path for the virtio-serial port */
+            path = QGA_VIRTIO_PATH_DEFAULT;
+        } else if (strcmp(method, "isa-serial") == 0){
+            /* try the default path for the serial port - COM1 */
+            path = QGA_SERIAL_PATH_DEFAULT;
+        } else {
             g_critical("must specify a path for this channel");
             return false;
         }
-        /* try the default path for the virtio-serial port */
-        path = QGA_VIRTIO_PATH_DEFAULT;
     }
 
     if (strcmp(method, "virtio-serial") == 0) {
Signature · 1 line
1.8.3.1
Applied
#2 lore raw

Quoting Miki Mishael (2014-01-15 03:33:44)

Quoted 6 lines

Add support for isa-serial method for qemu-ga on Windows, Added -p command line parameter for serial port name specification, e.g. "-p COM15".

Thanks, applied to qga tree:

https://github.com/mdroth/qemu/commits/qga

Quoted 85 lines
---
 qga/channel-win32.c | 20 ++++++++++++++++++--
 qga/main.c          | 12 +++++++++---
 2 files changed, 27 insertions(+), 5 deletions(-)
qga/channel-win32.c +18 -2
index 8a303f3..0d5e5f5 100644
@@ -287,12 +287,22 @@ GIOStatus ga_channel_write_all(GAChannel *c, const char *buf, size_t size)
 static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
                                 const gchar *path)
 {
-    if (method != GA_CHANNEL_VIRTIO_SERIAL) {
+    COMMTIMEOUTS comTimeOut = {0};
+    gchar newpath[MAXPATHLEN] = {0};
+    comTimeOut.ReadIntervalTimeout = 1;
+
+    if (method != GA_CHANNEL_VIRTIO_SERIAL && method != GA_CHANNEL_ISA_SERIAL) {
         g_critical("unsupported communication method");
         return false;
     }
 
-    c->handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
+    if (method == GA_CHANNEL_ISA_SERIAL){
+        snprintf(newpath, sizeof(newpath), "\\\\.\\%s", path);
+    }else {
+        g_strlcpy(newpath, path, sizeof(newpath));
+    }
+
+    c->handle = CreateFile(newpath, GENERIC_READ | GENERIC_WRITE, 0, NULL,
                            OPEN_EXISTING,
                            FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL);
     if (c->handle == INVALID_HANDLE_VALUE) {
@@ -300,6 +310,12 @@ static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
         return false;
     }
 
+    if (method == GA_CHANNEL_ISA_SERIAL && !SetCommTimeouts(c->handle,&comTimeOut)) {
+        g_critical("error setting timeout for com port: %lu",GetLastError());
+        CloseHandle(c->handle);
+        return false;
+    }
+
     return true;
 }
 
qga/main.c +9 -3
index c58b26a..c0b09ad 100644
@@ -47,9 +47,11 @@
 #ifndef _WIN32
 #define QGA_VIRTIO_PATH_DEFAULT "/dev/virtio-ports/org.qemu.guest_agent.0"
 #define QGA_STATE_RELATIVE_DIR  "run"
+#define QGA_SERIAL_PATH_DEFAULT "/dev/ttyS0"
 #else
 #define QGA_VIRTIO_PATH_DEFAULT "\\\\.\\Global\\org.qemu.guest_agent.0"
 #define QGA_STATE_RELATIVE_DIR  "qemu-ga"
+#define QGA_SERIAL_PATH_DEFAULT "COM1"
 #endif
 #ifdef CONFIG_FSFREEZE
 #define QGA_FSFREEZE_HOOK_DEFAULT CONFIG_QEMU_CONFDIR "/fsfreeze-hook"
@@ -659,12 +661,16 @@ static gboolean channel_init(GAState *s, const gchar *method, const gchar *path)
     }
 
     if (path == NULL) {
-        if (strcmp(method, "virtio-serial") != 0) {
+        if (strcmp(method, "virtio-serial") == 0 ) {
+            /* try the default path for the virtio-serial port */
+            path = QGA_VIRTIO_PATH_DEFAULT;
+        } else if (strcmp(method, "isa-serial") == 0){
+            /* try the default path for the serial port - COM1 */
+            path = QGA_SERIAL_PATH_DEFAULT;
+        } else {
             g_critical("must specify a path for this channel");
             return false;
         }
-        /* try the default path for the virtio-serial port */
-        path = QGA_VIRTIO_PATH_DEFAULT;
     }
 
     if (strcmp(method, "virtio-serial") == 0) {
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Miki Mishael

Hello,

I wonder if you have few minutes to review the patch and contribute to apply it to upstream. I appreciate your help.

Link:
http://lists.nongnu.org/archive/html/qemu-devel/2014-01/msg01823.html

Thanks,

Miki

----- Original Message -----
From: "Miki Mishael" <[email protected]>
To: [email protected]
Cc: "Yan Vugenfirer" <[email protected]>, "Michael Roth" <[email protected]>, "Adam Litke" <[email protected]>, "Ronen Hod" <[email protected]>, "Anthony Liguori" <[email protected]>, "Dmitry Fleytman" <[email protected]>
Sent: Wednesday, January 15, 2014 11:33:43 AM
Subject: [Qemu-devel] [PATCH V2] qemu-ga: isa-serial support on Windows

Add support for isa-serial method for qemu-ga on Windows, Added -p command line parameter for serial port name specification, e.g. "-p COM15".

Changes since V1:
* define default path for isa-serial for linux, "/dev/ttyS0".
* replaced static void ga_serial_path_correction function for path correction with snprintf.
* minor indentation fix.
* fixed error output when setting timeout for com port fails.

Miki Mishael (1):
qemu-ga: isa-serial support on Windows

 qga/channel-win32.c | 20 ++++++++++++++++++--
 qga/main.c          | 12 +++++++++---
 2 files changed, 27 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1