Add waiting loop to avoid potential race condition when doing NIC hot-plugin

This commit is contained in:
Kelven Yang 2012-07-27 16:40:04 -07:00
parent b31aea83b3
commit 4b0f317074
2 changed files with 37 additions and 25 deletions

View File

@ -102,9 +102,9 @@
<jvmarg value="-Dcom.sun.management.jmxremote.port=${jmxport}"/>
<jvmarg value="-Dcom.sun.management.jmxremote.authenticate=false"/>
<jvmarg value="-Dcom.sun.management.jmxremote.ssl=false"/>
<jvmarg value="-Xms256m"/>
<jvmarg value="-Xmx512m"/>
<jvmarg value="-XX:MaxPermSize=128m"/>
<jvmarg value="-Xms512m"/>
<jvmarg value="-Xmx1024m"/>
<jvmarg value="-XX:MaxPermSize=256m"/>
<jvmarg value="-ea"/>
<arg value="start"/>
</java>
@ -119,9 +119,9 @@
<jvmarg value="-Xdebug"/>
<jvmarg value="${debug.jvmarg}"/>
<jvmarg value="-ea"/>
<jvmarg value="-Xms256m"/>
<jvmarg value="-Xmx512m"/>
<jvmarg value="-XX:MaxPermSize=128m"/>
<jvmarg value="-Xms512m"/>
<jvmarg value="-Xmx1024m"/>
<jvmarg value="-XX:MaxPermSize=256m"/>
</java>
</target>

View File

@ -790,26 +790,38 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
// TODO : this is a temporary very inefficient solution, will refactor it later
Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
"ls /proc/sys/net/ipv4/conf");
if(result.first()) {
String[] tokens = result.second().split("\\s+");
for(String token : tokens) {
if(!("all".equalsIgnoreCase(token) || "default".equalsIgnoreCase(token) || "lo".equalsIgnoreCase(token))) {
String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
if(s_logger.isDebugEnabled())
s_logger.debug("Run domr script " + cmd);
Pair<Boolean, String> result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
// TODO need to find the dev index inside router based on IP address
cmd);
if(s_logger.isDebugEnabled())
s_logger.debug("result: " + result2.first() + ", output: " + result2.second());
if(result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim()))
return Integer.parseInt(token.substring(3));
"ls /proc/sys/net/ipv4/conf");
// when we dynamically plug in a new NIC into virtual router, it may take time to show up in guest OS
// we use a waiting loop here as a workaround to synchronize activities in systems
long startTick = System.currentTimeMillis();
while(System.currentTimeMillis() - startTick < 15000) {
if(result.first()) {
String[] tokens = result.second().split("\\s+");
for(String token : tokens) {
if(!("all".equalsIgnoreCase(token) || "default".equalsIgnoreCase(token) || "lo".equalsIgnoreCase(token))) {
String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
if(s_logger.isDebugEnabled())
s_logger.debug("Run domr script " + cmd);
Pair<Boolean, String> result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", mgr.getSystemVMKeyFile(), null,
// TODO need to find the dev index inside router based on IP address
cmd);
if(s_logger.isDebugEnabled())
s_logger.debug("result: " + result2.first() + ", output: " + result2.second());
if(result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim()))
return Integer.parseInt(token.substring(3));
}
}
}
s_logger.warn("can not find intereface associated with mac: " + mac + ", guest OS may still at loading state, retry...");
try {
Thread.currentThread().sleep(1000);
} catch (InterruptedException e) {
}
}
return -1;
@ -1128,7 +1140,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
s_logger.error(msg);
throw new Exception(msg);
}
// TODO need a way to specify the control of NIC device type
VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.E1000;