return max_cpus;
if ( !xc_physinfo(xch, &physinfo) )
+ {
max_cpus = physinfo.max_cpu_id + 1;
+ return max_cpus;
+ }
- return max_cpus;
+ return -1;
}
int xc_get_max_nodes(xc_interface *xch)
return max_nodes;
if ( !xc_physinfo(xch, &physinfo) )
+ {
max_nodes = physinfo.max_node_id + 1;
+ return max_nodes;
+ }
- return max_nodes;
+ return -1;
}
int xc_get_cpumap_size(xc_interface *xch)
{
- return (xc_get_max_cpus(xch) + 7) / 8;
+ int max_cpus = xc_get_max_cpus(xch);
+
+ if ( max_cpus < 0 )
+ return -1;
+ return (max_cpus + 7) / 8;
}
int xc_get_nodemap_size(xc_interface *xch)
{
- return (xc_get_max_nodes(xch) + 7) / 8;
+ int max_nodes = xc_get_max_nodes(xch);
+
+ if ( max_nodes < 0 )
+ return -1;
+ return (max_nodes + 7) / 8;
}
xc_cpumap_t xc_cpumap_alloc(xc_interface *xch)
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;
int max_cpus;
max_cpus = libxl_get_max_cpus(ctx);
- if (max_cpus == 0)
+ if (max_cpus < 0)
{
LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of CPUS");
ret = NULL;
int i, j, max_nodes;
max_nodes = libxl_get_max_nodes(ctx);
- if (max_nodes == 0)
+ if (max_nodes < 0)
{
LIBXL__LOG(ctx, XTL_ERROR, "Unable to determine number of NODES");
ret = NULL;
*nr_vcpus_out <= domaininfo.max_vcpu_id;
++*nr_vcpus_out, ++ptr) {
libxl_bitmap_init(&ptr->cpumap);
- if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap, 0)) {
- LOGE(ERROR, "allocating cpumap");
+ if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap, 0))
goto err;
- }
if (xc_vcpu_getinfo(ctx->xch, domid, *nr_vcpus_out, &vcpuinfo) == -1) {
LOGE(ERROR, "getting vcpu info");
goto err;
int ncpus;
ncpus = libxl_get_max_cpus(ctx);
- if (ncpus == 0)
- return ERROR_FAIL;
+ if (ncpus < 0)
+ return ncpus;
cpumap->map = xc_cpupool_freeinfo(ctx->xch);
if (cpumap->map == NULL)
int libxl_cpu_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *cpumap, int max_cpus)
{
- if (max_cpus < 0)
- return ERROR_INVAL;
+ GC_INIT(ctx);
+ int rc = 0;
+
+ if (max_cpus < 0) {
+ rc = ERROR_INVAL;
+ LOG(ERROR, "invalid number of cpus provided");
+ goto out;
+ }
if (max_cpus == 0)
max_cpus = libxl_get_max_cpus(ctx);
- if (max_cpus == 0)
- return ERROR_FAIL;
+ if (max_cpus < 0) {
+ LOG(ERROR, "failed to retrieve the maximum number of cpus");
+ rc = max_cpus;
+ goto out;
+ }
+ /* This can't fail: no need to check and log */
+ libxl_bitmap_alloc(ctx, cpumap, max_cpus);
- return libxl_bitmap_alloc(ctx, cpumap, max_cpus);
+ out:
+ GC_FREE;
+ return rc;
}
int libxl_node_bitmap_alloc(libxl_ctx *ctx, libxl_bitmap *nodemap,
int max_nodes)
{
- if (max_nodes < 0)
- return ERROR_INVAL;
+ GC_INIT(ctx);
+ int rc = 0;
+
+ if (max_nodes < 0) {
+ rc = ERROR_INVAL;
+ LOG(ERROR, "invalid number of nodes provided");
+ goto out;
+ }
+
if (max_nodes == 0)
max_nodes = libxl_get_max_nodes(ctx);
- if (max_nodes == 0)
- return ERROR_FAIL;
+ if (max_nodes < 0) {
+ LOG(ERROR, "failed to retrieve the maximum number of nodes");
+ rc = max_nodes;
+ goto out;
+ }
+ /* This can't fail: no need to check and log */
+ libxl_bitmap_alloc(ctx, nodemap, max_nodes);
- return libxl_bitmap_alloc(ctx, nodemap, max_nodes);
+ out:
+ GC_FREE;
+ return rc;
}
int libxl_nodemap_to_cpumap(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,
return NULL;
nr_cpus = xc_get_max_cpus(self->xc_handle);
- if ( nr_cpus == 0 )
+ if ( nr_cpus < 0 )
return pyxc_error_to_exception(self->xc_handle);
cpumap = xc_cpumap_alloc(self->xc_handle);
return NULL;
nr_cpus = xc_get_max_cpus(self->xc_handle);
- if ( nr_cpus == 0 )
+ if ( nr_cpus < 0 )
return pyxc_error_to_exception(self->xc_handle);
rc = xc_vcpu_getinfo(self->xc_handle, dom, vcpu, &info);
int nr_cpus;
nr_cpus = xc_get_max_cpus(self->xc_handle);
- if ( nr_cpus == 0 )
+ if ( nr_cpus < 0 )
return pyxc_error_to_exception(self->xc_handle);
cpulist = PyList_New(0);