From: Dario Faggioli <dario.faggioli@citrix.com>
To: xen-devel@lists.xen.org
Cc: Marcus Granado <Marcus.Granado@eu.citrix.com>,
Keir Fraser <keir@xen.org>,
Ian Campbell <Ian.Campbell@citrix.com>,
Li Yechen <lccycc123@gmail.com>,
George Dunlap <george.dunlap@eu.citrix.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
Juergen Gross <juergen.gross@ts.fujitsu.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Jan Beulich <JBeulich@suse.com>,
Justin Weaver <jtweaver@hawaii.edu>, Matt Wilson <msw@amazon.com>,
Elena Ufimtseva <ufimtseva@gmail.com>
Subject: [PATCH v3 02/14] libxl: sanitize error handling in libxl_get_max_{cpus, nodes}
Date: Mon, 18 Nov 2013 19:16:46 +0100 [thread overview]
Message-ID: <20131118181646.31002.55372.stgit@Solace> (raw)
In-Reply-To: <20131118175544.31002.79574.stgit@Solace>
as well as both error handling and logging in libxl_cpu_bitmap_alloc
and libxl_node_bitmap_alloc.
Now libxl_get_max_{cpus,nodes} either return a positive number, or
a libxl error code. Thanks to that, it is possible to fix loggig for
the two bitmap allocation functions, which now happens _inside_ the
functions themselves, and report what happens more accurately.
Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
---
Changes from v2:
* this wasn't there in v2, but fixing this for v3 was requested
during v2 review.
---
tools/libxl/libxl.c | 8 ++------
tools/libxl/libxl_utils.c | 48 +++++++++++++++++++++++++++++++++++++++++++--
tools/libxl/libxl_utils.h | 32 ++++++------------------------
3 files changed, 54 insertions(+), 34 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 0de1112..d3ab65e 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -616,10 +616,8 @@ static int cpupool_info(libxl__gc *gc,
info->n_dom = xcinfo->n_dom;
rc = libxl_cpu_bitmap_alloc(CTX, &info->cpumap, 0);
if (rc)
- {
- LOG(ERROR, "unable to allocate cpumap %d\n", rc);
goto out;
- }
+
memcpy(info->cpumap.map, xcinfo->cpumap, info->cpumap.size);
rc = 0;
@@ -4204,10 +4202,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
}
for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
- if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap, 0)) {
- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "allocating cpumap");
+ if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap, 0))
return NULL;
- }
if (xc_vcpu_getinfo(ctx->xch, domid, *nb_vcpu, &vcpuinfo) == -1) {
LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting vcpu info");
return NULL;
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 682f874..2a51c9c 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -645,6 +645,46 @@ char *libxl_bitmap_to_hex_string(libxl_ctx *ctx, const libxl_bitmap *bitmap)
return q;
}
+inline int libxl_cpu_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *cpumap,
+ int max_cpus)
+{
+ if (max_cpus < 0)
+ return ERROR_INVAL;
+
+ if (max_cpus == 0)
+ max_cpus = libxl_get_max_cpus(ctx);
+
+ if (max_cpus <= 0) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "failed to retrieve the maximum number of cpus");
+ return ERROR_FAIL;
+ }
+
+ /* This can't fail: no need to check and log */
+ return libxl_bitmap_alloc(ctx, cpumap, max_cpus);
+}
+
+int libxl_node_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *nodemap,
+ int max_nodes)
+{
+ if (max_nodes < 0)
+ return ERROR_INVAL;
+
+ if (max_nodes == 0)
+ max_nodes = libxl_get_max_nodes(ctx);
+
+ if (max_nodes <= 0) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "failed to retrieve the maximum number of nodes");
+ return ERROR_FAIL;
+ }
+
+ /* This can't fail: no need to check and log */
+ return libxl_bitmap_alloc(ctx, nodemap, max_nodes);
+}
+
int libxl_nodemap_to_cpumap(libxl_ctx *ctx,
const libxl_bitmap *nodemap,
libxl_bitmap *cpumap)
@@ -713,12 +753,16 @@ int libxl_cpumap_to_nodemap(libxl_ctx *ctx,
int libxl_get_max_cpus(libxl_ctx *ctx)
{
- return xc_get_max_cpus(ctx->xch);
+ int max_cpus = xc_get_max_cpus(ctx->xch);
+
+ return max_cpus <= 0 ? ERROR_FAIL : max_cpus;
}
int libxl_get_max_nodes(libxl_ctx *ctx)
{
- return xc_get_max_nodes(ctx->xch);
+ int max_nodes = xc_get_max_nodes(ctx->xch);
+
+ return max_nodes <= 0 ? ERROR_FAIL : max_nodes;
}
int libxl__enum_from_string(const libxl_enum_string_table *t,
diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h
index 7b84e6a..b11cf28 100644
--- a/tools/libxl/libxl_utils.h
+++ b/tools/libxl/libxl_utils.h
@@ -98,32 +98,12 @@ static inline int libxl_bitmap_cpu_valid(libxl_bitmap *bitmap, int bit)
#define libxl_for_each_set_bit(v, m) for (v = 0; v < (m).size * 8; v++) \
if (libxl_bitmap_test(&(m), v))
-static inline int libxl_cpu_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *cpumap,
- int max_cpus)
-{
- if (max_cpus < 0)
- return ERROR_INVAL;
- if (max_cpus == 0)
- max_cpus = libxl_get_max_cpus(ctx);
- if (max_cpus == 0)
- return ERROR_FAIL;
-
- return libxl_bitmap_alloc(ctx, cpumap, max_cpus);
-}
-
-static inline int libxl_node_bitmap_alloc(libxl_ctx *ctx,
- libxl_bitmap *nodemap,
- int max_nodes)
-{
- if (max_nodes < 0)
- return ERROR_INVAL;
- if (max_nodes == 0)
- max_nodes = libxl_get_max_nodes(ctx);
- if (max_nodes == 0)
- return ERROR_FAIL;
-
- return libxl_bitmap_alloc(ctx, nodemap, max_nodes);
-}
+int libxl_cpu_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *cpumap,
+ int max_cpus);
+int libxl_node_bitmap_alloc(libxl_ctx *ctx,
+ libxl_bitmap *nodemap,
+ int max_nodes);
/* Populate cpumap with the cpus spanned by the nodes in nodemap */
int libxl_nodemap_to_cpumap(libxl_ctx *ctx,
next prev parent reply other threads:[~2013-11-18 18:16 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-18 18:16 [PATCH v3 00/14] Series short description Dario Faggioli
2013-11-18 18:16 ` [PATCH v3 01/14] xl: match output of vcpu-list with pinning syntax Dario Faggioli
2013-11-18 18:16 ` Dario Faggioli [this message]
2013-11-19 12:24 ` [PATCH v3 02/14] libxl: sanitize error handling in libxl_get_max_{cpus, nodes} George Dunlap
2013-11-19 12:34 ` Dario Faggioli
2013-11-18 18:16 ` [PATCH v3 03/14] xl: allow for node-wise specification of vcpu pinning Dario Faggioli
2013-11-18 18:17 ` [PATCH v3 04/14] xl: implement and enable dryrun mode for `xl vcpu-pin' Dario Faggioli
2013-11-18 18:17 ` [PATCH v3 05/14] xl: test script for the cpumap parser (for vCPU pinning) Dario Faggioli
2013-11-18 18:17 ` [PATCH v3 06/14] xen: sched: rename v->cpu_affinity into v->cpu_hard_affinity Dario Faggioli
2013-11-18 18:17 ` [PATCH v3 07/14] xen: sched: introduce soft-affinity and use it instead d->node-affinity Dario Faggioli
2013-11-18 18:17 ` [PATCH v3 08/14] xen: derive NUMA node affinity from hard and soft CPU affinity Dario Faggioli
2013-11-19 14:14 ` George Dunlap
2013-11-19 16:20 ` Jan Beulich
2013-11-19 16:35 ` Dario Faggioli
2013-11-18 18:17 ` [PATCH v3 09/14] xen: sched: DOMCTL_*vcpuaffinity works with hard and soft affinity Dario Faggioli
2013-11-19 14:32 ` George Dunlap
2013-11-19 16:39 ` Jan Beulich
2013-11-22 18:55 ` Dario Faggioli
2013-11-25 9:32 ` Jan Beulich
2013-11-25 9:54 ` Dario Faggioli
2013-11-25 10:00 ` Jan Beulich
2013-11-25 10:58 ` George Dunlap
2013-11-18 18:18 ` [PATCH v3 10/14] libxc: get and set soft and hard affinity Dario Faggioli
2013-11-19 14:51 ` George Dunlap
2013-11-19 14:57 ` Ian Campbell
2013-11-19 14:58 ` George Dunlap
2013-11-19 17:08 ` Ian Campbell
2013-11-19 18:01 ` Dario Faggioli
2013-11-18 18:18 ` [PATCH v3 11/14] libxl: get and set soft affinity Dario Faggioli
2013-11-19 15:41 ` George Dunlap
2013-11-19 16:09 ` Dario Faggioli
2013-11-19 17:15 ` Ian Campbell
2013-11-19 18:58 ` Dario Faggioli
2013-11-20 11:30 ` Ian Campbell
2013-11-20 13:59 ` George Dunlap
2013-11-20 14:04 ` Ian Campbell
2013-11-20 16:59 ` Ian Jackson
2013-11-20 17:46 ` Dario Faggioli
2013-11-20 14:09 ` George Dunlap
2013-11-19 17:24 ` Ian Campbell
2013-11-19 17:51 ` Dario Faggioli
2013-11-20 11:27 ` Ian Campbell
2013-11-20 11:29 ` George Dunlap
2013-11-20 11:32 ` Ian Campbell
2013-11-20 11:40 ` Dario Faggioli
2013-11-20 14:45 ` George Dunlap
2013-11-20 14:52 ` Dario Faggioli
2013-11-20 12:00 ` Dario Faggioli
2013-11-20 12:05 ` Ian Campbell
2013-11-20 12:18 ` Dario Faggioli
2013-11-20 12:26 ` Ian Campbell
2013-11-20 14:50 ` Dario Faggioli
2013-11-20 14:56 ` Ian Campbell
2013-11-20 16:27 ` Dario Faggioli
2013-11-18 18:18 ` [PATCH v3 12/14] xl: enable getting and setting soft Dario Faggioli
2013-11-19 17:30 ` Ian Campbell
2013-11-19 17:52 ` Dario Faggioli
2013-11-18 18:18 ` [PATCH v3 13/14] xl: enable for specifying node-affinity in the config file Dario Faggioli
2013-11-19 17:35 ` Ian Campbell
2013-11-18 18:18 ` [PATCH v3 14/14] libxl: automatic NUMA placement affects soft affinity Dario Faggioli
2013-11-19 17:41 ` Ian Campbell
2013-11-19 17:57 ` Dario Faggioli
2013-11-18 18:20 ` [PATCH v3 00/14] Series short description Dario Faggioli
2013-11-19 16:00 ` George Dunlap
2013-11-19 16:08 ` Jan Beulich
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=20131118181646.31002.55372.stgit@Solace \
--to=dario.faggioli@citrix.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=Marcus.Granado@eu.citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=jtweaver@hawaii.edu \
--cc=juergen.gross@ts.fujitsu.com \
--cc=keir@xen.org \
--cc=lccycc123@gmail.com \
--cc=msw@amazon.com \
--cc=ufimtseva@gmail.com \
--cc=xen-devel@lists.xen.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.