[libvirt] [PATCHv2 21/21] virCaps: get rid of "defaultInitPath" value in the virCaps struct

Peter Krempa pkrempa at redhat.com
Wed Mar 6 15:38:05 UTC 2013


This gets rid of the parameter in favor of using the new callback
infrastructure to do the same stuff.

This patch implements the domain adjustment callback in the openVZ
driver and moves the check from the parser to a new validation method in
the callback infrastructure.
---
 src/conf/capabilities.h  |  1 -
 src/conf/domain_conf.c   | 31 +++++++++++++++++++------------
 src/openvz/openvz_conf.c | 23 +++++++++++++++++++++--
 3 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index bf64296..3ce0afc 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -167,7 +167,6 @@ struct _virCaps {
     int defaultDiskDriverType; /* enum virStorageFileFormat */
     int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch);
     bool hasWideScsiBus;
-    const char *defaultInitPath;
 };


diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d68e30a..4efdc0b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2479,6 +2479,22 @@ virDomainDefAdjustInternal(virDomainDefPtr def,
 }


+/* this is a place for global assumption checks */
+static int
+virDomainDefVerifyInternal(virDomainDefPtr def,
+                           virCapsPtr caps ATTRIBUTE_UNUSED)
+{
+    /* verify init path for container based domains */
+    if (STREQ(def->os.type, "exe") && !def->os.init) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("init binary must be specified"));
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virDomainDeviceDefAdjust(virDomainXMLConfPtr xmlconf,
                          virDomainDeviceDefPtr dev,
@@ -2551,6 +2567,9 @@ virDomainDefAdjust(virDomainXMLConfPtr xmlconf,
             return ret;
     }

+    if ((ret = virDomainDefVerifyInternal(def, caps)) < 0)
+        return ret;
+
     return 0;
 }

@@ -10200,18 +10219,6 @@ 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 {
-                virReportError(VIR_ERR_XML_ERROR, "%s",
-                               _("init binary must be specified"));
-                goto error;
-            }
-        }
         def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);

         if ((n = virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0) {
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 4e8a7cd..6aaec3f 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -175,10 +175,30 @@ static int openvzDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED,
 }


+static int
+openvzDomainDefAdjust(virDomainDefPtr def,
+                      virCapsPtr caps ATTRIBUTE_UNUSED)
+{
+    /* fill the init path */
+    if (STREQ(def->os.type, "exe") && !def->os.init) {
+        if (!(def->os.init = strdup("/sbin/init" ))) {
+            virReportOOMError();
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 virDomainXMLConfPtr
 openvzDomainXMLConfInit(void)
 {
-    return virDomainXMLConfNew(NULL, NULL, NULL);
+    virDomainDefAdjustCallbacks adjust = {
+        .domainBeforeDevices = openvzDomainDefAdjust,
+    };
+
+    return virDomainXMLConfNew(NULL, &adjust , NULL);
 }


@@ -213,7 +233,6 @@ virCapsPtr openvzCapsInit(void)
                                       NULL) == NULL)
         goto no_memory;

-    caps->defaultInitPath = "/sbin/init";
     caps->defaultConsoleTargetType = openvzDefaultConsoleType;

     return caps;
-- 
1.8.1.1




More information about the libvir-list mailing list