libxl: ocaml: allow device operations to be called asynchronously
authorRob Hoes <rob.hoes@citrix.com>
Tue, 10 Dec 2013 16:48:28 +0000 (16:48 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 11 Dec 2013 13:17:49 +0000 (13:17 +0000)
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
CC: David Scott <dave.scott@eu.citrix.com>
tools/ocaml/libs/xl/genwrap.py
tools/ocaml/libs/xl/xenlight_stubs.c

index f5d2224c2674801d6032cd46bd77b98dc685f37b..dd430693f28b4b7df55457c13189e3e0dd304bcb 100644 (file)
@@ -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,....] )
index 39a9632c398eb9072e096b81b0ca6e1cf566f942..1a0fab3db1397bd15d3c0e509e9a2844a3290a76 100644 (file)
@@ -405,15 +405,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));                              \
+               *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);                         \
                                                                        \