From patchwork Mon Mar 19 14:54:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 147540 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 1C00EB6EE7 for ; Tue, 20 Mar 2012 01:55:23 +1100 (EST) Received: from localhost ([::1]:53776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9dzV-0001e0-1D for incoming@patchwork.ozlabs.org; Mon, 19 Mar 2012 10:55:21 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9dzN-0001V6-4F for qemu-devel@nongnu.org; Mon, 19 Mar 2012 10:55:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9dyw-0006Bf-U5 for qemu-devel@nongnu.org; Mon, 19 Mar 2012 10:55:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35312) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9dyw-0006BC-MS for qemu-devel@nongnu.org; Mon, 19 Mar 2012 10:54:46 -0400 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 q2JEsiDD027590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 19 Mar 2012 10:54:44 -0400 Received: from blackpad.lan.raisama.net (ovpn-116-25.ams2.redhat.com [10.36.116.25]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q2JEsgg7005442; Mon, 19 Mar 2012 10:54:43 -0400 Received: by blackpad.lan.raisama.net (Postfix, from userid 500) id 165AA201ED9; Mon, 19 Mar 2012 11:54:44 -0300 (BRT) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2012 11:54:43 -0300 Message-Id: <1332168883-9961-4-git-send-email-ehabkost@redhat.com> In-Reply-To: <1332168883-9961-1-git-send-email-ehabkost@redhat.com> References: <1332168883-9961-1-git-send-email-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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] [PATCH 3/3] -readconfig: accept fd= option (v2) 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 Chhanges v1 -> v2: - Moved code to qemu-config-arch.c Cc: Ronnie Sahlberg Signed-off-by: Eduardo Habkost --- qemu-config-arch.c | 21 +++++++++++++++++++-- qemu-config.c | 16 ++++++++++++++++ qemu-config.h | 4 ++++ qemu-options.hx | 6 +++--- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/qemu-config-arch.c b/qemu-config-arch.c index 9180b73..ee5d515 100644 --- a/qemu-config-arch.c +++ b/qemu-config-arch.c @@ -23,6 +23,7 @@ */ #include "qemu-config-arch.h" #include "qemu-option.h" +#include "qemu-error.h" /* Not on vm_config_groups because this is not a global option setable by -set * (QEMU_OPTION_set), just settings used to parse -readconfig argument. @@ -36,21 +37,37 @@ static QemuOptsList qemu_readconfig_opts = { .name = "path", .type = QEMU_OPT_STRING, }, + { + .name = "fd", + .type = QEMU_OPT_NUMBER, + }, { /*End of list */ } }, }; + /* 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-config.c b/qemu-config.c index a2c8453..750626d 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -846,3 +846,19 @@ 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. + */ +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); +} diff --git a/qemu-config.h b/qemu-config.h index c2ab4fc..28356a6 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -20,4 +20,8 @@ int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname); */ int qemu_read_config_filename(const char *filename); +/* Read config from file descriptor + */ +int qemu_read_config_fd(int fd); + #endif /* QEMU_CONFIG_H */ diff --git a/qemu-options.hx b/qemu-options.hx index 5d14f92..ae64ca8 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"