From 14689d781005006d95d5f67573331fd64e4c57a6 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Sun, 23 Feb 2014 14:32:24 +0100 Subject: [PATCH] Gluster should store volumes in qcow2 format By default all network disks are in RAW format. Gluster works fine with QCOW2 which has some advantages. Disks are by default in QCOW2 format. It is possible to run into a mismatch, where the disk is in QCOW2 format, but QEMU gets started with format=raw. This causes the virtual machines to lockup on boot. Failures to start a virtual machine can be verified by checking the log of the virtual machine, and compare the output of 'qemu-img info'. In /var/log/libvirt/qemu/.log find the URL for the drive: -drive file=gluster+tcp://...,format=raw,.. Compare this with the 'qemu-img info' output of the same file, mounted under /mnt//: # qemu-img info /mnt// ... file format: qcow2 ... This change makes passes the format when creating a disk located on RBD (RAW only) and Gluster (QCOW2). Signed-off-by: Niels de Vos --- .../kvm/resource/LibvirtComputingResource.java | 8 ++++---- .../hypervisor/kvm/resource/LibvirtDomainXMLParser.java | 9 ++++++++- .../com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java | 8 ++++---- .../hypervisor/kvm/storage/KVMStorageProcessor.java | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index e6c750befac..26407a19f69 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -3704,13 +3704,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv we pass the pool's UUID as the authSecret */ disk.defNetworkBasedDisk(physicalDisk.getPath().replace("rbd:", ""), pool.getSourceHost(), pool.getSourcePort(), pool.getAuthUserName(), - pool.getUuid(), devId, diskBusType, diskProtocol.RBD); + pool.getUuid(), devId, diskBusType, diskProtocol.RBD, DiskDef.diskFmtType.RAW); } else if (pool.getType() == StoragePoolType.Gluster) { String mountpoint = pool.getLocalPath(); String path = physicalDisk.getPath(); String glusterVolume = pool.getSourceDir().replace("/", ""); disk.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), pool.getSourceHost(), pool.getSourcePort(), null, - null, devId, diskBusType, diskProtocol.GLUSTER); + null, devId, diskBusType, diskProtocol.GLUSTER, DiskDef.diskFmtType.QCOW2); } else if (pool.getType() == StoragePoolType.CLVM || physicalDisk.getFormat() == PhysicalDiskFormat.RAW) { disk.defBlockBasedDisk(physicalDisk.getPath(), devId, diskBusType); } else { @@ -3867,10 +3867,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv diskdef = new DiskDef(); if (attachingPool.getType() == StoragePoolType.RBD) { diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(), - attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD); + attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD, DiskDef.diskFmtType.RAW); } else if (attachingPool.getType() == StoragePoolType.Gluster) { diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), null, - null, devId, DiskDef.diskBus.VIRTIO, diskProtocol.GLUSTER); + null, devId, DiskDef.diskBus.VIRTIO, diskProtocol.GLUSTER, DiskDef.diskFmtType.QCOW2); } else if (attachingDisk.getFormat() == PhysicalDiskFormat.QCOW2) { diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, DiskDef.diskBus.VIRTIO, DiskDef.diskFmtType.QCOW2); } else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) { diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java index 9cf6a90ffe5..fabe9a881db 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java @@ -64,6 +64,7 @@ public class LibvirtDomainXMLParser { String type = disk.getAttribute("type"); DiskDef def = new DiskDef(); if (type.equalsIgnoreCase("network")) { + String diskFmtType = getAttrValue("driver", "type", disk); String diskCacheMode = getAttrValue("driver", "cache", disk); String diskPath = getAttrValue("source", "name", disk); String protocol = getAttrValue("source", "protocol", disk); @@ -73,9 +74,15 @@ public class LibvirtDomainXMLParser { int port = Integer.parseInt(getAttrValue("host", "port", disk)); String diskLabel = getAttrValue("target", "dev", disk); String bus = getAttrValue("target", "bus", disk); + + DiskDef.diskFmtType fmt = null; + if (diskFmtType != null) { + fmt = DiskDef.diskFmtType.valueOf(diskFmtType.toUpperCase()); + } + def.defNetworkBasedDisk(diskPath, host, port, authUserName, poolUuid, diskLabel, DiskDef.diskBus.valueOf(bus.toUpperCase()), - DiskDef.diskProtocol.valueOf(protocol.toUpperCase())); + DiskDef.diskProtocol.valueOf(protocol.toUpperCase()), fmt); def.setCacheMode(DiskDef.diskCacheMode.valueOf(diskCacheMode.toUpperCase())); } else { String diskFmtType = getAttrValue("driver", "type", disk); diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 290c5a93663..4032305b032 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -530,10 +530,10 @@ public class LibvirtVMDef { } public void defNetworkBasedDisk(String diskName, String sourceHost, int sourcePort, String authUserName, String authSecretUUID, int devId, diskBus bus, - diskProtocol protocol) { + diskProtocol protocol, diskFmtType diskFmtType) { _diskType = diskType.NETWORK; _deviceType = deviceType.DISK; - _diskFmtType = diskFmtType.RAW; + _diskFmtType = diskFmtType; _diskCacheMode = diskCacheMode.NONE; _sourcePath = diskName; _sourceHost = sourceHost; @@ -546,10 +546,10 @@ public class LibvirtVMDef { } public void defNetworkBasedDisk(String diskName, String sourceHost, int sourcePort, String authUserName, String authSecretUUID, String diskLabel, diskBus bus, - diskProtocol protocol) { + diskProtocol protocol, diskFmtType diskFmtType) { _diskType = diskType.NETWORK; _deviceType = deviceType.DISK; - _diskFmtType = diskFmtType.RAW; + _diskFmtType = diskFmtType; _diskCacheMode = diskCacheMode.NONE; _sourcePath = diskName; _sourceHost = sourceHost; 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 50671fa1382..3525d12b625 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 @@ -930,13 +930,13 @@ public class KVMStorageProcessor implements StorageProcessor { diskdef = new DiskDef(); if (attachingPool.getType() == StoragePoolType.RBD) { diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(), - attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD); + attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD, DiskDef.diskFmtType.RAW); } else if (attachingPool.getType() == StoragePoolType.Gluster) { String mountpoint = attachingPool.getLocalPath(); String path = attachingDisk.getPath(); String glusterVolume = attachingPool.getSourceDir().replace("/", ""); diskdef.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), attachingPool.getSourceHost(), attachingPool.getSourcePort(), null, - null, devId, DiskDef.diskBus.VIRTIO, diskProtocol.GLUSTER); + null, devId, DiskDef.diskBus.VIRTIO, diskProtocol.GLUSTER, DiskDef.diskFmtType.QCOW2); } else if (attachingDisk.getFormat() == PhysicalDiskFormat.QCOW2) { diskdef.defFileBasedDisk(attachingDisk.getPath(), devId, DiskDef.diskBus.VIRTIO, DiskDef.diskFmtType.QCOW2); } else if (attachingDisk.getFormat() == PhysicalDiskFormat.RAW) {