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>
26 #include <afs/opr_assert.h>
31 #include <rx/rx_queue.h>
32 #include <afs/afsint.h>
33 #include <afs/rxgen_consts.h>
35 #include <afs/errors.h>
36 #include <afs/ihandle.h>
37 #include <afs/partition.h>
38 #include <afs/vnode.h>
39 #include <afs/volume.h>
41 #include <afs/ptclient.h>
42 #include <afs/prs_fs.h>
43 #include <afs/afsutil.h>
45 #include <afs/cellconfig.h>
46 #include "../util/afsutil_prototypes.h"
47 #include "../viced/viced.h"
48 #include "../viced/host.h"
49 #include "../viced/callback.h"
50 #include "serialize_state.h"
52 #ifndef AFS_DEMAND_ATTACH_FS
54 main (int argc, char ** argv)
56 fprintf(stderr, "%s is only supported for demand attach fileservers\n",
57 argv[0] ? argv[0] : "state analyzer");
60 #else /* AFS_DEMAND_ATTACH_FS */
62 static void usage(char * prog);
63 static int openFile(char * path);
64 static void initState(void);
66 static void banner(void);
67 static void prompt(void);
69 static void print_help(void);
70 static void print_global_help(void);
71 static void print_h_help(void);
72 static void print_fe_help(void);
73 static void print_cb_help(void);
75 static void dump_hdr(void);
76 static void dump_h_hdr(void);
77 static void dump_cb_hdr(void);
79 static void dump_cb_timeout(void);
80 static void dump_cb_fehash(void);
82 static void dump_all_hes(void);
83 static void dump_all_fes(void);
84 static void dump_all_cbs(void);
86 static void dump_he(afs_uint32 idx);
87 static void dump_fe(afs_uint32 idx);
88 static void dump_cb(afs_uint32 idx);
89 static void dump_this_he(void);
90 static void dump_this_fe(void);
91 static void dump_this_cb(void);
92 static void dump_next_he(void);
93 static void dump_next_fe(void);
94 static void dump_next_cb(void);
95 static void dump_prev_he(void);
96 static void dump_prev_fe(void);
97 static void dump_prev_cb(void);
98 static void dump_first_he(void);
99 static void dump_first_fe(void);
100 static void dump_first_cb(void);
101 static void dump_last_he(void);
102 static void dump_last_fe(void);
103 static void dump_last_cb(void);
104 static void dump_he_hdr(void);
105 static void dump_he_entry(void);
106 static void dump_he_interfaces(void);
107 static void dump_he_hcps(void);
108 static void dump_fe_hdr(void);
109 static void dump_fe_entry(void);
110 static void dump_cb_entry(void);
112 static void hexdump_map(afs_uint32 offset, afs_uint32 len);
114 static int get_hdr(void);
115 static int get_h_hdr(void);
116 static int get_cb_hdr(void);
117 static int get_cb_timeout_hdr(void);
118 static int get_cb_timeout(void);
119 static int get_cb_fehash_hdr(void);
120 static int get_cb_fehash(void);
121 static int get_he(afs_uint32 idx);
122 static int get_he_hdr(void);
123 static int get_he_entry(void);
124 static int get_fe(afs_uint32 idx);
125 static int get_fe_hdr(void);
126 static int get_fe_entry(void);
127 static int get_cb(afs_uint32 idx);
128 static int get_cb_entry(void);
130 static int find_fe_by_index(afs_uint32 idx);
131 static int find_cb_by_index(afs_uint32 idx);
132 static int find_fe_by_fid(VolumeId vol, afs_uint32 vn, afs_uint32 uniq);
135 static int dump_fd = -1;
136 static void * map = NULL;
137 static size_t map_len;
140 struct fs_state_header hdr;
141 struct host_state_header h_hdr;
142 struct callback_state_header cb_hdr;
143 struct callback_state_timeout_header timeout_hdr;
144 struct callback_state_fehash_header fehash_hdr;
145 afs_uint32 * timeout;
148 /* pointers into the memory map */
152 void * timeout_hdr_p;
160 byte timeout_hdr_valid;
161 byte fehash_hdr_valid;
169 struct host_state_entry_header hdr;
170 struct hostDiskEntry he;
184 struct callback_state_entry_header hdr;
185 struct FEDiskEntry fe;
197 struct CBDiskEntry cb;
205 fprintf(stderr, "usage: %s [<state dump file>]\n", prog);
209 main(int argc, char ** argv)
212 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
220 if (openFile(argv[1]))
223 if (openFile((char *)AFSDIR_SERVER_FSSTATE_FILEPATH))
233 openFile(char * path)
236 struct afs_stat status;
238 dump_fd = afs_open(path, O_RDWR);
240 fprintf(stderr, "dump file '%s' failed to open\n", path);
245 printf("opened dump file '%s'\n", path);
247 if (afs_fstat(dump_fd, &status) == -1) {
248 fprintf(stderr, "failed to stat file\n");
253 map_len = status.st_size;
255 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
256 if (map == MAP_FAILED) {
257 fprintf(stderr, "failed to mmap file\n");
262 printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map);
267 munmap(map, map_len);
281 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
282 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
283 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
284 he_cache.cursor = fe_cache.cursor = NULL;
290 fprintf(stderr, "demand attach fs\n");
291 fprintf(stderr, "fileserver state analyzer\n");
292 fprintf(stderr, "version 0.1\n");
295 #define PROGNAME "fs state analyzer"
301 char prev_input[256];
309 } mode = PR_GLOBAL_MODE, next_mode;
312 input[0] = prev_input[0] = '\0';
318 printf(PROGNAME "> ");
321 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
324 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
327 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
330 fprintf(stderr, "prompt state broken; aborting\n");
333 if (fgets(input, 256, stdin) == NULL)
336 if (!strcmp(input, "")) {
337 /* repeat last command */
338 if (!strcmp(prev_input, "")) {
341 strlcpy(input, prev_input, sizeof(input));
343 /* save command for repetition */
344 strlcpy(prev_input, input, sizeof(prev_input));
347 tok = strtok(input, " \t\n");
349 while (tok && !strcmp(tok, ";")) {
350 tok = strtok(NULL, "; \t\n");
357 if (!strcasecmp(tok, "exit")) {
359 } else if (!strcasecmp(tok, "quit")) {
362 next_mode = PR_FE_MODE;
366 next_mode = PR_GLOBAL_MODE;
371 } else if (!strcasecmp(tok, "h")) {
372 tok = strtok(NULL, " \t");
378 } else if (!strcasecmp(tok, "fe")) {
379 tok = strtok(NULL, " \t");
385 } else if (!strcasecmp(tok, "fs")) {
386 tok = strtok(NULL, " \t");
387 mode = PR_GLOBAL_MODE;
392 } else if (!strcasecmp(tok, "cb")) {
393 tok = strtok(NULL, " \t");
399 } else if (!strcasecmp(tok, "help")) {
414 } else if (!strcasecmp(tok, "hexdump")) {
415 tok = strtok(NULL, " \t");
417 hexdump_map(0, map_len);
420 if (sscanf(tok, "%u", &x) != 1) {
421 fprintf(stderr, "hexdump parse error 1\n");
425 tok = strtok(NULL, " \t");
427 hexdump_map(x, map_len - x);
430 if (sscanf(tok, "%u", &y) != 1) {
431 fprintf(stderr, "hexdump parse error 2\n");
435 } else if (!strcasecmp(tok, "hdr")) {
449 } else if (!strcasecmp(tok, "this")) {
461 fprintf(stderr, "command not valid for this mode\n");
463 } else if (!strcasecmp(tok, "next")) {
475 fprintf(stderr, "command not valid for this mode\n");
477 } else if (!strcasecmp(tok, "prev")) {
489 fprintf(stderr, "command not valid for this mode\n");
491 } else if (!strcasecmp(tok, "first")) {
503 fprintf(stderr, "command not valid for this mode\n");
505 } else if (!strcasecmp(tok, "last")) {
517 fprintf(stderr, "command not valid for this mode\n");
519 } else if (!strcasecmp(tok, "dump")) {
531 fprintf(stderr, "command not valid for this mode\n");
533 } else if (!strcasecmp(tok, "find")) {
534 tok = strtok(NULL, " \t");
535 if (!tok || strcasecmp(tok, "by")) {
537 fprintf(stderr, "find syntax error 1 (%s)\n",
538 (tok) ? tok : "nil");
541 tok = strtok(NULL, " \t");
543 fprintf(stderr, "find syntax error 2\n");
548 fprintf(stderr, "not implemented yet\n");
551 if (!strcasecmp(tok, "index")) {
552 tok = strtok(NULL, " \t");
553 if (!tok || sscanf(tok, "%u", &x) != 1) {
555 fprintf(stderr, "find syntax error 3\n");
558 if (find_fe_by_index(x)) {
559 fprintf(stderr, "find returned no results\n");
561 } else if (!strcasecmp(tok, "fid")) {
562 tok = strtok(NULL, "(), \t");
563 if (!tok || sscanf(tok, "%u", &x) != 1) {
565 fprintf(stderr, "find syntax error 4\n");
568 tok = strtok(NULL, "(), \t");
569 if (!tok || sscanf(tok, "%u", &y) != 1) {
571 fprintf(stderr, "find syntax error 5\n");
574 tok = strtok(NULL, "(), \t");
575 if (!tok || sscanf(tok, "%u", &z) != 1) {
577 fprintf(stderr, "find syntax error 6\n");
580 if (find_fe_by_fid(x,y,z)) {
581 fprintf(stderr, "find returned no results\n");
584 fprintf(stderr, "unsupported filter type\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_cb_by_index(x)) {
596 fprintf(stderr, "find returned no results\n");
599 fprintf(stderr, "unsupported filter type\n");
603 fprintf(stderr, "find not supported for this menu\n");
605 } else if (!strcspn(tok, "0123456789")) {
606 if (sscanf(tok, "%u", &x) == 1) {
618 fprintf(stderr, "command not available from this menu\n");
621 fprintf(stderr, "input parse error ('%s')\n", tok);
623 } else if (mode == PR_FE_MODE) {
624 if (!strcmp(tok, "timeout")) {
626 } else if (!strcmp(tok, "hash")) {
630 fprintf(stderr, "unknown command\n");
632 tok = strtok(NULL, " \t");
640 printf("\th <...> -- host menu commands\n");
641 printf("\tfe <...> -- FileEntry menu commands\n");
642 printf("\tcb <...> -- CallBack menu commands\n");
643 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
644 printf("\tquit -- quit this menu\n");
645 printf("\texit -- exit the debugger\n");
646 printf("\thelp -- this help message\n");
650 print_global_help(void)
652 printf("\thdr -- display the fs_state_header struct\n");
658 printf("\thdr -- display the host_state_header struct\n");
659 printf("\tfirst -- display the first host\n");
660 printf("\tprev -- display the previous host\n");
661 printf("\tthis -- display this host\n");
662 printf("\tnext -- display the next host\n");
663 printf("\tlast -- display the last host\n");
664 printf("\tdump -- display all hosts\n");
670 printf("\thdr -- display the callback_state_header struct\n");
671 printf("\tfirst -- display the first FE\n");
672 printf("\tprev -- display the previous FE\n");
673 printf("\tthis -- display this FE\n");
674 printf("\tnext -- display the next FE\n");
675 printf("\tlast -- display the last FE\n");
676 printf("\tdump -- display all FEs\n");
677 printf("\ttimeout -- display the timeout queue heads\n");
678 printf("\thash -- display the file entry hash buckets\n");
679 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
680 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
686 printf("\thdr -- display the callback_state_entry_header struct\n");
687 printf("\tfirst -- display the first CB\n");
688 printf("\tprev -- display the previous CB\n");
689 printf("\tthis -- display this CB\n");
690 printf("\tnext -- display the next CB\n");
691 printf("\tlast -- display the last CB\n");
692 printf("\tdump -- display all CBs\n");
696 #define DPFTB1 "\t\t"
697 #define DPFTB2 "\t\t\t"
699 #define DPFOFF(addr) \
701 char * _p = (char *)addr; \
702 char * _m = (char *)map; \
703 printf("loading structure from address %"AFS_PTR_FMT" (offset %ld)\n", \
704 addr, (long)(_p-_m)); \
708 #define DPFSO(T, name) printf(T "%s = {\n", name)
709 #define DPFSO0(name) DPFSO(DPFTB0, name)
710 #define DPFSO1(name) DPFSO(DPFTB1, name)
711 #define DPFSC(T) printf(T "}\n")
712 #define DPFSC0 DPFSC(DPFTB0)
713 #define DPFSC1 DPFSC(DPFTB1)
716 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
717 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
718 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
719 #define DPFAC0 printf(" }\n")
720 #define DPFAC1 DPFAC0
721 #define DPFA1 printf(DPFTB1 " ")
722 #define DPFA2 printf(DPFTB2 " ")
723 #define DPFAN printf("\n")
724 #define DPFALE(type, var) printf("%" type, var)
725 #define DPFAE(type, var) printf("%" type ",\t", var)
728 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
729 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
730 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
733 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
734 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
735 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
738 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
739 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
740 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
743 #define DPFT(T, name, var) \
746 printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \
748 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
749 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
761 DPFSO0("fs_state_header");
763 DPFX2("magic", hdrs.hdr.stamp.magic);
764 DPFV2("version", "u", hdrs.hdr.stamp.version);
766 DPFT1("timestamp", hdrs.hdr.timestamp);
767 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
769 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
770 DPFS1("server_uuid", uuid_str);
771 DPFV1("valid", "d", hdrs.hdr.valid);
772 DPFV1("endianness", "d", hdrs.hdr.endianness);
773 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
775 SplitInt64(hdrs.hdr.h_offset, hi, lo);
777 DPFV2("hi", "u", hi);
778 DPFV2("lo", "u", lo);
781 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
783 DPFV2("hi", "u", hi);
784 DPFV2("lo", "u", lo);
787 DPFS1("server_version_string", hdrs.hdr.server_version_string);
790 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
791 fprintf(stderr, "* magic check failed\n");
793 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
794 fprintf(stderr, "* version check failed\n");
804 DPFOFF(hdrs.h_hdr_p);
805 DPFSO0("host_state_header");
807 DPFX2("magic", hdrs.h_hdr.stamp.magic);
808 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
810 DPFV1("records", "u", hdrs.h_hdr.records);
811 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
814 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
815 fprintf(stderr, "* magic check failed\n");
817 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
818 fprintf(stderr, "* version check failed\n");
830 DPFOFF(hdrs.cb_hdr_p);
831 DPFSO0("callback_state_header");
833 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
834 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
836 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
837 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
838 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
839 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
840 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
842 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
843 DPFSO1("timeout_offset");
844 DPFV2("hi", "u", hi);
845 DPFV2("lo", "u", lo);
848 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
849 DPFSO1("fehash_offset");
850 DPFV2("hi", "u", hi);
851 DPFV2("lo", "u", lo);
854 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
856 DPFV2("hi", "u", hi);
857 DPFV2("lo", "u", lo);
862 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
863 fprintf(stderr, "* magic check failed\n");
865 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
866 fprintf(stderr, "* version check failed\n");
871 dump_cb_timeout(void)
878 if (get_cb_timeout_hdr())
881 if (get_cb_timeout())
884 DPFOFF(hdrs.timeout_hdr_p);
885 DPFSO0("callback_state_timeout_header");
886 DPFX1("magic", hdrs.timeout_hdr.magic);
887 DPFV1("len", "u", hdrs.timeout_hdr.len);
888 DPFV1("records", "u", hdrs.timeout_hdr.records);
891 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
892 fprintf(stderr, "* magic check failed\n");
895 DPFOFF(hdrs.timeout_p);
897 for (i = 0; i < 127; i++) {
898 DPFAE("u", hdrs.timeout[i]);
904 DPFALE("u", hdrs.timeout[127]);
916 if (get_cb_fehash_hdr())
922 DPFOFF(hdrs.fehash_hdr_p);
923 DPFSO0("callback_state_fehash_header");
924 DPFX1("magic", hdrs.fehash_hdr.magic);
925 DPFV1("len", "u", hdrs.fehash_hdr.len);
926 DPFV1("records", "u", hdrs.fehash_hdr.records);
929 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
930 fprintf(stderr, "* magic check failed\n");
933 DPFOFF(hdrs.fehash_p);
935 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
936 DPFAE("u", hdrs.fehash[i]);
942 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
952 fprintf(stderr, "error getting host_state_header\n");
956 for (i = 0; i < hdrs.h_hdr.records; i++) {
967 fprintf(stderr, "error getting callback_state_header\n");
971 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
982 fprintf(stderr, "error getting callback_state_entry_header\n");
986 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
992 dump_he(afs_uint32 idx)
995 fprintf(stderr, "error getting he %d\n", idx);
999 DPFOFF(he_cursor.cursor);
1002 dump_he_interfaces();
1007 dump_fe(afs_uint32 idx)
1010 fprintf(stderr, "error getting fe %d\n", idx);
1014 DPFOFF(fe_cursor.cursor);
1020 dump_cb(afs_uint32 idx)
1023 fprintf(stderr, "error getting cb %d\n", idx);
1027 DPFOFF(cb_cursor.cursor);
1034 dump_he(he_cursor.idx);
1040 dump_fe(fe_cursor.idx);
1046 dump_cb(cb_cursor.idx);
1053 fprintf(stderr, "error getting host_state_header\n");
1057 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1058 fprintf(stderr, "no more HEs\n");
1062 dump_he(he_cursor.idx+1);
1069 fprintf(stderr, "error getting callback_state_header\n");
1073 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1074 fprintf(stderr, "no more FEs\n");
1078 dump_fe(fe_cursor.idx+1);
1085 fprintf(stderr, "error getting callback_state_entry_header\n");
1089 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1090 fprintf(stderr, "no more CBs\n");
1094 dump_cb(cb_cursor.idx+1);
1100 if (!he_cursor.idx) {
1101 fprintf(stderr, "no more HEs\n");
1105 dump_he(he_cursor.idx-1);
1111 if (!fe_cursor.idx) {
1112 fprintf(stderr, "no more FEs\n");
1116 dump_fe(fe_cursor.idx-1);
1122 if (!cb_cursor.idx) {
1123 fprintf(stderr, "no more CBs\n");
1127 dump_cb(cb_cursor.idx-1);
1134 fprintf(stderr, "error getting callback_state_header\n");
1138 if (!hdrs.cb_hdr.nFEs) {
1139 fprintf(stderr, "no FEs present\n");
1150 fprintf(stderr, "error getting host_state_header\n");
1154 if (!hdrs.h_hdr.records) {
1155 fprintf(stderr, "no HEs present\n");
1166 fprintf(stderr, "error getting callback_state_entry_header\n");
1170 if (!fe_cursor.hdr.nCBs) {
1171 fprintf(stderr, "no CBs present\n");
1182 fprintf(stderr, "error getting host_state_header\n");
1186 if (!hdrs.h_hdr.records) {
1187 fprintf(stderr, "no HEs present\n");
1191 dump_he(hdrs.h_hdr.records-1);
1198 fprintf(stderr, "error getting callback_state_header\n");
1202 if (!hdrs.cb_hdr.nFEs) {
1203 fprintf(stderr, "no FEs present\n");
1207 dump_fe(hdrs.cb_hdr.nFEs-1);
1214 fprintf(stderr, "error getting callback_state_entry_header\n");
1218 if (!fe_cursor.hdr.nCBs) {
1219 fprintf(stderr, "no CBs present\n");
1223 dump_cb(fe_cursor.hdr.nCBs-1);
1229 DPFSO0("host_state_entry_header");
1230 DPFX1("magic", he_cursor.hdr.magic);
1231 DPFV1("len", "u", he_cursor.hdr.len);
1232 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1233 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1236 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1237 fprintf(stderr, "* magic check failed\n");
1245 DPFSO0("hostDiskEntry");
1246 DPFS1("host", afs_inet_ntoa_r(he_cursor.he.host, hoststr));
1247 DPFV1("port", "u", he_cursor.he.port);
1248 DPFX1("hostFlags", he_cursor.he.hostFlags);
1249 DPFV1("Console", "u", he_cursor.he.Console);
1250 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1251 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1252 if (hdrs.hdr.stats_detailed) {
1253 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1255 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1256 DPFT1("LastCall", he_cursor.he.LastCall);
1257 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1258 DPFT1("cpsCall", he_cursor.he.cpsCall);
1259 DPFV1("cblist", "u", he_cursor.he.cblist);
1260 DPFV1("index", "u", he_cursor.he.index);
1265 dump_he_interfaces(void)
1268 struct Interface * ifp;
1272 if (!he_cursor.hdr.interfaces)
1275 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1277 assert(ifp != NULL);
1279 memcpy(ifp, he_cursor.ifp, len);
1281 DPFSO0("Interface");
1282 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1284 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1285 DPFS1("uuid", temp_str);
1286 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1287 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1289 DPFS2("addr", afs_inet_ntoa_r(ifp->interface[i].addr, hoststr));
1290 DPFV2("port", "u", ifp->interface[i].port);
1296 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1297 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1308 if (!he_cursor.hdr.hcps)
1311 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1313 assert(hcps != NULL);
1314 memcpy(hcps, he_cursor.hcps, len);
1317 DPFAO1("prlist_val");
1318 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1319 DPFAE("d", hcps[i]);
1325 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1334 DPFSO0("callback_state_entry_header");
1335 DPFX1("magic", fe_cursor.hdr.magic);
1336 DPFV1("len", "u", fe_cursor.hdr.len);
1337 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1340 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1341 fprintf(stderr, "* magic check failed\n");
1348 DPFSO0("FEDiskEntry");
1350 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1351 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1352 DPFV2("volid", AFS_VOLID_FMT, afs_printable_VolumeId_lu(fe_cursor.fe.fe.volid));
1353 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1354 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1355 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1356 DPFV2("status", "u", fe_cursor.fe.fe.status);
1358 DPFV1("index", "u", fe_cursor.fe.index);
1365 DPFSO0("CBDiskEntry");
1367 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1368 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1369 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1370 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1371 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1372 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1373 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1374 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1375 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1377 DPFV1("index", "u", cb_cursor.cb.index);
1381 #define DPFHMS printf(" ")
1382 #define DPFHS printf(" ")
1383 #define DPFHN(offset) printf("\n%u\t", offset)
1384 #define DPFHD(x) printf("%02X ", x)
1385 #define DPFHE printf("\n")
1388 hexdump_map(afs_uint32 offset, afs_uint32 len)
1391 unsigned char * p = (unsigned char *)map;
1396 if ((offset + len) > map_len) {
1397 fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n",
1398 offset+len, (unsigned long)map_len);
1406 for (i = offset % 16; i > 0; i--) {
1410 for (i=0; i < len; i++, p++, offset++) {
1411 if (!(offset % 16)) {
1413 } else if (!(offset % 8)) {
1424 if (!hdrs.hdr_valid) {
1425 if (map_len < sizeof(struct fs_state_header)) {
1426 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1429 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1442 if (hdrs.h_hdr_valid)
1448 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1451 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1454 if ((lo >= map_len) ||
1455 ((lo + sizeof(struct host_state_header)) > map_len) ||
1456 (lo + sizeof(struct host_state_header) < lo)) {
1457 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1463 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1465 buf += sizeof(struct host_state_header);
1466 he_cursor.fh = (void *)buf;
1476 if (hdrs.cb_hdr_valid)
1482 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1485 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1488 if ((lo >= map_len) ||
1489 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1490 (lo + sizeof(struct callback_state_header) < lo)) {
1491 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1497 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1498 hdrs.cb_hdr_p = buf;
1499 hdrs.cb_hdr_valid = 1;
1501 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1504 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1507 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1508 sizeof(struct FEDiskEntry)) +
1509 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1510 if ((hi > map_len) ||
1512 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1518 fe_cursor.ffe = (void *)buf;
1524 get_cb_timeout_hdr(void)
1529 if (hdrs.timeout_hdr_valid)
1535 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1538 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1541 if ((lo >= map_len) ||
1542 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1543 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1544 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1550 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1551 hdrs.timeout_hdr_p = buf;
1552 hdrs.timeout_hdr_valid = 1;
1553 buf += sizeof(struct callback_state_timeout_header);
1554 hdrs.timeout_p = buf;
1560 get_cb_timeout(void)
1565 if (get_cb_timeout_hdr())
1568 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1569 assert(hdrs.timeout != NULL);
1570 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1575 get_cb_fehash_hdr(void)
1580 if (hdrs.fehash_hdr_valid)
1586 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1589 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1592 if ((lo >= map_len) ||
1593 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1594 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1595 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1601 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1602 hdrs.fehash_hdr_p = buf;
1603 hdrs.fehash_hdr_valid = 1;
1604 buf += sizeof(struct callback_state_fehash_header);
1605 hdrs.fehash_p = buf;
1616 if (get_cb_fehash_hdr())
1619 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1620 assert(hdrs.fehash != NULL);
1621 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1626 get_he(afs_uint32 idx)
1634 if (idx >= hdrs.h_hdr.records)
1637 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1640 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1642 if (he_cache.cursor == NULL) {
1643 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1644 assert(he_cache.cursor != NULL);
1647 if (idx && he_cache.cursor[idx-1] == NULL) {
1648 for (i = 0; i < idx; i++) {
1649 if (he_cache.cursor[i] == NULL) {
1656 he_cursor.cursor = he_cursor.fh;
1657 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1658 p = (char *)he_cursor.cursor;
1659 p += he_cursor.hdr.len;
1660 he_cursor.cursor = (void *)p;
1662 he_cursor.cursor = he_cache.cursor[idx-1];
1665 p = (char *)he_cursor.cursor;
1666 p += he_cursor.hdr.len;
1667 he_cursor.cursor = (void *)p;
1670 he_cursor.idx = idx;
1671 he_cache.cursor[idx] = he_cursor.cursor;
1684 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1685 he_cursor.hdr_valid = 1;
1694 if (!he_cursor.hdr_valid) {
1700 p = (char *) he_cursor.cursor;
1701 p += sizeof(struct host_state_entry_header);
1703 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1705 he_cursor.he_valid = 1;
1706 p += sizeof(struct hostDiskEntry);
1707 he_cursor.ifp = (void *)p;
1708 if (he_cursor.hdr.interfaces) {
1709 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1710 he_cursor.hcps = (void *)p;
1712 he_cursor.hcps = he_cursor.ifp;
1718 get_fe(afs_uint32 idx)
1723 cb_cursor.cb_valid = 0;
1728 if (idx >= hdrs.cb_hdr.nFEs)
1731 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1734 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1736 if (fe_cache.cursor == NULL) {
1737 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1738 assert(fe_cache.cursor != NULL);
1741 if (idx && fe_cache.cursor[idx-1] == NULL) {
1742 for (i = 0; i < idx; i++) {
1743 if (fe_cache.cursor[i] == NULL) {
1750 fe_cursor.cursor = fe_cursor.ffe;
1751 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1752 p = (char *)fe_cursor.cursor;
1753 p += fe_cursor.hdr.len;
1754 fe_cursor.cursor = (void *)p;
1756 fe_cursor.cursor = fe_cache.cursor[idx-1];
1759 p = (char *)fe_cursor.cursor;
1760 p += fe_cursor.hdr.len;
1761 fe_cursor.cursor = (void *)p;
1764 fe_cursor.idx = idx;
1765 fe_cache.cursor[idx] = fe_cursor.cursor;
1778 if (!fe_cursor.cursor) {
1779 if(get_fe(fe_cursor.idx)) {
1784 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1785 fe_cursor.hdr_valid = 1;
1794 if (!fe_cursor.hdr_valid) {
1800 p = (char *) fe_cursor.cursor;
1801 p += sizeof(struct callback_state_entry_header);
1803 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1805 fe_cursor.fe_valid = 1;
1806 p += sizeof(struct FEDiskEntry);
1807 fe_cursor.fcb = (void *)p;
1812 get_cb(afs_uint32 idx)
1816 if (get_fe(fe_cursor.idx))
1819 if (idx >= fe_cursor.hdr.nCBs)
1822 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1825 cb_cursor.cb_valid = 0;
1827 p = (char *)fe_cursor.fcb;
1828 p += idx * sizeof(struct CBDiskEntry);
1829 cb_cursor.cursor = (void *)p;
1831 cb_cursor.idx = idx;
1842 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1843 cb_cursor.cb_valid = 1;
1849 find_he_by_index(afs_uint32 idx)
1857 for (i = 0; i < hdrs.h_hdr.records; i++) {
1859 fprintf(stderr, "error getting he %d\n", i);
1862 if (he_cursor.he.index == idx)
1866 if (i < hdrs.h_hdr.records) {
1875 find_fe_by_index(afs_uint32 idx)
1883 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1885 fprintf(stderr, "error getting fe %d\n", i);
1888 if (fe_cursor.fe.index == idx)
1892 if (i < hdrs.cb_hdr.nFEs) {
1900 find_fe_by_fid(VolumeId volid, afs_uint32 vnode, afs_uint32 unique)
1908 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1910 fprintf(stderr, "error getting fe %d\n", i);
1913 if ((fe_cursor.fe.fe.unique == unique) &&
1914 (fe_cursor.fe.fe.volid == volid) &&
1915 (fe_cursor.fe.fe.vnode == vnode))
1919 if (i < hdrs.cb_hdr.nFEs) {
1927 find_cb_by_index(afs_uint32 idx)
1935 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1937 fprintf(stderr, "error getting cb %d\n", i);
1940 if (cb_cursor.cb.index == idx)
1944 if (i < fe_cursor.hdr.nCBs) {
1951 #endif /* AFS_DEMAND_ATTACH_FS */