Skip to content

Commit 83ef09e

Browse files
committed
Only use the method createPhysicalDiskByLibVirt with RBD when the pool is of erasure code type. Also added javadoc for createPhysicalDisk method
1 parent 7c196d9 commit 83ef09e

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMPhysicalDisk.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ public class KVMPhysicalDisk {
3333
private String vmName;
3434
private boolean useAsTemplate;
3535

36+
public static final String RBD_DEFAULT_DATA_POOL = "rbd_default_data_pool";
37+
3638
public static String RBDStringBuilder(KVMStoragePool storagePool, String image) {
3739
String monHost = storagePool.getSourceHost();
3840
int monPort = storagePool.getSourcePort();
3941
String authUserName = storagePool.getAuthUserName();
4042
String authSecret = storagePool.getAuthSecret();
4143
Map<String, String> details = storagePool.getDetails();
42-
String dataPool = (details == null) ? null : details.get("rbd_default_data_pool");
44+
String dataPool = (details == null) ? null : details.get(RBD_DEFAULT_DATA_POOL);
4345

4446
String rbdOpts = "rbd:" + image;
4547
rbdOpts += ":mon_host=" + composeOptionForMonHosts(monHost, monPort);

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,17 +960,55 @@ public boolean deleteStoragePool(String uuid) {
960960
}
961961
}
962962

963+
/**
964+
* Creates a physical disk depending on the {@link StoragePoolType}:
965+
* <ul>
966+
* <li>
967+
* <b>{@link StoragePoolType#RBD}</b>
968+
* <ul>
969+
* <li>
970+
* If it is an erasure code pool, utilizes QemuImg to create the physical disk through the method
971+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByQemuImg(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long, byte[])}
972+
* </li>
973+
* <li>
974+
* Otherwise, utilize Libvirt to create the physical disk through the method
975+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByLibVirt(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long)}
976+
* </li>
977+
* </ul>
978+
* </li>
979+
* <li>
980+
* {@link StoragePoolType#NetworkFilesystem} and {@link StoragePoolType#Filesystem}
981+
* <ul>
982+
* <li>
983+
* If the format is {@link PhysicalDiskFormat#QCOW2} or {@link PhysicalDiskFormat#RAW}, utilizes QemuImg to create the physical disk through the method
984+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByQemuImg(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long, byte[])}
985+
* </li>
986+
* <li>
987+
* If the format is {@link PhysicalDiskFormat#DIR} or {@link PhysicalDiskFormat#TAR}, utilize Libvirt to create the physical disk through the method
988+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByLibVirt(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long)}
989+
* </li>
990+
* </ul>
991+
* </li>
992+
* <li>
993+
* For the rest of the {@link StoragePoolType} types, utilizes the Libvirt method
994+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByLibVirt(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long)}
995+
* </li>
996+
* </ul>
997+
*/
963998
@Override
964999
public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
9651000
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, byte[] passphrase) {
9661001

967-
logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool "
968-
+ pool.getUuid() + " with size " + toHumanReadableSize(size));
1002+
logger.info("Attempting to create volume {} ({}) in pool {} with size {}", name, pool.getType().toString(), pool.getUuid(), toHumanReadableSize(size));
9691003

9701004
StoragePoolType poolType = pool.getType();
971-
if (poolType.equals(StoragePoolType.RBD)) {
972-
return createPhysicalDiskByQemuImg(name, pool, PhysicalDiskFormat.RAW, provisioningType, size, passphrase);
973-
} else if (poolType.equals(StoragePoolType.NetworkFilesystem) || poolType.equals(StoragePoolType.Filesystem)) {
1005+
if (StoragePoolType.RBD.equals(poolType)) {
1006+
Map<String, String> details = pool.getDetails();
1007+
String dataPool = (details == null) ? null : details.get(KVMPhysicalDisk.RBD_DEFAULT_DATA_POOL);
1008+
1009+
return (dataPool == null) ? createPhysicalDiskByLibVirt(name, pool, PhysicalDiskFormat.RAW, provisioningType, size) :
1010+
createPhysicalDiskByQemuImg(name, pool, PhysicalDiskFormat.RAW, provisioningType, size, passphrase);
1011+
} else if (StoragePoolType.NetworkFilesystem.equals(poolType) || StoragePoolType.Filesystem.equals(poolType)) {
9741012
switch (format) {
9751013
case QCOW2:
9761014
case RAW:

0 commit comments

Comments
 (0)