From patchwork Tue Mar 13 20:53:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 146486 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 DA394B6F62 for ; Wed, 14 Mar 2012 07:53:59 +1100 (EST) Received: from localhost ([::1]:55452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7YjF-0005kk-PV for incoming@patchwork.ozlabs.org; Tue, 13 Mar 2012 16:53:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Yj4-0005dx-7p for qemu-devel@nongnu.org; Tue, 13 Mar 2012 16:53:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7Yih-0001BK-Ao for qemu-devel@nongnu.org; Tue, 13 Mar 2012 16:53:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46776) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7Yih-0001B2-33 for qemu-devel@nongnu.org; Tue, 13 Mar 2012 16:53:23 -0400 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 q2DKrKuS006999 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 13 Mar 2012 16:53:21 -0400 Received: from blackpad.lan.raisama.net (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2DKrJRc007013; Tue, 13 Mar 2012 16:53:20 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 4D4B9200C54; Tue, 13 Mar 2012 17:53:26 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2012 17:53:25 -0300 Message-Id: <1331672005-30798-3-git-send-email-ehabkost@redhat.com> In-Reply-To: <1331672005-30798-1-git-send-email-ehabkost@redhat.com> References: <1331672005-30798-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Ronnie Sahlberg Subject: [Qemu-devel] [RFC PATCH 2/2] -readconfig: accept fd= option 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 Cc: Ronnie Sahlberg Signed-off-by: Eduardo Habkost --- qemu-config.c | 35 +++++++++++++++++++++++++++++++++-- qemu-options.hx | 6 +++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/qemu-config.c b/qemu-config.c index 6b7b28b..0a7f42c 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -828,6 +828,10 @@ static QemuOptsList qemu_readconfig_opts = { .name = "path", .type = QEMU_OPT_STRING, }, + { + .name = "fd", + .type = QEMU_OPT_NUMBER, + }, { /*End of list */ } }, }; @@ -863,17 +867,44 @@ int qemu_read_config_filename(const char *filename) return qemu_read_config_file(f, filename); } +/* Read Qemu config file from file descriptor + * + * Returns 0 on success, -errno on failure. + */ +static int qemu_read_config_fd(int fd) +{ + /* For the "" pseudo-filename, used only for error messages */ + char fname[16]; + FILE *f = fdopen(fd, "r"); + if (f == NULL) { + return -errno; + } + snprintf(fname, sizeof(fname), "", fd); + return qemu_read_config_file(f, fname); +} + /* Read Qemu config file based on parsed QemuOpts object * * Returns 0 on success, -errno on failure. */ static int qemu_read_config_opts(QemuOpts *opts) { + int fd = -1; + uint64_t fd_arg = qemu_opt_get_number(opts, "fd", (uint64_t)-1); const char *path = qemu_opt_get(opts, "path"); - if (!path) { + + if (fd_arg != (uint64_t)-1) { + fd = fd_arg; + } + + if (path) { + return qemu_read_config_filename(path); + } else if (fd >= 0) { + return qemu_read_config_fd(fd); + } else { + error_report("no fd or path set for config file"); return -EINVAL; } - return qemu_read_config_filename(path); } /* Read config file based on option arguments on 'arg' diff --git a/qemu-options.hx b/qemu-options.hx index caa4fe1..86a5826 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2655,11 +2655,11 @@ Old param mode (ARM only). ETEXI DEF("readconfig", HAS_ARG, QEMU_OPTION_readconfig, - "-readconfig [path=]\n", QEMU_ARCH_ALL) + "-readconfig [path=]|fd=\n", QEMU_ARCH_ALL) STEXI -@item -readconfig [type=]@var{file} +@item -readconfig [path=]@var{file}|fd=@var{fd} @findex -readconfig -Read device configuration from @var{file}. +Read device configuration from @var{file}, or from file descriptor @var{fd}. ETEXI DEF("writeconfig", HAS_ARG, QEMU_OPTION_writeconfig, "-writeconfig \n"