From: Eric Chanudet <eric.chanudet@citrix.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH 3 of 4] xl: vcpu-set command
Date: Thu, 01 Apr 2010 17:27:25 +0100 [thread overview]
Message-ID: <a69f3e98d85a862513f0.1270139245@eric.cam.xci-test.com> (raw)
In-Reply-To: <patchbomb.1270139242@eric.cam.xci-test.com>
This patch add vcpu-set command to xl.
Acked-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
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
@@ -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");
}
}
@@ -1980,6 +1984,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) {
@@ -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]);
next prev parent reply other threads:[~2010-04-01 16:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-01 16:27 [PATCH 0 of 4] xl: vcpu commands and tsc_mode parameter Eric Chanudet
2010-04-01 16:27 ` [PATCH 1 of 4] xl: vcpu-list command Eric Chanudet
2010-04-01 16:27 ` [PATCH 2 of 4] xl: vcpu-pin command Eric Chanudet
2010-04-01 16:27 ` Eric Chanudet [this message]
2010-04-01 16:27 ` [PATCH 4 of 4] xl: tsc_mode parameter in guest configuration file Eric Chanudet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a69f3e98d85a862513f0.1270139245@eric.cam.xci-test.com \
--to=eric.chanudet@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).