qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Gabriel L. Somlo" <gsomlo@gmail.com>
To: qemu-devel@nongnu.org
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
Date: Tue, 24 Feb 2015 14:43:06 -0500	[thread overview]
Message-ID: <1424806987-24790-2-git-send-email-somlo@cmu.edu> (raw)
In-Reply-To: <1424806987-24790-1-git-send-email-somlo@cmu.edu>

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(+)

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

  reply	other threads:[~2015-02-24 19:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-24 19:43 [Qemu-devel] [RFC PATCH 0/2] host->guest environment variables via fw_cfg Gabriel L. Somlo
2015-02-24 19:43 ` Gabriel L. Somlo [this message]
2015-02-24 19:43 ` [Qemu-devel] [RFC PATCH 2/2] qga: add --getenv option to get env. vars from fw_cfg Gabriel L. Somlo
2015-02-25  9:09   ` Daniel P. Berrange
2015-02-24 23:07 ` [Qemu-devel] [RFC PATCH 0/2] host->guest environment variables via fw_cfg Laszlo Ersek
2015-02-25 22:40   ` Matt Fleming
2015-02-26  1:13     ` Gabriel L. Somlo
2015-02-26  9:45       ` Laszlo Ersek
2015-02-26 10:55         ` Matt Fleming
2015-02-26 11:13         ` Richard W.M. Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424806987-24790-2-git-send-email-somlo@cmu.edu \
    --to=gsomlo@gmail.com \
    --cc=lersek@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).