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/afs_assert.h>
29 #include <afs/afsint.h>
30 #include <afs/rxgen_consts.h>
32 #include <afs/errors.h>
33 #include <afs/ihandle.h>
34 #include <afs/vnode.h>
35 #include <afs/volume.h>
36 #ifdef AFS_ATHENA_STDENV
40 #include <afs/ptclient.h>
41 #include <afs/prs_fs.h>
42 #include <afs/afsutil.h>
44 #include <afs/cellconfig.h>
45 #include "../util/afsutil_prototypes.h"
46 #include "../viced/viced.h"
47 #include "../viced/host.h"
48 #include "../viced/callback.h"
49 #include "serialize_state.h"
51 #ifndef AFS_DEMAND_ATTACH_FS
53 main (int argc, char ** argv)
55 fprintf(stderr, "%s is only supported for demand attach fileservers\n",
56 argv[0] ? argv[0] : "state analyzer");
59 #else /* AFS_DEMAND_ATTACH_FS */
61 static void usage(char * prog);
62 static int openFile(char * path);
63 static void initState(void);
65 static void banner(void);
66 static void prompt(void);
68 static void print_help(void);
69 static void print_global_help(void);
70 static void print_h_help(void);
71 static void print_fe_help(void);
72 static void print_cb_help(void);
74 static void dump_hdr(void);
75 static void dump_h_hdr(void);
76 static void dump_cb_hdr(void);
78 static void dump_cb_timeout(void);
79 static void dump_cb_fehash(void);
81 static void dump_all_hes(void);
82 static void dump_all_fes(void);
83 static void dump_all_cbs(void);
85 static void dump_he(afs_uint32 idx);
86 static void dump_fe(afs_uint32 idx);
87 static void dump_cb(afs_uint32 idx);
88 static void dump_this_he(void);
89 static void dump_this_fe(void);
90 static void dump_this_cb(void);
91 static void dump_next_he(void);
92 static void dump_next_fe(void);
93 static void dump_next_cb(void);
94 static void dump_prev_he(void);
95 static void dump_prev_fe(void);
96 static void dump_prev_cb(void);
97 static void dump_first_he(void);
98 static void dump_first_fe(void);
99 static void dump_first_cb(void);
100 static void dump_last_he(void);
101 static void dump_last_fe(void);
102 static void dump_last_cb(void);
103 static void dump_he_hdr(void);
104 static void dump_he_entry(void);
105 static void dump_he_interfaces(void);
106 static void dump_he_hcps(void);
107 static void dump_fe_hdr(void);
108 static void dump_fe_entry(void);
109 static void dump_cb_entry(void);
111 static void hexdump_map(afs_uint32 offset, afs_uint32 len);
113 static int get_hdr(void);
114 static int get_h_hdr(void);
115 static int get_cb_hdr(void);
116 static int get_cb_timeout_hdr(void);
117 static int get_cb_timeout(void);
118 static int get_cb_fehash_hdr(void);
119 static int get_cb_fehash(void);
120 static int get_he(afs_uint32 idx);
121 static int get_he_hdr(void);
122 static int get_he_entry(void);
123 static int get_fe(afs_uint32 idx);
124 static int get_fe_hdr(void);
125 static int get_fe_entry(void);
126 static int get_cb(afs_uint32 idx);
127 static int get_cb_entry(void);
129 static int find_fe_by_index(afs_uint32 idx);
130 static int find_cb_by_index(afs_uint32 idx);
131 static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq);
134 static int dump_fd = -1;
135 static void * map = NULL;
136 static size_t map_len;
139 struct fs_state_header hdr;
140 struct host_state_header h_hdr;
141 struct callback_state_header cb_hdr;
142 struct callback_state_timeout_header timeout_hdr;
143 struct callback_state_fehash_header fehash_hdr;
144 afs_uint32 * timeout;
147 /* pointers into the memory map */
151 void * timeout_hdr_p;
159 byte timeout_hdr_valid;
160 byte fehash_hdr_valid;
168 struct host_state_entry_header hdr;
169 struct hostDiskEntry he;
183 struct callback_state_entry_header hdr;
184 struct FEDiskEntry fe;
196 struct CBDiskEntry cb;
204 fprintf(stderr, "usage: %s [<state dump file>]\n", prog);
208 main(int argc, char ** argv)
211 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
219 if (openFile(argv[1]))
222 if (openFile((char *)AFSDIR_SERVER_FSSTATE_FILEPATH))
232 openFile(char * path)
235 struct afs_stat status;
237 dump_fd = afs_open(path, O_RDWR);
239 fprintf(stderr, "dump file '%s' failed to open\n", path);
244 printf("opened dump file '%s'\n", path);
246 if (afs_fstat(dump_fd, &status) == -1) {
247 fprintf(stderr, "failed to stat file\n");
252 map_len = status.st_size;
254 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
255 if (map == MAP_FAILED) {
256 fprintf(stderr, "failed to mmap file\n");
261 printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map);
266 munmap(map, map_len);
280 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
281 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
282 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
283 he_cache.cursor = fe_cache.cursor = NULL;
289 fprintf(stderr, "demand attach fs\n");
290 fprintf(stderr, "fileserver state analyzer\n");
291 fprintf(stderr, "version 0.1\n");
294 #define PROGNAME "fs state analyzer"
300 char prev_input[256];
308 } mode = PR_GLOBAL_MODE, next_mode;
311 input[0] = prev_input[0] = '\0';
317 printf(PROGNAME "> ");
320 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
323 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
326 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
329 fprintf(stderr, "prompt state broken; aborting\n");
332 fgets(input, 256, stdin);
334 if (!strcmp(input, "")) {
335 /* repeat last command */
336 if (!strcmp(prev_input, "")) {
339 strlcpy(input, prev_input, sizeof(input));
341 /* save command for repetition */
342 strlcpy(prev_input, input, sizeof(prev_input));
345 tok = strtok(input, " \t\n");
347 while (tok && !strcmp(tok, ";")) {
348 tok = strtok(NULL, "; \t\n");
355 if (!strcasecmp(tok, "exit")) {
357 } else if (!strcasecmp(tok, "quit")) {
360 next_mode = PR_FE_MODE;
364 next_mode = PR_GLOBAL_MODE;
369 } else if (!strcasecmp(tok, "h")) {
370 tok = strtok(NULL, " \t");
376 } else if (!strcasecmp(tok, "fe")) {
377 tok = strtok(NULL, " \t");
383 } else if (!strcasecmp(tok, "fs")) {
384 tok = strtok(NULL, " \t");
385 mode = PR_GLOBAL_MODE;
390 } else if (!strcasecmp(tok, "cb")) {
391 tok = strtok(NULL, " \t");
397 } else if (!strcasecmp(tok, "help")) {
412 } else if (!strcasecmp(tok, "hexdump")) {
413 tok = strtok(NULL, " \t");
415 hexdump_map(0, map_len);
418 if (sscanf(tok, "%u", &x) != 1) {
419 fprintf(stderr, "hexdump parse error 1\n");
423 tok = strtok(NULL, " \t");
425 hexdump_map(x, map_len - x);
428 if (sscanf(tok, "%u", &y) != 1) {
429 fprintf(stderr, "hexdump parse error 2\n");
433 } else if (!strcasecmp(tok, "hdr")) {
447 } else if (!strcasecmp(tok, "this")) {
459 fprintf(stderr, "command not valid for this mode\n");
461 } else if (!strcasecmp(tok, "next")) {
473 fprintf(stderr, "command not valid for this mode\n");
475 } else if (!strcasecmp(tok, "prev")) {
487 fprintf(stderr, "command not valid for this mode\n");
489 } else if (!strcasecmp(tok, "first")) {
501 fprintf(stderr, "command not valid for this mode\n");
503 } else if (!strcasecmp(tok, "last")) {
515 fprintf(stderr, "command not valid for this mode\n");
517 } else if (!strcasecmp(tok, "dump")) {
529 fprintf(stderr, "command not valid for this mode\n");
531 } else if (!strcasecmp(tok, "find")) {
532 tok = strtok(NULL, " \t");
533 if (!tok || strcasecmp(tok, "by")) {
535 fprintf(stderr, "find syntax error 1 (%s)\n",
536 (tok) ? tok : "nil");
539 tok = strtok(NULL, " \t");
541 fprintf(stderr, "find syntax error 2\n");
546 fprintf(stderr, "not implemented yet\n");
549 if (!strcasecmp(tok, "index")) {
550 tok = strtok(NULL, " \t");
551 if (!tok || sscanf(tok, "%u", &x) != 1) {
553 fprintf(stderr, "find syntax error 3\n");
556 if (find_fe_by_index(x)) {
557 fprintf(stderr, "find returned no results\n");
559 } else if (!strcasecmp(tok, "fid")) {
560 tok = strtok(NULL, "(), \t");
561 if (!tok || sscanf(tok, "%u", &x) != 1) {
563 fprintf(stderr, "find syntax error 4\n");
566 tok = strtok(NULL, "(), \t");
567 if (!tok || sscanf(tok, "%u", &y) != 1) {
569 fprintf(stderr, "find syntax error 5\n");
572 tok = strtok(NULL, "(), \t");
573 if (!tok || sscanf(tok, "%u", &z) != 1) {
575 fprintf(stderr, "find syntax error 6\n");
578 if (find_fe_by_fid(x,y,z)) {
579 fprintf(stderr, "find returned no results\n");
582 fprintf(stderr, "unsupported filter type\n");
586 if (!strcasecmp(tok, "index")) {
587 tok = strtok(NULL, " \t");
588 if (!tok || sscanf(tok, "%u", &x) != 1) {
590 fprintf(stderr, "find syntax error 3\n");
593 if (find_cb_by_index(x)) {
594 fprintf(stderr, "find returned no results\n");
597 fprintf(stderr, "unsupported filter type\n");
601 fprintf(stderr, "find not supported for this menu\n");
603 } else if (!strcspn(tok, "0123456789")) {
604 if (sscanf(tok, "%u", &x) == 1) {
616 fprintf(stderr, "command not available from this menu\n");
619 fprintf(stderr, "input parse error ('%s')\n", tok);
621 } else if (mode == PR_FE_MODE) {
622 if (!strcmp(tok, "timeout")) {
624 } else if (!strcmp(tok, "hash")) {
628 fprintf(stderr, "unknown command\n");
630 tok = strtok(NULL, " \t");
638 printf("\th <...> -- host menu commands\n");
639 printf("\tfe <...> -- FileEntry menu commands\n");
640 printf("\tcb <...> -- CallBack menu commands\n");
641 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
642 printf("\tquit -- quit this menu\n");
643 printf("\texit -- exit the debugger\n");
644 printf("\thelp -- this help message\n");
648 print_global_help(void)
650 printf("\thdr -- display the fs_state_header struct\n");
656 printf("\thdr -- display the host_state_header struct\n");
657 printf("\tfirst -- display the first host\n");
658 printf("\tprev -- display the previous host\n");
659 printf("\tthis -- display this host\n");
660 printf("\tnext -- display the next host\n");
661 printf("\tlast -- display the last host\n");
662 printf("\tdump -- display all hosts\n");
668 printf("\thdr -- display the callback_state_header struct\n");
669 printf("\tfirst -- display the first FE\n");
670 printf("\tprev -- display the previous FE\n");
671 printf("\tthis -- display this FE\n");
672 printf("\tnext -- display the next FE\n");
673 printf("\tlast -- display the last FE\n");
674 printf("\tdump -- display all FEs\n");
675 printf("\ttimeout -- display the timeout queue heads\n");
676 printf("\thash -- display the file entry hash buckets\n");
677 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
678 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
684 printf("\thdr -- display the callback_state_entry_header struct\n");
685 printf("\tfirst -- display the first CB\n");
686 printf("\tprev -- display the previous CB\n");
687 printf("\tthis -- display this CB\n");
688 printf("\tnext -- display the next CB\n");
689 printf("\tlast -- display the last CB\n");
690 printf("\tdump -- display all CBs\n");
694 #define DPFTB1 "\t\t"
695 #define DPFTB2 "\t\t\t"
697 #define DPFOFF(addr) \
699 char * _p = (char *)addr; \
700 char * _m = (char *)map; \
701 printf("loading structure from address %"AFS_PTR_FMT" (offset %ld)\n", \
702 addr, (long)(_p-_m)); \
706 #define DPFSO(T, name) printf(T "%s = {\n", name)
707 #define DPFSO0(name) DPFSO(DPFTB0, name)
708 #define DPFSO1(name) DPFSO(DPFTB1, name)
709 #define DPFSC(T) printf(T "}\n")
710 #define DPFSC0 DPFSC(DPFTB0)
711 #define DPFSC1 DPFSC(DPFTB1)
714 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
715 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
716 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
717 #define DPFAC0 printf(" }\n")
718 #define DPFAC1 DPFAC0
719 #define DPFA1 printf(DPFTB1 " ")
720 #define DPFA2 printf(DPFTB2 " ")
721 #define DPFAN printf("\n")
722 #define DPFALE(type, var) printf("%" type, var)
723 #define DPFAE(type, var) printf("%" type ",\t", var)
726 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
727 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
728 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
731 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
732 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
733 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
736 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
737 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
738 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
741 #define DPFT(T, name, var) \
744 printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \
746 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
747 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
759 DPFSO0("fs_state_header");
761 DPFX2("magic", hdrs.hdr.stamp.magic);
762 DPFV2("version", "u", hdrs.hdr.stamp.version);
764 DPFT1("timestamp", hdrs.hdr.timestamp);
765 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
767 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
768 DPFS1("server_uuid", uuid_str);
769 DPFV1("valid", "d", hdrs.hdr.valid);
770 DPFV1("endianness", "d", hdrs.hdr.endianness);
771 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
773 SplitInt64(hdrs.hdr.h_offset, hi, lo);
775 DPFV2("hi", "u", hi);
776 DPFV2("lo", "u", lo);
779 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
781 DPFV2("hi", "u", hi);
782 DPFV2("lo", "u", lo);
785 DPFS1("server_version_string", hdrs.hdr.server_version_string);
788 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
789 fprintf(stderr, "* magic check failed\n");
791 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
792 fprintf(stderr, "* version check failed\n");
802 DPFOFF(hdrs.h_hdr_p);
803 DPFSO0("host_state_header");
805 DPFX2("magic", hdrs.h_hdr.stamp.magic);
806 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
808 DPFV1("records", "u", hdrs.h_hdr.records);
809 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
812 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
813 fprintf(stderr, "* magic check failed\n");
815 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
816 fprintf(stderr, "* version check failed\n");
828 DPFOFF(hdrs.cb_hdr_p);
829 DPFSO0("callback_state_header");
831 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
832 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
834 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
835 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
836 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
837 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
838 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
840 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
841 DPFSO1("timeout_offset");
842 DPFV2("hi", "u", hi);
843 DPFV2("lo", "u", lo);
846 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
847 DPFSO1("fehash_offset");
848 DPFV2("hi", "u", hi);
849 DPFV2("lo", "u", lo);
852 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
854 DPFV2("hi", "u", hi);
855 DPFV2("lo", "u", lo);
860 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
861 fprintf(stderr, "* magic check failed\n");
863 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
864 fprintf(stderr, "* version check failed\n");
869 dump_cb_timeout(void)
876 if (get_cb_timeout_hdr())
879 if (get_cb_timeout())
882 DPFOFF(hdrs.timeout_hdr_p);
883 DPFSO0("callback_state_timeout_header");
884 DPFX1("magic", hdrs.timeout_hdr.magic);
885 DPFV1("len", "u", hdrs.timeout_hdr.len);
886 DPFV1("records", "u", hdrs.timeout_hdr.records);
889 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
890 fprintf(stderr, "* magic check failed\n");
893 DPFOFF(hdrs.timeout_p);
895 for (i = 0; i < 127; i++) {
896 DPFAE("u", hdrs.timeout[i]);
902 DPFALE("u", hdrs.timeout[127]);
914 if (get_cb_fehash_hdr())
920 DPFOFF(hdrs.fehash_hdr_p);
921 DPFSO0("callback_state_fehash_header");
922 DPFX1("magic", hdrs.fehash_hdr.magic);
923 DPFV1("len", "u", hdrs.fehash_hdr.len);
924 DPFV1("records", "u", hdrs.fehash_hdr.records);
927 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
928 fprintf(stderr, "* magic check failed\n");
931 DPFOFF(hdrs.fehash_p);
933 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
934 DPFAE("u", hdrs.fehash[i]);
940 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
950 fprintf(stderr, "error getting host_state_header\n");
954 for (i = 0; i < hdrs.h_hdr.records; i++) {
965 fprintf(stderr, "error getting callback_state_header\n");
969 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
980 fprintf(stderr, "error getting callback_state_entry_header\n");
984 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
990 dump_he(afs_uint32 idx)
993 fprintf(stderr, "error getting he %d\n", idx);
997 DPFOFF(he_cursor.cursor);
1000 dump_he_interfaces();
1005 dump_fe(afs_uint32 idx)
1008 fprintf(stderr, "error getting fe %d\n", idx);
1012 DPFOFF(fe_cursor.cursor);
1018 dump_cb(afs_uint32 idx)
1021 fprintf(stderr, "error getting cb %d\n", idx);
1025 DPFOFF(cb_cursor.cursor);
1032 dump_he(he_cursor.idx);
1038 dump_fe(fe_cursor.idx);
1044 dump_cb(cb_cursor.idx);
1051 fprintf(stderr, "error getting host_state_header\n");
1055 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1056 fprintf(stderr, "no more HEs\n");
1060 dump_he(he_cursor.idx+1);
1067 fprintf(stderr, "error getting callback_state_header\n");
1071 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1072 fprintf(stderr, "no more FEs\n");
1076 dump_fe(fe_cursor.idx+1);
1083 fprintf(stderr, "error getting callback_state_entry_header\n");
1087 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1088 fprintf(stderr, "no more CBs\n");
1092 dump_cb(cb_cursor.idx+1);
1098 if (!he_cursor.idx) {
1099 fprintf(stderr, "no more HEs\n");
1103 dump_he(he_cursor.idx-1);
1109 if (!fe_cursor.idx) {
1110 fprintf(stderr, "no more FEs\n");
1114 dump_fe(fe_cursor.idx-1);
1120 if (!cb_cursor.idx) {
1121 fprintf(stderr, "no more CBs\n");
1125 dump_cb(cb_cursor.idx-1);
1132 fprintf(stderr, "error getting callback_state_header\n");
1136 if (!hdrs.cb_hdr.nFEs) {
1137 fprintf(stderr, "no FEs present\n");
1148 fprintf(stderr, "error getting host_state_header\n");
1152 if (!hdrs.h_hdr.records) {
1153 fprintf(stderr, "no HEs present\n");
1164 fprintf(stderr, "error getting callback_state_entry_header\n");
1168 if (!fe_cursor.hdr.nCBs) {
1169 fprintf(stderr, "no CBs present\n");
1180 fprintf(stderr, "error getting host_state_header\n");
1184 if (!hdrs.h_hdr.records) {
1185 fprintf(stderr, "no HEs present\n");
1189 dump_he(hdrs.h_hdr.records-1);
1196 fprintf(stderr, "error getting callback_state_header\n");
1200 if (!hdrs.cb_hdr.nFEs) {
1201 fprintf(stderr, "no FEs present\n");
1205 dump_fe(hdrs.cb_hdr.nFEs-1);
1212 fprintf(stderr, "error getting callback_state_entry_header\n");
1216 if (!fe_cursor.hdr.nCBs) {
1217 fprintf(stderr, "no CBs present\n");
1221 dump_cb(fe_cursor.hdr.nCBs-1);
1227 DPFSO0("host_state_entry_header");
1228 DPFX1("magic", he_cursor.hdr.magic);
1229 DPFV1("len", "u", he_cursor.hdr.len);
1230 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1231 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1234 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1235 fprintf(stderr, "* magic check failed\n");
1243 DPFSO0("hostDiskEntry");
1244 DPFS1("host", afs_inet_ntoa_r(he_cursor.he.host, hoststr));
1245 DPFV1("port", "u", he_cursor.he.port);
1246 DPFX1("hostFlags", he_cursor.he.hostFlags);
1247 DPFV1("Console", "u", he_cursor.he.Console);
1248 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1249 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1250 if (hdrs.hdr.stats_detailed) {
1251 #ifdef FS_STATS_DETAILED
1252 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1254 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1257 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1258 DPFT1("LastCall", he_cursor.he.LastCall);
1259 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1260 DPFT1("cpsCall", he_cursor.he.cpsCall);
1261 DPFV1("cblist", "u", he_cursor.he.cblist);
1262 DPFV1("index", "u", he_cursor.he.index);
1267 dump_he_interfaces(void)
1270 struct Interface * ifp;
1274 if (!he_cursor.hdr.interfaces)
1277 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1278 ifp = (struct Interface *) malloc(len);
1279 assert(ifp != NULL);
1281 memcpy(ifp, he_cursor.ifp, len);
1283 DPFSO0("Interface");
1284 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1286 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1287 DPFS1("uuid", temp_str);
1288 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1289 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1291 DPFS2("addr", afs_inet_ntoa_r(ifp->interface[i].addr, hoststr));
1292 DPFV2("port", "u", ifp->interface[i].port);
1298 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1299 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1310 if (!he_cursor.hdr.hcps)
1313 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1314 hcps = (afs_int32 *) malloc(len);
1315 assert(hcps != NULL);
1316 memcpy(hcps, he_cursor.hcps, len);
1319 DPFAO1("prlist_val");
1320 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1321 DPFAE("d", hcps[i]);
1327 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1336 DPFSO0("callback_state_entry_header");
1337 DPFX1("magic", fe_cursor.hdr.magic);
1338 DPFV1("len", "u", fe_cursor.hdr.len);
1339 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1342 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1343 fprintf(stderr, "* magic check failed\n");
1350 DPFSO0("FEDiskEntry");
1352 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1353 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1354 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1355 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1356 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1357 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1358 DPFV2("status", "u", fe_cursor.fe.fe.status);
1360 DPFV1("index", "u", fe_cursor.fe.index);
1367 DPFSO0("CBDiskEntry");
1369 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1370 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1371 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1372 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1373 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1374 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1375 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1376 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1377 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1379 DPFV1("index", "u", cb_cursor.cb.index);
1383 #define DPFHMS printf(" ")
1384 #define DPFHS printf(" ")
1385 #define DPFHN(offset) printf("\n%u\t", offset)
1386 #define DPFHD(x) printf("%02X ", x)
1387 #define DPFHE printf("\n")
1390 hexdump_map(afs_uint32 offset, afs_uint32 len)
1393 unsigned char * p = (unsigned char *)map;
1398 if ((offset + len) > map_len) {
1399 fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n",
1400 offset+len, (unsigned long)map_len);
1408 for (i = offset % 16; i > 0; i--) {
1412 for (i=0; i < len; i++, p++, offset++) {
1413 if (!(offset % 16)) {
1415 } else if (!(offset % 8)) {
1426 if (!hdrs.hdr_valid) {
1427 if (map_len < sizeof(struct fs_state_header)) {
1428 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1431 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1444 if (hdrs.h_hdr_valid)
1450 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1453 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1456 if ((lo >= map_len) ||
1457 ((lo + sizeof(struct host_state_header)) > map_len) ||
1458 (lo + sizeof(struct host_state_header) < lo)) {
1459 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1465 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1467 buf += sizeof(struct host_state_header);
1468 he_cursor.fh = (void *)buf;
1478 if (hdrs.cb_hdr_valid)
1484 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1487 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1490 if ((lo >= map_len) ||
1491 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1492 (lo + sizeof(struct callback_state_header) < lo)) {
1493 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1499 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1500 hdrs.cb_hdr_p = buf;
1501 hdrs.cb_hdr_valid = 1;
1503 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1506 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1509 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1510 sizeof(struct FEDiskEntry)) +
1511 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1512 if ((hi > map_len) ||
1514 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1520 fe_cursor.ffe = (void *)buf;
1526 get_cb_timeout_hdr(void)
1531 if (hdrs.timeout_hdr_valid)
1537 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1540 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1543 if ((lo >= map_len) ||
1544 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1545 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1546 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1552 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1553 hdrs.timeout_hdr_p = buf;
1554 hdrs.timeout_hdr_valid = 1;
1555 buf += sizeof(struct callback_state_timeout_header);
1556 hdrs.timeout_p = buf;
1562 get_cb_timeout(void)
1567 if (get_cb_timeout_hdr())
1570 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1571 assert(hdrs.timeout != NULL);
1572 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1577 get_cb_fehash_hdr(void)
1582 if (hdrs.fehash_hdr_valid)
1588 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1591 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1594 if ((lo >= map_len) ||
1595 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1596 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1597 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1603 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1604 hdrs.fehash_hdr_p = buf;
1605 hdrs.fehash_hdr_valid = 1;
1606 buf += sizeof(struct callback_state_fehash_header);
1607 hdrs.fehash_p = buf;
1618 if (get_cb_fehash_hdr())
1621 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1622 assert(hdrs.fehash != NULL);
1623 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1628 get_he(afs_uint32 idx)
1636 if (idx >= hdrs.h_hdr.records)
1639 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1642 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1644 if (he_cache.cursor == NULL) {
1645 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1646 assert(he_cache.cursor != NULL);
1649 if (idx && he_cache.cursor[idx-1] == NULL) {
1650 for (i = 0; i < idx; i++) {
1651 if (he_cache.cursor[i] == NULL) {
1658 he_cursor.cursor = he_cursor.fh;
1659 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1660 p = (char *)he_cursor.cursor;
1661 p += he_cursor.hdr.len;
1662 he_cursor.cursor = (void *)p;
1664 he_cursor.cursor = he_cache.cursor[idx-1];
1667 p = (char *)he_cursor.cursor;
1668 p += he_cursor.hdr.len;
1669 he_cursor.cursor = (void *)p;
1672 he_cursor.idx = idx;
1673 he_cache.cursor[idx] = he_cursor.cursor;
1686 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1687 he_cursor.hdr_valid = 1;
1696 if (!he_cursor.hdr_valid) {
1702 p = (char *) he_cursor.cursor;
1703 p += sizeof(struct host_state_entry_header);
1705 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1707 he_cursor.he_valid = 1;
1708 p += sizeof(struct hostDiskEntry);
1709 he_cursor.ifp = (void *)p;
1710 if (he_cursor.hdr.interfaces) {
1711 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1712 he_cursor.hcps = (void *)p;
1714 he_cursor.hcps = he_cursor.ifp;
1720 get_fe(afs_uint32 idx)
1725 cb_cursor.cb_valid = 0;
1730 if (idx >= hdrs.cb_hdr.nFEs)
1733 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1736 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1738 if (fe_cache.cursor == NULL) {
1739 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1740 assert(fe_cache.cursor != NULL);
1743 if (idx && fe_cache.cursor[idx-1] == NULL) {
1744 for (i = 0; i < idx; i++) {
1745 if (fe_cache.cursor[i] == NULL) {
1752 fe_cursor.cursor = fe_cursor.ffe;
1753 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1754 p = (char *)fe_cursor.cursor;
1755 p += fe_cursor.hdr.len;
1756 fe_cursor.cursor = (void *)p;
1758 fe_cursor.cursor = fe_cache.cursor[idx-1];
1761 p = (char *)fe_cursor.cursor;
1762 p += fe_cursor.hdr.len;
1763 fe_cursor.cursor = (void *)p;
1766 fe_cursor.idx = idx;
1767 fe_cache.cursor[idx] = fe_cursor.cursor;
1780 if (!fe_cursor.cursor) {
1781 if(get_fe(fe_cursor.idx)) {
1786 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1787 fe_cursor.hdr_valid = 1;
1796 if (!fe_cursor.hdr_valid) {
1802 p = (char *) fe_cursor.cursor;
1803 p += sizeof(struct callback_state_entry_header);
1805 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1807 fe_cursor.fe_valid = 1;
1808 p += sizeof(struct FEDiskEntry);
1809 fe_cursor.fcb = (void *)p;
1814 get_cb(afs_uint32 idx)
1818 if (get_fe(fe_cursor.idx))
1821 if (idx >= fe_cursor.hdr.nCBs)
1824 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1827 cb_cursor.cb_valid = 0;
1829 p = (char *)fe_cursor.fcb;
1830 p += idx * sizeof(struct CBDiskEntry);
1831 cb_cursor.cursor = (void *)p;
1833 cb_cursor.idx = idx;
1844 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1845 cb_cursor.cb_valid = 1;
1851 find_he_by_index(afs_uint32 idx)
1859 for (i = 0; i < hdrs.h_hdr.records; i++) {
1861 fprintf(stderr, "error getting he %d\n", i);
1864 if (he_cursor.he.index == idx)
1868 if (i < hdrs.h_hdr.records) {
1877 find_fe_by_index(afs_uint32 idx)
1885 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1887 fprintf(stderr, "error getting fe %d\n", i);
1890 if (fe_cursor.fe.index == idx)
1894 if (i < hdrs.cb_hdr.nFEs) {
1902 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1910 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1912 fprintf(stderr, "error getting fe %d\n", i);
1915 if ((fe_cursor.fe.fe.unique == unique) &&
1916 (fe_cursor.fe.fe.volid == volid) &&
1917 (fe_cursor.fe.fe.vnode == vnode))
1921 if (i < hdrs.cb_hdr.nFEs) {
1929 find_cb_by_index(afs_uint32 idx)
1937 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1939 fprintf(stderr, "error getting cb %d\n", i);
1942 if (cb_cursor.cb.index == idx)
1946 if (i < fe_cursor.hdr.nCBs) {
1953 #endif /* AFS_DEMAND_ATTACH_FS */