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-devel

[Xen-devel] [PATCH 2 of 3] Remove oxenstored's dependency on the log lib

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 2 of 3] Remove oxenstored's dependency on the log library of xapi-libs
From: Zheng Li <zheng.li@xxxxxxxxxxxxx>
Date: Sun, 31 Jul 2011 08:59:05 +0000
Delivery-date: Sun, 31 Jul 2011 02:08:25 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1312102743@eta>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1312102743@eta>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
... by consolidating some of the functions with its own logging facility.

Signed-off-by: Zheng Li <zheng.li@xxxxxxxxxxxxx>


----
diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
--- a/tools/ocaml/xenstored/Makefile
+++ b/tools/ocaml/xenstored/Makefile
@@ -3,9 +3,7 @@ OCAML_TOPLEVEL = $(CURDIR)/..
 include $(OCAML_TOPLEVEL)/common.make
 
 OCAMLINCLUDE += \
-       -I $(OCAML_TOPLEVEL)/libs/log \
        -I $(OCAML_TOPLEVEL)/libs/xb \
-       -I $(OCAML_TOPLEVEL)/libs/uuid \
        -I $(OCAML_TOPLEVEL)/libs/mmap \
        -I $(OCAML_TOPLEVEL)/libs/xc \
        -I $(OCAML_TOPLEVEL)/libs/eventchn
@@ -34,9 +32,7 @@ OBJS = define \
 INTF = symbol.cmi trie.cmi
 XENSTOREDLIBS = \
        unix.cmxa \
-       $(OCAML_TOPLEVEL)/libs/uuid/uuid.cmxa \
        -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/mmap 
$(OCAML_TOPLEVEL)/libs/mmap/mmap.cmxa \
-       -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/log 
$(OCAML_TOPLEVEL)/libs/log/log.cmxa \
        -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn 
$(OCAML_TOPLEVEL)/libs/eventchn/eventchn.cmxa \
        -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc 
$(OCAML_TOPLEVEL)/libs/xc/xc.cmxa \
        -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb 
$(OCAML_TOPLEVEL)/libs/xb/xb.cmxa \
diff --git a/tools/ocaml/xenstored/connection.ml 
b/tools/ocaml/xenstored/connection.ml
--- a/tools/ocaml/xenstored/connection.ml
+++ b/tools/ocaml/xenstored/connection.ml
@@ -232,3 +232,8 @@ let dump con chan =
                        Printf.fprintf chan "watch,%d,%s,%s\n" domid 
(Utils.hexify path) (Utils.hexify token)
                        ) (list_watches con);
        | None -> ()
+
+let debug con =
+       let domid = get_domstr con in
+       let watches = List.map (fun (path, token) -> Printf.sprintf "watch %s: 
%s %s\n" domid path token) (list_watches con) in
+       String.concat "" watches
diff --git a/tools/ocaml/xenstored/connections.ml 
b/tools/ocaml/xenstored/connections.ml
--- a/tools/ocaml/xenstored/connections.ml
+++ b/tools/ocaml/xenstored/connections.ml
@@ -15,7 +15,7 @@
  * GNU Lesser General Public License for more details.
  *)
 
-let debug fmt = Logs.debug "general" fmt
+let debug fmt = Logging.debug "connections" fmt
 
 type t = {
        mutable anonymous: Connection.t list;
@@ -165,3 +165,8 @@ let stats cons =
        );
        (List.length cons.anonymous, !nb_ops_anon, !nb_watchs_anon,
         Hashtbl.length cons.domains, !nb_ops_dom, !nb_watchs_dom)
+
+let debug cons =
+       let anonymous = List.map Connection.debug cons.anonymous in
+       let domains = Hashtbl.fold (fun _ con accu -> Connection.debug con :: 
accu) cons.domains [] in
+       String.concat "" (domains @ anonymous)
diff --git a/tools/ocaml/xenstored/disk.ml b/tools/ocaml/xenstored/disk.ml
--- a/tools/ocaml/xenstored/disk.ml
+++ b/tools/ocaml/xenstored/disk.ml
@@ -17,7 +17,7 @@
 let enable = ref false
 let xs_daemon_database = "/var/run/xenstored/db"
 
