[go: up one dir, main page]

File: chirp_global.c

package info (click to toggle)
cctools 7.1.2-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 43,744 kB
  • sloc: ansic: 187,336; cpp: 20,196; python: 18,633; sh: 11,159; xml: 3,688; perl: 2,817; makefile: 1,105
file content (1080 lines) | stat: -rw-r--r-- 28,289 bytes parent folder | download | duplicates (3)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
/*
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
Copyright (C) 2005- The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/

/*
The chirp_global module provides a "global" view of the Chirp storage space,
presenting multiple servers as one big file tree.  It uses the catalog_query
module to obtain the global list of servers and then uses chirp_reli to access
the underlying file servers.

So as to avoid many slow queries to the catalog server, queries are cached and
sonsulted repeatedly.  Each query pulls off the details of each server in the
form of jx json expressions that are placed into a hash table according
to the server name and port.  The catalog is not queried above once per minute.
Note that no matter how often the catalog is queried, the data will be stale
due to the propagation delay from servers to the catalog.  If you are using a
catalog other than the default, set the environment variable CATALOG_HOST to
point to it.

Directory lists simply iterate through the hash table to obtain the global
list.  Stat operations on file servers query the hash table in order to
determine a few key stats, such as total storage in use and last time heard
from.  This allows an ls -l through Parrot to show the last message time and
the space used (in MB.)
*/

#include "chirp_global.h"
#include "chirp_reli.h"
#include "chirp_protocol.h"
#include "chirp_multi.h"
#include "chirp_client.h"
#include "chirp_protocol.h"
#include "catalog_query.h"

#include "macros.h"
#include "debug.h"
#include "full_io.h"
#include "sleeptools.h"
#include "hash_table.h"
#include "xxmalloc.h"
#include "jx_parse.h"

#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>

static struct hash_table *server_table = 0;
static time_t last_update = 0;
static time_t update_interval = 60;
static int inhibit_catalog_queries = 0;

static int not_empty(const char *str)
{
	if(!str || !str[0] || !strcmp(str, "/")) {
		return 0;
	} else {
		return 1;
	}
}

static int is_multi_path(const char *host)
{
	return !strcmp(host, "multi") || !strcmp(host, "multi:9094");
}

static void chirp_jx_to_stat(struct jx *j, struct chirp_stat *info)
{
	memset(info, 0, sizeof(*info));
	info->cst_atime = info->cst_mtime = info->cst_ctime = jx_lookup_integer(j, "lastheardfrom");
	info->cst_size = jx_lookup_integer(j, "total") - jx_lookup_integer(j, "avail");
	info->cst_size /= 1024 * 1024;
	info->cst_mode = S_IFDIR | 0555;
}

static void chirp_blank_stat(struct chirp_stat *info)
{
	memset(info, 0, sizeof(*info));
	info->cst_mode = S_IFDIR | 0555;
}

static void parse_multi_path(const char *path, char *mhost, char *mpath)
{
	mhost[0] = 0;
	mpath[0] = 0;

	sscanf(path, "/%[^/]%s", mhost, mpath);

	if(mhost[0] && !mpath[0]) {
		strcpy(mpath, "/");
	}
}

static int server_table_load(time_t stoptime)
{
	struct catalog_query *q;
	struct jx *j;
	char *key;
	void *item;

	if((last_update + update_interval) > time(0)) {
		return 1;
	}

	if(!server_table) {
		server_table = hash_table_create(0, 0);
		if(!server_table)
			return 0;
	}

	if(inhibit_catalog_queries) {
		debug(D_CHIRP, "catalog queries disabled\n");
		return 1;
	}

	hash_table_firstkey(server_table);
	while(hash_table_nextkey(server_table, &key, &item)) {
		hash_table_remove(server_table, key);
		jx_delete(item);
	}

	debug(D_CHIRP, "querying catalog at %s", CATALOG_HOST);

	struct jx *jexpr = jx_operator(
		JX_OP_EQ,
		jx_symbol("type"),
		jx_string("chirp")
	);
	q = catalog_query_create(CATALOG_HOST, jexpr, stoptime);

	if(!q) {
		jx_delete(jexpr);
		return 0;
	}

	while((j = catalog_query_read(q, stoptime))) {
		char name[CHIRP_PATH_MAX];
		const char *hname;
		int port;

		hname = jx_lookup_string(j, "name");
		if(hname) {
			port = jx_lookup_integer(j, "port");
			if(!port)
				port = CHIRP_PORT;
			sprintf(name, "%s:%d", hname, port);
			hash_table_insert(server_table, name, j);
		} else {
			jx_delete(j);
		}
	}
	catalog_query_delete(q);
	last_update = time(0);

	return 1;
}

