Move *SYNC string translation out of fssync-debug
authorAndrew Deason <adeason@sinenomine.net>
Wed, 24 Feb 2010 15:47:03 +0000 (09:47 -0600)
committerDerrick Brashear <shadow@dementia.org>
Tue, 9 Mar 2010 19:04:57 +0000 (11:04 -0800)
Move the routines for translating ProgramType codes, and SYNC command
codes, response codes, etc out of fssync-debug, and into header files
anyone can use. These routines are useful especially for SYNC-related
debug or error logs.

Change-Id: Idc5ffe0dd798a9f18ca733e94d0bb4d740ad0836
Reviewed-on: http://gerrit.openafs.org/1390
Tested-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Alistair Ferguson <alistair.ferguson@mac.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/vol/daemon_com_inline.h [new file with mode: 0644]
src/vol/fssync-debug.c
src/vol/fssync_inline.h [new file with mode: 0644]
src/vol/volume_inline.h

diff --git a/src/vol/daemon_com_inline.h b/src/vol/daemon_com_inline.h
new file mode 100644 (file)
index 0000000..a6f5ea7
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010, Sine Nomine Associates.
+ * 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
+ */
+
+#ifndef AFS_VOL_DAEMON_COM_INLINE_H
+#define AFS_VOL_DAEMON_COM_INLINE_H
+
+#include "daemon_com.h"
+
+#define SYNC_ENUMCASE(en) \
+    case en: \
+        return #en; \
+        break
+
+static_inline char *
+SYNC_res2string(afs_int32 response)
+{
+    switch (response) {
+       SYNC_ENUMCASE(SYNC_OK);
+       SYNC_ENUMCASE(SYNC_DENIED);
+       SYNC_ENUMCASE(SYNC_COM_ERROR);
+       SYNC_ENUMCASE(SYNC_BAD_COMMAND);
+       SYNC_ENUMCASE(SYNC_FAILED);
+    default:
+       return "**UNKNOWN**";
+    }
+}
+
+#undef SYNC_ENUMCASE
+
+#endif /* AFS_VOL_DAEMON_COM_INLINE_H */
index 080d63e..6571437 100644 (file)
 #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>
@@ -85,11 +88,6 @@ 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);
@@ -341,13 +339,13 @@ debug_response(afs_int32 code, SYNC_response * res)
        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;
@@ -367,7 +365,7 @@ do_volop(struct state * state, afs_int32 command, SYNC_response * res)
     }
 
     fprintf(stderr, "calling FSYNC_VolOp with command code %d (%s)\n", 
-           command, command_code_to_string(command));
+           command, FSYNC_com2string(command));
 
     code = FSYNC_VolOp(state->vop->volume,
                       state->vop->partName,
@@ -401,96 +399,6 @@ do_volop(struct state * state, afs_int32 command, SYNC_response * res)
         } \
     } 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 
 VolOnline(struct cmd_syndesc * as, void * rock)
 {
@@ -883,7 +791,7 @@ VolHdrQuery(struct cmd_syndesc * as, void * rock)
        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);
        }
@@ -960,13 +868,13 @@ VolOpQuery(struct cmd_syndesc * as, void * rock)
        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));
+              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));
+              vop.com.command, FSYNC_com2string(vop.com.command));
        printf("\t\treason         = %d (%s)\n", 
-              vop.com.reason, reason_code_to_string(vop.com.reason));
+              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");
@@ -1036,7 +944,7 @@ do_vnqry(struct state * state, SYNC_response * res)
     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));
+           command, FSYNC_com2string(command));
 
     code = FSYNC_GenericOp(&qry, sizeof(qry), command, FSYNC_OPERATOR, res);
 
@@ -1227,7 +1135,7 @@ StatsQuery(struct cmd_syndesc * as, void * rock)
     common_prolog(as, &state);
 
     fprintf(stderr, "calling FSYNC_askfs with command code %d (%s)\n", 
-           command, command_code_to_string(command));
+           command, FSYNC_com2string(command));
 
     code = FSYNC_StatsOp(&scom, command, FSYNC_WHATEVER, &res);
 
