# HG changeset patch
# User "Gianni Tedesco (3P)" <gianni.tedesco@xxxxxxxxxx>
# Date 1281538264 -3600
# Node ID ca51dba3a7b1d9bd15215d89036eb98dfae8754d
# Parent fffedd3d70e14abf2e487c109937d0090adcfebc
xl: don't use libxl allocator for vcpu_list
This also fixes a bug with an erroneous call to libxl_free().
A destructor for the vcpu list is also implemented which is called from
xl.
Signed-off-by: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
tools/libxl/libxl.c | 16 +++++++++++++---
tools/libxl/libxl.h | 1 +
tools/libxl/xl_cmdimpl.c | 8 +++++---
3 files changed, 19 insertions(+), 6 deletions(-)
diff -r fffedd3d70e1 -r ca51dba3a7b1 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Wed Aug 11 13:18:05 2010 +0100
+++ b/tools/libxl/libxl.c Wed Aug 11 15:51:04 2010 +0100
@@ -2722,6 +2722,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
xc_domaininfo_t domaininfo;
xc_vcpuinfo_t vcpuinfo;
xc_physinfo_t physinfo = { 0 };
+ uint64_t *cpumaps;
+ unsigned num_cpuwords;
if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "getting infolist");
@@ -2732,14 +2734,15 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
return NULL;
}
*nrcpus = physinfo.max_cpu_id + 1;
- ptr = libxl_calloc(ctx, domaininfo.max_vcpu_id + 1, sizeof
(libxl_vcpuinfo));
+ ret = ptr = calloc(domaininfo.max_vcpu_id + 1, sizeof (libxl_vcpuinfo));
if (!ptr) {
return NULL;
}
- ret = ptr;
+ num_cpuwords = ((physinfo.max_cpu_id + 64) / 64);
+ cpumaps = calloc(num_cpuwords * sizeof(*cpumaps), domaininfo.max_vcpu_id +
1);
for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
- ptr->cpumap = libxl_calloc(ctx, (*nrcpus + 63) / 64, sizeof
(uint64_t));
+ ptr->cpumap = cpumaps + (num_cpuwords * *nb_vcpu);
if (!ptr->cpumap) {
return NULL;
}
@@ -2760,6 +2763,13 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
ptr->vcpu_time = vcpuinfo.cpu_time;
}
return ret;
+}
+
+void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu)
+{
+ if ( vcpu )
+ free(vcpu[0].cpumap);
+ free(vcpu);
}
int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
diff -r fffedd3d70e1 -r ca51dba3a7b1 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Wed Aug 11 13:18:05 2010 +0100
+++ b/tools/libxl/libxl.h Wed Aug 11 15:51:04 2010 +0100
@@ -598,6 +598,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, l
int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
int *nb_vcpu, int *nrcpus);
+void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu);
int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
uint64_t *cpumap, int nrcpus);
int libxl_set_vcpucount(libxl_ctx *ctx, uint32_t domid, uint32_t count);
diff -r fffedd3d70e1 -r ca51dba3a7b1 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Wed Aug 11 13:18:05 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Wed Aug 11 15:51:04 2010 +0100
@@ -3268,7 +3268,7 @@ void vcpulist(int argc, char **argv)
void vcpulist(int argc, char **argv)
{
libxl_dominfo *dominfo;
- libxl_vcpuinfo *vcpuinfo;
+ libxl_vcpuinfo *vcpuinfo, *list = NULL;
libxl_physinfo physinfo;
int nb_vcpu, nb_domain, nrcpus;
@@ -3284,7 +3284,7 @@ void vcpulist(int argc, char **argv)
goto vcpulist_out;
}
for (; nb_domain > 0; --nb_domain, ++dominfo) {
- if (!(vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid, &nb_vcpu,
+ if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid,
&nb_vcpu,
&nrcpus))) {
fprintf(stderr, "libxl_list_vcpu failed.\n");
goto vcpulist_out;
@@ -3292,19 +3292,21 @@ void vcpulist(int argc, char **argv)
for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
print_vcpuinfo(dominfo->domid, vcpuinfo, physinfo.nr_cpus);
}
+ libxl_free_vcpu_list(list);
}
} else {
for (; argc > 0; ++argv, --argc) {
if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
}
- if (!(vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus)))
{
+ if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu,
&nrcpus))) {
fprintf(stderr, "libxl_list_vcpu failed.\n");
goto vcpulist_out;
}
for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
print_vcpuinfo(domid, vcpuinfo, physinfo.nr_cpus);
}
+ libxl_free_vcpu_list(list);
}
}
vcpulist_out:
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|