-let error = Logs.error "general"
+let error fmt = Logging.error "disk" fmt
 
 (* unescape utils *)
 exception Bad_escape
diff --git a/tools/ocaml/xenstored/domain.ml b/tools/ocaml/xenstored/domain.ml
--- a/tools/ocaml/xenstored/domain.ml
+++ b/tools/ocaml/xenstored/domain.ml
@@ -16,7 +16,7 @@
 
 open Printf
 
-let debug fmt = Logs.debug "general" fmt
+let debug fmt = Logging.debug "domain" fmt
 
 type t =
 {
diff --git a/tools/ocaml/xenstored/domains.ml b/tools/ocaml/xenstored/domains.ml
--- a/tools/ocaml/xenstored/domains.ml
+++ b/tools/ocaml/xenstored/domains.ml
@@ -14,6 +14,8 @@
  * GNU Lesser General Public License for more details.
  *)
 
+let debug fmt = Logging.debug "domains" fmt
+
 type domains = {
        eventchn: Event.t;
        table: (Xc.domid, Domain.t) Hashtbl.t;
@@ -35,7 +37,7 @@ let cleanup xc doms =
                try
                        let info = Xc.domain_getinfo xc id in
                        if info.Xc.shutdown || info.Xc.dying then (
-                               Logs.debug "general" "Domain %u died (dying=%b, 
shutdown %b -- code %d)"
+                               debug "Domain %u died (dying=%b, shutdown %b -- 
code %d)"
                                                    id info.Xc.dying 
info.Xc.shutdown info.Xc.shutdown_code;
                                if info.Xc.dying then
                                        dead_dom := id :: !dead_dom
@@ -43,7 +45,7 @@ let cleanup xc doms =
                                        notify := true;
                        )
                with Xc.Error _ ->
