On Tue, 2010-08-03 at 13:29 +0100, Ian Campbell wrote:
>
> > I like the idea of the patch, I think the libxl bits should be in a
> > separate python module though or perhaps the gentypes.py.
>
> I agree, and said as much in my intro mail ;-)
FWIW this is roughly what the patch to do this would look like (appends
to the series, should really be folded back)
Ian.
libxl: separate type definitions into a separate file.
Keeps the type definitions separate from the scaffolding.
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
diff -r ba6f06badc87 -r 669a2933c9ab tools/libxl/Makefile
--- a/tools/libxl/Makefile Tue Aug 03 13:22:30 2010 +0100
+++ b/tools/libxl/Makefile Tue Aug 03 14:27:57 2010 +0100
@@ -55,8 +55,8 @@ libxl_paths.c: _libxl_paths.h
libxl.h: _libxl_types.h
-_libxl_types.h _libxl_types.c: gentypes.py libxltypes.py
- python gentypes.py __libxl_types.h __libxl_types.c
+_libxl_types.h _libxl_types.c: libxltypes.idl gentypes.py libxltypes.py
+ python gentypes.py libxltypes.idl __libxl_types.h __libxl_types.c
mv __libxl_types.h _libxl_types.h
mv __libxl_types.c _libxl_types.c
diff -r ba6f06badc87 -r 669a2933c9ab tools/libxl/gentypes.py
--- a/tools/libxl/gentypes.py Tue Aug 03 13:22:30 2010 +0100
+++ b/tools/libxl/gentypes.py Tue Aug 03 14:27:57 2010 +0100
@@ -92,11 +92,14 @@ def libxl_C_type_destroy(ty, v, indent =
return s.replace("\n", "\n%s" % indent)
if __name__ == '__main__':
- if len(sys.argv) < 3:
- print >>sys.stderr, "Usage: gentypes.py <header> <implementation>"
+ if len(sys.argv) < 4:
+ print >>sys.stderr, "Usage: gentypes.py <idl> <header>
<implementation>"
sys.exit(1)
- header = sys.argv[1]
+ idl = sys.argv[1]
+ (_,types) = libxltypes.parse(idl)
+
+ header = sys.argv[2]
print "outputting libxl type definitions to %s" % header
f = open(header, "w")
@@ -104,7 +107,8 @@ if __name__ == '__main__':
f.write("""#ifndef __LIBXL_TYPES_H
#define __LIBXL_TYPES_H
-/* DO NOT EDIT.
+/*
+ * DO NOT EDIT.
*
* This file is autogenerated by
* "%s"
@@ -112,7 +116,7 @@ if __name__ == '__main__':
""" % " ".join(sys.argv))
- for ty in libxltypes.Types:
+ for ty in types:
f.write(libxl_C_type_define(ty) + ";\n")
if ty.has_destructor:
f.write("void %s(%s *p);\n" % (ty.destructor, ty.typename))
@@ -121,7 +125,7 @@ if __name__ == '__main__':
f.write("""#endif /* __LIBXL_TYPES_H */\n""")
f.close()
- impl = sys.argv[2]
+ impl = sys.argv[3]
print "outputting libxl type implementations to %s" % impl
f = open(impl, "w")
@@ -146,7 +150,7 @@ static void __string_string_free(char **
""" % " ".join(sys.argv))
- for ty in [ty for ty in libxltypes.Types if ty.generated_destructor]:
+ for ty in [ty for ty in types if ty.generated_destructor]:
f.write("void %s(%s *p)\n" % (ty.destructor, ty.typename))
f.write("{\n")
f.write(libxl_C_type_destroy(ty, "p->"))
diff -r ba6f06badc87 -r 669a2933c9ab tools/libxl/libxltypes.idl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/libxl/libxltypes.idl Tue Aug 03 14:27:57 2010 +0100
@@ -0,0 +1,250 @@
+# -*- mode: python; -*-
+
+#
+# Builtin libxl types
+#
+
+libxl_ctx = Builtin("ctx")
+libxl_uuid = Builtin("uuid")
+libxl_mac = Builtin("mac")
+libxl_qemu_machine_type = Builtin("qemu_machine_type")
+libxl_console_constype = Builtin("console_constype")
+libxl_disk_phystype = Builtin("disk_phystype")
+libxl_nic_type = Builtin("nic_type")
+
+#
+# Complex libxl types
+#
+libxl_dominfo = Struct("dominfo",[
+ ("uuid", libxl_uuid),
+ ("domid", domid),
+ ("running", BitField(uint8, 1)),
+ ("blocked", BitField(uint8, 1)),
+ ("paused", BitField(uint8, 1)),
+ ("shutdown", BitField(uint8, 1)),
+ ("dying", BitField(uint8, 1)),
+
+ ("shutdown_reason", unsigned, False,
+"""Valid SHUTDOWN_* value from xen/sched.h iff (shutdown||dying).
+
+Otherwise set to a value guaranteed not to clash with any valid
+SHUTDOWN_* constant."""),
+ ("max_memkb", uint64),
+ ("cpu_time", uint64),
+ ("vcpu_max_id", uint32),
+ ("vcpu_online", uint32),
+ ])
+
+libxl_poolinfo = Struct("poolinfo", [
+ ("poolid", uint32)
+ ])
+
+libxl_vminfo = Struct("vminfo", [
+ ("uuid", libxl_uuid),
+ ("domid", domid),
+ ])
+
+libxl_version_info = Struct("version_info", [
+ ("xen_version_major", integer),
+ ("xen_version_minor", integer),
+ ("xen_version_extra", string),
+ ("compiler", string),
+ ("compile_by", string),
+ ("compile_domain", string),
+ ("compile_date", string),
+ ("capabilities", string),
+ ("changeset", string),
+ ("virt_start", unsigned_long),
+ ("pagesize", unsigned_long),
+ ("commandline", string),
+ ])
+
+libxl_file_reference = Struct("file_reference",[
+ ("path", string, False,
+"""Path is always set if the file refernece is valid. However if
+mapped is true then the actual file may already be unlinked."""),
+ ("mapped", integer),
+ ("data", void),
+ ("size", size_t)])
+
+libxl_domain_create_info = Struct("domain_create_info",[
+ ("hvm", bool),
+ ("hap", bool),
+ ("oos", bool),
+ ("ssidref", integer),
+ ("name", string),
+ ("uuid", libxl_uuid),
+ ("xsdata", KeyValueList(string, string)),
+ ("platformdata", KeyValueList(string, string)),
+ ("poolid", uint32),
+ ("poolname", string, True),
+ ])
+
+libxl_domain_build_info = Struct("domain_build_info",[
+ ("max_vcpus", integer),
+ ("cur_vcpus", integer),
+ ("tsc_mode", integer),
+ ("max_memkb", uint32),
+ ("target_memkb", uint32),
+ ("video_memkb", uint32),
+ ("shadow_memkb", uint32),
+ ("disable_migrate", bool),
+ ("kernel", libxl_file_reference),
+ ("hvm", integer),
+ ("u", KeyedUnion(None, "hvm",
+ [("hvm", "%s", Struct(None,
+ [("pae", bool),
+ ("apic", bool),
+ ("acpi", bool),
+ ("nx", bool),
+ ("viridian", bool),
+ ("timeoffset", string),
+ ("hpet", bool),
+ ("vpt_align", bool),
+ ("timer_mode", integer),
+ ])),
+ ("pv", "!%s", Struct(None,
+ [("slack_memkb", uint32),
+ ("bootloader", string, True),
+ ("bootloader_args", string, True),
+ ("cmdline", string),
+ ("ramdisk", libxl_file_reference),
+ ("features", string, True),
+ ])),
+ ])),
+ ],
+ comment =
+"""Instances of libxl_file_reference contained in this struct which
+have been mapped (with libxl_file_reference_map) will be unmapped
+by libxl_domain_build/restore. If either of these are never called
+then the user is responsible for calling
+libxl_file_reference_unmap.""")
+
+libxl_domain_build_state = Struct("domain_build_state",[
+ ("store_port", uint32),
+ ("store_mfn", unsigned_long),
+ ("console_port", uint32),
+ ("console_mfn", unsigned_long),
+ ])
+
+libxl_device_model_info = Struct("device_model_info",[
+ ("domid", integer),
+ ("uuid", libxl_uuid, False, "this is use only with stubdom,
and must be different from the domain uuid"),
+ ("dom_name", string),
+ ("device_model", string),
+ ("saved_state", string),
+ ("type", libxl_qemu_machine_type),
+ ("videoram", integer, False, "size of the videoram in MB"),
+ ("stdvga", bool, False, "stdvga enabled or disabled"),
+ ("vnc", bool, False, "vnc enabled or disabled"),
+ ("vnclisten", string, False, "address:port that should be
listened on for the VNC server if vnc is set"),
+ ("vncpasswd", string, False, "the VNC password"),
+ ("vncdisplay", integer, False, "set VNC display number"),
+ ("vncunused", bool, False, "try to find an unused port for
the VNC server"),
+ ("keymap", string, False, "set keyboard layout, default is
en-us keyboard"),
+ ("sdl", bool, False, "sdl enabled or disabled"),
+ ("opengl", bool, False, "opengl enabled or disabled (if
enabled requires sdl enabled)"),
+ ("nographic", bool, False, "no graphics, use serial port"),
+ ("serial", string, False, "serial port re-direct to pty
deivce"),
+ ("boot", string, False, "boot order, for example dca"),
+ ("usb", bool, False, "usb support enabled or
disabled"),
+ ("usbdevice", string, False, "enable usb mouse: tablet for
absolute mouse, mouse for PS/2 protocol relative mouse"),
+ ("soundhw", string, False, "enable sound hardware"),
+ ("apic", bool, False, "apic enabled or disabled"),
+ ("vcpus", integer, False, "max number of vcpus"),
+ ("vcpu_avail", integer, False, "vcpus actually available"),
+ ("xen_platform_pci", integer, False, "enable/disable the xen platform
pci device"),
+ ("extra", string_list, False, "extra parameters pass directly
to qemu, NULL terminated"),
+ ],
+ comment=
+"""Device Model information.
+
+Network is missing""")
+
+libxl_device_vfb = Struct("device_vfb", [
+ ("backend_domid", uint32),
+ ("domid", uint32),
+ ("devid", integer),
+ ("vnc", bool, False, "vnc enabled or disabled"),
+ ("vnclisten", string, False, "address:port that should be listened
on for the VNC server if vnc is set"),
+ ("vncpasswd", string, False, "the VNC password"),
+ ("vncdisplay", integer, False, "set VNC display number"),
+ ("vncunused", bool, False, "try to find an unused port for the VNC
server"),
+ ("keymap", string, False, "set keyboard layout, default is en-us
keyboard"),
+ ("sdl", bool, False, "sdl enabled or disabled"),
+ ("opengl", bool, False, "opengl enabled or disabled (if enabled
requires sdl enabled)"),
+ ("display", string),
+ ("xauthority", string),
+ ])
+
+libxl_device_vkb = Struct("device_vkb", [
+ ("backend_domid", uint32),
+ ("domid", domid),
+ ("devid", integer),
+ ])
+
+libxl_device_console = Struct("device_console", [
+ ("backend_domid", uint32),
+ ("domid", domid),
+ ("devid", integer),
+ ("constype", libxl_console_constype),
+ ("build_state", Reference(libxl_domain_build_state)),
+ ])
+
+libxl_device_disk = Struct("device_disk", [
+ ("backend_domid", uint32),
+ ("domid", domid),
+ ("physpath", string),
+ ("phystype", libxl_disk_phystype),
+ ("virtpath", string),
+ ("unpluggable", integer),
+ ("readwrite", integer),
+ ("is_cdrom", integer),
+ ])
+
+libxl_device_nic = Struct("device_nic", [
+ ("backend_domid", uint32),
+ ("domid", domid),
+ ("devid", integer),
+ ("mtu", integer),
+ ("model", string),
+ ("mac", libxl_mac),
+ ("ip", inaddr_ip),
+ ("bridge", string),
+ ("ifname", string),
+ ("script", string),
+ ("nictype", libxl_nic_type),
+ ])
+
+libxl_device_net2 = Struct("device_net2", [
+ ("devid", integer),
+ ("front_mac", libxl_mac),
+ ("back_mac", libxl_mac),
+ ("backend_domid", uint32),
+ ("domid", domid),
+ ("trusted", BitField(uint32, 1)),
+ ("back_trusted", BitField(uint32, 1)),
+ ("filter_mac", BitField(uint32, 1)),
+ ("front_filter_mac", BitField(uint32, 1)),
+ ("pdev", uint32),
+ ("max_bypasses", uint32),
+ ("bridge", string),
+ ])
+
+libxl_device_pci = Struct("device_pci", [
+ (None, Union(None, [("value", unsigned_integer),
+ (None, Struct(None,[("reserved1",
BitField(unsigned_integer, 2)),
+ ("reg",
BitField(unsigned_integer, 6)),
+ ("func",
BitField(unsigned_integer, 3)),
+ ("dev",
BitField(unsigned_integer, 5)),
+ ("bus",
BitField(unsigned_integer, 8)),
+ ("reserved2",
BitField(unsigned_integer, 7)),
+ ("enable",
BitField(unsigned_integer, 1)),
+ ])),
+ ])
+ ),
+ ("domain", unsigned_integer),
+ ("vdevfn", unsigned_integer),
+ ("msitranslate", bool),
+ ("power_mgmt", bool),
+ ])
diff -r ba6f06badc87 -r 669a2933c9ab tools/libxl/libxltypes.py
--- a/tools/libxl/libxltypes.py Tue Aug 03 13:22:30 2010 +0100
+++ b/tools/libxl/libxltypes.py Tue Aug 03 14:27:57 2010 +0100
@@ -1,3 +1,5 @@ class Type(object):
+import sys
+
class Type(object):
def __init__(self, typename, **kwargs):
self.comment = None
@@ -155,270 +157,25 @@ string_list = Builtin("char **", namespa
inaddr_ip = Builtin("struct in_addr", namespace = None)
-#
-# Builtin libxl types
-#
-
-libxl_ctx = Builtin("ctx")
-libxl_uuid = Builtin("uuid")
-libxl_mac = Builtin("mac")
-libxl_qemu_machine_type = Builtin("qemu_machine_type")
-libxl_console_constype = Builtin("console_constype")
-libxl_disk_phystype = Builtin("disk_phystype")
-libxl_nic_type = Builtin("nic_type")
-
-#
-# Complex libxl types
-#
-libxl_dominfo = Struct("dominfo",[
- ("uuid", libxl_uuid),
- ("domid", domid),
- ("running", BitField(uint8, 1)),
- ("blocked", BitField(uint8, 1)),
- ("paused", BitField(uint8, 1)),
- ("shutdown", BitField(uint8, 1)),
- ("dying", BitField(uint8, 1)),
+def parse(f):
+ print >>sys.stderr, "Parsing %s" % f
- ("shutdown_reason", unsigned, False,
-"""Valid SHUTDOWN_* value from xen/sched.h iff (shutdown||dying).
-
-Otherwise set to a value guaranteed not to clash with any valid
-SHUTDOWN_* constant."""),
- ("max_memkb", uint64),
- ("cpu_time", uint64),
- ("vcpu_max_id", uint32),
- ("vcpu_online", uint32),
- ])
-
-libxl_poolinfo = Struct("poolinfo", [
- ("poolid", uint32)
- ])
-
-libxl_vminfo = Struct("vminfo", [
- ("uuid", libxl_uuid),
- ("domid", domid),
- ])
-
-libxl_version_info = Struct("version_info", [
- ("xen_version_major", integer),
- ("xen_version_minor", integer),
- ("xen_version_extra", string),
- ("compiler", string),
- ("compile_by", string),
- ("compile_domain", string),
- ("compile_date", string),
- ("capabilities", string),
- ("changeset", string),
- ("virt_start", unsigned_long),
- ("pagesize", unsigned_long),
- ("commandline", string),
- ])
-
-libxl_file_reference = Struct("file_reference",[
- ("path", string, False,
-"""Path is always set if the file refernece is valid. However if
-mapped is true then the actual file may already be unlinked."""),
- ("mapped", integer),
- ("data", void),
- ("size", size_t)])
-
-libxl_domain_create_info = Struct("domain_create_info",[
- ("hvm", bool),
- ("hap", bool),
- ("oos", bool),
- ("ssidref", integer),
- ("name", string),
- ("uuid", libxl_uuid),
- ("xsdata", KeyValueList(string, string)),
- ("platformdata", KeyValueList(string, string)),
- ("poolid", uint32),
- ("poolname", string, True),
- ])
-
-libxl_domain_build_info = Struct("domain_build_info",[
- ("max_vcpus", integer),
- ("cur_vcpus", integer),
- ("tsc_mode", integer),
- ("max_memkb", uint32),
- ("target_memkb", uint32),
- ("video_memkb", uint32),
- ("shadow_memkb", uint32),
- ("disable_migrate", bool),
- ("kernel", libxl_file_reference),
- ("hvm", integer),
- ("u", KeyedUnion(None, "hvm",
- [("hvm", "%s", Struct(None,
- [("pae", bool),
- ("apic", bool),
- ("acpi", bool),
- ("nx", bool),
- ("viridian", bool),
- ("timeoffset", string),
- ("hpet", bool),
- ("vpt_align", bool),
- ("timer_mode", integer),
- ])),
- ("pv", "!%s", Struct(None,
- [("slack_memkb", uint32),
- ("bootloader", string, True),
- ("bootloader_args", string, True),
- ("cmdline", string),
- ("ramdisk", libxl_file_reference),
- ("features", string, True),
- ])),
- ])),
- ],
- comment =
-"""Instances of libxl_file_reference contained in this struct which
-have been mapped (with libxl_file_reference_map) will be unmapped
-by libxl_domain_build/restore. If either of these are never called
-then the user is responsible for calling
-libxl_file_reference_unmap.""")
-
-libxl_domain_build_state = Struct("domain_build_state",[
- ("store_port", uint32),
- ("store_mfn", unsigned_long),
- ("console_port", uint32),
- ("console_mfn", unsigned_long),
- ])
-
-libxl_device_model_info = Struct("device_model_info",[
- ("domid", integer),
- ("uuid", libxl_uuid, False, "this is use only with stubdom,
and must be different from the domain uuid"),
- ("dom_name", string),
- ("device_model", string),
- ("saved_state", string),
- ("type", libxl_qemu_machine_type),
- ("videoram", integer, False, "size of the videoram in MB"),
- ("stdvga", bool, False, "stdvga enabled or disabled"),
- ("vnc", bool, False, "vnc enabled or disabled"),
- ("vnclisten", string, False, "address:port that should be
listened on for the VNC server if vnc is set"),
- ("vncpasswd", string, False, "the VNC password"),
- ("vncdisplay", integer, False, "set VNC display number"),
- ("vncunused", bool, False, "try to find an unused port for
the VNC server"),
- ("keymap", string, False, "set keyboard layout, default is
en-us keyboard"),
- ("sdl", bool, False, "sdl enabled or disabled"),
- ("opengl", bool, False, "opengl enabled or disabled (if
enabled requires sdl enabled)"),
- ("nographic", bool, False, "no graphics, use serial port"),
- ("serial", string, False, "serial port re-direct to pty
deivce"),
- ("boot", string, False, "boot order, for example dca"),
- ("usb", bool, False, "usb support enabled or
disabled"),
- ("usbdevice", string, False, "enable usb mouse: tablet for
absolute mouse, mouse for PS/2 protocol relative mouse"),
- ("soundhw", string, False, "enable sound hardware"),
- ("apic", bool, False, "apic enabled or disabled"),
- ("vcpus", integer, False, "max number of vcpus"),
- ("vcpu_avail", integer, False, "vcpus actually available"),
- ("xen_platform_pci", integer, False, "enable/disable the xen platform
pci device"),
- ("extra", string_list, False, "extra parameters pass directly
to qemu, NULL terminated"),
- ],
- comment=
-"""Device Model information.
-
-Network is missing""")
-
-libxl_device_vfb = Struct("device_vfb", [
- ("backend_domid", uint32),
- ("domid", uint32),
- ("devid", integer),
- ("vnc", bool, False, "vnc enabled or disabled"),
- ("vnclisten", string, False, "address:port that should be listened
on for the VNC server if vnc is set"),
- ("vncpasswd", string, False, "the VNC password"),
- ("vncdisplay", integer, False, "set VNC display number"),
- ("vncunused", bool, False, "try to find an unused port for the VNC
server"),
- ("keymap", string, False, "set keyboard layout, default is en-us
keyboard"),
- ("sdl", bool, False, "sdl enabled or disabled"),
- ("opengl", bool, False, "opengl enabled or disabled (if enabled
requires sdl enabled)"),
- ("display", string),
- ("xauthority", string),
- ])
-
-libxl_device_vkb = Struct("device_vkb", [
- ("backend_domid", uint32),
- ("domid", domid),
- ("devid", integer),
- ])
-
-libxl_device_console = Struct("device_console", [
- ("backend_domid", uint32),
- ("domid", domid),
- ("devid", integer),
- ("constype", libxl_console_constype),
- ("build_state", Reference(libxl_domain_build_state)),
- ])
-
-libxl_device_disk = Struct("device_disk", [
- ("backend_domid", uint32),
- ("domid", domid),
- ("physpath", string),
- ("phystype", libxl_disk_phystype),
- ("virtpath", string),
- ("unpluggable", integer),
- ("readwrite", integer),
- ("is_cdrom", integer),
- ])
-
-libxl_device_nic = Struct("device_nic", [
- ("backend_domid", uint32),
- ("domid", domid),
- ("devid", integer),
- ("mtu", integer),
- ("model", string),
- ("mac", libxl_mac),
- ("ip", inaddr_ip),
- ("bridge", string),
- ("ifname", string),
- ("script", string),
- ("nictype", libxl_nic_type),
- ])
-
-libxl_device_net2 = Struct("device_net2", [
- ("devid", integer),
- ("front_mac", libxl_mac),
- ("back_mac", libxl_mac),
- ("backend_domid", uint32),
- ("domid", domid),
- ("trusted", BitField(uint32, 1)),
- ("back_trusted", BitField(uint32, 1)),
- ("filter_mac", BitField(uint32, 1)),
- ("front_filter_mac", BitField(uint32, 1)),
- ("pdev", uint32),
- ("max_bypasses", uint32),
- ("bridge", string),
- ])
-
-libxl_device_pci = Struct("device_pci", [
- (None, Union(None, [("value", unsigned_integer),
- (None, Struct(None,[("reserved1",
BitField(unsigned_integer, 2)),
- ("reg",
BitField(unsigned_integer, 6)),
- ("func",
BitField(unsigned_integer, 3)),
- ("dev",
BitField(unsigned_integer, 5)),
- ("bus",
BitField(unsigned_integer, 8)),
- ("reserved2",
BitField(unsigned_integer, 7)),
- ("enable",
BitField(unsigned_integer, 1)),
- ])),
- ])
- ),
- ("domain", unsigned_integer),
- ("vdevfn", unsigned_integer),
- ("msitranslate", bool),
- ("power_mgmt", bool),
- ])
-
-Types = [
- libxl_dominfo,
- libxl_poolinfo,
- libxl_vminfo,
- libxl_version_info,
- libxl_domain_create_info,
- libxl_file_reference,
- libxl_domain_build_info,
- libxl_domain_build_state,
- libxl_device_model_info,
- libxl_device_vfb,
- libxl_device_vkb,
- libxl_device_console,
- libxl_device_disk,
- libxl_device_nic,
- libxl_device_net2,
- libxl_device_pci,
-]
+ globs = {}
+ locs = {}
+ for n,t in globals().items():
+ if isinstance(t, Type):
+ globs[n] = t
+ elif isinstance(t,type(object)) and issubclass(t, Type):
+ globs[n] = t
+
+ try:
+ execfile(f, globs, locs)
+ except SyntaxError,e:
+ raise SyntaxError, \
+ "Errors were found at line %d while processing %s:\n\t%s"\
+ %(e.lineno,defconfig,e.text)
+
+ types = [t for n,t in locs.items() if isinstance(t,Type)]
+ builtins = [t for t in types if isinstance(t,Builtin)]
+ types = [t for t in types if not isinstance(t,Builtin)]
+ return (builtins,types)
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|