static struct jx *server_lookup(const char *host, time_t stoptime)
{
	if(server_table_load(stoptime)) {
		return hash_table_lookup(server_table, host);
	} else {
		return 0;
	}
}

void chirp_global_inhibit_catalog(int onoff)
{
	inhibit_catalog_queries = onoff;
}

struct chirp_file *chirp_global_open(const char *host, const char *path, INT64_T flags, INT64_T mode, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_open(mhost, mpath, flags, mode, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_open(host, path, flags, mode, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EISDIR;
			return 0;
		} else {
			if(flags & O_CREAT) {
				errno = EACCES;
			} else {
				errno = ENOENT;
			}
			return 0;
		}
	} else {
		errno = EISDIR;
		return 0;
	}
}

INT64_T chirp_global_close(struct chirp_file * file, time_t stoptime)
{
	return chirp_reli_close(file, stoptime);
}

INT64_T chirp_global_pread(struct chirp_file * file, void *buffer, INT64_T length, INT64_T offset, time_t stoptime)
{
	return chirp_reli_pread(file, buffer, length, offset, stoptime);
}

INT64_T chirp_global_pwrite(struct chirp_file * file, const void *buffer, INT64_T length, INT64_T offset, time_t stoptime)
{
	return chirp_reli_pwrite(file, buffer, length, offset, stoptime);
}

INT64_T chirp_global_sread(struct chirp_file * file, void *buffer, INT64_T length, INT64_T stride_length, INT64_T stride_skip, INT64_T offset, time_t stoptime)
{
	return chirp_reli_sread(file, buffer, length, stride_length, stride_skip, offset, stoptime);
}

INT64_T chirp_global_swrite(struct chirp_file * file, const void *buffer, INT64_T length, INT64_T stride_length, INT64_T stride_skip, INT64_T offset, time_t stoptime)
{
	return chirp_reli_swrite(file, buffer, length, stride_length, stride_skip, offset, stoptime);
}

INT64_T chirp_global_fstat(struct chirp_file * file, struct chirp_stat * buf, time_t stoptime)
{
	return chirp_reli_fstat(file, buf, stoptime);
}

INT64_T chirp_global_fstatfs(struct chirp_file * file, struct chirp_statfs * buf, time_t stoptime)
{
	return chirp_reli_fstatfs(file, buf, stoptime);
}

INT64_T chirp_global_fchown(struct chirp_file * file, INT64_T uid, INT64_T gid, time_t stoptime)
{
	return chirp_reli_fchown(file, uid, gid, stoptime);
}

INT64_T chirp_global_fchmod(struct chirp_file * file, INT64_T mode, time_t stoptime)
{
	return chirp_reli_fchmod(file, mode, stoptime);
}

INT64_T chirp_global_ftruncate(struct chirp_file * file, INT64_T length, time_t stoptime)
{
	return chirp_reli_ftruncate(file, length, stoptime);
}

INT64_T chirp_global_flush(struct chirp_file * file, time_t stoptime)
{
	return chirp_reli_flush(file, stoptime);
}

