Skip to content

Commit 38d8a84

Browse files
committed
CLOUDSTACK-4436: in case of older kvm host, we'd better try serveral times to make sure we passed cmdline parameters to system vms
1 parent ecbd9ed commit 38d8a84

2 files changed

Lines changed: 45 additions & 7 deletions

File tree

core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,41 @@ public String connect(final String ipAddress, final int port) {
12561256
return "Unable to connect";
12571257
}
12581258

1259+
public boolean connect(final String ipAddress, int retry, int sleep) {
1260+
for (int i = 0; i <= retry; i++) {
1261+
SocketChannel sch = null;
1262+
try {
1263+
if (s_logger.isDebugEnabled()) {
1264+
s_logger.debug("Trying to connect to " + ipAddress);
1265+
}
1266+
sch = SocketChannel.open();
1267+
sch.configureBlocking(true);
1268+
1269+
final InetSocketAddress addr = new InetSocketAddress(ipAddress, _port);
1270+
sch.connect(addr);
1271+
return true;
1272+
} catch (final IOException e) {
1273+
if (s_logger.isDebugEnabled()) {
1274+
s_logger.debug("Could not connect to " + ipAddress);
1275+
}
1276+
} finally {
1277+
if (sch != null) {
1278+
try {
1279+
sch.close();
1280+
} catch (final IOException e) {}
1281+
}
1282+
}
1283+
try {
1284+
Thread.sleep(sleep);
1285+
} catch (final InterruptedException e) {
1286+
}
1287+
}
1288+
1289+
s_logger.debug("Unable to logon to " + ipAddress);
1290+
1291+
return false;
1292+
}
1293+
12591294

12601295
@Override
12611296
public String getName() {

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,16 +3551,19 @@ protected StartAnswer execute(StartCommand cmd) {
35513551
if (vmSpec.getType() != VirtualMachine.Type.User) {
35523552
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)
35533553
//wait for 5 minutes at most
3554+
String controlIp = null;
3555+
for (NicTO nic : nics) {
3556+
if (nic.getType() == TrafficType.Control) {
3557+
controlIp = nic.getIp();
3558+
}
3559+
}
35543560
for (int count = 0; count < 30; count ++) {
3555-
boolean succeed = passCmdLine(vmName, vmSpec.getBootArgs());
3556-
if (succeed) {
3561+
passCmdLine(vmName, vmSpec.getBootArgs());
3562+
//check router is up?
3563+
boolean result = _virtRouterResource.connect(controlIp, 1, 5000);
3564+
if (result) {
35573565
break;
35583566
}
3559-
try {
3560-
Thread.sleep(5000);
3561-
} catch (InterruptedException e) {
3562-
s_logger.trace("Ignoring InterruptedException.", e);
3563-
}
35643567
}
35653568
} else {
35663569
passCmdLine(vmName, vmSpec.getBootArgs() );

0 commit comments

Comments
 (0)