-                       Logs.debug "general" "Domain %u died -- no domain info" 
id;
+                       debug "Domain %u died -- no domain info" id;
                        dead_dom := id :: !dead_dom;
                ) doms.table;
        List.iter (fun id ->
diff --git a/tools/ocaml/xenstored/logging.ml b/tools/ocaml/xenstored/logging.ml
--- a/tools/ocaml/xenstored/logging.ml
+++ b/tools/ocaml/xenstored/logging.ml
@@ -17,21 +17,122 @@
 open Stdext
 open Printf
 
-let error fmt = Logs.error "general" fmt
-let info fmt = Logs.info "general" fmt
-let debug fmt = Logs.debug "general" fmt
 
-let access_log_file = ref "/var/log/xenstored-access.log"
-let access_log_nb_files = ref 20
-let access_log_nb_lines = ref 13215
-let activate_access_log = ref true
+(* Logger common *)
 
-(* maximal size of the lines in xenstore-acces.log file *)
-let line_size = 180
+type logger =
+               { stop: unit -> unit;
+                 restart: unit -> unit;
+                 rotate: unit -> unit;
+                 write: 'a. ('a, unit, string, unit) format4 -> 'a }
 
-let log_read_ops = ref false
-let log_transaction_ops = ref false
-let log_special_ops = ref false
+let truncate_line nb_chars line = 
+       if String.length line > nb_chars - 1 then
+               let len = max (nb_chars - 1) 2 in
+               let dst_line = String.create len in
+               String.blit line 0 dst_line 0 (len - 2);
+               dst_line.[len-2] <- '.'; 
+               dst_line.[len-1] <- '.';
+               dst_line
+       else line
+
+let log_rotate ref_ch log_file log_nb_files =
+       let file n = sprintf "%s.%i" log_file n in
+       let log_files =
+               let rec aux accu n =
+                       if n >= log_nb_files then accu
+                       else
+                               if n = 1 && Sys.file_exists log_file
+                               then aux [log_file,1] 2
+                               else
+                                       let file = file (n-1) in
+                                       if Sys.file_exists file then
+                                               aux ((file, n) :: accu) (n+1)
+                                       else accu in
+               aux [] 1 in
+       List.iter (fun (f, n) -> Unix.rename f (file n)) log_files;
+       close_out !ref_ch;
+       ref_ch := open_out log_file
+
+let make_logger log_file log_nb_files log_nb_lines log_nb_chars post_rotate =
+       let channel = ref (open_out_gen [Open_append; Open_creat] 0o644 
log_file) in
+       let counter = ref 0 in
+       let stop() =
+               try flush !channel; close_out !channel
+               with _ -> () in
+       let restart() =
+               stop();
+               channel := open_out_gen [Open_append; Open_creat] 0o644 
log_file in
+       let rotate() =
+               log_rotate channel log_file log_nb_files;
+               (post_rotate (): unit);
+               counter := 0 in
+       let output s =
+               let s = if log_nb_chars > 0 then truncate_line log_nb_chars s 
else s in
+               let s = s ^ "\n" in
+               output_string !channel s;
+               flush !channel;
+               incr counter;
+               if !counter > log_nb_lines then rotate() in
+       { stop; restart; rotate; write = fun fmt -> Printf.ksprintf output fmt }
+
+
+(* Xenstored logger *) 
+
+exception Unknown_level of string
+
+type level = Debug | Info | Warn | Error | Null
+
+let int_of_level = function
+       | Debug -> 0 | Info -> 1 | Warn -> 2
+       | Error -> 3 | Null -> max_int
+
+let string_of_level = function
+       | Debug -> "debug" | Info -> "info" | Warn -> "warn"
+       | Error -> "error" | Null -> "null"
+
+let level_of_string = function
+       | "debug" -> Debug | "info"  -> Info | "warn"  -> Warn
+       | "error" -> Error | "null"  -> Null | s  -> raise (Unknown_level s)
+
+let string_of_date () =
+       let time = Unix.gettimeofday () in
+       let tm = Unix.gmtime time in
+       let msec = time -. (floor time) in
+       sprintf "%d%.2d%.2dT%.2d:%.2d:%.2d.%.3dZ"
+               (1900 + tm.Unix.tm_year) (tm.Unix.tm_mon + 1) tm.Unix.tm_mday
+               tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec
+               (int_of_float (1000.0 *. msec))
+
+let xenstored_log_file = ref "/var/log/xenstored.log"
+let xenstored_log_level = ref Null
+let xenstored_log_nb_files = ref 10
+let xenstored_log_nb_lines = ref 13215
+let xenstored_log_nb_chars = ref (-1)
+let xenstored_logger = ref (None: logger option)
+
+let init_xenstored_log () =
+       if !xenstored_log_level <> Null && !xenstored_log_nb_files > 0 then
+               let logger =
+                       make_logger 
+                               !xenstored_log_file !xenstored_log_nb_files 
!xenstored_log_nb_lines
+                               !xenstored_log_nb_chars ignore in
+               xenstored_logger := Some logger
+
+let xenstored_logging level key (fmt: (_,_,_,_) format4) =
+       match !xenstored_logger with
+       | Some logger when int_of_level level >= int_of_level 
!xenstored_log_level ->
+                       let date = string_of_date() in
+                       let level = string_of_level level in
+                       logger.write ("[%s|%5s|%s] " ^^ fmt) date level key
+       | _ -> Printf.ksprintf ignore fmt
+
+let debug key = xenstored_logging Debug key
+let info key = xenstored_logging Info key
+let warn key = xenstored_logging Warn key
+let error key = xenstored_logging Error key
+
+(* Access logger *)
 
 type access_type =
        | Coalesce
@@ -41,38 +142,10 @@ type access_type =
        | Endconn
        | XbOp of Xb.Op.operation
 
-type access =
-       {
-               fd: out_channel ref;
-               counter: int ref;
-               write: tid:int -> con:string -> ?data:string -> access_type -> 
unit;
-       }
-
-let string_of_date () =
-       let time = Unix.gettimeofday () in
-       let tm = Unix.localtime time in
-       let msec = time -. (floor time) in
-       sprintf "%d%.2d%.2d %.2d:%.2d:%.2d.%.3d" (1900 + tm.Unix.tm_year)
-               (tm.Unix.tm_mon + 1)
-               tm.Unix.tm_mday
-               tm.Unix.tm_hour
-               tm.Unix.tm_min
-               tm.Unix.tm_sec
-               (int_of_float (1000.0 *. msec))
-
-let fill_with_space n s =
-       if String.length s < n
-       then 
-               let r = String.make n ' ' in
-               String.blit s 0  r 0 (String.length s);
-               r
-       else 
-               s
-
 let string_of_tid ~con tid =
        if tid = 0
-       then fill_with_space 12 (sprintf "%s" con)
-       else fill_with_space 12 (sprintf "%s.%i" con tid)
+       then sprintf "%-12s" con
+       else sprintf "%-12s" (sprintf "%s.%i" con tid)
 
 let string_of_access_type = function
        | Coalesce                -> "coalesce "
@@ -109,41 +182,9 @@ let string_of_access_type = function
 
        | Xb.Op.Error             -> "error    "
        | Xb.Op.Watchevent        -> "w event  "
-
+               (* 
        | x                       -> Xb.Op.to_string x
-
-let file_exists file =
-       try
-               Unix.close (Unix.openfile file [Unix.O_RDONLY] 0o644);
-               true
-       with _ ->
-               false
-
-let log_rotate fd =
-       let file n = sprintf "%s.%i" !access_log_file n in
-       let log_files =
-               let rec aux accu n =
-                       if n >= !access_log_nb_files
-                       then accu
-                       else if n = 1 && file_exists !access_log_file
-                       then aux [!access_log_file,1] 2
-                       else
-                               let file = file (n-1) in
-                               if file_exists file
-                               then aux ((file,n) :: accu) (n+1)
-                               else accu
-               in
-               aux [] 1
-       in
-       let rec rename = function
-               | (f,n) :: t when n < !access_log_nb_files -> 
-                       Unix.rename f (file n);
-                       rename t
-               | _ -> ()
-       in
-       rename log_files;
-       close_out !fd;
-       fd := open_out !access_log_file
+               *) 
 
 let sanitize_data data =
        let data = String.copy data in
@@ -154,86 +195,67 @@ let sanitize_data data =
        done;
        String.escaped data
 
-let make save_to_disk =
-       let fd = ref (open_out_gen [Open_append; Open_creat] 0o644 
!access_log_file) in
-       let counter = ref 0 in
-       {
-               fd = fd;
-               counter = counter;
-               write = 
-                       if not !activate_access_log || !access_log_nb_files = 0
-                       then begin fun ~tid ~con ?data _ -> () end
-                       else fun ~tid ~con ?(data="") access_type ->
-                               let s = Printf.sprintf "[%s] %s %s %s\n" 
(string_of_date()) (string_of_tid ~con tid) 
-                                       (string_of_access_type access_type) 
(sanitize_data data) in
-                               let s =
-                                       if String.length s > line_size
-                                       then begin
-                                               let s = String.sub s 0 
line_size in
-                                               s.[line_size-3] <- '.'; 
-                                               s.[line_size-2] <- '.';
-                                               s.[line_size-1] <- '\n';
-                                               s
-                                       end else
-                                               s
-                               in
-                               incr counter;
-                               output_string !fd s;
-                               flush !fd;
-                               if !counter > !access_log_nb_lines 
-                               then begin 
-                                       log_rotate fd;
-                                       save_to_disk ();
-                                       counter := 0;
-                               end
-       }
+let activate_access_log = ref true
+let access_log_file = ref "/var/log/xenstored-access.log"
+let access_log_nb_files = ref 20
+let access_log_nb_lines = ref 13215
+let access_log_nb_chars = ref 180
+let access_log_read_ops = ref false
+let access_log_transaction_ops = ref false
+let access_log_special_ops = ref false
+let access_logger = ref None
 
-let access : (access option) ref = ref None
-let init aal save_to_disk =
-       activate_access_log := aal;
-       access := Some (make save_to_disk)
+let init_access_log post_rotate =
+       if !access_log_nb_files > 0 then
+               let logger =
+                       make_logger
+                               !access_log_file !access_log_nb_files 
!access_log_nb_lines
+                               !access_log_nb_chars post_rotate in
+               access_logger := Some logger
 
-let write_access_log ~con ~tid ?data access_type = 
+let access_logging ~con ~tid ?(data="") access_type =
         try
-         maybe (fun a -> a.write access_type ~con ~tid ?data) !access
+               maybe
+                       (fun logger ->
+                               let date = string_of_date() in
+                               let tid = string_of_tid ~con tid in
+                               let access_type = string_of_access_type 
access_type in
+                               let data = sanitize_data data in
+                               logger.write "[%s] %s %s %s" date tid 
access_type data)
+                       !access_logger
        with _ -> ()
 
-let new_connection = write_access_log Newconn
-let end_connection = write_access_log Endconn
+let new_connection = access_logging Newconn
+let end_connection = access_logging Endconn
 let read_coalesce ~tid ~con data =
-       if !log_read_ops
-       then write_access_log Coalesce ~tid ~con ~data:("read "^data)
-let write_coalesce data = write_access_log Coalesce ~data:("write "^data)
-let conflict = write_access_log Conflict
-let commit = write_access_log Commit
+       if !access_log_read_ops
+       then access_logging Coalesce ~tid ~con ~data:("read "^data)
+let write_coalesce data = access_logging Coalesce ~data:("write "^data)
+let conflict = access_logging Conflict
+let commit = access_logging Commit
 
 let xb_op ~tid ~con ~ty data =
-       let print =
-       match ty with
-               | Xb.Op.Read | Xb.Op.Directory | Xb.Op.Getperms -> !log_read_ops
+       let print = match ty with
+               | Xb.Op.Read | Xb.Op.Directory | Xb.Op.Getperms -> 
!access_log_read_ops
                | Xb.Op.Transaction_start | Xb.Op.Transaction_end ->
                        false (* transactions are managed below *)
                | Xb.Op.Introduce | Xb.Op.Release | Xb.Op.Getdomainpath | 
Xb.Op.Isintroduced | Xb.Op.Resume ->
-                       !log_special_ops
-               | _ -> true
-       in
-               if print 
-               then write_access_log ~tid ~con ~data (XbOp ty)
+                       !access_log_special_ops
+               | _ -> true in
+       if print then access_logging ~tid ~con ~data (XbOp ty)
 
 let start_transaction ~tid ~con = 
-       if !log_transaction_ops && tid <> 0
-       then write_access_log ~tid ~con (XbOp Xb.Op.Transaction_start)
+       if !access_log_transaction_ops && tid <> 0
+       then access_logging ~tid ~con (XbOp Xb.Op.Transaction_start)
 
 let end_transaction ~tid ~con = 
-       if !log_transaction_ops && tid <> 0
-       then write_access_log ~tid ~con (XbOp Xb.Op.Transaction_end)
+       if !access_log_transaction_ops && tid <> 0
+       then access_logging ~tid ~con (XbOp Xb.Op.Transaction_end)
 
 let xb_answer ~tid ~con ~ty data =
        let print = match ty with
-               | Xb.Op.Error when data="ENOENT " -> !log_read_ops
-               | Xb.Op.Error -> !log_special_ops
+               | Xb.Op.Error when String.startswith "ENOENT" data -> 
!access_log_read_ops
+               | Xb.Op.Error -> true
                | Xb.Op.Watchevent -> true
-               | _ -> false
-       in
-               if print
-               then write_access_log ~tid ~con ~data (XbOp ty)
+               | _ -> false in
+       if print then access_logging ~tid ~con ~data (XbOp ty)
diff --git a/tools/ocaml/xenstored/perms.ml b/tools/ocaml/xenstored/perms.ml
--- a/tools/ocaml/xenstored/perms.ml
+++ b/tools/ocaml/xenstored/perms.ml
@@ -15,6 +15,8 @@
  * GNU Lesser General Public License for more details.
  *)
 
