viced: Remove logging duplication
authorSimon Wilkinson <sxw@your-file-system.com>
Fri, 8 Apr 2011 15:18:13 +0000 (16:18 +0100)
committerDerrick Brashear <shadow@dementia.org>
Tue, 12 Apr 2011 22:51:56 +0000 (15:51 -0700)
In lots of places in the fileserver we were doing
    ViceLog(0, (x))
    osi_Panic(x)

Remove this duplication by creating a new macro, ViceLogThenPanic,
which does both of these in one fell swoop.

Change-Id: Icea349d60298eba1cca4a45db790f21ba3e7b3c7
Reviewed-on: http://gerrit.openafs.org/4455
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/util/afsutil.h
src/viced/afsfileprocs.c
src/viced/callback.c
src/viced/host.c
src/viced/viced.c

index 45a3940..31bed66 100644 (file)
@@ -50,6 +50,8 @@ extern void FSLog(const char *format, ...)
 
 #define ViceLog(level, str)  do { if ((level) <= LogLevel) (FSLog str); } while (0)
 #define vViceLog(level, str) do { if ((level) <= LogLevel) (vFSLog str); } while (0)
+#define ViceLogThenPanic(level, str) \
+    do { ViceLog(level, str); osi_Panic str; } while(0);
 
 extern int OpenLog(const char *filename);
 extern int ReOpenLog(const char *fileName);