INT64_T chirp_global_getfile(const char *host, const char *path, FILE * stream, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_getfile(mhost, mpath, stream, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_getfile(host, path, stream, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EISDIR;
			return -1;
		} else {
			errno = EACCES;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_getfile_buffer(const char *host, const char *path, char **buffer, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_getfile_buffer(mhost, mpath, buffer, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_getfile_buffer(host, path, buffer, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EISDIR;
			return -1;
		} else {
			errno = EACCES;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_putfile(const char *host, const char *path, FILE * stream, INT64_T mode, INT64_T length, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_putfile(mhost, mpath, stream, mode, length, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_putfile(host, path, stream, mode, length, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EISDIR;
			return -1;
		} else {
			errno = EACCES;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_putfile_buffer(const char *host, const char *path, const char *buffer, INT64_T mode, INT64_T length, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_putfile_buffer(mhost, mpath, buffer, mode, length, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_putfile_buffer(host, path, buffer, mode, length, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EISDIR;
			return -1;
		} else {
			errno = EACCES;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_getlongdir(const char *host, const char *path, chirp_longdir_t callback, void *arg, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_getlongdir(mhost, mpath, callback, arg, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_getlongdir(host, path, callback, arg, stoptime);
	} else if(not_empty(host)) {
		return chirp_reli_getlongdir(host, "/", callback, arg, stoptime);
	} else {
		if(server_table_load(stoptime)) {
			char *key;
			void *item;
			struct chirp_stat info;

			hash_table_firstkey(server_table);
			while(hash_table_nextkey(server_table, &key, &item)) {
				chirp_jx_to_stat(item, &info);
				callback(key, &info, arg);
			}
			chirp_blank_stat(&info);
			callback("multi", &info, arg);
			return 0;
		} else {
			errno = ENOENT;
			return -1;
		}
	}
}

INT64_T chirp_global_getdir(const char *host, const char *path, chirp_dir_t callback, void *arg, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_getdir(mhost, mpath, callback, arg, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_getdir(host, path, callback, arg, stoptime);
	} else if(not_empty(host)) {
		return chirp_reli_getdir(host, "/", callback, arg, stoptime);
	} else {
		if(server_table_load(stoptime)) {
			char *key;
			void *item;
			hash_table_firstkey(server_table);
			while(hash_table_nextkey(server_table, &key, &item)) {
				callback(key, arg);
			}
			callback("multi", arg);
			return 0;
		} else {
			errno = ENOENT;
			return -1;
		}
	}
}

INT64_T chirp_global_getacl(const char *host, const char *path, chirp_dir_t callback, void *arg, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_getacl(mhost, mpath, callback, arg, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_getacl(host, path, callback, arg, stoptime);
	} else if(not_empty(host)) {
		return chirp_reli_getacl(host, "/", callback, arg, stoptime);
	} else {
		errno = EINVAL;
		return -1;
	}
}

INT64_T chirp_global_setacl(const char *host, const char *path, const char *subject, const char *rights, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_setacl(mhost, mpath, subject, rights, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_setacl(host, path, subject, rights, stoptime);
	} else if(not_empty(host)) {
		return chirp_reli_setacl(host, "/", subject, rights, stoptime);
	} else {
		errno = EINVAL;
		return -1;
	}
}

INT64_T chirp_global_whoami(const char *host, const char *path, char *buf, INT64_T length, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_whoami(mhost, buf, length, stoptime);
	} else if(not_empty(host)) {
		return chirp_reli_whoami(host, buf, length, stoptime);
	} else {
		errno = EINVAL;
		return -1;
	}
}

INT64_T chirp_global_locate(const char *host, const char *path, chirp_loc_t callback, void *arg, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EINVAL;
		return -1;
		/*char mhost[CHIRP_PATH_MAX];
		   char mpath[CHIRP_PATH_MAX];
		   parse_multi_path(path,mhost,mpath);
		   return chirp_multi_locate(mhost,mpath,callback,arg,stoptime);
		 */
	} else if(not_empty(host)) {
		return chirp_reli_locate(host, path, callback, arg, stoptime);
	} else {
		errno = EINVAL;
		return -1;
	}
}

INT64_T chirp_global_unlink(const char *host, const char *path, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_unlink(mhost, mpath, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_unlink(host, path, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_rename(const char *host, const char *path, const char *newpath, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];

		char mnewhost[CHIRP_PATH_MAX];
		char mnewpath[CHIRP_PATH_MAX];

		parse_multi_path(path, mhost, mpath);
		parse_multi_path(path, mnewhost, mnewpath);

		if(!strcmp(mhost, mnewhost)) {
			return chirp_multi_rename(mhost, mpath, mnewpath, stoptime);
		} else {
			errno = EXDEV;
			return -1;
		}
	} else if(not_empty(path)) {
		return chirp_reli_rename(host, path, newpath, stoptime);
	} else {
		errno = EXDEV;
		return -1;
	}
}

INT64_T chirp_global_link(const char *host, const char *path, const char *newpath, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_symlink(mhost, mpath, newpath, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_link(host, path, newpath, stoptime);
	} else {
		errno = EXDEV;
		return -1;
	}
}

INT64_T chirp_global_symlink(const char *host, const char *path, const char *newpath, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_symlink(mhost, mpath, newpath, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_symlink(host, path, newpath, stoptime);
	} else {
		errno = EXDEV;
		return -1;
	}
}

INT64_T chirp_global_readlink(const char *host, const char *path, char *buf, INT64_T length, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_readlink(mhost, mpath, buf, length, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_readlink(host, path, buf, length, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EINVAL;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EINVAL;
		return -1;
	}
}

INT64_T chirp_global_mkdir(const char *host, const char *path, INT64_T mode, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_mkdir(mhost, mpath, mode, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_mkdir(host, path, mode, stoptime);
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_rmdir(const char *host, const char *path, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_rmdir(mhost, mpath, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_rmdir(host, path, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_rmall(const char *host, const char *path, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = ENOSYS;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_rmall(host, path, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_stat(const char *host, const char *path, struct chirp_stat * buf, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_stat(mhost, mpath, buf, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_stat(host, path, buf, stoptime);
	} else if(not_empty(host)) {
		struct jx *j = server_lookup(host, stoptime);
		if(j) {
			chirp_jx_to_stat(j, buf);
			return 0;
		} else {
			return chirp_reli_stat(host, "/", buf, stoptime);
		}
	} else {
		chirp_blank_stat(buf);
		return 0;
	}
}

INT64_T chirp_global_lstat(const char *host, const char *path, struct chirp_stat * buf, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_lstat(mhost, mpath, buf, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_lstat(host, path, buf, stoptime);
	} else if(not_empty(host)) {
		struct jx *j = server_lookup(host, stoptime);
		if(j) {
			chirp_jx_to_stat(j, buf);
			return 0;
		} else {
			return chirp_reli_lstat(host, "/", buf, stoptime);
		}
	} else {
		chirp_blank_stat(buf);
		return 0;
	}
}

INT64_T chirp_global_statfs(const char *host, const char *path, struct chirp_statfs * buf, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_statfs(mhost, mpath, buf, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_statfs(host, path, buf, stoptime);
	} else if(not_empty(host)) {
		return chirp_reli_statfs(host, "/", buf, stoptime);
	} else {
		memset(buf, 0, sizeof(*buf));
		return 0;
	}

}

INT64_T chirp_global_access(const char *host, const char *path, INT64_T mode, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_access(mhost, mpath, mode, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_access(host, path, mode, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			return 0;
		} else {
			return chirp_reli_access(host, path, mode, stoptime);
		}
	} else {
		return 0;
	}
}

INT64_T chirp_global_chmod(const char *host, const char *path, INT64_T mode, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_chmod(mhost, mpath, mode, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_chmod(host, path, mode, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}


INT64_T chirp_global_chown(const char *host, const char *path, INT64_T uid, INT64_T gid, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_chown(mhost, mpath, uid, gid, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_chown(host, path, uid, gid, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_lchown(const char *host, const char *path, INT64_T uid, INT64_T gid, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_lchown(mhost, mpath, uid, gid, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_lchown(host, path, uid, gid, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_truncate(const char *host, const char *path, INT64_T length, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_truncate(mhost, mpath, length, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_truncate(host, path, length, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EISDIR;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EISDIR;
		return -1;
	}
}

INT64_T chirp_global_utime(const char *host, const char *path, time_t actime, time_t modtime, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_utime(mhost, mpath, actime, modtime, stoptime);
	} else if(not_empty(path)) {
		return chirp_reli_utime(host, path, actime, modtime, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EISDIR;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EISDIR;
		return -1;
	}
}

INT64_T chirp_global_thirdput(const char *host, const char *path, const char *thirdhost, const char *thirdpath, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(host)) {
		return chirp_reli_thirdput(host, path, thirdhost, thirdpath, stoptime);
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_md5(const char *host, const char *path, unsigned char *digest, time_t stoptime)
{
	if(is_multi_path(host)) {
		char mhost[CHIRP_PATH_MAX];
		char mpath[CHIRP_PATH_MAX];
		parse_multi_path(path, mhost, mpath);
		return chirp_multi_md5(mhost, mpath, digest, stoptime);
	} else if(not_empty(host)) {
		return chirp_reli_md5(host, path, digest, stoptime);
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_lsalloc(const char *host, const char *path, char *alloc_path, INT64_T * size, INT64_T * inuse, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(host)) {
		return chirp_reli_lsalloc(host, path, alloc_path, size, inuse, stoptime);
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_mkalloc(const char *host, const char *path, INT64_T size, INT64_T mode, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_mkalloc(host, path, size, mode, stoptime);
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_getxattr(const char *host, const char *path, const char *name, void *data, size_t size, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_getxattr(host, path, name, data, size, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_fgetxattr(struct chirp_file * file, const char *name, void *data, size_t size, time_t stoptime)
{
	return chirp_reli_fgetxattr(file, name, data, size, stoptime);
}

INT64_T chirp_global_lgetxattr(const char *host, const char *path, const char *name, void *data, size_t size, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_lgetxattr(host, path, name, data, size, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_listxattr(const char *host, const char *path, char *list, size_t size, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_listxattr(host, path, list, size, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_flistxattr(struct chirp_file * file, char *list, size_t size, time_t stoptime)
{
	return chirp_reli_flistxattr(file, list, size, stoptime);
}

INT64_T chirp_global_llistxattr(const char *host, const char *path, char *list, size_t size, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_llistxattr(host, path, list, size, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_setxattr(const char *host, const char *path, const char *name, const void *data, size_t size, int flags, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_setxattr(host, path, name, data, size, flags, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_fsetxattr(struct chirp_file * file, const char *name, const void *data, size_t size, int flags, time_t stoptime)
{
	return chirp_reli_fsetxattr(file, name, data, size, flags, stoptime);
}

INT64_T chirp_global_lsetxattr(const char *host, const char *path, const char *name, const void *data, size_t size, int flags, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_lsetxattr(host, path, name, data, size, flags, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_removexattr(const char *host, const char *path, const char *name, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_removexattr(host, path, name, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

INT64_T chirp_global_fremovexattr(struct chirp_file * file, const char *name, time_t stoptime)
{
	return chirp_reli_fremovexattr(file, name, stoptime);
}

INT64_T chirp_global_lremovexattr(const char *host, const char *path, const char *name, time_t stoptime)
{
	if(is_multi_path(host)) {
		errno = EACCES;
		return -1;
	} else if(not_empty(path)) {
		return chirp_reli_lremovexattr(host, path, name, stoptime);
	} else if(not_empty(host)) {
		if(server_lookup(host, stoptime)) {
			errno = EACCES;
			return -1;
		} else {
			errno = ENOENT;
			return -1;
		}
	} else {
		errno = EACCES;
		return -1;
	}
}

/* vim: set noexpandtab tabstop=4: */