]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Fixes the error introduced by Matthias' fix for CA-35152
authorJonathan Ludlam <Jonathan.Ludlam@eu.citrix.com>
Thu, 28 Oct 2010 15:50:56 +0000 (16:50 +0100)
committerJonathan Ludlam <Jonathan.Ludlam@eu.citrix.com>
Thu, 28 Oct 2010 15:50:56 +0000 (16:50 +0100)
The original fix replaced memory_static_max with memory_dynamic_max in too many places.

Signed-off-by: Mike McClurg <mike.mcclurg@citrix.com> and Matthias Goergens <matthias.goergens@citrix.com>
ocaml/xapi/memory_check.ml

index 25890d9a4731fcc15a476fb9187559720e801ebb..63060bcec54640d315ff5fa851e5d4b1d027255f 100644 (file)
@@ -62,6 +62,15 @@ type accounting_policy =
        | Dynamic_min
                (** use dynamic_min: liberal: assumes that guests always co-operate. *)
 
+(** Common logic of vm_compute_start_memory and vm_compute_used_memory *)
+let choose_memory_required ~policy ~ballooning_enabled ~memory_dynamic_min ~memory_dynamic_max ~memory_static_max =
+       match (ballooning_enabled, policy) with
+               | (true, Dynamic_min) -> memory_dynamic_min
+               | (true, Dynamic_max) -> memory_dynamic_max
+               | (false, Dynamic_min)
+               | (false, Dynamic_max)
+               | (_, Static_max) -> memory_static_max
+
 (** Calculates the amount of memory required in both 'normal' and 'shadow'
 memory, to start a VM. If the given VM is a PV guest and if memory ballooning
 is enabled, this function returns values derived from the VM's dynamic memory
@@ -70,40 +79,34 @@ ballooning is not enabled or if the VM is an HVM guest, this function returns
 values derived from the VM's static memory maximum (since currently HVM guests
 are not able to start in a pre-ballooned state). *)
 let vm_compute_start_memory ~__context ?(policy=Dynamic_min) vm_record =
-       if Xapi_fist.disable_memory_checks () then (0L, 0L) else
-       let ballooning_enabled =
-               Helpers.ballooning_enabled_for_vm ~__context vm_record in
-       let memory_static_max = vm_record.API.vM_memory_static_max in
-       let memory_dynamic_min = vm_record.API.vM_memory_dynamic_min in
-       let memory_dynamic_max = vm_record.API.vM_memory_dynamic_max in
-
-       let memory_required = match (ballooning_enabled, policy) with
-               | (true, Dynamic_min) -> memory_dynamic_min
-               | (true, Dynamic_max) -> memory_dynamic_max
-               | (_, _) -> memory_dynamic_max in
-       vm_compute_required_memory vm_record
-               (Memory.kib_of_bytes_used memory_required)
+       if Xapi_fist.disable_memory_checks ()
+       then (0L, 0L)
+       else
+               let memory_required = choose_memory_required
+                       ~policy: policy
+                       ~ballooning_enabled: (Helpers.ballooning_enabled_for_vm ~__context vm_record)
+                       ~memory_dynamic_min: vm_record.API.vM_memory_dynamic_min
+                       ~memory_dynamic_max: vm_record.API.vM_memory_dynamic_max
+                       ~memory_static_max:  vm_record.API.vM_memory_static_max in
+               vm_compute_required_memory vm_record
+                       (Memory.kib_of_bytes_used memory_required)
 
 (** Calculates the amount of memory required in both 'normal' and 'shadow'
 memory, for a running VM. If the VM is currently subject to a memory balloon
 operation, this function returns the maximum amount of memory that the VM will
 need between now, and the point in future time when the operation completes. *)
-(* ToDo: Refactor out common functionality of vm_compute_used_memory and vm_compute_start_memory. *)
 let vm_compute_used_memory ~__context policy vm_ref =
        if Xapi_fist.disable_memory_checks () then 0L else
        let vm_main_record = Db.VM.get_record ~__context ~self:vm_ref in
        let vm_boot_record = Helpers.get_boot_record ~__context ~self:vm_ref in
-       let memory_static_max = vm_boot_record.API.vM_memory_static_max in
-       let memory_dynamic_min = vm_main_record.API.vM_memory_dynamic_min in
-       (* ToDo: Is vm_main_record or vm_boot_record the right thing here? *)
-       let memory_dynamic_max = vm_main_record.API.vM_memory_dynamic_max in
 
-       let ballooning_enabled =
-               Helpers.ballooning_enabled_for_vm ~__context vm_boot_record in
-       let memory_required = match (ballooning_enabled, policy) with
-               | (true, Dynamic_min) -> memory_dynamic_min
-               | (true, Dynamic_max) -> memory_dynamic_max
-               | (_, _) -> memory_dynamic_max in
+       let memory_required = choose_memory_required
+               ~policy: policy
+               ~ballooning_enabled: (Helpers.ballooning_enabled_for_vm ~__context vm_boot_record)
+               ~memory_dynamic_min: vm_main_record.API.vM_memory_dynamic_min
+               (* ToDo: Is vm_main_record or vm_boot_record the right thing for dynamic_max? *)
+               ~memory_dynamic_max: vm_main_record.API.vM_memory_dynamic_max 
+               ~memory_static_max:  vm_boot_record.API.vM_memory_static_max in
        memory_required +++ vm_main_record.API.vM_memory_overhead
 
 let vm_compute_resume_memory ~__context vm_ref =