]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virCaps: get rid of "defaultInitPath" value in the virCaps struct
authorPeter Krempa <pkrempa@redhat.com>
Wed, 6 Mar 2013 14:48:06 +0000 (15:48 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 4 Apr 2013 20:42:37 +0000 (22:42 +0200)
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
src/conf/domain_conf.c
src/openvz/openvz_conf.c
src/openvz/openvz_driver.c

index 8abe88a9bf3d145625e22bfa85ffe6dd6f0198a7..064da80632d53549e32389891f68da003b963f9f 100644 (file)
@@ -168,7 +168,6 @@ struct _virCaps {
     int defaultDiskDriverType; /* enum virStorageFileFormat */
     int (*defaultConsoleTargetType)(const char *ostype, virArch guestarch);
     bool hasWideScsiBus;
-    const char *defaultInitPath;
 };
 
 
index 03c6c7c4c3f9dcd7e467a82e632439e1f22e9c87..c21c687278dad2bb20faa0e4b0ade7eaae345bae 100644 (file)
@@ -2479,6 +2479,21 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def,
 }
 
 
+static int
+virDomainDefPostParseInternal(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
 virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
                             virDomainDefPtr def,
@@ -2542,6 +2557,10 @@ virDomainDefPostParse(virDomainDefPtr def,
                                           &data)) < 0)
         return ret;
 
+
+    if ((ret = virDomainDefPostParseInternal(def, caps)) < 0)
+        return ret;
+
     return 0;
 }
 
@@ -10333,18 +10352,6 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     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) {
index 3b0731bb58e35a8600d3040cb98d8895ed56c7ac..439e457cdcb158108300c8b9db6f539716d2fc11 100644 (file)
@@ -206,7 +206,6 @@ virCapsPtr openvzCapsInit(void)
                                       NULL) == NULL)
         goto no_memory;
 
-    caps->defaultInitPath = "/sbin/init";
     caps->defaultConsoleTargetType = openvzDefaultConsoleType;
 
     return caps;
index 9b1919a148914dc6243caaf4ebf2e978c40ba9fa..583a4157c56e34e4612148a302bae3b236a31e91 100644 (file)
@@ -97,6 +97,29 @@ static void cmdExecFree(const char *cmdExec[])
     }
 }
 
+
+static int
+openvzDomainDefPostParse(virDomainDefPtr def,
+                         virCapsPtr caps ATTRIBUTE_UNUSED,
+                         void *opaque 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;
+}
+
+
+virDomainDefParserConfig openvzDomainDefParserConfig = {
+        .domainPostParseCallback = openvzDomainDefPostParse,
+};
+
+
 /* generate arguments to create OpenVZ container
    return -1 - error
            0 - OK
@@ -1453,7 +1476,8 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn,
     if (!(driver->caps = openvzCapsInit()))
         goto cleanup;
 
-    if (!(driver->xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL)))
+    if (!(driver->xmlopt = virDomainXMLOptionNew(&openvzDomainDefParserConfig,
+                                                 NULL, NULL)))
         goto cleanup;
 
     if (openvzLoadDomains(driver) < 0)