Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C65B4E7B5 for ; Fri, 15 Mar 2013 14:01:04 +0000 (UTC) Received: (qmail 22071 invoked by uid 500); 15 Mar 2013 14:01:04 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 21831 invoked by uid 500); 15 Mar 2013 14:01:04 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 21791 invoked by uid 99); 15 Mar 2013 14:01:03 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Mar 2013 14:01:03 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 79CAF189BA; Fri, 15 Mar 2013 14:01:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chipchilders@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/3] git commit: refs/heads/4.1 - agent: Do not define domains persistent in libvirt Message-Id: <20130315140103.79CAF189BA@tyr.zones.apache.org> Date: Fri, 15 Mar 2013 14:01:03 +0000 (UTC) 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 Authored: Thu Feb 7 22:58:20 2013 +0100 Committer: Chip Childers 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 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; }