Skip to content

Commit a7004db

Browse files
committed
rbd: Create snapshot for cloning operations only when it is required
We used to create the snapshot after the copy from Secondary Storage, but it could be that we never use the snapshot. Now we check if the snapshot exists prior to performing the cloning operation
1 parent 155745e commit a7004db

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,30 @@ private KVMPhysicalDisk createDiskFromTemplateOnRBD(KVMPhysicalDisk template,
10361036
+ " is RBD format 2. We will perform a RBD clone using snapshot "
10371037
+ this.rbdTemplateSnapName);
10381038
/* The source image is format 2, we can do a RBD snapshot+clone (layering) */
1039+
1040+
1041+
s_logger.debug("Checking if RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName()
1042+
+ "@" + rbdTemplateSnapName + " exists prior to attempting a clone operation.");
1043+
1044+
List<RbdSnapInfo> snaps = srcImage.snapList();
1045+
s_logger.debug("Found " + snaps.size() + " snapshots on RBD image " + srcPool.getSourceDir() + "/" + template.getName());
1046+
boolean snapFound = false;
1047+
for (RbdSnapInfo snap : snaps) {
1048+
if (rbdTemplateSnapName.equals(snap.name)) {
1049+
s_logger.debug("RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName()
1050+
+ "@" + rbdTemplateSnapName + " already exists.");
1051+
snapFound = true;
1052+
break;
1053+
}
1054+
}
1055+
1056+
if (!snapFound) {
1057+
s_logger.debug("Creating RBD snapshot " + rbdTemplateSnapName + " on image " + name);
1058+
srcImage.snapCreate(rbdTemplateSnapName);
1059+
s_logger.debug("Protecting RBD snapshot " + rbdTemplateSnapName + " on image " + name);
1060+
srcImage.snapProtect(rbdTemplateSnapName);
1061+
}
1062+
10391063
rbd.clone(template.getName(), this.rbdTemplateSnapName, io, disk.getName(), this.rbdFeatures, this.rbdOrder);
10401064
s_logger.debug("Succesfully cloned " + template.getName() + "@" + this.rbdTemplateSnapName + " to " + disk.getName());
10411065
}
@@ -1234,12 +1258,6 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
12341258

12351259
RbdImage image = rbd.open(name);
12361260

1237-
/* Snapshot the image and protect that snapshot so we can clone (layer) from it */
1238-
s_logger.debug("Creating RBD snapshot " + rbdTemplateSnapName + " on image " + name);
1239-
image.snapCreate(rbdTemplateSnapName);
1240-
s_logger.debug("Protecting RBD snapshot " + rbdTemplateSnapName + " on image " + name);
1241-
image.snapProtect(rbdTemplateSnapName);
1242-
12431261
rbd.close(image);
12441262
r.ioCtxDestroy(io);
12451263
} catch (QemuImgException e) {

0 commit comments

Comments
 (0)