icl trace code deduplication
authorDerrick Brashear <shadow@dementia.org>
Tue, 2 Feb 2010 05:16:54 +0000 (00:16 -0500)
committerDerrick Brashear <shadow|account-1000005@unknown>
Tue, 2 Feb 2010 14:08:22 +0000 (06:08 -0800)
right now we have 2 copies of the same code for dealing with traced objects.
it's the same code! make a function, and call it 4 times.

Change-Id: I1c8b6d7b2cff59108eada1522ba1ec76efeba421
Reviewed-on: http://gerrit.openafs.org/1199
Tested-by: Derrick Brashear <shadow@dementia.org>
Reviewed-by: Simon Wilkinson <sxw@inf.ed.ac.uk>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/afs/afs_icl.c
src/config/icl.h
src/venus/fstrace.c

index 5a38b55..1f33bf7 100644 (file)
@@ -564,6 +564,51 @@ afs_icl_UseAddr(int type)
        return 0;
 }
 
+void
+afs_icl_AppendOne(struct afs_icl_log *logp, int type, long parm)
+{
+    if (type) {
+       /* marshall parameter 3 now */
+       if (type == ICL_TYPE_STRING)
+           afs_icl_AppendString(logp, (char *)parm);
+       else if (type == ICL_TYPE_HYPER) {
+           ICL_APPENDINT32(logp,
+                           (afs_int32) ((struct afs_hyper_t *)parm)->high);
+           ICL_APPENDINT32(logp,
+                           (afs_int32) ((struct afs_hyper_t *)parm)->low);
+       } else if (type == ICL_TYPE_INT64) {
+#ifndef WORDS_BIGENDIAN
+#ifdef AFS_64BIT_CLIENT
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[1]);
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[0]);
+#else /* AFS_64BIT_CLIENT */
+           ICL_APPENDINT32(logp, (afs_int32) parm);
+           ICL_APPENDINT32(logp, (afs_int32) 0);
+#endif /* AFS_64BIT_CLIENT */
+#else /* AFSLITTLE_ENDIAN */
+#ifdef AFS_64BIT_CLIENT
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[0]);
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[1]);
+#else /* AFS_64BIT_CLIENT */
+           ICL_APPENDINT32(logp, (afs_int32) 0);
+           ICL_APPENDINT32(logp, (afs_int32) parm);
+#endif /* AFS_64BIT_CLIENT */
+#endif /* AFSLITTLE_ENDIAN */
+       } else if (type == ICL_TYPE_FID) {
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[0]);
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[1]);
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[2]);
+           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) parm)[3]);
+       }
+#if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
+       else if (type == ICL_TYPE_INT32)
+           ICL_APPENDINT32(logp, (afs_int32) parm);
+#endif
+       else
+           ICL_APPENDLONG(logp, parm);
+    }
+}
+
 /* Function to append a record to the log.  Written for speed
  * since we know that we're going to have to make this work fast
  * pretty soon, anyway.  The log must be unlocked.
@@ -614,30 +659,30 @@ afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
        logp->lastTS = tv.tv_sec;
     }
 
-    rsize = 4;                 /* base case */
+    rsize = 4;                 /* base case: see 4 items below */
     if (t1) {
        /* compute size of parameter p1.  Only tricky case is string.
         * In that case, we have to call strlen to get the string length.
         */
-       ICL_SIZEHACK(t1, p1);
+       ICL_SIZEHACK(t1, p1, tsize, rsize);
     }
     if (t2) {
        /* compute size of parameter p2.  Only tricky case is string.
         * In that case, we have to call strlen to get the string length.
         */
-       ICL_SIZEHACK(t2, p2);
+       ICL_SIZEHACK(t2, p2, tsize, rsize);
     }
     if (t3) {
        /* compute size of parameter p3.  Only tricky case is string.
         * In that case, we have to call strlen to get the string length.
         */
-       ICL_SIZEHACK(t3, p3);
+       ICL_SIZEHACK(t3, p3, tsize, rsize);
     }
     if (t4) {
        /* compute size of parameter p4.  Only tricky case is string.
         * In that case, we have to call strlen to get the string length.
         */
-       ICL_SIZEHACK(t4, p4);
+       ICL_SIZEHACK(t4, p4, tsize, rsize);
     }
 
     /* At this point, we've computed all of the parameter sizes, and
@@ -661,166 +706,10 @@ afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op,
     ICL_APPENDINT32(logp,
                    (afs_int32) (tv.tv_sec & 0x3ff) * 1000000 + tv.tv_usec);
 
-    if (t1) {
-       /* marshall parameter 1 now */
-       if (t1 == ICL_TYPE_STRING) {
-           afs_icl_AppendString(logp, (char *)p1);
-       } else if (t1 == ICL_TYPE_HYPER) {
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p1)->high);
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p1)->low);
-       } else if (t1 == ICL_TYPE_INT64) {
-#ifndef WORDS_BIGENDIAN
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) p1);
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-#endif /* AFS_64BIT_CLIENT */
-#else /* AFSLITTLE_ENDIAN */
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-           ICL_APPENDINT32(logp, (afs_int32) p1);
-#endif /* AFS_64BIT_CLIENT */
-#endif /* AFSLITTLE_ENDIAN */
-       } else if (t1 == ICL_TYPE_FID) {
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[2]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p1)[3]);
-       }
-#if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
-       else if (t1 == ICL_TYPE_INT32)
-           ICL_APPENDINT32(logp, (afs_int32) p1);
-#endif
-       else
-           ICL_APPENDLONG(logp, p1);
-    }
-    if (t2) {
-       /* marshall parameter 2 now */
-       if (t2 == ICL_TYPE_STRING)
-           afs_icl_AppendString(logp, (char *)p2);
-       else if (t2 == ICL_TYPE_HYPER) {
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p2)->high);
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p2)->low);
-       } else if (t2 == ICL_TYPE_INT64) {
-#ifndef WORDS_BIGENDIAN
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) p2);
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-#endif /* AFS_64BIT_CLIENT */
-#else /* AFSLITTLE_ENDIAN */
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-           ICL_APPENDINT32(logp, (afs_int32) p2);
-#endif /* AFS_64BIT_CLIENT */
-#endif /* AFSLITTLE_ENDIAN */
-       } else if (t2 == ICL_TYPE_FID) {
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[2]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p2)[3]);
-       }
-#if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
-       else if (t2 == ICL_TYPE_INT32)
-           ICL_APPENDINT32(logp, (afs_int32) p2);
-#endif
-       else
-           ICL_APPENDLONG(logp, p2);
-    }
-    if (t3) {
-       /* marshall parameter 3 now */
-       if (t3 == ICL_TYPE_STRING)
-           afs_icl_AppendString(logp, (char *)p3);
-       else if (t3 == ICL_TYPE_HYPER) {
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p3)->high);
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p3)->low);
-       } else if (t3 == ICL_TYPE_INT64) {
-#ifndef WORDS_BIGENDIAN
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) p3);
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-#endif /* AFS_64BIT_CLIENT */
-#else /* AFSLITTLE_ENDIAN */
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-           ICL_APPENDINT32(logp, (afs_int32) p3);
-#endif /* AFS_64BIT_CLIENT */
-#endif /* AFSLITTLE_ENDIAN */
-       } else if (t3 == ICL_TYPE_FID) {
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[2]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p3)[3]);
-       }
-#if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
-       else if (t3 == ICL_TYPE_INT32)
-           ICL_APPENDINT32(logp, (afs_int32) p3);
-#endif
-       else
-           ICL_APPENDLONG(logp, p3);
-    }
-    if (t4) {
-       /* marshall parameter 4 now */
-       if (t4 == ICL_TYPE_STRING)
-           afs_icl_AppendString(logp, (char *)p4);
-       else if (t4 == ICL_TYPE_HYPER) {
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p4)->high);
-           ICL_APPENDINT32(logp,
-                           (afs_int32) ((struct afs_hyper_t *)p4)->low);
-       } else if (t4 == ICL_TYPE_INT64) {
-#ifndef WORDS_BIGENDIAN
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) p4);
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-#endif /* AFS_64BIT_CLIENT */
-#else /* AFSLITTLE_ENDIAN */
-#ifdef AFS_64BIT_CLIENT
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
-#else /* AFS_64BIT_CLIENT */
-           ICL_APPENDINT32(logp, (afs_int32) 0);
-           ICL_APPENDINT32(logp, (afs_int32) p4);
-#endif /* AFS_64BIT_CLIENT */
-#endif /* AFSLITTLE_ENDIAN */
-       } else if (t4 == ICL_TYPE_FID) {
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[0]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[1]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[2]);
-           ICL_APPENDINT32(logp, (afs_int32) ((afs_int32 *) p4)[3]);
-       }
-#if (defined(AFS_SGI61_ENV) && (_MIPS_SZLONG==64)) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
-       else if (t4 == ICL_TYPE_INT32)
-           ICL_APPENDINT32(logp, (afs_int32) p4);
-#endif
-       else
-           ICL_APPENDLONG(logp, p4);
-    }
+    afs_icl_AppendOne(logp, t1, p1);
+    afs_icl_AppendOne(logp, t2, p2);
+    afs_icl_AppendOne(logp, t3, p3);
+    afs_icl_AppendOne(logp, t4, p4);
     ReleaseWriteLock(&logp->lock);
 }
 
