|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2/2] xenstore: support XS_DIRECTORY_PART in libxenstore
This will enable all users of libxenstore to handle xenstore nodes
with a huge amount of children.
In order to not depend completely on the XS_DIRECTORY_PART
functionality use it only in case of E2BIG returned by XS_DIRECTORY.
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
tools/xenstore/xs.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 66 insertions(+), 8 deletions(-)
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index d1e01ba..e64ded8 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -558,15 +558,10 @@ static bool xs_bool(char *reply)
return true;
}
-char **xs_directory(struct xs_handle *h, xs_transaction_t t,
- const char *path, unsigned int *num)
+static char **xs_directory_common(char *strings, unsigned int len,
+ unsigned int *num)
{
- char *strings, *p, **ret;
- unsigned int len;
-
- strings = xs_single(h, t, XS_DIRECTORY, path, &len);
- if (!strings)
- return NULL;
+ char *p, **ret;
/* Count the strings. */
*num = xs_count_strings(strings, len);
@@ -586,6 +581,69 @@ char **xs_directory(struct xs_handle *h, xs_transaction_t
t,
return ret;
}
+static char **xs_directory_part(struct xs_handle *h, xs_transaction_t t,
+ const char *path, unsigned int *num)
+{
+ char *strings, *p, **ret;
+ unsigned int len, p_len;
+ int saved_errno;
+
+ if (t == XBT_NULL) {
+ for (;;) {
+ t = xs_transaction_start(h);
+ if (t == XBT_NULL)
+ return NULL;
+
+ ret = xs_directory_part(h, t, path, num);
+ saved_errno = errno;
+
+ if (xs_transaction_end(h, t, false) || ret == NULL) {
+ errno = saved_errno;
+ return ret;
+ }
+
+ free(ret);
+ }
+ }
+
+ strings = xs_single(h, t, XS_DIRECTORY_PART, path, &len);
+ if (!strings) {
+ /* If XS_DIRECTORY_PART is not supported return E2BIG. */
+ if (errno == ENOSYS)
+ errno = E2BIG;
+ return NULL;
+ }
+
+ while (len > 1 && strings[len - 2] != 0) {
+ p = xs_single(h, t, XS_DIRECTORY_PART, "@", &p_len);
+ if (!p) {
+ free_no_errno(strings);
+ return NULL;
+ }
+ strings = realloc(strings, len + p_len);
+ memcpy(strings + len, p, p_len);
+ len += p_len;
+ }
+
+ return xs_directory_common(strings, len - 1, num);
+}
+
+char **xs_directory(struct xs_handle *h, xs_transaction_t t,
+ const char *path, unsigned int *num)
+{
+ char *strings;
+ unsigned int len;
+
+ strings = xs_single(h, t, XS_DIRECTORY, path, &len);
+ if (!strings) {
+ if (errno != E2BIG)
+ return NULL;
+ return xs_directory_part(h, t, path, num);
+ }
+
+ return xs_directory_common(strings, len, num);
+}
+
/* Get the value of a single file, nul terminated.
* Returns a malloced value: call free() on it after use.
* len indicates length in bytes, not including the nul.
--
2.6.6
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |