Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / vol / fssync-debug.c
blobe974b09b25efe17644bf1cba9abbc05ca65420ae
1 /*
2 * Copyright 2006-2010, Sine Nomine Associates and others.
3 * All Rights Reserved.
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 */
10 /* Main program file. Define globals. */
11 #define MAIN 1
14 * fssync administration tool
18 #include <afsconfig.h>
19 #include <afs/param.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <dirent.h>
26 #include <sys/stat.h>
27 #include <time.h>
28 #include <errno.h>
29 #ifdef AFS_NT40_ENV
30 #include <io.h>
31 #include <WINNT/afsevent.h>
32 #else
33 #include <sys/param.h>
34 #include <sys/file.h>
35 #ifndef ITIMER_REAL
36 #include <sys/time.h>
37 #endif /* ITIMER_REAL */
38 #endif
39 #include <rx/xdr.h>
40 #include <afs/afsint.h>
41 #include <afs/afs_assert.h>
43 #include <fcntl.h>
45 #ifndef AFS_NT40_ENV
46 #include <afs/osi_inode.h>
47 #endif
49 #include <afs/cmd.h>
50 #include <afs/dir.h>
51 #include <afs/afsutil.h>
52 #include <afs/fileutil.h>
54 #include "nfs.h"
55 #include "lwp.h"
56 #include "lock.h"
57 #include "ihandle.h"
58 #include "vnode.h"
59 #include "volume.h"
60 #include "volume_inline.h"
61 #include "partition.h"
62 #include "daemon_com.h"
63 #include "daemon_com_inline.h"
64 #include "fssync.h"
65 #include "fssync_inline.h"
66 #include "vg_cache.h"
67 #ifdef AFS_NT40_ENV
68 #include <pthread.h>
69 #endif
71 int VolumeChanged; /* hack to make dir package happy */
74 struct volop_state {
75 afs_uint32 volume;
76 afs_uint32 vnode;
77 afs_uint32 unique;
78 char partName[16];
81 struct state {
82 afs_int32 reason;
83 struct volop_state * vop;
86 #ifndef AFS_DEMAND_ATTACH_FS
87 /* remember argv/argc for later, if we need to re-exec */
88 static char **fssd_argv;
89 static int fssd_argc;
90 #endif
92 static int common_prolog(struct cmd_syndesc *, struct state *);
93 static int common_volop_prolog(struct cmd_syndesc *, struct state *);
95 static int do_volop(struct state *, afs_int32 command, SYNC_response * res);
97 static int VolOnline(struct cmd_syndesc * as, void * rock);
98 static int VolOffline(struct cmd_syndesc * as, void * rock);
99 static int VolMode(struct cmd_syndesc * as, void * rock);
100 static int VolDetach(struct cmd_syndesc * as, void * rock);
101 static int VolBreakCBKs(struct cmd_syndesc * as, void * rock);
102 static int VolMove(struct cmd_syndesc * as, void * rock);
103 static int VolList(struct cmd_syndesc * as, void * rock);
104 static int VolLeaveOff(struct cmd_syndesc * as, void * rock);
105 static int VolForceAttach(struct cmd_syndesc * as, void * rock);
106 static int VolForceError(struct cmd_syndesc * as, void * rock);
107 static int VolQuery(struct cmd_syndesc * as, void * rock);
108 static int VolHdrQuery(struct cmd_syndesc * as, void * rock);
109 static int VolOpQuery(struct cmd_syndesc * as, void * rock);
110 static int StatsQuery(struct cmd_syndesc * as, void * rock);
111 static int VnQuery(struct cmd_syndesc * as, void * rock);
113 static int VGCQuery(struct cmd_syndesc * as, void * rock);
114 static int VGCAdd(struct cmd_syndesc * as, void * rock);
115 static int VGCDel(struct cmd_syndesc * as, void * rock);
116 static int VGCScan(struct cmd_syndesc * as, void * rock);
117 static int VGCScanAll(struct cmd_syndesc * as, void * rock);
119 static void print_vol_stats_general(VolPkgStats * stats);
120 static void print_vol_stats_viceP(struct DiskPartitionStats64 * stats);
121 static void print_vol_stats_hash(struct VolumeHashChainStats * stats);
122 #ifdef AFS_DEMAND_ATTACH_FS
123 static void print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats);
124 #endif
126 #ifndef AFS_NT40_ENV
127 #include "AFS_component_version_number.c"
128 #endif
129 #define MAX_ARGS 128
131 #define COMMON_PARMS_OFFSET 12
132 #define COMMON_PARMS(ts) \
133 cmd_Seek(ts, COMMON_PARMS_OFFSET); \
134 cmd_AddParm(ts, "-reason", CMD_SINGLE, CMD_OPTIONAL, "sync protocol reason code"); \
135 cmd_AddParm(ts, "-programtype", CMD_SINGLE, CMD_OPTIONAL, "program type code")
137 #define COMMON_VOLOP_PARMS_OFFSET 10
138 #define COMMON_VOLOP_PARMS(ts) \
139 cmd_Seek(ts, COMMON_VOLOP_PARMS_OFFSET); \
140 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id"); \
141 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name")
143 #define CUSTOM_PARMS_OFFSET 1
146 #define VOLOP_PARMS_DECL(ts) \
147 COMMON_VOLOP_PARMS(ts); \
148 COMMON_PARMS(ts)
149 #define COMMON_PARMS_DECL(ts) \
150 COMMON_PARMS(ts)
153 main(int argc, char **argv)
155 struct cmd_syndesc *ts;
156 int err = 0;
158 /* Initialize directory paths */
159 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
160 #ifdef AFS_NT40_ENV
161 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
162 #endif
163 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
164 argv[0]);
165 exit(2);
168 #ifndef AFS_DEMAND_ATTACH_FS
169 fssd_argv = argv;
170 fssd_argc = argc;
171 #endif
173 ts = cmd_CreateSyntax("online", VolOnline, NULL, "bring a volume online (FSYNC_VOL_ON opcode)");
174 VOLOP_PARMS_DECL(ts);
176 ts = cmd_CreateSyntax("offline", VolOffline, NULL, "take a volume offline (FSYNC_VOL_OFF opcode)");
177 VOLOP_PARMS_DECL(ts);
179 ts = cmd_CreateSyntax("mode", VolMode, NULL, "change volume attach mode (FSYNC_VOL_NEEDVOLUME opcode)");
180 VOLOP_PARMS_DECL(ts);
181 cmd_CreateAlias(ts, "needvolume");
183 ts = cmd_CreateSyntax("detach", VolDetach, NULL, "detach a volume (FSYNC_VOL_DONE opcode)");
184 VOLOP_PARMS_DECL(ts);
186 ts = cmd_CreateSyntax("callback", VolBreakCBKs, NULL, "break callbacks for volume (FSYNC_VOL_BREAKCBKS opcode)");
187 VOLOP_PARMS_DECL(ts);
188 cmd_CreateAlias(ts, "cbk");
190 ts = cmd_CreateSyntax("move", VolMove, NULL, "set volume moved flag (FSYNC_VOL_MOVE opcode)");
191 VOLOP_PARMS_DECL(ts);
193 ts = cmd_CreateSyntax("list", VolList, NULL, "sync local volume list (FSYNC_VOL_LISTVOLUMES opcode)");
194 VOLOP_PARMS_DECL(ts);
195 cmd_CreateAlias(ts, "ls");
197 ts = cmd_CreateSyntax("leaveoff", VolLeaveOff, 0, "leave volume offline (FSYNC_VOL_LEAVE_OFF opcode)");
198 VOLOP_PARMS_DECL(ts);
200 ts = cmd_CreateSyntax("attach", VolForceAttach, 0, "force full attachment (FSYNC_VOL_ATTACH opcode)");
201 VOLOP_PARMS_DECL(ts);
203 ts = cmd_CreateSyntax("error", VolForceError, 0, "force into hard error state (FSYNC_VOL_FORCE_ERROR opcode)");
204 VOLOP_PARMS_DECL(ts);
206 ts = cmd_CreateSyntax("query", VolQuery, NULL, "get volume structure (FSYNC_VOL_QUERY opcode)");
207 VOLOP_PARMS_DECL(ts);
208 cmd_CreateAlias(ts, "qry");
210 ts = cmd_CreateSyntax("header", VolHdrQuery, NULL, "get volume disk data structure (FSYNC_VOL_QUERY_HDR opcode)");
211 VOLOP_PARMS_DECL(ts);
212 cmd_CreateAlias(ts, "hdr");
214 ts = cmd_CreateSyntax("volop", VolOpQuery, NULL, "get pending volume operation info (FSYNC_VOL_QUERY_VOP opcode)");
215 VOLOP_PARMS_DECL(ts);
216 cmd_CreateAlias(ts, "vop");
218 ts = cmd_CreateSyntax("vnode", VnQuery, NULL, "get vnode structure (FSYNC_VOL_QUERY_VNODE opcode)");
219 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
220 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
221 cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id");
222 cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier");
223 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
224 COMMON_PARMS_DECL(ts);
226 ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information");
227 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
228 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "subcommand");
229 cmd_AddParm(ts, "-arg1", CMD_SINGLE, CMD_OPTIONAL, "arg1");
230 cmd_AddParm(ts, "-arg2", CMD_SINGLE, CMD_OPTIONAL, "arg2");
231 COMMON_PARMS_DECL(ts);
233 ts = cmd_CreateSyntax("vgcquery", VGCQuery, 0, "query volume group cache (FSYNC_VG_QUERY opcode)");
234 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
235 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
236 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
237 COMMON_PARMS_DECL(ts);
238 cmd_CreateAlias(ts, "vgcqry");
240 ts = cmd_CreateSyntax("vgcadd", VGCAdd, 0, "add entry to volume group cache (FSYNC_VG_ADD opcode)");
241 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
242 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
243 cmd_AddParm(ts, "-parent", CMD_SINGLE, 0, "parent volume id");
244 cmd_AddParm(ts, "-child", CMD_SINGLE, 0, "child volume id");
245 COMMON_PARMS_DECL(ts);
247 ts = cmd_CreateSyntax("vgcdel", VGCDel, 0, "delete entry from volume group cache (FSYNC_VG_DEL opcode)");
248 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
249 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
250 cmd_AddParm(ts, "-parent", CMD_SINGLE, 0, "parent volume id");
251 cmd_AddParm(ts, "-child", CMD_SINGLE, 0, "child volume id");
252 COMMON_PARMS_DECL(ts);
254 ts = cmd_CreateSyntax("vgcscan", VGCScan, 0,
255 "start volume group cache re-scan"
256 " (FSYNC_VG_SCAN opcode)");
257 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
258 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
259 COMMON_PARMS_DECL(ts);
261 ts = cmd_CreateSyntax("vgcscanall", VGCScanAll, 0,
262 "start whole-server volume group cache re-scan"
263 " (FSYNC_VG_SCAN_ALL opcode)");
264 COMMON_PARMS_DECL(ts);
266 err = cmd_Dispatch(argc, argv);
267 exit(err);
270 #ifdef AFS_DEMAND_ATTACH_FS
271 # define dafs_prolog()
272 #else
273 /* Try to detect if the fileserver is DAFS, and if so, re-exec as the
274 * DAFS-enabled fssync-debug (dafssync_debug). If we fail to detect or
275 * exec, just try to proceed anyway as if the server is not DAFS */
276 static void
277 dafs_prolog(void)
279 SYNC_response res;
280 SYNC_PROTO_BUF_DECL(res_buf);
281 afs_int32 code;
282 char *dfssd;
284 res.payload.len = SYNC_PROTO_MAX_LEN;
285 res.payload.buf = res_buf;
287 /* LISTVOLUMES is a no-op; we just want to get the response header flags
288 * to see if the server reports itself as DAFS or not */
289 code = FSYNC_VolOp(0, NULL, FSYNC_VOL_LISTVOLUMES, FSYNC_WHATEVER, &res);
290 if (code) {
291 /* probably failed to contact the fileserver; later code will provide
292 * some warning/error indication */
293 return;
296 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
297 /* fileserver is not DAFS, so we don't need to do anything */
298 return;
301 dfssd = afs_exec_alt(fssd_argc, fssd_argv, "da", NULL);
303 fprintf(stderr, "\n*** server asserted demand attach extensions, but we failed\n"
304 "*** to exec a DAFS-enabled fssync-debug '%s' (errno=%d);\n"
305 "*** attempting to proceed without it.\n\n", dfssd, errno);
307 free(dfssd);
309 #endif /* !AFS_DEMAND_ATTACH_FS */
311 static int
312 common_prolog(struct cmd_syndesc * as, struct state * state)
314 struct cmd_item *ti;
315 VolumePackageOptions opts;
317 #ifdef AFS_NT40_ENV
318 if (afs_winsockInit() < 0) {
319 Exit(1);
321 #endif
323 VOptDefaults(debugUtility, &opts);
324 if (VInitVolumePackage2(debugUtility, &opts)) {
325 /* VInitVolumePackage2 can fail on e.g. partition attachment errors,
326 * but we don't really care, since all we're doing is trying to use
327 * FSSYNC */
328 fprintf(stderr, "errors encountered initializing volume package, but "
329 "trying to continue anyway\n");
331 DInit(1);
333 if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) { /* -reason */
334 state->reason = atoi(ti->data);
335 } else {
336 state->reason = FSYNC_WHATEVER;
339 if ((ti = as->parms[COMMON_PARMS_OFFSET+1].items)) { /* -programtype */
340 if (!strcmp(ti->data, "fileServer")) {
341 programType = fileServer;
342 } else if (!strcmp(ti->data, "volumeUtility")) {
343 programType = volumeUtility;
344 } else if (!strcmp(ti->data, "salvager")) {
345 programType = salvager;
346 } else if (!strcmp(ti->data, "salvageServer")) {
347 programType = salvageServer;
348 } else if (!strcmp(ti->data, "volumeServer")) {
349 programType = volumeServer;
350 } else if (!strcmp(ti->data, "volumeSalvager")) {
351 programType = volumeSalvager;
352 } else {
353 programType = (ProgramType) atoi(ti->data);
357 VConnectFS();
359 return 0;
362 static int
363 common_volop_prolog(struct cmd_syndesc * as, struct state * state)
365 struct cmd_item *ti;
367 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
368 osi_Assert(state->vop != NULL);
370 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET].items)) { /* -volumeid */
371 state->vop->volume = atoi(ti->data);
372 } else {
373 fprintf(stderr, "required argument -volumeid not given\n");
376 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+1].items)) { /* -partition */
377 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
378 } else {
379 memset(state->vop->partName, 0, sizeof(state->vop->partName));
382 return 0;
385 static int
386 debug_response(afs_int32 code, SYNC_response * res)
388 switch (code) {
389 case SYNC_OK:
390 case SYNC_DENIED:
391 break;
392 default:
393 fprintf(stderr, "warning: response code indicates possible protocol error.\n");
396 fprintf(stderr, "FSSYNC service returned %d (%s)\n", code, SYNC_res2string(code));
398 if (res) {
399 fprintf(stderr, "protocol header response code was %d (%s)\n",
400 res->hdr.response, SYNC_res2string(res->hdr.response));
401 fprintf(stderr, "protocol reason code was %d (%s)\n",
402 res->hdr.reason, FSYNC_reason2string(res->hdr.reason));
405 return 0;
408 static int
409 do_volop(struct state * state, afs_int32 command, SYNC_response * res)
411 afs_int32 code;
412 SYNC_PROTO_BUF_DECL(res_buf);
413 SYNC_response res_l;
415 if (!res) {
416 res = &res_l;
417 res->payload.len = SYNC_PROTO_MAX_LEN;
418 res->payload.buf = res_buf;
421 fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n",
422 command, FSYNC_com2string(command));
424 code = FSYNC_VolOp(state->vop->volume,
425 state->vop->partName,
426 command,
427 state->reason,
428 res);
430 debug_response(code, res);
432 VDisconnectFS();
434 return 0;
439 #define ENUMTOSTRING(en) #en
440 #define ENUMCASE(en) \
441 case en: return ENUMTOSTRING(en)
443 #define FLAGTOSTRING(fl) #fl
444 #define FLAGCASE(bitstr, fl, str, count) \
445 do { \
446 if ((bitstr) & (fl)) { \
447 if (count) \
448 strlcat((str), " | ", sizeof(str)); \
449 strlcat((str), FLAGTOSTRING(fl), sizeof(str)); \
450 (count)++; \
452 } while (0)
454 static int
455 VolOnline(struct cmd_syndesc * as, void * rock)
457 struct state state;
459 common_prolog(as, &state);
460 common_volop_prolog(as, &state);
462 if (*(state.vop->partName)==0) {
463 fprintf(stderr, "required argument -partition not given\n");
464 return -1;
466 do_volop(&state, FSYNC_VOL_ON, NULL);
468 return 0;
471 static int
472 VolOffline(struct cmd_syndesc * as, void * rock)
474 struct state state;
476 common_prolog(as, &state);
477 common_volop_prolog(as, &state);
479 do_volop(&state, FSYNC_VOL_OFF, NULL);
481 return 0;
484 static int
485 VolMode(struct cmd_syndesc * as, void * rock)
487 struct state state;
489 common_prolog(as, &state);
490 common_volop_prolog(as, &state);
492 do_volop(&state, FSYNC_VOL_NEEDVOLUME, NULL);
494 return 0;
497 static int
498 VolDetach(struct cmd_syndesc * as, void * rock)
500 struct state state;
502 common_prolog(as, &state);
503 common_volop_prolog(as, &state);
505 do_volop(&state, FSYNC_VOL_DONE, NULL);
507 return 0;
510 static int
511 VolBreakCBKs(struct cmd_syndesc * as, void * rock)
513 struct state state;
515 common_prolog(as, &state);
516 common_volop_prolog(as, &state);
518 do_volop(&state, FSYNC_VOL_BREAKCBKS, NULL);
520 return 0;
523 static int
524 VolMove(struct cmd_syndesc * as, void * rock)
526 struct state state;
528 common_prolog(as, &state);
529 common_volop_prolog(as, &state);
531 do_volop(&state, FSYNC_VOL_MOVE, NULL);
533 return 0;
536 static int
537 VolList(struct cmd_syndesc * as, void * rock)
539 struct state state;
541 common_prolog(as, &state);
542 common_volop_prolog(as, &state);
544 do_volop(&state, FSYNC_VOL_LISTVOLUMES, NULL);
546 return 0;
549 static int
550 VolLeaveOff(struct cmd_syndesc * as, void * rock)
552 struct state state;
554 common_prolog(as, &state);
555 common_volop_prolog(as, &state);
557 do_volop(&state, FSYNC_VOL_LEAVE_OFF, NULL);
559 return 0;
562 static int
563 VolForceAttach(struct cmd_syndesc * as, void * rock)
565 struct state state;
567 common_prolog(as, &state);
568 common_volop_prolog(as, &state);
570 do_volop(&state, FSYNC_VOL_ATTACH, NULL);
572 return 0;
575 static int
576 VolForceError(struct cmd_syndesc * as, void * rock)
578 struct state state;
580 common_prolog(as, &state);
581 common_volop_prolog(as, &state);
583 do_volop(&state, FSYNC_VOL_FORCE_ERROR, NULL);
585 return 0;
588 #ifdef AFS_DEMAND_ATTACH_FS
589 static char *
590 vol_state_to_string(VolState state)
592 switch (state) {
593 ENUMCASE(VOL_STATE_UNATTACHED);
594 ENUMCASE(VOL_STATE_PREATTACHED);
595 ENUMCASE(VOL_STATE_ATTACHING);
596 ENUMCASE(VOL_STATE_ATTACHED);
597 ENUMCASE(VOL_STATE_UPDATING);
598 ENUMCASE(VOL_STATE_GET_BITMAP);
599 ENUMCASE(VOL_STATE_HDR_LOADING);
600 ENUMCASE(VOL_STATE_HDR_ATTACHING);
601 ENUMCASE(VOL_STATE_SHUTTING_DOWN);
602 ENUMCASE(VOL_STATE_GOING_OFFLINE);
603 ENUMCASE(VOL_STATE_OFFLINING);
604 ENUMCASE(VOL_STATE_DETACHING);
605 ENUMCASE(VOL_STATE_SALVSYNC_REQ);
606 ENUMCASE(VOL_STATE_SALVAGING);
607 ENUMCASE(VOL_STATE_ERROR);
608 ENUMCASE(VOL_STATE_VNODE_ALLOC);
609 ENUMCASE(VOL_STATE_VNODE_GET);
610 ENUMCASE(VOL_STATE_VNODE_CLOSE);
611 ENUMCASE(VOL_STATE_VNODE_RELEASE);
612 ENUMCASE(VOL_STATE_VLRU_ADD);
613 ENUMCASE(VOL_STATE_DELETED);
614 ENUMCASE(VOL_STATE_SALVAGE_REQ);
615 ENUMCASE(VOL_STATE_FREED);
616 default:
617 return "**UNKNOWN**";
621 static char *
622 vol_flags_to_string(afs_uint16 flags)
624 static char str[256];
625 int count = 0;
626 str[0]='\0';
628 FLAGCASE(flags, VOL_HDR_ATTACHED, str, count);
629 FLAGCASE(flags, VOL_HDR_LOADED, str, count);
630 FLAGCASE(flags, VOL_HDR_IN_LRU, str, count);
631 FLAGCASE(flags, VOL_IN_HASH, str, count);
632 FLAGCASE(flags, VOL_ON_VBYP_LIST, str, count);
633 FLAGCASE(flags, VOL_IS_BUSY, str, count);
634 FLAGCASE(flags, VOL_ON_VLRU, str, count);
635 FLAGCASE(flags, VOL_HDR_DONTSALV, str, count);
636 FLAGCASE(flags, VOL_LOCKED, str, count);
638 return str;
641 static char *
642 vlru_idx_to_string(int idx)
644 switch (idx) {
645 ENUMCASE(VLRU_QUEUE_NEW);
646 ENUMCASE(VLRU_QUEUE_MID);
647 ENUMCASE(VLRU_QUEUE_OLD);
648 ENUMCASE(VLRU_QUEUE_CANDIDATE);
649 ENUMCASE(VLRU_QUEUE_HELD);
650 ENUMCASE(VLRU_QUEUE_INVALID);
651 default:
652 return "**UNKNOWN**";
657 static char *
658 vn_state_to_string(VnState state)
660 switch (state) {
661 ENUMCASE(VN_STATE_INVALID);
662 ENUMCASE(VN_STATE_RELEASING);
663 ENUMCASE(VN_STATE_CLOSING);
664 ENUMCASE(VN_STATE_ALLOC);
665 ENUMCASE(VN_STATE_ONLINE);
666 ENUMCASE(VN_STATE_LOAD);
667 ENUMCASE(VN_STATE_EXCLUSIVE);
668 ENUMCASE(VN_STATE_STORE);
669 ENUMCASE(VN_STATE_READ);
670 ENUMCASE(VN_STATE_ERROR);
671 default:
672 return "**UNKNOWN**";
676 static char *
677 vn_flags_to_string(afs_uint32 flags)
679 static char str[128];
680 int count = 0;
681 str[0]='\0';
683 FLAGCASE(flags, VN_ON_HASH, str, count);
684 FLAGCASE(flags, VN_ON_LRU, str, count);
685 FLAGCASE(flags, VN_ON_VVN, str, count);
687 return str;
689 #endif
691 static int
692 VolQuery(struct cmd_syndesc * as, void * rock)
694 struct state state;
695 SYNC_PROTO_BUF_DECL(res_buf);
696 SYNC_response res;
697 Volume v;
698 #ifdef AFS_DEMAND_ATTACH_FS
699 int hi, lo;
700 #endif
702 dafs_prolog();
704 res.hdr.response_len = sizeof(res.hdr);
705 res.payload.buf = res_buf;
706 res.payload.len = SYNC_PROTO_MAX_LEN;
708 common_prolog(as, &state);
709 common_volop_prolog(as, &state);
711 do_volop(&state, FSYNC_VOL_QUERY, &res);
713 if (res.hdr.response == SYNC_OK) {
714 memcpy(&v, res.payload.buf, sizeof(Volume));
716 printf("volume = {\n");
717 printf("\thashid = %u\n", v.hashid);
718 printf("\theader = %p\n", v.header);
719 printf("\tdevice = %d\n", v.device);
720 printf("\tpartition = %p\n", v.partition);
721 printf("\tlinkHandle = %p\n", v.linkHandle);
722 printf("\tnextVnodeUnique = %u\n", v.nextVnodeUnique);
723 printf("\tdiskDataHandle = %p\n", v.diskDataHandle);
724 printf("\tvnodeHashOffset = %u\n", v.vnodeHashOffset);
725 printf("\tshuttingDown = %d\n", v.shuttingDown);
726 printf("\tgoingOffline = %d\n", v.goingOffline);
727 printf("\tcacheCheck = %u\n", v.cacheCheck);
728 printf("\tnUsers = %d\n", v.nUsers);
729 printf("\tneedsPutBack = %d\n", v.needsPutBack);
730 printf("\tspecialStatus = %d\n", v.specialStatus);
731 printf("\tupdateTime = %u\n", v.updateTime);
733 printf("\tvnodeIndex[vSmall] = {\n");
734 printf("\t\thandle = %p\n", v.vnodeIndex[vSmall].handle);
735 printf("\t\tbitmap = %p\n", v.vnodeIndex[vSmall].bitmap);
736 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vSmall].bitmapSize);
737 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vSmall].bitmapOffset);
738 printf("\t}\n");
739 printf("\tvnodeIndex[vLarge] = {\n");
740 printf("\t\thandle = %p\n", v.vnodeIndex[vLarge].handle);
741 printf("\t\tbitmap = %p\n", v.vnodeIndex[vLarge].bitmap);
742 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vLarge].bitmapSize);
743 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vLarge].bitmapOffset);
744 printf("\t}\n");
745 #ifdef AFS_DEMAND_ATTACH_FS
746 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
747 printf("\tupdateTime = %u\n", v.updateTime);
748 printf("\tattach_state = %s\n", vol_state_to_string(v.attach_state));
749 printf("\tattach_flags = %s\n", vol_flags_to_string(v.attach_flags));
750 printf("\tnWaiters = %d\n", v.nWaiters);
751 printf("\tchainCacheCheck = %d\n", v.chainCacheCheck);
753 /* online salvage structure */
754 printf("\tsalvage = {\n");
755 printf("\t\tprio = %u\n", v.salvage.prio);
756 printf("\t\treason = %d\n", v.salvage.reason);
757 printf("\t\trequested = %d\n", v.salvage.requested);
758 printf("\t\tscheduled = %d\n", v.salvage.scheduled);
759 printf("\t}\n");
761 /* statistics structure */
762 printf("\tstats = {\n");
764 printf("\t\thash_lookups = {\n");
765 SplitInt64(v.stats.hash_lookups,hi,lo);
766 printf("\t\t\thi = %u\n", hi);
767 printf("\t\t\tlo = %u\n", lo);
768 printf("\t\t}\n");
770 printf("\t\thash_short_circuits = {\n");
771 SplitInt64(v.stats.hash_short_circuits,hi,lo);
772 printf("\t\t\thi = %u\n", hi);
773 printf("\t\t\tlo = %u\n", lo);
774 printf("\t\t}\n");
776 printf("\t\thdr_loads = {\n");
777 SplitInt64(v.stats.hdr_loads,hi,lo);
778 printf("\t\t\thi = %u\n", hi);
779 printf("\t\t\tlo = %u\n", lo);
780 printf("\t\t}\n");
782 printf("\t\thdr_gets = {\n");
783 SplitInt64(v.stats.hdr_gets,hi,lo);
784 printf("\t\t\thi = %u\n", hi);
785 printf("\t\t\tlo = %u\n", lo);
786 printf("\t\t}\n");
788 printf("\t\tattaches = %u\n", v.stats.attaches);
789 printf("\t\tsoft_detaches = %u\n", v.stats.soft_detaches);
790 printf("\t\tsalvages = %u\n", v.stats.salvages);
791 printf("\t\tvol_ops = %u\n", v.stats.vol_ops);
793 printf("\t\tlast_attach = %u\n", v.stats.last_attach);
794 printf("\t\tlast_get = %u\n", v.stats.last_get);
795 printf("\t\tlast_promote = %u\n", v.stats.last_promote);
796 printf("\t\tlast_hdr_get = %u\n", v.stats.last_hdr_get);
797 printf("\t\tlast_hdr_load = %u\n", v.stats.last_hdr_load);
798 printf("\t\tlast_salvage = %u\n", v.stats.last_salvage);
799 printf("\t\tlast_salvage_req = %u\n", v.stats.last_salvage_req);
800 printf("\t\tlast_vol_op = %u\n", v.stats.last_vol_op);
801 printf("\t}\n");
803 /* VLRU state */
804 printf("\tvlru = {\n");
805 printf("\t\tidx = %d (%s)\n",
806 v.vlru.idx, vlru_idx_to_string(v.vlru.idx));
807 printf("\t}\n");
809 /* volume op state */
810 printf("\tpending_vol_op = %p\n", v.pending_vol_op);
812 #else /* !AFS_DEMAND_ATTACH_FS */
813 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
814 printf("*** server asserted demand attach extensions. this fssync-debug\n"
815 "*** is not built to recognize those extensions. please use an\n"
816 "*** fssync-debug with demand attach if you need to dump dafs\n"
817 "*** extended state.\n");
819 #endif /* !AFS_DEMAND_ATTACH_FS */
820 printf("}\n");
823 return 0;
826 static int
827 VolHdrQuery(struct cmd_syndesc * as, void * rock)
829 struct state state;
830 SYNC_PROTO_BUF_DECL(res_buf);
831 SYNC_response res;
832 VolumeDiskData v;
833 int i;
835 res.hdr.response_len = sizeof(res.hdr);
836 res.payload.buf = res_buf;
837 res.payload.len = SYNC_PROTO_MAX_LEN;
839 common_prolog(as, &state);
840 common_volop_prolog(as, &state);
842 do_volop(&state, FSYNC_VOL_QUERY_HDR, &res);
844 if (res.hdr.response == SYNC_OK) {
845 memcpy(&v, res.payload.buf, sizeof(VolumeDiskData));
847 printf("VolumeDiskData = {\n");
848 printf("\tstamp = {\n");
849 printf("\t\tmagic = 0x%x\n", v.stamp.magic);
850 printf("\t\tversion = %u\n", v.stamp.version);
851 printf("\t}\n");
853 printf("\tid = %u\n", v.id);
854 printf("\tname = '%s'\n", v.name);
855 if (v.inUse != 0) {
856 printf("\tinUse = %d (%s)\n", v.inUse, VPTypeToString(v.inUse));
857 } else {
858 printf("\tinUse = %d (no)\n", v.inUse);
860 printf("\tinService = %d\n", v.inService);
861 printf("\tblessed = %d\n", v.blessed);
862 printf("\tneedsSalvaged = %d\n", v.needsSalvaged);
863 printf("\tuniquifier = %u\n", v.uniquifier);
864 printf("\ttype = %d\n", v.type);
865 printf("\tparentId = %u\n", v.parentId);
866 printf("\tcloneId = %u\n", v.cloneId);
867 printf("\tbackupId = %u\n", v.backupId);
868 printf("\trestoredFromId = %u\n", v.restoredFromId);
869 printf("\tneedsCallback = %d\n", v.needsCallback);
870 printf("\tdestroyMe = %d\n", v.destroyMe);
871 printf("\tdontSalvage = %d\n", v.dontSalvage);
872 printf("\tmaxquota = %d\n", v.maxquota);
873 printf("\tminquota = %d\n", v.minquota);
874 printf("\tmaxfiles = %d\n", v.maxfiles);
875 printf("\taccountNumber = %u\n", v.accountNumber);
876 printf("\towner = %u\n", v.owner);
877 printf("\tfilecount = %d\n", v.filecount);
878 printf("\tdiskused = %d\n", v.diskused);
879 printf("\tdayUse = %d\n", v.dayUse);
880 for (i = 0; i < 7; i++) {
881 printf("\tweekUse[%d] = %d\n", i, v.weekUse[i]);
883 printf("\tdayUseDate = %u\n", v.dayUseDate);
884 printf("\tcreationDate = %u\n", v.creationDate);
885 printf("\taccessDate = %u\n", v.accessDate);
886 printf("\tupdateDate = %u\n", v.updateDate);
887 printf("\texpirationDate = %u\n", v.expirationDate);
888 printf("\tbackupDate = %u\n", v.backupDate);
889 printf("\tcopyDate = %u\n", v.copyDate);
890 #ifdef OPENAFS_VOL_STATS
891 printf("\tstat_initialized = %d\n", v.stat_initialized);
892 #else
893 printf("\tmtd = '%s'\n", v.motd);
894 #endif
895 printf("}\n");
898 return 0;
901 static int
902 VolOpQuery(struct cmd_syndesc * as, void * rock)
904 struct state state;
905 SYNC_PROTO_BUF_DECL(res_buf);
906 SYNC_response res;
907 FSSYNC_VolOp_info vop;
909 res.hdr.response_len = sizeof(res.hdr);
910 res.payload.buf = res_buf;
911 res.payload.len = SYNC_PROTO_MAX_LEN;
913 common_prolog(as, &state);
914 common_volop_prolog(as, &state);
916 do_volop(&state, FSYNC_VOL_QUERY_VOP, &res);
918 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
919 printf("*** file server not compiled with demand attach extensions.\n");
920 printf("*** pending volume operation metadata not available.\n");
923 if (res.hdr.response == SYNC_OK) {
924 memcpy(&vop, res.payload.buf, sizeof(FSSYNC_VolOp_info));
926 printf("pending_vol_op = {\n");
928 printf("\tcom = {\n");
929 printf("\t\tproto_version = %u\n", vop.com.proto_version);
930 printf("\t\tpkt_seq = %u\n", vop.com.pkt_seq);
931 printf("\t\tcom_seq = %u\n", vop.com.com_seq);
932 printf("\t\tprogramType = %d (%s)\n",
933 vop.com.programType, VPTypeToString(vop.com.programType));
934 printf("\t\tpid = %d\n", vop.com.pid);
935 printf("\t\ttid = %d\n", vop.com.tid);
936 printf("\t\tcommand = %d (%s)\n",
937 vop.com.command, FSYNC_com2string(vop.com.command));
938 printf("\t\treason = %d (%s)\n",
939 vop.com.reason, FSYNC_reason2string(vop.com.reason));
940 printf("\t\tcommand_len = %u\n", vop.com.command_len);
941 printf("\t\tflags = 0x%lux\n", afs_printable_uint32_lu(vop.com.flags));
942 printf("\t}\n");
944 printf("\tvop = {\n");
945 printf("\t\tvolume = %u\n", vop.vop.volume);
946 if (afs_strnlen(vop.vop.partName, sizeof(vop.vop.partName)) <
947 sizeof(vop.vop.partName)) {
948 printf("\t\tpartName = '%s'\n", vop.vop.partName);
949 } else {
950 printf("\t\tpartName = (illegal string)\n");
952 printf("\t}\n");
954 printf("}\n");
957 return 0;
960 static int
961 vn_prolog(struct cmd_syndesc * as, struct state * state)
963 struct cmd_item *ti;
965 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
966 osi_Assert(state->vop != NULL);
968 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -volumeid */
969 state->vop->volume = atoi(ti->data);
970 } else {
971 fprintf(stderr, "required argument -volumeid not given\n");
974 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -vnodeid */
975 state->vop->vnode = atoi(ti->data);
976 } else {
977 fprintf(stderr, "required argument -vnodeid not given\n");
980 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -unique */
981 state->vop->unique = atoi(ti->data);
982 } else {
983 state->vop->unique = 0;
986 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+3].items)) { /* -partition */
987 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
988 } else {
989 memset(state->vop->partName, 0, sizeof(state->vop->partName));
992 return 0;
995 static int
996 do_vnqry(struct state * state, SYNC_response * res)
998 afs_int32 code;
999 int command = FSYNC_VOL_QUERY_VNODE;
1000 FSSYNC_VnQry_hdr qry;
1002 qry.volume = state->vop->volume;
1003 qry.vnode = state->vop->vnode;
1004 qry.unique = state->vop->unique;
1005 qry.spare = 0;
1006 strlcpy(qry.partName, state->vop->partName, sizeof(qry.partName));
1008 fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n",
1009 command, FSYNC_com2string(command));
1011 code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
1013 debug_response(code, res);
1015 VDisconnectFS();
1017 return 0;
1020 static int
1021 VnQuery(struct cmd_syndesc * as, void * rock)
1023 struct state state;
1024 SYNC_PROTO_BUF_DECL(res_buf);
1025 SYNC_response res;
1026 Vnode v;
1028 dafs_prolog();
1030 res.hdr.response_len = sizeof(res.hdr);
1031 res.payload.buf = res_buf;
1032 res.payload.len = SYNC_PROTO_MAX_LEN;
1034 common_prolog(as, &state);
1035 vn_prolog(as, &state);
1037 do_vnqry(&state, &res);
1039 if (res.hdr.response == SYNC_OK) {
1040 memcpy(&v, res.payload.buf, sizeof(Vnode));
1042 printf("vnode = {\n");
1044 printf("\tvid_hash = {\n");
1045 printf("\t\tnext = %p\n", v.vid_hash.next);
1046 printf("\t\tprev = %p\n", v.vid_hash.prev);
1047 printf("\t}\n");
1049 printf("\thashNext = %p\n", v.hashNext);
1050 printf("\tlruNext = %p\n", v.lruNext);
1051 printf("\tlruPrev = %p\n", v.lruPrev);
1052 printf("\thashIndex = %hu\n", v.hashIndex);
1053 printf("\tchanged_newTime = %u\n", (unsigned int) v.changed_newTime);
1054 printf("\tchanged_oldTime = %u\n", (unsigned int) v.changed_oldTime);
1055 printf("\tdelete = %u\n", (unsigned int) v.delete);
1056 printf("\tvnodeNumber = %u\n", v.vnodeNumber);
1057 printf("\tvolumePtr = %p\n", v.volumePtr);
1058 printf("\tnUsers = %u\n", v.nUsers);
1059 printf("\tcacheCheck = %u\n", v.cacheCheck);
1061 #ifdef AFS_DEMAND_ATTACH_FS
1062 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
1063 printf("*** this fssync-debug is built to expect demand attach extensions.\n"
1064 "*** server asserted that is was not compiled with demand attach.\n"
1065 "*** please use an fssync-debug without demand attach to match your\n"
1066 "*** server.\n");
1067 goto done;
1070 printf("\tnReaders = %u\n", v.nReaders);
1071 printf("\tvn_state_flags = %s\n", vn_flags_to_string(v.vn_state_flags));
1072 printf("\tvn_state = %s\n", vn_state_to_string(v.vn_state));
1073 #else
1074 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
1075 printf("*** server asserted demand attach extensions. this fssync-debug is not\n"
1076 "*** built to recognize those extensions. please use an fssync-debug\n"
1077 "*** with demand attach to match your server.\n");
1078 goto done;
1080 #endif /* !AFS_DEMAND_ATTACH_FS */
1082 printf("\tvcp = %p\n", v.vcp);
1083 printf("\thandle = %p\n", v.handle);
1085 printf("\tdisk = {\n");
1086 printf("\t\ttype = %u\n", v.disk.type);
1087 printf("\t\tcloned = %u\n", v.disk.cloned);
1088 printf("\t\tmodeBits = %u\n", v.disk.modeBits);
1089 printf("\t\tlinkCount = %d\n", v.disk.linkCount);
1090 printf("\t\tlength = %u\n", v.disk.length);
1091 printf("\t\tuniquifier = %u\n", v.disk.uniquifier);
1092 printf("\t\tdataVersion = %u\n", v.disk.dataVersion);
1093 printf("\t\tvn_ino_lo = %u\n", v.disk.vn_ino_lo);
1094 printf("\t\tunixModifyTime = %u\n", v.disk.unixModifyTime);
1095 printf("\t\tauthor = %u\n", v.disk.author);
1096 printf("\t\towner = %u\n", v.disk.owner);
1097 printf("\t\tparent = %u\n", v.disk.parent);
1098 printf("\t\tvnodeMagic = %u\n", v.disk.vnodeMagic);
1100 printf("\t\tlock = {\n");
1101 printf("\t\t\tlockCount = %d\n", v.disk.lock.lockCount);
1102 printf("\t\t\tlockTime = %d\n", v.disk.lock.lockTime);
1103 printf("\t\t}\n");
1105 printf("\t\tserverModifyTime = %u\n", v.disk.serverModifyTime);
1106 printf("\t\tgroup = %d\n", v.disk.group);
1107 printf("\t\tvn_ino_hi = %d\n", v.disk.vn_ino_hi);
1108 printf("\t\tvn_length_hi = %u\n", v.disk.vn_length_hi);
1109 printf("\t}\n");
1111 printf("}\n");
1114 done:
1115 return 0;
1119 static int
1120 StatsQuery(struct cmd_syndesc * as, void * rock)
1122 afs_int32 code;
1123 int command;
1124 struct cmd_item *ti;
1125 struct state state;
1126 SYNC_PROTO_BUF_DECL(res_buf);
1127 SYNC_response res;
1128 FSSYNC_StatsOp_hdr scom;
1130 res.hdr.response_len = sizeof(res.hdr);
1131 res.payload.buf = res_buf;
1132 res.payload.len = SYNC_PROTO_MAX_LEN;
1134 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -subcommand */
1135 if (!strcasecmp(ti->data, "vicep")) {
1136 command = FSYNC_VOL_STATS_VICEP;
1137 } else if (!strcasecmp(ti->data, "hash")) {
1138 command = FSYNC_VOL_STATS_HASH;
1139 #ifdef AFS_DEMAND_ATTACH_FS
1140 } else if (!strcasecmp(ti->data, "hdr")) {
1141 command = FSYNC_VOL_STATS_HDR;
1142 } else if (!strcasecmp(ti->data, "vlru")) {
1143 command = FSYNC_VOL_STATS_VLRU;
1144 #endif
1145 } else if (!strcasecmp(ti->data, "pkg")) {
1146 command = FSYNC_VOL_STATS_GENERAL;
1147 } else if (!strcasecmp(ti->data, "help")) {
1148 fprintf(stderr, "fssync-debug stats subcommands:\n");
1149 fprintf(stderr, "\tpkg\tgeneral volume package stats\n");
1150 fprintf(stderr, "\tvicep\tvice partition stats\n");
1151 fprintf(stderr, "\thash\tvolume hash chain stats\n");
1152 #ifdef AFS_DEMAND_ATTACH_FS
1153 fprintf(stderr, "\thdr\tvolume header cache stats\n");
1154 fprintf(stderr, "\tvlru\tvlru generation stats\n");
1155 #endif
1156 exit(0);
1157 } else {
1158 fprintf(stderr, "invalid stats subcommand");
1159 exit(1);
1161 } else {
1162 command = FSYNC_VOL_STATS_GENERAL;
1165 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -arg1 */
1166 switch (command) {
1167 case FSYNC_VOL_STATS_VICEP:
1168 strlcpy(scom.args.partName, ti->data, sizeof(state.vop->partName));
1169 break;
1170 case FSYNC_VOL_STATS_HASH:
1171 scom.args.hash_bucket = atoi(ti->data);
1172 break;
1173 case FSYNC_VOL_STATS_VLRU:
1174 scom.args.vlru_generation = atoi(ti->data);
1175 break;
1176 default:
1177 fprintf(stderr, "unrecognized arguments\n");
1178 exit(1);
1180 } else {
1181 switch (command) {
1182 case FSYNC_VOL_STATS_VICEP:
1183 case FSYNC_VOL_STATS_HASH:
1184 case FSYNC_VOL_STATS_VLRU:
1185 fprintf(stderr, "this subcommand requires more parameters\n");
1186 exit(1);
1190 common_prolog(as, &state);
1192 fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
1193 command, FSYNC_com2string(command));
1195 code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
1197 switch (code) {
1198 case SYNC_OK:
1199 case SYNC_DENIED:
1200 break;
1201 default:
1202 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
1205 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, SYNC_res2string(code));
1206 fprintf(stderr, "protocol response code was %d (%s)\n",
1207 res.hdr.response, SYNC_res2string(res.hdr.response));
1208 fprintf(stderr, "protocol reason code was %d (%s)\n",
1209 res.hdr.reason, FSYNC_reason2string(res.hdr.reason));
1211 VDisconnectFS();
1213 if (res.hdr.response == SYNC_OK) {
1214 switch (command) {
1215 case FSYNC_VOL_STATS_GENERAL:
1217 struct VolPkgStats vol_stats;
1218 memcpy(&vol_stats, res_buf, sizeof(vol_stats));
1219 print_vol_stats_general(&vol_stats);
1220 break;
1222 case FSYNC_VOL_STATS_VICEP:
1224 struct DiskPartitionStats64 vicep_stats;
1225 memcpy(&vicep_stats, res_buf, sizeof(vicep_stats));
1226 print_vol_stats_viceP(&vicep_stats);
1227 break;
1229 case FSYNC_VOL_STATS_HASH:
1231 struct VolumeHashChainStats hash_stats;
1232 memcpy(&hash_stats, res_buf, sizeof(hash_stats));
1233 print_vol_stats_hash(&hash_stats);
1234 break;
1236 #ifdef AFS_DEMAND_ATTACH_FS
1237 case FSYNC_VOL_STATS_HDR:
1239 struct volume_hdr_LRU_stats hdr_stats;
1240 memcpy(&hdr_stats, res_buf, sizeof(hdr_stats));
1241 print_vol_stats_hdr(&hdr_stats);
1242 break;
1244 #endif /* AFS_DEMAND_ATTACH_FS */
1248 return 0;
1251 static void
1252 print_vol_stats_general(VolPkgStats * stats)
1254 #ifdef AFS_DEMAND_ATTACH_FS
1255 int i;
1256 #endif
1257 afs_uint32 hi, lo;
1259 printf("VolPkgStats = {\n");
1260 #ifdef AFS_DEMAND_ATTACH_FS
1261 for (i = 0; i < VOL_STATE_COUNT; i++) {
1262 printf("\tvol_state_count[%s] = %d\n",
1263 vol_state_to_string(i),
1264 stats->state_levels[i]);
1267 SplitInt64(stats->hash_looks, hi, lo);
1268 printf("\thash_looks = {\n");
1269 printf("\t\thi = %u\n", hi);
1270 printf("\t\tlo = %u\n", lo);
1271 printf("\t}\n");
1273 SplitInt64(stats->hash_reorders, hi, lo);
1274 printf("\thash_reorders = {\n");
1275 printf("\t\thi = %u\n", hi);
1276 printf("\t\tlo = %u\n", lo);
1277 printf("\t}\n");
1279 SplitInt64(stats->salvages, hi, lo);
1280 printf("\tsalvages = {\n");
1281 printf("\t\thi = %u\n", hi);
1282 printf("\t\tlo = %u\n", lo);
1283 printf("\t}\n");
1285 SplitInt64(stats->vol_ops, hi, lo);
1286 printf("\tvol_ops = {\n");
1287 printf("\t\thi = %u\n", hi);
1288 printf("\t\tlo = %u\n", lo);
1289 printf("\t}\n");
1290 #endif
1291 SplitInt64(stats->hdr_loads, hi, lo);
1292 printf("\thdr_loads = {\n");
1293 printf("\t\thi = %u\n", hi);
1294 printf("\t\tlo = %u\n", lo);
1295 printf("\t}\n");
1297 SplitInt64(stats->hdr_gets, hi, lo);
1298 printf("\thdr_gets = {\n");
1299 printf("\t\thi = %u\n", hi);
1300 printf("\t\tlo = %u\n", lo);
1301 printf("\t}\n");
1303 SplitInt64(stats->attaches, hi, lo);
1304 printf("\tattaches = {\n");
1305 printf("\t\thi = %u\n", hi);
1306 printf("\t\tlo = %u\n", lo);
1307 printf("\t}\n");
1309 SplitInt64(stats->soft_detaches, hi, lo);
1310 printf("\tsoft_detaches = {\n");
1311 printf("\t\thi = %u\n", hi);
1312 printf("\t\tlo = %u\n", lo);
1313 printf("\t}\n");
1315 printf("\thdr_cache_size = %d\n", stats->hdr_cache_size);
1317 printf("}\n");
1320 static void
1321 print_vol_stats_viceP(struct DiskPartitionStats64 * stats)
1323 printf("DiskPartitionStats64 = {\n");
1324 printf("\tfree = %" AFS_INT64_FMT "\n", stats->free);
1325 printf("\tminFree = %" AFS_INT64_FMT "\n", stats->minFree);
1326 printf("\ttotalUsable = %" AFS_INT64_FMT "\n", stats->totalUsable);
1327 printf("\tf_files = %" AFS_INT64_FMT "\n", stats->f_files);
1328 #ifdef AFS_DEMAND_ATTACH_FS
1329 printf("\tvol_list_len = %d\n", stats->vol_list_len);
1330 #endif
1331 printf("}\n");
1334 static void
1335 print_vol_stats_hash(struct VolumeHashChainStats * stats)
1337 #ifdef AFS_DEMAND_ATTACH_FS
1338 afs_uint32 hi, lo;
1339 #endif
1341 printf("DiskPartitionStats = {\n");
1342 printf("\ttable_size = %d\n", stats->table_size);
1343 printf("\tchain_len = %d\n", stats->chain_len);
1345 #ifdef AFS_DEMAND_ATTACH_FS
1346 printf("\tchain_cacheCheck = %d\n", stats->chain_cacheCheck);
1347 printf("\tchain_busy = %d\n", stats->chain_busy);
1349 SplitInt64(stats->chain_looks, hi, lo);
1350 printf("\tchain_looks = {\n");
1351 printf("\t\thi = %u\n", hi);
1352 printf("\t\tlo = %u\n", lo);
1353 printf("\t}\n");
1355 SplitInt64(stats->chain_gets, hi, lo);
1356 printf("\tchain_gets = {\n");
1357 printf("\t\thi = %u\n", hi);
1358 printf("\t\tlo = %u\n", lo);
1359 printf("\t}\n");
1361 SplitInt64(stats->chain_reorders, hi, lo);
1362 printf("\tchain_reorders = {\n");
1363 printf("\t\thi = %u\n", hi);
1364 printf("\t\tlo = %u\n", lo);
1365 printf("\t}\n");
1366 #endif /* AFS_DEMAND_ATTACH_FS */
1368 printf("}\n");
1372 #ifdef AFS_DEMAND_ATTACH_FS
1373 static void
1374 print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats)
1376 printf("volume_hdr_LRU_stats = {\n");
1377 printf("\tfree = %d\n", stats->free);
1378 printf("\tused = %d\n", stats->used);
1379 printf("\tattached = %d\n", stats->attached);
1380 printf("}\n");
1382 #endif /* AFS_DEMAND_ATTACH_FS */
1386 * query VGC.
1388 * @notes args:
1389 * - CUSTOM_PARMS_OFFSET+0 is partition string
1390 * - CUSTOM_PARMS_OFFSET+1 is volume id
1392 * @return operation status
1393 * @retval 0 success
1395 static int
1396 VGCQuery(struct cmd_syndesc * as, void * rock)
1398 afs_int32 code;
1399 struct state state;
1400 char * partName;
1401 VolumeId volid;
1402 FSSYNC_VGQry_response_t q_res;
1403 SYNC_response res;
1404 int i;
1405 struct cmd_item *ti;
1407 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+0].items)) { /* -partition */
1408 return -1;
1410 partName = ti->data;
1412 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -volumeid */
1413 return -1;
1415 volid = atoi(ti->data);
1417 common_prolog(as, &state);
1419 fprintf(stderr, "calling FSYNC_VCGQuery\n");
1421 code = FSYNC_VGCQuery(partName, volid, &q_res, &res);
1423 debug_response(code, &res);
1425 if (code == SYNC_OK) {
1426 printf("VG = {\n");
1427 printf("\trw\t=\t%u\n", q_res.rw);
1428 printf("\tchildren\t= (\n");
1429 for (i = 0; i < VOL_VG_MAX_VOLS; i++) {
1430 if (q_res.children[i]) {
1431 printf("\t\t%u\n", q_res.children[i]);
1434 printf("\t)\n");
1437 VDisconnectFS();
1439 return 0;
1442 static int
1443 VGCAdd(struct cmd_syndesc * as, void * rock)
1445 afs_int32 code;
1446 struct state state;
1447 char * partName;
1448 VolumeId parent, child;
1449 struct cmd_item *ti;
1450 SYNC_response res;
1452 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+0].items)) { /* -partition */
1453 return -1;
1455 partName = ti->data;
1457 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -parent */
1458 return -1;
1460 parent = atoi(ti->data);
1462 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -child */
1463 return -1;
1465 child = atoi(ti->data);
1467 common_prolog(as, &state);
1468 fprintf(stderr, "calling FSYNC_VCGAdd\n");
1469 code = FSYNC_VGCAdd(partName, parent, child, state.reason, &res);
1470 debug_response(code, &res);
1472 VDisconnectFS();
1474 return 0;
1477 static int
1478 VGCDel(struct cmd_syndesc * as, void * rock)
1480 afs_int32 code;
1481 struct state state;
1482 char * partName;
1483 VolumeId parent, child;
1484 struct cmd_item *ti;
1485 SYNC_response res;
1487 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+0].items)) { /* -partition */
1488 return -1;
1490 partName = ti->data;
1492 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -parent */
1493 return -1;
1495 parent = atoi(ti->data);
1497 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -child */
1498 return -1;
1500 child = atoi(ti->data);
1502 common_prolog(as, &state);
1503 fprintf(stderr, "calling FSYNC_VCGDel\n");
1504 code = FSYNC_VGCDel(partName, parent, child, state.reason, &res);
1505 debug_response(code, &res);
1507 VDisconnectFS();
1509 return 0;
1512 static int
1513 VGCScan(struct cmd_syndesc * as, void * rock)
1515 afs_int32 code;
1516 struct state state;
1517 char * partName;
1518 struct cmd_item *ti;
1520 if (!(ti = as->parms[CUSTOM_PARMS_OFFSET+0].items)) { /* -partition */
1521 return -1;
1523 partName = ti->data;
1525 common_prolog(as, &state);
1526 fprintf(stderr, "calling FSYNC_VCGScan\n");
1527 code = FSYNC_VGCScan(partName, state.reason);
1528 debug_response(code, NULL);
1530 VDisconnectFS();
1532 return 0;
1535 static int
1536 VGCScanAll(struct cmd_syndesc * as, void * rock)
1538 afs_int32 code;
1539 struct state state;
1541 common_prolog(as, &state);
1542 fprintf(stderr, "calling FSYNC_VCGScanAll\n");
1543 code = FSYNC_VGCScan(NULL, state.reason);
1544 debug_response(code, NULL);
1546 VDisconnectFS();
1548 return 0;