forked from MAYHEM-Lab/cspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwoofc.c
1276 lines (1140 loc) · 25.9 KB
/
woofc.c
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
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <time.h>
#include <sys/stat.h>
#include "log.h"
#include "woofc.h"
#include "woofc-access.h"
#include "woofc-cache.h"
extern char WooF_namespace[2048];
extern char WooF_dir[2048];
extern char WooF_namelog_dir[2048];
extern char Namelog_name[2048];
extern unsigned long Name_id;
extern LOG *Name_log;
extern char Host_ip[25];
void WooFDrop(WOOF *wf);
int WooFCreate(char *name,
unsigned long element_size,
unsigned long history_size)
{
WOOF_SHARED *wfs;
MIO *mio;
unsigned long space;
char local_name[4096];
char temp_name[4096];
char fname[1024];
char ip_str[25];
int err;
int is_local;
struct stat sbuf;
struct stat obuf;
int renamed;
double r;
if (name == NULL)
{
return (-1);
}
/*
* each element gets a seq_no and log index so we can handle
* function cancel if we wrap
*/
space = ((history_size + 1) * (element_size + sizeof(ELID))) +
sizeof(WOOF_SHARED);
if (WooF_dir == NULL)
{
fprintf(stderr, "WooFCreate: must init system\n");
fflush(stderr);
exit(1);
}
is_local = 0;
memset(local_name, 0, sizeof(local_name));
memset(ip_str, 0, sizeof(ip_str));
/*
* if it is a woof:// spec, check to see if the path matches the namespace
*
* if it does, it is local => use WooF_dir
*/
if (WooFValidURI(name))
{
err = WooFNameSpaceFromURI(name, local_name, sizeof(local_name));
if (err < 0)
{
fprintf(stderr, "WooFCreate: bad namespace in URI %s\n",
name);
fflush(stderr);
return (-1);
}
/*
* check to see if there is a host spec
*/
err = WooFIPAddrFromURI(name, ip_str, sizeof(ip_str));
if (err < 0)
{
strncpy(ip_str, Host_ip, sizeof(ip_str));
}
if ((strcmp(WooF_namespace, local_name) == 0) &&
(strcmp(Host_ip, ip_str) == 0))
{
/*
* woof spec for local name space, use WooF_dir
*/
is_local = 1;
memset(local_name, 0, sizeof(local_name));
strncpy(local_name, WooF_dir, sizeof(local_name));
if (local_name[strlen(local_name) - 1] != '/')
{
strncat(local_name, "/", 1);
}
err = WooFNameFromURI(name, fname, sizeof(fname));
if (err < 0)
{
fprintf(stderr, "WooFCreate: bad name in URI %s\n",
name);
fflush(stderr);
return (-1);
}
strncat(local_name, fname, sizeof(fname));
}
}
else
{ /* not URI spec so must be local */
is_local = 1;
strncpy(local_name, WooF_dir, sizeof(local_name));
if (local_name[strlen(local_name) - 1] != '/')
{
strncat(local_name, "/", 1);
}
strncat(local_name, name, sizeof(local_name));
}
if (is_local == 0)
{
fprintf(stderr, "WooFCreate: non-local create of %s not supported (yet)\n",
name);
fflush(stderr);
return (-1);
}
#ifdef NOTRIGHTNOW
/*
* here is where a remote create message would go
*/
if (WooFValidURI(name) && (is_local == 0))
{
err = WooFNameSpaceFromURI(name, local_name, sizeof(local_name));
if (err < 0)
{
fprintf(stderr, "WooFCreate: bad namespace in URI %s\n",
name);
fflush(stderr);
return (-1);
}
if (local_name[strlen(local_name) - 1] != '/')
{
strncat(local_name, "/", 1);
}
err = WooFNameFromURI(name, fname, sizeof(fname));
if (err < 0)
{
fprintf(stderr, "WooFCreate: bad name in URI %s\n",
name);
fflush(stderr);
return (-1);
}
strncat(local_name, fname, sizeof(fname));
}
else
{ /* assume this is WooF_dir local */
strncpy(local_name, WooF_dir, sizeof(local_name));
if (local_name[strlen(local_name) - 1] != '/')
{
strncat(local_name, "/", 1);
}
strncat(local_name, name, sizeof(local_name));
}
#endif
/*
* here is a HACK for open woof caching. If the woof being created already exists, rename it so that the new
* woof gets a different inode number (guaranteed). That way, a cached open woof can "tell" (by getting the
* inode number from a stat) whether the woof has changed since it was cached
*/
renamed = 0;
if (stat(local_name, &sbuf) >= 0)
{
memset(temp_name, 0, sizeof(temp_name));
r = drand48();
sprintf(temp_name, "%s.%10.10f", local_name, r);
rename(local_name, temp_name);
renamed = 1;
#ifdef DEBUG
printf("WooFCreate: renamed %s to %s\n", local_name, temp_name);
fflush(stdout);
#endif
}
mio = MIOOpen(local_name, "w+", space);
if (mio == NULL)
{
fprintf(stderr, "WooFCreate: couldn't open %s with space %lu\n", local_name, space);
fflush(stderr);
rename(temp_name, local_name);
return (-1);
}
#ifdef DEBUG
if (stat(local_name, &obuf) >= 0)
{
printf("WooFCreate: opened %s with inode %lu\n", local_name, obuf.st_ino);
}
else
{
printf("WooFCreate: opened %s\n", local_name);
}
fflush(stdout);
#endif
if (renamed == 1)
{
#ifdef DEBUG
printf("WooFCreate: attempting unlick of %s\n", temp_name);
fflush(stdout);
#endif
err = unlink(temp_name);
if (err < 0)
{
fprintf(stderr, "WooFCreate: couldn't dispose of %s\n", temp_name);
fflush(stderr);
}
}
wfs = (WOOF_SHARED *)MIOAddr(mio);
memset(wfs, 0, sizeof(WOOF_SHARED));
if (WooFValidURI(name))
{
strncpy(wfs->filename, fname, sizeof(wfs->filename));
}
else
{
strncpy(wfs->filename, name, sizeof(wfs->filename));
}
wfs->history_size = history_size;
wfs->element_size = element_size;
wfs->seq_no = 1;
InitSem(&wfs->mutex, 1);
InitSem(&wfs->tail_wait, history_size);
MIOClose(mio);
return (1);
}
WOOF *WooFOpen(char *name)
{
WOOF *wf;
WOOF_SHARED *wfs;
MIO *mio;
char local_name[4096];
char fname[4096];
int err;
struct stat sbuf;
if (name == NULL)
{
return (NULL);
}
if (WooF_dir[0] == 0)
{
fprintf(stderr, "WooFOpen: must init system\n");
fflush(stderr);
exit(1);
}
memset(local_name, 0, sizeof(local_name));
strncpy(local_name, WooF_dir, sizeof(local_name));
if (local_name[strlen(local_name) - 1] != '/')
{
strncat(local_name, "/", 1);
}
if (WooFValidURI(name))
{
err = WooFNameFromURI(name, fname, sizeof(fname));
if (err < 0)
{
fprintf(stderr, "WooFOpen: bad name in URI %s\n",
name);
fflush(stderr);
return (NULL);
}
strncat(local_name, fname, sizeof(fname));
}
else
{ /* assume this is WooF_dir local */
strncat(local_name, name, sizeof(local_name));
}
#ifdef DEBUG
printf("WooFOpen: trying to open %s from fname %s, %s with dir %s\n",
local_name,
fname,
name,
WooF_dir);
fflush(stdout);
#endif
if (stat(local_name, &sbuf) < 0)
{
fprintf(stderr, "WooFOpen: couldn't open woof: %s\n", local_name);
fflush(stderr);
return (NULL);
}
mio = MIOReOpen(local_name);
if (mio == NULL)
{
return (NULL);
}
#ifdef DEBUG
printf("WooFOpen: opened %s\n", local_name);
fflush(stdout);
#endif
wf = (WOOF *)malloc(sizeof(WOOF));
if (wf == NULL)
{
MIOClose(mio);
return (NULL);
}
memset(wf, 0, sizeof(WOOF));
wf->shared = (WOOF_SHARED *)MIOAddr(mio);
wf->mio = mio;
wf->ino = sbuf.st_ino;
return (wf);
}
void WooFDrop(WOOF *wf)
{
MIOClose(wf->mio);
free(wf);
return;
}
int WooFTruncate(char *name, unsigned long seq_no) {
WOOF *wf = WooFOpen(name);
if (wf == NULL) {
return -1;
}
WOOF_SHARED *wfs = wf->shared;
P(&wfs->tail_wait);
P(&wfs->mutex);
if (seq_no == 0) {
wfs->head = 0;
wfs->tail = 0;
wfs->seq_no = 1;
} else {
// if new seq_no is less than earliest seq_no, return -1
unsigned long earliest_seqno = (wfs->tail + 1) % wfs->history_size;
if (seq_no < earliest_seqno) {
fprintf(stderr, "WooFTruncate: seq_no %lu is less than the earliest seq_no %lu\n", seq_no, earliest_seqno);
fflush(stderr);
V(&wfs->mutex);
V(&wfs->tail_wait);
WooFDrop(wf);
return -1;
}
unsigned long latest_seqno = wfs->seq_no - 1;
unsigned long trunc_head = (wfs->head + wfs->history_size - (latest_seqno - seq_no)) % wfs->history_size;
wfs->head = trunc_head;
wfs->seq_no = seq_no + 1;
}
V(&wfs->mutex);
V(&wfs->tail_wait);
WooFDrop(wf);
return 1;
}
unsigned long WooFAppend(WOOF *wf, char *hand_name, void *element)
{
MIO *mio;
MIO *lmio;
WOOF_SHARED *wfs;
char woof_name[2048];
char log_name[4096];
pthread_t tid;
unsigned long next;
unsigned char *buf;
unsigned char *ptr;
ELID *el_id;
unsigned long seq_no;
unsigned long ndx;
int err;
char launch_string[4096];
char *namelog_seq_no;
unsigned long my_log_seq_no;
EVENT *ev;
unsigned long ls;
#ifdef DEBUG
printf("WooFAppend: called %s %s\n", wf->shared->filename, hand_name);
fflush(stdout);
#endif
wfs = wf->shared;
/*
* if called from within a handler, env variable carries cause seq_no
* for logging
*
* when called for first time on namespace to start, should be NULL
*/
namelog_seq_no = getenv("WOOF_NAMELOG_SEQNO");
if (namelog_seq_no != NULL)
{
my_log_seq_no = strtoul(namelog_seq_no, (char **)NULL, 10);
}
else
{
my_log_seq_no = 1;
}
if (hand_name != NULL)
{
ev = EventCreate(TRIGGER, Name_id);
if (ev == NULL)
{
fprintf(stderr, "WooFAppend: couldn't create log event\n");
exit(1);
}
ev->cause_host = Name_id;
ev->cause_seq_no = my_log_seq_no;
}
#ifdef DEBUG
printf("WooFAppend: checking for empty slot, ino: %lu\n", wf->ino);
fflush(stdout);
#endif
P(&wfs->tail_wait);
#ifdef DEBUG
printf("WooFAppend: got empty slot\n");
fflush(stdout);
#endif
#ifdef DEBUG
printf("WooFAppend: adding element\n");
fflush(stdout);
#endif
/*
* now drop the element in the object
*/
P(&wfs->mutex);
#ifdef DEBUG
printf("WooFAppend: in mutex\n");
fflush(stdout);
#endif
/*
* find the next spot
*/
next = (wfs->head + 1) % wfs->history_size;
ndx = next;
/*
* write the data and record the indices
*/
buf = (unsigned char *)(((void *)wfs) + sizeof(WOOF_SHARED));
ptr = buf + (next * (wfs->element_size + sizeof(ELID)));
el_id = (ELID *)(ptr + wfs->element_size);
/*
* tail is the last valid place where data could go
* check to see if it is allocated to a function that
* has yet to complete
*/
#ifdef DEBUG
printf("WooFAppend: element in\n");
fflush(stdout);
#endif
#if 0
while((el_id->busy == 1) && (next == wfs->tail)) {
#ifdef DEBUG
printf("WooFAppend: busy at %lu\n",next);
fflush(stdout);
#endif
V(&wfs->mutex);
P(&wfs->tail_wait);
P(&wfs->mutex);
next = (wfs->head + 1) % wfs->history_size;
ptr = buf + (next * (wfs->element_size + sizeof(ELID)));
el_id = (ELID *)(ptr+wfs->element_size);
}
#endif
/*
* write the element
*/
#ifdef DEBUG
printf("WooFAppend: writing element 0x%x\n", el_id);
fflush(stdout);
#endif
memcpy(ptr, element, wfs->element_size);
/*
* and elemant meta data after it
*/
el_id->seq_no = wfs->seq_no;
el_id->busy = 1;
/*
printf("WooFAppend: about to set head for name %s, head: %lu, next: %lu, size: %lu\n",
wfs->filename,wfs->head,next,wfs->history_size);
fflush(stdout);
*/
/*
* update circular buffer
*/
ndx = wfs->head = next;
if (next == wfs->tail)
{
wfs->tail = (wfs->tail + 1) % wfs->history_size;
}
seq_no = wfs->seq_no;
wfs->seq_no++;
V(&wfs->mutex);
#ifdef DEBUG
printf("WooFAppend: out of element mutex\n");
fflush(stdout);
#endif
/*
* if there is no handler, we are done (no need to generate log record)
* However, since there is no handler, woofc-shperherd can't V the counting
* semaphore for the WooF. Without a handler, the tail is immediately available since
* we don't know whether the WooF will be consumed -- V it in this case
*/
if (hand_name == NULL)
{
/*
* mark the woof as done for purposes of sync
*/
#if DONEFLAG
wfs->done = 1;
#endif
V(&wfs->tail_wait);
return (seq_no);
}
memset(ev->namespace, 0, sizeof(ev->namespace));
strncpy(ev->namespace, WooF_namespace, sizeof(ev->namespace));
#ifdef DEBUG
printf("WooFAppend: namespace: %s\n", ev->namespace);
fflush(stdout);
#endif
ev->woofc_ndx = ndx;
#ifdef DEBUG
printf("WooFAppend: ndx: %lu\n", ev->woofc_ndx);
fflush(stdout);
#endif
ev->woofc_seq_no = seq_no;
#ifdef DEBUG
printf("WooFAppend: seq_no: %lu\n", ev->woofc_seq_no);
fflush(stdout);
#endif
ev->woofc_element_size = wfs->element_size;
#ifdef DEBUG
printf("WooFAppend: element_size %lu\n", ev->woofc_element_size);
fflush(stdout);
#endif
ev->woofc_history_size = wfs->history_size;
#ifdef DEBUG
printf("WooFAppend: history_size %lu\n", ev->woofc_history_size);
fflush(stdout);
#endif
memset(ev->woofc_name, 0, sizeof(ev->woofc_name));
strncpy(ev->woofc_name, wfs->filename, sizeof(ev->woofc_name));
#ifdef DEBUG
printf("WooFAppend: name %s\n", ev->woofc_name);
fflush(stdout);
#endif
memset(ev->woofc_handler, 0, sizeof(ev->woofc_handler));
strncpy(ev->woofc_handler, hand_name, sizeof(ev->woofc_handler));
#ifdef DEBUG
printf("WooFAppend: handler %s\n", ev->woofc_handler);
fflush(stdout);
#endif
ev->ino = wf->ino;
#ifdef DEBUG
printf("WooFAppend: ino %lu\n", ev->ino);
fflush(stdout);
#endif
/*
* log the event so that it can be triggered
*/
memset(log_name, 0, sizeof(log_name));
sprintf(log_name, "%s/%s", WooF_namelog_dir, Namelog_name);
#ifdef DEBUG
printf("WooFAppend: logging event to %s\n", log_name);
fflush(stdout);
#endif
ls = LogEvent(Name_log, ev);
if (ls == 0)
{
fprintf(stderr, "WooFAppend: couldn't log event to log %s\n",
log_name);
fflush(stderr);
EventFree(ev);
return (-1);
}
#ifdef DEBUG
printf("WooFAppend: logged %lu for woof %s %s\n",
ls,
ev->woofc_name,
ev->woofc_handler);
fflush(stdout);
#endif
EventFree(ev);
V(&Name_log->tail_wait);
return (seq_no);
}
unsigned long WooFPut(char *wf_name, char *hand_name, void *element)
{
WOOF *wf;
unsigned long seq_no;
unsigned long el_size;
char wf_namespace[2048];
char ns_ip[25];
char my_ip[25];
int err;
#ifdef DEBUG
printf("WooFPut: called %s %s\n", wf_name, hand_name);
fflush(stdout);
#endif
memset(ns_ip, 0, sizeof(ns_ip));
err = WooFIPAddrFromURI(wf_name, ns_ip, sizeof(ns_ip));
/*
* if there is no IP address in the URI, use the local IP address
*/
if (err < 0)
{
err = WooFLocalIP(ns_ip, sizeof(ns_ip));
if (err < 0)
{
fprintf(stderr, "WooFPut: no local IP\n");
exit(1);
}
}
memset(my_ip, 0, sizeof(my_ip));
err = WooFLocalIP(my_ip, sizeof(my_ip));
if (err < 0)
{
fprintf(stderr, "WooFPut: no local IP\n");
exit(1);
}
memset(wf_namespace, 0, sizeof(wf_namespace));
err = WooFNameSpaceFromURI(wf_name, wf_namespace, sizeof(wf_namespace));
/*
* if this isn't for my namespace, try and remote put
*
* err < 0 implies that name is local name
*
* if namespace paths do not match or they do match but the IP addresses do not match, this is
* a remote put
*/
if ((err >= 0) &&
((strcmp(WooF_namespace, wf_namespace) != 0) ||
(strcmp(my_ip, ns_ip) != 0)))
{
el_size = WooFMsgGetElSize(wf_name);
if (el_size != (unsigned long)-1)
{
seq_no = WooFMsgPut(wf_name, hand_name, element, el_size);
return (seq_no);
}
else
{
fprintf(stderr, "WooFPut: couldn't get element size for %s\n",
wf_name);
fflush(stderr);
return (-1);
}
}
if (WooF_dir[0] == 0)
{
fprintf(stderr, "WooFPut: local namespace put must init system\n");
fflush(stderr);
return (-1);
}
#ifdef DEBUG
printf("WooFPut: namespace: %s, WooF_dir: %s, name: %s\n",
WooF_namespace, WooF_dir, wf_name);
fflush(stdout);
#endif
wf = WooFOpen(wf_name);
if (wf == NULL)
{
return (-1);
}
#ifdef DEBUG
printf("WooFPut: WooF %s open\n", wf_name);
fflush(stdout);
#endif
seq_no = WooFAppend(wf, hand_name, element);
WooFDrop(wf);
return (seq_no);
}
int WooFGet(char *wf_name, void *element, unsigned long seq_no)
{
WOOF *wf;
unsigned long el_size;
char wf_namespace[2048];
int err;
char ns_ip[25];
char my_ip[25];
#ifdef DEBUG
printf("WooFGet: called %s %lu\n", wf_name, seq_no);
fflush(stdout);
#endif
memset(ns_ip, 0, sizeof(ns_ip));
err = WooFIPAddrFromURI(wf_name, ns_ip, sizeof(ns_ip));
if (err < 0)
{
err = WooFLocalIP(ns_ip, sizeof(ns_ip));
if (err < 0)
{
fprintf(stderr, "WooFGet: no local IP\n");
exit(1);
}
}
memset(my_ip, 0, sizeof(my_ip));
err = WooFLocalIP(my_ip, sizeof(my_ip));
if (err < 0)
{
fprintf(stderr, "WooFGet: no local IP\n");
exit(1);
}
memset(wf_namespace, 0, sizeof(wf_namespace));
err = WooFNameSpaceFromURI(wf_name, wf_namespace, sizeof(wf_namespace));
/*
* if this isn't for my namespace, try and remote get
*
* err < 0 implies that name is local name
*
* if the name space paths do not match or they do but the IP addresses don't this
* is remote
*
*/
if ((err >= 0) &&
((strcmp(WooF_namespace, wf_namespace) != 0) ||
(strcmp(my_ip, ns_ip) != 0)))
{
el_size = WooFMsgGetElSize(wf_name);
if (el_size != (unsigned long)-1)
{
err = WooFMsgGet(wf_name, element, el_size, seq_no);
return (err);
}
else
{
fprintf(stderr, "WooFGet: couldn't get element size for %s\n",
wf_name);
fflush(stderr);
return (-1);
}
}
if (WooF_dir[0] == 0)
{
fprintf(stderr, "WooFGet: must init system\n");
fflush(stderr);
return (-1);
}
#ifdef DEBUG
printf("WooFGet: namespace: %s, WooF_dir: %s, name: %s\n",
WooF_namespace, WooF_dir, wf_name);
fflush(stdout);
#endif
wf = WooFOpen(wf_name);
if (wf == NULL)
{
return (-1);
}
#ifdef DEBUG
printf("WooFGet: WooF %s open\n", wf_name);
fflush(stdout);
#endif
err = WooFRead(wf, element, seq_no);
WooFDrop(wf);
return (err);
}
#if DONEFLAG
int WooFHandlerDone(char *wf_name, unsigned long seq_no)
{
WOOF *wf;
unsigned long el_size;
char wf_namespace[2048];
int err;
char ns_ip[25];
char my_ip[25];
int retval;
#ifdef DEBUG
printf("WooFHandlerDone: called %s %lu\n", wf_name, seq_no);
fflush(stdout);
#endif
memset(ns_ip, 0, sizeof(ns_ip));
err = WooFIPAddrFromURI(wf_name, ns_ip, sizeof(ns_ip));
if (err < 0)
{
err = WooFLocalIP(ns_ip, sizeof(ns_ip));
if (err < 0)
{
fprintf(stderr, "WooFGet: no local IP\n");
exit(1);
}
}
memset(my_ip, 0, sizeof(my_ip));
err = WooFLocalIP(my_ip, sizeof(my_ip));
if (err < 0)
{
fprintf(stderr, "WooFGet: no local IP\n");
exit(1);
}
memset(wf_namespace, 0, sizeof(wf_namespace));
err = WooFNameSpaceFromURI(wf_name, wf_namespace, sizeof(wf_namespace));
/*
* if this isn't for my namespace, try and remote get
*
* err < 0 implies that name is local name
*
* if the name space paths do not match or they do but the IP addresses don't this
* is remote
*
*/
if ((err >= 0) &&
((strcmp(WooF_namespace, wf_namespace) != 0) ||
(strcmp(my_ip, ns_ip) != 0)))
{
retval = WooFMsgGetDone(wf_name, seq_no);
return (retval);
}
if (WooF_dir[0] == 0)
{
fprintf(stderr, "WooFHandlerDone: must init system\n");
fflush(stderr);
return (-1);
}
#ifdef DEBUG
printf("WooFHandlerDone: namespace: %s, WooF_dir: %s, name: %s\n",
WooF_namespace, WooF_dir, wf_name);
fflush(stdout);
#endif
wf = WooFOpen(wf_name);
if (wf == NULL)
{
return (-1);
}
#ifdef DEBUG
printf("WooFHandlerDone: WooF %s open\n", wf_name);
fflush(stdout);
#endif
if (wf->shared->done == 1)
{
retval = 1;
}
else
{
retval = 0;
}
WooFDrop(wf);
return (retval);
}
#endif
unsigned long WooFGetLatestSeqno(char *wf_name)
{
WOOF *wf;
unsigned long latest_seq_no;
char wf_namespace[2048];
int err;
char ns_ip[25];
char my_ip[25];
#ifdef DEBUG
printf("WooFGetLatestSeqno: called %s\n", wf_name);
fflush(stdout);
#endif
memset(ns_ip, 0, sizeof(ns_ip));
err = WooFIPAddrFromURI(wf_name, ns_ip, sizeof(ns_ip));
if (err < 0)
{
err = WooFLocalIP(ns_ip, sizeof(ns_ip));
if (err < 0)
{
fprintf(stderr, "WooFGetLatestSeqno: no local IP\n");
exit(1);
}
}
memset(my_ip, 0, sizeof(my_ip));
err = WooFLocalIP(my_ip, sizeof(my_ip));
if (err < 0)
{
fprintf(stderr, "WooFGetLatestSeqno: no local IP\n");
exit(1);
}
memset(wf_namespace, 0, sizeof(wf_namespace));
err = WooFNameSpaceFromURI(wf_name, wf_namespace, sizeof(wf_namespace));
/*
* if this isn't for my namespace, try and remote get
*
* err < 0 implies that name is local name
*
* if the name space paths do not match or they do but the IP addresses don't this
* is remote
*
*/
if ((err >= 0) &&
((strcmp(WooF_namespace, wf_namespace) != 0) ||
(strcmp(my_ip, ns_ip) != 0)))
{
latest_seq_no = WooFMsgGetLatestSeqno(wf_name);
return (latest_seq_no);
}
if (WooF_dir[0] == 0)
{
fprintf(stderr, "WooFGetLatestSeqno: must init system\n");
fflush(stderr);
return (-1);
}
#ifdef DEBUG
printf("WooFGetLatestSeqno: namespace: %s, WooF_dir: %s, name: %s\n",
WooF_namespace, WooF_dir, wf_name);
fflush(stdout);
#endif
wf = WooFOpen(wf_name);
if (wf == NULL)
{
return (-1);
}
#ifdef DEBUG
printf("WooFGetLatestSeqno: WooF %s open\n", wf_name);
fflush(stdout);
#endif
latest_seq_no = WooFLatestSeqno(wf);
WooFDrop(wf);
return (latest_seq_no);
}
int WooFReadTail(WOOF *wf, void *elements, int element_count)
{
int i;
unsigned long ndx;
unsigned char *buf;
unsigned char *ptr;
unsigned char *lp;
WOOF_SHARED *wfs;
wfs = wf->shared;