From: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
Subject: [PATCH 5/5] fix name to domid conversion.
Date: Wed, 13 Jan 2010 16:14:55 +0000 [thread overview]
Message-ID: <1263399295-19453-6-git-send-email-vincent.hanquez@eu.citrix.com> (raw)
In-Reply-To: <1263399295-19453-1-git-send-email-vincent.hanquez@eu.citrix.com>
[-- Attachment #1: Type: text/plain, Size: 349 bytes --]
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>
---
tools/libxl/libxl_utils.c | 33 +++++++++++----------------------
tools/libxl/xl.c | 4 +---
2 files changed, 12 insertions(+), 25 deletions(-)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0005-fix-name-to-domid-conversion.patch --]
[-- Type: text/x-patch; name="0005-fix-name-to-domid-conversion.patch", Size: 2124 bytes --]
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 36c1c47..eca4347 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -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);
-
- 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;
- }
- }
+ if (!dominfo)
+ return ERROR_NOMEM;
+
+ 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;
}
diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c
index 90896f3..1e95ac5 100644
--- a/tools/libxl/xl.c
+++ b/tools/libxl/xl.c
@@ -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 {
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
prev parent reply other threads:[~2010-01-13 16:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-13 16:14 [PATCH 0/5] more solidification work Vincent Hanquez
2010-01-13 16:14 ` [PATCH 1/5] add some return values testing in stubdom Vincent Hanquez
2010-01-13 16:14 ` [PATCH 2/5] initialize enum to 1, to prevent defaulting to the 0 values when structure when not properly initialized by the client Vincent Hanquez
2010-01-13 16:14 ` [PATCH 3/5] add fuse around generic_device_add related to invalid kinds Vincent Hanquez
2010-01-13 16:14 ` [PATCH 4/5] add error in disk_add if phystype is not recognized Vincent Hanquez
2010-01-13 16:14 ` Vincent Hanquez [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1263399295-19453-6-git-send-email-vincent.hanquez@eu.citrix.com \
--to=vincent.hanquez@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).