WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH] add an explicit cache of the local hostname

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH] add an explicit cache of the local hostname
From: David Scott <dave.scott@xxxxxxxxxxxxx>
Date: Mon, 12 Apr 2010 17:56:11 +0100
Delivery-date: Mon, 12 Apr 2010 09:53:35 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User David Scott <dave.scott@xxxxxxxxxxxxx>
# Date 1271091282 -3600
# Node ID 06f4d30cef5f458c7b2cf8b47427424c9948db4f
# Parent  da78a9af0fdf61ad133a0c04d96d7eb286a94cdb
CA-40149: Add an explicit cache of the local hostname and make it posible to 
invalidate the cache.

The hostname is included in every log line.

Signed-off-by: David Scott <dave.scott@xxxxxxxxxxxxx>

diff -r da78a9af0fdf -r 06f4d30cef5f log/debug.ml
--- a/log/debug.ml      Fri Apr 09 10:49:50 2010 +0100
+++ b/log/debug.ml      Mon Apr 12 17:54:42 2010 +0100
@@ -21,11 +21,6 @@
 
 let get_thread_id () =
   try Thread.id (Thread.self ()) with _ -> -1 
-
-(* Theses functions need to be defined later in the code. *)
-let get_hostname = 
-  let f () = "Debug.get_hostname not set" in
-  ref f
 
 let associate_thread_with_task task = 
   let id = get_thread_id () in
@@ -81,8 +76,18 @@
   val name: string
 end
 
+let hostname_cache = ref None
+let hostname_m = Mutex.create ()
+let get_hostname () =
+  match Mutex.execute hostname_m (fun () -> !hostname_cache) with
+  | Some h -> h
+  | None ->
+               let h = Unix.gethostname () in
+               Mutex.execute hostname_m (fun () -> hostname_cache := Some h);
+               h
+let invalidate_hostname_cache () = Mutex.execute hostname_m (fun () -> 
hostname_cache := None)
+
 module Debugger = functor(Brand: BRAND) -> struct
-  let hostname = Unix.gethostname ()
   let _ =
     Mutex.execute dkmutex (fun () -> 
       debug_keys := StringSet.add Brand.name !debug_keys)
@@ -102,7 +107,7 @@
   let output (f:string -> ?extra:string -> ('a, unit, string, 'b) format4 -> 
'a) fmt =
     let extra = 
       Printf.sprintf "%s|%s|%s|%s" 
-      hostname
+      (get_hostname ())
       (get_thread_name ()) 
       (get_task ())
       Brand.name
@@ -112,7 +117,7 @@
        let output_and_return ?raw (f:string -> ?raw:bool -> ?extra:string -> 
('a, unit, string, 'b) format4 -> 'a) fmt =
     let extra =
       Printf.sprintf "%s|%s|%s|%s"
-      hostname
+      (get_hostname ())
       (get_thread_name ())
       (get_task ())
       Brand.name
diff -r da78a9af0fdf -r 06f4d30cef5f log/debug.mli
--- a/log/debug.mli     Fri Apr 09 10:49:50 2010 +0100
+++ b/log/debug.mli     Mon Apr 12 17:54:42 2010 +0100
@@ -13,6 +13,9 @@
  *)
 
 (** Debug utilities *)
+
+(** Throw away the cached hostname. The next log line will re-query the 
hostname *)
+val invalidate_hostname_cache: unit -> unit
 
 (** {2 Associate a task to the current actions} *)
 
2 files changed, 16 insertions(+), 8 deletions(-)
log/debug.ml  |   21 +++++++++++++--------
log/debug.mli |    3 +++


Attachment: xen-api-libs.hg.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-API] [PATCH] add an explicit cache of the local hostname, David Scott <=