Skip to content

Commit ec56ee9

Browse files
committed
Merge branch 'bugfix/CID-1241966'
2 parents d1e0a89 + 586e00c commit ec56ee9

2 files changed

Lines changed: 85 additions & 86 deletions

File tree

‎engine/orchestration/src/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java‎

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,16 @@ public Volume allocateDuplicateVolume(Volume oldVol, Long templateId) {
211211

212212
public VolumeVO allocateDuplicateVolumeVO(Volume oldVol, Long templateId) {
213213
VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(),
214-
oldVol.getName(),
215-
oldVol.getDataCenterId(),
216-
oldVol.getDomainId(),
217-
oldVol.getAccountId(),
218-
oldVol.getDiskOfferingId(),
219-
oldVol.getProvisioningType(),
220-
oldVol.getSize(),
221-
oldVol.getMinIops(),
222-
oldVol.getMaxIops(),
223-
oldVol.get_iScsiName());
214+
oldVol.getName(),
215+
oldVol.getDataCenterId(),
216+
oldVol.getDomainId(),
217+
oldVol.getAccountId(),
218+
oldVol.getDiskOfferingId(),
219+
oldVol.getProvisioningType(),
220+
oldVol.getSize(),
221+
oldVol.getMinIops(),
222+
oldVol.getMaxIops(),
223+
oldVol.get_iScsiName());
224224
if (templateId != null) {
225225
newVol.setTemplateId(templateId);
226226
} else {
@@ -595,16 +595,16 @@ public DiskProfile allocateRawVolume(Type type, String name, DiskOffering offeri
595595
maxIops = maxIops != null ? maxIops : offering.getMaxIops();
596596

597597
VolumeVO vol = new VolumeVO(type,
598-
name,
599-
vm.getDataCenterId(),
600-
owner.getDomainId(),
601-
owner.getId(),
602-
offering.getId(),
603-
offering.getProvisioningType(),
604-
size,
605-
minIops,
606-
maxIops,
607-
null);
598+
name,
599+
vm.getDataCenterId(),
600+
owner.getDomainId(),
601+
owner.getId(),
602+
offering.getId(),
603+
offering.getProvisioningType(),
604+
size,
605+
minIops,
606+
maxIops,
607+
null);
608608
if (vm != null) {
609609
vol.setInstanceId(vm.getId());
610610
}
@@ -656,16 +656,16 @@ public DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering
656656
maxIops = maxIops != null ? maxIops : offering.getMaxIops();
657657

658658
VolumeVO vol = new VolumeVO(type,
659-
name,
660-
vm.getDataCenterId(),
661-
owner.getDomainId(),
662-
owner.getId(),
663-
offering.getId(),
664-
offering.getProvisioningType(),
665-
size,
666-
minIops,
667-
maxIops,
668-
null);
659+
name,
660+
vm.getDataCenterId(),
661+
owner.getDomainId(),
662+
owner.getId(),
663+
offering.getId(),
664+
offering.getProvisioningType(),
665+
size,
666+
minIops,
667+
maxIops,
668+
null);
669669
vol.setFormat(getSupportedImageFormatForCluster(template.getHypervisorType()));
670670
if (vm != null) {
671671
vol.setInstanceId(vm.getId());
@@ -682,8 +682,8 @@ public DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering
682682
}
683683

684684
if (vm.getType() == VirtualMachine.Type.User) {
685-
UserVmVO userVm = _userVmDao.findById(vm.getId());
686-
vol.setDisplayVolume(userVm.isDisplayVm());
685+
UserVmVO userVm = _userVmDao.findById(vm.getId());
686+
vol.setDisplayVolume(userVm.isDisplayVm());
687687
}
688688

689689

