dafs-accurately-track-inuse-20080317
[openafs.git] / src / vol / fssync-debug.c
1 /*
2  * Copyright 2006-2008, Sine Nomine Associates and others.
3  * All Rights Reserved.
4  * 
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
8  */
9
10 /* Main program file. Define globals. */
11 #define MAIN 1
12
13 /*
14  * fssync administration tool
15  */
16
17
18 #include <afsconfig.h>
19 #include <afs/param.h>
20
21 RCSID
22     ("$Header$");
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <dirent.h>
28 #include <sys/stat.h>
29 #include <time.h>
30 #include <errno.h>
31 #ifdef AFS_NT40_ENV
32 #include <io.h>
33 #include <WINNT/afsevent.h>
34 #else
35 #include <sys/param.h>
36 #include <sys/file.h>
37 #ifndef ITIMER_REAL
38 #include <sys/time.h>
39 #endif /* ITIMER_REAL */
40 #endif
41 #include <rx/xdr.h>
42 #include <afs/afsint.h>
43 #include <afs/assert.h>
44
45
46 #include <fcntl.h>
47
48 #ifndef AFS_NT40_ENV
49 #include <afs/osi_inode.h>
50 #endif
51
52 #include <afs/cmd.h>
53 #include <afs/afsutil.h>
54 #include <afs/fileutil.h>
55
56 #include "nfs.h"
57 #include "lwp.h"
58 #include "lock.h"
59 #include "ihandle.h"
60 #include "vnode.h"
61 #include "volume.h"
62 #include "partition.h"
63 #include "daemon_com.h"
64 #include "fssync.h"
65 #ifdef AFS_NT40_ENV
66 #include <pthread.h>
67 #endif
68
69 int VolumeChanged; /* hack to make dir package happy */
70
71
72 struct volop_state {
73     afs_uint32 volume;
74     afs_uint32 vnode;
75     afs_uint32 unique;
76     char partName[16];
77 };
78
79 struct state {
80     afs_int32 reason;
81     struct volop_state * vop;
82 };
83
84 static int common_prolog(struct cmd_syndesc *, struct state *);
85 static int common_volop_prolog(struct cmd_syndesc *, struct state *);
86
87 static int do_volop(struct state *, afs_int32 command, SYNC_response * res);
88
89 static char * response_code_to_string(afs_int32);
90 static char * command_code_to_string(afs_int32);
91 static char * reason_code_to_string(afs_int32);
92 static char * program_type_to_string(afs_int32);
93
94 static int VolOnline(struct cmd_syndesc * as, void * rock);
95 static int VolOffline(struct cmd_syndesc * as, void * rock);
96 static int VolMode(struct cmd_syndesc * as, void * rock);
97 static int VolDetach(struct cmd_syndesc * as, void * rock);
98 static int VolBreakCBKs(struct cmd_syndesc * as, void * rock);
99 static int VolMove(struct cmd_syndesc * as, void * rock);
100 static int VolList(struct cmd_syndesc * as, void * rock);
101 static int VolQuery(struct cmd_syndesc * as, void * rock);
102 static int VolHdrQuery(struct cmd_syndesc * as, void * rock);
103 static int VolOpQuery(struct cmd_syndesc * as, void * rock);
104 static int StatsQuery(struct cmd_syndesc * as, void * rock);
105 static int VnQuery(struct cmd_syndesc * as, void * rock);
106
107 static void print_vol_stats_general(VolPkgStats * stats);
108 static void print_vol_stats_viceP(struct DiskPartitionStats64 * stats);
109 static void print_vol_stats_hash(struct VolumeHashChainStats * stats);
110 #ifdef AFS_DEMAND_ATTACH_FS
111 static void print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats);
112 #endif
113
114 #ifndef AFS_NT40_ENV
115 #include "AFS_component_version_number.c"
116 #endif
117 #define MAX_ARGS 128
118
119 #define COMMON_PARMS_OFFSET    12
120 #define COMMON_PARMS(ts) \
121     cmd_Seek(ts, COMMON_PARMS_OFFSET); \
122     cmd_AddParm(ts, "-reason", CMD_SINGLE, CMD_OPTIONAL, "sync protocol reason code"); \
123     cmd_AddParm(ts, "-programtype", CMD_SINGLE, CMD_OPTIONAL, "program type code")
124
125 #define COMMON_VOLOP_PARMS_OFFSET    10
126 #define COMMON_VOLOP_PARMS(ts) \
127     cmd_Seek(ts, COMMON_VOLOP_PARMS_OFFSET); \
128     cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id"); \
129     cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name")
130
131 #define CUSTOM_PARMS_OFFSET 1
132
133
134 #define VOLOP_PARMS_DECL(ts) \
135     COMMON_VOLOP_PARMS(ts); \
136     COMMON_PARMS(ts)
137 #define COMMON_PARMS_DECL(ts) \
138     COMMON_PARMS(ts)
139
140 int
141 main(int argc, char **argv)
142 {
143     struct cmd_syndesc *ts;
144     int err = 0;
145     int i;
146     extern char cml_version_number[];
147
148     /* Initialize directory paths */
149     if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
150 #ifdef AFS_NT40_ENV
151         ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
152 #endif
153         fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
154                 argv[0]);
155         exit(2);
156     }
157
158     
159     ts = cmd_CreateSyntax("online", VolOnline, NULL, "bring a volume online (FSYNC_VOL_ON opcode)");
160     VOLOP_PARMS_DECL(ts);
161
162     ts = cmd_CreateSyntax("offline", VolOffline, NULL, "take a volume offline (FSYNC_VOL_OFF opcode)");
163     VOLOP_PARMS_DECL(ts);
164
165     ts = cmd_CreateSyntax("mode", VolMode, NULL, "change volume attach mode (FSYNC_VOL_NEEDVOLUME opcode)");
166     VOLOP_PARMS_DECL(ts);
167     cmd_CreateAlias(ts, "needvolume");
168
169     ts = cmd_CreateSyntax("detach", VolDetach, NULL, "detach a volume (FSYNC_VOL_DONE opcode)");
170     VOLOP_PARMS_DECL(ts);
171
172     ts = cmd_CreateSyntax("callback", VolBreakCBKs, NULL, "break callbacks for volume (FSYNC_VOL_BREAKCBKS opcode)");
173     VOLOP_PARMS_DECL(ts);
174     cmd_CreateAlias(ts, "cbk");
175
176     ts = cmd_CreateSyntax("move", VolMove, NULL, "set volume moved flag (FSYNC_VOL_MOVE opcode)");
177     VOLOP_PARMS_DECL(ts);
178
179     ts = cmd_CreateSyntax("list", VolList, NULL, "sync local volume list (FSYNC_VOL_LISTVOLUMES opcode)");
180     VOLOP_PARMS_DECL(ts);
181     cmd_CreateAlias(ts, "ls");
182
183     ts = cmd_CreateSyntax("query", VolQuery, NULL, "get volume structure (FSYNC_VOL_QUERY opcode)");
184     VOLOP_PARMS_DECL(ts);
185     cmd_CreateAlias(ts, "qry");
186
187     ts = cmd_CreateSyntax("header", VolHdrQuery, NULL, "get volume disk data structure (FSYNC_VOL_QUERY_HDR opcode)");
188     VOLOP_PARMS_DECL(ts);
189     cmd_CreateAlias(ts, "hdr");
190
191     ts = cmd_CreateSyntax("volop", VolOpQuery, NULL, "get pending volume operation info (FSYNC_VOL_QUERY_VOP opcode)");
192     VOLOP_PARMS_DECL(ts);
193     cmd_CreateAlias(ts, "vop");
194
195     ts = cmd_CreateSyntax("vnode", VnQuery, NULL, "get vnode structure (FSYNC_VOL_QUERY_VNODE opcode)");
196     cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
197     cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
198     cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id");
199     cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier");
200     cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "paritition name");
201     COMMON_PARMS_DECL(ts);
202
203     ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information");
204     cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
205     cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "subcommand");
206     cmd_AddParm(ts, "-arg1", CMD_SINGLE, CMD_OPTIONAL, "arg1");
207     cmd_AddParm(ts, "-arg2", CMD_SINGLE, CMD_OPTIONAL, "arg2");
208     COMMON_PARMS_DECL(ts);
209
210     err = cmd_Dispatch(argc, argv);
211     exit(err);
212 }
213
214 static int
215 common_prolog(struct cmd_syndesc * as, struct state * state)
216 {
217     register struct cmd_item *ti;
218
219 #ifdef AFS_NT40_ENV
220     if (afs_winsockInit() < 0) {
221         Exit(1);
222     }
223 #endif
224
225     VInitVolumePackage(debugUtility, 1, 1,
226                        DONT_CONNECT_FS, 0);
227     DInit(1);
228
229     if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) {  /* -reason */
230         state->reason = atoi(ti->data);
231     }
232     if ((ti = as->parms[COMMON_PARMS_OFFSET+1].items)) {        /* -programtype */
233         if (!strcmp(ti->data, "fileServer")) {
234             programType = fileServer;
235         } else if (!strcmp(ti->data, "volumeUtility")) {
236             programType = volumeUtility;
237         } else if (!strcmp(ti->data, "salvager")) {
238             programType = salvager;
239         } else if (!strcmp(ti->data, "salvageServer")) {
240             programType = salvageServer;
241         } else {
242             programType = (ProgramType) atoi(ti->data);
243         }
244     }
245
246     VConnectFS();
247
248     return 0;
249 }
250
251 static int
252 common_volop_prolog(struct cmd_syndesc * as, struct state * state)
253 {
254     register struct cmd_item *ti;
255     char pname[100], *temp;
256
257     state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
258     assert(state->vop != NULL);
259
260     if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET].items)) {    /* -volumeid */
261         state->vop->volume = atoi(ti->data);
262     } else {
263         fprintf(stderr, "required argument -volumeid not given\n");
264     }
265
266     if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+1].items)) {  /* -partition */
267         strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
268     } else {
269         memset(state->vop->partName, 0, sizeof(state->vop->partName));
270     }
271
272     return 0;
273 }
274
275 static int
276 do_volop(struct state * state, afs_int32 command, SYNC_response * res)
277 {
278     afs_int32 code;
279     SYNC_PROTO_BUF_DECL(res_buf);
280     SYNC_response res_l;
281
282     if (!res) {
283         res = &res_l;
284         res->payload.len = SYNC_PROTO_MAX_LEN;
285         res->payload.buf = res_buf;
286     }
287
288     fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n", 
289             command, command_code_to_string(command));
290
291     code = FSYNC_VolOp(state->vop->volume,
292                        state->vop->partName,
293                        command,
294                        state->reason,
295                        res);
296
297     switch (code) {
298     case SYNC_OK:
299     case SYNC_DENIED:
300         break;
301     default:
302         fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
303     }
304
305     fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
306     fprintf(stderr, "protocol response code was %d (%s)\n", 
307             res->hdr.response, response_code_to_string(res->hdr.response));
308     fprintf(stderr, "protocol reason code was %d (%s)\n", 
309             res->hdr.reason, reason_code_to_string(res->hdr.reason));
310
311     VDisconnectFS();
312 }
313
314
315 #define ENUMTOSTRING(en)  #en
316 #define ENUMCASE(en) \
317     case en: \
318         return ENUMTOSTRING(en); \
319         break
320
321 #define FLAGTOSTRING(fl)  #fl
322 #define FLAGCASE(bitstr, fl, str, count) \
323     do { \
324         if ((bitstr) & (fl)) { \
325             if (count) \
326                 strlcat((str), " | ", sizeof(str)); \
327             strlcat((str), FLAGTOSTRING(fl), sizeof(str)); \
328             (count)++; \
329         } \
330     } while (0)
331
332 static char *
333 response_code_to_string(afs_int32 response)
334 {
335     switch (response) {
336         ENUMCASE(SYNC_OK);
337         ENUMCASE(SYNC_DENIED);
338         ENUMCASE(SYNC_COM_ERROR);
339         ENUMCASE(SYNC_BAD_COMMAND);
340         ENUMCASE(SYNC_FAILED);
341     default:
342         return "**UNKNOWN**";
343     }
344 }
345
346 static char *
347 command_code_to_string(afs_int32 command)
348 {
349     switch (command) {
350         ENUMCASE(SYNC_COM_CHANNEL_CLOSE);
351         ENUMCASE(FSYNC_VOL_ON);
352         ENUMCASE(FSYNC_VOL_OFF);
353         ENUMCASE(FSYNC_VOL_LISTVOLUMES);
354         ENUMCASE(FSYNC_VOL_NEEDVOLUME);
355         ENUMCASE(FSYNC_VOL_MOVE);
356         ENUMCASE(FSYNC_VOL_BREAKCBKS);
357         ENUMCASE(FSYNC_VOL_DONE);
358         ENUMCASE(FSYNC_VOL_QUERY);
359         ENUMCASE(FSYNC_VOL_QUERY_HDR);
360         ENUMCASE(FSYNC_VOL_QUERY_VOP);
361         ENUMCASE(FSYNC_VOL_STATS_GENERAL);
362         ENUMCASE(FSYNC_VOL_STATS_VICEP);
363         ENUMCASE(FSYNC_VOL_STATS_HASH);
364         ENUMCASE(FSYNC_VOL_STATS_HDR);
365         ENUMCASE(FSYNC_VOL_STATS_VLRU);
366         ENUMCASE(FSYNC_VOL_ATTACH);
367         ENUMCASE(FSYNC_VOL_FORCE_ERROR);
368         ENUMCASE(FSYNC_VOL_LEAVE_OFF);
369         ENUMCASE(FSYNC_VOL_QUERY_VNODE);
370     default:
371         return "**UNKNOWN**";
372     }
373 }
374
375 static char *
376 reason_code_to_string(afs_int32 reason)
377 {
378     switch (reason) {
379         ENUMCASE(SYNC_REASON_NONE);
380         ENUMCASE(SYNC_REASON_MALFORMED_PACKET);
381         ENUMCASE(SYNC_REASON_NOMEM);
382         ENUMCASE(SYNC_REASON_ENCODING_ERROR);
383         ENUMCASE(FSYNC_WHATEVER);
384         ENUMCASE(FSYNC_SALVAGE);
385         ENUMCASE(FSYNC_MOVE);
386         ENUMCASE(FSYNC_OPERATOR);
387         ENUMCASE(FSYNC_EXCLUSIVE);
388         ENUMCASE(FSYNC_UNKNOWN_VOLID);
389         ENUMCASE(FSYNC_HDR_NOT_ATTACHED);
390         ENUMCASE(FSYNC_NO_PENDING_VOL_OP);
391         ENUMCASE(FSYNC_VOL_PKG_ERROR);
392         ENUMCASE(FSYNC_UNKNOWN_VNID);
393     default:
394         return "**UNKNOWN**";
395     }
396 }
397
398 static char *
399 program_type_to_string(afs_int32 type)
400 {
401     switch ((ProgramType)type) {
402         ENUMCASE(fileServer);
403         ENUMCASE(volumeUtility);
404         ENUMCASE(salvager);
405         ENUMCASE(salvageServer);
406         ENUMCASE(debugUtility);
407     default:
408         return "**UNKNOWN**";
409     }
410 }
411
412 static int 
413 VolOnline(struct cmd_syndesc * as, void * rock)
414 {
415     struct state state;
416
417     common_prolog(as, &state);
418     common_volop_prolog(as, &state);
419
420     do_volop(&state, FSYNC_VOL_ON, NULL);
421
422     return 0;
423 }
424
425 static int 
426 VolOffline(struct cmd_syndesc * as, void * rock)
427 {
428     struct state state;
429
430     common_prolog(as, &state);
431     common_volop_prolog(as, &state);
432
433     do_volop(&state, FSYNC_VOL_OFF, NULL);
434
435     return 0;
436 }
437
438 static int
439 VolMode(struct cmd_syndesc * as, void * rock)
440 {
441     struct state state;
442
443     common_prolog(as, &state);
444     common_volop_prolog(as, &state);
445
446     do_volop(&state, FSYNC_VOL_NEEDVOLUME, NULL);
447
448     return 0;
449 }
450
451 static int
452 VolDetach(struct cmd_syndesc * as, void * rock)
453 {
454     struct state state;
455
456     common_prolog(as, &state);
457     common_volop_prolog(as, &state);
458
459     do_volop(&state, FSYNC_VOL_DONE, NULL);
460
461     return 0;
462 }
463
464 static int
465 VolBreakCBKs(struct cmd_syndesc * as, void * rock)
466 {
467     struct state state;
468
469     common_prolog(as, &state);
470     common_volop_prolog(as, &state);
471
472     do_volop(&state, FSYNC_VOL_BREAKCBKS, NULL);
473
474     return 0;
475 }
476
477 static int
478 VolMove(struct cmd_syndesc * as, void * rock)
479 {
480     struct state state;
481
482     common_prolog(as, &state);
483     common_volop_prolog(as, &state);
484
485     do_volop(&state, FSYNC_VOL_MOVE, NULL);
486
487     return 0;
488 }
489
490 static int
491 VolList(struct cmd_syndesc * as, void * rock)
492 {
493     struct state state;
494
495     common_prolog(as, &state);
496     common_volop_prolog(as, &state);
497
498     do_volop(&state, FSYNC_VOL_LISTVOLUMES, NULL);
499
500     return 0;
501 }
502
503 #ifdef AFS_DEMAND_ATTACH_FS
504 static char *
505 vol_state_to_string(VolState state)
506 {
507     switch (state) {
508         ENUMCASE(VOL_STATE_UNATTACHED);
509         ENUMCASE(VOL_STATE_PREATTACHED);
510         ENUMCASE(VOL_STATE_ATTACHING);
511         ENUMCASE(VOL_STATE_ATTACHED);
512         ENUMCASE(VOL_STATE_UPDATING);
513         ENUMCASE(VOL_STATE_GET_BITMAP);
514         ENUMCASE(VOL_STATE_HDR_LOADING);
515         ENUMCASE(VOL_STATE_HDR_ATTACHING);
516         ENUMCASE(VOL_STATE_SHUTTING_DOWN);
517         ENUMCASE(VOL_STATE_GOING_OFFLINE);
518         ENUMCASE(VOL_STATE_OFFLINING);
519         ENUMCASE(VOL_STATE_DETACHING);
520         ENUMCASE(VOL_STATE_SALVSYNC_REQ);
521         ENUMCASE(VOL_STATE_SALVAGING);
522         ENUMCASE(VOL_STATE_ERROR);
523         ENUMCASE(VOL_STATE_VNODE_ALLOC);
524         ENUMCASE(VOL_STATE_VNODE_GET);
525         ENUMCASE(VOL_STATE_VNODE_CLOSE);
526         ENUMCASE(VOL_STATE_VNODE_RELEASE);
527         ENUMCASE(VOL_STATE_VLRU_ADD);
528         ENUMCASE(VOL_STATE_FREED);
529     default:
530         return "**UNKNOWN**";
531     }
532 }
533
534 static char *
535 vol_flags_to_string(afs_uint16 flags)
536 {
537     static char str[128];
538     int count = 0;
539     str[0]='\0';
540
541     FLAGCASE(flags, VOL_HDR_ATTACHED, str, count);
542     FLAGCASE(flags, VOL_HDR_LOADED, str, count);
543     FLAGCASE(flags, VOL_HDR_IN_LRU, str, count);
544     FLAGCASE(flags, VOL_IN_HASH, str, count);
545     FLAGCASE(flags, VOL_ON_VBYP_LIST, str, count);
546     FLAGCASE(flags, VOL_IS_BUSY, str, count);
547     FLAGCASE(flags, VOL_ON_VLRU, str, count);
548     FLAGCASE(flags, VOL_HDR_DONTSALV, str, count);
549
550     return str;
551 }
552
553 static char *
554 vlru_idx_to_string(int idx)
555 {
556     switch (idx) {
557         ENUMCASE(VLRU_QUEUE_NEW);
558         ENUMCASE(VLRU_QUEUE_MID);
559         ENUMCASE(VLRU_QUEUE_OLD);
560         ENUMCASE(VLRU_QUEUE_CANDIDATE);
561         ENUMCASE(VLRU_QUEUE_HELD);
562         ENUMCASE(VLRU_QUEUE_INVALID);
563     default:
564         return "**UNKNOWN**";
565     }
566 }
567
568
569 static char *
570 vn_state_to_string(VnState state)
571 {
572     switch (state) {
573         ENUMCASE(VN_STATE_INVALID);
574         ENUMCASE(VN_STATE_RELEASING);
575         ENUMCASE(VN_STATE_CLOSING);
576         ENUMCASE(VN_STATE_ALLOC);
577         ENUMCASE(VN_STATE_ONLINE);
578         ENUMCASE(VN_STATE_LOAD);
579         ENUMCASE(VN_STATE_EXCLUSIVE);
580         ENUMCASE(VN_STATE_STORE);
581         ENUMCASE(VN_STATE_READ);
582         ENUMCASE(VN_STATE_ERROR);
583     default:
584         return "**UNKNOWN**";
585     }
586 }
587
588 static char *
589 vn_flags_to_string(afs_uint32 flags)
590 {
591     static char str[128];
592     int count = 0;
593     str[0]='\0';
594
595     FLAGCASE(flags, VN_ON_HASH, str, count);
596     FLAGCASE(flags, VN_ON_LRU, str, count);
597     FLAGCASE(flags, VN_ON_VVN, str, count);
598
599     return str;
600 }
601 #endif
602
603 static int
604 VolQuery(struct cmd_syndesc * as, void * rock)
605 {
606     struct state state;
607     SYNC_PROTO_BUF_DECL(res_buf);
608     SYNC_response res;
609     Volume v;
610     int hi, lo;
611
612     res.hdr.response_len = sizeof(res.hdr);
613     res.payload.buf = res_buf;
614     res.payload.len = SYNC_PROTO_MAX_LEN;
615
616     common_prolog(as, &state);
617     common_volop_prolog(as, &state);
618
619     do_volop(&state, FSYNC_VOL_QUERY, &res);
620
621     if (res.hdr.response == SYNC_OK) {
622         memcpy(&v, res.payload.buf, sizeof(Volume));
623
624         printf("volume = {\n");
625         printf("\thashid          = %u\n", v.hashid);
626         printf("\theader          = 0x%x\n", v.header);
627         printf("\tdevice          = %d\n", v.device);
628         printf("\tpartition       = 0x%x\n", v.partition);
629         printf("\tlinkHandle      = 0x%x\n", v.linkHandle);
630         printf("\tnextVnodeUnique = %u\n", v.nextVnodeUnique);
631         printf("\tdiskDataHandle  = 0x%x\n", v.diskDataHandle);
632         printf("\tvnodeHashOffset = %u\n", v.vnodeHashOffset);
633         printf("\tshuttingDown    = %d\n", v.shuttingDown);
634         printf("\tgoingOffline    = %d\n", v.goingOffline);
635         printf("\tcacheCheck      = %u\n", v.cacheCheck);
636         printf("\tnUsers          = %d\n", v.nUsers);
637         printf("\tneedsPutBack    = %d\n", v.needsPutBack);
638         printf("\tspecialStatus   = %d\n", v.specialStatus);
639         printf("\tupdateTime      = %u\n", v.updateTime);
640         
641         printf("\tvnodeIndex[vSmall] = {\n");
642         printf("\t\thandle       = 0x%x\n", v.vnodeIndex[vSmall].handle);
643         printf("\t\tbitmap       = 0x%x\n", v.vnodeIndex[vSmall].bitmap);
644         printf("\t\tbitmapSize   = %u\n", v.vnodeIndex[vSmall].bitmapSize);
645         printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vSmall].bitmapOffset);
646         printf("\t}\n");
647         printf("\tvnodeIndex[vLarge] = {\n");
648         printf("\t\thandle       = 0x%x\n", v.vnodeIndex[vLarge].handle);
649         printf("\t\tbitmap       = 0x%x\n", v.vnodeIndex[vLarge].bitmap);
650         printf("\t\tbitmapSize   = %u\n", v.vnodeIndex[vLarge].bitmapSize);
651         printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vLarge].bitmapOffset);
652         printf("\t}\n");
653 #ifdef AFS_DEMAND_ATTACH_FS
654         if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
655             printf("\tupdateTime      = %u\n", v.updateTime);
656             printf("\tattach_state    = %s\n", vol_state_to_string(v.attach_state));
657             printf("\tattach_flags    = %s\n", vol_flags_to_string(v.attach_flags));
658             printf("\tnWaiters        = %d\n", v.nWaiters);
659             printf("\tchainCacheCheck = %d\n", v.chainCacheCheck);
660             
661             /* online salvage structure */
662             printf("\tsalvage = {\n");
663             printf("\t\tprio      = %u\n", v.salvage.prio);
664             printf("\t\treason    = %d\n", v.salvage.reason);
665             printf("\t\trequested = %d\n", v.salvage.requested);
666             printf("\t\tscheduled = %d\n", v.salvage.scheduled);
667             printf("\t}\n");
668             
669             /* statistics structure */
670             printf("\tstats = {\n");
671
672             printf("\t\thash_lookups = {\n");
673             SplitInt64(v.stats.hash_lookups,hi,lo);
674             printf("\t\t\thi = %u\n", hi);
675             printf("\t\t\tlo = %u\n", lo);
676             printf("\t\t}\n");
677
678             printf("\t\thash_short_circuits = {\n");
679             SplitInt64(v.stats.hash_short_circuits,hi,lo);
680             printf("\t\t\thi = %u\n", hi);
681             printf("\t\t\tlo = %u\n", lo);
682             printf("\t\t}\n");
683
684             printf("\t\thdr_loads = {\n");
685             SplitInt64(v.stats.hdr_loads,hi,lo);
686             printf("\t\t\thi = %u\n", hi);
687             printf("\t\t\tlo = %u\n", lo);
688             printf("\t\t}\n");
689
690             printf("\t\thdr_gets = {\n");
691             SplitInt64(v.stats.hdr_gets,hi,lo);
692             printf("\t\t\thi = %u\n", hi);
693             printf("\t\t\tlo = %u\n", lo);
694             printf("\t\t}\n");
695             
696             printf("\t\tattaches         = %u\n", v.stats.attaches);
697             printf("\t\tsoft_detaches    = %u\n", v.stats.soft_detaches);
698             printf("\t\tsalvages         = %u\n", v.stats.salvages);
699             printf("\t\tvol_ops          = %u\n", v.stats.vol_ops);
700             
701             printf("\t\tlast_attach      = %u\n", v.stats.last_attach);
702             printf("\t\tlast_get         = %u\n", v.stats.last_get);
703             printf("\t\tlast_promote     = %u\n", v.stats.last_promote);
704             printf("\t\tlast_hdr_get     = %u\n", v.stats.last_hdr_get);
705             printf("\t\tlast_hdr_load    = %u\n", v.stats.last_hdr_load);
706             printf("\t\tlast_salvage     = %u\n", v.stats.last_salvage);
707             printf("\t\tlast_salvage_req = %u\n", v.stats.last_salvage_req);
708             printf("\t\tlast_vol_op      = %u\n", v.stats.last_vol_op);
709             printf("\t}\n");
710             
711             /* VLRU state */
712             printf("\tvlru = {\n");
713             printf("\t\tidx = %d (%s)\n", 
714                    v.vlru.idx, vlru_idx_to_string(v.vlru.idx));
715             printf("\t}\n");
716
717             /* volume op state */
718             printf("\tpending_vol_op  = 0x%x\n", v.pending_vol_op);
719         }
720 #else /* !AFS_DEMAND_ATTACH_FS */
721         if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
722             printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
723             printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
724             printf("*** to dump dafs extended state\n");
725         }
726 #endif /* !AFS_DEMAND_ATTACH_FS */
727         printf("}\n");
728     }
729
730     return 0;
731 }
732
733 static int
734 VolHdrQuery(struct cmd_syndesc * as, void * rock)
735 {
736     struct state state;
737     SYNC_PROTO_BUF_DECL(res_buf);
738     SYNC_response res;
739     VolumeDiskData v;
740     int i;
741
742     res.hdr.response_len = sizeof(res.hdr);
743     res.payload.buf = res_buf;
744     res.payload.len = SYNC_PROTO_MAX_LEN;
745
746     common_prolog(as, &state);
747     common_volop_prolog(as, &state);
748
749     do_volop(&state, FSYNC_VOL_QUERY_HDR, &res);
750
751     if (res.hdr.response == SYNC_OK) {
752         memcpy(&v, res.payload.buf, sizeof(VolumeDiskData));
753
754         printf("VolumeDiskData = {\n");
755         printf("\tstamp = {\n");
756         printf("\t\tmagic   = 0x%x\n", v.stamp.magic);
757         printf("\t\tversion = %u\n", v.stamp.version);
758         printf("\t}\n");
759         
760         printf("\tid               = %u\n", v.id);
761         printf("\tname             = '%s'\n", v.name);
762         if (v.inUse != 0) {
763             printf("\tinUse            = %d (%s)\n", v.inUse, program_type_to_string(v.inUse));
764         } else {
765             printf("\tinUse            = %d (no)\n", v.inUse);
766         }
767         printf("\tinService        = %d\n", v.inService);
768         printf("\tblessed          = %d\n", v.blessed);
769         printf("\tneedsSalvaged    = %d\n", v.needsSalvaged);
770         printf("\tuniquifier       = %u\n", v.uniquifier);
771         printf("\ttype             = %d\n", v.type);
772         printf("\tparentId         = %u\n", v.parentId);
773         printf("\tcloneId          = %u\n", v.cloneId);
774         printf("\tbackupId         = %u\n", v.backupId);
775         printf("\trestoredFromId   = %u\n", v.restoredFromId);
776         printf("\tneedsCallback    = %d\n", v.needsCallback);
777         printf("\tdestroyMe        = %d\n", v.destroyMe);
778         printf("\tdontSalvage      = %d\n", v.dontSalvage);
779         printf("\tmaxquota         = %d\n", v.maxquota);
780         printf("\tminquota         = %d\n", v.minquota);
781         printf("\tmaxfiles         = %d\n", v.maxfiles);
782         printf("\taccountNumber    = %u\n", v.accountNumber);
783         printf("\towner            = %u\n", v.owner);
784         printf("\tfilecount        = %d\n", v.filecount);
785         printf("\tdiskused         = %d\n", v.diskused);
786         printf("\tdayUse           = %d\n", v.dayUse);
787         for (i = 0; i < 7; i++) {
788             printf("\tweekUse[%d]       = %d\n", i, v.weekUse[i]);
789         }
790         printf("\tdayUseDate       = %u\n", v.dayUseDate);
791         printf("\tcreationDate     = %u\n", v.creationDate);
792         printf("\taccessDate       = %u\n", v.accessDate);
793         printf("\tupdateDate       = %u\n", v.updateDate);
794         printf("\texpirationDate   = %u\n", v.expirationDate);
795         printf("\tbackupDate       = %u\n", v.backupDate);
796         printf("\tcopyDate         = %u\n", v.copyDate);
797 #ifdef OPENAFS_VOL_STATS
798         printf("\tstat_initialized = %d\n", v.stat_initialized);
799 #else
800         printf("\tmtd              = '%s'\n", v.motd);
801 #endif
802         printf("}\n");
803     }
804
805     return 0;
806 }
807
808 static int
809 VolOpQuery(struct cmd_syndesc * as, void * rock)
810 {
811     struct state state;
812     SYNC_PROTO_BUF_DECL(res_buf);
813     SYNC_response res;
814     FSSYNC_VolOp_info vop;
815     int i;
816
817     res.hdr.response_len = sizeof(res.hdr);
818     res.payload.buf = res_buf;
819     res.payload.len = SYNC_PROTO_MAX_LEN;
820
821     common_prolog(as, &state);
822     common_volop_prolog(as, &state);
823
824     do_volop(&state, FSYNC_VOL_QUERY_VOP, &res);
825
826     if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
827         printf("*** file server not compiled with demand attach extensions.\n");
828         printf("*** pending volume operation metadata not available.\n");
829     }
830
831     if (res.hdr.response == SYNC_OK) {
832         memcpy(&vop, res.payload.buf, sizeof(FSSYNC_VolOp_info));
833
834         printf("pending_vol_op = {\n");
835
836         printf("\tcom = {\n");
837         printf("\t\tproto_version  = %u\n", vop.com.proto_version);
838         printf("\t\tprogramType    = %d (%s)\n", 
839                vop.com.programType, program_type_to_string(vop.com.programType));
840         printf("\t\tcommand        = %d (%s)\n", 
841                vop.com.command, command_code_to_string(vop.com.command));
842         printf("\t\treason         = %d (%s)\n", 
843                vop.com.reason, reason_code_to_string(vop.com.reason));
844         printf("\t\tcommand_len    = %u\n", vop.com.command_len);
845         printf("\t\tflags          = 0x%x\n", vop.com.flags);
846         printf("\t}\n");
847
848         printf("\tvop = {\n");
849         printf("\t\tvolume         = %u\n", vop.vop.volume);
850         if (afs_strnlen(vop.vop.partName, sizeof(vop.vop.partName)) <
851             sizeof(vop.vop.partName)) {
852             printf("\t\tpartName       = '%s'\n", vop.vop.partName);
853         } else {
854             printf("\t\tpartName       = (illegal string)\n");
855         }
856         printf("\t}\n");
857
858         printf("}\n");
859     }
860
861     return 0;
862 }
863
864 static int
865 vn_prolog(struct cmd_syndesc * as, struct state * state)
866 {
867     register struct cmd_item *ti;
868     char pname[100], *temp;
869
870     state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
871     assert(state->vop != NULL);
872
873     if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) {  /* -volumeid */
874         state->vop->volume = atoi(ti->data);
875     } else {
876         fprintf(stderr, "required argument -volumeid not given\n");
877     }
878
879     if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) {        /* -vnodeid */
880         state->vop->vnode = atoi(ti->data);
881     } else {
882         fprintf(stderr, "required argument -vnodeid not given\n");
883     }
884
885     if ((ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) {        /* -unique */
886         state->vop->unique = atoi(ti->data);
887     } else {
888         state->vop->unique = 0;
889     }
890
891     if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+3].items)) {  /* -partition */
892         strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
893     } else {
894         memset(state->vop->partName, 0, sizeof(state->vop->partName));
895     }
896
897     return 0;
898 }
899
900 static int
901 do_vnqry(struct state * state, SYNC_response * res)
902 {
903     afs_int32 code;
904     int command = FSYNC_VOL_QUERY_VNODE;
905     FSSYNC_VnQry_hdr qry;
906
907     qry.volume = state->vop->volume;
908     qry.vnode = state->vop->vnode;
909     qry.unique = state->vop->unique;
910     qry.spare = 0;
911     strlcpy(qry.partName, state->vop->partName, sizeof(qry.partName));
912
913     fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n", 
914             command, command_code_to_string(command));
915
916     code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
917
918     switch (code) {
919     case SYNC_OK:
920     case SYNC_DENIED:
921         break;
922     default:
923         fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
924     }
925
926     fprintf(stderr, "FSYNC_GenericOp returned %d (%s)\n", code, response_code_to_string(code));
927     fprintf(stderr, "protocol response code was %d (%s)\n", 
928             res->hdr.response, response_code_to_string(res->hdr.response));
929     fprintf(stderr, "protocol reason code was %d (%s)\n", 
930             res->hdr.reason, reason_code_to_string(res->hdr.reason));
931
932     VDisconnectFS();
933
934     return 0;
935 }
936
937 static int
938 VnQuery(struct cmd_syndesc * as, void * rock)
939 {
940     struct state state;
941     SYNC_PROTO_BUF_DECL(res_buf);
942     SYNC_response res;
943     Vnode v;
944     int hi, lo;
945
946     res.hdr.response_len = sizeof(res.hdr);
947     res.payload.buf = res_buf;
948     res.payload.len = SYNC_PROTO_MAX_LEN;
949
950     common_prolog(as, &state);
951     vn_prolog(as, &state);
952
953     do_vnqry(&state, &res);
954
955     if (res.hdr.response == SYNC_OK) {
956         memcpy(&v, res.payload.buf, sizeof(Volume));
957
958         printf("vnode = {\n");
959
960         printf("\tvid_hash = {\n");
961         printf("\t\tnext = 0x%lx\n", v.vid_hash.next);
962         printf("\t\tprev = 0x%lx\n", v.vid_hash.prev);
963         printf("\t}\n");
964
965         printf("\thashNext        = 0x%lx\n", v.hashNext);
966         printf("\tlruNext         = 0x%lx\n", v.lruNext);
967         printf("\tlruPrev         = 0x%lx\n", v.lruPrev);
968         printf("\thashIndex       = %hu\n", v.hashIndex);
969         printf("\tchanged_newTime = %u\n", (unsigned int) v.changed_newTime);
970         printf("\tchanged_oldTime = %u\n", (unsigned int) v.changed_oldTime);
971         printf("\tdelete          = %u\n", (unsigned int) v.delete);
972         printf("\tvnodeNumber     = %u\n", v.vnodeNumber);
973         printf("\tvolumePtr       = 0x%lx\n", v.volumePtr);
974         printf("\tnUsers          = %u\n", v.nUsers);
975         printf("\tcacheCheck      = %u\n", v.cacheCheck);
976
977 #ifdef AFS_DEMAND_ATTACH_FS
978         if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
979             printf("*** fssync-debug built to expect demand attach extensions.  server asserted\n");
980             printf("*** that it was not compiled with demand attach turned on.  please recompile\n");
981             printf("*** fssync-debug to match your server\n");
982             goto done;
983         }
984
985         printf("\tnReaders        = %u\n", v.nReaders);
986         printf("\tvn_state_flags  = %s\n", vn_flags_to_string(v.vn_state_flags));
987         printf("\tvn_state        = %s\n", vn_state_to_string(v.vn_state));
988 #else
989         if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
990             printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
991             printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
992             printf("*** to dump dafs extended state\n");
993             goto done;
994         }
995 #endif /* !AFS_DEMAND_ATTACH_FS */
996
997         printf("\twriter          = %u\n", v.writer);
998         printf("\tvcp             = 0x%lx\n", v.vcp);
999         printf("\thandle          = 0x%lx\n", v.handle);
1000
1001         printf("\tdisk = {\n");
1002         printf("\t\ttype              = %u\n", v.disk.type);
1003         printf("\t\tcloned            = %u\n", v.disk.cloned);
1004         printf("\t\tmodeBits          = %u\n", v.disk.modeBits);
1005         printf("\t\tlinkCount         = %d\n", v.disk.linkCount);
1006         printf("\t\tlength            = %u\n", v.disk.length);
1007         printf("\t\tuniquifier        = %u\n", v.disk.uniquifier);
1008         printf("\t\tdataVersion       = %u\n", v.disk.dataVersion);
1009         printf("\t\tvn_ino_lo         = %u\n", v.disk.vn_ino_lo);
1010         printf("\t\tunixModifyTime    = %u\n", v.disk.unixModifyTime);
1011         printf("\t\tauthor            = %u\n", v.disk.author);
1012         printf("\t\towner             = %u\n", v.disk.owner);
1013         printf("\t\tparent            = %u\n", v.disk.parent);
1014         printf("\t\tvnodeMagic        = %u\n", v.disk.vnodeMagic);
1015
1016         printf("\t\tlock = {\n");
1017         printf("\t\t\tlockCount   = %d\n", v.disk.lock.lockCount);
1018         printf("\t\t\tlockTime    = %d\n", v.disk.lock.lockTime);
1019         printf("\t\t}\n");
1020
1021         printf("\t\tserverModifyTime  = %u\n", v.disk.serverModifyTime);
1022         printf("\t\tgroup             = %d\n", v.disk.group);
1023         printf("\t\tvn_ino_hi         = %d\n", v.disk.vn_ino_hi);
1024         printf("\t\treserved6         = %u\n", v.disk.reserved6);
1025         printf("\t}\n");
1026
1027         printf("}\n");
1028     }
1029
1030  done:
1031     return 0;
1032 }
1033
1034
1035 static int
1036 StatsQuery(struct cmd_syndesc * as, void * rock)
1037 {
1038     afs_int32 code;
1039     int command;
1040     struct cmd_item *ti;
1041     struct state state;
1042     SYNC_PROTO_BUF_DECL(res_buf);
1043     SYNC_response res;
1044     FSSYNC_StatsOp_hdr scom;
1045     union {
1046         void * ptr;
1047         struct VolPkgStats * vol_stats;
1048         struct VolumeHashChainStats * hash_stats;
1049 #ifdef AFS_DEMAND_ATTACH_FS
1050         struct volume_hdr_LRU_stats * hdr_stats;
1051 #endif
1052         struct DiskPartitionStats64 * vicep_stats;
1053     } sres;
1054
1055     sres.ptr = res_buf;
1056     res.hdr.response_len = sizeof(res.hdr);
1057     res.payload.buf = res_buf;
1058     res.payload.len = SYNC_PROTO_MAX_LEN;
1059
1060     if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) {  /* -subcommand */
1061         if (!strcasecmp(ti->data, "vicep")) {
1062             command = FSYNC_VOL_STATS_VICEP;
1063         } else if (!strcasecmp(ti->data, "hash")) {
1064             command = FSYNC_VOL_STATS_HASH;
1065 #ifdef AFS_DEMAND_ATTACH_FS
1066         } else if (!strcasecmp(ti->data, "hdr")) {
1067             command = FSYNC_VOL_STATS_HDR;
1068         } else if (!strcasecmp(ti->data, "vlru")) {
1069             command = FSYNC_VOL_STATS_VLRU;
1070 #endif
1071         } else if (!strcasecmp(ti->data, "pkg")) {
1072             command = FSYNC_VOL_STATS_GENERAL;
1073         } else if (!strcasecmp(ti->data, "help")) {
1074             fprintf(stderr, "fssync-debug stats subcommands:\n");
1075             fprintf(stderr, "\tpkg\tgeneral volume package stats\n");
1076             fprintf(stderr, "\tvicep\tvice partition stats\n");
1077             fprintf(stderr, "\thash\tvolume hash chain stats\n");
1078 #ifdef AFS_DEMAND_ATTACH_FS
1079             fprintf(stderr, "\thdr\tvolume header cache stats\n");
1080             fprintf(stderr, "\tvlru\tvlru generation stats\n");
1081 #endif
1082             exit(0);
1083         } else {
1084             fprintf(stderr, "invalid stats subcommand");
1085             exit(1);
1086         }
1087     } else {
1088         command = FSYNC_VOL_STATS_GENERAL;
1089     }
1090
1091     if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) {        /* -arg1 */
1092         switch (command) {
1093         case FSYNC_VOL_STATS_VICEP:
1094             strlcpy(scom.args.partName, ti->data, sizeof(state.vop->partName));
1095             break;
1096         case FSYNC_VOL_STATS_HASH:
1097             scom.args.hash_bucket = atoi(ti->data);
1098             break;
1099         case FSYNC_VOL_STATS_VLRU:
1100             scom.args.vlru_generation = atoi(ti->data);
1101             break;
1102         default:
1103             fprintf(stderr, "unrecognized arguments\n");
1104             exit(1);
1105         }
1106     } else {
1107         switch (command) {
1108         case FSYNC_VOL_STATS_VICEP:
1109         case FSYNC_VOL_STATS_HASH:
1110         case FSYNC_VOL_STATS_VLRU:
1111             fprintf(stderr, "this subcommand requires more parameters\n");
1112             exit(1);
1113         }
1114     }
1115
1116     common_prolog(as, &state);
1117
1118     fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n", 
1119             command, command_code_to_string(command));
1120
1121     code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
1122
1123     switch (code) {
1124     case SYNC_OK:
1125     case SYNC_DENIED:
1126         break;
1127     default:
1128         fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
1129     }
1130
1131     fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
1132     fprintf(stderr, "protocol response code was %d (%s)\n", 
1133             res.hdr.response, response_code_to_string(res.hdr.response));
1134     fprintf(stderr, "protocol reason code was %d (%s)\n", 
1135             res.hdr.reason, reason_code_to_string(res.hdr.reason));
1136
1137     VDisconnectFS();
1138
1139     if (res.hdr.response == SYNC_OK) {
1140         switch (command) {
1141         case FSYNC_VOL_STATS_GENERAL:
1142             print_vol_stats_general(sres.vol_stats);
1143             break;
1144         case FSYNC_VOL_STATS_VICEP:
1145             print_vol_stats_viceP(sres.vicep_stats);
1146             break;
1147         case FSYNC_VOL_STATS_HASH:
1148             print_vol_stats_hash(sres.hash_stats);
1149             break;
1150 #ifdef AFS_DEMAND_ATTACH_FS
1151         case FSYNC_VOL_STATS_HDR:
1152             print_vol_stats_hdr(sres.hdr_stats);
1153             break;
1154 #endif /* AFS_DEMAND_ATTACH_FS */
1155         }
1156     }
1157
1158     return 0;
1159 }
1160
1161 static void
1162 print_vol_stats_general(VolPkgStats * stats)
1163 {
1164     int i;
1165     afs_uint32 hi, lo;
1166
1167     printf("VolPkgStats = {\n");
1168 #ifdef AFS_DEMAND_ATTACH_FS
1169     for (i = 0; i < VOL_STATE_COUNT; i++) {
1170         printf("\tvol_state_count[%s] = %d\n", 
1171                vol_state_to_string(i),
1172                stats->state_levels[i]);
1173     }
1174
1175     SplitInt64(stats->hash_looks, hi, lo);
1176     printf("\thash_looks = {\n");
1177     printf("\t\thi = %u\n", hi);
1178     printf("\t\tlo = %u\n", lo);
1179     printf("\t}\n");
1180
1181     SplitInt64(stats->hash_reorders, hi, lo);
1182     printf("\thash_reorders = {\n");
1183     printf("\t\thi = %u\n", hi);
1184     printf("\t\tlo = %u\n", lo);
1185     printf("\t}\n");
1186
1187     SplitInt64(stats->salvages, hi, lo);
1188     printf("\tsalvages = {\n");
1189     printf("\t\thi = %u\n", hi);
1190     printf("\t\tlo = %u\n", lo);
1191     printf("\t}\n");
1192
1193     SplitInt64(stats->vol_ops, hi, lo);
1194     printf("\tvol_ops = {\n");
1195     printf("\t\thi = %u\n", hi);
1196     printf("\t\tlo = %u\n", lo);
1197     printf("\t}\n");
1198 #endif
1199     SplitInt64(stats->hdr_loads, hi, lo);
1200     printf("\thdr_loads = {\n");
1201     printf("\t\thi = %u\n", hi);
1202     printf("\t\tlo = %u\n", lo);
1203     printf("\t}\n");
1204
1205     SplitInt64(stats->hdr_gets, hi, lo);
1206     printf("\thdr_gets = {\n");
1207     printf("\t\thi = %u\n", hi);
1208     printf("\t\tlo = %u\n", lo);
1209     printf("\t}\n");
1210
1211     SplitInt64(stats->attaches, hi, lo);
1212     printf("\tattaches = {\n");
1213     printf("\t\thi = %u\n", hi);
1214     printf("\t\tlo = %u\n", lo);
1215     printf("\t}\n");
1216
1217     SplitInt64(stats->soft_detaches, hi, lo);
1218     printf("\tsoft_detaches = {\n");
1219     printf("\t\thi = %u\n", hi);
1220     printf("\t\tlo = %u\n", lo);
1221     printf("\t}\n");
1222
1223     printf("\thdr_cache_size = %d\n", stats->hdr_cache_size);
1224             
1225     printf("}\n");
1226 }
1227
1228 static void
1229 print_vol_stats_viceP(struct DiskPartitionStats64 * stats)
1230 {
1231     printf("DiskPartitionStats64 = {\n");
1232     printf("\tfree = %lld\n", stats->free);
1233     printf("\tminFree = %lld\n", stats->minFree);
1234     printf("\ttotalUsable = %lld\n", stats->totalUsable);
1235     printf("\tf_files = %lld\n", stats->f_files);
1236 #ifdef AFS_DEMAND_ATTACH_FS
1237     printf("\tvol_list_len = %d\n", stats->vol_list_len);
1238 #endif
1239     printf("}\n");
1240 }
1241
1242 static void
1243 print_vol_stats_hash(struct VolumeHashChainStats * stats)
1244 {
1245     afs_uint32 hi, lo;
1246
1247     printf("DiskPartitionStats = {\n");
1248     printf("\ttable_size = %d\n", stats->table_size);
1249     printf("\tchain_len = %d\n", stats->chain_len);
1250
1251 #ifdef AFS_DEMAND_ATTACH_FS
1252     printf("\tchain_cacheCheck = %d\n", stats->chain_cacheCheck);
1253     printf("\tchain_busy = %d\n", stats->chain_busy);
1254
1255     SplitInt64(stats->chain_looks, hi, lo);
1256     printf("\tchain_looks = {\n");
1257     printf("\t\thi = %u\n", hi);
1258     printf("\t\tlo = %u\n", lo);
1259     printf("\t}\n");
1260
1261     SplitInt64(stats->chain_gets, hi, lo);
1262     printf("\tchain_gets = {\n");
1263     printf("\t\thi = %u\n", hi);
1264     printf("\t\tlo = %u\n", lo);
1265     printf("\t}\n");
1266
1267     SplitInt64(stats->chain_reorders, hi, lo);
1268     printf("\tchain_reorders = {\n");
1269     printf("\t\thi = %u\n", hi);
1270     printf("\t\tlo = %u\n", lo);
1271     printf("\t}\n");
1272 #endif /* AFS_DEMAND_ATTACH_FS */
1273
1274     printf("}\n");
1275 }
1276
1277
1278 #ifdef AFS_DEMAND_ATTACH_FS
1279 static void
1280 print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats)
1281 {
1282     printf("volume_hdr_LRU_stats = {\n");
1283     printf("\tfree = %d\n", stats->free);
1284     printf("\tused = %d\n", stats->used);
1285     printf("\tattached = %d\n", stats->attached);
1286     printf("}\n");
1287 }
1288 #endif /* AFS_DEMAND_ATTACH_FS */
1289