index 6c04403..deb1114 100644 (file)
@@ -150,20 +150,20 @@ struct afs_icl_log {
  */
 extern int afs_icl_sizeofLong;
 
-#define ICL_SIZEHACK(t1, p1) \
+#define ICL_SIZEHACK(t1, p1, ts1, rs1)         \
     MACRO_BEGIN \
        if ((t1) == ICL_TYPE_STRING) { \
-           tsize = (int)((unsigned)(strlen((char *)(p1)) + 4) >> 2); \
+           ts1 = (int)((unsigned)(strlen((char *)(p1)) + 4) >> 2); \
        } else if ((t1) == ICL_TYPE_HYPER  || (t1) == ICL_TYPE_INT64) \
-           tsize = 2; \
+           ts1 = 2; \
        else if ((t1) == ICL_TYPE_FID) \
-           tsize = 4; \
+           ts1 = 4; \
        else if ((t1) == ICL_TYPE_INT32) \
-           tsize = 1; \
+           ts1 = 1; \
        else \
-           tsize = afs_icl_sizeofLong; \
+           ts1 = afs_icl_sizeofLong; \
        /* now add in the parameter */ \
-       rsize += tsize; \
+       rs1 += ts1; \
     MACRO_END
 
 /* log flags */
index 6f438f9..2fb9645 100644 (file)
@@ -121,7 +121,7 @@ icl_GetSize(afs_int32 type, char *addr)
     int tsize;
 
     rsize = 0;
-    ICL_SIZEHACK(type, addr);
+    ICL_SIZEHACK(type, addr, tsize, rsize);
     return rsize;
 }