[PATCH] domain: Require <init> for container guests

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

 



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

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/conf/capabilities.h    |    1 +
 src/conf/domain_conf.c     |   12 ++++++++++++
 src/openvz/openvz_conf.c   |    4 +++-
 src/openvz/openvz_driver.c |   14 --------------
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 96bf0a2..e2fa1d6 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -150,6 +150,7 @@ struct _virCaps {
     int (*privateDataXMLFormat)(virBufferPtr, void *);
     int (*privateDataXMLParse)(xmlXPathContextPtr, void *);
     bool hasWideScsiBus;
+    const char *defaultInitPath;
 
     virDomainXMLNamespace ns;
 };
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9ab9a5a..f7e4959 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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") ||
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 88cd4c8..45bc398 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -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;
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 60f2dc2..6af4f75 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -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,
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]