stefano.stabellini@eu.citrix.com
2010-Aug-30 16:40 UTC
[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@eu.citrix.com>
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@lists.xensource.com
http://lists.xensource.com/xen-devel
stefano.stabellini@eu.citrix.com
2010-Aug-30 16:40 UTC
[Xen-devel] [PATCH] xl: fix vcpu-set cmd line parsing
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
diff -r defdbfd1608c tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Aug 30 17:34:53 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon Aug 30 17:36:50 2010 +0100
@@ -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;
}
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Ian Jackson
2010-Aug-31 18:06 UTC
Re: [Xen-devel] [PATCH] xl: fix vcpu-set cmd line parsing
stefano.stabellini@eu.citrix.com writes ("[Xen-devel] [PATCH] xl: fix
vcpu-set cmd line parsing"):> - if (argc != 4) {
> - help("vcpu-set");
...> + 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.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Stefano Stabellini
2010-Sep-01 10:24 UTC
Re: [Xen-devel] [PATCH] xl: fix vcpu-set cmd line parsing
On Tue, 31 Aug 2010, Ian Jackson wrote:> stefano.stabellini@eu.citrix.com writes ("[Xen-devel] [PATCH] xl: fix vcpu-set cmd line parsing"): > > - if (argc != 4) { > > - help("vcpu-set"); > ... > > + 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 Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> diff -r ae0cd4e5cc01 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Wed Sep 01 10:19:14 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Wed Sep 01 11:24:03 2010 +0100 @@ -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; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel