Skip to content

Commit fb9ceba

Browse files
committed
CLOUDSTACK-4424: Download RBD volume created from snapshot
This failed due to a RAW -> QCOW2 conversion (again). The current code still makes to much assumptions about everything always being QCOW2 while that is not always true.
1 parent 658844e commit fb9ceba

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMPhysicalDisk.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public static String RBDStringBuilder(String monHost, int monPort,
2727
String rbdOpts;
2828

2929
rbdOpts = "rbd:" + image;
30-
rbdOpts += ":mon_host=" + monHost + "\\\\:" + monPort;
30+
rbdOpts += ":mon_host=" + monHost;
31+
if (monPort != 6789) {
32+
rbdOpts += "\\\\:" + monPort;
33+
}
34+
3135
if (authUserName == null) {
3236
rbdOpts += ":auth_supported=none";
3337
} else {

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
375375
public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
376376
DataTO srcData = cmd.getSrcTO();
377377
DataTO destData = cmd.getDestTO();
378+
VolumeObjectTO srcVol = (VolumeObjectTO) srcData;
379+
VolumeObjectTO destVol = (VolumeObjectTO) destData;
380+
ImageFormat srcFormat = srcVol.getFormat();
381+
ImageFormat destFormat = destVol.getFormat();
378382
DataStoreTO srcStore = srcData.getDataStore();
379383
DataStoreTO destStore = destData.getDataStore();
380384
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) srcStore;
@@ -405,9 +409,9 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
405409

406410
String volumeName = UUID.randomUUID().toString();
407411

408-
409-
String destVolumeName = volumeName + ".qcow2";
412+
String destVolumeName = volumeName + "." + destFormat.getFileExtension();
410413
KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(srcVolumePath);
414+
volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
411415
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(
412416
secondaryStorageUrl);
413417
secondaryStoragePool.createFolder(destVolumePath);
@@ -418,6 +422,7 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
418422
destVolumeName,secondaryStoragePool);
419423
VolumeObjectTO newVol = new VolumeObjectTO();
420424
newVol.setPath(destVolumePath + File.separator + destVolumeName);
425+
newVol.setFormat(destFormat);
421426
return new CopyCmdAnswer(newVol);
422427
} catch (CloudRuntimeException e) {
423428
return new CopyCmdAnswer(e.toString());
@@ -661,7 +666,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
661666
*
662667
* These bindings will read the snapshot and write the contents to
663668
* the secondary storage directly
664-
*
669+
*
665670
* It will stop doing so if the amount of time spend is longer then
666671
* cmds.timeout
667672
*/

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,13 @@ public KVMStoragePool createStoragePool(String name, String host, int port,
479479
// if anyone is, undefine the pool so we can define it as requested.
480480
// This should be safe since a pool in use can't be removed, and no
481481
// volumes are affected by unregistering the pool with libvirt.
482-
s_logger.debug("Didn't find an existing storage pool " + name
482+
s_logger.debug("Didn't find an existing storage pool " + name
483483
+ " by UUID, checking for pools with duplicate paths");
484484

485485
try {
486486
String[] poolnames = conn.listStoragePools();
487487
for (String poolname : poolnames) {
488-
s_logger.debug("Checking path of existing pool " + poolname
488+
s_logger.debug("Checking path of existing pool " + poolname
489489
+ " against pool we want to create");
490490
StoragePool p = conn.storagePoolLookupByName(poolname);
491491
LibvirtStoragePoolDef pdef = getStoragePoolDef(conn, p);
@@ -503,7 +503,7 @@ public KVMStoragePool createStoragePool(String name, String host, int port,
503503
}
504504
}
505505
} catch (LibvirtException e) {
506-
s_logger.error("Failure in attempting to see if an existing storage pool might "
506+
s_logger.error("Failure in attempting to see if an existing storage pool might "
507507
+ "be using the path of the pool to be created:" + e);
508508
}
509509

@@ -546,14 +546,14 @@ public KVMStoragePool createStoragePool(String name, String host, int port,
546546
pool.setCapacity(sp.getInfo().capacity);
547547
pool.setUsed(sp.getInfo().allocation);
548548
pool.setAvailable(sp.getInfo().available);
549-
549+
550550
return pool;
551551
} catch (LibvirtException e) {
552552
String error = e.toString();
553553
if (error.contains("Storage source conflict")) {
554554
throw new CloudRuntimeException("A pool matching this location already exists in libvirt, "
555-
+ " but has a different UUID/Name. Cannot create new pool without first "
556-
+ " removing it. Check for inactive pools via 'virsh pool-list --all'. "
555+
+ " but has a different UUID/Name. Cannot create new pool without first "
556+
+ " removing it. Check for inactive pools via 'virsh pool-list --all'. "
557557
+ error);
558558
} else {
559559
throw new CloudRuntimeException(error);
@@ -824,7 +824,7 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
824824
if ((srcPool.getSourceHost().equals(destPool.getSourceHost())) && (srcPool.getSourceDir().equals(destPool.getSourceDir()))) {
825825
/* We are on the same Ceph cluster, but we require RBD format 2 on the source image */
826826
s_logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool");
827-
827+
828828
Rados r = new Rados(srcPool.getAuthUserName());
829829
r.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort());
830830
r.confSet("key", srcPool.getAuthSecret());
@@ -894,7 +894,7 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
894894

895895
sRbd.close(srcImage);
896896
dRbd.close(destImage);
897-
897+
898898
rSrc.ioCtxDestroy(sIO);
899899
rDest.ioCtxDestroy(dIO);
900900
}
@@ -965,12 +965,21 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
965965
for Secondary Storage
966966
*/
967967

968+
KVMStoragePool srcPool = disk.getPool();
969+
PhysicalDiskFormat sourceFormat = disk.getFormat();
970+
String sourcePath = disk.getPath();
971+
968972
KVMPhysicalDisk newDisk;
969973
if (destPool.getType() != StoragePoolType.RBD) {
970974
if (disk.getFormat() == PhysicalDiskFormat.TAR) {
971975
newDisk = destPool.createPhysicalDisk(name, PhysicalDiskFormat.DIR, disk.getVirtualSize());
972976
} else {
973-
newDisk = destPool.createPhysicalDisk(name, disk.getVirtualSize());
977+
/* If the source device is on a RBD storage pool force the new disk to the same format (RAW) */
978+
if (srcPool.getType() != StoragePoolType.RBD) {
979+
newDisk = destPool.createPhysicalDisk(name, disk.getVirtualSize());
980+
} else {
981+
newDisk = destPool.createPhysicalDisk(name, sourceFormat, disk.getVirtualSize());
982+
}
974983
}
975984
} else {
976985
newDisk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + name, name, destPool);
@@ -979,10 +988,7 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
979988
newDisk.setVirtualSize(disk.getSize());
980989
}
981990

982-
KVMStoragePool srcPool = disk.getPool();
983991
String destPath = newDisk.getPath();
984-
String sourcePath = disk.getPath();
985-
PhysicalDiskFormat sourceFormat = disk.getFormat();
986992
PhysicalDiskFormat destFormat = newDisk.getFormat();
987993

988994
QemuImg qemu = new QemuImg();
@@ -1116,11 +1122,7 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
11161122
srcPool.getAuthSecret(),
11171123
sourcePath));
11181124
srcFile.setFormat(sourceFormat);
1119-
destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(),
1120-
destPool.getSourcePort(),
1121-
destPool.getAuthUserName(),
1122-
destPool.getAuthSecret(),
1123-
destPath));
1125+
destFile = new QemuImgFile(destPath);
11241126
destFile.setFormat(destFormat);
11251127

11261128
try {

0 commit comments

Comments
 (0)