From mboxrd@z Thu Jan 1 00:00:00 1970 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) From: "Gabriel L. Somlo" Date: Tue, 24 Feb 2015 14:43:06 -0500 Message-Id: <1424806987-24790-2-git-send-email-somlo@cmu.edu> In-Reply-To: <1424806987-24790-1-git-send-email-somlo@cmu.edu> References: <1424806987-24790-1-git-send-email-somlo@cmu.edu> Subject: [Qemu-devel] [RFC PATCH 1/2] fw_cfg: Add -guestenv qemu command line option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mdroth@linux.vnet.ibm.com, lersek@redhat.com, rjones@redhat.com 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; -- 2.1.0