]> xenbits.xensource.com Git - libvirt.git/commitdiff
Allow passing of command line args to LXC container
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 3 Oct 2011 17:37:47 +0000 (18:37 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 4 Oct 2011 13:15:09 +0000 (14:15 +0100)
When booting a virtual machine with a kernel/initrd it is possible
to pass command line arguments using the <cmdline>...args...</cmdline>
element in the guest XML. These appear to the kernel / init process
in /proc/cmdline.

When booting a container we do not have a custom /proc/cmdline,
but we can easily set an environment variable for it. Ideally
we could pass individual arguments to the init process as a
regular set of 'char *argv[]' parameters, but that would involve
libvirt parsing the <cmdline> XML text. This can easily be added
later, even if we add the env variable now

* docs/drvlxc.html.in: Document env variables passed to LXC
* src/conf/domain_conf.c: Add <cmdline> to be parsed for
  guests of type='exe'
* src/lxc/lxc_container.c: Set LIBVIRT_LXC_CMDLINE env var

docs/drvlxc.html.in
src/conf/domain_conf.c
src/lxc/lxc_container.c

index 5ce218d92a75fa4af55375dc93252a50d2a92a54..47837d1a899ae883cfd08ec6d6f12a786680902e 100644 (file)
@@ -39,6 +39,23 @@ driver. On such kernels, it may be neccessary to unmount the blkio controller.
 </p>
 
 
+<h2>Environment setup for the container init</h2>
+
+<p>
+When the container "init" process is started, it will be given several useful
+environment variables.
+</p>
+
+<dl>
+<dt>LIBVIRT_LXC_NAME</dt>
+<dd>The name assigned to the container by libvirt</dd>
+<dt>LIBVIRT_LXC_UUID</dt>
+<dd>The UUID assigned to the container by libvirt</dd>
+<dt>LIBVIRT_LXC_CMDLINE</dt>
+<dd>The unparsed command line arguments specified in the container configuration</dd>
+</dl>
+
+
 <h3>Example config version 1</h3>
 <p></p>
 <pre>
index ab1249b704eb82d9383bfbb275b3f48de914f002..f9007ce5a9b678aaffcf2cd36d61eb8200a2ac66 100644 (file)
@@ -6834,6 +6834,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
                 goto error;
             }
         }
+        def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
     }
 
     if (STREQ(def->os.type, "xen") ||
index 787df9a3f6a00861045ab9c16e0e6c39bf075424..69cea8e4df1863c96eb1d10631447d0a1651b5d9 100644 (file)
@@ -116,6 +116,8 @@ static virCommandPtr lxcContainerBuildInitCmd(virDomainDefPtr vmDef)
     virCommandAddEnvString(cmd, "TERM=linux");
     virCommandAddEnvPair(cmd, "LIBVIRT_LXC_UUID", uuidstr);
     virCommandAddEnvPair(cmd, "LIBVIRT_LXC_NAME", vmDef->name);
+    if (vmDef->os.cmdline)
+        virCommandAddEnvPair(cmd, "LIBVIRT_LXC_CMDLINE", vmDef->os.cmdline);
 
     return cmd;
 }