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>
56 #include <afs/afsutil.h>
58 #include <afs/cellconfig.h>
60 #include "../util/afsutil_prototypes.h"
61 #include "../viced/viced.h"
62 #include "../viced/host.h"
63 #include "../viced/callback.h"
64 #include "serialize_state.h"
66 #include <sys/types.h>
71 /*@+fcnmacros +macrofcndecl@*/
74 extern off64_t afs_lseek(int FD, off64_t O, int F);
75 #endif /*S_SPLINT_S */
76 #define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F)
77 #define afs_stat stat64
78 #define afs_fstat fstat64
79 #define afs_open open64
80 #define afs_fopen fopen64
81 #define afs_mmap mmap64
83 extern void * mmap64(); /* ugly hack since aix build env appears to be somewhat broken */
85 #else /* !O_LARGEFILE */
87 extern off_t afs_lseek(int FD, off_t O, int F);
88 #endif /*S_SPLINT_S */
89 #define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F)
91 #define afs_fstat fstat
93 #define afs_fopen fopen
95 #endif /* !O_LARGEFILE */
96 /*@=fcnmacros =macrofcndecl@*/
99 #ifndef AFS_DEMAND_ATTACH_FS
101 main (int argc, char ** argv)
103 fprintf(stderr, "%s is only supported for demand attach fileservers\n",
104 argv[0] ? argv[0] : "state analyzer");
107 #else /* AFS_DEMAND_ATTACH_FS */
109 static void usage(char * prog);
110 static int openFile(char * path);
111 static void initState(void);
113 static void banner(void);
114 static void prompt(void);
116 static void print_help(void);
117 static void print_global_help(void);
118 static void print_h_help(void);
119 static void print_fe_help(void);
120 static void print_cb_help(void);
122 static void dump_hdr(void);
123 static void dump_h_hdr(void);
124 static void dump_cb_hdr(void);
126 static void dump_cb_timeout(void);
127 static void dump_cb_fehash(void);
129 static void dump_all_hes(void);
130 static void dump_all_fes(void);
131 static void dump_all_cbs(void);
133 static void dump_he(afs_uint32 idx);
134 static void dump_fe(afs_uint32 idx);
135 static void dump_cb(afs_uint32 idx);
136 static void dump_this_he(void);
137 static void dump_this_fe(void);
138 static void dump_this_cb(void);
139 static void dump_next_he(void);
140 static void dump_next_fe(void);
141 static void dump_next_cb(void);
142 static void dump_prev_he(void);
143 static void dump_prev_fe(void);
144 static void dump_prev_cb(void);
145 static void dump_first_he(void);
146 static void dump_first_fe(void);
147 static void dump_first_cb(void);
148 static void dump_last_he(void);
149 static void dump_last_fe(void);
150 static void dump_last_cb(void);
151 static void dump_he_hdr(void);
152 static void dump_he_entry(void);
153 static void dump_he_interfaces(void);
154 static void dump_he_hcps(void);
155 static void dump_fe_hdr(void);
156 static void dump_fe_entry(void);
157 static void dump_cb_entry(void);
159 static void hexdump_map(afs_uint32 offset, afs_uint32 len);
161 static int get_hdr(void);
162 static int get_h_hdr(void);
163 static int get_cb_hdr(void);
164 static int get_cb_timeout_hdr(void);
165 static int get_cb_timeout(void);
166 static int get_cb_fehash_hdr(void);
167 static int get_cb_fehash(void);
168 static int get_he(afs_uint32 idx);
169 static int get_he_hdr(void);
170 static int get_he_entry(void);
171 static int get_fe(afs_uint32 idx);
172 static int get_fe_hdr(void);
173 static int get_fe_entry(void);
174 static int get_cb(afs_uint32 idx);
175 static int get_cb_entry(void);
177 static int find_fe_by_index(afs_uint32 idx);
178 static int find_cb_by_index(afs_uint32 idx);
179 static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq);
182 static int dump_fd = -1;
183 static void * map = NULL;
184 static size_t map_len;
187 struct fs_state_header hdr;
188 struct host_state_header h_hdr;
189 struct callback_state_header cb_hdr;
190 struct callback_state_timeout_header timeout_hdr;
191 struct callback_state_fehash_header fehash_hdr;
192 afs_uint32 * timeout;
195 /* pointers into the memory map */
199 void * timeout_hdr_p;
207 byte timeout_hdr_valid;
208 byte fehash_hdr_valid;
216 struct host_state_entry_header hdr;
217 struct hostDiskEntry he;
231 struct callback_state_entry_header hdr;
232 struct FEDiskEntry fe;
244 struct CBDiskEntry cb;
256 fprintf(stderr, "usage: %s [<state dump file>]\n");
260 main(int argc, char ** argv)
264 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
272 if (openFile(argv[1]))
275 if (openFile(AFSDIR_SERVER_FSSTATE_FILEPATH))
285 openFile(char * path)
288 struct afs_stat status;
290 dump_fd = afs_open(path, O_RDWR);
292 fprintf(stderr, "dump file '%s' failed to open\n", path);
297 printf("opened dump file '%s'\n", path);
299 if (afs_fstat(dump_fd, &status) == -1) {
300 fprintf(stderr, "failed to stat file\n");
305 map_len = status.st_size;
307 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
308 if (map == MAP_FAILED) {
309 fprintf(stderr, "failed to mmap file\n");
314 printf("mapped %d bytes at 0x%x\n", map_len, map);
319 munmap(map, map_len);
333 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
334 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
335 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
336 he_cache.cursor = fe_cache.cursor = NULL;
342 fprintf(stderr, "demand attach fs\n");
343 fprintf(stderr, "fileserver state analyzer\n");
344 fprintf(stderr, "version 0.1\n");
347 #define PROGNAME "fs state analyzer"
353 char prev_input[256];
361 } mode = PR_GLOBAL_MODE, next_mode;
364 input[0] = prev_input[0] = '\0';
370 printf(PROGNAME "> ");
373 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
376 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
379 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
382 fprintf(stderr, "prompt state broken; aborting\n");
387 if (!strcmp(input, "")) {
388 /* repeat last command */
389 if (!strcmp(prev_input, "")) {
392 strlcpy(input, prev_input, sizeof(input));
394 /* save command for repetition */
395 strlcpy(prev_input, input, sizeof(prev_input));
398 tok = strtok(input, " \t");
400 while (tok && !strcmp(tok, ";")) {
401 tok = strtok(NULL, "; \t");
408 if (!strcasecmp(tok, "exit")) {
410 } else if (!strcasecmp(tok, "quit")) {
413 next_mode = PR_FE_MODE;
417 next_mode = PR_GLOBAL_MODE;
422 } else if (!strcasecmp(tok, "h")) {
423 tok = strtok(NULL, " \t");
429 } else if (!strcasecmp(tok, "fe")) {
430 tok = strtok(NULL, " \t");
436 } else if (!strcasecmp(tok, "fs")) {
437 tok = strtok(NULL, " \t");
438 mode = PR_GLOBAL_MODE;
443 } else if (!strcasecmp(tok, "cb")) {
444 tok = strtok(NULL, " \t");
450 } else if (!strcasecmp(tok, "help")) {
465 } else if (!strcasecmp(tok, "hexdump")) {
466 tok = strtok(NULL, " \t");
468 hexdump_map(0, map_len);
471 if (sscanf(tok, "%u", &x) != 1) {
472 fprintf(stderr, "hexdump parse error 1\n");
476 tok = strtok(NULL, " \t");
478 hexdump_map(x, map_len - x);
481 if (sscanf(tok, "%u", &y) != 1) {
482 fprintf(stderr, "hexdump parse error 2\n");
486 } else if (!strcasecmp(tok, "hdr")) {
500 } else if (!strcasecmp(tok, "this")) {
512 fprintf(stderr, "command not valid for this mode\n");
514 } else if (!strcasecmp(tok, "next")) {
526 fprintf(stderr, "command not valid for this mode\n");
528 } else if (!strcasecmp(tok, "prev")) {
540 fprintf(stderr, "command not valid for this mode\n");
542 } else if (!strcasecmp(tok, "first")) {
554 fprintf(stderr, "command not valid for this mode\n");
556 } else if (!strcasecmp(tok, "last")) {
568 fprintf(stderr, "command not valid for this mode\n");
570 } else if (!strcasecmp(tok, "dump")) {
582 fprintf(stderr, "command not valid for this mode\n");
584 } else if (!strcasecmp(tok, "find")) {
585 tok = strtok(NULL, " \t");
586 if (!tok || strcasecmp(tok, "by")) {
588 fprintf(stderr, "find syntax error 1 (%s)\n",
589 (tok) ? tok : "nil");
592 tok = strtok(NULL, " \t");
594 fprintf(stderr, "find syntax error 2\n");
599 fprintf(stderr, "not implemented yet\n");
602 if (!strcasecmp(tok, "index")) {
603 tok = strtok(NULL, " \t");
604 if (!tok || sscanf(tok, "%u", &x) != 1) {
606 fprintf(stderr, "find syntax error 3\n");
609 if (find_fe_by_index(x)) {
610 fprintf(stderr, "find returned no results\n");
612 } else if (!strcasecmp(tok, "fid")) {
613 tok = strtok(NULL, "(), \t");
614 if (!tok || sscanf(tok, "%u", &x) != 1) {
616 fprintf(stderr, "find syntax error 4\n");
619 tok = strtok(NULL, "(), \t");
620 if (!tok || sscanf(tok, "%u", &y) != 1) {
622 fprintf(stderr, "find syntax error 5\n");
625 tok = strtok(NULL, "(), \t");
626 if (!tok || sscanf(tok, "%u", &z) != 1) {
628 fprintf(stderr, "find syntax error 6\n");
631 if (find_fe_by_fid(x,y,z)) {
632 fprintf(stderr, "find returned no results\n");
635 fprintf(stderr, "unsupported filter type\n");
639 if (!strcasecmp(tok, "index")) {
640 tok = strtok(NULL, " \t");
641 if (!tok || sscanf(tok, "%u", &x) != 1) {
643 fprintf(stderr, "find syntax error 3\n");
646 if (find_cb_by_index(x)) {
647 fprintf(stderr, "find returned no results\n");
650 fprintf(stderr, "unsupported filter type\n");
654 fprintf(stderr, "find not supported for this menu\n");
656 } else if (!strcspn(tok, "0123456789")) {
657 if (sscanf(tok, "%u", &x) == 1) {
669 fprintf(stderr, "command not available from this menu\n");
672 fprintf(stderr, "input parse error ('%s')\n", tok);
674 } else if (mode == PR_FE_MODE) {
675 if (!strcmp(tok, "timeout")) {
677 } else if (!strcmp(tok, "hash")) {
681 fprintf(stderr, "unknown command\n");
683 tok = strtok(NULL, " \t");
691 printf("\th <...> -- host menu commands\n");
692 printf("\tfe <...> -- FileEntry menu commands\n");
693 printf("\tcb <...> -- CallBack menu commands\n");
694 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
695 printf("\tquit -- quit this menu\n");
696 printf("\texit -- exit the debugger\n");
697 printf("\thelp -- this help message\n");
701 print_global_help(void)
703 printf("\thdr -- display the fs_state_header struct\n");
709 printf("\thdr -- display the host_state_header struct\n");
710 printf("\tfirst -- display the first host\n");
711 printf("\tprev -- display the previous host\n");
712 printf("\tthis -- display this host\n");
713 printf("\tnext -- display the next host\n");
714 printf("\tlast -- display the last host\n");
715 printf("\tdump -- display all hosts\n");
721 printf("\thdr -- display the callback_state_header struct\n");
722 printf("\tfirst -- display the first FE\n");
723 printf("\tprev -- display the previous FE\n");
724 printf("\tthis -- display this FE\n");
725 printf("\tnext -- display the next FE\n");
726 printf("\tlast -- display the last FE\n");
727 printf("\tdump -- display all FEs\n");
728 printf("\ttimeout -- display the timeout queue heads\n");
729 printf("\thash -- display the file entry hash buckets\n");
730 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
731 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
737 printf("\thdr -- display the callback_state_entry_header struct\n");
738 printf("\tfirst -- display the first CB\n");
739 printf("\tprev -- display the previous CB\n");
740 printf("\tthis -- display this CB\n");
741 printf("\tnext -- display the next CB\n");
742 printf("\tlast -- display the last CB\n");
743 printf("\tdump -- display all CBs\n");
747 #define DPFTB1 "\t\t"
748 #define DPFTB2 "\t\t\t"
750 #define DPFOFF(addr) \
752 char * _p = (char *)addr; \
753 char * _m = (char *)map; \
754 printf("loading structure from address 0x%x (offset %u)\n", \
759 #define DPFSO(T, name) printf(T "%s = {\n", name)
760 #define DPFSO0(name) DPFSO(DPFTB0, name)
761 #define DPFSO1(name) DPFSO(DPFTB1, name)
762 #define DPFSC(T) printf(T "}\n")
763 #define DPFSC0 DPFSC(DPFTB0)
764 #define DPFSC1 DPFSC(DPFTB1)
767 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
768 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
769 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
770 #define DPFAC0 printf(" }\n")
771 #define DPFAC1 DPFAC0
772 #define DPFA1 printf(DPFTB1 " ")
773 #define DPFA2 printf(DPFTB2 " ")
774 #define DPFAN printf("\n")
775 #define DPFALE(type, var) printf("%" type, var)
776 #define DPFAE(type, var) printf("%" type ",\t", var)
779 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
780 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
781 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
784 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
785 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
786 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
789 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
790 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
791 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
794 #define DPFT(T, name, var) \
797 printf(T "%s = \"%s\"\n", name, strtok_r(ctime(&(var)), "\r\n", &last)); \
799 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
800 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
812 DPFSO0("fs_state_header");
814 DPFX2("magic", hdrs.hdr.stamp.magic);
815 DPFV2("version", "u", hdrs.hdr.stamp.version);
817 DPFT1("timestamp", hdrs.hdr.timestamp);
818 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
820 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
821 DPFS1("server_uuid", uuid_str);
822 DPFV1("valid", "d", hdrs.hdr.valid);
823 DPFV1("endianness", "d", hdrs.hdr.endianness);
824 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
826 SplitInt64(hdrs.hdr.h_offset, hi, lo);
828 DPFV2("hi", "u", hi);
829 DPFV2("lo", "u", lo);
832 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
834 DPFV2("hi", "u", hi);
835 DPFV2("lo", "u", lo);
838 DPFS1("server_version_string", hdrs.hdr.server_version_string);
841 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
842 fprintf(stderr, "* magic check failed\n");
844 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
845 fprintf(stderr, "* version check failed\n");
855 DPFOFF(hdrs.h_hdr_p);
856 DPFSO0("host_state_header");
858 DPFX2("magic", hdrs.h_hdr.stamp.magic);
859 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
861 DPFV1("records", "u", hdrs.h_hdr.records);
862 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
865 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
866 fprintf(stderr, "* magic check failed\n");
868 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
869 fprintf(stderr, "* version check failed\n");
881 DPFOFF(hdrs.cb_hdr_p);
882 DPFSO0("callback_state_header");
884 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
885 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
887 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
888 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
889 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
890 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
891 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
893 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
894 DPFSO1("timeout_offset");
895 DPFV2("hi", "u", hi);
896 DPFV2("lo", "u", lo);
899 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
900 DPFSO1("fehash_offset");
901 DPFV2("hi", "u", hi);
902 DPFV2("lo", "u", lo);
905 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
907 DPFV2("hi", "u", hi);
908 DPFV2("lo", "u", lo);
913 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
914 fprintf(stderr, "* magic check failed\n");
916 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
917 fprintf(stderr, "* version check failed\n");
922 dump_cb_timeout(void)
929 if (get_cb_timeout_hdr())
932 if (get_cb_timeout())
935 DPFOFF(hdrs.timeout_hdr_p);
936 DPFSO0("callback_state_timeout_header");
937 DPFX1("magic", hdrs.timeout_hdr.magic);
938 DPFV1("len", "u", hdrs.timeout_hdr.len);
939 DPFV1("records", "u", hdrs.timeout_hdr.records);
942 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
943 fprintf(stderr, "* magic check failed\n");
946 DPFOFF(hdrs.timeout_p);
948 for (i = 0; i < 127; i++) {
949 DPFAE("u", hdrs.timeout[i]);
955 DPFALE("u", hdrs.timeout[127]);
967 if (get_cb_fehash_hdr())
973 DPFOFF(hdrs.fehash_hdr_p);
974 DPFSO0("callback_state_fehash_header");
975 DPFX1("magic", hdrs.fehash_hdr.magic);
976 DPFV1("len", "u", hdrs.fehash_hdr.len);
977 DPFV1("records", "u", hdrs.fehash_hdr.records);
980 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
981 fprintf(stderr, "* magic check failed\n");
984 DPFOFF(hdrs.fehash_p);
986 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
987 DPFAE("u", hdrs.fehash[i]);
993 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
1003 fprintf(stderr, "error getting host_state_header\n");
1007 for (i = 0; i < hdrs.h_hdr.records; i++) {
1018 fprintf(stderr, "error getting callback_state_header\n");
1022 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1033 fprintf(stderr, "error getting callback_state_entry_header\n");
1037 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1043 dump_he(afs_uint32 idx)
1046 fprintf(stderr, "error getting he %d\n", idx);
1050 DPFOFF(he_cursor.cursor);
1053 dump_he_interfaces();
1058 dump_fe(afs_uint32 idx)
1061 fprintf(stderr, "error getting fe %d\n", idx);
1065 DPFOFF(fe_cursor.cursor);
1071 dump_cb(afs_uint32 idx)
1074 fprintf(stderr, "error getting cb %d\n", idx);
1078 DPFOFF(cb_cursor.cursor);
1085 dump_he(he_cursor.idx);
1091 dump_fe(fe_cursor.idx);
1097 dump_cb(cb_cursor.idx);
1104 fprintf(stderr, "error getting host_state_header\n");
1108 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1109 fprintf(stderr, "no more HEs\n");
1113 dump_he(he_cursor.idx+1);
1120 fprintf(stderr, "error getting callback_state_header\n");
1124 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1125 fprintf(stderr, "no more FEs\n");
1129 dump_fe(fe_cursor.idx+1);
1136 fprintf(stderr, "error getting callback_state_entry_header\n");
1140 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1141 fprintf(stderr, "no more CBs\n");
1145 dump_cb(cb_cursor.idx+1);
1151 if (!he_cursor.idx) {
1152 fprintf(stderr, "no more HEs\n");
1156 dump_he(he_cursor.idx-1);
1162 if (!fe_cursor.idx) {
1163 fprintf(stderr, "no more FEs\n");
1167 dump_fe(fe_cursor.idx-1);
1173 if (!cb_cursor.idx) {
1174 fprintf(stderr, "no more CBs\n");
1178 dump_cb(cb_cursor.idx-1);
1185 fprintf(stderr, "error getting callback_state_header\n");
1189 if (!hdrs.cb_hdr.nFEs) {
1190 fprintf(stderr, "no FEs present\n");
1201 fprintf(stderr, "error getting host_state_header\n");
1205 if (!hdrs.h_hdr.records) {
1206 fprintf(stderr, "no HEs present\n");
1217 fprintf(stderr, "error getting callback_state_entry_header\n");
1221 if (!fe_cursor.hdr.nCBs) {
1222 fprintf(stderr, "no CBs present\n");
1233 fprintf(stderr, "error getting host_state_header\n");
1237 if (!hdrs.h_hdr.records) {
1238 fprintf(stderr, "no HEs present\n");
1242 dump_he(hdrs.h_hdr.records-1);
1249 fprintf(stderr, "error getting callback_state_header\n");
1253 if (!hdrs.cb_hdr.nFEs) {
1254 fprintf(stderr, "no FEs present\n");
1258 dump_fe(hdrs.cb_hdr.nFEs-1);
1265 fprintf(stderr, "error getting callback_state_entry_header\n");
1269 if (!fe_cursor.hdr.nCBs) {
1270 fprintf(stderr, "no CBs present\n");
1274 dump_cb(fe_cursor.hdr.nCBs-1);
1280 DPFSO0("host_state_entry_header");
1281 DPFX1("magic", he_cursor.hdr.magic);
1282 DPFV1("len", "u", he_cursor.hdr.len);
1283 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1284 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1287 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1288 fprintf(stderr, "* magic check failed\n");
1295 DPFSO0("hostDiskEntry");
1296 DPFS1("host", afs_inet_ntoa(he_cursor.he.host));
1297 DPFV1("port", "u", he_cursor.he.port);
1298 DPFX1("hostFlags", he_cursor.he.hostFlags);
1299 DPFV1("Console", "u", he_cursor.he.Console);
1300 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1301 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1302 if (hdrs.hdr.stats_detailed) {
1303 #ifdef FS_STATS_DETAILED
1304 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1306 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1309 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1310 DPFT1("LastCall", he_cursor.he.LastCall);
1311 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1312 DPFT1("cpsCall", he_cursor.he.cpsCall);
1313 DPFV1("cblist", "u", he_cursor.he.cblist);
1314 DPFV1("index", "u", he_cursor.he.index);
1319 dump_he_interfaces(void)
1322 struct Interface * ifp;
1325 if (!he_cursor.hdr.interfaces)
1328 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1329 ifp = (struct Interface *) malloc(len);
1330 assert(ifp != NULL);
1332 memcpy(ifp, he_cursor.ifp, len);
1334 DPFSO0("Interface");
1335 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1337 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1338 DPFS1("uuid", temp_str);
1339 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1340 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1342 DPFS2("addr", afs_inet_ntoa(ifp->interface[i].addr));
1343 DPFV2("port", "u", ifp->interface[i].port);
1349 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1350 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1362 if (!he_cursor.hdr.hcps)
1365 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1366 hcps = (afs_int32 *) malloc(len);
1367 assert(hcps != NULL);
1368 memcpy(hcps, he_cursor.hcps, len);
1371 DPFAO1("prlist_val");
1372 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1373 DPFAE("d", hcps[i]);
1379 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1388 DPFSO0("callback_state_entry_header");
1389 DPFX1("magic", fe_cursor.hdr.magic);
1390 DPFV1("len", "u", fe_cursor.hdr.len);
1391 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1394 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1395 fprintf(stderr, "* magic check failed\n");
1402 DPFSO0("FEDiskEntry");
1404 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1405 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1406 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1407 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1408 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1409 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1410 DPFV2("status", "u", fe_cursor.fe.fe.status);
1412 DPFV1("index", "u", fe_cursor.fe.index);
1419 DPFSO0("CBDiskEntry");
1421 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1422 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1423 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1424 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1425 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1426 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1427 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1428 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1429 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1431 DPFV1("index", "u", cb_cursor.cb.index);
1435 #define DPFHMS printf(" ")
1436 #define DPFHS printf(" ")
1437 #define DPFHN(offset) printf("\n%u\t", offset)
1438 #define DPFHD(x) printf("%02X ", x)
1439 #define DPFHE printf("\n")
1442 hexdump_map(afs_uint32 offset, afs_uint32 len)
1445 unsigned char * p = (unsigned char *)map;
1451 if ((offset + len) > map_len) {
1452 fprintf(stderr, "offset + length exceeds memory map size (%u > %u)\n",
1453 offset+len, map_len);
1461 for (i = offset % 16; i > 0; i--) {
1465 for (i=0; i < len; i++, p++, offset++) {
1466 if (!(offset % 16)) {
1468 } else if (!(offset % 8)) {
1479 if (!hdrs.hdr_valid) {
1480 if (map_len < sizeof(struct fs_state_header)) {
1481 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1484 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1497 if (hdrs.h_hdr_valid)
1503 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1506 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1509 if ((lo >= map_len) ||
1510 ((lo + sizeof(struct host_state_header)) > map_len) ||
1511 (lo + sizeof(struct host_state_header) < lo)) {
1512 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1518 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1520 buf += sizeof(struct host_state_header);
1521 he_cursor.fh = (void *)buf;
1531 if (hdrs.cb_hdr_valid)
1537 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1540 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1543 if ((lo >= map_len) ||
1544 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1545 (lo + sizeof(struct callback_state_header) < lo)) {
1546 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1552 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1553 hdrs.cb_hdr_p = buf;
1554 hdrs.cb_hdr_valid = 1;
1556 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1559 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1562 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1563 sizeof(struct FEDiskEntry)) +
1564 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1565 if ((hi > map_len) ||
1567 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1573 fe_cursor.ffe = (void *)buf;
1579 get_cb_timeout_hdr(void)
1584 if (hdrs.timeout_hdr_valid)
1590 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1593 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1596 if ((lo >= map_len) ||
1597 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1598 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1599 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1605 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1606 hdrs.timeout_hdr_p = buf;
1607 hdrs.timeout_hdr_valid = 1;
1608 buf += sizeof(struct callback_state_timeout_header);
1609 hdrs.timeout_p = buf;
1615 get_cb_timeout(void)
1622 if (get_cb_timeout_hdr())
1625 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1626 assert(hdrs.timeout != NULL);
1627 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1632 get_cb_fehash_hdr(void)
1637 if (hdrs.fehash_hdr_valid)
1643 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1646 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1649 if ((lo >= map_len) ||
1650 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1651 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1652 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1658 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1659 hdrs.fehash_hdr_p = buf;
1660 hdrs.fehash_hdr_valid = 1;
1661 buf += sizeof(struct callback_state_fehash_header);
1662 hdrs.fehash_p = buf;
1675 if (get_cb_fehash_hdr())
1678 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1679 assert(hdrs.fehash != NULL);
1680 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1685 get_he(afs_uint32 idx)
1693 if (idx >= hdrs.h_hdr.records)
1696 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1699 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1701 if (he_cache.cursor == NULL) {
1702 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1703 assert(he_cache.cursor != NULL);
1706 if (idx && he_cache.cursor[idx-1] == NULL) {
1707 for (i = 0; i < idx; i++) {
1708 if (he_cache.cursor[i] == NULL) {
1715 he_cursor.cursor = he_cursor.fh;
1716 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1717 p = (char *)he_cursor.cursor;
1718 p += he_cursor.hdr.len;
1719 he_cursor.cursor = (void *)p;
1721 he_cursor.cursor = he_cache.cursor[idx-1];
1724 p = (char *)he_cursor.cursor;
1725 p += he_cursor.hdr.len;
1726 he_cursor.cursor = (void *)p;
1729 he_cursor.idx = idx;
1730 he_cache.cursor[idx] = he_cursor.cursor;
1743 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1744 he_cursor.hdr_valid = 1;
1753 if (!he_cursor.hdr_valid) {
1759 p = (char *) he_cursor.cursor;
1760 p += sizeof(struct host_state_entry_header);
1762 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1764 he_cursor.he_valid = 1;
1765 p += sizeof(struct hostDiskEntry);
1766 he_cursor.ifp = (void *)p;
1767 if (he_cursor.hdr.interfaces) {
1768 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1769 he_cursor.hcps = (void *)p;
1771 he_cursor.hcps = he_cursor.ifp;
1777 get_fe(afs_uint32 idx)
1782 cb_cursor.cb_valid = 0;
1787 if (idx >= hdrs.cb_hdr.nFEs)
1790 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1793 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1795 if (fe_cache.cursor == NULL) {
1796 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1797 assert(fe_cache.cursor != NULL);
1800 if (idx && fe_cache.cursor[idx-1] == NULL) {
1801 for (i = 0; i < idx; i++) {
1802 if (fe_cache.cursor[i] == NULL) {
1809 fe_cursor.cursor = fe_cursor.ffe;
1810 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1811 p = (char *)fe_cursor.cursor;
1812 p += fe_cursor.hdr.len;
1813 fe_cursor.cursor = (void *)p;
1815 fe_cursor.cursor = fe_cache.cursor[idx-1];
1818 p = (char *)fe_cursor.cursor;
1819 p += fe_cursor.hdr.len;
1820 fe_cursor.cursor = (void *)p;
1823 fe_cursor.idx = idx;
1824 fe_cache.cursor[idx] = fe_cursor.cursor;
1837 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1838 fe_cursor.hdr_valid = 1;
1847 if (!fe_cursor.hdr_valid) {
1853 p = (char *) fe_cursor.cursor;
1854 p += sizeof(struct callback_state_entry_header);
1856 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1858 fe_cursor.fe_valid = 1;
1859 p += sizeof(struct FEDiskEntry);
1860 fe_cursor.fcb = (void *)p;
1865 get_cb(afs_uint32 idx)
1870 if (get_fe(fe_cursor.idx))
1873 if (idx >= fe_cursor.hdr.nCBs)
1876 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1879 cb_cursor.cb_valid = 0;
1881 p = (char *)fe_cursor.fcb;
1882 p += idx * sizeof(struct CBDiskEntry);
1883 cb_cursor.cursor = (void *)p;
1885 cb_cursor.idx = idx;
1896 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1897 cb_cursor.cb_valid = 1;
1902 find_he_by_index(afs_uint32 idx)
1910 for (i = 0; i < hdrs.h_hdr.records; i++) {
1912 fprintf(stderr, "error getting he %d\n", i);
1915 if (he_cursor.he.index == idx)
1919 if (i < hdrs.h_hdr.records) {
1927 find_fe_by_index(afs_uint32 idx)
1935 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1937 fprintf(stderr, "error getting fe %d\n", i);
1940 if (fe_cursor.fe.index == idx)
1944 if (i < hdrs.cb_hdr.nFEs) {
1952 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1960 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1962 fprintf(stderr, "error getting fe %d\n", i);
1965 if ((fe_cursor.fe.fe.unique == unique) &&
1966 (fe_cursor.fe.fe.volid == volid) &&
1967 (fe_cursor.fe.fe.vnode == vnode))
1971 if (i < hdrs.cb_hdr.nFEs) {
1979 find_cb_by_index(afs_uint32 idx)
1987 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1989 fprintf(stderr, "error getting cb %d\n", i);
1992 if (cb_cursor.cb.index == idx)
1996 if (i < fe_cursor.hdr.nCBs) {
2003 #endif /* AFS_DEMAND_ATTACH_FS */