2 * Copyright 2006, Sine Nomine Associates and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
12 * fileserver state serialization
17 #include <afsconfig.h>
18 #include <afs/param.h>
25 #include <netinet/in.h>
31 #include <afs/assert.h>
34 #include <afs/afsint.h>
35 #include <afs/rxgen_consts.h>
37 #include <afs/errors.h>
38 #include <afs/ihandle.h>
39 #include <afs/vnode.h>
40 #include <afs/volume.h>
41 #ifdef AFS_ATHENA_STDENV
45 #include <afs/ptclient.h>
46 #include <afs/prs_fs.h>
47 #include <afs/afsutil.h>
49 #include <afs/cellconfig.h>
51 #include "../util/afsutil_prototypes.h"
52 #include "../viced/viced.h"
53 #include "../viced/host.h"
54 #include "../viced/callback.h"
55 #include "serialize_state.h"
57 #include <sys/types.h>
62 /*@+fcnmacros +macrofcndecl@*/
65 extern off64_t afs_lseek(int FD, off64_t O, int F);
66 #endif /*S_SPLINT_S */
67 #define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F)
68 #define afs_stat stat64
69 #define afs_fstat fstat64
70 #define afs_open open64
71 #define afs_fopen fopen64
72 #define afs_mmap mmap64
74 extern void * mmap64(); /* ugly hack since aix build env appears to be somewhat broken */
76 #else /* !O_LARGEFILE */
78 extern off_t afs_lseek(int FD, off_t O, int F);
79 #endif /*S_SPLINT_S */
80 #define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F)
82 #define afs_fstat fstat
84 #define afs_fopen fopen
86 #endif /* !O_LARGEFILE */
87 /*@=fcnmacros =macrofcndecl@*/
90 #ifndef AFS_DEMAND_ATTACH_FS
92 main (int argc, char ** argv)
94 fprintf(stderr, "%s is only supported for demand attach fileservers\n",
95 argv[0] ? argv[0] : "state analyzer");
98 #else /* AFS_DEMAND_ATTACH_FS */
100 static void usage(char * prog);
101 static int openFile(char * path);
102 static void initState(void);
104 static void banner(void);
105 static void prompt(void);
107 static void print_help(void);
108 static void print_global_help(void);
109 static void print_h_help(void);
110 static void print_fe_help(void);
111 static void print_cb_help(void);
113 static void dump_hdr(void);
114 static void dump_h_hdr(void);
115 static void dump_cb_hdr(void);
117 static void dump_cb_timeout(void);
118 static void dump_cb_fehash(void);
120 static void dump_all_hes(void);
121 static void dump_all_fes(void);
122 static void dump_all_cbs(void);
124 static void dump_he(afs_uint32 idx);
125 static void dump_fe(afs_uint32 idx);
126 static void dump_cb(afs_uint32 idx);
127 static void dump_this_he(void);
128 static void dump_this_fe(void);
129 static void dump_this_cb(void);
130 static void dump_next_he(void);
131 static void dump_next_fe(void);
132 static void dump_next_cb(void);
133 static void dump_prev_he(void);
134 static void dump_prev_fe(void);
135 static void dump_prev_cb(void);
136 static void dump_first_he(void);
137 static void dump_first_fe(void);
138 static void dump_first_cb(void);
139 static void dump_last_he(void);
140 static void dump_last_fe(void);
141 static void dump_last_cb(void);
142 static void dump_he_hdr(void);
143 static void dump_he_entry(void);
144 static void dump_he_interfaces(void);
145 static void dump_he_hcps(void);
146 static void dump_fe_hdr(void);
147 static void dump_fe_entry(void);
148 static void dump_cb_entry(void);
150 static void hexdump_map(afs_uint32 offset, afs_uint32 len);
152 static int get_hdr(void);
153 static int get_h_hdr(void);
154 static int get_cb_hdr(void);
155 static int get_cb_timeout_hdr(void);
156 static int get_cb_timeout(void);
157 static int get_cb_fehash_hdr(void);
158 static int get_cb_fehash(void);
159 static int get_he(afs_uint32 idx);
160 static int get_he_hdr(void);
161 static int get_he_entry(void);
162 static int get_fe(afs_uint32 idx);
163 static int get_fe_hdr(void);
164 static int get_fe_entry(void);
165 static int get_cb(afs_uint32 idx);
166 static int get_cb_entry(void);
168 static int find_fe_by_index(afs_uint32 idx);
169 static int find_cb_by_index(afs_uint32 idx);
170 static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq);
173 static int dump_fd = -1;
174 static void * map = NULL;
175 static size_t map_len;
178 struct fs_state_header hdr;
179 struct host_state_header h_hdr;
180 struct callback_state_header cb_hdr;
181 struct callback_state_timeout_header timeout_hdr;
182 struct callback_state_fehash_header fehash_hdr;
183 afs_uint32 * timeout;
186 /* pointers into the memory map */
190 void * timeout_hdr_p;
198 byte timeout_hdr_valid;
199 byte fehash_hdr_valid;
207 struct host_state_entry_header hdr;
208 struct hostDiskEntry he;
222 struct callback_state_entry_header hdr;
223 struct FEDiskEntry fe;
235 struct CBDiskEntry cb;
243 fprintf(stderr, "usage: %s [<state dump file>]\n", prog);
247 main(int argc, char ** argv)
250 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
258 if (openFile(argv[1]))
261 if (openFile((char *)AFSDIR_SERVER_FSSTATE_FILEPATH))
271 openFile(char * path)
274 struct afs_stat status;
276 dump_fd = afs_open(path, O_RDWR);
278 fprintf(stderr, "dump file '%s' failed to open\n", path);
283 printf("opened dump file '%s'\n", path);
285 if (afs_fstat(dump_fd, &status) == -1) {
286 fprintf(stderr, "failed to stat file\n");
291 map_len = status.st_size;
293 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
294 if (map == MAP_FAILED) {
295 fprintf(stderr, "failed to mmap file\n");
300 printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map);
305 munmap(map, map_len);
319 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
320 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
321 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
322 he_cache.cursor = fe_cache.cursor = NULL;
328 fprintf(stderr, "demand attach fs\n");
329 fprintf(stderr, "fileserver state analyzer\n");
330 fprintf(stderr, "version 0.1\n");
333 #define PROGNAME "fs state analyzer"
339 char prev_input[256];
347 } mode = PR_GLOBAL_MODE, next_mode;
350 input[0] = prev_input[0] = '\0';
356 printf(PROGNAME "> ");
359 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
362 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
365 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
368 fprintf(stderr, "prompt state broken; aborting\n");
371 fgets(input, 256, stdin);
373 if (!strcmp(input, "")) {
374 /* repeat last command */
375 if (!strcmp(prev_input, "")) {
378 strlcpy(input, prev_input, sizeof(input));
380 /* save command for repetition */
381 strlcpy(prev_input, input, sizeof(prev_input));
384 tok = strtok(input, " \t");
386 while (tok && !strcmp(tok, ";")) {
387 tok = strtok(NULL, "; \t");
394 if (!strcasecmp(tok, "exit")) {
396 } else if (!strcasecmp(tok, "quit")) {
399 next_mode = PR_FE_MODE;
403 next_mode = PR_GLOBAL_MODE;
408 } else if (!strcasecmp(tok, "h")) {
409 tok = strtok(NULL, " \t");
415 } else if (!strcasecmp(tok, "fe")) {
416 tok = strtok(NULL, " \t");
422 } else if (!strcasecmp(tok, "fs")) {
423 tok = strtok(NULL, " \t");
424 mode = PR_GLOBAL_MODE;
429 } else if (!strcasecmp(tok, "cb")) {
430 tok = strtok(NULL, " \t");
436 } else if (!strcasecmp(tok, "help")) {
451 } else if (!strcasecmp(tok, "hexdump")) {
452 tok = strtok(NULL, " \t");
454 hexdump_map(0, map_len);
457 if (sscanf(tok, "%u", &x) != 1) {
458 fprintf(stderr, "hexdump parse error 1\n");
462 tok = strtok(NULL, " \t");
464 hexdump_map(x, map_len - x);
467 if (sscanf(tok, "%u", &y) != 1) {
468 fprintf(stderr, "hexdump parse error 2\n");
472 } else if (!strcasecmp(tok, "hdr")) {
486 } else if (!strcasecmp(tok, "this")) {
498 fprintf(stderr, "command not valid for this mode\n");
500 } else if (!strcasecmp(tok, "next")) {
512 fprintf(stderr, "command not valid for this mode\n");
514 } else if (!strcasecmp(tok, "prev")) {
526 fprintf(stderr, "command not valid for this mode\n");
528 } else if (!strcasecmp(tok, "first")) {
540 fprintf(stderr, "command not valid for this mode\n");
542 } else if (!strcasecmp(tok, "last")) {
554 fprintf(stderr, "command not valid for this mode\n");
556 } else if (!strcasecmp(tok, "dump")) {
568 fprintf(stderr, "command not valid for this mode\n");
570 } else if (!strcasecmp(tok, "find")) {
571 tok = strtok(NULL, " \t");
572 if (!tok || strcasecmp(tok, "by")) {
574 fprintf(stderr, "find syntax error 1 (%s)\n",
575 (tok) ? tok : "nil");
578 tok = strtok(NULL, " \t");
580 fprintf(stderr, "find syntax error 2\n");
585 fprintf(stderr, "not implemented yet\n");
588 if (!strcasecmp(tok, "index")) {
589 tok = strtok(NULL, " \t");
590 if (!tok || sscanf(tok, "%u", &x) != 1) {
592 fprintf(stderr, "find syntax error 3\n");
595 if (find_fe_by_index(x)) {
596 fprintf(stderr, "find returned no results\n");
598 } else if (!strcasecmp(tok, "fid")) {
599 tok = strtok(NULL, "(), \t");
600 if (!tok || sscanf(tok, "%u", &x) != 1) {
602 fprintf(stderr, "find syntax error 4\n");
605 tok = strtok(NULL, "(), \t");
606 if (!tok || sscanf(tok, "%u", &y) != 1) {
608 fprintf(stderr, "find syntax error 5\n");
611 tok = strtok(NULL, "(), \t");
612 if (!tok || sscanf(tok, "%u", &z) != 1) {
614 fprintf(stderr, "find syntax error 6\n");
617 if (find_fe_by_fid(x,y,z)) {
618 fprintf(stderr, "find returned no results\n");
621 fprintf(stderr, "unsupported filter type\n");
625 if (!strcasecmp(tok, "index")) {
626 tok = strtok(NULL, " \t");
627 if (!tok || sscanf(tok, "%u", &x) != 1) {
629 fprintf(stderr, "find syntax error 3\n");
632 if (find_cb_by_index(x)) {
633 fprintf(stderr, "find returned no results\n");
636 fprintf(stderr, "unsupported filter type\n");
640 fprintf(stderr, "find not supported for this menu\n");
642 } else if (!strcspn(tok, "0123456789")) {
643 if (sscanf(tok, "%u", &x) == 1) {
655 fprintf(stderr, "command not available from this menu\n");
658 fprintf(stderr, "input parse error ('%s')\n", tok);
660 } else if (mode == PR_FE_MODE) {
661 if (!strcmp(tok, "timeout")) {
663 } else if (!strcmp(tok, "hash")) {
667 fprintf(stderr, "unknown command\n");
669 tok = strtok(NULL, " \t");
677 printf("\th <...> -- host menu commands\n");
678 printf("\tfe <...> -- FileEntry menu commands\n");
679 printf("\tcb <...> -- CallBack menu commands\n");
680 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
681 printf("\tquit -- quit this menu\n");
682 printf("\texit -- exit the debugger\n");
683 printf("\thelp -- this help message\n");
687 print_global_help(void)
689 printf("\thdr -- display the fs_state_header struct\n");
695 printf("\thdr -- display the host_state_header struct\n");
696 printf("\tfirst -- display the first host\n");
697 printf("\tprev -- display the previous host\n");
698 printf("\tthis -- display this host\n");
699 printf("\tnext -- display the next host\n");
700 printf("\tlast -- display the last host\n");
701 printf("\tdump -- display all hosts\n");
707 printf("\thdr -- display the callback_state_header struct\n");
708 printf("\tfirst -- display the first FE\n");
709 printf("\tprev -- display the previous FE\n");
710 printf("\tthis -- display this FE\n");
711 printf("\tnext -- display the next FE\n");
712 printf("\tlast -- display the last FE\n");
713 printf("\tdump -- display all FEs\n");
714 printf("\ttimeout -- display the timeout queue heads\n");
715 printf("\thash -- display the file entry hash buckets\n");
716 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
717 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
723 printf("\thdr -- display the callback_state_entry_header struct\n");
724 printf("\tfirst -- display the first CB\n");
725 printf("\tprev -- display the previous CB\n");
726 printf("\tthis -- display this CB\n");
727 printf("\tnext -- display the next CB\n");
728 printf("\tlast -- display the last CB\n");
729 printf("\tdump -- display all CBs\n");
733 #define DPFTB1 "\t\t"
734 #define DPFTB2 "\t\t\t"
736 #define DPFOFF(addr) \
738 char * _p = (char *)addr; \
739 char * _m = (char *)map; \
740 printf("loading structure from address %"AFS_PTR_FMT" (offset %ld)\n", \
741 addr, (long)(_p-_m)); \
745 #define DPFSO(T, name) printf(T "%s = {\n", name)
746 #define DPFSO0(name) DPFSO(DPFTB0, name)
747 #define DPFSO1(name) DPFSO(DPFTB1, name)
748 #define DPFSC(T) printf(T "}\n")
749 #define DPFSC0 DPFSC(DPFTB0)
750 #define DPFSC1 DPFSC(DPFTB1)
753 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
754 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
755 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
756 #define DPFAC0 printf(" }\n")
757 #define DPFAC1 DPFAC0
758 #define DPFA1 printf(DPFTB1 " ")
759 #define DPFA2 printf(DPFTB2 " ")
760 #define DPFAN printf("\n")
761 #define DPFALE(type, var) printf("%" type, var)
762 #define DPFAE(type, var) printf("%" type ",\t", var)
765 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
766 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
767 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
770 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
771 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
772 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
775 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
776 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
777 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
780 #define DPFT(T, name, var) \
783 printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \
785 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
786 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
798 DPFSO0("fs_state_header");
800 DPFX2("magic", hdrs.hdr.stamp.magic);
801 DPFV2("version", "u", hdrs.hdr.stamp.version);
803 DPFT1("timestamp", hdrs.hdr.timestamp);
804 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
806 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
807 DPFS1("server_uuid", uuid_str);
808 DPFV1("valid", "d", hdrs.hdr.valid);
809 DPFV1("endianness", "d", hdrs.hdr.endianness);
810 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
812 SplitInt64(hdrs.hdr.h_offset, hi, lo);
814 DPFV2("hi", "u", hi);
815 DPFV2("lo", "u", lo);
818 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
820 DPFV2("hi", "u", hi);
821 DPFV2("lo", "u", lo);
824 DPFS1("server_version_string", hdrs.hdr.server_version_string);
827 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
828 fprintf(stderr, "* magic check failed\n");
830 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
831 fprintf(stderr, "* version check failed\n");
841 DPFOFF(hdrs.h_hdr_p);
842 DPFSO0("host_state_header");
844 DPFX2("magic", hdrs.h_hdr.stamp.magic);
845 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
847 DPFV1("records", "u", hdrs.h_hdr.records);
848 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
851 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
852 fprintf(stderr, "* magic check failed\n");
854 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
855 fprintf(stderr, "* version check failed\n");
867 DPFOFF(hdrs.cb_hdr_p);
868 DPFSO0("callback_state_header");
870 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
871 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
873 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
874 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
875 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
876 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
877 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
879 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
880 DPFSO1("timeout_offset");
881 DPFV2("hi", "u", hi);
882 DPFV2("lo", "u", lo);
885 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
886 DPFSO1("fehash_offset");
887 DPFV2("hi", "u", hi);
888 DPFV2("lo", "u", lo);
891 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
893 DPFV2("hi", "u", hi);
894 DPFV2("lo", "u", lo);
899 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
900 fprintf(stderr, "* magic check failed\n");
902 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
903 fprintf(stderr, "* version check failed\n");
908 dump_cb_timeout(void)
915 if (get_cb_timeout_hdr())
918 if (get_cb_timeout())
921 DPFOFF(hdrs.timeout_hdr_p);
922 DPFSO0("callback_state_timeout_header");
923 DPFX1("magic", hdrs.timeout_hdr.magic);
924 DPFV1("len", "u", hdrs.timeout_hdr.len);
925 DPFV1("records", "u", hdrs.timeout_hdr.records);
928 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
929 fprintf(stderr, "* magic check failed\n");
932 DPFOFF(hdrs.timeout_p);
934 for (i = 0; i < 127; i++) {
935 DPFAE("u", hdrs.timeout[i]);
941 DPFALE("u", hdrs.timeout[127]);
953 if (get_cb_fehash_hdr())
959 DPFOFF(hdrs.fehash_hdr_p);
960 DPFSO0("callback_state_fehash_header");
961 DPFX1("magic", hdrs.fehash_hdr.magic);
962 DPFV1("len", "u", hdrs.fehash_hdr.len);
963 DPFV1("records", "u", hdrs.fehash_hdr.records);
966 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
967 fprintf(stderr, "* magic check failed\n");
970 DPFOFF(hdrs.fehash_p);
972 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
973 DPFAE("u", hdrs.fehash[i]);
979 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
989 fprintf(stderr, "error getting host_state_header\n");
993 for (i = 0; i < hdrs.h_hdr.records; i++) {
1004 fprintf(stderr, "error getting callback_state_header\n");
1008 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1019 fprintf(stderr, "error getting callback_state_entry_header\n");
1023 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1029 dump_he(afs_uint32 idx)
1032 fprintf(stderr, "error getting he %d\n", idx);
1036 DPFOFF(he_cursor.cursor);
1039 dump_he_interfaces();
1044 dump_fe(afs_uint32 idx)
1047 fprintf(stderr, "error getting fe %d\n", idx);
1051 DPFOFF(fe_cursor.cursor);
1057 dump_cb(afs_uint32 idx)
1060 fprintf(stderr, "error getting cb %d\n", idx);
1064 DPFOFF(cb_cursor.cursor);
1071 dump_he(he_cursor.idx);
1077 dump_fe(fe_cursor.idx);
1083 dump_cb(cb_cursor.idx);
1090 fprintf(stderr, "error getting host_state_header\n");
1094 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1095 fprintf(stderr, "no more HEs\n");
1099 dump_he(he_cursor.idx+1);
1106 fprintf(stderr, "error getting callback_state_header\n");
1110 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1111 fprintf(stderr, "no more FEs\n");
1115 dump_fe(fe_cursor.idx+1);
1122 fprintf(stderr, "error getting callback_state_entry_header\n");
1126 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1127 fprintf(stderr, "no more CBs\n");
1131 dump_cb(cb_cursor.idx+1);
1137 if (!he_cursor.idx) {
1138 fprintf(stderr, "no more HEs\n");
1142 dump_he(he_cursor.idx-1);
1148 if (!fe_cursor.idx) {
1149 fprintf(stderr, "no more FEs\n");
1153 dump_fe(fe_cursor.idx-1);
1159 if (!cb_cursor.idx) {
1160 fprintf(stderr, "no more CBs\n");
1164 dump_cb(cb_cursor.idx-1);
1171 fprintf(stderr, "error getting callback_state_header\n");
1175 if (!hdrs.cb_hdr.nFEs) {
1176 fprintf(stderr, "no FEs present\n");
1187 fprintf(stderr, "error getting host_state_header\n");
1191 if (!hdrs.h_hdr.records) {
1192 fprintf(stderr, "no HEs present\n");
1203 fprintf(stderr, "error getting callback_state_entry_header\n");
1207 if (!fe_cursor.hdr.nCBs) {
1208 fprintf(stderr, "no CBs present\n");
1219 fprintf(stderr, "error getting host_state_header\n");
1223 if (!hdrs.h_hdr.records) {
1224 fprintf(stderr, "no HEs present\n");
1228 dump_he(hdrs.h_hdr.records-1);
1235 fprintf(stderr, "error getting callback_state_header\n");
1239 if (!hdrs.cb_hdr.nFEs) {
1240 fprintf(stderr, "no FEs present\n");
1244 dump_fe(hdrs.cb_hdr.nFEs-1);
1251 fprintf(stderr, "error getting callback_state_entry_header\n");
1255 if (!fe_cursor.hdr.nCBs) {
1256 fprintf(stderr, "no CBs present\n");
1260 dump_cb(fe_cursor.hdr.nCBs-1);
1266 DPFSO0("host_state_entry_header");
1267 DPFX1("magic", he_cursor.hdr.magic);
1268 DPFV1("len", "u", he_cursor.hdr.len);
1269 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1270 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1273 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1274 fprintf(stderr, "* magic check failed\n");
1282 DPFSO0("hostDiskEntry");
1283 DPFS1("host", afs_inet_ntoa_r(he_cursor.he.host, hoststr));
1284 DPFV1("port", "u", he_cursor.he.port);
1285 DPFX1("hostFlags", he_cursor.he.hostFlags);
1286 DPFV1("Console", "u", he_cursor.he.Console);
1287 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1288 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1289 if (hdrs.hdr.stats_detailed) {
1290 #ifdef FS_STATS_DETAILED
1291 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1293 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1296 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1297 DPFT1("LastCall", he_cursor.he.LastCall);
1298 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1299 DPFT1("cpsCall", he_cursor.he.cpsCall);
1300 DPFV1("cblist", "u", he_cursor.he.cblist);
1301 DPFV1("index", "u", he_cursor.he.index);
1306 dump_he_interfaces(void)
1309 struct Interface * ifp;
1313 if (!he_cursor.hdr.interfaces)
1316 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1317 ifp = (struct Interface *) malloc(len);
1318 assert(ifp != NULL);
1320 memcpy(ifp, he_cursor.ifp, len);
1322 DPFSO0("Interface");
1323 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1325 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1326 DPFS1("uuid", temp_str);
1327 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1328 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1330 DPFS2("addr", afs_inet_ntoa_r(ifp->interface[i].addr, hoststr));
1331 DPFV2("port", "u", ifp->interface[i].port);
1337 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1338 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1349 if (!he_cursor.hdr.hcps)
1352 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1353 hcps = (afs_int32 *) malloc(len);
1354 assert(hcps != NULL);
1355 memcpy(hcps, he_cursor.hcps, len);
1358 DPFAO1("prlist_val");
1359 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1360 DPFAE("d", hcps[i]);
1366 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1375 DPFSO0("callback_state_entry_header");
1376 DPFX1("magic", fe_cursor.hdr.magic);
1377 DPFV1("len", "u", fe_cursor.hdr.len);
1378 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1381 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1382 fprintf(stderr, "* magic check failed\n");
1389 DPFSO0("FEDiskEntry");
1391 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1392 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1393 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1394 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1395 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1396 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1397 DPFV2("status", "u", fe_cursor.fe.fe.status);
1399 DPFV1("index", "u", fe_cursor.fe.index);
1406 DPFSO0("CBDiskEntry");
1408 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1409 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1410 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1411 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1412 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1413 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1414 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1415 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1416 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1418 DPFV1("index", "u", cb_cursor.cb.index);
1422 #define DPFHMS printf(" ")
1423 #define DPFHS printf(" ")
1424 #define DPFHN(offset) printf("\n%u\t", offset)
1425 #define DPFHD(x) printf("%02X ", x)
1426 #define DPFHE printf("\n")
1429 hexdump_map(afs_uint32 offset, afs_uint32 len)
1432 unsigned char * p = (unsigned char *)map;
1437 if ((offset + len) > map_len) {
1438 fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n",
1439 offset+len, (unsigned long)map_len);
1447 for (i = offset % 16; i > 0; i--) {
1451 for (i=0; i < len; i++, p++, offset++) {
1452 if (!(offset % 16)) {
1454 } else if (!(offset % 8)) {
1465 if (!hdrs.hdr_valid) {
1466 if (map_len < sizeof(struct fs_state_header)) {
1467 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1470 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1483 if (hdrs.h_hdr_valid)
1489 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1492 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1495 if ((lo >= map_len) ||
1496 ((lo + sizeof(struct host_state_header)) > map_len) ||
1497 (lo + sizeof(struct host_state_header) < lo)) {
1498 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1504 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1506 buf += sizeof(struct host_state_header);
1507 he_cursor.fh = (void *)buf;
1517 if (hdrs.cb_hdr_valid)
1523 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1526 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1529 if ((lo >= map_len) ||
1530 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1531 (lo + sizeof(struct callback_state_header) < lo)) {
1532 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1538 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1539 hdrs.cb_hdr_p = buf;
1540 hdrs.cb_hdr_valid = 1;
1542 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1545 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1548 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1549 sizeof(struct FEDiskEntry)) +
1550 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1551 if ((hi > map_len) ||
1553 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1559 fe_cursor.ffe = (void *)buf;
1565 get_cb_timeout_hdr(void)
1570 if (hdrs.timeout_hdr_valid)
1576 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1579 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1582 if ((lo >= map_len) ||
1583 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1584 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1585 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1591 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1592 hdrs.timeout_hdr_p = buf;
1593 hdrs.timeout_hdr_valid = 1;
1594 buf += sizeof(struct callback_state_timeout_header);
1595 hdrs.timeout_p = buf;
1601 get_cb_timeout(void)
1606 if (get_cb_timeout_hdr())
1609 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1610 assert(hdrs.timeout != NULL);
1611 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1616 get_cb_fehash_hdr(void)
1621 if (hdrs.fehash_hdr_valid)
1627 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1630 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1633 if ((lo >= map_len) ||
1634 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1635 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1636 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1642 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1643 hdrs.fehash_hdr_p = buf;
1644 hdrs.fehash_hdr_valid = 1;
1645 buf += sizeof(struct callback_state_fehash_header);
1646 hdrs.fehash_p = buf;
1657 if (get_cb_fehash_hdr())
1660 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1661 assert(hdrs.fehash != NULL);
1662 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1667 get_he(afs_uint32 idx)
1675 if (idx >= hdrs.h_hdr.records)
1678 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1681 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1683 if (he_cache.cursor == NULL) {
1684 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1685 assert(he_cache.cursor != NULL);
1688 if (idx && he_cache.cursor[idx-1] == NULL) {
1689 for (i = 0; i < idx; i++) {
1690 if (he_cache.cursor[i] == NULL) {
1697 he_cursor.cursor = he_cursor.fh;
1698 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1699 p = (char *)he_cursor.cursor;
1700 p += he_cursor.hdr.len;
1701 he_cursor.cursor = (void *)p;
1703 he_cursor.cursor = he_cache.cursor[idx-1];
1706 p = (char *)he_cursor.cursor;
1707 p += he_cursor.hdr.len;
1708 he_cursor.cursor = (void *)p;
1711 he_cursor.idx = idx;
1712 he_cache.cursor[idx] = he_cursor.cursor;
1725 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1726 he_cursor.hdr_valid = 1;
1735 if (!he_cursor.hdr_valid) {
1741 p = (char *) he_cursor.cursor;
1742 p += sizeof(struct host_state_entry_header);
1744 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1746 he_cursor.he_valid = 1;
1747 p += sizeof(struct hostDiskEntry);
1748 he_cursor.ifp = (void *)p;
1749 if (he_cursor.hdr.interfaces) {
1750 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1751 he_cursor.hcps = (void *)p;
1753 he_cursor.hcps = he_cursor.ifp;
1759 get_fe(afs_uint32 idx)
1764 cb_cursor.cb_valid = 0;
1769 if (idx >= hdrs.cb_hdr.nFEs)
1772 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1775 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1777 if (fe_cache.cursor == NULL) {
1778 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1779 assert(fe_cache.cursor != NULL);
1782 if (idx && fe_cache.cursor[idx-1] == NULL) {
1783 for (i = 0; i < idx; i++) {
1784 if (fe_cache.cursor[i] == NULL) {
1791 fe_cursor.cursor = fe_cursor.ffe;
1792 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1793 p = (char *)fe_cursor.cursor;
1794 p += fe_cursor.hdr.len;
1795 fe_cursor.cursor = (void *)p;
1797 fe_cursor.cursor = fe_cache.cursor[idx-1];
1800 p = (char *)fe_cursor.cursor;
1801 p += fe_cursor.hdr.len;
1802 fe_cursor.cursor = (void *)p;
1805 fe_cursor.idx = idx;
1806 fe_cache.cursor[idx] = fe_cursor.cursor;
1819 if (!fe_cursor.cursor) {
1820 if(get_fe(fe_cursor.idx)) {
1825 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1826 fe_cursor.hdr_valid = 1;
1835 if (!fe_cursor.hdr_valid) {
1841 p = (char *) fe_cursor.cursor;
1842 p += sizeof(struct callback_state_entry_header);
1844 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1846 fe_cursor.fe_valid = 1;
1847 p += sizeof(struct FEDiskEntry);
1848 fe_cursor.fcb = (void *)p;
1853 get_cb(afs_uint32 idx)
1857 if (get_fe(fe_cursor.idx))
1860 if (idx >= fe_cursor.hdr.nCBs)
1863 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1866 cb_cursor.cb_valid = 0;
1868 p = (char *)fe_cursor.fcb;
1869 p += idx * sizeof(struct CBDiskEntry);
1870 cb_cursor.cursor = (void *)p;
1872 cb_cursor.idx = idx;
1883 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1884 cb_cursor.cb_valid = 1;
1890 find_he_by_index(afs_uint32 idx)
1898 for (i = 0; i < hdrs.h_hdr.records; i++) {
1900 fprintf(stderr, "error getting he %d\n", i);
1903 if (he_cursor.he.index == idx)
1907 if (i < hdrs.h_hdr.records) {
1916 find_fe_by_index(afs_uint32 idx)
1924 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1926 fprintf(stderr, "error getting fe %d\n", i);
1929 if (fe_cursor.fe.index == idx)
1933 if (i < hdrs.cb_hdr.nFEs) {
1941 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1949 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1951 fprintf(stderr, "error getting fe %d\n", i);
1954 if ((fe_cursor.fe.fe.unique == unique) &&
1955 (fe_cursor.fe.fe.volid == volid) &&
1956 (fe_cursor.fe.fe.vnode == vnode))
1960 if (i < hdrs.cb_hdr.nFEs) {
1968 find_cb_by_index(afs_uint32 idx)
1976 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1978 fprintf(stderr, "error getting cb %d\n", i);
1981 if (cb_cursor.cb.index == idx)
1985 if (i < fe_cursor.hdr.nCBs) {
1992 #endif /* AFS_DEMAND_ATTACH_FS */