* [Qemu-devel] [PATCH v2] chardev: Allow for pty path passing.
@ 2019-01-03 21:06 Paulo Neves
2019-01-04 10:14 ` no-reply
2019-01-04 10:18 ` no-reply
0 siblings, 2 replies; 3+ messages in thread
From: Paulo Neves @ 2019-01-03 21:06 UTC (permalink / raw)
To: qemu-devel; +Cc: Paulo Neves
If a user requires a virtual serial device like provided
by the pty char device, the user needs to accept the
returned device name. This makes the program need to
have smarts to parse or communicate with qemu to get the
pty device.
With this patch the program can pass the path where
a symlink to the pty device will be, removing the
need for 2 way communication or smarts.
Signed-off-by: Paulo Neves <ptsneves@gmail.com>
---
chardev/char-pty.c | 39 ++++++++++++++++++++++++++++++++++++++-
chardev/char.c | 6 +++++-
qapi/char.json | 2 +-
3 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index f681d63..3bbf99e 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -34,6 +34,7 @@
typedef struct {
Chardev parent;
QIOChannel *ioc;
+ char *link_name;
int read_bytes;
/* Protected by the Chardev chr_write_lock. */
@@ -234,6 +235,12 @@ static void char_pty_finalize(Object *obj)
qemu_mutex_lock(&chr->chr_write_lock);
pty_chr_state(chr, 0);
object_unref(OBJECT(s->ioc));
+
+ if (s->link_name) {
+ unlink(s->link_name);
+ g_free(s->link_name);
+ }
+
pty_chr_timer_cancel(s);
qemu_mutex_unlock(&chr->chr_write_lock);
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
@@ -244,8 +251,9 @@ static void char_pty_open(Chardev *chr,
bool *be_opened,
Error **errp)
{
+ ChardevHostdev *opts = backend->u.pty.data;
PtyChardev *s;
- int master_fd, slave_fd;
+ int master_fd, slave_fd, symlink_ret;
char pty_name[PATH_MAX];
char *name;
@@ -256,6 +264,17 @@ static void char_pty_open(Chardev *chr,
}
close(slave_fd);
+
+ s = PTY_CHARDEV(chr);
+ s->link_name = g_strdup(opts->device);
+ symlink_ret = symlink(pty_name, s->link_name);
+
+ if (symlink_ret < 0) {
+ close(master_fd);
+ error_setg_errno(errp, errno, "Failed to create symlink to PTY");
+ return;
+ }
+
qemu_set_nonblock(master_fd);
chr->filename = g_strdup_printf("pty:%s", pty_name);
@@ -271,6 +290,23 @@ static void char_pty_open(Chardev *chr,
*be_opened = false;
}
+static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend,
+ Error **errp)
+{
+ const char *symlink_path = qemu_opt_get(opts, "path");
+ if(symlink_path == NULL) {
+ error_setg(errp, "chardev: pty symlink: no device path given");
+ return;
+
+ }
+ ChardevHostdev *dev;
+
+ backend->type = CHARDEV_BACKEND_KIND_PTY;
+ dev = backend->u.pipe.data = g_new0(ChardevHostdev, 1);
+ qemu_chr_parse_common(opts, qapi_ChardevHostdev_base(dev));
+ dev->device = g_strdup(symlink_path);
+}
+
static void char_pty_class_init(ObjectClass *oc, void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
@@ -279,6 +315,7 @@ static void char_pty_class_init(ObjectClass *oc, void *data)
cc->chr_write = char_pty_chr_write;
cc->chr_update_read_handler = pty_chr_update_read_handler;
cc->chr_add_watch = pty_chr_add_watch;
+ cc->parse = char_pty_parse;
}
static const TypeInfo char_pty_type_info = {
diff --git a/chardev/char.c b/chardev/char.c
index ccba36b..43fce4a 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -373,7 +373,6 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
}
if (strcmp(filename, "null") == 0 ||
- strcmp(filename, "pty") == 0 ||
strcmp(filename, "msmouse") == 0 ||
strcmp(filename, "wctablet") == 0 ||
strcmp(filename, "braille") == 0 ||
@@ -418,6 +417,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) ||
diff --git a/qapi/char.json b/qapi/char.json
index 77ed847..3fd5b07 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -229,7 +229,7 @@
##
# @ChardevHostdev:
#
-# Configuration info for device and pipe chardevs.
+# Configuration info for device, pty and pipe chardevs.
#
# @device: The name of the special file for the device,
# i.e. /dev/ttyS0 on Unix or COM1: on Windows
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] chardev: Allow for pty path passing.
2019-01-03 21:06 [Qemu-devel] [PATCH v2] chardev: Allow for pty path passing Paulo Neves
@ 2019-01-04 10:14 ` no-reply
2019-01-04 10:18 ` no-reply
1 sibling, 0 replies; 3+ messages in thread
From: no-reply @ 2019-01-04 10:14 UTC (permalink / raw)
To: ptsneves; +Cc: fam, qemu-devel
Patchew URL: https://patchew.org/QEMU/1546549573-22912-1-git-send-email-ptsneves@gmail.com/
Hi,
This series failed the docker-quick@centos7 build test. Please find the testing commands and
their output below. If you have Docker installed, you can probably reproduce it
locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-quick@centos7 SHOW_ENV=1 J=8
=== TEST SCRIPT END ===
libpmem support no
libudev no
WARNING: Use of SDL 1.2 is deprecated and will be removed in
WARNING: future releases. Please switch to using SDL 2.0
NOTE: cross-compilers enabled: 'cc'
GEN x86_64-softmmu/config-devices.mak.tmp
---
SIGN optionrom/kvmvapic.bin
LINK ivshmem-client
/tmp/qemu-test/src/chardev/char-pty.c: In function 'char_pty_open':
/tmp/qemu-test/src/chardev/char-pty.c:254:28: error: initialization from incompatible pointer type [-Werror]
ChardevHostdev *opts = backend->u.pty.data;
^
/tmp/qemu-test/src/chardev/char-pty.c: In function 'char_pty_parse':
/tmp/qemu-test/src/chardev/char-pty.c:296:5: error: implicit declaration of function 'qemu_opt_get' [-Werror=implicit-function-declaration]
const char *symlink_path = qemu_opt_get(opts, "path");
^
/tmp/qemu-test/src/chardev/char-pty.c:296:5: error: nested extern declaration of 'qemu_opt_get' [-Werror=nested-externs]
/tmp/qemu-test/src/chardev/char-pty.c:296:32: error: initialization makes pointer from integer without a cast [-Werror]
const char *symlink_path = qemu_opt_get(opts, "path");
^
/tmp/qemu-test/src/chardev/char-pty.c: At top level:
cc1: error: unrecognized command line option "-Wno-format-truncation" [-Werror]
cc1: all warnings being treated as errors
make: *** [chardev/char-pty.o] Error 1
make: *** Waiting for unfinished jobs....
The full log is available at
http://patchew.org/logs/1546549573-22912-1-git-send-email-ptsneves@gmail.com/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] chardev: Allow for pty path passing.
2019-01-03 21:06 [Qemu-devel] [PATCH v2] chardev: Allow for pty path passing Paulo Neves
2019-01-04 10:14 ` no-reply
@ 2019-01-04 10:18 ` no-reply
1 sibling, 0 replies; 3+ messages in thread
From: no-reply @ 2019-01-04 10:18 UTC (permalink / raw)
To: ptsneves; +Cc: fam, qemu-devel
Patchew URL: https://patchew.org/QEMU/1546549573-22912-1-git-send-email-ptsneves@gmail.com/
Hi,
This series seems to have some coding style problems. See output below for
more information:
Type: series
Message-id: 1546549573-22912-1-git-send-email-ptsneves@gmail.com
Subject: [Qemu-devel] [PATCH v2] chardev: Allow for pty path passing.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
d9f326b chardev: Allow for pty path passing.
=== OUTPUT BEGIN ===
Checking PATCH 1/1: chardev: Allow for pty path passing....
ERROR: space required before the open parenthesis '('
#80: FILE: chardev/char-pty.c:297:
+ if(symlink_path == NULL) {
total: 1 errors, 0 warnings, 102 lines checked
Your patch has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/1546549573-22912-1-git-send-email-ptsneves@gmail.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-04 10:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-03 21:06 [Qemu-devel] [PATCH v2] chardev: Allow for pty path passing Paulo Neves
2019-01-04 10:14 ` no-reply
2019-01-04 10:18 ` no-reply
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).