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>
33 #include <afs/assert.h>
36 #include <afs/afsint.h>
37 #include <afs/rxgen_consts.h>
39 #include <afs/errors.h>
40 #include <afs/ihandle.h>
41 #include <afs/vnode.h>
42 #include <afs/volume.h>
43 #ifdef AFS_ATHENA_STDENV
47 #include <afs/ptclient.h>
48 #include <afs/prs_fs.h>
49 #include <afs/afsutil.h>
51 #include <afs/cellconfig.h>
53 #include "../util/afsutil_prototypes.h"
54 #include "../viced/viced.h"
55 #include "../viced/host.h"
56 #include "../viced/callback.h"
57 #include "serialize_state.h"
59 #include <sys/types.h>
64 /*@+fcnmacros +macrofcndecl@*/
67 extern off64_t afs_lseek(int FD, off64_t O, int F);
68 #endif /*S_SPLINT_S */
69 #define afs_lseek(FD, O, F) lseek64(FD, (off64_t)(O), F)
70 #define afs_stat stat64
71 #define afs_fstat fstat64
72 #define afs_open open64
73 #define afs_fopen fopen64
74 #define afs_mmap mmap64
76 extern void * mmap64(); /* ugly hack since aix build env appears to be somewhat broken */
78 #else /* !O_LARGEFILE */
80 extern off_t afs_lseek(int FD, off_t O, int F);
81 #endif /*S_SPLINT_S */
82 #define afs_lseek(FD, O, F) lseek(FD, (off_t)(O), F)
84 #define afs_fstat fstat
86 #define afs_fopen fopen
88 #endif /* !O_LARGEFILE */
89 /*@=fcnmacros =macrofcndecl@*/
92 #ifndef AFS_DEMAND_ATTACH_FS
94 main (int argc, char ** argv)
96 fprintf(stderr, "%s is only supported for demand attach fileservers\n",
97 argv[0] ? argv[0] : "state analyzer");
100 #else /* AFS_DEMAND_ATTACH_FS */
102 static void usage(char * prog);
103 static int openFile(char * path);
104 static void initState(void);
106 static void banner(void);
107 static void prompt(void);
109 static void print_help(void);
110 static void print_global_help(void);
111 static void print_h_help(void);
112 static void print_fe_help(void);
113 static void print_cb_help(void);
115 static void dump_hdr(void);
116 static void dump_h_hdr(void);
117 static void dump_cb_hdr(void);
119 static void dump_cb_timeout(void);
120 static void dump_cb_fehash(void);
122 static void dump_all_hes(void);
123 static void dump_all_fes(void);
124 static void dump_all_cbs(void);
126 static void dump_he(afs_uint32 idx);
127 static void dump_fe(afs_uint32 idx);
128 static void dump_cb(afs_uint32 idx);
129 static void dump_this_he(void);
130 static void dump_this_fe(void);
131 static void dump_this_cb(void);
132 static void dump_next_he(void);
133 static void dump_next_fe(void);
134 static void dump_next_cb(void);
135 static void dump_prev_he(void);
136 static void dump_prev_fe(void);
137 static void dump_prev_cb(void);
138 static void dump_first_he(void);
139 static void dump_first_fe(void);
140 static void dump_first_cb(void);
141 static void dump_last_he(void);
142 static void dump_last_fe(void);
143 static void dump_last_cb(void);
144 static void dump_he_hdr(void);
145 static void dump_he_entry(void);
146 static void dump_he_interfaces(void);
147 static void dump_he_hcps(void);
148 static void dump_fe_hdr(void);
149 static void dump_fe_entry(void);
150 static void dump_cb_entry(void);
152 static void hexdump_map(afs_uint32 offset, afs_uint32 len);
154 static int get_hdr(void);
155 static int get_h_hdr(void);
156 static int get_cb_hdr(void);
157 static int get_cb_timeout_hdr(void);
158 static int get_cb_timeout(void);
159 static int get_cb_fehash_hdr(void);
160 static int get_cb_fehash(void);
161 static int get_he(afs_uint32 idx);
162 static int get_he_hdr(void);
163 static int get_he_entry(void);
164 static int get_fe(afs_uint32 idx);
165 static int get_fe_hdr(void);
166 static int get_fe_entry(void);
167 static int get_cb(afs_uint32 idx);
168 static int get_cb_entry(void);
170 static int find_fe_by_index(afs_uint32 idx);
171 static int find_cb_by_index(afs_uint32 idx);
172 static int find_fe_by_fid(afs_uint32 vol, afs_uint32 vn, afs_uint32 uniq);
175 static int dump_fd = -1;
176 static void * map = NULL;
177 static size_t map_len;
180 struct fs_state_header hdr;
181 struct host_state_header h_hdr;
182 struct callback_state_header cb_hdr;
183 struct callback_state_timeout_header timeout_hdr;
184 struct callback_state_fehash_header fehash_hdr;
185 afs_uint32 * timeout;
188 /* pointers into the memory map */
192 void * timeout_hdr_p;
200 byte timeout_hdr_valid;
201 byte fehash_hdr_valid;
209 struct host_state_entry_header hdr;
210 struct hostDiskEntry he;
224 struct callback_state_entry_header hdr;
225 struct FEDiskEntry fe;
237 struct CBDiskEntry cb;
249 fprintf(stderr, "usage: %s [<state dump file>]\n", prog);
253 main(int argc, char ** argv)
257 if (argc > 2 || (argc == 2 && !strcmp(argv[1], "-h"))) {
265 if (openFile(argv[1]))
268 if (openFile(AFSDIR_SERVER_FSSTATE_FILEPATH))
278 openFile(char * path)
281 struct afs_stat status;
283 dump_fd = afs_open(path, O_RDWR);
285 fprintf(stderr, "dump file '%s' failed to open\n", path);
290 printf("opened dump file '%s'\n", path);
292 if (afs_fstat(dump_fd, &status) == -1) {
293 fprintf(stderr, "failed to stat file\n");
298 map_len = status.st_size;
300 map = afs_mmap(NULL, map_len, PROT_READ, MAP_SHARED, dump_fd, 0);
301 if (map == MAP_FAILED) {
302 fprintf(stderr, "failed to mmap file\n");
307 printf("mapped %d bytes at 0x%x\n", map_len, map);
312 munmap(map, map_len);
326 hdrs.hdr_valid = hdrs.h_hdr_valid = hdrs.cb_hdr_valid = 0;
327 he_cursor.cursor = fe_cursor.cursor = cb_cursor.cursor = NULL;
328 he_cursor.fh = fe_cursor.ffe = fe_cursor.fcb = NULL;
329 he_cache.cursor = fe_cache.cursor = NULL;
335 fprintf(stderr, "demand attach fs\n");
336 fprintf(stderr, "fileserver state analyzer\n");
337 fprintf(stderr, "version 0.1\n");
340 #define PROGNAME "fs state analyzer"
346 char prev_input[256];
354 } mode = PR_GLOBAL_MODE, next_mode;
357 input[0] = prev_input[0] = '\0';
363 printf(PROGNAME "> ");
366 printf(PROGNAME ": h(%d)> ", he_cursor.idx);
369 printf(PROGNAME ": fe(%d)> ", fe_cursor.idx);
372 printf(PROGNAME ": fe(%d):cb(%d)> ", fe_cursor.idx, cb_cursor.idx);
375 fprintf(stderr, "prompt state broken; aborting\n");
380 if (!strcmp(input, "")) {
381 /* repeat last command */
382 if (!strcmp(prev_input, "")) {
385 strlcpy(input, prev_input, sizeof(input));
387 /* save command for repetition */
388 strlcpy(prev_input, input, sizeof(prev_input));
391 tok = strtok(input, " \t");
393 while (tok && !strcmp(tok, ";")) {
394 tok = strtok(NULL, "; \t");
401 if (!strcasecmp(tok, "exit")) {
403 } else if (!strcasecmp(tok, "quit")) {
406 next_mode = PR_FE_MODE;
410 next_mode = PR_GLOBAL_MODE;
415 } else if (!strcasecmp(tok, "h")) {
416 tok = strtok(NULL, " \t");
422 } else if (!strcasecmp(tok, "fe")) {
423 tok = strtok(NULL, " \t");
429 } else if (!strcasecmp(tok, "fs")) {
430 tok = strtok(NULL, " \t");
431 mode = PR_GLOBAL_MODE;
436 } else if (!strcasecmp(tok, "cb")) {
437 tok = strtok(NULL, " \t");
443 } else if (!strcasecmp(tok, "help")) {
458 } else if (!strcasecmp(tok, "hexdump")) {
459 tok = strtok(NULL, " \t");
461 hexdump_map(0, map_len);
464 if (sscanf(tok, "%u", &x) != 1) {
465 fprintf(stderr, "hexdump parse error 1\n");
469 tok = strtok(NULL, " \t");
471 hexdump_map(x, map_len - x);
474 if (sscanf(tok, "%u", &y) != 1) {
475 fprintf(stderr, "hexdump parse error 2\n");
479 } else if (!strcasecmp(tok, "hdr")) {
493 } else if (!strcasecmp(tok, "this")) {
505 fprintf(stderr, "command not valid for this mode\n");
507 } else if (!strcasecmp(tok, "next")) {
519 fprintf(stderr, "command not valid for this mode\n");
521 } else if (!strcasecmp(tok, "prev")) {
533 fprintf(stderr, "command not valid for this mode\n");
535 } else if (!strcasecmp(tok, "first")) {
547 fprintf(stderr, "command not valid for this mode\n");
549 } else if (!strcasecmp(tok, "last")) {
561 fprintf(stderr, "command not valid for this mode\n");
563 } else if (!strcasecmp(tok, "dump")) {
575 fprintf(stderr, "command not valid for this mode\n");
577 } else if (!strcasecmp(tok, "find")) {
578 tok = strtok(NULL, " \t");
579 if (!tok || strcasecmp(tok, "by")) {
581 fprintf(stderr, "find syntax error 1 (%s)\n",
582 (tok) ? tok : "nil");
585 tok = strtok(NULL, " \t");
587 fprintf(stderr, "find syntax error 2\n");
592 fprintf(stderr, "not implemented yet\n");
595 if (!strcasecmp(tok, "index")) {
596 tok = strtok(NULL, " \t");
597 if (!tok || sscanf(tok, "%u", &x) != 1) {
599 fprintf(stderr, "find syntax error 3\n");
602 if (find_fe_by_index(x)) {
603 fprintf(stderr, "find returned no results\n");
605 } else if (!strcasecmp(tok, "fid")) {
606 tok = strtok(NULL, "(), \t");
607 if (!tok || sscanf(tok, "%u", &x) != 1) {
609 fprintf(stderr, "find syntax error 4\n");
612 tok = strtok(NULL, "(), \t");
613 if (!tok || sscanf(tok, "%u", &y) != 1) {
615 fprintf(stderr, "find syntax error 5\n");
618 tok = strtok(NULL, "(), \t");
619 if (!tok || sscanf(tok, "%u", &z) != 1) {
621 fprintf(stderr, "find syntax error 6\n");
624 if (find_fe_by_fid(x,y,z)) {
625 fprintf(stderr, "find returned no results\n");
628 fprintf(stderr, "unsupported filter type\n");
632 if (!strcasecmp(tok, "index")) {
633 tok = strtok(NULL, " \t");
634 if (!tok || sscanf(tok, "%u", &x) != 1) {
636 fprintf(stderr, "find syntax error 3\n");
639 if (find_cb_by_index(x)) {
640 fprintf(stderr, "find returned no results\n");
643 fprintf(stderr, "unsupported filter type\n");
647 fprintf(stderr, "find not supported for this menu\n");
649 } else if (!strcspn(tok, "0123456789")) {
650 if (sscanf(tok, "%u", &x) == 1) {
662 fprintf(stderr, "command not available from this menu\n");
665 fprintf(stderr, "input parse error ('%s')\n", tok);
667 } else if (mode == PR_FE_MODE) {
668 if (!strcmp(tok, "timeout")) {
670 } else if (!strcmp(tok, "hash")) {
674 fprintf(stderr, "unknown command\n");
676 tok = strtok(NULL, " \t");
684 printf("\th <...> -- host menu commands\n");
685 printf("\tfe <...> -- FileEntry menu commands\n");
686 printf("\tcb <...> -- CallBack menu commands\n");
687 printf("\thexdump [<offset> [<len>]]\n\t\t -- hex dump the raw data\n");
688 printf("\tquit -- quit this menu\n");
689 printf("\texit -- exit the debugger\n");
690 printf("\thelp -- this help message\n");
694 print_global_help(void)
696 printf("\thdr -- display the fs_state_header struct\n");
702 printf("\thdr -- display the host_state_header struct\n");
703 printf("\tfirst -- display the first host\n");
704 printf("\tprev -- display the previous host\n");
705 printf("\tthis -- display this host\n");
706 printf("\tnext -- display the next host\n");
707 printf("\tlast -- display the last host\n");
708 printf("\tdump -- display all hosts\n");
714 printf("\thdr -- display the callback_state_header struct\n");
715 printf("\tfirst -- display the first FE\n");
716 printf("\tprev -- display the previous FE\n");
717 printf("\tthis -- display this FE\n");
718 printf("\tnext -- display the next FE\n");
719 printf("\tlast -- display the last FE\n");
720 printf("\tdump -- display all FEs\n");
721 printf("\ttimeout -- display the timeout queue heads\n");
722 printf("\thash -- display the file entry hash buckets\n");
723 printf("\tfind by index <id>\n\t\t -- find an fe by its array index\n");
724 printf("\tfind by fid <(vol,vnode,unique)>\n\t\t -- find an fe by its AFSFid\n");
730 printf("\thdr -- display the callback_state_entry_header struct\n");
731 printf("\tfirst -- display the first CB\n");
732 printf("\tprev -- display the previous CB\n");
733 printf("\tthis -- display this CB\n");
734 printf("\tnext -- display the next CB\n");
735 printf("\tlast -- display the last CB\n");
736 printf("\tdump -- display all CBs\n");
740 #define DPFTB1 "\t\t"
741 #define DPFTB2 "\t\t\t"
743 #define DPFOFF(addr) \
745 char * _p = (char *)addr; \
746 char * _m = (char *)map; \
747 printf("loading structure from address 0x%x (offset %u)\n", \
752 #define DPFSO(T, name) printf(T "%s = {\n", name)
753 #define DPFSO0(name) DPFSO(DPFTB0, name)
754 #define DPFSO1(name) DPFSO(DPFTB1, name)
755 #define DPFSC(T) printf(T "}\n")
756 #define DPFSC0 DPFSC(DPFTB0)
757 #define DPFSC1 DPFSC(DPFTB1)
760 #define DPFAO(T1, T2, name) printf(T1 "%s =\n" T2 "{ ", name)
761 #define DPFAO0(name) DPFAO(DPFTB0, DPFTB1, name)
762 #define DPFAO1(name) DPFAO(DPFTB1, DPFTB2, name)
763 #define DPFAC0 printf(" }\n")
764 #define DPFAC1 DPFAC0
765 #define DPFA1 printf(DPFTB1 " ")
766 #define DPFA2 printf(DPFTB2 " ")
767 #define DPFAN printf("\n")
768 #define DPFALE(type, var) printf("%" type, var)
769 #define DPFAE(type, var) printf("%" type ",\t", var)
772 #define DPFV(T, name, type, var) printf(T "%s = %" type "\n", name, var)
773 #define DPFV1(name, type, var) DPFV(DPFTB1, name, type, var)
774 #define DPFV2(name, type, var) DPFV(DPFTB2, name, type, var)
777 #define DPFX(T, name, var) printf(T "%s = 0x%x\n", name, var)
778 #define DPFX1(name, var) DPFX(DPFTB1, name, var)
779 #define DPFX2(name, var) DPFX(DPFTB2, name, var)
782 #define DPFS(T, name, var) printf(T "%s = \"%s\"\n", name, var)
783 #define DPFS1(name, var) DPFS(DPFTB1, name, var)
784 #define DPFS2(name, var) DPFS(DPFTB2, name, var)
787 #define DPFT(T, name, var) \
790 printf(T "%s = \"%s\"\n", name, strtok_r(ctime(&(var)), "\r\n", &last)); \
792 #define DPFT1(name, var) DPFT(DPFTB1, name, var)
793 #define DPFT2(name, var) DPFT(DPFTB2, name, var)
805 DPFSO0("fs_state_header");
807 DPFX2("magic", hdrs.hdr.stamp.magic);
808 DPFV2("version", "u", hdrs.hdr.stamp.version);
810 DPFT1("timestamp", hdrs.hdr.timestamp);
811 DPFV1("sys_name", "u", hdrs.hdr.sys_name);
813 afsUUID_to_string(&hdrs.hdr.server_uuid, uuid_str, sizeof(uuid_str));
814 DPFS1("server_uuid", uuid_str);
815 DPFV1("valid", "d", hdrs.hdr.valid);
816 DPFV1("endianness", "d", hdrs.hdr.endianness);
817 DPFV1("stats_detailed", "d", hdrs.hdr.stats_detailed);
819 SplitInt64(hdrs.hdr.h_offset, hi, lo);
821 DPFV2("hi", "u", hi);
822 DPFV2("lo", "u", lo);
825 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
827 DPFV2("hi", "u", hi);
828 DPFV2("lo", "u", lo);
831 DPFS1("server_version_string", hdrs.hdr.server_version_string);
834 if (hdrs.hdr.stamp.magic != FS_STATE_MAGIC) {
835 fprintf(stderr, "* magic check failed\n");
837 if (hdrs.hdr.stamp.version != FS_STATE_VERSION) {
838 fprintf(stderr, "* version check failed\n");
848 DPFOFF(hdrs.h_hdr_p);
849 DPFSO0("host_state_header");
851 DPFX2("magic", hdrs.h_hdr.stamp.magic);
852 DPFV2("version", "u", hdrs.h_hdr.stamp.version);
854 DPFV1("records", "u", hdrs.h_hdr.records);
855 DPFV1("index_max", "u", hdrs.h_hdr.index_max);
858 if (hdrs.h_hdr.stamp.magic != HOST_STATE_MAGIC) {
859 fprintf(stderr, "* magic check failed\n");
861 if (hdrs.h_hdr.stamp.version != HOST_STATE_VERSION) {
862 fprintf(stderr, "* version check failed\n");
874 DPFOFF(hdrs.cb_hdr_p);
875 DPFSO0("callback_state_header");
877 DPFX2("magic", hdrs.cb_hdr.stamp.magic);
878 DPFV2("version", "u", hdrs.cb_hdr.stamp.version);
880 DPFV1("nFEs", "u", hdrs.cb_hdr.nFEs);
881 DPFV1("nCBs", "u", hdrs.cb_hdr.nCBs);
882 DPFV1("fe_max", "u", hdrs.cb_hdr.fe_max);
883 DPFV1("cb_max", "u", hdrs.cb_hdr.cb_max);
884 DPFV1("tfirst", "d", hdrs.cb_hdr.tfirst);
886 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
887 DPFSO1("timeout_offset");
888 DPFV2("hi", "u", hi);
889 DPFV2("lo", "u", lo);
892 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
893 DPFSO1("fehash_offset");
894 DPFV2("hi", "u", hi);
895 DPFV2("lo", "u", lo);
898 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
900 DPFV2("hi", "u", hi);
901 DPFV2("lo", "u", lo);
906 if (hdrs.cb_hdr.stamp.magic != CALLBACK_STATE_MAGIC) {
907 fprintf(stderr, "* magic check failed\n");
909 if (hdrs.cb_hdr.stamp.version != CALLBACK_STATE_VERSION) {
910 fprintf(stderr, "* version check failed\n");
915 dump_cb_timeout(void)
922 if (get_cb_timeout_hdr())
925 if (get_cb_timeout())
928 DPFOFF(hdrs.timeout_hdr_p);
929 DPFSO0("callback_state_timeout_header");
930 DPFX1("magic", hdrs.timeout_hdr.magic);
931 DPFV1("len", "u", hdrs.timeout_hdr.len);
932 DPFV1("records", "u", hdrs.timeout_hdr.records);
935 if (hdrs.timeout_hdr.magic != CALLBACK_STATE_TIMEOUT_MAGIC) {
936 fprintf(stderr, "* magic check failed\n");
939 DPFOFF(hdrs.timeout_p);
941 for (i = 0; i < 127; i++) {
942 DPFAE("u", hdrs.timeout[i]);
948 DPFALE("u", hdrs.timeout[127]);
960 if (get_cb_fehash_hdr())
966 DPFOFF(hdrs.fehash_hdr_p);
967 DPFSO0("callback_state_fehash_header");
968 DPFX1("magic", hdrs.fehash_hdr.magic);
969 DPFV1("len", "u", hdrs.fehash_hdr.len);
970 DPFV1("records", "u", hdrs.fehash_hdr.records);
973 if (hdrs.fehash_hdr.magic != CALLBACK_STATE_FEHASH_MAGIC) {
974 fprintf(stderr, "* magic check failed\n");
977 DPFOFF(hdrs.fehash_p);
979 for (i = 0; i < hdrs.fehash_hdr.records - 1; i++) {
980 DPFAE("u", hdrs.fehash[i]);
986 DPFALE("u", hdrs.fehash[hdrs.fehash_hdr.records-1]);
996 fprintf(stderr, "error getting host_state_header\n");
1000 for (i = 0; i < hdrs.h_hdr.records; i++) {
1011 fprintf(stderr, "error getting callback_state_header\n");
1015 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1026 fprintf(stderr, "error getting callback_state_entry_header\n");
1030 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1036 dump_he(afs_uint32 idx)
1039 fprintf(stderr, "error getting he %d\n", idx);
1043 DPFOFF(he_cursor.cursor);
1046 dump_he_interfaces();
1051 dump_fe(afs_uint32 idx)
1054 fprintf(stderr, "error getting fe %d\n", idx);
1058 DPFOFF(fe_cursor.cursor);
1064 dump_cb(afs_uint32 idx)
1067 fprintf(stderr, "error getting cb %d\n", idx);
1071 DPFOFF(cb_cursor.cursor);
1078 dump_he(he_cursor.idx);
1084 dump_fe(fe_cursor.idx);
1090 dump_cb(cb_cursor.idx);
1097 fprintf(stderr, "error getting host_state_header\n");
1101 if ((he_cursor.idx + 1) >= hdrs.h_hdr.records) {
1102 fprintf(stderr, "no more HEs\n");
1106 dump_he(he_cursor.idx+1);
1113 fprintf(stderr, "error getting callback_state_header\n");
1117 if ((fe_cursor.idx + 1) >= hdrs.cb_hdr.nFEs) {
1118 fprintf(stderr, "no more FEs\n");
1122 dump_fe(fe_cursor.idx+1);
1129 fprintf(stderr, "error getting callback_state_entry_header\n");
1133 if ((cb_cursor.idx + 1) >= fe_cursor.hdr.nCBs) {
1134 fprintf(stderr, "no more CBs\n");
1138 dump_cb(cb_cursor.idx+1);
1144 if (!he_cursor.idx) {
1145 fprintf(stderr, "no more HEs\n");
1149 dump_he(he_cursor.idx-1);
1155 if (!fe_cursor.idx) {
1156 fprintf(stderr, "no more FEs\n");
1160 dump_fe(fe_cursor.idx-1);
1166 if (!cb_cursor.idx) {
1167 fprintf(stderr, "no more CBs\n");
1171 dump_cb(cb_cursor.idx-1);
1178 fprintf(stderr, "error getting callback_state_header\n");
1182 if (!hdrs.cb_hdr.nFEs) {
1183 fprintf(stderr, "no FEs present\n");
1194 fprintf(stderr, "error getting host_state_header\n");
1198 if (!hdrs.h_hdr.records) {
1199 fprintf(stderr, "no HEs present\n");
1210 fprintf(stderr, "error getting callback_state_entry_header\n");
1214 if (!fe_cursor.hdr.nCBs) {
1215 fprintf(stderr, "no CBs present\n");
1226 fprintf(stderr, "error getting host_state_header\n");
1230 if (!hdrs.h_hdr.records) {
1231 fprintf(stderr, "no HEs present\n");
1235 dump_he(hdrs.h_hdr.records-1);
1242 fprintf(stderr, "error getting callback_state_header\n");
1246 if (!hdrs.cb_hdr.nFEs) {
1247 fprintf(stderr, "no FEs present\n");
1251 dump_fe(hdrs.cb_hdr.nFEs-1);
1258 fprintf(stderr, "error getting callback_state_entry_header\n");
1262 if (!fe_cursor.hdr.nCBs) {
1263 fprintf(stderr, "no CBs present\n");
1267 dump_cb(fe_cursor.hdr.nCBs-1);
1273 DPFSO0("host_state_entry_header");
1274 DPFX1("magic", he_cursor.hdr.magic);
1275 DPFV1("len", "u", he_cursor.hdr.len);
1276 DPFV1("interfaces", "u", he_cursor.hdr.interfaces);
1277 DPFV1("hcps", "u", he_cursor.hdr.hcps);
1280 if (he_cursor.hdr.magic != HOST_STATE_ENTRY_MAGIC) {
1281 fprintf(stderr, "* magic check failed\n");
1288 DPFSO0("hostDiskEntry");
1289 DPFS1("host", afs_inet_ntoa(he_cursor.he.host));
1290 DPFV1("port", "u", he_cursor.he.port);
1291 DPFX1("hostFlags", he_cursor.he.hostFlags);
1292 DPFV1("Console", "u", he_cursor.he.Console);
1293 DPFV1("hcpsfailed", "u", he_cursor.he.hcpsfailed);
1294 DPFV1("hcps_valid", "u", he_cursor.he.hcps_valid);
1295 if (hdrs.hdr.stats_detailed) {
1296 #ifdef FS_STATS_DETAILED
1297 DPFV1("InSameNetwork", "u", he_cursor.he.InSameNetwork);
1299 DPFV1("InSameNetwork", "u", he_cursor.he.padding1[0]);
1302 DPFV1("hcps_len", "u", he_cursor.he.hcps_len);
1303 DPFT1("LastCall", he_cursor.he.LastCall);
1304 DPFT1("ActiveCall", he_cursor.he.ActiveCall);
1305 DPFT1("cpsCall", he_cursor.he.cpsCall);
1306 DPFV1("cblist", "u", he_cursor.he.cblist);
1307 DPFV1("index", "u", he_cursor.he.index);
1312 dump_he_interfaces(void)
1315 struct Interface * ifp;
1318 if (!he_cursor.hdr.interfaces)
1321 len = sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1322 ifp = (struct Interface *) malloc(len);
1323 assert(ifp != NULL);
1325 memcpy(ifp, he_cursor.ifp, len);
1327 DPFSO0("Interface");
1328 DPFV1("numberOfInterfaces", "u", ifp->numberOfInterfaces);
1330 afsUUID_to_string(&ifp->uuid, temp_str, sizeof(temp_str));
1331 DPFS1("uuid", temp_str);
1332 for (i = 0; i < he_cursor.hdr.interfaces; i++) {
1333 snprintf(temp_str, sizeof(temp_str), "interface[%d]", i);
1335 DPFS2("addr", afs_inet_ntoa(ifp->interface[i].addr));
1336 DPFV2("port", "u", ifp->interface[i].port);
1342 if (he_cursor.hdr.interfaces != ifp->numberOfInterfaces) {
1343 fprintf(stderr, "* interface count mismatch between header and Interface struct\n");
1355 if (!he_cursor.hdr.hcps)
1358 len = (he_cursor.hdr.hcps)*sizeof(afs_uint32);
1359 hcps = (afs_int32 *) malloc(len);
1360 assert(hcps != NULL);
1361 memcpy(hcps, he_cursor.hcps, len);
1364 DPFAO1("prlist_val");
1365 for (i = 0; i < he_cursor.hdr.hcps - 1; i++) {
1366 DPFAE("d", hcps[i]);
1372 DPFALE("d", hcps[he_cursor.hdr.hcps-1]);
1381 DPFSO0("callback_state_entry_header");
1382 DPFX1("magic", fe_cursor.hdr.magic);
1383 DPFV1("len", "u", fe_cursor.hdr.len);
1384 DPFV1("nCBs", "u", fe_cursor.hdr.nCBs);
1387 if (fe_cursor.hdr.magic != CALLBACK_STATE_ENTRY_MAGIC) {
1388 fprintf(stderr, "* magic check failed\n");
1395 DPFSO0("FEDiskEntry");
1397 DPFV2("vnode", "u", fe_cursor.fe.fe.vnode);
1398 DPFV2("unique", "u", fe_cursor.fe.fe.unique);
1399 DPFV2("volid", "u", fe_cursor.fe.fe.volid);
1400 DPFV2("fnext", "u", fe_cursor.fe.fe.fnext);
1401 DPFV2("ncbs", "u", fe_cursor.fe.fe.ncbs);
1402 DPFV2("firstcb", "u", fe_cursor.fe.fe.firstcb);
1403 DPFV2("status", "u", fe_cursor.fe.fe.status);
1405 DPFV1("index", "u", fe_cursor.fe.index);
1412 DPFSO0("CBDiskEntry");
1414 DPFV2("cnext", "u", cb_cursor.cb.cb.cnext);
1415 DPFV2("fhead", "u", cb_cursor.cb.cb.fhead);
1416 DPFV2("thead", "u", (afs_uint32)cb_cursor.cb.cb.thead);
1417 DPFV2("status", "u", (afs_uint32)cb_cursor.cb.cb.status);
1418 DPFV2("hhead", "u", cb_cursor.cb.cb.hhead);
1419 DPFV2("tprev", "u", cb_cursor.cb.cb.tprev);
1420 DPFV2("tnext", "u", cb_cursor.cb.cb.tnext);
1421 DPFV2("hprev", "u", cb_cursor.cb.cb.hprev);
1422 DPFV2("hnext", "u", cb_cursor.cb.cb.hnext);
1424 DPFV1("index", "u", cb_cursor.cb.index);
1428 #define DPFHMS printf(" ")
1429 #define DPFHS printf(" ")
1430 #define DPFHN(offset) printf("\n%u\t", offset)
1431 #define DPFHD(x) printf("%02X ", x)
1432 #define DPFHE printf("\n")
1435 hexdump_map(afs_uint32 offset, afs_uint32 len)
1438 unsigned char * p = (unsigned char *)map;
1444 if ((offset + len) > map_len) {
1445 fprintf(stderr, "offset + length exceeds memory map size (%u > %u)\n",
1446 offset+len, map_len);
1454 for (i = offset % 16; i > 0; i--) {
1458 for (i=0; i < len; i++, p++, offset++) {
1459 if (!(offset % 16)) {
1461 } else if (!(offset % 8)) {
1472 if (!hdrs.hdr_valid) {
1473 if (map_len < sizeof(struct fs_state_header)) {
1474 fprintf(stderr, "corrupt state dump: fs_state_header larger than memory map\n");
1477 memcpy(&hdrs.hdr, map, sizeof(hdrs.hdr));
1490 if (hdrs.h_hdr_valid)
1496 SplitInt64(hdrs.hdr.h_offset, hi, lo);
1499 fprintf(stderr, "hi offset bits set in h_offset; can't get host_state_header\n");
1502 if ((lo >= map_len) ||
1503 ((lo + sizeof(struct host_state_header)) > map_len) ||
1504 (lo + sizeof(struct host_state_header) < lo)) {
1505 fprintf(stderr, "h_offset puts host_state_header beyond end of memory map\n");
1511 memcpy(&hdrs.h_hdr, buf, sizeof(struct host_state_header));
1513 buf += sizeof(struct host_state_header);
1514 he_cursor.fh = (void *)buf;
1524 if (hdrs.cb_hdr_valid)
1530 SplitInt64(hdrs.hdr.cb_offset, hi, lo);
1533 fprintf(stderr, "hi offset bits set in cb_offset; can't get callback_state_header\n");
1536 if ((lo >= map_len) ||
1537 ((lo + sizeof(struct callback_state_header)) > map_len) ||
1538 (lo + sizeof(struct callback_state_header) < lo)) {
1539 fprintf(stderr, "cb_offset puts callback_state_header beyond end of memory map\n");
1545 memcpy(&hdrs.cb_hdr, buf, sizeof(struct callback_state_header));
1546 hdrs.cb_hdr_p = buf;
1547 hdrs.cb_hdr_valid = 1;
1549 SplitInt64(hdrs.cb_hdr.fe_offset, hi, lo);
1552 fprintf(stderr, "hi offset bits set in fe_offset; can't get callback_state_entry_header\n");
1555 hi = lo + (hdrs.cb_hdr.nFEs * (sizeof(struct callback_state_entry_header) +
1556 sizeof(struct FEDiskEntry)) +
1557 hdrs.cb_hdr.nCBs * sizeof(struct CBDiskEntry));
1558 if ((hi > map_len) ||
1560 fprintf(stderr, "fe_offset puts callback_state_entry_header beyond end of memory map\n");
1566 fe_cursor.ffe = (void *)buf;
1572 get_cb_timeout_hdr(void)
1577 if (hdrs.timeout_hdr_valid)
1583 SplitInt64(hdrs.cb_hdr.timeout_offset, hi, lo);
1586 fprintf(stderr, "hi offset bits set in timeout_offset; can't get callback_state_timeout_header\n");
1589 if ((lo >= map_len) ||
1590 ((lo + sizeof(struct callback_state_timeout_header)) > map_len) ||
1591 (lo + sizeof(struct callback_state_timeout_header) < lo)) {
1592 fprintf(stderr, "timeout_offset puts callback_state_timeout_header beyond end of memory map\n");
1598 memcpy(&hdrs.timeout_hdr, buf, sizeof(struct callback_state_timeout_header));
1599 hdrs.timeout_hdr_p = buf;
1600 hdrs.timeout_hdr_valid = 1;
1601 buf += sizeof(struct callback_state_timeout_header);
1602 hdrs.timeout_p = buf;
1608 get_cb_timeout(void)
1615 if (get_cb_timeout_hdr())
1618 hdrs.timeout = (afs_uint32 *) calloc(hdrs.timeout_hdr.records, sizeof(afs_uint32));
1619 assert(hdrs.timeout != NULL);
1620 memcpy(hdrs.timeout, hdrs.timeout_p, hdrs.timeout_hdr.records * sizeof(afs_uint32));
1625 get_cb_fehash_hdr(void)
1630 if (hdrs.fehash_hdr_valid)
1636 SplitInt64(hdrs.cb_hdr.fehash_offset, hi, lo);
1639 fprintf(stderr, "hi offset bits set in fehash_offset; can't get callback_state_fehash_header\n");
1642 if ((lo >= map_len) ||
1643 ((lo + sizeof(struct callback_state_fehash_header)) > map_len) ||
1644 (lo + sizeof(struct callback_state_fehash_header) < lo)) {
1645 fprintf(stderr, "timeout_offset puts callback_state_fehash_header beyond end of memory map\n");
1651 memcpy(&hdrs.fehash_hdr, buf, sizeof(struct callback_state_fehash_header));
1652 hdrs.fehash_hdr_p = buf;
1653 hdrs.fehash_hdr_valid = 1;
1654 buf += sizeof(struct callback_state_fehash_header);
1655 hdrs.fehash_p = buf;
1668 if (get_cb_fehash_hdr())
1671 hdrs.fehash = (afs_uint32 *) calloc(hdrs.fehash_hdr.records, sizeof(afs_uint32));
1672 assert(hdrs.fehash != NULL);
1673 memcpy(hdrs.fehash, hdrs.fehash_p, hdrs.fehash_hdr.records * sizeof(afs_uint32));
1678 get_he(afs_uint32 idx)
1686 if (idx >= hdrs.h_hdr.records)
1689 if (he_cursor.idx == idx && he_cursor.hdr_valid && he_cursor.he_valid)
1692 he_cursor.hdr_valid = he_cursor.he_valid = 0;
1694 if (he_cache.cursor == NULL) {
1695 he_cache.cursor = (void **) calloc(hdrs.h_hdr.records, sizeof(void *));
1696 assert(he_cache.cursor != NULL);
1699 if (idx && he_cache.cursor[idx-1] == NULL) {
1700 for (i = 0; i < idx; i++) {
1701 if (he_cache.cursor[i] == NULL) {
1708 he_cursor.cursor = he_cursor.fh;
1709 } else if (he_cursor.cursor == he_cache.cursor[idx-1]) {
1710 p = (char *)he_cursor.cursor;
1711 p += he_cursor.hdr.len;
1712 he_cursor.cursor = (void *)p;
1714 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;
1722 he_cursor.idx = idx;
1723 he_cache.cursor[idx] = he_cursor.cursor;
1736 memcpy(&he_cursor.hdr, he_cursor.cursor, sizeof(struct host_state_entry_header));
1737 he_cursor.hdr_valid = 1;
1746 if (!he_cursor.hdr_valid) {
1752 p = (char *) he_cursor.cursor;
1753 p += sizeof(struct host_state_entry_header);
1755 memcpy(&he_cursor.he, p, sizeof(struct hostDiskEntry));
1757 he_cursor.he_valid = 1;
1758 p += sizeof(struct hostDiskEntry);
1759 he_cursor.ifp = (void *)p;
1760 if (he_cursor.hdr.interfaces) {
1761 p += sizeof(struct Interface) + ((he_cursor.hdr.interfaces-1)*sizeof(struct AddrPort));
1762 he_cursor.hcps = (void *)p;
1764 he_cursor.hcps = he_cursor.ifp;
1770 get_fe(afs_uint32 idx)
1775 cb_cursor.cb_valid = 0;
1780 if (idx >= hdrs.cb_hdr.nFEs)
1783 if (fe_cursor.idx == idx && fe_cursor.hdr_valid && fe_cursor.fe_valid)
1786 fe_cursor.hdr_valid = fe_cursor.fe_valid = 0;
1788 if (fe_cache.cursor == NULL) {
1789 fe_cache.cursor = (void **) calloc(hdrs.cb_hdr.nFEs, sizeof(void *));
1790 assert(fe_cache.cursor != NULL);
1793 if (idx && fe_cache.cursor[idx-1] == NULL) {
1794 for (i = 0; i < idx; i++) {
1795 if (fe_cache.cursor[i] == NULL) {
1802 fe_cursor.cursor = fe_cursor.ffe;
1803 } else if (fe_cursor.cursor == fe_cache.cursor[idx-1]) {
1804 p = (char *)fe_cursor.cursor;
1805 p += fe_cursor.hdr.len;
1806 fe_cursor.cursor = (void *)p;
1808 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;
1816 fe_cursor.idx = idx;
1817 fe_cache.cursor[idx] = fe_cursor.cursor;
1830 if (!fe_cursor.cursor) {
1831 if(get_fe(fe_cursor.idx)) {
1836 memcpy(&fe_cursor.hdr, fe_cursor.cursor, sizeof(struct callback_state_entry_header));
1837 fe_cursor.hdr_valid = 1;
1846 if (!fe_cursor.hdr_valid) {
1852 p = (char *) fe_cursor.cursor;
1853 p += sizeof(struct callback_state_entry_header);
1855 memcpy(&fe_cursor.fe, p, sizeof(struct FEDiskEntry));
1857 fe_cursor.fe_valid = 1;
1858 p += sizeof(struct FEDiskEntry);
1859 fe_cursor.fcb = (void *)p;
1864 get_cb(afs_uint32 idx)
1869 if (get_fe(fe_cursor.idx))
1872 if (idx >= fe_cursor.hdr.nCBs)
1875 if (idx == cb_cursor.idx && cb_cursor.cb_valid)
1878 cb_cursor.cb_valid = 0;
1880 p = (char *)fe_cursor.fcb;
1881 p += idx * sizeof(struct CBDiskEntry);
1882 cb_cursor.cursor = (void *)p;
1884 cb_cursor.idx = idx;
1895 memcpy(&cb_cursor.cb, cb_cursor.cursor, sizeof(struct CBDiskEntry));
1896 cb_cursor.cb_valid = 1;
1901 find_he_by_index(afs_uint32 idx)
1909 for (i = 0; i < hdrs.h_hdr.records; i++) {
1911 fprintf(stderr, "error getting he %d\n", i);
1914 if (he_cursor.he.index == idx)
1918 if (i < hdrs.h_hdr.records) {
1926 find_fe_by_index(afs_uint32 idx)
1934 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1936 fprintf(stderr, "error getting fe %d\n", i);
1939 if (fe_cursor.fe.index == idx)
1943 if (i < hdrs.cb_hdr.nFEs) {
1951 find_fe_by_fid(afs_uint32 volid, afs_uint32 vnode, afs_uint32 unique)
1959 for (i = 0; i < hdrs.cb_hdr.nFEs; i++) {
1961 fprintf(stderr, "error getting fe %d\n", i);
1964 if ((fe_cursor.fe.fe.unique == unique) &&
1965 (fe_cursor.fe.fe.volid == volid) &&
1966 (fe_cursor.fe.fe.vnode == vnode))
1970 if (i < hdrs.cb_hdr.nFEs) {
1978 find_cb_by_index(afs_uint32 idx)
1986 for (i = 0; i < fe_cursor.hdr.nCBs; i++) {
1988 fprintf(stderr, "error getting cb %d\n", i);
1991 if (cb_cursor.cb.index == idx)
1995 if (i < fe_cursor.hdr.nCBs) {
2002 #endif /* AFS_DEMAND_ATTACH_FS */