+Fri Oct 24 12:32:23 BST Daniel P. Berrange <berrange@redhat.com>
+
+ * src/openvz_conf.c, src/openvz_conf.h: Extract version
+ info from vzctl tool
+ * src/openvz_driver.c: Implement the getVersion API call.
+
Fri Oct 24 12:30:23 BST Daniel P. Berrange <berrange@redhat.com>
Fix mingw build
#include <errno.h>
#include <string.h>
#include <sys/utsname.h>
+#include <sys/wait.h>
#include "openvz_conf.h"
#include "uuid.h"
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;
+ int len = virFileReadLimFD(newstdout, 512, &help);
+ if (len < 0)
+ goto cleanup2;
+
+ if (sscanf(help, "vzctl version %u.%u.%u",
+ &major, &minor, µ) != 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)
{
struct utsname utsname;
/* 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);
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;
if (openvzLoadDomains(driver) < 0)
goto cleanup;
+ if (openvzExtractVersion(conn, driver) < 0)
+ goto cleanup;
+
conn->privateData = driver;
return VIR_DRV_OPEN_SUCCESS;
openvzClose, /* close */
NULL, /* supports_feature */
openvzGetType, /* type */
- NULL, /* version */
+ openvzGetVersion, /* version */
NULL, /* hostname */
NULL, /* uri */
openvzGetMaxVCPUs, /* getMaxVcpus */