/*
* Copyright 2006-2010, Sine Nomine Associates and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
#include "ihandle.h"
#include "vnode.h"
#include "volume.h"
+#include "volume_inline.h"
#include "partition.h"
#include "daemon_com.h"
+#include "daemon_com_inline.h"
#include "fssync.h"
+#include "fssync_inline.h"
#include "vg_cache.h"
#ifdef AFS_NT40_ENV
#include <pthread.h>
struct volop_state * vop;
};
+#ifndef AFS_DEMAND_ATTACH_FS
+/* remember argv/argc for later, if we need to re-exec */
+static char **fssd_argv;
+static int fssd_argc;
+#endif
+
static int common_prolog(struct cmd_syndesc *, struct state *);
static int common_volop_prolog(struct cmd_syndesc *, struct state *);
static int do_volop(struct state *, afs_int32 command, SYNC_response * res);
-static char * response_code_to_string(afs_int32);
-static char * command_code_to_string(afs_int32);
-static char * reason_code_to_string(afs_int32);
-static char * program_type_to_string(afs_int32);
-
static int VolOnline(struct cmd_syndesc * as, void * rock);
static int VolOffline(struct cmd_syndesc * as, void * rock);
static int VolMode(struct cmd_syndesc * as, void * rock);
exit(2);
}
-
+#ifndef AFS_DEMAND_ATTACH_FS
+ fssd_argv = argv;
+ fssd_argc = argc;
+#endif
+
ts = cmd_CreateSyntax("online", VolOnline, NULL, "bring a volume online (FSYNC_VOL_ON opcode)");
VOLOP_PARMS_DECL(ts);
cmd_AddParm(ts, "-volumeid", CMD_SINGLE, 0, "volume id");
cmd_AddParm(ts, "-vnodeid", CMD_SINGLE, 0, "vnode id");
cmd_AddParm(ts, "-unique", CMD_SINGLE, 0, "uniquifier");
- cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "paritition name");
+ cmd_AddParm(ts, "-partition", CMD_SINGLE, 0, "partition name");
COMMON_PARMS_DECL(ts);
ts = cmd_CreateSyntax("stats", StatsQuery, NULL, "see 'stats help' for more information");
exit(err);
}
+#ifdef AFS_DEMAND_ATTACH_FS
+# define dafs_prolog()
+#else
+/* Try to detect if the fileserver is DAFS, and if so, re-exec as the
+ * DAFS-enabled fssync-debug (dafssync_debug). If we fail to detect or
+ * exec, just try to proceed anyway as if the server is not DAFS */
+static void
+dafs_prolog(void)
+{
+ SYNC_response res;
+ SYNC_PROTO_BUF_DECL(res_buf);
+ afs_int32 code;
+ char *dfssd;
+
+ res.payload.len = SYNC_PROTO_MAX_LEN;
+ res.payload.buf = res_buf;
+
+ /* LISTVOLUMES is a no-op; we just want to get the response header flags
+ * to see if the server reports itself as DAFS or not */
+ code = FSYNC_VolOp(0, NULL, FSYNC_VOL_LISTVOLUMES, FSYNC_WHATEVER, &res);
+ if (code) {
+ /* probably failed to contact the fileserver; later code will provide
+ * some warning/error indication */
+ return;
+ }
+
+ if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
+ /* fileserver is not DAFS, so we don't need to do anything */
+ return;
+ }
+
+ dfssd = afs_exec_alt(fssd_argc, fssd_argv, "da", NULL);
+
+ fprintf(stderr, "\n*** server asserted demand attach extensions, but we failed\n"
+ "*** to exec a DAFS-enabled fssync-debug '%s' (errno=%d);\n"
+ "*** attempting to proceed without it.\n\n", dfssd, errno);
+
+ free(dfssd);
+}
+#endif /* !AFS_DEMAND_ATTACH_FS */
+
static int
common_prolog(struct cmd_syndesc * as, struct state * state)
{
- register struct cmd_item *ti;
+ struct cmd_item *ti;
VolumePackageOptions opts;
#ifdef AFS_NT40_ENV
static int
common_volop_prolog(struct cmd_syndesc * as, struct state * state)
{
- register struct cmd_item *ti;
+ struct cmd_item *ti;
state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
assert(state->vop != NULL);
fprintf(stderr, "warning: response code indicates possible protocol error.\n");
}
- fprintf(stderr, "FSSYNC service returned %d (%s)\n", code, response_code_to_string(code));
+ fprintf(stderr, "FSSYNC service returned %d (%s)\n", code, SYNC_res2string(code));
if (res) {
fprintf(stderr, "protocol header response code was %d (%s)\n",
- res->hdr.response, response_code_to_string(res->hdr.response));
+ res->hdr.response, SYNC_res2string(res->hdr.response));
fprintf(stderr, "protocol reason code was %d (%s)\n",
- res->hdr.reason, reason_code_to_string(res->hdr.reason));
+ res->hdr.reason, FSYNC_reason2string(res->hdr.reason));
}
return 0;
res->payload.buf = res_buf;
}
- fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n",
- command, command_code_to_string(command));
+ fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n",
+ command, FSYNC_com2string(command));
code = FSYNC_VolOp(state->vop->volume,
state->vop->partName,
} \
} while (0)
-static char *
-response_code_to_string(afs_int32 response)
-{
- switch (response) {
- ENUMCASE(SYNC_OK);
- ENUMCASE(SYNC_DENIED);
- ENUMCASE(SYNC_COM_ERROR);
- ENUMCASE(SYNC_BAD_COMMAND);
- ENUMCASE(SYNC_FAILED);
- default:
- return "**UNKNOWN**";
- }
-}
-
-static char *
-command_code_to_string(afs_int32 command)
-{
- switch (command) {
- ENUMCASE(SYNC_COM_CHANNEL_CLOSE);
- ENUMCASE(FSYNC_VOL_ON);
- ENUMCASE(FSYNC_VOL_OFF);
- ENUMCASE(FSYNC_VOL_LISTVOLUMES);
- ENUMCASE(FSYNC_VOL_NEEDVOLUME);
- ENUMCASE(FSYNC_VOL_MOVE);
- ENUMCASE(FSYNC_VOL_BREAKCBKS);
- ENUMCASE(FSYNC_VOL_DONE);
- ENUMCASE(FSYNC_VOL_QUERY);
- ENUMCASE(FSYNC_VOL_QUERY_HDR);
- ENUMCASE(FSYNC_VOL_QUERY_VOP);
- ENUMCASE(FSYNC_VOL_STATS_GENERAL);
- ENUMCASE(FSYNC_VOL_STATS_VICEP);
- ENUMCASE(FSYNC_VOL_STATS_HASH);
- ENUMCASE(FSYNC_VOL_STATS_HDR);
- ENUMCASE(FSYNC_VOL_STATS_VLRU);
- ENUMCASE(FSYNC_VOL_ATTACH);
- ENUMCASE(FSYNC_VOL_FORCE_ERROR);
- ENUMCASE(FSYNC_VOL_LEAVE_OFF);
- ENUMCASE(FSYNC_VOL_QUERY_VNODE);
- ENUMCASE(FSYNC_VG_QUERY);
- ENUMCASE(FSYNC_VG_ADD);
- ENUMCASE(FSYNC_VG_DEL);
- ENUMCASE(FSYNC_VG_SCAN);
- ENUMCASE(FSYNC_VG_SCAN_ALL);
-
- default:
- return "**UNKNOWN**";
- }
-}
-
-static char *
-reason_code_to_string(afs_int32 reason)
-{
- switch (reason) {
- ENUMCASE(SYNC_REASON_NONE);
- ENUMCASE(SYNC_REASON_MALFORMED_PACKET);
- ENUMCASE(SYNC_REASON_NOMEM);
- ENUMCASE(SYNC_REASON_ENCODING_ERROR);
- ENUMCASE(FSYNC_WHATEVER);
- ENUMCASE(FSYNC_SALVAGE);
- ENUMCASE(FSYNC_MOVE);
- ENUMCASE(FSYNC_OPERATOR);
- ENUMCASE(FSYNC_EXCLUSIVE);
- ENUMCASE(FSYNC_UNKNOWN_VOLID);
- ENUMCASE(FSYNC_HDR_NOT_ATTACHED);
- ENUMCASE(FSYNC_NO_PENDING_VOL_OP);
- ENUMCASE(FSYNC_VOL_PKG_ERROR);
- ENUMCASE(FSYNC_UNKNOWN_VNID);
- ENUMCASE(FSYNC_WRONG_PART);
- ENUMCASE(FSYNC_BAD_STATE);
- ENUMCASE(FSYNC_BAD_PART);
- ENUMCASE(FSYNC_PART_SCANNING);
- default:
- return "**UNKNOWN**";
- }
-}
-
-static char *
-program_type_to_string(afs_int32 type)
-{
- switch ((ProgramType)type) {
- ENUMCASE(fileServer);
- ENUMCASE(volumeUtility);
- ENUMCASE(salvager);
- ENUMCASE(salvageServer);
- ENUMCASE(debugUtility);
- default:
- return "**UNKNOWN**";
- }
-}
-
-static int
+static int
VolOnline(struct cmd_syndesc * as, void * rock)
{
struct state state;
return 0;
}
-static int
+static int
VolOffline(struct cmd_syndesc * as, void * rock)
{
struct state state;
ENUMCASE(VOL_STATE_VNODE_CLOSE);
ENUMCASE(VOL_STATE_VNODE_RELEASE);
ENUMCASE(VOL_STATE_VLRU_ADD);
+ ENUMCASE(VOL_STATE_DELETED);
ENUMCASE(VOL_STATE_FREED);
default:
return "**UNKNOWN**";
int hi, lo;
#endif
+ dafs_prolog();
+
res.hdr.response_len = sizeof(res.hdr);
res.payload.buf = res_buf;
res.payload.len = SYNC_PROTO_MAX_LEN;
printf("\tneedsPutBack = %d\n", v.needsPutBack);
printf("\tspecialStatus = %d\n", v.specialStatus);
printf("\tupdateTime = %u\n", v.updateTime);
-
+
printf("\tvnodeIndex[vSmall] = {\n");
printf("\t\thandle = %p\n", v.vnodeIndex[vSmall].handle);
printf("\t\tbitmap = %p\n", v.vnodeIndex[vSmall].bitmap);
printf("\tattach_flags = %s\n", vol_flags_to_string(v.attach_flags));
printf("\tnWaiters = %d\n", v.nWaiters);
printf("\tchainCacheCheck = %d\n", v.chainCacheCheck);
-
+
/* online salvage structure */
printf("\tsalvage = {\n");
printf("\t\tprio = %u\n", v.salvage.prio);
printf("\t\trequested = %d\n", v.salvage.requested);
printf("\t\tscheduled = %d\n", v.salvage.scheduled);
printf("\t}\n");
-
+
/* statistics structure */
printf("\tstats = {\n");
printf("\t\t\thi = %u\n", hi);
printf("\t\t\tlo = %u\n", lo);
printf("\t\t}\n");
-
+
printf("\t\tattaches = %u\n", v.stats.attaches);
printf("\t\tsoft_detaches = %u\n", v.stats.soft_detaches);
printf("\t\tsalvages = %u\n", v.stats.salvages);
printf("\t\tvol_ops = %u\n", v.stats.vol_ops);
-
+
printf("\t\tlast_attach = %u\n", v.stats.last_attach);
printf("\t\tlast_get = %u\n", v.stats.last_get);
printf("\t\tlast_promote = %u\n", v.stats.last_promote);
printf("\t\tlast_salvage_req = %u\n", v.stats.last_salvage_req);
printf("\t\tlast_vol_op = %u\n", v.stats.last_vol_op);
printf("\t}\n");
-
+
/* VLRU state */
printf("\tvlru = {\n");
- printf("\t\tidx = %d (%s)\n",
+ printf("\t\tidx = %d (%s)\n",
v.vlru.idx, vlru_idx_to_string(v.vlru.idx));
printf("\t}\n");
}
#else /* !AFS_DEMAND_ATTACH_FS */
if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
- printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
- printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
- printf("*** to dump dafs extended state\n");
+ printf("*** server asserted demand attach extensions. this fssync-debug\n"
+ "*** is not built to recognize those extensions. please use an\n"
+ "*** fssync-debug with demand attach if you need to dump dafs\n"
+ "*** extended state.\n");
}
#endif /* !AFS_DEMAND_ATTACH_FS */
printf("}\n");
printf("\t\tmagic = 0x%x\n", v.stamp.magic);
printf("\t\tversion = %u\n", v.stamp.version);
printf("\t}\n");
-
+
printf("\tid = %u\n", v.id);
printf("\tname = '%s'\n", v.name);
if (v.inUse != 0) {
- printf("\tinUse = %d (%s)\n", v.inUse, program_type_to_string(v.inUse));
+ printf("\tinUse = %d (%s)\n", v.inUse, VPTypeToString(v.inUse));
} else {
printf("\tinUse = %d (no)\n", v.inUse);
}
printf("\t\tproto_version = %u\n", vop.com.proto_version);
printf("\t\tpkt_seq = %u\n", vop.com.pkt_seq);
printf("\t\tcom_seq = %u\n", vop.com.com_seq);
- printf("\t\tprogramType = %d (%s)\n",
- vop.com.programType, program_type_to_string(vop.com.programType));
+ printf("\t\tprogramType = %d (%s)\n",
+ vop.com.programType, VPTypeToString(vop.com.programType));
printf("\t\tpid = %d\n", vop.com.pid);
printf("\t\ttid = %d\n", vop.com.tid);
- printf("\t\tcommand = %d (%s)\n",
- vop.com.command, command_code_to_string(vop.com.command));
- printf("\t\treason = %d (%s)\n",
- vop.com.reason, reason_code_to_string(vop.com.reason));
+ printf("\t\tcommand = %d (%s)\n",
+ vop.com.command, FSYNC_com2string(vop.com.command));
+ printf("\t\treason = %d (%s)\n",
+ vop.com.reason, FSYNC_reason2string(vop.com.reason));
printf("\t\tcommand_len = %u\n", vop.com.command_len);
printf("\t\tflags = 0x%lux\n", afs_printable_uint32_lu(vop.com.flags));
printf("\t}\n");
static int
vn_prolog(struct cmd_syndesc * as, struct state * state)
{
- register struct cmd_item *ti;
+ struct cmd_item *ti;
state->vop = (struct volop_state *) calloc(1, sizeof(struct volop_state));
assert(state->vop != NULL);
qry.spare = 0;
strlcpy(qry.partName, state->vop->partName, sizeof(qry.partName));
- fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n",
- command, command_code_to_string(command));
+ fprintf(stderr, "calling FSYNC_GenericOp with command code %d (%s)\n",
+ command, FSYNC_com2string(command));
code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
SYNC_response res;
Vnode v;
+ dafs_prolog();
+
res.hdr.response_len = sizeof(res.hdr);
res.payload.buf = res_buf;
res.payload.len = SYNC_PROTO_MAX_LEN;
do_vnqry(&state, &res);
if (res.hdr.response == SYNC_OK) {
- memcpy(&v, res.payload.buf, sizeof(Volume));
+ memcpy(&v, res.payload.buf, sizeof(Vnode));
printf("vnode = {\n");
#ifdef AFS_DEMAND_ATTACH_FS
if (!(res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS)) {
- printf("*** fssync-debug built to expect demand attach extensions. server asserted\n");
- printf("*** that it was not compiled with demand attach turned on. please recompile\n");
- printf("*** fssync-debug to match your server\n");
+ printf("*** this fssync-debug is built to expect demand attach extensions.\n"
+ "*** server asserted that is was not compiled with demand attach.\n"
+ "*** please use an fssync-debug without demand attach to match your\n"
+ "*** server.\n");
goto done;
}
printf("\tvn_state = %s\n", vn_state_to_string(v.vn_state));
#else
if (res.hdr.flags & SYNC_FLAG_DAFS_EXTENSIONS) {
- printf("*** server asserted demand attach extensions. fssync-debug not built to\n");
- printf("*** recognize those extensions. please recompile fssync-debug if you need\n");
- printf("*** to dump dafs extended state\n");
+ printf("*** server asserted demand attach extensions. this fssync-debug is not\n"
+ "*** built to recognize those extensions. please use an fssync-debug\n"
+ "*** with demand attach to match your server.\n");
goto done;
}
#endif /* !AFS_DEMAND_ATTACH_FS */
SYNC_PROTO_BUF_DECL(res_buf);
SYNC_response res;
FSSYNC_StatsOp_hdr scom;
- union {
- void * ptr;
- struct VolPkgStats * vol_stats;
- struct VolumeHashChainStats * hash_stats;
-#ifdef AFS_DEMAND_ATTACH_FS
- struct volume_hdr_LRU_stats * hdr_stats;
-#endif
- struct DiskPartitionStats64 * vicep_stats;
- } sres;
- sres.ptr = res_buf;
res.hdr.response_len = sizeof(res.hdr);
res.payload.buf = res_buf;
res.payload.len = SYNC_PROTO_MAX_LEN;
common_prolog(as, &state);
- fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
- command, command_code_to_string(command));
+ fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n",
+ command, FSYNC_com2string(command));
code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
fprintf(stderr, "possible sync protocol error. return code was %d\n", code);
}
- fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, response_code_to_string(code));
- fprintf(stderr, "protocol response code was %d (%s)\n",
- res.hdr.response, response_code_to_string(res.hdr.response));
- fprintf(stderr, "protocol reason code was %d (%s)\n",
- res.hdr.reason, reason_code_to_string(res.hdr.reason));
+ fprintf(stderr, "FSYNC_VolOp returned %d (%s)\n", code, SYNC_res2string(code));
+ fprintf(stderr, "protocol response code was %d (%s)\n",
+ res.hdr.response, SYNC_res2string(res.hdr.response));
+ fprintf(stderr, "protocol reason code was %d (%s)\n",
+ res.hdr.reason, FSYNC_reason2string(res.hdr.reason));
VDisconnectFS();
if (res.hdr.response == SYNC_OK) {
switch (command) {
case FSYNC_VOL_STATS_GENERAL:
- print_vol_stats_general(sres.vol_stats);
- break;
+ {
+ struct VolPkgStats vol_stats;
+ memcpy(&vol_stats, res_buf, sizeof(vol_stats));
+ print_vol_stats_general(&vol_stats);
+ break;
+ }
case FSYNC_VOL_STATS_VICEP:
- print_vol_stats_viceP(sres.vicep_stats);
- break;
+ {
+ struct DiskPartitionStats64 vicep_stats;
+ memcpy(&vicep_stats, res_buf, sizeof(vicep_stats));
+ print_vol_stats_viceP(&vicep_stats);
+ break;
+ }
case FSYNC_VOL_STATS_HASH:
- print_vol_stats_hash(sres.hash_stats);
- break;
+ {
+ struct VolumeHashChainStats hash_stats;
+ memcpy(&hash_stats, res_buf, sizeof(hash_stats));
+ print_vol_stats_hash(&hash_stats);
+ break;
+ }
#ifdef AFS_DEMAND_ATTACH_FS
case FSYNC_VOL_STATS_HDR:
- print_vol_stats_hdr(sres.hdr_stats);
- break;
+ {
+ struct volume_hdr_LRU_stats hdr_stats;
+ memcpy(&hdr_stats, res_buf, sizeof(hdr_stats));
+ print_vol_stats_hdr(&hdr_stats);
+ break;
+ }
#endif /* AFS_DEMAND_ATTACH_FS */
}
}
printf("VolPkgStats = {\n");
#ifdef AFS_DEMAND_ATTACH_FS
for (i = 0; i < VOL_STATE_COUNT; i++) {
- printf("\tvol_state_count[%s] = %d\n",
+ printf("\tvol_state_count[%s] = %d\n",
vol_state_to_string(i),
stats->state_levels[i]);
}
printf("\t}\n");
printf("\thdr_cache_size = %d\n", stats->hdr_cache_size);
-
+
printf("}\n");
}