Skip to contentSkip to conversation

make devid a libxl type

PATCH Matthew Fioravante 2 participants 5 messages Sep 21, 2012 – Sep 25, 2012 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

This fixes a bug in libxl where device ids are not initialized properly. The devid field for each device is set to be an integer type which are always initialized to 0.

This makes the xl DEV-attach commands always fail to add more than one device, because each time the device id is initialized to 0, when it should be initialized to -1, which in the code will trigger a search for free id.

Signed off by Matthew Fioravante [email protected]

---
* Rebased off of latest xen-unstable
* Fixed whitespace errors

tools/libxl/gentest.py +1 -1
@@ -60,7 +60,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
@@ -307,6 +307,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_bitmap = Builtin("bitmap", dispose_fn="libxl_bitmap_dispose",
passby=PASS_BY_REFERENCE)
@@ -343,7 +344,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
@@ -352,7 +353,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", [
@@ -369,7 +370,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),
@@ -399,7 +400,7 @@ libxl_diskinfo = Struct("diskinfo", [
     ("backend_id", uint32),
     ("frontend", string),
     ("frontend_id", uint32),
-    ("devid", integer),
+    ("devid", libxl_devid),
     ("state", integer),
     ("evtch", integer),
     ("rref", integer),
@@ -410,7 +411,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");

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

#1 lore raw
Quoted 8 lines · Matthew Fioravante

This fixes a bug in libxl where device ids are not initialized properly. The devid field for each device is set to be an integer type which are always initialized to 0.

This makes the xl DEV-attach commands always fail to add more than one device, because each time the device id is initialized to 0, when it should be initialized to -1, which in the code will trigger a search for free id.

Which of the DEV-attach commands can be used to add more than one device?

Where is the code to do the search? I had a look in the disk and network cases and couldn't find it.

tools/ocaml/libs/xs/xs.mli exception Failed_to_connect · line 30

Quoted 8 lines
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

I can see why these were needed in the xl modules, but I don't see how this type can be required in the xenstore ones.

Ian.

#2 lore raw
Quoted 11 lines · Ian Campbell
Quoted 8 lines · Matthew Fioravante

This fixes a bug in libxl where device ids are not initialized properly. The devid field for each device is set to be an integer type which are always initialized to 0.

This makes the xl DEV-attach commands always fail to add more than one device, because each time the device id is initialized to 0, when it should be initialized to -1, which in the code will trigger a search for free id.

Which of the DEV-attach commands can be used to add more than one device?

network-attach, block-attach, and also my vtpm-attach.

Quoted 3 lines

Where is the code to do the search? I had a look in the disk and network cases and couldn't find it.

libxl.c

void libxl__device_nic_add(

    if (nic->devid == -1) {
        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
            rc = ERROR_FAIL;
            goto out_free;
        }
        if (!(l = libxl__xs_directory(gc, XBT_NULL,
                                     libxl__sprintf(gc, "%s/device/vif",
dompath), &nb))) {
            nic->devid = 0;
        } else {
            nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
        }
    }

Right now, nic-devid is 0 on attach. So it always tries to use 0. When you do a network-attach twice,
the second time it trys and fails to create device/vif/0

Quoted 11 lines

tools/ocaml/libs/xs/xs.mli exception Failed_to_connect · line 30

Quoted 9 lines
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

I can see why these were needed in the xl modules, but I don't see how this type can be required in the xenstore ones.

It shouldn't be required for xenstore or xc. The problem is they won't compile without it because of the way the ocaml build system works. As far as I understand it creates types for xl, xc, and xs from the libxl_types.idl. Either the build system needs to be changed, or devid needs to be a type in all libraries, or we find some other way to fix this initialization bug.

Quoted 3 lines

Ian.

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

#3 lore raw
Quoted 6 lines · Matthew Fioravante
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Matthew Fioravante

This fixes a bug in libxl where device ids are not initialized properly. The devid field for each device is set to be an integer type which are always initialized to 0.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

This makes the xl DEV-attach commands always fail to add more than one device, because each time the device id is initialized to 0, when it should be initialized to -1, which in the code will trigger a search for free id.

Which of the DEV-attach commands can be used to add more than one device?

network-attach, block-attach, and also my vtpm-attach.

Oh, you mean by being called repeatedly, not adding multiple devices in one go!

Quoted 6 lines
Quoted 2 lines

Where is the code to do the search? I had a look in the disk and network cases and couldn't find it.

libxl.c

void libxl__device_nic_add(

Quoted 13 lines
    if (nic->devid == -1) {
        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
            rc = ERROR_FAIL;
            goto out_free;
        }
        if (!(l = libxl__xs_directory(gc, XBT_NULL,
                                     libxl__sprintf(gc, "%s/device/vif",
dompath), &nb))) {
            nic->devid = 0;
        } else {
            nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
        }
    }

Not sure how I missed this.

Quoted 1 line

Right now, nic-devid is 0 on attach.

Is devid not a parameter to network-attach? It is to block-attach.

Quoted 2 lines

So it always tries to use 0. When you do a network-attach twice, the second time it trys and fails to create device/vif/0

Your change to use -1 as thye default is certainly correct. I'm just trying to figure out why xl does things this way in the first place.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/ocaml/libs/xs/xs.mli +0 -0
@@ -27,6 +27,7 @@ exception Failed_to_connect
 type perms = Xsraw.perms
 
Quoted 8 lines
Quoted 4 lines

tools/ocaml/libs/xs/xs.mli exception Failed_to_connect · line 30

Quoted 2 lines
tools/ocaml/libs/xs/xs.mli +1 -0
 type domid = int
+type devid = int

I can see why these were needed in the xl modules, but I don't see how this type can be required in the xenstore ones.

It shouldn't be required for xenstore or xc. The problem is they won't compile without it because of the way the ocaml build system works. As far as I understand it creates types for xl, xc, and xs from the libxl_types.idl.

No, only xl does this.

The others are the libxc and xenstore bindings which are completely hand coded and there is no concept of a devid at those layers anyway. What error do you get if you omit the changes to those module?

Quoted 8 lines

Either the build system needs to be changed, or devid
needs to be a type in all libraries, or we find some other way to fix this initialization bug.

Quoted 3 lines

Ian.

#4 lore raw
Quoted 36 lines · Ian Campbell
Quoted 6 lines · Matthew Fioravante
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Matthew Fioravante

This fixes a bug in libxl where device ids are not initialized properly. The devid field for each device is set to be an integer type which are always initialized to 0.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

This makes the xl DEV-attach commands always fail to add more than one device, because each time the device id is initialized to 0, when it should be initialized to -1, which in the code will trigger a search for free id.

Which of the DEV-attach commands can be used to add more than one device?

network-attach, block-attach, and also my vtpm-attach.

Oh, you mean by being called repeatedly, not adding multiple devices in one go!

Quoted 6 lines
Quoted 2 lines

Where is the code to do the search? I had a look in the disk and network cases and couldn't find it.

libxl.c

void libxl__device_nic_add(

Quoted 13 lines
    if (nic->devid == -1) {
        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
            rc = ERROR_FAIL;
            goto out_free;
        }
        if (!(l = libxl__xs_directory(gc, XBT_NULL,
                                     libxl__sprintf(gc, "%s/device/vif",
dompath), &nb))) {
            nic->devid = 0;
        } else {
            nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
        }
    }
Quoted 4 lines

Not sure how I missed this.

Quoted 1 line

Right now, nic-devid is 0 on attach.

Is devid not a parameter to network-attach? It is to block-attach.

It might be, but if its not specified I think the logical thing to do is to automatically choose the next available id.

Quoted 20 lines
Quoted 3 lines

So it always tries to use 0. When you do a network-attach twice, the second time it trys and fails to create device/vif/0

Your change to use -1 as thye default is certainly correct. I'm just trying to figure out why xl does things this way in the first place.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
tools/ocaml/libs/xs/xs.mli +0 -0
@@ -27,6 +27,7 @@ exception Failed_to_connect
 type perms = Xsraw.perms
 
Quoted 8 lines
Quoted 4 lines

tools/ocaml/libs/xs/xs.mli exception Failed_to_connect · line 30

Quoted 2 lines
tools/ocaml/libs/xs/xs.mli +1 -0
 type domid = int
+type devid = int

I can see why these were needed in the xl modules, but I don't see how this type can be required in the xenstore ones.

It shouldn't be required for xenstore or xc. The problem is they won't compile without it because of the way the ocaml build system works. As far as I understand it creates types for xl, xc, and xs from the libxl_types.idl.

Quoted 5 lines

No, only xl does this.

The others are the libxc and xenstore bindings which are completely hand coded and there is no concept of a devid at those layers anyway. What error do you get if you omit the changes to those module?

Ok I must be crazy. I went back and removed them and tried to compile it again and it works fine. I think I was forgetting to update both the .mli and the .ml files. Anyway a new patch with the xc/xs removed is attached.

Quoted 8 lines
Quoted 7 lines

Either the build system needs to be changed, or devid
needs to be a type in all libraries, or we find some other way to fix this initialization bug.

Quoted 2 lines

Ian.

Signed off by Matthew Fioravante [email protected]

---
* Rebased off of latest xen-unstable
* Fixed whitespace errors
* Removed devid from libxc and libxs

tools/libxl/gentest.py +1 -1
@@ -60,7 +60,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 +1 -0
@@ -307,6 +307,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 +6 -5
@@ -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_bitmap = Builtin("bitmap", dispose_fn="libxl_bitmap_dispose", passby=PASS_BY_REFERENCE)
@@ -343,7 +344,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
@@ -352,7 +353,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", [
@@ -369,7 +370,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),
@@ -399,7 +400,7 @@ libxl_diskinfo = Struct("diskinfo", [
     ("backend_id", uint32),
     ("frontend", string),
     ("frontend_id", uint32),
-    ("devid", integer),
+    ("devid", libxl_devid),
     ("state", integer),
     ("evtch", integer),
     ("rref", integer),
@@ -410,7 +411,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/xl/genwrap.py +3 -2
@@ -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
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@@ *)
 
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/python/xen/lowlevel/xl/xl.c +9 -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