From fa0da51c7e4d8903645c6b7b3784df80793c1389 Mon Sep 17 00:00:00 2001 From: Vincent Hanquez Date: Thu, 13 Aug 2009 11:33:35 +0100 Subject: [PATCH] add a caching ability for dbus connection. dbus bus is not reopen at each notification --- xenvm/vmact.ml | 11 +++++++++-- xenvm/vmconfig.ml | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/xenvm/vmact.ml b/xenvm/vmact.ml index ba54cd5..fd30774 100644 --- a/xenvm/vmact.ml +++ b/xenvm/vmact.ml @@ -55,12 +55,19 @@ let _notify state code l = connect_and_send addr fd | NotifyTcp6 _ -> () - | NotifyDBus (use_session, path) -> + | NotifyDBus (use_session, path, cachedconn) -> (* path/intf/method arbitrary for now. *) let dbus_path = sprintf "/org/xen/vm/%s" (String.replace "-" "_" state.vm_uuid) in let dbus_intf = "xenvm.signal.notify" in let dbus_meth = "notify" in - let bus = DBus.Bus.get (if use_session then DBus.Bus.Session else DBus.Bus.System) in + let bus = + match !cachedconn with + | None -> + let bus = DBus.Bus.get (if use_session then DBus.Bus.Session else DBus.Bus.System) in + cachedconn := Some bus; + bus + | Some bus -> bus + in let msg = DBus.Message.new_signal dbus_path dbus_intf dbus_meth in DBus.Message.append msg [ (DBus.String state.vm_uuid); (DBus.Int32 (Int32.of_int code)); diff --git a/xenvm/vmconfig.ml b/xenvm/vmconfig.ml index fedf007..9a21c61 100644 --- a/xenvm/vmconfig.ml +++ b/xenvm/vmconfig.ml @@ -24,7 +24,7 @@ type notify_ty = | NotifyTcp6 of string | NotifyTcp of Unix.inet_addr * int | NotifyUnix of string - | NotifyDBus of bool * string option + | NotifyDBus of bool * string option * (DBus.bus option ref) | NotifyNone let string_of_notify ty = @@ -32,7 +32,7 @@ let string_of_notify ty = | NotifyTcp6 s -> sprintf "tcp6,%s" s | NotifyTcp (iaddr, port) -> sprintf "tcp,%s:%d" "" port | NotifyUnix path -> sprintf "unix,%s" path - | NotifyDBus (sess, path) -> sprintf "dbus%s" (match path with None -> "" | Some path -> "," ^ path) + | NotifyDBus (sess, p, _) -> sprintf "dbus%s" (match p with None -> "" | Some path -> "," ^ path) | NotifyNone -> "" type snapshot_mode = @@ -301,8 +301,8 @@ let config_notify_of_string s = NotifyUnix path | "dbus" :: args -> ( match args with - | [] -> NotifyDBus (false, None) - | path :: [] -> NotifyDBus (false, Some path) + | [] -> NotifyDBus (false, None, ref None) + | path :: [] -> NotifyDBus (false, Some path, ref None) | _ -> failwith "notify: bad dbus format" ) | _ -> -- 2.39.5