forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
patch-0006-xenstore-support-XS_DIRECTORY_PART-in-libxenstore.patch
119 lines (111 loc) · 3.13 KB
/
patch-0006-xenstore-support-XS_DIRECTORY_PART-in-libxenstore.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
From 8757f7bd268d6323dceed3040c5bc6d34340aae2 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Mon, 5 Dec 2016 08:48:47 +0100
Subject: [PATCH 06/25] 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@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.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 d1e01babb6a5..40e32750dad3 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.25.4