@@ -898,6 +898,9 @@ let external_rpc queue_name uri =
898898 uri
899899 call
900900
901+ (* Internal exception, never escapes the module *)
902+ exception Message_switch_failure
903+
901904(* * Synchronise the SM table with the SMAPIv1 plugins on the disk and the SMAPIv2
902905 plugins mentioned in the configuration file whitelist. *)
903906let on_xapi_start ~__context =
@@ -929,6 +932,38 @@ let on_xapi_start ~__context =
929932 Xapi_sm. update_from_query_result ~__context (List. assoc ty existing) query_result
930933 ) (List. intersect smapiv1_drivers (List. map fst existing));
931934 let smapiv2_drivers = List. set_difference to_keep smapiv1_drivers in
935+ (* Query the message switch to detect running SMAPIv2 plugins. *)
936+ let running_smapiv2_drivers =
937+ if ! Xcp_client. use_switch then begin
938+ try
939+ let open Message_switch in
940+ let open Protocol_unix in
941+ let (>>|) result f =
942+ match Client. error_to_msg result with
943+ | `Error (`Msg x ) ->
944+ error " Error %s while querying message switch queues" x;
945+ raise Message_switch_failure
946+ | `Ok x -> f x
947+ in
948+ Client. connect ~switch: ! Xcp_client. switch_path ()
949+ >> | fun t ->
950+ Client. list ~t ~prefix: ! Storage_interface. queue_name ~filter: `Alive ()
951+ >> | fun running_smapiv2_driver_queues ->
952+ List. filter
953+ (fun driver ->
954+ List. exists
955+ (Xstringext.String. endswith driver)
956+ running_smapiv2_driver_queues)
957+ smapiv2_drivers
958+ with
959+ | Message_switch_failure -> [] (* no more logging *)
960+ | e ->
961+ error " Unexpected error querying the message switch: %s" (Printexc. to_string e);
962+ Debug. log_backtrace e (Backtrace. get e);
963+ []
964+ end
965+ else smapiv2_drivers
966+ in
932967 (* Create all missing SMAPIv2 plugins *)
933968 let query ty =
934969 let queue_name = ! Storage_interface. queue_name ^ " ." ^ ty in
@@ -940,12 +975,12 @@ let on_xapi_start ~__context =
940975 List. iter
941976 (fun ty ->
942977 Xapi_sm. create_from_query_result ~__context (query ty)
943- ) (List. set_difference smapiv2_drivers (List. map fst existing));
978+ ) (List. set_difference running_smapiv2_drivers (List. map fst existing));
944979 (* Update all existing SMAPIv2 plugins *)
945980 List. iter
946981 (fun ty ->
947982 Xapi_sm. update_from_query_result ~__context (List. assoc ty existing) (query ty)
948- ) (List. intersect smapiv2_drivers (List. map fst existing))
983+ ) (List. intersect running_smapiv2_drivers (List. map fst existing))
949984
950985let bind ~__context ~pbd =
951986 (* Start the VM if necessary, record its uuid *)
0 commit comments