+let info fmt = Logging.info "perms" fmt
+
 open Stdext
 
 let activate = ref true
@@ -145,16 +147,16 @@ let check (connection:Connection.t) requ
                in
                match perm, request with
                | NONE, _ ->
-                       Logs.info "io" "Permission denied: Domain %d has no 
permission" domainid;
+                       info "Permission denied: Domain %d has no permission" 
domainid;
                        false
                | RDWR, _ -> true
                | READ, READ -> true
                | WRITE, WRITE -> true
                | READ, _ ->
-                       Logs.info "io" "Permission denied: Domain %d has read 
only access" domainid;
+                       info "Permission denied: Domain %d has read only 
access" domainid;
                        false
                | WRITE, _ ->
-                       Logs.info "io" "Permission denied: Domain %d has write 
only access" domainid;
+                       info "Permission denied: Domain %d has write only 
access" domainid;
                        false
        in
        if !activate
diff --git a/tools/ocaml/xenstored/process.ml b/tools/ocaml/xenstored/process.ml
--- a/tools/ocaml/xenstored/process.ml
+++ b/tools/ocaml/xenstored/process.ml
@@ -14,6 +14,9 @@
  * GNU Lesser General Public License for more details.
  *)
 
+let error fmt = Logging.error "process" fmt
+let info fmt = Logging.info "process" fmt
+
 open Printf
 open Stdext
 
