From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zheng Li Subject: [PATCH 6/8] oxenstored: enable domain connection indexing based on eventchn port Date: Mon, 15 Sep 2014 23:39:18 +0100 Message-ID: <1410820760-7994-7-git-send-email-dev@zheng.li> References: <1410820760-7994-1-git-send-email-dev@zheng.li> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XTexi-00073j-8W for xen-devel@lists.xenproject.org; Mon, 15 Sep 2014 22:41:34 +0000 In-Reply-To: <1410820760-7994-1-git-send-email-dev@zheng.li> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Dave Scott , Joe Jin , "Luis R. Rodriguez" , Luonengjun , Zheng Li , Fanhenglong , "Liuqiming (John)" , Ian Jackson List-Id: xen-devel@lists.xenproject.org Currently in xenstore connection database, we use a hash table of (domid -> connection) to store domain connections. This allows fast indexing based on domids. This patch adds another dimention of fast indexing which is based on the eventchn port number. This is useful when doing selective connections processing based on incoming events. For memory efficiency, the implementation reuse the the existing domain connections hash table, but use the negative of a port number as the index (to distinguish from domid which always >= 0). Signed-off-by: Zheng Li --- tools/ocaml/xenstored/connections.ml | 21 +++++++++++++++++---- tools/ocaml/xenstored/domain.ml | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/ocaml/xenstored/connections.ml b/tools/ocaml/xenstored/connections.ml index 59c5c1a..a0f1b89 100644 --- a/tools/ocaml/xenstored/connections.ml +++ b/tools/ocaml/xenstored/connections.ml @@ -19,6 +19,7 @@ let debug fmt = Logging.debug "connections" fmt type t = { anonymous: (Unix.file_descr, Connection.t) Hashtbl.t; + (* the key of the domains table can be either a domid or a port number (taking negative) *) domains: (int, Connection.t) Hashtbl.t; mutable watches: (string, Connection.watch list) Trie.t; } @@ -33,7 +34,10 @@ let add_anonymous cons fd can_write = let add_domain cons dom = let xbcon = Xenbus.Xb.open_mmap (Domain.get_interface dom) (fun () -> Domain.notify dom) in let con = Connection.create xbcon (Some dom) in - Hashtbl.add cons.domains (Domain.get_id dom) con + Hashtbl.add cons.domains (Domain.get_id dom) con; + match Domain.get_port dom with + | Some p -> Hashtbl.add cons.domains (-1 * Xeneventchn.to_int p) con; + | None -> () let select cons = Hashtbl.fold @@ -45,8 +49,11 @@ let select cons = let find cons = Hashtbl.find cons.anonymous -let find_domain cons id = - Hashtbl.find cons.domains id +let find_domain cons = + Hashtbl.find cons.domains + +let find_domain_by_port cons port = + Hashtbl.find cons.domains (-1 * Xeneventchn.to_int port) let del_watches_of_con con watches = match List.filter (fun w -> Connection.get_con w != con) watches with @@ -65,13 +72,19 @@ let del_domain cons id = try let con = find_domain cons id in Hashtbl.remove cons.domains id; + (match Connection.get_domain con with + | Some d -> + (match Domain.get_port d with + | Some p -> Hashtbl.remove cons.domains (-1 * Xeneventchn.to_int p) + | None -> ()) + | None -> ()); cons.watches <- Trie.map (del_watches_of_con con) cons.watches; Connection.close con with exn -> debug "del domain %u: %s" id (Printexc.to_string exn) let iter_domains cons fct = - Hashtbl.iter (fun k c -> fct c) cons.domains + Hashtbl.iter (fun k c -> if k >= 0 then fct c) cons.domains let iter_anonymous cons fct = Hashtbl.iter (fun _ c -> fct c) cons.anonymous diff --git a/tools/ocaml/xenstored/domain.ml b/tools/ocaml/xenstored/domain.ml index 444069d..06d5749 100644 --- a/tools/ocaml/xenstored/domain.ml +++ b/tools/ocaml/xenstored/domain.ml @@ -35,6 +35,7 @@ let get_id domain = domain.id let get_interface d = d.interface let get_mfn d = d.mfn let get_remote_port d = d.remote_port +let get_port d = d.port let is_bad_domain domain = domain.bad_client let mark_as_bad domain = domain.bad_client <- true -- 2.1.0