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");
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 %u)\n", \
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");
1281 DPFSO0("hostDiskEntry");
1282 DPFS1("host", afs_inet_ntoa(he_cursor.he.host));
1283 DPFV1("port", "u", he_cursor.he.port);
1284 DPFX1("hostFlags", he_cursor.he.hostFlags);
1285 DPFV1("Console", "u", he_cursor.he.Console);
1286 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1287 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1288 if (hdrs.hdr.stats_detailed) {
1289 #ifdef FS_STATS_DETAILED
1290 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1292 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1295 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1296 DPFT1("LastCall", he_cursor.he.LastCall);
1297 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1298 DPFT1("cpsCall", he_cursor.he.cpsCall);
1299 DPFV1("cblist", "u", he_cursor.he.cblist);
1300 DPFV1("index", "u", he_cursor.he.index);
1305 dump_he_interfaces(void)
1308 struct Interface * ifp;
1311 if (!he_cursor.hdr.interfaces)
1314 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1315 ifp = (struct Interface *) malloc(len);
1316 assert(ifp != NULL);
1318 memcpy(ifp, he_cursor.ifp, len);
1320 DPFSO0("Interface");
1321 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1323 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1324 DPFS1("uuid", temp_str);
1325 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1326 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1328 DPFS2("addr", afs_inet_ntoa(ifp->interface[i].addr));
1329 DPFV2("port", "u", ifp->interface[i].port);
1335 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1336 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1347 if (!he_cursor.hdr.hcps)
1350 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1351 hcps = (afs_int32 *) malloc(len);
1352 assert(hcps != NULL);
1353 memcpy(hcps, he_cursor.hcps, len);
1356 DPFAO1("prlist_val");
1357 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1358 DPFAE("d", hcps[i]);
1364 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1373 DPFSO0("callback_state_entry_header");
1374 DPFX1("magic", fe_cursor.hdr.magic);
1375 DPFV1("len", "u", fe_cursor.hdr.len);
1376 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1379 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1380 fprintf(stderr, "* magic check failed\n");
1387 DPFSO0("FEDiskEntry");
1389 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1390 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1391 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1392 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1393 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1394 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1395 DPFV2("status", "u", fe_cursor.fe.fe.status);
1397 DPFV1("index", "u", fe_cursor.fe.index);
1404 DPFSO0("CBDiskEntry");
1406 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1407 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1408 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1409 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1410 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1411 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1412 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1413 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1414 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1416 DPFV1("index", "u", cb_cursor.cb.index);
1420 #define DPFHMS printf(" ")
1421 #define DPFHS printf(" ")
1422 #define DPFHN(offset) printf("\n%u\t", offset)
1423 #define DPFHD(x) printf("%02X ", x)
1424 #define DPFHE printf("\n")
1427 hexdump_map(afs_uint32 offset, afs_uint32 len)
1430 unsigned char * p = (unsigned char *)map;
1435 if ((offset + len) > map_len) {
1436 fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n",
1437 offset+len, (unsigned long)map_len);
1445 for (i = offset % 16; i > 0; i--) {
1449 for (i=0; i < len; i++, p++, offset++) {
1450 if (!(offset % 16)) {
1452 } else if (!(offset % 8)) {
1463 if (!hdrs.hdr_valid) {
1464 if (map_len < sizeof(struct fs_state_header)) {
1465 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1468 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1481 if (hdrs.h_hdr_valid)
1487 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1490 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1493 if ((lo >= map_len) ||
1494 ((lo + sizeof(struct host_state_header)) > map_len) ||
1495 (lo + sizeof(struct host_state_header) < lo)) {
1496 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1502 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1504 buf += sizeof(struct host_state_header);
1505 he_cursor.fh = (void *)buf;
1515 if (hdrs.cb_hdr_valid)
1521 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1524 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1527 if ((lo >= map_len) ||
1528 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1529 (lo + sizeof(struct callback_state_header) < lo)) {
1530 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1536 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1537 hdrs.cb_hdr_p = buf;
1538 hdrs.cb_hdr_valid = 1;
1540 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1543 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1546 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1547 sizeof(struct FEDiskEntry)) +
1548 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1549 if ((hi > map_len) ||
1551 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1557 fe_cursor.ffe = (void *)buf;
1563 get_cb_timeout_hdr(void)
1568 if (hdrs.timeout_hdr_valid)
1574 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1577 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1580 if ((lo >= map_len) ||
1581 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1582 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1583 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1589 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1590 hdrs.timeout_hdr_p = buf;
1591 hdrs.timeout_hdr_valid = 1;
1592 buf += sizeof(struct callback_state_timeout_header);
1593 hdrs.timeout_p = buf;
1599 get_cb_timeout(void)
1604 if (get_cb_timeout_hdr())
1607 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1608 assert(hdrs.timeout != NULL);
1609 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1614 get_cb_fehash_hdr(void)
1619 if (hdrs.fehash_hdr_valid)
1625 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1628 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1631 if ((lo >= map_len) ||
1632 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1633 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1634 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1640 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1641 hdrs.fehash_hdr_p = buf;
1642 hdrs.fehash_hdr_valid = 1;
1643 buf += sizeof(struct callback_state_fehash_header);
1644 hdrs.fehash_p = buf;
1655 if (get_cb_fehash_hdr())
1658 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1659 assert(hdrs.fehash != NULL);
1660 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1665 get_he(afs_uint32 idx)
1673 if (idx >= hdrs.h_hdr.records)
1676 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1679 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1681 if (he_cache.cursor == NULL) {
1682 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1683 assert(he_cache.cursor != NULL);
1686 if (idx && he_cache.cursor[idx-1] == NULL) {
1687 for (i = 0; i < idx; i++) {
1688 if (he_cache.cursor[i] == NULL) {
1695 he_cursor.cursor = he_cursor.fh;
1696 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1697 p = (char *)he_cursor.cursor;
1698 p += he_cursor.hdr.len;
1699 he_cursor.cursor = (void *)p;
1701 he_cursor.cursor = he_cache.cursor[idx-1];
1704 p = (char *)he_cursor.cursor;
1705 p += he_cursor.hdr.len;
1706 he_cursor.cursor = (void *)p;
1709 he_cursor.idx = idx;
1710 he_cache.cursor[idx] = he_cursor.cursor;
1723 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1724 he_cursor.hdr_valid = 1;
1733 if (!he_cursor.hdr_valid) {
1739 p = (char *) he_cursor.cursor;
1740 p += sizeof(struct host_state_entry_header);
1742 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1744 he_cursor.he_valid = 1;
1745 p += sizeof(struct hostDiskEntry);
1746 he_cursor.ifp = (void *)p;
1747 if (he_cursor.hdr.interfaces) {
1748 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1749 he_cursor.hcps = (void *)p;
1751 he_cursor.hcps = he_cursor.ifp;
1757 get_fe(afs_uint32 idx)
1762 cb_cursor.cb_valid = 0;
1767 if (idx >= hdrs.cb_hdr.nFEs)
1770 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1773 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1775 if (fe_cache.cursor == NULL) {
1776 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1777 assert(fe_cache.cursor != NULL);
1780 if (idx && fe_cache.cursor[idx-1] == NULL) {
1781 for (i = 0; i < idx; i++) {
1782 if (fe_cache.cursor[i] == NULL) {
1789 fe_cursor.cursor = fe_cursor.ffe;
1790 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1791 p = (char *)fe_cursor.cursor;
1792 p += fe_cursor.hdr.len;
1793 fe_cursor.cursor = (void *)p;
1795 fe_cursor.cursor = fe_cache.cursor[idx-1];
1798 p = (char *)fe_cursor.cursor;
1799 p += fe_cursor.hdr.len;
1800 fe_cursor.cursor = (void *)p;
1803 fe_cursor.idx = idx;
1804 fe_cache.cursor[idx] = fe_cursor.cursor;
1817 if (!fe_cursor.cursor) {
1818 if(get_fe(fe_cursor.idx)) {
1823 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1824 fe_cursor.hdr_valid = 1;
1833 if (!fe_cursor.hdr_valid) {
1839 p = (char *) fe_cursor.cursor;
1840 p += sizeof(struct callback_state_entry_header);
1842 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1844 fe_cursor.fe_valid = 1;
1845 p += sizeof(struct FEDiskEntry);
1846 fe_cursor.fcb = (void *)p;
1851 get_cb(afs_uint32 idx)
1855 if (get_fe(fe_cursor.idx))
1858 if (idx >= fe_cursor.hdr.nCBs)
1861 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1864 cb_cursor.cb_valid = 0;
1866 p = (char *)fe_cursor.fcb;
1867 p += idx * sizeof(struct CBDiskEntry);
1868 cb_cursor.cursor = (void *)p;
1870 cb_cursor.idx = idx;
1881 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1882 cb_cursor.cb_valid = 1;
1888 find_he_by_index(afs_uint32 idx)
1896 for (i = 0; i < hdrs.h_hdr.records; i++) {
1898 fprintf(stderr, "error getting he %d\n", i);
1901 if (he_cursor.he.index == idx)
1905 if (i < hdrs.h_hdr.records) {
1914 find_fe_by_index(afs_uint32 idx)
1922 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1924 fprintf(stderr, "error getting fe %d\n", i);
1927 if (fe_cursor.fe.index == idx)
1931 if (i < hdrs.cb_hdr.nFEs) {
1939 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1947 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1949 fprintf(stderr, "error getting fe %d\n", i);
1952 if ((fe_cursor.fe.fe.unique == unique) &&
1953 (fe_cursor.fe.fe.volid == volid) &&
1954 (fe_cursor.fe.fe.vnode == vnode))
1958 if (i < hdrs.cb_hdr.nFEs) {
1966 find_cb_by_index(afs_uint32 idx)
1974 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1976 fprintf(stderr, "error getting cb %d\n", i);
1979 if (cb_cursor.cb.index == idx)
1983 if (i < fe_cursor.hdr.nCBs) {
1990 #endif /* AFS_DEMAND_ATTACH_FS */