xl make devid a libxl type
PATCH 1/6 xl make devid a libxl type
Previously device ids in libxl were treated as integers meaning they were being initialized to 0, which is a valid device id. This patch makes devid its own type in libxl and initializes it to -1, an invalid value.
Signed off by Matthew Fioravante [email protected]
tools/libxl/gentest.py +1 -1
@@ -48,7 +48,7 @@ def gen_rand_init(ty, v, indent = " ", parent = None): passby=idl.PASS_BY_REFERENCE)) elif ty.typename in ["libxl_uuid", "libxl_mac", "libxl_hwcap"]: s += "rand_bytes((uint8_t *)%s, sizeof(*%s));\n" % (v,v) - elif ty.typename in ["libxl_domid"] or isinstance(ty, idl.Number): + elif ty.typename in ["libxl_domid", "libxl_devid"] or
isinstance(ty, idl.Number):
s += "%s = rand() %% (sizeof(%s)*8);\n" % \
(ty.pass_arg(v, parent is None),
ty.pass_arg(v, parent is None))
tools/libxl/libxl.h +0 -0
@@ -299,6 +299,7 @@ void libxl_cpuid_dispose(libxl_cpuid_policy_list
*cpuid_list);
#define LIBXL_PCI_FUNC_ALL (~0U)
typedef uint32_t libxl_domid;
+typedef int libxl_devid;
/*
* Formatting Enumerations.
tools/libxl/libxl_types.idl +0 -0
@@ -8,6 +8,7 @@ namespace("libxl_") libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) libxl_domid = Builtin("domid", json_fn = "yajl_gen_integer",
autogenerate_json = False)
+libxl_devid = Builtin("devid", json_fn = "yajl_gen_integer", autogenerate_json = False, signed = True, init_val="-1")
libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE) libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE) libxl_cpumap = Builtin("cpumap", dispose_fn="libxl_cpumap_dispose",
passby=PASS_BY_REFERENCE)
@@ -318,7 +319,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
libxl_device_vfb = Struct("device_vfb", [
("backend_domid", libxl_domid),
- ("devid", integer),
+ ("devid", libxl_devid),
("vnc", libxl_vnc_info),
("sdl", libxl_sdl_info),
# set keyboard layout, default is en-us keyboard
@@ -327,7 +328,7 @@ libxl_device_vfb = Struct("device_vfb", [ libxl_device_vkb = Struct("device_vkb", [
("backend_domid", libxl_domid),
- ("devid", integer),
+ ("devid", libxl_devid),
]) libxl_device_disk = Struct("device_disk", [
@@ -344,7 +345,7 @@ libxl_device_disk = Struct("device_disk", [
libxl_device_nic = Struct("device_nic", [
("backend_domid", libxl_domid),
- ("devid", integer),
+ ("devid", libxl_devid),
("mtu", integer),
("model", string),
("mac", libxl_mac),
@@ -374,7 +375,7 @@ libxl_diskinfo = Struct("diskinfo", [
("backend_id", uint32),
("frontend", string),
("frontend_id", uint32),
- ("devid", integer),
+ ("devid", libxl_devid),
("state", integer),
("evtch", integer),
("rref", integer),
@@ -385,7 +386,7 @@ libxl_nicinfo = Struct("nicinfo", [
("backend_id", uint32),
("frontend", string),
("frontend_id", uint32),
- ("devid", integer),
+ ("devid", libxl_devid),
("state", integer),
("evtch", integer),
("rref_tx", integer),tools/ocaml/libs/xc/xenctrl.ml +1 -0
@@ -16,6 +16,7 @@ (** *) type domid = int +type devid = int (* ** xenctrl.h ** *)
(quoted diff) +0 -0
b/tools/ocaml/libs/xc/xenctrl.mli
tools/ocaml/libs/xc/xenctrl.mli +1 -0
@@ -15,6 +15,7 @@ *) type domid = int +type devid = int type vcpuinfo = { online : bool; blocked : bool;
tools/ocaml/libs/xl/genwrap.py +0 -0
@@ -10,6 +10,7 @@ builtins = { "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)"),
"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_key_value_list": ("(string * string) list",
None, None),
@@ -41,8 +42,8 @@ def stub_fn_name(ty, name):
return "stub_xl_%s_%s" % (ty.rawname,name) def ocaml_type_of(ty):
- if ty.rawname == "domid":
- return "domid"
+ if ty.rawname in ["domid","devid"]:
+ return ty.rawname
elif isinstance(ty,idl.UInt):
if ty.width in [8, 16]:
# handle as ints
(quoted diff) +0 -0
b/tools/ocaml/libs/xl/xenlight.ml.in
tools/ocaml/libs/xl/xenlight.ml.in +1 -0
@@ -16,6 +16,7 @@ exception Error of string type domid = int +type devid = int (* @@LIBXL_TYPES@@ *)
(quoted diff) +0 -0
b/tools/ocaml/libs/xl/xenlight.mli.in
tools/ocaml/libs/xl/xenlight.mli.in +1 -0
@@ -16,6 +16,7 @@ exception Error of string type domid = int +type devid = int (* @@LIBXL_TYPES@@ *)
tools/ocaml/libs/xs/xs.ml +1 -0
@@ -17,6 +17,7 @@ type perms = Xsraw.perms type con = Xsraw.con type domid = int +type devid = int type xsh = {
tools/ocaml/libs/xs/xs.mli +1 -0
@@ -27,6 +27,7 @@ exception Failed_to_connect type perms = Xsraw.perms type domid = int +type devid = int type con type xsh = {
(quoted diff) +0 -0
b/tools/python/xen/lowlevel/xl/xl.c
tools/python/xen/lowlevel/xl/xl.c +0 -0
@@ -281,6 +281,11 @@ int attrib__libxl_domid_set(PyObject *v,
libxl_domid *domid) {
return 0;}
+int attrib__libxl_devid_set(PyObject *v, libxl_devid *devid) {
+ *devid = PyInt_AsLong(v);
+ return 0;
+}
+
int attrib__struct_in_addr_set(PyObject *v, struct in_addr *pptr)
{
PyErr_SetString(PyExc_NotImplementedError, "Setting in_addr");
@@ -342,6 +347,10 @@ PyObject *attrib__libxl_domid_get(libxl_domid *domid) {
return PyInt_FromLong(*domid);}
+PyObject *attrib__libxl_devid_get(libxl_devid *devid) {
+ return PyInt_FromLong(*devid);
+}
+
PyObject *attrib__struct_in_addr_get(struct in_addr *pptr)
{
PyErr_SetString(PyExc_NotImplementedError, "Getting in_addr");Signature · 1 line
1.7.4.4
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
tools/ocaml/libs/xc/xenctrl.ml line 19
Quoted 8 lines · Matthew Fioravante
tools/ocaml/libs/xc/xenctrl.ml +1
-0@@ -16,6 +16,7 @@ (** *) type domid = int +type devid = int
I don't think libxc exposes the notion of a devid, does it?
In which case there's no need to have a type for it here or in the .mli.
tools/ocaml/libs/xs/xs.ml line 20
Quoted 8 lines
tools/ocaml/libs/xs/xs.ml +1
-0@@ -17,6 +17,7 @@ type perms = Xsraw.perms type con = Xsraw.con type domid = int +type devid = int
Likewise xenstore doesn't have a devid either AFAIK.
tools/python/xen/lowlevel/xl/xl.c
Quoted 4 lines
tools/python/xen/lowlevel/xl/xl.c +0
-0
Are you basing your patches on xen-unstable? I ask because this file isn't built there and so I wonder how you noticed it to change it.
Ian.
Quoted 6 lines · Ian Campbell
Quoted 5 lines · Matthew Fioravante
tools/ocaml/libs/xc/xenctrl.ml +0
-0@@ -16,6 +16,7 @@
Quoted 6 lines
tools/ocaml/libs/xc/xenctrl.ml line 19
Quoted 3 lines
tools/ocaml/libs/xc/xenctrl.ml +1
-0(** *) type domid = int +type devid = intI don't think libxc exposes the notion of a devid, does it?
In which case there's no need to have a type for it here or in the .mli.
Unfortunately it looks like the ocaml makefiles build their list of types by using the libxl_types.idl system. Ocaml xs currently won't compile without this.
Quoted 9 lines
tools/ocaml/libs/xs/xs.ml line 20
Quoted 8 lines
tools/ocaml/libs/xs/xs.ml +1
-0@@ -17,6 +17,7 @@ type perms = Xsraw.perms type con = Xsraw.con type domid = int +type devid = intLikewise xenstore doesn't have a devid either AFAIK.
Same as above
Quoted 6 lines
tools/python/xen/lowlevel/xl/xl.c
Quoted 4 lines
tools/python/xen/lowlevel/xl/xl.c +0
-0Are you basing your patches on xen-unstable? I ask because this file isn't built there and so I wonder how you noticed it to change it.
I based it off of the xen-unstable tree on git, which I now realize is the wrong tree.
Quoted 2 lines
Ian.
The whole purpose of this patch is initialize device ids to -1 instead of zero and the only way I could come up to do that cleanly within libxl's type system was to create a new type. Is there another better way to fix this problem? As long as device ids are initialized to zero, all the xl DEVICE-attach commands will fail for attaching more than 1 device.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 3 lines · Matthew Fioravante
The whole purpose of this patch is initialize device ids to -1 instead of zero and the only way I could come up to do that cleanly within libxl's type system was to create a new type.
I think that's the right thing to do.
Ian.