From: Ian Campbell Subject: Re: [PATCH v6 04/11] libxl: ocaml: allow device operations to be called asynchronously Date: Tue, 10 Dec 2013 13:25:48 +0000 Message-ID: <1386681948.30568.6.camel@kazak.uk.xensource.com> References: <1386602250-29866-1-git-send-email-rob.hoes@citrix.com> <1386602250-29866-5-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1386602250-29866-5-git-send-email-rob.hoes@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Rob Hoes Cc: ian.jackson@eu.citrix.com, dave.scott@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Mon, 2013-12-09 at 15:17 +0000, Rob Hoes wrote: > Signed-off-by: Rob Hoes > CC: David Scott > CC: Ian Campbell > > --- > v6: Updated patch to register for_callback value with the GC. > --- > tools/ocaml/libs/xl/genwrap.py | 6 +++--- > tools/ocaml/libs/xl/xenlight_stubs.c | 18 +++++++++++++++--- > 2 files changed, 18 insertions(+), 6 deletions(-) > > diff --git a/tools/ocaml/libs/xl/genwrap.py b/tools/ocaml/libs/xl/genwrap.py > index f5d2224..dd43069 100644 > --- a/tools/ocaml/libs/xl/genwrap.py > +++ b/tools/ocaml/libs/xl/genwrap.py > @@ -22,9 +22,9 @@ builtins = { > "libxl_cpuid_policy_list": ("unit", "%(c)s = 0", "Val_unit"), > } > > -DEVICE_FUNCTIONS = [ ("add", ["ctx", "t", "domid", "unit"]), > - ("remove", ["ctx", "t", "domid", "unit"]), > - ("destroy", ["ctx", "t", "domid", "unit"]), > +DEVICE_FUNCTIONS = [ ("add", ["ctx", "t", "domid", "?async:'a", "unit", "unit"]), > + ("remove", ["ctx", "t", "domid", "?async:'a", "unit", "unit"]), > + ("destroy", ["ctx", "t", "domid", "?async:'a", "unit", "unit"]), > ] > > functions = { # ( name , [type1,type2,....] ) > diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c > index 660dd09..b6649a7 100644 > --- a/tools/ocaml/libs/xl/xenlight_stubs.c > +++ b/tools/ocaml/libs/xl/xenlight_stubs.c > @@ -401,15 +401,27 @@ void async_callback(libxl_ctx *ctx, int rc, void *for_callback) > #define STRINGIFY(x) _STRINGIFY(x) > > #define _DEVICE_ADDREMOVE(type,op) \ > -value stub_xl_device_##type##_##op(value ctx, value info, value domid) \ > +value stub_xl_device_##type##_##op(value ctx, value info, value domid, \ > + value async, value unit) \ > { \ > - CAMLparam3(ctx, info, domid); \ > + CAMLparam5(ctx, info, domid, async, unit); \ > libxl_device_##type c_info; \ > int ret, marker_var; \ > + libxl_asyncop_how ao_how; \ > + value *p; \ > \ > device_##type##_val(CTX, &c_info, info); \ > \ > - ret = libxl_device_##type##_##op(CTX, Int_val(domid), &c_info, 0); \ > + if (async != Val_none) { \ > + p = malloc(sizeof(value)); \ This lacks error handling, or as Ian J suggested previously a wrapper to fail in a graceful manner. I think that can be a future more global cleanup though. Acked-by: Ian Campbell > + *p = Some_val(async); \ > + caml_register_global_root(p); \ > + ao_how.callback = async_callback; \ > + ao_how.u.for_callback = (void *) p; \ > + } \ > + \ > + ret = libxl_device_##type##_##op(CTX, Int_val(domid), &c_info, \ > + async != Val_none ? &ao_how : NULL); \ > \ > libxl_device_##type##_dispose(&c_info); \ > \