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

[Xen-changelog] [xen-unstable] xl: vcpu-set command



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1270533337 -3600
# Node ID 29f271d3ceec05f7dbf470a9dfd2309249017435
# Parent  98e7aff6ee19ec595d369b55783dac226d249469
xl: vcpu-set command

Signed-off-by: Eric Chanudet <eric.chanudet@xxxxxxxxxx>
Acked-by: Vincent Hanquez <vincent.hanquez@xxxxxxxxxxxxx>
Acked-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c |   23 +++++++++++++++++++
 tools/libxl/libxl.h |    1 
 tools/libxl/xl.c    |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)

diff -r 98e7aff6ee19 -r 29f271d3ceec tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue Apr 06 06:54:51 2010 +0100
+++ b/tools/libxl/libxl.c       Tue Apr 06 06:55:37 2010 +0100
@@ -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 -r 98e7aff6ee19 -r 29f271d3ceec tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Tue Apr 06 06:54:51 2010 +0100
+++ b/tools/libxl/libxl.h       Tue Apr 06 06:55:37 2010 +0100
@@ -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 -r 98e7aff6ee19 -r 29f271d3ceec tools/libxl/xl.c
--- a/tools/libxl/xl.c  Tue Apr 06 06:54:51 2010 +0100
+++ b/tools/libxl/xl.c  Tue Apr 06 06:55:37 2010 +0100
@@ -878,6 +878,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");
@@ -941,6 +942,9 @@ static void help(char *command)
     } else if (!strcmp(command, "vcpu-pin")) {
         printf("Usage: xl 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: xl vcpu-set <Domain> <vCPUs>\n\n");
+        printf("Set the number of active VCPUs for allowed for the 
domain.\n\n");
     }
 }
 
@@ -1977,6 +1981,60 @@ int main_vcpupin(int argc, char **argv)
     }
 
     vcpupin(argv[1], argv[2] , argv[3]);
+    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);
 }
 
@@ -2025,6 +2083,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]);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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