From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlM3C-0000HA-29 for qemu-devel@nongnu.org; Wed, 19 Dec 2012 10:59:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TlM38-00081I-D0 for qemu-devel@nongnu.org; Wed, 19 Dec 2012 10:59:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35828) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlM38-000810-5c for qemu-devel@nongnu.org; Wed, 19 Dec 2012 10:59:14 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBJFxDNP002948 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Dec 2012 10:59:13 -0500 From: Gerd Hoffmann Date: Wed, 19 Dec 2012 16:59:04 +0100 Message-Id: <1355932747-1755-7-git-send-email-kraxel@redhat.com> In-Reply-To: <1355932747-1755-1-git-send-email-kraxel@redhat.com> References: <1355932747-1755-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 6/9] chardev: hotplug, qmp, file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, Gerd Hoffmann , mprivozn@redhat.com Signed-off-by: Gerd Hoffmann --- qapi-schema.json | 9 +++++- qemu-char.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index e3f0d44..8904d36 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3030,9 +3030,16 @@ # # Since: 1.4 ## +{ 'union': 'ChardevFileSource', 'data': { 'path' : 'str', + 'fd' : 'str' } } + +{ 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource', + 'out' : 'ChardevFileSource' } } + { 'type': 'ChardevDummy', 'data': { } } -{ 'union': 'ChardevBackend', 'data': { 'null' : 'ChardevDummy' } } +{ 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile', + 'null' : 'ChardevDummy' } } { 'command': 'chardev-add', 'data': {'id' : 'str', 'backend' : 'ChardevBackend' } } diff --git a/qemu-char.c b/qemu-char.c index d2f0852..47d55ea 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2925,11 +2925,86 @@ CharDriverState *qemu_char_get_next_serial(void) return serial_hds[next_serial++]; } +#ifdef _WIN32 + +static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) +{ + HANDLE out; + + if (file->in) { + error_setg(errp, "input file not supported"); + return NULL; + } + if (file->out->kind != CHARDEV_FILE_SOURCE_KIND_PATH) { + error_setg(errp, "only file paths supported"); + return NULL; + } + + out = CreateFile(file->out->path, GENERIC_WRITE, FILE_SHARE_READ, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (out == INVALID_HANDLE_VALUE) { + error_setg(errp, "open %s failed", file->out->path); + return NULL; + } + return qemu_chr_open_win_file(out); +} + +#else /* WIN32 */ + +static int qmp_chardev_open_file_source(ChardevFileSource *src, int flags, + Error **errp) +{ + int fd = -1; + + switch (src->kind) { + case CHARDEV_FILE_SOURCE_KIND_PATH: + TFR(fd = qemu_open(src->path, flags, 0666)); + if (fd == -1) { + error_setg(errp, "open %s: %s", src->path, strerror(errno)); + } + break; + case CHARDEV_FILE_SOURCE_KIND_FD: + fd = monitor_get_fd(cur_mon, src->fd, errp); + break; + default: + error_setg(errp, "unknown chardev file source (%d)", src->kind); + break; + } + return fd; +} + +static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp) +{ + int flags, in = -1, out = -1; + + flags = O_WRONLY | O_TRUNC | O_CREAT | O_BINARY; + out = qmp_chardev_open_file_source(file->out, flags, errp); + if (error_is_set(errp)) { + return NULL; + } + + if (file->in) { + flags = O_RDONLY; + in = qmp_chardev_open_file_source(file->in, flags, errp); + if (error_is_set(errp)) { + qemu_close(out); + return NULL; + } + } + + return qemu_chr_open_fd(in, out); +} + +#endif /* WIN32 */ + void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp) { CharDriverState *chr; switch (backend->kind) { + case CHARDEV_BACKEND_KIND_FILE: + chr = qmp_chardev_open_file(backend->file, errp); + break; case CHARDEV_BACKEND_KIND_NULL: chr = qemu_chr_open_null(NULL); break; @@ -2938,7 +3013,7 @@ void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp) return; } - if (chr == NULL) { + if (chr == NULL && !error_is_set(errp)) { error_setg(errp, "Failed to create chardev"); } } -- 1.7.1