Skip to contentSkip to conversation

chardev: add path option for pty backend

PATCH Superseded Octavian Purdila 5 participants 7 messages May 31, 2024 – Jun 3, 2024

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chardev: add path option for pty backend

Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY.

Based on patch from Paulo Neves:

https://patchew.org/QEMU/[email protected]/

Tested with the following invocations that the link is created and removed when qemu stops:

  qemu-system-x86_64 -nodefaults -mon chardev=compat_monitor \
  -chardev pty,path=test,id=compat_monitor0

qemu-system-x86_64 -nodefaults -monitor pty:test

Also tested that when a link path is not passed invocations still work, e.g.:

qemu-system-x86_64 -monitor pty

---
 chardev/char-pty.c | 34 ++++++++++++++++++++++++++++++++++
 chardev/char.c     |  5 +++++
 qapi/char.json     |  4 ++--
 qemu-options.hx    | 14 ++++++++++----
 4 files changed, 51 insertions(+), 6 deletions(-)
chardev/char-pty.c +34 -0
index cc2f7617fe..7cd5d34851 100644
@@ -29,6 +29,7 @@
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
+#include "qemu/option.h"
 #include "qemu/qemu-print.h"
 
 #include "chardev/char-io.h"
@@ -41,6 +42,7 @@ struct PtyChardev {
 
     int connected;
     GSource *timer_src;
+    char *symlink_path;
 };
 typedef struct PtyChardev PtyChardev;
 
@@ -204,6 +206,12 @@ static void char_pty_finalize(Object *obj)
     Chardev *chr = CHARDEV(obj);
     PtyChardev *s = PTY_CHARDEV(obj);
 
+    /* unlink symlink */
+    if (s->symlink_path) {
+        unlink(s->symlink_path);
+        g_free(s->symlink_path);
+    }
+
     pty_chr_state(chr, 0);
     object_unref(OBJECT(s->ioc));
     pty_chr_timer_cancel(s);
