cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke4...@apache.org
Subject [02/50] [abbrv] git commit: updated refs/heads/4.5 to 50ee981
Date Mon, 13 Oct 2014 04:41:19 GMT
BUG-ID: CLOUDSTACK-7662. Resize of detached volume fails.
Support offline volume resize on ESX by creating a worker VM to attach the unattached volume
to and then resize it.

(cherry picked from commit 65ed25b7a63586e25a568d845527d547f0045889)


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4b581bfa
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4b581bfa
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4b581bfa

Branch: refs/heads/4.5
Commit: 4b581bfa5f2d62de0452fee0a47ed20336667056
Parents: 54110ed
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Tue Aug 13 12:44:44 2013 -0700
Committer: David Nalley <david@gnsa.us>
Committed: Mon Oct 13 00:14:22 2014 -0400

----------------------------------------------------------------------
 .../vmware/resource/VmwareResource.java         | 53 ++++++++++++++++----
 1 file changed, 44 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b581bfa/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
index 226a884..085b6bb 100755
--- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java
@@ -545,11 +545,43 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
         String path = cmd.getPath();
         String vmName = cmd.getInstanceName();
         long newSize = cmd.getNewSize() / 1024;
+        long oldSize = cmd.getCurrentSize()/1024;
+        boolean useWorkerVm = false;
+
+        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
+        String poolId = cmd.getPoolUuid();
+        VirtualMachineMO vmMo = null;
+        DatastoreMO dsMo = null;
+        ManagedObjectReference morDS = null;
+        String vmdkDataStorePath = null;
 
         try {
-            VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
+            if (newSize < oldSize) {
+                throw new Exception("VMware doesn't support shrinking volume from larger
size: " + oldSize/(1024*1024) + " GB to a smaller size: " + newSize/(1024*1024) + " GB");
+            } else if (newSize == oldSize) {
+                return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
+            }
+            if (vmName.equalsIgnoreCase("none")) {
+                // we need to spawn a worker VM to attach the volume to and
+                // resize the volume.
+                useWorkerVm = true;
+                vmName = this.getWorkerName(getServiceContext(), cmd, 0);
+
+                morDS = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost,
poolId);
+                dsMo = new DatastoreMO(hyperHost.getContext(), morDS);
+                s_logger.info("Create worker VM " + vmName);
+                vmMo = HypervisorHostHelper.createWorkerVM(hyperHost, dsMo, vmName);
+                if (vmMo == null) {
+                    throw new Exception("Unable to create a worker VM for volume resize");
+                }
+
+                synchronized (this) {
+                    vmdkDataStorePath = VmwareStorageLayoutHelper.getLegacyDatastorePathFromVmdkFileName(dsMo,
path + ".vmdk");
+                    vmMo.attachDisk(new String[] { vmdkDataStorePath }, morDS);
+                }
+            }
             // find VM through datacenter (VM is not at the target host yet)
-            VirtualMachineMO vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
+            vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
             if (vmMo == null) {
                 String msg = "VM " + vmName + " does not exist in VMware datacenter";
                 s_logger.error(msg);
@@ -563,13 +595,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
                 throw new Exception("No such disk device: " + path);
             }
             VirtualDisk disk = vdisk.first();
-            long oldSize = disk.getCapacityInKB();
-            if (newSize < oldSize) {
-                throw new Exception("VMware doesn't support shrinking volume from larger
size: " + oldSize/(1024*1024) + " GB to a smaller size: "
-                        + newSize/(1024*1024) + " GB");
-            } else if (newSize == oldSize) {
-                return new ResizeVolumeAnswer(cmd, true, "success", newSize * 1024);
-            }
             disk.setCapacityInKB(newSize);
 
             VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
@@ -586,6 +611,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource,
Vmwa
             s_logger.error("Unable to resize volume", e);
             String error = "Failed to resize volume: " + e.getMessage();
             return new ResizeVolumeAnswer(cmd, false, error);
+        } finally {
+            try {
+                if (useWorkerVm == true) {
+                    s_logger.info("Destroy worker VM after volume resize");
+                    vmMo.detachDisk(vmdkDataStorePath, false);
+                    vmMo.destroy();
+                }
+            } catch (Throwable e) {
+                s_logger.info("Failed to destroy worker VM: " + vmName);
+            }
         }
     }
 


Mime
View raw message