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;
247 fprintf(stderr, "usage: %s [<state dump file>]\n", prog);
251 main(int argc, char ** argv)
255 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
263 if (openFile(argv[1]))
266 if (openFile(AFSDIR_SERVER_FSSTATE_FILEPATH))
276 openFile(char * path)
279 struct afs_stat status;
281 dump_fd = afs_open(path, O_RDWR);
283 fprintf(stderr, "dump file '%s' failed to open\n", path);
288 printf("opened dump file '%s'\n", path);
290 if (afs_fstat(dump_fd, &status) == -1) {
291 fprintf(stderr, "failed to stat file\n");
296 map_len = status.st_size;
298 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
299 if (map == MAP_FAILED) {
300 fprintf(stderr, "failed to mmap file\n");
305 printf("mapped %d bytes at 0x%x\n", map_len, map);
310 munmap(map, map_len);
324 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
325 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
326 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
327 he_cache.cursor = fe_cache.cursor = NULL;
333 fprintf(stderr, "demand attach fs\n");
334 fprintf(stderr, "fileserver state analyzer\n");
335 fprintf(stderr, "version 0.1\n");
338 #define PROGNAME "fs state analyzer"
344 char prev_input[256];
352 } mode = PR_GLOBAL_MODE, next_mode;
355 input[0] = prev_input[0] = '\0';
361 printf(PROGNAME "> ");
364 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
367 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
370 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
373 fprintf(stderr, "prompt state broken; aborting\n");
378 if (!strcmp(input, "")) {
379 /* repeat last command */
380 if (!strcmp(prev_input, "")) {
383 strlcpy(input, prev_input, sizeof(input));
385 /* save command for repetition */
386 strlcpy(prev_input, input, sizeof(prev_input));
389 tok = strtok(input, " \t");
391 while (tok && !strcmp(tok, ";")) {
392 tok = strtok(NULL, "; \t");
399 if (!strcasecmp(tok, "exit")) {
401 } else if (!strcasecmp(tok, "quit")) {
404 next_mode = PR_FE_MODE;
408 next_mode = PR_GLOBAL_MODE;
413 } else if (!strcasecmp(tok, "h")) {
414 tok = strtok(NULL, " \t");
420 } else if (!strcasecmp(tok, "fe")) {
421 tok = strtok(NULL, " \t");
427 } else if (!strcasecmp(tok, "fs")) {
428 tok = strtok(NULL, " \t");
429 mode = PR_GLOBAL_MODE;
434 } else if (!strcasecmp(tok, "cb")) {
435 tok = strtok(NULL, " \t");
441 } else if (!strcasecmp(tok, "help")) {
456 } else if (!strcasecmp(tok, "hexdump")) {
457 tok = strtok(NULL, " \t");
459 hexdump_map(0, map_len);
462 if (sscanf(tok, "%u", &x) != 1) {
463 fprintf(stderr, "hexdump parse error 1\n");
467 tok = strtok(NULL, " \t");
469 hexdump_map(x, map_len - x);
472 if (sscanf(tok, "%u", &y) != 1) {
473 fprintf(stderr, "hexdump parse error 2\n");
477 } else if (!strcasecmp(tok, "hdr")) {
491 } else if (!strcasecmp(tok, "this")) {
503 fprintf(stderr, "command not valid for this mode\n");
505 } else if (!strcasecmp(tok, "next")) {
517 fprintf(stderr, "command not valid for this mode\n");
519 } else if (!strcasecmp(tok, "prev")) {
531 fprintf(stderr, "command not valid for this mode\n");
533 } else if (!strcasecmp(tok, "first")) {
545 fprintf(stderr, "command not valid for this mode\n");
547 } else if (!strcasecmp(tok, "last")) {
559 fprintf(stderr, "command not valid for this mode\n");
561 } else if (!strcasecmp(tok, "dump")) {
573 fprintf(stderr, "command not valid for this mode\n");
575 } else if (!strcasecmp(tok, "find")) {
576 tok = strtok(NULL, " \t");
577 if (!tok || strcasecmp(tok, "by")) {
579 fprintf(stderr, "find syntax error 1 (%s)\n",
580 (tok) ? tok : "nil");
583 tok = strtok(NULL, " \t");
585 fprintf(stderr, "find syntax error 2\n");
590 fprintf(stderr, "not implemented yet\n");
593 if (!strcasecmp(tok, "index")) {
594 tok = strtok(NULL, " \t");
595 if (!tok || sscanf(tok, "%u", &x) != 1) {
597 fprintf(stderr, "find syntax error 3\n");
600 if (find_fe_by_index(x)) {
601 fprintf(stderr, "find returned no results\n");
603 } else if (!strcasecmp(tok, "fid")) {
604 tok = strtok(NULL, "(), \t");
605 if (!tok || sscanf(tok, "%u", &x) != 1) {
607 fprintf(stderr, "find syntax error 4\n");
610 tok = strtok(NULL, "(), \t");
611 if (!tok || sscanf(tok, "%u", &y) != 1) {
613 fprintf(stderr, "find syntax error 5\n");
616 tok = strtok(NULL, "(), \t");
617 if (!tok || sscanf(tok, "%u", &z) != 1) {
619 fprintf(stderr, "find syntax error 6\n");
622 if (find_fe_by_fid(x,y,z)) {
623 fprintf(stderr, "find returned no results\n");
626 fprintf(stderr, "unsupported filter type\n");
630 if (!strcasecmp(tok, "index")) {
631 tok = strtok(NULL, " \t");
632 if (!tok || sscanf(tok, "%u", &x) != 1) {
634 fprintf(stderr, "find syntax error 3\n");
637 if (find_cb_by_index(x)) {
638 fprintf(stderr, "find returned no results\n");
641 fprintf(stderr, "unsupported filter type\n");
645 fprintf(stderr, "find not supported for this menu\n");
647 } else if (!strcspn(tok, "0123456789")) {
648 if (sscanf(tok, "%u", &x) == 1) {
660 fprintf(stderr, "command not available from this menu\n");
663 fprintf(stderr, "input parse error ('%s')\n", tok);
665 } else if (mode == PR_FE_MODE) {
666 if (!strcmp(tok, "timeout")) {
668 } else if (!strcmp(tok, "hash")) {
672 fprintf(stderr, "unknown command\n");
674 tok = strtok(NULL, " \t");
682 printf("\th <...> -- host menu commands\n");
683 printf("\tfe <...> -- FileEntry menu commands\n");
684 printf("\tcb <...> -- CallBack menu commands\n");
685 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
686 printf("\tquit -- quit this menu\n");
687 printf("\texit -- exit the debugger\n");
688 printf("\thelp -- this help message\n");
692 print_global_help(void)
694 printf("\thdr -- display the fs_state_header struct\n");
700 printf("\thdr -- display the host_state_header struct\n");
701 printf("\tfirst -- display the first host\n");
702 printf("\tprev -- display the previous host\n");
703 printf("\tthis -- display this host\n");
704 printf("\tnext -- display the next host\n");
705 printf("\tlast -- display the last host\n");
706 printf("\tdump -- display all hosts\n");
712 printf("\thdr -- display the callback_state_header struct\n");
713 printf("\tfirst -- display the first FE\n");
714 printf("\tprev -- display the previous FE\n");
715 printf("\tthis -- display this FE\n");
716 printf("\tnext -- display the next FE\n");
717 printf("\tlast -- display the last FE\n");
718 printf("\tdump -- display all FEs\n");
719 printf("\ttimeout -- display the timeout queue heads\n");
720 printf("\thash -- display the file entry hash buckets\n");
721 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
722 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
728 printf("\thdr -- display the callback_state_entry_header struct\n");
729 printf("\tfirst -- display the first CB\n");
730 printf("\tprev -- display the previous CB\n");
731 printf("\tthis -- display this CB\n");
732 printf("\tnext -- display the next CB\n");
733 printf("\tlast -- display the last CB\n");
734 printf("\tdump -- display all CBs\n");
738 #define DPFTB1 "\t\t"
739 #define DPFTB2 "\t\t\t"
741 #define DPFOFF(addr) \
743 char * _p = (char *)addr; \
744 char * _m = (char *)map; \
745 printf("loading structure from address 0x%x (offset %u)\n", \
750 #define DPFSO(T, name) printf(T "%s = {\n", name)
751 #define DPFSO0(name) DPFSO(DPFTB0, name)
752 #define DPFSO1(name) DPFSO(DPFTB1, name)
753 #define DPFSC(T) printf(T "}\n")
754 #define DPFSC0 DPFSC(DPFTB0)
755 #define DPFSC1 DPFSC(DPFTB1)
758 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
759 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
760 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
761 #define DPFAC0 printf(" }\n")
762 #define DPFAC1 DPFAC0
763 #define DPFA1 printf(DPFTB1 " ")
764 #define DPFA2 printf(DPFTB2 " ")
765 #define DPFAN printf("\n")
766 #define DPFALE(type, var) printf("%" type, var)
767 #define DPFAE(type, var) printf("%" type ",\t", var)
770 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
771 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
772 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
775 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
776 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
777 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
780 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
781 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
782 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
785 #define DPFT(T, name, var) \
788 printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \
790 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
791 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
803 DPFSO0("fs_state_header");
805 DPFX2("magic", hdrs.hdr.stamp.magic);
806 DPFV2("version", "u", hdrs.hdr.stamp.version);
808 DPFT1("timestamp", hdrs.hdr.timestamp);
809 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
811 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
812 DPFS1("server_uuid", uuid_str);
813 DPFV1("valid", "d", hdrs.hdr.valid);
814 DPFV1("endianness", "d", hdrs.hdr.endianness);
815 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
817 SplitInt64(hdrs.hdr.h_offset, hi, lo);
819 DPFV2("hi", "u", hi);
820 DPFV2("lo", "u", lo);
823 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
825 DPFV2("hi", "u", hi);
826 DPFV2("lo", "u", lo);
829 DPFS1("server_version_string", hdrs.hdr.server_version_string);
832 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
833 fprintf(stderr, "* magic check failed\n");
835 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
836 fprintf(stderr, "* version check failed\n");
846 DPFOFF(hdrs.h_hdr_p);
847 DPFSO0("host_state_header");
849 DPFX2("magic", hdrs.h_hdr.stamp.magic);
850 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
852 DPFV1("records", "u", hdrs.h_hdr.records);
853 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
856 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
857 fprintf(stderr, "* magic check failed\n");
859 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
860 fprintf(stderr, "* version check failed\n");
872 DPFOFF(hdrs.cb_hdr_p);
873 DPFSO0("callback_state_header");
875 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
876 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
878 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
879 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
880 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
881 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
882 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
884 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
885 DPFSO1("timeout_offset");
886 DPFV2("hi", "u", hi);
887 DPFV2("lo", "u", lo);
890 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
891 DPFSO1("fehash_offset");
892 DPFV2("hi", "u", hi);
893 DPFV2("lo", "u", lo);
896 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
898 DPFV2("hi", "u", hi);
899 DPFV2("lo", "u", lo);
904 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
905 fprintf(stderr, "* magic check failed\n");
907 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
908 fprintf(stderr, "* version check failed\n");
913 dump_cb_timeout(void)
920 if (get_cb_timeout_hdr())
923 if (get_cb_timeout())
926 DPFOFF(hdrs.timeout_hdr_p);
927 DPFSO0("callback_state_timeout_header");
928 DPFX1("magic", hdrs.timeout_hdr.magic);
929 DPFV1("len", "u", hdrs.timeout_hdr.len);
930 DPFV1("records", "u", hdrs.timeout_hdr.records);
933 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
934 fprintf(stderr, "* magic check failed\n");
937 DPFOFF(hdrs.timeout_p);
939 for (i = 0; i < 127; i++) {
940 DPFAE("u", hdrs.timeout[i]);
946 DPFALE("u", hdrs.timeout[127]);
958 if (get_cb_fehash_hdr())
964 DPFOFF(hdrs.fehash_hdr_p);
965 DPFSO0("callback_state_fehash_header");
966 DPFX1("magic", hdrs.fehash_hdr.magic);
967 DPFV1("len", "u", hdrs.fehash_hdr.len);
968 DPFV1("records", "u", hdrs.fehash_hdr.records);
971 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
972 fprintf(stderr, "* magic check failed\n");
975 DPFOFF(hdrs.fehash_p);
977 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
978 DPFAE("u", hdrs.fehash[i]);
984 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
994 fprintf(stderr, "error getting host_state_header\n");
998 for (i = 0; i < hdrs.h_hdr.records; i++) {
1009 fprintf(stderr, "error getting callback_state_header\n");
1013 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1024 fprintf(stderr, "error getting callback_state_entry_header\n");
1028 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1034 dump_he(afs_uint32 idx)
1037 fprintf(stderr, "error getting he %d\n", idx);
1041 DPFOFF(he_cursor.cursor);
1044 dump_he_interfaces();
1049 dump_fe(afs_uint32 idx)
1052 fprintf(stderr, "error getting fe %d\n", idx);
1056 DPFOFF(fe_cursor.cursor);
1062 dump_cb(afs_uint32 idx)
1065 fprintf(stderr, "error getting cb %d\n", idx);
1069 DPFOFF(cb_cursor.cursor);
1076 dump_he(he_cursor.idx);
1082 dump_fe(fe_cursor.idx);
1088 dump_cb(cb_cursor.idx);
1095 fprintf(stderr, "error getting host_state_header\n");
1099 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1100 fprintf(stderr, "no more HEs\n");
1104 dump_he(he_cursor.idx+1);
1111 fprintf(stderr, "error getting callback_state_header\n");
1115 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1116 fprintf(stderr, "no more FEs\n");
1120 dump_fe(fe_cursor.idx+1);
1127 fprintf(stderr, "error getting callback_state_entry_header\n");
1131 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1132 fprintf(stderr, "no more CBs\n");
1136 dump_cb(cb_cursor.idx+1);
1142 if (!he_cursor.idx) {
1143 fprintf(stderr, "no more HEs\n");
1147 dump_he(he_cursor.idx-1);
1153 if (!fe_cursor.idx) {
1154 fprintf(stderr, "no more FEs\n");
1158 dump_fe(fe_cursor.idx-1);
1164 if (!cb_cursor.idx) {
1165 fprintf(stderr, "no more CBs\n");
1169 dump_cb(cb_cursor.idx-1);
1176 fprintf(stderr, "error getting callback_state_header\n");
1180 if (!hdrs.cb_hdr.nFEs) {
1181 fprintf(stderr, "no FEs present\n");
1192 fprintf(stderr, "error getting host_state_header\n");
1196 if (!hdrs.h_hdr.records) {
1197 fprintf(stderr, "no HEs present\n");
1208 fprintf(stderr, "error getting callback_state_entry_header\n");
1212 if (!fe_cursor.hdr.nCBs) {
1213 fprintf(stderr, "no CBs present\n");
1224 fprintf(stderr, "error getting host_state_header\n");
1228 if (!hdrs.h_hdr.records) {
1229 fprintf(stderr, "no HEs present\n");
1233 dump_he(hdrs.h_hdr.records-1);
1240 fprintf(stderr, "error getting callback_state_header\n");
1244 if (!hdrs.cb_hdr.nFEs) {
1245 fprintf(stderr, "no FEs present\n");
1249 dump_fe(hdrs.cb_hdr.nFEs-1);
1256 fprintf(stderr, "error getting callback_state_entry_header\n");
1260 if (!fe_cursor.hdr.nCBs) {
1261 fprintf(stderr, "no CBs present\n");
1265 dump_cb(fe_cursor.hdr.nCBs-1);
1271 DPFSO0("host_state_entry_header");
1272 DPFX1("magic", he_cursor.hdr.magic);
1273 DPFV1("len", "u", he_cursor.hdr.len);
1274 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1275 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1278 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1279 fprintf(stderr, "* magic check failed\n");
1286 DPFSO0("hostDiskEntry");
1287 DPFS1("host", afs_inet_ntoa(he_cursor.he.host));
1288 DPFV1("port", "u", he_cursor.he.port);
1289 DPFX1("hostFlags", he_cursor.he.hostFlags);
1290 DPFV1("Console", "u", he_cursor.he.Console);
1291 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1292 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1293 if (hdrs.hdr.stats_detailed) {
1294 #ifdef FS_STATS_DETAILED
1295 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1297 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1300 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1301 DPFT1("LastCall", he_cursor.he.LastCall);
1302 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1303 DPFT1("cpsCall", he_cursor.he.cpsCall);
1304 DPFV1("cblist", "u", he_cursor.he.cblist);
1305 DPFV1("index", "u", he_cursor.he.index);
1310 dump_he_interfaces(void)
1313 struct Interface * ifp;
1316 if (!he_cursor.hdr.interfaces)
1319 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1320 ifp = (struct Interface *) malloc(len);
1321 assert(ifp != NULL);
1323 memcpy(ifp, he_cursor.ifp, len);
1325 DPFSO0("Interface");
1326 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1328 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1329 DPFS1("uuid", temp_str);
1330 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1331 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1333 DPFS2("addr", afs_inet_ntoa(ifp->interface[i].addr));
1334 DPFV2("port", "u", ifp->interface[i].port);
1340 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1341 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1353 if (!he_cursor.hdr.hcps)
1356 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1357 hcps = (afs_int32 *) malloc(len);
1358 assert(hcps != NULL);
1359 memcpy(hcps, he_cursor.hcps, len);
1362 DPFAO1("prlist_val");
1363 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1364 DPFAE("d", hcps[i]);
1370 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1379 DPFSO0("callback_state_entry_header");
1380 DPFX1("magic", fe_cursor.hdr.magic);
1381 DPFV1("len", "u", fe_cursor.hdr.len);
1382 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1385 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1386 fprintf(stderr, "* magic check failed\n");
1393 DPFSO0("FEDiskEntry");
1395 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1396 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1397 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1398 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1399 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1400 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1401 DPFV2("status", "u", fe_cursor.fe.fe.status);
1403 DPFV1("index", "u", fe_cursor.fe.index);
1410 DPFSO0("CBDiskEntry");
1412 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1413 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1414 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1415 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1416 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1417 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1418 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1419 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1420 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1422 DPFV1("index", "u", cb_cursor.cb.index);
1426 #define DPFHMS printf(" ")
1427 #define DPFHS printf(" ")
1428 #define DPFHN(offset) printf("\n%u\t", offset)
1429 #define DPFHD(x) printf("%02X ", x)
1430 #define DPFHE printf("\n")
1433 hexdump_map(afs_uint32 offset, afs_uint32 len)
1436 unsigned char * p = (unsigned char *)map;
1442 if ((offset + len) > map_len) {
1443 fprintf(stderr, "offset + length exceeds memory map size (%u > %u)\n",
1444 offset+len, map_len);
1452 for (i = offset % 16; i > 0; i--) {
1456 for (i=0; i < len; i++, p++, offset++) {
1457 if (!(offset % 16)) {
1459 } else if (!(offset % 8)) {
1470 if (!hdrs.hdr_valid) {
1471 if (map_len < sizeof(struct fs_state_header)) {
1472 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1475 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1488 if (hdrs.h_hdr_valid)
1494 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1497 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1500 if ((lo >= map_len) ||
1501 ((lo + sizeof(struct host_state_header)) > map_len) ||
1502 (lo + sizeof(struct host_state_header) < lo)) {
1503 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1509 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1511 buf += sizeof(struct host_state_header);
1512 he_cursor.fh = (void *)buf;
1522 if (hdrs.cb_hdr_valid)
1528 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1531 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1534 if ((lo >= map_len) ||
1535 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1536 (lo + sizeof(struct callback_state_header) < lo)) {
1537 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1543 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1544 hdrs.cb_hdr_p = buf;
1545 hdrs.cb_hdr_valid = 1;
1547 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1550 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1553 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1554 sizeof(struct FEDiskEntry)) +
1555 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1556 if ((hi > map_len) ||
1558 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1564 fe_cursor.ffe = (void *)buf;
1570 get_cb_timeout_hdr(void)
1575 if (hdrs.timeout_hdr_valid)
1581 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1584 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1587 if ((lo >= map_len) ||
1588 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1589 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1590 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1596 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1597 hdrs.timeout_hdr_p = buf;
1598 hdrs.timeout_hdr_valid = 1;
1599 buf += sizeof(struct callback_state_timeout_header);
1600 hdrs.timeout_p = buf;
1606 get_cb_timeout(void)
1613 if (get_cb_timeout_hdr())
1616 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1617 assert(hdrs.timeout != NULL);
1618 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1623 get_cb_fehash_hdr(void)
1628 if (hdrs.fehash_hdr_valid)
1634 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1637 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1640 if ((lo >= map_len) ||
1641 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1642 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1643 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1649 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1650 hdrs.fehash_hdr_p = buf;
1651 hdrs.fehash_hdr_valid = 1;
1652 buf += sizeof(struct callback_state_fehash_header);
1653 hdrs.fehash_p = buf;
1666 if (get_cb_fehash_hdr())
1669 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1670 assert(hdrs.fehash != NULL);
1671 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1676 get_he(afs_uint32 idx)
1684 if (idx >= hdrs.h_hdr.records)
1687 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1690 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1692 if (he_cache.cursor == NULL) {
1693 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1694 assert(he_cache.cursor != NULL);
1697 if (idx && he_cache.cursor[idx-1] == NULL) {
1698 for (i = 0; i < idx; i++) {
1699 if (he_cache.cursor[i] == NULL) {
1706 he_cursor.cursor = he_cursor.fh;
1707 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1708 p = (char *)he_cursor.cursor;
1709 p += he_cursor.hdr.len;
1710 he_cursor.cursor = (void *)p;
1712 he_cursor.cursor = he_cache.cursor[idx-1];
1715 p = (char *)he_cursor.cursor;
1716 p += he_cursor.hdr.len;
1717 he_cursor.cursor = (void *)p;
1720 he_cursor.idx = idx;
1721 he_cache.cursor[idx] = he_cursor.cursor;
1734 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1735 he_cursor.hdr_valid = 1;
1744 if (!he_cursor.hdr_valid) {
1750 p = (char *) he_cursor.cursor;
1751 p += sizeof(struct host_state_entry_header);
1753 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1755 he_cursor.he_valid = 1;
1756 p += sizeof(struct hostDiskEntry);
1757 he_cursor.ifp = (void *)p;
1758 if (he_cursor.hdr.interfaces) {
1759 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1760 he_cursor.hcps = (void *)p;
1762 he_cursor.hcps = he_cursor.ifp;
1768 get_fe(afs_uint32 idx)
1773 cb_cursor.cb_valid = 0;
1778 if (idx >= hdrs.cb_hdr.nFEs)
1781 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1784 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1786 if (fe_cache.cursor == NULL) {
1787 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1788 assert(fe_cache.cursor != NULL);
1791 if (idx && fe_cache.cursor[idx-1] == NULL) {
1792 for (i = 0; i < idx; i++) {
1793 if (fe_cache.cursor[i] == NULL) {
1800 fe_cursor.cursor = fe_cursor.ffe;
1801 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1802 p = (char *)fe_cursor.cursor;
1803 p += fe_cursor.hdr.len;
1804 fe_cursor.cursor = (void *)p;
1806 fe_cursor.cursor = fe_cache.cursor[idx-1];
1809 p = (char *)fe_cursor.cursor;
1810 p += fe_cursor.hdr.len;
1811 fe_cursor.cursor = (void *)p;
1814 fe_cursor.idx = idx;
1815 fe_cache.cursor[idx] = fe_cursor.cursor;
1828 if (!fe_cursor.cursor) {
1829 if(get_fe(fe_cursor.idx)) {
1834 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1835 fe_cursor.hdr_valid = 1;
1844 if (!fe_cursor.hdr_valid) {
1850 p = (char *) fe_cursor.cursor;
1851 p += sizeof(struct callback_state_entry_header);
1853 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1855 fe_cursor.fe_valid = 1;
1856 p += sizeof(struct FEDiskEntry);
1857 fe_cursor.fcb = (void *)p;
1862 get_cb(afs_uint32 idx)
1867 if (get_fe(fe_cursor.idx))
1870 if (idx >= fe_cursor.hdr.nCBs)
1873 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1876 cb_cursor.cb_valid = 0;
1878 p = (char *)fe_cursor.fcb;
1879 p += idx * sizeof(struct CBDiskEntry);
1880 cb_cursor.cursor = (void *)p;
1882 cb_cursor.idx = idx;
1893 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1894 cb_cursor.cb_valid = 1;
1899 find_he_by_index(afs_uint32 idx)
1907 for (i = 0; i < hdrs.h_hdr.records; i++) {
1909 fprintf(stderr, "error getting he %d\n", i);
1912 if (he_cursor.he.index == idx)
1916 if (i < hdrs.h_hdr.records) {
1924 find_fe_by_index(afs_uint32 idx)
1932 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1934 fprintf(stderr, "error getting fe %d\n", i);
1937 if (fe_cursor.fe.index == idx)
1941 if (i < hdrs.cb_hdr.nFEs) {
1949 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1957 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1959 fprintf(stderr, "error getting fe %d\n", i);
1962 if ((fe_cursor.fe.fe.unique == unique) &&
1963 (fe_cursor.fe.fe.volid == volid) &&
1964 (fe_cursor.fe.fe.vnode == vnode))
1968 if (i < hdrs.cb_hdr.nFEs) {
1976 find_cb_by_index(afs_uint32 idx)
1984 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1986 fprintf(stderr, "error getting cb %d\n", i);
1989 if (cb_cursor.cb.index == idx)
1993 if (i < fe_cursor.hdr.nCBs) {
2000 #endif /* AFS_DEMAND_ATTACH_FS */