Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions ocaml/xapi/xapi_sm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,24 @@ let update_from_query_result ~__context (self, r) q_result =
if _type <> "storage_access" then (
let driver_filename = Sm_exec.cmd_name q_result.driver in
let existing_features = Db.SM.get_features ~__context ~self in
let query_features = Smint.Feature.parse_string_int64 q_result.features in
let removed_features =
Listext.List.set_difference existing_features query_features
in
List.iter
(fun (f, v) -> debug "%s: removing features %s:%Ld" __FUNCTION__ f v)
removed_features ;
let retained_features =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an observation: the retained_features and removed_features are just the partition of whether each feature in existing_features being in query_features or not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in ocaml with

let retained_features, removed_features =
  List.partition (fun x -> List.mem x query_features) existing_features
in

Listext.List.set_difference existing_features removed_features
in
let new_features =
Smint.Feature.parse_string_int64 q_result.features
query_features
|> find_pending_features existing_features
|> 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
let features = retained_features @ new_features in
List.iter
(fun (f, v) -> debug "%s: declaring new features %s:%Ld" __FUNCTION__ f v)
new_features ;
Expand Down
Loading