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 39158E71E for ; Fri, 8 Feb 2013 21:10:46 +0000 (UTC) Received: (qmail 99349 invoked by uid 500); 8 Feb 2013 21:10:36 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 99253 invoked by uid 500); 8 Feb 2013 21:10:36 -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 97891 invoked by uid 99); 8 Feb 2013 21:10:34 -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, 08 Feb 2013 21:10:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 94E2D3AAC8; Fri, 8 Feb 2013 21:10:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bfederle@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [9/43] git commit: refs/heads/ui-plugins - agent: Do not define domains persistent in libvirt Message-Id: <20130208211034.94E2D3AAC8@tyr.zones.apache.org> Date: Fri, 8 Feb 2013 21:10:34 +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/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 Authored: Thu Feb 7 22:58:20 2013 +0100 Committer: Wido den Hollander 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 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; }