From patchwork Tue Feb 24 19:43:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 443116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C8CD314012E for ; Wed, 25 Feb 2015 06:45:01 +1100 (AEDT) Received: from localhost ([::1]:51065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQLPg-0005Qs-3q for incoming@patchwork.ozlabs.org; Tue, 24 Feb 2015 14:45:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQLO5-0002UO-HD for qemu-devel@nongnu.org; Tue, 24 Feb 2015 14:43:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQLO1-0005G7-G1 for qemu-devel@nongnu.org; Tue, 24 Feb 2015 14:43:21 -0500 Received: from mail-qa0-x229.google.com ([2607:f8b0:400d:c00::229]:59471) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQLO1-0005Fm-Cf for qemu-devel@nongnu.org; Tue, 24 Feb 2015 14:43:17 -0500 Received: by mail-qa0-f41.google.com with SMTP id x12so28844389qac.0 for ; Tue, 24 Feb 2015 11:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D4oAQeSUKlCRHgp5vVA8Lhf2eSf4VkbEh51r29+0H+E=; b=f8eSYlYz7A8bH4P6H3PBI3Rg1PrW5yKGOwRwtzEEJJrYGtOEArX3RXeeTx+fvXLREl dkGpw5liU8YrbDVGgVgta+mttdnXkhcGrxBOQv4m1RjibnWVMoQnZyXPDB3sUJjeifPf fTtEuGmZQK4nLhd9I21aYr8PMTcO1hHwHsKK+3mbcBukWA7ArN+5G1ClYK7B8G4bd93z 7QBZ5SsyuqjtGVSoytbkeElHyckmHxbwjmafpqftgg501U9/TpN9CYieWwMQO8c6gSkN nyL0smOCZ7K0rHP/2mXoEQ6bwg4cR8iHtv4BeLTDjRN/+HWoamGA4UFlEpmMDKUEwuEo S3UA== X-Received: by 10.140.107.75 with SMTP id g69mr37919299qgf.103.1424806995941; Tue, 24 Feb 2015 11:43:15 -0800 (PST) Received: from HEDWIG.ini.cmu.edu (HEDWIG.INI.CMU.EDU. [128.2.16.51]) by mx.google.com with ESMTPSA id j2sm10121193qao.42.2015.02.24.11.43.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Feb 2015 11:43:15 -0800 (PST) From: "Gabriel L. Somlo" X-Google-Original-From: "Gabriel L. Somlo" To: qemu-devel@nongnu.org Date: Tue, 24 Feb 2015 14:43:06 -0500 Message-Id: <1424806987-24790-2-git-send-email-somlo@cmu.edu> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1424806987-24790-1-git-send-email-somlo@cmu.edu> References: <1424806987-24790-1-git-send-email-somlo@cmu.edu> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c00::229 Cc: mdroth@linux.vnet.ibm.com, lersek@redhat.com, rjones@redhat.com Subject: [Qemu-devel] [RFC PATCH 1/2] fw_cfg: Add -guestenv qemu command line 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 Introduce "-guestenv" command line option, which allows passing of environment variables to the guest in a "fire-and-forget", asynchronous way. The guest may retrieve this data at its convenience, by accessing the provided fw_cfg device from the inside. The new "etc/guestenv" blob will be a set of concatenated null-terminated ascii strings: "key1=val1\0key2=val2\0...\0keyN=valN\0", each string being added by its own separate "-guestenv " command line argument to qemu. I'm currently not checking for the presence of an '=' character in each entry, nor am I currently checking for duplicate keys. Right now, I'm only inserting the new fw_cfg file from i386/pc.c, since this is a proof-of-concept/RFC, but this should work easily on any platform on which fw_cfg is supported. Signed-off-by: Gabriel Somlo --- hw/i386/pc.c | 4 ++++ include/sysemu/sysemu.h | 3 +++ qemu-options.hx | 9 +++++++++ vl.c | 14 ++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index c7af6aa..4133b21 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -715,6 +715,10 @@ static FWCfgState *bochs_bios_init(void) (1 + apic_id_limit + nb_numa_nodes) * sizeof(*numa_fw_cfg)); + if (guestenv) { + fw_cfg_add_file(fw_cfg, "etc/guestenv", guestenv, guestenv_len); + } + return fw_cfg; } diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 748d059..fd00266 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -14,6 +14,9 @@ /* vl.c */ +extern char *guestenv; +extern int guestenv_len; + extern const char *bios_name; extern const char *qemu_name; diff --git a/qemu-options.hx b/qemu-options.hx index ee4b223..b9d5565 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2646,6 +2646,15 @@ STEXI @table @option ETEXI +DEF("guestenv", HAS_ARG, QEMU_OPTION_guestenv, \ + "-guestenv entry add 'entry' to environment passed to guest\n", + QEMU_ARCH_ALL) +STEXI +@item -guestenv @var{entry} +@findex -guestenv +Add @var{entry} to environment passed to guest +ETEXI + DEF("serial", HAS_ARG, QEMU_OPTION_serial, \ "-serial dev redirect the serial port to char device 'dev'\n", QEMU_ARCH_ALL) diff --git a/vl.c b/vl.c index 8c8f142..a94dcb5 100644 --- a/vl.c +++ b/vl.c @@ -187,6 +187,9 @@ int nb_numa_nodes; int max_numa_nodeid; NodeInfo numa_info[MAX_NODES]; +char *guestenv; +int guestenv_len; + /* The bytes in qemu_uuid[] are in the order specified by RFC4122, _not_ in the * little-endian "wire format" described in the SMBIOS 2.6 specification. */ @@ -2249,6 +2252,14 @@ struct device_config { static QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs); +static void add_guestenv_entry(const char *entry) +{ + int entry_len = strlen(entry) + 1; + guestenv = g_realloc(guestenv, guestenv_len + entry_len); + strcpy(guestenv + guestenv_len, entry); + guestenv_len += entry_len; +} + static void add_device_config(int type, const char *cmdline) { struct device_config *conf; @@ -3320,6 +3331,9 @@ int main(int argc, char **argv, char **envp) qemu_opt_set(device, "mount_tag", "v_synth"); break; } + case QEMU_OPTION_guestenv: + add_guestenv_entry(optarg); + break; case QEMU_OPTION_serial: add_device_config(DEV_SERIAL, optarg); default_serial = 0;