]> xenbits.xensource.com Git - libvirt.git/commitdiff
domain: Require <init> for container guests
authorCole Robinson <crobinso@redhat.com>
Thu, 12 May 2011 20:12:05 +0000 (16:12 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 13 May 2011 14:32:53 +0000 (10:32 -0400)
Use capabilities to allow a driver to register a default <init> if none
is specified in the XML. Openvz was already open-coding this to be /sbin/init

LXC currently falls over if no init is specified, so an explicit error is
an improvement IMO.

(Side note: I don't think we can set a default value for LXC. If we use
/sbin/init but the user doesn't specify a separate root FS for their guest,
the container will rerun the host's init which can be traumatic :). For
virt-install I'm thinking of defaulting to /sbin/init if a root FS has
been specified, otherwise require the user to manually specify <init>)

src/conf/capabilities.h
src/conf/domain_conf.c
src/openvz/openvz_conf.c
src/openvz/openvz_driver.c

index 96bf0a25c841171b364fa6bb47824ff48c6a9342..e2fa1d654071b107c46af1baadad7eff5d981beb 100644 (file)
@@ -150,6 +150,7 @@ struct _virCaps {
     int (*privateDataXMLFormat)(virBufferPtr, void *);
     int (*privateDataXMLParse)(xmlXPathContextPtr, void *);
     bool hasWideScsiBus;
+    const char *defaultInitPath;
 
     virDomainXMLNamespace ns;
 };
index 9ab9a5a498506283dfc77ea4d0afb1310549c996..f7e4959707114112373edde7389216a9e0ba1472 100644 (file)
@@ -5708,6 +5708,18 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     if (STREQ(def->os.type, "exe")) {
         def->os.init = virXPathString("string(./os/init[1])", ctxt);
+        if (!def->os.init) {
+            if (caps->defaultInitPath) {
+                def->os.init = strdup(caps->defaultInitPath);
+                if (!def->os.init) {
+                    goto no_memory;
+                }
+            } else {
+                virDomainReportError(VIR_ERR_XML_ERROR, "%s",
+                                     _("init binary must be specified"));
+                goto error;
+            }
+        }
     }
 
     if (STREQ(def->os.type, "xen") ||
index 88cd4c88ff1303b18cd70b046356dd4215cf2d3b..45bc398764dcd197a2ad7050dcfc0023db324466 100644 (file)
@@ -174,8 +174,10 @@ virCapsPtr openvzCapsInit(void)
                                       0,
                                       NULL) == NULL)
         goto no_memory;
-    return caps;
 
+    caps->defaultInitPath = "/sbin/init";
+
+    return caps;
 no_memory:
     virCapabilitiesFree(caps);
     return NULL;
index fbb8800e3650e3e296ce9853605609bdcee06710..3e1952fa1edf0f46a2e4daa05b9e012e3e5dfb87 100644 (file)
@@ -857,13 +857,6 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
                                          VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
-    if (vmdef->os.init == NULL) {
-        if (!(vmdef->os.init = strdup("/sbin/init"))) {
-            virReportOOMError();
-            goto cleanup;
-        }
-    }
-
     vm = virDomainFindByName(&driver->domains, vmdef->name);
     if (vm) {
         openvzError(VIR_ERR_OPERATION_FAILED,
@@ -943,13 +936,6 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
                                          VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
-    if (vmdef->os.init == NULL) {
-        if (!(vmdef->os.init = strdup("/sbin/init"))) {
-            virReportOOMError();
-            goto cleanup;
-        }
-    }
-
     vm = virDomainFindByName(&driver->domains, vmdef->name);
     if (vm) {
         openvzError(VIR_ERR_OPERATION_FAILED,