2 * Copyright 2006-2008, 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
10 /* Main program file. Define globals. */
14 * fssync administration tool
18 #include <afsconfig.h>
19 #include <afs/param.h>
33 #include <WINNT/afsevent.h>
35 #include <sys/param.h>
39 #endif /* ITIMER_REAL */
42 #include <afs/afsint.h>
43 #include <afs/assert.h>
49 #include <afs/osi_inode.h>
53 #include <afs/afsutil.h>
54 #include <afs/fileutil.h>
62 #include "partition.h"
63 #include "daemon_com.h"
69 int VolumeChanged; /* hack to make dir package happy */
81 struct volop_state * vop;
84 static int common_prolog(struct cmd_syndesc *, struct state *);
85 static int common_volop_prolog(struct cmd_syndesc *, struct state *);
87 static int do_volop(struct state *, afs_int32 command, SYNC_response * res);
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);
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 VolLeaveOff(struct cmd_syndesc * as, void * rock);
102 static int VolForceAttach(struct cmd_syndesc * as, void * rock);
103 static int VolForceError(struct cmd_syndesc * as, void * rock);
104 static int VolQuery(struct cmd_syndesc * as, void * rock);
105 static int VolHdrQuery(struct cmd_syndesc * as, void * rock);
106 static int VolOpQuery(struct cmd_syndesc * as, void * rock);
107 static int StatsQuery(struct cmd_syndesc * as, void * rock);
108 static int VnQuery(struct cmd_syndesc * as, void * rock);
110 static void print_vol_stats_general(VolPkgStats * stats);
111 static void print_vol_stats_viceP(struct DiskPartitionStats64 * stats);
112 static void print_vol_stats_hash(struct VolumeHashChainStats * stats);
113 #ifdef AFS_DEMAND_ATTACH_FS
114 static void print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats);
118 #include "AFS_component_version_number.c"
122 #define COMMON_PARMS_OFFSET 12
123 #define COMMON_PARMS(ts) \
124 cmd_Seek(ts, COMMON_PARMS_OFFSET); \
125 cmd_AddParm(ts, "-reason", CMD_SINGLE, CMD_OPTIONAL, "sync protocol reason code"); \
126 cmd_AddParm(ts, "-programtype", CMD_SINGLE, CMD_OPTIONAL, "program type code")
128 #define COMMON_VOLOP_PARMS_OFFSET 10
129 #define COMMON_VOLOP_PARMS(ts) \
130 cmd_Seek(ts, COMMON_VOLOP_PARMS_OFFSET); \
131 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id"); \
132 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name")
134 #define CUSTOM_PARMS_OFFSET 1
137 #define VOLOP_PARMS_DECL(ts) \
138 COMMON_VOLOP_PARMS(ts); \
140 #define COMMON_PARMS_DECL(ts) \
144 main(int argc, char **argv)
146 struct cmd_syndesc *ts;
149 extern char cml_version_number[];
151 /* Initialize directory paths */
152 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
154 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
156 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
162 ts = cmd_CreateSyntax("online", VolOnline, NULL, "bring a volume online (FSYNC_VOL_ON opcode)");
163 VOLOP_PARMS_DECL(ts);
165 ts = cmd_CreateSyntax("offline", VolOffline, NULL, "take a volume offline (FSYNC_VOL_OFF opcode)");
166 VOLOP_PARMS_DECL(ts);
168 ts = cmd_CreateSyntax("mode", VolMode, NULL, "change volume attach mode (FSYNC_VOL_NEEDVOLUME opcode)");
169 VOLOP_PARMS_DECL(ts);
170 cmd_CreateAlias(ts, "needvolume");
172 ts = cmd_CreateSyntax("detach", VolDetach, NULL, "detach a volume (FSYNC_VOL_DONE opcode)");
173 VOLOP_PARMS_DECL(ts);
175 ts = cmd_CreateSyntax("callback", VolBreakCBKs, NULL, "break callbacks for volume (FSYNC_VOL_BREAKCBKS opcode)");
176 VOLOP_PARMS_DECL(ts);
177 cmd_CreateAlias(ts, "cbk");
179 ts = cmd_CreateSyntax("move", VolMove, NULL, "set volume moved flag (FSYNC_VOL_MOVE opcode)");
180 VOLOP_PARMS_DECL(ts);
182 ts = cmd_CreateSyntax("list", VolList, NULL, "sync local volume list (FSYNC_VOL_LISTVOLUMES opcode)");
183 VOLOP_PARMS_DECL(ts);
184 cmd_CreateAlias(ts, "ls");
186 ts = cmd_CreateSyntax("leaveoff", VolLeaveOff, 0, "leave volume offline (FSYNC_VOL_LEAVE_OFF opcode)");
187 VOLOP_PARMS_DECL(ts);
189 ts = cmd_CreateSyntax("attach", VolForceAttach, 0, "force full attachment (FSYNC_VOL_ATTACH opcode)");
190 VOLOP_PARMS_DECL(ts);
192 ts = cmd_CreateSyntax("error", VolForceError, 0, "force into hard error state (FSYNC_VOL_FORCE_ERROR opcode)");
193 VOLOP_PARMS_DECL(ts);
195 ts = cmd_CreateSyntax("query", VolQuery, NULL, "get volume structure (FSYNC_VOL_QUERY opcode)");
196 VOLOP_PARMS_DECL(ts);
197 cmd_CreateAlias(ts, "qry");
199 ts = cmd_CreateSyntax("header", VolHdrQuery, NULL, "get volume disk data structure (FSYNC_VOL_QUERY_HDR opcode)");
200 VOLOP_PARMS_DECL(ts);
201 cmd_CreateAlias(ts, "hdr");
203 ts = cmd_CreateSyntax("volop", VolOpQuery, NULL, "get pending volume operation info (FSYNC_VOL_QUERY_VOP opcode)");
204 VOLOP_PARMS_DECL(ts);
205 cmd_CreateAlias(ts, "vop");
207 ts = cmd_CreateSyntax("vnode", VnQuery, NULL, "get vnode structure (FSYNC_VOL_QUERY_VNODE opcode)");
208 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
209 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
210 cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id");
211 cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier");
212 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "paritition name");
213 COMMON_PARMS_DECL(ts);
215 ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information");
216 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
217 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "subcommand");
218 cmd_AddParm(ts, "-arg1", CMD_SINGLE, CMD_OPTIONAL, "arg1");
219 cmd_AddParm(ts, "-arg2", CMD_SINGLE, CMD_OPTIONAL, "arg2");
220 COMMON_PARMS_DECL(ts);
222 err = cmd_Dispatch(argc, argv);
227 common_prolog(struct cmd_syndesc * as, struct state * state)
229 register struct cmd_item *ti;
232 if (afs_winsockInit() < 0) {
237 VInitVolumePackage(debugUtility, 1, 1,
241 if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) { /* -reason */
242 state->reason = atoi(ti->data);
244 if ((ti = as->parms[COMMON_PARMS_OFFSET+1].items)) { /* -programtype */
245 if (!strcmp(ti->data, "fileServer")) {
246 programType = fileServer;
247 } else if (!strcmp(ti->data, "volumeUtility")) {
248 programType = volumeUtility;
249 } else if (!strcmp(ti->data, "salvager")) {
250 programType = salvager;
251 } else if (!strcmp(ti->data, "salvageServer")) {
252 programType = salvageServer;
254 programType = (ProgramType) atoi(ti->data);
264 common_volop_prolog(struct cmd_syndesc * as, struct state * state)
266 register struct cmd_item *ti;
267 char pname[100], *temp;
269 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
270 assert(state->vop != NULL);
272 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET].items)) { /* -volumeid */
273 state->vop->volume = atoi(ti->data);
275 fprintf(stderr, "required argument -volumeid not given\n");
278 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+1].items)) { /* -partition */
279 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
281 memset(state->vop->partName, 0, sizeof(state->vop->partName));
288 do_volop(struct state * state, afs_int32 command, SYNC_response * res)
291 SYNC_PROTO_BUF_DECL(res_buf);
296 res->payload.len = SYNC_PROTO_MAX_LEN;
297 res->payload.buf = res_buf;
300 fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n",
301 command, command_code_to_string(command));
303 code = FSYNC_VolOp(state->vop->volume,
304 state->vop->partName,
314 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
317 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
318 fprintf(stderr, "protocol response code was %d (%s)\n",
319 res->hdr.response, response_code_to_string(res->hdr.response));
320 fprintf(stderr, "protocol reason code was %d (%s)\n",
321 res->hdr.reason, reason_code_to_string(res->hdr.reason));
327 #define ENUMTOSTRING(en) #en
328 #define ENUMCASE(en) \
330 return ENUMTOSTRING(en); \
333 #define FLAGTOSTRING(fl) #fl
334 #define FLAGCASE(bitstr, fl, str, count) \
336 if ((bitstr) & (fl)) { \
338 strlcat((str), " | ", sizeof(str)); \
339 strlcat((str), FLAGTOSTRING(fl), sizeof(str)); \
345 response_code_to_string(afs_int32 response)
349 ENUMCASE(SYNC_DENIED);
350 ENUMCASE(SYNC_COM_ERROR);
351 ENUMCASE(SYNC_BAD_COMMAND);
352 ENUMCASE(SYNC_FAILED);
354 return "**UNKNOWN**";
359 command_code_to_string(afs_int32 command)
362 ENUMCASE(SYNC_COM_CHANNEL_CLOSE);
363 ENUMCASE(FSYNC_VOL_ON);
364 ENUMCASE(FSYNC_VOL_OFF);
365 ENUMCASE(FSYNC_VOL_LISTVOLUMES);
366 ENUMCASE(FSYNC_VOL_NEEDVOLUME);
367 ENUMCASE(FSYNC_VOL_MOVE);
368 ENUMCASE(FSYNC_VOL_BREAKCBKS);
369 ENUMCASE(FSYNC_VOL_DONE);
370 ENUMCASE(FSYNC_VOL_QUERY);
371 ENUMCASE(FSYNC_VOL_QUERY_HDR);
372 ENUMCASE(FSYNC_VOL_QUERY_VOP);
373 ENUMCASE(FSYNC_VOL_STATS_GENERAL);
374 ENUMCASE(FSYNC_VOL_STATS_VICEP);
375 ENUMCASE(FSYNC_VOL_STATS_HASH);
376 ENUMCASE(FSYNC_VOL_STATS_HDR);
377 ENUMCASE(FSYNC_VOL_STATS_VLRU);
378 ENUMCASE(FSYNC_VOL_ATTACH);
379 ENUMCASE(FSYNC_VOL_FORCE_ERROR);
380 ENUMCASE(FSYNC_VOL_LEAVE_OFF);
381 ENUMCASE(FSYNC_VOL_QUERY_VNODE);
383 return "**UNKNOWN**";
388 reason_code_to_string(afs_int32 reason)
391 ENUMCASE(SYNC_REASON_NONE);
392 ENUMCASE(SYNC_REASON_MALFORMED_PACKET);
393 ENUMCASE(SYNC_REASON_NOMEM);
394 ENUMCASE(SYNC_REASON_ENCODING_ERROR);
395 ENUMCASE(FSYNC_WHATEVER);
396 ENUMCASE(FSYNC_SALVAGE);
397 ENUMCASE(FSYNC_MOVE);
398 ENUMCASE(FSYNC_OPERATOR);
399 ENUMCASE(FSYNC_EXCLUSIVE);
400 ENUMCASE(FSYNC_UNKNOWN_VOLID);
401 ENUMCASE(FSYNC_HDR_NOT_ATTACHED);
402 ENUMCASE(FSYNC_NO_PENDING_VOL_OP);
403 ENUMCASE(FSYNC_VOL_PKG_ERROR);
404 ENUMCASE(FSYNC_UNKNOWN_VNID);
406 return "**UNKNOWN**";
411 program_type_to_string(afs_int32 type)
413 switch ((ProgramType)type) {
414 ENUMCASE(fileServer);
415 ENUMCASE(volumeUtility);
417 ENUMCASE(salvageServer);
418 ENUMCASE(debugUtility);
420 return "**UNKNOWN**";
425 VolOnline(struct cmd_syndesc * as, void * rock)
429 common_prolog(as, &state);
430 common_volop_prolog(as, &state);
432 do_volop(&state, FSYNC_VOL_ON, NULL);
438 VolOffline(struct cmd_syndesc * as, void * rock)
442 common_prolog(as, &state);
443 common_volop_prolog(as, &state);
445 do_volop(&state, FSYNC_VOL_OFF, NULL);
451 VolMode(struct cmd_syndesc * as, void * rock)
455 common_prolog(as, &state);
456 common_volop_prolog(as, &state);
458 do_volop(&state, FSYNC_VOL_NEEDVOLUME, NULL);
464 VolDetach(struct cmd_syndesc * as, void * rock)
468 common_prolog(as, &state);
469 common_volop_prolog(as, &state);
471 do_volop(&state, FSYNC_VOL_DONE, NULL);
477 VolBreakCBKs(struct cmd_syndesc * as, void * rock)
481 common_prolog(as, &state);
482 common_volop_prolog(as, &state);
484 do_volop(&state, FSYNC_VOL_BREAKCBKS, NULL);
490 VolMove(struct cmd_syndesc * as, void * rock)
494 common_prolog(as, &state);
495 common_volop_prolog(as, &state);
497 do_volop(&state, FSYNC_VOL_MOVE, NULL);
503 VolList(struct cmd_syndesc * as, void * rock)
507 common_prolog(as, &state);
508 common_volop_prolog(as, &state);
510 do_volop(&state, FSYNC_VOL_LISTVOLUMES, NULL);
516 VolLeaveOff(struct cmd_syndesc * as, void * rock)
520 common_prolog(as, &state);
521 common_volop_prolog(as, &state);
523 do_volop(&state, FSYNC_VOL_LEAVE_OFF, NULL);
529 VolForceAttach(struct cmd_syndesc * as, void * rock)
533 common_prolog(as, &state);
534 common_volop_prolog(as, &state);
536 do_volop(&state, FSYNC_VOL_ATTACH, NULL);
542 VolForceError(struct cmd_syndesc * as, void * rock)
546 common_prolog(as, &state);
547 common_volop_prolog(as, &state);
549 do_volop(&state, FSYNC_VOL_FORCE_ERROR, NULL);
554 #ifdef AFS_DEMAND_ATTACH_FS
556 vol_state_to_string(VolState state)
559 ENUMCASE(VOL_STATE_UNATTACHED);
560 ENUMCASE(VOL_STATE_PREATTACHED);
561 ENUMCASE(VOL_STATE_ATTACHING);
562 ENUMCASE(VOL_STATE_ATTACHED);
563 ENUMCASE(VOL_STATE_UPDATING);
564 ENUMCASE(VOL_STATE_GET_BITMAP);
565 ENUMCASE(VOL_STATE_HDR_LOADING);
566 ENUMCASE(VOL_STATE_HDR_ATTACHING);
567 ENUMCASE(VOL_STATE_SHUTTING_DOWN);
568 ENUMCASE(VOL_STATE_GOING_OFFLINE);
569 ENUMCASE(VOL_STATE_OFFLINING);
570 ENUMCASE(VOL_STATE_DETACHING);
571 ENUMCASE(VOL_STATE_SALVSYNC_REQ);
572 ENUMCASE(VOL_STATE_SALVAGING);
573 ENUMCASE(VOL_STATE_ERROR);
574 ENUMCASE(VOL_STATE_VNODE_ALLOC);
575 ENUMCASE(VOL_STATE_VNODE_GET);
576 ENUMCASE(VOL_STATE_VNODE_CLOSE);
577 ENUMCASE(VOL_STATE_VNODE_RELEASE);
578 ENUMCASE(VOL_STATE_VLRU_ADD);
579 ENUMCASE(VOL_STATE_FREED);
581 return "**UNKNOWN**";
586 vol_flags_to_string(afs_uint16 flags)
588 static char str[128];
592 FLAGCASE(flags, VOL_HDR_ATTACHED, str, count);
593 FLAGCASE(flags, VOL_HDR_LOADED, str, count);
594 FLAGCASE(flags, VOL_HDR_IN_LRU, str, count);
595 FLAGCASE(flags, VOL_IN_HASH, str, count);
596 FLAGCASE(flags, VOL_ON_VBYP_LIST, str, count);
597 FLAGCASE(flags, VOL_IS_BUSY, str, count);
598 FLAGCASE(flags, VOL_ON_VLRU, str, count);
599 FLAGCASE(flags, VOL_HDR_DONTSALV, str, count);
605 vlru_idx_to_string(int idx)
608 ENUMCASE(VLRU_QUEUE_NEW);
609 ENUMCASE(VLRU_QUEUE_MID);
610 ENUMCASE(VLRU_QUEUE_OLD);
611 ENUMCASE(VLRU_QUEUE_CANDIDATE);
612 ENUMCASE(VLRU_QUEUE_HELD);
613 ENUMCASE(VLRU_QUEUE_INVALID);
615 return "**UNKNOWN**";
621 vn_state_to_string(VnState state)
624 ENUMCASE(VN_STATE_INVALID);
625 ENUMCASE(VN_STATE_RELEASING);
626 ENUMCASE(VN_STATE_CLOSING);
627 ENUMCASE(VN_STATE_ALLOC);
628 ENUMCASE(VN_STATE_ONLINE);
629 ENUMCASE(VN_STATE_LOAD);
630 ENUMCASE(VN_STATE_EXCLUSIVE);
631 ENUMCASE(VN_STATE_STORE);
632 ENUMCASE(VN_STATE_READ);
633 ENUMCASE(VN_STATE_ERROR);
635 return "**UNKNOWN**";
640 vn_flags_to_string(afs_uint32 flags)
642 static char str[128];
646 FLAGCASE(flags, VN_ON_HASH, str, count);
647 FLAGCASE(flags, VN_ON_LRU, str, count);
648 FLAGCASE(flags, VN_ON_VVN, str, count);
655 VolQuery(struct cmd_syndesc * as, void * rock)
658 SYNC_PROTO_BUF_DECL(res_buf);
663 res.hdr.response_len = sizeof(res.hdr);
664 res.payload.buf = res_buf;
665 res.payload.len = SYNC_PROTO_MAX_LEN;
667 common_prolog(as, &state);
668 common_volop_prolog(as, &state);
670 do_volop(&state, FSYNC_VOL_QUERY, &res);
672 if (res.hdr.response == SYNC_OK) {
673 memcpy(&v, res.payload.buf, sizeof(Volume));
675 printf("volume = {\n");
676 printf("\thashid = %u\n", v.hashid);
677 printf("\theader = 0x%x\n", v.header);
678 printf("\tdevice = %d\n", v.device);
679 printf("\tpartition = 0x%x\n", v.partition);
680 printf("\tlinkHandle = 0x%x\n", v.linkHandle);
681 printf("\tnextVnodeUnique = %u\n", v.nextVnodeUnique);
682 printf("\tdiskDataHandle = 0x%x\n", v.diskDataHandle);
683 printf("\tvnodeHashOffset = %u\n", v.vnodeHashOffset);
684 printf("\tshuttingDown = %d\n", v.shuttingDown);
685 printf("\tgoingOffline = %d\n", v.goingOffline);
686 printf("\tcacheCheck = %u\n", v.cacheCheck);
687 printf("\tnUsers = %d\n", v.nUsers);
688 printf("\tneedsPutBack = %d\n", v.needsPutBack);
689 printf("\tspecialStatus = %d\n", v.specialStatus);
690 printf("\tupdateTime = %u\n", v.updateTime);
692 printf("\tvnodeIndex[vSmall] = {\n");
693 printf("\t\thandle = 0x%x\n", v.vnodeIndex[vSmall].handle);
694 printf("\t\tbitmap = 0x%x\n", v.vnodeIndex[vSmall].bitmap);
695 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vSmall].bitmapSize);
696 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vSmall].bitmapOffset);
698 printf("\tvnodeIndex[vLarge] = {\n");
699 printf("\t\thandle = 0x%x\n", v.vnodeIndex[vLarge].handle);
700 printf("\t\tbitmap = 0x%x\n", v.vnodeIndex[vLarge].bitmap);
701 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vLarge].bitmapSize);
702 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vLarge].bitmapOffset);
704 #ifdef AFS_DEMAND_ATTACH_FS
705 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
706 printf("\tupdateTime = %u\n", v.updateTime);
707 printf("\tattach_state = %s\n", vol_state_to_string(v.attach_state));
708 printf("\tattach_flags = %s\n", vol_flags_to_string(v.attach_flags));
709 printf("\tnWaiters = %d\n", v.nWaiters);
710 printf("\tchainCacheCheck = %d\n", v.chainCacheCheck);
712 /* online salvage structure */
713 printf("\tsalvage = {\n");
714 printf("\t\tprio = %u\n", v.salvage.prio);
715 printf("\t\treason = %d\n", v.salvage.reason);
716 printf("\t\trequested = %d\n", v.salvage.requested);
717 printf("\t\tscheduled = %d\n", v.salvage.scheduled);
720 /* statistics structure */
721 printf("\tstats = {\n");
723 printf("\t\thash_lookups = {\n");
724 SplitInt64(v.stats.hash_lookups,hi,lo);
725 printf("\t\t\thi = %u\n", hi);
726 printf("\t\t\tlo = %u\n", lo);
729 printf("\t\thash_short_circuits = {\n");
730 SplitInt64(v.stats.hash_short_circuits,hi,lo);
731 printf("\t\t\thi = %u\n", hi);
732 printf("\t\t\tlo = %u\n", lo);
735 printf("\t\thdr_loads = {\n");
736 SplitInt64(v.stats.hdr_loads,hi,lo);
737 printf("\t\t\thi = %u\n", hi);
738 printf("\t\t\tlo = %u\n", lo);
741 printf("\t\thdr_gets = {\n");
742 SplitInt64(v.stats.hdr_gets,hi,lo);
743 printf("\t\t\thi = %u\n", hi);
744 printf("\t\t\tlo = %u\n", lo);
747 printf("\t\tattaches = %u\n", v.stats.attaches);
748 printf("\t\tsoft_detaches = %u\n", v.stats.soft_detaches);
749 printf("\t\tsalvages = %u\n", v.stats.salvages);
750 printf("\t\tvol_ops = %u\n", v.stats.vol_ops);
752 printf("\t\tlast_attach = %u\n", v.stats.last_attach);
753 printf("\t\tlast_get = %u\n", v.stats.last_get);
754 printf("\t\tlast_promote = %u\n", v.stats.last_promote);
755 printf("\t\tlast_hdr_get = %u\n", v.stats.last_hdr_get);
756 printf("\t\tlast_hdr_load = %u\n", v.stats.last_hdr_load);
757 printf("\t\tlast_salvage = %u\n", v.stats.last_salvage);
758 printf("\t\tlast_salvage_req = %u\n", v.stats.last_salvage_req);
759 printf("\t\tlast_vol_op = %u\n", v.stats.last_vol_op);
763 printf("\tvlru = {\n");
764 printf("\t\tidx = %d (%s)\n",
765 v.vlru.idx, vlru_idx_to_string(v.vlru.idx));
768 /* volume op state */
769 printf("\tpending_vol_op = 0x%x\n", v.pending_vol_op);
771 #else /* !AFS_DEMAND_ATTACH_FS */
772 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
773 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
774 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
775 printf("*** to dump dafs extended state\n");
777 #endif /* !AFS_DEMAND_ATTACH_FS */
785 VolHdrQuery(struct cmd_syndesc * as, void * rock)
788 SYNC_PROTO_BUF_DECL(res_buf);
793 res.hdr.response_len = sizeof(res.hdr);
794 res.payload.buf = res_buf;
795 res.payload.len = SYNC_PROTO_MAX_LEN;
797 common_prolog(as, &state);
798 common_volop_prolog(as, &state);
800 do_volop(&state, FSYNC_VOL_QUERY_HDR, &res);
802 if (res.hdr.response == SYNC_OK) {
803 memcpy(&v, res.payload.buf, sizeof(VolumeDiskData));
805 printf("VolumeDiskData = {\n");
806 printf("\tstamp = {\n");
807 printf("\t\tmagic = 0x%x\n", v.stamp.magic);
808 printf("\t\tversion = %u\n", v.stamp.version);
811 printf("\tid = %u\n", v.id);
812 printf("\tname = '%s'\n", v.name);
814 printf("\tinUse = %d (%s)\n", v.inUse, program_type_to_string(v.inUse));
816 printf("\tinUse = %d (no)\n", v.inUse);
818 printf("\tinService = %d\n", v.inService);
819 printf("\tblessed = %d\n", v.blessed);
820 printf("\tneedsSalvaged = %d\n", v.needsSalvaged);
821 printf("\tuniquifier = %u\n", v.uniquifier);
822 printf("\ttype = %d\n", v.type);
823 printf("\tparentId = %u\n", v.parentId);
824 printf("\tcloneId = %u\n", v.cloneId);
825 printf("\tbackupId = %u\n", v.backupId);
826 printf("\trestoredFromId = %u\n", v.restoredFromId);
827 printf("\tneedsCallback = %d\n", v.needsCallback);
828 printf("\tdestroyMe = %d\n", v.destroyMe);
829 printf("\tdontSalvage = %d\n", v.dontSalvage);
830 printf("\tmaxquota = %d\n", v.maxquota);
831 printf("\tminquota = %d\n", v.minquota);
832 printf("\tmaxfiles = %d\n", v.maxfiles);
833 printf("\taccountNumber = %u\n", v.accountNumber);
834 printf("\towner = %u\n", v.owner);
835 printf("\tfilecount = %d\n", v.filecount);
836 printf("\tdiskused = %d\n", v.diskused);
837 printf("\tdayUse = %d\n", v.dayUse);
838 for (i = 0; i < 7; i++) {
839 printf("\tweekUse[%d] = %d\n", i, v.weekUse[i]);
841 printf("\tdayUseDate = %u\n", v.dayUseDate);
842 printf("\tcreationDate = %u\n", v.creationDate);
843 printf("\taccessDate = %u\n", v.accessDate);
844 printf("\tupdateDate = %u\n", v.updateDate);
845 printf("\texpirationDate = %u\n", v.expirationDate);
846 printf("\tbackupDate = %u\n", v.backupDate);
847 printf("\tcopyDate = %u\n", v.copyDate);
848 #ifdef OPENAFS_VOL_STATS
849 printf("\tstat_initialized = %d\n", v.stat_initialized);
851 printf("\tmtd = '%s'\n", v.motd);
860 VolOpQuery(struct cmd_syndesc * as, void * rock)
863 SYNC_PROTO_BUF_DECL(res_buf);
865 FSSYNC_VolOp_info vop;
868 res.hdr.response_len = sizeof(res.hdr);
869 res.payload.buf = res_buf;
870 res.payload.len = SYNC_PROTO_MAX_LEN;
872 common_prolog(as, &state);
873 common_volop_prolog(as, &state);
875 do_volop(&state, FSYNC_VOL_QUERY_VOP, &res);
877 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
878 printf("*** file server not compiled with demand attach extensions.\n");
879 printf("*** pending volume operation metadata not available.\n");
882 if (res.hdr.response == SYNC_OK) {
883 memcpy(&vop, res.payload.buf, sizeof(FSSYNC_VolOp_info));
885 printf("pending_vol_op = {\n");
887 printf("\tcom = {\n");
888 printf("\t\tproto_version = %u\n", vop.com.proto_version);
889 printf("\t\tpkt_seq = %u\n", vop.com.pkt_seq);
890 printf("\t\tcom_seq = %u\n", vop.com.com_seq);
891 printf("\t\tprogramType = %d (%s)\n",
892 vop.com.programType, program_type_to_string(vop.com.programType));
893 printf("\t\tpid = %d\n", vop.com.pid);
894 printf("\t\ttid = %d\n", vop.com.tid);
895 printf("\t\tcommand = %d (%s)\n",
896 vop.com.command, command_code_to_string(vop.com.command));
897 printf("\t\treason = %d (%s)\n",
898 vop.com.reason, reason_code_to_string(vop.com.reason));
899 printf("\t\tcommand_len = %u\n", vop.com.command_len);
900 printf("\t\tflags = 0x%x\n", vop.com.flags);
903 printf("\tvop = {\n");
904 printf("\t\tvolume = %u\n", vop.vop.volume);
905 if (afs_strnlen(vop.vop.partName, sizeof(vop.vop.partName)) <
906 sizeof(vop.vop.partName)) {
907 printf("\t\tpartName = '%s'\n", vop.vop.partName);
909 printf("\t\tpartName = (illegal string)\n");
920 vn_prolog(struct cmd_syndesc * as, struct state * state)
922 register struct cmd_item *ti;
923 char pname[100], *temp;
925 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
926 assert(state->vop != NULL);
928 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -volumeid */
929 state->vop->volume = atoi(ti->data);
931 fprintf(stderr, "required argument -volumeid not given\n");
934 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -vnodeid */
935 state->vop->vnode = atoi(ti->data);
937 fprintf(stderr, "required argument -vnodeid not given\n");
940 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -unique */
941 state->vop->unique = atoi(ti->data);
943 state->vop->unique = 0;
946 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+3].items)) { /* -partition */
947 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
949 memset(state->vop->partName, 0, sizeof(state->vop->partName));
956 do_vnqry(struct state * state, SYNC_response * res)
959 int command = FSYNC_VOL_QUERY_VNODE;
960 FSSYNC_VnQry_hdr qry;
962 qry.volume = state->vop->volume;
963 qry.vnode = state->vop->vnode;
964 qry.unique = state->vop->unique;
966 strlcpy(qry.partName, state->vop->partName, sizeof(qry.partName));
968 fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n",
969 command, command_code_to_string(command));
971 code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
978 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
981 fprintf(stderr, "FSYNC_GenericOp returned %d (%s)\n", code, response_code_to_string(code));
982 fprintf(stderr, "protocol response code was %d (%s)\n",
983 res->hdr.response, response_code_to_string(res->hdr.response));
984 fprintf(stderr, "protocol reason code was %d (%s)\n",
985 res->hdr.reason, reason_code_to_string(res->hdr.reason));
993 VnQuery(struct cmd_syndesc * as, void * rock)
996 SYNC_PROTO_BUF_DECL(res_buf);
1001 res.hdr.response_len = sizeof(res.hdr);
1002 res.payload.buf = res_buf;
1003 res.payload.len = SYNC_PROTO_MAX_LEN;
1005 common_prolog(as, &state);
1006 vn_prolog(as, &state);
1008 do_vnqry(&state, &res);
1010 if (res.hdr.response == SYNC_OK) {
1011 memcpy(&v, res.payload.buf, sizeof(Volume));
1013 printf("vnode = {\n");
1015 printf("\tvid_hash = {\n");
1016 printf("\t\tnext = 0x%lx\n", v.vid_hash.next);
1017 printf("\t\tprev = 0x%lx\n", v.vid_hash.prev);
1020 printf("\thashNext = 0x%lx\n", v.hashNext);
1021 printf("\tlruNext = 0x%lx\n", v.lruNext);
1022 printf("\tlruPrev = 0x%lx\n", v.lruPrev);
1023 printf("\thashIndex = %hu\n", v.hashIndex);
1024 printf("\tchanged_newTime = %u\n", (unsigned int) v.changed_newTime);
1025 printf("\tchanged_oldTime = %u\n", (unsigned int) v.changed_oldTime);
1026 printf("\tdelete = %u\n", (unsigned int) v.delete);
1027 printf("\tvnodeNumber = %u\n", v.vnodeNumber);
1028 printf("\tvolumePtr = 0x%lx\n", v.volumePtr);
1029 printf("\tnUsers = %u\n", v.nUsers);
1030 printf("\tcacheCheck = %u\n", v.cacheCheck);
1032 #ifdef AFS_DEMAND_ATTACH_FS
1033 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
1034 printf("*** fssync-debug built to expect demand attach extensions. server asserted\n");
1035 printf("*** that it was not compiled with demand attach turned on. please recompile\n");
1036 printf("*** fssync-debug to match your server\n");
1040 printf("\tnReaders = %u\n", v.nReaders);
1041 printf("\tvn_state_flags = %s\n", vn_flags_to_string(v.vn_state_flags));
1042 printf("\tvn_state = %s\n", vn_state_to_string(v.vn_state));
1044 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
1045 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
1046 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
1047 printf("*** to dump dafs extended state\n");
1050 #endif /* !AFS_DEMAND_ATTACH_FS */
1052 printf("\twriter = %u\n", v.writer);
1053 printf("\tvcp = 0x%lx\n", v.vcp);
1054 printf("\thandle = 0x%lx\n", v.handle);
1056 printf("\tdisk = {\n");
1057 printf("\t\ttype = %u\n", v.disk.type);
1058 printf("\t\tcloned = %u\n", v.disk.cloned);
1059 printf("\t\tmodeBits = %u\n", v.disk.modeBits);
1060 printf("\t\tlinkCount = %d\n", v.disk.linkCount);
1061 printf("\t\tlength = %u\n", v.disk.length);
1062 printf("\t\tuniquifier = %u\n", v.disk.uniquifier);
1063 printf("\t\tdataVersion = %u\n", v.disk.dataVersion);
1064 printf("\t\tvn_ino_lo = %u\n", v.disk.vn_ino_lo);
1065 printf("\t\tunixModifyTime = %u\n", v.disk.unixModifyTime);
1066 printf("\t\tauthor = %u\n", v.disk.author);
1067 printf("\t\towner = %u\n", v.disk.owner);
1068 printf("\t\tparent = %u\n", v.disk.parent);
1069 printf("\t\tvnodeMagic = %u\n", v.disk.vnodeMagic);
1071 printf("\t\tlock = {\n");
1072 printf("\t\t\tlockCount = %d\n", v.disk.lock.lockCount);
1073 printf("\t\t\tlockTime = %d\n", v.disk.lock.lockTime);
1076 printf("\t\tserverModifyTime = %u\n", v.disk.serverModifyTime);
1077 printf("\t\tgroup = %d\n", v.disk.group);
1078 printf("\t\tvn_ino_hi = %d\n", v.disk.vn_ino_hi);
1079 printf("\t\treserved6 = %u\n", v.disk.reserved6);
1091 StatsQuery(struct cmd_syndesc * as, void * rock)
1095 struct cmd_item *ti;
1097 SYNC_PROTO_BUF_DECL(res_buf);
1099 FSSYNC_StatsOp_hdr scom;
1102 struct VolPkgStats * vol_stats;
1103 struct VolumeHashChainStats * hash_stats;
1104 #ifdef AFS_DEMAND_ATTACH_FS
1105 struct volume_hdr_LRU_stats * hdr_stats;
1107 struct DiskPartitionStats64 * vicep_stats;
1111 res.hdr.response_len = sizeof(res.hdr);
1112 res.payload.buf = res_buf;
1113 res.payload.len = SYNC_PROTO_MAX_LEN;
1115 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -subcommand */
1116 if (!strcasecmp(ti->data, "vicep")) {
1117 command = FSYNC_VOL_STATS_VICEP;
1118 } else if (!strcasecmp(ti->data, "hash")) {
1119 command = FSYNC_VOL_STATS_HASH;
1120 #ifdef AFS_DEMAND_ATTACH_FS
1121 } else if (!strcasecmp(ti->data, "hdr")) {
1122 command = FSYNC_VOL_STATS_HDR;
1123 } else if (!strcasecmp(ti->data, "vlru")) {
1124 command = FSYNC_VOL_STATS_VLRU;
1126 } else if (!strcasecmp(ti->data, "pkg")) {
1127 command = FSYNC_VOL_STATS_GENERAL;
1128 } else if (!strcasecmp(ti->data, "help")) {
1129 fprintf(stderr, "fssync-debug stats subcommands:\n");
1130 fprintf(stderr, "\tpkg\tgeneral volume package stats\n");
1131 fprintf(stderr, "\tvicep\tvice partition stats\n");
1132 fprintf(stderr, "\thash\tvolume hash chain stats\n");
1133 #ifdef AFS_DEMAND_ATTACH_FS
1134 fprintf(stderr, "\thdr\tvolume header cache stats\n");
1135 fprintf(stderr, "\tvlru\tvlru generation stats\n");
1139 fprintf(stderr, "invalid stats subcommand");
1143 command = FSYNC_VOL_STATS_GENERAL;
1146 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -arg1 */
1148 case FSYNC_VOL_STATS_VICEP:
1149 strlcpy(scom.args.partName, ti->data, sizeof(state.vop->partName));
1151 case FSYNC_VOL_STATS_HASH:
1152 scom.args.hash_bucket = atoi(ti->data);
1154 case FSYNC_VOL_STATS_VLRU:
1155 scom.args.vlru_generation = atoi(ti->data);
1158 fprintf(stderr, "unrecognized arguments\n");
1163 case FSYNC_VOL_STATS_VICEP:
1164 case FSYNC_VOL_STATS_HASH:
1165 case FSYNC_VOL_STATS_VLRU:
1166 fprintf(stderr, "this subcommand requires more parameters\n");
1171 common_prolog(as, &state);
1173 fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
1174 command, command_code_to_string(command));
1176 code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
1183 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
1186 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
1187 fprintf(stderr, "protocol response code was %d (%s)\n",
1188 res.hdr.response, response_code_to_string(res.hdr.response));
1189 fprintf(stderr, "protocol reason code was %d (%s)\n",
1190 res.hdr.reason, reason_code_to_string(res.hdr.reason));
1194 if (res.hdr.response == SYNC_OK) {
1196 case FSYNC_VOL_STATS_GENERAL:
1197 print_vol_stats_general(sres.vol_stats);
1199 case FSYNC_VOL_STATS_VICEP:
1200 print_vol_stats_viceP(sres.vicep_stats);
1202 case FSYNC_VOL_STATS_HASH:
1203 print_vol_stats_hash(sres.hash_stats);
1205 #ifdef AFS_DEMAND_ATTACH_FS
1206 case FSYNC_VOL_STATS_HDR:
1207 print_vol_stats_hdr(sres.hdr_stats);
1209 #endif /* AFS_DEMAND_ATTACH_FS */
1217 print_vol_stats_general(VolPkgStats * stats)
1222 printf("VolPkgStats = {\n");
1223 #ifdef AFS_DEMAND_ATTACH_FS
1224 for (i = 0; i < VOL_STATE_COUNT; i++) {
1225 printf("\tvol_state_count[%s] = %d\n",
1226 vol_state_to_string(i),
1227 stats->state_levels[i]);
1230 SplitInt64(stats->hash_looks, hi, lo);
1231 printf("\thash_looks = {\n");
1232 printf("\t\thi = %u\n", hi);
1233 printf("\t\tlo = %u\n", lo);
1236 SplitInt64(stats->hash_reorders, hi, lo);
1237 printf("\thash_reorders = {\n");
1238 printf("\t\thi = %u\n", hi);
1239 printf("\t\tlo = %u\n", lo);
1242 SplitInt64(stats->salvages, hi, lo);
1243 printf("\tsalvages = {\n");
1244 printf("\t\thi = %u\n", hi);
1245 printf("\t\tlo = %u\n", lo);
1248 SplitInt64(stats->vol_ops, hi, lo);
1249 printf("\tvol_ops = {\n");
1250 printf("\t\thi = %u\n", hi);
1251 printf("\t\tlo = %u\n", lo);
1254 SplitInt64(stats->hdr_loads, hi, lo);
1255 printf("\thdr_loads = {\n");
1256 printf("\t\thi = %u\n", hi);
1257 printf("\t\tlo = %u\n", lo);
1260 SplitInt64(stats->hdr_gets, hi, lo);
1261 printf("\thdr_gets = {\n");
1262 printf("\t\thi = %u\n", hi);
1263 printf("\t\tlo = %u\n", lo);
1266 SplitInt64(stats->attaches, hi, lo);
1267 printf("\tattaches = {\n");
1268 printf("\t\thi = %u\n", hi);
1269 printf("\t\tlo = %u\n", lo);
1272 SplitInt64(stats->soft_detaches, hi, lo);
1273 printf("\tsoft_detaches = {\n");
1274 printf("\t\thi = %u\n", hi);
1275 printf("\t\tlo = %u\n", lo);
1278 printf("\thdr_cache_size = %d\n", stats->hdr_cache_size);
1284 print_vol_stats_viceP(struct DiskPartitionStats64 * stats)
1286 printf("DiskPartitionStats64 = {\n");
1287 printf("\tfree = %lld\n", stats->free);
1288 printf("\tminFree = %lld\n", stats->minFree);
1289 printf("\ttotalUsable = %lld\n", stats->totalUsable);
1290 printf("\tf_files = %lld\n", stats->f_files);
1291 #ifdef AFS_DEMAND_ATTACH_FS
1292 printf("\tvol_list_len = %d\n", stats->vol_list_len);
1298 print_vol_stats_hash(struct VolumeHashChainStats * stats)
1302 printf("DiskPartitionStats = {\n");
1303 printf("\ttable_size = %d\n", stats->table_size);
1304 printf("\tchain_len = %d\n", stats->chain_len);
1306 #ifdef AFS_DEMAND_ATTACH_FS
1307 printf("\tchain_cacheCheck = %d\n", stats->chain_cacheCheck);
1308 printf("\tchain_busy = %d\n", stats->chain_busy);
1310 SplitInt64(stats->chain_looks, hi, lo);
1311 printf("\tchain_looks = {\n");
1312 printf("\t\thi = %u\n", hi);
1313 printf("\t\tlo = %u\n", lo);
1316 SplitInt64(stats->chain_gets, hi, lo);
1317 printf("\tchain_gets = {\n");
1318 printf("\t\thi = %u\n", hi);
1319 printf("\t\tlo = %u\n", lo);
1322 SplitInt64(stats->chain_reorders, hi, lo);
1323 printf("\tchain_reorders = {\n");
1324 printf("\t\thi = %u\n", hi);
1325 printf("\t\tlo = %u\n", lo);
1327 #endif /* AFS_DEMAND_ATTACH_FS */
1333 #ifdef AFS_DEMAND_ATTACH_FS
1335 print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats)
1337 printf("volume_hdr_LRU_stats = {\n");
1338 printf("\tfree = %d\n", stats->free);
1339 printf("\tused = %d\n", stats->used);
1340 printf("\tattached = %d\n", stats->attached);
1343 #endif /* AFS_DEMAND_ATTACH_FS */