@@ -330,6 +338,7 @@ static void char_pty_open(Chardev *chr,
     int master_fd, slave_fd;
     char pty_name[PATH_MAX];
     char *name;
+    char *symlink_path = backend->u.pty.data->device;
 
     master_fd = qemu_openpty_raw(&slave_fd, pty_name);
     if (master_fd < 0) {
@@ -354,12 +363,37 @@ static void char_pty_open(Chardev *chr,
     g_free(name);
     s->timer_src = NULL;
     *be_opened = false;
+
+    /* create symbolic link */
+    if (symlink_path) {
+        int res = symlink(pty_name, symlink_path);
+
+        if (res != 0) {
+            error_setg_errno(errp, errno, "Failed to create PTY symlink");
+            close(master_fd);
+        } else {
+            s->symlink_path = g_strdup(symlink_path);
+        }
+    }
+}
+
+static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
+                           Error **errp)
+{
+    const char *path = qemu_opt_get(opts, "path");
+    ChardevHostdev *dev;
+
+    backend->type = CHARDEV_BACKEND_KIND_PTY;
+    dev = backend->u.pty.data = g_new0(ChardevHostdev, 1);
+    qemu_chr_parse_common(opts, qapi_ChardevHostdev_base(dev));
+    dev->device = path ? g_strdup(path) : NULL;
 }
 
 static void char_pty_class_init(ObjectClass *oc, void *data)
 {
     ChardevClass *cc = CHARDEV_CLASS(oc);
 
+    cc->parse = char_pty_parse;
     cc->open = char_pty_open;
     cc->chr_write = char_pty_chr_write;
     cc->chr_update_read_handler = pty_chr_update_read_handler;
chardev/char.c +5 -0
index 3c43fb1278..404c6b8a4f 100644
@@ -428,6 +428,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
         qemu_opt_set(opts, "path", p, &error_abort);
         return opts;
     }
+    if (strstart(filename, "pty:", &p)) {
+        qemu_opt_set(opts, "backend", "pty", &error_abort);
+        qemu_opt_set(opts, "path", p, &error_abort);
+        return opts;
+    }
     if (strstart(filename, "tcp:", &p) ||
         strstart(filename, "telnet:", &p) ||
         strstart(filename, "tn3270:", &p) ||
qapi/char.json +2 -2
index 777dde55d9..4c74bfc437 100644
@@ -509,7 +509,7 @@
 ##
 # @ChardevHostdevWrapper:
 #
-# @data: Configuration info for device and pipe chardevs
+# @data: Configuration info for device, pty and pipe chardevs
 #
 # Since: 1.4
 ##
@@ -650,7 +650,7 @@
             'pipe': 'ChardevHostdevWrapper',
             'socket': 'ChardevSocketWrapper',
             'udp': 'ChardevUdpWrapper',
-            'pty': 'ChardevCommonWrapper',
+            'pty': 'ChardevHostdevWrapper',
             'null': 'ChardevCommonWrapper',
             'mux': 'ChardevMuxWrapper',
             'msmouse': 'ChardevCommonWrapper',
qemu-options.hx +10 -4
index 8ca7f34ef0..5eec194242 100644
@@ -3569,7 +3569,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
     "-chardev console,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev serial,id=id,path=path[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
 #else
-    "-chardev pty,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
+    "-chardev pty,id=id[,path=path][,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev stdio,id=id[,mux=on|off][,signal=on|off][,logfile=PATH][,logappend=on|off]\n"
 #endif
 #ifdef CONFIG_BRLAPI
@@ -3808,12 +3808,16 @@ The available backends are:
 
     ``path`` specifies the name of the serial device to open.
 
-``-chardev pty,id=id``
+``-chardev pty,id=id[,path=path]``
     Create a new pseudo-terminal on the host and connect to it. ``pty``
     does not take any options.
 
     ``pty`` is not available on Windows hosts.
 
+    ``path`` specifies the symbolic link path to be created that
+    points to the pty device.
+
+
 ``-chardev stdio,id=id[,signal=on|off]``
     Connect to standard input and standard output of the QEMU process.
 
@@ -4171,8 +4175,10 @@ SRST
 
             vc:80Cx24C
 
-    ``pty``
-        [Linux only] Pseudo TTY (a new PTY is automatically allocated)
+    ``pty[:path]``
+        [Linux only] Pseudo TTY (a new PTY is automatically allocated).
+        Optionally a path can be given to create a symbolic link to
+        the allocated PTY.
 
     ``none``
         No device is allocated. Note that for machine types which
Signature · 1 line
2.45.1.288.g0e0cd299f1-goog
#1 lore raw
Quoted 13 lines · Octavian Purdila

Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY.

Based on patch from Paulo Neves:

https://patchew.org/QEMU/[email protected]/

Tested with the following invocations that the link is created and removed when qemu stops:

  qemu-system-x86_64 -nodefaults -mon chardev=compat_monitor \
  -chardev pty,path=test,id=compat_monitor0
Quoted 8 lines

qemu-system-x86_64 -nodefaults -monitor pty:test

Also tested that when a link path is not passed invocations still work, e.g.:

qemu-system-x86_64 -monitor pty

When creating a new version of someone else's previous patch, you generally should keep the original Signed-off-by, then add 1 or 2 lines explaining what further changes you made, then add your own Signed-off-by.

Quoted 172 lines
---
 chardev/char-pty.c | 34 ++++++++++++++++++++++++++++++++++
 chardev/char.c     |  5 +++++
 qapi/char.json     |  4 ++--
 qemu-options.hx    | 14 ++++++++++----
 4 files changed, 51 insertions(+), 6 deletions(-)
chardev/char-pty.c +34 -0
index cc2f7617fe..7cd5d34851 100644
@@ -29,6 +29,7 @@
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
+#include "qemu/option.h"
 #include "qemu/qemu-print.h"
 
 #include "chardev/char-io.h"
@@ -41,6 +42,7 @@ struct PtyChardev {
 
     int connected;
     GSource *timer_src;
+    char *symlink_path;
 };
 typedef struct PtyChardev PtyChardev;
 
@@ -204,6 +206,12 @@ static void char_pty_finalize(Object *obj)
     Chardev *chr = CHARDEV(obj);
     PtyChardev *s = PTY_CHARDEV(obj);
 
+    /* unlink symlink */
+    if (s->symlink_path) {
+        unlink(s->symlink_path);
+        g_free(s->symlink_path);
+    }
+
     pty_chr_state(chr, 0);
     object_unref(OBJECT(s->ioc));
     pty_chr_timer_cancel(s);
@@ -330,6 +338,7 @@ static void char_pty_open(Chardev *chr,
     int master_fd, slave_fd;
     char pty_name[PATH_MAX];
     char *name;
+    char *symlink_path = backend->u.pty.data->device;
 
     master_fd = qemu_openpty_raw(&slave_fd, pty_name);
     if (master_fd < 0) {
@@ -354,12 +363,37 @@ static void char_pty_open(Chardev *chr,
     g_free(name);
     s->timer_src = NULL;
     *be_opened = false;
+
+    /* create symbolic link */
+    if (symlink_path) {
+        int res = symlink(pty_name, symlink_path);
+
+        if (res != 0) {
+            error_setg_errno(errp, errno, "Failed to create PTY symlink");
+            close(master_fd);
+        } else {
+            s->symlink_path = g_strdup(symlink_path);
+        }
+    }
+}
+
+static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
+                           Error **errp)
+{
+    const char *path = qemu_opt_get(opts, "path");
+    ChardevHostdev *dev;
+
+    backend->type = CHARDEV_BACKEND_KIND_PTY;
+    dev = backend->u.pty.data = g_new0(ChardevHostdev, 1);
+    qemu_chr_parse_common(opts, qapi_ChardevHostdev_base(dev));
+    dev->device = path ? g_strdup(path) : NULL;
 }
 
 static void char_pty_class_init(ObjectClass *oc, void *data)
 {
     ChardevClass *cc = CHARDEV_CLASS(oc);
 
+    cc->parse = char_pty_parse;
     cc->open = char_pty_open;
     cc->chr_write = char_pty_chr_write;
     cc->chr_update_read_handler = pty_chr_update_read_handler;
chardev/char.c +5 -0
index 3c43fb1278..404c6b8a4f 100644
@@ -428,6 +428,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
         qemu_opt_set(opts, "path", p, &error_abort);
         return opts;
     }
+    if (strstart(filename, "pty:", &p)) {
+        qemu_opt_set(opts, "backend", "pty", &error_abort);
+        qemu_opt_set(opts, "path", p, &error_abort);
+        return opts;
+    }
     if (strstart(filename, "tcp:", &p) ||
         strstart(filename, "telnet:", &p) ||
         strstart(filename, "tn3270:", &p) ||
qapi/char.json +2 -2
index 777dde55d9..4c74bfc437 100644
@@ -509,7 +509,7 @@
 ##
 # @ChardevHostdevWrapper:
 #
-# @data: Configuration info for device and pipe chardevs
+# @data: Configuration info for device, pty and pipe chardevs
 #
 # Since: 1.4
 ##
@@ -650,7 +650,7 @@
             'pipe': 'ChardevHostdevWrapper',
             'socket': 'ChardevSocketWrapper',
             'udp': 'ChardevUdpWrapper',
-            'pty': 'ChardevCommonWrapper',
+            'pty': 'ChardevHostdevWrapper',
             'null': 'ChardevCommonWrapper',
             'mux': 'ChardevMuxWrapper',
             'msmouse': 'ChardevCommonWrapper',
qemu-options.hx +10 -4
index 8ca7f34ef0..5eec194242 100644
@@ -3569,7 +3569,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
     "-chardev console,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev serial,id=id,path=path[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
 #else
-    "-chardev pty,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
+    "-chardev pty,id=id[,path=path][,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev stdio,id=id[,mux=on|off][,signal=on|off][,logfile=PATH][,logappend=on|off]\n"
 #endif
 #ifdef CONFIG_BRLAPI
@@ -3808,12 +3808,16 @@ The available backends are:
 
     ``path`` specifies the name of the serial device to open.
 
-``-chardev pty,id=id``
+``-chardev pty,id=id[,path=path]``
     Create a new pseudo-terminal on the host and connect to it. ``pty``
     does not take any options.
 
     ``pty`` is not available on Windows hosts.
 
+    ``path`` specifies the symbolic link path to be created that
+    points to the pty device.
+
+
 ``-chardev stdio,id=id[,signal=on|off]``
     Connect to standard input and standard output of the QEMU process.
 
@@ -4171,8 +4175,10 @@ SRST
 
             vc:80Cx24C
 
-    ``pty``
-        [Linux only] Pseudo TTY (a new PTY is automatically allocated)
+    ``pty[:path]``
+        [Linux only] Pseudo TTY (a new PTY is automatically allocated).
+        Optionally a path can be given to create a symbolic link to
+        the allocated PTY.
 
     ``none``
         No device is allocated. Note that for machine types which
Signature · 1 line
2.45.1.288.g0e0cd299f1-goog

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
In reply to Octavian Purdila

Hi

Quoted 74 lines · Octavian Purdila

Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY.

Based on patch from Paulo Neves:

https://patchew.org/QEMU/[email protected]/

Tested with the following invocations that the link is created and removed when qemu stops:

  qemu-system-x86_64 -nodefaults -mon chardev=compat_monitor \
  -chardev pty,path=test,id=compat_monitor0

qemu-system-x86_64 -nodefaults -monitor pty:test

Also tested that when a link path is not passed invocations still work, e.g.:

qemu-system-x86_64 -monitor pty

---
 chardev/char-pty.c | 34 ++++++++++++++++++++++++++++++++++
 chardev/char.c     |  5 +++++
 qapi/char.json     |  4 ++--
 qemu-options.hx    | 14 ++++++++++----
 4 files changed, 51 insertions(+), 6 deletions(-)
chardev/char-pty.c +9 -0
index cc2f7617fe..7cd5d34851 100644
@@ -29,6 +29,7 @@
 #include "qemu/sockets.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
+#include "qemu/option.h"
 #include "qemu/qemu-print.h"
 
 #include "chardev/char-io.h"
@@ -41,6 +42,7 @@ struct PtyChardev {
 
     int connected;
     GSource *timer_src;
+    char *symlink_path;
 };
 typedef struct PtyChardev PtyChardev;
 
@@ -204,6 +206,12 @@ static void char_pty_finalize(Object *obj)
     Chardev *chr = CHARDEV(obj);
     PtyChardev *s = PTY_CHARDEV(obj);
 
+    /* unlink symlink */
+    if (s->symlink_path) {
+        unlink(s->symlink_path);
+        g_free(s->symlink_path);
+    }
+
     pty_chr_state(chr, 0);
     object_unref(OBJECT(s->ioc));
     pty_chr_timer_cancel(s);
@@ -330,6 +338,7 @@ static void char_pty_open(Chardev *chr,
     int master_fd, slave_fd;
     char pty_name[PATH_MAX];
     char *name;
+    char *symlink_path = backend->u.pty.data->device;
 
     master_fd = qemu_openpty_raw(&slave_fd, pty_name);
     if (master_fd < 0) {
@@ -354,12 +363,37 @@ static void char_pty_open(Chardev *chr,
     g_free(name);
     s->timer_src = NULL;

chardev/char-pty.c static void char_pty_open(Chardev *chr, · line 374

Quoted 10 lines
chardev/char-pty.c +8 -0
     *be_opened = false;
+
+    /* create symbolic link */
+    if (symlink_path) {
+        int res = symlink(pty_name, symlink_path);
+
+        if (res != 0) {
+            error_setg_errno(errp, errno, "Failed to create PTY symlink");
+            close(master_fd);
 

The fd is owned by s->ioc at this point: this will end up in double-close in finalize.

Quoted 31 lines
chardev/char-pty.c +17 -0
+        } else {
+            s->symlink_path = g_strdup(symlink_path);
+        }
+    }
+}
+
+static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
+                           Error **errp)
+{
+    const char *path = qemu_opt_get(opts, "path");
+    ChardevHostdev *dev;
+
+    backend->type = CHARDEV_BACKEND_KIND_PTY;
+    dev = backend->u.pty.data = g_new0(ChardevHostdev, 1);
+    qemu_chr_parse_common(opts, qapi_ChardevHostdev_base(dev));
+    dev->device = path ? g_strdup(path) : NULL;
 }
 
 static void char_pty_class_init(ObjectClass *oc, void *data)
 {
     ChardevClass *cc = CHARDEV_CLASS(oc);
 
+    cc->parse = char_pty_parse;
     cc->open = char_pty_open;
     cc->chr_write = char_pty_chr_write;
     cc->chr_update_read_handler = pty_chr_update_read_handler;
chardev/char.c +0 -0
index 3c43fb1278..404c6b8a4f 100644

chardev/char.c QemuOpts *qemu_chr_parse_compat(const char *label, · line 437

Quoted 10 lines
chardev/char.c +5 -0
@@ -428,6 +428,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label,
 const char *filename,
         qemu_opt_set(opts, "path", p, &error_abort);
         return opts;
     }
+    if (strstart(filename, "pty:", &p)) {
+        qemu_opt_set(opts, "backend", "pty", &error_abort);
+        qemu_opt_set(opts, "path", p, &error_abort);
+        return opts;
+    }
 

I am not sure we want to expand compat parsing here, but probably ok.

Quoted 74 lines
chardev/char.c +0 -0
     if (strstart(filename, "tcp:", &p) ||
         strstart(filename, "telnet:", &p) ||
         strstart(filename, "tn3270:", &p) ||
qapi/char.json +2 -2
index 777dde55d9..4c74bfc437 100644
@@ -509,7 +509,7 @@
 ##
 # @ChardevHostdevWrapper:
 #
-# @data: Configuration info for device and pipe chardevs
+# @data: Configuration info for device, pty and pipe chardevs
 #
 # Since: 1.4
 ##
@@ -650,7 +650,7 @@
             'pipe': 'ChardevHostdevWrapper',
             'socket': 'ChardevSocketWrapper',
             'udp': 'ChardevUdpWrapper',
-            'pty': 'ChardevCommonWrapper',
+            'pty': 'ChardevHostdevWrapper',
             'null': 'ChardevCommonWrapper',
             'mux': 'ChardevMuxWrapper',
             'msmouse': 'ChardevCommonWrapper',
qemu-options.hx +0 -0
index 8ca7f34ef0..5eec194242 100644
@@ -3569,7 +3569,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
     "-chardev

console,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
"-chardev
serial,id=id,path=path[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
#else

qemu-options.hx +1 -1
-    "-chardev pty,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
+    "-chardev

pty,id=id[,path=path][,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
"-chardev
stdio,id=id[,mux=on|off][,signal=on|off][,logfile=PATH][,logappend=on|off]\n"
#endif
#ifdef CONFIG_BRLAPI

qemu-options.hx +9 -4
@@ -3808,12 +3808,16 @@ The available backends are:
 
     ``path`` specifies the name of the serial device to open.
 
-``-chardev pty,id=id``
+``-chardev pty,id=id[,path=path]``
     Create a new pseudo-terminal on the host and connect to it. ``pty``
     does not take any options.
 
     ``pty`` is not available on Windows hosts.
 
+    ``path`` specifies the symbolic link path to be created that
+    points to the pty device.
+
+
 ``-chardev stdio,id=id[,signal=on|off]``
     Connect to standard input and standard output of the QEMU process.
 
@@ -4171,8 +4175,10 @@ SRST
 
             vc:80Cx24C
 
-    ``pty``
-        [Linux only] Pseudo TTY (a new PTY is automatically allocated)
+    ``pty[:path]``
+        [Linux only] Pseudo TTY (a new PTY is automatically allocated).
+        Optionally a path can be given to create a symbolic link to
+        the allocated PTY.
 
     ``none``
         No device is allocated. Note that for machine types which
--
Quoted 4 lines

2.45.1.288.g0e0cd299f1-goog

thanks

Signature · 1 line
Marc-André Lureau
#3 lore raw
In reply to Octavian Purdila
Quoted 11 lines · Octavian Purdila

Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY.

Based on patch from Paulo Neves:

https://patchew.org/QEMU/[email protected]/

Tested with the following invocations that the link is created and removed when qemu stops:

Quoted 8 lines
  qemu-system-x86_64 -nodefaults -mon chardev=compat_monitor \
  -chardev pty,path=test,id=compat_monitor0

qemu-system-x86_64 -nodefaults -monitor pty:test

Also tested that when a link path is not passed invocations still work, e.g.:

qemu-system-x86_64 -monitor pty

Could we have some justification here for why the new functionality is useful, please? (e.g. what new use cases it permits).

Quoted 12 lines
qapi/char.json +1 -1
@@ -509,7 +509,7 @@
 ##
 # @ChardevHostdevWrapper:
 #
-# @data: Configuration info for device and pipe chardevs
+# @data: Configuration info for device, pty and pipe chardevs
 #
 # Since: 1.4
 ##

qapi/char.json line 656

Quoted 8 lines
qapi/char.json +1 -1
@@ -650,7 +650,7 @@
             'pipe': 'ChardevHostdevWrapper',
             'socket': 'ChardevSocketWrapper',
             'udp': 'ChardevUdpWrapper',
-            'pty': 'ChardevCommonWrapper',
+            'pty': 'ChardevHostdevWrapper',
             'null': 'ChardevCommonWrapper',
             'mux': 'ChardevMuxWrapper',
             'msmouse': 'ChardevCommonWrapper',

Does this break QAPI compatibility?

Quoted 14 lines
qemu-options.hx +1 -1
index 8ca7f34ef0..5eec194242 100644
@@ -3569,7 +3569,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
     "-chardev console,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev serial,id=id,path=path[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
 #else
-    "-chardev pty,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
+    "-chardev pty,id=id[,path=path][,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev stdio,id=id[,mux=on|off][,signal=on|off][,logfile=PATH][,logappend=on|off]\n"
 #endif
 #ifdef CONFIG_BRLAPI

qemu-options.hx The available backends are: · line 3813

Quoted 7 lines
qemu-options.hx +1 -1
@@ -3808,12 +3808,16 @@ The available backends are:
 
     ``path`` specifies the name of the serial device to open.
 
-``-chardev pty,id=id``
+``-chardev pty,id=id[,path=path]``
     Create a new pseudo-terminal on the host and connect to it. ``pty``
     does not take any options.

We just added an option, so we should delete the line saying that it doesn't take any options :-)

qemu-options.hx The available backends are: · line 3818

Quoted 5 lines
qemu-options.hx +2 -0
     ``pty`` is not available on Windows hosts.
 
+    ``path`` specifies the symbolic link path to be created that
+    points to the pty device.

I think we could usefully make this a little less terse. Perhaps
If ``path`` is specified, QEMU will create a symbolic link at that location which points to the new PTY device.
?

thanks
-- PMM

#4 lore raw

Hi

Quoted 18 lines · Peter Maydell
Quoted 16 lines · Octavian Purdila

Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY.

Based on patch from Paulo Neves:

https://patchew.org/QEMU/[email protected]/

Tested with the following invocations that the link is created and removed when qemu stops:

  qemu-system-x86_64 -nodefaults -mon chardev=compat_monitor \
  -chardev pty,path=test,id=compat_monitor0

qemu-system-x86_64 -nodefaults -monitor pty:test

Quoted 8 lines
Quoted 3 lines

Also tested that when a link path is not passed invocations still work, e.g.:

qemu-system-x86_64 -monitor pty

Could we have some justification here for why the new functionality is useful, please? (e.g. what new use cases it permits).

It avoids the need to HMP/QMP query the allocated pty path. I don't think there are other benefits.

Quoted 62 lines
Quoted 12 lines
qapi/char.json +1 -1
@@ -509,7 +509,7 @@
 ##
 # @ChardevHostdevWrapper:
 #
-# @data: Configuration info for device and pipe chardevs
+# @data: Configuration info for device, pty and pipe chardevs
 #
 # Since: 1.4
 ##

qapi/char.json line 656

Quoted 8 lines
qapi/char.json +1 -1
@@ -650,7 +650,7 @@
             'pipe': 'ChardevHostdevWrapper',
             'socket': 'ChardevSocketWrapper',
             'udp': 'ChardevUdpWrapper',
-            'pty': 'ChardevCommonWrapper',
+            'pty': 'ChardevHostdevWrapper',
             'null': 'ChardevCommonWrapper',
             'mux': 'ChardevMuxWrapper',
             'msmouse': 'ChardevCommonWrapper',

Does this break QAPI compatibility?

Quoted 14 lines
qemu-options.hx +1 -1
index 8ca7f34ef0..5eec194242 100644
@@ -3569,7 +3569,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
     "-chardev console,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev serial,id=id,path=path[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
 #else
-    "-chardev pty,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
+    "-chardev pty,id=id[,path=path][,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev stdio,id=id[,mux=on|off][,signal=on|off][,logfile=PATH][,logappend=on|off]\n"
 #endif
 #ifdef CONFIG_BRLAPI

qemu-options.hx The available backends are: · line 3813

Quoted 7 lines
qemu-options.hx +1 -1
@@ -3808,12 +3808,16 @@ The available backends are:
 
     ``path`` specifies the name of the serial device to open.
 
-``-chardev pty,id=id``
+``-chardev pty,id=id[,path=path]``
     Create a new pseudo-terminal on the host and connect to it. ``pty``
     does not take any options.

We just added an option, so we should delete the line saying that it doesn't take any options :-)

qemu-options.hx The available backends are: · line 3818

Quoted 5 lines
qemu-options.hx +2 -0
     ``pty`` is not available on Windows hosts.
 
+    ``path`` specifies the symbolic link path to be created that
+    points to the pty device.

I think we could usefully make this a little less terse. Perhaps
If ``path`` is specified, QEMU will create a symbolic link at that location which points to the new PTY device.
?

thanks
-- PMM

#5 lore raw
In reply to Peter Maydell
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Octavian Purdila

Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY.

Based on patch from Paulo Neves:

https://patchew.org/QEMU/[email protected]/

Tested with the following invocations that the link is created and removed when qemu stops:

  qemu-system-x86_64 -nodefaults -mon chardev=compat_monitor \
  -chardev pty,path=test,id=compat_monitor0

qemu-system-x86_64 -nodefaults -monitor pty:test

Quoted 7 lines
Quoted 3 lines

Also tested that when a link path is not passed invocations still work, e.g.:

qemu-system-x86_64 -monitor pty

Could we have some justification here for why the new functionality is useful, please? (e.g. what new use cases it permits).

The PTY paths are dynamically allocated so you can't predict them as an app launching QEMU. You need to connect to the monitor and interogate QEMU to find the path. So supporting a symlink simplifies usage.

This was explained in the original patches' commit message, and that description should have been kept.

Quoted 14 lines
Quoted 14 lines
qapi/char.json +1 -1
@@ -509,7 +509,7 @@
 ##
 # @ChardevHostdevWrapper:
 #
-# @data: Configuration info for device and pipe chardevs
+# @data: Configuration info for device, pty and pipe chardevs
 #
 # Since: 1.4
 ##
@@ -650,7 +650,7 @@
             'pipe': 'ChardevHostdevWrapper',
             'socket': 'ChardevSocketWrapper',
Quoted 8 lines

qapi/char.json line 656

Quoted 6 lines
qapi/char.json +1 -1
             'udp': 'ChardevUdpWrapper',
-            'pty': 'ChardevCommonWrapper',
+            'pty': 'ChardevHostdevWrapper',
             'null': 'ChardevCommonWrapper',
             'mux': 'ChardevMuxWrapper',
             'msmouse': 'ChardevCommonWrapper',

Does this break QAPI compatibility?

No, what matters for compatibility is the *contents* of the struct, not the particular struct names. Since ChardevHostdevWrapper is a superset of of ChardevCommonWrapper we are fine with back compat.

Quoted 31 lines
Quoted 15 lines
qemu-options.hx +1 -1
index 8ca7f34ef0..5eec194242 100644
@@ -3569,7 +3569,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
     "-chardev console,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev serial,id=id,path=path[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
 #else
-    "-chardev pty,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
+    "-chardev pty,id=id[,path=path][,mux=on|off][,logfile=PATH][,logappend=on|off]\n"
     "-chardev stdio,id=id[,mux=on|off][,signal=on|off][,logfile=PATH][,logappend=on|off]\n"
 #endif
 #ifdef CONFIG_BRLAPI

qemu-options.hx The available backends are: · line 3813

Quoted 7 lines
qemu-options.hx +1 -1
@@ -3808,12 +3808,16 @@ The available backends are:
 
     ``path`` specifies the name of the serial device to open.
 
-``-chardev pty,id=id``
+``-chardev pty,id=id[,path=path]``
     Create a new pseudo-terminal on the host and connect to it. ``pty``
     does not take any options.

We just added an option, so we should delete the line saying that it doesn't take any options :-)

Quoted 3 lines
qemu-options.hx +0 -0
     ``pty`` is not available on Windows hosts.
 
Quoted 7 lines

qemu-options.hx The available backends are: · line 3818

Quoted 2 lines
qemu-options.hx +2 -0
+    ``path`` specifies the symbolic link path to be created that
+    points to the pty device.

I think we could usefully make this a little less terse. Perhaps
If ``path`` is specified, QEMU will create a symbolic link at that location which points to the new PTY device.
?

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#6 lore raw
Quoted 27 lines · Daniel P. Berrangé
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Octavian Purdila

Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY.

Based on patch from Paulo Neves:

https://patchew.org/QEMU/[email protected]/

Tested with the following invocations that the link is created and removed when qemu stops:

  qemu-system-x86_64 -nodefaults -mon chardev=compat_monitor \
  -chardev pty,path=test,id=compat_monitor0

qemu-system-x86_64 -nodefaults -monitor pty:test

Quoted 7 lines
Quoted 3 lines

Also tested that when a link path is not passed invocations still work, e.g.:

qemu-system-x86_64 -monitor pty

Could we have some justification here for why the new functionality is useful, please? (e.g. what new use cases it permits).

Quoted 7 lines

The PTY paths are dynamically allocated so you can't predict them as an app launching QEMU. You need to connect to the monitor and interogate QEMU to find the path. So supporting a symlink simplifies usage.

This was explained in the original patches' commit message, and that description should have been kept.

Sounds good. We could add that to the documentation also:

Quoted 9 lines
Quoted 9 lines

qemu-options.hx The available backends are: · line 3818

Quoted 4 lines

``pty`` is not available on Windows hosts.

qemu-options.hx +2 -0
+    ``path`` specifies the symbolic link path to be created that
+    points to the pty device.

I think we could usefully make this a little less terse. Perhaps
If ``path`` is specified, QEMU will create a symbolic link at that location which points to the new PTY device.
?

This allows you to avoid having to make a query via the QMP or HMP monitor to find out what the new PTY device path is.

thanks
-- PMM