[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/8] tools/ocaml/evtchn: Extend the init() binding with a cloexec flag


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Tue, 22 Nov 2022 15:20:39 +0000
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Edwin Török <edvin.torok@xxxxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Christian Lindig <christian.lindig@xxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Rob Hoes <Rob.Hoes@xxxxxxxxxx>
  • Delivery-date: Tue, 22 Nov 2022 15:21:04 +0000
  • Ironport-data: A9a23:hTo2yKt7nX/mPVa7uVC3M74eeefnVAReMUV32f8akzHdYApBsoF/q tZmKWqPaf+ON2ChfNklbdzloRkGvZSAn4JjTwBkrSBjQShH+JbJXdiXEBz9bniYRiHhoOCLz O1FM4Wdc5pkJpP4jk3wWlQ0hSAkjclkfpKlVKiffHg0HVU/IMsYoUoLs/YjhYJ1isSODQqIu Nfjy+XSI1bg0DNvWo4uw/vrRChH4bKj5lv0gnRkPaoR5QaEzSFJZH4iDfrZw0XQE9E88tGSH 44v/JnhlkvF8hEkDM+Sk7qTWiXmlZaLYGBiIlIPM0STqkAqSh4ai87XB9JFAatjsB2bnsgZ9 Tl4ncfYpTHFnEH7sL91vxFwS0mSNEDdkVPNCSDXXce7lyUqf5ZwqhnH4Y5f0YAwo45K7W9yG fMwMm5dcw+EnMiP/rfqZbhuqpk+NJbkBdZK0p1g5Wmx4fcORJnCR+PB5MNC3Sd2jcdLdRrcT 5NHM3w1Nk2GOkARfAdMYH49tL7Aan3XWjtUsl+K44Ew5HDe1ldZ27nxKtvFPNeNQK25m27I+ z2YpDWoUnn2MvTB4yie9Umj1tbhujHDVpgwL+K176Zl1Qj7Kms7V0RNCArTTeOCokK3Rd93M UEf/Ssq668o+ySDXtT7GhG1vnOAlhodQMZLVf037hmXzajZ6BrfAXILJgOtc/R/6pVwH2Zzk AbUwZW5XlSDrYF5V1qHqOeJsjSpExErKD4tNC0oEBYdvNba9dRbYg30cjpzLEKkpoSrR2Cok 2vT/XlWa6Y71pBSifjilbzTq3f1/8WSEFZojunCdjj9hj6VcrJJcGBBBbLzyf9bZLiUQVCa1 JTvs5jPtbteZX1hecHkfQnsIF1Kz6zfWNEkqQQzd6TNDhz0k5NjFKgJiN2EGG9nM9wfZRjia 1LJtAVa6fd7ZSX0PPcqPtzuUZp0ksAM8OgJsdiNPrJzjmVZLlfbrEmCm2bNt4wSrKTcuf5mY srKGSpdJX0bFb5m3FKLqxQ1iNcWK+FX7T27eK0XODz9jObOPyfME+9t3ZnnRrlR0Z5oaT79q 753X/ZmAT0GOAEiSkE7KbIuEG0=
  • Ironport-hdrordr: A9a23:DuguTqnm83TML+DVJOEj+peXo6TpDfIU3DAbv31ZSRFFG/Fxl6 iV8sjzsiWE8Qr5OUtQ/+xoV5PhfZqxz/JICMwqTNKftWrdyQyVxeNZnOjfKlTbckWUnINgPO VbAsxD4bXLfCBHZK3BgTVQfexO/DD+ytHLudvj
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Edwin Török <edvin.torok@xxxxxxxxxx>

For live update, oxenstored wants to clear CLOEXEC on the evtchn handle, so it
survives the execve() into the new oxenstored.

Have the new interface match how cloexec works in other Ocaml standard
libraries.

Signed-off-by: Edwin Török <edvin.torok@xxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>
---
CC: Christian Lindig <christian.lindig@xxxxxxxxxx>
CC: David Scott <dave@xxxxxxxxxx>
CC: Edwin Torok <edvin.torok@xxxxxxxxxx>
CC: Rob Hoes <Rob.Hoes@xxxxxxxxxx>

Split out of combined patch
---
 tools/ocaml/libs/eventchn/xeneventchn.ml      |  5 ++++-
 tools/ocaml/libs/eventchn/xeneventchn.mli     |  9 ++++++---
 tools/ocaml/libs/eventchn/xeneventchn_stubs.c | 10 +++++++---
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/tools/ocaml/libs/eventchn/xeneventchn.ml 
b/tools/ocaml/libs/eventchn/xeneventchn.ml
index be4de82f46b9..c16fdd4674f7 100644
--- a/tools/ocaml/libs/eventchn/xeneventchn.ml
+++ b/tools/ocaml/libs/eventchn/xeneventchn.ml
@@ -16,7 +16,10 @@
 
 type handle
 
-external init: unit -> handle = "stub_eventchn_init"
+external _init: bool -> handle = "stub_eventchn_init"
+
+let init ?(cloexec=true) () = _init cloexec
+
 external fdopen: Unix.file_descr -> handle = "stub_eventchn_fdopen"
 external fd: handle -> Unix.file_descr = "stub_eventchn_fd"
 
diff --git a/tools/ocaml/libs/eventchn/xeneventchn.mli 
b/tools/ocaml/libs/eventchn/xeneventchn.mli
index 98b3c86f3702..870429b6b53a 100644
--- a/tools/ocaml/libs/eventchn/xeneventchn.mli
+++ b/tools/ocaml/libs/eventchn/xeneventchn.mli
@@ -43,9 +43,12 @@ val to_int: t -> int
 
 val of_int: int -> t
 
-val init: unit -> handle
-(** Return an initialised event channel interface. On error it
-    will throw a Failure exception. *)
+val init: ?cloexec:bool -> unit -> handle
+(** [init ?cloexec ()]
+    Return an initialised event channel interface.
+    The default is to close the underlying file descriptor
+    on [execve], which can be overriden with [~cloexec:false].
+    On error it will throw a Failure exception. *)
 
 val fdopen: Unix.file_descr -> handle
 (** Return an initialised event channel interface, from an already open evtchn
diff --git a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c 
b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
index 7bdf711bc150..aa8a69cc1ecb 100644
--- a/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
+++ b/tools/ocaml/libs/eventchn/xeneventchn_stubs.c
@@ -50,14 +50,18 @@ static struct custom_operations xenevtchn_ops = {
        .compare_ext = custom_compare_ext_default, /* Can't compare     */
 };
 
-CAMLprim value stub_eventchn_init(void)
+CAMLprim value stub_eventchn_init(value cloexec)
 {
-       CAMLparam0();
+       CAMLparam1(cloexec);
        CAMLlocal1(result);
        xenevtchn_handle *xce;
+       unsigned int flags = 0;
+
+       if ( !Bool_val(cloexec) )
+               flags |= XENEVTCHN_NO_CLOEXEC;
 
        caml_enter_blocking_section();
-       xce = xenevtchn_open(NULL, 0);
+       xce = xenevtchn_open(NULL, flags);
        caml_leave_blocking_section();
 
        if (xce == NULL)
-- 
2.11.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.