Skip to content

Commit 82ab74b

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 c873845 commit 82ab74b

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
@@ -859,17 +859,55 @@ public boolean deleteStoragePool(String uuid) {
859859
}
860860
}
861861

862+
/**
863+
* Creates a physical disk depending on the {@link StoragePoolType}:
864+
* <ul>
865+
* <li>
866+
* <b>{@link StoragePoolType#RBD}</b>
867+
* <ul>
868+
* <li>
869+
* If it is an erasure code pool, utilizes QemuImg to create the physical disk through the method
870+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByQemuImg(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long, byte[])}
871+
* </li>
872+
* <li>
873+
* Otherwise, utilize Libvirt to create the physical disk through the method
874+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByLibVirt(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long)}
875+
* </li>
876+
* </ul>
877+
* </li>
878+
* <li>
879+
* {@link StoragePoolType#NetworkFilesystem} and {@link StoragePoolType#Filesystem}
880+
* <ul>
881+
* <li>
882+
* If the format is {@link PhysicalDiskFormat#QCOW2} or {@link PhysicalDiskFormat#RAW}, utilizes QemuImg to create the physical disk through the method
883+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByQemuImg(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long, byte[])}
884+
* </li>
885+
* <li>
886+
* If the format is {@link PhysicalDiskFormat#DIR} or {@link PhysicalDiskFormat#TAR}, utilize Libvirt to create the physical disk through the method
887+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByLibVirt(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long)}
888+
* </li>
889+
* </ul>
890+
* </li>
891+
* <li>
892+
* For the rest of the {@link StoragePoolType} types, utilizes the Libvirt method
893+
* {@link LibvirtStorageAdaptor#createPhysicalDiskByLibVirt(String, KVMStoragePool, PhysicalDiskFormat, Storage.ProvisioningType, long)}
894+
* </li>
895+
* </ul>
896+
*/
862897
@Override
863898
public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
864899
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, byte[] passphrase) {
865900

866-
logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool "
867-
+ pool.getUuid() + " with size " + toHumanReadableSize(size));
901+
logger.info("Attempting to create volume {} ({}) in pool {} with size {}", name, pool.getType().toString(), pool.getUuid(), toHumanReadableSize(size));
868902

869903
StoragePoolType poolType = pool.getType();
870-
if (poolType.equals(StoragePoolType.RBD)) {
871-
return createPhysicalDiskByQemuImg(name, pool, PhysicalDiskFormat.RAW, provisioningType, size, passphrase);
872-
} else if (poolType.equals(StoragePoolType.NetworkFilesystem) || poolType.equals(StoragePoolType.Filesystem)) {
904+
if (StoragePoolType.RBD.equals(poolType)) {
905+
Map<String, String> details = pool.getDetails();
906+
String dataPool = (details == null) ? null : details.get(KVMPhysicalDisk.RBD_DEFAULT_DATA_POOL);
907+
908+
return (dataPool == null) ? createPhysicalDiskByLibVirt(name, pool, PhysicalDiskFormat.RAW, provisioningType, size) :
909+
createPhysicalDiskByQemuImg(name, pool, PhysicalDiskFormat.RAW, provisioningType, size, passphrase);
910+
} else if (StoragePoolType.NetworkFilesystem.equals(poolType) || StoragePoolType.Filesystem.equals(poolType)) {
873911
switch (format) {
874912
case QCOW2:
875913
case RAW:

0 commit comments

Comments
 (0)