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>
This commit is contained in:
Keir Fraser committed 2010-01-14 09:42:40 +00:00
1 parent 9ff53e8d1a
commit 0b5e4f99ae
2 files changed
+12 -25

No files matched your search

+11 -22
View File
@@ -56,34 +56,23 @@ char *libxl_domid_to_name(struct libxl_ctx *ctx, uint32_t domid)
int libxl_name_to_domid(struct libxl_ctx *ctx, char *name, uint32_t *domid)
{
unsigned int num, len;
char path[strlen("/local/domain") + 12];
int i, j, nb_domains;
char *domname, **l;
int i, nb_domains;
char *domname;
struct libxl_dominfo *dominfo;
dominfo = libxl_domain_list(ctx, &nb_domains);
if (!dominfo)
return ERROR_NOMEM;
l = xs_directory(ctx->xsh, XBT_NULL, "/local/domain", &num);
for (i = 0; i < num; i++) {
snprintf(path, sizeof(path), "/local/domain/%s/name", l[i]);
domname = xs_read(ctx->xsh, XBT_NULL, path, &len);
if (domname != NULL && len == strlen(name) && !strncmp(domname, name, len)) {
int domid_i = atoi(l[i]);
for (j = 0; j < nb_domains; j++) {
if (dominfo[j].domid == domid_i) {
*domid = domid_i;
free(dominfo);
free(l);
free(domname);
return 0;
}
}
for (i = 0; i < nb_domains; i++) {
domname = libxl_domid_to_name(ctx, dominfo[i].domid);
if (!domname)
continue;
if (strcmp(domname, name) == 0) {
*domid = dominfo[i].domid;
return 0;
}
free(domname);
}
free(dominfo);
free(l);
return -1;
}
+1 -3
View File
@@ -59,9 +59,7 @@ static int domain_qualifier_to_domid(struct libxl_ctx *ctx, char *p, uint32_t *d
}
}
if (i == 0)
return -1;
if (alldigit) {
if (i > 0 && alldigit) {
*domid = strtoul(p, NULL, 10);
return 0;
} else {
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.