@@ -79,7 +82,7 @@ let create_implicit_path t perm path =
 
 (* packets *)
 let do_debug con t domains cons data =
-       if not !allow_debug
+       if not (Connection.is_dom0 con) && not !allow_debug
        then None
        else try match split None '\000' data with
        | "print" :: msg :: _ ->
@@ -89,6 +92,9 @@ let do_debug con t domains cons data =
                let domid = int_of_string domid in
                let quota = (Store.get_quota t.Transaction.store) in
                Some (Quota.to_string quota domid ^ "\000")
+       | "watches" :: _ ->
+               let watches = Connections.debug cons in
+               Some (watches ^ "\000")
        | "mfn" :: domid :: _ ->
                let domid = int_of_string domid in
                let con = Connections.find_domain cons domid in
@@ -162,9 +168,10 @@ let do_introduce con t domains cons data
                | _                         -> raise Invalid_Cmd_Args;
                in
        let dom =
-               if Domains.exist domains domid then
+               if Domains.exist domains domid then begin
+                       Connections.fire_spec_watches cons "@introduceDomain";
                        Domains.find domains domid
-               else try
+               end else try
                        let ndom = Xc.with_intf (fun xc ->
                                Domains.create xc domains domid mfn port) in
                        Connections.add_domain cons ndom;
