Skip to content

Commit 50b9205

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-6122: Map rbd image on host before attaching to Vm
1 parent b4d3aac commit 50b9205

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5458,4 +5458,8 @@ public void setRunLevel(int level) {
54585458

54595459
}
54605460

5461+
public HypervisorType getHypervisorType(){
5462+
return _hypervisorType;
5463+
}
5464+
54615465
}

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import javax.naming.ConfigurationException;
4040

41+
import com.cloud.hypervisor.Hypervisor;
4142
import org.apache.commons.io.FileUtils;
4243
import org.apache.log4j.Logger;
4344
import org.libvirt.Connect;
@@ -955,8 +956,23 @@ protected synchronized String attachOrDetachDisk(Connect conn, boolean attach, S
955956
} else {
956957
diskdef = new DiskDef();
957958
if (attachingPool.getType() == StoragePoolType.RBD) {
958-
diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(),
959-
attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD, DiskDef.diskFmtType.RAW);
959+
if(resource.getHypervisorType() == Hypervisor.HypervisorType.LXC){
960+
// For LXC, map image to host and then attach to Vm
961+
String mapRbd = Script.runSimpleBashScript("rbd map " + attachingDisk.getPath() + " --id "+attachingPool.getAuthUserName());
962+
//Split pool and image details from disk path
963+
String[] splitPoolImage = attachingDisk.getPath().split("/");
964+
//ToDo: rbd showmapped supports json and xml output. Use json/xml to get device
965+
String device = Script.runSimpleBashScript("rbd showmapped | grep \""+splitPoolImage[0]+" "+splitPoolImage[1]+"\" | cut -d \" \" -f10");
966+
if (device != null) {
967+
s_logger.debug("RBD device on host is: "+device);
968+
diskdef.defBlockBasedDisk(device, devId, DiskDef.diskBus.VIRTIO);
969+
} else {
970+
throw new InternalErrorException("Error while mapping disk "+attachingDisk.getPath()+" on host");
971+
}
972+
} else {
973+
diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(),
974+
attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD, DiskDef.diskFmtType.RAW);
975+
}
960976
} else if (attachingPool.getType() == StoragePoolType.Gluster) {
961977
String mountpoint = attachingPool.getLocalPath();
962978
String path = attachingDisk.getPath();

0 commit comments

Comments
 (0)