]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
VMware: Support more than 2 driver backends
authorDoug Goldstein <cardoe@cardoe.com>
Tue, 24 Sep 2013 16:24:30 +0000 (11:24 -0500)
committerDaniel Veillard <veillard@redhat.com>
Sun, 29 Sep 2013 10:40:36 +0000 (18:40 +0800)
Currently the VMware version check code only supports two types of
VMware backends, Workstation and Player. But in the near future we will
have an additional one so we need to support more. Additionally, we
discover and cache the path to the vmrun binary so we should use that
path when using the corresponding binary from the VMware VIX SDK.

src/vmware/vmware_conf.c
src/vmware/vmware_driver.c

index 261a4f6e5d2676c02ad151e93211a5f171e514ec..c11c92d34fdc3cc37d91238e8455d6528c4c2a8b 100644 (file)
@@ -257,10 +257,30 @@ vmwareExtractVersion(struct vmware_driver *driver)
 {
     unsigned long version = 0;
     int ret = -1;
-    virCommandPtr cmd;
+    virCommandPtr cmd = NULL;
     char * outbuf = NULL;
-    const char * bin = (driver->type == VMWARE_DRIVER_PLAYER) ?
-                 "vmplayer" : "vmware";
+    char *bin = NULL;
+    char *vmwarePath = NULL;
+
+    if ((vmwarePath = mdir_name(driver->vmrun)) == NULL)
+        goto cleanup;
+
+    switch (driver->type) {
+        case VMWARE_DRIVER_PLAYER:
+            if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmplayer"))
+                goto cleanup;
+            break;
+
+        case VMWARE_DRIVER_WORKSTATION:
+            if (virAsprintf(&bin, "%s/%s", vmwarePath, "vmware"))
+                goto cleanup;
+            break;
+
+        default:
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("invalid driver type for version detection"));
+            goto cleanup;
+    }
 
     cmd = virCommandNewArgList(bin, "-v", NULL);
     virCommandSetOutputBuffer(cmd, &outbuf);
@@ -276,6 +296,8 @@ vmwareExtractVersion(struct vmware_driver *driver)
 cleanup:
     virCommandFree(cmd);
     VIR_FREE(outbuf);
+    VIR_FREE(bin);
+    VIR_FREE(vmwarePath);
     return ret;
 }
 
index 4e56971961834dcd93991547a896d8b90dd30216..23576fa793118797b391b2d9227ad7b92fb1f4e7 100644 (file)
@@ -93,6 +93,7 @@ vmwareConnectOpen(virConnectPtr conn,
 {
     struct vmware_driver *driver;
     size_t i;
+    char *tmp;
 
     virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
 
@@ -144,8 +145,25 @@ vmwareConnectOpen(virConnectPtr conn,
     if (virMutexInit(&driver->lock) < 0)
         goto cleanup;
 
-    driver->type = STRNEQ(conn->uri->scheme, "vmwareplayer") ?
-      VMWARE_DRIVER_WORKSTATION : VMWARE_DRIVER_PLAYER;
+    if ((tmp = STRSKIP(conn->uri->scheme, "vmware")) == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to parse URI "
+                       "scheme '%s'"), conn->uri->scheme);
+        goto cleanup;
+    }
+
+    driver->type = -1;
+    for (i = 0; i < VMWARE_DRIVER_LAST; i++) {
+        if (STREQ(tmp, vmwareDriverTypeToString(i))) {
+            driver->type = i;
+           break;
+       }
+    }
+
+    if (driver->type == -1) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find valid "
+                       "requested VMware backend '%s'"), tmp);
+        goto cleanup;
+    }
 
     if (!(driver->domains = virDomainObjListNew()))
         goto cleanup;