[PATCHv3 24/27] virCaps: get rid of "defaultInitPath" value in the virCaps struct

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

 



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   |  1 -
 src/openvz/openvz_driver.c | 27 ++++++++++++++++++++++++++-
 4 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index a70896a..43ace12 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -168,7 +168,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 ce65eac..45558e2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2481,6 +2481,22 @@ virDomainDefAdjustInternal(virDomainDefPtr def ATTRIBUTE_UNUSED,
 }


+/* 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,
@@ -2556,6 +2572,9 @@ virDomainDefAdjust(virDomainXMLConfPtr xmlconf,
             return ret;
     }

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

@@ -10212,18 +10231,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 e3e64e5..05c6113 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -206,7 +206,6 @@ virCapsPtr openvzCapsInit(void)
                                       NULL) == NULL)
         goto no_memory;

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

     return caps;
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index a6f4c66..ef736f3 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -97,6 +97,29 @@ static void cmdExecFree(const char *cmdExec[])
     }
 }

+
+static int
+openvzDomainDefAdjust(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;
+}
+
+
+virDomainDefAdjustCallbacks openvzDomainDefAdjustCallbacks = {
+        .domainBeforeDevices = openvzDomainDefAdjust,
+};
+
+
 /* generate arguments to create OpenVZ container
    return -1 - error
            0 - OK
@@ -1453,7 +1476,9 @@ static virDrvOpenStatus openvzOpen(virConnectPtr conn,
     if (!(driver->caps = openvzCapsInit()))
         goto cleanup;

-    if (!(driver->xmlconf = virDomainXMLConfNew(NULL, NULL, NULL)))
+    if (!(driver->xmlconf = virDomainXMLConfNew(NULL,
+                                                &openvzDomainDefAdjustCallbacks,
+                                                NULL)))
         goto cleanup;

     if (openvzLoadDomains(driver) < 0)
-- 
1.8.1.5

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