Re: [libvirt] PATCH 2/4: implement getVersion method for openvz

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

 



This patch implements the getVersion driver method for openvz to report
the version number of vzctl. This is needed in the next patch to determine
if we have builtin support for bridges


Daniel

diff -r 524f426a413d src/openvz_conf.c
--- a/src/openvz_conf.c	Tue Oct 14 14:41:47 2008 +0100
+++ b/src/openvz_conf.c	Tue Oct 14 15:09:10 2008 +0100
@@ -41,6 +41,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/utsname.h>
+#include <sys/wait.h>
 
 #include "openvz_conf.h"
 #include "uuid.h"
@@ -63,6 +64,74 @@ strtoI(const char *str)
 
     return val;
 }
+
+
+static int
+openvzExtractVersionInfo(const char *cmd, int *retversion)
+{
+    const char *const vzarg[] = { cmd, "--help", NULL };
+    const char *const vzenv[] = { "LC_ALL=C", NULL };
+    pid_t child;
+    int newstdout = -1;
+    int ret = -1, status;
+    unsigned int major, minor, micro;
+    unsigned int version;
+
+    if (retversion)
+        *retversion = 0;
+
+    if (virExec(NULL, vzarg, vzenv, NULL,
+                &child, -1, &newstdout, NULL, VIR_EXEC_NONE) < 0)
+        return -1;
+
+    char *help = NULL;
+    enum { MAX_HELP_OUTPUT_SIZE = 8192 };
+    int len = virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help);
+    if (len < 0)
+        goto cleanup2;
+
+    if (sscanf(help, "vzctl version %u.%u.%u",
+               &major, &minor, &micro) != 3) {
+        goto cleanup2;
+    }
+
+    version = (major * 1000 * 1000) + (minor * 1000) + micro;
+
+    if (retversion)
+        *retversion = version;
+
+    ret = 0;
+
+cleanup2:
+    VIR_FREE(help);
+    if (close(newstdout) < 0)
+        ret = -1;
+
+rewait:
+    if (waitpid(child, &status, 0) != child) {
+        if (errno == EINTR)
+            goto rewait;
+        ret = -1;
+    }
+
+    return ret;
+}
+
+int openvzExtractVersion(virConnectPtr conn,
+                         struct openvz_driver *driver)
+{
+    if (driver->version > 0)
+        return 0;
+
+    if (openvzExtractVersionInfo(VZCTL, &driver->version) < 0) {
+        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+                    "%s", _("Cound not extract vzctl version"));
+        return -1;
+    }
+
+    return 0;
+}
+
 
 virCapsPtr openvzCapsInit(void)
 {
diff -r 524f426a413d src/openvz_conf.h
--- a/src/openvz_conf.h	Tue Oct 14 14:41:47 2008 +0100
+++ b/src/openvz_conf.h	Tue Oct 14 15:10:48 2008 +0100
@@ -47,15 +47,18 @@ enum { OPENVZ_WARN, OPENVZ_ERR };
 
 
 /* OpenVZ commands - Replace with wrapper scripts later? */
-#define VZLIST  "vzlist"
-#define VZCTL   "vzctl"
+#define VZLIST  "/usr/sbin/vzlist"
+#define VZCTL   "/usr/sbin/vzctl"
 
 struct openvz_driver {
     virCapsPtr caps;
     virDomainObjList domains;
+    int version;
 };
 
 int openvz_readline(int fd, char *ptr, int maxlen);
+int openvzExtractVersion(virConnectPtr conn,
+                         struct openvz_driver *driver);
 int openvzReadConfigParam(int vpsid ,const char * param, char *value, int maxlen);
 virCapsPtr openvzCapsInit(void);
 int openvzLoadDomains(struct openvz_driver *driver);
diff -r 524f426a413d src/openvz_driver.c
--- a/src/openvz_driver.c	Tue Oct 14 14:41:47 2008 +0100
+++ b/src/openvz_driver.c	Tue Oct 14 15:11:56 2008 +0100
@@ -172,6 +172,12 @@ static virDomainPtr openvzDomainLookupBy
     return dom;
 }
 
+static int openvzGetVersion(virConnectPtr conn, unsigned long *version) {
+    struct  openvz_driver *driver = (struct openvz_driver *)conn->privateData;
+    *version = driver->version;
+    return 0;
+}
+
 static char *openvzGetOSType(virDomainPtr dom)
 {
     struct  openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData;
@@ -777,6 +783,9 @@ static virDrvOpenStatus openvzOpen(virCo
     if (openvzLoadDomains(driver) < 0)
         goto cleanup;
 
+    if (openvzExtractVersion(conn, driver) < 0)
+        goto cleanup;
+
     conn->privateData = driver;
 
     return VIR_DRV_OPEN_SUCCESS;
@@ -961,7 +970,7 @@ static virDriver openvzDriver = {
     openvzClose, /* close */
     NULL, /* supports_feature */
     openvzGetType, /* type */
-    NULL, /* version */
+    openvzGetVersion, /* version */
     NULL, /* hostname */
     NULL, /* uri */
     openvzGetMaxVCPUs, /* getMaxVcpus */

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

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