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>
24 #include <netinet/in.h>
32 #include <afs/afs_assert.h>
35 #include <afs/afsint.h>
36 #include <afs/rxgen_consts.h>
38 #include <afs/errors.h>
39 #include <afs/ihandle.h>
40 #include <afs/vnode.h>
41 #include <afs/volume.h>
42 #ifdef AFS_ATHENA_STDENV
46 #include <afs/ptclient.h>
47 #include <afs/prs_fs.h>
48 #include <afs/afsutil.h>
50 #include <afs/cellconfig.h>
52 #include "../util/afsutil_prototypes.h"
53 #include "../viced/viced.h"
54 #include "../viced/host.h"
55 #include "../viced/callback.h"
56 #include "serialize_state.h"
58 #include <sys/types.h>
63 /*@+fcnmacros +macrofcndecl@*/
66 extern off64_t afs_lseek(int FD, off64_t O, int F);
67 #endif /*S_SPLINT_S */
68 #define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F)
69 #define afs_stat stat64
70 #define afs_fstat fstat64
71 #define afs_open open64
72 #define afs_fopen fopen64
73 #define afs_mmap mmap64
75 extern void * mmap64(); /* ugly hack since aix build env appears to be somewhat broken */
77 #else /* !O_LARGEFILE */
79 extern off_t afs_lseek(int FD, off_t O, int F);
80 #endif /*S_SPLINT_S */
81 #define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F)
83 #define afs_fstat fstat
85 #define afs_fopen fopen
87 #endif /* !O_LARGEFILE */
88 /*@=fcnmacros =macrofcndecl@*/
91 #ifndef AFS_DEMAND_ATTACH_FS
93 main (int argc, char ** argv)
95 fprintf(stderr, "%s is only supported for demand attach fileservers\n",
96 argv[0] ? argv[0] : "state analyzer");
99 #else /* AFS_DEMAND_ATTACH_FS */
101 static void usage(char * prog);
102 static int openFile(char * path);
103 static void initState(void);
105 static void banner(void);
106 static void prompt(void);
108 static void print_help(void);
109 static void print_global_help(void);
110 static void print_h_help(void);
111 static void print_fe_help(void);
112 static void print_cb_help(void);
114 static void dump_hdr(void);
115 static void dump_h_hdr(void);
116 static void dump_cb_hdr(void);
118 static void dump_cb_timeout(void);
119 static void dump_cb_fehash(void);
121 static void dump_all_hes(void);
122 static void dump_all_fes(void);
123 static void dump_all_cbs(void);
125 static void dump_he(afs_uint32 idx);
126 static void dump_fe(afs_uint32 idx);
127 static void dump_cb(afs_uint32 idx);
128 static void dump_this_he(void);
129 static void dump_this_fe(void);
130 static void dump_this_cb(void);
131 static void dump_next_he(void);
132 static void dump_next_fe(void);
133 static void dump_next_cb(void);
134 static void dump_prev_he(void);
135 static void dump_prev_fe(void);
136 static void dump_prev_cb(void);
137 static void dump_first_he(void);
138 static void dump_first_fe(void);
139 static void dump_first_cb(void);
140 static void dump_last_he(void);
141 static void dump_last_fe(void);
142 static void dump_last_cb(void);
143 static void dump_he_hdr(void);
144 static void dump_he_entry(void);
145 static void dump_he_interfaces(void);
146 static void dump_he_hcps(void);
147 static void dump_fe_hdr(void);
148 static void dump_fe_entry(void);
149 static void dump_cb_entry(void);
151 static void hexdump_map(afs_uint32 offset, afs_uint32 len);
153 static int get_hdr(void);
154 static int get_h_hdr(void);
155 static int get_cb_hdr(void);
156 static int get_cb_timeout_hdr(void);
157 static int get_cb_timeout(void);
158 static int get_cb_fehash_hdr(void);
159 static int get_cb_fehash(void);
160 static int get_he(afs_uint32 idx);
161 static int get_he_hdr(void);
162 static int get_he_entry(void);
163 static int get_fe(afs_uint32 idx);
164 static int get_fe_hdr(void);
165 static int get_fe_entry(void);
166 static int get_cb(afs_uint32 idx);
167 static int get_cb_entry(void);
169 static int find_fe_by_index(afs_uint32 idx);
170 static int find_cb_by_index(afs_uint32 idx);
171 static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq);
174 static int dump_fd = -1;
175 static void * map = NULL;
176 static size_t map_len;
179 struct fs_state_header hdr;
180 struct host_state_header h_hdr;
181 struct callback_state_header cb_hdr;
182 struct callback_state_timeout_header timeout_hdr;
183 struct callback_state_fehash_header fehash_hdr;
184 afs_uint32 * timeout;
187 /* pointers into the memory map */
191 void * timeout_hdr_p;
199 byte timeout_hdr_valid;
200 byte fehash_hdr_valid;
208 struct host_state_entry_header hdr;
209 struct hostDiskEntry he;
223 struct callback_state_entry_header hdr;
224 struct FEDiskEntry fe;
236 struct CBDiskEntry cb;
244 fprintf(stderr, "usage: %s [<state dump file>]\n", prog);
248 main(int argc, char ** argv)
251 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
259 if (openFile(argv[1]))
262 if (openFile((char *)AFSDIR_SERVER_FSSTATE_FILEPATH))
272 openFile(char * path)
275 struct afs_stat status;
277 dump_fd = afs_open(path, O_RDWR);
279 fprintf(stderr, "dump file '%s' failed to open\n", path);
284 printf("opened dump file '%s'\n", path);
286 if (afs_fstat(dump_fd, &status) == -1) {
287 fprintf(stderr, "failed to stat file\n");
292 map_len = status.st_size;
294 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
295 if (map == MAP_FAILED) {
296 fprintf(stderr, "failed to mmap file\n");
301 printf("mapped %lu bytes at %"AFS_PTR_FMT"\n", (unsigned long)map_len, map);
306 munmap(map, map_len);
320 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
321 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
322 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
323 he_cache.cursor = fe_cache.cursor = NULL;
329 fprintf(stderr, "demand attach fs\n");
330 fprintf(stderr, "fileserver state analyzer\n");
331 fprintf(stderr, "version 0.1\n");
334 #define PROGNAME "fs state analyzer"
340 char prev_input[256];
348 } mode = PR_GLOBAL_MODE, next_mode;
351 input[0] = prev_input[0] = '\0';
357 printf(PROGNAME "> ");
360 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
363 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
366 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
369 fprintf(stderr, "prompt state broken; aborting\n");
372 fgets(input, 256, stdin);
374 if (!strcmp(input, "")) {
375 /* repeat last command */
376 if (!strcmp(prev_input, "")) {
379 strlcpy(input, prev_input, sizeof(input));
381 /* save command for repetition */
382 strlcpy(prev_input, input, sizeof(prev_input));
385 tok = strtok(input, " \t\n");
387 while (tok && !strcmp(tok, ";")) {
388 tok = strtok(NULL, "; \t\n");
395 if (!strcasecmp(tok, "exit")) {
397 } else if (!strcasecmp(tok, "quit")) {
400 next_mode = PR_FE_MODE;
404 next_mode = PR_GLOBAL_MODE;
409 } else if (!strcasecmp(tok, "h")) {
410 tok = strtok(NULL, " \t");
416 } else if (!strcasecmp(tok, "fe")) {
417 tok = strtok(NULL, " \t");
423 } else if (!strcasecmp(tok, "fs")) {
424 tok = strtok(NULL, " \t");
425 mode = PR_GLOBAL_MODE;
430 } else if (!strcasecmp(tok, "cb")) {
431 tok = strtok(NULL, " \t");
437 } else if (!strcasecmp(tok, "help")) {
452 } else if (!strcasecmp(tok, "hexdump")) {
453 tok = strtok(NULL, " \t");
455 hexdump_map(0, map_len);
458 if (sscanf(tok, "%u", &x) != 1) {
459 fprintf(stderr, "hexdump parse error 1\n");
463 tok = strtok(NULL, " \t");
465 hexdump_map(x, map_len - x);
468 if (sscanf(tok, "%u", &y) != 1) {
469 fprintf(stderr, "hexdump parse error 2\n");
473 } else if (!strcasecmp(tok, "hdr")) {
487 } else if (!strcasecmp(tok, "this")) {
499 fprintf(stderr, "command not valid for this mode\n");
501 } else if (!strcasecmp(tok, "next")) {
513 fprintf(stderr, "command not valid for this mode\n");
515 } else if (!strcasecmp(tok, "prev")) {
527 fprintf(stderr, "command not valid for this mode\n");
529 } else if (!strcasecmp(tok, "first")) {
541 fprintf(stderr, "command not valid for this mode\n");
543 } else if (!strcasecmp(tok, "last")) {
555 fprintf(stderr, "command not valid for this mode\n");
557 } else if (!strcasecmp(tok, "dump")) {
569 fprintf(stderr, "command not valid for this mode\n");
571 } else if (!strcasecmp(tok, "find")) {
572 tok = strtok(NULL, " \t");
573 if (!tok || strcasecmp(tok, "by")) {
575 fprintf(stderr, "find syntax error 1 (%s)\n",
576 (tok) ? tok : "nil");
579 tok = strtok(NULL, " \t");
581 fprintf(stderr, "find syntax error 2\n");
586 fprintf(stderr, "not implemented yet\n");
589 if (!strcasecmp(tok, "index")) {
590 tok = strtok(NULL, " \t");
591 if (!tok || sscanf(tok, "%u", &x) != 1) {
593 fprintf(stderr, "find syntax error 3\n");
596 if (find_fe_by_index(x)) {
597 fprintf(stderr, "find returned no results\n");
599 } else if (!strcasecmp(tok, "fid")) {
600 tok = strtok(NULL, "(), \t");
601 if (!tok || sscanf(tok, "%u", &x) != 1) {
603 fprintf(stderr, "find syntax error 4\n");
606 tok = strtok(NULL, "(), \t");
607 if (!tok || sscanf(tok, "%u", &y) != 1) {
609 fprintf(stderr, "find syntax error 5\n");
612 tok = strtok(NULL, "(), \t");
613 if (!tok || sscanf(tok, "%u", &z) != 1) {
615 fprintf(stderr, "find syntax error 6\n");
618 if (find_fe_by_fid(x,y,z)) {
619 fprintf(stderr, "find returned no results\n");
622 fprintf(stderr, "unsupported filter type\n");
626 if (!strcasecmp(tok, "index")) {
627 tok = strtok(NULL, " \t");
628 if (!tok || sscanf(tok, "%u", &x) != 1) {
630 fprintf(stderr, "find syntax error 3\n");
633 if (find_cb_by_index(x)) {
634 fprintf(stderr, "find returned no results\n");
637 fprintf(stderr, "unsupported filter type\n");
641 fprintf(stderr, "find not supported for this menu\n");
643 } else if (!strcspn(tok, "0123456789")) {
644 if (sscanf(tok, "%u", &x) == 1) {
656 fprintf(stderr, "command not available from this menu\n");
659 fprintf(stderr, "input parse error ('%s')\n", tok);
661 } else if (mode == PR_FE_MODE) {
662 if (!strcmp(tok, "timeout")) {
664 } else if (!strcmp(tok, "hash")) {
668 fprintf(stderr, "unknown command\n");
670 tok = strtok(NULL, " \t");
678 printf("\th <...> -- host menu commands\n");
679 printf("\tfe <...> -- FileEntry menu commands\n");
680 printf("\tcb <...> -- CallBack menu commands\n");
681 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
682 printf("\tquit -- quit this menu\n");
683 printf("\texit -- exit the debugger\n");
684 printf("\thelp -- this help message\n");
688 print_global_help(void)
690 printf("\thdr -- display the fs_state_header struct\n");
696 printf("\thdr -- display the host_state_header struct\n");
697 printf("\tfirst -- display the first host\n");
698 printf("\tprev -- display the previous host\n");
699 printf("\tthis -- display this host\n");
700 printf("\tnext -- display the next host\n");
701 printf("\tlast -- display the last host\n");
702 printf("\tdump -- display all hosts\n");
708 printf("\thdr -- display the callback_state_header struct\n");
709 printf("\tfirst -- display the first FE\n");
710 printf("\tprev -- display the previous FE\n");
711 printf("\tthis -- display this FE\n");
712 printf("\tnext -- display the next FE\n");
713 printf("\tlast -- display the last FE\n");
714 printf("\tdump -- display all FEs\n");
715 printf("\ttimeout -- display the timeout queue heads\n");
716 printf("\thash -- display the file entry hash buckets\n");
717 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
718 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
724 printf("\thdr -- display the callback_state_entry_header struct\n");
725 printf("\tfirst -- display the first CB\n");
726 printf("\tprev -- display the previous CB\n");
727 printf("\tthis -- display this CB\n");
728 printf("\tnext -- display the next CB\n");
729 printf("\tlast -- display the last CB\n");
730 printf("\tdump -- display all CBs\n");
734 #define DPFTB1 "\t\t"
735 #define DPFTB2 "\t\t\t"
737 #define DPFOFF(addr) \
739 char * _p = (char *)addr; \
740 char * _m = (char *)map; \
741 printf("loading structure from address %"AFS_PTR_FMT" (offset %ld)\n", \
742 addr, (long)(_p-_m)); \
746 #define DPFSO(T, name) printf(T "%s = {\n", name)
747 #define DPFSO0(name) DPFSO(DPFTB0, name)
748 #define DPFSO1(name) DPFSO(DPFTB1, name)
749 #define DPFSC(T) printf(T "}\n")
750 #define DPFSC0 DPFSC(DPFTB0)
751 #define DPFSC1 DPFSC(DPFTB1)
754 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
755 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
756 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
757 #define DPFAC0 printf(" }\n")
758 #define DPFAC1 DPFAC0
759 #define DPFA1 printf(DPFTB1 " ")
760 #define DPFA2 printf(DPFTB2 " ")
761 #define DPFAN printf("\n")
762 #define DPFALE(type, var) printf("%" type, var)
763 #define DPFAE(type, var) printf("%" type ",\t", var)
766 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
767 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
768 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
771 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
772 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
773 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
776 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
777 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
778 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
781 #define DPFT(T, name, var) \
784 printf(T "%s = \"%.24s\"\n", name, ctime(&t)); \
786 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
787 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
799 DPFSO0("fs_state_header");
801 DPFX2("magic", hdrs.hdr.stamp.magic);
802 DPFV2("version", "u", hdrs.hdr.stamp.version);
804 DPFT1("timestamp", hdrs.hdr.timestamp);
805 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
807 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
808 DPFS1("server_uuid", uuid_str);
809 DPFV1("valid", "d", hdrs.hdr.valid);
810 DPFV1("endianness", "d", hdrs.hdr.endianness);
811 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
813 SplitInt64(hdrs.hdr.h_offset, hi, lo);
815 DPFV2("hi", "u", hi);
816 DPFV2("lo", "u", lo);
819 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
821 DPFV2("hi", "u", hi);
822 DPFV2("lo", "u", lo);
825 DPFS1("server_version_string", hdrs.hdr.server_version_string);
828 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
829 fprintf(stderr, "* magic check failed\n");
831 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
832 fprintf(stderr, "* version check failed\n");
842 DPFOFF(hdrs.h_hdr_p);
843 DPFSO0("host_state_header");
845 DPFX2("magic", hdrs.h_hdr.stamp.magic);
846 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
848 DPFV1("records", "u", hdrs.h_hdr.records);
849 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
852 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
853 fprintf(stderr, "* magic check failed\n");
855 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
856 fprintf(stderr, "* version check failed\n");
868 DPFOFF(hdrs.cb_hdr_p);
869 DPFSO0("callback_state_header");
871 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
872 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
874 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
875 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
876 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
877 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
878 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
880 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
881 DPFSO1("timeout_offset");
882 DPFV2("hi", "u", hi);
883 DPFV2("lo", "u", lo);
886 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
887 DPFSO1("fehash_offset");
888 DPFV2("hi", "u", hi);
889 DPFV2("lo", "u", lo);
892 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
894 DPFV2("hi", "u", hi);
895 DPFV2("lo", "u", lo);
900 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
901 fprintf(stderr, "* magic check failed\n");
903 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
904 fprintf(stderr, "* version check failed\n");
909 dump_cb_timeout(void)
916 if (get_cb_timeout_hdr())
919 if (get_cb_timeout())
922 DPFOFF(hdrs.timeout_hdr_p);
923 DPFSO0("callback_state_timeout_header");
924 DPFX1("magic", hdrs.timeout_hdr.magic);
925 DPFV1("len", "u", hdrs.timeout_hdr.len);
926 DPFV1("records", "u", hdrs.timeout_hdr.records);
929 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
930 fprintf(stderr, "* magic check failed\n");
933 DPFOFF(hdrs.timeout_p);
935 for (i = 0; i < 127; i++) {
936 DPFAE("u", hdrs.timeout[i]);
942 DPFALE("u", hdrs.timeout[127]);
954 if (get_cb_fehash_hdr())
960 DPFOFF(hdrs.fehash_hdr_p);
961 DPFSO0("callback_state_fehash_header");
962 DPFX1("magic", hdrs.fehash_hdr.magic);
963 DPFV1("len", "u", hdrs.fehash_hdr.len);
964 DPFV1("records", "u", hdrs.fehash_hdr.records);
967 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
968 fprintf(stderr, "* magic check failed\n");
971 DPFOFF(hdrs.fehash_p);
973 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
974 DPFAE("u", hdrs.fehash[i]);
980 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
990 fprintf(stderr, "error getting host_state_header\n");
994 for (i = 0; i < hdrs.h_hdr.records; i++) {
1005 fprintf(stderr, "error getting callback_state_header\n");
1009 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1020 fprintf(stderr, "error getting callback_state_entry_header\n");
1024 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1030 dump_he(afs_uint32 idx)
1033 fprintf(stderr, "error getting he %d\n", idx);
1037 DPFOFF(he_cursor.cursor);
1040 dump_he_interfaces();
1045 dump_fe(afs_uint32 idx)
1048 fprintf(stderr, "error getting fe %d\n", idx);
1052 DPFOFF(fe_cursor.cursor);
1058 dump_cb(afs_uint32 idx)
1061 fprintf(stderr, "error getting cb %d\n", idx);
1065 DPFOFF(cb_cursor.cursor);
1072 dump_he(he_cursor.idx);
1078 dump_fe(fe_cursor.idx);
1084 dump_cb(cb_cursor.idx);
1091 fprintf(stderr, "error getting host_state_header\n");
1095 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1096 fprintf(stderr, "no more HEs\n");
1100 dump_he(he_cursor.idx+1);
1107 fprintf(stderr, "error getting callback_state_header\n");
1111 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1112 fprintf(stderr, "no more FEs\n");
1116 dump_fe(fe_cursor.idx+1);
1123 fprintf(stderr, "error getting callback_state_entry_header\n");
1127 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1128 fprintf(stderr, "no more CBs\n");
1132 dump_cb(cb_cursor.idx+1);
1138 if (!he_cursor.idx) {
1139 fprintf(stderr, "no more HEs\n");
1143 dump_he(he_cursor.idx-1);
1149 if (!fe_cursor.idx) {
1150 fprintf(stderr, "no more FEs\n");
1154 dump_fe(fe_cursor.idx-1);
1160 if (!cb_cursor.idx) {
1161 fprintf(stderr, "no more CBs\n");
1165 dump_cb(cb_cursor.idx-1);
1172 fprintf(stderr, "error getting callback_state_header\n");
1176 if (!hdrs.cb_hdr.nFEs) {
1177 fprintf(stderr, "no FEs present\n");
1188 fprintf(stderr, "error getting host_state_header\n");
1192 if (!hdrs.h_hdr.records) {
1193 fprintf(stderr, "no HEs present\n");
1204 fprintf(stderr, "error getting callback_state_entry_header\n");
1208 if (!fe_cursor.hdr.nCBs) {
1209 fprintf(stderr, "no CBs present\n");
1220 fprintf(stderr, "error getting host_state_header\n");
1224 if (!hdrs.h_hdr.records) {
1225 fprintf(stderr, "no HEs present\n");
1229 dump_he(hdrs.h_hdr.records-1);
1236 fprintf(stderr, "error getting callback_state_header\n");
1240 if (!hdrs.cb_hdr.nFEs) {
1241 fprintf(stderr, "no FEs present\n");
1245 dump_fe(hdrs.cb_hdr.nFEs-1);
1252 fprintf(stderr, "error getting callback_state_entry_header\n");
1256 if (!fe_cursor.hdr.nCBs) {
1257 fprintf(stderr, "no CBs present\n");
1261 dump_cb(fe_cursor.hdr.nCBs-1);
1267 DPFSO0("host_state_entry_header");
1268 DPFX1("magic", he_cursor.hdr.magic);
1269 DPFV1("len", "u", he_cursor.hdr.len);
1270 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1271 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1274 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1275 fprintf(stderr, "* magic check failed\n");
1283 DPFSO0("hostDiskEntry");
1284 DPFS1("host", afs_inet_ntoa_r(he_cursor.he.host, hoststr));
1285 DPFV1("port", "u", he_cursor.he.port);
1286 DPFX1("hostFlags", he_cursor.he.hostFlags);
1287 DPFV1("Console", "u", he_cursor.he.Console);
1288 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1289 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1290 if (hdrs.hdr.stats_detailed) {
1291 #ifdef FS_STATS_DETAILED
1292 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1294 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1297 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1298 DPFT1("LastCall", he_cursor.he.LastCall);
1299 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1300 DPFT1("cpsCall", he_cursor.he.cpsCall);
1301 DPFV1("cblist", "u", he_cursor.he.cblist);
1302 DPFV1("index", "u", he_cursor.he.index);
1307 dump_he_interfaces(void)
1310 struct Interface * ifp;
1314 if (!he_cursor.hdr.interfaces)
1317 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1318 ifp = (struct Interface *) malloc(len);
1319 assert(ifp != NULL);
1321 memcpy(ifp, he_cursor.ifp, len);
1323 DPFSO0("Interface");
1324 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1326 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1327 DPFS1("uuid", temp_str);
1328 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1329 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1331 DPFS2("addr", afs_inet_ntoa_r(ifp->interface[i].addr, hoststr));
1332 DPFV2("port", "u", ifp->interface[i].port);
1338 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1339 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1350 if (!he_cursor.hdr.hcps)
1353 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1354 hcps = (afs_int32 *) malloc(len);
1355 assert(hcps != NULL);
1356 memcpy(hcps, he_cursor.hcps, len);
1359 DPFAO1("prlist_val");
1360 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1361 DPFAE("d", hcps[i]);
1367 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1376 DPFSO0("callback_state_entry_header");
1377 DPFX1("magic", fe_cursor.hdr.magic);
1378 DPFV1("len", "u", fe_cursor.hdr.len);
1379 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1382 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1383 fprintf(stderr, "* magic check failed\n");
1390 DPFSO0("FEDiskEntry");
1392 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1393 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1394 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1395 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1396 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1397 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1398 DPFV2("status", "u", fe_cursor.fe.fe.status);
1400 DPFV1("index", "u", fe_cursor.fe.index);
1407 DPFSO0("CBDiskEntry");
1409 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1410 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1411 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1412 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1413 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1414 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1415 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1416 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1417 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1419 DPFV1("index", "u", cb_cursor.cb.index);
1423 #define DPFHMS printf(" ")
1424 #define DPFHS printf(" ")
1425 #define DPFHN(offset) printf("\n%u\t", offset)
1426 #define DPFHD(x) printf("%02X ", x)
1427 #define DPFHE printf("\n")
1430 hexdump_map(afs_uint32 offset, afs_uint32 len)
1433 unsigned char * p = (unsigned char *)map;
1438 if ((offset + len) > map_len) {
1439 fprintf(stderr, "offset + length exceeds memory map size (%u > %lu)\n",
1440 offset+len, (unsigned long)map_len);
1448 for (i = offset % 16; i > 0; i--) {
1452 for (i=0; i < len; i++, p++, offset++) {
1453 if (!(offset % 16)) {
1455 } else if (!(offset % 8)) {
1466 if (!hdrs.hdr_valid) {
1467 if (map_len < sizeof(struct fs_state_header)) {
1468 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1471 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1484 if (hdrs.h_hdr_valid)
1490 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1493 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1496 if ((lo >= map_len) ||
1497 ((lo + sizeof(struct host_state_header)) > map_len) ||
1498 (lo + sizeof(struct host_state_header) < lo)) {
1499 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1505 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1507 buf += sizeof(struct host_state_header);
1508 he_cursor.fh = (void *)buf;
1518 if (hdrs.cb_hdr_valid)
1524 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1527 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1530 if ((lo >= map_len) ||
1531 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1532 (lo + sizeof(struct callback_state_header) < lo)) {
1533 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1539 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1540 hdrs.cb_hdr_p = buf;
1541 hdrs.cb_hdr_valid = 1;
1543 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1546 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1549 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1550 sizeof(struct FEDiskEntry)) +
1551 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1552 if ((hi > map_len) ||
1554 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1560 fe_cursor.ffe = (void *)buf;
1566 get_cb_timeout_hdr(void)
1571 if (hdrs.timeout_hdr_valid)
1577 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1580 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1583 if ((lo >= map_len) ||
1584 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1585 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1586 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1592 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1593 hdrs.timeout_hdr_p = buf;
1594 hdrs.timeout_hdr_valid = 1;
1595 buf += sizeof(struct callback_state_timeout_header);
1596 hdrs.timeout_p = buf;
1602 get_cb_timeout(void)
1607 if (get_cb_timeout_hdr())
1610 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1611 assert(hdrs.timeout != NULL);
1612 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1617 get_cb_fehash_hdr(void)
1622 if (hdrs.fehash_hdr_valid)
1628 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1631 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1634 if ((lo >= map_len) ||
1635 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1636 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1637 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1643 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1644 hdrs.fehash_hdr_p = buf;
1645 hdrs.fehash_hdr_valid = 1;
1646 buf += sizeof(struct callback_state_fehash_header);
1647 hdrs.fehash_p = buf;
1658 if (get_cb_fehash_hdr())
1661 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1662 assert(hdrs.fehash != NULL);
1663 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1668 get_he(afs_uint32 idx)
1676 if (idx >= hdrs.h_hdr.records)
1679 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1682 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1684 if (he_cache.cursor == NULL) {
1685 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1686 assert(he_cache.cursor != NULL);
1689 if (idx && he_cache.cursor[idx-1] == NULL) {
1690 for (i = 0; i < idx; i++) {
1691 if (he_cache.cursor[i] == NULL) {
1698 he_cursor.cursor = he_cursor.fh;
1699 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1700 p = (char *)he_cursor.cursor;
1701 p += he_cursor.hdr.len;
1702 he_cursor.cursor = (void *)p;
1704 he_cursor.cursor = he_cache.cursor[idx-1];
1707 p = (char *)he_cursor.cursor;
1708 p += he_cursor.hdr.len;
1709 he_cursor.cursor = (void *)p;
1712 he_cursor.idx = idx;
1713 he_cache.cursor[idx] = he_cursor.cursor;
1726 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1727 he_cursor.hdr_valid = 1;
1736 if (!he_cursor.hdr_valid) {
1742 p = (char *) he_cursor.cursor;
1743 p += sizeof(struct host_state_entry_header);
1745 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1747 he_cursor.he_valid = 1;
1748 p += sizeof(struct hostDiskEntry);
1749 he_cursor.ifp = (void *)p;
1750 if (he_cursor.hdr.interfaces) {
1751 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1752 he_cursor.hcps = (void *)p;
1754 he_cursor.hcps = he_cursor.ifp;
1760 get_fe(afs_uint32 idx)
1765 cb_cursor.cb_valid = 0;
1770 if (idx >= hdrs.cb_hdr.nFEs)
1773 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1776 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1778 if (fe_cache.cursor == NULL) {
1779 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1780 assert(fe_cache.cursor != NULL);
1783 if (idx && fe_cache.cursor[idx-1] == NULL) {
1784 for (i = 0; i < idx; i++) {
1785 if (fe_cache.cursor[i] == NULL) {
1792 fe_cursor.cursor = fe_cursor.ffe;
1793 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1794 p = (char *)fe_cursor.cursor;
1795 p += fe_cursor.hdr.len;
1796 fe_cursor.cursor = (void *)p;
1798 fe_cursor.cursor = fe_cache.cursor[idx-1];
1801 p = (char *)fe_cursor.cursor;
1802 p += fe_cursor.hdr.len;
1803 fe_cursor.cursor = (void *)p;
1806 fe_cursor.idx = idx;
1807 fe_cache.cursor[idx] = fe_cursor.cursor;
1820 if (!fe_cursor.cursor) {
1821 if(get_fe(fe_cursor.idx)) {
1826 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1827 fe_cursor.hdr_valid = 1;
1836 if (!fe_cursor.hdr_valid) {
1842 p = (char *) fe_cursor.cursor;
1843 p += sizeof(struct callback_state_entry_header);
1845 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1847 fe_cursor.fe_valid = 1;
1848 p += sizeof(struct FEDiskEntry);
1849 fe_cursor.fcb = (void *)p;
1854 get_cb(afs_uint32 idx)
1858 if (get_fe(fe_cursor.idx))
1861 if (idx >= fe_cursor.hdr.nCBs)
1864 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1867 cb_cursor.cb_valid = 0;
1869 p = (char *)fe_cursor.fcb;
1870 p += idx * sizeof(struct CBDiskEntry);
1871 cb_cursor.cursor = (void *)p;
1873 cb_cursor.idx = idx;
1884 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1885 cb_cursor.cb_valid = 1;
1891 find_he_by_index(afs_uint32 idx)
1899 for (i = 0; i < hdrs.h_hdr.records; i++) {
1901 fprintf(stderr, "error getting he %d\n", i);
1904 if (he_cursor.he.index == idx)
1908 if (i < hdrs.h_hdr.records) {
1917 find_fe_by_index(afs_uint32 idx)
1925 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1927 fprintf(stderr, "error getting fe %d\n", i);
1930 if (fe_cursor.fe.index == idx)
1934 if (i < hdrs.cb_hdr.nFEs) {
1942 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1950 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1952 fprintf(stderr, "error getting fe %d\n", i);
1955 if ((fe_cursor.fe.fe.unique == unique) &&
1956 (fe_cursor.fe.fe.volid == volid) &&
1957 (fe_cursor.fe.fe.vnode == vnode))
1961 if (i < hdrs.cb_hdr.nFEs) {
1969 find_cb_by_index(afs_uint32 idx)
1977 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1979 fprintf(stderr, "error getting cb %d\n", i);
1982 if (cb_cursor.cb.index == idx)
1986 if (i < fe_cursor.hdr.nCBs) {
1993 #endif /* AFS_DEMAND_ATTACH_FS */