diff options
-rw-r--r-- | tools/libxl/Makefile | 11 | ||||
-rw-r--r-- | tools/libxl/_libxl_types.h | 425 | ||||
-rw-r--r-- | tools/libxl/gentypes.py | 91 | ||||
-rw-r--r-- | tools/libxl/idl.txt | 147 | ||||
-rw-r--r-- | tools/libxl/libxl.idl | 329 | ||||
-rw-r--r-- | tools/libxl/libxltypes.py | 168 |
6 files changed, 743 insertions, 428 deletions
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index ee260f3bb9..3abb12dd5c 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -60,6 +60,14 @@ _libxl_paths.h: genpath libxl_paths.c: _libxl_paths.h +libxl.h: _libxl_types.h + +$(LIBXL_OBJS:%.o=%.c) $(LIBXLU_OBJS:%.o=%.c) $(XL_OBJS:%.o=%.c): libxl.h + +_libxl_types.h: libxl.idl gentypes.py libxltypes.py + python gentypes.py libxl.idl __libxl_types.h + mv __libxl_types.h _libxl_types.h + libxenlight.so: libxenlight.so.$(MAJOR) ln -sf $< $@ @@ -107,10 +115,7 @@ install: all .PHONY: clean clean: - # XXX Preserve during transition to autogeneration - cp _libxl_types.h SAVED__libxl_types.h $(RM) -f _*.h *.o *.so* *.a $(CLIENTS) $(DEPS) - mv SAVED__libxl_types.h _libxl_types.h # $(RM) -f $(AUTOSRCS) $(AUTOINCS) distclean: clean diff --git a/tools/libxl/_libxl_types.h b/tools/libxl/_libxl_types.h deleted file mode 100644 index 700b67bc1e..0000000000 --- a/tools/libxl/_libxl_types.h +++ /dev/null @@ -1,425 +0,0 @@ -#ifndef __LIBXL_TYPES_H -#define __LIBXL_TYPES_H - -typedef struct { - libxl_uuid uuid; - uint32_t domid; - uint8_t running:1; - uint8_t blocked:1; - uint8_t paused:1; - uint8_t shutdown:1; - uint8_t dying:1; - /* - * Valid SHUTDOWN_* value from xen/sched.h iff (shutdown||dying). - * - * Otherwise set to a value guaranteed not to clash with any valid - * SHUTDOWN_* constant. - */ - unsigned int shutdown_reason; - uint64_t max_memkb; - uint64_t cpu_time; - uint32_t vcpu_max_id; - uint32_t vcpu_online; -} libxl_dominfo; - -typedef struct { - uint32_t poolid; -} libxl_poolinfo; - -typedef struct { - libxl_uuid uuid; - uint32_t domid; -} libxl_vminfo; - -typedef struct { - int xen_version_major; - int xen_version_minor; - char * xen_version_extra; - char * compiler; - char * compile_by; - char * compile_domain; - char * compile_date; - char * capabilities; - char * changeset; - unsigned long virt_start; - unsigned long pagesize; - char * commandline; -} libxl_version_info; - -typedef struct { - bool hvm; - bool hap; - bool oos; - int ssidref; - char * name; - libxl_uuid uuid; - libxl_key_value_list xsdata; - libxl_key_value_list platformdata; - uint32_t poolid; - char * poolname; -} libxl_domain_create_info; - -typedef struct { - /* - * Path is always set if the file reference is valid. However if - * mapped is true then the actual file may already be unlinked. - */ - char * path; - int mapped; - void * data; - size_t size; -} libxl_file_reference; - -/* - * 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. - */ -typedef struct { - int max_vcpus; - int cur_vcpus; - int tsc_mode; - uint32_t max_memkb; - uint32_t target_memkb; - uint32_t video_memkb; - uint32_t shadow_memkb; - bool disable_migrate; - libxl_file_reference kernel; - int hvm; - union { - struct { - bool pae; - bool apic; - bool acpi; - bool nx; - bool viridian; - char * timeoffset; - bool hpet; - bool vpt_align; - int timer_mode; - } hvm; - struct { - uint32_t slack_memkb; - const char * bootloader; - const char * bootloader_args; - char * cmdline; - libxl_file_reference ramdisk; - const char * features; - } pv; - } u; -} libxl_domain_build_info; - -typedef struct { - uint32_t store_port; - unsigned long store_mfn; - uint32_t console_port; - unsigned long console_mfn; -} libxl_domain_build_state; - -/* - * Device Model information. - * - * Network is missing - */ -typedef struct { - int domid; - /* - * this is use only with stubdom, and must be different from the domain uuid - */ - libxl_uuid uuid; - char * dom_name; - char * device_model; - char * saved_state; - libxl_qemu_machine_type type; - /* - * size of the videoram in MB - */ - int videoram; - /* - * stdvga enabled or disabled - */ - bool stdvga; - /* - * vnc enabled or disabled - */ - bool vnc; - /* - * address:port that should be listened on for the VNC server if vnc is set - */ - char * vnclisten; - /* - * the VNC password - */ - char * vncpasswd; - /* - * set VNC display number - */ - int vncdisplay; - /* - * try to find an unused port for the VNC server - */ - bool vncunused; - /* - * set keyboard layout, default is en-us keyboard - */ - char * keymap; - /* - * sdl enabled or disabled - */ - bool sdl; - /* - * opengl enabled or disabled (if enabled requires sdl enabled) - */ - bool opengl; - /* - * no graphics, use serial port - */ - bool nographic; - /* - * serial port re-direct to pty deivce - */ - char * serial; - /* - * boot order, for example dca - */ - char * boot; - /* - * usb support enabled or disabled - */ - bool usb; - /* - * enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse - */ - char * usbdevice; - /* - * enable sound hardware - */ - char * soundhw; - /* - * apic enabled or disabled - */ - bool apic; - /* - * max number of vcpus - */ - int vcpus; - /* - * vcpus actually available - */ - int vcpu_avail; - /* - * enable/disable the xen platform pci device - */ - int xen_platform_pci; - /* - * extra parameters pass directly to qemu, NULL terminated - */ - libxl_string_list extra; -} libxl_device_model_info; - -typedef struct { - uint32_t backend_domid; - uint32_t domid; - int devid; - /* - * vnc enabled or disabled - */ - bool vnc; - /* - * address:port that should be listened on for the VNC server if vnc is set - */ - char * vnclisten; - /* - * the VNC password - */ - char * vncpasswd; - /* - * set VNC display number - */ - int vncdisplay; - /* - * try to find an unused port for the VNC server - */ - bool vncunused; - /* - * set keyboard layout, default is en-us keyboard - */ - char * keymap; - /* - * sdl enabled or disabled - */ - bool sdl; - /* - * opengl enabled or disabled (if enabled requires sdl enabled) - */ - bool opengl; - char * display; - char * xauthority; -} libxl_device_vfb; - -typedef struct { - uint32_t backend_domid; - uint32_t domid; - int devid; -} libxl_device_vkb; - -typedef struct { - uint32_t backend_domid; - uint32_t domid; - int devid; - libxl_console_consback consback; - libxl_domain_build_state * build_state; - char * output; -} libxl_device_console; - -typedef struct { - uint32_t backend_domid; - uint32_t domid; - char * physpath; - libxl_disk_phystype phystype; - char * virtpath; - int unpluggable; - int readwrite; - int is_cdrom; -} libxl_device_disk; - -typedef struct { - uint32_t backend_domid; - uint32_t domid; - int devid; - int mtu; - char * model; - libxl_mac mac; - struct in_addr ip; - char * bridge; - char * ifname; - char * script; - libxl_nic_type nictype; -} libxl_device_nic; - -typedef struct { - int devid; - libxl_mac front_mac; - libxl_mac back_mac; - uint32_t backend_domid; - uint32_t domid; - uint32_t trusted:1; - uint32_t back_trusted:1; - uint32_t filter_mac:1; - uint32_t front_filter_mac:1; - uint32_t pdev; - uint32_t max_bypasses; - char * bridge; -} libxl_device_net2; - -typedef struct { - union { - unsigned int value; - struct { - unsigned int reserved1:2; - unsigned int reg:6; - unsigned int func:3; - unsigned int dev:5; - unsigned int bus:8; - unsigned int reserved2:7; - unsigned int enable:1; - }; - }; - unsigned int domain; - unsigned int vdevfn; - unsigned int vfunc_mask; - bool msitranslate; - bool power_mgmt; -} libxl_device_pci; - -typedef struct { - char * backend; - uint32_t backend_id; - char * frontend; - uint32_t frontend_id; - int devid; - int state; - int evtch; - int rref; -} libxl_diskinfo; - -typedef struct { - char * backend; - uint32_t backend_id; - char * frontend; - uint32_t frontend_id; - int devid; - int state; - char * script; - libxl_mac mac; - int evtch; - int rref_tx; - int rref_rx; -} libxl_nicinfo; - -typedef struct { - /* - * vcpu's id - */ - uint32_t vcpuid; - /* - * current mapping - */ - uint32_t cpu; - /* - * currently online (not hotplugged)? - */ - uint8_t online:1; - /* - * blocked waiting for an event? - */ - uint8_t blocked:1; - /* - * currently scheduled on its CPU? - */ - uint8_t running:1; - /* - * total vcpu time ran (ns) - */ - uint64_t vcpu_time; - /* - * current cpu's affinities - */ - libxl_cpumap cpumap; -} libxl_vcpuinfo; - -typedef struct { - uint32_t threads_per_core; - uint32_t cores_per_socket; - uint32_t max_cpu_id; - uint32_t nr_cpus; - uint32_t cpu_khz; - uint64_t total_pages; - uint64_t free_pages; - uint64_t scrub_pages; - uint32_t nr_nodes; - libxl_hwcap hw_cap; - uint32_t phys_cap; -} libxl_physinfo; - -typedef struct { - int weight; - int cap; -} libxl_sched_credit; - -typedef struct { - char * backend; - uint32_t backend_id; - char * frontend; - uint32_t frontend_id; - int devid; - int state; - libxl_mac mac; - int trusted; - libxl_mac back_mac; - int filter_mac; -} libxl_net2info; - -#endif /* __LIBXL_TYPES_H */ diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py new file mode 100644 index 0000000000..5053d8dea7 --- /dev/null +++ b/tools/libxl/gentypes.py @@ -0,0 +1,91 @@ +#!/usr/bin/python + +import sys +import re + +import libxltypes + +def format_comment(level, comment): + indent = reduce(lambda x,y: x + " ", range(level), "") + s = "%s/*\n" % indent + s += "%s * " % indent + comment = comment.replace("\n", "\n%s * " % indent) + x = re.compile(r'^%s \* $' % indent, re.MULTILINE) + comment = x.sub("%s *" % indent, comment) + s += comment + s += "\n" + s += "%s */" % indent + s += "\n" + return s + +def libxl_C_type_of(ty): + return ty.typename + +def libxl_C_instance_of(ty, instancename): + if isinstance(ty, libxltypes.BitField): + return libxl_C_type_of(ty) + " " + instancename + ":%d" % ty.width + elif isinstance(ty, libxltypes.Aggregate) and ty.typename is None: + if instancename is None: + return libxl_C_type_define(ty) + else: + return libxl_C_type_define(ty) + " " + instancename + else: + return libxl_C_type_of(ty) + " " + instancename + +def libxl_C_type_define(ty, indent = ""): + s = "" + if isinstance(ty, libxltypes.Aggregate): + if ty.comment is not None: + s += format_comment(0, ty.comment) + + if ty.typename is None: + s += "%s {\n" % ty.kind + else: + s += "typedef %s {\n" % ty.kind + + for f in ty.fields: + if f.comment is not None: + s += format_comment(4, f.comment) + x = libxl_C_instance_of(f.type, f.name) + if f.const: + x = "const " + x + x = x.replace("\n", "\n ") + s += " " + x + ";\n" + if ty.typename is None: + s += "}" + else: + s += "} %s" % ty.typename + else: + raise NotImplementedError("%s" % type(ty)) + return s.replace("\n", "\n%s" % indent) + +if __name__ == '__main__': + if len(sys.argv) < 3: + print >>sys.stderr, "Usage: gentypes.py <idl> <header>" + sys.exit(1) + + idl = sys.argv[1] + (_,types) = libxltypes.parse(idl) + + header = sys.argv[2] + print "outputting libxl types to %s" % header + + f = open(header, "w") + + f.write("""#ifndef __LIBXL_TYPES_H +#define __LIBXL_TYPES_H + +/* + * DO NOT EDIT. + * + * This file is autogenerated by + * "%s" + */ + +""" % " ".join(sys.argv)) + + for t in types: + f.write(libxl_C_type_define(t) + ";\n") + f.write("\n") + + f.write("""#endif /* __LIBXL_TYPES_H */\n""") diff --git a/tools/libxl/idl.txt b/tools/libxl/idl.txt new file mode 100644 index 0000000000..9cb3f67ee7 --- /dev/null +++ b/tools/libxl/idl.txt @@ -0,0 +1,147 @@ +libxltypes IDL +-------------- + +Each type in the libxl interface is represented by an object of type +libxltypes.Type (or a subclass thereof). Every local variable defined +by the .idl file must be an instance of libxltypes.Type (e.g. you may +not define Python functions or any other construct other than defining +variables) + +The name of the type must be passed as the first argument to the +constructor when defining a new type. The name given should not +contain the initial namespace element (e.g. "libxl_"). See below for +how to specify a namespace. + +The Type.typename contains the C name of the type _including_ the +namespace element. + +The libxltypes.Type base class has several other properties which +apply to all types. The properties are set by passing a named +parameter to the constructor. + +Type.comment: + + A free text comment which describes the type. + +Type.namespace: (default: "libxl_") + + The namespace in which the type resides. Usually this is "libxl_" but + system defined and builtin types may differ. + + If the typename is not None then the namespace is prepended to the + type. + +Type.passby: (default: libxltypes.PASS_BY_VALUE) + + Defines the manner in which a type should be passed to C + functions. Valid values for this fields are: + libxltypes.PASS_BY_VALUE + libxltypes.PASS_BY_REFERENCE + +Type.destructor_fn: (default: typename + "_destroy" or None if type == None) + + The name of the C function which will free all dynamically allocated + memory contained within this type (but not the type itself). + +Type.autogenerate_destructor: (default: True) + + Indicates if the above named Type.destructor_fn should be + autogenerated. + +Other simple type-Classes +------------------------- + +libxltype.Builtin + + Instances of this class represent types which are predefined within + the system. + +libxltype.UInt + + Instances of this class represent the standard uint<N>_t types. + + The <N> for a given instance must be passed to the constructor and is + then available in UInt.width + +libxltype.BitField + + Instances of this class represent bitfield type classes. + + The base type and desired width for a given instance must be passed + to the contructor. The base type becomes the type of the instance and + width is contained in BitField.width + +libxltype.Reference + + Instances of this type represent a reference to another type + + The referant type must be passed to the constructor and is then + available in Reference.ref_type + +Complex type-Classes +-------------------- + +libxltype.Aggregate + + Base class for type-Classes which contain a number of other types + (e.g. structs and unions). + + The contained types are available in the list Aggregate.fields. Each + element in the list is of type libxltype.Field representing a member + of the aggregate. + + Each field has the following properties: + + Field.type The type of the member (a libxltypes.Type). + Field.name The name of the member (can be None for anonymous + fields). + Field.const Boolean, true if the member is const. + Field.comment A free text comment which describes the member. + +libxltype.Struct + + A subclass of libxltype.Aggregate representing the C struct type. + + Struct.kind == "struct" + +libxltype.Union + + A subclass of libxltype.Aggregate representing the C union type. + + Union.kind == "union" + +libxltype.KeyedUnion + + A subclass of libxltype.Aggregate which represents the C union type + where the currently valid member of the union can be determined based + upon another member in the containing type. + + The KeyedUnion.keyvar_name must contain the name of the member of the + containing type which determines the valid member of the union + + The fields in a KeyedUnion have an extra Field.keyvar_expr + property. This must be a string containing a single "%s" format + specifier such that when "%s" is substited by an instance of + KeyedUnion.keyvar_name it becomes a C expression which evaluates to + True IFF this field currently contains valid data. + +Standard Types +-------------- + +Several standard types a predefined. They are + +void (void pointer type) +bool +size_t +integer (C int type) +unsigned_integer (C unsigned int type) +unsigned (C unsigned int type) +unsigned_long (C unsigned long type) + +uint{8,16,32,64} uint{8,16,32,64}_t + +domid Domain ID + +string NULL terminated string + +inaddr_ip struct in_addr diff --git a/tools/libxl/libxl.idl b/tools/libxl/libxl.idl new file mode 100644 index 0000000000..c424286a7a --- /dev/null +++ b/tools/libxl/libxl.idl @@ -0,0 +1,329 @@ +# -*- 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_consback = Builtin("console_consback") +libxl_console_constype = Builtin("console_constype") +libxl_disk_phystype = Builtin("disk_phystype") +libxl_nic_type = Builtin("nic_type") + +libxl_string_list = Builtin("string_list") +libxl_key_value_list = Builtin("key_value_list") + +libxl_cpumap = Builtin("cpumap") + +libxl_hwcap = Builtin("hwcap") + +# +# 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_domain_create_info = Struct("domain_create_info",[ + ("hvm", bool), + ("hap", bool), + ("oos", bool), + ("ssidref", integer), + ("name", string), + ("uuid", libxl_uuid), + ("xsdata", libxl_key_value_list), + ("platformdata", libxl_key_value_list), + ("poolid", uint32), + ("poolname", string), + ]) + +libxl_file_reference = Struct("file_reference",[ + ("path", string, False, +"""Path is always set if the file reference is valid. However if +mapped is true then the actual file may already be unlinked."""), + ("mapped", integer), + ("data", void), + ("size", size_t)]) + +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", libxl_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), + ("consback", libxl_console_consback), + ("build_state", Reference(libxl_domain_build_state)), + ("output", string), + ]) + +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), + ("vfunc_mask", unsigned_integer), + ("msitranslate", bool), + ("power_mgmt", bool), + ]) + +libxl_diskinfo = Struct("diskinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", integer), + ("state", integer), + ("evtch", integer), + ("rref", integer), + ]) + +libxl_nicinfo = Struct("nicinfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", integer), + ("state", integer), + ("script", string), + ("mac", libxl_mac), + ("evtch", integer), + ("rref_tx", integer), + ("rref_rx", integer), + ]) + +libxl_vcpuinfo = Struct("vcpuinfo", [ + ("vcpuid", uint32, False, "vcpu's id"), + ("cpu", uint32, False, "current mapping"), + ("online", BitField(uint8, 1), False, "currently online (not hotplugged)?"), + ("blocked", BitField(uint8, 1), False, "blocked waiting for an event?"), + ("running", BitField(uint8, 1), False, "currently scheduled on its CPU?"), + ("vcpu_time", uint64, False, "total vcpu time ran (ns)"), + ("cpumap", libxl_cpumap, False, "current cpu's affinities"), + ]) + +libxl_physinfo = Struct("physinfo", [ + ("threads_per_core", uint32), + ("cores_per_socket", uint32), + + ("max_cpu_id", uint32), + ("nr_cpus", uint32), + ("cpu_khz", uint32), + + ("total_pages", uint64), + ("free_pages", uint64), + ("scrub_pages", uint64), + + ("nr_nodes", uint32), + ("hw_cap", libxl_hwcap), + ("phys_cap", uint32), + ]) + +libxl_sched_credit = Struct("sched_credit", [ + ("weight", integer), + ("cap", integer), + ]) + +libxl_net2info = Struct("net2info", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", integer), + ("state", integer), + ("mac", libxl_mac), + ("trusted", integer), + ("back_mac", libxl_mac), + ("filter_mac", integer), + ]) diff --git a/tools/libxl/libxltypes.py b/tools/libxl/libxltypes.py new file mode 100644 index 0000000000..f08ee22c4b --- /dev/null +++ b/tools/libxl/libxltypes.py @@ -0,0 +1,168 @@ +import sys + +class Type(object): + def __init__(self, typename, **kwargs): + self.comment = kwargs.setdefault('comment', None) + self.namespace = kwargs.setdefault('namespace', "libxl_") + + if typename is None: # Anonymous type + self.typename = None + elif self.namespace is None: # e.g. system provided types + self.typename = typename + else: + self.typename = self.namespace + typename + +class Builtin(Type): + """Builtin type""" + def __init__(self, typename, **kwargs): + Type.__init__(self, typename, **kwargs) + +class UInt(Type): + def __init__(self, w, **kwargs): + kwargs.setdefault('namespace', None) + Type.__init__(self, "uint%d_t" % w, **kwargs) + + self.width = w + +class BitField(Type): + def __init__(self, ty, w, **kwargs): + kwargs.setdefault('namespace', None) + Type.__init__(self, ty.typename, **kwargs) + + self.width = w + +class Field(object): + """An element of an Aggregate type""" + def __init__(self, type, name, **kwargs): + self.type = type + self.name = name + self.const = kwargs.setdefault('const', False) + self.comment = kwargs.setdefault('comment', None) + self.keyvar_expr = kwargs.setdefault('keyvar_expr', None) + +class Aggregate(Type): + """A type containing a collection of other types""" + def __init__(self, kind, typename, fields, **kwargs): + Type.__init__(self, typename, **kwargs) + + self.kind = kind + + self.fields = [] + for f in fields: + # (name, type[, const=False[, comment=None]]) + if len(f) == 2: + n,t = f + const = False + comment = None + elif len(f) == 3: + n,t,const = f + comment = None + else: + n,t,const,comment = f + self.fields.append(Field(t,n,const=const,comment=comment)) + +class Struct(Aggregate): + def __init__(self, name, fields, **kwargs): + Aggregate.__init__(self, "struct", name, fields, **kwargs) + +class Union(Aggregate): + def __init__(self, name, fields, **kwargs): + Aggregate.__init__(self, "union", name, fields, **kwargs) + +class KeyedUnion(Aggregate): + """A union which is keyed of another variable in the parent structure""" + def __init__(self, name, keyvar_name, fields, **kwargs): + Aggregate.__init__(self, "union", name, [], **kwargs) + + self.keyvar_name = keyvar_name + + for f in fields: + # (name, keyvar_expr, type) + + # keyvar_expr must contain exactly one %s which will be replaced with the keyvar_name + + n, kve, ty = f + self.fields.append(Field(ty, n, keyvar_expr=kve)) + +class Reference(Type): + """A reference to another type""" + def __init__(self, ty, **kwargs): + # Ugh + kwargs.setdefault('namespace', ty.namespace) + typename = ty.typename[len(kwargs['namespace']):] + Type.__init__(self, typename + " *", **kwargs) + +# +# Standard Types +# + +void = Builtin("void *", namespace = None) +bool = Builtin("bool", namespace = None) +size_t = Builtin("size_t", namespace = None) + +integer = Builtin("int", namespace = None) +unsigned_integer = Builtin("unsigned int", namespace = None) +unsigned = Builtin("unsigned int", namespace = None) +unsigned_long = Builtin("unsigned long", namespace = None) + +uint8 = UInt(8) +uint16 = UInt(16) +uint32 = UInt(32) +uint64 = UInt(64) + +domid = UInt(32) + +string = Builtin("char *", namespace = None) + +inaddr_ip = Builtin("struct in_addr", namespace = None) + +class OrderedDict(dict): + """A dictionary which remembers insertion order. + + push to back on duplicate insertion""" + + def __init__(self): + dict.__init__(self) + self.__ordered = [] + + def __setitem__(self, key, value): + try: + self.__ordered.remove(key) + except ValueError: + pass + + self.__ordered.append(key) + dict.__setitem__(self, key, value) + + def ordered_keys(self): + return self.__ordered + def ordered_values(self): + return [self[x] for x in self.__ordered] + def ordered_items(self): + return [(x,self[x]) for x in self.__ordered] + +def parse(f): + print >>sys.stderr, "Parsing %s" % f + + globs = {} + locs = OrderedDict() + + 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,f,e.text) + + types = [t for t in locs.ordered_values() 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) |