aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ocaml
diff options
context:
space:
mode:
authorDavid Scott <dave.scott@eu.citrix.com>2013-03-20 20:24:42 +0000
committerIan Campbell <ian.campbell@citrix.com>2013-04-11 12:03:11 +0100
commitdfb9738cdc8cdbdf38747edfcdcf1bae46f074f2 (patch)
treef5da47fb42c7b8c359623ec98e803eb8a43ad678 /tools/ocaml
parent0b1161e03753114ee149c7d65c1912fcbc3cf5df (diff)
downloadxen-dfb9738cdc8cdbdf38747edfcdcf1bae46f074f2.tar.gz
xen-dfb9738cdc8cdbdf38747edfcdcf1bae46f074f2.tar.bz2
xen-dfb9738cdc8cdbdf38747edfcdcf1bae46f074f2.zip
ocaml: eventchn: add a 'type t' to represent an event channel
It's a common OCaml convention to add a 'type t' in a module to represent the main "thing" that the module is about. We add an opaque type t and to_int/of_int functions for those who really need it, in particular: 1. to_int is needed for debug logging; and 2. both to_int and of_int are needed for anyone who communicates a port number through xenstore. Signed-off-by: David Scott <dave.scott@eu.citrix.com> Acked-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/ocaml')
-rw-r--r--tools/ocaml/libs/eventchn/xeneventchn.ml6
-rw-r--r--tools/ocaml/libs/eventchn/xeneventchn.mli17
-rw-r--r--tools/ocaml/xenstored/domain.ml28
-rw-r--r--tools/ocaml/xenstored/event.ml6
-rw-r--r--tools/ocaml/xenstored/xenstored.ml2
5 files changed, 41 insertions, 18 deletions
diff --git a/tools/ocaml/libs/eventchn/xeneventchn.ml b/tools/ocaml/libs/eventchn/xeneventchn.ml
index 79ad9b1e95..acebe10c6f 100644
--- a/tools/ocaml/libs/eventchn/xeneventchn.ml
+++ b/tools/ocaml/libs/eventchn/xeneventchn.ml
@@ -20,6 +20,9 @@ type handle
external init: unit -> handle = "stub_eventchn_init"
external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
+
+type t = int
+
external notify: handle -> int -> unit = "stub_eventchn_notify"
external bind_interdomain: handle -> int -> int -> int = "stub_eventchn_bind_interdomain"
external bind_dom_exc_virq: handle -> int = "stub_eventchn_bind_dom_exc_virq"
@@ -27,4 +30,7 @@ external unbind: handle -> int -> unit = "stub_eventchn_unbind"
external pending: handle -> int = "stub_eventchn_pending"
external unmask: handle -> int -> unit = "stub_eventchn_unmask"
+let to_int x = x
+let of_int x = x
+
let _ = Callback.register_exception "eventchn.error" (Error "register_callback")
diff --git a/tools/ocaml/libs/eventchn/xeneventchn.mli b/tools/ocaml/libs/eventchn/xeneventchn.mli
index 394acc2821..2b582cdaaf 100644
--- a/tools/ocaml/libs/eventchn/xeneventchn.mli
+++ b/tools/ocaml/libs/eventchn/xeneventchn.mli
@@ -18,14 +18,19 @@ exception Error of string
type handle
+type t
+
+val to_int: t -> int
+val of_int: int -> t
+
external init : unit -> handle = "stub_eventchn_init"
external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
-external notify : handle -> int -> unit = "stub_eventchn_notify"
-external bind_interdomain : handle -> int -> int -> int
+external notify : handle -> t -> unit = "stub_eventchn_notify"
+external bind_interdomain : handle -> int -> int -> t
= "stub_eventchn_bind_interdomain"
-external bind_dom_exc_virq : handle -> int = "stub_eventchn_bind_dom_exc_virq"
-external unbind : handle -> int -> unit = "stub_eventchn_unbind"
-external pending : handle -> int = "stub_eventchn_pending"
-external unmask : handle -> int -> unit
+external bind_dom_exc_virq : handle -> t = "stub_eventchn_bind_dom_exc_virq"
+external unbind : handle -> t -> unit = "stub_eventchn_unbind"
+external pending : handle -> t = "stub_eventchn_pending"
+external unmask : handle -> t -> unit
= "stub_eventchn_unmask"
diff --git a/tools/ocaml/xenstored/domain.ml b/tools/ocaml/xenstored/domain.ml
index c17f567a47..85ab282c54 100644
--- a/tools/ocaml/xenstored/domain.ml
+++ b/tools/ocaml/xenstored/domain.ml
@@ -17,6 +17,7 @@
open Printf
let debug fmt = Logging.debug "domain" fmt
+let warn fmt = Logging.warn "domain" fmt
type t =
{
@@ -25,7 +26,7 @@ type t =
remote_port: int;
interface: Xenmmap.mmap_interface;
eventchn: Event.t;
- mutable port: int;
+ mutable port: Xeneventchn.t option;
}
let get_path dom = "/local/domain/" ^ (sprintf "%u" dom.id)
@@ -34,19 +35,30 @@ let get_interface d = d.interface
let get_mfn d = d.mfn
let get_remote_port d = d.remote_port
+let string_of_port = function
+| None -> "None"
+| Some x -> string_of_int (Xeneventchn.to_int x)
+
let dump d chan =
- fprintf chan "dom,%d,%nd,%d\n" d.id d.mfn d.port
+ fprintf chan "dom,%d,%nd,%s\n" d.id d.mfn (string_of_port d.port)
-let notify dom = Event.notify dom.eventchn dom.port; ()
+let notify dom = match dom.port with
+| None ->
+ warn "domain %d: attempt to notify on unknown port" dom.id
+| Some port ->
+ Event.notify dom.eventchn port
let bind_interdomain dom =
- dom.port <- Event.bind_interdomain dom.eventchn dom.id dom.remote_port;
- debug "domain %d bound port %d" dom.id dom.port
+ dom.port <- Some (Event.bind_interdomain dom.eventchn dom.id dom.remote_port);
+ debug "domain %d bound port %s" dom.id (string_of_port dom.port)
let close dom =
- debug "domain %d unbound port %d" dom.id dom.port;
- Event.unbind dom.eventchn dom.port;
+ debug "domain %d unbound port %s" dom.id (string_of_port dom.port);
+ begin match dom.port with
+ | None -> ()
+ | Some port -> Event.unbind dom.eventchn port
+ end;
Xenmmap.unmap dom.interface;
()
@@ -56,7 +68,7 @@ let make id mfn remote_port interface eventchn = {
remote_port = remote_port;
interface = interface;
eventchn = eventchn;
- port = -1
+ port = None
}
let is_dom0 d = d.id = 0
diff --git a/tools/ocaml/xenstored/event.ml b/tools/ocaml/xenstored/event.ml
index cca8d93543..ccca90b6fc 100644
--- a/tools/ocaml/xenstored/event.ml
+++ b/tools/ocaml/xenstored/event.ml
@@ -17,12 +17,12 @@
(**************** high level binding ****************)
type t = {
handle: Xeneventchn.handle;
- mutable virq_port: int;
+ mutable virq_port: Xeneventchn.t option;
}
-let init () = { handle = Xeneventchn.init (); virq_port = -1; }
+let init () = { handle = Xeneventchn.init (); virq_port = None; }
let fd eventchn = Xeneventchn.fd eventchn.handle
-let bind_dom_exc_virq eventchn = eventchn.virq_port <- Xeneventchn.bind_dom_exc_virq eventchn.handle
+let bind_dom_exc_virq eventchn = eventchn.virq_port <- Some (Xeneventchn.bind_dom_exc_virq eventchn.handle)
let bind_interdomain eventchn domid port = Xeneventchn.bind_interdomain eventchn.handle domid port
let unbind eventchn port = Xeneventchn.unbind eventchn.handle port
let notify eventchn port = Xeneventchn.notify eventchn.handle port
diff --git a/tools/ocaml/xenstored/xenstored.ml b/tools/ocaml/xenstored/xenstored.ml
index 3416666382..4045aedc97 100644
--- a/tools/ocaml/xenstored/xenstored.ml
+++ b/tools/ocaml/xenstored/xenstored.ml
@@ -300,7 +300,7 @@ let _ =
and handle_eventchn fd =
let port = Event.pending eventchn in
finally (fun () ->
- if port = eventchn.Event.virq_port then (
+ if Some port = eventchn.Event.virq_port then (
let (notify, deaddom) = Domains.cleanup xc domains in
List.iter (Connections.del_domain cons) deaddom;
if deaddom <> [] || notify then