cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [1/2] git commit: updated refs/heads/4.5 to 3f2e259
Date Mon, 30 Nov 2015 09:41:54 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.5 abb7e3fba -> 3f2e259e1


CLOUDSTACK-9083: Add disk serial to kvm virt xml

Adds disk serial ids based on volume uuids to the virt xml. This may be useful
for appliances/software that needs some serial ids on the VM disks. This does not
impact existing/running VMs, the vm virt xmls will be updates for running VMs
the next time they are stopped/started.

For testing, disk serial (of debian based systemvm) in the virt xml matched that
in /sys/devices/pci0000:00:0000:00:07.0/virtio4/block/vda/serial.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


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

Branch: refs/heads/4.5
Commit: cbb9c4acdf8262dd74d75df1309d46fa6c6102df
Parents: 0da2736
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Wed Nov 25 14:37:40 2015 +0530
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Wed Nov 25 14:46:49 2015 +0530

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java           |  6 ++++++
 .../com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java  | 11 ++++++++++-
 .../hypervisor/kvm/storage/KVMStorageProcessor.java      |  9 ++++++---
 .../kvm/resource/LibvirtComputingResourceTest.java       |  8 ++++++++
 4 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cbb9c4ac/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 45acef0..85b7376 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
@@ -4004,6 +4004,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
 
             if (data instanceof VolumeObjectTO) {
                 VolumeObjectTO volumeObjectTO = (VolumeObjectTO)data;
+                disk.setSerial(diskUuidToSerial(volumeObjectTO.getUuid()));
                 if ((volumeObjectTO.getBytesReadRate() != null) && (volumeObjectTO.getBytesReadRate()
> 0))
                     disk.setBytesReadRate(volumeObjectTO.getBytesReadRate());
                 if ((volumeObjectTO.getBytesWriteRate() != null) && (volumeObjectTO.getBytesWriteRate()
> 0))
@@ -4294,6 +4295,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements
Serv
         }
     }
 
+    public String diskUuidToSerial(String uuid) {
+        String uuidWithoutHyphen = uuid.replace("-","");
+        return uuidWithoutHyphen.substring(0, Math.min(uuidWithoutHyphen.length(), 20));
+    }
+
     private String getIqn() {
         try {
             final String textToFind = "InitiatorName=";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cbb9c4ac/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 8ff720e..688c082 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
@@ -404,7 +404,7 @@ public class LibvirtVMDef {
 
     public static class DiskDef {
         public enum deviceType {
-            FLOPPY("floppy"), DISK("disk"), CDROM("cdrom");
+            FLOPPY("floppy"), DISK("disk"), CDROM("cdrom"), LUN("lun");
             String _type;
 
             deviceType(String type) {
@@ -509,6 +509,7 @@ public class LibvirtVMDef {
         private Long _iopsReadRate;
         private Long _iopsWriteRate;
         private diskCacheMode _diskCacheMode;
+        private String _serial;
         private boolean qemuDriver = true;
 
         public void setDeviceType(deviceType deviceType) {
@@ -693,6 +694,10 @@ public class LibvirtVMDef {
             this.qemuDriver = qemuDriver;
         }
 
+        public void setSerial(String serial) {
+            this._serial = serial;
+        }
+
         @Override
         public String toString() {
             StringBuilder diskBuilder = new StringBuilder();
@@ -746,6 +751,10 @@ public class LibvirtVMDef {
             }
             diskBuilder.append("/>\n");
 
+            if (_serial != null && !_serial.isEmpty() && _deviceType != deviceType.LUN)
{
+                diskBuilder.append("<serial>" + _serial + "</serial>");
+            }
+
             if ((_deviceType != deviceType.CDROM) &&
                     (s_libvirtVersion >= 9008) &&
                     (s_qemuVersion >= 1001000) &&

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cbb9c4ac/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 ebbb3d3..83e151a 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
@@ -931,7 +931,7 @@ public class KVMStorageProcessor implements StorageProcessor {
         return null;
     }
 
-    protected synchronized String attachOrDetachDisk(Connect conn, boolean attach, String
vmName, KVMPhysicalDisk attachingDisk, int devId) throws LibvirtException,
+    protected synchronized String attachOrDetachDisk(Connect conn, boolean attach, String
vmName, KVMPhysicalDisk attachingDisk, int devId, String serial) throws LibvirtException,
         InternalErrorException {
         List<DiskDef> disks = null;
         Domain dm = null;
@@ -967,6 +967,7 @@ public class KVMStorageProcessor implements StorageProcessor {
                 }
             } else {
                 diskdef = new DiskDef();
+                diskdef.setSerial(serial);
                 if (attachingPool.getType() == StoragePoolType.RBD) {
                     if(resource.getHypervisorType() == Hypervisor.HypervisorType.LXC){
                         // For LXC, map image to host and then attach to Vm
@@ -1009,6 +1010,7 @@ public class KVMStorageProcessor implements StorageProcessor {
         VolumeObjectTO vol = (VolumeObjectTO)disk.getData();
         PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)vol.getDataStore();
         String vmName = cmd.getVmName();
+        String serial = resource.diskUuidToSerial(vol.getUuid());
         try {
             Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
 
@@ -1016,7 +1018,7 @@ public class KVMStorageProcessor implements StorageProcessor {
 
             KVMPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(),
primaryStore.getUuid(), vol.getPath());
 
-            attachOrDetachDisk(conn, true, vmName, phyDisk, disk.getDiskSeq().intValue());
+            attachOrDetachDisk(conn, true, vmName, phyDisk, disk.getDiskSeq().intValue(),
serial);
 
             return new AttachAnswer(disk);
         } catch (LibvirtException e) {
@@ -1035,12 +1037,13 @@ public class KVMStorageProcessor implements StorageProcessor {
         VolumeObjectTO vol = (VolumeObjectTO)disk.getData();
         PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)vol.getDataStore();
         String vmName = cmd.getVmName();
+        String serial = resource.diskUuidToSerial(vol.getUuid());
         try {
             Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
 
             KVMPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(),
primaryStore.getUuid(), vol.getPath());
 
-            attachOrDetachDisk(conn, false, vmName, phyDisk, disk.getDiskSeq().intValue());
+            attachOrDetachDisk(conn, false, vmName, phyDisk, disk.getDiskSeq().intValue(),
serial);
 
             storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(),
vol.getPath());
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cbb9c4ac/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index bf4546c..789da34 100644
--- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -360,6 +360,14 @@ public class LibvirtComputingResourceTest {
     }
 
     @Test
+    public void diskUuidToSerialTest() {
+        String uuid = "38400000-8cf0-11bd-b24e-10b96e4ef00d";
+        String expected = "384000008cf011bdb24e";
+        LibvirtComputingResource lcr = new LibvirtComputingResource();
+        Assert.assertEquals(expected, lcr.diskUuidToSerial(uuid));
+    }
+
+    @Test
     public void testUUID() {
         String uuid = "1";
         LibvirtComputingResource lcr = new LibvirtComputingResource();


Mime
View raw message