@@ -1239,11 +1147,11 @@ StatsQuery(struct cmd_syndesc * as, void * rock)
        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, "FSYNC_VolOp returned %d (%s)\n", code, SYNC_res2string(code));
     fprintf(stderr, "protocol 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));
 
     VDisconnectFS();
 
diff --git a/src/vol/fssync_inline.h b/src/vol/fssync_inline.h
new file mode 100644 (file)
index 0000000..ce91dd7
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2010, Sine Nomine Associates.
+ * 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
+ */
+
+#ifndef AFS_VOL_FSSYNC_INLINE_H
+#define AFS_VOL_FSSYNC_INLINE_H
+
+#include "fssync.h"
+
+#define FSYNC_ENUMCASE(en) \
+    case en: \
+        return #en; \
+        break
+
+static_inline char *
+FSYNC_com2string(afs_int32 command)
+{
+    switch (command) {
+       FSYNC_ENUMCASE(SYNC_COM_CHANNEL_CLOSE);
+       FSYNC_ENUMCASE(FSYNC_VOL_ON);
+       FSYNC_ENUMCASE(FSYNC_VOL_OFF);
+       FSYNC_ENUMCASE(FSYNC_VOL_LISTVOLUMES);
+       FSYNC_ENUMCASE(FSYNC_VOL_NEEDVOLUME);
+       FSYNC_ENUMCASE(FSYNC_VOL_MOVE);
+       FSYNC_ENUMCASE(FSYNC_VOL_BREAKCBKS);
+       FSYNC_ENUMCASE(FSYNC_VOL_DONE);
+       FSYNC_ENUMCASE(FSYNC_VOL_QUERY);
+       FSYNC_ENUMCASE(FSYNC_VOL_QUERY_HDR);
+       FSYNC_ENUMCASE(FSYNC_VOL_QUERY_VOP);
+       FSYNC_ENUMCASE(FSYNC_VOL_STATS_GENERAL);
+       FSYNC_ENUMCASE(FSYNC_VOL_STATS_VICEP);
+       FSYNC_ENUMCASE(FSYNC_VOL_STATS_HASH);
+       FSYNC_ENUMCASE(FSYNC_VOL_STATS_HDR);
+       FSYNC_ENUMCASE(FSYNC_VOL_STATS_VLRU);
+       FSYNC_ENUMCASE(FSYNC_VOL_ATTACH);
+       FSYNC_ENUMCASE(FSYNC_VOL_FORCE_ERROR);
+       FSYNC_ENUMCASE(FSYNC_VOL_LEAVE_OFF);
+       FSYNC_ENUMCASE(FSYNC_VOL_QUERY_VNODE);
+       FSYNC_ENUMCASE(FSYNC_VG_QUERY);
+       FSYNC_ENUMCASE(FSYNC_VG_ADD);
+       FSYNC_ENUMCASE(FSYNC_VG_DEL);
+       FSYNC_ENUMCASE(FSYNC_VG_SCAN);
+       FSYNC_ENUMCASE(FSYNC_VG_SCAN_ALL);
+
+    default:
+       return "**UNKNOWN**";
+    }
+}
+
+static_inline char *
+FSYNC_reason2string(afs_int32 reason)
+{
+    switch (reason) {
+       FSYNC_ENUMCASE(SYNC_REASON_NONE);
+       FSYNC_ENUMCASE(SYNC_REASON_MALFORMED_PACKET);
+       FSYNC_ENUMCASE(SYNC_REASON_NOMEM);
+       FSYNC_ENUMCASE(SYNC_REASON_ENCODING_ERROR);
+       FSYNC_ENUMCASE(FSYNC_WHATEVER);
+       FSYNC_ENUMCASE(FSYNC_SALVAGE);
+       FSYNC_ENUMCASE(FSYNC_MOVE);
+       FSYNC_ENUMCASE(FSYNC_OPERATOR);
+       FSYNC_ENUMCASE(FSYNC_EXCLUSIVE);
+       FSYNC_ENUMCASE(FSYNC_UNKNOWN_VOLID);
+       FSYNC_ENUMCASE(FSYNC_HDR_NOT_ATTACHED);
+       FSYNC_ENUMCASE(FSYNC_NO_PENDING_VOL_OP);
+       FSYNC_ENUMCASE(FSYNC_VOL_PKG_ERROR);
+       FSYNC_ENUMCASE(FSYNC_UNKNOWN_VNID);
+       FSYNC_ENUMCASE(FSYNC_WRONG_PART);
+       FSYNC_ENUMCASE(FSYNC_BAD_STATE);
+       FSYNC_ENUMCASE(FSYNC_BAD_PART);
+       FSYNC_ENUMCASE(FSYNC_PART_SCANNING);
+    default:
+       return "**UNKNOWN**";
+    }
+}
+
+#undef FSYNC_ENUMCASE
+
+#endif /* AFS_VOL_FSSYNC_INLINE_H */
index d51c81d..2342b64 100644 (file)
@@ -293,4 +293,35 @@ VChangeState_r(Volume * vp, VolState new_state)
 
 #endif /* AFS_DEMAND_ATTACH_FS */
 
+#define VENUMCASE(en) \
+    case en: \
+        return #en; \
+        break
+
+/**
+ * translate a ProgramType code to a string.
+ *
+ * @param[in] type ProgramType numeric code
+ *
+ * @return a human-readable string for that program type
+ *  @retval "**UNKNOWN**" an unknown ProgramType was given
+ */
+static_inline char *
+VPTypeToString(ProgramType type)
+{
+    switch (type) {
+       VENUMCASE(fileServer);
+       VENUMCASE(volumeUtility);
+       VENUMCASE(salvager);
+       VENUMCASE(salvageServer);
+       VENUMCASE(debugUtility);
+       VENUMCASE(volumeServer);
+       VENUMCASE(volumeSalvager);
+    default:
+       return "**UNKNOWN**";
+    }
+}
+
+#undef VENUMCASE
+
 #endif /* _AFS_VOL_VOLUME_INLINE_H */