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>
27 #include <netinet/in.h>
40 #include <afs/assert.h>
43 #include <afs/afsint.h>
44 #include <afs/rxgen_consts.h>
46 #include <afs/errors.h>
47 #include <afs/ihandle.h>
48 #include <afs/vnode.h>
49 #include <afs/volume.h>
50 #ifdef AFS_ATHENA_STDENV
54 #include <afs/ptclient.h>
55 #include <afs/prs_fs.h>
57 #include <afs/afsutil.h>
59 #include <afs/cellconfig.h>
61 #include "../util/afsutil_prototypes.h"
62 #include "../viced/viced.h"
63 #include "../viced/host.h"
64 #include "../viced/callback.h"
65 #include "serialize_state.h"
67 #include <sys/types.h>
72 /*@+fcnmacros +macrofcndecl@*/
75 extern off64_t afs_lseek(int FD, off64_t O, int F);
76 #endif /*S_SPLINT_S */
77 #define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F)
78 #define afs_stat stat64
79 #define afs_fstat fstat64
80 #define afs_open open64
81 #define afs_fopen fopen64
82 #define afs_mmap mmap64
84 extern void * mmap64(); /* ugly hack since aix build env appears to be somewhat broken */
86 #else /* !O_LARGEFILE */
88 extern off_t afs_lseek(int FD, off_t O, int F);
89 #endif /*S_SPLINT_S */
90 #define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F)
92 #define afs_fstat fstat
94 #define afs_fopen fopen
96 #endif /* !O_LARGEFILE */
97 /*@=fcnmacros =macrofcndecl@*/
100 #ifndef AFS_DEMAND_ATTACH_FS
102 main (int argc, char ** argv)
104 fprintf(stderr, "%s is only supported for demand attach fileservers\n",
105 argv[0] ? argv[0] : "state analyzer");
108 #else /* AFS_DEMAND_ATTACH_FS */
110 static void usage(char * prog);
111 static int openFile(char * path);
112 static void initState(void);
114 static void banner(void);
115 static void prompt(void);
117 static void print_help(void);
118 static void print_global_help(void);
119 static void print_h_help(void);
120 static void print_fe_help(void);
121 static void print_cb_help(void);
123 static void dump_hdr(void);
124 static void dump_h_hdr(void);
125 static void dump_cb_hdr(void);
127 static void dump_cb_timeout(void);
128 static void dump_cb_fehash(void);
130 static void dump_all_hes(void);
131 static void dump_all_fes(void);
132 static void dump_all_cbs(void);
134 static void dump_he(afs_uint32 idx);
135 static void dump_fe(afs_uint32 idx);
136 static void dump_cb(afs_uint32 idx);
137 static void dump_this_he(void);
138 static void dump_this_fe(void);
139 static void dump_this_cb(void);
140 static void dump_next_he(void);
141 static void dump_next_fe(void);
142 static void dump_next_cb(void);
143 static void dump_prev_he(void);
144 static void dump_prev_fe(void);
145 static void dump_prev_cb(void);
146 static void dump_first_he(void);
147 static void dump_first_fe(void);
148 static void dump_first_cb(void);
149 static void dump_last_he(void);
150 static void dump_last_fe(void);
151 static void dump_last_cb(void);
152 static void dump_he_hdr(void);
153 static void dump_he_entry(void);
154 static void dump_he_interfaces(void);
155 static void dump_he_hcps(void);
156 static void dump_fe_hdr(void);
157 static void dump_fe_entry(void);
158 static void dump_cb_entry(void);
160 static void hexdump_map(afs_uint32 offset, afs_uint32 len);
162 static int get_hdr(void);
163 static int get_h_hdr(void);
164 static int get_cb_hdr(void);
165 static int get_cb_timeout_hdr(void);
166 static int get_cb_timeout(void);
167 static int get_cb_fehash_hdr(void);
168 static int get_cb_fehash(void);
169 static int get_he(afs_uint32 idx);
170 static int get_he_hdr(void);
171 static int get_he_entry(void);
172 static int get_fe(afs_uint32 idx);
173 static int get_fe_hdr(void);
174 static int get_fe_entry(void);
175 static int get_cb(afs_uint32 idx);
176 static int get_cb_entry(void);
178 static int find_fe_by_index(afs_uint32 idx);
179 static int find_cb_by_index(afs_uint32 idx);
180 static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq);
183 static int dump_fd = -1;
184 static void * map = NULL;
185 static size_t map_len;
188 struct fs_state_header hdr;
189 struct host_state_header h_hdr;
190 struct callback_state_header cb_hdr;
191 struct callback_state_timeout_header timeout_hdr;
192 struct callback_state_fehash_header fehash_hdr;
193 afs_uint32 * timeout;
196 /* pointers into the memory map */
200 void * timeout_hdr_p;
208 byte timeout_hdr_valid;
209 byte fehash_hdr_valid;
217 struct host_state_entry_header hdr;
218 struct hostDiskEntry he;
232 struct callback_state_entry_header hdr;
233 struct FEDiskEntry fe;
245 struct CBDiskEntry cb;
257 fprintf(stderr, "usage: %s [<state dump file>]\n");
261 main(int argc, char ** argv)
265 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
273 if (openFile(argv[1]))
276 if (openFile(AFSDIR_SERVER_FSSTATE_FILEPATH))
286 openFile(char * path)
289 struct afs_stat status;
291 dump_fd = afs_open(path, O_RDWR);
293 fprintf(stderr, "dump file '%s' failed to open\n", path);
298 printf("opened dump file '%s'\n", path);
300 if (afs_fstat(dump_fd, &status) == -1) {
301 fprintf(stderr, "failed to stat file\n");
306 map_len = status.st_size;
308 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
309 if (map == MAP_FAILED) {
310 fprintf(stderr, "failed to mmap file\n");
315 printf("mapped %d bytes at 0x%x\n", map_len, map);
320 munmap(map, map_len);
334 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
335 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
336 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
337 he_cache.cursor = fe_cache.cursor = NULL;
343 fprintf(stderr, "demand attach fs\n");
344 fprintf(stderr, "fileserver state analyzer\n");
345 fprintf(stderr, "version 0.1\n");
348 #define PROGNAME "fs state analyzer"
354 char prev_input[256];
362 } mode = PR_GLOBAL_MODE, next_mode;
365 input[0] = prev_input[0] = '\0';
371 printf(PROGNAME "> ");
374 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
377 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
380 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
383 fprintf(stderr, "prompt state broken; aborting\n");
388 if (!strcmp(input, "")) {
389 /* repeat last command */
390 if (!strcmp(prev_input, "")) {
393 strlcpy(input, prev_input, sizeof(input));
395 /* save command for repetition */
396 strlcpy(prev_input, input, sizeof(prev_input));
399 tok = strtok(input, " \t");
401 while (tok && !strcmp(tok, ";")) {
402 tok = strtok(NULL, "; \t");
409 if (!strcasecmp(tok, "exit")) {
411 } else if (!strcasecmp(tok, "quit")) {
414 next_mode = PR_FE_MODE;
418 next_mode = PR_GLOBAL_MODE;
423 } else if (!strcasecmp(tok, "h")) {
424 tok = strtok(NULL, " \t");
430 } else if (!strcasecmp(tok, "fe")) {
431 tok = strtok(NULL, " \t");
437 } else if (!strcasecmp(tok, "fs")) {
438 tok = strtok(NULL, " \t");
439 mode = PR_GLOBAL_MODE;
444 } else if (!strcasecmp(tok, "cb")) {
445 tok = strtok(NULL, " \t");
451 } else if (!strcasecmp(tok, "help")) {
466 } else if (!strcasecmp(tok, "hexdump")) {
467 tok = strtok(NULL, " \t");
469 hexdump_map(0, map_len);
472 if (sscanf(tok, "%u", &x) != 1) {
473 fprintf(stderr, "hexdump parse error 1\n");
477 tok = strtok(NULL, " \t");
479 hexdump_map(x, map_len - x);
482 if (sscanf(tok, "%u", &y) != 1) {
483 fprintf(stderr, "hexdump parse error 2\n");
487 } else if (!strcasecmp(tok, "hdr")) {
501 } else if (!strcasecmp(tok, "this")) {
513 fprintf(stderr, "command not valid for this mode\n");
515 } else if (!strcasecmp(tok, "next")) {
527 fprintf(stderr, "command not valid for this mode\n");
529 } else if (!strcasecmp(tok, "prev")) {
541 fprintf(stderr, "command not valid for this mode\n");
543 } else if (!strcasecmp(tok, "first")) {
555 fprintf(stderr, "command not valid for this mode\n");
557 } else if (!strcasecmp(tok, "last")) {
569 fprintf(stderr, "command not valid for this mode\n");
571 } else if (!strcasecmp(tok, "dump")) {
583 fprintf(stderr, "command not valid for this mode\n");
585 } else if (!strcasecmp(tok, "find")) {
586 tok = strtok(NULL, " \t");
587 if (!tok || strcasecmp(tok, "by")) {
589 fprintf(stderr, "find syntax error 1 (%s)\n",
590 (tok) ? tok : "nil");
593 tok = strtok(NULL, " \t");
595 fprintf(stderr, "find syntax error 2\n");
600 fprintf(stderr, "not implemented yet\n");
603 if (!strcasecmp(tok, "index")) {
604 tok = strtok(NULL, " \t");
605 if (!tok || sscanf(tok, "%u", &x) != 1) {
607 fprintf(stderr, "find syntax error 3\n");
610 if (find_fe_by_index(x)) {
611 fprintf(stderr, "find returned no results\n");
613 } else if (!strcasecmp(tok, "fid")) {
614 tok = strtok(NULL, "(), \t");
615 if (!tok || sscanf(tok, "%u", &x) != 1) {
617 fprintf(stderr, "find syntax error 4\n");
620 tok = strtok(NULL, "(), \t");
621 if (!tok || sscanf(tok, "%u", &y) != 1) {
623 fprintf(stderr, "find syntax error 5\n");
626 tok = strtok(NULL, "(), \t");
627 if (!tok || sscanf(tok, "%u", &z) != 1) {
629 fprintf(stderr, "find syntax error 6\n");
632 if (find_fe_by_fid(x,y,z)) {
633 fprintf(stderr, "find returned no results\n");
636 fprintf(stderr, "unsupported filter type\n");
640 if (!strcasecmp(tok, "index")) {
641 tok = strtok(NULL, " \t");
642 if (!tok || sscanf(tok, "%u", &x) != 1) {
644 fprintf(stderr, "find syntax error 3\n");
647 if (find_cb_by_index(x)) {
648 fprintf(stderr, "find returned no results\n");
651 fprintf(stderr, "unsupported filter type\n");
655 fprintf(stderr, "find not supported for this menu\n");
657 } else if (!strcspn(tok, "0123456789")) {
658 if (sscanf(tok, "%u", &x) == 1) {
670 fprintf(stderr, "command not available from this menu\n");
673 fprintf(stderr, "input parse error ('%s')\n", tok);
675 } else if (mode == PR_FE_MODE) {
676 if (!strcmp(tok, "timeout")) {
678 } else if (!strcmp(tok, "hash")) {
682 fprintf(stderr, "unknown command\n");
684 tok = strtok(NULL, " \t");
692 printf("\th <...> -- host menu commands\n");
693 printf("\tfe <...> -- FileEntry menu commands\n");
694 printf("\tcb <...> -- CallBack menu commands\n");
695 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
696 printf("\tquit -- quit this menu\n");
697 printf("\texit -- exit the debugger\n");
698 printf("\thelp -- this help message\n");
702 print_global_help(void)
704 printf("\thdr -- display the fs_state_header struct\n");
710 printf("\thdr -- display the host_state_header struct\n");
711 printf("\tfirst -- display the first host\n");
712 printf("\tprev -- display the previous host\n");
713 printf("\tthis -- display this host\n");
714 printf("\tnext -- display the next host\n");
715 printf("\tlast -- display the last host\n");
716 printf("\tdump -- display all hosts\n");
722 printf("\thdr -- display the callback_state_header struct\n");
723 printf("\tfirst -- display the first FE\n");
724 printf("\tprev -- display the previous FE\n");
725 printf("\tthis -- display this FE\n");
726 printf("\tnext -- display the next FE\n");
727 printf("\tlast -- display the last FE\n");
728 printf("\tdump -- display all FEs\n");
729 printf("\ttimeout -- display the timeout queue heads\n");
730 printf("\thash -- display the file entry hash buckets\n");
731 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
732 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
738 printf("\thdr -- display the callback_state_entry_header struct\n");
739 printf("\tfirst -- display the first CB\n");
740 printf("\tprev -- display the previous CB\n");
741 printf("\tthis -- display this CB\n");
742 printf("\tnext -- display the next CB\n");
743 printf("\tlast -- display the last CB\n");
744 printf("\tdump -- display all CBs\n");
748 #define DPFTB1 "\t\t"
749 #define DPFTB2 "\t\t\t"
751 #define DPFOFF(addr) \
753 char * _p = (char *)addr; \
754 char * _m = (char *)map; \
755 printf("loading structure from address 0x%x (offset %u)\n", \
760 #define DPFSO(T, name) printf(T "%s = {\n", name)
761 #define DPFSO0(name) DPFSO(DPFTB0, name)
762 #define DPFSO1(name) DPFSO(DPFTB1, name)
763 #define DPFSC(T) printf(T "}\n")
764 #define DPFSC0 DPFSC(DPFTB0)
765 #define DPFSC1 DPFSC(DPFTB1)
768 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
769 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
770 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
771 #define DPFAC0 printf(" }\n")
772 #define DPFAC1 DPFAC0
773 #define DPFA1 printf(DPFTB1 " ")
774 #define DPFA2 printf(DPFTB2 " ")
775 #define DPFAN printf("\n")
776 #define DPFALE(type, var) printf("%" type, var)
777 #define DPFAE(type, var) printf("%" type ",\t", var)
780 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
781 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
782 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
785 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
786 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
787 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
790 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
791 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
792 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
795 #define DPFT(T, name, var) \
798 printf(T "%s = \"%s\"\n", name, strtok_r(ctime(&(var)), "\r\n", &last)); \
800 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
801 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
813 DPFSO0("fs_state_header");
815 DPFX2("magic", hdrs.hdr.stamp.magic);
816 DPFV2("version", "u", hdrs.hdr.stamp.version);
818 DPFT1("timestamp", hdrs.hdr.timestamp);
819 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
821 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
822 DPFS1("server_uuid", uuid_str);
823 DPFV1("valid", "d", hdrs.hdr.valid);
824 DPFV1("endianness", "d", hdrs.hdr.endianness);
825 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
827 SplitInt64(hdrs.hdr.h_offset, hi, lo);
829 DPFV2("hi", "u", hi);
830 DPFV2("lo", "u", lo);
833 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
835 DPFV2("hi", "u", hi);
836 DPFV2("lo", "u", lo);
839 DPFS1("server_version_string", hdrs.hdr.server_version_string);
842 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
843 fprintf(stderr, "* magic check failed\n");
845 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
846 fprintf(stderr, "* version check failed\n");
856 DPFOFF(hdrs.h_hdr_p);
857 DPFSO0("host_state_header");
859 DPFX2("magic", hdrs.h_hdr.stamp.magic);
860 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
862 DPFV1("records", "u", hdrs.h_hdr.records);
863 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
866 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
867 fprintf(stderr, "* magic check failed\n");
869 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
870 fprintf(stderr, "* version check failed\n");
882 DPFOFF(hdrs.cb_hdr_p);
883 DPFSO0("callback_state_header");
885 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
886 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
888 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
889 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
890 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
891 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
892 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
894 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
895 DPFSO1("timeout_offset");
896 DPFV2("hi", "u", hi);
897 DPFV2("lo", "u", lo);
900 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
901 DPFSO1("fehash_offset");
902 DPFV2("hi", "u", hi);
903 DPFV2("lo", "u", lo);
906 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
908 DPFV2("hi", "u", hi);
909 DPFV2("lo", "u", lo);
914 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
915 fprintf(stderr, "* magic check failed\n");
917 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
918 fprintf(stderr, "* version check failed\n");
923 dump_cb_timeout(void)
930 if (get_cb_timeout_hdr())
933 if (get_cb_timeout())
936 DPFOFF(hdrs.timeout_hdr_p);
937 DPFSO0("callback_state_timeout_header");
938 DPFX1("magic", hdrs.timeout_hdr.magic);
939 DPFV1("len", "u", hdrs.timeout_hdr.len);
940 DPFV1("records", "u", hdrs.timeout_hdr.records);
943 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
944 fprintf(stderr, "* magic check failed\n");
947 DPFOFF(hdrs.timeout_p);
949 for (i = 0; i < 127; i++) {
950 DPFAE("u", hdrs.timeout[i]);
956 DPFALE("u", hdrs.timeout[127]);
968 if (get_cb_fehash_hdr())
974 DPFOFF(hdrs.fehash_hdr_p);
975 DPFSO0("callback_state_fehash_header");
976 DPFX1("magic", hdrs.fehash_hdr.magic);
977 DPFV1("len", "u", hdrs.fehash_hdr.len);
978 DPFV1("records", "u", hdrs.fehash_hdr.records);
981 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
982 fprintf(stderr, "* magic check failed\n");
985 DPFOFF(hdrs.fehash_p);
987 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
988 DPFAE("u", hdrs.fehash[i]);
994 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
1004 fprintf(stderr, "error getting host_state_header\n");
1008 for (i = 0; i < hdrs.h_hdr.records; i++) {
1019 fprintf(stderr, "error getting callback_state_header\n");
1023 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1034 fprintf(stderr, "error getting callback_state_entry_header\n");
1038 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1044 dump_he(afs_uint32 idx)
1047 fprintf(stderr, "error getting he %d\n", idx);
1051 DPFOFF(he_cursor.cursor);
1054 dump_he_interfaces();
1059 dump_fe(afs_uint32 idx)
1062 fprintf(stderr, "error getting fe %d\n", idx);
1066 DPFOFF(fe_cursor.cursor);
1072 dump_cb(afs_uint32 idx)
1075 fprintf(stderr, "error getting cb %d\n", idx);
1079 DPFOFF(cb_cursor.cursor);
1086 dump_he(he_cursor.idx);
1092 dump_fe(fe_cursor.idx);
1098 dump_cb(cb_cursor.idx);
1105 fprintf(stderr, "error getting host_state_header\n");
1109 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1110 fprintf(stderr, "no more HEs\n");
1114 dump_he(he_cursor.idx+1);
1121 fprintf(stderr, "error getting callback_state_header\n");
1125 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1126 fprintf(stderr, "no more FEs\n");
1130 dump_fe(fe_cursor.idx+1);
1137 fprintf(stderr, "error getting callback_state_entry_header\n");
1141 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1142 fprintf(stderr, "no more CBs\n");
1146 dump_cb(cb_cursor.idx+1);
1152 if (!he_cursor.idx) {
1153 fprintf(stderr, "no more HEs\n");
1157 dump_he(he_cursor.idx-1);
1163 if (!fe_cursor.idx) {
1164 fprintf(stderr, "no more FEs\n");
1168 dump_fe(fe_cursor.idx-1);
1174 if (!cb_cursor.idx) {
1175 fprintf(stderr, "no more CBs\n");
1179 dump_cb(cb_cursor.idx-1);
1186 fprintf(stderr, "error getting callback_state_header\n");
1190 if (!hdrs.cb_hdr.nFEs) {
1191 fprintf(stderr, "no FEs present\n");
1202 fprintf(stderr, "error getting host_state_header\n");
1206 if (!hdrs.h_hdr.records) {
1207 fprintf(stderr, "no HEs present\n");
1218 fprintf(stderr, "error getting callback_state_entry_header\n");
1222 if (!fe_cursor.hdr.nCBs) {
1223 fprintf(stderr, "no CBs present\n");
1234 fprintf(stderr, "error getting host_state_header\n");
1238 if (!hdrs.h_hdr.records) {
1239 fprintf(stderr, "no HEs present\n");
1243 dump_he(hdrs.h_hdr.records-1);
1250 fprintf(stderr, "error getting callback_state_header\n");
1254 if (!hdrs.cb_hdr.nFEs) {
1255 fprintf(stderr, "no FEs present\n");
1259 dump_fe(hdrs.cb_hdr.nFEs-1);
1266 fprintf(stderr, "error getting callback_state_entry_header\n");
1270 if (!fe_cursor.hdr.nCBs) {
1271 fprintf(stderr, "no CBs present\n");
1275 dump_cb(fe_cursor.hdr.nCBs-1);
1281 DPFSO0("host_state_entry_header");
1282 DPFX1("magic", he_cursor.hdr.magic);
1283 DPFV1("len", "u", he_cursor.hdr.len);
1284 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1285 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1288 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1289 fprintf(stderr, "* magic check failed\n");
1296 DPFSO0("hostDiskEntry");
1297 DPFS1("host", afs_inet_ntoa(he_cursor.he.host));
1298 DPFV1("port", "u", he_cursor.he.port);
1299 DPFX1("hostFlags", he_cursor.he.hostFlags);
1300 DPFV1("Console", "u", he_cursor.he.Console);
1301 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1302 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1303 if (hdrs.hdr.stats_detailed) {
1304 #ifdef FS_STATS_DETAILED
1305 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1307 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1310 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1311 DPFT1("LastCall", he_cursor.he.LastCall);
1312 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1313 DPFT1("cpsCall", he_cursor.he.cpsCall);
1314 DPFV1("cblist", "u", he_cursor.he.cblist);
1315 DPFV1("index", "u", he_cursor.he.index);
1320 dump_he_interfaces(void)
1323 struct Interface * ifp;
1326 if (!he_cursor.hdr.interfaces)
1329 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1330 ifp = (struct Interface *) malloc(len);
1331 assert(ifp != NULL);
1333 memcpy(ifp, he_cursor.ifp, len);
1335 DPFSO0("Interface");
1336 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1338 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1339 DPFS1("uuid", temp_str);
1340 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1341 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1343 DPFS2("addr", afs_inet_ntoa(ifp->interface[i].addr));
1344 DPFV2("port", "u", ifp->interface[i].port);
1350 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1351 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1363 if (!he_cursor.hdr.hcps)
1366 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1367 hcps = (afs_int32 *) malloc(len);
1368 assert(hcps != NULL);
1369 memcpy(hcps, he_cursor.hcps, len);
1372 DPFAO1("prlist_val");
1373 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1374 DPFAE("d", hcps[i]);
1380 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1389 DPFSO0("callback_state_entry_header");
1390 DPFX1("magic", fe_cursor.hdr.magic);
1391 DPFV1("len", "u", fe_cursor.hdr.len);
1392 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1395 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1396 fprintf(stderr, "* magic check failed\n");
1403 DPFSO0("FEDiskEntry");
1405 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1406 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1407 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1408 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1409 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1410 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1411 DPFV2("status", "u", fe_cursor.fe.fe.status);
1413 DPFV1("index", "u", fe_cursor.fe.index);
1420 DPFSO0("CBDiskEntry");
1422 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1423 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1424 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1425 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1426 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1427 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1428 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1429 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1430 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1432 DPFV1("index", "u", cb_cursor.cb.index);
1436 #define DPFHMS printf(" ")
1437 #define DPFHS printf(" ")
1438 #define DPFHN(offset) printf("\n%u\t", offset)
1439 #define DPFHD(x) printf("%02X ", x)
1440 #define DPFHE printf("\n")
1443 hexdump_map(afs_uint32 offset, afs_uint32 len)
1446 unsigned char * p = (unsigned char *)map;
1452 if ((offset + len) > map_len) {
1453 fprintf(stderr, "offset + length exceeds memory map size (%u > %u)\n",
1454 offset+len, map_len);
1462 for (i = offset % 16; i > 0; i--) {
1466 for (i=0; i < len; i++, p++, offset++) {
1467 if (!(offset % 16)) {
1469 } else if (!(offset % 8)) {
1480 if (!hdrs.hdr_valid) {
1481 if (map_len < sizeof(struct fs_state_header)) {
1482 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1485 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1498 if (hdrs.h_hdr_valid)
1504 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1507 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1510 if ((lo >= map_len) ||
1511 ((lo + sizeof(struct host_state_header)) > map_len) ||
1512 (lo + sizeof(struct host_state_header) < lo)) {
1513 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1519 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1521 buf += sizeof(struct host_state_header);
1522 he_cursor.fh = (void *)buf;
1532 if (hdrs.cb_hdr_valid)
1538 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1541 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1544 if ((lo >= map_len) ||
1545 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1546 (lo + sizeof(struct callback_state_header) < lo)) {
1547 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1553 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1554 hdrs.cb_hdr_p = buf;
1555 hdrs.cb_hdr_valid = 1;
1557 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1560 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1563 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1564 sizeof(struct FEDiskEntry)) +
1565 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1566 if ((hi > map_len) ||
1568 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1574 fe_cursor.ffe = (void *)buf;
1580 get_cb_timeout_hdr(void)
1585 if (hdrs.timeout_hdr_valid)
1591 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1594 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1597 if ((lo >= map_len) ||
1598 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1599 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1600 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1606 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1607 hdrs.timeout_hdr_p = buf;
1608 hdrs.timeout_hdr_valid = 1;
1609 buf += sizeof(struct callback_state_timeout_header);
1610 hdrs.timeout_p = buf;
1616 get_cb_timeout(void)
1623 if (get_cb_timeout_hdr())
1626 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1627 assert(hdrs.timeout != NULL);
1628 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1633 get_cb_fehash_hdr(void)
1638 if (hdrs.fehash_hdr_valid)
1644 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1647 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1650 if ((lo >= map_len) ||
1651 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1652 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1653 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1659 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1660 hdrs.fehash_hdr_p = buf;
1661 hdrs.fehash_hdr_valid = 1;
1662 buf += sizeof(struct callback_state_fehash_header);
1663 hdrs.fehash_p = buf;
1676 if (get_cb_fehash_hdr())
1679 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1680 assert(hdrs.fehash != NULL);
1681 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1686 get_he(afs_uint32 idx)
1694 if (idx >= hdrs.h_hdr.records)
1697 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1700 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1702 if (he_cache.cursor == NULL) {
1703 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1704 assert(he_cache.cursor != NULL);
1707 if (idx && he_cache.cursor[idx-1] == NULL) {
1708 for (i = 0; i < idx; i++) {
1709 if (he_cache.cursor[i] == NULL) {
1716 he_cursor.cursor = he_cursor.fh;
1717 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1718 p = (char *)he_cursor.cursor;
1719 p += he_cursor.hdr.len;
1720 he_cursor.cursor = (void *)p;
1722 he_cursor.cursor = he_cache.cursor[idx-1];
1725 p = (char *)he_cursor.cursor;
1726 p += he_cursor.hdr.len;
1727 he_cursor.cursor = (void *)p;
1730 he_cursor.idx = idx;
1731 he_cache.cursor[idx] = he_cursor.cursor;
1744 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1745 he_cursor.hdr_valid = 1;
1754 if (!he_cursor.hdr_valid) {
1760 p = (char *) he_cursor.cursor;
1761 p += sizeof(struct host_state_entry_header);
1763 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1765 he_cursor.he_valid = 1;
1766 p += sizeof(struct hostDiskEntry);
1767 he_cursor.ifp = (void *)p;
1768 if (he_cursor.hdr.interfaces) {
1769 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1770 he_cursor.hcps = (void *)p;
1772 he_cursor.hcps = he_cursor.ifp;
1778 get_fe(afs_uint32 idx)
1783 cb_cursor.cb_valid = 0;
1788 if (idx >= hdrs.cb_hdr.nFEs)
1791 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1794 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1796 if (fe_cache.cursor == NULL) {
1797 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1798 assert(fe_cache.cursor != NULL);
1801 if (idx && fe_cache.cursor[idx-1] == NULL) {
1802 for (i = 0; i < idx; i++) {
1803 if (fe_cache.cursor[i] == NULL) {
1810 fe_cursor.cursor = fe_cursor.ffe;
1811 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1812 p = (char *)fe_cursor.cursor;
1813 p += fe_cursor.hdr.len;
1814 fe_cursor.cursor = (void *)p;
1816 fe_cursor.cursor = fe_cache.cursor[idx-1];
1819 p = (char *)fe_cursor.cursor;
1820 p += fe_cursor.hdr.len;
1821 fe_cursor.cursor = (void *)p;
1824 fe_cursor.idx = idx;
1825 fe_cache.cursor[idx] = fe_cursor.cursor;
1838 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1839 fe_cursor.hdr_valid = 1;
1848 if (!fe_cursor.hdr_valid) {
1854 p = (char *) fe_cursor.cursor;
1855 p += sizeof(struct callback_state_entry_header);
1857 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1859 fe_cursor.fe_valid = 1;
1860 p += sizeof(struct FEDiskEntry);
1861 fe_cursor.fcb = (void *)p;
1866 get_cb(afs_uint32 idx)
1871 if (get_fe(fe_cursor.idx))
1874 if (idx >= fe_cursor.hdr.nCBs)
1877 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1880 cb_cursor.cb_valid = 0;
1882 p = (char *)fe_cursor.fcb;
1883 p += idx * sizeof(struct CBDiskEntry);
1884 cb_cursor.cursor = (void *)p;
1886 cb_cursor.idx = idx;
1897 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1898 cb_cursor.cb_valid = 1;
1903 find_he_by_index(afs_uint32 idx)
1911 for (i = 0; i < hdrs.h_hdr.records; i++) {
1913 fprintf(stderr, "error getting he %d\n", i);
1916 if (he_cursor.he.index == idx)
1920 if (i < hdrs.h_hdr.records) {
1928 find_fe_by_index(afs_uint32 idx)
1936 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1938 fprintf(stderr, "error getting fe %d\n", i);
1941 if (fe_cursor.fe.index == idx)
1945 if (i < hdrs.cb_hdr.nFEs) {
1953 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1961 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1963 fprintf(stderr, "error getting fe %d\n", i);
1966 if ((fe_cursor.fe.fe.unique == unique) &&
1967 (fe_cursor.fe.fe.volid == volid) &&
1968 (fe_cursor.fe.fe.vnode == vnode))
1972 if (i < hdrs.cb_hdr.nFEs) {
1980 find_cb_by_index(afs_uint32 idx)
1988 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1990 fprintf(stderr, "error getting cb %d\n", i);
1993 if (cb_cursor.cb.index == idx)
1997 if (i < fe_cursor.hdr.nCBs) {
2004 #endif /* AFS_DEMAND_ATTACH_FS */