From 119b27b2c6c366949b574fbca1574f15d67a3af3 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 3 Dec 2015 11:54:20 +0100 Subject: [PATCH 1/3] CLOUDSTACK-9101: update volume size after resizevolume --- server/src/com/cloud/storage/VolumeApiServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index 6fe0a14343e..4313bfc4319 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -1158,6 +1158,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic if (newDiskOfferingId != null) { volume.setDiskOfferingId(newDiskOfferingId); } + if (currentSize != newSize) { + volume.setSize(newSize); + } _volsDao.update(volume.getId(), volume); From d6e21f74163212b198731ddf23dd48bc4c787b84 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 3 Dec 2015 11:53:42 +0100 Subject: [PATCH 2/3] CLOUDSTACK-9101: add UI support for root volume resize --- ui/scripts/storage.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/ui/scripts/storage.js b/ui/scripts/storage.js index 77bd00284b1..599802a45ab 100644 --- a/ui/scripts/storage.js +++ b/ui/scripts/storage.js @@ -1536,14 +1536,27 @@ }, createForm: { title: 'label.action.resize.volume', + preFilter: function(args) { + if (args.context.volumes != null && args.context.volumes[0].type == 'ROOT') { + args.$form.find('.form-item[rel=newdiskoffering]').hide(); + } else { + args.$form.find('.form-item[rel=newsize]').hide(); + } + }, fields: { newdiskoffering: { label: 'label.resize.new.offering.id', select: function(args) { + if (args.context.volumes != null && args.context.volumes[0].type == 'ROOT') { + args.response.success({ + data: [] + }); + return; + } + $.ajax({ url: createURL("listDiskOfferings"), dataType: "json", - async: false, success: function(json) { diskofferingObjs = json.listdiskofferingsresponse.diskoffering; var items = []; @@ -1605,8 +1618,7 @@ validation: { required: true, number: true - }, - isHidden: true + } }, shrinkok: { label: 'label.resize.shrink.ok', @@ -1640,7 +1652,7 @@ var newDiskOffering = args.data.newdiskoffering; var newSize; - if (selectedDiskOfferingObj.iscustomized == true) { + if (selectedDiskOfferingObj == null || selectedDiskOfferingObj.iscustomized == true) { newSize = args.data.newsize; } if (newDiskOffering != null && newDiskOffering.length > 0) { @@ -1651,9 +1663,9 @@ } var minIops; - var maxIops + var maxIops; - if (selectedDiskOfferingObj.iscustomizediops == true) { + if (selectedDiskOfferingObj != null && selectedDiskOfferingObj.iscustomizediops == true) { minIops = args.data.minIops; maxIops = args.data.maxIops; } @@ -2338,11 +2350,14 @@ allowedActions.push("takeSnapshot"); allowedActions.push("recurringSnapshot"); } + } - if (jsonObj.type == "DATADISK") { + if (jsonObj.hypervisor == "KVM" || jsonObj.hypervisor == "XenServer" || jsonObj.hypervisor == "VMware") { + if (jsonObj.state == "Ready" || jsonObj.state == "Allocated") { allowedActions.push("resize"); } } + if (jsonObj.state != "Allocated") { if ((jsonObj.vmstate == "Stopped" || jsonObj.virtualmachineid == null) && jsonObj.state == "Ready") { allowedActions.push("downloadVolume"); From 9221cb3e0d0e5a0ea374f10e889f7e32c2a3eda1 Mon Sep 17 00:00:00 2001 From: Wei Zhou Date: Thu, 3 Dec 2015 14:31:55 +0100 Subject: [PATCH 3/3] CLOUDSTACK-9101: resize root volume of stopped vm on KVM --- scripts/storage/qcow2/resizevolume.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/storage/qcow2/resizevolume.sh b/scripts/storage/qcow2/resizevolume.sh index 1e6ffd648f5..da77cb1adca 100755 --- a/scripts/storage/qcow2/resizevolume.sh +++ b/scripts/storage/qcow2/resizevolume.sh @@ -187,6 +187,22 @@ resizeqcow2() { # if this is a shrink operation, fail if commands will shrink the volume and we haven't signed of on shrinking failshrink + #move this back into cloudstack libvirt calls once the libvirt java bindings support block resize + #we try to inform hypervisor of new size, but don't fail if we can't + if `virsh help 2>/dev/null | grep -q blockresize` + then + if `virsh domstate $vmname >/dev/null 2>&1` + then + log "vm $vmname is running, use 'virsh blockresize' to resize the volume" + notifyqemu + if [ $? -eq 0 ] + then + log "performed successful resize - currentsize:$currentsize newsize:$newsize path:$path type:$ptype vmname:$vmname live:$liveresize shrink:$shrink" + exit 0 + fi + fi + fi + output=`qemu-img resize $path $newsize 2>&1` retval=$? @@ -196,10 +212,6 @@ resizeqcow2() { exit 1 fi - #move this back into cloudstack libvirt calls once the libvirt java bindings support block resize - #we try to inform hypervisor of new size, but don't fail if we can't - notifyqemu - log "performed successful resize - currentsize:$currentsize newsize:$newsize path:$path type:$ptype vmname:$vmname live:$liveresize shrink:$shrink" } @@ -244,7 +256,7 @@ then resizelvm elif [ "$ptype" == "QCOW2" ] then - notifyqemu + resizeqcow2 elif [ "$ptype" == "NOTIFYONLY" ] then notifyqemu