rhtyd closed pull request #2766: kvm: Agent should not check if remaining 
memory on host is sufficient
URL: https://github.com/apache/cloudstack/pull/2766
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 3983b18b297..ed87974cd51 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -277,7 +277,6 @@
     protected int _rngRateBytes = 2048;
     private File _qemuSocketsPath;
     private final String _qemuGuestAgentSocketName = "org.qemu.guest_agent.0";
-    private long _totalMemory;
     protected WatchDogAction _watchDogAction = WatchDogAction.NONE;
     protected WatchDogModel _watchDogModel = WatchDogModel.I6300ESB;
 
@@ -2603,7 +2602,6 @@ public Type getType() {
     public StartupCommand[] initialize() {
 
         final List<Object> info = getHostInfo();
-        _totalMemory = (Long)info.get(2);
 
         final StartupRoutingCommand cmd =
                 new StartupRoutingCommand((Integer)info.get(0), 
(Long)info.get(1), (Long)info.get(2), (Long)info.get(4), (String)info.get(3), 
_hypervisorType,
@@ -3792,10 +3790,6 @@ public void restoreVMSnapshotMetadata(Domain dm, String 
vmName, List<Ternary<Str
         }
     }
 
-    public long getTotalMemory() {
-        return _totalMemory;
-    }
-
     public String getHostDistro() {
         return _hostDistro;
     }
diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java
index 5a75f078f9e..fd5f2fa83ef 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java
@@ -24,7 +24,6 @@
 
 import org.apache.log4j.Logger;
 import org.libvirt.Connect;
-import org.libvirt.Domain;
 import org.libvirt.DomainInfo.DomainState;
 import org.libvirt.LibvirtException;
 
@@ -65,13 +64,6 @@ public Answer execute(final StartCommand command, final 
LibvirtComputingResource
             vm = libvirtComputingResource.createVMFromSpec(vmSpec);
             conn = libvirtUtilitiesHelper.getConnectionByType(vm.getHvsType());
 
-            Long remainingMem = getFreeMemory(conn, libvirtComputingResource);
-            if (remainingMem == null){
-                return new StartAnswer(command, "failed to get free memory");
-            } else if (remainingMem < vmSpec.getMinRam()) {
-                return new StartAnswer(command, "Not enough memory on the 
host, remaining: " + remainingMem + ", asking: " + vmSpec.getMinRam());
-            }
-
             final NicTO[] nics = vmSpec.getNics();
 
             for (final NicTO nic : nics) {
@@ -160,22 +152,4 @@ public Answer execute(final StartCommand command, final 
LibvirtComputingResource
             }
         }
     }
-
-    private Long getFreeMemory(final Connect conn, final 
LibvirtComputingResource libvirtComputingResource){
-        try {
-            long allocatedMem = 0;
-            int[] ids = conn.listDomains();
-            for(int id :ids) {
-                Domain dm = conn.domainLookupByID(id);
-                allocatedMem += dm.getMaxMemory() * 1024L;
-                s_logger.debug("vm: " + dm.getName() + " mem: " + 
dm.getMaxMemory() * 1024L);
-            }
-            Long remainingMem = libvirtComputingResource.getTotalMemory() - 
allocatedMem;
-            s_logger.debug("remaining mem" + remainingMem);
-            return remainingMem;
-        } catch (Exception e) {
-            s_logger.debug("failed to get free memory", e);
-            return null;
-        }
-    }
 }
diff --git 
a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
 
b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index be191f5e9a5..adadc1f4671 100644
--- 
a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ 
b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -5038,7 +5038,6 @@ public void testStartCommandHostMemory() {
             when(conn.domainLookupByID(vmId)).thenReturn(dm);
             when(dm.getMaxMemory()).thenReturn(1024L);
             when(dm.getName()).thenReturn(vmName);
-            
when(libvirtComputingResource.getTotalMemory()).thenReturn(2048*1024L);
             doNothing().when(libvirtComputingResource).createVbd(conn, vmSpec, 
vmName, vmDef);
         } catch (final LibvirtException e) {
             fail(e.getMessage());


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to