@@ -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;
}
@@ -14,6 +14,9 @@
/* vl.c */
+extern char *guestenv;
+extern int guestenv_len;
+
extern const char *bios_name;
extern const char *qemu_name;
@@ -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)
@@ -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;
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 <line>" 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 <somlo@cmu.edu> --- hw/i386/pc.c | 4 ++++ include/sysemu/sysemu.h | 3 +++ qemu-options.hx | 9 +++++++++ vl.c | 14 ++++++++++++++ 4 files changed, 30 insertions(+)