From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xen.org
Cc: Juergen Gross <jgross@suse.com>,
sstabellini@kernel.org, wei.liu2@citrix.com,
George.Dunlap@eu.citrix.com, andrew.cooper3@citrix.com,
ian.jackson@eu.citrix.com, tim@xen.org, jbeulich@suse.com
Subject: [PATCH v3 06/12] xenstore: support XS_DIRECTORY_PART in libxenstore
Date: Fri, 11 Nov 2016 09:00:04 +0100 [thread overview]
Message-ID: <1478851210-6251-7-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1478851210-6251-1-git-send-email-jgross@suse.com>
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@suse.com>
---
tools/xenstore/xs.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 72 insertions(+), 8 deletions(-)
diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index d1e01ba..40e3275 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,75 @@ 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)
+{
+ unsigned int off, result_len;
+ char gen[24], offstr[8];
+ struct iovec iovec[2];
+ char *result = NULL, *strings = NULL;
+
+ gen[0] = 0;
+ iovec[0].iov_base = (void *)path;
+ iovec[0].iov_len = strlen(path) + 1;
+
+ for (off = 0;;) {
+ snprintf(offstr, sizeof(offstr), "%u", off);
+ iovec[1].iov_base = (void *)offstr;
+ iovec[1].iov_len = strlen(offstr) + 1;
+ result = xs_talkv(h, t, XS_DIRECTORY_PART, iovec, 2,
+ &result_len);
+
+ /* If XS_DIRECTORY_PART isn't supported return E2BIG. */
+ if (!result) {
+ if (errno == ENOSYS)
+ errno = E2BIG;
+ return NULL;
+ }
+
+ if (off) {
+ if (strcmp(gen, result)) {
+ free(result);
+ free(strings);
+ strings = NULL;
+ off = 0;
+ continue;
+ }
+ } else
+ strncpy(gen, result, sizeof(gen));
+
+ result_len -= strlen(result) + 1;
+ strings = realloc(strings, off + result_len);
+ memcpy(strings + off, result + strlen(result) + 1, result_len);
+ free(result);
+ off += result_len;
+
+ if (off <= 1 || strings[off - 2] == 0)
+ break;
+ }
+
+ if (off > 1)
+ off--;
+
+ return xs_directory_common(strings, off, 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@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-11-11 8:00 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-11 7:59 [PATCH v3 00/12] xenstore: support reading directory with many children Juergen Gross
2016-11-11 7:59 ` [PATCH v3 01/12] xenstore: modify add_change_node() parameter types Juergen Gross
2016-11-12 15:09 ` Wei Liu
2016-11-11 8:00 ` [PATCH v3 02/12] xenstore: call add_change_node() directly when writing node Juergen Gross
2016-11-12 15:10 ` Wei Liu
2016-11-13 10:50 ` Juergen Gross
2016-11-14 8:46 ` Wei Liu
2016-11-11 8:00 ` [PATCH v3 03/12] xenstore: use common tdb record header in xenstore Juergen Gross
2016-11-12 15:10 ` Wei Liu
2016-11-11 8:00 ` [PATCH v3 04/12] xenstore: add per-node generation counter Juergen Gross
2016-11-12 15:10 ` Wei Liu
2016-11-11 8:00 ` [PATCH v3 05/12] xenstore: add support for reading directory with many children Juergen Gross
2016-11-11 10:09 ` Jan Beulich
[not found] ` <5825A6D6020000780011DEA4@suse.com>
2016-11-11 10:43 ` Juergen Gross
2016-11-11 11:12 ` Jan Beulich
[not found] ` <5825B59B020000780011DF28@suse.com>
2016-11-11 11:15 ` Juergen Gross
2016-11-12 15:11 ` Wei Liu
2016-11-11 8:00 ` Juergen Gross [this message]
2016-11-12 15:11 ` [PATCH v3 06/12] xenstore: support XS_DIRECTORY_PART in libxenstore Wei Liu
2016-11-11 8:00 ` [PATCH v3 07/12] xenstore: use array for xenstore wire command handling Juergen Gross
2016-11-12 15:11 ` Wei Liu
2016-11-11 8:00 ` [PATCH v3 08/12] xenstore: let command functions return error or success Juergen Gross
2016-11-12 15:11 ` Wei Liu
2016-11-13 11:05 ` Juergen Gross
2016-11-11 8:00 ` [PATCH v3 09/12] xenstore: make functions static Juergen Gross
2016-11-11 13:02 ` Andrew Cooper
2016-11-11 13:19 ` Juergen Gross
2016-11-11 8:00 ` [PATCH v3 10/12] xenstore: add helper functions for wire argument parsing Juergen Gross
2016-11-12 15:11 ` Wei Liu
2016-11-11 8:00 ` [PATCH v3 11/12] xenstore: add small default data buffer to internal struct Juergen Gross
2016-11-12 15:11 ` Wei Liu
2016-11-11 8:00 ` [PATCH v3 12/12] xenstore: handle memory allocation failures in xenstored Juergen Gross
2016-11-11 11:07 ` Juergen Gross
2016-11-12 15:11 ` Wei Liu
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=1478851210-6251-7-git-send-email-jgross@suse.com \
--to=jgross@suse.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/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).