debuggers.hg

changeset 22651:6b0620970c73

Support renaming of cpupools

Add a new library function libxl_cpupool_rename() and a new xl command
xl cpupool-rename to support renaming of cpupools.

Signed-off-by: juergen.gross@ts.fujitsu.com
Signed-off-by: Ian Jackson <ian.jackson.citrix.com>
author Juergen Gross <juergen.gross@ts.fujitsu.com>
date Thu Dec 09 13:37:32 2010 +0100 (2010-12-09)
parents e115ee319a64
children 26d58b44cd27
files tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/libxl_utils.c tools/libxl/xl.h tools/libxl/xl_cmdimpl.c tools/libxl/xl_cmdtable.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Thu Dec 09 11:26:37 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Thu Dec 09 13:37:32 2010 +0100
     1.3 @@ -3885,6 +3885,49 @@ out:
     1.4      return rc;
     1.5  }
     1.6  
     1.7 +int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid)
     1.8 +{
     1.9 +    libxl__gc gc = LIBXL_INIT_GC(ctx);
    1.10 +    xs_transaction_t t;
    1.11 +    xc_cpupoolinfo_t *info;
    1.12 +    int rc;
    1.13 +
    1.14 +    info = xc_cpupool_getinfo(ctx->xch, poolid);
    1.15 +    if (info == NULL) {
    1.16 +        libxl__free_all(&gc);
    1.17 +        return ERROR_NOMEM;
    1.18 +    }
    1.19 +
    1.20 +    rc = ERROR_INVAL;
    1.21 +    if (info->cpupool_id != poolid)
    1.22 +        goto out;
    1.23 +
    1.24 +    rc = 0;
    1.25 +
    1.26 +    for (;;) {
    1.27 +        t = xs_transaction_start(ctx->xsh);
    1.28 +
    1.29 +        libxl__xs_write(&gc, t,
    1.30 +                        libxl__sprintf(&gc, "/local/pool/%d/name", poolid),
    1.31 +                        "%s", name);
    1.32 +
    1.33 +        if (xs_transaction_end(ctx->xsh, t, 0))
    1.34 +            break;
    1.35 +
    1.36 +        if (errno == EAGAIN)
    1.37 +            continue;
    1.38 +
    1.39 +        rc = ERROR_FAIL;
    1.40 +        break;
    1.41 +    }
    1.42 +
    1.43 +out:
    1.44 +    xc_cpupool_infofree(ctx->xch, info);
    1.45 +    libxl__free_all(&gc);
    1.46 +
    1.47 +    return rc;
    1.48 +}
    1.49 +
    1.50  int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu)
    1.51  {
    1.52      int rc;
     2.1 --- a/tools/libxl/libxl.h	Thu Dec 09 11:26:37 2010 +0100
     2.2 +++ b/tools/libxl/libxl.h	Thu Dec 09 13:37:32 2010 +0100
     2.3 @@ -528,6 +528,7 @@ int libxl_create_cpupool(libxl_ctx *ctx,
     2.4                           libxl_cpumap cpumap, libxl_uuid *uuid,
     2.5                           uint32_t *poolid);
     2.6  int libxl_destroy_cpupool(libxl_ctx *ctx, uint32_t poolid);
     2.7 +int libxl_cpupool_rename(libxl_ctx *ctx, const char *name, uint32_t poolid);
     2.8  int libxl_cpupool_cpuadd(libxl_ctx *ctx, uint32_t poolid, int cpu);
     2.9  int libxl_cpupool_cpuadd_node(libxl_ctx *ctx, uint32_t poolid, int node, int *cpus);
    2.10  int libxl_cpupool_cpuremove(libxl_ctx *ctx, uint32_t poolid, int cpu);
     3.1 --- a/tools/libxl/libxl_utils.c	Thu Dec 09 11:26:37 2010 +0100
     3.2 +++ b/tools/libxl/libxl_utils.c	Thu Dec 09 13:37:32 2010 +0100
     3.3 @@ -107,10 +107,10 @@ char *libxl_cpupoolid_to_name(libxl_ctx 
     3.4      char path[strlen("/local/pool") + 12];
     3.5      char *s;
     3.6  
     3.7 -    if (poolid == 0)
     3.8 -        return strdup("Pool-0");
     3.9      snprintf(path, sizeof(path), "/local/pool/%d/name", poolid);
    3.10      s = xs_read(ctx->xsh, XBT_NULL, path, &len);
    3.11 +    if (!s && (poolid == 0))
    3.12 +        return strdup("Pool-0");
    3.13      return s;
    3.14  }
    3.15  
     4.1 --- a/tools/libxl/xl.h	Thu Dec 09 11:26:37 2010 +0100
     4.2 +++ b/tools/libxl/xl.h	Thu Dec 09 13:37:32 2010 +0100
     4.3 @@ -82,6 +82,7 @@ int main_network2detach(int argc, char *
     4.4  int main_cpupoolcreate(int argc, char **argv);
     4.5  int main_cpupoollist(int argc, char **argv);
     4.6  int main_cpupooldestroy(int argc, char **argv);
     4.7 +int main_cpupoolrename(int argc, char **argv);
     4.8  int main_cpupoolcpuadd(int argc, char **argv);
     4.9  int main_cpupoolcpuremove(int argc, char **argv);
    4.10  int main_cpupoolmigrate(int argc, char **argv);
     5.1 --- a/tools/libxl/xl_cmdimpl.c	Thu Dec 09 11:26:37 2010 +0100
     5.2 +++ b/tools/libxl/xl_cmdimpl.c	Thu Dec 09 13:37:32 2010 +0100
     5.3 @@ -5729,6 +5729,47 @@ int main_cpupooldestroy(int argc, char *
     5.4      return -libxl_destroy_cpupool(&ctx, poolid);
     5.5  }
     5.6  
     5.7 +int main_cpupoolrename(int argc, char **argv)
     5.8 +{
     5.9 +    int opt;
    5.10 +    const char *pool;
    5.11 +    const char *new_name;
    5.12 +    uint32_t poolid;
    5.13 +
    5.14 +    while ((opt = getopt(argc, argv, "h")) != -1) {
    5.15 +        switch (opt) {
    5.16 +        case 'h':
    5.17 +            help("cpupool-rename");
    5.18 +            return 0;
    5.19 +        default:
    5.20 +            fprintf(stderr, "option `%c' not supported.\n", opt);
    5.21 +            break;
    5.22 +        }
    5.23 +    }
    5.24 +
    5.25 +    pool = argv[optind++];
    5.26 +    if (!pool || !argv[optind]) {
    5.27 +        fprintf(stderr, "'xl cpupool-rename' requires 2 arguments.\n\n");
    5.28 +        help("cpupool-rename");
    5.29 +        return 1;
    5.30 +    }
    5.31 +
    5.32 +    if (cpupool_qualifier_to_cpupoolid(pool, &poolid, NULL) ||
    5.33 +        !libxl_cpupoolid_to_name(&ctx, poolid)) {
    5.34 +        fprintf(stderr, "unknown cpupool \'%s\'\n", pool);
    5.35 +        return -ERROR_FAIL;
    5.36 +    }
    5.37 +
    5.38 +    new_name = argv[optind];
    5.39 +
    5.40 +    if (libxl_cpupool_rename(&ctx, new_name, poolid)) {
    5.41 +        fprintf(stderr, "Can't rename cpupool '%s'.\n", pool);
    5.42 +        return 1;
    5.43 +    }
    5.44 +
    5.45 +    return 0;
    5.46 +}
    5.47 +
    5.48  int main_cpupoolcpuadd(int argc, char **argv)
    5.49  {
    5.50      int opt;
     6.1 --- a/tools/libxl/xl_cmdtable.c	Thu Dec 09 11:26:37 2010 +0100
     6.2 +++ b/tools/libxl/xl_cmdtable.c	Thu Dec 09 13:37:32 2010 +0100
     6.3 @@ -358,6 +358,11 @@ struct cmd_spec cmd_table[] = {
     6.4        "Deactivates a CPU pool",
     6.5        "<CPU Pool>",
     6.6      },
     6.7 +    { "cpupool-rename",
     6.8 +      &main_cpupoolrename,
     6.9 +      "Renames a CPU pool",
    6.10 +      "<CPU Pool> <new name>",
    6.11 +    },
    6.12      { "cpupool-cpu-add",
    6.13        &main_cpupoolcpuadd,
    6.14        "Adds a CPU to a CPU pool",