Skip to content

Commit

Permalink
CP-46379: Propagate 'traceparent' to 'Sm.*' functions
Browse files Browse the repository at this point in the history
Adds an optional parameter to 'Sm.*' function to inherit the
traceparent.

The 'traceparent' was not propagated to the functions inside 'sm.ml'.
This commit propagetes the 'traceparent' and instruments 'sm.ml' to
create spans for function calls.

Signed-off-by: Gabriel Buica <[email protected]>
  • Loading branch information
GabrielBuica committed Dec 15, 2023
1 parent 9ec01f0 commit f189579
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 37 deletions.
56 changes: 38 additions & 18 deletions ocaml/xapi/sm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ let driver_filename driver =

(*****************************************************************************)

let with_dbg ~name ~dbg f = Debuginfo.with_dbg ~module_name:"SM" ~name ~dbg f

let debug operation driver msg = debug "SM %s %s %s" driver operation msg

let srmaster_only (_, dconf) =
Expand Down Expand Up @@ -132,9 +134,10 @@ let sr_update dconf driver sr =
let call = Sm_exec.make_call ~sr_ref:sr dconf "sr_update" [] in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_create dconf driver sr sm_config vdi_type size name_label
let vdi_create ~dbg dconf driver sr sm_config vdi_type size name_label
name_description metadata_of_pool is_a_snapshot snapshot_time snapshot_of
read_only =
with_dbg ~dbg ~name:"vdi_create" @@ fun _ ->
debug "vdi_create" driver
(sprintf "sr=%s sm_config=[%s] type=[%s] size=%Ld" (Ref.string_of sr)
(String.concat "; " (List.map (fun (k, v) -> k ^ "=" ^ v) sm_config))
Expand All @@ -157,13 +160,15 @@ let vdi_create dconf driver sr sm_config vdi_type size name_label
in
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_update dconf driver sr vdi =
let vdi_update ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_update" @@ fun _ ->
debug "vdi_update" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
let call = Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_update" [] in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_introduce dconf driver sr new_uuid sm_config location =
let vdi_introduce ~dbg dconf driver sr new_uuid sm_config location =
with_dbg ~dbg ~name:"vdi_introduce" @@ fun _ ->
debug "vdi_introduce" driver
(sprintf "sr=%s new_uuid=%s sm_config=[%s] location=%s" (Ref.string_of sr)
new_uuid
Expand All @@ -176,14 +181,16 @@ let vdi_introduce dconf driver sr new_uuid sm_config location =
in
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_delete dconf driver sr vdi =
let vdi_delete ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_delete" @@ fun _ ->
debug "vdi_delete" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
srmaster_only dconf ;
let call = Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_delete" [] in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_attach dconf driver sr vdi writable =
let vdi_attach ~dbg dconf driver sr vdi writable =
with_dbg ~dbg ~name:"vdi_attach" @@ fun _ ->
debug "vdi_attach" driver
(sprintf "sr=%s vdi=%s writable=%b" (Ref.string_of sr) (Ref.string_of vdi)
writable
Expand All @@ -195,13 +202,15 @@ let vdi_attach dconf driver sr vdi writable =
let result = Sm_exec.exec_xmlrpc (driver_filename driver) call in
Sm_exec.parse_attach_result result

let vdi_detach dconf driver sr vdi =
let vdi_detach ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_detach" @@ fun _ ->
debug "vdi_detach" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
let call = Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_detach" [] in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_activate dconf driver sr vdi writable =
let vdi_activate ~dbg dconf driver sr vdi writable =
with_dbg ~dbg ~name:"vdi_activate" @@ fun _ ->
debug "vdi_activate" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
let call =
Expand All @@ -210,15 +219,17 @@ let vdi_activate dconf driver sr vdi writable =
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_deactivate dconf driver sr vdi =
let vdi_deactivate ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_deactivate" @@ fun _ ->
debug "vdi_deactivate" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
let call =
Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_deactivate" []
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_snapshot dconf driver driver_params sr vdi =
let vdi_snapshot ~dbg dconf driver driver_params sr vdi =
with_dbg ~dbg ~name:"vdi_snapshot" @@ fun _ ->
debug "vdi_snapshot" driver
(sprintf "sr=%s vdi=%s driver_params=[%s]" (Ref.string_of sr)
(Ref.string_of vdi)
Expand All @@ -231,7 +242,8 @@ let vdi_snapshot dconf driver driver_params sr vdi =
in
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_clone dconf driver driver_params sr vdi =
let vdi_clone ~dbg dconf driver driver_params sr vdi =
with_dbg ~dbg ~name:"vdi_clone" @@ fun _ ->
debug "vdi_clone" driver
(sprintf "sr=%s vdi=%s driver_params=[%s]" (Ref.string_of sr)
(Ref.string_of vdi)
Expand All @@ -244,7 +256,8 @@ let vdi_clone dconf driver driver_params sr vdi =
in
Sm_exec.parse_vdi_info (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_resize dconf driver sr vdi newsize =
let vdi_resize ~dbg dconf driver sr vdi newsize =
with_dbg ~dbg ~name:"vdi_resize" @@ fun _ ->
debug "vdi_resize" driver
(sprintf "sr=%s vdi=%s newsize=%Ld" (Ref.string_of sr) (Ref.string_of vdi)
newsize
Expand All @@ -264,7 +277,8 @@ let vdi_generate_config dconf driver sr vdi =
in
Sm_exec.parse_string (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_compose dconf driver sr vdi1 vdi2 =
let vdi_compose ~dbg dconf driver sr vdi1 vdi2 =
with_dbg ~dbg ~name:"vdi_compose" @@ fun _ ->
debug "vdi_compose" driver
(sprintf "sr=%s vdi1=%s vdi2=%s" (Ref.string_of sr) (Ref.string_of vdi1)
(Ref.string_of vdi2)
Expand All @@ -276,23 +290,26 @@ let vdi_compose dconf driver sr vdi1 vdi2 =
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_epoch_begin dconf driver sr vdi =
let vdi_epoch_begin ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_epoch_begin" @@ fun _ ->
debug "vdi_epoch_begin" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
let call =
Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_epoch_begin" []
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_epoch_end dconf driver sr vdi =
let vdi_epoch_end ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_epoch_end" @@ fun _ ->
debug "vdi_epoch_end" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
let call =
Sm_exec.make_call ~sr_ref:sr ~vdi_ref:vdi dconf "vdi_epoch_end" []
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_enable_cbt dconf driver sr vdi =
let vdi_enable_cbt ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_enable_cbt" @@ fun _ ->
debug "vdi_enable_cbt" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
srmaster_only dconf ;
Expand All @@ -301,7 +318,8 @@ let vdi_enable_cbt dconf driver sr vdi =
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_disable_cbt dconf driver sr vdi =
let vdi_disable_cbt ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_disable_cbt" @@ fun _ ->
debug "vdi_disable_cbt" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
srmaster_only dconf ;
Expand All @@ -310,7 +328,8 @@ let vdi_disable_cbt dconf driver sr vdi =
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_data_destroy dconf driver sr vdi =
let vdi_data_destroy ~dbg dconf driver sr vdi =
with_dbg ~dbg ~name:"vdi_data_destroy" @@ fun _ ->
debug "vdi_data_destroy" driver
(sprintf "sr=%s vdi=%s" (Ref.string_of sr) (Ref.string_of vdi)) ;
srmaster_only dconf ;
Expand All @@ -319,7 +338,8 @@ let vdi_data_destroy dconf driver sr vdi =
in
Sm_exec.parse_unit (Sm_exec.exec_xmlrpc (driver_filename driver) call)

let vdi_list_changed_blocks dconf driver sr ~vdi_from ~vdi_to =
let vdi_list_changed_blocks ~dbg dconf driver sr ~vdi_from ~vdi_to =
with_dbg ~dbg ~name:"vdi_list_changed_blocks" @@ fun _ ->
debug "vdi_list_changed_blocks" driver
(sprintf "sr=%s vdi_from=%s vdi_to=%s" (Ref.string_of sr)
(Ref.string_of vdi_from) (Ref.string_of vdi_to)
Expand Down
3 changes: 2 additions & 1 deletion ocaml/xapi/static_vdis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ let permanent_vdi_deactivate_by_uuid ~__context ~uuid =
try
let vdi = Db.VDI.get_by_uuid ~__context ~uuid in
Sm.call_sm_vdi_functions ~__context ~vdi (fun srconf srtype sr ->
Sm.vdi_deactivate srconf srtype sr vdi
let dbg = Context.string_of_task_and_tracing __context in
Sm.vdi_deactivate ~dbg srconf srtype sr vdi
)
with e ->
warn
Expand Down
36 changes: 18 additions & 18 deletions ocaml/xapi/storage_smapiv1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ module SMAPIv1 : Server_impl = struct
try
for_vdi ~dbg ~sr ~vdi "VDI.epoch_begin"
(fun device_config _type sr self ->
Sm.vdi_epoch_begin device_config _type sr self
Sm.vdi_epoch_begin ~dbg device_config _type sr self
)
with Api_errors.Server_error (code, params) ->
raise (Storage_error (Backend_error (code, params)))
Expand All @@ -511,7 +511,7 @@ module SMAPIv1 : Server_impl = struct
for_vdi ~dbg ~sr ~vdi "VDI.attach2"
(fun device_config _type sr self ->
let attach_info_v1 =
Sm.vdi_attach device_config _type sr self read_write
Sm.vdi_attach ~dbg device_config _type sr self read_write
in
(* Record whether the VDI is benefiting from read caching *)
Server_helpers.exec_with_new_task "VDI.attach2"
Expand Down Expand Up @@ -600,7 +600,7 @@ module SMAPIv1 : Server_impl = struct
(* If the backend doesn't advertise the capability then do nothing *)
if List.mem_assoc Smint.Vdi_activate (Sm.features_of_driver _type)
then
Sm.vdi_activate device_config _type sr self read_write
Sm.vdi_activate ~dbg device_config _type sr self read_write
else
info "%s sr:%s does not support vdi_activate: doing nothing" dp
(Ref.string_of sr)
Expand Down Expand Up @@ -629,7 +629,7 @@ module SMAPIv1 : Server_impl = struct
(* If the backend doesn't advertise the capability then do nothing *)
if List.mem_assoc Smint.Vdi_deactivate (Sm.features_of_driver _type)
then
Sm.vdi_deactivate device_config _type sr self
Sm.vdi_deactivate ~dbg device_config _type sr self
else
info "%s sr:%s does not support vdi_deactivate: doing nothing" dp
(Ref.string_of sr)
Expand All @@ -641,7 +641,7 @@ module SMAPIv1 : Server_impl = struct
with_dbg ~name:"VDI.detach" ~dbg @@ fun _ ->
try
for_vdi ~dbg ~sr ~vdi "VDI.detach" (fun device_config _type sr self ->
Sm.vdi_detach device_config _type sr self ;
Sm.vdi_detach ~dbg device_config _type sr self ;
Server_helpers.exec_with_new_task "VDI.detach"
~subtask_of:(Ref.of_string dbg) (fun __context ->
let on_key = read_caching_key ~__context in
Expand All @@ -664,7 +664,7 @@ module SMAPIv1 : Server_impl = struct
try
for_vdi ~dbg ~sr ~vdi "VDI.epoch_end"
(fun device_config _type sr self ->
Sm.vdi_epoch_end device_config _type sr self
Sm.vdi_epoch_end ~dbg device_config _type sr self
)
with Api_errors.Server_error (code, params) ->
raise (Storage_error (Backend_error (code, params)))
Expand All @@ -689,7 +689,7 @@ module SMAPIv1 : Server_impl = struct
let sr = Db.SR.get_by_uuid ~__context ~uuid:(s_of_sr sr) in
let vi =
Sm.call_sm_functions ~__context ~sR:sr (fun device_config _type ->
Sm.vdi_create device_config _type sr vdi_info.sm_config
Sm.vdi_create ~dbg device_config _type sr vdi_info.sm_config
vdi_info.ty vdi_info.virtual_size vdi_info.name_label
vdi_info.name_description vdi_info.metadata_of_pool
vdi_info.is_a_snapshot vdi_info.snapshot_time
Expand Down Expand Up @@ -717,7 +717,7 @@ module SMAPIv1 : Server_impl = struct
let vi =
for_vdi ~dbg ~sr ~vdi:vdi_info.vdi call_name
(fun device_config _type sr self ->
call_f device_config _type vdi_info.sm_config sr self
call_f ~dbg device_config _type vdi_info.sm_config sr self
)
in
(* PR-1255: modify clone, snapshot to take the same parameters as create? *)
Expand Down Expand Up @@ -756,7 +756,7 @@ module SMAPIv1 : Server_impl = struct
for_vdi ~dbg ~sr
~vdi:(Storage_interface.Vdi.of_string vi.Smint.vdi_info_location)
"VDI.update" (fun device_config _type sr self ->
Sm.vdi_update device_config _type sr self
Sm.vdi_update ~dbg device_config _type sr self
) ;
let vdi = vdi_info_from_db ~__context self in
debug "vdi = %s" (string_of_vdi_info vdi) ;
Expand Down Expand Up @@ -796,7 +796,7 @@ module SMAPIv1 : Server_impl = struct
try
let vi =
for_vdi ~dbg ~sr ~vdi "VDI.resize" (fun device_config _type sr self ->
Sm.vdi_resize device_config _type sr self new_size
Sm.vdi_resize ~dbg device_config _type sr self new_size
)
in
Server_helpers.exec_with_new_task "VDI.resize"
Expand All @@ -819,7 +819,7 @@ module SMAPIv1 : Server_impl = struct
with_dbg ~name:"VDI.destroy" ~dbg @@ fun _ ->
try
for_vdi ~dbg ~sr ~vdi "VDI.destroy" (fun device_config _type sr self ->
Sm.vdi_delete device_config _type sr self
Sm.vdi_delete ~dbg device_config _type sr self
) ;
with_lock vdi_read_write_m (fun () ->
Hashtbl.remove vdi_read_write (sr, vdi)
Expand All @@ -838,7 +838,7 @@ module SMAPIv1 : Server_impl = struct
Server_helpers.exec_with_new_task "VDI.stat"
~subtask_of:(Ref.of_string dbg) (fun __context ->
for_vdi ~dbg ~sr ~vdi "VDI.stat" (fun device_config _type sr self ->
Sm.vdi_update device_config _type sr self ;
Sm.vdi_update ~dbg device_config _type sr self ;
vdi_info_of_vdi_rec __context
(Db.VDI.get_record ~__context ~self)
)
Expand All @@ -856,7 +856,7 @@ module SMAPIv1 : Server_impl = struct
let vi =
Sm.call_sm_functions ~__context ~sR:sr
(fun device_config sr_type ->
Sm.vdi_introduce device_config sr_type sr uuid sm_config
Sm.vdi_introduce ~dbg device_config sr_type sr uuid sm_config
location
)
in
Expand All @@ -878,13 +878,13 @@ module SMAPIv1 : Server_impl = struct
let new_vdi =
for_vdi ~dbg ~sr ~vdi "VDI.clone"
(fun device_config _type sr self ->
let vi = Sm.vdi_clone device_config _type [] sr self in
let vi = Sm.vdi_clone ~dbg device_config _type [] sr self in
Storage_interface.Vdi.of_string vi.Smint.vdi_info_location
)
in
for_vdi ~dbg ~sr ~vdi:new_vdi "VDI.destroy"
(fun device_config _type sr self ->
Sm.vdi_delete device_config _type sr self
Sm.vdi_delete ~dbg device_config _type sr self
)
)
)
Expand Down Expand Up @@ -1046,7 +1046,7 @@ module SMAPIv1 : Server_impl = struct
let vdi1 = find_vdi ~__context sr vdi1 |> fst in
for_vdi ~dbg ~sr ~vdi:vdi2 "VDI.compose"
(fun device_config _type sr self ->
Sm.vdi_compose device_config _type sr vdi1 self
Sm.vdi_compose ~dbg device_config _type sr vdi1 self
)
)
with
Expand Down Expand Up @@ -1107,7 +1107,7 @@ module SMAPIv1 : Server_impl = struct
with_dbg ~name:"VDI.call_cbt_function" ~dbg @@ fun _ ->
try
for_vdi ~dbg ~sr ~vdi f_name (fun device_config _type sr self ->
f device_config _type sr self
f ~dbg device_config _type sr self
)
with
| Smint.Not_implemented_in_backend ->
Expand Down Expand Up @@ -1142,7 +1142,7 @@ module SMAPIv1 : Server_impl = struct
let vdi_from = find_vdi ~__context sr vdi_from |> fst in
for_vdi ~dbg ~sr ~vdi:vdi_to "VDI.list_changed_blocks"
(fun device_config _type sr vdi_to ->
Sm.vdi_list_changed_blocks device_config _type sr ~vdi_from
Sm.vdi_list_changed_blocks ~dbg device_config _type sr ~vdi_from
~vdi_to
)
)
Expand Down

0 comments on commit f189579

Please sign in to comment.