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

[Xen-devel] [PATCH] xl: vcpu-set command


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Eric Chanudet <eric.chanudet@xxxxxxxxxx>
  • Date: Mon, 29 Mar 2010 13:29:40 +0100
  • Delivery-date: Mon, 29 Mar 2010 05:30:38 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type; b=lwehmcZlRPqbne+NXxBAS0dIDVORiMeFsfsqPgwmFPnl7EkKI1Dux7mF3aUOwCuFq7 B5shMfCRWobI0BM5AUJxiIWaJ0Rp06ZXbwRXdtK0vv1LrFU6jSDRu1hVmkJmd5eHWTHw oWrsY3kIHvZyZnxVflCX7a+4kEZiB+4NAchTc=
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>

This patch add vcpu-set command to xl.

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2289,3 +2289,26 @@ int libxl_set_vcpuaffinity(struct libxl_
 {
     return (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, cpusize));
 }
+
+int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count)
+{
+    xc_domaininfo_t domaininfo;
+    char *dompath;
+    int i;
+
+    if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
+        return ERROR_FAIL;
+    }
+    if (!count || ((domaininfo.max_vcpu_id + 1) < count)) {
+        return ERROR_INVAL;
+    }
+    if (!(dompath = libxl_xs_get_dompath(ctx, domid)))
+        return ERROR_FAIL;
+
+    for (i = 0; i <= domaininfo.max_vcpu_id; ++i) {
+        libxl_xs_write(ctx, XBT_NULL,
+                       libxl_sprintf(ctx, "%s/cpu/%u/availability",
dompath, i),
+                       "%s", ((1 << i) & ((1 << count) - 1)) ?
"online" : "offline");
+    }
+    return 0;
+}
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -388,5 +388,6 @@ struct libxl_vcpuinfo *libxl_list_vcpu(s
                                        int *nb_vcpu, int *cpusize);
 int libxl_set_vcpuaffinity(struct libxl_ctx *ctx, uint32_t domid,
uint32_t vcpuid,
                            uint64_t *cpumap, int cpusize);
+int libxl_set_vcpucount(struct libxl_ctx *ctx, uint32_t domid, uint32_t count);
 #endif /* LIBXL_H */

diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -876,6 +876,7 @@ static void help(char *command)
         printf(" button-press                  indicate an ACPI
button press to the domain\n\n");
         printf(" vcpu-list                     list the VCPUs for
all/some domains.\n\n");
         printf(" vcpu-pin                      Set which CPUs a VCPU
can use.\n\n");
+        printf(" vcpu-set                      Set the number of
active VCPUs allowed for the domain.\n\n");
     } else if(!strcmp(command, "create")) {
         printf("Usage: xl create <ConfigFile> [options] [vars]\n\n");
         printf("Create a domain based on <ConfigFile>.\n\n");
@@ -939,6 +940,9 @@ static void help(char *command)
     } else if (!strcmp(command, "vcpu-pin")) {
         printf("Usage: xm vcpu-pin <Domain> <VCPU|all> <CPUs|all>\n\n");
         printf("Set which CPUs a VCPU can use.\n\n");
+    } else if (!strcmp(command, "vcpu-set")) {
+        printf("Usage: xm vcpu-set <Domain> <vCPUs>\n\n");
+        printf("Set the number of active VCPUs for allowed for the
domain.\n\n");
     }
 }

@@ -1956,6 +1960,60 @@ int main_vcpupin(int argc, char **argv)
     exit(0);
 }

+void vcpuset(char *d, char* nr_vcpus)
+{
+    struct libxl_ctx ctx;
+    char *endptr;
+    uint32_t domid;
+    unsigned int max_vcpus;
+
+    max_vcpus = strtoul(nr_vcpus, &endptr, 10);
+    if (nr_vcpus == endptr) {
+        fprintf(stderr, "Error: Invalid argument.\n");
+        return;
+    }
+
+    if (libxl_ctx_init(&ctx, LIBXL_VERSION)) {
+        fprintf(stderr, "cannot init xl context\n");
+        return;
+    }
+    libxl_ctx_set_log(&ctx, log_callback, NULL);
+
+    if (domain_qualifier_to_domid(&ctx, d, &domid) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", d);
+        goto vcpuset_out;
+    }
+    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");
+    }
+
+  vcpuset_out:
+    libxl_ctx_free(&ctx);
+}
+
+int main_vcpuset(int argc, char **argv)
+{
+    int opt;
+
+    if (argc != 3) {
+        help("vcpu-set");
+        exit(0);
+    }
+    while ((opt = getopt(argc, argv, "h")) != -1) {
+        switch (opt) {
+        case 'h':
+        help("vcpu-set");
+            exit(0);
+        default:
+            fprintf(stderr, "option `%c' not supported.\n", opt);
+            break;
+        }
+    }
+
+    vcpuset(argv[1], argv[2]);
+    exit(0);
+}
+
 int main(int argc, char **argv)
 {
     if (argc < 2) {
@@ -2001,6 +2059,8 @@ int main(int argc, char **argv)
         main_vcpulist(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "vcpu-pin")) {
         main_vcpupin(argc - 1, argv + 1);
+    } else if (!strcmp(argv[1], "vcpu-set")) {
+        main_vcpuset(argc - 1, argv + 1);
     } else if (!strcmp(argv[1], "help")) {
         if (argc > 2)
             help(argv[2]);

-- 
Eric CHANUDET
XenClient Team

_______________________________________________
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®.