cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject git commit: updated refs/heads/master to f0e82f3
Date Mon, 15 Sep 2014 04:52:34 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 8a3793c58 -> f0e82f340


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


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f0e82f34
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f0e82f34
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f0e82f34

Branch: refs/heads/master
Commit: f0e82f340aa1a470aebbd5900aca6693211fbb08
Parents: 8a3793c
Author: Kishan Kavala <kishan@apache.org>
Authored: Mon Sep 15 10:15:54 2014 +0530
Committer: Kishan Kavala <kishan@apache.org>
Committed: Mon Sep 15 10:15:54 2014 +0530

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java  | 33 +++++++++++++++++---
 .../hypervisor/kvm/resource/LibvirtVMDef.java   | 20 ++++++++++--
 .../kvm/storage/KVMStorageProcessor.java        | 11 ++-----
 3 files changed, 49 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0e82f34/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
----------------------------------------------------------------------
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 d608707..a79526a 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;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0e82f34/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java
----------------------------------------------------------------------
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 3480a97..bc95204 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("<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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f0e82f34/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
----------------------------------------------------------------------
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 2280672..e7ed264 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
@@ -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");
     }
+
 }


Mime
View raw message