# HG changeset patch # User Jonathan Knowles # Date 1265039940 0 # Node ID 03168d007c006a76260daf2b7bd31a6f22b8209d # Parent 37170963c47d622c236d9023f83d69be6bb3f126 [PCR0047] Adds missing Ocamldoc comments and reformatting code in line with our Ocaml Best Practices Guide. Also removes a few anachronistic comments. Signed-off-by: Jonathan Knowles diff -r 37170963c47d -r 03168d007c00 ocaml/util/vm_memory_constraints.ml --- a/ocaml/util/vm_memory_constraints.ml Thu Jan 28 16:36:45 2010 +0000 +++ b/ocaml/util/vm_memory_constraints.ml Mon Feb 01 15:59:00 2010 +0000 @@ -11,11 +11,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. *) + +(** Operations for transforming and validating memory constraints. *) module type T = sig - (** Represents a set of memory constraints for a guest. Constraints are - in valid order if (and only if) they satisfy the following inequality: - static_min <= dynamic_min <= dynamic_max <= static_max *) + (** Represents a set of memory constraints for a guest. Constraints + * are in valid order if (and only if) they satisfy the following: + * static_min <= dynamic_min <= dynamic_max <= static_max + *) type t = { static_min : Int64.t; @@ -26,39 +29,43 @@ } (** Creates a set of memory constraints from the given tuple whose - elements appear in order of increasing size. *) + * elements appear in order of increasing size. + *) val create : (int64 * int64 * int64 * int64 * int64) -> t - (** Transforms the given set of memory constraints into a valid set, *) - (** if possible, or else returns None. Any constraints returned by *) - (** this function are guaranteed to be in valid order such that: *) - (** static_min <= dynamic_min <= target <= dynamic_max <= static_max *) - (** *) - (** + If the given constraints are valid, this function returns a *) - (** copy of those constraints. *) - (** + If the given constraints are invalid, but can be made valid *) - (** by adjusting [(dynamic_min, dynamic_max)] to be in the range *) - (** defined by [static_min, static_max], or by adjusting [target] *) - (** to be within the range defined by [(dynamic_min, dynamic_max)], *) - (** this function returns such a modified set of constraints. *) - (** + If the given constraints are invalid and they cannot be made *) - (** valid by modifying the dynamic constraints, this function *) - (** function returns None. *) - (** *) + (** Transforms the given set of memory constraints into a valid set, if + * possible, or else returns None. Constraints returned by this function + * are guaranteed to be in valid order such that: + * + * static_min <= dynamic_min <= target <= dynamic_max <= static_max + * + * If the given constraints are valid, this function simply returns a copy + * of those constraints. + * + * If the given constraints are invalid, but can be made valid by adjusting + * [(dynamic_min, dynamic_max)] to be in the range defined by [static_min, + * static_max], or by adjusting [target] to be within the range defined by + * [(dynamic_min, dynamic_max)], this function returns such a modified set + * of constraints. + * + * If the given constraints are invalid and they cannot be made valid by + * modifying the dynamic constraints, this function function returns None. + *) val transform : constraints:t -> t option (** Returns true if and only if the given memory constraints are in valid - order such that: static_min <= dynamic_min <= dynamic_max <= static_max *) + * order such that: static_min <= dynamic_min <= dynamic_max <= static_max + *) val valid : constraints:t -> bool - (** Takes the given set of possibly-invalid memory constraints {i s}, - returning a new set of valid and unballooned constraints {i t} s.t.: - {ol - {- t.dynamic_max := s.static_max} - {- t.target := s.static_max} - {- t.dynamic_min := s.static_max} - {- t.static_min := minimum (s.static_min, s.static_max)}} - *) + (** Takes the given set of possibly-invalid memory constraints {i s}, and + * returns a new set of valid and unballooned constraints {i t} s.t.: + * {ol + * {- t.dynamic_max := s.static_max} + * {- t.target := s.static_max} + * {- t.dynamic_min := s.static_max} + * {- t.static_min := minimum (s.static_min, s.static_max)}} + *) val reset_to_safe_defaults : constraints:t -> t end @@ -124,6 +131,6 @@ target = max; dynamic_min = max; static_min = if min < max then min else max - } + } end diff -r 37170963c47d -r 03168d007c00 ocaml/xapi/xapi_vm_helpers.ml --- a/ocaml/xapi/xapi_vm_helpers.ml Thu Jan 28 16:36:45 2010 +0000 +++ b/ocaml/xapi/xapi_vm_helpers.ml Mon Feb 01 15:59:00 2010 +0000 @@ -568,7 +568,6 @@ let set_memory_dynamic_range ~__context ~self ~min ~max = (* NB called in either `Halted or `Running states *) - (* NB In phase 1 we use the dynamic_min as the balloon target. *) let power_state = Db.VM.get_power_state ~__context ~self in (* Check the range constraints *) let constraints = @@ -577,7 +576,7 @@ else Vm_memory_constraints.get ~__context ~vm_ref:self in let constraints = { constraints with Vm_memory_constraints. dynamic_min = min; - target = min; (* phase 1 *) + target = min; dynamic_max = max } in if not (Vm_memory_constraints.valid ~constraints) then raise (Api_errors.Server_error(Api_errors.memory_constraint_violation, @@ -590,15 +589,14 @@ Db.VM.set_memory_dynamic_max ~__context ~self ~value:max; if power_state = `Running then begin - let domid = Helpers.domid_of_vm ~__context ~self in - Vmopshelpers.with_xc_and_xs - (fun xc xs -> - Domain.set_memory_dynamic_range ~xs - ~min:(Int64.to_int (Int64.div min 1024L)) - ~max:(Int64.to_int (Int64.div max 1024L)) - domid; - At_least_once_more.again Memory_control.async_balance_memory - ) + let domid = Helpers.domid_of_vm ~__context ~self in + Vmopshelpers.with_xc_and_xs + (fun xc xs -> + Domain.set_memory_dynamic_range ~xs + ~min:(Int64.to_int (Int64.div min 1024L)) + ~max:(Int64.to_int (Int64.div max 1024L)) + domid; + At_least_once_more.again Memory_control.async_balance_memory) end (** Sets the current memory target for a running VM, to the given *)