Skip to content

Commit 5ea1ada

Browse files
authored
Allow full clone volumes with thin provisioning in KVM (#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 f62b85d commit 5ea1ada

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
@@ -863,6 +863,14 @@ public Property<Integer> getWorkers() {
863863
* */
864864
public static final Property<Integer> REVERT_SNAPSHOT_TIMEOUT = new Property<>("revert.snapshot.timeout", 10800);
865865

866+
/**
867+
* If set to true, creates VMs as full clones of their templates on KVM hypervisor. Creates as linked clones otherwise. <br>
868+
* Data type: Boolean. <br>
869+
* Default value: <code>false</code>
870+
*/
871+
public static final Property<Boolean> CREATE_FULL_CLONE = new Property<>("create.full.clone", false);
872+
873+
866874
public static class Property <T>{
867875
private String name;
868876
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
@@ -32,6 +32,8 @@
3232
import java.util.concurrent.ConcurrentHashMap;
3333
import java.util.stream.Collectors;
3434

35+
import com.cloud.agent.properties.AgentProperties;
36+
import com.cloud.agent.properties.AgentPropertiesFileHandler;
3537
import org.apache.cloudstack.api.ApiConstants;
3638
import org.apache.cloudstack.utils.cryptsetup.KeyFile;
3739
import org.apache.cloudstack.utils.qemu.QemuImageOptions;
@@ -1315,14 +1317,22 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
13151317
passphraseObjects.add(QemuObject.prepareSecretForQemuImg(format, QemuObject.EncryptFormat.LUKS, keyFile.toString(), "sec0", options));
13161318
disk.setQemuEncryptFormat(QemuObject.EncryptFormat.LUKS);
13171319
}
1320+
1321+
QemuImgFile srcFile = new QemuImgFile(template.getPath(), template.getFormat());
1322+
Boolean createFullClone = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CREATE_FULL_CLONE);
13181323
switch(provisioningType){
13191324
case THIN:
1320-
QemuImgFile backingFile = new QemuImgFile(template.getPath(), template.getFormat());
1321-
qemu.create(destFile, backingFile, options, passphraseObjects);
1325+
logger.info("Creating volume [{}] {} backing file [{}] as the property [{}] is [{}].", destFile.getFileName(), createFullClone ? "without" : "with",
1326+
template.getPath(), AgentProperties.CREATE_FULL_CLONE.getName(), createFullClone);
1327+
if (createFullClone) {
1328+
qemu.convert(srcFile, destFile, options, passphraseObjects, null, false);
1329+
} else {
1330+
qemu.create(destFile, srcFile, options, passphraseObjects);
1331+
}
13221332
break;
13231333
case SPARSE:
13241334
case FAT:
1325-
QemuImgFile srcFile = new QemuImgFile(template.getPath(), template.getFormat());
1335+
srcFile = new QemuImgFile(template.getPath(), template.getFormat());
13261336
qemu.convert(srcFile, destFile, options, passphraseObjects, null, false);
13271337
break;
13281338
}

0 commit comments

Comments
 (0)