Skip to content

Commit 998b1ba

Browse files
committed
Merge pull request apache#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>
2 parents 4f6ff6c + 9221cb3 commit 998b1ba

3 files changed

Lines changed: 42 additions & 12 deletions

File tree

‎scripts/storage/qcow2/resizevolume.sh‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ resizeqcow2() {
187187
# if this is a shrink operation, fail if commands will shrink the volume and we haven't signed of on shrinking
188188
failshrink
189189

190+
#move this back into cloudstack libvirt calls once the libvirt java bindings support block resize
191+
#we try to inform hypervisor of new size, but don't fail if we can't
192+
if `virsh help 2>/dev/null | grep -q blockresize`
193+
then
194+
if `virsh domstate $vmname >/dev/null 2>&1`
195+
then
196+
log "vm $vmname is running, use 'virsh blockresize' to resize the volume"
197+
notifyqemu
198+
if [ $? -eq 0 ]
199+
then
200+
log "performed successful resize - currentsize:$currentsize newsize:$newsize path:$path type:$ptype vmname:$vmname live:$liveresize shrink:$shrink"
201+
exit 0
202+
fi
203+
fi
204+
fi
205+
190206
output=`qemu-img resize $path $newsize 2>&1`
191207
retval=$?
192208

@@ -196,10 +212,6 @@ resizeqcow2() {
196212
exit 1
197213
fi
198214

199-
#move this back into cloudstack libvirt calls once the libvirt java bindings support block resize
200-
#we try to inform hypervisor of new size, but don't fail if we can't
201-
notifyqemu
202-
203215
log "performed successful resize - currentsize:$currentsize newsize:$newsize path:$path type:$ptype vmname:$vmname live:$liveresize shrink:$shrink"
204216
}
205217

@@ -244,7 +256,7 @@ then
244256
resizelvm
245257
elif [ "$ptype" == "QCOW2" ]
246258
then
247-
notifyqemu
259+
resizeqcow2
248260
elif [ "$ptype" == "NOTIFYONLY" ]
249261
then
250262
notifyqemu

‎server/src/com/cloud/storage/VolumeApiServiceImpl.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,9 @@ private VolumeVO orchestrateResizeVolume(long volumeId, long currentSize, long n
11581158
if (newDiskOfferingId != null) {
11591159
volume.setDiskOfferingId(newDiskOfferingId);
11601160
}
1161+
if (currentSize != newSize) {
1162+
volume.setSize(newSize);
1163+
}
11611164

11621165
_volsDao.update(volume.getId(), volume);
11631166

‎ui/scripts/storage.js‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,14 +1536,27 @@
15361536
},
15371537
createForm: {
15381538
title: 'label.action.resize.volume',
1539+
preFilter: function(args) {
1540+
if (args.context.volumes != null && args.context.volumes[0].type == 'ROOT') {
1541+
args.$form.find('.form-item[rel=newdiskoffering]').hide();
1542+
} else {
1543+
args.$form.find('.form-item[rel=newsize]').hide();
1544+
}
1545+
},
15391546
fields: {
15401547
newdiskoffering: {
15411548
label: 'label.resize.new.offering.id',
15421549
select: function(args) {
1550+
if (args.context.volumes != null && args.context.volumes[0].type == 'ROOT') {
1551+
args.response.success({
1552+
data: []
1553+
});
1554+
return;
1555+
}
1556+
15431557
$.ajax({
15441558
url: createURL("listDiskOfferings"),
15451559
dataType: "json",
1546-
async: false,
15471560
success: function(json) {
15481561
diskofferingObjs = json.listdiskofferingsresponse.diskoffering;
15491562
var items = [];
@@ -1605,8 +1618,7 @@
16051618
validation: {
16061619
required: true,
16071620
number: true
1608-
},
1609-
isHidden: true
1621+
}
16101622
},
16111623
shrinkok: {
16121624
label: 'label.resize.shrink.ok',
@@ -1640,7 +1652,7 @@
16401652

16411653
var newDiskOffering = args.data.newdiskoffering;
16421654
var newSize;
1643-
if (selectedDiskOfferingObj.iscustomized == true) {
1655+
if (selectedDiskOfferingObj == null || selectedDiskOfferingObj.iscustomized == true) {
16441656
newSize = args.data.newsize;
16451657
}
16461658
if (newDiskOffering != null && newDiskOffering.length > 0) {
@@ -1651,9 +1663,9 @@
16511663
}
16521664

16531665
var minIops;
1654-
var maxIops
1666+
var maxIops;
16551667

1656-
if (selectedDiskOfferingObj.iscustomizediops == true) {
1668+
if (selectedDiskOfferingObj != null && selectedDiskOfferingObj.iscustomizediops == true) {
16571669
minIops = args.data.minIops;
16581670
maxIops = args.data.maxIops;
16591671
}
@@ -2338,11 +2350,14 @@
23382350
allowedActions.push("takeSnapshot");
23392351
allowedActions.push("recurringSnapshot");
23402352
}
2353+
}
23412354

2342-
if (jsonObj.type == "DATADISK") {
2355+
if (jsonObj.hypervisor == "KVM" || jsonObj.hypervisor == "XenServer" || jsonObj.hypervisor == "VMware") {
2356+
if (jsonObj.state == "Ready" || jsonObj.state == "Allocated") {
23432357
allowedActions.push("resize");
23442358
}
23452359
}
2360+
23462361
if (jsonObj.state != "Allocated") {
23472362
if ((jsonObj.vmstate == "Stopped" || jsonObj.virtualmachineid == null) && jsonObj.state == "Ready") {
23482363
allowedActions.push("downloadVolume");

0 commit comments

Comments
 (0)