libxl: Add a gc to libxl_cpumap_alloc, ..._to_hex_string
PATCH 1/1 libxl: Add a gc to libxl_cpumap_alloc, ..._to_hex_string
This need to be slotted into my save/restore series, since a new case of libxl__*alloc(0,...) was just added.
Thanks,
Ian.
From: Ian Jackson <[email protected]>
Subject: [PATCH] libxl: Add a gc to libxl_cpumap_alloc, ..._to_hex_string
In the next patch we are going to change the definition of NOGC to require a local variable libxl__gc *gc. And this means that passing 0 to libxl__calloc is going to be wrong.
libxl_cpumap_alloc doesn't have a gc but passes 0 to libxl_calloc Fix this by:
- introducing an `out' label and an rc variable
- replacing the returns with rc = ERROR_BLAH; goto out;
- adding uses of GC_INIT and GC_FREE.
- changing NULL to NOGC in the call to libxl__calloc
Likewise fix libxl_cpumap_to_hex_string by:
- adding a libxl_ctx* parameter and updating the one call site
- adding uses of GC_INIT and GC_FREE.
- changing NULL to NOGC in the call to libxl__zalloc
--- tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_utils.c | 28 ++++++++++++++++++++-------- tools/libxl/libxl_utils.h | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-)
tools/libxl/libxl_dm.c +1 -1
@@ -204,7 +204,7 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc, } nr_set_cpus =libxl_cpumap_count_set (&b_info->avail_vcpus); - s =libxl_cpumap_to_hex_string (&b_info->avail_vcpus); + s =libxl_cpumap_to_hex_string (CTX , &b_info->avail_vcpus);flexarray_vappend (dm_args,"-vcpu_avail" ,libxl__sprintf (gc,"%s" , s),NULL );free (s);
tools/libxl/libxl_utils.c +20 -8
@@ -491,19 +491,29 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,int libxl_cpumap_alloc (libxl_ctx *ctx,libxl_cpumap *cpumap,int max_cpus) { +GC_INIT (ctx);int sz; +int rc; -if (max_cpus <0 ) -return ERROR_INVAL ; +if (max_cpus <0 ) { + rc =ERROR_INVAL ; + goto out; + }if (max_cpus ==0 ) max_cpus =libxl_get_max_cpus (ctx); -if (max_cpus ==0 ) -return ERROR_FAIL ; +if (max_cpus ==0 ) { + rc =ERROR_FAIL ; + goto out; + } sz = (max_cpus +7 ) /8 ; - cpumap->map =libxl__calloc (NULL ,sizeof (*cpumap->map), sz); + cpumap->map =libxl__calloc (NOGC ,sizeof (*cpumap->map), sz); cpumap->size = sz; -return 0 ; + + rc =0 ; + out: +GC_FREE ; +return rc; }void libxl_cpumap_dispose (libxl_cpumap *map)
@@ -542,10 +552,11 @@ int libxl_cpumap_count_set(const libxl_cpumap *cpumap) }/* NB. caller is responsible for freeing the memory */ -char *libxl_cpumap_to_hex_string (const libxl_cpumap *cpumap) +char *libxl_cpumap_to_hex_string (libxl_ctx *ctx,const libxl_cpumap *cpumap) { +GC_INIT (ctx);int i = cpumap->size; -char *p =libxl__zalloc (NULL , cpumap->size *2 +3 ); +char *p =libxl__zalloc (NOGC , cpumap->size *2 +3 );char *q = p;strncpy (p,"0x" ,2 ); p +=2 ;
@@ -554,6 +565,7 @@ char *libxl_cpumap_to_hex_string(const libxl_cpumap *cpumap) p +=2 ; } *p ='\0' ; +GC_FREE ;return q; }
tools/libxl/libxl_utils.h +1 -1
@@ -68,7 +68,7 @@ int libxl_cpumap_test(const libxl_cpumap *cpumap, int cpu);void libxl_cpumap_set (libxl_cpumap *cpumap,int cpu);void libxl_cpumap_reset (libxl_cpumap *cpumap,int cpu);int libxl_cpumap_count_set (const libxl_cpumap *cpumap); -char *libxl_cpumap_to_hex_string (const libxl_cpumap *cpumap); +char *libxl_cpumap_to_hex_string (libxl_ctx *ctx,const libxl_cpumap *cpumap);static inline void libxl_cpumap_set_any (libxl_cpumap *cpumap) {memset (cpumap->map,-1 , cpumap->size);
Signature · 1 line
tg: (197c736..) t/xen/xl.nogc.add-gcs.cpumap (depends on: t/xen/xl.nogc.add-gcs)
Quoted 20 lines · Ian Jackson
This need to be slotted into my save/restore series, since a new case of libxl__*alloc(0,...) was just added.
Thanks,
Ian.From: Ian Jackson <[email protected]>
Subject: [PATCH] libxl: Add a gc tolibxl_cpumap_alloc, ..._to_hex_stringIn the next patch we are going to change the definition of NOGC to require a local variable
libxl__gc*gc. And this means that passing 0 tolibxl__callocis going to be wrong.
libxl_cpumap_allocdoesn't have a gc but passes 0 tolibxl_callocFix this by:
- introducing an `out' label and an rc variable
- replacing the returns with rc =ERROR_BLAH; goto out;
- adding uses ofGC_INITandGC_FREE.
- changing NULL to NOGC in the call tolibxl__calloc
Quoted 6 lines
Likewise fix
libxl_cpumap_to_hex_stringby:
- adding a libxl_ctx* parameter and updating the one call site
- adding uses ofGC_INITandGC_FREE.
- changing NULL to NOGC in the call tolibxl__zallocSigned-off-by Ian Jackson <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Roger Pau Monné writes ("Re: [Xen-devel] [PATCH] libxl: Add a gc to libxl_cpumap_alloc, ..._to_hex_string"):
Quoted 5 lines · Ian Jackson
Quoted 2 lines
This need to be slotted into my save/restore series, since a new case of libxl__*alloc(0,...) was just added.
Acked-by Roger Pau Monne <[email protected]>
Thanks, and also to Dario, for the review. I have committed this now.
Ian.