forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
patch-0007-xenstore-use-array-for-xenstore-wire-command-handlin.patch
232 lines (218 loc) · 6.76 KB
/
patch-0007-xenstore-use-array-for-xenstore-wire-command-handlin.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
From 61e6fc1f816b78a52ac1b2a00d5a2c5f7a5920c4 Mon Sep 17 00:00:00 2001
From: Juergen Gross <jgross@suse.com>
Date: Mon, 5 Dec 2016 08:48:48 +0100
Subject: [PATCH 07/25] xenstore: use array for xenstore wire command handling
Instead of switch() statements for selecting wire command actions use
an array for this purpose.
While doing this add the XS_RESTRICT type for diagnostic prints and
correct the printed string for XS_IS_DOMAIN_INTRODUCED.
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/xenstore/xenstored_core.c | 158 +++++++++-----------------------
xen/include/public/io/xs_wire.h | 2 +
2 files changed, 46 insertions(+), 114 deletions(-)
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index fad786c1355f..aef72f37c48a 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -86,6 +86,7 @@ static bool trigger_talloc_report = false;
static void corrupt(struct connection *conn, const char *fmt, ...);
static void check_store(void);
+static const char *sockmsg_string(enum xsd_sockmsg_type type);
#define log(...) \
do { \
@@ -124,36 +125,6 @@ bool replace_tdb(const char *newname, TDB_CONTEXT *newtdb)
return true;
}
-static char *sockmsg_string(enum xsd_sockmsg_type type)
-{
- switch (type) {
- case XS_DEBUG: return "DEBUG";
- case XS_DIRECTORY: return "DIRECTORY";
- case XS_READ: return "READ";
- case XS_GET_PERMS: return "GET_PERMS";
- case XS_WATCH: return "WATCH";
- case XS_UNWATCH: return "UNWATCH";
- case XS_TRANSACTION_START: return "TRANSACTION_START";
- case XS_TRANSACTION_END: return "TRANSACTION_END";
- case XS_INTRODUCE: return "INTRODUCE";
- case XS_RELEASE: return "RELEASE";
- case XS_GET_DOMAIN_PATH: return "GET_DOMAIN_PATH";
- case XS_WRITE: return "WRITE";
- case XS_MKDIR: return "MKDIR";
- case XS_RM: return "RM";
- case XS_SET_PERMS: return "SET_PERMS";
- case XS_WATCH_EVENT: return "WATCH_EVENT";
- case XS_ERROR: return "ERROR";
- case XS_IS_DOMAIN_INTRODUCED: return "XS_IS_DOMAIN_INTRODUCED";
- case XS_RESUME: return "RESUME";
- case XS_SET_TARGET: return "SET_TARGET";
- case XS_RESET_WATCHES: return "RESET_WATCHES";
- case XS_DIRECTORY_PART: return "DIRECTORY_PART";
- default:
- return "**UNKNOWN**";
- }
-}
-
void trace(const char *fmt, ...)
{
va_list arglist;
@@ -1313,12 +1284,51 @@ static void do_debug(struct connection *conn, struct buffered_data *in)
send_ack(conn, XS_DEBUG);
}
+static struct {
+ const char *str;
+ void (*func)(struct connection *conn, struct buffered_data *in);
+} const wire_funcs[XS_TYPE_COUNT] = {
+ [XS_DEBUG] = { "DEBUG", do_debug },
+ [XS_DIRECTORY] = { "DIRECTORY", send_directory },
+ [XS_READ] = { "READ", do_read },
+ [XS_GET_PERMS] = { "GET_PERMS", do_get_perms },
+ [XS_WATCH] = { "WATCH", do_watch },
+ [XS_UNWATCH] = { "UNWATCH", do_unwatch },
+ [XS_TRANSACTION_START] = { "TRANSACTION_START", do_transaction_start },
+ [XS_TRANSACTION_END] = { "TRANSACTION_END", do_transaction_end },
+ [XS_INTRODUCE] = { "INTRODUCE", do_introduce },
+ [XS_RELEASE] = { "RELEASE", do_release },
+ [XS_GET_DOMAIN_PATH] = { "GET_DOMAIN_PATH", do_get_domain_path },
+ [XS_WRITE] = { "WRITE", do_write },
+ [XS_MKDIR] = { "MKDIR", do_mkdir },
+ [XS_RM] = { "RM", do_rm },
+ [XS_SET_PERMS] = { "SET_PERMS", do_set_perms },
+ [XS_WATCH_EVENT] = { "WATCH_EVENT", NULL },
+ [XS_ERROR] = { "ERROR", NULL },
+ [XS_IS_DOMAIN_INTRODUCED] =
+ { "IS_DOMAIN_INTRODUCED", do_is_domain_introduced },
+ [XS_RESUME] = { "RESUME", do_resume },
+ [XS_SET_TARGET] = { "SET_TARGET", do_set_target },
+ [XS_RESTRICT] = { "RESTRICT", NULL },
+ [XS_RESET_WATCHES] = { "RESET_WATCHES", do_reset_watches },
+ [XS_DIRECTORY_PART] = { "DIRECTORY_PART", send_directory_part },
+};
+
+static const char *sockmsg_string(enum xsd_sockmsg_type type)
+{
+ if ((unsigned)type < XS_TYPE_COUNT && wire_funcs[type].str)
+ return wire_funcs[type].str;
+
+ return "**UNKNOWN**";
+}
+
/* Process "in" for conn: "in" will vanish after this conversation, so
* we can talloc off it for temporary variables. May free "conn".
*/
static void process_message(struct connection *conn, struct buffered_data *in)
{
struct transaction *trans;
+ enum xsd_sockmsg_type type = in->hdr.msg.type;
trans = transaction_lookup(conn, in->hdr.msg.tx_id);
if (IS_ERR(trans)) {
@@ -1329,91 +1339,11 @@ static void process_message(struct connection *conn, struct buffered_data *in)
assert(conn->transaction == NULL);
conn->transaction = trans;
- switch (in->hdr.msg.type) {
- case XS_DIRECTORY:
- send_directory(conn, in);
- break;
-
- case XS_READ:
- do_read(conn, in);
- break;
-
- case XS_WRITE:
- do_write(conn, in);
- break;
-
- case XS_MKDIR:
- do_mkdir(conn, in);
- break;
-
- case XS_RM:
- do_rm(conn, in);
- break;
-
- case XS_GET_PERMS:
- do_get_perms(conn, in);
- break;
-
- case XS_SET_PERMS:
- do_set_perms(conn, in);
- break;
-
- case XS_DEBUG:
- do_debug(conn, in);
- break;
-
- case XS_WATCH:
- do_watch(conn, in);
- break;
-
- case XS_UNWATCH:
- do_unwatch(conn, in);
- break;
-
- case XS_TRANSACTION_START:
- do_transaction_start(conn, in);
- break;
-
- case XS_TRANSACTION_END:
- do_transaction_end(conn, in);
- break;
-
- case XS_INTRODUCE:
- do_introduce(conn, in);
- break;
-
- case XS_IS_DOMAIN_INTRODUCED:
- do_is_domain_introduced(conn, in);
- break;
-
- case XS_RELEASE:
- do_release(conn, in);
- break;
-
- case XS_GET_DOMAIN_PATH:
- do_get_domain_path(conn, in);
- break;
-
- case XS_RESUME:
- do_resume(conn, in);
- break;
-
- case XS_SET_TARGET:
- do_set_target(conn, in);
- break;
-
- case XS_RESET_WATCHES:
- do_reset_watches(conn, in);
- break;
-
- case XS_DIRECTORY_PART:
- send_directory_part(conn, in);
- break;
-
- default:
- eprintf("Client unknown operation %i", in->hdr.msg.type);
+ if ((unsigned)type < XS_TYPE_COUNT && wire_funcs[type].func)
+ wire_funcs[type].func(conn, in);
+ else {
+ eprintf("Client unknown operation %i", type);
send_error(conn, ENOSYS);
- break;
}
conn->transaction = NULL;
diff --git a/xen/include/public/io/xs_wire.h b/xen/include/public/io/xs_wire.h
index 545f916b9cd1..54c1d71c8573 100644
--- a/xen/include/public/io/xs_wire.h
+++ b/xen/include/public/io/xs_wire.h
@@ -52,6 +52,8 @@ enum xsd_sockmsg_type
XS_RESET_WATCHES,
XS_DIRECTORY_PART,
+ XS_TYPE_COUNT, /* Number of valid types. */
+
XS_INVALID = 0xffff /* Guaranteed to remain an invalid type */
};
--
2.25.4