CLOUDSTACK-7543: Attach RBD disk for LXC during start. Moved rbd map code seperate method. When adding block device, qemu driver should not be used for LXC

This commit is contained in:
Kishan Kavala 2014-09-15 10:15:54 +05:30
parent 8a3793c582
commit f0e82f340a
3 changed files with 49 additions and 15 deletions

View File

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

View File

@ -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("<driver name='qemu'" + " type='" + _diskFmtType
+ "' cache='" + _diskCacheMode + "' " + "/>\n");
if(qemuDriver) {
diskBuilder.append("<driver name='qemu'" + " type='" + _diskFmtType
+ "' cache='" + _diskCacheMode + "' " + "/>\n");
}
if (_diskType == diskType.FILE) {
diskBuilder.append("<source ");
if (_sourcePath != null) {

View File

@ -945,9 +945,7 @@ public class KVMStorageProcessor implements StorageProcessor {
if (attachingPool.getType() == StoragePoolType.RBD) {
if (resource.getHypervisorType() == Hypervisor.HypervisorType.LXC) {
String[] splitPoolImage = attachingDisk.getPath().split("/");
//ToDo: rbd showmapped supports json and xml output. Use json/xml to get device
String device = Script.runSimpleBashScript("rbd showmapped | grep \""+splitPoolImage[0]+"[ ]*"+splitPoolImage[1]+"\" | grep -o \"[^ ]*[ ]*$\"");
String device = resource.mapRbdDevice(attachingDisk);
if (device != null) {
s_logger.debug("RBD device on host is: "+device);
attachingDisk.setPath(device);
@ -970,11 +968,7 @@ public class KVMStorageProcessor implements StorageProcessor {
if (attachingPool.getType() == StoragePoolType.RBD) {
if(resource.getHypervisorType() == Hypervisor.HypervisorType.LXC){
// For LXC, map image to host and then attach to Vm
String mapRbd = Script.runSimpleBashScript("rbd map " + attachingDisk.getPath() + " --id "+attachingPool.getAuthUserName());
//Split pool and image details from disk path
String[] splitPoolImage = attachingDisk.getPath().split("/");
//ToDo: rbd showmapped supports json and xml output. Use json/xml to get device
String device = Script.runSimpleBashScript("rbd showmapped | grep \""+splitPoolImage[0]+"[ ]*"+splitPoolImage[1]+"\" | grep -o \"[^ ]*[ ]*$\"");
String device = resource.mapRbdDevice(attachingDisk);
if (device != null) {
s_logger.debug("RBD device on host is: "+device);
diskdef.defBlockBasedDisk(device, devId, DiskDef.diskBus.VIRTIO);
@ -1272,4 +1266,5 @@ public class KVMStorageProcessor implements StorageProcessor {
public Answer forgetObject(ForgetObjectCmd cmd) {
return new Answer(cmd, false, "not implememented yet");
}
}