@@ -1092,7 +1092,7 @@ private List<VolumeTask> getTasks(List<VolumeVO> vols, Map<Volume, StoragePool>
10921092
if (assignedPool == null && recreate) {
10931093
assignedPool = _storagePoolDao.findById(vol.getPoolId());
10941094
}
1095-
if (assignedPool != null || recreate) {
1095+
if (assignedPool != null) {
10961096
Volume.State state = vol.getState();
10971097
if (state == Volume.State.Allocated || state == Volume.State.Creating) {
10981098
VolumeTask task = new VolumeTask(VolumeTaskType.RECREATE, vol, null);

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java‎

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818

1919
import java.io.File;
2020
import java.util.ArrayList;
21+
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
2324
import java.util.UUID;
24-
import java.util.HashMap;
25-
2625

2726
import org.apache.commons.codec.binary.Base64;
2827
import org.apache.log4j.Logger;
@@ -354,6 +353,9 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) {
354353
storage.create(0);
355354
}
356355
LibvirtStoragePoolDef spd = getStoragePoolDef(conn, storage);
356+
if (spd == null) {
357+
throw new CloudRuntimeException("Unable to parse the storage pool definition for storage pool " + uuid);
358+
}
357359
StoragePoolType type = null;
358360
if (spd.getPoolType() == LibvirtStoragePoolDef.poolType.NETFS) {
359361
type = StoragePoolType.NetworkFilesystem;
@@ -375,7 +377,7 @@ public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) {
375377
pool.setLocalPath("");
376378

377379
if (pool.getType() == StoragePoolType.RBD
378-
|| pool.getType() == StoragePoolType.Gluster) {
380+
|| pool.getType() == StoragePoolType.Gluster) {
379381
pool.setSourceHost(spd.getSourceHost());
380382
pool.setSourcePort(spd.getSourcePort());
381383
pool.setSourceDir(spd.getSourceDir());
@@ -633,32 +635,32 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
633635
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
634636

635637
s_logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool "
636-
+ pool.getUuid() + " with size " + size);
638+
+ pool.getUuid() + " with size " + size);
637639

638640
switch (pool.getType()){
639-
case RBD:
640-
return createPhysicalDiskOnRBD(name, pool, format, provisioningType, size);
641-
case NetworkFilesystem:
642-
case Filesystem:
643-
switch (format){
644-
case QCOW2:
645-
return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size);
646-
case RAW:
647-
return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size);
648-
case DIR:
649-
return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size);
650-
case TAR:
651-
return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size);
652-
default:
653-
throw new CloudRuntimeException("Unexpected disk format is specified.");
654-
}
655-
default:
641+
case RBD:
642+
return createPhysicalDiskOnRBD(name, pool, format, provisioningType, size);
643+
case NetworkFilesystem:
644+
case Filesystem:
645+
switch (format){
646+
case QCOW2:
647+
return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size);
648+
case RAW:
649+
return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size);
650+
case DIR:
651+
return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size);
652+
case TAR:
656653
return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size);
654+
default:
655+
throw new CloudRuntimeException("Unexpected disk format is specified.");
656+
}
657+
default:
658+
return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size);
657659
}
658660
}
659661

