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 /* Initialize directory paths */
150 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
152 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
154 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
160 ts = cmd_CreateSyntax("online", VolOnline, NULL, "bring a volume online (FSYNC_VOL_ON opcode)");
161 VOLOP_PARMS_DECL(ts);
163 ts = cmd_CreateSyntax("offline", VolOffline, NULL, "take a volume offline (FSYNC_VOL_OFF opcode)");
164 VOLOP_PARMS_DECL(ts);
166 ts = cmd_CreateSyntax("mode", VolMode, NULL, "change volume attach mode (FSYNC_VOL_NEEDVOLUME opcode)");
167 VOLOP_PARMS_DECL(ts);
168 cmd_CreateAlias(ts, "needvolume");
170 ts = cmd_CreateSyntax("detach", VolDetach, NULL, "detach a volume (FSYNC_VOL_DONE opcode)");
171 VOLOP_PARMS_DECL(ts);
173 ts = cmd_CreateSyntax("callback", VolBreakCBKs, NULL, "break callbacks for volume (FSYNC_VOL_BREAKCBKS opcode)");
174 VOLOP_PARMS_DECL(ts);
175 cmd_CreateAlias(ts, "cbk");
177 ts = cmd_CreateSyntax("move", VolMove, NULL, "set volume moved flag (FSYNC_VOL_MOVE opcode)");
178 VOLOP_PARMS_DECL(ts);
180 ts = cmd_CreateSyntax("list", VolList, NULL, "sync local volume list (FSYNC_VOL_LISTVOLUMES opcode)");
181 VOLOP_PARMS_DECL(ts);
182 cmd_CreateAlias(ts, "ls");
184 ts = cmd_CreateSyntax("leaveoff", VolLeaveOff, 0, "leave volume offline (FSYNC_VOL_LEAVE_OFF opcode)");
185 VOLOP_PARMS_DECL(ts);
187 ts = cmd_CreateSyntax("attach", VolForceAttach, 0, "force full attachment (FSYNC_VOL_ATTACH opcode)");
188 VOLOP_PARMS_DECL(ts);
190 ts = cmd_CreateSyntax("error", VolForceError, 0, "force into hard error state (FSYNC_VOL_FORCE_ERROR opcode)");
191 VOLOP_PARMS_DECL(ts);
193 ts = cmd_CreateSyntax("query", VolQuery, NULL, "get volume structure (FSYNC_VOL_QUERY opcode)");
194 VOLOP_PARMS_DECL(ts);
195 cmd_CreateAlias(ts, "qry");
197 ts = cmd_CreateSyntax("header", VolHdrQuery, NULL, "get volume disk data structure (FSYNC_VOL_QUERY_HDR opcode)");
198 VOLOP_PARMS_DECL(ts);
199 cmd_CreateAlias(ts, "hdr");
201 ts = cmd_CreateSyntax("volop", VolOpQuery, NULL, "get pending volume operation info (FSYNC_VOL_QUERY_VOP opcode)");
202 VOLOP_PARMS_DECL(ts);
203 cmd_CreateAlias(ts, "vop");
205 ts = cmd_CreateSyntax("vnode", VnQuery, NULL, "get vnode structure (FSYNC_VOL_QUERY_VNODE opcode)");
206 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
207 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
208 cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id");
209 cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier");
210 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "paritition name");
211 COMMON_PARMS_DECL(ts);
213 ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information");
214 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
215 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "subcommand");
216 cmd_AddParm(ts, "-arg1", CMD_SINGLE, CMD_OPTIONAL, "arg1");
217 cmd_AddParm(ts, "-arg2", CMD_SINGLE, CMD_OPTIONAL, "arg2");
218 COMMON_PARMS_DECL(ts);
220 err = cmd_Dispatch(argc, argv);
225 common_prolog(struct cmd_syndesc * as, struct state * state)
227 register struct cmd_item *ti;
230 if (afs_winsockInit() < 0) {
235 VInitVolumePackage(debugUtility, 1, 1,
239 if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) { /* -reason */
240 state->reason = atoi(ti->data);
242 if ((ti = as->parms[COMMON_PARMS_OFFSET+1].items)) { /* -programtype */
243 if (!strcmp(ti->data, "fileServer")) {
244 programType = fileServer;
245 } else if (!strcmp(ti->data, "volumeUtility")) {
246 programType = volumeUtility;
247 } else if (!strcmp(ti->data, "salvager")) {
248 programType = salvager;
249 } else if (!strcmp(ti->data, "salvageServer")) {
250 programType = salvageServer;
252 programType = (ProgramType) atoi(ti->data);
262 common_volop_prolog(struct cmd_syndesc * as, struct state * state)
264 register struct cmd_item *ti;
266 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
267 assert(state->vop != NULL);
269 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET].items)) { /* -volumeid */
270 state->vop->volume = atoi(ti->data);
272 fprintf(stderr, "required argument -volumeid not given\n");
275 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+1].items)) { /* -partition */
276 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
278 memset(state->vop->partName, 0, sizeof(state->vop->partName));
285 do_volop(struct state * state, afs_int32 command, SYNC_response * res)
288 SYNC_PROTO_BUF_DECL(res_buf);
293 res->payload.len = SYNC_PROTO_MAX_LEN;
294 res->payload.buf = res_buf;
297 fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n",
298 command, command_code_to_string(command));
300 code = FSYNC_VolOp(state->vop->volume,
301 state->vop->partName,
311 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
314 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
315 fprintf(stderr, "protocol response code was %d (%s)\n",
316 res->hdr.response, response_code_to_string(res->hdr.response));
317 fprintf(stderr, "protocol reason code was %d (%s)\n",
318 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);
661 #ifdef AFS_DEMAND_ATTACH_FS
665 res.hdr.response_len = sizeof(res.hdr);
666 res.payload.buf = res_buf;
667 res.payload.len = SYNC_PROTO_MAX_LEN;
669 common_prolog(as, &state);
670 common_volop_prolog(as, &state);
672 do_volop(&state, FSYNC_VOL_QUERY, &res);
674 if (res.hdr.response == SYNC_OK) {
675 memcpy(&v, res.payload.buf, sizeof(Volume));
677 printf("volume = {\n");
678 printf("\thashid = %u\n", v.hashid);
679 printf("\theader = %p\n", v.header);
680 printf("\tdevice = %d\n", v.device);
681 printf("\tpartition = %p\n", v.partition);
682 printf("\tlinkHandle = %p\n", v.linkHandle);
683 printf("\tnextVnodeUnique = %u\n", v.nextVnodeUnique);
684 printf("\tdiskDataHandle = %p\n", v.diskDataHandle);
685 printf("\tvnodeHashOffset = %u\n", v.vnodeHashOffset);
686 printf("\tshuttingDown = %d\n", v.shuttingDown);
687 printf("\tgoingOffline = %d\n", v.goingOffline);
688 printf("\tcacheCheck = %u\n", v.cacheCheck);
689 printf("\tnUsers = %d\n", v.nUsers);
690 printf("\tneedsPutBack = %d\n", v.needsPutBack);
691 printf("\tspecialStatus = %d\n", v.specialStatus);
692 printf("\tupdateTime = %u\n", v.updateTime);
694 printf("\tvnodeIndex[vSmall] = {\n");
695 printf("\t\thandle = %p\n", v.vnodeIndex[vSmall].handle);
696 printf("\t\tbitmap = %p\n", v.vnodeIndex[vSmall].bitmap);
697 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vSmall].bitmapSize);
698 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vSmall].bitmapOffset);
700 printf("\tvnodeIndex[vLarge] = {\n");
701 printf("\t\thandle = %p\n", v.vnodeIndex[vLarge].handle);
702 printf("\t\tbitmap = %p\n", v.vnodeIndex[vLarge].bitmap);
703 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vLarge].bitmapSize);
704 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vLarge].bitmapOffset);
706 #ifdef AFS_DEMAND_ATTACH_FS
707 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
708 printf("\tupdateTime = %u\n", v.updateTime);
709 printf("\tattach_state = %s\n", vol_state_to_string(v.attach_state));
710 printf("\tattach_flags = %s\n", vol_flags_to_string(v.attach_flags));
711 printf("\tnWaiters = %d\n", v.nWaiters);
712 printf("\tchainCacheCheck = %d\n", v.chainCacheCheck);
714 /* online salvage structure */
715 printf("\tsalvage = {\n");
716 printf("\t\tprio = %u\n", v.salvage.prio);
717 printf("\t\treason = %d\n", v.salvage.reason);
718 printf("\t\trequested = %d\n", v.salvage.requested);
719 printf("\t\tscheduled = %d\n", v.salvage.scheduled);
722 /* statistics structure */
723 printf("\tstats = {\n");
725 printf("\t\thash_lookups = {\n");
726 SplitInt64(v.stats.hash_lookups,hi,lo);
727 printf("\t\t\thi = %u\n", hi);
728 printf("\t\t\tlo = %u\n", lo);
731 printf("\t\thash_short_circuits = {\n");
732 SplitInt64(v.stats.hash_short_circuits,hi,lo);
733 printf("\t\t\thi = %u\n", hi);
734 printf("\t\t\tlo = %u\n", lo);
737 printf("\t\thdr_loads = {\n");
738 SplitInt64(v.stats.hdr_loads,hi,lo);
739 printf("\t\t\thi = %u\n", hi);
740 printf("\t\t\tlo = %u\n", lo);
743 printf("\t\thdr_gets = {\n");
744 SplitInt64(v.stats.hdr_gets,hi,lo);
745 printf("\t\t\thi = %u\n", hi);
746 printf("\t\t\tlo = %u\n", lo);
749 printf("\t\tattaches = %u\n", v.stats.attaches);
750 printf("\t\tsoft_detaches = %u\n", v.stats.soft_detaches);
751 printf("\t\tsalvages = %u\n", v.stats.salvages);
752 printf("\t\tvol_ops = %u\n", v.stats.vol_ops);
754 printf("\t\tlast_attach = %u\n", v.stats.last_attach);
755 printf("\t\tlast_get = %u\n", v.stats.last_get);
756 printf("\t\tlast_promote = %u\n", v.stats.last_promote);
757 printf("\t\tlast_hdr_get = %u\n", v.stats.last_hdr_get);
758 printf("\t\tlast_hdr_load = %u\n", v.stats.last_hdr_load);
759 printf("\t\tlast_salvage = %u\n", v.stats.last_salvage);
760 printf("\t\tlast_salvage_req = %u\n", v.stats.last_salvage_req);
761 printf("\t\tlast_vol_op = %u\n", v.stats.last_vol_op);
765 printf("\tvlru = {\n");
766 printf("\t\tidx = %d (%s)\n",
767 v.vlru.idx, vlru_idx_to_string(v.vlru.idx));
770 /* volume op state */
771 printf("\tpending_vol_op = %p\n", v.pending_vol_op);
773 #else /* !AFS_DEMAND_ATTACH_FS */
774 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
775 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
776 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
777 printf("*** to dump dafs extended state\n");
779 #endif /* !AFS_DEMAND_ATTACH_FS */
787 VolHdrQuery(struct cmd_syndesc * as, void * rock)
790 SYNC_PROTO_BUF_DECL(res_buf);
795 res.hdr.response_len = sizeof(res.hdr);
796 res.payload.buf = res_buf;
797 res.payload.len = SYNC_PROTO_MAX_LEN;
799 common_prolog(as, &state);
800 common_volop_prolog(as, &state);
802 do_volop(&state, FSYNC_VOL_QUERY_HDR, &res);
804 if (res.hdr.response == SYNC_OK) {
805 memcpy(&v, res.payload.buf, sizeof(VolumeDiskData));
807 printf("VolumeDiskData = {\n");
808 printf("\tstamp = {\n");
809 printf("\t\tmagic = 0x%x\n", v.stamp.magic);
810 printf("\t\tversion = %u\n", v.stamp.version);
813 printf("\tid = %u\n", v.id);
814 printf("\tname = '%s'\n", v.name);
816 printf("\tinUse = %d (%s)\n", v.inUse, program_type_to_string(v.inUse));
818 printf("\tinUse = %d (no)\n", v.inUse);
820 printf("\tinService = %d\n", v.inService);
821 printf("\tblessed = %d\n", v.blessed);
822 printf("\tneedsSalvaged = %d\n", v.needsSalvaged);
823 printf("\tuniquifier = %u\n", v.uniquifier);
824 printf("\ttype = %d\n", v.type);
825 printf("\tparentId = %u\n", v.parentId);
826 printf("\tcloneId = %u\n", v.cloneId);
827 printf("\tbackupId = %u\n", v.backupId);
828 printf("\trestoredFromId = %u\n", v.restoredFromId);
829 printf("\tneedsCallback = %d\n", v.needsCallback);
830 printf("\tdestroyMe = %d\n", v.destroyMe);
831 printf("\tdontSalvage = %d\n", v.dontSalvage);
832 printf("\tmaxquota = %d\n", v.maxquota);
833 printf("\tminquota = %d\n", v.minquota);
834 printf("\tmaxfiles = %d\n", v.maxfiles);
835 printf("\taccountNumber = %u\n", v.accountNumber);
836 printf("\towner = %u\n", v.owner);
837 printf("\tfilecount = %d\n", v.filecount);
838 printf("\tdiskused = %d\n", v.diskused);
839 printf("\tdayUse = %d\n", v.dayUse);
840 for (i = 0; i < 7; i++) {
841 printf("\tweekUse[%d] = %d\n", i, v.weekUse[i]);
843 printf("\tdayUseDate = %u\n", v.dayUseDate);
844 printf("\tcreationDate = %u\n", v.creationDate);
845 printf("\taccessDate = %u\n", v.accessDate);
846 printf("\tupdateDate = %u\n", v.updateDate);
847 printf("\texpirationDate = %u\n", v.expirationDate);
848 printf("\tbackupDate = %u\n", v.backupDate);
849 printf("\tcopyDate = %u\n", v.copyDate);
850 #ifdef OPENAFS_VOL_STATS
851 printf("\tstat_initialized = %d\n", v.stat_initialized);
853 printf("\tmtd = '%s'\n", v.motd);
862 VolOpQuery(struct cmd_syndesc * as, void * rock)
865 SYNC_PROTO_BUF_DECL(res_buf);
867 FSSYNC_VolOp_info vop;
869 res.hdr.response_len = sizeof(res.hdr);
870 res.payload.buf = res_buf;
871 res.payload.len = SYNC_PROTO_MAX_LEN;
873 common_prolog(as, &state);
874 common_volop_prolog(as, &state);
876 do_volop(&state, FSYNC_VOL_QUERY_VOP, &res);
878 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
879 printf("*** file server not compiled with demand attach extensions.\n");
880 printf("*** pending volume operation metadata not available.\n");
883 if (res.hdr.response == SYNC_OK) {
884 memcpy(&vop, res.payload.buf, sizeof(FSSYNC_VolOp_info));
886 printf("pending_vol_op = {\n");
888 printf("\tcom = {\n");
889 printf("\t\tproto_version = %u\n", vop.com.proto_version);
890 printf("\t\tpkt_seq = %u\n", vop.com.pkt_seq);
891 printf("\t\tcom_seq = %u\n", vop.com.com_seq);
892 printf("\t\tprogramType = %d (%s)\n",
893 vop.com.programType, program_type_to_string(vop.com.programType));
894 printf("\t\tpid = %d\n", vop.com.pid);
895 printf("\t\ttid = %d\n", vop.com.tid);
896 printf("\t\tcommand = %d (%s)\n",
897 vop.com.command, command_code_to_string(vop.com.command));
898 printf("\t\treason = %d (%s)\n",
899 vop.com.reason, reason_code_to_string(vop.com.reason));
900 printf("\t\tcommand_len = %u\n", vop.com.command_len);
901 printf("\t\tflags = 0x%lux\n", afs_cast_uint32(vop.com.flags));
904 printf("\tvop = {\n");
905 printf("\t\tvolume = %u\n", vop.vop.volume);
906 if (afs_strnlen(vop.vop.partName, sizeof(vop.vop.partName)) <
907 sizeof(vop.vop.partName)) {
908 printf("\t\tpartName = '%s'\n", vop.vop.partName);
910 printf("\t\tpartName = (illegal string)\n");
921 vn_prolog(struct cmd_syndesc * as, struct state * state)
923 register struct cmd_item *ti;
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);
1000 res.hdr.response_len = sizeof(res.hdr);
1001 res.payload.buf = res_buf;
1002 res.payload.len = SYNC_PROTO_MAX_LEN;
1004 common_prolog(as, &state);
1005 vn_prolog(as, &state);
1007 do_vnqry(&state, &res);
1009 if (res.hdr.response == SYNC_OK) {
1010 memcpy(&v, res.payload.buf, sizeof(Volume));
1012 printf("vnode = {\n");
1014 printf("\tvid_hash = {\n");
1015 printf("\t\tnext = %p\n", v.vid_hash.next);
1016 printf("\t\tprev = %p\n", v.vid_hash.prev);
1019 printf("\thashNext = %p\n", v.hashNext);
1020 printf("\tlruNext = %p\n", v.lruNext);
1021 printf("\tlruPrev = %p\n", v.lruPrev);
1022 printf("\thashIndex = %hu\n", v.hashIndex);
1023 printf("\tchanged_newTime = %u\n", (unsigned int) v.changed_newTime);
1024 printf("\tchanged_oldTime = %u\n", (unsigned int) v.changed_oldTime);
1025 printf("\tdelete = %u\n", (unsigned int) v.delete);
1026 printf("\tvnodeNumber = %u\n", v.vnodeNumber);
1027 printf("\tvolumePtr = %p\n", v.volumePtr);
1028 printf("\tnUsers = %u\n", v.nUsers);
1029 printf("\tcacheCheck = %u\n", v.cacheCheck);
1031 #ifdef AFS_DEMAND_ATTACH_FS
1032 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
1033 printf("*** fssync-debug built to expect demand attach extensions. server asserted\n");
1034 printf("*** that it was not compiled with demand attach turned on. please recompile\n");
1035 printf("*** fssync-debug to match your server\n");
1039 printf("\tnReaders = %u\n", v.nReaders);
1040 printf("\tvn_state_flags = %s\n", vn_flags_to_string(v.vn_state_flags));
1041 printf("\tvn_state = %s\n", vn_state_to_string(v.vn_state));
1043 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
1044 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
1045 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
1046 printf("*** to dump dafs extended state\n");
1049 #endif /* !AFS_DEMAND_ATTACH_FS */
1051 printf("\twriter = %u\n", (unsigned int) v.writer);
1052 printf("\tvcp = %p\n", v.vcp);
1053 printf("\thandle = %p\n", v.handle);
1055 printf("\tdisk = {\n");
1056 printf("\t\ttype = %u\n", v.disk.type);
1057 printf("\t\tcloned = %u\n", v.disk.cloned);
1058 printf("\t\tmodeBits = %u\n", v.disk.modeBits);
1059 printf("\t\tlinkCount = %d\n", v.disk.linkCount);
1060 printf("\t\tlength = %u\n", v.disk.length);
1061 printf("\t\tuniquifier = %u\n", v.disk.uniquifier);
1062 printf("\t\tdataVersion = %u\n", v.disk.dataVersion);
1063 printf("\t\tvn_ino_lo = %u\n", v.disk.vn_ino_lo);
1064 printf("\t\tunixModifyTime = %u\n", v.disk.unixModifyTime);
1065 printf("\t\tauthor = %u\n", v.disk.author);
1066 printf("\t\towner = %u\n", v.disk.owner);
1067 printf("\t\tparent = %u\n", v.disk.parent);
1068 printf("\t\tvnodeMagic = %u\n", v.disk.vnodeMagic);
1070 printf("\t\tlock = {\n");
1071 printf("\t\t\tlockCount = %d\n", v.disk.lock.lockCount);
1072 printf("\t\t\tlockTime = %d\n", v.disk.lock.lockTime);
1075 printf("\t\tserverModifyTime = %u\n", v.disk.serverModifyTime);
1076 printf("\t\tgroup = %d\n", v.disk.group);
1077 printf("\t\tvn_ino_hi = %d\n", v.disk.vn_ino_hi);
1078 printf("\t\tvn_length_hi = %u\n", v.disk.vn_length_hi);
1090 StatsQuery(struct cmd_syndesc * as, void * rock)
1094 struct cmd_item *ti;
1096 SYNC_PROTO_BUF_DECL(res_buf);
1098 FSSYNC_StatsOp_hdr scom;
1101 struct VolPkgStats * vol_stats;
1102 struct VolumeHashChainStats * hash_stats;
1103 #ifdef AFS_DEMAND_ATTACH_FS
1104 struct volume_hdr_LRU_stats * hdr_stats;
1106 struct DiskPartitionStats64 * vicep_stats;
1110 res.hdr.response_len = sizeof(res.hdr);
1111 res.payload.buf = res_buf;
1112 res.payload.len = SYNC_PROTO_MAX_LEN;
1114 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -subcommand */
1115 if (!strcasecmp(ti->data, "vicep")) {
1116 command = FSYNC_VOL_STATS_VICEP;
1117 } else if (!strcasecmp(ti->data, "hash")) {
1118 command = FSYNC_VOL_STATS_HASH;
1119 #ifdef AFS_DEMAND_ATTACH_FS
1120 } else if (!strcasecmp(ti->data, "hdr")) {
1121 command = FSYNC_VOL_STATS_HDR;
1122 } else if (!strcasecmp(ti->data, "vlru")) {
1123 command = FSYNC_VOL_STATS_VLRU;
1125 } else if (!strcasecmp(ti->data, "pkg")) {
1126 command = FSYNC_VOL_STATS_GENERAL;
1127 } else if (!strcasecmp(ti->data, "help")) {
1128 fprintf(stderr, "fssync-debug stats subcommands:\n");
1129 fprintf(stderr, "\tpkg\tgeneral volume package stats\n");
1130 fprintf(stderr, "\tvicep\tvice partition stats\n");
1131 fprintf(stderr, "\thash\tvolume hash chain stats\n");
1132 #ifdef AFS_DEMAND_ATTACH_FS
1133 fprintf(stderr, "\thdr\tvolume header cache stats\n");
1134 fprintf(stderr, "\tvlru\tvlru generation stats\n");
1138 fprintf(stderr, "invalid stats subcommand");
1142 command = FSYNC_VOL_STATS_GENERAL;
1145 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -arg1 */
1147 case FSYNC_VOL_STATS_VICEP:
1148 strlcpy(scom.args.partName, ti->data, sizeof(state.vop->partName));
1150 case FSYNC_VOL_STATS_HASH:
1151 scom.args.hash_bucket = atoi(ti->data);
1153 case FSYNC_VOL_STATS_VLRU:
1154 scom.args.vlru_generation = atoi(ti->data);
1157 fprintf(stderr, "unrecognized arguments\n");
1162 case FSYNC_VOL_STATS_VICEP:
1163 case FSYNC_VOL_STATS_HASH:
1164 case FSYNC_VOL_STATS_VLRU:
1165 fprintf(stderr, "this subcommand requires more parameters\n");
1170 common_prolog(as, &state);
1172 fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
1173 command, command_code_to_string(command));
1175 code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
1182 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
1185 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
1186 fprintf(stderr, "protocol response code was %d (%s)\n",
1187 res.hdr.response, response_code_to_string(res.hdr.response));
1188 fprintf(stderr, "protocol reason code was %d (%s)\n",
1189 res.hdr.reason, reason_code_to_string(res.hdr.reason));
1193 if (res.hdr.response == SYNC_OK) {
1195 case FSYNC_VOL_STATS_GENERAL:
1196 print_vol_stats_general(sres.vol_stats);
1198 case FSYNC_VOL_STATS_VICEP:
1199 print_vol_stats_viceP(sres.vicep_stats);
1201 case FSYNC_VOL_STATS_HASH:
1202 print_vol_stats_hash(sres.hash_stats);
1204 #ifdef AFS_DEMAND_ATTACH_FS
1205 case FSYNC_VOL_STATS_HDR:
1206 print_vol_stats_hdr(sres.hdr_stats);
1208 #endif /* AFS_DEMAND_ATTACH_FS */
1216 print_vol_stats_general(VolPkgStats * stats)
1218 #ifdef AFS_DEMAND_ATTACH_FS
1223 printf("VolPkgStats = {\n");
1224 #ifdef AFS_DEMAND_ATTACH_FS
1225 for (i = 0; i < VOL_STATE_COUNT; i++) {
1226 printf("\tvol_state_count[%s] = %d\n",
1227 vol_state_to_string(i),
1228 stats->state_levels[i]);
1231 SplitInt64(stats->hash_looks, hi, lo);
1232 printf("\thash_looks = {\n");
1233 printf("\t\thi = %u\n", hi);
1234 printf("\t\tlo = %u\n", lo);
1237 SplitInt64(stats->hash_reorders, hi, lo);
1238 printf("\thash_reorders = {\n");
1239 printf("\t\thi = %u\n", hi);
1240 printf("\t\tlo = %u\n", lo);
1243 SplitInt64(stats->salvages, hi, lo);
1244 printf("\tsalvages = {\n");
1245 printf("\t\thi = %u\n", hi);
1246 printf("\t\tlo = %u\n", lo);
1249 SplitInt64(stats->vol_ops, hi, lo);
1250 printf("\tvol_ops = {\n");
1251 printf("\t\thi = %u\n", hi);
1252 printf("\t\tlo = %u\n", lo);
1255 SplitInt64(stats->hdr_loads, hi, lo);
1256 printf("\thdr_loads = {\n");
1257 printf("\t\thi = %u\n", hi);
1258 printf("\t\tlo = %u\n", lo);
1261 SplitInt64(stats->hdr_gets, hi, lo);
1262 printf("\thdr_gets = {\n");
1263 printf("\t\thi = %u\n", hi);
1264 printf("\t\tlo = %u\n", lo);
1267 SplitInt64(stats->attaches, hi, lo);
1268 printf("\tattaches = {\n");
1269 printf("\t\thi = %u\n", hi);
1270 printf("\t\tlo = %u\n", lo);
1273 SplitInt64(stats->soft_detaches, hi, lo);
1274 printf("\tsoft_detaches = {\n");
1275 printf("\t\thi = %u\n", hi);
1276 printf("\t\tlo = %u\n", lo);
1279 printf("\thdr_cache_size = %d\n", stats->hdr_cache_size);
1285 print_vol_stats_viceP(struct DiskPartitionStats64 * stats)
1287 printf("DiskPartitionStats64 = {\n");
1288 printf("\tfree = %" AFS_INT64_FMT "\n", stats->free);
1289 printf("\tminFree = %" AFS_INT64_FMT "\n", stats->minFree);
1290 printf("\ttotalUsable = %" AFS_INT64_FMT "\n", stats->totalUsable);
1291 printf("\tf_files = %" AFS_INT64_FMT "\n", stats->f_files);
1292 #ifdef AFS_DEMAND_ATTACH_FS
1293 printf("\tvol_list_len = %d\n", stats->vol_list_len);
1299 print_vol_stats_hash(struct VolumeHashChainStats * stats)
1301 #ifdef AFS_DEMAND_ATTACH_FS
1305 printf("DiskPartitionStats = {\n");
1306 printf("\ttable_size = %d\n", stats->table_size);
1307 printf("\tchain_len = %d\n", stats->chain_len);
1309 #ifdef AFS_DEMAND_ATTACH_FS
1310 printf("\tchain_cacheCheck = %d\n", stats->chain_cacheCheck);
1311 printf("\tchain_busy = %d\n", stats->chain_busy);
1313 SplitInt64(stats->chain_looks, hi, lo);
1314 printf("\tchain_looks = {\n");
1315 printf("\t\thi = %u\n", hi);
1316 printf("\t\tlo = %u\n", lo);
1319 SplitInt64(stats->chain_gets, hi, lo);
1320 printf("\tchain_gets = {\n");
1321 printf("\t\thi = %u\n", hi);
1322 printf("\t\tlo = %u\n", lo);
1325 SplitInt64(stats->chain_reorders, hi, lo);
1326 printf("\tchain_reorders = {\n");
1327 printf("\t\thi = %u\n", hi);
1328 printf("\t\tlo = %u\n", lo);
1330 #endif /* AFS_DEMAND_ATTACH_FS */
1336 #ifdef AFS_DEMAND_ATTACH_FS
1338 print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats)
1340 printf("volume_hdr_LRU_stats = {\n");
1341 printf("\tfree = %d\n", stats->free);
1342 printf("\tused = %d\n", stats->used);
1343 printf("\tattached = %d\n", stats->attached);
1346 #endif /* AFS_DEMAND_ATTACH_FS */