Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 00 of 16] libxl: autogenerate type definitions and destructor functions
The series introduces auto-generation of the type definitions used in the libxl interface followed by auto-generation of a destructor function for each type. In the future it may be possible to use the related data structures for other purposes, for example auto-generation of the functions to marshal between C and language binding data types. tools/_libxl_types.h should be identical both before applying and after applying+building "libxl: autogenerate _libxl_types.h" apart from a "DO NOT EDIT" header. Since last time: * rebase, many precurors were committed Since the time before that: * rebased * corrected Makefile dependencies to include libxltypes.idl * manually implemented libxl_file_reference_destroy since it is more complex than just freeing the contained types. * Made libxl_file_reference_{map,unmap} into internal functions. * Added typedefs for various types: - libxl_cpumap - libxl_hwcap * Made libxl_xen_console_reader an opaque type and by making the definition internal. * moved more types from libxl.h to _libxl_types.h. I think all those which it makes sense to generate are now accounted for. * disabled destructor generation for types which have no interesting fields (i.e. had empty destructor functions). I have retained the empty destructors for types which belong to a set where some types do have a valid need for a destructor funntion (e.g. libxl_device_* or libxl_*info) * Audit for usages of libxl_device_* and libxl_*info which can use the new destructors. I''m sure I haven''t caught them all. Tested with: create destroy (w/ valgrind) block-list (w/ valgrind) network-list (w/ valgrind) network-attach (w/ valgrind) network-detach (w/ valgrind) vcpu-list (w/ valgrind) cd-insert (w/ valgrind) create, other than dry run, and valgrind don''t currently play nice together. It''s not clear if its all the foreign mappings or something else. I''ve tested creating both HVM and PV guests. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 01 of 16] xl: free all data on exit from the domain monitor daemon
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143676 -3600 # Node ID fabe8b10fdc20dc68738a6921ef1b0f66b761cc6 # Parent b1f4b4be1f94c0007794f86abd019f5c2629c59b xl: free all data on exit from the domain monitor daemon. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r b1f4b4be1f94 -r fabe8b10fdc2 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:00:29 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:16 2010 +0100 @@ -1557,9 +1557,11 @@ start: if (ret) { switch (handle_domain_death(&ctx, domid, &event, &d_config, &info)) { case 2: - if (!preserve_domain(&ctx, domid, &event, &d_config, &info)) + if (!preserve_domain(&ctx, domid, &event, &d_config, &info)) { /* If we fail then exit leaving the old domain in place. */ - exit(-1); + ret = -1; + goto out; + } /* Otherwise fall through and restart. */ case 1: @@ -1577,7 +1579,8 @@ start: goto start; case 0: LOG("Done. Exiting now"); - exit(0); + ret = 0; + goto out; } } break; @@ -1589,13 +1592,13 @@ start: libxl_free_event(&event); } - close(logfile); - exit(0); - error_out: if (domid) libxl_domain_destroy(&ctx, domid, 0); + out: + if (logfile != 2) + close(logfile); free_domain_config(&d_config); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 02 of 16] libxl: move type definitions into _libxl_types.h
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID f9ed451bcf9e247d99040918034403b649ccb021 # Parent fabe8b10fdc20dc68738a6921ef1b0f66b761cc6 libxl: move type definitions into _libxl_types.h The intention is to autogenerate this file in a future patch. This pure code motion patch allows for easier before and after comparison of that patch. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r fabe8b10fdc2 -r f9ed451bcf9e tools/libxl/Makefile --- a/tools/libxl/Makefile Wed Aug 18 16:01:16 2010 +0100 +++ b/tools/libxl/Makefile Wed Aug 18 16:01:17 2010 +0100 @@ -102,12 +102,15 @@ install: all ln -sf libxlutil.so.$(XLUMAJOR).$(XLUMINOR) $(DESTDIR)$(LIBDIR)/libxlutil.so.$(XLUMAJOR) ln -sf libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(LIBDIR)/libxlutil.so $(INSTALL_DATA) libxlutil.a $(DESTDIR)$(LIBDIR) - $(INSTALL_DATA) libxl.h $(DESTDIR)$(INCLUDEDIR) + $(INSTALL_DATA) libxl.h _libxl_types.h $(DESTDIR)$(INCLUDEDIR) $(INSTALL_DATA) bash-completion $(DESTDIR)$(BASH_COMPLETION_DIR)/xl.sh .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 -r fabe8b10fdc2 -r f9ed451bcf9e tools/libxl/_libxl_types.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/_libxl_types.h Wed Aug 18 16:01:17 2010 +0100 @@ -0,0 +1,315 @@ +#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 refernece 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; + +typedef struct { + int domid; + libxl_uuid uuid; /* this is use only with stubdom, and must be different from the domain uuid */ + char *dom_name; + char *device_model; + char *saved_state; + libxl_qemu_machine_type type; + int videoram; /* size of the videoram in MB */ + bool stdvga; /* stdvga enabled or disabled */ + bool vnc; /* vnc enabled or disabled */ + char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ + char *vncpasswd; /* the VNC password */ + int vncdisplay; /* set VNC display number */ + bool vncunused; /* try to find an unused port for the VNC server */ + char *keymap; /* set keyboard layout, default is en-us keyboard */ + bool sdl; /* sdl enabled or disabled */ + bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */ + bool nographic; /* no graphics, use serial port */ + char *serial; /* serial port re-direct to pty deivce */ + char *boot; /* boot order, for example dca */ + bool usb; /* usb support enabled or disabled */ + char *usbdevice; /* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */ + char *soundhw; /* enable sound hardware */ + bool apic; /* apic enabled or disabled */ + int vcpus; /* max number of vcpus */ + int vcpu_avail; /* vcpus actually available */ + int xen_platform_pci; /* enable/disable the xen platform pci device */ + libxl_string_list extra; /* extra parameters pass directly to qemu, NULL terminated */ + /* Network is missing */ +} libxl_device_model_info; + +typedef struct { + uint32_t backend_domid; + uint32_t domid; + int devid; + bool vnc; /* vnc enabled or disabled */ + char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ + char *vncpasswd; /* the VNC password */ + int vncdisplay; /* set VNC display number */ + bool vncunused; /* try to find an unused port for the VNC server */ + char *keymap; /* set keyboard layout, default is en-us keyboard */ + bool sdl; /* sdl enabled or disabled */ + bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */ + 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 { + uint32_t vcpuid; /* vcpu''s id */ + uint32_t cpu; /* current mapping */ + uint8_t online:1; /* currently online (not hotplugged)? */ + uint8_t blocked:1; /* blocked waiting for an event? */ + uint8_t running:1; /* currently scheduled on its CPU? */ + uint64_t vcpu_time; /* total vcpu time ran (ns) */ + libxl_cpumap cpumap; /* current cpu''s affinities */ +} 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 -r fabe8b10fdc2 -r f9ed451bcf9e tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Aug 18 16:01:16 2010 +0100 +++ b/tools/libxl/libxl.h Wed Aug 18 16:01:17 2010 +0100 @@ -180,52 +180,7 @@ typedef enum { #define LIBXL_PCI_FUNC_ALL (~0U) -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; +#include "_libxl_types.h" typedef struct { xentoollog_logger *lg; @@ -242,205 +197,11 @@ const libxl_version_info* libxl_get_vers const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx); 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 refernece 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; - -typedef struct { #define XL_SUSPEND_DEBUG 1 #define XL_SUSPEND_LIVE 2 int flags; int (*suspend_callback)(void *, int); } libxl_domain_suspend_info; - -typedef struct { - int domid; - libxl_uuid uuid; /* this is use only with stubdom, and must be different from the domain uuid */ - char *dom_name; - char *device_model; - char *saved_state; - libxl_qemu_machine_type type; - int videoram; /* size of the videoram in MB */ - bool stdvga; /* stdvga enabled or disabled */ - bool vnc; /* vnc enabled or disabled */ - char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ - char *vncpasswd; /* the VNC password */ - int vncdisplay; /* set VNC display number */ - bool vncunused; /* try to find an unused port for the VNC server */ - char *keymap; /* set keyboard layout, default is en-us keyboard */ - bool sdl; /* sdl enabled or disabled */ - bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */ - bool nographic; /* no graphics, use serial port */ - char *serial; /* serial port re-direct to pty deivce */ - char *boot; /* boot order, for example dca */ - bool usb; /* usb support enabled or disabled */ - char *usbdevice; /* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */ - char *soundhw; /* enable sound hardware */ - bool apic; /* apic enabled or disabled */ - int vcpus; /* max number of vcpus */ - int vcpu_avail; /* vcpus actually available */ - int xen_platform_pci; /* enable/disable the xen platform pci device */ - libxl_string_list extra; /* extra parameters pass directly to qemu, NULL terminated */ - /* Network is missing */ -} libxl_device_model_info; - -typedef struct { - uint32_t backend_domid; - uint32_t domid; - int devid; - bool vnc; /* vnc enabled or disabled */ - char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ - char *vncpasswd; /* the VNC password */ - int vncdisplay; /* set VNC display number */ - bool vncunused; /* try to find an unused port for the VNC server */ - char *keymap; /* set keyboard layout, default is en-us keyboard */ - bool sdl; /* sdl enabled or disabled */ - bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */ - 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; enum { ERROR_VERSION = -1, @@ -594,17 +355,6 @@ int libxl_detach_device_model(libxl_ctx libxl_device_model_starting *starting); /* DM is detached even if error is returned */ -typedef struct { - char *backend; - uint32_t backend_id; - char *frontend; - uint32_t frontend_id; - int devid; - int state; - int evtch; - int rref; -} libxl_diskinfo; - int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); int libxl_device_disk_del(libxl_ctx *ctx, libxl_device_disk *disk, int wait); libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num); @@ -617,20 +367,6 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u */ char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk); int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk); - -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; int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); int libxl_device_nic_del(libxl_ctx *ctx, libxl_device_nic *nic, int wait); @@ -692,33 +428,6 @@ typedef enum { int libxl_button_press(libxl_ctx *ctx, uint32_t domid, libxl_button button); -typedef struct { - uint32_t vcpuid; /* vcpu''s id */ - uint32_t cpu; /* current mapping */ - uint8_t online:1; /* currently online (not hotplugged)? */ - uint8_t blocked:1; /* blocked waiting for an event? */ - uint8_t running:1; /* currently scheduled on its CPU? */ - uint64_t vcpu_time; /* total vcpu time ran (ns) */ - libxl_cpumap cpumap; /* current cpu''s affinities */ -} 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; - int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo); libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid, int *nb_vcpu, int *nrcpus); @@ -729,11 +438,6 @@ int libxl_set_vcpucount(libxl_ctx *ctx, int libxl_get_sched_id(libxl_ctx *ctx); - -typedef struct { - int weight; - int cap; -} libxl_sched_credit; int libxl_sched_credit_domain_get(libxl_ctx *ctx, uint32_t domid, libxl_sched_credit *scinfo); @@ -766,19 +470,6 @@ int libxl_tmem_shared_auth(libxl_ctx *ct int auth); int libxl_tmem_freeable(libxl_ctx *ctx); -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; - int libxl_device_net2_add(libxl_ctx *ctx, uint32_t domid, libxl_device_net2 *net2); libxl_net2info *libxl_device_net2_list(libxl_ctx *ctx, uint32_t domid, _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 03 of 16] libxl: tweak formatting/whitespace of _libxl_types.h
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID 0fd1eb6a846d69ee95b3ada4d55143f9b667de41 # Parent f9ed451bcf9e247d99040918034403b649ccb021 libxl: tweak formatting/whitespace of _libxl_types.h to better suit autogeneration This makes it easier to do a before/after comparison when the file becomes autogenerated. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r f9ed451bcf9e -r 0fd1eb6a846d tools/libxl/_libxl_types.h --- a/tools/libxl/_libxl_types.h Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/_libxl_types.h Wed Aug 18 16:01:17 2010 +0100 @@ -9,7 +9,6 @@ typedef struct { uint8_t paused:1; uint8_t shutdown:1; uint8_t dying:1; - /* * Valid SHUTDOWN_* value from xen/sched.h iff (shutdown||dying). * @@ -17,7 +16,6 @@ typedef struct { * SHUTDOWN_* constant. */ unsigned int shutdown_reason; - uint64_t max_memkb; uint64_t cpu_time; uint32_t vcpu_max_id; @@ -36,16 +34,16 @@ typedef struct { 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; + 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; + char * commandline; } libxl_version_info; typedef struct { @@ -53,22 +51,22 @@ typedef struct { bool hap; bool oos; int ssidref; - char *name; + char * name; libxl_uuid uuid; libxl_key_value_list xsdata; libxl_key_value_list platformdata; uint32_t poolid; - char *poolname; + char * poolname; } libxl_domain_create_info; typedef struct { /* - * Path is always set if the file refernece is valid. However if + * 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; + char * path; int mapped; - void *data; + void * data; size_t size; } libxl_file_reference; @@ -97,18 +95,18 @@ typedef struct { bool acpi; bool nx; bool viridian; - char *timeoffset; + 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; + uint32_t slack_memkb; + const char * bootloader; + const char * bootloader_args; + char * cmdline; libxl_file_reference ramdisk; - const char *features; + const char * features; } pv; } u; } libxl_domain_build_info; @@ -120,51 +118,145 @@ typedef struct { unsigned long console_mfn; } libxl_domain_build_state; +/* + * Device Model information. + * + * Network is missing + */ typedef struct { int domid; - libxl_uuid uuid; /* this is use only with stubdom, and must be different from the domain uuid */ - char *dom_name; - char *device_model; - char *saved_state; + /* + * 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; - int videoram; /* size of the videoram in MB */ - bool stdvga; /* stdvga enabled or disabled */ - bool vnc; /* vnc enabled or disabled */ - char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ - char *vncpasswd; /* the VNC password */ - int vncdisplay; /* set VNC display number */ - bool vncunused; /* try to find an unused port for the VNC server */ - char *keymap; /* set keyboard layout, default is en-us keyboard */ - bool sdl; /* sdl enabled or disabled */ - bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */ - bool nographic; /* no graphics, use serial port */ - char *serial; /* serial port re-direct to pty deivce */ - char *boot; /* boot order, for example dca */ - bool usb; /* usb support enabled or disabled */ - char *usbdevice; /* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */ - char *soundhw; /* enable sound hardware */ - bool apic; /* apic enabled or disabled */ - int vcpus; /* max number of vcpus */ - int vcpu_avail; /* vcpus actually available */ - int xen_platform_pci; /* enable/disable the xen platform pci device */ - libxl_string_list extra; /* extra parameters pass directly to qemu, NULL terminated */ - /* Network is missing */ + /* + * 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; - bool vnc; /* vnc enabled or disabled */ - char *vnclisten; /* address:port that should be listened on for the VNC server if vnc is set */ - char *vncpasswd; /* the VNC password */ - int vncdisplay; /* set VNC display number */ - bool vncunused; /* try to find an unused port for the VNC server */ - char *keymap; /* set keyboard layout, default is en-us keyboard */ - bool sdl; /* sdl enabled or disabled */ - bool opengl; /* opengl enabled or disabled (if enabled requires sdl enabled) */ - char *display; - char *xauthority; + /* + * 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 { @@ -178,16 +270,16 @@ typedef struct { uint32_t domid; int devid; libxl_console_consback consback; - libxl_domain_build_state *build_state; - char *output; + libxl_domain_build_state * build_state; + char * output; } libxl_device_console; typedef struct { uint32_t backend_domid; uint32_t domid; - char *physpath; + char * physpath; libxl_disk_phystype phystype; - char *virtpath; + char * virtpath; int unpluggable; int readwrite; int is_cdrom; @@ -198,12 +290,12 @@ typedef struct { uint32_t domid; int devid; int mtu; - char *model; + char * model; libxl_mac mac; struct in_addr ip; - char *bridge; - char *ifname; - char *script; + char * bridge; + char * ifname; + char * script; libxl_nic_type nictype; } libxl_device_nic; @@ -219,7 +311,7 @@ typedef struct { uint32_t front_filter_mac:1; uint32_t pdev; uint32_t max_bypasses; - char *bridge; + char * bridge; } libxl_device_net2; typedef struct { @@ -243,9 +335,9 @@ typedef struct { } libxl_device_pci; typedef struct { - char *backend; + char * backend; uint32_t backend_id; - char *frontend; + char * frontend; uint32_t frontend_id; int devid; int state; @@ -254,13 +346,13 @@ typedef struct { } libxl_diskinfo; typedef struct { - char *backend; + char * backend; uint32_t backend_id; - char *frontend; + char * frontend; uint32_t frontend_id; int devid; int state; - char *script; + char * script; libxl_mac mac; int evtch; int rref_tx; @@ -268,31 +360,49 @@ typedef struct { } libxl_nicinfo; typedef struct { - uint32_t vcpuid; /* vcpu''s id */ - uint32_t cpu; /* current mapping */ - uint8_t online:1; /* currently online (not hotplugged)? */ - uint8_t blocked:1; /* blocked waiting for an event? */ - uint8_t running:1; /* currently scheduled on its CPU? */ - uint64_t vcpu_time; /* total vcpu time ran (ns) */ - libxl_cpumap cpumap; /* current cpu''s affinities */ + /* + * 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; +} libxl_physinfo; typedef struct { int weight; @@ -300,9 +410,9 @@ typedef struct { } libxl_sched_credit; typedef struct { - char *backend; + char * backend; uint32_t backend_id; - char *frontend; + char * frontend; uint32_t frontend_id; int devid; int state; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 04 of 16] libxl: autogenerate _libxl_types.h
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID ec0d4b02e9c270b2a3e328b5b5e62e3a05aa6b1e # Parent 0fd1eb6a846d69ee95b3ada4d55143f9b667de41 libxl: autogenerate _libxl_types.h The libxl interface types are represented by a simple python data structure (which could be parsed from a bespoke language in the future). This will allow the autogeneration of functions to free the component members of the libxl types. In the future it may also enable auto generation of type marshalling code for language bindings. The generated file should be identical to before with the exception of the "DO NOT EDIT" header. It was unfortunately necessary to add explcit an dependency on _libxl_types.h (indirectly via libxl.h) to all C files since the autogenerated dependencies are not available in time. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 0fd1eb6a846d -r ec0d4b02e9c2 tools/libxl/Makefile --- a/tools/libxl/Makefile Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/Makefile Wed Aug 18 16:01:17 2010 +0100 @@ -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 -r 0fd1eb6a846d -r ec0d4b02e9c2 tools/libxl/_libxl_types.h --- a/tools/libxl/_libxl_types.h Wed Aug 18 16:01:17 2010 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r 0fd1eb6a846d -r ec0d4b02e9c2 tools/libxl/gentypes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/gentypes.py Wed Aug 18 16:01:17 2010 +0100 @@ -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 -r 0fd1eb6a846d -r ec0d4b02e9c2 tools/libxl/idl.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/idl.txt Wed Aug 18 16:01:17 2010 +0100 @@ -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 -r 0fd1eb6a846d -r ec0d4b02e9c2 tools/libxl/libxl.idl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 @@ -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 -r 0fd1eb6a846d -r ec0d4b02e9c2 tools/libxl/libxltypes.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/libxltypes.py Wed Aug 18 16:01:17 2010 +0100 @@ -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) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 05 of 16] libxl: generate destructors for each libxl defined type
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID 1ee0c9db536b4af2a8543a80d2a939a3b5ec76e7 # Parent ec0d4b02e9c270b2a3e328b5b5e62e3a05aa6b1e libxl: generate destructors for each libxl defined type I chose the name "_destroy" rather than "_free" because the destructor functions will free only the members of a type recursively but will not free the actual type structure itself. The allocation of the type is typically done by the caller and may not be a single allocation, e.g. lists/arrays of types or embedded in other structures etc. The exceptions to this rule are libxl_string_list_destroy and libxl_key_value_list_destroy but I''m not 100% convinced they are exceptions (since they are kind-of opaque) and I couldn''t see a cleanerway to express this concept. I have made a best effort attempt to implement these functions sanely but since as far as I can tell nothing in the current code base ever sets libxl_domain_create_info.{xsdata,platformdata} I''m flying somewhat blind. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r ec0d4b02e9c2 -r 1ee0c9db536b .hgignore --- a/.hgignore Wed Aug 18 16:01:17 2010 +0100 +++ b/.hgignore Wed Aug 18 16:01:17 2010 +0100 @@ -182,6 +182,7 @@ ^tools/libxen/test/test_bindings$ ^tools/libxen/test/test_event_handling$ ^tools/libxl/_.*\.h$ +^tools/libxl/_.*\.c$ ^tools/libxl/libxlu_cfg_y\.output$ ^tools/libxl/xl$ ^tools/libaio/src/.*\.ol$ diff -r ec0d4b02e9c2 -r 1ee0c9db536b tools/libxl/Makefile --- a/tools/libxl/Makefile Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/Makefile Wed Aug 18 16:01:17 2010 +0100 @@ -25,6 +25,7 @@ endif endif LIBXL_OBJS = flexarray.o libxl.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y) +LIBXL_OBJS += _libxl_types.o AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c @@ -64,9 +65,10 @@ 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 +_libxl_types.h _libxl_types.c: libxl.idl gentypes.py libxltypes.py + python gentypes.py libxl.idl __libxl_types.h __libxl_types.c mv __libxl_types.h _libxl_types.h + mv __libxl_types.c _libxl_types.c libxenlight.so: libxenlight.so.$(MAJOR) ln -sf $< $@ @@ -116,6 +118,7 @@ install: all .PHONY: clean clean: $(RM) -f _*.h *.o *.so* *.a $(CLIENTS) $(DEPS) + $(RM) -f _*.c # $(RM) -f $(AUTOSRCS) $(AUTOINCS) distclean: clean diff -r ec0d4b02e9c2 -r 1ee0c9db536b tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/gentypes.py Wed Aug 18 16:01:17 2010 +0100 @@ -59,16 +59,53 @@ def libxl_C_type_define(ty, indent = "") raise NotImplementedError("%s" % type(ty)) return s.replace("\n", "\n%s" % indent) +def libxl_C_type_destroy(ty, v, reference, indent = " ", parent = None): + if reference: + deref = v + "->" + else: + deref = v + "." + + s = "" + if isinstance(ty, libxltypes.KeyedUnion): + if parent is None: + raise Exception("KeyedUnion type must have a parent") + for f in ty.fields: + keyvar_expr = f.keyvar_expr % (parent + ty.keyvar_name) + s += "if (" + keyvar_expr + ") {\n" + s += libxl_C_type_destroy(f.type, deref + f.name, False, indent + " ", deref) + s += "}\n" + elif isinstance(ty, libxltypes.Reference): + s += libxl_C_type_destroy(ty.ref_type, v, True, indent, v) + elif isinstance(ty, libxltypes.Struct) and (parent is None or ty.destructor_fn is None): + for f in [f for f in ty.fields if not f.const]: + + if f.name is None: # Anonynous struct + s += libxl_C_type_destroy(f.type, deref, False, "", deref) + else: + s += libxl_C_type_destroy(f.type, deref + f.name, False, "", deref) + else: + if ty.passby == libxltypes.PASS_BY_REFERENCE and not reference: + makeref = "&" + else: + makeref = "" + + if ty.destructor_fn is not None: + s += "%s(%s);\n" % (ty.destructor_fn, makeref + v) + + if s != "": + s = indent + s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + if __name__ == ''__main__'': - if len(sys.argv) < 3: - print >>sys.stderr, "Usage: gentypes.py <idl> <header>" + if len(sys.argv) < 4: + print >>sys.stderr, "Usage: gentypes.py <idl> <header> <implementation>" sys.exit(1) idl = sys.argv[1] (_,types) = libxltypes.parse(idl) header = sys.argv[2] - print "outputting libxl types to %s" % header + print "outputting libxl type definitions to %s" % header f = open(header, "w") @@ -84,8 +121,39 @@ if __name__ == ''__main__'': """ % " ".join(sys.argv)) - for t in types: - f.write(libxl_C_type_define(t) + ";\n") + for ty in types: + f.write(libxl_C_type_define(ty) + ";\n") + if ty.destructor_fn is not None: + f.write("void %s(%s *p);\n" % (ty.destructor_fn, ty.typename)) f.write("\n") f.write("""#endif /* __LIBXL_TYPES_H */\n""") + f.close() + + impl = sys.argv[3] + print "outputting libxl type implementations to %s" % impl + + f = open(impl, "w") + f.write(""" +/* DO NOT EDIT. + * + * This file is autogenerated by + * "%s" + */ + +#include "libxl_osdeps.h" + +#include <stdint.h> +#include <stdlib.h> + +#include "libxl.h" + +""" % " ".join(sys.argv)) + + for ty in [t for t in types if t.autogenerate_destructor]: + f.write("void %s(%s *p)\n" % (ty.destructor_fn, ty.typename)) + f.write("{\n") + f.write(libxl_C_type_destroy(ty, "p", True)) + f.write("}\n") + f.write("\n") + f.close() diff -r ec0d4b02e9c2 -r 1ee0c9db536b tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.c Wed Aug 18 16:01:17 2010 +0100 @@ -71,6 +71,33 @@ int libxl_ctx_free(libxl_ctx *ctx) do_free_version_info(&ctx->version_info); if (ctx->xsh) xs_daemon_close(ctx->xsh); return 0; +} + +void libxl_string_list_destroy(libxl_string_list sl) +{ + int i; + + if (!sl) + return; + + for (i = 0; sl[i] != NULL; i++) + free(sl[i]); + free(sl); +} + +void libxl_key_value_list_destroy(libxl_key_value_list kvl) +{ + int i; + + if (!kvl) + return; + + for (i = 0; kvl[i] != NULL; i += 2) { + free(kvl[i]); + if (kvl[i + 1]) + free(kvl[i + 1]); + } + free(kvl); } /******************************************************************************/ diff -r ec0d4b02e9c2 -r 1ee0c9db536b tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.h Wed Aug 18 16:01:17 2010 +0100 @@ -142,8 +142,10 @@ typedef uint8_t libxl_mac[6]; typedef uint8_t libxl_mac[6]; typedef char **libxl_string_list; +void libxl_string_list_destroy(libxl_string_list sl); typedef char **libxl_key_value_list; +void libxl_key_value_list_destroy(libxl_key_value_list kvl); typedef uint64_t *libxl_cpumap; diff -r ec0d4b02e9c2 -r 1ee0c9db536b tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 @@ -12,10 +12,10 @@ libxl_disk_phystype = Builtin("disk_phys 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_string_list = Builtin("string_list", destructor_fn="libxl_string_list_destroy") +libxl_key_value_list = Builtin("key_value_list", destructor_fn="libxl_key_value_list_destroy") -libxl_cpumap = Builtin("cpumap") +libxl_cpumap = Builtin("cpumap", destructor_fn="free") libxl_hwcap = Builtin("hwcap") diff -r ec0d4b02e9c2 -r 1ee0c9db536b tools/libxl/libxltypes.py --- a/tools/libxl/libxltypes.py Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxltypes.py Wed Aug 18 16:01:17 2010 +0100 @@ -1,9 +1,16 @@ import sys import sys + +PASS_BY_VALUE = 1 +PASS_BY_REFERENCE = 2 class Type(object): def __init__(self, typename, **kwargs): self.comment = kwargs.setdefault(''comment'', None) self.namespace = kwargs.setdefault(''namespace'', "libxl_") + + self.passby = kwargs.setdefault(''passby'', PASS_BY_VALUE) + if self.passby not in [PASS_BY_VALUE, PASS_BY_REFERENCE]: + raise ValueError if typename is None: # Anonymous type self.typename = None @@ -12,14 +19,23 @@ class Type(object): else: self.typename = self.namespace + typename + if self.typename is not None: + self.destructor_fn = kwargs.setdefault(''destructor_fn'', self.typename + "_destroy") + else: + self.destructor_fn = kwargs.setdefault(''destructor_fn'', None) + + self.autogenerate_destructor = kwargs.setdefault(''autogenerate_destructor'', True) + class Builtin(Type): """Builtin type""" def __init__(self, typename, **kwargs): + kwargs.setdefault(''destructor_fn'', None) Type.__init__(self, typename, **kwargs) class UInt(Type): def __init__(self, w, **kwargs): kwargs.setdefault(''namespace'', None) + kwargs.setdefault(''destructor_fn'', None) Type.__init__(self, "uint%d_t" % w, **kwargs) self.width = w @@ -27,6 +43,7 @@ class BitField(Type): class BitField(Type): def __init__(self, ty, w, **kwargs): kwargs.setdefault(''namespace'', None) + kwargs.setdefault(''destructor_fn'', None) Type.__init__(self, ty.typename, **kwargs) self.width = w @@ -63,10 +80,16 @@ class Aggregate(Type): class Struct(Aggregate): def __init__(self, name, fields, **kwargs): + kwargs.setdefault(''passby'', PASS_BY_REFERENCE) Aggregate.__init__(self, "struct", name, fields, **kwargs) class Union(Aggregate): def __init__(self, name, fields, **kwargs): + # Generally speaking some intelligence is required to free a + # union therefore any specific instance of this class will + # need to provide an explicit destructor function. + kwargs.setdefault(''passby'', PASS_BY_REFERENCE) + kwargs.setdefault(''destructor_fn'', None) Aggregate.__init__(self, "union", name, fields, **kwargs) class KeyedUnion(Aggregate): @@ -87,7 +110,14 @@ class Reference(Type): class Reference(Type): """A reference to another type""" def __init__(self, ty, **kwargs): + self.ref_type = ty + # Ugh + + kwargs.setdefault(''destructor_fn'', "free") + kwargs.setdefault(''autogenerate_destructor'', False) + kwargs.setdefault(''passby'', PASS_BY_VALUE) + kwargs.setdefault(''namespace'', ty.namespace) typename = ty.typename[len(kwargs[''namespace'']):] Type.__init__(self, typename + " *", **kwargs) @@ -112,7 +142,7 @@ uint64 = UInt(64) domid = UInt(32) -string = Builtin("char *", namespace = None) +string = Builtin("char *", namespace = None, destructor_fn = "free") inaddr_ip = Builtin("struct in_addr", namespace = None) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 06 of 16] libxl: libxl_device_console.build_state is const
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID 07a0a384e66898d530a6dc78ad2004ce5653dda7 # Parent 1ee0c9db536b4af2a8543a80d2a939a3b5ec76e7 libxl: libxl_device_console.build_state is const This field always refers to a libxl_domain_build_state structure which is managed already by the caller, therefore it is incorrect to free it as part of libxl_device_console_destroy. (arguably this field should be a copy of, not a reference too, the original) Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 1ee0c9db536b -r 07a0a384e668 tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 @@ -195,7 +195,7 @@ libxl_device_console = Struct("device_co ("domid", domid), ("devid", integer), ("consback", libxl_console_consback), - ("build_state", Reference(libxl_domain_build_state)), + ("build_state", Reference(libxl_domain_build_state), True), ("output", string), ]) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 07 of 16] libxl: build info bootloader{, _args} are not const
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID a02fd486972239cb17683f69dc8a506df21ef0d3 # Parent 07a0a384e66898d530a6dc78ad2004ce5653dda7 libxl: build info bootloader{,_args} are not const. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 07a0a384e668 -r a02fd4869722 tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 @@ -112,8 +112,8 @@ libxl_domain_build_info = Struct("domain ])), ("pv", "!%s", Struct(None, [("slack_memkb", uint32), - ("bootloader", string, True), - ("bootloader_args", string, True), + ("bootloader", string), + ("bootloader_args", string), ("cmdline", string), ("ramdisk", libxl_file_reference), ("features", string, True), _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 08 of 16] libxl: do not generate a destructor for data types which do not require one
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID 6315b60118071a50e53f1ce3d959528538ed665f # Parent a02fd486972239cb17683f69dc8a506df21ef0d3 libxl: do not generate a destructor for data types which do not require one libxl_dominfo, libxl_poolinfo, libxl_vminfo, libxl_domain_build_state, libxl_physinfo and libxl_sched_credit contain no members which require destruction so omit the auto generated destructor. As an exception continue to generate destructors for libxl_device_* and libxl_{devtype}* even if they have no interesting members so that all device types can be treated the same without special knowledge about the type contents being required. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r a02fd4869722 -r 6315b6011807 tools/libxl/gentypes.py --- a/tools/libxl/gentypes.py Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/gentypes.py Wed Aug 18 16:01:17 2010 +0100 @@ -150,7 +150,7 @@ if __name__ == ''__main__'': """ % " ".join(sys.argv)) - for ty in [t for t in types if t.autogenerate_destructor]: + for ty in [t for t in types if t.destructor_fn is not None and t.autogenerate_destructor]: f.write("void %s(%s *p)\n" % (ty.destructor_fn, ty.typename)) f.write("{\n") f.write(libxl_C_type_destroy(ty, "p", True)) diff -r a02fd4869722 -r 6315b6011807 tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 @@ -40,16 +40,16 @@ SHUTDOWN_* constant."""), ("cpu_time", uint64), ("vcpu_max_id", uint32), ("vcpu_online", uint32), - ]) + ], destructor_fn=None) libxl_poolinfo = Struct("poolinfo", [ ("poolid", uint32) - ]) + ], destructor_fn=None) libxl_vminfo = Struct("vminfo", [ ("uuid", libxl_uuid), ("domid", domid), - ]) + ], destructor_fn=None) libxl_version_info = Struct("version_info", [ ("xen_version_major", integer), @@ -132,7 +132,7 @@ libxl_domain_build_state = Struct("domai ("store_mfn", unsigned_long), ("console_port", uint32), ("console_mfn", unsigned_long), - ]) + ], destructor_fn=None) libxl_device_model_info = Struct("device_model_info",[ ("domid", integer), @@ -308,12 +308,12 @@ libxl_physinfo = Struct("physinfo", [ ("nr_nodes", uint32), ("hw_cap", libxl_hwcap), ("phys_cap", uint32), - ]) + ], destructor_fn=None) libxl_sched_credit = Struct("sched_credit", [ ("weight", integer), ("cap", integer), - ]) + ], destructor_fn=None) libxl_net2info = Struct("net2info", [ ("backend", string), _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 09 of 16] libxl: implement destroy for libxl_file_reference builtin type
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID 16a79a67cce31cc0697d1a5f2bcbabc948419001 # Parent 6315b60118071a50e53f1ce3d959528538ed665f libxl: implement destroy for libxl_file_reference builtin type As well as freeing data any file mappings need to be torn down so implement an explicit destroy function. Also the map and unmap function are internal to libxl so make that so. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 6315b6011807 -r 16a79a67cce3 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.c Wed Aug 18 16:01:17 2010 +0100 @@ -23,7 +23,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <sys/select.h> -#include <sys/mman.h> #include <sys/wait.h> #include <sys/time.h> #include <signal.h> @@ -340,9 +339,9 @@ int libxl_domain_build(libxl_ctx *ctx, l } ret = build_post(ctx, domid, info, state, vments, localents); out: - libxl_file_reference_unmap(ctx, &info->kernel); + libxl__file_reference_unmap(&info->kernel); if (!info->hvm) - libxl_file_reference_unmap(ctx, &info->u.pv.ramdisk); + libxl__file_reference_unmap(&info->u.pv.ramdisk); libxl_free_all(&gc); return ret; @@ -405,9 +404,9 @@ int libxl_domain_restore(libxl_ctx *ctx, } out: - libxl_file_reference_unmap(ctx, &info->kernel); + libxl__file_reference_unmap(&info->kernel); if (!info->hvm) - libxl_file_reference_unmap(ctx, &info->u.pv.ramdisk); + libxl__file_reference_unmap(&info->u.pv.ramdisk); esave = errno; @@ -3347,47 +3346,8 @@ int libxl_tmem_freeable(libxl_ctx *ctx) return rc; } -int libxl_file_reference_map(libxl_ctx *ctx, libxl_file_reference *f) +void libxl_file_reference_destroy(libxl_file_reference *f) { - struct stat st_buf; - int ret, fd; - void *data; - - if (f->mapped) - return 0; - - fd = open(f->path, O_RDONLY); - if (f < 0) - return ERROR_FAIL; - - ret = fstat(fd, &st_buf); - if (ret < 0) - goto out; - - ret = -1; - data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - if (data == NULL) - goto out; - - f->mapped = 1; - f->data = data; - f->size = st_buf.st_size; - - ret = 0; -out: - close(fd); - - return ret == 0 ? 0 : ERROR_FAIL; + libxl__file_reference_unmap(f); + free(f->path); } - -int libxl_file_reference_unmap(libxl_ctx *ctx, libxl_file_reference *f) -{ - int ret; - - if (!f->mapped) - return 0; - - ret = munmap(f->data, f->size); - - return ret == 0 ? 0 : ERROR_FAIL; -} diff -r 6315b6011807 -r 16a79a67cce3 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.h Wed Aug 18 16:01:17 2010 +0100 @@ -142,10 +142,8 @@ typedef uint8_t libxl_mac[6]; typedef uint8_t libxl_mac[6]; typedef char **libxl_string_list; -void libxl_string_list_destroy(libxl_string_list sl); typedef char **libxl_key_value_list; -void libxl_key_value_list_destroy(libxl_key_value_list kvl); typedef uint64_t *libxl_cpumap; @@ -235,8 +233,10 @@ int libxl_domain_destroy(libxl_ctx *ctx, int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid, int force); int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_info *info, const char *name_suffix, libxl_uuid new_uuid); -int libxl_file_reference_map(libxl_ctx *ctx, libxl_file_reference *f); -int libxl_file_reference_unmap(libxl_ctx *ctx, libxl_file_reference *f); +/* destructors for builtin data types */ +void libxl_string_list_destroy(libxl_string_list sl); +void libxl_key_value_list_destroy(libxl_key_value_list kvl); +void libxl_file_reference_destroy(libxl_file_reference *f); /* * Run the configured bootloader for a PV domain and update diff -r 6315b6011807 -r 16a79a67cce3 tools/libxl/libxl.idl --- a/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.idl Wed Aug 18 16:01:17 2010 +0100 @@ -85,7 +85,7 @@ mapped is true then the actual file may mapped is true then the actual file may already be unlinked."""), ("mapped", integer), ("data", void), - ("size", size_t)]) + ("size", size_t)], autogenerate_destructor=False) libxl_domain_build_info = Struct("domain_build_info",[ ("max_vcpus", integer), diff -r 6315b6011807 -r 16a79a67cce3 tools/libxl/libxl_bootloader.c --- a/tools/libxl/libxl_bootloader.c Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl_bootloader.c Wed Aug 18 16:01:17 2010 +0100 @@ -279,12 +279,12 @@ static void parse_bootloader_result(libx if (strncmp("kernel ", o, strlen("kernel ")) == 0) { free(info->kernel.path); info->kernel.path = strdup(o + strlen("kernel ")); - libxl_file_reference_map(ctx, &info->kernel); + libxl__file_reference_map(&info->kernel); unlink(info->kernel.path); } else if (strncmp("ramdisk ", o, strlen("ramdisk ")) == 0) { free(info->u.pv.ramdisk.path); info->u.pv.ramdisk.path = strdup(o + strlen("ramdisk ")); - libxl_file_reference_map(ctx, &info->u.pv.ramdisk); + libxl__file_reference_map(&info->u.pv.ramdisk); unlink(info->u.pv.ramdisk.path); } else if (strncmp("args ", o, strlen("args ")) == 0) { free(info->u.pv.cmdline); diff -r 6315b6011807 -r 16a79a67cce3 tools/libxl/libxl_internal.c --- a/tools/libxl/libxl_internal.c Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl_internal.c Wed Aug 18 16:01:17 2010 +0100 @@ -18,6 +18,12 @@ #include <stdio.h> #include <stdarg.h> #include <string.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <unistd.h> #include "libxl.h" #include "libxl_internal.h" @@ -185,3 +191,48 @@ char *libxl_abs_path(libxl_gc *gc, char return libxl_sprintf(gc, "%s/%s", path, s); } + +int libxl__file_reference_map(libxl_file_reference *f) +{ + struct stat st_buf; + int ret, fd; + void *data; + + if (f->mapped) + return 0; + + fd = open(f->path, O_RDONLY); + if (f < 0) + return ERROR_FAIL; + + ret = fstat(fd, &st_buf); + if (ret < 0) + goto out; + + ret = -1; + data = mmap(NULL, st_buf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + if (data == NULL) + goto out; + + f->mapped = 1; + f->data = data; + f->size = st_buf.st_size; + + ret = 0; +out: + close(fd); + + return ret == 0 ? 0 : ERROR_FAIL; +} + +int libxl__file_reference_unmap(libxl_file_reference *f) +{ + int ret; + + if (!f->mapped) + return 0; + + ret = munmap(f->data, f->size); + + return ret == 0 ? 0 : ERROR_FAIL; +} diff -r 6315b6011807 -r 16a79a67cce3 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl_internal.h Wed Aug 18 16:01:17 2010 +0100 @@ -274,4 +274,7 @@ struct libxl__xen_console_reader { _hidden int libxl_error_set(libxl_ctx *ctx, int code); +_hidden int libxl__file_reference_map(libxl_file_reference *f); +_hidden int libxl__file_reference_unmap(libxl_file_reference *f); + #endif _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 10 of 16] xl: free the libxl types contained in struct domain_config
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143677 -3600 # Node ID 5b79ae928eb160e14fc5376cae03ff83b0bfb024 # Parent 16a79a67cce31cc0697d1a5f2bcbabc948419001 xl: free the libxl types contained in struct domain_config Resolves the following leaks found using "valgrind xl create -n ..." (plus presumably others which didn''t trigger because I have no devices of that type) ==21241== 5 bytes in 1 blocks are definitely lost in loss record 1 of 6 ==21241== at 0x4022F0A: malloc (vg_replace_malloc.c:236) ==21241== by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so) ==21241== by 0x804E56B: parse_config_data (xl_cmdimpl.c:760) ==21241== by 0x8056B04: create_domain (xl_cmdimpl.c:1357) ==21241== by 0x8057ECE: main_create (xl_cmdimpl.c:3154) ==21241== by 0x804B2FB: main (xl.c:76) ==21241===21241== 6 bytes in 1 blocks are definitely lost in loss record 2 of 6 ==21241== at 0x4022F0A: malloc (vg_replace_malloc.c:236) ==21241== by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so) ==21241== by 0x804DAAA: parse_config_data (xl_cmdimpl.c:586) ==21241== by 0x8056B04: create_domain (xl_cmdimpl.c:1357) ==21241== by 0x8057ECE: main_create (xl_cmdimpl.c:3154) ==21241== by 0x804B2FB: main (xl.c:76) ==21241===21241== 24 bytes in 1 blocks are definitely lost in loss record 3 of 6 ==21241== at 0x4022F0A: malloc (vg_replace_malloc.c:236) ==21241== by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so) ==21241== by 0x804E51F: parse_config_data (xl_cmdimpl.c:754) ==21241== by 0x8056B04: create_domain (xl_cmdimpl.c:1357) ==21241== by 0x8057ECE: main_create (xl_cmdimpl.c:3154) ==21241== by 0x804B2FB: main (xl.c:76) ==21241===21241== 27 bytes in 1 blocks are definitely lost in loss record 4 of 6 ==21241== at 0x4022F0A: malloc (vg_replace_malloc.c:236) ==21241== by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so) ==21241== by 0x804DF4A: parse_config_data (xl_cmdimpl.c:664) ==21241== by 0x8056B04: create_domain (xl_cmdimpl.c:1357) ==21241== by 0x8057ECE: main_create (xl_cmdimpl.c:3154) ==21241== by 0x804B2FB: main (xl.c:76) ==21241===21241== 28 bytes in 1 blocks are definitely lost in loss record 5 of 6 ==21241== at 0x4022F0A: malloc (vg_replace_malloc.c:236) ==21241== by 0x410C1A7: vasprintf (in /lib/i686/cmov/libc-2.7.so) ==21241== by 0x40EE59A: asprintf (in /lib/i686/cmov/libc-2.7.so) ==21241== by 0x804CA8B: init_nic_info (xl_cmdimpl.c:322) ==21241== by 0x804E6FF: parse_config_data (xl_cmdimpl.c:791) ==21241== by 0x8056B04: create_domain (xl_cmdimpl.c:1357) ==21241== by 0x8057ECE: main_create (xl_cmdimpl.c:3154) ==21241== by 0x804B2FB: main (xl.c:76) ==21241===21241== 44 bytes in 1 blocks are definitely lost in loss record 6 of 6 ==21241== at 0x4022F0A: malloc (vg_replace_malloc.c:236) ==21241== by 0x411B22F: strdup (in /lib/i686/cmov/libc-2.7.so) ==21241== by 0x804E168: parse_config_data (xl_cmdimpl.c:694) ==21241== by 0x8056B04: create_domain (xl_cmdimpl.c:1357) ==21241== by 0x8057ECE: main_create (xl_cmdimpl.c:3154) ==21241== by 0x804B2FB: main (xl.c:76) Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 16a79a67cce3 -r 5b79ae928eb1 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:17 2010 +0100 @@ -144,12 +144,34 @@ struct domain_config { static void free_domain_config(struct domain_config *d_config) { + int i; + + for (i=0; i<d_config->num_disks; i++) + libxl_device_disk_destroy(&d_config->disks[i]); free(d_config->disks); + + for (i=0; i<d_config->num_vifs; i++) + libxl_device_nic_destroy(&d_config->vifs[i]); free(d_config->vifs); + + for (i=0; i<d_config->num_vif2s; i++) + libxl_device_net2_destroy(&d_config->vif2s[i]); free(d_config->vif2s); + + for (i=0; i<d_config->num_pcidevs; i++) + libxl_device_pci_destroy(&d_config->pcidevs[i]); free(d_config->pcidevs); + + for (i=0; i<d_config->num_vfbs; i++) + libxl_device_vfb_destroy(&d_config->vfbs[i]); free(d_config->vfbs); + + for (i=0; i<d_config->num_vkbs; i++) + libxl_device_vkb_destroy(&d_config->vkbs[i]); free(d_config->vkbs); + + libxl_domain_create_info_destroy(&d_config->c_info); + libxl_domain_build_info_destroy(&d_config->b_info); } /* Optional data, in order: @@ -309,7 +331,7 @@ static void init_nic_info(libxl_device_n nic_info->domid = 0; nic_info->devid = devnum; nic_info->mtu = 1492; - nic_info->model = "e1000"; + nic_info->model = strdup("e1000"); nic_info->mac[0] = 0x00; nic_info->mac[1] = 0x16; nic_info->mac[2] = 0x3e; @@ -317,7 +339,7 @@ static void init_nic_info(libxl_device_n nic_info->mac[4] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0))); nic_info->mac[5] = 1 + (int) (0xff * (rand() / (RAND_MAX + 1.0))); nic_info->ifname = NULL; - nic_info->bridge = "xenbr0"; + nic_info->bridge = strdup("xenbr0"); CHK_ERRNO( asprintf(&nic_info->script, "%s/vif-bridge", libxl_xen_script_dir_path()) ); nic_info->nictype = NICTYPE_IOEMU; @@ -796,6 +818,7 @@ static void parse_config_data(const char break; *p2 = ''\0''; if (!strcmp(p, "model")) { + free(nic->model); nic->model = strdup(p2 + 1); } else if (!strcmp(p, "mac")) { char *p3 = p2 + 1; @@ -817,6 +840,7 @@ static void parse_config_data(const char *(p3 + 2) = ''\0''; nic->mac[5] = strtol(p3, NULL, 16); } else if (!strcmp(p, "bridge")) { + free(nic->bridge); nic->bridge = strdup(p2 + 1); } else if (!strcmp(p, "type")) { if (!strcmp(p2 + 1, "ioemu")) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 11 of 16] libxl: use libxl_version_info_destroy instead of hand-coded do_free_version_info
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143678 -3600 # Node ID db45826441cd0333a747303155f6c8bfe01b1ca5 # Parent 5b79ae928eb160e14fc5376cae03ff83b0bfb024 libxl: use libxl_version_info_destroy instead of hand-coded do_free_version_info Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 5b79ae928eb1 -r db45826441cd tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Aug 18 16:01:17 2010 +0100 +++ b/tools/libxl/libxl.c Wed Aug 18 16:01:18 2010 +0100 @@ -63,11 +63,10 @@ int libxl_ctx_init(libxl_ctx *ctx, int v return 0; } -static void do_free_version_info(libxl_version_info *info); int libxl_ctx_free(libxl_ctx *ctx) { xc_interface_close(ctx->xch); - do_free_version_info(&ctx->version_info); + libxl_version_info_destroy(&ctx->version_info); if (ctx->xsh) xs_daemon_close(ctx->xsh); return 0; } @@ -2848,18 +2847,6 @@ int libxl_get_physinfo(libxl_ctx *ctx, l return 0; } -static void do_free_version_info(libxl_version_info *info) -{ - free(info->xen_version_extra); - free(info->compiler); - free(info->compile_by); - free(info->compile_domain); - free(info->compile_date); - free(info->capabilities); - free(info->changeset); - free(info->commandline); -} - const libxl_version_info* libxl_get_version_info(libxl_ctx *ctx) { union { _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 12 of 16] xl: destroy device model info after creation
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143678 -3600 # Node ID 893c1c066ce97cb56cdc4498f95f243163c1e056 # Parent db45826441cd0333a747303155f6c8bfe01b1ca5 xl: destroy device model info after creation Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r db45826441cd -r 893c1c066ce9 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 @@ -1624,6 +1624,8 @@ out: if (logfile != 2) close(logfile); + libxl_device_model_info_destroy(&dm_info); + free_domain_config(&d_config); free(config_data); _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 13 of 16] libxl/xl: use libxl_diskinfo_destroy and libxl_device_disk_destroy
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143678 -3600 # Node ID 96473378234f500d368fa5afe8230d608272b852 # Parent 893c1c066ce97cb56cdc4498f95f243163c1e056 libxl/xl: use libxl_diskinfo_destroy and libxl_device_disk_destroy Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 893c1c066ce9 -r 96473378234f tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/libxl.c Wed Aug 18 16:01:18 2010 +0100 @@ -1347,8 +1347,8 @@ static char ** libxl_build_device_model_ flexarray_set(dm_args, num++, libxl_sprintf(gc, "-%s", disks[i].virtpath)); flexarray_set(dm_args, num++, disks[i].physpath); } + libxl_device_disk_destroy(&disks[i]); } - /* FIXME: leaks disk paths */ free(disks); flexarray_set(dm_args, num++, NULL); return (char **) flexarray_contents(dm_args); @@ -2554,6 +2554,7 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u int num, i; uint32_t stubdomid; libxl_device_disk *disks; + int ret = ERROR_FAIL; if (!disk->physpath) { disk->physpath = ""; @@ -2567,9 +2568,11 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u } if (i == num) { XL_LOG(ctx, XL_LOG_ERROR, "Virtual device not found"); - free(disks); - return ERROR_FAIL; + goto out; } + + ret = 0; + libxl_device_disk_del(ctx, disks + i, 1); libxl_device_disk_add(ctx, domid, disk); stubdomid = libxl_get_stubdom_id(ctx, domid); @@ -2580,9 +2583,11 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u libxl_device_disk_add(ctx, stubdomid, disk); disk->domid = domid; } - /* FIXME: leaks disk paths */ +out: + for (i = 0; i < num; i++) + libxl_device_disk_destroy(&disks[i]); free(disks); - return 0; + return ret; } /******************************************************************************/ diff -r 893c1c066ce9 -r 96473378234f tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 @@ -4261,7 +4261,7 @@ int main_blocklist(int argc, char **argv int main_blocklist(int argc, char **argv) { int opt; - int nb; + int i, nb; libxl_device_disk *disks; libxl_diskinfo diskinfo; @@ -4291,14 +4291,17 @@ int main_blocklist(int argc, char **argv if (!disks) { continue; } - for (; nb > 0; --nb, ++disks) { - if (!libxl_device_disk_getinfo(&ctx, domid, disks, &diskinfo)) { + for (i=0; i<nb; i++) { + if (!libxl_device_disk_getinfo(&ctx, domid, &disks[i], &diskinfo)) { /* Vdev BE hdl st evch rref BE-path*/ printf("%-5d %-3d %-6d %-5d %-6d %-8d %-30s\n", diskinfo.devid, diskinfo.backend_id, diskinfo.frontend_id, diskinfo.state, diskinfo.evtch, diskinfo.rref, diskinfo.backend); - } - } + libxl_diskinfo_destroy(&diskinfo); + } + libxl_device_disk_destroy(&disks[i]); + } + free(disks); } return 0; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 14 of 16] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143678 -3600 # Node ID 9dfdd32ce1282c4f9ca38e8735dd2cea97d39b19 # Parent 96473378234f500d368fa5afe8230d608272b852 libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy Replaces libxl_free_nics_list diff -r 96473378234f -r 9dfdd32ce128 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/libxl.c Wed Aug 18 16:01:18 2010 +0100 @@ -2039,17 +2039,6 @@ int libxl_device_nic_del(libxl_ctx *ctx, return libxl_device_del(ctx, &device, wait); } -void libxl_free_nics_list(libxl_nicinfo *nics, unsigned int nb) -{ - unsigned int i; - for(i = 0; i < nb; i++) { - free(nics[i].backend); - free(nics[i].frontend); - free(nics[i].script); - } - free(nics); -} - libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb) { libxl_gc gc = LIBXL_INIT_GC(ctx); diff -r 96473378234f -r 9dfdd32ce128 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/libxl.h Wed Aug 18 16:01:18 2010 +0100 @@ -373,7 +373,6 @@ int libxl_device_nic_add(libxl_ctx *ctx, int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); int libxl_device_nic_del(libxl_ctx *ctx, libxl_device_nic *nic, int wait); libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb); -void libxl_free_nics_list(libxl_nicinfo *nics, unsigned int nb); int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_console *console); diff -r 96473378234f -r 9dfdd32ce128 tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/libxl_utils.c Wed Aug 18 16:01:18 2010 +0100 @@ -405,42 +405,44 @@ int libxl_mac_to_device_nic(libxl_ctx *c int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid, const char *mac, libxl_device_nic *nic) { - libxl_nicinfo *nics, *list; - unsigned int nb, i, j; + libxl_nicinfo *nics; + unsigned int nb, i; + int found; uint8_t mac_n[6]; uint8_t *a, *b; const char *tok; char *endptr; - list = nics = libxl_list_nics(ctx, domid, &nb); - if (!nics) { + nics = libxl_list_nics(ctx, domid, &nb); + if (!nics) return ERROR_FAIL; - } for (i = 0, tok = mac; *tok && (i < 6); ++i, tok += 3) { mac_n[i] = strtol(tok, &endptr, 16); - if (endptr != (tok + 2)) { + if (endptr != (tok + 2)) return ERROR_INVAL; - } } memset(nic, 0, sizeof (libxl_device_nic)); - for (j = 0; j < nb; ++j, ++nics) { - for (i = 0, a = nics->mac, b = mac_n; + found = 0; + for (i = 0; i < nb; ++i) { + for (i = 0, a = nics[i].mac, b = mac_n; (b < mac_n + 6) && (*a == *b); ++a, ++b) ; if ((b >= mac_n + 6) && (*a == *b)) { - nic->backend_domid = nics->backend_id; - nic->domid = nics->frontend_id; - nic->devid = nics->devid; - memcpy(nic->mac, nics->mac, sizeof (nic->mac)); - nic->script = nics->script; - libxl_free_nics_list(list, nb); - return 0; + nic->backend_domid = nics[i].backend_id; + nic->domid = nics[i].frontend_id; + nic->devid = nics[i].devid; + memcpy(nic->mac, nics[i].mac, sizeof (nic->mac)); + nic->script = strdup(nics[i].script); + found = 1; + break; } } - libxl_free_nics_list(list, nb); - return 0; + for (i=0; i<nb; i++) + libxl_nicinfo_destroy(&nics[i]); + free(nics); + return found; } int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid, @@ -472,8 +474,7 @@ int libxl_devid_to_device_nic(libxl_ctx ++i, tok = strtok(NULL, ":")) { nic->mac[i] = strtoul(tok, NULL, 16); } - nic->script = libxl_xs_read(&gc, XBT_NULL, - libxl_sprintf(&gc, "%s/script", nic_path_be)); + nic->script = xs_read(ctx->xsh, XBT_NULL, libxl_sprintf(&gc, "%s/script", nic_path_be), NULL); rc = 0; out: libxl_free_all(&gc); diff -r 96473378234f -r 9dfdd32ce128 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 @@ -4091,13 +4091,14 @@ int main_networkattach(int argc, char ** fprintf(stderr, "libxl_device_nic_add failed.\n"); return 1; } + libxl_device_nic_destroy(&nic); return 0; } int main_networklist(int argc, char **argv) { int opt; - libxl_nicinfo *nics, *list; + libxl_nicinfo *nics; unsigned int nb, i; if (argc < 3) { @@ -4123,22 +4124,23 @@ int main_networklist(int argc, char **ar fprintf(stderr, "%s is an invalid domain identifier\n", *argv); continue; } - if (!(list = nics = libxl_list_nics(&ctx, domid, &nb))) { - continue; - } - for (i = 0; i < nb; ++i, ++nics) { + if (!(nics = libxl_list_nics(&ctx, domid, &nb))) { + continue; + } + for (i = 0; i < nb; ++i) { /* Idx BE */ - printf("%-3d %-2d ", nics->devid, nics->backend_id); + printf("%-3d %-2d ", nics[i].devid, nics[i].backend_id); /* MAC */ printf("%02x:%02x:%02x:%02x:%02x:%02x ", - nics->mac[0], nics->mac[1], nics->mac[2], - nics->mac[3], nics->mac[4], nics->mac[5]); + nics[i].mac[0], nics[i].mac[1], nics[i].mac[2], + nics[i].mac[3], nics[i].mac[4], nics[i].mac[5]); /* Hdl Sta evch txr/rxr BE-path */ printf("%6d %5d %6d %5d/%-11d %-30s\n", - nics->devid, nics->state, nics->evtch, - nics->rref_tx, nics->rref_rx, nics->backend); - } - libxl_free_nics_list(list, nb); + nics[i].devid, nics[i].state, nics[i].evtch, + nics[i].rref_tx, nics[i].rref_rx, nics[i].backend); + libxl_nicinfo_destroy(&nics[i]); + } + free(nics); } return 0; } @@ -4183,6 +4185,7 @@ int main_networkdetach(int argc, char ** fprintf(stderr, "libxl_device_nic_del failed.\n"); return 1; } + libxl_device_nic_destroy(&nic); return 0; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 15 of 16] libxl/xl: Use libxl_vcpuinfo_destroy
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143678 -3600 # Node ID 59783ebb23f5107c6984c93c413744d8f47e316a # Parent 9dfdd32ce1282c4f9ca38e8735dd2cea97d39b19 libxl/xl: Use libxl_vcpuinfo_destroy Replaces libxl_free_vcpu_list. The ->cpumap field is now always a unique allocation rather than each being an offset into the cpumap allocated in the first libxl_device_pci in the list. Refactor vcpulist so that the two cases can share more code. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 9dfdd32ce128 -r 59783ebb23f5 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/libxl.c Wed Aug 18 16:01:18 2010 +0100 @@ -2894,7 +2894,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct xc_domaininfo_t domaininfo; xc_vcpuinfo_t vcpuinfo; xc_physinfo_t physinfo = { 0 }; - uint64_t *cpumaps; unsigned num_cpuwords; if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) { @@ -2912,9 +2911,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct } num_cpuwords = ((physinfo.max_cpu_id + 64) / 64); - cpumaps = calloc(num_cpuwords * sizeof(*cpumaps), domaininfo.max_vcpu_id + 1); for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) { - ptr->cpumap = cpumaps + (num_cpuwords * *nb_vcpu); + ptr->cpumap = malloc(num_cpuwords * sizeof(*ptr->cpumap)); if (!ptr->cpumap) { return NULL; } @@ -2935,13 +2933,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct ptr->vcpu_time = vcpuinfo.cpu_time; } return ret; -} - -void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu) -{ - if ( vcpu ) - free(vcpu[0].cpumap); - free(vcpu); } int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, diff -r 9dfdd32ce128 -r 59783ebb23f5 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/libxl.h Wed Aug 18 16:01:18 2010 +0100 @@ -432,7 +432,6 @@ int libxl_get_physinfo(libxl_ctx *ctx, l int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo); libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid, int *nb_vcpu, int *nrcpus); -void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu); int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid, uint64_t *cpumap, int nrcpus); int libxl_set_vcpucount(libxl_ctx *ctx, uint32_t domid, uint32_t count); diff -r 9dfdd32ce128 -r 59783ebb23f5 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 @@ -3301,49 +3301,58 @@ static void print_vcpuinfo(uint32_t tdom } } +static void print_domain_vcpuinfo(uint32_t domid, uint32_t nr_cpus) +{ + libxl_vcpuinfo *vcpuinfo; + int i, nb_vcpu, nrcpus; + + vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus); + + if (!vcpuinfo) { + fprintf(stderr, "libxl_list_vcpu failed.\n"); + return; + } + + for (i = 0; i < nb_vcpu; i++) { + print_vcpuinfo(domid, &vcpuinfo[i], nr_cpus); + libxl_vcpuinfo_destroy(&vcpuinfo[i]); + } + + free(vcpuinfo); +} + static void vcpulist(int argc, char **argv) { - libxl_dominfo *dominfo, *domlist; - libxl_vcpuinfo *vcpuinfo, *list = NULL; + libxl_dominfo *dominfo; libxl_physinfo physinfo; - int nb_vcpu, nb_domain, nrcpus; + int i, nb_domain; if (libxl_get_physinfo(&ctx, &physinfo) != 0) { fprintf(stderr, "libxl_physinfo failed.\n"); goto vcpulist_out; } + printf("%-32s %5s %5s %5s %5s %9s %s\n", "Name", "ID", "VCPU", "CPU", "State", "Time(s)", "CPU Affinity"); if (!argc) { - if (!(domlist = dominfo = libxl_list_domain(&ctx, &nb_domain))) { + if (!(dominfo = libxl_list_domain(&ctx, &nb_domain))) { fprintf(stderr, "libxl_list_domain failed.\n"); goto vcpulist_out; } - for (; nb_domain > 0; --nb_domain, ++dominfo) { - if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid, &nb_vcpu, - &nrcpus))) { - fprintf(stderr, "libxl_list_vcpu failed.\n"); - goto vcpulist_out; - } - for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) { - print_vcpuinfo(dominfo->domid, vcpuinfo, physinfo.nr_cpus); - } - libxl_free_vcpu_list(list); - } - free(domlist); + + for (i = 0; i<nb_domain; i++) + print_domain_vcpuinfo(dominfo[i].domid, physinfo.nr_cpus); + + free(dominfo); + } else { for (; argc > 0; ++argv, --argc) { if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) { fprintf(stderr, "%s is an invalid domain identifier\n", *argv); - } - if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus))) { - fprintf(stderr, "libxl_list_vcpu failed.\n"); goto vcpulist_out; } - for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) { - print_vcpuinfo(domid, vcpuinfo, physinfo.nr_cpus); - } - libxl_free_vcpu_list(list); + + print_domain_vcpuinfo(domid, physinfo.nr_cpus); } } vcpulist_out: _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell
2010-Aug-18 15:44 UTC
[Xen-devel] [PATCH 16 of 16] xl: use libxl_device_pci_destroy
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1282143678 -3600 # Node ID e3baac77b53cc611ba3e7bcc8f73ba341433b0ff # Parent 59783ebb23f5107c6984c93c413744d8f47e316a xl: use libxl_device_pci_destroy Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 59783ebb23f5 -r e3baac77b53c tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Aug 18 16:01:18 2010 +0100 @@ -2010,6 +2010,7 @@ static void pcilist(char *dom) printf("VFn domain bus slot func\n"); for (i = 0; i < num; i++) { printf("0x%02x 0x%04x 0x%02x 0x%02x 0x%01x\n", pcidevs[i].vdevfn, pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, pcidevs[i].func); + libxl_device_pci_destroy(&pcidevs[i]); } free(pcidevs); } @@ -2052,6 +2053,7 @@ static void pcidetach(char *dom, char *b exit(2); } libxl_device_pci_remove(&ctx, domid, &pcidev); + libxl_device_pci_destroy(&pcidev); } int main_pcidetach(int argc, char **argv) @@ -2092,6 +2094,7 @@ static void pciattach(char *dom, char *b exit(2); } libxl_device_pci_add(&ctx, domid, &pcidev); + libxl_device_pci_destroy(&pcidev); } int main_pciattach(int argc, char **argv) _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Apparently Analagous Threads
- [PATCH 0 of 3] libxl: cleanups for type destructor generation
- [PATCH 09/11] add iomem support to libxl
- [PATCH]: add libxl python binding
- [PATCH v4 1/2] libxl: postpone backend name resolution
- [PATCH] libxl: do not overwrite user supplied config when running bootloader