[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] 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>

diff -r 32c9a19ac98b tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Mon Aug 30 14:59:12 2010 +0100
+++ b/tools/libxl/libxl.c       Mon Aug 30 17:34:52 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)
+int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, uint32_t bitmask)
 {
     libxl_gc gc = LIBXL_INIT_GC(ctx);
-    xc_domaininfo_t domaininfo;
+    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 32c9a19ac98b tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Mon Aug 30 14:59:12 2010 +0100
+++ b/tools/libxl/libxl.h       Mon Aug 30 17:34:52 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 32c9a19ac98b tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Mon Aug 30 14:59:12 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Mon Aug 30 17:34:52 2010 +0100
@@ -3504,7 +3504,8 @@ int main_vcpupin(int argc, char **argv)
 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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.