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 d60870791c5..a79526a0b15 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 @@ -3982,16 +3982,29 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } - // For LXC, find and add the root filesystem + // For LXC, find and add the root filesystem, rbd data disks if (HypervisorType.LXC.toString().toLowerCase().equals(vm.getHvsType())) { for (DiskTO volume : disks) { + DataTO data = volume.getData(); + PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore(); if (volume.getType() == Volume.Type.ROOT) { - DataTO data = volume.getData(); - PrimaryDataStoreTO store = (PrimaryDataStoreTO)data.getDataStore(); KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath()); FilesystemDef rootFs = new FilesystemDef(physicalDisk.getPath(), "/"); vm.getDevices().addDevice(rootFs); - break; + } else if (volume.getType() == Volume.Type.DATADISK) { + KVMPhysicalDisk physicalDisk = _storagePoolMgr.getPhysicalDisk(store.getPoolType(), store.getUuid(), data.getPath()); + KVMStoragePool pool = physicalDisk.getPool(); + if(StoragePoolType.RBD.equals(pool.getType())) { + int devId = volume.getDiskSeq().intValue(); + String device = mapRbdDevice(physicalDisk); + if (device != null) { + s_logger.debug("RBD device on host is: " + device); + DiskDef diskdef = new DiskDef(); + diskdef.defBlockBasedDisk(device, devId, DiskDef.diskBus.VIRTIO); + diskdef.setQemuDriver(false); + vm.getDevices().addDevice(diskdef); + } + } } } } @@ -5241,4 +5254,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return true; } + public String mapRbdDevice(KVMPhysicalDisk disk){ + KVMStoragePool pool = disk.getPool(); + //Check if rbd image is already mapped + String[] splitPoolImage = disk.getPath().split("/"); + String device = Script.runSimpleBashScript("rbd showmapped | grep \""+splitPoolImage[0]+"[ ]*"+splitPoolImage[1]+"\" | grep -o \"[^ ]*[ ]*$\""); + if(device == null) { + //If not mapped, map and return mapped device + String mapRbd = Script.runSimpleBashScript("rbd map " + disk.getPath() + " --id "+pool.getAuthUserName()); + device = Script.runSimpleBashScript("rbd showmapped | grep \""+splitPoolImage[0]+"[ ]*"+splitPoolImage[1]+"\" | grep -o \"[^ ]*[ ]*$\""); + } + return device; + } } 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 3480a977990..bc952042215 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 @@ -336,9 +336,15 @@ public class LibvirtVMDef { for (List devs : devices.values()) { for (Object dev : devs) { if (_guestType == GuestDef.guestType.LXC) { - if (dev instanceof GraphicDef || dev instanceof InputDef || dev instanceof DiskDef) { + if (dev instanceof GraphicDef || dev instanceof InputDef) { continue; } + if(dev instanceof DiskDef){ + DiskDef disk = (DiskDef)dev; + if(!disk.getDiskType().toString().equals("block")){ + continue; + } + } } devicesBuilder.append(dev.toString()); } @@ -466,6 +472,7 @@ public class LibvirtVMDef { private Long _iopsReadRate; private Long _iopsWriteRate; private diskCacheMode _diskCacheMode; + private boolean qemuDriver = true; public void setDeviceType(deviceType deviceType) { _deviceType = deviceType; @@ -645,6 +652,10 @@ public class LibvirtVMDef { return _diskCacheMode; } + public void setQemuDriver(boolean qemuDriver){ + this.qemuDriver = qemuDriver; + } + @Override public String toString() { StringBuilder diskBuilder = new StringBuilder(); @@ -654,8 +665,11 @@ public class LibvirtVMDef { } diskBuilder.append(" type='" + _diskType + "'"); diskBuilder.append(">\n"); - diskBuilder.append("\n"); + if(qemuDriver) { + diskBuilder.append("\n"); + } + if (_diskType == diskType.FILE) { diskBuilder.append("