Skip to content

Commit 4b4c52e

Browse files
committed
CLOUDSTACK-8560: Stat the resulting image after copying from template and return the size
This way we update the DB with the actual size of the disk after deployment from template
1 parent 3e3c11f commit 4b4c52e

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.ceph.rbd.Rbd;
4040
import com.ceph.rbd.RbdException;
4141
import com.ceph.rbd.RbdImage;
42+
import com.ceph.rbd.jna.RbdImageInfo;
4243
import com.ceph.rbd.jna.RbdSnapInfo;
4344

4445
import org.apache.cloudstack.utils.qemu.QemuImg;
@@ -1239,6 +1240,10 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
12391240
destFile = new QemuImgFile(destPath, destFormat);
12401241
try {
12411242
qemu.convert(srcFile, destFile);
1243+
Map<String, String> destInfo = qemu.info(destFile);
1244+
Long virtualSize = Long.parseLong(destInfo.get(new String("virtual_size")));
1245+
newDisk.setVirtualSize(virtualSize);
1246+
newDisk.setSize(virtualSize);
12421247
} catch (QemuImgException e) {
12431248
s_logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage());
12441249
newDisk = null;
@@ -1257,18 +1262,19 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
12571262
s_logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2");
12581263
try {
12591264
srcFile = new QemuImgFile(sourcePath, sourceFormat);
1265+
String rbdDestPath = destPool.getSourceDir() + "/" + name;
12601266
String rbdDestFile = KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(),
12611267
destPool.getSourcePort(),
12621268
destPool.getAuthUserName(),
12631269
destPool.getAuthSecret(),
1264-
destPool.getSourceDir() + "/" + name);
1270+
rbdDestPath);
12651271
destFile = new QemuImgFile(rbdDestFile, destFormat);
12661272

1267-
s_logger.debug("Starting copy from source image " + srcFile.getFileName() + " to RBD image " + destPool.getSourceDir() + "/" + name);
1273+
s_logger.debug("Starting copy from source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath);
12681274
qemu.convert(srcFile, destFile);
1269-
s_logger.debug("Succesfully converted source image " + srcFile.getFileName() + " to RBD image " + destPool.getSourceDir() + "/" + name);
1275+
s_logger.debug("Succesfully converted source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath);
12701276

1271-
/* We still have to create and protect a RBD snapshot in order to do cloning */
1277+
/* We have to stat the RBD image to see how big it became afterwards */
12721278
Rados r = new Rados(destPool.getAuthUserName());
12731279
r.confSet("mon_host", destPool.getSourceHost() + ":" + destPool.getSourcePort());
12741280
r.confSet("key", destPool.getAuthSecret());
@@ -1280,8 +1286,12 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
12801286
Rbd rbd = new Rbd(io);
12811287

12821288
RbdImage image = rbd.open(name);
1283-
1289+
RbdImageInfo rbdInfo = image.stat();
1290+
newDisk.setSize(rbdInfo.size);
1291+
newDisk.setVirtualSize(rbdInfo.size);
1292+
s_logger.debug("After copy the resulting RBD image " + rbdDestPath + " is " + rbdInfo.size + " bytes long");
12841293
rbd.close(image);
1294+
12851295
r.ioCtxDestroy(io);
12861296
} catch (QemuImgException e) {
12871297
s_logger.error("Failed to convert from " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage());

0 commit comments

Comments
 (0)