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>
31 #include <WINNT/afsevent.h>
33 #include <sys/param.h>
37 #endif /* ITIMER_REAL */
40 #include <afs/afsint.h>
41 #include <afs/assert.h>
47 #include <afs/osi_inode.h>
52 #include <afs/afsutil.h>
53 #include <afs/fileutil.h>
61 #include "partition.h"
62 #include "daemon_com.h"
68 int VolumeChanged; /* hack to make dir package happy */
80 struct volop_state * vop;
83 static int common_prolog(struct cmd_syndesc *, struct state *);
84 static int common_volop_prolog(struct cmd_syndesc *, struct state *);
86 static int do_volop(struct state *, afs_int32 command, SYNC_response * res);
88 static char * response_code_to_string(afs_int32);
89 static char * command_code_to_string(afs_int32);
90 static char * reason_code_to_string(afs_int32);
91 static char * program_type_to_string(afs_int32);
93 static int VolOnline(struct cmd_syndesc * as, void * rock);
94 static int VolOffline(struct cmd_syndesc * as, void * rock);
95 static int VolMode(struct cmd_syndesc * as, void * rock);
96 static int VolDetach(struct cmd_syndesc * as, void * rock);
97 static int VolBreakCBKs(struct cmd_syndesc * as, void * rock);
98 static int VolMove(struct cmd_syndesc * as, void * rock);
99 static int VolList(struct cmd_syndesc * as, void * rock);
100 static int VolLeaveOff(struct cmd_syndesc * as, void * rock);
101 static int VolForceAttach(struct cmd_syndesc * as, void * rock);
102 static int VolForceError(struct cmd_syndesc * as, void * rock);
103 static int VolQuery(struct cmd_syndesc * as, void * rock);
104 static int VolHdrQuery(struct cmd_syndesc * as, void * rock);
105 static int VolOpQuery(struct cmd_syndesc * as, void * rock);
106 static int StatsQuery(struct cmd_syndesc * as, void * rock);
107 static int VnQuery(struct cmd_syndesc * as, void * rock);
109 static void print_vol_stats_general(VolPkgStats * stats);
110 static void print_vol_stats_viceP(struct DiskPartitionStats64 * stats);
111 static void print_vol_stats_hash(struct VolumeHashChainStats * stats);
112 #ifdef AFS_DEMAND_ATTACH_FS
113 static void print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats);
117 #include "AFS_component_version_number.c"
121 #define COMMON_PARMS_OFFSET 12
122 #define COMMON_PARMS(ts) \
123 cmd_Seek(ts, COMMON_PARMS_OFFSET); \
124 cmd_AddParm(ts, "-reason", CMD_SINGLE, CMD_OPTIONAL, "sync protocol reason code"); \
125 cmd_AddParm(ts, "-programtype", CMD_SINGLE, CMD_OPTIONAL, "program type code")
127 #define COMMON_VOLOP_PARMS_OFFSET 10
128 #define COMMON_VOLOP_PARMS(ts) \
129 cmd_Seek(ts, COMMON_VOLOP_PARMS_OFFSET); \
130 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id"); \
131 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name")
133 #define CUSTOM_PARMS_OFFSET 1
136 #define VOLOP_PARMS_DECL(ts) \
137 COMMON_VOLOP_PARMS(ts); \
139 #define COMMON_PARMS_DECL(ts) \
143 main(int argc, char **argv)
145 struct cmd_syndesc *ts;
148 /* Initialize directory paths */
149 if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) {
151 ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0);
153 fprintf(stderr, "%s: Unable to obtain AFS server directory.\n",
159 ts = cmd_CreateSyntax("online", VolOnline, NULL, "bring a volume online (FSYNC_VOL_ON opcode)");
160 VOLOP_PARMS_DECL(ts);
162 ts = cmd_CreateSyntax("offline", VolOffline, NULL, "take a volume offline (FSYNC_VOL_OFF opcode)");
163 VOLOP_PARMS_DECL(ts);
165 ts = cmd_CreateSyntax("mode", VolMode, NULL, "change volume attach mode (FSYNC_VOL_NEEDVOLUME opcode)");
166 VOLOP_PARMS_DECL(ts);
167 cmd_CreateAlias(ts, "needvolume");
169 ts = cmd_CreateSyntax("detach", VolDetach, NULL, "detach a volume (FSYNC_VOL_DONE opcode)");
170 VOLOP_PARMS_DECL(ts);
172 ts = cmd_CreateSyntax("callback", VolBreakCBKs, NULL, "break callbacks for volume (FSYNC_VOL_BREAKCBKS opcode)");
173 VOLOP_PARMS_DECL(ts);
174 cmd_CreateAlias(ts, "cbk");
176 ts = cmd_CreateSyntax("move", VolMove, NULL, "set volume moved flag (FSYNC_VOL_MOVE opcode)");
177 VOLOP_PARMS_DECL(ts);
179 ts = cmd_CreateSyntax("list", VolList, NULL, "sync local volume list (FSYNC_VOL_LISTVOLUMES opcode)");
180 VOLOP_PARMS_DECL(ts);
181 cmd_CreateAlias(ts, "ls");
183 ts = cmd_CreateSyntax("leaveoff", VolLeaveOff, 0, "leave volume offline (FSYNC_VOL_LEAVE_OFF opcode)");
184 VOLOP_PARMS_DECL(ts);
186 ts = cmd_CreateSyntax("attach", VolForceAttach, 0, "force full attachment (FSYNC_VOL_ATTACH opcode)");
187 VOLOP_PARMS_DECL(ts);
189 ts = cmd_CreateSyntax("error", VolForceError, 0, "force into hard error state (FSYNC_VOL_FORCE_ERROR opcode)");
190 VOLOP_PARMS_DECL(ts);
192 ts = cmd_CreateSyntax("query", VolQuery, NULL, "get volume structure (FSYNC_VOL_QUERY opcode)");
193 VOLOP_PARMS_DECL(ts);
194 cmd_CreateAlias(ts, "qry");
196 ts = cmd_CreateSyntax("header", VolHdrQuery, NULL, "get volume disk data structure (FSYNC_VOL_QUERY_HDR opcode)");
197 VOLOP_PARMS_DECL(ts);
198 cmd_CreateAlias(ts, "hdr");
200 ts = cmd_CreateSyntax("volop", VolOpQuery, NULL, "get pending volume operation info (FSYNC_VOL_QUERY_VOP opcode)");
201 VOLOP_PARMS_DECL(ts);
202 cmd_CreateAlias(ts, "vop");
204 ts = cmd_CreateSyntax("vnode", VnQuery, NULL, "get vnode structure (FSYNC_VOL_QUERY_VNODE opcode)");
205 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
206 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
207 cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id");
208 cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier");
209 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "paritition name");
210 COMMON_PARMS_DECL(ts);
212 ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information");
213 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
214 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "subcommand");
215 cmd_AddParm(ts, "-arg1", CMD_SINGLE, CMD_OPTIONAL, "arg1");
216 cmd_AddParm(ts, "-arg2", CMD_SINGLE, CMD_OPTIONAL, "arg2");
217 COMMON_PARMS_DECL(ts);
219 err = cmd_Dispatch(argc, argv);
224 common_prolog(struct cmd_syndesc * as, struct state * state)
226 register struct cmd_item *ti;
229 if (afs_winsockInit() < 0) {
234 VInitVolumePackage(debugUtility, 1, 1,
238 if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) { /* -reason */
239 state->reason = atoi(ti->data);
241 if ((ti = as->parms[COMMON_PARMS_OFFSET+1].items)) { /* -programtype */
242 if (!strcmp(ti->data, "fileServer")) {
243 programType = fileServer;
244 } else if (!strcmp(ti->data, "volumeUtility")) {
245 programType = volumeUtility;
246 } else if (!strcmp(ti->data, "salvager")) {
247 programType = salvager;
248 } else if (!strcmp(ti->data, "salvageServer")) {
249 programType = salvageServer;
251 programType = (ProgramType) atoi(ti->data);
261 common_volop_prolog(struct cmd_syndesc * as, struct state * state)
263 register struct cmd_item *ti;
265 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
266 assert(state->vop != NULL);
268 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET].items)) { /* -volumeid */
269 state->vop->volume = atoi(ti->data);
271 fprintf(stderr, "required argument -volumeid not given\n");
274 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+1].items)) { /* -partition */
275 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
277 memset(state->vop->partName, 0, sizeof(state->vop->partName));
284 do_volop(struct state * state, afs_int32 command, SYNC_response * res)
287 SYNC_PROTO_BUF_DECL(res_buf);
292 res->payload.len = SYNC_PROTO_MAX_LEN;
293 res->payload.buf = res_buf;
296 fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n",
297 command, command_code_to_string(command));
299 code = FSYNC_VolOp(state->vop->volume,
300 state->vop->partName,
310 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
313 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
314 fprintf(stderr, "protocol response code was %d (%s)\n",
315 res->hdr.response, response_code_to_string(res->hdr.response));
316 fprintf(stderr, "protocol reason code was %d (%s)\n",
317 res->hdr.reason, reason_code_to_string(res->hdr.reason));
326 #define ENUMTOSTRING(en) #en
327 #define ENUMCASE(en) \
329 return ENUMTOSTRING(en); \
332 #define FLAGTOSTRING(fl) #fl
333 #define FLAGCASE(bitstr, fl, str, count) \
335 if ((bitstr) & (fl)) { \
337 strlcat((str), " | ", sizeof(str)); \
338 strlcat((str), FLAGTOSTRING(fl), sizeof(str)); \
344 response_code_to_string(afs_int32 response)
348 ENUMCASE(SYNC_DENIED);
349 ENUMCASE(SYNC_COM_ERROR);
350 ENUMCASE(SYNC_BAD_COMMAND);
351 ENUMCASE(SYNC_FAILED);
353 return "**UNKNOWN**";
358 command_code_to_string(afs_int32 command)
361 ENUMCASE(SYNC_COM_CHANNEL_CLOSE);
362 ENUMCASE(FSYNC_VOL_ON);
363 ENUMCASE(FSYNC_VOL_OFF);
364 ENUMCASE(FSYNC_VOL_LISTVOLUMES);
365 ENUMCASE(FSYNC_VOL_NEEDVOLUME);
366 ENUMCASE(FSYNC_VOL_MOVE);
367 ENUMCASE(FSYNC_VOL_BREAKCBKS);
368 ENUMCASE(FSYNC_VOL_DONE);
369 ENUMCASE(FSYNC_VOL_QUERY);
370 ENUMCASE(FSYNC_VOL_QUERY_HDR);
371 ENUMCASE(FSYNC_VOL_QUERY_VOP);
372 ENUMCASE(FSYNC_VOL_STATS_GENERAL);
373 ENUMCASE(FSYNC_VOL_STATS_VICEP);
374 ENUMCASE(FSYNC_VOL_STATS_HASH);
375 ENUMCASE(FSYNC_VOL_STATS_HDR);
376 ENUMCASE(FSYNC_VOL_STATS_VLRU);
377 ENUMCASE(FSYNC_VOL_ATTACH);
378 ENUMCASE(FSYNC_VOL_FORCE_ERROR);
379 ENUMCASE(FSYNC_VOL_LEAVE_OFF);
380 ENUMCASE(FSYNC_VOL_QUERY_VNODE);
382 return "**UNKNOWN**";
387 reason_code_to_string(afs_int32 reason)
390 ENUMCASE(SYNC_REASON_NONE);
391 ENUMCASE(SYNC_REASON_MALFORMED_PACKET);
392 ENUMCASE(SYNC_REASON_NOMEM);
393 ENUMCASE(SYNC_REASON_ENCODING_ERROR);
394 ENUMCASE(FSYNC_WHATEVER);
395 ENUMCASE(FSYNC_SALVAGE);
396 ENUMCASE(FSYNC_MOVE);
397 ENUMCASE(FSYNC_OPERATOR);
398 ENUMCASE(FSYNC_EXCLUSIVE);
399 ENUMCASE(FSYNC_UNKNOWN_VOLID);
400 ENUMCASE(FSYNC_HDR_NOT_ATTACHED);
401 ENUMCASE(FSYNC_NO_PENDING_VOL_OP);
402 ENUMCASE(FSYNC_VOL_PKG_ERROR);
403 ENUMCASE(FSYNC_UNKNOWN_VNID);
405 return "**UNKNOWN**";
410 program_type_to_string(afs_int32 type)
412 switch ((ProgramType)type) {
413 ENUMCASE(fileServer);
414 ENUMCASE(volumeUtility);
416 ENUMCASE(salvageServer);
417 ENUMCASE(debugUtility);
419 return "**UNKNOWN**";
424 VolOnline(struct cmd_syndesc * as, void * rock)
428 common_prolog(as, &state);
429 common_volop_prolog(as, &state);
431 do_volop(&state, FSYNC_VOL_ON, NULL);
437 VolOffline(struct cmd_syndesc * as, void * rock)
441 common_prolog(as, &state);
442 common_volop_prolog(as, &state);
444 do_volop(&state, FSYNC_VOL_OFF, NULL);
450 VolMode(struct cmd_syndesc * as, void * rock)
454 common_prolog(as, &state);
455 common_volop_prolog(as, &state);
457 do_volop(&state, FSYNC_VOL_NEEDVOLUME, NULL);
463 VolDetach(struct cmd_syndesc * as, void * rock)
467 common_prolog(as, &state);
468 common_volop_prolog(as, &state);
470 do_volop(&state, FSYNC_VOL_DONE, NULL);
476 VolBreakCBKs(struct cmd_syndesc * as, void * rock)
480 common_prolog(as, &state);
481 common_volop_prolog(as, &state);
483 do_volop(&state, FSYNC_VOL_BREAKCBKS, NULL);
489 VolMove(struct cmd_syndesc * as, void * rock)
493 common_prolog(as, &state);
494 common_volop_prolog(as, &state);
496 do_volop(&state, FSYNC_VOL_MOVE, NULL);
502 VolList(struct cmd_syndesc * as, void * rock)
506 common_prolog(as, &state);
507 common_volop_prolog(as, &state);
509 do_volop(&state, FSYNC_VOL_LISTVOLUMES, NULL);
515 VolLeaveOff(struct cmd_syndesc * as, void * rock)
519 common_prolog(as, &state);
520 common_volop_prolog(as, &state);
522 do_volop(&state, FSYNC_VOL_LEAVE_OFF, NULL);
528 VolForceAttach(struct cmd_syndesc * as, void * rock)
532 common_prolog(as, &state);
533 common_volop_prolog(as, &state);
535 do_volop(&state, FSYNC_VOL_ATTACH, NULL);
541 VolForceError(struct cmd_syndesc * as, void * rock)
545 common_prolog(as, &state);
546 common_volop_prolog(as, &state);
548 do_volop(&state, FSYNC_VOL_FORCE_ERROR, NULL);
553 #ifdef AFS_DEMAND_ATTACH_FS
555 vol_state_to_string(VolState state)
558 ENUMCASE(VOL_STATE_UNATTACHED);
559 ENUMCASE(VOL_STATE_PREATTACHED);
560 ENUMCASE(VOL_STATE_ATTACHING);
561 ENUMCASE(VOL_STATE_ATTACHED);
562 ENUMCASE(VOL_STATE_UPDATING);
563 ENUMCASE(VOL_STATE_GET_BITMAP);
564 ENUMCASE(VOL_STATE_HDR_LOADING);
565 ENUMCASE(VOL_STATE_HDR_ATTACHING);
566 ENUMCASE(VOL_STATE_SHUTTING_DOWN);
567 ENUMCASE(VOL_STATE_GOING_OFFLINE);
568 ENUMCASE(VOL_STATE_OFFLINING);
569 ENUMCASE(VOL_STATE_DETACHING);
570 ENUMCASE(VOL_STATE_SALVSYNC_REQ);
571 ENUMCASE(VOL_STATE_SALVAGING);
572 ENUMCASE(VOL_STATE_ERROR);
573 ENUMCASE(VOL_STATE_VNODE_ALLOC);
574 ENUMCASE(VOL_STATE_VNODE_GET);
575 ENUMCASE(VOL_STATE_VNODE_CLOSE);
576 ENUMCASE(VOL_STATE_VNODE_RELEASE);
577 ENUMCASE(VOL_STATE_VLRU_ADD);
578 ENUMCASE(VOL_STATE_FREED);
580 return "**UNKNOWN**";
585 vol_flags_to_string(afs_uint16 flags)
587 static char str[128];
591 FLAGCASE(flags, VOL_HDR_ATTACHED, str, count);
592 FLAGCASE(flags, VOL_HDR_LOADED, str, count);
593 FLAGCASE(flags, VOL_HDR_IN_LRU, str, count);
594 FLAGCASE(flags, VOL_IN_HASH, str, count);
595 FLAGCASE(flags, VOL_ON_VBYP_LIST, str, count);
596 FLAGCASE(flags, VOL_IS_BUSY, str, count);
597 FLAGCASE(flags, VOL_ON_VLRU, str, count);
598 FLAGCASE(flags, VOL_HDR_DONTSALV, str, count);
604 vlru_idx_to_string(int idx)
607 ENUMCASE(VLRU_QUEUE_NEW);
608 ENUMCASE(VLRU_QUEUE_MID);
609 ENUMCASE(VLRU_QUEUE_OLD);
610 ENUMCASE(VLRU_QUEUE_CANDIDATE);
611 ENUMCASE(VLRU_QUEUE_HELD);
612 ENUMCASE(VLRU_QUEUE_INVALID);
614 return "**UNKNOWN**";
620 vn_state_to_string(VnState state)
623 ENUMCASE(VN_STATE_INVALID);
624 ENUMCASE(VN_STATE_RELEASING);
625 ENUMCASE(VN_STATE_CLOSING);
626 ENUMCASE(VN_STATE_ALLOC);
627 ENUMCASE(VN_STATE_ONLINE);
628 ENUMCASE(VN_STATE_LOAD);
629 ENUMCASE(VN_STATE_EXCLUSIVE);
630 ENUMCASE(VN_STATE_STORE);
631 ENUMCASE(VN_STATE_READ);
632 ENUMCASE(VN_STATE_ERROR);
634 return "**UNKNOWN**";
639 vn_flags_to_string(afs_uint32 flags)
641 static char str[128];
645 FLAGCASE(flags, VN_ON_HASH, str, count);
646 FLAGCASE(flags, VN_ON_LRU, str, count);
647 FLAGCASE(flags, VN_ON_VVN, str, count);
654 VolQuery(struct cmd_syndesc * as, void * rock)
657 SYNC_PROTO_BUF_DECL(res_buf);
660 #ifdef AFS_DEMAND_ATTACH_FS
664 res.hdr.response_len = sizeof(res.hdr);
665 res.payload.buf = res_buf;
666 res.payload.len = SYNC_PROTO_MAX_LEN;
668 common_prolog(as, &state);
669 common_volop_prolog(as, &state);
671 do_volop(&state, FSYNC_VOL_QUERY, &res);
673 if (res.hdr.response == SYNC_OK) {
674 memcpy(&v, res.payload.buf, sizeof(Volume));
676 printf("volume = {\n");
677 printf("\thashid = %u\n", v.hashid);
678 printf("\theader = %p\n", v.header);
679 printf("\tdevice = %d\n", v.device);
680 printf("\tpartition = %p\n", v.partition);
681 printf("\tlinkHandle = %p\n", v.linkHandle);
682 printf("\tnextVnodeUnique = %u\n", v.nextVnodeUnique);
683 printf("\tdiskDataHandle = %p\n", v.diskDataHandle);
684 printf("\tvnodeHashOffset = %u\n", v.vnodeHashOffset);
685 printf("\tshuttingDown = %d\n", v.shuttingDown);
686 printf("\tgoingOffline = %d\n", v.goingOffline);
687 printf("\tcacheCheck = %u\n", v.cacheCheck);
688 printf("\tnUsers = %d\n", v.nUsers);
689 printf("\tneedsPutBack = %d\n", v.needsPutBack);
690 printf("\tspecialStatus = %d\n", v.specialStatus);
691 printf("\tupdateTime = %u\n", v.updateTime);
693 printf("\tvnodeIndex[vSmall] = {\n");
694 printf("\t\thandle = %p\n", v.vnodeIndex[vSmall].handle);
695 printf("\t\tbitmap = %p\n", v.vnodeIndex[vSmall].bitmap);
696 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vSmall].bitmapSize);
697 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vSmall].bitmapOffset);
699 printf("\tvnodeIndex[vLarge] = {\n");
700 printf("\t\thandle = %p\n", v.vnodeIndex[vLarge].handle);
701 printf("\t\tbitmap = %p\n", v.vnodeIndex[vLarge].bitmap);
702 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vLarge].bitmapSize);
703 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vLarge].bitmapOffset);
705 #ifdef AFS_DEMAND_ATTACH_FS
706 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
707 printf("\tupdateTime = %u\n", v.updateTime);
708 printf("\tattach_state = %s\n", vol_state_to_string(v.attach_state));
709 printf("\tattach_flags = %s\n", vol_flags_to_string(v.attach_flags));
710 printf("\tnWaiters = %d\n", v.nWaiters);
711 printf("\tchainCacheCheck = %d\n", v.chainCacheCheck);
713 /* online salvage structure */
714 printf("\tsalvage = {\n");
715 printf("\t\tprio = %u\n", v.salvage.prio);
716 printf("\t\treason = %d\n", v.salvage.reason);
717 printf("\t\trequested = %d\n", v.salvage.requested);
718 printf("\t\tscheduled = %d\n", v.salvage.scheduled);
721 /* statistics structure */
722 printf("\tstats = {\n");
724 printf("\t\thash_lookups = {\n");
725 SplitInt64(v.stats.hash_lookups,hi,lo);
726 printf("\t\t\thi = %u\n", hi);
727 printf("\t\t\tlo = %u\n", lo);
730 printf("\t\thash_short_circuits = {\n");
731 SplitInt64(v.stats.hash_short_circuits,hi,lo);
732 printf("\t\t\thi = %u\n", hi);
733 printf("\t\t\tlo = %u\n", lo);
736 printf("\t\thdr_loads = {\n");
737 SplitInt64(v.stats.hdr_loads,hi,lo);
738 printf("\t\t\thi = %u\n", hi);
739 printf("\t\t\tlo = %u\n", lo);
742 printf("\t\thdr_gets = {\n");
743 SplitInt64(v.stats.hdr_gets,hi,lo);
744 printf("\t\t\thi = %u\n", hi);
745 printf("\t\t\tlo = %u\n", lo);
748 printf("\t\tattaches = %u\n", v.stats.attaches);
749 printf("\t\tsoft_detaches = %u\n", v.stats.soft_detaches);
750 printf("\t\tsalvages = %u\n", v.stats.salvages);
751 printf("\t\tvol_ops = %u\n", v.stats.vol_ops);
753 printf("\t\tlast_attach = %u\n", v.stats.last_attach);
754 printf("\t\tlast_get = %u\n", v.stats.last_get);
755 printf("\t\tlast_promote = %u\n", v.stats.last_promote);
756 printf("\t\tlast_hdr_get = %u\n", v.stats.last_hdr_get);
757 printf("\t\tlast_hdr_load = %u\n", v.stats.last_hdr_load);
758 printf("\t\tlast_salvage = %u\n", v.stats.last_salvage);
759 printf("\t\tlast_salvage_req = %u\n", v.stats.last_salvage_req);
760 printf("\t\tlast_vol_op = %u\n", v.stats.last_vol_op);
764 printf("\tvlru = {\n");
765 printf("\t\tidx = %d (%s)\n",
766 v.vlru.idx, vlru_idx_to_string(v.vlru.idx));
769 /* volume op state */
770 printf("\tpending_vol_op = %p\n", v.pending_vol_op);
772 #else /* !AFS_DEMAND_ATTACH_FS */
773 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
774 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
775 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
776 printf("*** to dump dafs extended state\n");
778 #endif /* !AFS_DEMAND_ATTACH_FS */
786 VolHdrQuery(struct cmd_syndesc * as, void * rock)
789 SYNC_PROTO_BUF_DECL(res_buf);
794 res.hdr.response_len = sizeof(res.hdr);
795 res.payload.buf = res_buf;
796 res.payload.len = SYNC_PROTO_MAX_LEN;
798 common_prolog(as, &state);
799 common_volop_prolog(as, &state);
801 do_volop(&state, FSYNC_VOL_QUERY_HDR, &res);
803 if (res.hdr.response == SYNC_OK) {
804 memcpy(&v, res.payload.buf, sizeof(VolumeDiskData));
806 printf("VolumeDiskData = {\n");
807 printf("\tstamp = {\n");
808 printf("\t\tmagic = 0x%x\n", v.stamp.magic);
809 printf("\t\tversion = %u\n", v.stamp.version);
812 printf("\tid = %u\n", v.id);
813 printf("\tname = '%s'\n", v.name);
815 printf("\tinUse = %d (%s)\n", v.inUse, program_type_to_string(v.inUse));
817 printf("\tinUse = %d (no)\n", v.inUse);
819 printf("\tinService = %d\n", v.inService);
820 printf("\tblessed = %d\n", v.blessed);
821 printf("\tneedsSalvaged = %d\n", v.needsSalvaged);
822 printf("\tuniquifier = %u\n", v.uniquifier);
823 printf("\ttype = %d\n", v.type);
824 printf("\tparentId = %u\n", v.parentId);
825 printf("\tcloneId = %u\n", v.cloneId);
826 printf("\tbackupId = %u\n", v.backupId);
827 printf("\trestoredFromId = %u\n", v.restoredFromId);
828 printf("\tneedsCallback = %d\n", v.needsCallback);
829 printf("\tdestroyMe = %d\n", v.destroyMe);
830 printf("\tdontSalvage = %d\n", v.dontSalvage);
831 printf("\tmaxquota = %d\n", v.maxquota);
832 printf("\tminquota = %d\n", v.minquota);
833 printf("\tmaxfiles = %d\n", v.maxfiles);
834 printf("\taccountNumber = %u\n", v.accountNumber);
835 printf("\towner = %u\n", v.owner);
836 printf("\tfilecount = %d\n", v.filecount);
837 printf("\tdiskused = %d\n", v.diskused);
838 printf("\tdayUse = %d\n", v.dayUse);
839 for (i = 0; i < 7; i++) {
840 printf("\tweekUse[%d] = %d\n", i, v.weekUse[i]);
842 printf("\tdayUseDate = %u\n", v.dayUseDate);
843 printf("\tcreationDate = %u\n", v.creationDate);
844 printf("\taccessDate = %u\n", v.accessDate);
845 printf("\tupdateDate = %u\n", v.updateDate);
846 printf("\texpirationDate = %u\n", v.expirationDate);
847 printf("\tbackupDate = %u\n", v.backupDate);
848 printf("\tcopyDate = %u\n", v.copyDate);
849 #ifdef OPENAFS_VOL_STATS
850 printf("\tstat_initialized = %d\n", v.stat_initialized);
852 printf("\tmtd = '%s'\n", v.motd);
861 VolOpQuery(struct cmd_syndesc * as, void * rock)
864 SYNC_PROTO_BUF_DECL(res_buf);
866 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%lux\n", afs_printable_uint32_lu(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;
924 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
925 assert(state->vop != NULL);
927 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -volumeid */
928 state->vop->volume = atoi(ti->data);
930 fprintf(stderr, "required argument -volumeid not given\n");
933 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -vnodeid */
934 state->vop->vnode = atoi(ti->data);
936 fprintf(stderr, "required argument -vnodeid not given\n");
939 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -unique */
940 state->vop->unique = atoi(ti->data);
942 state->vop->unique = 0;
945 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+3].items)) { /* -partition */
946 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
948 memset(state->vop->partName, 0, sizeof(state->vop->partName));
955 do_vnqry(struct state * state, SYNC_response * res)
958 int command = FSYNC_VOL_QUERY_VNODE;
959 FSSYNC_VnQry_hdr qry;
961 qry.volume = state->vop->volume;
962 qry.vnode = state->vop->vnode;
963 qry.unique = state->vop->unique;
965 strlcpy(qry.partName, state->vop->partName, sizeof(qry.partName));
967 fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n",
968 command, command_code_to_string(command));
970 code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
977 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
980 fprintf(stderr, "FSYNC_GenericOp returned %d (%s)\n", code, response_code_to_string(code));
981 fprintf(stderr, "protocol response code was %d (%s)\n",
982 res->hdr.response, response_code_to_string(res->hdr.response));
983 fprintf(stderr, "protocol reason code was %d (%s)\n",
984 res->hdr.reason, reason_code_to_string(res->hdr.reason));
992 VnQuery(struct cmd_syndesc * as, void * rock)
995 SYNC_PROTO_BUF_DECL(res_buf);
999 res.hdr.response_len = sizeof(res.hdr);
1000 res.payload.buf = res_buf;
1001 res.payload.len = SYNC_PROTO_MAX_LEN;
1003 common_prolog(as, &state);
1004 vn_prolog(as, &state);
1006 do_vnqry(&state, &res);
1008 if (res.hdr.response == SYNC_OK) {
1009 memcpy(&v, res.payload.buf, sizeof(Volume));
1011 printf("vnode = {\n");
1013 printf("\tvid_hash = {\n");
1014 printf("\t\tnext = %p\n", v.vid_hash.next);
1015 printf("\t\tprev = %p\n", v.vid_hash.prev);
1018 printf("\thashNext = %p\n", v.hashNext);
1019 printf("\tlruNext = %p\n", v.lruNext);
1020 printf("\tlruPrev = %p\n", v.lruPrev);
1021 printf("\thashIndex = %hu\n", v.hashIndex);
1022 printf("\tchanged_newTime = %u\n", (unsigned int) v.changed_newTime);
1023 printf("\tchanged_oldTime = %u\n", (unsigned int) v.changed_oldTime);
1024 printf("\tdelete = %u\n", (unsigned int) v.delete);
1025 printf("\tvnodeNumber = %u\n", v.vnodeNumber);
1026 printf("\tvolumePtr = %p\n", v.volumePtr);
1027 printf("\tnUsers = %u\n", v.nUsers);
1028 printf("\tcacheCheck = %u\n", v.cacheCheck);
1030 #ifdef AFS_DEMAND_ATTACH_FS
1031 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
1032 printf("*** fssync-debug built to expect demand attach extensions. server asserted\n");
1033 printf("*** that it was not compiled with demand attach turned on. please recompile\n");
1034 printf("*** fssync-debug to match your server\n");
1038 printf("\tnReaders = %u\n", v.nReaders);
1039 printf("\tvn_state_flags = %s\n", vn_flags_to_string(v.vn_state_flags));
1040 printf("\tvn_state = %s\n", vn_state_to_string(v.vn_state));
1042 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
1043 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
1044 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
1045 printf("*** to dump dafs extended state\n");
1048 #endif /* !AFS_DEMAND_ATTACH_FS */
1050 printf("\twriter = %u\n", (unsigned int) v.writer);
1051 printf("\tvcp = %p\n", v.vcp);
1052 printf("\thandle = %p\n", v.handle);
1054 printf("\tdisk = {\n");
1055 printf("\t\ttype = %u\n", v.disk.type);
1056 printf("\t\tcloned = %u\n", v.disk.cloned);
1057 printf("\t\tmodeBits = %u\n", v.disk.modeBits);
1058 printf("\t\tlinkCount = %d\n", v.disk.linkCount);
1059 printf("\t\tlength = %u\n", v.disk.length);
1060 printf("\t\tuniquifier = %u\n", v.disk.uniquifier);
1061 printf("\t\tdataVersion = %u\n", v.disk.dataVersion);
1062 printf("\t\tvn_ino_lo = %u\n", v.disk.vn_ino_lo);
1063 printf("\t\tunixModifyTime = %u\n", v.disk.unixModifyTime);
1064 printf("\t\tauthor = %u\n", v.disk.author);
1065 printf("\t\towner = %u\n", v.disk.owner);
1066 printf("\t\tparent = %u\n", v.disk.parent);
1067 printf("\t\tvnodeMagic = %u\n", v.disk.vnodeMagic);
1069 printf("\t\tlock = {\n");
1070 printf("\t\t\tlockCount = %d\n", v.disk.lock.lockCount);
1071 printf("\t\t\tlockTime = %d\n", v.disk.lock.lockTime);
1074 printf("\t\tserverModifyTime = %u\n", v.disk.serverModifyTime);
1075 printf("\t\tgroup = %d\n", v.disk.group);
1076 printf("\t\tvn_ino_hi = %d\n", v.disk.vn_ino_hi);
1077 printf("\t\tvn_length_hi = %u\n", v.disk.vn_length_hi);
1089 StatsQuery(struct cmd_syndesc * as, void * rock)
1093 struct cmd_item *ti;
1095 SYNC_PROTO_BUF_DECL(res_buf);
1097 FSSYNC_StatsOp_hdr scom;
1100 struct VolPkgStats * vol_stats;
1101 struct VolumeHashChainStats * hash_stats;
1102 #ifdef AFS_DEMAND_ATTACH_FS
1103 struct volume_hdr_LRU_stats * hdr_stats;
1105 struct DiskPartitionStats64 * vicep_stats;
1109 res.hdr.response_len = sizeof(res.hdr);
1110 res.payload.buf = res_buf;
1111 res.payload.len = SYNC_PROTO_MAX_LEN;
1113 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -subcommand */
1114 if (!strcasecmp(ti->data, "vicep")) {
1115 command = FSYNC_VOL_STATS_VICEP;
1116 } else if (!strcasecmp(ti->data, "hash")) {
1117 command = FSYNC_VOL_STATS_HASH;
1118 #ifdef AFS_DEMAND_ATTACH_FS
1119 } else if (!strcasecmp(ti->data, "hdr")) {
1120 command = FSYNC_VOL_STATS_HDR;
1121 } else if (!strcasecmp(ti->data, "vlru")) {
1122 command = FSYNC_VOL_STATS_VLRU;
1124 } else if (!strcasecmp(ti->data, "pkg")) {
1125 command = FSYNC_VOL_STATS_GENERAL;
1126 } else if (!strcasecmp(ti->data, "help")) {
1127 fprintf(stderr, "fssync-debug stats subcommands:\n");
1128 fprintf(stderr, "\tpkg\tgeneral volume package stats\n");
1129 fprintf(stderr, "\tvicep\tvice partition stats\n");
1130 fprintf(stderr, "\thash\tvolume hash chain stats\n");
1131 #ifdef AFS_DEMAND_ATTACH_FS
1132 fprintf(stderr, "\thdr\tvolume header cache stats\n");
1133 fprintf(stderr, "\tvlru\tvlru generation stats\n");
1137 fprintf(stderr, "invalid stats subcommand");
1141 command = FSYNC_VOL_STATS_GENERAL;
1144 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -arg1 */
1146 case FSYNC_VOL_STATS_VICEP:
1147 strlcpy(scom.args.partName, ti->data, sizeof(state.vop->partName));
1149 case FSYNC_VOL_STATS_HASH:
1150 scom.args.hash_bucket = atoi(ti->data);
1152 case FSYNC_VOL_STATS_VLRU:
1153 scom.args.vlru_generation = atoi(ti->data);
1156 fprintf(stderr, "unrecognized arguments\n");
1161 case FSYNC_VOL_STATS_VICEP:
1162 case FSYNC_VOL_STATS_HASH:
1163 case FSYNC_VOL_STATS_VLRU:
1164 fprintf(stderr, "this subcommand requires more parameters\n");
1169 common_prolog(as, &state);
1171 fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
1172 command, command_code_to_string(command));
1174 code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
1181 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
1184 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
1185 fprintf(stderr, "protocol response code was %d (%s)\n",
1186 res.hdr.response, response_code_to_string(res.hdr.response));
1187 fprintf(stderr, "protocol reason code was %d (%s)\n",
1188 res.hdr.reason, reason_code_to_string(res.hdr.reason));
1192 if (res.hdr.response == SYNC_OK) {
1194 case FSYNC_VOL_STATS_GENERAL:
1195 print_vol_stats_general(sres.vol_stats);
1197 case FSYNC_VOL_STATS_VICEP:
1198 print_vol_stats_viceP(sres.vicep_stats);
1200 case FSYNC_VOL_STATS_HASH:
1201 print_vol_stats_hash(sres.hash_stats);
1203 #ifdef AFS_DEMAND_ATTACH_FS
1204 case FSYNC_VOL_STATS_HDR:
1205 print_vol_stats_hdr(sres.hdr_stats);
1207 #endif /* AFS_DEMAND_ATTACH_FS */
1215 print_vol_stats_general(VolPkgStats * stats)
1217 #ifdef AFS_DEMAND_ATTACH_FS
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 = %" AFS_INT64_FMT "\n", stats->free);
1288 printf("\tminFree = %" AFS_INT64_FMT "\n", stats->minFree);
1289 printf("\ttotalUsable = %" AFS_INT64_FMT "\n", stats->totalUsable);
1290 printf("\tf_files = %" AFS_INT64_FMT "\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)
1300 #ifdef AFS_DEMAND_ATTACH_FS
1304 printf("DiskPartitionStats = {\n");
1305 printf("\ttable_size = %d\n", stats->table_size);
1306 printf("\tchain_len = %d\n", stats->chain_len);
1308 #ifdef AFS_DEMAND_ATTACH_FS
1309 printf("\tchain_cacheCheck = %d\n", stats->chain_cacheCheck);
1310 printf("\tchain_busy = %d\n", stats->chain_busy);
1312 SplitInt64(stats->chain_looks, hi, lo);
1313 printf("\tchain_looks = {\n");
1314 printf("\t\thi = %u\n", hi);
1315 printf("\t\tlo = %u\n", lo);
1318 SplitInt64(stats->chain_gets, hi, lo);
1319 printf("\tchain_gets = {\n");
1320 printf("\t\thi = %u\n", hi);
1321 printf("\t\tlo = %u\n", lo);
1324 SplitInt64(stats->chain_reorders, hi, lo);
1325 printf("\tchain_reorders = {\n");
1326 printf("\t\thi = %u\n", hi);
1327 printf("\t\tlo = %u\n", lo);
1329 #endif /* AFS_DEMAND_ATTACH_FS */
1335 #ifdef AFS_DEMAND_ATTACH_FS
1337 print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats)
1339 printf("volume_hdr_LRU_stats = {\n");
1340 printf("\tfree = %d\n", stats->free);
1341 printf("\tused = %d\n", stats->used);
1342 printf("\tattached = %d\n", stats->attached);
1345 #endif /* AFS_DEMAND_ATTACH_FS */