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/<VM>.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/<pool-uuid>/<img-uuid>:

    # qemu-img info /mnt/<pool-uuid>/<img-uuid>
    ...
    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 <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2014-02-23 14:32:24 +01:00 committed by Wido den Hollander
parent c02197ae86
commit 14689d7810
4 changed files with 18 additions and 11 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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;

View File

@ -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) {