debuggers.hg

changeset 20847:ab5845cfa62d

libxenlight: fix name to domid conversion.

also simplify massively the function that iterate over all domains to
find the corresponding domid to a name.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 14 09:42:40 2010 +0000 (2010-01-14)
parents 7a412f9f6aae
children aaf34d74b622
files tools/libxl/libxl_utils.c tools/libxl/xl.c
line diff
     1.1 --- a/tools/libxl/libxl_utils.c	Thu Jan 14 09:42:06 2010 +0000
     1.2 +++ b/tools/libxl/libxl_utils.c	Thu Jan 14 09:42:40 2010 +0000
     1.3 @@ -56,34 +56,23 @@ char *libxl_domid_to_name(struct libxl_c
     1.4  
     1.5  int libxl_name_to_domid(struct libxl_ctx *ctx, char *name, uint32_t *domid)
     1.6  {
     1.7 -    unsigned int num, len;
     1.8 -    char path[strlen("/local/domain") + 12];
     1.9 -    int i, j, nb_domains;
    1.10 -    char *domname, **l;
    1.11 +    int i, nb_domains;
    1.12 +    char *domname;
    1.13      struct libxl_dominfo *dominfo;
    1.14  
    1.15      dominfo = libxl_domain_list(ctx, &nb_domains);
    1.16 +    if (!dominfo)
    1.17 +        return ERROR_NOMEM;
    1.18  
    1.19 -    l = xs_directory(ctx->xsh, XBT_NULL, "/local/domain", &num);
    1.20 -    for (i = 0; i < num; i++) {
    1.21 -        snprintf(path, sizeof(path), "/local/domain/%s/name", l[i]);
    1.22 -        domname = xs_read(ctx->xsh, XBT_NULL, path, &len);
    1.23 -        if (domname != NULL && len == strlen(name) && !strncmp(domname, name, len)) {
    1.24 -            int domid_i = atoi(l[i]);
    1.25 -            for (j = 0; j < nb_domains; j++) {
    1.26 -                if (dominfo[j].domid == domid_i) {
    1.27 -                    *domid = domid_i;
    1.28 -                    free(dominfo);
    1.29 -                    free(l);
    1.30 -                    free(domname);
    1.31 -                    return 0;
    1.32 -                }
    1.33 -            }
    1.34 +    for (i = 0; i < nb_domains; i++) {
    1.35 +        domname = libxl_domid_to_name(ctx, dominfo[i].domid);
    1.36 +        if (!domname)
    1.37 +            continue;
    1.38 +        if (strcmp(domname, name) == 0) {
    1.39 +            *domid = dominfo[i].domid;
    1.40 +            return 0;
    1.41          }
    1.42 -        free(domname);
    1.43      }
    1.44 -    free(dominfo);
    1.45 -    free(l);
    1.46      return -1;
    1.47  }
    1.48  
     2.1 --- a/tools/libxl/xl.c	Thu Jan 14 09:42:06 2010 +0000
     2.2 +++ b/tools/libxl/xl.c	Thu Jan 14 09:42:40 2010 +0000
     2.3 @@ -59,9 +59,7 @@ static int domain_qualifier_to_domid(str
     2.4          }
     2.5      }
     2.6  
     2.7 -    if (i == 0)
     2.8 -        return -1;
     2.9 -    if (alldigit) {
    2.10 +    if (i > 0 && alldigit) {
    2.11          *domid = strtoul(p, NULL, 10);
    2.12          return 0;
    2.13      } else {