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);
762 printf("\tinUse = %d\n", v.inUse);
763 printf("\tinService = %d\n", v.inService);
764 printf("\tblessed = %d\n", v.blessed);
765 printf("\tneedsSalvaged = %d\n", v.needsSalvaged);
766 printf("\tuniquifier = %u\n", v.uniquifier);
767 printf("\ttype = %d\n", v.type);
768 printf("\tparentId = %u\n", v.parentId);
769 printf("\tcloneId = %u\n", v.cloneId);
770 printf("\tbackupId = %u\n", v.backupId);
771 printf("\trestoredFromId = %u\n", v.restoredFromId);
772 printf("\tneedsCallback = %d\n", v.needsCallback);
773 printf("\tdestroyMe = %d\n", v.destroyMe);
774 printf("\tdontSalvage = %d\n", v.dontSalvage);
775 printf("\tmaxquota = %d\n", v.maxquota);
776 printf("\tminquota = %d\n", v.minquota);
777 printf("\tmaxfiles = %d\n", v.maxfiles);
778 printf("\taccountNumber = %u\n", v.accountNumber);
779 printf("\towner = %u\n", v.owner);
780 printf("\tfilecount = %d\n", v.filecount);
781 printf("\tdiskused = %d\n", v.diskused);
782 printf("\tdayUse = %d\n", v.dayUse);
783 for (i = 0; i < 7; i++) {
784 printf("\tweekUse[%d] = %d\n", i, v.weekUse[i]);
786 printf("\tdayUseDate = %u\n", v.dayUseDate);
787 printf("\tcreationDate = %u\n", v.creationDate);
788 printf("\taccessDate = %u\n", v.accessDate);
789 printf("\tupdateDate = %u\n", v.updateDate);
790 printf("\texpirationDate = %u\n", v.expirationDate);
791 printf("\tbackupDate = %u\n", v.backupDate);
792 printf("\tcopyDate = %u\n", v.copyDate);
793 #ifdef OPENAFS_VOL_STATS
794 printf("\tstat_initialized = %d\n", v.stat_initialized);
796 printf("\tmtd = '%s'\n", v.motd);
805 VolOpQuery(struct cmd_syndesc * as, void * rock)
808 SYNC_PROTO_BUF_DECL(res_buf);
810 FSSYNC_VolOp_info vop;
813 res.hdr.response_len = sizeof(res.hdr);
814 res.payload.buf = res_buf;
815 res.payload.len = SYNC_PROTO_MAX_LEN;
817 common_prolog(as, &state);
818 common_volop_prolog(as, &state);
820 do_volop(&state, FSYNC_VOL_QUERY_VOP, &res);
822 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
823 printf("*** file server not compiled with demand attach extensions.\n");
824 printf("*** pending volume operation metadata not available.\n");
827 if (res.hdr.response == SYNC_OK) {
828 memcpy(&vop, res.payload.buf, sizeof(FSSYNC_VolOp_info));
830 printf("pending_vol_op = {\n");
832 printf("\tcom = {\n");
833 printf("\t\tproto_version = %u\n", vop.com.proto_version);
834 printf("\t\tprogramType = %d (%s)\n",
835 vop.com.programType, program_type_to_string(vop.com.programType));
836 printf("\t\tcommand = %d (%s)\n",
837 vop.com.command, command_code_to_string(vop.com.command));
838 printf("\t\treason = %d (%s)\n",
839 vop.com.reason, reason_code_to_string(vop.com.reason));
840 printf("\t\tcommand_len = %u\n", vop.com.command_len);
841 printf("\t\tflags = 0x%x\n", vop.com.flags);
844 printf("\tvop = {\n");
845 printf("\t\tvolume = %u\n", vop.vop.volume);
846 if (afs_strnlen(vop.vop.partName, sizeof(vop.vop.partName)) <
847 sizeof(vop.vop.partName)) {
848 printf("\t\tpartName = '%s'\n", vop.vop.partName);
850 printf("\t\tpartName = (illegal string)\n");
861 vn_prolog(struct cmd_syndesc * as, struct state * state)
863 register struct cmd_item *ti;
864 char pname[100], *temp;
866 state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
867 assert(state->vop != NULL);
869 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -volumeid */
870 state->vop->volume = atoi(ti->data);
872 fprintf(stderr, "required argument -volumeid not given\n");
875 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -vnodeid */
876 state->vop->vnode = atoi(ti->data);
878 fprintf(stderr, "required argument -vnodeid not given\n");
881 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+2].items)) { /* -unique */
882 state->vop->unique = atoi(ti->data);
884 state->vop->unique = 0;
887 if ((ti = as->parms[COMMON_VOLOP_PARMS_OFFSET+3].items)) { /* -partition */
888 strlcpy(state->vop->partName, ti->data, sizeof(state->vop->partName));
890 memset(state->vop->partName, 0, sizeof(state->vop->partName));
897 do_vnqry(struct state * state, SYNC_response * res)
900 int command = FSYNC_VOL_QUERY_VNODE;
901 FSSYNC_VnQry_hdr qry;
903 qry.volume = state->vop->volume;
904 qry.vnode = state->vop->vnode;
905 qry.unique = state->vop->unique;
907 strlcpy(qry.partName, state->vop->partName, sizeof(qry.partName));
909 fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n",
910 command, command_code_to_string(command));
912 code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
919 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
922 fprintf(stderr, "FSYNC_GenericOp returned %d (%s)\n", code, response_code_to_string(code));
923 fprintf(stderr, "protocol response code was %d (%s)\n",
924 res->hdr.response, response_code_to_string(res->hdr.response));
925 fprintf(stderr, "protocol reason code was %d (%s)\n",
926 res->hdr.reason, reason_code_to_string(res->hdr.reason));
934 VnQuery(struct cmd_syndesc * as, void * rock)
937 SYNC_PROTO_BUF_DECL(res_buf);
942 res.hdr.response_len = sizeof(res.hdr);
943 res.payload.buf = res_buf;
944 res.payload.len = SYNC_PROTO_MAX_LEN;
946 common_prolog(as, &state);
947 vn_prolog(as, &state);
949 do_vnqry(&state, &res);
951 if (res.hdr.response == SYNC_OK) {
952 memcpy(&v, res.payload.buf, sizeof(Volume));
954 printf("vnode = {\n");
956 printf("\tvid_hash = {\n");
957 printf("\t\tnext = 0x%lx\n", v.vid_hash.next);
958 printf("\t\tprev = 0x%lx\n", v.vid_hash.prev);
961 printf("\thashNext = 0x%lx\n", v.hashNext);
962 printf("\tlruNext = 0x%lx\n", v.lruNext);
963 printf("\tlruPrev = 0x%lx\n", v.lruPrev);
964 printf("\thashIndex = %hu\n", v.hashIndex);
965 printf("\tchanged_newTime = %u\n", (unsigned int) v.changed_newTime);
966 printf("\tchanged_oldTime = %u\n", (unsigned int) v.changed_oldTime);
967 printf("\tdelete = %u\n", (unsigned int) v.delete);
968 printf("\tvnodeNumber = %u\n", v.vnodeNumber);
969 printf("\tvolumePtr = 0x%lx\n", v.volumePtr);
970 printf("\tnUsers = %u\n", v.nUsers);
971 printf("\tcacheCheck = %u\n", v.cacheCheck);
973 #ifdef AFS_DEMAND_ATTACH_FS
974 if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
975 printf("*** fssync-debug built to expect demand attach extensions. server asserted\n");
976 printf("*** that it was not compiled with demand attach turned on. please recompile\n");
977 printf("*** fssync-debug to match your server\n");
981 printf("\tnReaders = %u\n", v.nReaders);
982 printf("\tvn_state_flags = %s\n", vn_flags_to_string(v.vn_state_flags));
983 printf("\tvn_state = %s\n", vn_state_to_string(v.vn_state));
985 if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
986 printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
987 printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
988 printf("*** to dump dafs extended state\n");
991 #endif /* !AFS_DEMAND_ATTACH_FS */
993 printf("\twriter = %u\n", v.writer);
994 printf("\tvcp = 0x%lx\n", v.vcp);
995 printf("\thandle = 0x%lx\n", v.handle);
997 printf("\tdisk = {\n");
998 printf("\t\ttype = %u\n", v.disk.type);
999 printf("\t\tcloned = %u\n", v.disk.cloned);
1000 printf("\t\tmodeBits = %u\n", v.disk.modeBits);
1001 printf("\t\tlinkCount = %d\n", v.disk.linkCount);
1002 printf("\t\tlength = %u\n", v.disk.length);
1003 printf("\t\tuniquifier = %u\n", v.disk.uniquifier);
1004 printf("\t\tdataVersion = %u\n", v.disk.dataVersion);
1005 printf("\t\tvn_ino_lo = %u\n", v.disk.vn_ino_lo);
1006 printf("\t\tunixModifyTime = %u\n", v.disk.unixModifyTime);
1007 printf("\t\tauthor = %u\n", v.disk.author);
1008 printf("\t\towner = %u\n", v.disk.owner);
1009 printf("\t\tparent = %u\n", v.disk.parent);
1010 printf("\t\tvnodeMagic = %u\n", v.disk.vnodeMagic);
1012 printf("\t\tlock = {\n");
1013 printf("\t\t\tlockCount = %d\n", v.disk.lock.lockCount);
1014 printf("\t\t\tlockTime = %d\n", v.disk.lock.lockTime);
1017 printf("\t\tserverModifyTime = %u\n", v.disk.serverModifyTime);
1018 printf("\t\tgroup = %d\n", v.disk.group);
1019 printf("\t\tvn_ino_hi = %d\n", v.disk.vn_ino_hi);
1020 printf("\t\treserved6 = %u\n", v.disk.reserved6);
1032 StatsQuery(struct cmd_syndesc * as, void * rock)
1036 struct cmd_item *ti;
1038 SYNC_PROTO_BUF_DECL(res_buf);
1040 FSSYNC_StatsOp_hdr scom;
1043 struct VolPkgStats * vol_stats;
1044 struct VolumeHashChainStats * hash_stats;
1045 #ifdef AFS_DEMAND_ATTACH_FS
1046 struct volume_hdr_LRU_stats * hdr_stats;
1048 struct DiskPartitionStats64 * vicep_stats;
1052 res.hdr.response_len = sizeof(res.hdr);
1053 res.payload.buf = res_buf;
1054 res.payload.len = SYNC_PROTO_MAX_LEN;
1056 if ((ti = as->parms[CUSTOM_PARMS_OFFSET].items)) { /* -subcommand */
1057 if (!strcasecmp(ti->data, "vicep")) {
1058 command = FSYNC_VOL_STATS_VICEP;
1059 } else if (!strcasecmp(ti->data, "hash")) {
1060 command = FSYNC_VOL_STATS_HASH;
1061 #ifdef AFS_DEMAND_ATTACH_FS
1062 } else if (!strcasecmp(ti->data, "hdr")) {
1063 command = FSYNC_VOL_STATS_HDR;
1064 } else if (!strcasecmp(ti->data, "vlru")) {
1065 command = FSYNC_VOL_STATS_VLRU;
1067 } else if (!strcasecmp(ti->data, "pkg")) {
1068 command = FSYNC_VOL_STATS_GENERAL;
1069 } else if (!strcasecmp(ti->data, "help")) {
1070 fprintf(stderr, "fssync-debug stats subcommands:\n");
1071 fprintf(stderr, "\tpkg\tgeneral volume package stats\n");
1072 fprintf(stderr, "\tvicep\tvice partition stats\n");
1073 fprintf(stderr, "\thash\tvolume hash chain stats\n");
1074 #ifdef AFS_DEMAND_ATTACH_FS
1075 fprintf(stderr, "\thdr\tvolume header cache stats\n");
1076 fprintf(stderr, "\tvlru\tvlru generation stats\n");
1080 fprintf(stderr, "invalid stats subcommand");
1084 command = FSYNC_VOL_STATS_GENERAL;
1087 if ((ti = as->parms[CUSTOM_PARMS_OFFSET+1].items)) { /* -arg1 */
1089 case FSYNC_VOL_STATS_VICEP:
1090 strlcpy(scom.args.partName, ti->data, sizeof(state.vop->partName));
1092 case FSYNC_VOL_STATS_HASH:
1093 scom.args.hash_bucket = atoi(ti->data);
1095 case FSYNC_VOL_STATS_VLRU:
1096 scom.args.vlru_generation = atoi(ti->data);
1099 fprintf(stderr, "unrecognized arguments\n");
1104 case FSYNC_VOL_STATS_VICEP:
1105 case FSYNC_VOL_STATS_HASH:
1106 case FSYNC_VOL_STATS_VLRU:
1107 fprintf(stderr, "this subcommand requires more parameters\n");
1112 common_prolog(as, &state);
1114 fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
1115 command, command_code_to_string(command));
1117 code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
1124 fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
1127 fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
1128 fprintf(stderr, "protocol response code was %d (%s)\n",
1129 res.hdr.response, response_code_to_string(res.hdr.response));
1130 fprintf(stderr, "protocol reason code was %d (%s)\n",
1131 res.hdr.reason, reason_code_to_string(res.hdr.reason));
1135 if (res.hdr.response == SYNC_OK) {
1137 case FSYNC_VOL_STATS_GENERAL:
1138 print_vol_stats_general(sres.vol_stats);
1140 case FSYNC_VOL_STATS_VICEP:
1141 print_vol_stats_viceP(sres.vicep_stats);
1143 case FSYNC_VOL_STATS_HASH:
1144 print_vol_stats_hash(sres.hash_stats);
1146 #ifdef AFS_DEMAND_ATTACH_FS
1147 case FSYNC_VOL_STATS_HDR:
1148 print_vol_stats_hdr(sres.hdr_stats);
1150 #endif /* AFS_DEMAND_ATTACH_FS */
1158 print_vol_stats_general(VolPkgStats * stats)
1163 printf("VolPkgStats = {\n");
1164 #ifdef AFS_DEMAND_ATTACH_FS
1165 for (i = 0; i < VOL_STATE_COUNT; i++) {
1166 printf("\tvol_state_count[%s] = %d\n",
1167 vol_state_to_string(i),
1168 stats->state_levels[i]);
1171 SplitInt64(stats->hash_looks, hi, lo);
1172 printf("\thash_looks = {\n");
1173 printf("\t\thi = %u\n", hi);
1174 printf("\t\tlo = %u\n", lo);
1177 SplitInt64(stats->hash_reorders, hi, lo);
1178 printf("\thash_reorders = {\n");
1179 printf("\t\thi = %u\n", hi);
1180 printf("\t\tlo = %u\n", lo);
1183 SplitInt64(stats->salvages, hi, lo);
1184 printf("\tsalvages = {\n");
1185 printf("\t\thi = %u\n", hi);
1186 printf("\t\tlo = %u\n", lo);
1189 SplitInt64(stats->vol_ops, hi, lo);
1190 printf("\tvol_ops = {\n");
1191 printf("\t\thi = %u\n", hi);
1192 printf("\t\tlo = %u\n", lo);
1195 SplitInt64(stats->hdr_loads, hi, lo);
1196 printf("\thdr_loads = {\n");
1197 printf("\t\thi = %u\n", hi);
1198 printf("\t\tlo = %u\n", lo);
1201 SplitInt64(stats->hdr_gets, hi, lo);
1202 printf("\thdr_gets = {\n");
1203 printf("\t\thi = %u\n", hi);
1204 printf("\t\tlo = %u\n", lo);
1207 SplitInt64(stats->attaches, hi, lo);
1208 printf("\tattaches = {\n");
1209 printf("\t\thi = %u\n", hi);
1210 printf("\t\tlo = %u\n", lo);
1213 SplitInt64(stats->soft_detaches, hi, lo);
1214 printf("\tsoft_detaches = {\n");
1215 printf("\t\thi = %u\n", hi);
1216 printf("\t\tlo = %u\n", lo);
1219 printf("\thdr_cache_size = %d\n", stats->hdr_cache_size);
1225 print_vol_stats_viceP(struct DiskPartitionStats64 * stats)
1227 printf("DiskPartitionStats64 = {\n");
1228 printf("\tfree = %lld\n", stats->free);
1229 printf("\tminFree = %lld\n", stats->minFree);
1230 printf("\ttotalUsable = %lld\n", stats->totalUsable);
1231 printf("\tf_files = %lld\n", stats->f_files);
1232 #ifdef AFS_DEMAND_ATTACH_FS
1233 printf("\tvol_list_len = %d\n", stats->vol_list_len);
1239 print_vol_stats_hash(struct VolumeHashChainStats * stats)
1243 printf("DiskPartitionStats = {\n");
1244 printf("\ttable_size = %d\n", stats->table_size);
1245 printf("\tchain_len = %d\n", stats->chain_len);
1247 #ifdef AFS_DEMAND_ATTACH_FS
1248 printf("\tchain_cacheCheck = %d\n", stats->chain_cacheCheck);
1249 printf("\tchain_busy = %d\n", stats->chain_busy);
1251 SplitInt64(stats->chain_looks, hi, lo);
1252 printf("\tchain_looks = {\n");
1253 printf("\t\thi = %u\n", hi);
1254 printf("\t\tlo = %u\n", lo);
1257 SplitInt64(stats->chain_gets, hi, lo);
1258 printf("\tchain_gets = {\n");
1259 printf("\t\thi = %u\n", hi);
1260 printf("\t\tlo = %u\n", lo);
1263 SplitInt64(stats->chain_reorders, hi, lo);
1264 printf("\tchain_reorders = {\n");
1265 printf("\t\thi = %u\n", hi);
1266 printf("\t\tlo = %u\n", lo);
1268 #endif /* AFS_DEMAND_ATTACH_FS */
1274 #ifdef AFS_DEMAND_ATTACH_FS
1276 print_vol_stats_hdr(struct volume_hdr_LRU_stats * stats)
1278 printf("volume_hdr_LRU_stats = {\n");
1279 printf("\tfree = %d\n", stats->free);
1280 printf("\tused = %d\n", stats->used);
1281 printf("\tattached = %d\n", stats->attached);
1284 #endif /* AFS_DEMAND_ATTACH_FS */