return 0;
}
+int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus)
+{
+ int rc = 0;
+ int cpu;
+ libxl_cpumap freemap;
+ libxl_topologyinfo topology;
+
+ if (libxl_get_freecpus(ctx, &freemap)) {
+ return ERROR_FAIL;
+ }
+
+ if (libxl_get_topologyinfo(ctx, &topology)) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ *cpus = 0;
+ for (cpu = 0; cpu < topology.nodemap.entries; cpu++) {
+ if (libxl_cpumap_test(&freemap, cpu) &&
+ (topology.nodemap.array[cpu] == node) &&
+ !libxl_cpupool_cpuadd(ctx, poolid, cpu)) {
+ (*cpus)++;
+ }
+ }
+
+ libxl_topologyinfo_destroy(&topology);
+
+out:
+ libxl_cpumap_destroy(&freemap);
+ return rc;
+}
+
int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu)
{
int rc;
return 0;
}
+int libxl_cpupool_cpuremove_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus)
+{
+ int ret = 0;
+ int n_pools;
+ int p;
+ int cpu;
+ libxl_topologyinfo topology;
+ libxl_cpupoolinfo *poolinfo;
+
+ poolinfo = libxl_list_cpupool(ctx, &n_pools);
+ if (!poolinfo) {
+ return ERROR_NOMEM;
+ }
+
+ if (libxl_get_topologyinfo(ctx, &topology)) {
+ ret = ERROR_FAIL;
+ goto out;
+ }
+
+ *cpus = 0;
+ for (p = 0; p < n_pools; p++) {
+ if (poolinfo[p].poolid == poolid) {
+ for (cpu = 0; cpu < topology.nodemap.entries; cpu++) {
+ if ((topology.nodemap.array[cpu] == node) &&
+ libxl_cpumap_test(&poolinfo[p].cpumap, cpu) &&
+ !libxl_cpupool_cpuremove(ctx, poolid, cpu)) {
+ (*cpus)++;
+ }
+ }
+ }
+ }
+
+ libxl_topologyinfo_destroy(&topology);
+
+out:
+ for (p = 0; p < n_pools; p++) {
+ libxl_cpupoolinfo_destroy(poolinfo + p);
+ }
+
+ return ret;
+}
+
int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
uint32_t poolid;
int schedid = -1;
XLU_ConfigList *cpus;
- int n_cpus, i, n;
+ XLU_ConfigList *nodes;
+ int n_cpus, n_nodes, i, n;
libxl_cpumap freemap;
libxl_cpumap cpumap;
libxl_uuid uuid;
+ libxl_topologyinfo topology;
while (1) {
opt = getopt_long(argc, argv, "hnf:", long_options, &option_index);
fprintf(stderr, "Failed to allocate cpumap\n");
return -ERROR_FAIL;
}
- if (!xlu_cfg_get_list(config, "cpus", &cpus, 0, 0)) {
+ if (!xlu_cfg_get_list(config, "nodes", &nodes, 0, 0)) {
+ n_cpus = 0;
+ n_nodes = 0;
+ if (libxl_get_topologyinfo(&ctx, &topology)) {
+ fprintf(stderr, "libxl_get_topologyinfo failed\n");
+ return -ERROR_FAIL;
+ }
+ while ((buf = xlu_cfg_get_listitem(nodes, n_nodes)) != NULL) {
+ n = atoi(buf);
+ for (i = 0; i < topology.nodemap.entries; i++) {
+ if ((topology.nodemap.array[i] == n) &&
+ libxl_cpumap_test(&freemap, i)) {
+ libxl_cpumap_set(&cpumap, i);
+ n_cpus++;
+ }
+ }
+ n_nodes++;
+ }
+
+ libxl_topologyinfo_destroy(&topology);
+
+ if (n_cpus == 0) {
+ fprintf(stderr, "no free cpu found\n");
+ return -ERROR_FAIL;
+ }
+ } else if (!xlu_cfg_get_list(config, "cpus", &cpus, 0, 0)) {
n_cpus = 0;
while ((buf = xlu_cfg_get_listitem(cpus, n_cpus)) != NULL) {
i = atoi(buf);
const char *pool;
uint32_t poolid;
int cpu;
+ int node;
+ int n;
while ((opt = getopt(argc, argv, "h")) != -1) {
switch (opt) {
help("cpupool-cpu-add");
return -ERROR_FAIL;
}
- cpu = atoi(argv[optind]);
+ node = -1;
+ cpu = -1;
+ if (strncmp(argv[optind], "node:", 5) == 0) {
+ node = atoi(argv[optind] + 5);
+ } else {
+ cpu = atoi(argv[optind]);
+ }
if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
!libxl_cpupoolid_to_name(&ctx, poolid)) {
return -ERROR_FAIL;
}
- return -libxl_cpupool_cpuadd(&ctx, poolid, cpu);
+ if (cpu >= 0) {
+ return -libxl_cpupool_cpuadd(&ctx, poolid, cpu);
+ }
+
+ if (libxl_cpupool_cpuadd_node(&ctx, poolid, node, &n)) {
+ fprintf(stderr, "libxl_cpupool_cpuadd_node failed\n");
+ return -ERROR_FAIL;
+ }
+
+ if (n > 0) {
+ return 0;
+ }
+
+ fprintf(stderr, "no free cpu found\n");
+ return -ERROR_FAIL;
}
int main_cpupoolcpuremove(int argc, char **argv)
const char *pool;
uint32_t poolid;
int cpu;
+ int node;
+ int n;
while ((opt = getopt(argc, argv, "h")) != -1) {
switch (opt) {
help("cpupool-cpu-remove");
return -ERROR_FAIL;
}
- cpu = atoi(argv[optind]);
+ node = -1;
+ cpu = -1;
+ if (strncmp(argv[optind], "node:", 5) == 0) {
+ node = atoi(argv[optind] + 5);
+ } else {
+ cpu = atoi(argv[optind]);
+ }
if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
!libxl_cpupoolid_to_name(&ctx, poolid)) {
return -ERROR_FAIL;
}
- return -libxl_cpupool_cpuremove(&ctx, poolid, cpu);
+ if (cpu >= 0) {
+ return -libxl_cpupool_cpuremove(&ctx, poolid, cpu);
+ }
+
+ if (libxl_cpupool_cpuremove_node(&ctx, poolid, node, &n)) {
+ fprintf(stderr, "libxl_cpupool_cpuremove_node failed\n");
+ return -ERROR_FAIL;
+ }
+
+ if (n == 0) {
+ fprintf(stderr, "no cpu of node found in cpupool\n");
+ return -ERROR_FAIL;
+ }
+
+ return 0;
}
int main_cpupoolmigrate(int argc, char **argv)