Skip to contentSkip to conversation

libxl: ocaml: improve the bindings

PATCH In review Rob Hoes 3 participants 34 messages Jun 13, 2013 – Aug 22, 2013

lore
Share & tools
lore

Rob Hoes

author
#0 lore raw

This is version 2 of this patch series to fix the OCaml binding to libxl.

I believe I have addressed all the points raised by Dave Scott and Ian Campbell. Sorry for the delay in getting this new series out!

The main changes are:
* Several fixes to ensure the bindings play well with the OCaml GC. This includes properly using macros such as CAMLparam* and CAMLreturn* for _all_ OCaml values (even intermediate ones), and using "custom" blocks to encapsulate pointers to C code (including handy "finalize" functions for cleanup.
* Fixes in the way KeyedUnions are handled.
* Use the libxl init function to generate default records for libxl types.
* Improve the functions that deal with event handling. We now have some higher-level functions to makes this easier as well as safer, and errors are translated properly.

---------

The following series of patches fill in most of the gaps in the OCaml bindings to libxl, to make them useful for clients such as xapi/xenopsd (from XCP). There are a number of bugfixes to the existing bindings as well. I have an experimental version of xenopsd that successfully uses the new bindings.

An earlier version of the first half of the series was submitted to the last by Ian Campbell on 20 Nov 2012. With his permission, I have updated most of them to fix some issues (which were discussed on the mailing list at the time). I have left Ian's signed-off-by line on those patches (please let me know if that is not appropriate).

For convenience, the patches in this series may be pulled using:

git pull git://github.com/robhoes/xen.git hydrogen-upstream-v2

Cheers,
Rob

author
#1 lore raw

PATCH v2 1/30 libxl: Add LIBXL_SHUTDOWN_REASON_UNKNOWN

libxl_dominfo.shutdown_reason is valid iff (shutdown||dying). This is a bit annoying when generating language bindings since it needs all sorts of special casing. Just introduce an explicit value instead.

---
 tools/libxl/libxl.c         |    2 +-
 tools/libxl/libxl_types.idl |    5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
tools/libxl/libxl.c +1 -1
index ee1fa9c..b9ec689 100644
@@ -526,7 +526,7 @@ static void xcinfo2xlinfo(const xc_domaininfo_t *xcinfo,
     if (xlinfo->shutdown || xlinfo->dying)
         xlinfo->shutdown_reason = (xcinfo->flags>>XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask;
     else
-        xlinfo->shutdown_reason  = ~0;
+        xlinfo->shutdown_reason = LIBXL_SHUTDOWN_REASON_UNKNOWN;
 
     xlinfo->outstanding_memkb = PAGE_TO_MEMKB(xcinfo->outstanding_pages);
     xlinfo->current_memkb = PAGE_TO_MEMKB(xcinfo->tot_pages);
tools/libxl/libxl_types.idl +3 -2
index d218a2d..a22569f 100644
@@ -118,14 +118,15 @@ libxl_scheduler = Enumeration("scheduler", [
     (7, "arinc653"),
     ])
 
-# Consistent with SHUTDOWN_* in sched.h
+# Consistent with SHUTDOWN_* in sched.h (apart from UNKNOWN)
 libxl_shutdown_reason = Enumeration("shutdown_reason", [
+    (-1, "unknown"),
     (0, "poweroff"),
     (1, "reboot"),
     (2, "suspend"),
     (3, "crash"),
     (4, "watchdog"),
-    ])
+    ], init_val = "LIBXL_SHUTDOWN_REASON_UNKNOWN")
 
 libxl_vga_interface_type = Enumeration("vga_interface_type", [
     (1, "CIRRUS"),
Signature · 1 line
1.7.10.4
author
#2 lore raw

PATCH v2 2/30 libxl: idl: allow KeyedUnion members to be empty

In reply to Rob Hoes

This is useful when the key enum has an "invalid" option and avoids the need to declare a dummy struct. Use this for domain_build_info resulting in the generated API changing like so:

    --- tools/libxl/_libxl_BACKUP_types.h
    +++ tools/libxl/_libxl_types.h
    @@ -377,8 +377,6 @@ typedef struct libxl_domain_build_info {
                 const char * features;
                 libxl_defbool e820_host;
             } pv;
    -        struct {
    -        } invalid;
         } u;
     } libxl_domain_build_info;
     void libxl_domain_build_info_dispose(libxl_domain_build_info *p);

+ a related change to the JSON generation.

---
 tools/libxl/gentest.py      |    3 ++-
 tools/libxl/gentypes.py     |   11 ++++++++---
 tools/libxl/libxl_types.idl |    2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)
tools/libxl/gentest.py +2 -1
index 84b4fd7..6fab493 100644
@@ -46,7 +46,8 @@ def gen_rand_init(ty, v, indent = "    ", parent = None):
         for f in ty.fields:
             (nparent,fexpr) = ty.member(v, f, parent is None)
             s += "case %s:\n" % f.enumname
-            s += gen_rand_init(f.type, fexpr, indent + "    ", nparent)
+            if f.type is not None:
+                s += gen_rand_init(f.type, fexpr, indent + "    ", nparent)
             s += "    break;\n"
         s += "}\n"
     elif isinstance(ty, idl.Struct) \
tools/libxl/gentypes.py +8 -3
index 30f29ba..be06257 100644
@@ -45,6 +45,8 @@ def libxl_C_type_define(ty, indent = ""):
             s += "typedef %s %s {\n" % (ty.kind, ty.typename)
 
         for f in ty.fields:
+            if isinstance(ty, idl.KeyedUnion) and f.type is None: continue
+            
             x = libxl_C_instance_of(f.type, f.name)
             if f.const:
                 x = "const " + x
@@ -67,7 +69,8 @@ def libxl_C_type_dispose(ty, v, indent = "    ", parent = None):
         for f in ty.fields:
             (nparent,fexpr) = ty.member(v, f, parent is None)
             s += "case %s:\n" % f.enumname
-            s += libxl_C_type_dispose(f.type, fexpr, indent + "    ", nparent)
+            if f.type is not None:
+                s += libxl_C_type_dispose(f.type, fexpr, indent + "    ", nparent)
             s += "    break;\n"
         s += "}\n"
     elif isinstance(ty, idl.Array):
@@ -115,7 +118,8 @@ def _libxl_C_type_init(ty, v, indent = "    ", parent = None, subinit=False):
             for f in ty.fields:
                 (nparent,fexpr) = ty.member(v, f, parent is None)
                 s += "case %s:\n" % f.enumname
-                s += _libxl_C_type_init(f.type, fexpr, "    ", nparent)
+                if f.type is not None:
+                    s += _libxl_C_type_init(f.type, fexpr, "    ", nparent)
                 s += "    break;\n"
             s += "}\n"
         else:
@@ -214,7 +218,8 @@ def libxl_C_type_gen_json(ty, v, indent = "    ", parent = None):
         for f in ty.fields:
             (nparent,fexpr) = ty.member(v, f, parent is None)
             s += "case %s:\n" % f.enumname
-            s += libxl_C_type_gen_json(f.type, fexpr, indent + "    ", nparent)
+            if f.type is not None:
+                s += libxl_C_type_gen_json(f.type, fexpr, indent + "    ", nparent)
             s += "    break;\n"
         s += "}\n"
     elif isinstance(ty, idl.Struct) and (parent is None or ty.json_fn is None):
tools/libxl/libxl_types.idl +1 -1
index a22569f..81fb25a 100644
@@ -344,7 +344,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                       # Use host's E820 for PCI passthrough.
                                       ("e820_host", libxl_defbool),
                                       ])),
-                 ("invalid", Struct(None, [])),
+                 ("invalid", None),
                  ], keyvar_init_val = "LIBXL_DOMAIN_TYPE_INVALID")),
     ], dir=DIR_IN
 )
Signature · 1 line
1.7.10.4
author
#3 lore raw

PATCH v2 3/30 libxl: idl: add domain_type field to libxl_dominfo struct

In reply to Rob Hoes

This allows a toolstack to find out whether a VM has booted as PV or HVM.

---
 tools/libxl/libxl.c         |    2 ++
 tools/libxl/libxl_types.idl |    1 +
 2 files changed, 3 insertions(+)
tools/libxl/libxl.c +2 -0
index b9ec689..564b4c1 100644
@@ -537,6 +537,8 @@ static void xcinfo2xlinfo(const xc_domaininfo_t *xcinfo,
     xlinfo->vcpu_max_id = xcinfo->max_vcpu_id;
     xlinfo->vcpu_online = xcinfo->nr_online_vcpus;
     xlinfo->cpupool = xcinfo->cpupool;
+    xlinfo->domain_type = (xcinfo->flags & XEN_DOMINF_hvm_guest) ?
+        LIBXL_DOMAIN_TYPE_HVM : LIBXL_DOMAIN_TYPE_PV;
 }
 
 libxl_dominfo * libxl_list_domain(libxl_ctx *ctx, int *nb_domain_out)
tools/libxl/libxl_types.idl +1 -0
index 81fb25a..1b8fd44 100644
@@ -205,6 +205,7 @@ libxl_dominfo = Struct("dominfo",[
     ("vcpu_max_id", uint32),
     ("vcpu_online", uint32),
     ("cpupool",     uint32),
+    ("domain_type", libxl_domain_type),
     ], dir=DIR_OUT)
 
 libxl_cpupoolinfo = Struct("cpupoolinfo", [
Signature · 1 line
1.7.10.4
author
#4 lore raw

PATCH v2 4/30 libxl: idl: complete some enums in the IDL with their defaults

In reply to Rob Hoes

There are several enums in the IDL that are initialised to 0, while the value 0 is not part of the enum itself. This creates problems for language bindings generated from the IDL, such as the OCaml ones.

Added an explicit (0, "UNKNOWN") enum value where appropriate, or used init_val to default to a sensible value.

---
 tools/libxl/libxl_types.idl |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tools/libxl/libxl_types.idl +8 -3
index 1b8fd44..daa8bb9 100644
@@ -32,14 +32,16 @@ libxl_domain_type = Enumeration("domain_type", [
     (-1, "INVALID"),
     (1, "HVM"),
     (2, "PV"),
-    ])
+    ], init_val = -1)
 
 libxl_device_model_version = Enumeration("device_model_version", [
+    (0, "UNKNOWN"),
     (1, "QEMU_XEN_TRADITIONAL"), # Historical qemu-xen device model (qemu-dm)
     (2, "QEMU_XEN"),             # Upstream based qemu-xen device model
     ])
 
 libxl_console_type = Enumeration("console_type", [
+    (0, "UNKNOWN"),
     (1, "SERIAL"),
     (2, "PV"),
     ])
@@ -61,6 +63,7 @@ libxl_disk_backend = Enumeration("disk_backend", [
     ])
 
 libxl_nic_type = Enumeration("nic_type", [
+    (0, "UNKNOWN"),
     (1, "VIF_IOEMU"),
     (2, "VIF"),
     ])
