aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorYang Zhang <yang.z.zhang@Intel.com>2012-06-28 17:47:13 +0100
committerYang Zhang <yang.z.zhang@Intel.com>2012-06-28 17:47:13 +0100
commit928c75ce59fc11c707b8bfd0b99ce0c07ab89926 (patch)
treeac46f583868400516b25bba67a19915c7888df1c /tools
parent8f7e8f7b56f62eb7fe7d459424b9f56466faaefb (diff)
downloadxen-928c75ce59fc11c707b8bfd0b99ce0c07ab89926.tar.gz
xen-928c75ce59fc11c707b8bfd0b99ce0c07ab89926.tar.bz2
xen-928c75ce59fc11c707b8bfd0b99ce0c07ab89926.zip
libxl: allow to allocate cpumap with specific size
Currently, libxl_cpumap_alloc()allocate the cpumap with size of number of physical cpus. In some place, we may want to allocate specific size of cpumap. This patch allow to pass a argument to specific the size that you want to allocate. If pass 0, it means the size is equal to number of physical cpus. Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/libxl/libxl.c8
-rw-r--r--tools/libxl/libxl_create.c4
-rw-r--r--tools/libxl/libxl_utils.c12
-rw-r--r--tools/libxl/libxl_utils.h2
-rw-r--r--tools/libxl/xl_cmdimpl.c18
5 files changed, 23 insertions, 21 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 6fc5472bb7..205c1e61de 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -570,7 +570,7 @@ static int cpupool_info(libxl__gc *gc,
info->poolid = xcinfo->cpupool_id;
info->sched = xcinfo->sched_id;
info->n_dom = xcinfo->n_dom;
- if (libxl_cpumap_alloc(CTX, &info->cpumap))
+ if (libxl_cpumap_alloc(CTX, &info->cpumap, 0))
goto out;
memcpy(info->cpumap.map, xcinfo->cpumap, info->cpumap.size);
@@ -3288,7 +3288,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
}
for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
- if (libxl_cpumap_alloc(ctx, &ptr->cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &ptr->cpumap, 0)) {
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpumap");
return NULL;
}
@@ -4041,8 +4041,8 @@ int libxl_cpupool_destroy(libxl_ctx *ctx, uint32_t poolid)
if ((info->cpupool_id != poolid) || (info->n_dom))
goto out;
- rc = ERROR_NOMEM;
- if (libxl_cpumap_alloc(ctx, &cpumap))
+ rc = libxl_cpumap_alloc(ctx, &cpumap, 0);
+ if (rc)
goto out;
memcpy(cpumap.map, info->cpumap, cpumap.size);
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 67cd207379..08e5536c0c 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -205,8 +205,8 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
b_info->cur_vcpus = 1;
if (!b_info->cpumap.size) {
- if (libxl_cpumap_alloc(CTX, &b_info->cpumap))
- return ERROR_NOMEM;
+ if (libxl_cpumap_alloc(CTX, &b_info->cpumap, 0))
+ return ERROR_FAIL;
libxl_cpumap_set_any(&b_info->cpumap);
}
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 67ef82c8e4..2acf7d4a43 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -489,19 +489,19 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
return rc;
}
-int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap)
+int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap, int max_cpus)
{
- int max_cpus;
int sz;
- max_cpus = libxl_get_max_cpus(ctx);
+ if (max_cpus < 0)
+ return ERROR_INVAL;
+ if (max_cpus == 0)
+ max_cpus = libxl_get_max_cpus(ctx);
if (max_cpus == 0)
return ERROR_FAIL;
sz = (max_cpus + 7) / 8;
- cpumap->map = calloc(sz, sizeof(*cpumap->map));
- if (!cpumap->map)
- return ERROR_NOMEM;
+ cpumap->map = libxl__calloc(NULL, sizeof(*cpumap->map), sz);
cpumap->size = sz;
return 0;
}
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 74beb52a67..7ab0c0915c 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -63,7 +63,7 @@ int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid, int devid,
int libxl_vdev_to_device_disk(libxl_ctx *ctx, uint32_t domid, const char *vdev,
libxl_device_disk *disk);
-int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap);
+int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap, int max_cpus);
int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index c80b9fb55d..02b55f1305 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -503,7 +503,7 @@ static int vcpupin_parse(char *cpu, libxl_cpumap *cpumap)
return 0;
}
- if (libxl_cpumap_alloc(ctx, &exclude_cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &exclude_cpumap, 0)) {
fprintf(stderr, "Error: Failed to allocate cpumap.\n");
return ENOMEM;
}
@@ -656,7 +656,7 @@ static void parse_config_data(const char *config_source,
if (!xlu_cfg_get_list (config, "cpus", &cpus, 0, 1)) {
int i, n_cpus = 0;
- if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &b_info->cpumap, 0)) {
fprintf(stderr, "Unable to allocate cpumap\n");
exit(1);
}
@@ -692,7 +692,7 @@ static void parse_config_data(const char *config_source,
else if (!xlu_cfg_get_string (config, "cpus", &buf, 0)) {
char *buf2 = strdup(buf);
- if (libxl_cpumap_alloc(ctx, &b_info->cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &b_info->cpumap, 0)) {
fprintf(stderr, "Unable to allocate cpumap\n");
exit(1);
}
@@ -1779,7 +1779,9 @@ start:
if (vcpu_to_pcpu) {
libxl_cpumap vcpu_cpumap;
- libxl_cpumap_alloc(ctx, &vcpu_cpumap);
+ ret = libxl_cpumap_alloc(ctx, &vcpu_cpumap, 0);
+ if (ret)
+ goto error_out;
for (i = 0; i < d_config.b_info.max_vcpus; i++) {
if (vcpu_to_pcpu[i] != -1) {
@@ -4051,7 +4053,7 @@ static void vcpupin(const char *d, const char *vcpu, char *cpu)
find_domain(d);
- if (libxl_cpumap_alloc(ctx, &cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &cpumap, 0)) {
goto vcpupin_out;
}
@@ -4108,7 +4110,7 @@ static void vcpuset(const char *d, const char* nr_vcpus)
find_domain(d);
- if (libxl_cpumap_alloc(ctx, &cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &cpumap, 0)) {
fprintf(stderr, "libxl_cpumap_alloc failed\n");
return;
}
@@ -5921,7 +5923,7 @@ int main_cpupoolcreate(int argc, char **argv)
fprintf(stderr, "libxl_get_freecpus failed\n");
goto out_cfg;
}
- if (libxl_cpumap_alloc(ctx, &cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &cpumap, 0)) {
fprintf(stderr, "Failed to allocate cpumap\n");
goto out_cfg;
}
@@ -6289,7 +6291,7 @@ int main_cpupoolnumasplit(int argc, char **argv)
return -ERROR_FAIL;
}
- if (libxl_cpumap_alloc(ctx, &cpumap)) {
+ if (libxl_cpumap_alloc(ctx, &cpumap, 0)) {
fprintf(stderr, "Failed to allocate cpumap\n");
libxl_cputopology_list_free(topology, n_cpus);
return -ERROR_FAIL;