libxl: JSON infrastructure, fixes and prerequisite patches for new API
v6 cover libxl: JSON infrastructure, fixes and prerequisite patches for new API
This series contains prerequisite patches to build the new libxl API called libxl_retrieve_domain_configuration. The design and implementation of that new API is being discussed at the moment. I think it's worthwhile to send out these prerequisite patches to reduce the length of patchset.
This patch series contains 3 types of patches
1. push some configuration handling logic from xl to libxl
2. bugfix for JSON generator
3. JSON infrastructure: change to generator, introduce parser, introduce deep copy functions
For previous posting please refer to
<[email protected]>
Legend:
A - acked
M - minor changes like commit message, coding style, comment in code etc C - changed since last version
S - no change since last version, just reposting
Wei.
Wei Liu (18):
A libxl: make cpupool_qualifier_to_cpupoolid a library function S xl / libxl: push parsing of SSID and CPU pool ID down to libxl C xl / libxl: push VCPU affinity pinning down to libxl
M libxl: libxl_uuid_copy now takes a ctx argument
A xl: remove parsing of "vncviewer" option in xl domain config file M libxl: fix JSON generator for uint64_t
A libxl IDL: rename json_fn to json_gen_fn
A libxl_json: introduce libxl__object_from_json
A libxl_json: introduce parser functions for builtin types M libxl/gentypes.py: special-case KeyedUnion map handle generation C libxl/gentypes.py: don't generate default values
C libxl IDL: generate code to parse libxl__json_object to libxl_FOO
struct
A libxl/gentest.py: test JSON parser
A libxl: introduce libxl_key_value_list_length
A libxl: introduce libxl_cpuid_policy_list_length
A libxl: copy function for builtin types
A libxl IDL: generate deep copy functions
A libxl/gentest.py: test deep copy functions
docs/man/xl.cfg.pod.5 | 4 - tools/libxl/gentest.py | 64 ++++++- tools/libxl/gentypes.py | 259 +++++++++++++++++++++++++-- tools/libxl/idl.py | 43 ++++- tools/libxl/idl.txt | 21 ++- tools/libxl/libxl.c | 101 ++++++++++- tools/libxl/libxl.h | 85 ++++++++- tools/libxl/libxl_cpuid.c | 135 ++++++++++++-- tools/libxl/libxl_create.c | 59 ++++++- tools/libxl/libxl_dm.c | 4 + tools/libxl/libxl_dom.c | 14 ++ tools/libxl/libxl_internal.h | 8 + tools/libxl/libxl_json.c | 322 ++++++++++++++++++++++++++++++++++ tools/libxl/libxl_json.h | 37 +++- tools/libxl/libxl_nocpuid.c | 13 ++ tools/libxl/libxl_types.idl | 48 +++-- tools/libxl/libxl_types_internal.idl | 4 +- tools/libxl/libxl_utils.c | 58 +++++- tools/libxl/libxl_utils.h | 7 + tools/libxl/libxl_uuid.c | 8 +- tools/libxl/libxl_uuid.h | 7 +- tools/libxl/xl_cmdimpl.c | 239 +++++++------------------ tools/libxl/xl_sxp.c | 7 +- 23 files changed, 1288 insertions(+), 259 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v6 1/18 libxl: make cpupool_qualifier_to_cpupoolid a library function
--- tools/libxl/libxl.h | 9 +++++++++ tools/libxl/libxl_utils.c | 31 ++++++++++++++++++++++++++++ tools/libxl/libxl_utils.h | 3 +++ tools/libxl/xl_cmdimpl.c | 49 +++++++++------------------------------------ 4 files changed, 52 insertions(+), 40 deletions(-)
tools/libxl/libxl.h +9 -0
@@ -67,6 +67,15 @@* the same $(XEN_VERSION) (e.g. throughout a major release). */ +/* LIBXL_HAVE_CPUPOOL_QUALIFIER_TO_CPUPOOLID +* +* If this is defined, libxl has a library function called +* libxl_cpupool_qualifier_to_cpupoolid, which takes in a CPU pool +* qualifier in the form of number or string, then returns the ID of +* that CPU pool. +*/ +#define LIBXL_HAVE_CPUPOOL_QUALIFIER_TO_CPUPOOLID 1 +/* * LIBXL_HAVE_FIRMWARE_PASSTHROUGH indicates the feature for * passing in SMBIOS and ACPI firmware to HVM guests is present
tools/libxl/libxl_utils.c +31 -0
@@ -108,6 +108,37 @@ int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const char *name,return rv; } +static int qualifier_to_id (const char *p,uint32_t *id_r) +{ +int i, alldigit; + + alldigit =1 ; +for (i =0 ; p[i]; i++) { +if (!isdigit ((uint8_t )p[i])) { + alldigit =0 ; +break ; + } + } + +if (i >0 && alldigit) { + *id_r =strtoul (p,NULL ,10 ); +return 0 ; + }else { +/* check here if it's a uuid and do proper conversion */ + } +return 1 ; +} + +int libxl_cpupool_qualifier_to_cpupoolid (libxl_ctx *ctx,const char *p, +uint32_t *poolid_r, +int *was_name_r) +{ +int was_name; + + was_name =qualifier_to_id (p, poolid_r); +if (was_name_r) *was_name_r = was_name; +return was_name ?libxl_name_to_cpupoolid (ctx, p, poolid_r) :0 ; +}char *libxl_cpupoolid_to_name (libxl_ctx *ctx,uint32_t poolid) {
tools/libxl/libxl_utils.h +3 -0
@@ -23,6 +23,9 @@ unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsignedint libxl_name_to_domid (libxl_ctx *ctx,const char *name,uint32_t *domid);int libxl_domain_qualifier_to_domid (libxl_ctx *ctx,const char *name,uint32_t *domid);char *libxl_domid_to_name (libxl_ctx *ctx,uint32_t domid); +int libxl_cpupool_qualifier_to_cpupoolid (libxl_ctx *ctx,const char *p, +uint32_t *poolid_r, +int *was_name_r);int libxl_name_to_cpupoolid (libxl_ctx *ctx,const char *name,uint32_t *poolid);char *libxl_cpupoolid_to_name (libxl_ctx *ctx,uint32_t poolid);int libxl_cpupoolid_is_valid (libxl_ctx *ctx,uint32_t poolid);
tools/libxl/xl_cmdimpl.c +9 -40
103 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v6 2/18 xl / libxl: push parsing of SSID and CPU pool ID down to libxl
In reply to Wei LiuThis patch pushes parsing of "init_seclabel", "seclabel", "device_model_stubdomain_seclabel" and "pool" down to libxl level.
Originally the parsing is done in xl level, which is not ideal because libxl won't have the truely relevant information. With this patch libxl holds important information by itself.
The libxl IDL is extended to hold the string of labels and pool name. And if there those strings are present they take precedence over the numeric representations.
As all relevant structures have a field called X_name / X_label now, a string is also copied there so that we can use it directly. In order to be compatible with users of older versions of libxl, this patch also defines LIBXL_HAVE_SSID_LABEL and LIBXL_HAVE_CPUPOOL_NAME. If they are defined, the respective strings are available. And if those strings are not NULL, libxl will do the parsing and ignore the numeric values.
--- tools/libxl/libxl.c | 19 ++++++-- tools/libxl/libxl.h | 20 ++++++++ tools/libxl/libxl_create.c | 57 +++++++++++++++++++++++ tools/libxl/libxl_dm.c | 4 ++ tools/libxl/libxl_types.idl | 6 +++ tools/libxl/xl_cmdimpl.c | 107 ++++++++++++------------------------------- tools/libxl/xl_sxp.c | 7 +-- 7 files changed, 134 insertions(+), 86 deletions(-)
tools/libxl/libxl.c +15 -4
@@ -516,12 +516,18 @@ int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid,return 0 ; } -static void xcinfo2xlinfo (const xc_domaininfo_t *xcinfo, +static void xcinfo2xlinfo (libxl_ctx *ctx, +const xc_domaininfo_t *xcinfo,libxl_dominfo *xlinfo) { +size_t size; +memcpy (&(xlinfo->uuid), xcinfo->handle,sizeof (xen_domain_handle_t)); xlinfo->domid = xcinfo->domain; xlinfo->ssidref = xcinfo->ssidref; +if (libxl_flask_sid_to_context (ctx, xlinfo->ssidref, + &xlinfo->ssid_label, &size) <0 ) + xlinfo->ssid_label =NULL ; xlinfo->dying = !!(xcinfo->flags&XEN_DOMINF_dying); xlinfo->shutdown = !!(xcinfo->flags&XEN_DOMINF_shutdown);
@@ -568,7 +574,7 @@ libxl_dominfo * libxl_list_domain(libxl_ctx *ctx, int *nb_domain_out) }for (i =0 ; i < ret; i++) { -xcinfo2xlinfo (&info[i], &ptr[i]); +xcinfo2xlinfo (ctx, &info[i], &ptr[i]); } *nb_domain_out = ret;return ptr;
@@ -587,7 +593,7 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *info_r,if (ret==0 || xcinfo.domain != domid)return ERROR_INVAL ;if (info_r) -xcinfo2xlinfo (&xcinfo, info_r); +xcinfo2xlinfo (ctx, &xcinfo, info_r);return 0 ; }
@@ -615,6 +621,11 @@ static int cpupool_info(libxl__gc *gc, } info->poolid = xcinfo->cpupool_id; + info->pool_name =libxl_cpupoolid_to_name (CTX , info->poolid); +if (!info->pool_name) { + rc =ERROR_FAIL ; + goto out; + } info->sched = xcinfo->sched_id; info->n_dom = xcinfo->n_dom; rc =libxl_cpu_bitmap_alloc (CTX , &info->cpumap,0 );
@@ -4159,7 +4170,7 @@ retry_transaction: abort_transaction =1 ; goto out; } -xcinfo2xlinfo (&info, &ptr); +xcinfo2xlinfo (ctx, &info, &ptr); uuid =libxl__uuid2string (gc, ptr.uuid);libxl__xs_write (gc, t,libxl__sprintf (gc,"/vm/%s/memory" , uuid),"%" PRIu32, new_target_memkb /1024 );
tools/libxl/libxl.h +20 -0
@@ -498,6 +498,26 @@#define LIBXL_EXTERNAL_CALLERS_ONLY /* disappears for callers outside libxl */ #endif +/* +* LIBXL_HAVE_SSID_LABEL +* +* If this is defined, then libxl IDL contains string of XSM security +* label in all XSM related structures. +* +* If set this string takes precedence over the numeric field. +*/ +#define LIBXL_HAVE_SSID_LABEL 1 + +/* +* LIBXL_HAVE_CPUPOOL_NAME +* +* If this is defined, then libxl IDL contains string of CPU pool +* name in all CPU pool related structures. +* +* If set this string takes precedence over the numeric field. +*/ +#define LIBXL_HAVE_CPUPOOL_NAME 1 +typedef uint8_t libxl_mac [6 ];#define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"#define LIBXL_MAC_FMTLEN ((2*6)+5)/* 6 hex bytes plus 5 colons */
tools/libxl/libxl_create.c +57 -0
63 lines not on this page · raw message
tools/libxl/libxl_dm.c +4 -0
@@ -910,7 +910,11 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) dm_config->c_info.type =LIBXL_DOMAIN_TYPE_PV ; dm_config->c_info.name =libxl__stub_dm_name (gc,libxl__domid_to_name (gc, guest_domid)); +/* When we are here to launch stubdom, ssidref is a valid value +* already, no need to parse it again. +*/ dm_config->c_info.ssidref = guest_config->b_info.device_model_ssidref; + dm_config->c_info.ssid_label =NULL ;libxl_uuid_generate (&dm_config->c_info.uuid);
tools/libxl/libxl_types.idl +6 -0
@@ -215,6 +215,7 @@ libxl_dominfo = Struct("dominfo",[ ("uuid", libxl_uuid), ("domid", libxl_domid), ("ssidref", uint32), + ("ssid_label", string), ("running", bool), ("blocked", bool), ("paused", bool),
@@ -240,6 +241,7 @@ libxl_dominfo = Struct("dominfo",[ libxl_cpupoolinfo = Struct("cpupoolinfo", [ ("poolid", uint32), + ("pool_name", string), ("sched", libxl_scheduler), ("n_dom", uint32), ("cpumap", libxl_bitmap)
@@ -270,11 +272,13 @@ libxl_domain_create_info = Struct("domain_create_info",[ ("hap", libxl_defbool), ("oos", libxl_defbool), ("ssidref", uint32), + ("ssid_label", string), ("name", string), ("uuid", libxl_uuid), ("xsdata", libxl_key_value_list), ("platformdata", libxl_key_value_list), ("poolid", uint32), + ("pool_name", string), ("run_hotplug_scripts",libxl_defbool), ("pvh", libxl_defbool), ("driver_domain",libxl_defbool),
@@ -309,6 +313,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("shadow_memkb", MemKB), ("rtc_timeoffset", uint32), ("exec_ssidref", uint32), + ("exec_ssid_label", string), ("localtime", libxl_defbool), ("disable_migrate", libxl_defbool), ("cpuid", libxl_cpuid_policy_list),
@@ -319,6 +324,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ # if you set device_model you must set device_model_version too ("device_model", string), ("device_model_ssidref", uint32), + ("device_model_ssid_label", string), # extra parameters pass directly to qemu, NULL terminated ("extra", libxl_string_list),
tools/libxl/xl_cmdimpl.c +30 -77
141 lines not on this page · raw message
tools/libxl/xl_sxp.c +2 -5
@@ -37,7 +37,6 @@ void printf_info_sexp(int domid, libxl_domain_config *d_config)libxl_domain_create_info *c_info = &d_config->c_info;libxl_domain_build_info *b_info = &d_config->b_info; -char *pool;printf ("(domain\n\t(domid %d)\n" , domid);printf ("\t(create_info)\n" );
@@ -55,10 +54,8 @@ void printf_info_sexp(int domid, libxl_domain_config *d_config) }else {printf ("\t(uuid <unknown>)\n" ); } - pool =libxl_cpupoolid_to_name (ctx, c_info->poolid); -if (pool) -printf ("\t(cpupool %s)\n" , pool); -free (pool); +if (c_info->pool_name) +printf ("\t(cpupool %s)\n" , c_info->pool_name);if (c_info->xsdata)printf ("\t(xsdata contains data)\n" );else
Signature · 1 line
1.7.10.4
Re: [PATCH v6 02/18] xl / libxl: push parsing of SSID and CPU pool ID down to libxl
Quoted 7 lines · Wei Liu
This patch pushes parsing of "
init_seclabel", "seclabel", "device_model_stubdomain_seclabel" and "pool" down to libxl level.Originally the parsing is done in xl level, which is not ideal because libxl won't have the truely relevant information. With this patch libxl holds important information by itself.
Quoted 6 lines
The libxl IDL is extended to hold the string of labels and pool name. And if there those strings are present they take precedence over the numeric representations.
As all relevant structures have a field called
X_name/X_labelnow, a string is also copied there so that we can use it directly.
I'm not sure what you mean by this. Do you mean that if the caller uses the numeric and not the string version we will populate the string side?
Quoted 10 lines
In order to
be compatible with users of older versions of libxl, this patch also definesLIBXL_HAVE_SSID_LABELandLIBXL_HAVE_CPUPOOL_NAME. If they are defined, the respective strings are available. And if those strings are not NULL, libxl will do the parsing and ignore the numeric values.Signed-off-by Wei Liu <[email protected]>Cc Dario Faggioli <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel De Graaf <[email protected]>
(I switched to Juergen's new address in the CC)
Quoted 21 lines
--- tools/libxl/libxl.c | 19 ++++++-- tools/libxl/libxl.h | 20 ++++++++ tools/libxl/libxl_create.c | 57 +++++++++++++++++++++++ tools/libxl/libxl_dm.c | 4 ++ tools/libxl/libxl_types.idl | 6 +++ tools/libxl/xl_cmdimpl.c | 107 ++++++++++++------------------------------- tools/libxl/xl_sxp.c | 7 +-- 7 files changed, 134 insertions(+), 86 deletions(-)tools/libxl/libxl.c +2
-1@@ -516,12 +516,18 @@ int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid,return 0 ; } -static void xcinfo2xlinfo(const xc_domaininfo_t *xcinfo, +static void xcinfo2xlinfo(libxl_ctx *ctx, + const xc_domaininfo_t *xcinfo,
tools/libxl/libxl.c int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, · line 530
Quoted 10 lines
tools/libxl/libxl.c +5
-0libxl_dominfo *xlinfo) { +size_t size; +memcpy (&(xlinfo->uuid), xcinfo->handle,sizeof (xen_domain_handle_t)); xlinfo->domid = xcinfo->domain; xlinfo->ssidref = xcinfo->ssidref; +if (libxl_flask_sid_to_context (ctx, xlinfo->ssidref, + &xlinfo->ssid_label, &size) <0 ) + xlinfo->ssid_label =NULL ;
libxl_set_memory_target uses xcinfo2xlinfo but incorrectly fails to call dispose on the result, so it will leak any ssid_label.
The other callers of this function all seem to return the result to the application, which can be expected to be correct here.
Other than that:
Ian.
Re: [PATCH v6 02/18] xl / libxl: push parsing of SSID and CPU pool ID down to libxl
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Wei Liu
This patch pushes parsing of "
init_seclabel", "seclabel", "device_model_stubdomain_seclabel" and "pool" down to libxl level.Originally the parsing is done in xl level, which is not ideal because libxl won't have the truely relevant information. With this patch libxl holds important information by itself.
The libxl IDL is extended to hold the string of labels and pool name. And if there those strings are present they take precedence over the numeric representations.
Quoted 6 lines
Quoted 2 lines
As all relevant structures have a field called
X_name/X_labelnow, a string is also copied there so that we can use it directly.I'm not sure what you mean by this. Do you mean that if the caller uses the numeric and not the string version we will populate the string side?
I mean I added string field in libxl_dominfo etc, so that caller won't have to do the translation.
I shall make this clearer in commit message.
Quoted 31 lines
Quoted 10 lines
In order to
be compatible with users of older versions of libxl, this patch also definesLIBXL_HAVE_SSID_LABELandLIBXL_HAVE_CPUPOOL_NAME. If they are defined, the respective strings are available. And if those strings are not NULL, libxl will do the parsing and ignore the numeric values.Signed-off-by Wei Liu <[email protected]>Cc Dario Faggioli <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel De Graaf <[email protected]>(I switched to Juergen's new address in the CC)
Quoted 18 lines
--- tools/libxl/libxl.c | 19 ++++++-- tools/libxl/libxl.h | 20 ++++++++ tools/libxl/libxl_create.c | 57 +++++++++++++++++++++++ tools/libxl/libxl_dm.c | 4 ++ tools/libxl/libxl_types.idl | 6 +++ tools/libxl/xl_cmdimpl.c | 107 ++++++++++++------------------------------- tools/libxl/xl_sxp.c | 7 +-- 7 files changed, 134 insertions(+), 86 deletions(-)tools/libxl/libxl.c +0
-0@@ -516,12 +516,18 @@ int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid,return 0 ; }
Quoted 17 lines
tools/libxl/libxl.c int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, · line 530
Quoted 13 lines
tools/libxl/libxl.c +7
-1-static void xcinfo2xlinfo (const xc_domaininfo_t *xcinfo, +static void xcinfo2xlinfo (libxl_ctx *ctx, +const xc_domaininfo_t *xcinfo,libxl_dominfo *xlinfo) { +size_t size; +memcpy (&(xlinfo->uuid), xcinfo->handle,sizeof (xen_domain_handle_t)); xlinfo->domid = xcinfo->domain; xlinfo->ssidref = xcinfo->ssidref; +if (libxl_flask_sid_to_context (ctx, xlinfo->ssidref, + &xlinfo->ssid_label, &size) <0 ) + xlinfo->ssid_label =NULL ;
libxl_set_memory_targetuses xcinfo2xlinfo but incorrectly fails to call dispose on the result, so it will leak anyssid_label.
I will fix this.
Wei.
Quoted 7 lines
The other callers of this function all seem to return the result to the application, which can be expected to be correct here.
Other than that:
Acked-by Ian Campbell <[email protected]>Ian.
PATCH v6 3/18 xl / libxl: push VCPU affinity pinning down to libxl
In reply to Wei LiuThis patch introduces an array of libxl_bitmap called "vcpu_affinity" in libxl IDL to preserve VCPU to PCPU mapping. This is necessary for libxl to preserve all information to construct a domain.
Also define LIBXL_HAVE_AFFINITY_LIST in libxl.h to mark the change in API.
--- tools/libxl/libxl.h | 14 ++++++++++ tools/libxl/libxl_dom.c | 14 ++++++++++ tools/libxl/libxl_types.idl | 1 + tools/libxl/xl_cmdimpl.c | 64 ++++++++++++------------------------------- 4 files changed, 46 insertions(+), 47 deletions(-)
tools/libxl/libxl.h +14 -0
@@ -331,6 +331,20 @@#endif /* +* LIBXL_HAVE_VCPU_AFFINITY_LIST +* +* If this is defined, then libxl_domain_build_info structure will +* contain vcpu_affinity, an array of libxl_bitmap that contains +* the necessary information to pin a VCPU to a PCPU. Libxl will try +* to pin VCPUs to PCPUs according to this list. +* +* The number of libxl_bitmap in the array equals to the maximum number +* of VCPUs. The size of each bitmap equals to the maximum number of +* PCPUs. +*/ +#define LIBXL_HAVE_VCPU_AFFINITY_KEY_VALUE_LIST 1 + +/* * LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST * * If this is defined, then the libxl_domain_build_info structure will
tools/libxl/libxl_dom.c +14 -0
@@ -263,6 +263,20 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,libxl_domain_set_nodeaffinity (ctx, domid, &info->nodemap);libxl_set_vcpuaffinity_all (ctx, domid, info->max_vcpus, &info->cpumap); +/* If we have vcpu affinity list, pin vcpu to pcpu. */ +if (d_config->b_info.num_vcpumaps) { +int i; + +for (i =0 ; i < d_config->b_info.num_vcpumaps; i++) { +if (libxl_set_vcpuaffinity (ctx, domid, i, + &d_config->b_info.vcpu_affinity[i])) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"setting affinity failed on vcpu `%d'." , i); +return ERROR_FAIL ; + } + } + } +if (xc_domain_setmaxmem (ctx->xch, domid, info->target_memkb +LIBXL_MAXMEM_CONSTANT ) <0 ) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"Couldn't set max memory" );
tools/libxl/libxl_types.idl +1 -0
@@ -305,6 +305,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("avail_vcpus", libxl_bitmap), ("cpumap", libxl_bitmap), ("nodemap", libxl_bitmap), + ("vcpu_affinity", Array(libxl_bitmap, "num_vcpumaps")), ("numa_placement", libxl_defbool), ("tsc_mode", libxl_tsc_mode), ("max_memkb", MemKB),
tools/libxl/xl_cmdimpl.c +17 -47
98 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
In case people are wondering, the main change in this patch is that now we use bitmap in IDL instead of key value list.
Wei.
Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
In reply to Wei LiuQuoted 10 lines · Wei Liu
This patch introduces an array of
libxl_bitmapcalled "vcpu_affinity" in libxl IDL to preserve VCPU to PCPU mapping. This is necessary for libxl to preserve all information to construct a domain.Also define
LIBXL_HAVE_AFFINITY_LISTinlibxl.hto mark the change in API.Signed-off-by Wei Liu <[email protected]>Cc Dario Faggioli <[email protected]>
So, as far as this patch is concerned:
This clashes (not that badly, but it does) with my soft affinity series, that I just resent yesterday night. It's not a big deal, we just need two arrays of libxl_bitmap-s instead of just one: one for hard affinity, and one for soft affinity. Probably that also means that b_info->vcpu_affinity should have to be renamed to something like b_info->vcpu_hard_affinity (or b_info->vcpu_hard_aff, or b_info->hard_affinity, if we want to try keep it a bit shorter).
In any case, if this series goes in first, I'll rebase mine on top of this one and respin it. It mine goes in first, Wei, I'm up for modifying this patch of yours as described above, if you want/need it of course.
Just let me know.
Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
Quoted 15 lines · Dario Faggioli
Quoted 10 lines · Wei Liu
This patch introduces an array of
libxl_bitmapcalled "vcpu_affinity" in libxl IDL to preserve VCPU to PCPU mapping. This is necessary for libxl to preserve all information to construct a domain.Also define
LIBXL_HAVE_AFFINITY_LISTinlibxl.hto mark the change in API.Signed-off-by Wei Liu <[email protected]>Cc Dario Faggioli <[email protected]>So, as far as this patch is concerned:
Acked-by Dario Faggioli <[email protected]>
Quoted 8 lines
This clashes (not that badly, but it does) with my soft affinity series, that I just resent yesterday night. It's not a big deal, we just need two arrays of libxl_bitmap-s instead of just one: one for hard affinity, and one for soft affinity. Probably that also means that
b_info->vcpu_affinityshould have to be renamed to something likeb_info->vcpu_hard_affinity(orb_info->vcpu_hard_aff, orb_info->hard_affinity, if we want to try keep it a bit shorter).
I would go for vcpu_hard_affinity. When it comes to interface I prefer it to be as explicit as possible.
Quoted 4 lines
In any case, if this series goes in first, I'll rebase mine on top of this one and respin it. It mine goes in first, Wei, I'm up for modifying this patch of yours as described above, if you want/need it of course.
Thanks. I think that will do.
Wei.
Quoted 11 lines
Just let me know.
Regards,
DarioSignature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
Ian Campbell
Acked-byRe: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
Quoted 25 lines · Wei Liu
Quoted 15 lines · Dario Faggioli
Quoted 10 lines · Wei Liu
This patch introduces an array of
libxl_bitmapcalled "vcpu_affinity" in libxl IDL to preserve VCPU to PCPU mapping. This is necessary for libxl to preserve all information to construct a domain.Also define
LIBXL_HAVE_AFFINITY_LISTinlibxl.hto mark the change in API.Signed-off-by Wei Liu <[email protected]>Cc Dario Faggioli <[email protected]>So, as far as this patch is concerned:
Acked-by Dario Faggioli <[email protected]>Quoted 8 lines
This clashes (not that badly, but it does) with my soft affinity series, that I just resent yesterday night. It's not a big deal, we just need two arrays of libxl_bitmap-s instead of just one: one for hard affinity, and one for soft affinity. Probably that also means that
b_info->vcpu_affinityshould have to be renamed to something likeb_info->vcpu_hard_affinity(orb_info->vcpu_hard_aff, orb_info->hard_affinity, if we want to try keep it a bit shorter).
Quoted 2 lines
I would go for
vcpu_hard_affinity. When it comes to interface I prefer it to be as explicit as possible.
Renaming fields in the API is problematic, so we should make this be correct when we first check it in, whichever order that is in.
Once that is resolved:
Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Wei Liu
Quoted 23 lines · Dario Faggioli
Quoted 10 lines · Wei Liu
This patch introduces an array of
libxl_bitmapcalled "vcpu_affinity" in libxl IDL to preserve VCPU to PCPU mapping. This is necessary for libxl to preserve all information to construct a domain.Also define
LIBXL_HAVE_AFFINITY_LISTinlibxl.hto mark the change in API.Signed-off-by Wei Liu <[email protected]>Cc Dario Faggioli <[email protected]>So, as far as this patch is concerned:
Acked-by Dario Faggioli <[email protected]>This clashes (not that badly, but it does) with my soft affinity series, that I just resent yesterday night. It's not a big deal, we just need two arrays of libxl_bitmap-s instead of just one: one for hard affinity, and one for soft affinity. Probably that also means that
b_info->vcpu_affinityshould have to be renamed to something likeb_info->vcpu_hard_affinity(orb_info->vcpu_hard_aff, orb_info->hard_affinity, if we want to try keep it a bit shorter).
Quoted 6 lines
Quoted 2 lines
I would go for
vcpu_hard_affinity. When it comes to interface I prefer it to be as explicit as possible.Renaming fields in the API is problematic, so we should make this be correct when we first check it in, whichever order that is in.
Good point.
Well, I may be wrong, but it looks to me that the more logical order would be for Wei's series to go in first, and me to rebase mine on top of that. If we do it the other way around, Wei's would have to call the field vcpu_hard_affinity, without the distinction between hard and soft affinity being present and explained anywhere in the tree.
Not a big deal, probably, if my series follows quickly enough, but cetainly confusing for future archaeologists, I guess. :-)
This assuming both the series to be pretty, and almost equally, close to green light.
In an case, it would still be useful for me to have the current version (v7) of the soft affinity series reviewed, so that I'll know whether such rebasing is the only thing I should change in v8. :-)
Let me know what you prefer.
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
Quoted 33 lines · Dario Faggioli
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Wei Liu
Quoted 23 lines · Dario Faggioli
Quoted 10 lines · Wei Liu
This patch introduces an array of
libxl_bitmapcalled "vcpu_affinity" in libxl IDL to preserve VCPU to PCPU mapping. This is necessary for libxl to preserve all information to construct a domain.Also define
LIBXL_HAVE_AFFINITY_LISTinlibxl.hto mark the change in API.Signed-off-by Wei Liu <[email protected]>Cc Dario Faggioli <[email protected]>So, as far as this patch is concerned:
Acked-by Dario Faggioli <[email protected]>This clashes (not that badly, but it does) with my soft affinity series, that I just resent yesterday night. It's not a big deal, we just need two arrays of libxl_bitmap-s instead of just one: one for hard affinity, and one for soft affinity. Probably that also means that
b_info->vcpu_affinityshould have to be renamed to something likeb_info->vcpu_hard_affinity(orb_info->vcpu_hard_aff, orb_info->hard_affinity, if we want to try keep it a bit shorter).Quoted 6 lines
Quoted 2 lines
I would go for
vcpu_hard_affinity. When it comes to interface I prefer it to be as explicit as possible.Renaming fields in the API is problematic, so we should make this be correct when we first check it in, whichever order that is in.
Quoted 8 lines
Good point.
Well, I may be wrong, but it looks to me that the more logical order would be for Wei's series to go in first, and me to rebase mine on top of that. If we do it the other way around, Wei's would have to call the field
vcpu_hard_affinity, without the distinction between hard and soft affinity being present and explained anywhere in the tree.
I don't think this is a big problem. I will change the name to vcpu_hard_affinity and note this in commit message.
Wei.
Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
In reply to Wei LiuQuoted 10 lines · Wei Liu
tools/libxl/libxl_types.idl +0
-0@@ -305,6 +305,7 @@ libxl_domain_build_info =Struct("domain_build_info",[
("avail_vcpus", libxl_bitmap), ("cpumap", libxl_bitmap), ("nodemap", libxl_bitmap), + ("vcpu_affinity", Array(libxl_bitmap, "num_vcpumaps")),
Looking at one of Dario's patches I became confused about how this new field relates to the existing cpumap field.
Am I right that the new field is just a per-vcpu version of the old (which only allows you to set the affinity of every vcpu together)?
Can this relationship be mentioned in the commit message and/or comments please.
I also wonder if the name could be changed to better reflect this relationship, but I can't actually think of a good name. cpumap_FOO where FOO has connotations of per-vcpu/listiness.
I also just noticed that this change violates the following from idl.txt:
idl.Array.len_var contains an idl.Field which is added to the parent idl.Aggregate and will contain the length of the array. The field MUST be named num_ARRAYNAME.
Ian.
Quoted 3 lines
("numa_placement", libxl_defbool),
("tsc_mode", libxl_tsc_mode),
("max_memkb", MemKB),Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
Quoted 15 lines · Ian Campbell
Quoted 10 lines · Wei Liu
tools/libxl/libxl_types.idl +0
-0@@ -305,6 +305,7 @@ libxl_domain_build_info =Struct("domain_build_info",[
("avail_vcpus", libxl_bitmap), ("cpumap", libxl_bitmap), ("nodemap", libxl_bitmap), + ("vcpu_affinity", Array(libxl_bitmap, "num_vcpumaps")),Looking at one of Dario's patches I became confused about how this new field relates to the existing cpumap field.
Quoted 3 lines
Am I right that the new field is just a per-vcpu version of the old (which only allows you to set the affinity of every vcpu together)?
Yes, you're right. The old field denotes the PCPUs this domain is allowed to run on. The new array specifies the PCPUs each VCPU can run on.
Quoted 3 lines
Can this relationship be mentioned in the commit message and/or comments please.
Sure.
Quoted 10 lines
I also wonder if the name could be changed to better reflect this relationship, but I can't actually think of a good name.
cpumap_FOOwhere FOO has connotations of per-vcpu/listiness.I also just noticed that this change violates the following from idl.txt:
idl.Array.len_var contains an idl.Field which is added to the parent idl.Aggregate and will contain the length of the array. The field MUST be namednum_ARRAYNAME.
I will change lenvar to num_ARRAYNAME.
Wei.
Quoted 6 lines
Ian.
Quoted 3 lines
("numa_placement", libxl_defbool), ("tsc_mode", libxl_tsc_mode), ("max_memkb", MemKB),
Re: [PATCH v6 03/18] xl / libxl: push VCPU affinity pinning down to libxl
Quoted 16 lines · Wei Liu
Quoted 15 lines · Ian Campbell
Quoted 10 lines · Wei Liu
tools/libxl/libxl_types.idl +0
-0@@ -305,6 +305,7 @@ libxl_domain_build_info =Struct("domain_build_info",[
("avail_vcpus", libxl_bitmap), ("cpumap", libxl_bitmap), ("nodemap", libxl_bitmap), + ("vcpu_affinity", Array(libxl_bitmap, "num_vcpumaps")),Looking at one of Dario's patches I became confused about how this new field relates to the existing cpumap field.
Quoted 8 lines
Quoted 3 lines
Am I right that the new field is just a per-vcpu version of the old (which only allows you to set the affinity of every vcpu together)?
Yes, you're right. The old field denotes the PCPUs this domain is allowed to run on. The new array specifies the PCPUs each VCPU can run on.
Well, there's no "new" and "old". I mean, as can clearly be seen in the hunk above, 'cpumap' is still there, and vcpu_affinity is being added.
Fact is, considering how xl parses XXX in "cpus=XXX", only one between 'cpumap' and 'vcpu_affinity' will contain actual information.
With my series on top of this one (or vice versa), we'll have:
("cpumap", libxl_bitmap)
("cpumap_soft", libxl_bitmap)
("vcpu_affinity", Array(libxl_bitmap, "num_vcpumaps"))which is missing the soft affinity equivalent of 'vcpu_affinity'. meaning that, either me or Wei, when rebasing on top of the other series which went in first, will have to add it, meaning we'll end up with the following:
("cpumap", libxl_bitmap)
("cpumap_soft", libxl_bitmap)
("vcpu_hard_affinity", Array(libxl_bitmap, "num_vcpumaps"))
("vcpu_soft_affinity", Array(libxl_bitmap, "num_vcpumaps"))which is a lot of fields, and not particularly easy to understand, IMHO.
Quoted 3 lines
Quoted 3 lines
Can this relationship be mentioned in the commit message and/or comments please.
I think we could go farther than that... way farther. I mean, "cpumap" contains the vcpu affinity to be applied to all the vcpus of the domain, if the config file was something like "cpus="1,3-6". "vcpu_affinity" contains a cpumap for each vcpu, if the config file was something like "cpus=["1", "5"] (and all this repeated for soft affinity, with my series).
Can't we kill "cpumap" (and "cpumap_soft" too, in my series) and use "vcpu_affinity" (i.e., "vcpu_hard_affinity" and "vcpu_soft_affinity" after my series) only? What would happen is, in case we find "cpus="4-5", we set all the bitmaps of "vcpu_hard_affinity" to "4-5".
What do you think?
Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v6 4/18 libxl: libxl_uuid_copy now takes a ctx argument
In reply to Wei LiuMake it consistent with existing libxl functions like libxl_bitmap_copy etc.
--- tools/libxl/libxl.c | 2 +- tools/libxl/libxl.h | 12 +++++++++++- tools/libxl/libxl_create.c | 2 +- tools/libxl/libxl_utils.c | 2 +- tools/libxl/libxl_uuid.c | 8 +++++--- tools/libxl/libxl_uuid.h | 7 ++++++- 6 files changed, 25 insertions(+), 8 deletions(-)
tools/libxl/libxl.c +1 -1
@@ -2006,7 +2006,7 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx,if (devid == vtpms[i].devid) { vtpm->backend_domid = vtpms[i].backend_domid; vtpm->devid = vtpms[i].devid; -libxl_uuid_copy (&vtpm->uuid, &vtpms[i].uuid); +libxl_uuid_copy (ctx, &vtpm->uuid, &vtpms[i].uuid); rc =0 ;break ; }
tools/libxl/libxl.h +11 -1
@@ -319,13 +319,15 @@#include <xentoollog.h> +typedef struct libxl__ctx libxl_ctx ; +#include <libxl_uuid.h> #include <_libxl_list.h> /* API compatibility. */ #ifdef LIBXL_API_VERSION #if LIBXL_API_VERSION !=0x040200 &&LIBXL_API_VERSION !=0x040300 && \ -LIBXL_API_VERSION !=0x040400 +LIBXL_API_VERSION !=0x040400 &&LIBXL_API_VERSION !=0x040500 #error Unknown LIBXL_API_VERSION#endif #endif
@@ -513,6 +515,14 @@#endif /* +* LIBXL_HAVE_UUID_COPY_CTX_PARAM +* +* If this is defined, libxl_uuid_copy has changed to take a libxl_ctx +* structure. +*/ +#define LIBXL_HAVE_UUID_COPY_CTX_PARAM 1 + +/* * LIBXL_HAVE_SSID_LABEL * * If this is defined, then libxl IDL contains string of XSM security
tools/libxl/libxl_create.c +1 -1
@@ -479,7 +479,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, *domid =-1 ;/* Ultimately, handle is an array of 16 uint8_t, same as uuid */ -libxl_uuid_copy ((libxl_uuid *)handle, &info->uuid); +libxl_uuid_copy (ctx, (libxl_uuid *)handle, &info->uuid); ret =xc_domain_create (ctx->xch, info->ssidref, handle, flags, domid);if (ret <0 ) {
tools/libxl/libxl_utils.c +1 -1
@@ -536,7 +536,7 @@ int libxl_uuid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,if (!libxl_uuid_compare (uuid, &vtpms[i].uuid)) { vtpm->backend_domid = vtpms[i].backend_domid; vtpm->devid = vtpms[i].devid; -libxl_uuid_copy (&vtpm->uuid, &vtpms[i].uuid); +libxl_uuid_copy (ctx, &vtpm->uuid, &vtpms[i].uuid); rc =0 ;break ; }
tools/libxl/libxl_uuid.c +5 -3
@@ -14,7 +14,7 @@#include "libxl_osdeps.h" /* must come before any other headers */ -#include <libxl_uuid.h> +#include <libxl_internal.h> #include "libxl_internal.h"
@@ -35,7 +35,8 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in)return uuid_parse (in, uuid->uuid); } -void libxl_uuid_copy (libxl_uuid *dst,const libxl_uuid *src) +void libxl_uuid_copy (libxl_ctx *ctx_opt,libxl_uuid *dst, +const libxl_uuid *src) {uuid_copy (dst->uuid, src->uuid); }
@@ -82,7 +83,8 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in) }#undef LIBXL__UUID_PTRS -void libxl_uuid_copy (libxl_uuid *dst,const libxl_uuid *src) +void libxl_uuid_copy (libxl_ctx *ctx_opt,libxl_uuid *dst, +const libxl_uuid *src) {memcpy (dst->uuid, src->uuid,sizeof (dst->uuid)); }
tools/libxl/libxl_uuid.h +6 -1
@@ -56,7 +56,12 @@ typedef struct {int libxl_uuid_is_nil (libxl_uuid *uuid);void libxl_uuid_generate (libxl_uuid *uuid);int libxl_uuid_from_string (libxl_uuid *uuid,const char *in); -void libxl_uuid_copy (libxl_uuid *dst,const libxl_uuid *src); +void libxl_uuid_copy (libxl_ctx *ctx_opt,libxl_uuid *dst, +const libxl_uuid *src); +#if defined(LIBXL_API_VERSION ) &&LIBXL_API_VERSION <0x040500 +void libxl_uuid_copy(dst, src) libxl_uuid_copy(NULL, dst, src) +#endif +void libxl_uuid_clear (libxl_uuid *uuid);int libxl_uuid_compare (libxl_uuid *uuid1,libxl_uuid *uuid2);uint8_t *libxl_uuid_bytearray (libxl_uuid *uuid);
Signature · 1 line
1.7.10.4
Re: [PATCH v6 04/18] libxl: libxl_uuid_copy now takes a ctx argument
tools/libxl/libxl.h line 322
Quoted 9 lines · Wei Liu
tools/libxl/libxl.h +1
-0@@ -319,13 +319,15 @@#include <xentoollog.h> +typedef struct libxl__ctx libxl_ctx ;
Looks like you didn't move the existing one, but instead added a second?
tools/libxl/libxl_uuid.c line 19
Quoted 12 lines
tools/libxl/libxl_uuid.c +1
-1@@ -14,7 +14,7 @@#include "libxl_osdeps.h" /* must come before any other headers */ -#include <libxl_uuid.h> +#include <libxl_internal.h> #include "libxl_internal.h"
I'm getting deja vu ;-)
Other than those two things looks good. With them resolved:
Ian.
Re: [PATCH v6 04/18] libxl: libxl_uuid_copy now takes a ctx argument
Quoted 24 lines · Ian Campbell
tools/libxl/libxl.h line 322
Quoted 9 lines · Wei Liu
tools/libxl/libxl.h +1
-0@@ -319,13 +319,15 @@#include <xentoollog.h> +typedef struct libxl__ctx libxl_ctx ;Looks like you didn't move the existing one, but instead added a second?
Quoted 11 lines
tools/libxl/libxl_uuid.c +1
-1@@ -14,7 +14,7 @@#include "libxl_osdeps.h" /* must come before any other headers */ -#include <libxl_uuid.h> +#include <libxl_internal.h>
Quoted 7 lines
tools/libxl/libxl_uuid.c line 19
Quoted 1 line
tools/libxl/libxl_uuid.c +0
-0#include "libxl_internal.h" I'm getting deja vu ;-)
Other than those two things looks good. With them resolved:
Acked-by Ian Campbell <[email protected]>
Done. Thanks.
Quoted 2 lines
Ian.
PATCH v6 5/18 xl: remove parsing of "vncviewer" option in xl domain config file
In reply to Wei LiuPrint out a warning and suggest user use "-V" option when invoking "xl create". Also remove that option in manpage. This will introduce a minor functional regression but it's very easy to work around.
The rationale behind this change is that, this option is actually not part of domain configuration. It just affects whether a vncviewer should be automatically spawn, but has nothing to do with how a domain should be constructed. And this option is also bogus, considering if you migrate a domain to a remote host and the receiver spawns a vncviewer on the receiving side then it either dies silently or occupies resource.
--- docs/man/xl.cfg.pod.5 | 4 ---- tools/libxl/xl_cmdimpl.c | 21 ++++++++------------- 2 files changed, 8 insertions(+), 17 deletions(-)
docs/man/xl.cfg.pod.5 +0 -4
@@ -1114,10 +1114,6 @@ The default is cirrus. Allow access to the display via the VNC protocol. This enables the other VNC-related settings. The default is to enable this. -=item B<vncviewer=BOOLEAN> - -Automatically spawn a vncviewer when creating/restoring a guest. - =item B<vnclisten="ADDRESS[:DISPLAYNUM]"> Specifies the IP address, and optionally VNC display number, to use.
tools/libxl/xl_cmdimpl.c +8 -13
@@ -693,9 +693,7 @@ static void parse_top_level_sdl_options(XLU_Config *config,static void parse_config_data (const char *config_source,const char *config_data,int config_len, -libxl_domain_config *d_config, -struct domain_create *dom_info) - +libxl_domain_config *d_config) {const char *buf;long l;
@@ -929,12 +927,9 @@ static void parse_config_data(const char *config_source,if (!xlu_cfg_get_long (config,"rtc_timeoffset" , &l,0 )) b_info->rtc_timeoffset = l; -if (dom_info && !xlu_cfg_get_long (config,"vncviewer" , &l,0 )) { -/* Command line arguments must take precedence over what's -* specified in the configuration file. */ -if (!dom_info->vnc) - dom_info->vnc = l; - } +if (!xlu_cfg_get_long (config,"vncviewer" , &l,0 )) +fprintf (stderr,"WARNING: ignoring \"vncviewer\" option. " +"Use \"-V\" option of \"xl create\" to automatically spawn vncviewer.\n" );xlu_cfg_get_defbool (config,"localtime" , &b_info->localtime,0 );
@@ -2117,7 +2112,7 @@ static uint32_t create_domain(struct domain_create *dom_info)if (!dom_info->quiet)printf ("Parsing config from %s\n" , config_source); -parse_config_data (config_source, config_data, config_len, &d_config, dom_info); +parse_config_data (config_source, config_data, config_len, &d_config);if (migrate_fd >=0 ) {if (d_config.c_info.name) {
@@ -2292,7 +2287,7 @@ start:libxl_domain_config_dispose (&d_config);libxl_domain_config_init (&d_config);parse_config_data (config_source, config_data, config_len, - &d_config, dom_info); + &d_config);/* * XXX FIXME: If this sleep is not there then domain
@@ -3103,7 +3098,7 @@ static void list_domains_details(const libxl_dominfo *info, int nb_domain)continue ;CHK_SYSCALL (asprintf (&config_source,"<domid %d data>" , info[i].domid));libxl_domain_config_init (&d_config); -parse_config_data (config_source, (char *)data, len, &d_config,NULL ); +parse_config_data (config_source, (char *)data, len, &d_config);if (default_output_format ==OUTPUT_FORMAT_JSON ) s =printf_info_one_json (hand, info[i].domid, &d_config);else
@@ -4404,7 +4399,7 @@ int main_config_update(int argc, char **argv)libxl_domain_config_init (&d_config); -parse_config_data (filename, config_data, config_len, &d_config,NULL ); +parse_config_data (filename, config_data, config_len, &d_config);if (debug || dryrun_only)printf_info (default_output_format,-1 , &d_config);
Signature · 1 line
1.7.10.4
PATCH v6 6/18 libxl: fix JSON generator for uint64_t
In reply to Wei Liuyajl_gen_integer cannot cope with uint64_t, because it takes a signed long long. If we pass to it an uint64_t number which is between INT_MAX and UINT_MAX, it generates a negative number. Later when we feed this generated number into parser, the result gets signed extended, which is wrong.
A new function called libxl__uint64_gen_json is introduced to handle uint64_t. It utilises yajl_gen_number to generate numbers.
Also removed a duplicated definition of MemKB while I was there.
--- tools/libxl/idl.py | 2 +- tools/libxl/libxl_json.c | 21 +++++++++++++++++++++ tools/libxl/libxl_json.h | 1 + tools/libxl/libxl_types.idl | 4 +--- 4 files changed, 24 insertions(+), 4 deletions(-)
tools/libxl/idl.py +1 -1
@@ -266,7 +266,7 @@ integer = Number("int", namespace = None, signed = True) uint8 = UInt(8) uint16 = UInt(16) uint32 = UInt(32) -uint64 = UInt(64) +uint64 = UInt(64, json_fn = "libxl__uint64_gen_json") string = Builtin("char *", namespace = None, dispose_fn = "free", json_fn = "libxl__string_gen_json",
tools/libxl/libxl_json.c +21 -0
@@ -781,6 +781,27 @@ out:return ret; } +yajl_gen_status libxl__uint64_gen_json (yajl_gen hand,uint64_t val) +{ +char *num; +unsigned int len; +yajl_gen_status s; + + + len =asprintf (&num,"%" PRIu64, val); +if (len ==-1 ) { + s = yajl_gen_in_error_state; + goto out; + } + + s =yajl_gen_number (hand, num, len); + +free (num); + +out: +return s; +} +/* * Local variables: * mode: C
tools/libxl/libxl_json.h +1 -0
@@ -22,6 +22,7 @@# include <yajl/yajl_version.h> #endif +yajl_gen_status libxl__uint64_gen_json (yajl_gen hand,uint64_t val);yajl_gen_status libxl_defbool_gen_json (yajl_gen hand,libxl_defbool *p);yajl_gen_status libxl_domid_gen_json (yajl_gen hand,libxl_domid *p);yajl_gen_status libxl_uuid_gen_json (yajl_gen hand,libxl_uuid *p);
tools/libxl/libxl_types.idl +1 -3
@@ -22,7 +22,7 @@ libxl_hwcap = Builtin("hwcap", passby=PASS_BY_REFERENCE) # Specific integer types # -MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT") +MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT", json_fn = "libxl__uint64_gen_json") # # Constants / Enumerations
@@ -288,8 +288,6 @@ libxl_domain_restore_params = Struct("domain_restore_params", [ ("checkpointed_stream", integer), ]) -MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT") - libxl_domain_sched_params = Struct("domain_sched_params",[ ("sched", libxl_scheduler), ("weight", integer, {'init_val': 'LIBXL_DOMAIN_SCHED_PARAM_WEIGHT_DEFAULT'}),
Signature · 1 line
1.7.10.4
PATCH v6 7/18 libxl IDL: rename json_fn to json_gen_fn
In reply to Wei LiuThis json_fn is in fact used to generate string representation of a json data structure. We will introduce another json function to parse json data structure in later changeset, so rename json_fn to json_gen_fn to clarify.
--- tools/libxl/gentest.py | 4 ++-- tools/libxl/gentypes.py | 12 ++++++------ tools/libxl/idl.py | 12 ++++++------ tools/libxl/idl.txt | 4 ++-- tools/libxl/libxl_types.idl | 6 +++--- tools/libxl/libxl_types_internal.idl | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-)
tools/libxl/gentest.py +2 -2
@@ -52,7 +52,7 @@ def gen_rand_init(ty, v, indent = " ", parent = None): s += " break;\n" s += "}\n" elif isinstance(ty, idl.Struct) \ - and (parent is None or ty.json_fn is None): + and (parent is None or ty.json_gen_fn is None): for f in [f for f in ty.fields if not f.const]: (nparent,fexpr) = ty.member(v, f, parent is None) s += gen_rand_init(f.type, fexpr, "", nparent)
@@ -243,7 +243,7 @@ int main(int argc, char **argv) f.write(" printf(\"Testing TYPE_to_json()\\n\");\n") f.write(" printf(\"----------------------\\n\");\n") f.write(" printf(\"\\n\");\n") - for ty in [t for t in types if t.json_fn is not None]: + for ty in [t for t in types if t.json_gen_fn is not None]: arg = ty.typename + "_val" f.write(" %s_rand_init(%s);\n" % (ty.typename, \ ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE)))
tools/libxl/gentypes.py +6 -6
@@ -229,7 +229,7 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" s += " break;\n" s += "}\n" - elif isinstance(ty, idl.Struct) and (parent is None or ty.json_fn is None): + elif isinstance(ty, idl.Struct) and (parent is None or ty.json_gen_fn is None): s += "s = yajl_gen_map_open(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"
@@ -243,8 +243,8 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n" else: - if ty.json_fn is not None: - s += "s = %s(hand, %s);\n" % (ty.json_fn, ty.pass_arg(v, parent is None)) + if ty.json_gen_fn is not None: + s += "s = %s(hand, %s);\n" % (ty.json_gen_fn, ty.pass_arg(v, parent is None)) s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"
@@ -341,7 +341,7 @@ if __name__ == '__main__': f.write("%svoid %s(%s, %s);\n" % (ty.hidden(), ty.init_fn + "_" + ku.keyvar.name, ty.make_arg("p"), ku.keyvar.type.make_arg(ku.keyvar.name))) - if ty.json_fn is not None: + if ty.json_gen_fn is not None: f.write("%schar *%s_to_json(libxl_ctx *ctx, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p"))) if isinstance(ty, idl.Enumeration): f.write("%sconst char *%s_to_string(%s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p")))
@@ -369,7 +369,7 @@ if __name__ == '__main__': """ % (header_json_define, header_json_define, " ".join(sys.argv))) - for ty in [ty for ty in types if ty.json_fn is not None]: + for ty in [ty for ty in types if ty.json_gen_fn is not None]: f.write("%syajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) f.write("\n")
@@ -426,7 +426,7 @@ if __name__ == '__main__': f.write("}\n") f.write("\n") - for ty in [t for t in types if t.json_fn is not None]: + for ty in [t for t in types if t.json_gen_fn is not None]: f.write("yajl_gen_status %s_gen_json(yajl_gen hand, %s)\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) f.write("{\n") f.write(libxl_C_type_gen_json(ty, "p"))
tools/libxl/idl.py +6 -6
@@ -65,9 +65,9 @@ class Type(object): self.autogenerate_init_fn = kwargs.setdefault('autogenerate_init_fn', False) if self.typename is not None and not self.private: - self.json_fn = kwargs.setdefault('json_fn', self.typename + "_gen_json") + self.json_gen_fn = kwargs.setdefault('json_gen_fn', self.typename + "_gen_json") else: - self.json_fn = kwargs.setdefault('json_fn', None) + self.json_gen_fn = kwargs.setdefault('json_gen_fn', None) self.autogenerate_json = kwargs.setdefault('autogenerate_json', True)
@@ -118,7 +118,7 @@ class Number(Builtin): kwargs.setdefault('namespace', None) kwargs.setdefault('dispose_fn', None) kwargs.setdefault('signed', False) - kwargs.setdefault('json_fn', "yajl_gen_integer") + kwargs.setdefault('json_gen_fn', "yajl_gen_integer") self.signed = kwargs['signed'] Builtin.__init__(self, ctype, **kwargs)
@@ -256,7 +256,7 @@ class KeyedUnion(Aggregate): void = Builtin("void *", namespace = None) bool = Builtin("bool", namespace = None, - json_fn = "yajl_gen_bool", + json_gen_fn = "yajl_gen_bool", autogenerate_json = False) size_t = Number("size_t", namespace = None)
@@ -266,10 +266,10 @@ integer = Number("int", namespace = None, signed = True) uint8 = UInt(8) uint16 = UInt(16) uint32 = UInt(32) -uint64 = UInt(64, json_fn = "libxl__uint64_gen_json") +uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") string = Builtin("char *", namespace = None, dispose_fn = "free", - json_fn = "libxl__string_gen_json", + json_gen_fn = "libxl__string_gen_json", autogenerate_json = False) class Array(Type):
tools/libxl/idl.txt +2 -2
@@ -60,14 +60,14 @@ Type.autogenerate_init_fn: (default: True if dir in [IN, BOTH]) Indicates if the above named Type.init_fn should be autogenerated. -Type.json_fn: (default: typename + "_gen_json" or None if type == None) +Type.json_gen_fn: (default: typename + "_gen_json" or None if type == None) The name of the C function which will generate a YAJL data structure representing this type. Type.autogenerate_json: (default: True) - Indicates if the above named Type.json_fn should be autogenerated. + Indicates if the above named Type.json_gen_fn should be autogenerated. Other simple type-Classes -------------------------
tools/libxl/libxl_types.idl +3 -3
@@ -7,8 +7,8 @@ namespace("libxl_") libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) -libxl_domid = Builtin("domid", json_fn = "yajl_gen_integer", autogenerate_json = False) -libxl_devid = Builtin("devid", json_fn = "yajl_gen_integer", autogenerate_json = False, signed = True, init_val="-1") +libxl_domid = Builtin("domid", json_gen_fn = "yajl_gen_integer", autogenerate_json = False) +libxl_devid = Builtin("devid", json_gen_fn = "yajl_gen_integer", autogenerate_json = False, signed = True, init_val="-1") libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE) libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE) libxl_bitmap = Builtin("bitmap", dispose_fn="libxl_bitmap_dispose", passby=PASS_BY_REFERENCE)
@@ -22,7 +22,7 @@ libxl_hwcap = Builtin("hwcap", passby=PASS_BY_REFERENCE) # Specific integer types # -MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT", json_fn = "libxl__uint64_gen_json") +MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT", json_gen_fn = "libxl__uint64_gen_json") # # Constants / Enumerations
tools/libxl/libxl_types_internal.idl +1 -1
@@ -1,7 +1,7 @@ namespace("libxl__") hidden(True) -libxl_domid = Builtin("domid", namespace="libxl_", json_fn = "yajl_gen_integer") +libxl_domid = Builtin("domid", namespace="libxl_", json_gen_fn = "yajl_gen_integer") libxl__qmp_message_type = Enumeration("qmp_message_type", [ (1, "QMP"),
Signature · 1 line
1.7.10.4
PATCH v6 8/18 libxl_json: introduce libxl__object_from_json
In reply to Wei LiuGiven a JSON string, we need to convert it to libxl_FOO struct.
The approach is:
JSON string -> libxl__json_object -> libxl_FOO struct
With this approach we can make use of libxl's infrastructure to do the first half (JSON string -> libxl__json_object).
Second half is done by auto-generated code by libxl's IDL infrastructure. IDL patch(es) will come later.
--- tools/libxl/libxl_internal.h | 8 ++++++++ tools/libxl/libxl_json.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
tools/libxl/libxl_internal.h +8 -0
@@ -1640,6 +1640,14 @@ typedef struct libxl__json_object {struct libxl__json_object *parent; } libxl__json_object; +typedef int (*libxl__json_parse_callback )(libxl__gc *gc, +libxl__json_object *o, +void *p); +_hidden int libxl__object_from_json(libxl_ctx *ctx, const char *type, +libxl__json_parse_callback parse, +void *p, +const char *s); + typedef struct { char *map_key; libxl__json_object *obj;
tools/libxl/libxl_json.c +30 -0
@@ -802,6 +802,36 @@ out:return s; } +int libxl__object_from_json (libxl_ctx *ctx,const char *type, +libxl__json_parse_callback parse, +void *p,const char *s) +{ +GC_INIT (ctx); +libxl__json_object *o; +int rc; + + o =libxl__json_parse (gc, s); +if (!o) { +LOG (ERROR , +"unable to generate libxl__json_object from JSON representation of %s." , + type); + rc =ERROR_FAIL ; + goto out; + } + + rc =parse (gc, o, p); +if (rc) { +LOG (ERROR ,"unable to convert libxl__json_object to %s. (rc=%d)" , type, rc); + rc =ERROR_FAIL ; + goto out; + } + + rc =0 ; +out: +GC_FREE ; +return rc; +} +/* * Local variables: * mode: C
Signature · 1 line
1.7.10.4
PATCH v6 9/18 libxl_json: introduce parser functions for builtin types
In reply to Wei LiuThis changeset introduces following functions:
* libxl_defbool_parse_json
* libxl__bool_parse_json
* libxl_uuid_parse_json
* libxl_mac_parse_json
* libxl_bitmap_parse_json
* libxl_cpuid_policy_list_parse_json
* libxl_string_list_parse_json
* libxl_key_value_list_parse_json
* libxl_hwcap_parse_json
* libxl__int_parse_json
* libxl__uint{8,16,32,64}_parse_json
* libxl__string_parse_json
They will be used in later patch to convert the libxl__json_object tree of a builtin type to libxl_FOO struct.
Also remove declaration of libxl_domid_gen_json as libxl_domid uses yajl_gen_integer to generate JSON object.
--- tools/libxl/libxl_cpuid.c | 89 +++++++++++--- tools/libxl/libxl_json.c | 271 +++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_json.h | 36 +++++- tools/libxl/libxl_nocpuid.c | 7 ++ 4 files changed, 386 insertions(+), 17 deletions(-)
tools/libxl/libxl_cpuid.c +73 -16
@@ -338,29 +338,29 @@ void libxl_cpuid_set(libxl_ctx *ctx, uint32_t domid, (const char**)(cpuid[i].policy), cpuid_res); } +static const char *input_names[2 ] = {"leaf" ,"subleaf" }; +static const char *policy_names[4 ] = {"eax" ,"ebx" ,"ecx" ,"edx" }; +/* +* Aiming for: +* [ +* { 'leaf': 'val-eax', +* 'subleaf': 'val-ecx', +* 'eax': 'filter', +* 'ebx': 'filter', +* 'ecx': 'filter', +* 'edx': 'filter' }, +* { 'leaf': 'val-eax', ..., 'eax': 'filter', ... }, +* ... etc ... +* ] +*/ +yajl_gen_status libxl_cpuid_policy_list_gen_json (yajl_gen hand,libxl_cpuid_policy_list *pcpuid) {libxl_cpuid_policy_list cpuid = *pcpuid;yajl_gen_status s; -const char *input_names[2 ] = {"leaf" ,"subleaf" }; -const char *policy_names[4 ] = {"eax" ,"ebx" ,"ecx" ,"edx" };int i, j; -/* -* Aiming for: -* [ -* { 'leaf': 'val-eax', -* 'subleaf': 'val-ecx', -* 'eax': 'filter', -* 'ebx': 'filter', -* 'ecx': 'filter', -* 'edx': 'filter' }, -* { 'leaf': 'val-eax', ..., 'eax': 'filter', ... }, -* ... etc ... -* ] -*/ - s =yajl_gen_array_open (hand);if (s != yajl_gen_status_ok) goto out;
@@ -398,6 +398,63 @@ out:return s; } +int libxl_cpuid_policy_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_cpuid_policy_list *p) +{ +int i, size; +libxl_cpuid_policy_list l; +flexarray_t *array; + +if (!libxl__json_object_is_array (o)) +return ERROR_FAIL ; + + array =libxl__json_object_get_array (o); +if (!array->count) +return 0 ; + + size = array->count; +/* need one extra slot as sentinel */ + l = *p =libxl__calloc (NOGC , size +1 ,sizeof (libxl_cpuid_policy)); + + l[size].input[0 ] =XEN_CPUID_INPUT_UNUSED ; + l[size].input[1 ] =XEN_CPUID_INPUT_UNUSED ; + +for (i =0 ; i < size; i++) { +const libxl__json_object *t; +int j; + +if (flexarray_get (array, i, (void **)&t) !=0 ) +return ERROR_FAIL ; + +if (!libxl__json_object_is_map (t)) +return ERROR_FAIL ; + +for (j =0 ; j <ARRAY_SIZE (l[0 ].input); j++) { +const libxl__json_object *r; + + r =libxl__json_map_get (input_names[j], t,JSON_INTEGER ); +if (!r) + l[i].input[j] =XEN_CPUID_INPUT_UNUSED ; +else + l[i].input[j] =libxl__json_object_get_integer (r); + } + +for (j =0 ; j <ARRAY_SIZE (l[0 ].policy); j++) { +const libxl__json_object *r; + + r =libxl__json_map_get (policy_names[j], t,JSON_STRING ); +if (!r) + l[i].policy[j] =NULL ; +else + l[i].policy[j] = +libxl__strdup (NOGC ,libxl__json_object_get_string (r)); + } + } + +return 0 ; +} +/* * Local variables: * mode: C
tools/libxl/libxl_json.c +271 -0
325 lines not on this page · raw message
tools/libxl/libxl_json.h +35 -1
@@ -22,18 +22,52 @@# include <yajl/yajl_version.h> #endif +typedef struct libxl__gc libxl__gc ; +typedef struct libxl__json_object libxl__json_object ; +yajl_gen_status libxl__uint64_gen_json (yajl_gen hand,uint64_t val);yajl_gen_status libxl_defbool_gen_json (yajl_gen hand,libxl_defbool *p); -yajl_gen_status libxl_domid_gen_json (yajl_gen hand,libxl_domid *p); +int libxl_defbool_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_defbool *p); +int libxl__bool_parse_json (libxl__gc *gc,const libxl__json_object *o, +bool *p);yajl_gen_status libxl_uuid_gen_json (yajl_gen hand,libxl_uuid *p); +int libxl_uuid_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_uuid *p);yajl_gen_status libxl_mac_gen_json (yajl_gen hand,libxl_mac *p); +int libxl_mac_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_mac *p);yajl_gen_status libxl_bitmap_gen_json (yajl_gen hand,libxl_bitmap *p); +int libxl_bitmap_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_bitmap *p);yajl_gen_status libxl_cpuid_policy_list_gen_json (yajl_gen hand,libxl_cpuid_policy_list *p); +int libxl_cpuid_policy_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_cpuid_policy_list *p);yajl_gen_status libxl_string_list_gen_json (yajl_gen hand,libxl_string_list *p); +int libxl_string_list_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_string_list *p);yajl_gen_status libxl_key_value_list_gen_json (yajl_gen hand,libxl_key_value_list *p); +int libxl_key_value_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_key_value_list *p);yajl_gen_status libxl_hwcap_gen_json (yajl_gen hand,libxl_hwcap *p); +int libxl_hwcap_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_hwcap *p); +int libxl__int_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint8_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint16_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint32_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint64_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__string_parse_json (libxl__gc *gc,const libxl__json_object *o, +char **p);#include <_libxl_types_json.h>
tools/libxl/libxl_nocpuid.c +7 -0
@@ -44,6 +44,13 @@ yajl_gen_status libxl_cpuid_policy_list_gen_json(yajl_gen hand,return 0 ; } +int libxl_cpuid_policy_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_cpuid_policy_list *p) +{ +return 0 ; +} +/* * Local variables: * mode: C
Signature · 1 line
1.7.10.4
PATCH v6 10/18 libxl/gentypes.py: special-case KeyedUnion map handle generation
In reply to Wei LiuGenerate JSON map handle according to KeyedUnion discriminator.
The original JSON output for a keyed union is like:
{
...
"u" : { FIELDS }
...
}
The discriminator is not generated, so that the parser won't be able to figure out the fields in the incoming stream.
So we need to change this to something more sensible. For example, for keyed union libxl_domain_type, which has a discriminator called "type", we generate following for HVM guest:
{
...
"type.hvm" : { HVM FIELDS }
...
}
Parser then can know the type of this union and how to interpret the incoming stream.
Note that we change the existing API here. However the original output is quite broken anyway, we cannot make sensible use of it and I doubt that there's existing user of existing API. So we are acutally fixing a problem.
--- tools/libxl/gentypes.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
tools/libxl/gentypes.py +21 -3
@@ -186,6 +186,26 @@ def libxl_C_type_member_init(ty, field): s += "\n" return s +def libxl_C_type_gen_map_key(f, parent, indent = ""): + s = "" + if isinstance(f.type, idl.KeyedUnion): + s += "switch (%s) {\n" % (parent + f.type.keyvar.name) + for x in f.type.fields: + v = f.type.keyvar.name + "." + x.name + s += "case %s:\n" % x.enumname + s += " s = yajl_gen_string(hand, (const unsigned char *)\"%s\", sizeof(\"%s\")-1);\n" % (v, v) + s += " if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + s += " break;\n" + s += "}\n" + else: + s += "s = yajl_gen_string(hand, (const unsigned char *)\"%s\", sizeof(\"%s\")-1);\n" % (f.name, f.name) + s += "if (s != yajl_gen_status_ok)\n" + s += " goto out;\n" + if s != "": + s = indent + s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None:
@@ -235,9 +255,7 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) - s += "s = yajl_gen_string(hand, (const unsigned char *)\"%s\", sizeof(\"%s\")-1);\n" % (f.name, f.name) - s += "if (s != yajl_gen_status_ok)\n" - s += " goto out;\n" + s += libxl_C_type_gen_map_key(f, nparent) s += libxl_C_type_gen_json(f.type, fexpr, "", nparent) s += "s = yajl_gen_map_close(hand);\n" s += "if (s != yajl_gen_status_ok)\n"
Signature · 1 line
1.7.10.4
PATCH v6 11/18 libxl/gentypes.py: don't generate default values
In reply to Wei LiuIf a type has init_val defined and a field of the type has the value of init_val, there's no need to generate output for that field in JSON output. When the parser consumes that generated JSON object, all default values should be automatically filled in.
Also define init_val for enumeration type, string type and libxl_defbool type.
--- tools/libxl/gentypes.py | 27 ++++++++++++++++++++++++--- tools/libxl/idl.py | 3 ++- tools/libxl/libxl_types.idl | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-)
tools/libxl/gentypes.py +24 -3
@@ -135,7 +135,7 @@ def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): else: s += _libxl_C_type_init(f.type, fexpr, "", nparent) else: - if ty.init_val is not None: + if ty.init_val is not None and ty.typename != "libxl_defbool": s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), ty.init_val) elif ty.init_fn is not None: s += "%s(%s);\n" % (ty.init_fn, ty.pass_arg(v, parent is None))
@@ -206,6 +206,13 @@ def libxl_C_type_gen_map_key(f, parent, indent = ""): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def get_init_val(f): + if f.init_val is not None: + return f.init_val + elif f.type.init_val is not None: + return f.type.init_val + return None + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None:
@@ -255,8 +262,22 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) - s += libxl_C_type_gen_map_key(f, nparent) - s += libxl_C_type_gen_json(f.type, fexpr, "", nparent) + init_val = get_init_val(f) + if init_val: + if f.type.typename != "libxl_defbool": + s += "if (%s != %s) {\n" % (fexpr, init_val) + else: + s += "if (%s.val != %s) {\n" % (fexpr, init_val) + indent1 = " " + else: + indent1 = "" + + s += libxl_C_type_gen_map_key(f, nparent, indent1) + s += libxl_C_type_gen_json(f.type, fexpr, indent1, nparent) + + if init_val: + s += "}\n" + s += "s = yajl_gen_map_close(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"
tools/libxl/idl.py +2 -1
@@ -142,6 +142,7 @@ class EnumerationValue(object): class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('init_val', '0') Type.__init__(self, typename, **kwargs) self.value_namespace = kwargs.setdefault('value_namespace',
@@ -270,7 +271,7 @@ uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") string = Builtin("char *", namespace = None, dispose_fn = "free", json_gen_fn = "libxl__string_gen_json", - autogenerate_json = False) + autogenerate_json = False, init_val = "NULL") class Array(Type): """An array of the same type"""
tools/libxl/libxl_types.idl +2 -1
@@ -5,7 +5,8 @@ namespace("libxl_") -libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) +libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE, + init_val="LIBXL__DEFBOOL_DEFAULT") libxl_domid = Builtin("domid", json_gen_fn = "yajl_gen_integer", autogenerate_json = False) libxl_devid = Builtin("devid", json_gen_fn = "yajl_gen_integer", autogenerate_json = False, signed = True, init_val="-1")
Signature · 1 line
1.7.10.4
Re: [PATCH v6 11/18] libxl/gentypes.py: don't generate default values
Quoted 20 lines · Wei Liu
If a type has
init_valdefined and a field of the type has the value ofinit_val, there's no need to generate output for that field in JSON output. When the parser consumes that generated JSON object, all default values should be automatically filled in.Also define
init_valfor enumeration type, string type andlibxl_defbooltype.Signed-off-by Wei Liu <[email protected]>--- tools/libxl/gentypes.py | 27 ++++++++++++++++++++++++--- tools/libxl/idl.py | 3 ++- tools/libxl/libxl_types.idl | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-)tools/libxl/gentypes.py +0
-0
tools/libxl/gentypes.py def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): · line 138
Quoted 5 lines
tools/libxl/gentypes.py +1
-1@@ -135,7 +135,7 @@ def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): else: s += _libxl_C_type_init(f.type, fexpr, "", nparent) else: - if ty.init_val is not None: + if ty.init_val is not None and ty.typename != "libxl_defbool":
Why is libxl_defbool special here?
Quoted 22 lines
tools/libxl/gentypes.py +7
-1s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), ty.init_val) elif ty.init_fn is not None: s += "%s(%s);\n" % (ty.init_fn, ty.pass_arg(v, parent is None))@@ -206,6 +206,13 @@ def libxl_C_type_gen_map_key(f, parent, indent = ""): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def get_init_val(f): + if f.init_val is not None: + return f.init_val + elif f.type.init_val is not None: + return f.type.init_val + return None + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None:@@ -255,8 +262,22 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) - s += libxl_C_type_gen_map_key(f, nparent)
tools/libxl/gentypes.py def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): · line 273
Quoted 10 lines
tools/libxl/gentypes.py +9
-1- s += libxl_C_type_gen_json(f.type, fexpr, "", nparent) + init_val = get_init_val(f) + if init_val: + if f.type.typename != "libxl_defbool": + s += "if (%s != %s) {\n" % (fexpr, init_val) + else: + s += "if (%s.val != %s) {\n" % (fexpr, init_val) + indent1 = " " + else: + indent1 = ""
I don't think this is right. If a type doesn't has an init_val then its init_val is 0 and you should compare as a boolean. e.g.
if init_val:
s += "if (%s != %s) {\n" % (fexpr, init_val)
else:
s += "if (%s) {\n" % (fexpr)This gets rid of the special casing of libxl_defbool (where 0 == default) as well as removing a bunch of unnecessary p->foo = 0 from the generated init fns too.
You could also possibly implement this by having get_init_val return an explicit "0" as a fallback but I think that will resent in less clear generated code.
Quoted 14 lines
tools/libxl/gentypes.py +6
-0+ s += libxl_C_type_gen_map_key(f, nparent, indent1) + s += libxl_C_type_gen_json(f.type, fexpr, indent1, nparent) + + if init_val: + s += "}\n" + s += "s = yajl_gen_map_close(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"tools/libxl/idl.py +0
-0
tools/libxl/idl.py class EnumerationValue(object): · line 145
Quoted 4 lines
tools/libxl/idl.py +1
-0@@ -142,6 +142,7 @@ class EnumerationValue(object): class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('init_val', '0')
I'm not sure about this, but I think you don't need it for the reasons above.
tools/libxl/idl.py uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") · line 274
Quoted 9 lines
tools/libxl/idl.py +1
-1Type.__init__(self, typename, **kwargs) self.value_namespace = kwargs.setdefault('value_namespace',@@ -270,7 +271,7 @@ uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") string = Builtin("char *", namespace = None, dispose_fn = "free", json_gen_fn = "libxl__string_gen_json", - autogenerate_json = False) + autogenerate_json = False, init_val = "NULL")
If you do as I suggest above then you don't need this I think.
tools/libxl/idl.py uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") · line 276
Quoted 4 lines
tools/libxl/idl.py +2
-1-libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) +libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE, + init_val="LIBXL__DEFBOOL_DEFAULT")
Or this.
BTW, I happened to notice that some enums in the IDL define their (non-zero) default using the integer form, which isn't wrong but did leap out at me from the generated code. If you fancy fixing that while you are in the area that would be great. I noticed this on libxl_action_on_shutdown and libxl_vga_interface_type.
See libxl_timer_mode for how to do it properly. (Maybe idl.py should do the translation, but lets not go there...)
Re: [PATCH v6 11/18] libxl/gentypes.py: don't generate default values
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Wei Liu
If a type has
init_valdefined and a field of the type has the value ofinit_val, there's no need to generate output for that field in JSON output. When the parser consumes that generated JSON object, all default values should be automatically filled in.Also define
init_valfor enumeration type, string type andlibxl_defbooltype.Signed-off-by Wei Liu <[email protected]>--- tools/libxl/gentypes.py | 27 ++++++++++++++++++++++++--- tools/libxl/idl.py | 3 ++- tools/libxl/libxl_types.idl | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-)
Quoted 13 lines
tools/libxl/gentypes.py def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): · line 138
Quoted 10 lines
tools/libxl/gentypes.py +1
-1@@ -135,7 +135,7 @@ def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): else: s += _libxl_C_type_init(f.type, fexpr, "", nparent) else: - if ty.init_val is not None: + if ty.init_val is not None and ty.typename != "libxl_defbool":Why is
libxl_defboolspecial here?
Because it's an opaque type and I didn't bother to modify the code generator to have it generate some other functions to return value from opaque type, as libxl_defbool is the only one that needs extra care so far.
Quoted 35 lines
Quoted 22 lines
tools/libxl/gentypes.py +7
-1s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), ty.init_val) elif ty.init_fn is not None: s += "%s(%s);\n" % (ty.init_fn, ty.pass_arg(v, parent is None))@@ -206,6 +206,13 @@ def libxl_C_type_gen_map_key(f, parent, indent = ""): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def get_init_val(f): + if f.init_val is not None: + return f.init_val + elif f.type.init_val is not None: + return f.type.init_val + return None + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None:@@ -255,8 +262,22 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) - s += libxl_C_type_gen_map_key(f, nparent)tools/libxl/gentypes.py def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): · line 273
Quoted 10 lines
tools/libxl/gentypes.py +9
-1- s += libxl_C_type_gen_json(f.type, fexpr, "", nparent) + init_val = get_init_val(f) + if init_val: + if f.type.typename != "libxl_defbool": + s += "if (%s != %s) {\n" % (fexpr, init_val) + else: + s += "if (%s.val != %s) {\n" % (fexpr, init_val) + indent1 = " " + else: + indent1 = ""I don't think this is right. If a type doesn't has an
init_valthen itsinit_valis 0 and you should compare as a boolean. e.g.
Quoted 5 lines
if init_val:
s += "if (%s != %s) {\n" % (fexpr, init_val)
else:
s += "if (%s) {\n" % (fexpr)OK, I'm fine with this.
Quoted 4 lines
This gets rid of the special casing of
libxl_defbool(where 0 == default) as well as removing a bunch of unnecessaryp->foo= 0 from the generated init fns too.
Not true for libxl_defbool, as stated above, generating code like
if (some_defbool_field)
won't work.
Quoted 17 lines
You could also possibly implement this by having
get_init_valreturn an explicit "0" as a fallback but I think that will resent in less clear generated code.Quoted 13 lines
tools/libxl/gentypes.py +6
-0+ s += libxl_C_type_gen_map_key(f, nparent, indent1) + s += libxl_C_type_gen_json(f.type, fexpr, indent1, nparent) + + if init_val: + s += "}\n" + s += "s = yajl_gen_map_close(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"tools/libxl/idl.py +0
-0
Quoted 9 lines
tools/libxl/idl.py class EnumerationValue(object): · line 145
Quoted 5 lines
tools/libxl/idl.py +1
-0@@ -142,6 +142,7 @@ class EnumerationValue(object): class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('init_val', '0')I'm not sure about this, but I think you don't need it for the reasons above.
IIRC with this line Enumeration type doesn't have a default value.
Quoted 11 lines
tools/libxl/idl.py uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") · line 274
Quoted 9 lines
tools/libxl/idl.py +1
-1Type.__init__(self, typename, **kwargs) self.value_namespace = kwargs.setdefault('value_namespace',@@ -270,7 +271,7 @@ uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") string = Builtin("char *", namespace = None, dispose_fn = "free", json_gen_fn = "libxl__string_gen_json", - autogenerate_json = False) + autogenerate_json = False, init_val = "NULL")If you do as I suggest above then you don't need this I think.
Yes, you're right on this one.
Quoted 7 lines
tools/libxl/idl.py uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") · line 276
Quoted 4 lines
tools/libxl/idl.py +2
-1-libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) +libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE, + init_val="LIBXL__DEFBOOL_DEFAULT")Or this.
I would rather be explicit than implicit. LIBXL__DEFBOOL_DEFAULT happens to be 0 and that's all. If we ever change our internal implementation (however unlikely), generator will generate wrong thing. And I bet it won't be very pleasant to debug this...
Quoted 6 lines
BTW, I happened to notice that some enums in the IDL define their (non-zero) default using the integer form, which isn't wrong but did leap out at me from the generated code. If you fancy fixing that while you are in the area that would be great. I noticed this on
libxl_action_on_shutdownandlibxl_vga_interface_type.
I did that in my previous round but you said you wouldn't worry about readability of generated code (albeit I also modified those "0"s).
So you think it's only necessary to have non-zero default using LIBXL_* defines? I'm fine with this.
Wei.
Quoted 2 lines
See
libxl_timer_modefor how to do it properly. (Maybeidl.pyshould do the translation, but lets not go there...)
Re: [PATCH v6 11/18] libxl/gentypes.py: don't generate default values
On Tue, Jun 10, 2014 at 02:43:00PM +0100, Wei Liu wrote:
[...]
Quoted 3 lines
Quoted 1 line
IIRC with this line Enumeration type doesn't have a default value.
^^ without
Re: [PATCH v6 11/18] libxl/gentypes.py: don't generate default values
In reply to Wei LiuQuoted 31 lines · Wei Liu
Quoted 16 lines · Ian Campbell
Quoted 15 lines · Wei Liu
If a type has
init_valdefined and a field of the type has the value ofinit_val, there's no need to generate output for that field in JSON output. When the parser consumes that generated JSON object, all default values should be automatically filled in.Also define
init_valfor enumeration type, string type andlibxl_defbooltype.Signed-off-by Wei Liu <[email protected]>--- tools/libxl/gentypes.py | 27 ++++++++++++++++++++++++--- tools/libxl/idl.py | 3 ++- tools/libxl/libxl_types.idl | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-)Quoted 13 lines
tools/libxl/gentypes.py def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): · line 138
Quoted 10 lines
tools/libxl/gentypes.py +1
-1@@ -135,7 +135,7 @@ def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): else: s += _libxl_C_type_init(f.type, fexpr, "", nparent) else: - if ty.init_val is not None: + if ty.init_val is not None and ty.typename != "libxl_defbool":Why is
libxl_defboolspecial here?
Quoted 4 lines
Because it's an opaque type and I didn't bother to modify the code generator to have it generate some other functions to return value from opaque type, as
libxl_defboolis the only one that needs extra care so far.
Ah, ok. BTW I think "ty != libxl_debool" is valid. Or maybe isinstance(), whichever one works is better than a string compare I think.
Quoted 44 lines
Quoted 36 lines
Quoted 23 lines
tools/libxl/gentypes.py +7
-1s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), ty.init_val) elif ty.init_fn is not None: s += "%s(%s);\n" % (ty.init_fn, ty.pass_arg(v, parent is None))@@ -206,6 +206,13 @@ def libxl_C_type_gen_map_key(f, parent, indent = ""): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def get_init_val(f): + if f.init_val is not None: + return f.init_val + elif f.type.init_val is not None: + return f.type.init_val + return None + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None:@@ -255,8 +262,22 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) - s += libxl_C_type_gen_map_key(f, nparent)tools/libxl/gentypes.py def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): · line 273
Quoted 10 lines
tools/libxl/gentypes.py +9
-1- s += libxl_C_type_gen_json(f.type, fexpr, "", nparent) + init_val = get_init_val(f) + if init_val: + if f.type.typename != "libxl_defbool": + s += "if (%s != %s) {\n" % (fexpr, init_val) + else: + s += "if (%s.val != %s) {\n" % (fexpr, init_val) + indent1 = " " + else: + indent1 = ""I don't think this is right. If a type doesn't has an
init_valthen itsinit_valis 0 and you should compare as a boolean. e.g.Quoted 5 lines
if init_val: s += "if (%s != %s) {\n" % (fexpr, init_val) else: s += "if (%s) {\n" % (fexpr)OK, I'm fine with this.
Quoted 8 lines
Quoted 4 lines
This gets rid of the special casing of
libxl_defbool(where 0 == default) as well as removing a bunch of unnecessaryp->foo= 0 from the generated init fns too.Not true for
libxl_defbool, as stated above, generating code like
if (some_defbool_field)
won't work.
Oh yes. Ick.
Can you perhaps abstract this into:
def get_field_val(ftype, fexpr):
ftype == libxl_defbool:
return "%s.val" % fexpr
else:
return fexpr
?
Quoted 28 lines
Quoted 18 lines
You could also possibly implement this by having
get_init_valreturn an explicit "0" as a fallback but I think that will resent in less clear generated code.Quoted 13 lines
tools/libxl/gentypes.py +6
-0+ s += libxl_C_type_gen_map_key(f, nparent, indent1) + s += libxl_C_type_gen_json(f.type, fexpr, indent1, nparent) + + if init_val: + s += "}\n" + s += "s = yajl_gen_map_close(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"tools/libxl/idl.py +0
-0Quoted 9 lines
tools/libxl/idl.py class EnumerationValue(object): · line 145
Quoted 5 lines
tools/libxl/idl.py +1
-0@@ -142,6 +142,7 @@ class EnumerationValue(object): class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('init_val', '0')I'm not sure about this, but I think you don't need it for the reasons above.
Quoted 1 line
IIRC with this line Enumeration type doesn't have a default value.
^out (per your other mail)
It should be None, which I think is set by the following Type.__init__.
Quoted 8 lines
Quoted 7 lines
tools/libxl/idl.py class EnumerationValue(object): · line 147
Quoted 4 lines
tools/libxl/idl.py +2
-1-libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) +libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE, + init_val="LIBXL__DEFBOOL_DEFAULT")Or this.
Quoted 4 lines
I would rather be explicit than implicit.
LIBXL__DEFBOOL_DEFAULThappens to be 0 and that's all. If we ever change our internal implementation (however unlikely), generator will generate wrong thing. And I bet it won't be very pleasant to debug this...
The assumption that the default bit pattern for any type is all zeroes is pretty firmly baked into lots of places. It is incredibly unlikely that this is going to change.
Quoted 9 lines
Quoted 6 lines
BTW, I happened to notice that some enums in the IDL define their (non-zero) default using the integer form, which isn't wrong but did leap out at me from the generated code. If you fancy fixing that while you are in the area that would be great. I noticed this on
libxl_action_on_shutdownandlibxl_vga_interface_type.I did that in my previous round but you said you wouldn't worry about readability of generated code (albeit I also modified those "0"s).
So I did, I started off mentioning the unlogged s/1/LIBXL_VGA_INTERFACE_TYPE_CIRRUS/ but then didn't notice that we got on to talking about 0s too. Sorry.
Quoted 2 lines
So you think it's only necessary to have non-zero default using LIBXL_* defines? I'm fine with this.
If they have an init_val at all I think it should use the names not the numbers. If the default is 0 then it needn't be specified explicitly (and in that case it'll be if (x) not if (x==THING) in the generated code)
But no need to fix this unless you want to, it's just a minor wrinkle in the existing thing.
Quoted 4 lines
Wei.
Quoted 2 lines
See
libxl_timer_modefor how to do it properly. (Maybeidl.pyshould do the translation, but lets not go there...)
Re: [PATCH v6 11/18] libxl/gentypes.py: don't generate default values
On Tue, Jun 10, 2014 at 03:56:10PM +0100, Ian Campbell wrote:
[...]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
tools/libxl/gentypes.py def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): · line 138
Quoted 2 lines
tools/libxl/gentypes.py +1
-1- if ty.init_val is not None: + if ty.init_val is not None and ty.typename != "libxl_defbool":Why is
libxl_defboolspecial here?
Quoted 9 lines
Quoted 4 lines
Because it's an opaque type and I didn't bother to modify the code generator to have it generate some other functions to return value from opaque type, as
libxl_defboolis the only one that needs extra care so far.Ah, ok. BTW I think "ty !=
libxl_debool" is valid. Or maybeisinstance(), whichever one works is better than a string compare I think.
No problem.
Quoted 57 lines
Quoted 44 lines
Quoted 36 lines
Quoted 23 lines
s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), ty.init_val) elif ty.init_fn is not None: s += "%s(%s);\n" % (ty.init_fn, ty.pass_arg(v, parent is None))tools/libxl/gentypes.py +7
-1@@ -206,6 +206,13 @@ def libxl_C_type_gen_map_key(f, parent, indent = ""): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def get_init_val(f): + if f.init_val is not None: + return f.init_val + elif f.type.init_val is not None: + return f.type.init_val + return None + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None:@@ -255,8 +262,22 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) - s += libxl_C_type_gen_map_key(f, nparent)tools/libxl/gentypes.py def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): · line 273
Quoted 10 lines
tools/libxl/gentypes.py +9
-1- s += libxl_C_type_gen_json(f.type, fexpr, "", nparent) + init_val = get_init_val(f) + if init_val: + if f.type.typename != "libxl_defbool": + s += "if (%s != %s) {\n" % (fexpr, init_val) + else: + s += "if (%s.val != %s) {\n" % (fexpr, init_val) + indent1 = " " + else: + indent1 = ""I don't think this is right. If a type doesn't has an
init_valthen itsinit_valis 0 and you should compare as a boolean. e.g.Quoted 5 lines
if init_val: s += "if (%s != %s) {\n" % (fexpr, init_val) else: s += "if (%s) {\n" % (fexpr)OK, I'm fine with this.
Quoted 8 lines
Quoted 4 lines
This gets rid of the special casing of
libxl_defbool(where 0 == default) as well as removing a bunch of unnecessaryp->foo= 0 from the generated init fns too.Not true for
libxl_defbool, as stated above, generating code like
if (some_defbool_field)
won't work.Oh yes. Ick.
Can you perhaps abstract this into:
Quoted 7 lines
def
get_field_val(ftype, fexpr):
ftype ==libxl_defbool:
return "%s.val" % fexpr
else:
return fexpr?
Good idea.
Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
You could also possibly implement this by having
get_init_valreturn an explicit "0" as a fallback but I think that will resent in less clear generated code.Quoted 14 lines
tools/libxl/gentypes.py +6
-0+ s += libxl_C_type_gen_map_key(f, nparent, indent1) + s += libxl_C_type_gen_json(f.type, fexpr, indent1, nparent) + + if init_val: + s += "}\n" + s += "s = yajl_gen_map_close(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"tools/libxl/idl.py +0
-0tools/libxl/idl.py class EnumerationValue(object): · line 145
Quoted 4 lines
tools/libxl/idl.py +1
-0@@ -142,6 +142,7 @@ class EnumerationValue(object): class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('init_val', '0')I'm not sure about this, but I think you don't need it for the reasons above.
Quoted 5 lines
Quoted 1 line
IIRC with this line Enumeration type doesn't have a default value.
^out (per your other mail)
It should be None, which I think is set by the following Type.__init__.
Yes, it's None if it's not explicitly set.
If I make get_init_val function return 0 when it encounters None then I don't need this hunk anymore.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
tools/libxl/idl.py class EnumerationValue(object): · line 147
Quoted 4 lines
tools/libxl/idl.py +2
-1-libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE) +libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE, + init_val="LIBXL__DEFBOOL_DEFAULT")Or this.
Quoted 9 lines
Quoted 4 lines
I would rather be explicit than implicit.
LIBXL__DEFBOOL_DEFAULThappens to be 0 and that's all. If we ever change our internal implementation (however unlikely), generator will generate wrong thing. And I bet it won't be very pleasant to debug this...The assumption that the default bit pattern for any type is all zeroes is pretty firmly baked into lots of places. It is incredibly unlikely that this is going to change.
Ack.
Quoted 17 lines
Quoted 9 lines
Quoted 6 lines
BTW, I happened to notice that some enums in the IDL define their (non-zero) default using the integer form, which isn't wrong but did leap out at me from the generated code. If you fancy fixing that while you are in the area that would be great. I noticed this on
libxl_action_on_shutdownandlibxl_vga_interface_type.I did that in my previous round but you said you wouldn't worry about readability of generated code (albeit I also modified those "0"s).
So I did, I started off mentioning the unlogged s/1/LIBXL_VGA_INTERFACE_TYPE_CIRRUS/ but then didn't notice that we got on to talking about 0s too. Sorry.
Quoted 2 lines
So you think it's only necessary to have non-zero default using LIBXL_* defines? I'm fine with this.
Quoted 8 lines
If they have an
init_valat all I think it should use the names not the numbers. If the default is 0 then it needn't be specified explicitly (and in that case it'll be if (x) not if (x==THING) in the generated code)But no need to fix this unless you want to, it's just a minor wrinkle in the existing thing.
This is rather trivial after all. I can fix this in my next version.
Wei.
Re: [PATCH v6 11/18] libxl/gentypes.py: don't generate default values
Quoted 118 lines · Wei Liu
On Tue, Jun 10, 2014 at 03:56:10PM +0100, Ian Campbell wrote:
[...]Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
tools/libxl/gentypes.py def _libxl_C_type_init(ty, v, indent = " ", parent = None, subinit=False): · line 138
Quoted 2 lines
tools/libxl/gentypes.py +1
-1- if ty.init_val is not None: + if ty.init_val is not None and ty.typename != "libxl_defbool":Why is
libxl_defboolspecial here?Quoted 9 lines
Quoted 4 lines
Because it's an opaque type and I didn't bother to modify the code generator to have it generate some other functions to return value from opaque type, as
libxl_defboolis the only one that needs extra care so far.Ah, ok. BTW I think "ty !=
libxl_debool" is valid. Or maybeisinstance(), whichever one works is better than a string compare I think.No problem.
Quoted 57 lines
Quoted 44 lines
Quoted 36 lines
Quoted 23 lines
s += "%s = %s;\n" % (ty.pass_arg(v, parent is None), ty.init_val) elif ty.init_fn is not None: s += "%s(%s);\n" % (ty.init_fn, ty.pass_arg(v, parent is None))tools/libxl/gentypes.py +7
-1@@ -206,6 +206,13 @@ def libxl_C_type_gen_map_key(f, parent, indent = ""): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def get_init_val(f): + if f.init_val is not None: + return f.init_val + elif f.type.init_val is not None: + return f.type.init_val + return None + def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s = "" if parent is None:@@ -255,8 +262,22 @@ def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): s += " goto out;\n" for f in [f for f in ty.fields if not f.const and not f.type.private]: (nparent,fexpr) = ty.member(v, f, parent is None) - s += libxl_C_type_gen_map_key(f, nparent)tools/libxl/gentypes.py def libxl_C_type_gen_json(ty, v, indent = " ", parent = None): · line 273
Quoted 10 lines
tools/libxl/gentypes.py +9
-1- s += libxl_C_type_gen_json(f.type, fexpr, "", nparent) + init_val = get_init_val(f) + if init_val: + if f.type.typename != "libxl_defbool": + s += "if (%s != %s) {\n" % (fexpr, init_val) + else: + s += "if (%s.val != %s) {\n" % (fexpr, init_val) + indent1 = " " + else: + indent1 = ""I don't think this is right. If a type doesn't has an
init_valthen itsinit_valis 0 and you should compare as a boolean. e.g.Quoted 5 lines
if init_val: s += "if (%s != %s) {\n" % (fexpr, init_val) else: s += "if (%s) {\n" % (fexpr)OK, I'm fine with this.
Quoted 8 lines
Quoted 4 lines
This gets rid of the special casing of
libxl_defbool(where 0 == default) as well as removing a bunch of unnecessaryp->foo= 0 from the generated init fns too.Not true for
libxl_defbool, as stated above, generating code like
if (some_defbool_field)
won't work.Oh yes. Ick.
Can you perhaps abstract this into:
Quoted 7 lines
def
get_field_val(ftype, fexpr):
ftype ==libxl_defbool:
return "%s.val" % fexpr
else:
return fexpr?
Good idea.
Quoted 31 lines
Quoted 28 lines
Quoted 18 lines
You could also possibly implement this by having
get_init_valreturn an explicit "0" as a fallback but I think that will resent in less clear generated code.Quoted 13 lines
tools/libxl/gentypes.py +6
-0+ s += libxl_C_type_gen_map_key(f, nparent, indent1) + s += libxl_C_type_gen_json(f.type, fexpr, indent1, nparent) + + if init_val: + s += "}\n" + s += "s = yajl_gen_map_close(hand);\n" s += "if (s != yajl_gen_status_ok)\n" s += " goto out;\n"tools/libxl/idl.py +0
-0Quoted 9 lines
tools/libxl/idl.py class EnumerationValue(object): · line 145
Quoted 5 lines
tools/libxl/idl.py +1
-0@@ -142,6 +142,7 @@ class EnumerationValue(object): class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('init_val', '0')I'm not sure about this, but I think you don't need it for the reasons above.
Quoted 1 line
IIRC with this line Enumeration type doesn't have a default value.
^out (per your other mail)
Quoted 7 lines
Quoted 2 lines
It should be None, which I think is set by the following Type.__init__.
Yes, it's None if it's not explicitly set.
If I make
get_init_valfunction return 0 when it encounters None then I don't need this hunk anymore.
I think it should return None in this case and then you use
if init_val:
s += "if (%s != %s) {\n" % (fexpr, init_val)
else:
s += "if (%s) {\n" % (fexpr)as discussed previously. Or maybe you could make get_init_val return the complete appropriate expression and call it get_default_expr (or something better than that)
Quoted 22 lines
Quoted 22 lines
Quoted 9 lines
Quoted 6 lines
BTW, I happened to notice that some enums in the IDL define their (non-zero) default using the integer form, which isn't wrong but did leap out at me from the generated code. If you fancy fixing that while you are in the area that would be great. I noticed this on
libxl_action_on_shutdownandlibxl_vga_interface_type.I did that in my previous round but you said you wouldn't worry about readability of generated code (albeit I also modified those "0"s).
So I did, I started off mentioning the unlogged s/1/LIBXL_VGA_INTERFACE_TYPE_CIRRUS/ but then didn't notice that we got on to talking about 0s too. Sorry.
Quoted 2 lines
So you think it's only necessary to have non-zero default using LIBXL_* defines? I'm fine with this.
If they have an
init_valat all I think it should use the names not the numbers. If the default is 0 then it needn't be specified explicitly (and in that case it'll be if (x) not if (x==THING) in the generated code)
Quoted 5 lines
Quoted 3 lines
But no need to fix this unless you want to, it's just a minor wrinkle in the existing thing.
This is rather trivial after all. I can fix this in my next version.
Thanks.
Ian.
Re: [PATCH v6 11/18] libxl/gentypes.py: don't generate default values
On Tue, Jun 10, 2014 at 04:54:26PM +0100, Ian Campbell wrote:
[...]
Quoted 12 lines
Quoted 10 lines
Quoted 5 lines
Quoted 1 line
IIRC with this line Enumeration type doesn't have a default value.
^out (per your other mail)
It should be None, which I think is set by the following Type.__init__.
Yes, it's None if it's not explicitly set.
If I make
get_init_valfunction return 0 when it encounters None then I don't need this hunk anymore.I think it should return None in this case and then you use
Quoted 9 lines
if init_val: s += "if (%s != %s) {\n" % (fexpr, init_val) else: s += "if (%s) {\n" % (fexpr)as discussed previously. Or maybe you could make
get_init_valreturn the complete appropriate expression and call itget_default_expr(or something better than that)
Oh I was talking nonsense in my previous email. get_init_val is in fact returning the expression and your suggestion to change it to get_default_expr is good. Anyway, I will figure this out. Sorry for the confusion.
Wei.
PATCH v6 12/18 libxl IDL: generate code to parse libxl__json_object to libxl_FOO struct
In reply to Wei Liulibxl_FOO_parse_json functions are generated.
Note that these functions are used to parse libxl__json_object to libxl__FOO struct. They don't consume JSON string.
--- tools/libxl/gentypes.py | 131 ++++++++++++++++++++++++++++++++++ tools/libxl/idl.py | 15 ++++ tools/libxl/idl.txt | 7 +- tools/libxl/libxl.h | 14 ++++ tools/libxl/libxl_types.idl | 29 ++++---- tools/libxl/libxl_types_internal.idl | 4 +- 6 files changed, 186 insertions(+), 14 deletions(-)
tools/libxl/gentypes.py +131 -0
@@ -304,6 +304,116 @@ def libxl_C_type_to_json(ty, v, indent = " "): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def libxl_C_type_parse_json(ty, w, v, indent = " ", parent = None, discriminator = None): + s = "" + if parent is None: + s += "int rc = 0;\n" + s += "const libxl__json_object *x = o;\n" + + if isinstance(ty, idl.Array): + if parent is None: + raise Exception("Array type must have a parent") + if discriminator is not None: + raise Exception("Only KeyedUnion can have discriminator") + lenvar = parent + ty.lenvar.name + s += "{\n" + s += " libxl__json_object *t;\n" + s += " int i;\n" + s += " if (!libxl__json_object_is_array(x)) {\n" + s += " rc = -1;\n" + s += " goto out;\n" + s += " }\n" + s += " %s = x->u.array->count;\n" % lenvar + s += " %s = libxl__calloc(NOGC, %s, sizeof(*%s));\n" % (v, lenvar, v) + s += " if (!%s && %s != 0) {\n" % (v, lenvar) + s += " rc = -1;\n" + s += " goto out;\n" + s += " }\n" + s += " for (i=0; (t=libxl__json_array_get(x,i)); i++) {\n" + s += libxl_C_type_parse_json(ty.elem_type, "t", v+"[i]", + indent + " ", parent) + s += " }\n" + s += " if (i != %s) {\n" % lenvar + s += " rc = -1;\n" + s += " goto out;\n" + s += " }\n" + s += "}\n" + elif isinstance(ty, idl.Enumeration): + if discriminator is not None: + raise Exception("Only KeyedUnion can have discriminator") + s += "{\n" + s += " const char *enum_str;\n" + s += " if (!libxl__json_object_is_string(x)) {\n" + s += " rc = -1;\n" + s += " goto out;\n" + s += " }\n" + s += " enum_str = libxl__json_object_get_string(x);\n" + s += " rc = %s_from_string(enum_str, %s);\n" % (ty.typename, ty.pass_arg(v, parent is None, idl.PASS_BY_REFERENCE)) + s += " if (rc)\n" + s += " goto out;\n" + s += "}\n" + elif isinstance(ty, idl.KeyedUnion): + if parent is None: + raise Exception("KeyedUnion type must have a parent") + if discriminator is None: + raise Excpetion("KeyedUnion type must have a discriminator") + for f in ty.fields: + if f.enumname != discriminator: + continue + (nparent,fexpr) = ty.member(v, f, parent is None) + if f.type is not None: + s += libxl_C_type_parse_json(f.type, w, fexpr, indent + " ", nparent) + elif isinstance(ty, idl.Struct) and (parent is None or ty.json_parse_fn is None): + if discriminator is not None: + raise Exception("Only KeyedUnion can have discriminator") + for f in [f for f in ty.fields if not f.const and not f.type.private]: + saved_var_name = "saved_%s" % f.name + s += "{\n" + s += " const libxl__json_object *%s = NULL;\n" % saved_var_name + s += " %s = x;\n" % saved_var_name + if isinstance(f.type, idl.KeyedUnion): + for x in f.type.fields: + s += " x = libxl__json_map_get(\"%s\", %s, JSON_MAP);\n" % \ + (f.type.keyvar.name + "." + x.name, w) + s += " if (x) {\n" + (nparent, fexpr) = ty.member(v, f.type.keyvar, parent is None) + s += " %s = %s;\n" % (fexpr, x.enumname) + (nparent,fexpr) = ty.member(v, f, parent is None) + s += libxl_C_type_parse_json(f.type, "x", fexpr, " ", nparent, x.enumname) + s += " }\n" + else: + s += " x = libxl__json_map_get(\"%s\", %s, %s);\n" % (f.name, w, f.type.json_parse_type) + s += " if (x) {\n" + (nparent,fexpr) = ty.member(v, f, parent is None) + s += libxl_C_type_parse_json(f.type, "x", fexpr, " ", nparent) + s += " }\n" + s += " x = %s;\n" % saved_var_name + s += "}\n" + else: + if discriminator is not None: + raise Exception("Only KeyedUnion can have discriminator") + if ty.json_parse_fn is not None: + s += "rc = %s(gc, %s, &%s);\n" % (ty.json_parse_fn, w, v) + s += "if (rc)\n" + s += " goto out;\n" + + if parent is None: + s += "out:\n" + s += "return rc;\n" + + if s != "": + s = indent +s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + +def libxl_C_type_from_json(ty, v, w, indent = " "): + s = "" + parse = "(libxl__json_parse_callback)&%s_parse_json" % ty.typename + s += "return libxl__object_from_json(ctx, \"%s\", %s, %s, %s);\n" % (ty.typename, parse, v, w) + + if s != "": + s = indent + s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + def libxl_C_enum_to_string(ty, e, indent = " "): s = "" s += "switch(%s) {\n" % e
@@ -382,6 +492,8 @@ if __name__ == '__main__': ku.keyvar.type.make_arg(ku.keyvar.name))) if ty.json_gen_fn is not None: f.write("%schar *%s_to_json(libxl_ctx *ctx, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p"))) + if ty.json_parse_fn is not None: + f.write("%sint %s_from_json(libxl_ctx *ctx, %s, const char *s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) if isinstance(ty, idl.Enumeration): f.write("%sconst char *%s_to_string(%s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p"))) f.write("%sint %s_from_string(const char *s, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("e", passby=idl.PASS_BY_REFERENCE)))
@@ -411,6 +523,10 @@ if __name__ == '__main__': for ty in [ty for ty in types if ty.json_gen_fn is not None]: f.write("%syajl_gen_status %s_gen_json(yajl_gen hand, %s);\n" % (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) + for ty in [ty for ty in types if ty.json_parse_fn is not None]: + f.write("%sint %s_parse_json(libxl__gc *gc, const libxl__json_object *o, %s);\n" % \ + (ty.hidden(), ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) + f.write("\n") f.write("""#endif /* %s */\n""" % header_json_define) f.close()
@@ -478,4 +594,19 @@ if __name__ == '__main__': f.write("}\n") f.write("\n") + for ty in [t for t in types if t.json_parse_fn is not None]: + f.write("int %s_parse_json(libxl__gc *gc, const libxl__json_object *%s, %s)\n" % (ty.typename,"o",ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) + f.write("{\n") + f.write(libxl_C_type_parse_json(ty, "o", "p")) + f.write("}\n") + f.write("\n") + + f.write("int %s_from_json(libxl_ctx *ctx, %s, const char *s)\n" % (ty.typename, ty.make_arg("p", passby=idl.PASS_BY_REFERENCE))) + f.write("{\n") + if not isinstance(ty, idl.Enumeration): + f.write(" %s_init(p);\n" % ty.typename) + f.write(libxl_C_type_from_json(ty, "p", "s")) + f.write("}\n") + f.write("\n") + f.close()
tools/libxl/idl.py +15 -0
@@ -66,8 +66,12 @@ class Type(object): if self.typename is not None and not self.private: self.json_gen_fn = kwargs.setdefault('json_gen_fn', self.typename + "_gen_json") + self.json_parse_type = kwargs.setdefault('json_parse_type', "JSON_ANY") + self.json_parse_fn = kwargs.setdefault('json_parse_fn', self.typename + "_parse_json") else: self.json_gen_fn = kwargs.setdefault('json_gen_fn', None) + self.json_parse_type = kwargs.setdefault('json_parse_type', None) + self.json_parse_fn = kwargs.setdefault('json_parse_fn', None) self.autogenerate_json = kwargs.setdefault('autogenerate_json', True)
@@ -119,6 +123,9 @@ class Number(Builtin): kwargs.setdefault('dispose_fn', None) kwargs.setdefault('signed', False) kwargs.setdefault('json_gen_fn', "yajl_gen_integer") + kwargs.setdefault('json_parse_type', "JSON_INTEGER") + # json_parse_fn might be overriden on specific type + kwargs.setdefault('json_parse_fn', "libxl__int_parse_json") self.signed = kwargs['signed'] Builtin.__init__(self, ctype, **kwargs)
@@ -126,6 +133,7 @@ class UInt(Number): def __init__(self, w, **kwargs): kwargs.setdefault('namespace', None) kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('json_parse_fn', "libxl__uint%d_parse_json" % w) Number.__init__(self, "uint%d_t" % w, **kwargs) self.width = w
@@ -143,6 +151,7 @@ class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) kwargs.setdefault('init_val', '0') + kwargs.setdefault('json_parse_type', "JSON_STRING") Type.__init__(self, typename, **kwargs) self.value_namespace = kwargs.setdefault('value_namespace',
@@ -172,6 +181,7 @@ class Field(object): class Aggregate(Type): """A type containing a collection of other types""" def __init__(self, kind, typename, fields, **kwargs): + kwargs.setdefault('json_parse_type', "JSON_MAP") Type.__init__(self, typename, **kwargs) if self.typename is not None:
@@ -258,6 +268,8 @@ class KeyedUnion(Aggregate): void = Builtin("void *", namespace = None) bool = Builtin("bool", namespace = None, json_gen_fn = "yajl_gen_bool", + json_parse_type = "JSON_BOOL", + json_parse_fn = "libxl__bool_parse_json", autogenerate_json = False) size_t = Number("size_t", namespace = None)
@@ -271,12 +283,15 @@ uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") string = Builtin("char *", namespace = None, dispose_fn = "free", json_gen_fn = "libxl__string_gen_json", + json_parse_type = "JSON_STRING | JSON_NULL", + json_parse_fn = "libxl__string_parse_json", autogenerate_json = False, init_val = "NULL") class Array(Type): """An array of the same type""" def __init__(self, elem_type, lenvar_name, **kwargs): kwargs.setdefault('dispose_fn', 'free') + kwargs.setdefault('json_parse_type', 'JSON_ARRAY') Type.__init__(self, namespace=elem_type.namespace, typename=elem_type.rawname + " *", **kwargs) lv_kwargs = dict([(x.lstrip('lenvar_'),y) for (x,y) in kwargs.items() if x.startswith('lenvar_')])
tools/libxl/idl.txt +6 -1
@@ -65,9 +65,14 @@ Type.json_gen_fn: (default: typename + "_gen_json" or None if type == None) The name of the C function which will generate a YAJL data structure representing this type. +Type.json_parse_fn: (default: typename + "_parse_json" or None if type == None) + + The name of the C function which will parse a libxl JSON structure + representing this type to C type. + Type.autogenerate_json: (default: True) - Indicates if the above named Type.json_gen_fn should be autogenerated. + Indicates if the above named Type.json_*_fn should be autogenerated. Other simple type-Classes -------------------------
tools/libxl/libxl.h +14 -0
@@ -305,6 +305,20 @@* * Generates a JSON object from "p" in the form of a NULL terminated * string. +* +* <type *> libxl_<type>_from_json(const char *json) +* int libxl_<type>_from_json(const char *json) +* +* Parses "json" and returns: +* +* an int value, if <type> is enumeration type. The value is the enum value +* representing the respective string in "json". +* +* an instance of <type>, if <type> is aggregate type. The returned +* instance has its fields filled in by the parser according to "json". +* +* If the parsing fails, caller cannot rely on the value / instance +* returned. */ #ifndef LIBXL_H #define LIBXL_H
tools/libxl/libxl_types.idl +17 -12
@@ -5,19 +5,24 @@ namespace("libxl_") -libxl_defbool = Builtin("defbool", passby=PASS_BY_REFERENCE, +libxl_defbool = Builtin("defbool", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, init_val="LIBXL__DEFBOOL_DEFAULT") -libxl_domid = Builtin("domid", json_gen_fn = "yajl_gen_integer", autogenerate_json = False) -libxl_devid = Builtin("devid", json_gen_fn = "yajl_gen_integer", autogenerate_json = False, signed = True, init_val="-1") -libxl_uuid = Builtin("uuid", passby=PASS_BY_REFERENCE) -libxl_mac = Builtin("mac", passby=PASS_BY_REFERENCE) -libxl_bitmap = Builtin("bitmap", dispose_fn="libxl_bitmap_dispose", passby=PASS_BY_REFERENCE) -libxl_cpuid_policy_list = Builtin("cpuid_policy_list", dispose_fn="libxl_cpuid_dispose", passby=PASS_BY_REFERENCE) - -libxl_string_list = Builtin("string_list", dispose_fn="libxl_string_list_dispose", passby=PASS_BY_REFERENCE) -libxl_key_value_list = Builtin("key_value_list", dispose_fn="libxl_key_value_list_dispose", passby=PASS_BY_REFERENCE) -libxl_hwcap = Builtin("hwcap", passby=PASS_BY_REFERENCE) +libxl_domid = Builtin("domid", json_gen_fn = "yajl_gen_integer", json_parse_fn = "libxl__uint32_parse_json", + json_parse_type = "JSON_INTEGER", autogenerate_json = False) +libxl_devid = Builtin("devid", json_gen_fn = "yajl_gen_integer", json_parse_fn = "libxl__int_parse_json", + json_parse_type = "JSON_INTEGER", autogenerate_json = False, signed = True, init_val="-1") +libxl_uuid = Builtin("uuid", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE) +libxl_mac = Builtin("mac", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE) +libxl_bitmap = Builtin("bitmap", json_parse_type="JSON_ARRAY", dispose_fn="libxl_bitmap_dispose", passby=PASS_BY_REFERENCE) +libxl_cpuid_policy_list = Builtin("cpuid_policy_list", json_parse_type="JSON_ARRAY", + dispose_fn="libxl_cpuid_dispose", passby=PASS_BY_REFERENCE) + +libxl_string_list = Builtin("string_list", json_parse_type="JSON_ARRAY", + dispose_fn="libxl_string_list_dispose", passby=PASS_BY_REFERENCE) +libxl_key_value_list = Builtin("key_value_list", json_parse_type="JSON_MAP", + dispose_fn="libxl_key_value_list_dispose", passby=PASS_BY_REFERENCE) +libxl_hwcap = Builtin("hwcap", json_parse_type="JSON_ARRAY", passby=PASS_BY_REFERENCE) # # Specific integer types
@@ -583,7 +588,7 @@ libxl_event_type = Enumeration("event_type", [ libxl_ev_user = UInt(64) -libxl_ev_link = Builtin("ev_link", passby=PASS_BY_REFERENCE, private=True) +libxl_ev_link = Builtin("ev_link", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, private=True) libxl_event = Struct("event",[ ("link", libxl_ev_link),
tools/libxl/libxl_types_internal.idl +3 -1
@@ -1,7 +1,9 @@ namespace("libxl__") hidden(True) -libxl_domid = Builtin("domid", namespace="libxl_", json_gen_fn = "yajl_gen_integer") +libxl_domid = Builtin("domid", namespace="libxl_", json_gen_fn = "yajl_gen_integer", + json_parse_fn = "libxl__uint32_parse_json", json_parse_type = "JSON_INTEGER", + autogenerate_json = False) libxl__qmp_message_type = Enumeration("qmp_message_type", [ (1, "QMP"),
Signature · 1 line
1.7.10.4
Re: [PATCH v6 12/18] libxl IDL: generate code to parse libxl__json_object to libxl_FOO struct
Quoted 6 lines · Wei Liu
libxl_FOO_parse_jsonfunctions are generated.Note that these functions are used to parse
libxl__json_objecttolibxl__FOOstruct. They don't consume JSON string.Signed-off-by Wei Liu <[email protected]>
One small thought:
tools/libxl/gentypes.py def libxl_C_type_to_json(ty, v, indent = " "): · line 373
Quoted 5 lines
tools/libxl/gentypes.py +5
-0+ for f in [f for f in ty.fields if not f.const and not f.type.private]: + saved_var_name = "saved_%s" % f.name + s += "{\n" + s += " const libxl__json_object *%s = NULL;\n" % saved_var_name + s += " %s = x;\n" % saved_var_name
You could do the assign and the declaration on one line.
PATCH v6 13/18 libxl/gentest.py: test JSON parser
In reply to Wei LiuThe test is done in following steps:
1. initialise libxl_FOO struct
2. generate JSON string A for libxl_FOO struct FOO1
3. convert JSON string A to libxl_FOO struct FOO2
4. generate JSON string B for libxl_FOO struct FOO2
5. compare A and B
If A and B are identical then we are good.
--- tools/libxl/gentest.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
tools/libxl/gentest.py +20 -3
@@ -225,10 +225,11 @@ int main(int argc, char **argv) """) for ty in types: - f.write(" %s %s_val;\n" % (ty.typename, ty.typename)) + f.write(" %s %s_val, %s_val_new;\n" % \ + (ty.typename, ty.typename, ty.typename)) f.write(""" int rc; - char *s; + char *s, *new_s; xentoollog_logger_stdiostream *logger; libxl_ctx *ctx;
@@ -240,20 +241,36 @@ int main(int argc, char **argv) exit(1); } """) - f.write(" printf(\"Testing TYPE_to_json()\\n\");\n") + f.write(" printf(\"Testing TYPE_to/from_json()\\n\");\n") f.write(" printf(\"----------------------\\n\");\n") f.write(" printf(\"\\n\");\n") for ty in [t for t in types if t.json_gen_fn is not None]: arg = ty.typename + "_val" f.write(" %s_rand_init(%s);\n" % (ty.typename, \ ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) + if not isinstance(ty, idl.Enumeration): + f.write(" %s_init(%s_new);\n" % (ty.typename, \ + ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) f.write(" s = %s_to_json(ctx, %s);\n" % \ (ty.typename, ty.pass_arg(arg, isref=False))) f.write(" printf(\"%%s: %%s\\n\", \"%s\", s);\n" % ty.typename) f.write(" if (s == NULL) abort();\n") + f.write(" rc = %s_from_json(ctx, &%s_val_new, s);\n" % \ + (ty.typename, ty.typename)) + f.write(" if (rc) abort();\n") + f.write(" new_s = %s_to_json(ctx, %s_new);\n" % \ + (ty.typename, ty.pass_arg(arg, isref=False))) + f.write(" if (new_s == NULL) abort();\n") + f.write(" if (strcmp(s, new_s)) {\n") + f.write(" printf(\"Huh? Regenerated string different from original string.\\n\");\n") + f.write(" printf(\"Regenerated string: %s\\n\", new_s);\n") + f.write(" abort();\n") + f.write(" }\n") f.write(" free(s);\n") + f.write(" free(new_s);\n") if ty.dispose_fn is not None: f.write(" %s(&%s_val);\n" % (ty.dispose_fn, ty.typename)) + f.write(" %s(&%s_val_new);\n" % (ty.dispose_fn, ty.typename)) f.write("\n") f.write(" printf(\"Testing Enumerations\\n\");\n")
Signature · 1 line
1.7.10.4
PATCH v6 14/18 libxl: introduce libxl_key_value_list_length
In reply to Wei Liu--- tools/libxl/libxl.c | 13 +++++++++++++ tools/libxl/libxl.h | 1 + 2 files changed, 14 insertions(+)
tools/libxl/libxl.c +13 -0
@@ -216,6 +216,19 @@ int libxl_string_list_length(const libxl_string_list *psl)return i; } +int libxl_key_value_list_length (libxl_key_value_list *pkvl) +{ +int i =0 ; +libxl_key_value_list kvl = *pkvl; + +if (kvl) { +while (kvl[2 * i])/* Only checks keys */ + i++; + } + +return i; +} +void libxl_key_value_list_dispose (libxl_key_value_list *pkvl) {int i;
tools/libxl/libxl.h +1 -0
@@ -567,6 +567,7 @@ int libxl_string_list_length(const libxl_string_list *sl);typedef char **libxl_key_value_list ;void libxl_key_value_list_dispose (libxl_key_value_list *kvl); +int libxl_key_value_list_length (libxl_key_value_list *kvl);typedef uint32_t libxl_hwcap [8 ];
Signature · 1 line
1.7.10.4
PATCH v6 15/18 libxl: introduce libxl_cpuid_policy_list_length
In reply to Wei Liu--- tools/libxl/libxl.h | 1 + tools/libxl/libxl_cpuid.c | 13 +++++++++++++ 2 files changed, 14 insertions(+)
tools/libxl/libxl.h +1 -0
@@ -587,6 +587,7 @@ void libxl_bitmap_dispose(libxl_bitmap *map);typedef struct libxl__cpuid_policy libxl_cpuid_policy ;typedef libxl_cpuid_policy *libxl_cpuid_policy_list ;void libxl_cpuid_dispose (libxl_cpuid_policy_list *cpuid_list); +int libxl_cpuid_policy_list_length (libxl_cpuid_policy_list *l);#define LIBXL_PCI_FUNC_ALL (~0U)
tools/libxl/libxl_cpuid.c +13 -0
@@ -455,6 +455,19 @@ int libxl_cpuid_policy_list_parse_json(libxl__gc *gc,return 0 ; } +int libxl_cpuid_policy_list_length (libxl_cpuid_policy_list *pl) +{ +int i =0 ; +libxl_cpuid_policy_list l = *pl; + +if (l) { +while (l[i].input[0 ] !=XEN_CPUID_INPUT_UNUSED ) + i++; + } + +return i; +} +/* * Local variables: * mode: C
Signature · 1 line
1.7.10.4
PATCH v6 16/18 libxl: copy function for builtin types
In reply to Wei LiuThese functions will be used in later patch to deep-copy a structure.
Functions introduced:
* libxl_string_list_copy
* libxl_key_value_list_copy
* libxl_hwcap_copy
* libxl_mac_copy
* libxl_cpuid_policy_list_copy
* libxl_string_copy
* libxl_bitmap_copy_alloc
--- tools/libxl/libxl.c | 67 +++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 14 +++++++-- tools/libxl/libxl_cpuid.c | 33 +++++++++++++++++++++ tools/libxl/libxl_nocpuid.c | 6 ++++ tools/libxl/libxl_utils.c | 25 ++++++++++++++++ tools/libxl/libxl_utils.h | 4 +++ 6 files changed, 147 insertions(+), 2 deletions(-)
tools/libxl/libxl.c +67 -0
@@ -205,6 +205,29 @@ void libxl_string_list_dispose(libxl_string_list *psl)free (sl); } +void libxl_string_list_copy (libxl_ctx *ctx, +libxl_string_list *dst, +libxl_string_list *src) +{ +GC_INIT (ctx); +int i, len; + +if (!*src) { + *dst =NULL ; + goto out; + } + + len =libxl_string_list_length (src); +/* one extra slot for sentinel */ + *dst =libxl__calloc (NOGC , len +1 ,sizeof (char *)); + +for (i =0 ; i < len; i++) + (*dst)[i] =libxl__strdup (NOGC , (*src)[i]); + +out: +GC_FREE ; +} +int libxl_string_list_length (const libxl_string_list *psl) {int i =0 ;
@@ -245,6 +268,34 @@ void libxl_key_value_list_dispose(libxl_key_value_list *pkvl)free (kvl); } +void libxl_key_value_list_copy (libxl_ctx *ctx, +libxl_key_value_list *dst, +libxl_key_value_list *src) +{ +GC_INIT (ctx); +int i, len; + +if (*src ==NULL ) { + *dst =NULL ; + goto out; + } + + len =libxl_key_value_list_length (src); +/* one extra slot for sentinel */ + *dst =libxl__calloc (NOGC , len *2 +1 ,sizeof (char *)); + +for (i =0 ; i < len *2 ; i +=2 ) { + (*dst)[i] =libxl__strdup (NOGC , (*src)[i]); +if ((*src)[i+1 ]) + (*dst)[i+1 ] =libxl__strdup (NOGC , (*src)[i+1 ]); +else + (*dst)[i+1 ] =NULL ; + } + +out: +GC_FREE ; +} +void libxl_defbool_set (libxl_defbool *db,bool b) { db->val = b ?LIBXL__DEFBOOL_TRUE :LIBXL__DEFBOOL_FALSE ;
@@ -5688,6 +5739,22 @@ int libxl_fd_set_cloexec(libxl_ctx *ctx, int fd, int cloexec)int libxl_fd_set_nonblock (libxl_ctx *ctx,int fd,int nonblock) {return fd_set_flags (ctx,fd,F_GETFL ,F_SETFL ,"FL" ,O_NONBLOCK , nonblock); } + +void libxl_hwcap_copy (libxl_ctx *ctx,libxl_hwcap *dst,libxl_hwcap *src) +{ +int i; + +for (i =0 ; i <8 ; i++) + (*dst)[i] = (*src)[i]; +} + +void libxl_mac_copy (libxl_ctx *ctx,libxl_mac *dst,libxl_mac *src) +{ +int i; + +for (i =0 ; i <6 ; i++) + (*dst)[i] = (*src)[i]; +}/* * Local variables: * mode: C
tools/libxl/libxl.h +12 -2
@@ -556,20 +556,29 @@ typedef struct libxl__ctx libxl_ctx;*/ #define LIBXL_HAVE_CPUPOOL_NAME 1 +typedef struct libxl__ctx libxl_ctx ; +typedef uint8_t libxl_mac [6 ];#define LIBXL_MAC_FMT "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"#define LIBXL_MAC_FMTLEN ((2*6)+5)/* 6 hex bytes plus 5 colons */ #define LIBXL_MAC_BYTES (mac) mac[0], mac[1], mac[2], mac[3], mac[4], mac[5] +void libxl_mac_copy (libxl_ctx *ctx,libxl_mac *dst,libxl_mac *src);typedef char **libxl_string_list ;void libxl_string_list_dispose (libxl_string_list *sl);int libxl_string_list_length (const libxl_string_list *sl); +void libxl_string_list_copy (libxl_ctx *ctx,libxl_string_list *dst, +libxl_string_list *src);typedef char **libxl_key_value_list ;void libxl_key_value_list_dispose (libxl_key_value_list *kvl);int libxl_key_value_list_length (libxl_key_value_list *kvl); +void libxl_key_value_list_copy (libxl_ctx *ctx, +libxl_key_value_list *dst, +libxl_key_value_list *src);typedef uint32_t libxl_hwcap [8 ]; +void libxl_hwcap_copy (libxl_ctx *ctx,libxl_hwcap *dst,libxl_hwcap *src);typedef uint64_t libxl_ev_user ;
@@ -588,6 +597,9 @@ typedef struct libxl__cpuid_policy libxl_cpuid_policy;typedef libxl_cpuid_policy *libxl_cpuid_policy_list ;void libxl_cpuid_dispose (libxl_cpuid_policy_list *cpuid_list);int libxl_cpuid_policy_list_length (libxl_cpuid_policy_list *l); +void libxl_cpuid_policy_list_copy (libxl_ctx *ctx, +libxl_cpuid_policy_list *dst, +libxl_cpuid_policy_list *src);#define LIBXL_PCI_FUNC_ALL (~0U)
@@ -632,8 +644,6 @@ bool libxl_defbool_val(libxl_defbool db);const char *libxl_defbool_to_string (libxl_defbool b); -typedef struct libxl__ctx libxl_ctx ; -#define LIBXL_TIMER_MODE_DEFAULT -1#define LIBXL_MEMKB_DEFAULT ~0ULL
tools/libxl/libxl_cpuid.c +33 -0
@@ -468,6 +468,39 @@ int libxl_cpuid_policy_list_length(libxl_cpuid_policy_list *pl)return i; } +void libxl_cpuid_policy_list_copy (libxl_ctx *ctx, +libxl_cpuid_policy_list *dst, +libxl_cpuid_policy_list *src) +{ +GC_INIT (ctx); +int i, j, len; + +if (*src ==NULL ) { + *dst =NULL ; + goto out; + } + + len =libxl_cpuid_policy_list_length (src); +/* one extra slot for sentinel */ + *dst =libxl__calloc (NOGC , len +1 ,sizeof (libxl_cpuid_policy)); + (*dst)[len].input[0 ] =XEN_CPUID_INPUT_UNUSED ; + (*dst)[len].input[1 ] =XEN_CPUID_INPUT_UNUSED ; + +for (i =0 ; i < len; i++) { +for (j =0 ; j <2 ; j++) + (*dst)[i].input[j] = (*src)[i].input[j]; +for (j =0 ; j <4 ; j++) +if ((*src)[i].policy[j]) + (*dst)[i].policy[j] = +libxl__strdup (NOGC , (*src)[i].policy[j]); +else + (*dst)[i].policy[j] =NULL ; + } + +out: +GC_FREE ; +} +/* * Local variables: * mode: C
tools/libxl/libxl_nocpuid.c +6 -0
@@ -51,6 +51,12 @@ int libxl_cpuid_policy_list_parse_json(libxl__gc *gc,return 0 ; } +void libxl_cpuid_policy_list_copy (libxl_ctx *ctx, +libxl_cpuid_policy_list *dst, +libxl_cpuid_policy_list *src) +{ +} +/* * Local variables: * mode: C
tools/libxl/libxl_utils.c +25 -0
@@ -614,6 +614,19 @@ void libxl_bitmap_copy(libxl_ctx *ctx, libxl_bitmap *dptr,memcpy (dptr->map, sptr->map, sz *sizeof (*dptr->map)); } +void libxl_bitmap_copy_alloc (libxl_ctx *ctx, +libxl_bitmap *dptr, +const libxl_bitmap *sptr) +{ +GC_INIT (ctx); + + dptr->map =libxl__calloc (NOGC , sptr->size,sizeof (*sptr->map)); + dptr->size = sptr->size; +memcpy (dptr->map, sptr->map, sptr->size *sizeof (*sptr->map)); + +GC_FREE ; +} +int libxl_bitmap_is_full (const libxl_bitmap *bitmap) {int i;
@@ -1013,6 +1026,18 @@ int libxl_domid_valid_guest(uint32_t domid)return domid >0 && domid <DOMID_FIRST_RESERVED ; } +void libxl_string_copy (libxl_ctx *ctx,char **dst,char **src) +{ +GC_INIT (ctx); + +if (*src) + *dst =libxl__strdup (NOGC , *src); +else + *dst =NULL ; + +GC_FREE ; +} +/* * Local variables: * mode: C
tools/libxl/libxl_utils.h +4 -0
@@ -76,6 +76,8 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid,int libxl_bitmap_alloc (libxl_ctx *ctx,libxl_bitmap *bitmap,int n_bits);/* Allocated bimap is from malloc, libxl_bitmap_dispose() to be * called by the application when done. */ +void libxl_bitmap_copy_alloc (libxl_ctx *ctx,libxl_bitmap *dptr, +const libxl_bitmap *sptr);void libxl_bitmap_copy (libxl_ctx *ctx,libxl_bitmap *dptr,const libxl_bitmap *sptr);int libxl_bitmap_is_full (const libxl_bitmap *bitmap);
@@ -121,6 +123,8 @@ int libxl_cpumap_to_nodemap(libxl_ctx *ctx, return (s + 1023) / 1024; } +void libxl_string_copy (libxl_ctx *ctx,char **dst,char **src); +#endif /*
Signature · 1 line
1.7.10.4
PATCH v6 17/18 libxl IDL: generate deep copy functions
In reply to Wei LiuIntroduces copy_fn for a type.
For most builtin types we can use direct assignment. For those builtin types which cannot use direct assignment we use the copy functions in previous patch.
--- tools/libxl/gentypes.py | 67 ++++++++++++++++++++++++++++++++++ tools/libxl/idl.py | 13 ++++++- tools/libxl/idl.txt | 12 ++++++ tools/libxl/libxl_types.idl | 27 ++++++++------ tools/libxl/libxl_types_internal.idl | 2 +- 5 files changed, 108 insertions(+), 13 deletions(-)
tools/libxl/gentypes.py +67 -0
@@ -100,6 +100,61 @@ def libxl_C_type_dispose(ty, v, indent = " ", parent = None): s = indent + s return s.replace("\n", "\n%s" % indent).rstrip(indent) +def libxl_C_type_copy(ty, v, w, indent = " ", vparent = None, wparent = None): + s = "" + + if vparent is None: + s += "GC_INIT(ctx);\n"; + + if isinstance(ty, idl.KeyedUnion): + if vparent is None or wparent is None: + raise Exception("KeyedUnion type must have a parent") + s += "%s = %s;\n" % ((vparent + ty.keyvar.name), (wparent + ty.keyvar.name)) + s += "switch (%s) {\n" % (wparent + ty.keyvar.name) + for f in ty.fields: + (vnparent,vfexpr) = ty.member(v, f, vparent is None) + (wnparent,wfexpr) = ty.member(w, f, wparent is None) + s += "case %s:\n" % f.enumname + if f.type is not None: + s += libxl_C_type_copy(f.type, vfexpr, wfexpr, indent + " ", + vnparent, wnparent) + s += " break;\n" + s += "}\n" + elif isinstance(ty, idl.Array): + if vparent is None or wparent is None: + raise Exception("Array type must have a parent") + s += "%s = libxl__calloc(NOGC, %s, sizeof(*%s));\n" % (ty.pass_arg(v, vparent is None), + (wparent + ty.lenvar.name), + ty.pass_arg(w, wparent is None)) + s += "%s = %s;\n" % ((vparent + ty.lenvar.name), (wparent + ty.lenvar.name)) + s += "{\n" + s += " int i;\n" + s += " for (i=0; i<%s; i++)\n" % (wparent + ty.lenvar.name) + s += libxl_C_type_copy(ty.elem_type, v+"[i]", w+"[i]", + indent + " ", vparent, wparent) + s += "}\n" + elif isinstance(ty, idl.Struct) and ((vparent is None and wparent is None) or ty.copy_fn is None): + for f in [f for f in ty.fields if not f.const and not f.type.private]: + (vnparent,vfexpr) = ty.member(v, f, vparent is None) + (wnparent,wfexpr) = ty.member(w, f, wparent is None) + s += libxl_C_type_copy(f.type, vfexpr, wfexpr, "", vnparent, wnparent) + else: + if ty.copy_fn is not None: + s += "%s(ctx, %s, %s);\n" % (ty.copy_fn, + ty.pass_arg(v, vparent is None, passby=idl.PASS_BY_REFERENCE), + ty.pass_arg(w, wparent is None, passby=idl.PASS_BY_REFERENCE)) + + else: + s += "%s = %s;\n" % (ty.pass_arg(v, vparent is None, passby=idl.PASS_BY_VALUE), + ty.pass_arg(w, wparent is None, passby=idl.PASS_BY_VALUE)) + + if vparent is None: + s += "GC_FREE;\n" + + if s != "": + s = indent + s + return s.replace("\n", "\n%s" % indent).rstrip(indent) + def libxl_init_members(ty, nesting = 0): """Returns a list of members of ty which require a separate init"""
@@ -481,6 +536,9 @@ if __name__ == '__main__': f.write(libxl_C_type_define(ty) + ";\n") if ty.dispose_fn is not None: f.write("%svoid %s(%s);\n" % (ty.hidden(), ty.dispose_fn, ty.make_arg("p"))) + if ty.copy_fn is not None: + f.write("%svoid %s(libxl_ctx *ctx, %s, %s);\n" % (ty.hidden(), ty.copy_fn, + ty.make_arg("dst"), ty.make_arg("src"))) if ty.init_fn is not None: f.write("%svoid %s(%s);\n" % (ty.hidden(), ty.init_fn, ty.make_arg("p"))) for field in libxl_init_members(ty):
@@ -560,6 +618,15 @@ if __name__ == '__main__': f.write(" memset(p, LIBXL_DTOR_POISON, sizeof(*p));\n") f.write("}\n") f.write("\n") + + for ty in [t for t in types if t.copy_fn and t.autogenerate_copy_fn]: + f.write("void %s(libxl_ctx *ctx, %s, %s)\n" % (ty.copy_fn, + ty.make_arg("dst", passby=idl.PASS_BY_REFERENCE), + ty.make_arg("src", passby=idl.PASS_BY_REFERENCE))) + f.write("{\n") + f.write(libxl_C_type_copy(ty, "dst", "src")) + f.write("}\n") + f.write("\n") for ty in [t for t in types if t.init_fn is not None and t.autogenerate_init_fn]: f.write(libxl_C_type_init(ty))
tools/libxl/idl.py +12 -1
@@ -60,6 +60,13 @@ class Type(object): self.autogenerate_dispose_fn = kwargs.setdefault('autogenerate_dispose_fn', True) + if self.typename is not None: + self.copy_fn = kwargs.setdefault('copy_fn', self.typename + "_copy") + else: + self.copy_fn = kwargs.setdefault('copy_fn', None) + + self.autogenerate_copy_fn = kwargs.setdefault('autogenerate_copy_fn', True) + self.init_fn = kwargs.setdefault('init_fn', None) self.init_val = kwargs.setdefault('init_val', None) self.autogenerate_init_fn = kwargs.setdefault('autogenerate_init_fn', False)
@@ -121,6 +128,7 @@ class Number(Builtin): def __init__(self, ctype, **kwargs): kwargs.setdefault('namespace', None) kwargs.setdefault('dispose_fn', None) + kwargs.setdefault('copy_fn', None) kwargs.setdefault('signed', False) kwargs.setdefault('json_gen_fn', "yajl_gen_integer") kwargs.setdefault('json_parse_type', "JSON_INTEGER")
@@ -134,6 +142,7 @@ class UInt(Number): kwargs.setdefault('namespace', None) kwargs.setdefault('dispose_fn', None) kwargs.setdefault('json_parse_fn', "libxl__uint%d_parse_json" % w) + kwargs.setdefault('copy_fn', None) Number.__init__(self, "uint%d_t" % w, **kwargs) self.width = w
@@ -151,6 +160,7 @@ class Enumeration(Type): def __init__(self, typename, values, **kwargs): kwargs.setdefault('dispose_fn', None) kwargs.setdefault('init_val', '0') + kwargs.setdefault('copy_fn', None) kwargs.setdefault('json_parse_type', "JSON_STRING") Type.__init__(self, typename, **kwargs)
@@ -267,6 +277,7 @@ class KeyedUnion(Aggregate): void = Builtin("void *", namespace = None) bool = Builtin("bool", namespace = None, + copy_fn=None, json_gen_fn = "yajl_gen_bool", json_parse_type = "JSON_BOOL", json_parse_fn = "libxl__bool_parse_json",
@@ -281,7 +292,7 @@ uint16 = UInt(16) uint32 = UInt(32) uint64 = UInt(64, json_gen_fn = "libxl__uint64_gen_json") -string = Builtin("char *", namespace = None, dispose_fn = "free", +string = Builtin("char *", namespace = None, copy_fn = "libxl_string_copy", dispose_fn = "free", json_gen_fn = "libxl__string_gen_json", json_parse_type = "JSON_STRING | JSON_NULL", json_parse_fn = "libxl__string_parse_json",
tools/libxl/idl.txt +12 -0
@@ -44,6 +44,18 @@ Type.autogenerate_dispose_fn: (default: True) Indicates if the above named Type.dispose_fn should be autogenerated. +Type.copy_fn: (default: typename + "_copy" or None if type == None) + + The name of the C function which will deep copy all fields within + this type. + +Type.autogenerate_copy_fn: (default: True) + + Indicates if the above named Type.copy_fn should be + autogenerated. + +Type.autogenerate_copy_fn + Type.init_val: (default: None) C expression for the value to initialise instances of this type to.
tools/libxl/libxl_types.idl +16 -11
@@ -5,24 +5,29 @@ namespace("libxl_") -libxl_defbool = Builtin("defbool", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, +libxl_defbool = Builtin("defbool", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, copy_fn=None, init_val="LIBXL__DEFBOOL_DEFAULT") - libxl_domid = Builtin("domid", json_gen_fn = "yajl_gen_integer", json_parse_fn = "libxl__uint32_parse_json", - json_parse_type = "JSON_INTEGER", autogenerate_json = False) + json_parse_type = "JSON_INTEGER", autogenerate_json = False, copy_fn=None) libxl_devid = Builtin("devid", json_gen_fn = "yajl_gen_integer", json_parse_fn = "libxl__int_parse_json", - json_parse_type = "JSON_INTEGER", autogenerate_json = False, signed = True, init_val="-1") -libxl_uuid = Builtin("uuid", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE) -libxl_mac = Builtin("mac", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE) -libxl_bitmap = Builtin("bitmap", json_parse_type="JSON_ARRAY", dispose_fn="libxl_bitmap_dispose", passby=PASS_BY_REFERENCE) + json_parse_type = "JSON_INTEGER", autogenerate_json = False, signed = True, init_val="-1", + copy_fn=None) +libxl_uuid = Builtin("uuid", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, copy_fn="libxl_uuid_copy") +libxl_mac = Builtin("mac", json_parse_type="JSON_STRING", passby=PASS_BY_REFERENCE, copy_fn="libxl_mac_copy") +libxl_bitmap = Builtin("bitmap", json_parse_type="JSON_ARRAY", dispose_fn="libxl_bitmap_dispose", + copy_fn='libxl_bitmap_copy_alloc', passby=PASS_BY_REFERENCE) libxl_cpuid_policy_list = Builtin("cpuid_policy_list", json_parse_type="JSON_ARRAY", - dispose_fn="libxl_cpuid_dispose", passby=PASS_BY_REFERENCE) + dispose_fn="libxl_cpuid_dispose", passby=PASS_BY_REFERENCE, + copy_fn="libxl_cpuid_policy_list_copy") libxl_string_list = Builtin("string_list", json_parse_type="JSON_ARRAY", - dispose_fn="libxl_string_list_dispose", passby=PASS_BY_REFERENCE) + dispose_fn="libxl_string_list_dispose", passby=PASS_BY_REFERENCE, + copy_fn="libxl_string_list_copy") libxl_key_value_list = Builtin("key_value_list", json_parse_type="JSON_MAP", - dispose_fn="libxl_key_value_list_dispose", passby=PASS_BY_REFERENCE) -libxl_hwcap = Builtin("hwcap", json_parse_type="JSON_ARRAY", passby=PASS_BY_REFERENCE) + dispose_fn="libxl_key_value_list_dispose", passby=PASS_BY_REFERENCE, + copy_fn="libxl_key_value_list_copy") +libxl_hwcap = Builtin("hwcap", json_parse_type="JSON_ARRAY", passby=PASS_BY_REFERENCE, + copy_fn="libxl_hwcap_copy") # # Specific integer types
tools/libxl/libxl_types_internal.idl +1 -1
@@ -3,7 +3,7 @@ hidden(True) libxl_domid = Builtin("domid", namespace="libxl_", json_gen_fn = "yajl_gen_integer", json_parse_fn = "libxl__uint32_parse_json", json_parse_type = "JSON_INTEGER", - autogenerate_json = False) + autogenerate_json = False, copy_fn = None) libxl__qmp_message_type = Enumeration("qmp_message_type", [ (1, "QMP"),
Signature · 1 line
1.7.10.4
PATCH v6 18/18 libxl/gentest.py: test deep copy functions
In reply to Wei LiuThe test is done as followed:
1. initialise libxl_FOO struct A
2. deep-copy A to B
3. generate JSON string for A and B
4. compare two JSON strings
If two strings are identical then we're good.
--- tools/libxl/gentest.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
tools/libxl/gentest.py +37 -0
@@ -273,6 +273,43 @@ int main(int argc, char **argv) f.write(" %s(&%s_val_new);\n" % (ty.dispose_fn, ty.typename)) f.write("\n") + f.write(" printf(\"Testing TYPE_copy()\\n\");\n") + f.write(" printf(\"----------------------\\n\");\n") + f.write(" printf(\"\\n\");\n") + for ty in [t for t in types if t.copy_fn is not None]: + f.write(" printf(\"Testing %s_copy, \");\n" % ty.typename) + arg = ty.typename + "_val" + f.write(" %s_init(%s);\n" % (ty.typename, \ + ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) + f.write(" %s_rand_init(%s);\n" % (ty.typename, \ + ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) + f.write(" %s_init(%s_new);\n" % (ty.typename, \ + ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) + f.write(" %s_copy(ctx, %s_new, %s);\n" % (ty.typename, \ + ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE), \ + ty.pass_arg(arg, isref=False, passby=idl.PASS_BY_REFERENCE))) + f.write(" s = %s_to_json(ctx, %s);\n" % \ + (ty.typename, ty.pass_arg(arg, isref=False))) + f.write(" if (s == NULL) abort();\n") + f.write(" new_s = %s_to_json(ctx, %s_new);\n" % \ + (ty.typename, ty.pass_arg(arg, isref=False))) + f.write(" if (new_s == NULL) abort();\n") + f.write(" if (strcmp(s, new_s)) {\n") + f.write(" printf(\"Huh? Deep copy for %s failed. Regenerated string different from original string.\\n\");\n" \ + % ty.typename) + f.write(" printf(\"Original string: %s\\n\", s);\n") + f.write(" printf(\"Regenerated string: %s\\n\", new_s);\n") + f.write(" abort();\n") + f.write(" }\n") + f.write(" free(s);\n") + f.write(" free(new_s);\n") + if ty.dispose_fn is not None: + f.write(" %s(&%s_val);\n" % (ty.dispose_fn, ty.typename)) + f.write(" %s(&%s_val_new);\n" % (ty.dispose_fn, ty.typename)) + f.write(" printf(\"done\\n\");\n") + f.write("\n") + + f.write(" printf(\"\\n\");\n") f.write(" printf(\"Testing Enumerations\\n\");\n") f.write(" printf(\"--------------------\\n\");\n") f.write(" printf(\"\\n\");\n")
Signature · 1 line
1.7.10.4
Ian Campbell
AppliedQuoted 2 lines · Wei Liu
Wei Liu (18):
A libxl: makecpupool_qualifier_to_cpupoolida library function
Applied.
Quoted 1 line
A xl: remove parsing of "vncviewer" option in xl domain config file
Applied.
Quoted 1 line
M libxl: fix JSON generator for
uint64_t
Acked + applied.
Quoted 3 lines
A libxl IDL: rename
json_fntojson_gen_fn
Alibxl_json: introducelibxl__object_from_json
Alibxl_json: introduce parser functions for builtin types
Applied all three.
Quoted 1 line
M
libxl/gentypes.py: special-case KeyedUnion map handle generation
Acked + applied.
Quoted 3 lines
C libxl IDL: generate code to parse
libxl__json_objecttolibxl_FOO
struct
Alibxl/gentest.py: test JSON parser
I skipped reviewing these ones this time around. Will come back to them.
Quoted 2 lines
A libxl: introduce
libxl_key_value_list_lengthA libxl: introducelibxl_cpuid_policy_list_length
Applied.
Quoted 1 line
A libxl: copy function for builtin types
This one didn't apply due to some missing prerequisites. At this point I stopped trying to apply things because I figured the rest wouldn't apply either.
Ian.
Quoted 13 lines · Ian Campbell
Quoted 2 lines · Wei Liu
Wei Liu (18):
A libxl: makecpupool_qualifier_to_cpupoolida library functionApplied.
Quoted 1 line
A xl: remove parsing of "vncviewer" option in xl domain config file
Applied.
Quoted 1 line
M libxl: fix JSON generator for
uint64_tAcked + applied.
Quoted 3 lines
A libxl IDL: rename
json_fntojson_gen_fn
Alibxl_json: introducelibxl__object_from_jsonAlibxl_json: introduce parser functions for builtin types
The last one breaks on older gcc:
In file included from flexarray.c:16:
libxl_internal.h:136: error: redefinition of typedef ‘libxl__gc’ libxl_json.h:25: note: previous declaration of ‘libxl__gc’ was here In file included from flexarray.c:16:
libxl_internal.h:1641: error: redefinition of typedef ‘libxl__json_object’ libxl_json.h:26: note: previous declaration of ‘libxl__json_object’ was here make[4]: *** [flexarray.o] Error 1
Looks like at some point gcc started allowing multiple typedefs. So, for example:
FC-64 <build@build-mk2:/tmp> cat foo.c; gcc --version |head -1; gcc foo.c typedef int foo;
typedef int foo;
main(){}
gcc (GCC) 4.4.4 20100503 (Red Hat 4.4.4-2)
foo.c:2: error: redefinition of typedef ‘foo’
foo.c:1: note: previous declaration of ‘foo’ was here
FC-64 <build@build-mk2:/tmp>
but
ostr@workbase> cat foo.c; gcc --version |head -1; gcc foo.c typedef int foo;
typedef int foo;
main(){}
gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
ostr@workbase>
-boris
Quoted 26 lines
Applied all three.
Quoted 1 line
M
libxl/gentypes.py: special-case KeyedUnion map handle generationAcked + applied.
Quoted 3 lines
C libxl IDL: generate code to parse
libxl__json_objecttolibxl_FOO
struct
Alibxl/gentest.py: test JSON parserI skipped reviewing these ones this time around. Will come back to them.
Quoted 2 lines
A libxl: introduce
libxl_key_value_list_lengthA libxl: introducelibxl_cpuid_policy_list_lengthApplied.
Quoted 1 line
A libxl: copy function for builtin types
This one didn't apply due to some missing prerequisites. At this point I stopped trying to apply things because I figured the rest wouldn't apply either.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 26 lines · Boris Ostrovsky
Quoted 13 lines · Ian Campbell
Quoted 2 lines · Wei Liu
Wei Liu (18):
A libxl: makecpupool_qualifier_to_cpupoolida library functionApplied.
Quoted 1 line
A xl: remove parsing of "vncviewer" option in xl domain config file
Applied.
Quoted 1 line
M libxl: fix JSON generator for
uint64_tAcked + applied.
Quoted 3 lines
A libxl IDL: rename
json_fntojson_gen_fn
Alibxl_json: introducelibxl__object_from_jsonAlibxl_json: introduce parser functions for builtin typesThe last one breaks on older gcc:
In file included from flexarray.c:16:
libxl_internal.h:136: error: redefinition of typedef ‘libxl__gc’ libxl_json.h:25: note: previous declaration of ‘libxl__gc’ was here In file included from flexarray.c:16:
libxl_internal.h:1641: error: redefinition of typedef ‘libxl__json_object’ libxl_json.h:26: note: previous declaration of ‘libxl__json_object’ was here make[4]: *** [flexarray.o] Error 1
Quoted 1 line
Looks like at some point gcc started allowing multiple typedefs. So, for example:
And this is apparently that point (for version 4.6, I believe):
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=ce3765bf44e49ef0568a1ad4a0b7f807591d6412
-boris
Quoted 58 lines
FC-64 <build@build-mk2:/tmp> cat
foo.c; gcc --version |head -1; gccfoo.ctypedef int foo;
typedef int foo;
main(){}
gcc (GCC) 4.4.4 20100503 (Red Hat 4.4.4-2)
foo.c:2: error: redefinition of typedef ‘foo’
foo.c:1: note: previous declaration of ‘foo’ was here
FC-64 <build@build-mk2:/tmp>but
ostr@workbase> cat
foo.c; gcc --version |head -1; gccfoo.ctypedef int foo;
typedef int foo;
main(){}gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
ostr@workbase>-boris
Quoted 19 lines
Applied all three.
Quoted 1 line
M
libxl/gentypes.py: special-case KeyedUnion map handle generationAcked + applied.
Quoted 3 lines
C libxl IDL: generate code to parse
libxl__json_objecttolibxl_FOO
struct
Alibxl/gentest.py: test JSON parserI skipped reviewing these ones this time around. Will come back to them.
Quoted 2 lines
A libxl: introduce
libxl_key_value_list_lengthA libxl: introducelibxl_cpuid_policy_list_lengthApplied.
Quoted 1 line
A libxl: copy function for builtin types
This one didn't apply due to some missing prerequisites. At this point I stopped trying to apply things because I figured the rest wouldn't apply either.
Quoted 7 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 31 lines · Boris Ostrovsky
Quoted 27 lines · Boris Ostrovsky
Quoted 13 lines · Ian Campbell
Quoted 2 lines · Wei Liu
Wei Liu (18):
A libxl: makecpupool_qualifier_to_cpupoolida library functionApplied.
Quoted 1 line
A xl: remove parsing of "vncviewer" option in xl domain config file
Applied.
Quoted 1 line
M libxl: fix JSON generator for
uint64_tAcked + applied.
Quoted 3 lines
A libxl IDL: rename
json_fntojson_gen_fn
Alibxl_json: introducelibxl__object_from_json
Alibxl_json: introduce parser functions for builtin typesThe last one breaks on older gcc:
In file included from flexarray.c:16:
libxl_internal.h:136: error: redefinition of typedef ‘libxl__gc’ libxl_json.h:25: note: previous declaration of ‘libxl__gc’ was here In file included from flexarray.c:16:
libxl_internal.h:1641: error: redefinition of typedef ‘libxl__json_object’ libxl_json.h:26: note: previous declaration of ‘libxl__json_object’ was here
make[4]: *** [flexarray.o] Error 1Quoted 2 lines
Looks like at some point gcc started allowing multiple typedefs. So, for example:
Quoted 6 lines
And this is apparently that point (for version 4.6, I believe):
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=ce3765bf44e49ef0568a1ad4a0b7f807591d6412
-boris
Thanks for reporting. Now that I notice these functions really belong to libxl_internal.h.
Does this patch fix it for you?
Wei.
---8<---
From 5a57f827f644f716b3748beec0214bbefddda4b6 Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 10 Jun 2014 22:16:14 +0100
Subject: [PATCH] libxl: move some internal functions to libxl_internal.h
In 752f181f ("libxl_json: introduce parser functions for builtin types") a bunch of parser functions are added to libxl_json.h, which breaks GCC < 4.6.
These functions are internal and libxl_json.h is public header, so move them to libxl_internal.h.
--- tools/libxl/libxl_internal.h | 32 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_json.h | 35 ----------------------------------- 2 files changed, 32 insertions(+), 35 deletions(-)
tools/libxl/libxl_internal.h +32 -0
@@ -3147,6 +3147,38 @@ void libxl__numa_candidate_put_nodemap(libxl__gc *gc,*/ #define CTYPE (isfoo,c) (isfoo((unsigned char)(c))) +int libxl_defbool_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_defbool *p); +int libxl__bool_parse_json (libxl__gc *gc,const libxl__json_object *o, +bool *p); +int libxl_mac_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_mac *p); +int libxl_bitmap_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_bitmap *p); +int libxl_uuid_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_uuid *p); +int libxl_cpuid_policy_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_cpuid_policy_list *p); +int libxl_string_list_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_string_list *p); +int libxl_key_value_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_key_value_list *p); +int libxl_hwcap_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_hwcap *p); +int libxl__int_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint8_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint16_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint32_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint64_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__string_parse_json (libxl__gc *gc,const libxl__json_object *o, +char **p);#endif
tools/libxl/libxl_json.h +0 -35
@@ -22,52 +22,17 @@# include <yajl/yajl_version.h> #endif -typedef struct libxl__gc libxl__gc ; -typedef struct libxl__json_object libxl__json_object ; -yajl_gen_status libxl__uint64_gen_json (yajl_gen hand,uint64_t val);yajl_gen_status libxl_defbool_gen_json (yajl_gen hand,libxl_defbool *p); -int libxl_defbool_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_defbool *p); -int libxl__bool_parse_json (libxl__gc *gc,const libxl__json_object *o, -bool *p);yajl_gen_status libxl_uuid_gen_json (yajl_gen hand,libxl_uuid *p); -int libxl_uuid_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_uuid *p);yajl_gen_status libxl_mac_gen_json (yajl_gen hand,libxl_mac *p); -int libxl_mac_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_mac *p);yajl_gen_status libxl_bitmap_gen_json (yajl_gen hand,libxl_bitmap *p); -int libxl_bitmap_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_bitmap *p);yajl_gen_status libxl_cpuid_policy_list_gen_json (yajl_gen hand,libxl_cpuid_policy_list *p); -int libxl_cpuid_policy_list_parse_json (libxl__gc *gc, -const libxl__json_object *o, -libxl_cpuid_policy_list *p);yajl_gen_status libxl_string_list_gen_json (yajl_gen hand,libxl_string_list *p); -int libxl_string_list_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_string_list *p);yajl_gen_status libxl_key_value_list_gen_json (yajl_gen hand,libxl_key_value_list *p); -int libxl_key_value_list_parse_json (libxl__gc *gc, -const libxl__json_object *o, -libxl_key_value_list *p);yajl_gen_status libxl_hwcap_gen_json (yajl_gen hand,libxl_hwcap *p); -int libxl_hwcap_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_hwcap *p); -int libxl__int_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__uint8_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__uint16_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__uint32_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__uint64_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__string_parse_json (libxl__gc *gc,const libxl__json_object *o, -char **p);#include <_libxl_types_json.h>
Signature · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 32 lines · Wei Liu
Quoted 31 lines · Boris Ostrovsky
Quoted 26 lines · Boris Ostrovsky
Quoted 13 lines · Ian Campbell
Quoted 2 lines · Wei Liu
Wei Liu (18):
A libxl: makecpupool_qualifier_to_cpupoolida library functionApplied.
Quoted 1 line
A xl: remove parsing of "vncviewer" option in xl domain config file
Applied.
Quoted 1 line
M libxl: fix JSON generator for
uint64_tAcked + applied.
Quoted 3 lines
A libxl IDL: rename
json_fntojson_gen_fn
Alibxl_json: introducelibxl__object_from_jsonAlibxl_json: introduce parser functions for builtin typesThe last one breaks on older gcc:
In file included from flexarray.c:16:
libxl_internal.h:136: error: redefinition of typedef ‘libxl__gc’ libxl_json.h:25: note: previous declaration of ‘libxl__gc’ was here In file included from flexarray.c:16:
libxl_internal.h:1641: error: redefinition of typedef ‘libxl__json_object’ libxl_json.h:26: note: previous declaration of ‘libxl__json_object’ was here
make[4]: *** [flexarray.o] Error 1Quoted 2 lines
Looks like at some point gcc started allowing multiple typedefs. So, for example:
And this is apparently that point (for version 4.6, I believe):
Quoted 8 lines
Quoted 4 lines
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=ce3765bf44e49ef0568a1ad4a0b7f807591d6412
-boris
Thanks for reporting. Now that I notice these functions really belong to
libxl_internal.h.Does this patch fix it for you?
Yes, it allows me to build libxl. I can't test it right now but will do it tomorrow.
Thanks.
-boris
Quoted 112 lines
Wei.
---8<---
From5a57f827f644f716b3748beec0214bbefddda4b6Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 10 Jun 2014 22:16:14 +0100
Subject: [PATCH] libxl: move some internal functions tolibxl_internal.hIn
752f181f("libxl_json: introduce parser functions for builtin types") a bunch of parser functions are added tolibxl_json.h, which breaks GCC < 4.6.These functions are internal and
libxl_json.his public header, so move them tolibxl_internal.h.Signed-off-by Wei Liu <[email protected]>--- tools/libxl/libxl_internal.h | 32 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_json.h | 35 ----------------------------------- 2 files changed, 32 insertions(+), 35 deletions(-)tools/libxl/libxl_internal.h +32
-0@@ -3147,6 +3147,38 @@ void libxl__numa_candidate_put_nodemap(libxl__gc *gc,*/ #define CTYPE (isfoo,c) (isfoo((unsigned char)(c))) +int libxl_defbool_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_defbool *p); +int libxl__bool_parse_json (libxl__gc *gc,const libxl__json_object *o, +bool *p); +int libxl_mac_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_mac *p); +int libxl_bitmap_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_bitmap *p); +int libxl_uuid_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_uuid *p); +int libxl_cpuid_policy_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_cpuid_policy_list *p); +int libxl_string_list_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_string_list *p); +int libxl_key_value_list_parse_json (libxl__gc *gc, +const libxl__json_object *o, +libxl_key_value_list *p); +int libxl_hwcap_parse_json (libxl__gc *gc,const libxl__json_object *o, +libxl_hwcap *p); +int libxl__int_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint8_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint16_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint32_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__uint64_parse_json (libxl__gc *gc,const libxl__json_object *o, +void *p); +int libxl__string_parse_json (libxl__gc *gc,const libxl__json_object *o, +char **p);#endif tools/libxl/libxl_json.h +0
-28@@ -22,52 +22,17 @@# include <yajl/yajl_version.h> #endif -typedef struct libxl__gc libxl__gc ; -typedef struct libxl__json_object libxl__json_object ; -yajl_gen_status libxl__uint64_gen_json (yajl_gen hand,uint64_t val);yajl_gen_status libxl_defbool_gen_json (yajl_gen hand,libxl_defbool *p); -int libxl_defbool_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_defbool *p); -int libxl__bool_parse_json (libxl__gc *gc,const libxl__json_object *o, -bool *p);yajl_gen_status libxl_uuid_gen_json (yajl_gen hand,libxl_uuid *p); -int libxl_uuid_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_uuid *p);yajl_gen_status libxl_mac_gen_json (yajl_gen hand,libxl_mac *p); -int libxl_mac_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_mac *p);yajl_gen_status libxl_bitmap_gen_json (yajl_gen hand,libxl_bitmap *p); -int libxl_bitmap_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_bitmap *p);yajl_gen_status libxl_cpuid_policy_list_gen_json (yajl_gen hand,libxl_cpuid_policy_list *p); -int libxl_cpuid_policy_list_parse_json (libxl__gc *gc, -const libxl__json_object *o, -libxl_cpuid_policy_list *p);yajl_gen_status libxl_string_list_gen_json (yajl_gen hand,libxl_string_list *p); -int libxl_string_list_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_string_list *p);yajl_gen_status libxl_key_value_list_gen_json (yajl_gen hand,libxl_key_value_list *p); -int libxl_key_value_list_parse_json (libxl__gc *gc, -const libxl__json_object *o, -libxl_key_value_list *p);yajl_gen_status libxl_hwcap_gen_json (yajl_gen hand,libxl_hwcap *p); -int libxl_hwcap_parse_json (libxl__gc *gc,const libxl__json_object *o, -libxl_hwcap *p); -int libxl__int_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__uint8_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__uint16_parse_json(libxl__gc *gc, const libxl__json_object *o,
tools/libxl/libxl_json.h line 38
Quoted 10 lines
tools/libxl/libxl_json.h +0
-7- void *p); -int libxl__uint32_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__uint64_parse_json (libxl__gc *gc,const libxl__json_object *o, -void *p); -int libxl__string_parse_json (libxl__gc *gc,const libxl__json_object *o, -char **p);#include <_libxl_types_json.h>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 36 lines · Boris Ostrovsky
Quoted 35 lines · Wei Liu
Quoted 34 lines · Boris Ostrovsky
Quoted 26 lines · Boris Ostrovsky
Quoted 13 lines · Ian Campbell
Quoted 2 lines · Wei Liu
Wei Liu (18):
A libxl: makecpupool_qualifier_to_cpupoolida library functionApplied.
Quoted 1 line
A xl: remove parsing of "vncviewer" option in xl domain config file
Applied.
Quoted 1 line
M libxl: fix JSON generator for
uint64_tAcked + applied.
Quoted 3 lines
A libxl IDL: rename
json_fntojson_gen_fn
Alibxl_json: introducelibxl__object_from_json
Alibxl_json: introduce parser functions for builtin typesThe last one breaks on older gcc:
In file included from flexarray.c:16:
libxl_internal.h:136: error: redefinition of typedef ‘libxl__gc’ libxl_json.h:25: note: previous declaration of ‘libxl__gc’ was here In file included from flexarray.c:16:
libxl_internal.h:1641: error: redefinition of typedef ‘libxl__json_object’ libxl_json.h:26: note: previous declaration of ‘libxl__json_object’ was here
make[4]: *** [flexarray.o] Error 1Quoted 2 lines
Looks like at some point gcc started allowing multiple typedefs. So, for example:
And this is apparently that point (for version 4.6, I believe):
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=ce3765bf44e49ef0568a1ad4a0b7f807591d6412
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
-boris
Thanks for reporting. Now that I notice these functions really belong to
libxl_internal.h.Does this patch fix it for you?
Yes, it allows me to build libxl. I can't test it right now but will do it tomorrow.
FWIW I tested this patch with gcc 4.4 it worked. The core bit is it avoids having duplicate libxl__gc and libxl__json_object.
If you're thinking about testing new functionalities then there's probably nothing to test at the moment. The user of this infrastructure is just not yet in tree. :-)
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 6 lines · Wei Liu
---8<---
From5a57f827f644f716b3748beec0214bbefddda4b6Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 10 Jun 2014 22:16:14 +0100
Subject: [PATCH] libxl: move some internal functions tolibxl_internal.h
Quoted 8 lines
In
752f181f("libxl_json: introduce parser functions for builtin types") a bunch of parser functions are added tolibxl_json.h, which breaks GCC < 4.6.These functions are internal and
libxl_json.his public header, so move them tolibxl_internal.h.Signed-off-by Wei Liu <[email protected]>
Acked + applied.
FYI there is a bunch of existing internal (ish) stuff in there which I was planning to move to (new) libxl_json_internal.h at some point. Due
to: http://lists.xen.org/archives/html/xen-devel/2014-06/msg00069.html
Ian.
Quoted 16 lines · Ian Campbell
Quoted 13 lines · Wei Liu
---8<---
From5a57f827f644f716b3748beec0214bbefddda4b6Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Tue, 10 Jun 2014 22:16:14 +0100
Subject: [PATCH] libxl: move some internal functions tolibxl_internal.hIn
752f181f("libxl_json: introduce parser functions for builtin types") a bunch of parser functions are added tolibxl_json.h, which breaks GCC < 4.6.These functions are internal and
libxl_json.his public header, so move them tolibxl_internal.h.
Quoted 8 lines
Quoted 1 line
Signed-off-by Wei Liu <[email protected]>Acked + applied.
FYI there is a bunch of existing internal (ish) stuff in there which I was planning to move to (new)
libxl_json_internal.hat some point. Due
to: http://lists.xen.org/archives/html/xen-devel/2014-06/msg00069.html
I was thinking about the same thing at some point last night but I didn't want to stay up any longer than necessary. :-P
Wei.
Quoted 3 lines
Ian.