From patchwork Wed Dec 19 15:59:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 207449 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 C3BE22C0082 for ; Thu, 20 Dec 2012 03:13:34 +1100 (EST) Received: from localhost ([::1]:45099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlM3n-0001lg-2g for incoming@patchwork.ozlabs.org; Wed, 19 Dec 2012 10:59:55 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlM3D-0000JG-Fk 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 1TlM35-0007zP-Hu for qemu-devel@nongnu.org; Wed, 19 Dec 2012 10:59:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23058) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TlM35-0007z1-A4 for qemu-devel@nongnu.org; Wed, 19 Dec 2012 10:59:11 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBJFxAlI002802 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 19 Dec 2012 10:59:10 -0500 Received: from rincewind.home.kraxel.org (ovpn-116-48.ams2.redhat.com [10.36.116.48]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBJFx8Wm026608; Wed, 19 Dec 2012 10:59:09 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 7B3694140A; Wed, 19 Dec 2012 16:59:07 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 19 Dec 2012 16:59:02 +0100 Message-Id: <1355932747-1755-5-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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, Gerd Hoffmann , mprivozn@redhat.com Subject: [Qemu-devel] [PATCH 4/9] chardev: hotplug, qmp, null 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 Signed-off-by: Gerd Hoffmann --- qapi-schema.json | 32 ++++++++++++++++++++++++++++++++ qemu-char.c | 34 ++++++++++++++++++++++++++++++++++ qmp-commands.hx | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 0 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 5dfa052..e3f0d44 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3017,3 +3017,35 @@ # Since: 1.3.0 ## { 'command': 'nbd-server-stop' } + +## +# @chardev-add: +# +# Add a file chardev +# +# @id: the chardev's ID, must be unique +# @backend: backend type and parameters +# +# Returns: Nothing on success +# +# Since: 1.4 +## +{ 'type': 'ChardevDummy', 'data': { } } + +{ 'union': 'ChardevBackend', 'data': { 'null' : 'ChardevDummy' } } + +{ 'command': 'chardev-add', 'data': {'id' : 'str', + 'backend' : 'ChardevBackend' } } + +## +# @chardev-remove: +# +# Remove a chardev +# +# @id: the chardev's ID, must exist and not be in use +# +# Returns: Nothing on success +# +# Since: 1.4 +## +{ 'command': 'chardev-remove', 'data': {'id': 'str'} } diff --git a/qemu-char.c b/qemu-char.c index 208c525..d2f0852 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2925,3 +2925,37 @@ CharDriverState *qemu_char_get_next_serial(void) return serial_hds[next_serial++]; } +void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp) +{ + CharDriverState *chr; + + switch (backend->kind) { + case CHARDEV_BACKEND_KIND_NULL: + chr = qemu_chr_open_null(NULL); + break; + default: + error_setg(errp, "unknown chardev backend (%d)", backend->kind); + return; + } + + if (chr == NULL) { + error_setg(errp, "Failed to create chardev"); + } +} + +void qmp_chardev_remove(const char *id, Error **errp) +{ + CharDriverState *chr; + + chr = qemu_chr_find(id); + if (NULL == chr) { + error_setg(errp, "Chardev '%s' not found", id); + return; + } + if (chr->chr_can_read || chr->chr_read || + chr->chr_event || chr->handler_opaque) { + error_setg(errp, "Chardev '%s' is busy", id); + return; + } + qemu_chr_delete(chr); +} diff --git a/qmp-commands.hx b/qmp-commands.hx index 5c692d0..10408e9 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -2654,3 +2654,53 @@ EQMP .args_type = "", .mhandler.cmd_new = qmp_marshal_input_query_target, }, + + { + .name = "chardev-add", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_add, + }, + +SQMP +chardev-add +---------------- + +Add a chardev. + +Arguments: + +- "id": the chardev's ID, must be unique (json-string) +- "backend": chardev backend type + parameters + +Example: + +-> { "execute" : "chardev-add", + "arguments" : { "id" : "foo", + FIXME } } +<- { "return": {} } + +EQMP + + { + .name = "chardev-remove", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_chardev_remove, + }, + + +SQMP +chardev-remove +-------------- + +Remove a chardev. + +Arguments: + +- "id": the chardev's ID, must exist and not be in use (json-string) + +Example: + +-> { "execute": "chardev-remove", "arguments": { "id" : "foo" } } +<- { "return": {} } + +EQMP