660662
private KVMPhysicalDisk createPhysicalDiskByLibVirt(String name, KVMStoragePool pool,
661-
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
663+
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
662664
LibvirtStoragePool libvirtPool = (LibvirtStoragePool) pool;
663665
StoragePool virtPool = libvirtPool.getPool();
664666
LibvirtStorageVolumeDef.volFormat libvirtformat = LibvirtStorageVolumeDef.volFormat.getFormat(format);
@@ -690,7 +692,7 @@ private KVMPhysicalDisk createPhysicalDiskByLibVirt(String name, KVMStoragePool
690692

691693

692694
private KVMPhysicalDisk createPhysicalDiskByQemuImg(String name, KVMStoragePool pool,
693-
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
695+
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
694696
String volPath = pool.getLocalPath() + "/" + name;
695697
String volName = name;
696698
long virtualSize = 0;
@@ -725,7 +727,7 @@ private KVMPhysicalDisk createPhysicalDiskByQemuImg(String name, KVMStoragePool
725727
}
726728

727729
private KVMPhysicalDisk createPhysicalDiskOnRBD(String name, KVMStoragePool pool,
728-
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
730+
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
729731
String volPath = null;
730732

731733
/**
@@ -751,7 +753,7 @@ private KVMPhysicalDisk createPhysicalDiskOnRBD(String name, KVMStoragePool pool
751753

752754
IoCTX io = r.ioCtxCreate(pool.getSourceDir());
753755
Rbd rbd = new Rbd(io);
754-
rbd.create(name, size, this.rbdFeatures, this.rbdOrder);
756+
rbd.create(name, size, rbdFeatures, rbdOrder);
755757

756758
r.ioCtxDestroy(io);
757759
} catch (RadosException e) {
@@ -855,7 +857,7 @@ public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.Imag
855857
r.ioCtxDestroy(io);
856858

857859
s_logger.debug("Succesfully unprotected and removed any snapshots of " + pool.getSourceDir() + "/" + uuid +
858-
" Continuing to remove the RBD image");
860+
" Continuing to remove the RBD image");
859861
} catch (RadosException e) {
860862
throw new CloudRuntimeException(e.toString());
861863
} catch (RbdException e) {
@@ -893,7 +895,7 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
893895
String name, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, KVMStoragePool destPool, int timeout) {
894896

895897
s_logger.info("Creating volume " + name + " from template " + template.getName() + " in pool " + destPool.getUuid() +
896-
" (" + destPool.getType().toString() + ") with size " + size);
898+
" (" + destPool.getType().toString() + ") with size " + size);
897899

898900
KVMPhysicalDisk disk = null;
899901

@@ -920,15 +922,15 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
920922
Map<String, String> options = new HashMap<String, String>();
921923
options.put("preallocation", QemuImg.PreallocationType.getPreallocationType(provisioningType).toString());
922924
switch(provisioningType){
923-
case THIN:
924-
QemuImgFile backingFile = new QemuImgFile(template.getPath(), template.getFormat());
925-
qemu.create(destFile, backingFile, options);
926-
break;
927-
case SPARSE:
928-
case FAT:
929-
QemuImgFile srcFile = new QemuImgFile(template.getPath(), template.getFormat());
930-
qemu.convert(srcFile, destFile, options);
931-
break;
925+
case THIN:
926+
QemuImgFile backingFile = new QemuImgFile(template.getPath(), template.getFormat());
927+
qemu.create(destFile, backingFile, options);
928+
break;
929+
case SPARSE:
930+
case FAT:
931+
QemuImgFile srcFile = new QemuImgFile(template.getPath(), template.getFormat());
932+
qemu.convert(srcFile, destFile, options);
933+
break;
932934
}
933935
} else if (format == PhysicalDiskFormat.RAW) {
934936
QemuImgFile sourceFile = new QemuImgFile(template.getPath(), template.getFormat());
@@ -964,7 +966,7 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template,
964966
So for RBD we don't create the image, but let qemu-img do that for us.
965967
966968
We then create a KVMPhysicalDisk object that we can return
967-
*/
969+
*/
968970

969971
KVMStoragePool srcPool = template.getPool();
970972
KVMPhysicalDisk disk = null;
@@ -1013,7 +1015,7 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template,
10131015

10141016
try {
10151017
if ((srcPool.getSourceHost().equals(destPool.getSourceHost())) && (srcPool.getSourceDir().equals(destPool.getSourceDir()))) {
1016-
/* We are on the same Ceph cluster, but we require RBD format 2 on the source image */
1018+
/* We are on the same Ceph cluster, but we require RBD format 2 on the source image */
10171019
s_logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool");
10181020

10191021
Rados r = new Rados(srcPool.getAuthUserName());
@@ -1028,7 +1030,7 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template,
10281030
RbdImage srcImage = rbd.open(template.getName());
10291031

10301032
if (srcImage.isOldFormat()) {
1031-
/* The source image is RBD format 1, we have to do a regular copy */
1033+
/* The source image is RBD format 1, we have to do a regular copy */
10321034
s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() +
10331035
" is RBD format 1. We have to perform a regular copy (" + disk.getVirtualSize() + " bytes)");
10341036

@@ -1043,20 +1045,20 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template,
10431045
} else {
10441046
s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName()
10451047
+ " is RBD format 2. We will perform a RBD clone using snapshot "
1046-
+ this.rbdTemplateSnapName);
1047-
/* The source image is format 2, we can do a RBD snapshot+clone (layering) */
1048+
+ rbdTemplateSnapName);
1049+
/* The source image is format 2, we can do a RBD snapshot+clone (layering) */
10481050

10491051

10501052
s_logger.debug("Checking if RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName()
1051-
+ "@" + rbdTemplateSnapName + " exists prior to attempting a clone operation.");
1053+
+ "@" + rbdTemplateSnapName + " exists prior to attempting a clone operation.");
10521054

10531055
List<RbdSnapInfo> snaps = srcImage.snapList();
10541056
s_logger.debug("Found " + snaps.size() + " snapshots on RBD image " + srcPool.getSourceDir() + "/" + template.getName());
10551057
boolean snapFound = false;
10561058
for (RbdSnapInfo snap : snaps) {
10571059
if (rbdTemplateSnapName.equals(snap.name)) {
10581060
s_logger.debug("RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName()
1059-
+ "@" + rbdTemplateSnapName + " already exists.");
1061+
+ "@" + rbdTemplateSnapName + " already exists.");
10601062
snapFound = true;
10611063
break;
10621064
}
@@ -1069,14 +1071,14 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template,
10691071
srcImage.snapProtect(rbdTemplateSnapName);
10701072
}
10711073

1072-
rbd.clone(template.getName(), this.rbdTemplateSnapName, io, disk.getName(), this.rbdFeatures, this.rbdOrder);
1073-
s_logger.debug("Succesfully cloned " + template.getName() + "@" + this.rbdTemplateSnapName + " to " + disk.getName());
1074+
rbd.clone(template.getName(), rbdTemplateSnapName, io, disk.getName(), rbdFeatures, rbdOrder);
1075+
s_logger.debug("Succesfully cloned " + template.getName() + "@" + rbdTemplateSnapName + " to " + disk.getName());
10741076
}
10751077

10761078
rbd.close(srcImage);
10771079
r.ioCtxDestroy(io);
10781080
} else {
1079-
/* The source pool or host is not the same Ceph cluster, we do a simple copy with Qemu-Img */
1081+
/* The source pool or host is not the same Ceph cluster, we do a simple copy with Qemu-Img */
10801082
s_logger.debug("Both the source and destination are RBD, but not the same Ceph cluster. Performing a copy");
10811083

10821084
Rados rSrc = new Rados(srcPool.getAuthUserName());
@@ -1240,16 +1242,13 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
12401242
* To do so it's mandatory that librbd on the system is at least 0.67.7 (Ceph Dumpling)
12411243
*/
12421244
s_logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2");
1243-
String sourceFile;
1244-
boolean useTmpFile = false;
1245-
12461245
try {
12471246
srcFile = new QemuImgFile(sourcePath, sourceFormat);
12481247
String rbdDestFile = KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(),
1249-
destPool.getSourcePort(),
1250-
destPool.getAuthUserName(),
1251-
destPool.getAuthSecret(),
1252-
destPool.getSourceDir() + "/" + name);
1248+
destPool.getSourcePort(),
1249+
destPool.getAuthUserName(),
1250+
destPool.getAuthSecret(),
1251+
destPool.getSourceDir() + "/" + name);
12531252
destFile = new QemuImgFile(rbdDestFile, destFormat);
12541253

12551254
s_logger.debug("Starting copy from source image " + srcFile.getFileName() + " to RBD image " + destPool.getSourceDir() + "/" + name);

0 commit comments

Comments
 (0)