From: anthony.perard@citrix.com
To: Xen Devel <xen-devel@lists.xensource.com>
Cc: anthony.perard@citrix.com
Subject: [PATCH V2 1/2] libxl: Factorize function libxl_device_disk_list
Date: Thu, 6 Jan 2011 17:50:37 +0000 [thread overview]
Message-ID: <1294336238-29822-1-git-send-email-anthony.perard@citrix.com> (raw)
In-Reply-To: <19749.53779.853334.446731@mariner.uk.xensource.com>
From: Anthony PERARD <anthony.perard@citrix.com>
This patch adds function libxl_append_disk_list_of_type to get disks
parameter of one backend type.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
tools/libxl/libxl.c | 99 ++++++++++++++++++++++++++-------------------------
1 files changed, 50 insertions(+), 49 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 10d4527..79ad06c 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2518,61 +2518,62 @@ int libxl_device_vkb_hard_shutdown(libxl_ctx *ctx, uint32_t domid)
return ERROR_NI;
}
-libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
+static unsigned int libxl_append_disk_list_of_type(libxl_ctx *ctx,
+ uint32_t domid,
+ const char *type,
+ libxl_device_disk **disks,
+ unsigned int *ndisks)
{
libxl__gc gc = LIBXL_INIT_GC(ctx);
- char *be_path_tap, *be_path_vbd;
- libxl_device_disk *dend, *disks, *ret = NULL;
- char **b, **l = NULL;
- unsigned int numl, len;
- char *type;
-
- be_path_vbd = libxl__sprintf(&gc, "%s/backend/vbd/%d", libxl__xs_get_dompath(&gc, 0), domid);
- be_path_tap = libxl__sprintf(&gc, "%s/backend/tap/%d", libxl__xs_get_dompath(&gc, 0), domid);
-
- b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_vbd, &numl);
- if (l) {
- ret = realloc(ret, sizeof(libxl_device_disk) * numl);
- disks = ret;
- *num = numl;
- dend = ret + *num;
- for (; disks < dend; ++disks, ++l) {
- disks->backend_domid = 0;
- disks->domid = domid;
- disks->physpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/params", be_path_vbd, *l), &len);
- libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/type", be_path_vbd, *l)), &(disks->phystype));
- disks->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/dev", be_path_vbd, *l), &len);
- disks->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/removable", be_path_vbd, *l)));
- if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/mode", be_path_vbd, *l)), "w"))
- disks->readwrite = 1;
- else
- disks->readwrite = 0;
- type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/frontend", be_path_vbd, *l))));
- disks->is_cdrom = !strcmp(type, "cdrom");
- }
- }
- b = l = libxl__xs_directory(&gc, XBT_NULL, be_path_tap, &numl);
- if (l) {
- ret = realloc(ret, sizeof(libxl_device_disk) * (*num + numl));
- disks = ret + *num;
- *num += numl;
- for (dend = ret + *num; disks < dend; ++disks, ++l) {
- disks->backend_domid = 0;
- disks->domid = domid;
- disks->physpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/params", be_path_tap, *l), &len);
- libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/type", be_path_tap, *l)), &(disks->phystype));
- disks->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/dev", be_path_tap, *l), &len);
- disks->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/removable", be_path_tap, *l)));
- if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/mode", be_path_tap, *l)), "w"))
- disks->readwrite = 1;
+ char *be_path = NULL;
+ char **dir = NULL;
+ unsigned int n = 0, len = 0;
+ libxl_device_disk *pdisk = NULL, *pdisk_end = NULL;
+ char *physpath_tmp = NULL;
+
+ be_path = libxl__sprintf(&gc, "%s/backend/%s/%d",
+ libxl__xs_get_dompath(&gc, 0), type, domid);
+ dir = libxl__xs_directory(&gc, XBT_NULL, be_path, &n);
+ if (dir) {
+ *disks = realloc(*disks, sizeof (libxl_device_disk) * (*ndisks + n));
+ pdisk = *disks + *ndisks;
+ *ndisks += n;
+ pdisk_end = *disks + *ndisks;
+ for (; pdisk < pdisk_end; pdisk++, dir++) {
+ pdisk->backend_domid = 0;
+ pdisk->domid = domid;
+ physpath_tmp = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/params", be_path, *dir), &len);
+ if (strchr(physpath_tmp, ':')) {
+ pdisk->physpath = strdup(strchr(physpath_tmp, ':') + 1);
+ free(physpath_tmp);
+ } else {
+ pdisk->physpath = physpath_tmp;
+ }
+ libxl_string_to_phystype(ctx, libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/type", be_path, *dir)), &(pdisk->phystype));
+ pdisk->virtpath = xs_read(ctx->xsh, XBT_NULL, libxl__sprintf(&gc, "%s/%s/dev", be_path, *dir), &len);
+ pdisk->unpluggable = atoi(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/removable", be_path, *dir)));
+ if (!strcmp(libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/mode", be_path, *dir)), "w"))
+ pdisk->readwrite = 1;
else
- disks->readwrite = 0;
- type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/frontend", be_path_tap, *l))));
- disks->is_cdrom = !strcmp(type, "cdrom");
+ pdisk->readwrite = 0;
+ type = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/device-type", libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/%s/frontend", be_path, *dir))));
+ pdisk->is_cdrom = !strcmp(type, "cdrom");
}
}
+
libxl__free_all(&gc);
- return ret;
+ return n;
+}
+
+libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num)
+{
+ libxl_device_disk *disks = NULL;
+ unsigned int ndisks = 0;
+
+ *num = libxl_append_disk_list_of_type(ctx, domid, "vbd", &disks, &ndisks);
+ *num += libxl_append_disk_list_of_type(ctx, domid, "tap", &disks, &ndisks);
+
+ return disks;
}
int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
--
1.7.1
next prev parent reply other threads:[~2011-01-06 17:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-16 14:16 [PATCH] libxl: Specify the target ram size to Qemu (new) when calling it anthony.perard
2010-12-16 14:16 ` [PATCH] libxl: Lists qdisk device in libxl_device_disk_list anthony.perard
2011-01-06 14:30 ` Ian Jackson
2011-01-06 17:50 ` anthony.perard [this message]
2011-01-06 18:04 ` [PATCH V2 1/2] libxl: Factorize function libxl_device_disk_list Ian Jackson
2011-01-06 17:50 ` [PATCH V2 2/2] libxl: Lists qdisk device in libxl_device_disk_list anthony.perard
2011-01-06 18:05 ` Ian Jackson
2011-01-06 14:28 ` [PATCH] libxl: Specify the target ram size to Qemu (new) when calling it Ian Jackson
2011-01-06 14:35 ` Keir Fraser
2011-01-06 15:12 ` Anthony PERARD
2011-01-06 15:46 ` Ian Jackson
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=1294336238-29822-1-git-send-email-anthony.perard@citrix.com \
--to=anthony.perard@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).