[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-API] [PATCH] Use Pool.restrictions in DB to get/set pool restrictions, rather than local ref
# HG changeset patch # User Rob Hoes <rob.hoes@xxxxxxxxxx> Use Pool.restrictions in DB to get/set pool restrictions, rather than local ref Signed-off-by: Rob Hoes <rob.hoes@xxxxxxxxxx> diff -r c03274a6bb78 ocaml/license/restrictions.ml --- a/ocaml/license/restrictions.ml Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/license/restrictions.ml Fri Apr 09 17:30:54 2010 +0100 @@ -264,40 +264,36 @@ let get () = restrictions_of_sku (get_sku ()) -(* Cache of pool restrictions, always updated at least once when the master reads its license *) -let pool_restrictions = ref most_permissive -let pool_restrictions_m = Mutex.create () +let get_pool ~__context = + let pool = List.hd (Db.Pool.get_all ~__context) in + of_assoc_list (Db.Pool.get_restrictions ~__context ~self:pool) -let get_pool () = Mutex.execute pool_restrictions_m (fun () -> !pool_restrictions) - -let update_pool_restrictions ~__context = - Mutex.execute pool_restrictions_m (fun () -> - let hosts = List.map (fun (_, host_r) -> host_r.API.host_license_params) (Db.Host.get_all_records ~__context) in - let new_restrictions = pool_restrictions_of_list (List.map of_assoc_list hosts) in - if new_restrictions <> !pool_restrictions then begin - info "Old pool restrictions: %s" (to_compact_string !pool_restrictions); - info "New pool restrictions: %s" (to_compact_string new_restrictions); - pool_restrictions := new_restrictions - end; - let pool = List.hd (Db.Pool.get_all ~__context) in +let update_pool_restrictions ~__context = + let pool = List.hd (Db.Pool.get_all ~__context) in + let pool_restrictions = of_assoc_list (Db.Pool.get_restrictions ~__context ~self:pool) in + let hosts = List.map (fun (_, host_r) -> host_r.API.host_license_params) (Db.Host.get_all_records ~__context) in + let new_restrictions = pool_restrictions_of_list (List.map of_assoc_list hosts) in + if new_restrictions <> pool_restrictions then begin + info "Old pool restrictions: %s" (to_compact_string pool_restrictions); + info "New pool restrictions: %s" (to_compact_string new_restrictions); Db.Pool.set_restrictions ~__context ~self:pool ~value:(to_assoc_list new_restrictions) - ) + end let license_ok_for_wlb ~__context = - (get_pool()).enable_wlb + (get_pool ~__context).enable_wlb let license_ok_for_rbac ~__context = - (get_pool()).enable_rbac + (get_pool ~__context).enable_rbac let context_ok_for_dmc ~__context = - (get_pool()).enable_dmc + (get_pool ~__context).enable_dmc -let ok_for_checkpoint () = - (get_pool()).enable_checkpoint +let ok_for_checkpoint ~__context = + (get_pool ~__context).enable_checkpoint -let ok_for_vswitch_controller () = - (get_pool()).enable_vswitch_controller +let ok_for_vswitch_controller ~__context = + (get_pool ~__context).enable_vswitch_controller -let ok_for_cpu_masking () = - (get_pool()).enable_cpu_masking +let ok_for_cpu_masking ~__context = + (get_pool ~__context).enable_cpu_masking diff -r c03274a6bb78 ocaml/license/restrictions.mli --- a/ocaml/license/restrictions.mli Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/license/restrictions.mli Fri Apr 09 17:30:54 2010 +0100 @@ -71,7 +71,7 @@ (** Return cache of pool restrictions, always updated at least once when the master reads its license. * Called on the master to gate some operations. *) -val get_pool : unit -> restrictions +val get_pool : __context:Context.t -> restrictions (* called by xapi_host *) (** Called whenever a slave resets its Host.license_params after reading in a license. *) @@ -81,21 +81,21 @@ val restrictions_of_sku : sku -> restrictions (** Checks whether we are entitled to enable Workload Balancing (WLB) in the pool. *) -val license_ok_for_wlb : __context:'a -> bool +val license_ok_for_wlb : __context:Context.t -> bool (** Checks whether we are entitled to enable Role-Based Access Control (RBAC) in the pool *) -val license_ok_for_rbac : __context:'a -> bool +val license_ok_for_rbac : __context:Context.t -> bool (** Checks whether we are entitled to enable Dynamic Memory Control (DMC) * in the pool. *) -val context_ok_for_dmc : __context:'a -> bool +val context_ok_for_dmc : __context:Context.t -> bool (** Checks whether we are entitled to enable checkpoint *) -val ok_for_checkpoint : unit -> bool +val ok_for_checkpoint : __context:Context.t -> bool (** Checks whether we are entitled to use a VSwitch Controller *) -val ok_for_vswitch_controller : unit -> bool +val ok_for_vswitch_controller : __context:Context.t -> bool (** Checks whether we are entitled to mask CPU features *) -val ok_for_cpu_masking : unit -> bool +val ok_for_cpu_masking : __context:Context.t -> bool diff -r c03274a6bb78 ocaml/xapi/cli_operations.ml --- a/ocaml/xapi/cli_operations.ml Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/xapi/cli_operations.ml Fri Apr 09 17:30:54 2010 +0100 @@ -183,7 +183,8 @@ let invalid_hosts = List.map (fun (_, host_r) -> [ host_r.API.host_hostname; String.sub host_r.API.host_uuid 0 8; "-"; "-"; "-"; "-"; "-" ]) invalid in - let pool_restrictions = Restrictions.get_pool () in + let __context = Context.make "diagnostic_license_status" in + let pool_restrictions = Restrictions.get_pool ~__context in let pool_free = List.fold_left (||) false (List.map (fun h -> Restrictions.is_floodgate_free (Restrictions.sku_of_string h.license.License.sku)) host_licenses) in let divider = [ "-"; "-"; "-"; "-"; "-"; "-"; "-" ] in let pool = [ "-"; "-"; Restrictions.to_compact_string pool_restrictions; "-"; string_of_bool pool_free; "-"; "-" ] in diff -r c03274a6bb78 ocaml/xapi/xapi.ml --- a/ocaml/xapi/xapi.ml Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/xapi/xapi.ml Fri Apr 09 17:30:54 2010 +0100 @@ -819,7 +819,7 @@ "Initialise Monitor_rrds.use_min_max", [], Monitor_rrds.update_use_min_max; "Initialising licensing", [], handle_licensing; "control domain memory", [ Startup.OnThread ], control_domain_memory; - "message_hook_thread", [ Startup.NoExnRaising ], Xapi_message.start_message_hook_thread; + "message_hook_thread", [ Startup.NoExnRaising ], (Xapi_message.start_message_hook_thread ~__context); "heartbeat thread", [ Startup.NoExnRaising; Startup.OnThread ], Db_gc.start_heartbeat_thread; "resynchronising HA state", [ Startup.NoExnRaising ], resynchronise_ha_state; "pool db backup", [ Startup.OnlyMaster; Startup.OnThread ], Pool_db_backup.pool_db_backup_thread; diff -r c03274a6bb78 ocaml/xapi/xapi_ha.ml --- a/ocaml/xapi/xapi_ha.ml Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/xapi/xapi_ha.ml Fri Apr 09 17:30:54 2010 +0100 @@ -1366,7 +1366,7 @@ if Db.Pool.get_ha_enabled ~__context ~self:pool then raise (Api_errors.Server_error(Api_errors.ha_is_enabled, [])); - if not ((Restrictions.get_pool()).Restrictions.enable_xha) + if not ((Restrictions.get_pool ~__context).Restrictions.enable_xha) then raise (Api_errors.Server_error(Api_errors.license_restriction, [])); (* Check that all of our 'disallow_unplug' PIFs are currently attached *) diff -r c03274a6bb78 ocaml/xapi/xapi_host.ml --- a/ocaml/xapi/xapi_host.ml Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/xapi/xapi_host.ml Fri Apr 09 17:30:54 2010 +0100 @@ -1268,7 +1268,7 @@ let set_cpu_features ~__context ~host ~features = debug "Set CPU features"; (* check restrictions *) - if not (Restrictions.ok_for_cpu_masking ()) then + if not (Restrictions.ok_for_cpu_masking ~__context) then raise (Api_errors.Server_error (Api_errors.feature_restricted, [])); let cpuid = Cpuid.read_cpu_info () in diff -r c03274a6bb78 ocaml/xapi/xapi_message.ml --- a/ocaml/xapi/xapi_message.ml Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/xapi/xapi_message.ml Fri Apr 09 17:30:54 2010 +0100 @@ -163,9 +163,9 @@ to_xml output _ref message; Buffer.contents buffer -let handle_message message = +let handle_message ~__context message = try - if not (Restrictions.get_pool ()).Restrictions.enable_email + if not (Restrictions.get_pool ~__context).Restrictions.enable_email then info "Email alerting is restricted by current license: not generating email" else begin let output, log = Forkhelpers.execute_command_get_output (Xapi_globs.xapi_message_script) [message] in @@ -175,8 +175,8 @@ error "Unexpected exception in message hook. Exception='%s'" (ExnHelper.string_of_exn e); log_backtrace () -let start_message_hook_thread () = - queue_push := Thread_queue.make ~name:"email message queue" ~max_q_length:100 handle_message +let start_message_hook_thread ~__context () = + queue_push := Thread_queue.make ~name:"email message queue" ~max_q_length:100 (handle_message ~__context) (********************************************************************) diff -r c03274a6bb78 ocaml/xapi/xapi_vm.ml --- a/ocaml/xapi/xapi_vm.ml Fri Apr 09 15:07:04 2010 +0100 +++ b/ocaml/xapi/xapi_vm.ml Fri Apr 09 17:30:54 2010 +0100 @@ -920,7 +920,7 @@ (* As the checkpoint operation modify the domain state, we take the vm_lock to do not let the event *) (* thread mess around with that. *) let checkpoint ~__context ~vm ~new_name = - if not (Restrictions.ok_for_checkpoint ()) then + if not (Restrictions.ok_for_checkpoint ~__context) then raise (Api_errors.Server_error(Api_errors.license_restriction, [])) else begin Local_work_queue.wait_in_line Local_work_queue.long_running_queue Attachment:
pool-restrictions _______________________________________________ xen-api mailing list xen-api@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/mailman/listinfo/xen-api
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |