xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Christian Lindig <christian.lindig@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Christian Lindig <christian.lindig@citrix.com>
Subject: [PATCH 1/1] tools/ocaml: Re-introduce Xenctrl.with_intf wrapper
Date: Tue, 30 Oct 2018 11:16:12 +0000	[thread overview]
Message-ID: <20181030111612.19258-1-christian.lindig@citrix.com> (raw)

Commit 81946a73dc975a7dafe9017a8e61d1e64fdbedbf removed
Xenctrl.with_intf based on its undesirable behaviour of opening and
closing a Xenctrl connection with every invocation. This commit
re-introduces with_intf but with an updated behaviour: it maintains a
global Xenctrl connection which is opened upon first usage and kept
open. This handle can be obtained by clients using new functions
get_handle() and close_handle().

The main motivation of re-introducing with_intf is that otherwise
clients will have to implement this functionality individually.

Signed-off-by: Christian Lindig <christian.lindig@citrix.com>
---
 tools/ocaml/libs/xc/xenctrl.ml  | 22 ++++++++++++++++++++++
 tools/ocaml/libs/xc/xenctrl.mli | 10 ++++++++++
 2 files changed, 32 insertions(+)

diff --git a/tools/ocaml/libs/xc/xenctrl.ml b/tools/ocaml/libs/xc/xenctrl.ml
index 955dd92546..44857a2d1c 100644
--- a/tools/ocaml/libs/xc/xenctrl.ml
+++ b/tools/ocaml/libs/xc/xenctrl.ml
@@ -141,6 +141,28 @@ type handle
 external interface_open: unit -> handle = "stub_xc_interface_open"
 external interface_close: handle -> unit = "stub_xc_interface_close"
 
+let handle = ref None
+
+let get_handle () = !handle
+
+let close_handle () =
+	match !handle with
+	| Some h -> interface_close h
+	| None -> ()
+
+let with_intf f =
+	match !handle with
+	| Some h -> f h
+	| None ->
+		let h =
+			try interface_open () with
+			| e ->
+				let msg = Printexc.to_string e in
+				failwith ("failed to open xenctrl: "^msg)
+		in
+		handle := Some h;
+		f h
+
 external domain_create: handle -> domctl_create_config -> domid
        = "stub_xc_domain_create"
 
diff --git a/tools/ocaml/libs/xc/xenctrl.mli b/tools/ocaml/libs/xc/xenctrl.mli
index eeed24fa96..b31d7fefe5 100644
--- a/tools/ocaml/libs/xc/xenctrl.mli
+++ b/tools/ocaml/libs/xc/xenctrl.mli
@@ -109,6 +109,16 @@ type handle
 external interface_open : unit -> handle = "stub_xc_interface_open"
 external interface_close : handle -> unit = "stub_xc_interface_close"
 
+(** [with_intf f] runs [f] with a global handle that is opened on demand
+ * and kept open. A client should use either [interface_open]
+ * or [with_intf] but not mix both.
+ *)
+val with_intf : (handle -> 'a) -> 'a
+(** [get_handle] returns the global handle used by [with_intf] *)
+val get_handle: unit -> handle option
+(** [close handle] closes the handle maintained by [with_intf] *)
+val close_handle: unit -> unit
+
 external domain_create : handle -> domctl_create_config -> domid
   = "stub_xc_domain_create"
 external domain_sethandle : handle -> domid -> string -> unit = "stub_xc_domain_sethandle"
-- 
2.19.1


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

             reply	other threads:[~2018-10-30 11:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 11:16 Christian Lindig [this message]
2018-10-30 16:48 ` [PATCH 1/1] tools/ocaml: Re-introduce Xenctrl.with_intf wrapper Ian Jackson
2018-10-30 16:54   ` Christian Lindig
2018-10-30 17:01     ` Ian Jackson
2018-10-30 17:11       ` Christian Lindig
2018-10-30 18:23         ` Ian Jackson
2018-10-31 11:33     ` [PATCH v2 " Christian Lindig
2018-10-31 11:33       ` [PATCH " Christian Lindig
2018-10-31 15:41         ` [PATCH v2 1/1] tools/ocaml: Re-introduce Xenctrl.with_intf wrapper [and 1 more messages] Ian Jackson
2018-10-31 15:50           ` Christian Lindig
2018-10-31 16:01             ` Ian Jackson
2018-10-31 16:57               ` Christian Lindig
2018-10-31 17:01                 ` Ian Jackson
2018-11-01  9:12     ` [PATCH 1/1] tools/ocaml: Re-introduce Xenctrl.with_intf wrapper Christian Lindig
2018-11-01 11:22       ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181030111612.19258-1-christian.lindig@citrix.com \
    --to=christian.lindig@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).