From 38d8a84ebcef5f3ef600c30dbd90b16d2b05aa7b Mon Sep 17 00:00:00 2001 From: Edison Su Date: Mon, 26 Aug 2013 13:59:54 -0700 Subject: [PATCH] CLOUDSTACK-4436: in case of older kvm host, we'd better try serveral times to make sure we passed cmdline parameters to system vms --- .../VirtualRoutingResource.java | 35 +++++++++++++++++++ .../resource/LibvirtComputingResource.java | 19 +++++----- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index ec8bc8d166c..23543915dd2 100755 --- a/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -1256,6 +1256,41 @@ public class VirtualRoutingResource implements Manager { return "Unable to connect"; } + public boolean connect(final String ipAddress, int retry, int sleep) { + for (int i = 0; i <= retry; i++) { + SocketChannel sch = null; + try { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Trying to connect to " + ipAddress); + } + sch = SocketChannel.open(); + sch.configureBlocking(true); + + final InetSocketAddress addr = new InetSocketAddress(ipAddress, _port); + sch.connect(addr); + return true; + } catch (final IOException e) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Could not connect to " + ipAddress); + } + } finally { + if (sch != null) { + try { + sch.close(); + } catch (final IOException e) {} + } + } + try { + Thread.sleep(sleep); + } catch (final InterruptedException e) { + } + } + + s_logger.debug("Unable to logon to " + ipAddress); + + return false; + } + @Override public String getName() { 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 404a6da6a63..67819bcfad3 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 @@ -3551,15 +3551,18 @@ ServerResource { if (vmSpec.getType() != VirtualMachine.Type.User) { if ((_kernelVersion < 2006034) && (conn.getVersion() < 1001000)) { // CLOUDSTACK-2823: try passCmdLine some times if kernel < 2.6.34 and qemu < 1.1.0 on hypervisor (for instance, CentOS 6.4) //wait for 5 minutes at most - for (int count = 0; count < 30; count ++) { - boolean succeed = passCmdLine(vmName, vmSpec.getBootArgs()); - if (succeed) { - break; + String controlIp = null; + for (NicTO nic : nics) { + if (nic.getType() == TrafficType.Control) { + controlIp = nic.getIp(); } - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - s_logger.trace("Ignoring InterruptedException.", e); + } + for (int count = 0; count < 30; count ++) { + passCmdLine(vmName, vmSpec.getBootArgs()); + //check router is up? + boolean result = _virtRouterResource.connect(controlIp, 1, 5000); + if (result) { + break; } } } else {