Merge pull request #1161 from ustcweizhou/resize-volume-issues

CLOUDSTACK-9101: fix some issues in resize volume(1) fix issue: volume size is not updated even if the operation succeed
(2) Add ui support for root volume resize
(3) resize on qcow2 type ROOT volume of stopped vm does not really work
see https://issues.apache.org/jira/browse/CLOUDSTACK-9101

* pr/1161:
  CLOUDSTACK-9101: resize root volume of stopped vm on KVM
  CLOUDSTACK-9101: add UI support for root volume resize
  CLOUDSTACK-9101: update volume size after resizevolume

Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
Daan Hoogland 2015-12-06 19:44:16 +01:00
commit 998b1ba629
3 changed files with 42 additions and 12 deletions

View File

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

View File

@ -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);

View File

@ -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");