qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 1/2] fw_cfg: Add -guestenv qemu command line opt


From: Gabriel L. Somlo
Subject: [Qemu-devel] [RFC PATCH 1/2] fw_cfg: Add -guestenv qemu command line option
Date: Tue, 24 Feb 2015 14:43:06 -0500

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 <address@hidden>
---
 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
address@hidden -guestenv @var{entry}
address@hidden -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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]