xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xen.org
Cc: Juergen Gross <jgross@suse.com>,
	wei.liu2@citrix.com, andrew.cooper3@citrix.com,
	ian.jackson@eu.citrix.com, david.vrabel@citrix.com,
	jbeulich@suse.com
Subject: [PATCH 2/2] xenstore: support XS_DIRECTORY_PART in libxenstore
Date: Tue, 25 Oct 2016 07:52:41 +0200	[thread overview]
Message-ID: <1477374761-25962-3-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1477374761-25962-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 | 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@lists.xen.org
https://lists.xen.org/xen-devel

      parent reply	other threads:[~2016-10-25  5:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-25  5:52 [PATCH 0/2] xenstore: support reading directory with many children Juergen Gross
2016-10-25  5:52 ` [PATCH 1/2] xenstore: add support for " Juergen Gross
2016-10-25  9:06   ` Jan Beulich
     [not found]   ` <580F3CC902000078001195F3@suse.com>
2016-10-25 11:41     ` Juergen Gross
2016-10-25 13:20       ` Jan Beulich
     [not found]       ` <580F785502000078001197C7@suse.com>
2016-10-25 13:47         ` Juergen Gross
2016-10-25 14:02           ` Jan Beulich
     [not found]           ` <580F820E0200007800119823@suse.com>
2016-10-25 14:48             ` Juergen Gross
2016-10-25  5:52 ` Juergen Gross [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=1477374761-25962-3-git-send-email-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=david.vrabel@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --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).