index 9150406..05d8ae4 100644 (file)
@@ -2028,30 +2028,26 @@ RXGetVolumeStatus(AFSFetchVolumeStatus * status, char **name, char **offMsg,
     temp = strlen(V_name(volptr)) + 1;
     *name = malloc(temp);
     if (!*name) {
-       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
-       osi_Panic("Failed malloc in RXGetVolumeStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
     }
     strcpy(*name, V_name(volptr));
     temp = strlen(V_offlineMessage(volptr)) + 1;
     *offMsg = malloc(temp);
     if (!*offMsg) {
-       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
-       osi_Panic("Failed malloc in RXGetVolumeStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
     }
     strcpy(*offMsg, V_offlineMessage(volptr));
 #if OPENAFS_VOL_STATS
     *motd = malloc(1);
     if (!*motd) {
-       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
-       osi_Panic("Failed malloc in RXGetVolumeStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
     }
     strcpy(*motd, nullString);
 #else
     temp = strlen(V_motd(volptr)) + 1;
     *motd = malloc(temp);
     if (!*motd) {
-       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
-       osi_Panic("Failed malloc in RXGetVolumeStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in RXGetVolumeStatus\n"));
     }
     strcpy(*motd, V_motd(volptr));
 #endif /* FS_STATS_DETAILED */
@@ -2140,8 +2136,7 @@ AllocSendBuffer(void)
        FS_UNLOCK;
        tmp = malloc(sendBufSize);
        if (!tmp) {
-           ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
-           osi_Panic("Failed malloc in AllocSendBuffer\n");
+           ViceLogThenPanic(0, ("Failed malloc in AllocSendBuffer\n"));
        }
        return tmp;
     }
@@ -2517,8 +2512,7 @@ SRXAFS_FetchACL(struct rx_call * acall, struct AFSFid * Fid,
     AccessList->AFSOpaque_len = 0;
     AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
     if (!AccessList->AFSOpaque_val) {
-       ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
-       osi_Panic("Failed malloc in SRXAFS_FetchACL\n");
+       ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchACL\n"));
     }
 
     /*
@@ -2707,15 +2701,13 @@ SRXAFS_BulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
     OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
        malloc(nfiles * sizeof(struct AFSFetchStatus));
     if (!OutStats->AFSBulkStats_val) {
-       ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
-       osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
     }
     OutStats->AFSBulkStats_len = nfiles;
     CallBacks->AFSCBs_val = (struct AFSCallBack *)
        malloc(nfiles * sizeof(struct AFSCallBack));
     if (!CallBacks->AFSCBs_val) {
-       ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
-       osi_Panic("Failed malloc in SRXAFS_BulkStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
     }
     CallBacks->AFSCBs_len = nfiles;
 
@@ -2858,15 +2850,13 @@ SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
     OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
        malloc(nfiles * sizeof(struct AFSFetchStatus));
     if (!OutStats->AFSBulkStats_val) {
-       ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
-       osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
     }
     OutStats->AFSBulkStats_len = nfiles;
     CallBacks->AFSCBs_val = (struct AFSCallBack *)
        malloc(nfiles * sizeof(struct AFSCallBack));
     if (!CallBacks->AFSCBs_val) {
-       ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
-       osi_Panic("Failed malloc in SRXAFS_FetchStatus\n");
+       ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
     }
     CallBacks->AFSCBs_len = nfiles;
 
index 13b5cf1..3322b0e 100644 (file)
@@ -346,11 +346,9 @@ CDel(struct CallBack *cb, int deletefe)
     for (safety = 0, cbp = &fe->firstcb; *cbp && *cbp != cbi;
         cbp = &itocb(*cbp)->cnext, safety++) {
        if (safety > cbstuff.nblks + 10) {
-           osi_Panic("CDel: Internal Error -- shutting down: wanted %d from %d, now at %d\n",
-                     cbi, fe->firstcb, *cbp);
-           ViceLog(0,
-                   ("CDel: Internal Error -- shutting down: wanted %d from %d, now at %d\n",
-                    cbi, fe->firstcb, *cbp));
+           ViceLogThenPanic(0, ("CDel: Internal Error -- shutting down: "
+                                "wanted %d from %d, now at %d\n",
+                                cbi, fe->firstcb, *cbp));
            DumpCallBackState_r();
            ShutDownAndCore(PANIC);
        }
@@ -431,8 +429,7 @@ InitCallBack(int nblks)
      * FE[0] and CB[0] are not used--and not allocated */
     FE = ((struct FileEntry *)(calloc(nblks, sizeof(struct FileEntry))));
     if (!FE) {
-       ViceLog(0, ("Failed malloc in InitCallBack\n"));
-       osi_Panic("Failed malloc in InitCallBack\n");
+       ViceLogThenPanic(0, ("Failed malloc in InitCallBack\n"));
     }
     FE--;  /* FE[0] is supposed to point to junk */
     cbstuff.nFEs = nblks;
@@ -440,8 +437,7 @@ InitCallBack(int nblks)
        FreeFE(&FE[cbstuff.nFEs]);      /* This is correct */
     CB = ((struct CallBack *)(calloc(nblks, sizeof(struct CallBack))));
     if (!CB) {
-       ViceLog(0, ("Failed malloc in InitCallBack\n"));
-       osi_Panic("Failed malloc in InitCallBack\n");
+       ViceLogThenPanic(0, ("Failed malloc in InitCallBack\n"));
     }
     CB--;  /* CB[0] is supposed to point to junk */
     cbstuff.nCBs = nblks;
@@ -2961,9 +2957,8 @@ MultiBreakCallBackAlternateAddress_r(struct host *host,
     interfaces = calloc(i, sizeof(struct AddrPort));
     conns = calloc(i, sizeof(struct rx_connection *));
     if (!interfaces || !conns) {
-       ViceLog(0,
-               ("Failed malloc in MultiBreakCallBackAlternateAddress_r\n"));
-       osi_Panic("Failed malloc in MultiBreakCallBackAlternateAddress_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in "
+                            "MultiBreakCallBackAlternateAddress_r\n"));
     }
 
     /* initialize alternate rx connections */
@@ -3057,8 +3052,8 @@ MultiProbeAlternateAddress_r(struct host *host)
     interfaces = calloc(i, sizeof(struct AddrPort));
     conns = calloc(i, sizeof(struct rx_connection *));
     if (!interfaces || !conns) {
-       ViceLog(0, ("Failed malloc in MultiProbeAlternateAddress_r\n"));
-       osi_Panic("Failed malloc in MultiProbeAlternateAddress_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in "
+                            "MultiProbeAlternateAddress_r\n"));
     }
 
     /* initialize alternate rx connections */
index 9b27d2f..9e250c3 100644 (file)
@@ -979,13 +979,11 @@ h_Enumerate(int (*proc) (struct host*, int, void *), void *param)
     }
     list = (struct host **)malloc(hostCount * sizeof(struct host *));
     if (!list) {
-       ViceLog(0, ("Failed malloc in h_Enumerate (list)\n"));
-       osi_Panic("Failed malloc in h_Enumerate (list)\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_Enumerate (list)\n"));
     }
     flags = (int *)malloc(hostCount * sizeof(int));
     if (!flags) {
-       ViceLog(0, ("Failed malloc in h_Enumerate (flags)\n"));
-       osi_Panic("Failed malloc in h_Enumerate (flags)\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_Enumerate (flags)\n"));
     }
     for (totalCount = count = 0, host = hostList;
          host && totalCount < hostCount;
@@ -1146,8 +1144,7 @@ h_AddHostToUuidHashTable_r(struct afsUUID *uuid, struct host *host)
     /* insert into beginning of list for this bucket */
     chain = (struct h_UuidHashChain *)malloc(sizeof(struct h_UuidHashChain));
     if (!chain) {
-       ViceLog(0, ("Failed malloc in h_AddHostToUuidHashTable_r\n"));
-       osi_Panic("Failed malloc in h_AddHostToUuidHashTable_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_AddHostToUuidHashTable_r\n"));
     }
     chain->hostPtr = host;
     chain->next = hostUuidHashTable[index];
