From patchwork Wed Feb 15 10:14:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Otubo X-Patchwork-Id: 9573821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A91E160209 for ; Wed, 15 Feb 2017 10:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 971542843F for ; Wed, 15 Feb 2017 10:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C03428473; Wed, 15 Feb 2017 10:48:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1E0ED2843F for ; Wed, 15 Feb 2017 10:48:12 +0000 (UTC) Received: from localhost ([::1]:39609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdx86-0005XE-0m for patchwork-qemu-devel@patchwork.kernel.org; Wed, 15 Feb 2017 05:48:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdwbm-0007Dz-Oe for qemu-devel@nongnu.org; Wed, 15 Feb 2017 05:14:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdwbj-0004wm-MA for qemu-devel@nongnu.org; Wed, 15 Feb 2017 05:14:46 -0500 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]:36823) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cdwbj-0004vX-FO for qemu-devel@nongnu.org; Wed, 15 Feb 2017 05:14:43 -0500 Received: by mail-wm0-x231.google.com with SMTP id c85so37896068wmi.1 for ; Wed, 15 Feb 2017 02:14:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4fASzf+04BxeDmdvzThDG6WMxEoXKkaOrOsvTE/eg8w=; b=PschTiFg0J6DZ/mCkJsi6mr5mETtXo7X9YKEBL2re7Tp1EkUVQA9P7e7jQl74GTNnY wmcDiOnSBhFgXQzwZmWVdc10B22yzZZQPw25XUjKHk3n4+Ml7Nvd3b9HgWT8WpAha5BA JZcLsl1QU4xkUzYC/SxsR2VpOrCE4+OUemWzIU2lsuUZr9e30lP1bJs5HXEebyMw0zPU 7HJ+pr8lz7X96m/b9u1i9DquMKCr1/X2LPpoixWyJMD26/0FwbLufdt4mUuDwWBCYfKU 1VGzZ+awd/o0W2CrmZSPi7vbg+CdZ2R7lBrKDU17xkQJx5o/JV/kxVbCY29IHhcW5gSg 5y6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4fASzf+04BxeDmdvzThDG6WMxEoXKkaOrOsvTE/eg8w=; b=dkNxBAfo4xm9T6fEodfMV3Z0wgJG1W+li4JIh322pdT7QnTaiRo+NsC6PGScXt5xqC PckU3HVLMoAP4c6Neymh8wPbgoGgTuh6SHb0S+6jggSmu32HZQJfLYNZX3L62i+sXS3J x9brI4Y2MUg0HRSQropCPB6Jrvtw56cocK7jMXw7z1ck7E2dkYTlbO/iBbsmbjljS1Vj zJfBTvTSxFl90K+fdUY3OMHqOy0t2vCw6as0Jjr/tTykeqPhkBMeFKVJgW++CheUemV2 HUo3LJ1Bszu9j7fQlWfvK6iyWdrf8RoZpcs4Mmjvw6secgyHoR5vWSHPIJdRDJ1/EfZ9 9trg== X-Gm-Message-State: AMke39k1vuKWByz1iSQXelvGJDNaL8WaF2lQ+E/Mjbq8r3mXQ1gatm+t0zgJq10wERoeDgZk X-Received: by 10.28.217.136 with SMTP id q130mr7502525wmg.13.1487153681025; Wed, 15 Feb 2017 02:14:41 -0800 (PST) Received: from vader.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id c133sm4723867wmd.13.2017.02.15.02.14.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Feb 2017 02:14:40 -0800 (PST) From: Eduardo Otubo To: qemu-devel@nongnu.org Date: Wed, 15 Feb 2017 11:14:26 +0100 Message-Id: <20170215101427.23736-2-eduardo.otubo@profitbricks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170215101427.23736-1-eduardo.otubo@profitbricks.com> References: <20170215101427.23736-1-eduardo.otubo@profitbricks.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::231 Subject: [Qemu-devel] [PATCH 1/2] qmp/hmp: add writeconfig X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dgilbert@redhat.com, Eduardo Otubo , armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for the command `writeconfig' on the QMP and HMP consoles. This is a simple way to keep track of current state of VM after series of hotplugs and/or hotunplugs of different devices: (qemu) writeconfig qemu.conf Signed-off-by: Eduardo Otubo --- hmp-commands.hx | 14 ++++++++++++++ hmp.c | 9 +++++++++ hmp.h | 1 + qapi-schema.json | 20 ++++++++++++++++++++ ui/console.c | 14 ++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index 88192817b2..ac562192bb 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -252,6 +252,20 @@ Password: ******** ETEXI { + .name = "writeconfig", + .args_type = "filename:F", + .params = "filename", + .help = "write config file", + .cmd = hmp_writeconfig, + }, + +STEXI +@item writeconfig @var{filename} +@findex writeconfig +Write config file @var{filename}. +ETEXI + + { .name = "screendump", .args_type = "filename:F", .params = "filename", diff --git a/hmp.c b/hmp.c index 2bc4f062bb..4f2b8a10d2 100644 --- a/hmp.c +++ b/hmp.c @@ -1913,6 +1913,15 @@ err_out: goto out; } +void hmp_writeconfig(Monitor *mon, const QDict *qdict) +{ + const char *filename = qdict_get_str(qdict, "filename"); + Error *err = NULL; + + qmp_writeconfig(filename, &err); + hmp_handle_error(mon, &err); +} + void hmp_screendump(Monitor *mon, const QDict *qdict) { const char *filename = qdict_get_str(qdict, "filename"); diff --git a/hmp.h b/hmp.h index 05daf7cd5c..63d44fe50f 100644 --- a/hmp.h +++ b/hmp.h @@ -94,6 +94,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict); void hmp_closefd(Monitor *mon, const QDict *qdict); void hmp_sendkey(Monitor *mon, const QDict *qdict); void hmp_screendump(Monitor *mon, const QDict *qdict); +void hmp_writeconfig(Monitor *mon, const QDict *qdict); void hmp_nbd_server_start(Monitor *mon, const QDict *qdict); void hmp_nbd_server_add(Monitor *mon, const QDict *qdict); void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict); diff --git a/qapi-schema.json b/qapi-schema.json index 5edb08d621..c19b1ff3df 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4696,6 +4696,26 @@ 'data': { 'keys': ['KeyValue'], '*hold-time': 'int' } } ## +# @writeconfig: +# +# Write config to file. +# +# @filename: the path of a new file to store the current config +# +# Returns: Nothing on success +# +# Since: 2.7.0 +# +# Example: +# +# -> { "execute": "writeconfig", +# "arguments": { "filename": "/tmp/qemu.conf" } } +# <- { "return": {} } +# +## +{ 'command': 'writeconfig', 'data': {'filename': 'str'} } + +## # @screendump: # # Write a PPM of the VGA screen to a file. diff --git a/ui/console.c b/ui/console.c index 49d0740b40..d2e3d753a8 100644 --- a/ui/console.c +++ b/ui/console.c @@ -30,6 +30,7 @@ #include "sysemu/char.h" #include "trace.h" #include "exec/memory.h" +#include "qemu/config-file.h" #define DEFAULT_BACKSCROLL 512 #define CONSOLE_CURSOR_PERIOD 500 @@ -342,6 +343,19 @@ write_err: goto out; } +void qmp_writeconfig(const char *filename, Error **errp) +{ + if (filename == NULL) { + error_setg(errp, "You must specify a filename."); + return; + } + + FILE *fp; + fp = fopen(filename, "w"); + qemu_config_write(fp); + fclose(fp); +} + void qmp_screendump(const char *filename, Error **errp) { QemuConsole *con = qemu_console_lookup_by_index(0);