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 VolQuery(struct cmd_syndesc * as, void * rock);
102 static int VolHdrQuery(struct cmd_syndesc * as, void * rock);
103 static int VolOpQuery(struct cmd_syndesc * as, void * rock);
104 static int StatsQuery(struct cmd_syndesc * as, void * rock);
105 static int VnQuery(struct cmd_syndesc * as, void * rock);
107 static void print_vol_stats_general(VolPkgStats * stats);
108 static void print_vol_stats_viceP(struct DiskPartitionStats64 * stats);
109 static void print_vol_stats_hash(struct VolumeHashChainStats * stats);
110 #ifdef AFS_DEMAND_ATTACH_FS
111 static void print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats);
115 #include "AFS_component_version_number.c"
119 #define COMMON_PARMS_OFFSET 12
120 #define COMMON_PARMS(ts) \
121 cmd_Seek(ts, COMMON_PARMS_OFFSET); \
122 cmd_AddParm(ts, "-reason", CMD_SINGLE, CMD_OPTIONAL, "sync protocol reason code"); \
123 cmd_AddParm(ts, "-programtype", CMD_SINGLE, CMD_OPTIONAL, "program type code")
125 #define COMMON_VOLOP_PARMS_OFFSET 10
126 #define COMMON_VOLOP_PARMS(ts) \
127 cmd_Seek(ts, COMMON_VOLOP_PARMS_OFFSET); \
128 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id"); \
129 cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL, "partition name")
131 #define CUSTOM_PARMS_OFFSET 1
134 #define VOLOP_PARMS_DECL(ts) \
135 COMMON_VOLOP_PARMS(ts); \
137 #define COMMON_PARMS_DECL(ts) \
141 main(int argc, char **argv)
143 struct cmd_syndesc *ts;
146 extern char cml_version_number[];
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("query", VolQuery, NULL, "get volume structure (FSYNC_VOL_QUERY opcode)");
184 VOLOP_PARMS_DECL(ts);
185 cmd_CreateAlias(ts, "qry");
187 ts = cmd_CreateSyntax("header", VolHdrQuery, NULL, "get volume disk data structure (FSYNC_VOL_QUERY_HDR opcode)");
188 VOLOP_PARMS_DECL(ts);
189 cmd_CreateAlias(ts, "hdr");
191 ts = cmd_CreateSyntax("volop", VolOpQuery, NULL, "get pending volume operation info (FSYNC_VOL_QUERY_VOP opcode)");
192 VOLOP_PARMS_DECL(ts);
193 cmd_CreateAlias(ts, "vop");
195 ts = cmd_CreateSyntax("vnode", VnQuery, NULL, "get vnode structure (FSYNC_VOL_QUERY_VNODE opcode)");
196 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
197 cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
198 cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id");
199 cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier");
200 cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "paritition name");
201 COMMON_PARMS_DECL(ts);
203 ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information");
204 cmd_Seek(ts, CUSTOM_PARMS_OFFSET);
205 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "subcommand");
206 cmd_AddParm(ts, "-arg1", CMD_SINGLE, CMD_OPTIONAL, "arg1");
207 cmd_AddParm(ts, "-arg2", CMD_SINGLE, CMD_OPTIONAL, "arg2");
208 COMMON_PARMS_DECL(ts);
210 err = cmd_Dispatch(argc, argv);
215 common_prolog(struct cmd_syndesc * as, struct state * state)
217 register struct cmd_item *ti;
220 if (afs_winsockInit() < 0) {
225 VInitVolumePackage(debugUtility, 1, 1,
229 if ((ti = as->parms[COMMON_PARMS_OFFSET].items)) { /* -reason */
230 state->reason = atoi(ti->data);
232 if ((ti = as->parms[COMMON_PARMS_OFFSET+1].items)) { /* -programtype */
233 if (!strcmp(ti->data, "fileServer")) {
234 programType = fileServer;
235 } else if (!strcmp(ti->data, "volumeUtility")) {
236 programType = volumeUtility;
237 } else if (!strcmp(ti->data, "salvager")) {
238 programType = salvager;
239 } else if (!strcmp(ti->data, "salvageServer")) {
240 programType = salvageServer;
242 programType = (ProgramType) atoi(ti->data);
252 common_volop_prolog(struct cmd_syndesc * as, struct state * state)
254 register struct cmd_item *ti;
255 char pname[100], *temp;
257 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
258 assert(state->vop != NULL);
260 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET].items)) { /* -volumeid */
261 state->vop->volume = atoi(ti->data);
263 fprintf(stderr, "required argument -volumeid not given\n");
266 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+1].items)) { /* -partition */
267 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
269 memset(state->vop->partName, 0, sizeof(state->vop->partName));
276 do_volop(struct state * state, afs_int32 command, SYNC_response * res)
279 SYNC_PROTO_BUF_DECL(res_buf);
284 res->payload.len = SYNC_PROTO_MAX_LEN;
285 res->payload.buf = res_buf;
288 fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n",
289 command, command_code_to_string(command));
291 code = FSYNC_VolOp(state->vop->volume,
292 state->vop->partName,
302 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
305 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
306 fprintf(stderr, "protocol response code was %d (%s)\n",
307 res->hdr.response, response_code_to_string(res->hdr.response));
308 fprintf(stderr, "protocol reason code was %d (%s)\n",
309 res->hdr.reason, reason_code_to_string(res->hdr.reason));
315 #define ENUMTOSTRING(en) #en
316 #define ENUMCASE(en) \
318 return ENUMTOSTRING(en); \
321 #define FLAGTOSTRING(fl) #fl
322 #define FLAGCASE(bitstr, fl, str, count) \
324 if ((bitstr) & (fl)) { \
326 strlcat((str), " | ", sizeof(str)); \
327 strlcat((str), FLAGTOSTRING(fl), sizeof(str)); \
333 response_code_to_string(afs_int32 response)
337 ENUMCASE(SYNC_DENIED);
338 ENUMCASE(SYNC_COM_ERROR);
339 ENUMCASE(SYNC_BAD_COMMAND);
340 ENUMCASE(SYNC_FAILED);
342 return "**UNKNOWN**";
347 command_code_to_string(afs_int32 command)
350 ENUMCASE(SYNC_COM_CHANNEL_CLOSE);
351 ENUMCASE(FSYNC_VOL_ON);
352 ENUMCASE(FSYNC_VOL_OFF);
353 ENUMCASE(FSYNC_VOL_LISTVOLUMES);
354 ENUMCASE(FSYNC_VOL_NEEDVOLUME);
355 ENUMCASE(FSYNC_VOL_MOVE);
356 ENUMCASE(FSYNC_VOL_BREAKCBKS);
357 ENUMCASE(FSYNC_VOL_DONE);
358 ENUMCASE(FSYNC_VOL_QUERY);
359 ENUMCASE(FSYNC_VOL_QUERY_HDR);
360 ENUMCASE(FSYNC_VOL_QUERY_VOP);
361 ENUMCASE(FSYNC_VOL_STATS_GENERAL);
362 ENUMCASE(FSYNC_VOL_STATS_VICEP);
363 ENUMCASE(FSYNC_VOL_STATS_HASH);
364 ENUMCASE(FSYNC_VOL_STATS_HDR);
365 ENUMCASE(FSYNC_VOL_STATS_VLRU);
366 ENUMCASE(FSYNC_VOL_ATTACH);
367 ENUMCASE(FSYNC_VOL_FORCE_ERROR);
368 ENUMCASE(FSYNC_VOL_LEAVE_OFF);
369 ENUMCASE(FSYNC_VOL_QUERY_VNODE);
371 return "**UNKNOWN**";
376 reason_code_to_string(afs_int32 reason)
379 ENUMCASE(SYNC_REASON_NONE);
380 ENUMCASE(SYNC_REASON_MALFORMED_PACKET);
381 ENUMCASE(SYNC_REASON_NOMEM);
382 ENUMCASE(SYNC_REASON_ENCODING_ERROR);
383 ENUMCASE(FSYNC_WHATEVER);
384 ENUMCASE(FSYNC_SALVAGE);
385 ENUMCASE(FSYNC_MOVE);
386 ENUMCASE(FSYNC_OPERATOR);
387 ENUMCASE(FSYNC_EXCLUSIVE);
388 ENUMCASE(FSYNC_UNKNOWN_VOLID);
389 ENUMCASE(FSYNC_HDR_NOT_ATTACHED);
390 ENUMCASE(FSYNC_NO_PENDING_VOL_OP);
391 ENUMCASE(FSYNC_VOL_PKG_ERROR);
392 ENUMCASE(FSYNC_UNKNOWN_VNID);
394 return "**UNKNOWN**";
399 program_type_to_string(afs_int32 type)
401 switch ((ProgramType)type) {
402 ENUMCASE(fileServer);
403 ENUMCASE(volumeUtility);
405 ENUMCASE(salvageServer);
406 ENUMCASE(debugUtility);
408 return "**UNKNOWN**";
413 VolOnline(struct cmd_syndesc * as, void * rock)
417 common_prolog(as, &state);
418 common_volop_prolog(as, &state);
420 do_volop(&state, FSYNC_VOL_ON, NULL);
426 VolOffline(struct cmd_syndesc * as, void * rock)
430 common_prolog(as, &state);
431 common_volop_prolog(as, &state);
433 do_volop(&state, FSYNC_VOL_OFF, NULL);
439 VolMode(struct cmd_syndesc * as, void * rock)
443 common_prolog(as, &state);
444 common_volop_prolog(as, &state);
446 do_volop(&state, FSYNC_VOL_NEEDVOLUME, NULL);
452 VolDetach(struct cmd_syndesc * as, void * rock)
456 common_prolog(as, &state);
457 common_volop_prolog(as, &state);
459 do_volop(&state, FSYNC_VOL_DONE, NULL);
465 VolBreakCBKs(struct cmd_syndesc * as, void * rock)
469 common_prolog(as, &state);
470 common_volop_prolog(as, &state);
472 do_volop(&state, FSYNC_VOL_BREAKCBKS, NULL);
478 VolMove(struct cmd_syndesc * as, void * rock)
482 common_prolog(as, &state);
483 common_volop_prolog(as, &state);
485 do_volop(&state, FSYNC_VOL_MOVE, NULL);
491 VolList(struct cmd_syndesc * as, void * rock)
495 common_prolog(as, &state);
496 common_volop_prolog(as, &state);
498 do_volop(&state, FSYNC_VOL_LISTVOLUMES, NULL);
503 #ifdef AFS_DEMAND_ATTACH_FS
505 vol_state_to_string(VolState state)
508 ENUMCASE(VOL_STATE_UNATTACHED);
509 ENUMCASE(VOL_STATE_PREATTACHED);
510 ENUMCASE(VOL_STATE_ATTACHING);
511 ENUMCASE(VOL_STATE_ATTACHED);
512 ENUMCASE(VOL_STATE_UPDATING);
513 ENUMCASE(VOL_STATE_GET_BITMAP);
514 ENUMCASE(VOL_STATE_HDR_LOADING);
515 ENUMCASE(VOL_STATE_HDR_ATTACHING);
516 ENUMCASE(VOL_STATE_SHUTTING_DOWN);
517 ENUMCASE(VOL_STATE_GOING_OFFLINE);
518 ENUMCASE(VOL_STATE_OFFLINING);
519 ENUMCASE(VOL_STATE_DETACHING);
520 ENUMCASE(VOL_STATE_SALVSYNC_REQ);
521 ENUMCASE(VOL_STATE_SALVAGING);
522 ENUMCASE(VOL_STATE_ERROR);
523 ENUMCASE(VOL_STATE_VNODE_ALLOC);
524 ENUMCASE(VOL_STATE_VNODE_GET);
525 ENUMCASE(VOL_STATE_VNODE_CLOSE);
526 ENUMCASE(VOL_STATE_VNODE_RELEASE);
527 ENUMCASE(VOL_STATE_VLRU_ADD);
528 ENUMCASE(VOL_STATE_FREED);
530 return "**UNKNOWN**";
535 vol_flags_to_string(afs_uint16 flags)
537 static char str[128];
541 FLAGCASE(flags, VOL_HDR_ATTACHED, str, count);
542 FLAGCASE(flags, VOL_HDR_LOADED, str, count);
543 FLAGCASE(flags, VOL_HDR_IN_LRU, str, count);
544 FLAGCASE(flags, VOL_IN_HASH, str, count);
545 FLAGCASE(flags, VOL_ON_VBYP_LIST, str, count);
546 FLAGCASE(flags, VOL_IS_BUSY, str, count);
547 FLAGCASE(flags, VOL_ON_VLRU, str, count);
548 FLAGCASE(flags, VOL_HDR_DONTSALV, str, count);
554 vlru_idx_to_string(int idx)
557 ENUMCASE(VLRU_QUEUE_NEW);
558 ENUMCASE(VLRU_QUEUE_MID);
559 ENUMCASE(VLRU_QUEUE_OLD);
560 ENUMCASE(VLRU_QUEUE_CANDIDATE);
561 ENUMCASE(VLRU_QUEUE_HELD);
562 ENUMCASE(VLRU_QUEUE_INVALID);
564 return "**UNKNOWN**";
570 vn_state_to_string(VnState state)
573 ENUMCASE(VN_STATE_INVALID);
574 ENUMCASE(VN_STATE_RELEASING);
575 ENUMCASE(VN_STATE_CLOSING);
576 ENUMCASE(VN_STATE_ALLOC);
577 ENUMCASE(VN_STATE_ONLINE);
578 ENUMCASE(VN_STATE_LOAD);
579 ENUMCASE(VN_STATE_EXCLUSIVE);
580 ENUMCASE(VN_STATE_STORE);
581 ENUMCASE(VN_STATE_READ);
582 ENUMCASE(VN_STATE_ERROR);
584 return "**UNKNOWN**";
589 vn_flags_to_string(afs_uint32 flags)
591 static char str[128];
595 FLAGCASE(flags, VN_ON_HASH, str, count);
596 FLAGCASE(flags, VN_ON_LRU, str, count);
597 FLAGCASE(flags, VN_ON_VVN, str, count);
604 VolQuery(struct cmd_syndesc * as, void * rock)
607 SYNC_PROTO_BUF_DECL(res_buf);
612 res.hdr.response_len = sizeof(res.hdr);
613 res.payload.buf = res_buf;
614 res.payload.len = SYNC_PROTO_MAX_LEN;
616 common_prolog(as, &state);
617 common_volop_prolog(as, &state);
619 do_volop(&state, FSYNC_VOL_QUERY, &res);
621 if (res.hdr.response == SYNC_OK) {
622 memcpy(&v, res.payload.buf, sizeof(Volume));
624 printf("volume = {\n");
625 printf("\thashid = %u\n", v.hashid);
626 printf("\theader = 0x%x\n", v.header);
627 printf("\tdevice = %d\n", v.device);
628 printf("\tpartition = 0x%x\n", v.partition);
629 printf("\tlinkHandle = 0x%x\n", v.linkHandle);
630 printf("\tnextVnodeUnique = %u\n", v.nextVnodeUnique);
631 printf("\tdiskDataHandle = 0x%x\n", v.diskDataHandle);
632 printf("\tvnodeHashOffset = %u\n", v.vnodeHashOffset);
633 printf("\tshuttingDown = %d\n", v.shuttingDown);
634 printf("\tgoingOffline = %d\n", v.goingOffline);
635 printf("\tcacheCheck = %u\n", v.cacheCheck);
636 printf("\tnUsers = %d\n", v.nUsers);
637 printf("\tneedsPutBack = %d\n", v.needsPutBack);
638 printf("\tspecialStatus = %d\n", v.specialStatus);
639 printf("\tupdateTime = %u\n", v.updateTime);
641 printf("\tvnodeIndex[vSmall] = {\n");
642 printf("\t\thandle = 0x%x\n", v.vnodeIndex[vSmall].handle);
643 printf("\t\tbitmap = 0x%x\n", v.vnodeIndex[vSmall].bitmap);
644 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vSmall].bitmapSize);
645 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vSmall].bitmapOffset);
647 printf("\tvnodeIndex[vLarge] = {\n");
648 printf("\t\thandle = 0x%x\n", v.vnodeIndex[vLarge].handle);
649 printf("\t\tbitmap = 0x%x\n", v.vnodeIndex[vLarge].bitmap);
650 printf("\t\tbitmapSize = %u\n", v.vnodeIndex[vLarge].bitmapSize);
651 printf("\t\tbitmapOffset = %u\n", v.vnodeIndex[vLarge].bitmapOffset);
653 #ifdef AFS_DEMAND_ATTACH_FS
654 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
655 printf("\tupdateTime = %u\n", v.updateTime);
656 printf("\tattach_state = %s\n", vol_state_to_string(v.attach_state));
657 printf("\tattach_flags = %s\n", vol_flags_to_string(v.attach_flags));
658 printf("\tnWaiters = %d\n", v.nWaiters);
659 printf("\tchainCacheCheck = %d\n", v.chainCacheCheck);
661 /* online salvage structure */
662 printf("\tsalvage = {\n");
663 printf("\t\tprio = %u\n", v.salvage.prio);
664 printf("\t\treason = %d\n", v.salvage.reason);
665 printf("\t\trequested = %d\n", v.salvage.requested);
666 printf("\t\tscheduled = %d\n", v.salvage.scheduled);
669 /* statistics structure */
670 printf("\tstats = {\n");
672 printf("\t\thash_lookups = {\n");
673 SplitInt64(v.stats.hash_lookups,hi,lo);
674 printf("\t\t\thi = %u\n", hi);
675 printf("\t\t\tlo = %u\n", lo);
678 printf("\t\thash_short_circuits = {\n");
679 SplitInt64(v.stats.hash_short_circuits,hi,lo);
680 printf("\t\t\thi = %u\n", hi);
681 printf("\t\t\tlo = %u\n", lo);
684 printf("\t\thdr_loads = {\n");
685 SplitInt64(v.stats.hdr_loads,hi,lo);
686 printf("\t\t\thi = %u\n", hi);
687 printf("\t\t\tlo = %u\n", lo);
690 printf("\t\thdr_gets = {\n");
691 SplitInt64(v.stats.hdr_gets,hi,lo);
692 printf("\t\t\thi = %u\n", hi);
693 printf("\t\t\tlo = %u\n", lo);
696 printf("\t\tattaches = %u\n", v.stats.attaches);
697 printf("\t\tsoft_detaches = %u\n", v.stats.soft_detaches);
698 printf("\t\tsalvages = %u\n", v.stats.salvages);
699 printf("\t\tvol_ops = %u\n", v.stats.vol_ops);
701 printf("\t\tlast_attach = %u\n", v.stats.last_attach);
702 printf("\t\tlast_get = %u\n", v.stats.last_get);
703 printf("\t\tlast_promote = %u\n", v.stats.last_promote);
704 printf("\t\tlast_hdr_get = %u\n", v.stats.last_hdr_get);
705 printf("\t\tlast_hdr_load = %u\n", v.stats.last_hdr_load);
706 printf("\t\tlast_salvage = %u\n", v.stats.last_salvage);
707 printf("\t\tlast_salvage_req = %u\n", v.stats.last_salvage_req);
708 printf("\t\tlast_vol_op = %u\n", v.stats.last_vol_op);
712 printf("\tvlru = {\n");
713 printf("\t\tidx = %d (%s)\n",
714 v.vlru.idx, vlru_idx_to_string(v.vlru.idx));
717 /* volume op state */
718 printf("\tpending_vol_op = 0x%x\n", v.pending_vol_op);
720 #else /* !AFS_DEMAND_ATTACH_FS */
721 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
722 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
723 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
724 printf("*** to dump dafs extended state\n");
726 #endif /* !AFS_DEMAND_ATTACH_FS */
734 VolHdrQuery(struct cmd_syndesc * as, void * rock)
737 SYNC_PROTO_BUF_DECL(res_buf);
742 res.hdr.response_len = sizeof(res.hdr);
743 res.payload.buf = res_buf;
744 res.payload.len = SYNC_PROTO_MAX_LEN;
746 common_prolog(as, &state);
747 common_volop_prolog(as, &state);
749 do_volop(&state, FSYNC_VOL_QUERY_HDR, &res);
751 if (res.hdr.response == SYNC_OK) {
752 memcpy(&v, res.payload.buf, sizeof(VolumeDiskData));
754 printf("VolumeDiskData = {\n");
755 printf("\tstamp = {\n");
756 printf("\t\tmagic = 0x%x\n", v.stamp.magic);
757 printf("\t\tversion = %u\n", v.stamp.version);
760 printf("\tid = %u\n", v.id);
761 printf("\tname = '%s'\n", v.name);
763 printf("\tinUse = %d (%s)\n", v.inUse, program_type_to_string(v.inUse));
765 printf("\tinUse = %d (no)\n", v.inUse);
767 printf("\tinService = %d\n", v.inService);
768 printf("\tblessed = %d\n", v.blessed);
769 printf("\tneedsSalvaged = %d\n", v.needsSalvaged);
770 printf("\tuniquifier = %u\n", v.uniquifier);
771 printf("\ttype = %d\n", v.type);
772 printf("\tparentId = %u\n", v.parentId);
773 printf("\tcloneId = %u\n", v.cloneId);
774 printf("\tbackupId = %u\n", v.backupId);
775 printf("\trestoredFromId = %u\n", v.restoredFromId);
776 printf("\tneedsCallback = %d\n", v.needsCallback);
777 printf("\tdestroyMe = %d\n", v.destroyMe);
778 printf("\tdontSalvage = %d\n", v.dontSalvage);
779 printf("\tmaxquota = %d\n", v.maxquota);
780 printf("\tminquota = %d\n", v.minquota);
781 printf("\tmaxfiles = %d\n", v.maxfiles);
782 printf("\taccountNumber = %u\n", v.accountNumber);
783 printf("\towner = %u\n", v.owner);
784 printf("\tfilecount = %d\n", v.filecount);
785 printf("\tdiskused = %d\n", v.diskused);
786 printf("\tdayUse = %d\n", v.dayUse);
787 for (i = 0; i < 7; i++) {
788 printf("\tweekUse[%d] = %d\n", i, v.weekUse[i]);
790 printf("\tdayUseDate = %u\n", v.dayUseDate);
791 printf("\tcreationDate = %u\n", v.creationDate);
792 printf("\taccessDate = %u\n", v.accessDate);
793 printf("\tupdateDate = %u\n", v.updateDate);
794 printf("\texpirationDate = %u\n", v.expirationDate);
795 printf("\tbackupDate = %u\n", v.backupDate);
796 printf("\tcopyDate = %u\n", v.copyDate);
797 #ifdef OPENAFS_VOL_STATS
798 printf("\tstat_initialized = %d\n", v.stat_initialized);
800 printf("\tmtd = '%s'\n", v.motd);
809 VolOpQuery(struct cmd_syndesc * as, void * rock)
812 SYNC_PROTO_BUF_DECL(res_buf);
814 FSSYNC_VolOp_info vop;
817 res.hdr.response_len = sizeof(res.hdr);
818 res.payload.buf = res_buf;
819 res.payload.len = SYNC_PROTO_MAX_LEN;
821 common_prolog(as, &state);
822 common_volop_prolog(as, &state);
824 do_volop(&state, FSYNC_VOL_QUERY_VOP, &res);
826 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
827 printf("*** file server not compiled with demand attach extensions.\n");
828 printf("*** pending volume operation metadata not available.\n");
831 if (res.hdr.response == SYNC_OK) {
832 memcpy(&vop, res.payload.buf, sizeof(FSSYNC_VolOp_info));
834 printf("pending_vol_op = {\n");
836 printf("\tcom = {\n");
837 printf("\t\tproto_version = %u\n", vop.com.proto_version);
838 printf("\t\tprogramType = %d (%s)\n",
839 vop.com.programType, program_type_to_string(vop.com.programType));
840 printf("\t\tcommand = %d (%s)\n",
841 vop.com.command, command_code_to_string(vop.com.command));
842 printf("\t\treason = %d (%s)\n",
843 vop.com.reason, reason_code_to_string(vop.com.reason));
844 printf("\t\tcommand_len = %u\n", vop.com.command_len);
845 printf("\t\tflags = 0x%x\n", vop.com.flags);
848 printf("\tvop = {\n");
849 printf("\t\tvolume = %u\n", vop.vop.volume);
850 if (afs_strnlen(vop.vop.partName, sizeof(vop.vop.partName)) <
851 sizeof(vop.vop.partName)) {
852 printf("\t\tpartName = '%s'\n", vop.vop.partName);
854 printf("\t\tpartName = (illegal string)\n");
865 vn_prolog(struct cmd_syndesc * as, struct state * state)
867 register struct cmd_item *ti;
868 char pname[100], *temp;
870 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
871 assert(state->vop != NULL);
873 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -volumeid */
874 state->vop->volume = atoi(ti->data);
876 fprintf(stderr, "required argument -volumeid not given\n");
879 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -vnodeid */
880 state->vop->vnode = atoi(ti->data);
882 fprintf(stderr, "required argument -vnodeid not given\n");
885 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -unique */
886 state->vop->unique = atoi(ti->data);
888 state->vop->unique = 0;
891 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+3].items)) { /* -partition */
892 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
894 memset(state->vop->partName, 0, sizeof(state->vop->partName));
901 do_vnqry(struct state * state, SYNC_response * res)
904 int command = FSYNC_VOL_QUERY_VNODE;
905 FSSYNC_VnQry_hdr qry;
907 qry.volume = state->vop->volume;
908 qry.vnode = state->vop->vnode;
909 qry.unique = state->vop->unique;
911 strlcpy(qry.partName, state->vop->partName, sizeof(qry.partName));
913 fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n",
914 command, command_code_to_string(command));
916 code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
923 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
926 fprintf(stderr, "FSYNC_GenericOp returned %d (%s)\n", code, response_code_to_string(code));
927 fprintf(stderr, "protocol response code was %d (%s)\n",
928 res->hdr.response, response_code_to_string(res->hdr.response));
929 fprintf(stderr, "protocol reason code was %d (%s)\n",
930 res->hdr.reason, reason_code_to_string(res->hdr.reason));
938 VnQuery(struct cmd_syndesc * as, void * rock)
941 SYNC_PROTO_BUF_DECL(res_buf);
946 res.hdr.response_len = sizeof(res.hdr);
947 res.payload.buf = res_buf;
948 res.payload.len = SYNC_PROTO_MAX_LEN;
950 common_prolog(as, &state);
951 vn_prolog(as, &state);
953 do_vnqry(&state, &res);
955 if (res.hdr.response == SYNC_OK) {
956 memcpy(&v, res.payload.buf, sizeof(Volume));
958 printf("vnode = {\n");
960 printf("\tvid_hash = {\n");
961 printf("\t\tnext = 0x%lx\n", v.vid_hash.next);
962 printf("\t\tprev = 0x%lx\n", v.vid_hash.prev);
965 printf("\thashNext = 0x%lx\n", v.hashNext);
966 printf("\tlruNext = 0x%lx\n", v.lruNext);
967 printf("\tlruPrev = 0x%lx\n", v.lruPrev);
968 printf("\thashIndex = %hu\n", v.hashIndex);
969 printf("\tchanged_newTime = %u\n", (unsigned int) v.changed_newTime);
970 printf("\tchanged_oldTime = %u\n", (unsigned int) v.changed_oldTime);
971 printf("\tdelete = %u\n", (unsigned int) v.delete);
972 printf("\tvnodeNumber = %u\n", v.vnodeNumber);
973 printf("\tvolumePtr = 0x%lx\n", v.volumePtr);
974 printf("\tnUsers = %u\n", v.nUsers);
975 printf("\tcacheCheck = %u\n", v.cacheCheck);
977 #ifdef AFS_DEMAND_ATTACH_FS
978 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
979 printf("*** fssync-debug built to expect demand attach extensions. server asserted\n");
980 printf("*** that it was not compiled with demand attach turned on. please recompile\n");
981 printf("*** fssync-debug to match your server\n");
985 printf("\tnReaders = %u\n", v.nReaders);
986 printf("\tvn_state_flags = %s\n", vn_flags_to_string(v.vn_state_flags));
987 printf("\tvn_state = %s\n", vn_state_to_string(v.vn_state));
989 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
990 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
991 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
992 printf("*** to dump dafs extended state\n");
995 #endif /* !AFS_DEMAND_ATTACH_FS */
997 printf("\twriter = %u\n", v.writer);
998 printf("\tvcp = 0x%lx\n", v.vcp);
999 printf("\thandle = 0x%lx\n", v.handle);
1001 printf("\tdisk = {\n");
1002 printf("\t\ttype = %u\n", v.disk.type);
1003 printf("\t\tcloned = %u\n", v.disk.cloned);
1004 printf("\t\tmodeBits = %u\n", v.disk.modeBits);
1005 printf("\t\tlinkCount = %d\n", v.disk.linkCount);
1006 printf("\t\tlength = %u\n", v.disk.length);
1007 printf("\t\tuniquifier = %u\n", v.disk.uniquifier);
1008 printf("\t\tdataVersion = %u\n", v.disk.dataVersion);
1009 printf("\t\tvn_ino_lo = %u\n", v.disk.vn_ino_lo);
1010 printf("\t\tunixModifyTime = %u\n", v.disk.unixModifyTime);
1011 printf("\t\tauthor = %u\n", v.disk.author);
1012 printf("\t\towner = %u\n", v.disk.owner);
1013 printf("\t\tparent = %u\n", v.disk.parent);
1014 printf("\t\tvnodeMagic = %u\n", v.disk.vnodeMagic);
1016 printf("\t\tlock = {\n");
1017 printf("\t\t\tlockCount = %d\n", v.disk.lock.lockCount);
1018 printf("\t\t\tlockTime = %d\n", v.disk.lock.lockTime);
1021 printf("\t\tserverModifyTime = %u\n", v.disk.serverModifyTime);
1022 printf("\t\tgroup = %d\n", v.disk.group);
1023 printf("\t\tvn_ino_hi = %d\n", v.disk.vn_ino_hi);
1024 printf("\t\treserved6 = %u\n", v.disk.reserved6);
1036 StatsQuery(struct cmd_syndesc * as, void * rock)
1040 struct cmd_item *ti;
1042 SYNC_PROTO_BUF_DECL(res_buf);
1044 FSSYNC_StatsOp_hdr scom;
1047 struct VolPkgStats * vol_stats;
1048 struct VolumeHashChainStats * hash_stats;
1049 #ifdef AFS_DEMAND_ATTACH_FS
1050 struct volume_hdr_LRU_stats * hdr_stats;
1052 struct DiskPartitionStats64 * vicep_stats;
1056 res.hdr.response_len = sizeof(res.hdr);
1057 res.payload.buf = res_buf;
1058 res.payload.len = SYNC_PROTO_MAX_LEN;
1060 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -subcommand */
1061 if (!strcasecmp(ti->data, "vicep")) {
1062 command = FSYNC_VOL_STATS_VICEP;
1063 } else if (!strcasecmp(ti->data, "hash")) {
1064 command = FSYNC_VOL_STATS_HASH;
1065 #ifdef AFS_DEMAND_ATTACH_FS
1066 } else if (!strcasecmp(ti->data, "hdr")) {
1067 command = FSYNC_VOL_STATS_HDR;
1068 } else if (!strcasecmp(ti->data, "vlru")) {
1069 command = FSYNC_VOL_STATS_VLRU;
1071 } else if (!strcasecmp(ti->data, "pkg")) {
1072 command = FSYNC_VOL_STATS_GENERAL;
1073 } else if (!strcasecmp(ti->data, "help")) {
1074 fprintf(stderr, "fssync-debug stats subcommands:\n");
1075 fprintf(stderr, "\tpkg\tgeneral volume package stats\n");
1076 fprintf(stderr, "\tvicep\tvice partition stats\n");
1077 fprintf(stderr, "\thash\tvolume hash chain stats\n");
1078 #ifdef AFS_DEMAND_ATTACH_FS
1079 fprintf(stderr, "\thdr\tvolume header cache stats\n");
1080 fprintf(stderr, "\tvlru\tvlru generation stats\n");
1084 fprintf(stderr, "invalid stats subcommand");
1088 command = FSYNC_VOL_STATS_GENERAL;
1091 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -arg1 */
1093 case FSYNC_VOL_STATS_VICEP:
1094 strlcpy(scom.args.partName, ti->data, sizeof(state.vop->partName));
1096 case FSYNC_VOL_STATS_HASH:
1097 scom.args.hash_bucket = atoi(ti->data);
1099 case FSYNC_VOL_STATS_VLRU:
1100 scom.args.vlru_generation = atoi(ti->data);
1103 fprintf(stderr, "unrecognized arguments\n");
1108 case FSYNC_VOL_STATS_VICEP:
1109 case FSYNC_VOL_STATS_HASH:
1110 case FSYNC_VOL_STATS_VLRU:
1111 fprintf(stderr, "this subcommand requires more parameters\n");
1116 common_prolog(as, &state);
1118 fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
1119 command, command_code_to_string(command));
1121 code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
1128 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
1131 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
1132 fprintf(stderr, "protocol response code was %d (%s)\n",
1133 res.hdr.response, response_code_to_string(res.hdr.response));
1134 fprintf(stderr, "protocol reason code was %d (%s)\n",
1135 res.hdr.reason, reason_code_to_string(res.hdr.reason));
1139 if (res.hdr.response == SYNC_OK) {
1141 case FSYNC_VOL_STATS_GENERAL:
1142 print_vol_stats_general(sres.vol_stats);
1144 case FSYNC_VOL_STATS_VICEP:
1145 print_vol_stats_viceP(sres.vicep_stats);
1147 case FSYNC_VOL_STATS_HASH:
1148 print_vol_stats_hash(sres.hash_stats);
1150 #ifdef AFS_DEMAND_ATTACH_FS
1151 case FSYNC_VOL_STATS_HDR:
1152 print_vol_stats_hdr(sres.hdr_stats);
1154 #endif /* AFS_DEMAND_ATTACH_FS */
1162 print_vol_stats_general(VolPkgStats * stats)
1167 printf("VolPkgStats = {\n");
1168 #ifdef AFS_DEMAND_ATTACH_FS
1169 for (i = 0; i < VOL_STATE_COUNT; i++) {
1170 printf("\tvol_state_count[%s] = %d\n",
1171 vol_state_to_string(i),
1172 stats->state_levels[i]);
1175 SplitInt64(stats->hash_looks, hi, lo);
1176 printf("\thash_looks = {\n");
1177 printf("\t\thi = %u\n", hi);
1178 printf("\t\tlo = %u\n", lo);
1181 SplitInt64(stats->hash_reorders, hi, lo);
1182 printf("\thash_reorders = {\n");
1183 printf("\t\thi = %u\n", hi);
1184 printf("\t\tlo = %u\n", lo);
1187 SplitInt64(stats->salvages, hi, lo);
1188 printf("\tsalvages = {\n");
1189 printf("\t\thi = %u\n", hi);
1190 printf("\t\tlo = %u\n", lo);
1193 SplitInt64(stats->vol_ops, hi, lo);
1194 printf("\tvol_ops = {\n");
1195 printf("\t\thi = %u\n", hi);
1196 printf("\t\tlo = %u\n", lo);
1199 SplitInt64(stats->hdr_loads, hi, lo);
1200 printf("\thdr_loads = {\n");
1201 printf("\t\thi = %u\n", hi);
1202 printf("\t\tlo = %u\n", lo);
1205 SplitInt64(stats->hdr_gets, hi, lo);
1206 printf("\thdr_gets = {\n");
1207 printf("\t\thi = %u\n", hi);
1208 printf("\t\tlo = %u\n", lo);
1211 SplitInt64(stats->attaches, hi, lo);
1212 printf("\tattaches = {\n");
1213 printf("\t\thi = %u\n", hi);
1214 printf("\t\tlo = %u\n", lo);
1217 SplitInt64(stats->soft_detaches, hi, lo);
1218 printf("\tsoft_detaches = {\n");
1219 printf("\t\thi = %u\n", hi);
1220 printf("\t\tlo = %u\n", lo);
1223 printf("\thdr_cache_size = %d\n", stats->hdr_cache_size);
1229 print_vol_stats_viceP(struct DiskPartitionStats64 * stats)
1231 printf("DiskPartitionStats64 = {\n");
1232 printf("\tfree = %lld\n", stats->free);
1233 printf("\tminFree = %lld\n", stats->minFree);
1234 printf("\ttotalUsable = %lld\n", stats->totalUsable);
1235 printf("\tf_files = %lld\n", stats->f_files);
1236 #ifdef AFS_DEMAND_ATTACH_FS
1237 printf("\tvol_list_len = %d\n", stats->vol_list_len);
1243 print_vol_stats_hash(struct VolumeHashChainStats * stats)
1247 printf("DiskPartitionStats = {\n");
1248 printf("\ttable_size = %d\n", stats->table_size);
1249 printf("\tchain_len = %d\n", stats->chain_len);
1251 #ifdef AFS_DEMAND_ATTACH_FS
1252 printf("\tchain_cacheCheck = %d\n", stats->chain_cacheCheck);
1253 printf("\tchain_busy = %d\n", stats->chain_busy);
1255 SplitInt64(stats->chain_looks, hi, lo);
1256 printf("\tchain_looks = {\n");
1257 printf("\t\thi = %u\n", hi);
1258 printf("\t\tlo = %u\n", lo);
1261 SplitInt64(stats->chain_gets, hi, lo);
1262 printf("\tchain_gets = {\n");
1263 printf("\t\thi = %u\n", hi);
1264 printf("\t\tlo = %u\n", lo);
1267 SplitInt64(stats->chain_reorders, hi, lo);
1268 printf("\tchain_reorders = {\n");
1269 printf("\t\thi = %u\n", hi);
1270 printf("\t\tlo = %u\n", lo);
1272 #endif /* AFS_DEMAND_ATTACH_FS */
1278 #ifdef AFS_DEMAND_ATTACH_FS
1280 print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats)
1282 printf("volume_hdr_LRU_stats = {\n");
1283 printf("\tfree = %d\n", stats->free);
1284 printf("\tused = %d\n", stats->used);
1285 printf("\tattached = %d\n", stats->attached);
1288 #endif /* AFS_DEMAND_ATTACH_FS */