Skip to content

Commit 71f6e52

Browse files
JoaoJandredhslove
authored andcommitted
Allow full clone volumes with thin provisioning in KVM (apache#11177)
It adds a configuration called create.full.clone to the agent.properties file. When set to true, all QCOW2 volumes created will be full-clone. If false (default), the current behavior remains, where only FAT and SPARSE volumes are full-clone and THIN volumes are linked-clone.
1 parent 682b6cd commit 71f6e52

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

agent/conf/agent.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,6 @@ iscsi.session.cleanup.enabled=false
447447

448448
# Timeout (in seconds) to wait for the incremental snapshot to complete.
449449
# incremental.snapshot.timeout=10800
450+
451+
# If set to true, creates VMs as full clones of their templates on KVM hypervisor. Creates as linked clones otherwise.
452+
# create.full.clone=false

agent/src/main/java/com/cloud/agent/properties/AgentProperties.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,14 @@ public Property<Integer> getWorkers() {
875875
* */
876876
public static final Property<Integer> REVERT_SNAPSHOT_TIMEOUT = new Property<>("revert.snapshot.timeout", 10800);
877877

878+
/**
879+
* If set to true, creates VMs as full clones of their templates on KVM hypervisor. Creates as linked clones otherwise. <br>
880+
* Data type: Boolean. <br>
881+
* Default value: <code>false</code>
882+
*/
883+
public static final Property<Boolean> CREATE_FULL_CLONE = new Property<>("create.full.clone", false);
884+
885+
878886
public static class Property <T>{
879887
private String name;
880888
private T defaultValue;

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.stream.Collectors;
3434

3535
import com.cloud.utils.Pair;
36+
import com.cloud.agent.properties.AgentProperties;
37+
import com.cloud.agent.properties.AgentPropertiesFileHandler;
3638
import org.apache.cloudstack.api.ApiConstants;
3739
import org.apache.cloudstack.utils.cryptsetup.KeyFile;
3840
import org.apache.cloudstack.utils.qemu.QemuImageOptions;
@@ -1448,14 +1450,22 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
14481450
passphraseObjects.add(QemuObject.prepareSecretForQemuImg(format, QemuObject.EncryptFormat.LUKS, keyFile.toString(), "sec0", options));
14491451
disk.setQemuEncryptFormat(QemuObject.EncryptFormat.LUKS);
14501452
}
1453+
1454+
QemuImgFile srcFile = new QemuImgFile(template.getPath(), template.getFormat());
1455+
Boolean createFullClone = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CREATE_FULL_CLONE);
14511456
switch(provisioningType){
14521457
case THIN:
1453-
QemuImgFile backingFile = new QemuImgFile(template.getPath(), template.getFormat());
1454-
qemu.create(destFile, backingFile, options, passphraseObjects);
1458+
logger.info("Creating volume [{}] {} backing file [{}] as the property [{}] is [{}].", destFile.getFileName(), createFullClone ? "without" : "with",
1459+
template.getPath(), AgentProperties.CREATE_FULL_CLONE.getName(), createFullClone);
1460+
if (createFullClone) {
1461+
qemu.convert(srcFile, destFile, options, passphraseObjects, null, false);
1462+
} else {
1463+
qemu.create(destFile, srcFile, options, passphraseObjects);
1464+
}
14551465
break;
14561466
case SPARSE:
14571467
case FAT:
1458-
QemuImgFile srcFile = new QemuImgFile(template.getPath(), template.getFormat());
1468+
srcFile = new QemuImgFile(template.getPath(), template.getFormat());
14591469
qemu.convert(srcFile, destFile, options, passphraseObjects, null, false);
14601470
break;
14611471
}

0 commit comments

Comments
 (0)