incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chipchild...@apache.org
Subject [1/3] git commit: refs/heads/4.1 - agent: Do not define domains persistent in libvirt
Date Fri, 15 Mar 2013 14:01:03 GMT
agent: Do not define domains persistent in libvirt

We used to define domains persistent in libvirt, which caused XML definitions
to stay there after a reboot of the hypervisor.

We however don't do anything with those already defined domains, actually, we wipe
all defined domains when starting the agent.

Some users however reported that libvirt started these domains after a reboot
before the CloudStack agent was started.

By starting domains from the XML description and not defining them we prevent
them from ever being stored in libvirt.


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

Branch: refs/heads/4.1
Commit: cefece71488e6d91e9551a74ae21f4ead01e4a7a
Parents: 9e1d593
Author: Wido den Hollander <wido@widodh.nl>
Authored: Thu Feb 7 22:58:20 2013 +0100
Committer: Chip Childers <chip.childers@gmail.com>
Committed: Fri Mar 15 09:55:51 2013 -0400

----------------------------------------------------------------------
 .../kvm/resource/LibvirtComputingResource.java     |  100 ++-------------
 1 files changed, 13 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cefece71/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 64928ea..f131ea0 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
@@ -367,10 +367,6 @@ ServerResource {
         NATIVE, OPENVSWITCH
     }
 
-    protected enum defineOps {
-        UNDEFINE_VM, DEFINE_VM
-    }
-
     protected BridgeType _bridgeType;
 
     private String getEndIpFromStartIp(String startIp, int numIps) {
@@ -977,75 +973,22 @@ ServerResource {
 
     protected String startDomain(Connect conn, String vmName, String domainXML)
             throws LibvirtException, InternalErrorException {
-        /* No duplicated vm, we will success, or failed */
-        boolean failed = false;
         Domain dm = null;
         try {
-            dm = conn.domainDefineXML(domainXML);
+            /*
+                We create a transient domain here. When this method gets
+                called we receive a full XML specification of the guest,
+                so no need to define it persistent.
+
+                This also makes sure we never have any old "garbage" defined
+                in libvirt which might haunt us.
+            */
+            dm = conn.domainCreateXML(domainXML, 0);
         } catch (final LibvirtException e) {
-            /* Duplicated defined vm */
-            s_logger.warn("Failed to define domain " + vmName + ": "
+            s_logger.warn("Failed to start domain " + vmName + ": "
                     + e.getMessage());
-            failed = true;
-        } finally {
-            try {
-                if (dm != null) {
-                    dm.free();
-                }
-            } catch (final LibvirtException e) {
-
-            }
         }
 
-        /* If failed, undefine the vm */
-        Domain dmOld = null;
-        Domain dmNew = null;
-        try {
-            if (failed) {
-                dmOld = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName
-                        .getBytes()));
-                dmOld.undefine();
-                dmNew = conn.domainDefineXML(domainXML);
-            }
-        } catch (final LibvirtException e) {
-            s_logger.warn("Failed to define domain (second time) " + vmName
-                    + ": " + e.getMessage());
-            throw e;
-        } catch (Exception e) {
-            s_logger.warn("Failed to define domain (second time) " + vmName
-                    + ": " + e.getMessage());
-            throw new InternalErrorException(e.toString());
-        } finally {
-            try {
-                if (dmOld != null) {
-                    dmOld.free();
-                }
-                if (dmNew != null) {
-                    dmNew.free();
-                }
-            } catch (final LibvirtException e) {
-
-            }
-        }
-
-        /* Start the VM */
-        try {
-            dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName
-                    .getBytes()));
-            dm.create();
-        } catch (LibvirtException e) {
-            s_logger.warn("Failed to start domain: " + vmName + ": "
-                    + e.getMessage());
-            throw e;
-        } finally {
-            try {
-                if (dm != null) {
-                    dm.free();
-                }
-            } catch (final LibvirtException e) {
-
-            }
-        }
         return null;
     }
 
@@ -2863,7 +2806,7 @@ ServerResource {
             List<InterfaceDef> ifaces = getInterfaces(conn, vmName);
 
             destroy_network_rules_for_vm(conn, vmName);
-            String result = stopVM(conn, vmName, defineOps.UNDEFINE_VM);
+            String result = stopVM(conn, vmName);
             if (result == null) {
                 for (DiskDef disk : disks) {
                     if (disk.getDeviceType() == DiskDef.deviceType.CDROM
@@ -3906,7 +3849,7 @@ ServerResource {
                     .getBytes()));
             String vmDef = dm.getXMLDesc(0);
             s_logger.debug(vmDef);
-            msg = stopVM(conn, vmName, defineOps.UNDEFINE_VM);
+            msg = stopVM(conn, vmName);
             msg = startDomain(conn, vmName, vmDef);
             return null;
         } catch (LibvirtException e) {
@@ -3928,7 +3871,7 @@ ServerResource {
         return msg;
     }
 
-    protected String stopVM(Connect conn, String vmName, defineOps df) {
+    protected String stopVM(Connect conn, String vmName) {
         DomainInfo.DomainState state = null;
         Domain dm = null;
 
@@ -3978,23 +3921,6 @@ ServerResource {
             }
         }
 
-        if (df == defineOps.UNDEFINE_VM) {
-            try {
-                dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName
-                        .getBytes()));
-                dm.undefine();
-            } catch (LibvirtException e) {
-
-            } finally {
-                try {
-                    if (dm != null) {
-                        dm.free();
-                    }
-                } catch (LibvirtException l) {
-
-                }
-            }
-        }
         return null;
     }
 


Mime
View raw message