@@ -75,7 +78,7 @@ libxl_action_on_shutdown = Enumeration("action_on_shutdown", [
 
     (5, "COREDUMP_DESTROY"),
     (6, "COREDUMP_RESTART"),
-    ])
+    ], init_val = 1)
 
 libxl_trigger = Enumeration("trigger", [
     (0, "UNKNOWN"),
@@ -96,6 +99,7 @@ libxl_tsc_mode = Enumeration("tsc_mode", [
 
 # Consistent with the values defined for HVM_PARAM_TIMER_MODE.
 libxl_timer_mode = Enumeration("timer_mode", [
+    (-1, "unknown"),
     (0, "delay_for_missed_ticks"),
     (1, "no_delay_for_missed_ticks"),
     (2, "no_missed_ticks_pending"),
@@ -103,6 +107,7 @@ libxl_timer_mode = Enumeration("timer_mode", [
     ], init_val = "LIBXL_TIMER_MODE_DEFAULT")
 
 libxl_bios_type = Enumeration("bios_type", [
+    (0, "unknown"),
     (1, "rombios"),
     (2, "seabios"),
     (3, "ovmf"),
@@ -131,7 +136,7 @@ libxl_shutdown_reason = Enumeration("shutdown_reason", [
 libxl_vga_interface_type = Enumeration("vga_interface_type", [
     (1, "CIRRUS"),
     (2, "STD"),
-    ], init_val = 0)
+    ], init_val = 1)
 
 #
 # Complex libxl types
Signature · 1 line
1.7.10.4
author
#5 lore raw

PATCH v2 5/30 libxl: ocaml: fix code intended to output comments before definitions

In reply to Rob Hoes

I'm not sure how useful these comments actually are but erred on the side of fixing rather than removing.

---
 tools/ocaml/libs/xl/genwrap.py |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/ocaml/libs/xl/genwrap.py +4 -2
index ea978bf..5757218 100644
@@ -79,12 +79,14 @@ def gen_ocaml_ml(ty, interface, indent=""):
         s = ("""(* %s interface *)\n""" % ty.typename)
     else:
         s = ("""(* %s implementation *)\n""" % ty.typename)
+        
     if isinstance(ty, idl.Enumeration):
-        s = "type %s = \n" % ty.rawname
+        s += "type %s = \n" % ty.rawname
         for v in ty.values:
             s += "\t | %s\n" % v.rawname
     elif isinstance(ty, idl.Aggregate):
-        s = ""
+        s += ""
+        
         if ty.typename is None:
             raise NotImplementedError("%s has no typename" % type(ty))
         else:
Signature · 1 line
1.7.10.4
author
#6 lore raw

PATCH v2 6/30 libxl: ocaml: support for Arrays in bindings generator.

In reply to Rob Hoes

No change in generated code because no arrays are currently generated.

---
 tools/ocaml/libs/xl/genwrap.py |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tools/ocaml/libs/xl/genwrap.py +9 -2
index 5757218..1b68b6b 100644
@@ -143,7 +143,14 @@ def c_val(ty, c, o, indent="", parent = None):
             raise NotImplementedError("No c_val fn for Builtin %s (%s)" % (ty.typename, type(ty)))
         s += "%s;" % (fn % { "o": o, "c": c })
     elif isinstance (ty,idl.Array):
-        raise("Cannot handle Array type\n")
+        s += "{\n"
+        s += "\tint i;\n"
+        s += "\t%s = Wosize_val(%s);\n" % (parent + ty.lenvar.name, o)
+        s += "\t%s = (%s) calloc(%s, sizeof(*%s));\n" % (c, ty.typename, parent + ty.lenvar.name, c)
+        s += "\tfor(i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
+        s += c_val(ty.elem_type, c+"[i]", "Field(%s, i)" % o, indent="\t\t", parent=parent) + "\n"
+        s += "\t}\n"
+        s += "}\n"
     elif isinstance(ty,idl.Enumeration) and (parent is None):
         n = 0
         s += "switch(Int_val(%s)) {\n" % o
@@ -207,7 +214,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
         s += "\t    value array_elem;\n"
         s += "\t    %s = caml_alloc(%s,0);\n" % (o, parent + ty.lenvar.name)
         s += "\t    for(i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
-        s += "\t        %s\n" % ocaml_Val(ty.elem_type, "array_elem", c + "[i]", "")
+        s += "\t        %s\n" % ocaml_Val(ty.elem_type, "array_elem", c + "[i]", "", parent=parent)
         s += "\t        Store_field(%s, i, array_elem);\n" % o
         s += "\t    }\n"
         s += "\t}"
Signature · 1 line
1.7.10.4
author
#7 lore raw

PATCH v2 7/30 libxl: ocaml: avoid reserved words in type and field names.

In reply to Rob Hoes

Current just s/type/ty/ and there are no such fields (yet) so no change to generated code.

---
 tools/ocaml/libs/xl/genwrap.py |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
tools/ocaml/libs/xl/genwrap.py +7 -1
index 1b68b6b..d76a007 100644
@@ -70,8 +70,14 @@ def ocaml_type_of(ty):
     else:
         return ty.rawname
 
+def munge_name(name):
+    if name == "type":
+        return "ty"
+    else:
+        return name
+    
 def ocaml_instance_of(type, name):
-    return "%s : %s" % (name, ocaml_type_of(type))
+    return "%s : %s" % (munge_name(name), ocaml_type_of(type))
 
 def gen_ocaml_ml(ty, interface, indent=""):
 
Signature · 1 line
1.7.10.4
author
#8 lore raw

PATCH v2 8/30 libxl: ocaml: support for KeyedUnion in the bindings generator.

In reply to Rob Hoes

A KeyedUnion consists of two fields in the containing struct. First an enum field ("e") used as a descriminator and second a union ("u") containing potentially anonymous structs associated with each enum value.

We map the anonymous structs to structs named after the descriminator field ("e") and the specific enum values. We then declare an ocaml variant type name e__union mapping each enum value to its associated struct.

So given IDL:

foo = Enumeration("foo", [

    (0, "BAR"),
    (1, "BAZ"),
])
s = Struct("s", [
    ("u", KeyedUnion(none, foo, "blargle", [
        ("bar", Struct(...xxx...)),
        ("baz", Struct(...yyy...)),
    ])),

])

We generate C:

enum { FOO, BAR } foo;

struct s {
    enum foo blargle;
    union {
        struct { ...xxx... } bar;
        struct { ...yyy... } baz;
    } u;
}

and map this to ocaml

type foo = BAR | BAZ;

module S = struct

    type blargle_bar = ...xxx...;

    type blargle_baz = ...yyy...;

    type blargle__union = Bar of blargle_bar | Baz of blargle_baz;

    type t =
    {
        blargle : blargle__union;
    }

end

These type names are OK because they are already within the namespace associated with the struct "s".

If the struct associated with bar is empty then we don't bother with blargle_bar of "of blargle_bar".

No actually change in the generated code since we don't generate any KeyedUnions yet.

The actual implementation was inspired by
http://www.linux-nantes.org/~fmonnier/ocaml/ocaml-wrapping-c.php#ref_constvrnt

---
 tools/libxl/idl.py             |    3 +
 tools/ocaml/libs/xl/genwrap.py |  160 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 146 insertions(+), 17 deletions(-)
tools/libxl/idl.py +3 -0
index 7d95e3f..f4908dd 100644
@@ -216,6 +216,9 @@ class Struct(Aggregate):
         kwargs.setdefault('passby', PASS_BY_REFERENCE)
         Aggregate.__init__(self, "struct", name, fields, **kwargs)
 
+    def has_fields(self):
+        return len(self.fields) != 0
+
 class Union(Aggregate):
     def __init__(self, name, fields, **kwargs):
         # Generally speaking some intelligence is required to free a
tools/ocaml/libs/xl/genwrap.py +143 -17

209 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#9 lore raw

PATCH v2 9/30 libxl: ocaml: add some more builtin types.

In reply to Rob Hoes

* bitmaps
* string_list
* key_value_list
* cpuid_policy_list (left "empty" for now)

None of these are used yet, so no change to the generated code.

Bitmap_val requires a ctx, so leave it as an abort for now.

---
 tools/ocaml/libs/xl/genwrap.py       |    6 +-
 tools/ocaml/libs/xl/xenlight_stubs.c |  127 ++++++++++++++++++++++++++++++----
 2 files changed, 119 insertions(+), 14 deletions(-)
tools/ocaml/libs/xl/genwrap.py +5 -1
index 0c80e3d..05c4582 100644
@@ -13,9 +13,13 @@ builtins = {
     "libxl_devid":          ("devid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_defbool":        ("bool option",            "%(c)s = Defbool_val(%(o)s)",        "Val_defbool(%(c)s)" ),
     "libxl_uuid":           ("int array",              "Uuid_val(gc, lg, &%(c)s, %(o)s)",   "Val_uuid(&%(c)s)"),
-    "libxl_key_value_list": ("(string * string) list", None,                                None),
+    "libxl_bitmap":         ("bool array",             "Bitmap_val(gc, lg, &%(c)s, %(o)s)",   "Val_bitmap(&%(c)s)"),    
+    "libxl_key_value_list": ("(string * string) list", "libxl_key_value_list_val(gc, lg, &%(c)s, %(o)s)", "Val_key_value_list(&%(c)s)"),
+    "libxl_string_list":    ("string list",            "libxl_string_list_val(gc, lg, &%(c)s, %(o)s)", "Val_string_list(&%(c)s)"),
     "libxl_mac":            ("int array",              "Mac_val(gc, lg, &%(c)s, %(o)s)",    "Val_mac(&%(c)s)"),
     "libxl_hwcap":          ("int32 array",            None,                                "Val_hwcap(&%(c)s)"),
+    # The following needs to be sorted out later
+    "libxl_cpuid_policy_list": ("unit",                "%(c)s = 0",                         "Val_unit"),
     }
 
 DEVICE_FUNCTIONS = [ ("add",            ["t", "domid", "unit"]),
tools/ocaml/libs/xl/xenlight_stubs.c +114 -13

161 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#10 lore raw

PATCH v2 10/30 libxc: ocaml: add simple binding for xentoollog (output only).

In reply to Rob Hoes

These bindings allow ocaml code to receive log message via xentoollog but do not support injecting messages into xentoollog from ocaml. Receiving log messages from libx{c,l} and forwarding them to ocaml is the use case which is needed by the following patches.

Add a simple noddy test case (tools/ocaml/test).

---
 .gitignore                                     |    1 +
 .hgignore                                      |    1 +
 tools/ocaml/Makefile                           |    2 +-
 tools/ocaml/Makefile.rules                     |    2 +-
 tools/ocaml/libs/Makefile                      |    1 +
 tools/ocaml/libs/xentoollog/META.in            |    4 +
 tools/ocaml/libs/xentoollog/Makefile           |   33 ++++
 tools/ocaml/libs/xentoollog/caml_xentoollog.h  |   24 +++
 tools/ocaml/libs/xentoollog/xentoollog.ml      |   98 +++++++++++
 tools/ocaml/libs/xentoollog/xentoollog.mli     |   53 ++++++
 tools/ocaml/libs/xentoollog/xentoollog_stubs.c |  222 ++++++++++++++++++++++++
 tools/ocaml/test/Makefile                      |   28 +++
 tools/ocaml/test/xtl.ml                        |   19 ++
 13 files changed, 486 insertions(+), 2 deletions(-)
 create mode 100644 tools/ocaml/libs/xentoollog/META.in
 create mode 100644 tools/ocaml/libs/xentoollog/Makefile
 create mode 100644 tools/ocaml/libs/xentoollog/caml_xentoollog.h
 create mode 100644 tools/ocaml/libs/xentoollog/xentoollog.ml
 create mode 100644 tools/ocaml/libs/xentoollog/xentoollog.mli
 create mode 100644 tools/ocaml/libs/xentoollog/xentoollog_stubs.c
 create mode 100644 tools/ocaml/test/Makefile
 create mode 100644 tools/ocaml/test/xtl.ml
.gitignore +1 -0
index 960c29e..5acebd0 100644
@@ -401,6 +401,7 @@ tools/ocaml/libs/xl/_libxl_types.mli.in
 tools/ocaml/libs/xl/xenlight.ml
 tools/ocaml/libs/xl/xenlight.mli
 tools/ocaml/xenstored/oxenstored
+tools/ocaml/test/xtl
 
 tools/debugger/kdd/kdd
 tools/firmware/etherboot/ipxe.tar.gz
.hgignore +1 -0
index f3877a9..685a785 100644
@@ -326,6 +326,7 @@
 ^tools/ocaml/libs/xl/xenlight\.ml$
 ^tools/ocaml/libs/xl/xenlight\.mli$
 ^tools/ocaml/xenstored/oxenstored$
+^tools/ocaml/test/xtl$
 ^tools/autom4te\.cache$
 ^tools/config\.h$
 ^tools/config\.log$
tools/ocaml/Makefile +1 -1
index 6b22bbe..8e4ca36 100644
@@ -1,7 +1,7 @@
 XEN_ROOT = $(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-SUBDIRS_PROGRAMS = xenstored
+SUBDIRS_PROGRAMS = xenstored test
 
 SUBDIRS = libs $(SUBDIRS_PROGRAMS)
 
tools/ocaml/Makefile.rules +1 -1
index 5e6d81e..0745e83 100644
@@ -24,7 +24,7 @@ ALL_OCAML_OBJS ?= $(OBJS)
 %.cmi: %.mli
 	$(call quiet-command, $(OCAMLC) $(OCAMLCFLAGS) -c -o $@ $<,MLI,$@)
 
-%.cmx: %.ml
+%.cmx %.o: %.ml
 	$(call quiet-command, $(OCAMLOPT) $(OCAMLOPTFLAGS) -c -o $@ $<,MLOPT,$@)
 
 %.ml: %.mll
tools/ocaml/libs/Makefile +1 -0
index bca0fa2..3afdc89 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS= \
 	mmap \
+	xentoollog \
 	xc eventchn \
 	xb xs xl
 
tools/ocaml/libs/xentoollog/META.in new file +4 -0
new file mode 100644
index 0000000..7b06683
@@ -0,0 +1,4 @@
+version = "@VERSION@"
+description = "Xen Tools Logger Interface"
+archive(byte) = "xentoollog.cma"
+archive(native) = "xentoollog.cmxa"
tools/ocaml/libs/xentoollog/Makefile new file +33 -0
new file mode 100644
index 0000000..17dca95
@@ -0,0 +1,33 @@
+TOPLEVEL=$(CURDIR)/../..
+XEN_ROOT=$(TOPLEVEL)/../..
+include $(TOPLEVEL)/common.make
+
+CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest)
+OCAMLINCLUDE +=
+
+OBJS = xentoollog
+INTF = xentoollog.cmi
+LIBS = xentoollog.cma xentoollog.cmxa
+
+LIBS_xentoollog = $(LDLIBS_libxenctrl)
+
+xentoollog_OBJS = $(OBJS)
+xentoollog_C_OBJS = xentoollog_stubs
+
+OCAML_LIBRARY = xentoollog
+
+all: $(INTF) $(LIBS)
+
+libs: $(LIBS)
+
+.PHONY: install
+install: $(LIBS) META
+	mkdir -p $(OCAMLDESTDIR)
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xentoollog
+	ocamlfind install -destdir $(OCAMLDESTDIR) -ldconf ignore xentoollog META $(INTF) $(LIBS) *.a *.so *.cmx
+
+.PHONY: uninstall
+uninstall:
+	ocamlfind remove -destdir $(OCAMLDESTDIR) xentoollog
+
+include $(TOPLEVEL)/Makefile.rules
tools/ocaml/libs/xentoollog/caml_xentoollog.h new file +24 -0
new file mode 100644
index 0000000..0eb7618
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2013      Citrix Ltd.
+ * Author Ian Campbell <[email protected]>
+ * Author Rob Hoes <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+struct caml_xtl {
+	xentoollog_logger vtable;
+	char *vmessage_cb;
+	char *progress_cb;
+};
+
+#define Xtl_val(x)(*((struct caml_xtl **) Data_custom_val(x)))
+
tools/ocaml/libs/xentoollog/xentoollog.ml new file +98 -0

98 lines not on this page · raw message

tools/ocaml/libs/xentoollog/xentoollog.mli new file +53 -0

53 lines not on this page · raw message

tools/ocaml/libs/xentoollog/xentoollog_stubs.c new file +222 -0

222 lines not on this page · raw message

tools/ocaml/test/Makefile new file +28 -0
new file mode 100644
index 0000000..980054c
@@ -0,0 +1,28 @@
+XEN_ROOT = $(CURDIR)/../../..
+OCAML_TOPLEVEL = $(CURDIR)/..
+include $(OCAML_TOPLEVEL)/common.make
+
+OCAMLINCLUDE += \
+	-I $(OCAML_TOPLEVEL)/libs/xentoollog
+
+OBJS = xtl
+
+PROGRAMS = xtl
+
+xtl_LIBS =  \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xentoollog $(OCAML_TOPLEVEL)/libs/xentoollog/xentoollog.cmxa \
+	-cclib -lxenctrl
+
+xtl_OBJS = xtl
+
+OCAML_PROGRAM = xtl
+
+all: $(PROGRAMS)
+
+bins: $(PROGRAMS)
+
+install: all
+	$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
+	$(INSTALL_PROG) $(PROGRAMS) $(DESTDIR)$(BINDIR)
+
+include $(OCAML_TOPLEVEL)/Makefile.rules
tools/ocaml/test/xtl.ml new file +19 -0
new file mode 100644
index 0000000..3a1df82
@@ -0,0 +1,19 @@
+open Arg
+open Xentoollog
+  
+let do_test level = 
+  let lgr = Xentoollog.create_stdio_logger ~level:level () in
+  begin
+    Xentoollog.test lgr;
+  end
+
+let () =
+  let debug_level = ref Xentoollog.Info in
+  let speclist = [
+    ("-v", Arg.Unit (fun () -> debug_level := Xentoollog.Debug), "Verbose");
+    ("-q", Arg.Unit (fun () -> debug_level := Xentoollog.Critical), "Quiet");
+  ] in
+  let usage_msg = "usage: xtl [OPTIONS]" in
+  Arg.parse speclist (fun s -> ()) usage_msg;
+
+  do_test !debug_level
Signature · 1 line
1.7.10.4
author
#11 lore raw

PATCH v2 11/30 libxl: ocaml: allocate a long lived libxl context.

In reply to Rob Hoes

Rather than allocating a new context for every libxl call begin to switch to a model where a context is allocated by the caller and may then be used for multiple calls down into the library.

---
 tools/ocaml/libs/xl/META.in          |    1 +
 tools/ocaml/libs/xl/Makefile         |    3 +++
 tools/ocaml/libs/xl/xenlight.ml.in   |    4 ++++
 tools/ocaml/libs/xl/xenlight.mli.in  |    4 ++++
 tools/ocaml/libs/xl/xenlight_stubs.c |   42 +++++++++++++++++++++++++++++++++-
 5 files changed, 53 insertions(+), 1 deletion(-)
tools/ocaml/libs/xl/META.in +1 -0
index fe2c60b..3f0c552 100644
@@ -1,4 +1,5 @@
 version = "@VERSION@"
 description = "Xen Toolstack Library"
+requires = "xentoollog"
 archive(byte) = "xenlight.cma"
 archive(native) = "xenlight.cmxa"
tools/ocaml/libs/xl/Makefile +3 -0
index c9e5274..6917a20 100644
@@ -5,11 +5,14 @@ include $(TOPLEVEL)/common.make
 # ignore unused generated functions
 CFLAGS += -Wno-unused
 CFLAGS += $(CFLAGS_libxenlight)
+CFLAGS += -I ../xentoollog
 
 OBJS = xenlight
 INTF = xenlight.cmi
 LIBS = xenlight.cma xenlight.cmxa
 
+OCAMLINCLUDE += -I ../xentoollog
+
 LIBS_xenlight = $(LDLIBS_libxenlight)
 
 xenlight_OBJS = $(OBJS)
tools/ocaml/libs/xl/xenlight.ml.in +4 -0
index dcc1a38..3d663d8 100644
@@ -20,6 +20,10 @@ type devid = int
 
 (* @@LIBXL_TYPES@@ *)
 
+type ctx
+
+external ctx_alloc: Xentoollog.handle -> ctx = "stub_libxl_ctx_alloc"
+
 external send_trigger : domid -> trigger -> int -> unit = "stub_xl_send_trigger"
 external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys"
tools/ocaml/libs/xl/xenlight.mli.in +4 -0
index 3fd0165..96d859c 100644
@@ -20,6 +20,10 @@ type devid = int
 
 (* @@LIBXL_TYPES@@ *)
 
+type ctx
+
+external ctx_alloc: Xentoollog.handle -> ctx = "stub_libxl_ctx_alloc"
+
 external send_trigger : domid -> trigger -> int -> unit = "stub_xl_send_trigger"
 external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys"
tools/ocaml/libs/xl/xenlight_stubs.c +41 -1

75 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#12 lore raw

PATCH v2 12/30 libxl: ocaml: switch all functions over to take a context.

In reply to Rob Hoes

Since the context has a logger we can get rid of the logger built into these bindings and use the xentoollog bindings instead.

The gc is of limited use when most things are freed with libxl_FOO_dispose, so get rid of that too.

---
 tools/ocaml/libs/xl/genwrap.py       |   44 ++--
 tools/ocaml/libs/xl/xenlight.ml.in   |   11 +-
 tools/ocaml/libs/xl/xenlight.mli.in  |    9 +-
 tools/ocaml/libs/xl/xenlight_stubs.c |  477 +++++++++-------------------------
 4 files changed, 153 insertions(+), 388 deletions(-)
tools/ocaml/libs/xl/genwrap.py +22 -22
index 05c4582..b617cb5 100644
@@ -8,23 +8,23 @@ import idl
 builtins = {
     "bool":                 ("bool",                   "%(c)s = Bool_val(%(o)s)",           "Val_bool(%(c)s)" ),
     "int":                  ("int",                    "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
-    "char *":               ("string",                 "%(c)s = dup_String_val(gc, %(o)s)", "caml_copy_string(%(c)s)"),
+    "char *":               ("string",                 "%(c)s = dup_String_val(%(o)s)", "caml_copy_string(%(c)s)"),
     "libxl_domid":          ("domid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_devid":          ("devid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_defbool":        ("bool option",            "%(c)s = Defbool_val(%(o)s)",        "Val_defbool(%(c)s)" ),
-    "libxl_uuid":           ("int array",              "Uuid_val(gc, lg, &%(c)s, %(o)s)",   "Val_uuid(&%(c)s)"),
-    "libxl_bitmap":         ("bool array",             "Bitmap_val(gc, lg, &%(c)s, %(o)s)",   "Val_bitmap(&%(c)s)"),    
-    "libxl_key_value_list": ("(string * string) list", "libxl_key_value_list_val(gc, lg, &%(c)s, %(o)s)", "Val_key_value_list(&%(c)s)"),
-    "libxl_string_list":    ("string list",            "libxl_string_list_val(gc, lg, &%(c)s, %(o)s)", "Val_string_list(&%(c)s)"),
-    "libxl_mac":            ("int array",              "Mac_val(gc, lg, &%(c)s, %(o)s)",    "Val_mac(&%(c)s)"),
+    "libxl_uuid":           ("int array",              "Uuid_val(&%(c)s, %(o)s)",   "Val_uuid(&%(c)s)"),
+    "libxl_bitmap":         ("bool array",             "Bitmap_val(ctx, &%(c)s, %(o)s)",   "Val_bitmap(&%(c)s)"),    
+    "libxl_key_value_list": ("(string * string) list", "libxl_key_value_list_val(&%(c)s, %(o)s)", "Val_key_value_list(&%(c)s)"),
+    "libxl_string_list":    ("string list",            "libxl_string_list_val(&%(c)s, %(o)s)", "Val_string_list(&%(c)s)"),
+    "libxl_mac":            ("int array",              "Mac_val(&%(c)s, %(o)s)",    "Val_mac(&%(c)s)"),
     "libxl_hwcap":          ("int32 array",            None,                                "Val_hwcap(&%(c)s)"),
     # The following needs to be sorted out later
     "libxl_cpuid_policy_list": ("unit",                "%(c)s = 0",                         "Val_unit"),
     }
 
-DEVICE_FUNCTIONS = [ ("add",            ["t", "domid", "unit"]),
-                     ("remove",         ["t", "domid", "unit"]),
-                     ("destroy",        ["t", "domid", "unit"]),
+DEVICE_FUNCTIONS = [ ("add",            ["ctx", "t", "domid", "unit"]),
+                     ("remove",         ["ctx", "t", "domid", "unit"]),
+                     ("destroy",        ["ctx", "t", "domid", "unit"]),
                    ]
 
 functions = { # ( name , [type1,type2,....] )
@@ -33,13 +33,13 @@ functions = { # ( name , [type1,type2,....] )
     "device_disk":    DEVICE_FUNCTIONS,
     "device_nic":     DEVICE_FUNCTIONS,
     "device_pci":     DEVICE_FUNCTIONS,
-    "physinfo":       [ ("get",            ["unit", "t"]),
+    "physinfo":       [ ("get",            ["ctx", "t"]),
                       ],
-    "cputopology":    [ ("get",            ["unit", "t array"]),
+    "cputopology":    [ ("get",            ["ctx", "t array"]),
                       ],
     "domain_sched_params":
-                      [ ("get",            ["domid", "t"]),
-                        ("set",            ["domid", "t", "unit"]),
+                      [ ("get",            ["ctx", "domid", "t"]),
+                        ("set",            ["ctx", "domid", "t", "unit"]),
                       ],
 }
 def stub_fn_name(ty, name):
@@ -229,7 +229,7 @@ def c_val(ty, c, o, indent="", parent = None):
         for e in ty.values:
             s += "    case %d: *%s = %s; break;\n" % (n, c, e.name)
             n += 1
-        s += "    default: failwith_xl(\"cannot convert value to %s\", lg); break;\n" % ty.typename
+        s += "    default: failwith_xl(\"cannot convert value to %s\"); break;\n" % ty.typename
         s += "}"
     elif isinstance(ty, idl.KeyedUnion):
         s += "{\n"
@@ -242,7 +242,7 @@ def c_val(ty, c, o, indent="", parent = None):
                                                     parent + ty.keyvar.name,
                                                     f.enumname)
                 n += 1
-        s += "\t\t    default: failwith_xl(\"variant handling bug %s%s (long)\", lg); break;\n" % (parent, ty.keyvar.name)        
+        s += "\t\t    default: failwith_xl(\"variant handling bug %s%s (long)\"); break;\n" % (parent, ty.keyvar.name)        
         s += "\t\t}\n"
         s += "\t} else {\n"
         s += "\t\t/* Is block... */\n"
@@ -258,7 +258,7 @@ def c_val(ty, c, o, indent="", parent = None):
                 s += "%s" % c_val(f.type, fexpr, "Field(%s, 0)" % o, indent=indent+"\t\t        ")
                 s += "break;\n"
                 n += 1
-        s += "\t\t    default: failwith_xl(\"variant handling bug %s%s (block)\", lg); break;\n" % (parent, ty.keyvar.name)
+        s += "\t\t    default: failwith_xl(\"variant handling bug %s%s (block)\"); break;\n" % (parent, ty.keyvar.name)
         s += "\t\t}\n"
         s += "\t}\n"
         s += "}"
@@ -271,14 +271,14 @@ def c_val(ty, c, o, indent="", parent = None):
             s += "%s\n" % c_val(f.type, fexpr, "Field(%s, %d)" % (o,n), parent=nparent)
             n = n + 1
     else:
-        s += "%s_val(gc, lg, %s, %s);" % (ty.rawname, ty.pass_arg(c, parent is None, passby=idl.PASS_BY_REFERENCE), o)
+        s += "%s_val(ctx, %s, %s);" % (ty.rawname, ty.pass_arg(c, parent is None, passby=idl.PASS_BY_REFERENCE), o)
     
     return s.replace("\n", "\n%s" % indent)
 
 def gen_c_val(ty, indent=""):
     s = "/* Convert caml value to %s */\n" % ty.rawname
     
-    s += "static int %s_val (caml_gc *gc, struct caml_logger *lg, %s, value v)\n" % (ty.rawname, ty.make_arg("c_val", passby=idl.PASS_BY_REFERENCE))
+    s += "static int %s_val (libxl_ctx *ctx, %s, value v)\n" % (ty.rawname, ty.make_arg("c_val", passby=idl.PASS_BY_REFERENCE))
     s += "{\n"
     s += "\tCAMLparam1(v);\n"
     s += "\n"
@@ -327,7 +327,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
         for e in ty.values:
             s += "    case %s: %s = Int_val(%d); break;\n" % (e.name, o, n)
             n += 1
-        s += "    default: failwith_xl(\"cannot convert value from %s\", lg); break;\n" % ty.typename
+        s += "    default: failwith_xl(\"cannot convert value from %s\"); break;\n" % ty.typename
         s += "}"
     elif isinstance(ty, idl.KeyedUnion):
         n = 0
@@ -356,7 +356,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
                 m += 1
                 #s += "\t        %s = caml_alloc(%d,%d);\n" % (o,len(f.type.fields),n)
             s += "\t        break;\n"
-        s += "\t    default: failwith_xl(\"cannot convert value from %s\", lg); break;\n" % ty.typename
+        s += "\t    default: failwith_xl(\"cannot convert value from %s\"); break;\n" % ty.typename
         s += "\t}"
     elif isinstance(ty,idl.Aggregate) and (parent is None or ty.rawname is None):
         s += "{\n"
@@ -381,14 +381,14 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
             n = n + 1
         s += "}"
     else:
-        s += "%s = Val_%s(gc, lg, %s);" % (o, ty.rawname, ty.pass_arg(c, parent is None))
+        s += "%s = Val_%s(%s);" % (o, ty.rawname, ty.pass_arg(c, parent is None))
     
     return s.replace("\n", "\n%s" % indent).rstrip(indent)
 
 def gen_Val_ocaml(ty, indent=""):
     s = "/* Convert %s to a caml value */\n" % ty.rawname
 
-    s += "static value Val_%s (caml_gc *gc, struct caml_logger *lg, %s)\n" % (ty.rawname, ty.make_arg(ty.rawname+"_c"))
+    s += "static value Val_%s (%s)\n" % (ty.rawname, ty.make_arg(ty.rawname+"_c"))
     s += "{\n"
     s += "\tCAMLparam0();\n"
     s += "\tCAMLlocal1(%s_ocaml);\n" % ty.rawname
tools/ocaml/libs/xl/xenlight.ml.in +5 -6
index 3d663d8..dffba72 100644
@@ -15,17 +15,16 @@
 
 exception Error of string
 
+type ctx
 type domid = int
 type devid = int
 
 (* @@LIBXL_TYPES@@ *)
 
-type ctx
-
 external ctx_alloc: Xentoollog.handle -> ctx = "stub_libxl_ctx_alloc"
 
-external send_trigger : domid -> trigger -> int -> unit = "stub_xl_send_trigger"
-external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq"
-external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys"
+external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
+external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
+external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
 
-let _ = Callback.register_exception "xl.error" (Error "register_callback")
+let _ = Callback.register_exception "Xenlight.Error" (Error(""))
tools/ocaml/libs/xl/xenlight.mli.in +4 -5
index 96d859c..e2686bb 100644
@@ -15,15 +15,14 @@
 
 exception Error of string
 
+type ctx
 type domid = int
 type devid = int
 
 (* @@LIBXL_TYPES@@ *)
 
-type ctx
-
 external ctx_alloc: Xentoollog.handle -> ctx = "stub_libxl_ctx_alloc"
 
-external send_trigger : domid -> trigger -> int -> unit = "stub_xl_send_trigger"
-external send_sysrq : domid -> char -> unit = "stub_xl_send_sysrq"
-external send_debug_keys : domid -> string -> unit = "stub_xl_send_debug_keys"
+external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
+external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
+external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
tools/ocaml/libs/xl/xenlight_stubs.c +122 -355

633 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#13 lore raw

PATCH v2 13/30 libxl: ocaml: propagate the libxl return error code in exceptions

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py       |   10 ++---
 tools/ocaml/libs/xl/xenlight.ml.in   |   43 ++++++++++++++++++--
 tools/ocaml/libs/xl/xenlight.mli.in  |   26 ++++++++++--
 tools/ocaml/libs/xl/xenlight_stubs.c |   74 +++++++++++++++++++++++++++-------
 4 files changed, 127 insertions(+), 26 deletions(-)
tools/ocaml/libs/xl/genwrap.py +5 -5
index b617cb5..15d513a 100644
@@ -229,7 +229,7 @@ def c_val(ty, c, o, indent="", parent = None):
         for e in ty.values:
             s += "    case %d: *%s = %s; break;\n" % (n, c, e.name)
             n += 1
-        s += "    default: failwith_xl(\"cannot convert value to %s\"); break;\n" % ty.typename
+        s += "    default: failwith_xl(ERROR_FAIL, \"cannot convert value to %s\"); break;\n" % ty.typename
         s += "}"
     elif isinstance(ty, idl.KeyedUnion):
         s += "{\n"
@@ -242,7 +242,7 @@ def c_val(ty, c, o, indent="", parent = None):
                                                     parent + ty.keyvar.name,
                                                     f.enumname)
                 n += 1
-        s += "\t\t    default: failwith_xl(\"variant handling bug %s%s (long)\"); break;\n" % (parent, ty.keyvar.name)        
+        s += "\t\t    default: failwith_xl(ERROR_FAIL, \"variant handling bug %s%s (long)\"); break;\n" % (parent, ty.keyvar.name)        
         s += "\t\t}\n"
         s += "\t} else {\n"
         s += "\t\t/* Is block... */\n"
@@ -258,7 +258,7 @@ def c_val(ty, c, o, indent="", parent = None):
                 s += "%s" % c_val(f.type, fexpr, "Field(%s, 0)" % o, indent=indent+"\t\t        ")
                 s += "break;\n"
                 n += 1
-        s += "\t\t    default: failwith_xl(\"variant handling bug %s%s (block)\"); break;\n" % (parent, ty.keyvar.name)
+        s += "\t\t    default: failwith_xl(ERROR_FAIL, \"variant handling bug %s%s (block)\"); break;\n" % (parent, ty.keyvar.name)
         s += "\t\t}\n"
         s += "\t}\n"
         s += "}"
@@ -327,7 +327,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
         for e in ty.values:
             s += "    case %s: %s = Int_val(%d); break;\n" % (e.name, o, n)
             n += 1
-        s += "    default: failwith_xl(\"cannot convert value from %s\"); break;\n" % ty.typename
+        s += "    default: failwith_xl(ERROR_FAIL, \"cannot convert value from %s\"); break;\n" % ty.typename
         s += "}"
     elif isinstance(ty, idl.KeyedUnion):
         n = 0
@@ -356,7 +356,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
                 m += 1
                 #s += "\t        %s = caml_alloc(%d,%d);\n" % (o,len(f.type.fields),n)
             s += "\t        break;\n"
-        s += "\t    default: failwith_xl(\"cannot convert value from %s\"); break;\n" % ty.typename
+        s += "\t    default: failwith_xl(ERROR_FAIL, \"cannot convert value from %s\"); break;\n" % ty.typename
         s += "\t}"
     elif isinstance(ty,idl.Aggregate) and (parent is None or ty.rawname is None):
         s += "{\n"
tools/ocaml/libs/xl/xenlight.ml.in +39 -4

57 lines not on this page · raw message

tools/ocaml/libs/xl/xenlight.mli.in +23 -3
index e2686bb..34b1ce5 100644
@@ -13,16 +13,36 @@
  * GNU Lesser General Public License for more details.
  *)
 
-exception Error of string
-
 type ctx
 type domid = int
 type devid = int
 
-(* @@LIBXL_TYPES@@ *)
+type error =
+    Nonspecific |
+    Version |
+    Fail |
+    Ni |
+    Nomem |
+    Inval |
+    Badfail |
+    Guest_Timedout |
+    Timedout |
+    Noparavirt |
+    Not_Ready |
+    Osevent_Reg_Fail |
+    Bufferfull |
+    Unknown_Child
+
+val string_of_error: error -> string
+
+exception Error of (error * string)
 
 external ctx_alloc: Xentoollog.handle -> ctx = "stub_libxl_ctx_alloc"
 
+external test_raise_exception: unit -> unit = "stub_raise_exception"
+
+(* @@LIBXL_TYPES@@ *)
+
 external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
 external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
tools/ocaml/libs/xl/xenlight_stubs.c +60 -14

142 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#14 lore raw

PATCH v2 14/30 libxl: ocaml: make Val_defbool GC-proof

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/xenlight_stubs.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
tools/ocaml/libs/xl/xenlight_stubs.c +7 -5
index 53b9d4e..7b7d696 100644
@@ -332,15 +332,17 @@ static int Uuid_val(libxl_uuid *c_val, value v)
 static value Val_defbool(libxl_defbool c_val)
 {
 	CAMLparam0();
-	CAMLlocal1(v);
+	CAMLlocal2(v1, v2);
+	bool b;
 
 	if (libxl_defbool_is_default(c_val))
-		v = Val_none;
+		v2 = Val_none;
 	else {
-		bool b = libxl_defbool_val(c_val);
-		v = Val_some(b ? Val_bool(true) : Val_bool(false));
+		b = libxl_defbool_val(c_val);
+		v1 = b ? Val_bool(true) : Val_bool(false);
+		v2 = Val_some(v1);
 	}
-	CAMLreturn(v);
+	CAMLreturn(v2);
 }
 
 static libxl_defbool Defbool_val(value v)
Signature · 1 line
1.7.10.4
author
#15 lore raw

PATCH v2 15/30 libxl: ocaml: add domain_build/create_info/config and events to the bindings.

In reply to Rob Hoes

We now have enoguh infrastructure in place to do this trivially.

---
 tools/libxl/libxl_types.idl    |    2 +-
 tools/ocaml/libs/xl/genwrap.py |    4 ----
 2 files changed, 1 insertion(+), 5 deletions(-)
tools/libxl/libxl_types.idl +1 -1
index daa8bb9..58fd103 100644
@@ -435,7 +435,7 @@ libxl_domain_config = Struct("domain_config", [
     ("on_reboot", libxl_action_on_shutdown),
     ("on_watchdog", libxl_action_on_shutdown),
     ("on_crash", libxl_action_on_shutdown),
-    ])
+    ], dir=DIR_IN)
 
 libxl_diskinfo = Struct("diskinfo", [
     ("backend", string),
tools/ocaml/libs/xl/genwrap.py +0 -4
index 15d513a..3f8bcbf 100644
@@ -426,11 +426,7 @@ if __name__ == '__main__':
     # Do not generate these yet.
     blacklist = [
         "cpupoolinfo",
-        "domain_create_info",
-        "domain_build_info",
-        "domain_config",
         "vcpuinfo",
-        "event",
         ]
 
     for t in blacklist:
Signature · 1 line
1.7.10.4
author
#16 lore raw

PATCH v2 16/30 libxl: ocaml: add META to list of generated files in Makefile

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/Makefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ocaml/libs/xl/Makefile +1 -1
index 6917a20..0408cc2 100644
@@ -22,7 +22,7 @@ OCAML_LIBRARY = xenlight
 
 GENERATED_FILES += xenlight.ml xenlight.ml.tmp xenlight.mli xenlight.mli.tmp
 GENERATED_FILES += _libxl_types.ml.in _libxl_types.mli.in
-GENERATED_FILES += _libxl_types.inc
+GENERATED_FILES += _libxl_types.inc META
 
 all: $(INTF) $(LIBS)
 
Signature · 1 line
1.7.10.4
author
#17 lore raw

PATCH v2 17/30 libxl: ocaml: fix the handling of enums in the bindings generator

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/ocaml/libs/xl/genwrap.py +1 -1
index 3f8bcbf..f0d4885 100644
@@ -325,7 +325,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
         n = 0
         s += "switch(%s) {\n" % c
         for e in ty.values:
-            s += "    case %s: %s = Int_val(%d); break;\n" % (e.name, o, n)
+            s += "    case %s: %s = Val_int(%d); break;\n" % (e.name, o, n)
             n += 1
         s += "    default: failwith_xl(ERROR_FAIL, \"cannot convert value from %s\"); break;\n" % ty.typename
         s += "}"
Signature · 1 line
1.7.10.4
author
#18 lore raw

PATCH v2 18/30 libxl: ocaml: use the "string option" type for IDL strings

In reply to Rob Hoes

The libxl IDL is based on C type "char *", and therefore "strings" can by NULL, or be an actual string. In ocaml, it is common to encode such things as option types.

---
 tools/ocaml/libs/xl/genwrap.py       |    2 +-
 tools/ocaml/libs/xl/xenlight_stubs.c |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
tools/ocaml/libs/xl/genwrap.py +1 -1
index f0d4885..d967ee6 100644
@@ -8,7 +8,7 @@ import idl
 builtins = {
     "bool":                 ("bool",                   "%(c)s = Bool_val(%(o)s)",           "Val_bool(%(c)s)" ),
     "int":                  ("int",                    "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
-    "char *":               ("string",                 "%(c)s = dup_String_val(%(o)s)", "caml_copy_string(%(c)s)"),
+    "char *":               ("string option",          "%(c)s = String_option_val(%(o)s)",  "Val_string_option(%(c)s)"),
     "libxl_domid":          ("domid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_devid":          ("devid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_defbool":        ("bool option",            "%(c)s = Defbool_val(%(o)s)",        "Val_defbool(%(c)s)" ),
tools/ocaml/libs/xl/xenlight_stubs.c +21 -0
index 7b7d696..e801643 100644
@@ -371,6 +371,27 @@ static value Val_hwcap(libxl_hwcap *c_val)
 	CAMLreturn(hwcap);
 }
 
+static value Val_string_option(const char *c_val)
+{
+	CAMLparam0();
+	CAMLlocal2(tmp1, tmp2);
+	if (c_val) {
+		tmp1 = caml_copy_string(c_val);
+		tmp2 = Val_some(tmp1);
+		CAMLreturn(tmp2);
+	}
+	else
+		CAMLreturn(Val_none);
+}
+
+static char *String_option_val(value v)
+{
+	char *s = NULL;
+	if (v != Val_none)
+		s = dup_String_val(Some_val(v));
+	return s;
+}
+
 #include "_libxl_types.inc"
 
 #define _STRINGIFY(x) #x
Signature · 1 line
1.7.10.4
#19 lore raw

Re: [PATCH v2 18/30] libxl: ocaml: use the "string option" type for IDL strings

Quoted 2 lines · Rob Hoes

The libxl IDL is based on C type "char *", and therefore "strings" can by NULL, or be an actual string. In ocaml, it is common to encode such

"can be NULL" perhaps?

~Andrew

Quoted 53 lines

things as option types.

---
 tools/ocaml/libs/xl/genwrap.py       |    2 +-
 tools/ocaml/libs/xl/xenlight_stubs.c |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
tools/ocaml/libs/xl/genwrap.py +1 -1
index f0d4885..d967ee6 100644
@@ -8,7 +8,7 @@ import idl
 builtins = {
     "bool":                 ("bool",                   "%(c)s = Bool_val(%(o)s)",           "Val_bool(%(c)s)" ),
     "int":                  ("int",                    "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
-    "char *":               ("string",                 "%(c)s = dup_String_val(%(o)s)", "caml_copy_string(%(c)s)"),
+    "char *":               ("string option",          "%(c)s = String_option_val(%(o)s)",  "Val_string_option(%(c)s)"),
     "libxl_domid":          ("domid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_devid":          ("devid",                  "%(c)s = Int_val(%(o)s)",            "Val_int(%(c)s)"  ),
     "libxl_defbool":        ("bool option",            "%(c)s = Defbool_val(%(o)s)",        "Val_defbool(%(c)s)" ),
tools/ocaml/libs/xl/xenlight_stubs.c +21 -0
index 7b7d696..e801643 100644
@@ -371,6 +371,27 @@ static value Val_hwcap(libxl_hwcap *c_val)
 	CAMLreturn(hwcap);
 }
 
+static value Val_string_option(const char *c_val)
+{
+	CAMLparam0();
+	CAMLlocal2(tmp1, tmp2);
+	if (c_val) {
+		tmp1 = caml_copy_string(c_val);
+		tmp2 = Val_some(tmp1);
+		CAMLreturn(tmp2);
+	}
+	else
+		CAMLreturn(Val_none);
+}
+
+static char *String_option_val(value v)
+{
+	char *s = NULL;
+	if (v != Val_none)
+		s = dup_String_val(Some_val(v));
+	return s;
+}
+
 #include "_libxl_types.inc"
 
 #define _STRINGIFY(x) #x
author
#20 lore raw

PATCH v2 19/30 libxl: ocaml: add xen_console_read

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/xenlight.ml.in   |    1 +
 tools/ocaml/libs/xl/xenlight.mli.in  |    1 +
 tools/ocaml/libs/xl/xenlight_stubs.c |   27 +++++++++++++++++++++++++++
 3 files changed, 29 insertions(+)
tools/ocaml/libs/xl/xenlight.ml.in +1 -0
index 883df0c..fd5c4ce 100644
@@ -61,5 +61,6 @@ external test_raise_exception: unit -> unit = "stub_raise_exception"
 external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
 external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
+external xen_console_read : ctx -> string list = "stub_xl_xen_console_read"
 
 let _ = Callback.register_exception "Xenlight.Error" (Error(Fail, ""))
tools/ocaml/libs/xl/xenlight.mli.in +1 -0
index 34b1ce5..11ea43c 100644
@@ -46,3 +46,4 @@ external test_raise_exception: unit -> unit = "stub_raise_exception"
 external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
 external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
+external xen_console_read : ctx -> string list = "stub_xl_xen_console_read"
tools/ocaml/libs/xl/xenlight_stubs.c +27 -0
index e801643..cacaaca 100644
@@ -557,6 +557,33 @@ value stub_xl_send_debug_keys(value ctx, value keys)
 	CAMLreturn(Val_unit);
 }
 
+value stub_xl_xen_console_read(value ctx)
+{
+	CAMLparam1(ctx);
+	CAMLlocal3(list, cons, ml_line);
+	int i = 0, ret;
+	char *console[32768], *line;
+	libxl_xen_console_reader *cr;
+
+	cr = libxl_xen_console_read_start(CTX, 0);
+	if (cr)
+		for (i = 0; libxl_xen_console_read_line(CTX, cr, &line) > 0; i++)
+			console[i] = strdup(line);
+	libxl_xen_console_read_finish(CTX, cr);
+
+	list = Val_emptylist;
+	for (; i > 0; i--) {
+		ml_line = caml_copy_string(console[i - 1]);
+		free(console[i - 1]);
+		cons = caml_alloc(2, 0);
+		Store_field(cons, 0, ml_line);  // head
+		Store_field(cons, 1, list);     // tail
+		list = cons;
+	}
+
+	CAMLreturn(list);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: t
Signature · 1 line
1.7.10.4
author
#21 lore raw

PATCH v2 20/30 libxl: ocaml: add dominfo_list and dominfo_get

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py       |    3 +++
 tools/ocaml/libs/xl/xenlight_stubs.c |   41 ++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
tools/ocaml/libs/xl/genwrap.py +3 -0
index d967ee6..23de43a 100644
@@ -33,6 +33,9 @@ functions = { # ( name , [type1,type2,....] )
     "device_disk":    DEVICE_FUNCTIONS,
     "device_nic":     DEVICE_FUNCTIONS,
     "device_pci":     DEVICE_FUNCTIONS,
+    "dominfo":        [ ("list",           ["ctx", "t list"]),
+                        ("get",            ["ctx", "domid", "t"]),
+                      ],
     "physinfo":       [ ("get",            ["ctx", "t"]),
                       ],
     "cputopology":    [ ("get",            ["ctx", "t array"]),
tools/ocaml/libs/xl/xenlight_stubs.c +41 -0

47 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#22 lore raw

PATCH v2 21/30 libxl: ocaml: implement some simple tests

In reply to Rob Hoes
---
 .gitignore                          |    3 ++-
 .hgignore                           |    2 ++
 tools/ocaml/test/Makefile           |   30 ++++++++++++++++++++++++++----
 tools/ocaml/test/list_domains.ml    |   29 +++++++++++++++++++++++++++++
 tools/ocaml/test/raise_exception.ml |   11 +++++++++++
 tools/ocaml/test/send_debug_keys.ml |   16 ++++++++++++++++
 6 files changed, 86 insertions(+), 5 deletions(-)
 create mode 100644 tools/ocaml/test/list_domains.ml
 create mode 100644 tools/ocaml/test/raise_exception.ml
 create mode 100644 tools/ocaml/test/send_debug_keys.ml
.gitignore +2 -1
index 5acebd0..70cca17 100644
@@ -402,7 +402,8 @@ tools/ocaml/libs/xl/xenlight.ml
 tools/ocaml/libs/xl/xenlight.mli
 tools/ocaml/xenstored/oxenstored
 tools/ocaml/test/xtl
-
+tools/ocaml/test/send_debug_keys
+tools/ocaml/test/list_domains
 tools/debugger/kdd/kdd
 tools/firmware/etherboot/ipxe.tar.gz
 tools/firmware/etherboot/ipxe/
.hgignore +2 -0
index 685a785..9de4f27 100644
@@ -327,6 +327,8 @@
 ^tools/ocaml/libs/xl/xenlight\.mli$
 ^tools/ocaml/xenstored/oxenstored$
 ^tools/ocaml/test/xtl$
+^tools/ocaml/test/send_debug_keys$
+^tools/ocaml/test/list_domains$
 ^tools/autom4te\.cache$
 ^tools/config\.h$
 ^tools/config\.log$
tools/ocaml/test/Makefile +26 -4
index 980054c..2c5fdd8 100644
@@ -3,11 +3,12 @@ OCAML_TOPLEVEL = $(CURDIR)/..
 include $(OCAML_TOPLEVEL)/common.make
 
 OCAMLINCLUDE += \
-	-I $(OCAML_TOPLEVEL)/libs/xentoollog
+	-I $(OCAML_TOPLEVEL)/libs/xentoollog \
+	-I $(OCAML_TOPLEVEL)/libs/xl
 
-OBJS = xtl
+OBJS = xtl send_debug_keys list_domains raise_exception
 
-PROGRAMS = xtl
+PROGRAMS = xtl send_debug_keys list_domains raise_exception
 
 xtl_LIBS =  \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xentoollog $(OCAML_TOPLEVEL)/libs/xentoollog/xentoollog.cmxa \
@@ -15,7 +16,28 @@ xtl_LIBS =  \
 
 xtl_OBJS = xtl
 
-OCAML_PROGRAM = xtl
+send_debug_keys_LIBS =  \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xentoollog $(OCAML_TOPLEVEL)/libs/xentoollog/xentoollog.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xl $(OCAML_TOPLEVEL)/libs/xl/xenlight.cmxa \
+	-cclib -lxenlight
+
+send_debug_keys_OBJS = send_debug_keys
+
+list_domains_LIBS =  \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xentoollog $(OCAML_TOPLEVEL)/libs/xentoollog/xentoollog.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xl $(OCAML_TOPLEVEL)/libs/xl/xenlight.cmxa \
+	-cclib -lxenlight
+
+list_domains_OBJS = list_domains
+
+raise_exception_LIBS =  \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xentoollog $(OCAML_TOPLEVEL)/libs/xentoollog/xentoollog.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xl $(OCAML_TOPLEVEL)/libs/xl/xenlight.cmxa \
+	-cclib -lxenlight
+
+raise_exception_OBJS = raise_exception
+
+OCAML_PROGRAM = xtl send_debug_keys list_domains raise_exception
 
 all: $(PROGRAMS)
 
tools/ocaml/test/list_domains.ml new file +29 -0
new file mode 100644
index 0000000..e21dd71
@@ -0,0 +1,29 @@
+open Arg
+open Printf
+open Xentoollog
+open Xenlight
+
+let bool_as_char b c = if b then c else '-'
+
+let print_dominfo dominfo =
+  let id = dominfo.Xenlight.Dominfo.domid
+  and running = bool_as_char dominfo.Xenlight.Dominfo.running 'r'
+  and blocked = bool_as_char dominfo.Xenlight.Dominfo.blocked 'b'
+  and paused = bool_as_char dominfo.Xenlight.Dominfo.paused 'p'
+  and shutdown = bool_as_char dominfo.Xenlight.Dominfo.shutdown 's'
+  and dying = bool_as_char dominfo.Xenlight.Dominfo.dying 'd'
+  and memory = dominfo.Xenlight.Dominfo.current_memkb
+  in
+  printf "Dom %d: %c%c%c%c%c %LdKB\n" id running blocked paused shutdown dying memory
+
+let _ =
+  let logger = Xentoollog.create_stdio_logger (*~level:Xentoollog.Debug*) () in
+  let ctx = Xenlight.ctx_alloc logger in
+  try
+    let domains = Xenlight.Dominfo.list ctx in
+    List.iter (fun d -> print_dominfo d) domains
+  with Xenlight.Error(err, fn) -> begin
+    printf "Caught Exception: %s: %s\n" (Xenlight.string_of_error err) fn;
+  end
+
+
tools/ocaml/test/raise_exception.ml new file +11 -0
new file mode 100644
index 0000000..d4371f5
@@ -0,0 +1,11 @@
+open Printf
+open Xentoollog
+open Xenlight
+
+let _ = 
+  try
+    Xenlight.test_raise_exception ()
+  with Xenlight.Error(err, fn) -> begin
+    printf "Caught Exception: %s: %s\n" (Xenlight.string_of_error err) fn;
+  end
+
tools/ocaml/test/send_debug_keys.ml new file +16 -0
new file mode 100644
index 0000000..6db89e8
@@ -0,0 +1,16 @@
+open Arg
+open Printf
+open Xentoollog
+open Xenlight
+
+let send_keys ctx s = 
+  printf "Sending debug key %s\n" s;
+  Xenlight.send_debug_keys ctx s;
+  ()
+  
+let _ = 
+  let logger = Xentoollog.create_stdio_logger () in
+  let ctx = Xenlight.ctx_alloc logger in
+  Arg.parse [
+  ] (fun s -> send_keys ctx s) "usage: send_debug_keys <keys>"
+
Signature · 1 line
1.7.10.4
author
#23 lore raw

PATCH v2 22/30 libxl: ocaml: event management

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/xenlight.ml.in   |   70 +++++++-
 tools/ocaml/libs/xl/xenlight.mli.in  |   48 +++++
 tools/ocaml/libs/xl/xenlight_stubs.c |  325 ++++++++++++++++++++++++++++++++++
 3 files changed, 442 insertions(+), 1 deletion(-)
tools/ocaml/libs/xl/xenlight.ml.in +69 -1
index fd5c4ce..06c9f52 100644
@@ -56,6 +56,14 @@ external ctx_alloc: Xentoollog.handle -> ctx = "stub_libxl_ctx_alloc"
 
 external test_raise_exception: unit -> unit = "stub_raise_exception"
 
+type event =
+	| POLLIN (* There is data to read *)
+	| POLLPRI (* There is urgent data to read *)
+	| POLLOUT (* Writing now will not block *)
+	| POLLERR (* Error condition (revents only) *)
+	| POLLHUP (* Device has been disconnected (revents only) *)
+	| POLLNVAL (* Invalid request: fd not open (revents only). *)
+
 (* @@LIBXL_TYPES@@ *)
 
 external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
@@ -63,4 +71,64 @@ external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
 external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
 external xen_console_read : ctx -> string list = "stub_xl_xen_console_read"
 
-let _ = Callback.register_exception "Xenlight.Error" (Error(Fail, ""))
+module type EVENT_USERS =
+	sig
+		type osevent_user
+		type event_user
+		type async_user
+	end
+
+module Async = functor (S: EVENT_USERS) -> struct
+	type for_libxl
+	type event_hooks
+	type osevent_hooks
+
+	module OseventSet = Set.Make(struct type t = S.osevent_user;; let compare = Pervasives.compare end)
+	module EventSet = Set.Make(struct type t = S.event_user;; let compare = Pervasives.compare end)
+	module AsyncSet = Set.Make(struct type t = S.async_user;; let compare = Pervasives.compare end)
+
+	let osevent_users = ref OseventSet.empty
+	let event_users = ref EventSet.empty
+	let async_users = ref AsyncSet.empty
+	let async_callback_ref = ref None
+
+	external osevent_register_hooks' : ctx -> S.osevent_user -> osevent_hooks = "stub_libxl_osevent_register_hooks"
+	external osevent_occurred_fd : ctx -> for_libxl -> Unix.file_descr -> event list -> event list -> unit = "stub_libxl_osevent_occurred_fd"
+	external osevent_occurred_timeout : ctx -> for_libxl -> unit = "stub_libxl_osevent_occurred_timeout"
+
+	let osevent_register_hooks ctx ~user ~fd_register ~fd_modify ~fd_deregister ~timeout_register ~timeout_modify =
+		Callback.register "libxl_fd_register" fd_register;
+		Callback.register "libxl_fd_modify" fd_modify;
+		Callback.register "libxl_fd_deregister" fd_deregister;
+		Callback.register "libxl_timeout_register" timeout_register;
+		Callback.register "libxl_timeout_modify" timeout_modify;
+		osevent_users := OseventSet.add user !osevent_users;
+		osevent_register_hooks' ctx user
+
+	let async f user =
+		async_users := AsyncSet.add user !async_users;
+		f ?async:(Some user) ()
+
+	let async_callback' result user =
+		async_users := AsyncSet.remove user !async_users;
+		match !async_callback_ref with
+		| None -> ()
+		| Some f -> f ~result ~user
+
+	let async_register_callback ~async_callback =
+		async_callback_ref := Some async_callback;
+		Callback.register "libxl_async_callback" async_callback'
+
+	external evenable_domain_death : ctx -> domid -> int -> unit = "stub_libxl_evenable_domain_death"
+	external event_register_callbacks' : ctx -> S.event_user -> event_hooks = "stub_libxl_event_register_callbacks"
+
+	let event_register_callbacks ctx ~user ~event_occurs_callback ~event_disaster_callback =
+		Callback.register "libxl_event_occurs_callback" event_occurs_callback;
+		Callback.register "libxl_event_disaster_callback" event_disaster_callback;
+		event_users := EventSet.add user !event_users;
+		event_register_callbacks' ctx user
+end
+
+let _ =
+	Callback.register_exception "Xenlight.Error" (Error(Fail, ""))
+
tools/ocaml/libs/xl/xenlight.mli.in +48 -0

57 lines not on this page · raw message

tools/ocaml/libs/xl/xenlight_stubs.c +325 -0

343 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#24 lore raw

PATCH v2 23/30 libxl: ocaml: allow device operations to be called asynchronously

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py       |    6 +++---
 tools/ocaml/libs/xl/xenlight_stubs.c |   14 +++++++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)
tools/ocaml/libs/xl/genwrap.py +3 -3
index 23de43a..57ec143 100644
@@ -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,....] )
tools/ocaml/libs/xl/xenlight_stubs.c +11 -3
index c98a660..5ac8213 100644
@@ -420,15 +420,23 @@ 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;					\
 									\
 	device_##type##_val(CTX, &c_info, info);			\
 									\
-	ret = libxl_device_##type##_##op(CTX, Int_val(domid), &c_info, 0); \
+	if (async != Val_none) {					\
+		ao_how.callback = async_callback;			\
+		ao_how.u.for_callback = (void *) Some_val(async);	\
+	}								\
+									\
+	ret = libxl_device_##type##_##op(CTX, Int_val(domid), &c_info,	\
+		async != Val_none ? &ao_how : NULL);			\
 									\
 	libxl_device_##type##_dispose(&c_info);				\
 									\
Signature · 1 line
1.7.10.4
author
#25 lore raw

PATCH v2 24/30 libxl: ocaml: add NIC helper functions

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py       |    5 ++++-
 tools/ocaml/libs/xl/xenlight_stubs.c |   36 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)
tools/ocaml/libs/xl/genwrap.py +4 -1
index 57ec143..c99326b 100644
@@ -31,7 +31,10 @@ functions = { # ( name , [type1,type2,....] )
     "device_vfb":     DEVICE_FUNCTIONS,
     "device_vkb":     DEVICE_FUNCTIONS,
     "device_disk":    DEVICE_FUNCTIONS,
-    "device_nic":     DEVICE_FUNCTIONS,
+    "device_nic":     DEVICE_FUNCTIONS +
+                      [ ("list",           ["ctx", "domid", "t list"]),
+                        ("of_devid",       ["ctx", "domid", "int", "t"]),
+                      ],
     "device_pci":     DEVICE_FUNCTIONS,
     "dominfo":        [ ("list",           ["ctx", "t list"]),
                         ("get",            ["ctx", "domid", "t"]),
tools/ocaml/libs/xl/xenlight_stubs.c +36 -0
index 5ac8213..d833ba1 100644
@@ -457,6 +457,42 @@ DEVICE_ADDREMOVE(vfb)
 DEVICE_ADDREMOVE(vkb)
 DEVICE_ADDREMOVE(pci)
 
+value stub_xl_device_nic_of_devid(value ctx, value domid, value devid)
+{
+	CAMLparam3(ctx, domid, devid);
+	libxl_device_nic nic;
+	libxl_devid_to_device_nic(CTX, Int_val(domid), Int_val(devid), &nic);
+	CAMLreturn(Val_device_nic(&nic));
+}
+
+value stub_xl_device_nic_list(value ctx, value domid)
+{
+	CAMLparam2(ctx, domid);
+	CAMLlocal2(list, temp);
+	libxl_device_nic *c_list;
+	int i, nb;
+	uint32_t c_domid;
+
+	c_domid = Int_val(domid);
+
+	c_list = libxl_device_nic_list(CTX, c_domid, &nb);
+	if (!c_list)
+		failwith_xl(ERROR_FAIL, "nic_list");
+
+	list = temp = Val_emptylist;
+	for (i = 0; i < nb; i++) {
+		list = caml_alloc_small(2, Tag_cons);
+		Field(list, 0) = Val_int(0);
+		Field(list, 1) = temp;
+		temp = list;
+		Store_field(list, 0, Val_device_nic(&c_list[i]));
+		libxl_device_nic_dispose(&c_list[i]);
+	}
+	free(c_list);
+
+	CAMLreturn(list);
+}
+
 value stub_xl_physinfo_get(value ctx)
 {
 	CAMLparam1(ctx);
Signature · 1 line
1.7.10.4
author
#26 lore raw

PATCH v2 25/30 libxl: ocaml: add PCI device helper functions

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py       |    7 ++-
 tools/ocaml/libs/xl/xenlight_stubs.c |   90 ++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
tools/ocaml/libs/xl/genwrap.py +6 -1
index c99326b..489ae9d 100644
@@ -35,7 +35,12 @@ functions = { # ( name , [type1,type2,....] )
                       [ ("list",           ["ctx", "domid", "t list"]),
                         ("of_devid",       ["ctx", "domid", "int", "t"]),
                       ],
-    "device_pci":     DEVICE_FUNCTIONS,
+    "device_pci":     DEVICE_FUNCTIONS +
+                      [ ("list",              ["ctx", "domid", "t list"]),
+                        ("assignable_add",    ["ctx", "t", "bool", "unit"]),
+                        ("assignable_remove", ["ctx", "t", "bool", "unit"]),
+                        ("assignable_list",   ["ctx", "t list"]),
+                      ],
     "dominfo":        [ ("list",           ["ctx", "t list"]),
                         ("get",            ["ctx", "domid", "t"]),
                       ],
tools/ocaml/libs/xl/xenlight_stubs.c +90 -0

96 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#27 lore raw

PATCH v2 26/30 libxl: ocaml: add disk and cdrom helper functions

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py       |   17 +++++++-----
 tools/ocaml/libs/xl/xenlight_stubs.c |   47 ++++++++++++++++++++++++++++++----
 2 files changed, 52 insertions(+), 12 deletions(-)
tools/ocaml/libs/xl/genwrap.py +10 -7
index 489ae9d..92326e1 100644
@@ -26,18 +26,21 @@ DEVICE_FUNCTIONS = [ ("add",            ["ctx", "t", "domid", "?async:'a", "unit
                      ("remove",         ["ctx", "t", "domid", "?async:'a", "unit", "unit"]),
                      ("destroy",        ["ctx", "t", "domid", "?async:'a", "unit", "unit"]),
                    ]
+DEVICE_LIST =      [ ("list",           ["ctx", "domid", "t list"]),
+                   ]
 
 functions = { # ( name , [type1,type2,....] )
     "device_vfb":     DEVICE_FUNCTIONS,
     "device_vkb":     DEVICE_FUNCTIONS,
-    "device_disk":    DEVICE_FUNCTIONS,
-    "device_nic":     DEVICE_FUNCTIONS +
-                      [ ("list",           ["ctx", "domid", "t list"]),
-                        ("of_devid",       ["ctx", "domid", "int", "t"]),
+    "device_disk":    DEVICE_FUNCTIONS + DEVICE_LIST +
+                      [ ("insert",         ["ctx", "t", "domid", "?async:'a", "unit", "unit"]),
+                        ("of_vdev",        ["ctx", "domid", "string", "t"]),
+                      ],
+    "device_nic":     DEVICE_FUNCTIONS + DEVICE_LIST +
+                      [ ("of_devid",       ["ctx", "domid", "int", "t"]),
                       ],
-    "device_pci":     DEVICE_FUNCTIONS +
-                      [ ("list",              ["ctx", "domid", "t list"]),
-                        ("assignable_add",    ["ctx", "t", "bool", "unit"]),
+    "device_pci":     DEVICE_FUNCTIONS + DEVICE_LIST +
+                      [ ("assignable_add",    ["ctx", "t", "bool", "unit"]),
                         ("assignable_remove", ["ctx", "t", "bool", "unit"]),
                         ("assignable_list",   ["ctx", "t list"]),
                       ],
tools/ocaml/libs/xl/xenlight_stubs.c +42 -5

77 lines not on this page · raw message

Signature · 1 line
1.7.10.4
author
#28 lore raw

PATCH v2 27/30 libxl: ocaml: add VM lifecycle operations

In reply to Rob Hoes

Also, reorganise toplevel OCaml functions into modules of Xenlight.

---
 tools/ocaml/libs/xl/xenlight.ml.in   |   23 +++-
 tools/ocaml/libs/xl/xenlight.mli.in  |   23 +++-
 tools/ocaml/libs/xl/xenlight_stubs.c |  198 ++++++++++++++++++++++++++++++++++
 tools/ocaml/test/send_debug_keys.ml  |    2 +-
 4 files changed, 237 insertions(+), 9 deletions(-)
tools/ocaml/libs/xl/xenlight.ml.in +19 -4
index 06c9f52..4cfd085 100644
@@ -66,10 +66,25 @@ type event =
 
 (* @@LIBXL_TYPES@@ *)
 
-external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
-external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
-external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
-external xen_console_read : ctx -> string list = "stub_xl_xen_console_read"
+module Domain = struct
+	external create_new : ctx -> Domain_config.t -> ?async:'a -> unit -> domid = "stub_libxl_domain_create_new"
+	external create_restore : ctx -> Domain_config.t -> Unix.file_descr -> ?async:'a -> unit -> domid = "stub_libxl_domain_create_restore"
+	external shutdown : ctx -> domid -> unit = "stub_libxl_domain_shutdown"
+	external wait_shutdown : ctx -> domid -> unit = "stub_libxl_domain_wait_shutdown"
+	external reboot : ctx -> domid -> unit = "stub_libxl_domain_reboot"
+	external destroy : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_destroy"
+	external suspend : ctx -> domid -> Unix.file_descr -> ?async:'a -> unit -> unit = "stub_libxl_domain_suspend"
+	external pause : ctx -> domid -> unit = "stub_libxl_domain_pause"
+	external unpause : ctx -> domid -> unit = "stub_libxl_domain_unpause"
+
+	external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
+	external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
+end
+
+module Host = struct
+	external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
+	external xen_console_read : ctx -> string list = "stub_xl_xen_console_read"
+end
 
 module type EVENT_USERS =
 	sig
tools/ocaml/libs/xl/xenlight.mli.in +19 -4
index 0b06712..d49edde 100644
@@ -51,10 +51,25 @@ type event =
 
 (* @@LIBXL_TYPES@@ *)
 
-external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
-external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
-external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
-external xen_console_read : ctx -> string list = "stub_xl_xen_console_read"
+module Domain : sig
+	external create_new : ctx -> Domain_config.t -> ?async:'a -> unit -> domid = "stub_libxl_domain_create_new"
+	external create_restore : ctx -> Domain_config.t -> Unix.file_descr -> ?async:'a -> unit -> domid = "stub_libxl_domain_create_restore"
+	external shutdown : ctx -> domid -> unit = "stub_libxl_domain_shutdown"
+	external wait_shutdown : ctx -> domid -> unit = "stub_libxl_domain_wait_shutdown"
+	external reboot : ctx -> domid -> unit = "stub_libxl_domain_reboot"
+	external destroy : ctx -> domid -> ?async:'a -> unit -> unit = "stub_libxl_domain_destroy"
+	external suspend : ctx -> domid -> Unix.file_descr -> ?async:'a -> unit -> unit = "stub_libxl_domain_suspend"
+	external pause : ctx -> domid -> unit = "stub_libxl_domain_pause"
+	external unpause : ctx -> domid -> unit = "stub_libxl_domain_unpause"
+
+	external send_trigger : ctx -> domid -> trigger -> int -> unit = "stub_xl_send_trigger"
+	external send_sysrq : ctx -> domid -> char -> unit = "stub_xl_send_sysrq"
+end
+
+module Host : sig
+	external send_debug_keys : ctx -> string -> unit = "stub_xl_send_debug_keys"
+	external xen_console_read : ctx -> string list = "stub_xl_xen_console_read"
+end
 
 module type EVENT_USERS =
 	sig
tools/ocaml/libs/xl/xenlight_stubs.c +198 -0

204 lines not on this page · raw message

tools/ocaml/test/send_debug_keys.ml +1 -1
index 6db89e8..6cf59ea 100644
@@ -5,7 +5,7 @@ open Xenlight
 
 let send_keys ctx s = 
   printf "Sending debug key %s\n" s;
-  Xenlight.send_debug_keys ctx s;
+  Xenlight.Host.send_debug_keys ctx s;
   ()
   
 let _ = 
Signature · 1 line
1.7.10.4
author
#29 lore raw

PATCH v2 28/30 libxl: ocaml: in send_debug_keys, clean up before raising exception

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/xenlight_stubs.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/ocaml/libs/xl/xenlight_stubs.c +2 -2
index aab3b21..084961a 100644
@@ -981,11 +981,11 @@ value stub_xl_send_debug_keys(value ctx, value keys)
 	c_keys = dup_String_val(keys);
 
 	ret = libxl_send_debug_keys(CTX, c_keys);
+	free(c_keys);
+
 	if (ret != 0)
 		failwith_xl(ret, "send_debug_keys");
 
-	free(c_keys);
-
 	CAMLreturn(Val_unit);
 }
 
Signature · 1 line
1.7.10.4
author
#30 lore raw

PATCH v2 29/30 libxl: ocaml: provide defaults for libxl types

In reply to Rob Hoes

Libxl functions such as libxl_domain_create_new take large structs of configuration parameters. Often, we would like to use the default values for many of these parameters.

The struct and keyed-union types in libxl have init functions, which fill in the defaults for a given type. This commit provides an OCaml interface to obtain records of defaults by calling the relevant init function.

These default records can be used as a base to construct your own records, and to selectively override parameters where needed.

For example, a Domain_create_info record can now be created as follows:

  Xenlight.Domain_create_info.({ default ctx () with
    ty = Xenlight.DOMAIN_TYPE_PV;
    name = Some vm_name;
    uuid = vm_uuid;
  })

For types with KeyedUnion fields, such as Domain_build_info, a record with defaults is obtained by specifying the type key:

Xenlight.Domain_build_info.default ctx ~ty:Xenlight.DOMAIN_TYPE_HVM ()

---
 tools/ocaml/libs/xl/genwrap.py |   61 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 54 insertions(+), 7 deletions(-)
tools/ocaml/libs/xl/genwrap.py +54 -7
index 92326e1..7738b96 100644
@@ -115,6 +115,7 @@ def gen_struct(ty):
 
 def gen_ocaml_keyedunions(ty, interface, indent, parent = None):
     s = ""
+    union_type = ""
     
     if ty.rawname is not None:
         # Non-anonymous types need no special handling
@@ -154,9 +155,11 @@ def gen_ocaml_keyedunions(ty, interface, indent, parent = None):
         s += " | ".join(u) + "\n"
         ty.union_name = name
 
+        union_type = "?%s:%s" % (munge_name(nparent), ty.keyvar.type.rawname)
+
     if s == "":
-        return None
-    return s.replace("\n", "\n%s" % indent)
+        return None, None
+    return s.replace("\n", "\n%s" % indent), union_type
 
 def gen_ocaml_ml(ty, interface, indent=""):
 
@@ -184,17 +187,27 @@ def gen_ocaml_ml(ty, interface, indent=""):
                 s += "module %s = struct\n" % module_name
                 
         # Handle KeyedUnions...
+        union_types = []
         for f in ty.fields:
-            ku = gen_ocaml_keyedunions(f.type, interface, "\t")
+            ku, union_type = gen_ocaml_keyedunions(f.type, interface, "\t")
             if ku is not None:
                 s += ku
                 s += "\n"
+            if union_type is not None:
+                union_types.append(union_type)
 
         s += "\ttype t =\n"
         s += "\t{\n"
         s += gen_struct(ty)
         s += "\t}\n"
-        
+
+        if ty.init_fn is not None:
+            union_args = "".join([u + " -> " for u in union_types])
+            if interface:
+                s += "\tval default : ctx -> %sunit -> t\n" % union_args
+            else:
+                s += "\texternal default : ctx -> %sunit -> t = \"stub_libxl_%s_init\"\n" % (union_args, ty.rawname)
+
         if functions.has_key(ty.rawname):
             for name,args in functions[ty.rawname]:
                 s += "\texternal %s : " % name
@@ -422,6 +435,38 @@ def gen_c_stub_prototype(ty, fns):
         s += ");\n"
     return s
 
+def gen_c_default(ty):
+    s = "/* Get the defaults for %s */\n" % ty.rawname
+    # Handle KeyedUnions...
+    union_types = []
+    for f in ty.fields:
+        if isinstance(f.type, idl.KeyedUnion):
+            union_types.append(f.type.keyvar)
+
+    s += "value stub_libxl_%s_init(value ctx, %svalue unit)\n" % (ty.rawname,
+        "".join(["value " + u.name + ", " for u in union_types]))
+    s += "{\n"
+    s += "\tCAMLparam%d(ctx, %sunit);\n" % (len(union_types) + 2, "".join([u.name + ", " for u in union_types]))
+    s += "\tCAMLlocal1(val);\n"
+    s += "\tlibxl_%s c_val;\n" % ty.rawname
+    s += "\tlibxl_%s_init(&c_val);\n" % ty.rawname
+    for u in union_types:
+        s += "\tif (%s != Val_none) {\n" % u.name
+        s += "\t\t%s c = 0;\n" % u.type.typename
+        s += "\t\t%s_val(CTX, &c, Some_val(%s));\n" % (u.type.rawname, u.name)
+        s += "\t\tlibxl_%s_init_%s(&c_val, c);\n" % (ty.rawname, u.name)
+        s += "\t}\n"
+    s += "\tval = Val_%s(&c_val);\n" % ty.rawname
+    if ty.dispose_fn:
+        s += "\tlibxl_%s_dispose(&c_val);\n" % ty.rawname
+    s += "\tCAMLreturn(val);\n"
+    s += "}\n"
+    return s
+
+def gen_c_defaults(ty):
+    s = gen_c_default(ty)
+    return s
+
 def autogen_header(open_comment, close_comment):
     s = open_comment + " AUTO-GENERATED FILE DO NOT EDIT " + close_comment + "\n"
     s += open_comment + " autogenerated by \n"
@@ -474,12 +519,14 @@ if __name__ == '__main__':
         if ty.marshal_in():
             cinc.write(gen_c_val(ty))
             cinc.write("\n")
-        if ty.marshal_out():
-            cinc.write(gen_Val_ocaml(ty))
-            cinc.write("\n")
+        cinc.write(gen_Val_ocaml(ty))
+        cinc.write("\n")
         if functions.has_key(ty.rawname):
             cinc.write(gen_c_stub_prototype(ty, functions[ty.rawname]))
             cinc.write("\n")
+        if ty.init_fn is not None:
+            cinc.write(gen_c_defaults(ty))
+            cinc.write("\n")
         #sys.stdout.write("\n")
     
     ml.write("(* END OF AUTO-GENERATED CODE *)\n")
Signature · 1 line
1.7.10.4
author
#31 lore raw

PATCH v2 30/30 libxl: ocaml: use CAMLlocal1 macro rather than value-type in auto-generated C-code

In reply to Rob Hoes
---
 tools/ocaml/libs/xl/genwrap.py |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/ocaml/libs/xl/genwrap.py +2 -2
index 7738b96..e074f5e 100644
@@ -341,7 +341,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
     elif isinstance(ty, idl.Array):
         s += "{\n"
         s += "\t    int i;\n"
-        s += "\t    value array_elem;\n"
+        s += "\t    CAMLlocal1(array_elem);\n"
         s += "\t    %s = caml_alloc(%s,0);\n" % (o, parent + ty.lenvar.name)
         s += "\t    for(i=0; i<%s; i++) {\n" % (parent + ty.lenvar.name)
         s += "\t        %s\n" % ocaml_Val(ty.elem_type, "array_elem", c + "[i]", "", parent=parent)
@@ -391,7 +391,7 @@ def ocaml_Val(ty, o, c, indent="", parent = None):
             fn = "anon_field"
         else:
             fn = "%s_field" % ty.rawname
-        s += "\tvalue %s;\n" % fn
+        s += "\tCAMLlocal1(%s);\n" % fn
         s += "\n"
         s += "\t%s = caml_alloc_tuple(%d);\n" % (o, len(ty.fields))
         
Signature · 1 line
1.7.10.4
author
#32 lore raw
In reply to Rob Hoes

Hi,

I'd like to ask for the patches to the libxl OCaml bindings, which I submitted a while ago, to be considered for Xen 4.4.

I have rebased the series onto the current master branch, and there were no conflicts. The rebased version can be pulled using "git pull https://github.com/robhoes/xen.git hydrogen-upstream-v2-rebased".

Thanks,
Rob

Quoted 50 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Rob Hoes
Sent: 13 June 2013 4:25 PM
To: [email protected]
Subject: [Xen-devel] libxl: ocaml: improve the bindings

This is version 2 of this patch series to fix the OCaml binding to libxl.

I believe I have addressed all the points raised by Dave Scott and Ian Campbell. Sorry for the delay in getting this new series out!

The main changes are:
* Several fixes to ensure the bindings play well with the OCaml GC. This includes properly using macros such as CAMLparam* and CAMLreturn* for _all_ OCaml values (even intermediate ones), and using "custom" blocks to encapsulate pointers to C code (including handy "finalize" functions for cleanup.
* Fixes in the way KeyedUnions are handled.
* Use the libxl init function to generate default records for libxl types.
* Improve the functions that deal with event handling. We now have some higher-level functions to makes this easier as well as safer, and errors are translated properly.

---------

The following series of patches fill in most of the gaps in the OCaml bindings to libxl, to make them useful for clients such as xapi/xenopsd (from XCP).
There are a number of bugfixes to the existing bindings as well. I have an experimental version of xenopsd that successfully uses the new bindings.

An earlier version of the first half of the series was submitted to the last by Ian Campbell on 20 Nov 2012. With his permission, I have updated most of them to fix some issues (which were discussed on the mailing list at the time). I have left Ian's signed-off-by line on those patches (please let me know if that is not appropriate).

For convenience, the patches in this series may be pulled using:

git pull git://github.com/robhoes/xen.git hydrogen-upstream-v2

Cheers,
Rob

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#33 lore raw
Quoted 8 lines · Rob Hoes

Hi,

I'd like to ask for the patches to the libxl OCaml bindings, which I submitted a while ago, to be considered for Xen 4.4.

I have rebased the series onto the current master branch, and there were no conflicts. The rebased version can be pulled using "git pull
https://github.com/robhoes/xen.git hydrogen-upstream-v2-rebased".

Please can you also repost as patches here.

Ian.