@@ -357,8 +364,7 @@ let process_packet ~store ~cons ~doms ~c
                        in
                input_handle_error ~cons ~doms ~fct ~ty ~con ~t ~rid ~data;
        with exn ->
-               Logs.error "general" "process packet: %s"
-                         (Printexc.to_string exn);
+               error "process packet: %s" (Printexc.to_string exn);
                Connection.send_error con tid rid "EIO"
 
 let write_access_log ~ty ~tid ~con ~data =
@@ -372,7 +378,7 @@ let do_input store cons doms con =
                let packet = Connection.pop_in con in
                let tid, rid, ty, data = Xb.Packet.unpack packet in
                (* As we don't log IO, do not call an unnecessary sanitize_data 
-                  Logs.info "io" "[%s] -> [%d] %s \"%s\""
+                  info "[%s] -> [%d] %s \"%s\""
                         (Connection.get_domstr con) tid
                         (Xb.Op.to_string ty) (sanitize_data data); *)
                process_packet ~store ~cons ~doms ~con ~tid ~rid ~ty ~data;
@@ -386,7 +392,7 @@ let do_output store cons doms con =
                        let packet = Connection.peek_output con in
                        let tid, rid, ty, data = Xb.Packet.unpack packet in
                        (* As we don't log IO, do not call an unnecessary 
sanitize_data 
-                          Logs.info "io" "[%s] <- %s \"%s\""
+                          info "[%s] <- %s \"%s\""
                                 (Connection.get_domstr con)
                                 (Xb.Op.to_string ty) (sanitize_data data);*)
                        write_answer_log ~ty ~tid ~con ~data;
diff --git a/tools/ocaml/xenstored/quota.ml b/tools/ocaml/xenstored/quota.ml
--- a/tools/ocaml/xenstored/quota.ml
+++ b/tools/ocaml/xenstored/quota.ml
@@ -18,7 +18,7 @@ exception Limit_reached
 exception Data_too_big
 exception Transaction_opened
 
-let warn fmt = Logs.warn "general" fmt
+let warn fmt = Logging.warn "quota" fmt
 let activate = ref true
 let maxent = ref (10000)
 let maxsize = ref (4096)
