# HG changeset patch
# User Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
# Date 1283277901 -3600
# Node ID de4a22b6f582fb140cc8a5618765c1461e2e01d9
# Parent 2d30f5845cb2310c0acb3620b23912e6fbad1b37
libxl: drop libxl_set_vcpucount, introduce libxl_set_vcpuonline
This patch renames libxl_set_vcpucount to libxl_set_vcpuonline and
modifies the function to take a bitmap of online/offline vcpus as
parameter.
It also introduces a xenstore transaction to write the available cpus
to xenstore.
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
tools/libxl/libxl.c | 30 ++++++++++++++++--------------
tools/libxl/libxl.h | 2 +-
tools/libxl/xl_cmdimpl.c | 11 +++++++----
3 files changed, 24 insertions(+), 19 deletions(-)
diff -r 2d30f5845cb2 -r de4a22b6f582 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Tue Aug 31 17:51:51 2010 +0100
+++ b/tools/libxl/libxl.c Tue Aug 31 19:05:01 2010 +0100
@@ -2955,30 +2955,32 @@ int libxl_set_vcpuaffinity(libxl_ctx *ct
return 0;
}
-int libxl_set_vcpucount(libxl_ctx *ctx, uint32_t domid, uint32_t count)
-{
- libxl_gc gc = LIBXL_INIT_GC(ctx);
- xc_domaininfo_t domaininfo;
+int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, uint32_t bitmask)
+{
+ libxl_gc gc = LIBXL_INIT_GC(ctx);
+ libxl_dominfo info;
char *dompath;
+ xs_transaction_t t;
int i, rc = ERROR_FAIL;
- if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
+ if (libxl_domain_info(ctx, &info, domid) < 0) {
XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "getting domain info list");
goto out;
}
- if (!count || ((domaininfo.max_vcpu_id + 1) < count)) {
- rc = ERROR_INVAL;
- goto out;
- }
if (!(dompath = libxl_xs_get_dompath(&gc, domid)))
goto out;
- for (i = 0; i <= domaininfo.max_vcpu_id; ++i) {
- libxl_xs_write(&gc, XBT_NULL,
+retry_transaction:
+ t = xs_transaction_start(ctx->xsh);
+ for (i = 0; i <= info.vcpu_max_id; i++)
+ libxl_xs_write(&gc, t,
libxl_sprintf(&gc, "%s/cpu/%u/availability", dompath,
i),
- "%s", ((1 << i) & ((1 << count) - 1)) ? "online" :
"offline");
- }
- rc = 0;
+ "%s", ((1 << i) & bitmask) ? "online" : "offline");
+ if (!xs_transaction_end(ctx->xsh, t, 0)) {
+ if (errno == EAGAIN)
+ goto retry_transaction;
+ } else
+ rc = 0;
out:
libxl_free_all(&gc);
return rc;
diff -r 2d30f5845cb2 -r de4a22b6f582 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Tue Aug 31 17:51:51 2010 +0100
+++ b/tools/libxl/libxl.h Tue Aug 31 19:05:01 2010 +0100
@@ -434,7 +434,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
int *nb_vcpu, int *nrcpus);
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);
+int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, uint32_t bitmask);
int libxl_get_sched_id(libxl_ctx *ctx);
diff -r 2d30f5845cb2 -r de4a22b6f582 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Tue Aug 31 17:51:51 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Tue Aug 31 19:05:01 2010 +0100
@@ -3504,7 +3504,8 @@ static void vcpuset(char *d, char* nr_vc
static void vcpuset(char *d, char* nr_vcpus)
{
char *endptr;
- unsigned int max_vcpus;
+ unsigned int max_vcpus, i;
+ uint32_t bitmask = 0;
max_vcpus = strtoul(nr_vcpus, &endptr, 10);
if (nr_vcpus == endptr) {
@@ -3514,9 +3515,11 @@ static void vcpuset(char *d, char* nr_vc
find_domain(d);
- if (libxl_set_vcpucount(&ctx, domid, max_vcpus) == ERROR_INVAL) {
- fprintf(stderr, "Error: Cannot set vcpus greater than max vcpus on
running domain or lesser than 1.\n");
- }
+ for (i = 0; i < max_vcpus; i++)
+ bitmask |= 1 << i;
+
+ if (libxl_set_vcpuonline(&ctx, domid, bitmask) < 0)
+ fprintf(stderr, "libxl_set_vcpuonline failed domid=%d bitmask=%x\n",
domid, bitmask);
}
int main_vcpuset(int argc, char **argv)
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|