forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch-0008-xenstore-let-command-functions-return-error-or-succe.patch
1044 lines (895 loc) · 27.1 KB
/
patch-0008-xenstore-let-command-functions-return-error-or-succe.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From ea13030de9bfb18a54c2d73d3f1c2e5b6f499d43 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 5 Dec 2016 08:48:49 +0100
Subject: [PATCH 08/25] xenstore: let command functions return error or success
Add a return value to all wire command functions of xenstored. If such
a function returns an error send the error message in
process_message().
Only code refactoring, no change in behavior expected.
Signed-off-by: Juergen Gross <[email protected]>
Acked-by: Wei Liu <[email protected]>
Signed-off-by: Wei Liu <[email protected]>
---
tools/xenstore/xenstored_core.c | 215 +++++++++++--------------
tools/xenstore/xenstored_domain.c | 170 ++++++++-----------
tools/xenstore/xenstored_domain.h | 14 +-
tools/xenstore/xenstored_transaction.c | 50 +++---
tools/xenstore/xenstored_transaction.h | 4 +-
tools/xenstore/xenstored_watch.c | 46 +++---
tools/xenstore/xenstored_watch.h | 4 +-
7 files changed, 213 insertions(+), 290 deletions(-)
diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index aef72f37c48a..f7760cc8fe1e 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -775,33 +775,31 @@ bool check_event_node(const char *node)
return true;
}
-static void send_directory(struct connection *conn, struct buffered_data *in)
+static int send_directory(struct connection *conn, struct buffered_data *in)
{
struct node *node;
const char *name = onearg(in);
name = canonicalize(conn, name);
node = get_node(conn, in, name, XS_PERM_READ);
- if (!node) {
- send_error(conn, errno);
- return;
- }
+ if (!node)
+ return errno;
send_reply(conn, XS_DIRECTORY, node->children, node->childlen);
+
+ return 0;
}
-static void send_directory_part(struct connection *conn,
- struct buffered_data *in)
+static int send_directory_part(struct connection *conn,
+ struct buffered_data *in)
{
unsigned int off, len, maxlen, genlen;
char *name, *child, *data;
struct node *node;
char gen[24];
- if (xs_count_strings(in->buffer, in->used) != 2) {
- send_error(conn, EINVAL);
- return;
- }
+ if (xs_count_strings(in->buffer, in->used) != 2)
+ return EINVAL;
/* First arg is node name. */
name = canonicalize(conn, in->buffer);
@@ -810,10 +808,8 @@ static void send_directory_part(struct connection *conn,
off = atoi(in->buffer + strlen(in->buffer) + 1);
node = get_node(conn, in, name, XS_PERM_READ);
- if (!node) {
- send_error(conn, errno);
- return;
- }
+ if (!node)
+ return errno;
genlen = snprintf(gen, sizeof(gen), "%"PRIu64, node->generation) + 1;
@@ -821,7 +817,7 @@ static void send_directory_part(struct connection *conn,
if (off >= node->childlen) {
gen[genlen] = 0;
send_reply(conn, XS_DIRECTORY_PART, gen, genlen + 1);
- return;
+ return 0;
}
len = 0;
@@ -836,10 +832,8 @@ static void send_directory_part(struct connection *conn,
}
data = talloc_array(in, char, genlen + len + 1);
- if (!data) {
- send_error(conn, ENOMEM);
- return;
- }
+ if (!data)
+ return ENOMEM;
memcpy(data, gen, genlen);
memcpy(data + genlen, node->children + off, len);
@@ -849,21 +843,23 @@ static void send_directory_part(struct connection *conn,
}
send_reply(conn, XS_DIRECTORY_PART, data, genlen + len);
+
+ return 0;
}
-static void do_read(struct connection *conn, struct buffered_data *in)
+static int do_read(struct connection *conn, struct buffered_data *in)
{
struct node *node;
const char *name = onearg(in);
name = canonicalize(conn, name);
node = get_node(conn, in, name, XS_PERM_READ);
- if (!node) {
- send_error(conn, errno);
- return;
- }
+ if (!node)
+ return errno;
send_reply(conn, XS_READ, node->data, node->datalen);
+
+ return 0;
}
static void delete_node_single(struct connection *conn, struct node *node,
@@ -982,7 +978,7 @@ static struct node *create_node(struct connection *conn,
}
/* path, data... */
-static void do_write(struct connection *conn, struct buffered_data *in)
+static int do_write(struct connection *conn, struct buffered_data *in)
{
unsigned int offset, datalen;
struct node *node;
@@ -990,10 +986,8 @@ static void do_write(struct connection *conn, struct buffered_data *in)
char *name;
/* Extra "strings" can be created by binary data. */
- if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) {
- send_error(conn, EINVAL);
- return;
- }
+ if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
+ return EINVAL;
offset = strlen(vec[0]) + 1;
datalen = in->used - offset;
@@ -1002,39 +996,32 @@ static void do_write(struct connection *conn, struct buffered_data *in)
node = get_node(conn, in, name, XS_PERM_WRITE);
if (!node) {
/* No permissions, invalid input? */
- if (errno != ENOENT) {
- send_error(conn, errno);
- return;
- }
+ if (errno != ENOENT)
+ return errno;
node = create_node(conn, name, in->buffer + offset, datalen);
- if (!node) {
- send_error(conn, errno);
- return;
- }
+ if (!node)
+ return errno;
} else {
node->data = in->buffer + offset;
node->datalen = datalen;
- if (!write_node(conn, node)){
- send_error(conn, errno);
- return;
- }
+ if (!write_node(conn, node))
+ return errno;
}
wrl_apply_debit_direct(conn);
fire_watches(conn, in, name, false);
send_ack(conn, XS_WRITE);
+
+ return 0;
}
-static void do_mkdir(struct connection *conn, struct buffered_data *in)
+static int do_mkdir(struct connection *conn, struct buffered_data *in)
{
struct node *node;
const char *name = onearg(in);
- if (!name) {
- errno = EINVAL;
- send_error(conn, errno);
- return;
- }
+ if (!name)
+ return EINVAL;
name = canonicalize(conn, name);
node = get_node(conn, in, name, XS_PERM_WRITE);
@@ -1042,19 +1029,17 @@ static void do_mkdir(struct connection *conn, struct buffered_data *in)
/* If it already exists, fine. */
if (!node) {
/* No permissions? */
- if (errno != ENOENT) {
- send_error(conn, errno);
- return;
- }
+ if (errno != ENOENT)
+ return errno;
node = create_node(conn, name, NULL, 0);
- if (!node) {
- send_error(conn, errno);
- return;
- }
+ if (!node)
+ return errno;
wrl_apply_debit_direct(conn);
fire_watches(conn, in, name, false);
}
send_ack(conn, XS_MKDIR);
+
+ return 0;
}
static void delete_node(struct connection *conn, struct node *node,
@@ -1124,18 +1109,14 @@ static int _rm(struct connection *conn, struct node *node, const char *name)
happen is the child will continue to take up space, but will
otherwise be unreachable. */
struct node *parent = read_node(conn, name, get_parent(name, name));
- if (!parent) {
- send_error(conn, EINVAL);
- return 0;
- }
+ if (!parent)
+ return EINVAL;
- if (!delete_child(conn, parent, basename(name))) {
- send_error(conn, EINVAL);
- return 0;
- }
+ if (!delete_child(conn, parent, basename(name)))
+ return EINVAL;
delete_node(conn, node, true);
- return 1;
+ return 0;
}
@@ -1150,9 +1131,10 @@ static void internal_rm(const char *name)
}
-static void do_rm(struct connection *conn, struct buffered_data *in)
+static int do_rm(struct connection *conn, struct buffered_data *in)
{
struct node *node;
+ int ret;
const char *name = onearg(in);
name = canonicalize(conn, name);
@@ -1163,29 +1145,30 @@ static void do_rm(struct connection *conn, struct buffered_data *in)
node = read_node(conn, in, get_parent(in, name));
if (node) {
send_ack(conn, XS_RM);
- return;
+ return 0;
}
/* Restore errno, just in case. */
errno = ENOENT;
}
- send_error(conn, errno);
- return;
+ return errno;
}
- if (streq(name, "/")) {
- send_error(conn, EINVAL);
- return;
- }
+ if (streq(name, "/"))
+ return EINVAL;
- if (_rm(conn, node, name)) {
- wrl_apply_debit_direct(conn);
- fire_watches(conn, in, name, true);
- send_ack(conn, XS_RM);
- }
+ ret = _rm(conn, node, name);
+ if (ret)
+ return ret;
+
+ wrl_apply_debit_direct(conn);
+ fire_watches(conn, in, name, true);
+ send_ack(conn, XS_RM);
+
+ return 0;
}
-static void do_get_perms(struct connection *conn, struct buffered_data *in)
+static int do_get_perms(struct connection *conn, struct buffered_data *in)
{
struct node *node;
const char *name = onearg(in);
@@ -1194,19 +1177,19 @@ static void do_get_perms(struct connection *conn, struct buffered_data *in)
name = canonicalize(conn, name);
node = get_node(conn, in, name, XS_PERM_READ);
- if (!node) {
- send_error(conn, errno);
- return;
- }
+ if (!node)
+ return errno;
strings = perms_to_strings(node, node->perms, node->num_perms, &len);
if (!strings)
- send_error(conn, errno);
- else
- send_reply(conn, XS_GET_PERMS, strings, len);
+ return errno;
+
+ send_reply(conn, XS_GET_PERMS, strings, len);
+
+ return 0;
}
-static void do_set_perms(struct connection *conn, struct buffered_data *in)
+static int do_set_perms(struct connection *conn, struct buffered_data *in)
{
unsigned int num;
struct xs_permissions *perms;
@@ -1214,10 +1197,8 @@ static void do_set_perms(struct connection *conn, struct buffered_data *in)
struct node *node;
num = xs_count_strings(in->buffer, in->used);
- if (num < 2) {
- send_error(conn, EINVAL);
- return;
- }
+ if (num < 2)
+ return EINVAL;
/* First arg is node name. */
name = canonicalize(conn, in->buffer);
@@ -1226,55 +1207,44 @@ static void do_set_perms(struct connection *conn, struct buffered_data *in)
/* We must own node to do this (tools can do this too). */
node = get_node(conn, in, name, XS_PERM_WRITE|XS_PERM_OWNER);
- if (!node) {
- send_error(conn, errno);
- return;
- }
+ if (!node)
+ return errno;
perms = talloc_array(node, struct xs_permissions, num);
- if (!xs_strings_to_perms(perms, num, permstr)) {
- send_error(conn, errno);
- return;
- }
+ if (!xs_strings_to_perms(perms, num, permstr))
+ return errno;
/* Unprivileged domains may not change the owner. */
- if (domain_is_unprivileged(conn) &&
- perms[0].id != node->perms[0].id) {
- send_error(conn, EPERM);
- return;
- }
+ if (domain_is_unprivileged(conn) && perms[0].id != node->perms[0].id)
+ return EPERM;
domain_entry_dec(conn, node);
node->perms = perms;
node->num_perms = num;
domain_entry_inc(conn, node);
- if (!write_node(conn, node)) {
- send_error(conn, errno);
- return;
- }
+ if (!write_node(conn, node))
+ return errno;
wrl_apply_debit_direct(conn);
fire_watches(conn, in, name, false);
send_ack(conn, XS_SET_PERMS);
+
+ return 0;
}
-static void do_debug(struct connection *conn, struct buffered_data *in)
+static int do_debug(struct connection *conn, struct buffered_data *in)
{
int num;
- if (conn->id != 0) {
- send_error(conn, EACCES);
- return;
- }
+ if (conn->id != 0)
+ return EACCES;
num = xs_count_strings(in->buffer, in->used);
if (streq(in->buffer, "print")) {
- if (num < 2) {
- send_error(conn, EINVAL);
- return;
- }
+ if (num < 2)
+ return EINVAL;
xprintf("debug: %s", in->buffer + get_string(in, 0));
}
@@ -1282,11 +1252,13 @@ static void do_debug(struct connection *conn, struct buffered_data *in)
check_store();
send_ack(conn, XS_DEBUG);
+
+ return 0;
}
static struct {
const char *str;
- void (*func)(struct connection *conn, struct buffered_data *in);
+ int (*func)(struct connection *conn, struct buffered_data *in);
} const wire_funcs[XS_TYPE_COUNT] = {
[XS_DEBUG] = { "DEBUG", do_debug },
[XS_DIRECTORY] = { "DIRECTORY", send_directory },
@@ -1329,6 +1301,7 @@ static void process_message(struct connection *conn, struct buffered_data *in)
{
struct transaction *trans;
enum xsd_sockmsg_type type = in->hdr.msg.type;
+ int ret;
trans = transaction_lookup(conn, in->hdr.msg.tx_id);
if (IS_ERR(trans)) {
@@ -1340,11 +1313,13 @@ static void process_message(struct connection *conn, struct buffered_data *in)
conn->transaction = trans;
if ((unsigned)type < XS_TYPE_COUNT && wire_funcs[type].func)
- wire_funcs[type].func(conn, in);
+ ret = wire_funcs[type].func(conn, in);
else {
eprintf("Client unknown operation %i", type);
- send_error(conn, ENOSYS);
+ ret = ENOSYS;
}
+ if (ret)
+ send_error(conn, ret);
conn->transaction = NULL;
}
diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c
index 17a66be33929..3fc997fafed9 100644
--- a/tools/xenstore/xenstored_domain.c
+++ b/tools/xenstore/xenstored_domain.c
@@ -357,7 +357,7 @@ static void domain_conn_reset(struct domain *domain)
}
/* domid, mfn, evtchn, path */
-void do_introduce(struct connection *conn, struct buffered_data *in)
+int do_introduce(struct connection *conn, struct buffered_data *in)
{
struct domain *domain;
char *vec[3];
@@ -367,40 +367,32 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
int rc;
struct xenstore_domain_interface *interface;
- if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) {
- send_error(conn, EINVAL);
- return;
- }
+ if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
+ return EINVAL;
- if (domain_is_unprivileged(conn) || !conn->can_write) {
- send_error(conn, EACCES);
- return;
- }
+ if (domain_is_unprivileged(conn) || !conn->can_write)
+ return EACCES;
domid = atoi(vec[0]);
mfn = atol(vec[1]);
port = atoi(vec[2]);
/* Sanity check args. */
- if (port <= 0) {
- send_error(conn, EINVAL);
- return;
- }
+ if (port <= 0)
+ return EINVAL;
domain = find_domain_by_domid(domid);
if (domain == NULL) {
interface = map_interface(domid, mfn);
- if (!interface) {
- send_error(conn, errno);
- return;
- }
+ if (!interface)
+ return errno;
/* Hang domain off "in" until we're finished. */
domain = new_domain(in, domid, port);
if (!domain) {
+ rc = errno;
unmap_interface(interface);
- send_error(conn, errno);
- return;
+ return rc;
}
domain->interface = interface;
domain->mfn = mfn;
@@ -416,165 +408,137 @@ void do_introduce(struct connection *conn, struct buffered_data *in)
rc = xenevtchn_bind_interdomain(xce_handle, domid, port);
domain->port = (rc == -1) ? 0 : rc;
domain->remote_port = port;
- } else {
- send_error(conn, EINVAL);
- return;
- }
+ } else
+ return EINVAL;
domain_conn_reset(domain);
send_ack(conn, XS_INTRODUCE);
+
+ return 0;
}
-void do_set_target(struct connection *conn, struct buffered_data *in)
+int do_set_target(struct connection *conn, struct buffered_data *in)
{
char *vec[2];
unsigned int domid, tdomid;
struct domain *domain, *tdomain;
- if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) {
- send_error(conn, EINVAL);
- return;
- }
+ if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec))
+ return EINVAL;
- if (domain_is_unprivileged(conn) || !conn->can_write) {
- send_error(conn, EACCES);
- return;
- }
+ if (domain_is_unprivileged(conn) || !conn->can_write)
+ return EACCES;
domid = atoi(vec[0]);
tdomid = atoi(vec[1]);
domain = find_domain_by_domid(domid);
- if (!domain) {
- send_error(conn, ENOENT);
- return;
- }
- if (!domain->conn) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domain)
+ return ENOENT;
+ if (!domain->conn)
+ return EINVAL;
tdomain = find_domain_by_domid(tdomid);
- if (!tdomain) {
- send_error(conn, ENOENT);
- return;
- }
+ if (!tdomain)
+ return ENOENT;
- if (!tdomain->conn) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!tdomain->conn)
+ return EINVAL;
talloc_reference(domain->conn, tdomain->conn);
domain->conn->target = tdomain->conn;
send_ack(conn, XS_SET_TARGET);
+
+ return 0;
}
/* domid */
-void do_release(struct connection *conn, struct buffered_data *in)
+int do_release(struct connection *conn, struct buffered_data *in)
{
const char *domid_str = onearg(in);
struct domain *domain;
unsigned int domid;
- if (!domid_str) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domid_str)
+ return EINVAL;
domid = atoi(domid_str);
- if (!domid) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domid)
+ return EINVAL;
- if (domain_is_unprivileged(conn)) {
- send_error(conn, EACCES);
- return;
- }
+ if (domain_is_unprivileged(conn))
+ return EACCES;
domain = find_domain_by_domid(domid);
- if (!domain) {
- send_error(conn, ENOENT);
- return;
- }
+ if (!domain)
+ return ENOENT;
- if (!domain->conn) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domain->conn)
+ return EINVAL;
talloc_free(domain->conn);
send_ack(conn, XS_RELEASE);
+
+ return 0;
}
-void do_resume(struct connection *conn, struct buffered_data *in)
+int do_resume(struct connection *conn, struct buffered_data *in)
{
struct domain *domain;
unsigned int domid;
const char *domid_str = onearg(in);
- if (!domid_str) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domid_str)
+ return EINVAL;
domid = atoi(domid_str);
- if (!domid) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domid)
+ return EINVAL;
- if (domain_is_unprivileged(conn)) {
- send_error(conn, EACCES);
- return;
- }
+ if (domain_is_unprivileged(conn))
+ return EACCES;
domain = find_domain_by_domid(domid);
- if (!domain) {
- send_error(conn, ENOENT);
- return;
- }
+ if (!domain)
+ return ENOENT;
- if (!domain->conn) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domain->conn)
+ return EINVAL;
domain->shutdown = 0;
send_ack(conn, XS_RESUME);
+
+ return 0;
}
-void do_get_domain_path(struct connection *conn, struct buffered_data *in)
+int do_get_domain_path(struct connection *conn, struct buffered_data *in)
{
char *path;
const char *domid_str = onearg(in);
- if (!domid_str) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domid_str)
+ return EINVAL;
path = talloc_domain_path(conn, atoi(domid_str));
send_reply(conn, XS_GET_DOMAIN_PATH, path, strlen(path) + 1);
talloc_free(path);
+
+ return 0;
}
-void do_is_domain_introduced(struct connection *conn, struct buffered_data *in)
+int do_is_domain_introduced(struct connection *conn, struct buffered_data *in)
{
int result;
unsigned int domid;
const char *domid_str = onearg(in);
- if (!domid_str) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!domid_str)
+ return EINVAL;
domid = atoi(domid_str);
if (domid == DOMID_SELF)
@@ -583,15 +547,19 @@ void do_is_domain_introduced(struct connection *conn, struct buffered_data *in)
result = (find_domain_by_domid(domid) != NULL);
send_reply(conn, XS_IS_DOMAIN_INTRODUCED, result ? "T" : "F", 2);
+
+ return 0;
}
/* Allow guest to reset all watches */
-void do_reset_watches(struct connection *conn, struct buffered_data *in)
+int do_reset_watches(struct connection *conn, struct buffered_data *in)
{
conn_delete_all_watches(conn);
conn_delete_all_transactions(conn);
send_ack(conn, XS_RESET_WATCHES);
+
+ return 0;
}
static int close_xc_handle(void *_handle)
diff --git a/tools/xenstore/xenstored_domain.h b/tools/xenstore/xenstored_domain.h
index 561ab5daff3d..4aa80db2c92a 100644
--- a/tools/xenstore/xenstored_domain.h
+++ b/tools/xenstore/xenstored_domain.h
@@ -22,25 +22,25 @@
void handle_event(void);
/* domid, mfn, eventchn, path */
-void do_introduce(struct connection *conn, struct buffered_data *in);
+int do_introduce(struct connection *conn, struct buffered_data *in);
/* domid */
-void do_is_domain_introduced(struct connection *conn, struct buffered_data *in);
+int do_is_domain_introduced(struct connection *conn, struct buffered_data *in);
/* domid */
-void do_release(struct connection *conn, struct buffered_data *in);
+int do_release(struct connection *conn, struct buffered_data *in);
/* domid */
-void do_resume(struct connection *conn, struct buffered_data *in);
+int do_resume(struct connection *conn, struct buffered_data *in);
/* domid, target */
-void do_set_target(struct connection *conn, struct buffered_data *in);
+int do_set_target(struct connection *conn, struct buffered_data *in);
/* domid */
-void do_get_domain_path(struct connection *conn, struct buffered_data *in);
+int do_get_domain_path(struct connection *conn, struct buffered_data *in);
/* Allow guest to reset all watches */
-void do_reset_watches(struct connection *conn, struct buffered_data *in);
+int do_reset_watches(struct connection *conn, struct buffered_data *in);
void domain_init(void);
diff --git a/tools/xenstore/xenstored_transaction.c b/tools/xenstore/xenstored_transaction.c
index 3d1090197a48..9797fa501692 100644
--- a/tools/xenstore/xenstored_transaction.c
+++ b/tools/xenstore/xenstored_transaction.c
@@ -150,21 +150,17 @@ struct transaction *transaction_lookup(struct connection *conn, uint32_t id)
return ERR_PTR(-ENOENT);
}
-void do_transaction_start(struct connection *conn, struct buffered_data *in)
+int do_transaction_start(struct connection *conn, struct buffered_data *in)
{
struct transaction *trans, *exists;
char id_str[20];
/* We don't support nested transactions. */
- if (conn->transaction) {
- send_error(conn, EBUSY);
- return;
- }
+ if (conn->transaction)
+ return EBUSY;
- if (conn->id && conn->transaction_started > quota_max_transaction) {
- send_error(conn, ENOSPC);
- return;
- }
+ if (conn->id && conn->transaction_started > quota_max_transaction)
+ return ENOSPC;
/* Attach transaction to input for autofree until it's complete */
trans = talloc_zero(in, struct transaction);
@@ -174,10 +170,8 @@ void do_transaction_start(struct connection *conn, struct buffered_data *in)
trans->tdb_name = talloc_asprintf(trans, "%s.%p",
xs_daemon_tdb(), trans);
trans->tdb = tdb_copy(tdb_context(conn), trans->tdb_name);
- if (!trans->tdb) {
- send_error(conn, errno);
- return;
- }
+ if (!trans->tdb)
+ return errno;
/* Make it close if we go away. */
talloc_steal(trans, trans->tdb);
@@ -196,24 +190,22 @@ void do_transaction_start(struct connection *conn, struct buffered_data *in)
snprintf(id_str, sizeof(id_str), "%u", trans->id);
send_reply(conn, XS_TRANSACTION_START, id_str, strlen(id_str)+1);
+
+ return 0;
}
-void do_transaction_end(struct connection *conn, struct buffered_data *in)
+int do_transaction_end(struct connection *conn, struct buffered_data *in)
{
const char *arg = onearg(in);
struct changed_node *i;
struct changed_domain *d;
struct transaction *trans;
- if (!arg || (!streq(arg, "T") && !streq(arg, "F"))) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!arg || (!streq(arg, "T") && !streq(arg, "F")))
+ return EINVAL;
- if ((trans = conn->transaction) == NULL) {
- send_error(conn, ENOENT);
- return;
- }
+ if ((trans = conn->transaction) == NULL)
+ return ENOENT;
conn->transaction = NULL;
list_del(&trans->list);
@@ -224,17 +216,13 @@ void do_transaction_end(struct connection *conn, struct buffered_data *in)
if (streq(arg, "T")) {
/* FIXME: Merge, rather failing on any change. */
- if (trans->generation != generation) {
- send_error(conn, EAGAIN);
- return;
- }
+ if (trans->generation != generation)
+ return EAGAIN;
wrl_apply_debit_trans_commit(conn);
- if (!replace_tdb(trans->tdb_name, trans->tdb)) {
- send_error(conn, errno);
- return;
- }
+ if (!replace_tdb(trans->tdb_name, trans->tdb))
+ return errno;
/* Don't close this: we won! */
trans->tdb = NULL;
@@ -248,6 +236,8 @@ void do_transaction_end(struct connection *conn, struct buffered_data *in)
generation += trans->trans_gen;
}
send_ack(conn, XS_TRANSACTION_END);
+
+ return 0;
}
void transaction_entry_inc(struct transaction *trans, unsigned int domid)
diff --git a/tools/xenstore/xenstored_transaction.h b/tools/xenstore/xenstored_transaction.h
index 7f0a78179235..aeeac3dcedb4 100644
--- a/tools/xenstore/xenstored_transaction.h
+++ b/tools/xenstore/xenstored_transaction.h
@@ -21,8 +21,8 @@
struct transaction;
-void do_transaction_start(struct connection *conn, struct buffered_data *node);
-void do_transaction_end(struct connection *conn, struct buffered_data *in);
+int do_transaction_start(struct connection *conn, struct buffered_data *node);
+int do_transaction_end(struct connection *conn, struct buffered_data *in);
struct transaction *transaction_lookup(struct connection *conn, uint32_t id);
diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_watch.c
index 856750ebcd9b..8cfc5b088234 100644
--- a/tools/xenstore/xenstored_watch.c
+++ b/tools/xenstore/xenstored_watch.c
@@ -121,46 +121,36 @@ static int destroy_watch(void *_watch)
return 0;
}
-void do_watch(struct connection *conn, struct buffered_data *in)
+int do_watch(struct connection *conn, struct buffered_data *in)
{
struct watch *watch;
char *vec[2];
bool relative;
- if (get_strings(in, vec, ARRAY_SIZE(vec)) != ARRAY_SIZE(vec)) {
- send_error(conn, EINVAL);
- return;
- }
+ if (get_strings(in, vec, ARRAY_SIZE(vec)) != ARRAY_SIZE(vec))
+ return EINVAL;
if (strstarts(vec[0], "@")) {
relative = false;
- if (strlen(vec[0]) > XENSTORE_REL_PATH_MAX) {
- send_error(conn, EINVAL);
- return;
- }
+ if (strlen(vec[0]) > XENSTORE_REL_PATH_MAX)
+ return EINVAL;
/* check if valid event */
} else {
relative = !strstarts(vec[0], "/");
vec[0] = canonicalize(conn, vec[0]);
- if (!is_valid_nodename(vec[0])) {
- send_error(conn, EINVAL);
- return;
- }
+ if (!is_valid_nodename(vec[0]))
+ return EINVAL;
}
/* Check for duplicates. */
list_for_each_entry(watch, &conn->watches, list) {
if (streq(watch->node, vec[0]) &&
- streq(watch->token, vec[1])) {
- send_error(conn, EEXIST);
- return;
- }
+ streq(watch->token, vec[1]))
+ return EEXIST;
}
- if (domain_watch(conn) > quota_nb_watch_per_domain) {
- send_error(conn, E2BIG);
- return;
- }
+ if (domain_watch(conn) > quota_nb_watch_per_domain)
+ return E2BIG;
watch = talloc(conn, struct watch);
watch->node = talloc_strdup(watch, vec[0]);
@@ -180,17 +170,17 @@ void do_watch(struct connection *conn, struct buffered_data *in)
/* We fire once up front: simplifies clients and restart. */
add_event(conn, in, watch, watch->node);
+
+ return 0;
}
-void do_unwatch(struct connection *conn, struct buffered_data *in)
+int do_unwatch(struct connection *conn, struct buffered_data *in)