incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [9/43] git commit: refs/heads/ui-plugins - agent: Do not define domains persistent in libvirt
Date Fri, 08 Feb 2013 21:10:34 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/5dfcd309
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/5dfcd309
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/5dfcd309

Branch: refs/heads/ui-plugins
Commit: 5dfcd309f10e5bd6a918f7fdff3f44a3dff2374a
Parents: f6c4b22
Author: Wido den Hollander <wido@widodh.nl>
Authored: Thu Feb 7 22:58:20 2013 +0100
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Thu Feb 7 23:07:05 2013 +0100

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


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5dfcd309/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 4acd083..49d2f0b 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
@@ -368,10 +368,6 @@ ServerResource {
         NATIVE, OPENVSWITCH
     }
 
-    protected enum defineOps {
-        UNDEFINE_VM, DEFINE_VM
-    }
-
     protected BridgeType _bridgeType;
 
     private String getEndIpFromStartIp(String startIp, int numIps) {
@@ -981,75 +977,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;
     }
 
@@ -2845,7 +2788,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
@@ -3888,7 +3831,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) {
@@ -3910,7 +3853,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;
 
@@ -3960,23 +3903,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