@@ -30,8 +30,6 @@ module E = Debug.Make (struct let name = "mscgen" end)
3030
3131let cmd_name driver = sprintf " %s/%sSR" ! Xapi_globs. sm_dir driver
3232
33- let sm_username = " __sm__backend"
34-
3533let with_dbg ~name ~dbg f =
3634 Debug_info. with_dbg ~module_name: " Sm_exec" ~name ~dbg f
3735
@@ -317,80 +315,6 @@ let methodResponse xml =
317315 | xml ->
318316 XMLRPC.From. methodResponse xml
319317
320- let reusable_sessions : (string option, API.ref_session) Hashtbl.t =
321- Hashtbl. create 5
322-
323- let sm_sessions_m = Mutex. create ()
324-
325- let with_sm_sessions_lock f =
326- Xapi_stdext_threads.Threadext.Mutex. execute sm_sessions_m f
327-
328- let is_valid_session ~__context session_id =
329- try
330- (* Call an API function to check the session is still valid *)
331- let rpc = Helpers. make_rpc ~__context in
332- ignore (Client.Client.Pool. get_all ~rpc ~session_id ) ;
333- true
334- with Api_errors. Server_error (err , _ ) ->
335- debug " %s: Invalid session: %s" __FUNCTION__ err ;
336- false
337-
338- let session_access ~__context session sr =
339- (* Give this session access to this particular SR *)
340- Option. iter
341- (fun sr ->
342- Db.Session. add_to_other_config ~__context ~self: session
343- ~key: Xapi_globs. _sm_session ~value: (Ref. string_of sr)
344- )
345- sr
346-
347- let create_session ~__context sr =
348- let host = ! Xapi_globs. localhost_ref in
349- let session =
350- Xapi_session. login_no_password ~__context ~uname: None ~host ~pool: false
351- ~is_local_superuser: true ~subject: Ref. null ~auth_user_sid: " "
352- ~auth_user_name: sm_username ~rbac_permissions: []
353- in
354- session_access ~__context session sr ;
355- session
356-
357- let rec get_session ~__context sr =
358- let sr_key = Option. map Ref. string_of sr in
359- let session = Hashtbl. find_opt reusable_sessions sr_key in
360- match session with
361- | Some session ->
362- if is_valid_session ~__context session then
363- session
364- else (
365- with_sm_sessions_lock (fun () -> Hashtbl. remove reusable_sessions sr_key) ;
366- (get_session [@ tailcall]) ~__context sr
367- )
368- | None ->
369- let new_session = create_session ~__context sr in
370- with_sm_sessions_lock (fun () ->
371- match Hashtbl. find_opt reusable_sessions sr_key with
372- | None ->
373- Hashtbl. add reusable_sessions sr_key new_session ;
374- new_session
375- | Some session ->
376- Xapi_session. destroy_db_session ~__context ~self: new_session ;
377- session
378- )
379-
380- let with_session ~traceparent sr f =
381- Server_helpers. exec_with_new_task " sm_exec"
382- ~origin: (Internal_Traced traceparent) (fun __context ->
383- if ! Xapi_globs. reuse_pool_sessions then
384- let session_id = get_session ~__context sr in
385- f session_id
386- else
387- let session_id = create_session ~__context sr in
388- let destroy_session () =
389- Xapi_session. destroy_db_session ~__context ~self: session_id
390- in
391- finally (fun () -> f session_id) destroy_session
392- )
393-
394318(* ***************************************************************************************)
395319(* Functions that actually execute the python backends *)
396320
@@ -515,8 +439,9 @@ let exec_xmlrpc ~dbg ?context:_ ?(needs_session = true) (driver : string)
515439 )
516440 in
517441 if needs_session then
518- with_session ~traceparent: (Debug_info. span_of di) call.sr_ref
519- (fun session_id -> do_call {call with session_ref= Some session_id}
442+ Xapi_session.SM. with_session ~traceparent: (Debug_info. span_of di)
443+ call.sr_ref (fun session_id ->
444+ do_call {call with session_ref= Some session_id}
520445 )
521446 else
522447 do_call call
0 commit comments