incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [30/50] [abbrv] git commit: fix patch disks from reproducing like rabbits RB: https://reviews.apache.org/r/7040 Signed-off-by: Edison Su <sudison@gmail.com>
Date Thu, 13 Sep 2012 18:43:49 GMT
fix patch disks from reproducing like rabbits
RB: https://reviews.apache.org/r/7040
Signed-off-by: Edison Su <sudison@gmail.com>


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

Branch: refs/heads/javelin
Commit: 4c3ab1afb67a8fd3c1b04006c0f4fa8cb2bfd37d
Parents: 651ac2a
Author: Marcus Sorensen <shadowsor@gmail.com>
Authored: Wed Sep 12 16:48:38 2012 -0700
Committer: Edison Su <sudison@gmail.com>
Committed: Wed Sep 12 16:48:38 2012 -0700

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java     |   42 +++++++++++----
 .../kvm/storage/KVMStoragePoolManager.java         |    4 ++
 .../kvm/storage/LibvirtStorageAdaptor.java         |   17 ++++++
 .../hypervisor/kvm/storage/StorageAdaptor.java     |    2 +
 4 files changed, 55 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4c3ab1af/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 ad2b07b..9312519 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
@@ -2585,8 +2585,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements
             if (result == null) {
                 for (DiskDef disk : disks) {
                     if (disk.getDeviceType() == DiskDef.deviceType.CDROM
-                            && disk.getDiskPath() != null)
+                            && disk.getDiskPath() != null) {
                         cleanupDisk(conn, disk);
+                    } else if (disk.getDiskPath().contains(vmName + "-patchdisk") 
+                            && vmName.matches("^[rsv]-\\d+-VM$")) {
+                        if (!_storagePoolMgr.deleteVbdByPath(disk.getDiskPath())) {
+                            s_logger.warn("failed to delete patch disk " + disk.getDiskPath());
+                        }
+                    }
                 }
             }
 
@@ -2947,29 +2953,45 @@ public class LibvirtComputingResource extends ServerResourceBase implements
         List<DiskDef> disks = vm.getDevices().getDisks();
         DiskDef rootDisk = disks.get(0);
         VolumeTO rootVol = getVolume(vmSpec, Volume.Type.ROOT);
-        KVMStoragePool pool = _storagePoolMgr.getStoragePool(rootVol
-                .getPoolUuid());
-        KVMPhysicalDisk disk = pool.createPhysicalDisk(UUID.randomUUID()
-                .toString(), KVMPhysicalDisk.PhysicalDiskFormat.RAW,
+        String patchName = vmName + "-patchdisk";
+        KVMStoragePool pool = _storagePoolMgr.getStoragePool(rootVol.getPoolUuid());
+        String patchDiskPath = pool.getLocalPath() + "/" + patchName;
+
+        List<KVMPhysicalDisk> phyDisks = pool.listPhysicalDisks();
+        boolean foundDisk = false;
+
+        for (KVMPhysicalDisk phyDisk : phyDisks) {
+            if (phyDisk.getPath().equals(patchDiskPath)) {
+                foundDisk = true;
+                break;
+            } 
+        }
+
+        if (!foundDisk) {
+            s_logger.debug("generating new patch disk for " + vmName + " since none was found");
+            KVMPhysicalDisk disk = pool.createPhysicalDisk(patchName, KVMPhysicalDisk.PhysicalDiskFormat.RAW,
                 10L * 1024 * 1024);
+        } else {
+            s_logger.debug("found existing patch disk at " + patchDiskPath + " using it for
" + vmName);
+        }
+
         /* Format/create fs on this disk */
         final Script command = new Script(_createvmPath, _timeout, s_logger);
-        command.add("-f", disk.getPath());
+        command.add("-f", patchDiskPath);
         String result = command.execute();
         if (result != null) {
             s_logger.debug("Failed to create data disk: " + result);
             throw new InternalErrorException("Failed to create data disk: "
                     + result);
         }
-        String datadiskPath = disk.getPath();
 
         /* add patch disk */
         DiskDef patchDisk = new DiskDef();
 
         if (pool.getType() == StoragePoolType.CLVM) {
-            patchDisk.defBlockBasedDisk(datadiskPath, 1, rootDisk.getBusType());
+            patchDisk.defBlockBasedDisk(patchDiskPath, 1, rootDisk.getBusType());
         } else {
-            patchDisk.defFileBasedDisk(datadiskPath, 1, rootDisk.getBusType(),
+            patchDisk.defFileBasedDisk(patchDiskPath, 1, rootDisk.getBusType(),
             DiskDef.diskFmtType.RAW);
         }
  
@@ -2977,7 +2999,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
 
         String bootArgs = vmSpec.getBootArgs();
 
-        patchSystemVm(bootArgs, datadiskPath, vmName);
+        patchSystemVm(bootArgs, patchDiskPath, vmName);
     }
 
     private void createVif(LibvirtVMDef vm, NicTO nic)

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4c3ab1af/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
index 751da83..8246a5c 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java
@@ -73,6 +73,10 @@ public class KVMStoragePoolManager {
         return true;
     }
 
+    public boolean deleteVbdByPath(String diskPath) {
+        return this._storageAdaptor.deleteVbdByPath(diskPath);
+    }
+
     public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name,
                                                     KVMStoragePool destPool) {
         if (destPool.getType() == StoragePoolType.RBD) {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4c3ab1af/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
index 9f62ee8..d6236a0 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
@@ -882,4 +882,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
 
         return true;
     }
+
+    public boolean deleteVbdByPath(String diskPath) {
+        Connect conn;
+        try {
+            conn = LibvirtConnection.getConnection();
+            StorageVol vol = conn.storageVolLookupByPath(diskPath);
+            if(vol != null) {
+                s_logger.debug("requested delete disk " + diskPath);
+                vol.delete(0);
+            }
+        } catch (LibvirtException e) {
+            s_logger.debug("Libvirt error in attempting to find and delete patch disk:" +
e.toString());
+            return false;
+        }
+        return true;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/4c3ab1af/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java
b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java
index be6c5c0..ec10332 100644
--- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java
+++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java
@@ -65,4 +65,6 @@ public interface StorageAdaptor {
 
     public boolean createFolder(String uuid, String path);
 
+    public boolean deleteVbdByPath(String path);
+
 }


Mime
View raw message