@@ -21,7 +21,8 @@ let finally = Xapi_stdext_pervasives.Pervasiveext.finally
2121
2222module XenAPI = Client. Client
2323open Storage_interface
24- open Storage_utils
24+
25+ let transform_storage_exn = Storage_utils. transform_storage_exn
2526
2627module D = Debug. Make (struct let name = " storage_access" end )
2728
@@ -103,8 +104,50 @@ let external_rpc queue_name uri =
103104(* Internal exception, never escapes the module *)
104105exception Message_switch_failure
105106
106- (* We have to be careful in this function, because an exception raised from
107- here will cause the startup sequence to fail *)
107+ (* We have to be careful in the call tree of on_xapi_start, because an
108+ exception raised in it will cause the startup sequence to fail *)
109+
110+ let get_smapiv2_drivers_from_switch () =
111+ let module Client = Message_switch_unix.Protocol_unix. Client in
112+ try
113+ let ( >>| ) result f =
114+ match Client. error_to_msg result with
115+ | Error (`Msg x ) ->
116+ error " %s: Error %s while querying message switch queues" __FUNCTION__
117+ x ;
118+ raise Message_switch_failure
119+ | Ok x ->
120+ f x
121+ in
122+ Client. connect ~switch: ! Xcp_client. switch_path () >> | fun t ->
123+ Client. list ~t ~prefix: ! Storage_interface. queue_name ~filter: `Alive ()
124+ >> | fun running_smapiv2_driver_queues ->
125+ running_smapiv2_driver_queues
126+ (* The results include the prefix itself, but that is the main storage
127+ queue, we don't need it *)
128+ |> List. filter (( <> ) ! Storage_interface. queue_name)
129+ |> Listext.List. try_map (fun driver ->
130+ (* Get the last component of the queue name:
131+ org.xen.xapi.storage.sr_type -> sr_type *)
132+ driver
133+ |> String. split_on_char '.'
134+ |> Listext.List. last
135+ |> Option. to_result ~none: (Invalid_argument driver)
136+ )
137+ |> function
138+ | Ok drivers ->
139+ drivers
140+ | Error exn ->
141+ raise exn
142+ with
143+ | Message_switch_failure ->
144+ [] (* no more logging *)
145+ | e ->
146+ Backtrace. is_important e ;
147+ error " Unexpected error querying the message switch: %s"
148+ (Printexc. to_string e) ;
149+ Debug. log_backtrace e (Backtrace. get e) ;
150+ []
108151
109152(* * Synchronise the SM table with the SMAPIv1 plugins on the disk and the SMAPIv2
110153 plugins mentioned in the configuration file whitelist. *)
@@ -130,52 +173,12 @@ let on_xapi_start ~__context =
130173 List. map (fun (_ , rc ) -> rc.API. sR_type) (Db.SR. get_all_records ~__context)
131174 in
132175 let to_keep = configured_drivers @ in_use_drivers in
133- (* The SMAPIv2 drivers we know about *)
134- let smapiv2_drivers = Listext.List. set_difference to_keep smapiv1_drivers in
135176 (* Query the message switch to detect running SMAPIv2 plugins. *)
136177 let running_smapiv2_drivers =
137- if ! Xcp_client. use_switch then (
138- try
139- let open Message_switch_unix.Protocol_unix in
140- let ( >>| ) result f =
141- match Client. error_to_msg result with
142- | Error (`Msg x ) ->
143- error " Error %s while querying message switch queues" x ;
144- raise Message_switch_failure
145- | Ok x ->
146- f x
147- in
148- Client. connect ~switch: ! Xcp_client. switch_path () >> | fun t ->
149- Client. list ~t ~prefix: ! Storage_interface. queue_name ~filter: `Alive ()
150- >> | fun running_smapiv2_driver_queues ->
151- running_smapiv2_driver_queues
152- (* The results include the prefix itself, but that is the main storage
153- queue, we don't need it *)
154- |> List. filter (( <> ) ! Storage_interface. queue_name)
155- |> Listext.List. try_map (fun driver ->
156- (* Get the last component of the queue name:
157- org.xen.xapi.storage.sr_type -> sr_type *)
158- driver
159- |> String. split_on_char '.'
160- |> Listext.List. last
161- |> Option. to_result ~none: (Invalid_argument driver)
162- )
163- |> function
164- | Ok drivers ->
165- drivers
166- | Error exn ->
167- raise exn
168- with
169- | Message_switch_failure ->
170- [] (* no more logging *)
171- | e ->
172- Backtrace. is_important e ;
173- error " Unexpected error querying the message switch: %s"
174- (Printexc. to_string e) ;
175- Debug. log_backtrace e (Backtrace. get e) ;
176- []
177- ) else
178- smapiv2_drivers
178+ if ! Xcp_client. use_switch then
179+ get_smapiv2_drivers_from_switch ()
180+ else (* The SMAPIv2 drivers we know about *)
181+ Listext.List. set_difference to_keep smapiv1_drivers
179182 in
180183 (* Add all the running SMAPIv2 drivers *)
181184 let to_keep = to_keep @ running_smapiv2_drivers in
0 commit comments