Skip to content

Commit

Permalink
CP-51835: Keep the HTTP /repository handler enabled
Browse files Browse the repository at this point in the history
The HTTP /repository handler is guarded by a mutex `exposing_pool_repo_mutex` currently.
Since now HTTP /repository is protected by `session_id` cookie, we can remove the mutex
from this handler and keep the handler enabled all the time.
Also, rename the mutex `exposing_pool_repo_mutex` to `pool_update_ops_mutex`.

Signed-off-by: Bengang Yuan <[email protected]>
  • Loading branch information
BengangY committed Oct 24, 2024
1 parent 0c7b7e4 commit 654e7c1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
10 changes: 1 addition & 9 deletions ocaml/xapi/repository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -488,18 +488,14 @@ let get_host_updates_in_json ~__context ~installed =
(ExnHelper.string_of_exn e) ;
raise Api_errors.(Server_error (get_host_updates_failed, [ref]))

(* This handler hosts HTTP endpoint '/repository' which will be available iif
* 'is_local_pool_repo_enabled' returns true with 'with_pool_repositories' being called by
* others.
*)
let get_repository_handler (req : Http.Request.t) s _ =
let open Http in
let open Xapi_stdext_std.Xstringext in
debug "Repository.get_repository_handler URL %s" req.Request.uri ;
req.Request.close <- true ;
if Fileserver.access_forbidden req s then
Http_svr.response_forbidden ~req s
else if is_local_pool_repo_enabled () then
else
let can_be_authorized =
try
Xapi_http.with_context "get_repository_handler" req s (fun _ -> ()) ;
Expand Down Expand Up @@ -536,10 +532,6 @@ let get_repository_handler (req : Http.Request.t) s _ =
(ExnHelper.string_of_exn e) ;
Http_svr.response_forbidden ~req s
)
else (
error "Rejecting request: local pool repository is not enabled" ;
Http_svr.response_forbidden ~req s
)

let consolidate_updates_of_hosts ~repository_name ~updates_info ~hosts =
Hashtbl.fold
Expand Down
13 changes: 3 additions & 10 deletions ocaml/xapi/repository_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open Updateinfo
module LivePatchSet = Set.Make (LivePatch)
module RpmFullNameSet = Set.Make (String)

let exposing_pool_repo_mutex = Mutex.create ()
let pool_update_ops_mutex = Mutex.create ()

module Pkgs = (val Pkg_mgr.get_pkg_mgr)

Expand Down Expand Up @@ -234,17 +234,10 @@ let assert_gpgkey_path_is_valid path =
let with_pool_repositories f =
Xapi_stdext_pervasives.Pervasiveext.finally
(fun () ->
Mutex.lock exposing_pool_repo_mutex ;
Mutex.lock pool_update_ops_mutex ;
f ()
)
(fun () -> Mutex.unlock exposing_pool_repo_mutex)

let is_local_pool_repo_enabled () =
if Mutex.try_lock exposing_pool_repo_mutex then (
Mutex.unlock exposing_pool_repo_mutex ;
false
) else
true
(fun () -> Mutex.unlock pool_update_ops_mutex)

let with_updateinfo_xml gz_path f =
let tmpfile, tmpch =
Expand Down

0 comments on commit 654e7c1

Please sign in to comment.