Skip to content

Commit 36825ec

Browse files
committed
storage_access: share code for unregistering plugins
This helps seeing the structure of on_xapi_start when reading the code Signed-off-by: Pau Ruiz Safont <pau.safont@vates.tech>
1 parent f8b6991 commit 36825ec

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

ocaml/xapi/storage_access.ml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ let get_smapiv2_drivers_from_switch () =
149149
Debug.log_backtrace e (Backtrace.get e) ;
150150
[]
151151

152+
let log_and_unregister ~__context ~reason __FUN (self, rc) =
153+
info "%s: unregistering SM plugin %s (%s) since %s" __FUN rc.API.sM_name_label
154+
rc.API.sM_uuid reason ;
155+
try Db.SM.destroy ~__context ~self with _ -> ()
156+
152157
(** Synchronise the SM table with the SMAPIv1 plugins on the disk and the SMAPIv2
153158
plugins mentioned in the configuration file whitelist. *)
154159
let on_xapi_start ~__context =
@@ -182,26 +187,22 @@ let on_xapi_start ~__context =
182187
in
183188
(* Add all the running SMAPIv2 drivers *)
184189
let to_keep = to_keep @ running_smapiv2_drivers in
190+
let unused = Listext.List.set_difference (List.map fst existing) to_keep in
185191
let unavailable =
186192
List.filter (fun (_, (_, rc)) -> not (is_available rc)) existing
187193
in
188194
(* Delete all records which aren't configured or in-use *)
189-
List.iter
190-
(fun ty ->
191-
info
192-
"Unregistering SM plugin %s since not in the whitelist and not in-use"
193-
ty ;
194-
let self, _ = List.assoc ty existing in
195-
try Db.SM.destroy ~__context ~self with _ -> ()
196-
)
197-
(Listext.List.set_difference (List.map fst existing) to_keep) ;
198-
List.iter
199-
(fun (name, (self, rc)) ->
200-
info "%s: unregistering SM plugin %s (%s) since it is unavailable"
201-
__FUNCTION__ name rc.API.sM_uuid ;
202-
try Db.SM.destroy ~__context ~self with _ -> ()
203-
)
204-
unavailable ;
195+
let unregister_unused ty =
196+
let sm = List.assoc ty existing in
197+
let reason = "it's not in the allowed list and not in-use" in
198+
log_and_unregister ~__context ~reason __FUNCTION__ sm
199+
in
200+
let unregister_unavailable (_, sm) =
201+
let reason = "it's unavailable" in
202+
log_and_unregister ~__context ~reason __FUNCTION__ sm
203+
in
204+
List.iter unregister_unused unused ;
205+
List.iter unregister_unavailable unavailable ;
205206

206207
(* Synchronize SMAPIv1 plugins *)
207208

0 commit comments

Comments
 (0)