cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sate...@apache.org
Subject [25/50] git commit: updated refs/heads/vmware-datamodel to 2acbe30
Date Fri, 03 May 2013 17:11:53 GMT
CLOUDSTACK-2160: fix bug add a huge size guest network will cause out of memory

Signed-off-by: Mice Xia <mice_xia@tcloudcomputing.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f1c794de
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f1c794de
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f1c794de

Branch: refs/heads/vmware-datamodel
Commit: f1c794de1bb913002b5316992e331700a1f822b5
Parents: f101241
Author: Hongtu Zang <hongtu_zang@tcloudcomputing.com>
Authored: Wed Apr 24 11:13:29 2013 +0800
Committer: Mice Xia <mice_xia@tcloudcomputing.com>
Committed: Thu May 2 13:19:12 2013 +0800

----------------------------------------------------------------------
 server/src/com/cloud/network/NetworkModelImpl.java |    9 +++------
 .../src/com/cloud/network/NetworkServiceImpl.java  |    7 ++-----
 utils/src/com/cloud/utils/net/NetUtils.java        |   10 +++++++---
 3 files changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f1c794de/server/src/com/cloud/network/NetworkModelImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkModelImpl.java b/server/src/com/cloud/network/NetworkModelImpl.java
index bd62886..7b712ea 100755
--- a/server/src/com/cloud/network/NetworkModelImpl.java
+++ b/server/src/com/cloud/network/NetworkModelImpl.java
@@ -1666,20 +1666,17 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel
{
         List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
         List<String> secondaryIps = _nicSecondaryIpDao.listSecondaryIpAddressInNetwork(network.getId());
         ips.addAll(secondaryIps);
-        Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1]));
         Set<Long> usedIps = new TreeSet<Long>(); 
-        
+
         for (String ip : ips) {
             if (requestedIp != null && requestedIp.equals(ip)) {
                 s_logger.warn("Requested ip address " + requestedIp + " is already in use
in network" + network);
                 return null;
             }
-    
+
             usedIps.add(NetUtils.ip2Long(ip));
         }
-        if (usedIps.size() != 0) {
-            allPossibleIps.removeAll(usedIps);
-        }
+        Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1]),
usedIps);
 
         String gateway = network.getGateway();
         if ((gateway != null) && (allPossibleIps.contains(NetUtils.ip2Long(gateway))))

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f1c794de/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 2dcb47d..ae0e421 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -2066,9 +2066,8 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
     protected Set<Long> getAvailableIps(Network network, String requestedIp) {
         String[] cidr = network.getCidr().split("/");
         List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
-        Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1]));
         Set<Long> usedIps = new TreeSet<Long>(); 
-        
+
         for (String ip : ips) {
             if (requestedIp != null && requestedIp.equals(ip)) {
                 s_logger.warn("Requested ip address " + requestedIp + " is already in use
in network" + network);
@@ -2077,9 +2076,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
 
             usedIps.add(NetUtils.ip2Long(ip));
         }
-        if (usedIps.size() != 0) {
-            allPossibleIps.removeAll(usedIps);
-        }
+        Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1]),
usedIps);
 
         String gateway = network.getGateway();
         if ((gateway != null) && (allPossibleIps.contains(NetUtils.ip2Long(gateway))))

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f1c794de/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index 5988dd5..9f28d5b 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -627,7 +627,7 @@ public class NetUtils {
         return result;
     }
 
-    public static Set<Long> getAllIpsFromCidr(String cidr, long size) {
+    public static Set<Long> getAllIpsFromCidr(String cidr, long size, Set<Long>
usedIps) {
         assert (size < 32) : "You do know this is not for ipv6 right?  Keep it smaller
than 32 but you have " + size;
         Set<Long> result = new TreeSet<Long>();
         long ip = ip2Long(cidr);
@@ -639,8 +639,12 @@ public class NetUtils {
 
         end++;
         end = (end << (32 - size)) - 2;
-        while (start <= end) {
-            result.add(start);
+        int maxIps = 255; // get 255 ips as maximum
+        while (start <= end && maxIps > 0) {
+            if (!usedIps.contains(start)){
+                result.add(start);
+                maxIps--;
+            }
             start++;
         }
 


Mime
View raw message