diff --git a/lib/debug.ml b/lib/debug.ml index 96442986..8d34ced6 100644 --- a/lib/debug.ml +++ b/lib/debug.ml @@ -47,9 +47,15 @@ module ThreadLocalTable = struct IntMap.find_opt id t.tbl end -let names = ThreadLocalTable.make () -let tasks = ThreadLocalTable.make () +type task = { + desc: string + ; client: string option +} + +let tasks: task ThreadLocalTable.t = ThreadLocalTable.make () + +let names: string ThreadLocalTable.t = ThreadLocalTable.make () let gettimestring () = let time = Unix.gettimeofday () in @@ -67,11 +73,13 @@ let escape = Astring.String.Ascii.escape let format include_time brand priority message = let id = get_thread_id () in - let name = - match ThreadLocalTable.find names with Some x -> x | None -> "" - in - let task = - match ThreadLocalTable.find tasks with Some x -> x | None -> "" + let task, name = + (* if the task's client is known, attach it to the task's name *) + let name = match ThreadLocalTable.find names with Some x -> x | None -> "" in + match ThreadLocalTable.find tasks with + | None -> "", name + | Some {desc; client=None} -> desc, name + | Some {desc; client=Some client} -> desc, Printf.sprintf "%s->%s" client name in Printf.sprintf "[%s%5s||%d %s|%s|%s] %s" (if include_time then gettimestring () else "") @@ -201,8 +209,8 @@ let log_backtrace_exn ?(level = Syslog.Err) ?(msg = "error") exn _bt = let log_backtrace e bt = log_backtrace_exn e bt -let with_thread_associated task f x = - ThreadLocalTable.add tasks task ; +let with_thread_associated ?client desc f x = + ThreadLocalTable.add tasks {desc; client} ; let result = Backtrace.with_backtraces (fun () -> f x) in ThreadLocalTable.remove tasks ; match result with @@ -212,7 +220,7 @@ let with_thread_associated task f x = (* This function is a top-level exception handler typically used on fresh threads. This is the last chance to do something with the backtrace *) output_log "backtrace" Syslog.Err "error" - (Printf.sprintf "%s failed with exception %s" task + (Printf.sprintf "%s failed with exception %s" desc (Printexc.to_string exn)) ; log_backtrace exn bt ; raise exn diff --git a/lib/debug.mli b/lib/debug.mli index ca224e72..78b17cd5 100644 --- a/lib/debug.mli +++ b/lib/debug.mli @@ -20,7 +20,7 @@ val init_logs : unit -> unit (** {2 Associate a task to the current actions} *) -val with_thread_associated : string -> ('a -> 'b) -> 'a -> 'b +val with_thread_associated : ?client:string -> string -> ('a -> 'b) -> 'a -> 'b (** Do an action with a task name associated with the current thread *) (** {2 Associate a name to the current thread} *) diff --git a/xen/xenops_interface.ml b/xen/xenops_interface.ml index cebe545c..1d7cedc7 100644 --- a/xen/xenops_interface.ml +++ b/xen/xenops_interface.ml @@ -811,6 +811,13 @@ module XenopsAPI (R : RPC) = struct @-> Param.mk ~name:"metadata" Types.string @-> returning vm_id_p err ) + + let import_metadata_async = + declare "VM.import_metadata_async" [] + (debug_info_p + @-> Param.mk ~name:"metadata" Types.string + @-> returning task_id_p err + ) end module PCI = struct