tools/libxl/libxl.c | 17 ++++++++++++++---
tools/libxl/libxl.h | 1 +
tools/libxl/xl_cmdimpl.c | 8 +++++---
3 files changed, 20 insertions(+), 6 deletions(-)
This also fixes a bug with an erroneous call to libxl_free(). A destructor for
the vpcu list is also implemented which is called from xl.
Signed-off-by: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
diff -r 7ffe8e01c721 -r 4a877c3d722f tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue Aug 10 15:45:42 2010 +0100
+++ b/tools/libxl/libxl.c Tue Aug 10 15:47:00 2010 +0100
@@ -2557,6 +2557,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");
@@ -2567,14 +2569,16 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
return NULL;
}
*cpusize = 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, (*cpusize + 63) / 64, sizeof
(uint64_t));
+ ptr->cpumap = cpumaps + (num_cpuwords * *nb_vcpu);
if (!ptr->cpumap) {
return NULL;
}
@@ -2596,6 +2600,13 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
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,
uint64_t *cpumap, int cpusize)
{
diff -r 7ffe8e01c721 -r 4a877c3d722f tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Tue Aug 10 15:45:42 2010 +0100
+++ b/tools/libxl/libxl.h Tue Aug 10 15:47:00 2010 +0100
@@ -595,6 +595,7 @@ typedef struct {
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 *cpusize);
+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 cpusize);
int libxl_set_vcpucount(libxl_ctx *ctx, uint32_t domid, uint32_t count);
diff -r 7ffe8e01c721 -r 4a877c3d722f tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue Aug 10 15:45:42 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Tue Aug 10 15:47:00 2010 +0100
@@ -3243,7 +3243,7 @@ static void print_vcpuinfo(uint32_t tdom
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, cpusize;
@@ -3259,26 +3259,28 @@ 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,
&cpusize))) {
+ if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid,
&nb_vcpu, &cpusize))) {
fprintf(stderr, "libxl_list_vcpu failed.\n");
goto vcpulist_out;
}
for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
print_vcpuinfo(dominfo->domid, vcpuinfo, physinfo.nr_cpus);
}
+ libxl_free_vcpu_list(list);
}
} 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,
&cpusize))) {
+ if (!(vcpuinfo = list = libxl_list_vcpu(&ctx, domid, &nb_vcpu,
&cpusize))) {
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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|