Skip to content

Commit ac216e9

Browse files
committed
storage_access: log when there are SM duplicates on startup
This should help document the cases where the issue persists, even after the tweaks done to the function. Only some fields are kept because of their relevance to the issue, and to help identify them. The rest of the fields are less dynamic or hold much less significance. For example, capabilities is an unversioned field of features. Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent e12dd8a commit ac216e9

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

ocaml/xapi/storage_access.ml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ let ( let@ ) f x = f x
169169
(** Synchronise the SM table with the SMAPIv1 plugins on the disk and the SMAPIv2
170170
plugins mentioned in the configuration file whitelist. *)
171171
let on_xapi_start ~__context =
172+
let __FUN = __FUNCTION__ in
172173
(* An SM is either implemented as a plugin - for which we check its
173174
presence, or via an API *)
174175
let is_available rc =
@@ -275,7 +276,50 @@ let on_xapi_start ~__context =
275276
list_assoc_all ty existing
276277
|> List.iter (fun sm -> Xapi_sm.update_from_query_result ~__context sm qr)
277278
)
278-
(StringSet.inter running_smapiv2_drivers existing_types)
279+
(StringSet.inter running_smapiv2_drivers existing_types) ;
280+
281+
(* Warn in logs when there are still duplicates *)
282+
let add_to_dups (last, dups) (_, curr) =
283+
match (last.API.sM_type = curr.API.sM_type, dups) with
284+
| false, _ ->
285+
(curr, dups)
286+
| true, x :: _ when x = last ->
287+
(curr, curr :: dups)
288+
| true, _ ->
289+
(curr, curr :: last :: dups)
290+
in
291+
let find_all_duplicates lst =
292+
lst
293+
|> List.sort (fun (_, a_rc) (_, b_rc) ->
294+
Stdlib.compare a_rc.API.sM_type b_rc.API.sM_type
295+
)
296+
|> function
297+
| [] ->
298+
[]
299+
| head :: rest ->
300+
List.fold_left add_to_dups (snd head, []) rest |> snd
301+
in
302+
303+
let features_to_string feats =
304+
Fmt.(to_to_string (Dump.list (Dump.pair string int64)) feats)
305+
in
306+
let plugin_to_string plugin =
307+
Printf.sprintf "{ type:%s; name:%s; UUID:%s; features:%s; }"
308+
plugin.API.sM_type plugin.API.sM_name_label plugin.API.sM_uuid
309+
(features_to_string plugin.API.sM_features)
310+
in
311+
let log_plugins = function
312+
| [] ->
313+
()
314+
| duplicates ->
315+
let duplicates =
316+
String.concat "\n; " (List.map plugin_to_string duplicates)
317+
in
318+
warn "%s: found duplicate SM plugins for the same type: [\n %s\n]"
319+
__FUN duplicates
320+
in
321+
322+
Db.SM.get_all_records ~__context |> find_all_duplicates |> log_plugins
279323

280324
let bind ~__context ~pbd =
281325
let dbg = Context.string_of_task __context in

0 commit comments

Comments
 (0)