@@ -1333,8 +1330,7 @@ createHostAddrHashChain_r(int index, afs_uint32 addr, afs_uint16 port, struct ho
     /* insert into beginning of list for this bucket */
     chain = (struct h_AddrHashChain *)malloc(sizeof(struct h_AddrHashChain));
     if (!chain) {
-       ViceLog(0, ("Failed malloc in h_AddHostToAddrHashTable_r\n"));
-       osi_Panic("Failed malloc in h_AddHostToAddrHashTable_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_AddHostToAddrHashTable_r\n"));
     }
     chain->hostPtr = host;
     chain->next = hostAddrHashTable[index];
@@ -1554,8 +1550,7 @@ addInterfaceAddr_r(struct host *host, afs_uint32 addr, afs_uint16 port)
     interface = (struct Interface *)
        malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * number));
     if (!interface) {
-       ViceLog(0, ("Failed malloc in addInterfaceAddr_r\n"));
-       osi_Panic("Failed malloc in addInterfaceAddr_r\n");
+       ViceLogThenPanic(0, ("Failed malloc in addInterfaceAddr_r\n"));
     }
     interface->numberOfInterfaces = number + 1;
     interface->uuid = host->interface->uuid;
@@ -1747,8 +1742,7 @@ h_GetHost_r(struct rx_connection *tcon)
            ((code == 0) && (afs_uuid_equal(&interf.uuid, &nulluuid)))) {
            identP = (struct Identity *)malloc(sizeof(struct Identity));
            if (!identP) {
-               ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-               osi_Panic("Failed malloc in h_GetHost_r\n");
+               ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
            }
            identP->valid = 0;
            rx_SetSpecific(tcon, rxcon_ident_key, identP);
@@ -1789,8 +1783,7 @@ h_GetHost_r(struct rx_connection *tcon)
            interfValid = 1;
            identP = (struct Identity *)malloc(sizeof(struct Identity));
            if (!identP) {
-               ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-               osi_Panic("Failed malloc in h_GetHost_r\n");
+               ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
            }
            identP->valid = 1;
            identP->uuid = interf.uuid;
@@ -1978,8 +1971,7 @@ h_GetHost_r(struct rx_connection *tcon)
                    pident = 1;
 
                if (!identP) {
-                   ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-                   osi_Panic("Failed malloc in h_GetHost_r\n");
+                   ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
                }
                identP->valid = 0;
                if (!pident)
@@ -1997,8 +1989,7 @@ h_GetHost_r(struct rx_connection *tcon)
                    pident = 1;
 
                if (!identP) {
-                   ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-                   osi_Panic("Failed malloc in h_GetHost_r\n");
+                   ViceLogThenPanic(0, ("Failed malloc in h_GetHost_r\n"));
                }
                identP->valid = 1;
                interfValid = 1;
@@ -2262,8 +2253,7 @@ MapName_r(char *aname, char *acell, afs_int32 * aval)
            foreign = 1;        /* attempt cross-cell authentication */
            tname = (char *)malloc(PR_MAXNAMELEN);
            if (!tname) {
-               ViceLog(0, ("Failed malloc in MapName_r\n"));
-               osi_Panic("Failed malloc in MapName_r\n");
+               ViceLogThenPanic(0, ("Failed malloc in MapName_r\n"));
            }
            strcpy(tname, aname);
            tname[anamelen] = '@';
@@ -2695,8 +2685,7 @@ h_UserName(struct client *client)
     lids.idlist_len = 1;
     lids.idlist_val = (afs_int32 *) malloc(1 * sizeof(afs_int32));
     if (!lids.idlist_val) {
-       ViceLog(0, ("Failed malloc in h_UserName\n"));
-       osi_Panic("Failed malloc in h_UserName\n");
+       ViceLogThenPanic(0, ("Failed malloc in h_UserName\n"));
     }
     lnames.namelist_len = 0;
     lnames.namelist_val = (prname *) 0;
@@ -4033,16 +4022,14 @@ initInterfaceAddr_r(struct host *host, struct interfaceAddr *interf)
            malloc(sizeof(struct Interface) +
                   (sizeof(struct AddrPort) * (count - 1)));
        if (!interface) {
-           ViceLog(0, ("Failed malloc in initInterfaceAddr_r 1\n"));
-           osi_Panic("Failed malloc in initInterfaceAddr_r 1\n");
+           ViceLogThenPanic(0, ("Failed malloc in initInterfaceAddr_r 1\n"));
        }
        interface->numberOfInterfaces = count;
     } else {
        interface = (struct Interface *)
            malloc(sizeof(struct Interface) + (sizeof(struct AddrPort) * count));
        if (!interface) {
-           ViceLog(0, ("Failed malloc in initInterfaceAddr_r 2\n"));
-           osi_Panic("Failed malloc in initInterfaceAddr_r 2\n");
+           ViceLogThenPanic(0, ("Failed malloc in initInterfaceAddr_r 2\n"));
        }
        interface->numberOfInterfaces = count + 1;
        interface->interface[count].addr = myAddr;
index aabe7a3..e9770fd 100644 (file)
@@ -764,10 +764,9 @@ static void *
 ShutdownWatchdogLWP(void *unused)
 {
     sleep(panic_timeout);
-    ViceLog(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
-                "within %d seconds; forcing panic\n", panic_timeout));
-    osi_Panic("ShutdownWatchdogLWP: Failed to shutdown and panic "
-             "within %d seconds; forcing panic\n", panic_timeout);
+    ViceLogThenPanic(0, ("ShutdownWatchdogLWP: Failed to shutdown and panic "
+                         "within %d seconds; forcing panic\n",
+                        panic_timeout));
     return NULL;
 }
 
@@ -1590,9 +1589,8 @@ NewParms(int initializing)
 void
 Die(char *msg)
 {
-    ViceLog(0, ("%s\n", msg));
-    osi_Panic("%s\n", msg);
 
+    ViceLogThenPanic(0, ("%s\n", msg));
 }                              /*Die */