Skip to content

Commit

Permalink
fixup! CA-400060: Sm feature intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent-lau committed Nov 5, 2024
1 parent e700ae7 commit 164697a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions ocaml/xapi/xapi_sm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ let create_from_query_result ~__context q =
let find_pending_features existing_features features =
Listext.List.set_difference features existing_features

let update_pending_hosts_features ~__context self new_features =
(** [addto_pending_hosts_features ~__context self new_features] will add [new_features]
to pending features of host [self]. It then returns a list of currently pending features *)
let addto_pending_hosts_features ~__context self new_features =
let host = Helpers.get_localhost ~__context in
let new_features =
List.map (fun (f, v) -> Smint.unparse_feature (f, v)) new_features
Expand Down Expand Up @@ -88,6 +90,16 @@ let valid_hosts_pending_features ~__context pending_features =
(List.nth_opt l 0 |> Option.fold ~none:[] ~some:Fun.id)
(List.tl l)

let remove_valid_features_from_pending ~__context ~self valid_features =
let valid_features = List.map Smint.unparse_feature valid_features in
let new_pending_feature =
Db.SM.get_host_pending_features ~__context ~self
|> List.map (fun (h, pending_features) ->
(h, Listext.List.set_difference pending_features valid_features)
)
in
Db.SM.set_host_pending_features ~__context ~self ~value:new_pending_feature

let update_from_query_result ~__context (self, r) q_result =
let open Storage_interface in
let _type = String.lowercase_ascii q_result.driver in
Expand All @@ -97,9 +109,10 @@ let update_from_query_result ~__context (self, r) q_result =
let new_features =
Smint.parse_string_int64_features q_result.features
|> find_pending_features existing_features
|> update_pending_hosts_features ~__context self
|> addto_pending_hosts_features ~__context self
|> valid_hosts_pending_features ~__context
in
remove_valid_features_from_pending ~__context ~self new_features ;
let features = existing_features @ new_features in
List.iter
(fun (f, v) -> debug "%s: declaring new features %s:%Ld" __FUNCTION__ f v)
Expand Down

0 comments on commit 164697a

Please sign in to comment.