# HG changeset patch # User Rob Hoes CP-1622: XenAPI functions for masking CPU features There are two new functions: * Host.set_cpu_features, for applying feature masks * Host.reset_cpu_features, for removing all current masks Signed-off-by: Rob Hoes diff -r 1cbc49ef217a ocaml/xapi/xapi_host.ml --- a/ocaml/xapi/xapi_host.ml Tue Feb 16 22:52:01 2010 +0000 +++ b/ocaml/xapi/xapi_host.ml Tue Feb 16 22:54:32 2010 +0000 @@ -13,6 +13,7 @@ *) open Pervasiveext open Stringext +open Listext open Threadext open Xapi_host_helpers open Xapi_support @@ -1262,12 +1263,47 @@ debug "Refreshing software_version"; let software_version = Create_misc.make_software_version () in Db.Host.set_software_version ~__context ~self:host ~value:software_version - + let set_cpu_features ~__context ~host ~features = debug "Set CPU features"; - () + (* check restrictions *) + if not (Restrictions.ok_for_cpu_masking ()) then + raise (Api_errors.Server_error (Api_errors.feature_restricted, [])); + + let cpuid = Cpuid.read_cpu_info () in + + (* parse features string *) + let features = + try Cpuid.string_to_features features + with Cpuid.InvalidFeatureString e -> + raise (Api_errors.Server_error (Api_errors.invalid_feature_string, [e])) + in + + (* check masking is possible *) + begin try + Cpuid.assert_maskability cpuid cpuid.Cpuid.manufacturer features + with + | Cpuid.MaskingNotSupported e -> + raise (Api_errors.Server_error (Api_errors.cpu_feature_masking_not_supported, [e])) + | Cpuid.InvalidFeatureString e -> + raise (Api_errors.Server_error (Api_errors.invalid_feature_string, [e])) + | Cpuid.ManufacturersDiffer -> () (* cannot happen *) + end; + + (* add masks to Xen command line *) + ignore (Xen_cmdline.delete_cpuid_masks ["cpuid_mask_ecx"; "cpuid_mask_edx"; "cpuid_mask_ext_ecx"; "cpuid_mask_ext_edx"]); + let new_masks = Cpuid.xen_masking_string cpuid features in + ignore (Xen_cmdline.set_cpuid_masks new_masks); + + (* update database *) + let cpu_info = Db.Host.get_cpu_info ~__context ~self:host in + let cpu_info = List.replace_assoc "features_after_reboot" (Cpuid.features_to_string features) cpu_info in + Db.Host.set_cpu_info ~__context ~self:host ~value:cpu_info let reset_cpu_features ~__context ~host = debug "Reset CPU features"; - () - + ignore (Xen_cmdline.delete_cpuid_masks ["cpuid_mask_ecx"; "cpuid_mask_edx"; "cpuid_mask_ext_ecx"; "cpuid_mask_ext_edx"]); + let cpu_info = Db.Host.get_cpu_info ~__context ~self:host in + let physical_features = List.assoc "physical_features" cpu_info in + let cpu_info = List.replace_assoc "features_after_reboot" physical_features cpu_info in + Db.Host.set_cpu_info ~__context ~self:host ~value:cpu_info diff -r 1cbc49ef217a ocaml/xapi/xapi_host.mli --- a/ocaml/xapi/xapi_host.mli Tue Feb 16 22:52:01 2010 +0000 +++ b/ocaml/xapi/xapi_host.mli Tue Feb 16 22:54:32 2010 +0000 @@ -227,15 +227,15 @@ (** {2 Licensing} *) -val apply_edition : __context:Context.t -> host:API.ref_host -> edition:string -> unit (** Attempt to activate the given edition (one of "free", "enterprise" or "platinum". * In needed, the function automatically checks v6 licenses in and out * from the license server (via the v6 daemon). If the requested edition is not * available, the call will fail with an exception, leaving the edition as it is. * Also call this function to change to a different license server, after the * connection details in host.license_server have been amended. *) +val apply_edition : __context:Context.t -> host:API.ref_host -> edition:string -> unit - + (** {2 CPU Feature Masking} *) (** Set the CPU features to be used after a reboot, if the given features string is valid. *)