Skip to contentSkip to conversation

libxl: drop libxl_set_vcpucount, introduce libxl_set_vcpuonline

PATCH New [email protected] 2 participants 4 messages Aug 30, 2010 – Sep 1, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

tools/libxl/libxl.c +14 -12
diff -r 32c9a19ac98b tools/libxl/libxl.c
@@ -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;
tools/libxl/libxl.h +1 -1
diff -r 32c9a19ac98b tools/libxl/libxl.h
@@ -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);
 
tools/libxl/xl_cmdimpl.c +7 -4
diff -r 32c9a19ac98b tools/libxl/xl_cmdimpl.c
@@ -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)
#1 lore raw

PATCH 1/1 xl: fix vcpu-set cmd line parsing

tools/libxl/xl_cmdimpl.c +6 -5
diff -r defdbfd1608c tools/libxl/xl_cmdimpl.c
@@ -3526,10 +3526,6 @@ int main_vcpuset(int argc, char **argv)
 {
     int opt;
 
-    if (argc != 4) {
-        help("vcpu-set");
-        return 0;
-    }
     while ((opt = getopt(argc, argv, "h")) != -1) {
         switch (opt) {
         case 'h':
@@ -3541,7 +3537,12 @@ int main_vcpuset(int argc, char **argv)
         }
     }
 
-    vcpuset(argv[2], argv[3]);
+    if (optind >= argc - 1) {
+        help("vcpu-set");
+        return 2;
+    }
+
+    vcpuset(argv[optind], argv[optind+1]);
     return 0;
 }
#2 lore raw

Re: [PATCH] xl: fix vcpu-set cmd line parsing

[email protected] writes ("[Xen-devel] [PATCH] xl: fix vcpu-set cmd line parsing"):

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +0 -2
-    if (argc != 4) {
-        help("vcpu-set");

...

tools/libxl/xl_cmdimpl.c int main_vcpuset(int argc, char **argv) · line 3541

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +2 -0
+    if (optind >= argc - 1) {
+        help("vcpu-set");

I applaud your efforts to fix up the broken command-line parsing but surely this can't be right ? We need to have exactly two more arguments, not at least two.

Ian.

#3 lore raw

Re: [PATCH] xl: fix vcpu-set cmd line parsing

Quoted 10 lines · Ian Jackson

[email protected] writes ("[Xen-devel] [PATCH] xl: fix vcpu-set cmd line parsing"):

Quoted 2 lines
(quoted diff) +0 -2
-    if (argc != 4) {
-        help("vcpu-set");

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+    if (optind >= argc - 1) {
+        help("vcpu-set");

I applaud your efforts to fix up the broken command-line parsing but surely this can't be right ? We need to have exactly two more arguments, not at least two.

Yes, you are right.
Updated patch appended.

---

xl: fix vcpu-set cmd line parsing

tools/libxl/xl_cmdimpl.c +6 -5
diff -r ae0cd4e5cc01 tools/libxl/xl_cmdimpl.c
@@ -3526,10 +3526,6 @@ int main_vcpuset(int argc, char **argv)
 {
     int opt;
 
-    if (argc != 4) {
-        help("vcpu-set");
-        return 0;
-    }
     while ((opt = getopt(argc, argv, "h")) != -1) {
         switch (opt) {
         case 'h':
@@ -3541,7 +3537,12 @@ int main_vcpuset(int argc, char **argv)
         }
     }
 
-    vcpuset(argv[2], argv[3]);
+    if (optind != argc - 2) {
+        help("vcpu-set");
+        return 2;
+    }
+
+    vcpuset(argv[optind], argv[optind+1]);
     return 0;
 }