From 29bf2302a3756f9e190579982d736056dd4403ce Mon Sep 17 00:00:00 2001 From: lippirk Date: Tue, 20 Oct 2020 15:23:23 +0100 Subject: [PATCH 1/2] CP-35026 optionally include client info in logs Signed-off-by: lippirk (cherry picked from commit 7e6d615526e7e356dee3a2e1baf666ef3997e621) --- lib/debug.ml | 28 ++++++++++++++++++---------- lib/debug.mli | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) 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} *) From 485a86b4fafae6b6c6ce314f9d8f1a5ee623e1a0 Mon Sep 17 00:00:00 2001 From: Rob Hoes Date: Mon, 9 Nov 2020 22:16:28 +0000 Subject: [PATCH 2/2] CA-347560: Add VM.import_metadata_async This is a variant of `VM.import_metadata` that always queues the operation and returns a task id immediately (like most VM operations). This is useful, once the original (synchronous) function may block for longer periods while other operations on the VM complete. Signed-off-by: Rob Hoes (cherry picked from commit 83de389b98214d283ca73d23255601232fc8ef1c) --- xen/xenops_interface.ml | 7 +++++++ 1 file changed, 7 insertions(+) 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