From patchwork Thu Feb 28 07:50:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 223797 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2532D2C007B for ; Thu, 28 Feb 2013 18:55:08 +1100 (EST) Received: from localhost ([::1]:60181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAyKY-0006Kr-AG for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2013 02:55:06 -0500 Received: from eggs.gnu.org ([208.118.235.92]:45513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAyG3-0007xl-RD for qemu-devel@nongnu.org; Thu, 28 Feb 2013 02:50:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAyG1-00077b-OP for qemu-devel@nongnu.org; Thu, 28 Feb 2013 02:50:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57229) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAyG1-000769-F9 for qemu-devel@nongnu.org; Thu, 28 Feb 2013 02:50:25 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1S7oMaY025232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 28 Feb 2013 02:50:22 -0500 Received: from rincewind.home.kraxel.org (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1S7oC5i016517; Thu, 28 Feb 2013 02:50:13 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id C7510452BA; Thu, 28 Feb 2013 08:50:10 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 28 Feb 2013 08:50:05 +0100 Message-Id: <1362037809-27836-14-git-send-email-kraxel@redhat.com> In-Reply-To: <1362037809-27836-1-git-send-email-kraxel@redhat.com> References: <1362037809-27836-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 13/17] chardev: add spice support to qapi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds 'spicevmc' and 'spiceport' support to qapi and also switches over the spice chardev initialization to the new qapi code path. --- include/ui/qemu-spice.h | 7 +++++-- qapi-schema.json | 26 +++++++++++++++++++++++++- qemu-char.c | 44 ++++++++++++++++++++++++++++++++++++++------ spice-qemu-char.c | 26 ++++++++++---------------- 4 files changed, 78 insertions(+), 25 deletions(-) diff --git a/include/ui/qemu-spice.h b/include/ui/qemu-spice.h index 5a78fd7..eba6d77 100644 --- a/include/ui/qemu-spice.h +++ b/include/ui/qemu-spice.h @@ -44,10 +44,13 @@ int qemu_spice_migrate_info(const char *hostname, int port, int tls_port, void do_info_spice_print(Monitor *mon, const QObject *data); void do_info_spice(Monitor *mon, QObject **ret_data); -CharDriverState *qemu_chr_open_spice(QemuOpts *opts); +CharDriverState *qemu_chr_open_spice_vmc(const char *type); #if SPICE_SERVER_VERSION >= 0x000c02 -CharDriverState *qemu_chr_open_spice_port(QemuOpts *opts); +CharDriverState *qemu_chr_open_spice_port(const char *name); void qemu_spice_register_ports(void); +#else +static inline CharDriverState *qemu_chr_open_spice_port(const char *name) +{ return NULL; } #endif #else /* CONFIG_SPICE */ diff --git a/qapi-schema.json b/qapi-schema.json index c9e9bd5..f570185 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3209,6 +3209,28 @@ { 'type': 'ChardevStdio', 'data': { '*signal' : 'bool' } } ## +# @ChardevSpiceChannel: +# +# Configuration info for spice vm channel chardevs. +# +# @type: kind of channel (for example vdagent). +# +# Since: 1.5 +## +{ 'type': 'ChardevSpiceChannel', 'data': { 'type' : 'str' } } + +## +# @ChardevSpicePort: +# +# Configuration info for spice port chardevs. +# +# @fqdn: name of the channel (see docs/spice-port-fqdn.txt) +# +# Since: 1.5 +## +{ 'type': 'ChardevSpicePort', 'data': { 'fqdn' : 'str' } } + +## # @ChardevBackend: # # Configuration info for the new chardev backend. @@ -3228,7 +3250,9 @@ 'msmouse': 'ChardevDummy', 'braille': 'ChardevDummy', 'stdio' : 'ChardevStdio', - 'console': 'ChardevDummy' } } + 'console': 'ChardevDummy', + 'spicevmc' : 'ChardevSpiceChannel', + 'spiceport' : 'ChardevSpicePort' } } ## # @ChardevReturn: diff --git a/qemu-char.c b/qemu-char.c index 0fa1393..0d752dd 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2971,6 +2971,32 @@ static void qemu_chr_parse_pipe(QemuOpts *opts, ChardevBackend *backend, backend->pipe->device = g_strdup(device); } +static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend, + Error **errp) +{ + const char *name = qemu_opt_get(opts, "name"); + + if (name == NULL) { + error_setg(errp, "chardev: spice channel: no name given"); + return; + } + backend->spicevmc = g_new0(ChardevSpiceChannel, 1); + backend->spicevmc->type = g_strdup(name); +} + +static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend, + Error **errp) +{ + const char *name = qemu_opt_get(opts, "name"); + + if (name == NULL) { + error_setg(errp, "chardev: spice port: no name given"); + return; + } + backend->spiceport = g_new0(ChardevSpicePort, 1); + backend->spiceport->fqdn = g_strdup(name); +} + static const struct { const char *name; /* old, pre qapi */ @@ -3002,12 +3028,10 @@ static const struct { { .name = "pipe", .kind = CHARDEV_BACKEND_KIND_PIPE, .parse = qemu_chr_parse_pipe }, { .name = "braille", .kind = CHARDEV_BACKEND_KIND_BRAILLE }, -#ifdef CONFIG_SPICE - { .name = "spicevmc", .open = qemu_chr_open_spice }, -#if SPICE_SERVER_VERSION >= 0x000c02 - { .name = "spiceport", .open = qemu_chr_open_spice_port }, -#endif -#endif + { .name = "spicevmc", .kind = CHARDEV_BACKEND_KIND_SPICEVMC, + .parse = qemu_chr_parse_spice_vmc }, + { .name = "spiceport", .kind = CHARDEV_BACKEND_KIND_SPICEPORT, + .parse = qemu_chr_parse_spice_port }, }; CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts, @@ -3481,6 +3505,14 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, chr = qemu_chr_open_win_con(); break; #endif +#ifdef CONFIG_SPICE + case CHARDEV_BACKEND_KIND_SPICEVMC: + chr = qemu_chr_open_spice_vmc(backend->spicevmc->type); + break; + case CHARDEV_BACKEND_KIND_SPICEPORT: + chr = qemu_chr_open_spice_port(backend->spiceport->fqdn); + break; +#endif default: error_setg(errp, "unknown chardev backend (%d)", backend->kind); break; diff --git a/spice-qemu-char.c b/spice-qemu-char.c index a4d7de8..e5df195 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -217,16 +217,14 @@ static void print_allowed_subtypes(void) fprintf(stderr, "\n"); } -static CharDriverState *chr_open(QemuOpts *opts, const char *subtype) +static CharDriverState *chr_open(const char *subtype) { CharDriverState *chr; SpiceCharDriver *s; - uint32_t debug = qemu_opt_get_number(opts, "debug", 0); chr = g_malloc0(sizeof(CharDriverState)); s = g_malloc0(sizeof(SpiceCharDriver)); s->chr = chr; - s->debug = debug; s->active = false; s->sin.subtype = subtype; chr->opaque = s; @@ -240,35 +238,32 @@ static CharDriverState *chr_open(QemuOpts *opts, const char *subtype) return chr; } -CharDriverState *qemu_chr_open_spice(QemuOpts *opts) +CharDriverState *qemu_chr_open_spice_vmc(const char *type) { CharDriverState *chr; - const char *name = qemu_opt_get(opts, "name"); const char **psubtype = spice_server_char_device_recognized_subtypes(); - const char *subtype = NULL; - if (name == NULL) { + if (type == NULL) { fprintf(stderr, "spice-qemu-char: missing name parameter\n"); print_allowed_subtypes(); return NULL; } - for(;*psubtype != NULL; ++psubtype) { - if (strcmp(name, *psubtype) == 0) { - subtype = *psubtype; + for (; *psubtype != NULL; ++psubtype) { + if (strcmp(type, *psubtype) == 0) { break; } } - if (subtype == NULL) { - fprintf(stderr, "spice-qemu-char: unsupported name: %s\n", name); + if (*psubtype == NULL) { + fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type); print_allowed_subtypes(); return NULL; } - chr = chr_open(opts, subtype); + chr = chr_open(type); #if SPICE_SERVER_VERSION < 0x000901 /* See comment in vmc_state() */ - if (strcmp(subtype, "vdagent") == 0) { + if (strcmp(type, "vdagent") == 0) { qemu_chr_generic_open(chr); } #endif @@ -277,11 +272,10 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts) } #if SPICE_SERVER_VERSION >= 0x000c02 -CharDriverState *qemu_chr_open_spice_port(QemuOpts *opts) +CharDriverState *qemu_chr_open_spice_port(const char *name) { CharDriverState *chr; SpiceCharDriver *s; - const char *name = qemu_opt_get(opts, "name"); if (name == NULL) { fprintf(stderr, "spice-qemu-char: missing name parameter\n");