diff --git a/tools/ocaml/xenstored/store.ml b/tools/ocaml/xenstored/store.ml
--- a/tools/ocaml/xenstored/store.ml
+++ b/tools/ocaml/xenstored/store.ml
@@ -83,7 +83,7 @@ let check_perm node connection request =
 let check_owner node connection =
        if not (Perms.check_owner connection node.perms)
        then begin
-               Logs.info "io" "Permission denied: Domain %d not owner" 
(get_owner node);
+               Logging.info "store|node" "Permission denied: Domain %d not 
owner" (get_owner node);
                raise Define.Permission_denied;
        end
 
diff --git a/tools/ocaml/xenstored/xenstored.conf 
b/tools/ocaml/xenstored/xenstored.conf
--- a/tools/ocaml/xenstored/xenstored.conf
+++ b/tools/ocaml/xenstored/xenstored.conf
@@ -22,9 +22,14 @@ quota-transaction = 10
 # Activate filed base backend
 persistant = false
 
-# Logs
-log = error;general;file:/var/log/xenstored.log
-log = warn;general;file:/var/log/xenstored.log
-log = info;general;file:/var/log/xenstored.log
+# Xenstored logs
+# xenstored-log-file = /var/log/xenstored.log
+# xenstored-log-level = null
+# xenstored-log-nb-files = 10
 
-# log = debug;io;file:/var/log/xenstored-io.log
+# Xenstored access logs
+# access-log-file = /var/log/xenstored-access.log
+# access-log-nb-lines = 13215
+# acesss-log-nb-chars = 180
+# access-log-special-ops = false
+
diff --git a/tools/ocaml/xenstored/xenstored.ml 
b/tools/ocaml/xenstored/xenstored.ml
--- a/tools/ocaml/xenstored/xenstored.ml
+++ b/tools/ocaml/xenstored/xenstored.ml
@@ -18,7 +18,10 @@
 open Printf
 open Parse_arg
 open Stdext
-open Logging
+
+let error fmt = Logging.error "xenstored" fmt
+let debug fmt = Logging.debug "xenstored" fmt
+let info fmt = Logging.info "xenstored" fmt
 
 (*------------ event klass processors --------------*)
 let process_connection_fds store cons domains rset wset =
@@ -64,7 +67,8 @@ let sigusr1_handler store =
                ()
 
 let sighup_handler _ =
-       try Logs.reopen (); info "Log re-opened" with _ -> ()
+       maybe (fun logger -> logger.Logging.restart()) 
!Logging.xenstored_logger;
+       maybe (fun logger -> logger.Logging.restart()) !Logging.access_logger
 
 let config_filename cf =
        match cf.config_file with
@@ -75,26 +79,6 @@ let default_pidfile = "/var/run/xenstore
 
 let parse_config filename =
        let pidfile = ref default_pidfile in
-       let set_log s =
-               let ls = String.split ~limit:3 ';' s in
-               let level, key, logger = match ls with
-               | [ level; key; logger ] -> level, key, logger
-               | _ -> failwith "format mismatch: expecting 3 arguments" in
-
-               let loglevel = match level with
-               | "debug" -> Log.Debug
-               | "info"  -> Log.Info
-               | "warn"  -> Log.Warn
-               | "error" -> Log.Error
-               | s       -> failwith (sprintf "Unknown log level: %s" s) in
-
-               (* if key is empty, append to the default logger *)
-               let append =
-                       if key = "" then
-                               Logs.append_default
-                       else
-                               Logs.append key in
-               append loglevel logger in
        let options = [
                ("merge-activate", Config.Set_bool Transaction.do_coalesce);
                ("perms-activate", Config.Set_bool Perms.activate);
@@ -104,14 +88,20 @@ let parse_config filename =
                ("quota-maxentity", Config.Set_int Quota.maxent);
                ("quota-maxsize", Config.Set_int Quota.maxsize);
                ("test-eagain", Config.Set_bool Transaction.test_eagain);
-               ("log", Config.String set_log);
                ("persistant", Config.Set_bool Disk.enable);
+               ("xenstored-log-file", Config.Set_string 
Logging.xenstored_log_file);
+               ("xenstored-log-level", Config.String
+                       (fun s -> Logging.xenstored_log_level := 
Logging.level_of_string s));
+               ("xenstored-log-nb-files", Config.Set_int 
Logging.xenstored_log_nb_files);
+               ("xenstored-log-nb-lines", Config.Set_int 
Logging.xenstored_log_nb_lines);
+               ("xenstored-log-nb-chars", Config.Set_int 
Logging.xenstored_log_nb_chars);
                ("access-log-file", Config.Set_string Logging.access_log_file);
                ("access-log-nb-files", Config.Set_int 
Logging.access_log_nb_files);
                ("access-log-nb-lines", Config.Set_int 
Logging.access_log_nb_lines);
-               ("access-log-read-ops", Config.Set_bool Logging.log_read_ops);
-               ("access-log-transactions-ops", Config.Set_bool 
Logging.log_transaction_ops);
-               ("access-log-special-ops", Config.Set_bool 
Logging.log_special_ops);
+               ("access-log-nb-chars", Config.Set_int 
Logging.access_log_nb_chars);
+               ("access-log-read-ops", Config.Set_bool 
Logging.access_log_read_ops);
+               ("access-log-transactions-ops", Config.Set_bool 
Logging.access_log_transaction_ops);
+               ("access-log-special-ops", Config.Set_bool 
Logging.access_log_special_ops);
                ("allow-debug", Config.Set_bool Process.allow_debug);
                ("pid-file", Config.Set_string pidfile); ] in
        begin try Config.read filename options (fun _ _ -> raise Not_found)
