diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMPhysicalDisk.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMPhysicalDisk.java index 7f088fad28a..6b4d61e71a3 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMPhysicalDisk.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMPhysicalDisk.java @@ -27,7 +27,11 @@ public class KVMPhysicalDisk { String rbdOpts; rbdOpts = "rbd:" + image; - rbdOpts += ":mon_host=" + monHost + "\\\\:" + monPort; + rbdOpts += ":mon_host=" + monHost; + if (monPort != 6789) { + rbdOpts += "\\\\:" + monPort; + } + if (authUserName == null) { rbdOpts += ":auth_supported=none"; } else { diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index 95a426ac219..50a3e928ad2 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -375,6 +375,10 @@ public class KVMStorageProcessor implements StorageProcessor { public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) { DataTO srcData = cmd.getSrcTO(); DataTO destData = cmd.getDestTO(); + VolumeObjectTO srcVol = (VolumeObjectTO) srcData; + VolumeObjectTO destVol = (VolumeObjectTO) destData; + ImageFormat srcFormat = srcVol.getFormat(); + ImageFormat destFormat = destVol.getFormat(); DataStoreTO srcStore = srcData.getDataStore(); DataStoreTO destStore = destData.getDataStore(); PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) srcStore; @@ -405,9 +409,9 @@ public class KVMStorageProcessor implements StorageProcessor { String volumeName = UUID.randomUUID().toString(); - - String destVolumeName = volumeName + ".qcow2"; + String destVolumeName = volumeName + "." + destFormat.getFileExtension(); KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(srcVolumePath); + volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString())); secondaryStoragePool = storagePoolMgr.getStoragePoolByURI( secondaryStorageUrl); secondaryStoragePool.createFolder(destVolumePath); @@ -418,6 +422,7 @@ public class KVMStorageProcessor implements StorageProcessor { destVolumeName,secondaryStoragePool); VolumeObjectTO newVol = new VolumeObjectTO(); newVol.setPath(destVolumePath + File.separator + destVolumeName); + newVol.setFormat(destFormat); return new CopyCmdAnswer(newVol); } catch (CloudRuntimeException e) { return new CopyCmdAnswer(e.toString()); @@ -661,7 +666,7 @@ public class KVMStorageProcessor implements StorageProcessor { * * These bindings will read the snapshot and write the contents to * the secondary storage directly - * + * * It will stop doing so if the amount of time spend is longer then * cmds.timeout */ diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index d487e3cd7b2..719a03d60d0 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -479,13 +479,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { // if anyone is, undefine the pool so we can define it as requested. // This should be safe since a pool in use can't be removed, and no // volumes are affected by unregistering the pool with libvirt. - s_logger.debug("Didn't find an existing storage pool " + name + s_logger.debug("Didn't find an existing storage pool " + name + " by UUID, checking for pools with duplicate paths"); try { String[] poolnames = conn.listStoragePools(); for (String poolname : poolnames) { - s_logger.debug("Checking path of existing pool " + poolname + s_logger.debug("Checking path of existing pool " + poolname + " against pool we want to create"); StoragePool p = conn.storagePoolLookupByName(poolname); LibvirtStoragePoolDef pdef = getStoragePoolDef(conn, p); @@ -503,7 +503,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } } } catch (LibvirtException e) { - s_logger.error("Failure in attempting to see if an existing storage pool might " + s_logger.error("Failure in attempting to see if an existing storage pool might " + "be using the path of the pool to be created:" + e); } @@ -546,14 +546,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { pool.setCapacity(sp.getInfo().capacity); pool.setUsed(sp.getInfo().allocation); pool.setAvailable(sp.getInfo().available); - + return pool; } catch (LibvirtException e) { String error = e.toString(); if (error.contains("Storage source conflict")) { throw new CloudRuntimeException("A pool matching this location already exists in libvirt, " - + " but has a different UUID/Name. Cannot create new pool without first " - + " removing it. Check for inactive pools via 'virsh pool-list --all'. " + + " but has a different UUID/Name. Cannot create new pool without first " + + " removing it. Check for inactive pools via 'virsh pool-list --all'. " + error); } else { throw new CloudRuntimeException(error); @@ -824,7 +824,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { if ((srcPool.getSourceHost().equals(destPool.getSourceHost())) && (srcPool.getSourceDir().equals(destPool.getSourceDir()))) { /* We are on the same Ceph cluster, but we require RBD format 2 on the source image */ s_logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool"); - + Rados r = new Rados(srcPool.getAuthUserName()); r.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort()); r.confSet("key", srcPool.getAuthSecret()); @@ -894,7 +894,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { sRbd.close(srcImage); dRbd.close(destImage); - + rSrc.ioCtxDestroy(sIO); rDest.ioCtxDestroy(dIO); } @@ -965,12 +965,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { for Secondary Storage */ + KVMStoragePool srcPool = disk.getPool(); + PhysicalDiskFormat sourceFormat = disk.getFormat(); + String sourcePath = disk.getPath(); + KVMPhysicalDisk newDisk; if (destPool.getType() != StoragePoolType.RBD) { if (disk.getFormat() == PhysicalDiskFormat.TAR) { newDisk = destPool.createPhysicalDisk(name, PhysicalDiskFormat.DIR, disk.getVirtualSize()); } else { - newDisk = destPool.createPhysicalDisk(name, disk.getVirtualSize()); + /* If the source device is on a RBD storage pool force the new disk to the same format (RAW) */ + if (srcPool.getType() != StoragePoolType.RBD) { + newDisk = destPool.createPhysicalDisk(name, disk.getVirtualSize()); + } else { + newDisk = destPool.createPhysicalDisk(name, sourceFormat, disk.getVirtualSize()); + } } } else { newDisk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + name, name, destPool); @@ -979,10 +988,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { newDisk.setVirtualSize(disk.getSize()); } - KVMStoragePool srcPool = disk.getPool(); String destPath = newDisk.getPath(); - String sourcePath = disk.getPath(); - PhysicalDiskFormat sourceFormat = disk.getFormat(); PhysicalDiskFormat destFormat = newDisk.getFormat(); QemuImg qemu = new QemuImg(); @@ -1116,11 +1122,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { srcPool.getAuthSecret(), sourcePath)); srcFile.setFormat(sourceFormat); - destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(), - destPool.getSourcePort(), - destPool.getAuthUserName(), - destPool.getAuthSecret(), - destPath)); + destFile = new QemuImgFile(destPath); destFile.setFormat(destFormat); try {