@@ -223,9 +213,6 @@ let to_file store cons file =
 end
 
 let _ =
-       printf "Xen Storage Daemon, version %d.%d\n%!"
-              Define.xenstored_major Define.xenstored_minor;
-
        let cf = do_argv in
        let pidfile =
                if Sys.file_exists (config_filename cf) then
@@ -249,13 +236,13 @@ let _ =
                in
        
        if cf.daemonize then
-               Unixext.daemonize ();
+               Unixext.daemonize ()
+       else
+               printf "Xen Storage Daemon, version %d.%d\n%!" 
+                       Define.xenstored_major Define.xenstored_minor;
 
        (try Unixext.pidfile_write pidfile with _ -> ());
 
-       info "Xen Storage Daemon, version %d.%d"
-            Define.xenstored_major Define.xenstored_minor;
-
        (* for compatilibity with old xenstored *)
        begin match cf.pidfile with
        | Some pidfile -> Unixext.pidfile_write pidfile
@@ -293,7 +280,14 @@ let _ =
        Sys.set_signal Sys.sigusr1 (Sys.Signal_handle (fun i -> sigusr1_handler 
store));
        Sys.set_signal Sys.sigpipe Sys.Signal_ignore;
 
-       Logging.init cf.activate_access_log (fun () -> DB.to_file store cons 
"/var/run/xenstored/db");
+       Logging.init_xenstored_log();
+       if cf.activate_access_log then begin
+               let post_rotate () = DB.to_file store cons 
"/var/run/xenstored/db" in
+               Logging.init_access_log post_rotate
+       end;
+
+       info "Xen Storage Daemon, version %d.%d"
+            Define.xenstored_major Define.xenstored_minor;
 
        let spec_fds =
                (match rw_sock with None -> [] | Some x -> [ x ]) @
 tools/ocaml/xenstored/Makefile       |    4 -
 tools/ocaml/xenstored/connection.ml  |    5 +
 tools/ocaml/xenstored/connections.ml |    7 +-
 tools/ocaml/xenstored/disk.ml        |    2 +-
 tools/ocaml/xenstored/domain.ml      |    2 +-
 tools/ocaml/xenstored/domains.ml     |    6 +-
 tools/ocaml/xenstored/logging.ml     |  302 ++++++++++++++++++----------------
 tools/ocaml/xenstored/perms.ml       |    8 +-
 tools/ocaml/xenstored/process.ml     |   20 +-
 tools/ocaml/xenstored/quota.ml       |    2 +-
 tools/ocaml/xenstored/store.ml       |    2 +-
 tools/ocaml/xenstored/xenstored.conf |   15 +-
 tools/ocaml/xenstored/xenstored.ml   |   62 +++---
 13 files changed, 237 insertions(+), 200 deletions(-)


Attachment: xen-unstable-2.patch
Description: Text Data

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel