From 52c91be7ca3c834c470fc739696dffe5fd01c0fe Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 16 Jul 2010 23:20:27 +0100 Subject: [PATCH] vol: Fix logging functions Fix the Log, Abort and Quit functions used by the vol package so that they are all defined in a common header file, rather than prototyped in each file which uses them. Use the appropriate macros to flag those functions which never return, and mark them all as taking printf style input. Fix all of the callers which had mismatched format strings and arguments. Change-Id: I78194f623360e13f055f8f37b3558c08a70acd1f Reviewed-on: http://gerrit.openafs.org/2444 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/vol/clone.c | 7 +++---- src/vol/common.c | 2 ++ src/vol/common.h | 14 ++++++++++++++ src/vol/daemon_com.c | 3 +-- src/vol/fssync-client.c | 3 +-- src/vol/fssync-server.c | 3 +-- src/vol/namei_ops.c | 18 +++++++++++------- src/vol/nuke.c | 4 +--- src/vol/partition.c | 13 +++++++------ src/vol/purge.c | 3 +-- src/vol/salvaged.c | 6 +----- src/vol/salvager.c | 8 +------- src/vol/salvsync-client.c | 3 +-- src/vol/salvsync-server.c | 3 +-- src/vol/vnode.c | 20 +++++++++----------- src/vol/vol-salvage.c | 5 ++--- src/vol/volume.c | 4 ++-- src/vol/vutil.c | 3 +-- 18 files changed, 60 insertions(+), 62 deletions(-) create mode 100644 src/vol/common.h diff --git a/src/vol/clone.c b/src/vol/clone.c index 9e68ab57a..13cef1bb6 100644 --- a/src/vol/clone.c +++ b/src/vol/clone.c @@ -53,8 +53,7 @@ #include "partition.h" #include "viceinode.h" #include "vol_prototypes.h" - -/*@printflike@*/ extern void Log(const char *format, ...); +#include "common.h" int (*vol_PollProc) (void) = 0; /* someone must init this */ @@ -260,7 +259,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) } else if (rwinode) { if (IH_INC(V_linkHandle(rwvp), rwinode, V_parentId(rwvp)) == -1) { - Log("IH_INC failed: %x, %s, %u errno %d\n", + Log("IH_INC failed: %"AFS_PTR_FMT", %s, %u errno %d\n", V_linkHandle(rwvp), PrintInode(NULL, rwinode), V_parentId(rwvp), errno); VForceOffline(rwvp); @@ -313,7 +312,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone) if (inodeinced) { if (IH_DEC(V_linkHandle(rwvp), rwinode, V_parentId(rwvp)) == -1) { - Log("IH_DEC failed: %x, %s, %u errno %d\n", + Log("IH_DEC failed: %"AFS_PTR_FMT", %s, %u errno %d\n", V_linkHandle(rwvp), PrintInode(NULL, rwinode), V_parentId(rwvp), errno); VForceOffline(rwvp); diff --git a/src/vol/common.c b/src/vol/common.c index 753daef0b..6d6625f6b 100644 --- a/src/vol/common.c +++ b/src/vol/common.c @@ -23,6 +23,8 @@ #include +#include "common.h" + int Statistics = 0; /*@printflike@*/ void diff --git a/src/vol/common.h b/src/vol/common.h new file mode 100644 index 000000000..b2bc758c0 --- /dev/null +++ b/src/vol/common.h @@ -0,0 +1,14 @@ +#ifndef AFS_SRC_VOL_COMMON_H +#define AFS_SRC_VOL_COMMON_H + +/* common.c */ +extern void Log(const char *format, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2); +extern void Abort(const char *format, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2) + AFS_NORETURN; +extern void Quit(const char *format, ...) + AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2) + AFS_NORETURN; + +#endif diff --git a/src/vol/daemon_com.c b/src/vol/daemon_com.c index aaf67801b..3f582140f 100644 --- a/src/vol/daemon_com.c +++ b/src/vol/daemon_com.c @@ -53,6 +53,7 @@ #include "vnode.h" #include "volume.h" #include "partition.h" +#include "common.h" #include #ifdef USE_UNIX_SOCKETS @@ -60,8 +61,6 @@ #include #endif -/*@printflike@*/ extern void Log(const char *format, ...); - int (*V_BreakVolumeCallbacks) (VolumeId); #define MAXHANDLERS 4 /* Up to 4 clients; must be at least 2, so that diff --git a/src/vol/fssync-client.c b/src/vol/fssync-client.c index 4fa64486c..1725fa40d 100644 --- a/src/vol/fssync-client.c +++ b/src/vol/fssync-client.c @@ -70,11 +70,10 @@ #include "vnode.h" #include "volume.h" #include "partition.h" +#include "common.h" #ifdef FSSYNC_BUILD_CLIENT -/*@printflike@*/ extern void Log(const char *format, ...); - extern int LogLevel; static SYNC_client_state fssync_state = diff --git a/src/vol/fssync-server.c b/src/vol/fssync-server.c index f79f1e39a..c54ad3712 100644 --- a/src/vol/fssync-server.c +++ b/src/vol/fssync-server.c @@ -87,6 +87,7 @@ #include "volume_inline.h" #include "partition.h" #include "vg_cache.h" +#include "common.h" #ifdef HAVE_POLL #include @@ -99,8 +100,6 @@ #ifdef FSSYNC_BUILD_SERVER -/*@printflike@*/ extern void Log(const char *format, ...); - int (*V_BreakVolumeCallbacks) (VolumeId volume); #define MAXHANDLERS 4 /* Up to 4 clients; must be at least 2, so that diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index 26a0a753a..dc4cd8f20 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -41,6 +41,7 @@ #include "partition.h" #include "fssync.h" #include "volume_inline.h" +#include "common.h" #include /*@+fcnmacros +macrofcndecl@*/ @@ -65,8 +66,6 @@ extern off_t afs_lseek(int FD, off_t O, int F); #endif /* !O_LARGEFILE */ /*@=fcnmacros =macrofcndecl@*/ -/*@printflike@*/ extern void Log(const char *format, ...); - #ifndef LOCK_SH #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ @@ -1261,8 +1260,9 @@ ListViceInodes(char *devname, char *mountedOn, FILE *inodeFile, return -2; } if (status.st_size != ninodes * sizeof(struct ViceInodeInfo)) { - Log("Wrong size (%d instead of %d) in inode file for %s\n", - status.st_size, ninodes * sizeof(struct ViceInodeInfo), + Log("Wrong size (%d instead of %lu) in inode file for %s\n", + (int) status.st_size, + (long unsigned int) ninodes * sizeof(struct ViceInodeInfo), mountedOn); return -2; } @@ -1557,7 +1557,8 @@ convertVolumeInfo(int fdr, int fdw, afs_uint32 vid) if (read(fdr, &vd, sizeof(struct VolumeDiskData)) != sizeof(struct VolumeDiskData)) { - Log("1 convertVolumeInfo: read failed for %lu with code %d\n", vid, + Log("1 convertVolumeInfo: read failed for %lu with code %d\n", + afs_printable_uint32_lu(vid), errno); return -1; } @@ -1575,7 +1576,8 @@ convertVolumeInfo(int fdr, int fdw, afs_uint32 vid) } if (write(fdw, &vd, sizeof(struct VolumeDiskData)) != sizeof(struct VolumeDiskData)) { - Log("1 convertVolumeInfo: write failed for %lu with code %d\n", vid, + Log("1 convertVolumeInfo: write failed for %lu with code %d\n", + afs_printable_uint32_lu(vid), errno); return -1; } @@ -1697,7 +1699,9 @@ namei_ConvertROtoRWvolume(char *pname, afs_uint32 volumeId) continue; } } - Log("1 namei_ConvertROtoRWvolume: found special file %s/%s for volume %lu\n", dir_name, dp->d_name, info.u.param[0]); + Log("1 namei_ConvertROtoRWvolume: found special file %s/%s" + " for volume %lu\n", dir_name, dp->d_name, + afs_printable_uint32_lu(info.u.param[0])); closedir(dirp); code = VVOLEXISTS; goto done; diff --git a/src/vol/nuke.c b/src/vol/nuke.c index b937f5456..ae26a4792 100644 --- a/src/vol/nuke.c +++ b/src/vol/nuke.c @@ -45,6 +45,7 @@ #include "salvage.h" #include "daemon_com.h" #include "fssync.h" +#include "common.h" #ifdef O_LARGEFILE #define afs_stat stat64 @@ -52,9 +53,6 @@ #define afs_stat stat #endif /* !O_LARGEFILE */ -/*@printflike@*/ extern void Log(const char *format, ...); - - struct Lock localLock; #define MAXATONCE 100 diff --git a/src/vol/partition.c b/src/vol/partition.c index ca0aa3bc9..f9297f924 100644 --- a/src/vol/partition.c +++ b/src/vol/partition.c @@ -115,6 +115,7 @@ #include "lwp.h" #include #include "ihandle.h" +#include "common.h" #ifdef AFS_NAMEI_ENV #ifdef AFS_NT40_ENV #include "ntops.h" @@ -177,8 +178,6 @@ #endif /* !O_LARGEFILE */ -/*@printflike@*/ extern void Log(const char *format, ...); - int aixlow_water = 8; /* default 8% */ struct DiskPartition64 *DiskPartitionList; @@ -1093,12 +1092,14 @@ VPrintDiskStats_r(void) struct DiskPartition64 *dp; for (dp = DiskPartitionList; dp; dp = dp->next) { if (dp->free < 0) { - Log("Partition %s: %d available 1K blocks (minfree=%d), " - "overallocated by %d blocks\n", dp->name, + Log("Partition %s: %"AFS_INT64_FMT + " available 1K blocks (minfree=%"AFS_INT64_FMT"), " + "overallocated by %"AFS_INT64_FMT" blocks\n", dp->name, dp->totalUsable, dp->minFree, -dp->free); } else { - Log("Partition %s: %d available 1K blocks (minfree=%d), " - "%d free blocks\n", dp->name, + Log("Partition %s: %"AFS_INT64_FMT + " available 1K blocks (minfree=%"AFS_INT64_FMT"), " + "%"AFS_INT64_FMT" free blocks\n", dp->name, dp->totalUsable, dp->minFree, dp->free); } } diff --git a/src/vol/purge.c b/src/vol/purge.c index 17029abc7..d1f0fb6c8 100644 --- a/src/vol/purge.c +++ b/src/vol/purge.c @@ -48,6 +48,7 @@ #include "partition.h" #include "daemon_com.h" #include "fssync.h" +#include "common.h" /* forward declarations */ static int ObliterateRegion(Volume * avp, VnodeClass aclass, StreamHandle_t * afile, @@ -60,8 +61,6 @@ static void PurgeHeader(Volume * vp); static void PurgeIndex_r(Volume * vp, VnodeClass class); static void PurgeHeader_r(Volume * vp); -/*@printflike@*/ extern void Log(const char *format, ...); - /* No lock needed. Only the volserver will call this, and only one transaction * can have a given volume (volid/partition pair) in use at a time */ diff --git a/src/vol/salvaged.c b/src/vol/salvaged.c index f1dde1f94..6b6199d76 100644 --- a/src/vol/salvaged.c +++ b/src/vol/salvaged.c @@ -118,6 +118,7 @@ #include "viceinode.h" #include "salvage.h" #include "vol-salvage.h" +#include "common.h" #ifdef AFS_NT40_ENV #include #endif @@ -131,11 +132,6 @@ #error "online salvager not supported on NT" #endif /* AFS_NT40_ENV */ - -/* Forward declarations */ -/*@printflike@*/ void Log(const char *format, ...); - - /*@+fcnmacros +macrofcndecl@*/ #ifdef O_LARGEFILE #define afs_fopen fopen64 diff --git a/src/vol/salvager.c b/src/vol/salvager.c index 8d7ec45cb..c12f338c4 100644 --- a/src/vol/salvager.c +++ b/src/vol/salvager.c @@ -120,20 +120,14 @@ #include "viceinode.h" #include "salvage.h" #include "vol-salvage.h" +#include "common.h" #ifdef AFS_NT40_ENV #include pthread_t main_thread; #endif - static int get_salvage_lock = 0; - -/* Forward declarations */ -/*@printflike@*/ void Log(const char *format, ...); -/*@printflike@*/ void Abort(const char *format, ...); - - static int handleit(struct cmd_syndesc *as, void *arock) { diff --git a/src/vol/salvsync-client.c b/src/vol/salvsync-client.c index f2255dc0f..e62e5f602 100644 --- a/src/vol/salvsync-client.c +++ b/src/vol/salvsync-client.c @@ -47,10 +47,9 @@ #include "vnode.h" #include "volume.h" #include "partition.h" +#include "common.h" #include -/*@printflike@*/ extern void Log(const char *format, ...); - #ifdef AFS_DEMAND_ATTACH_FS /* * SALVSYNC is a feature specific to the demand attach fileserver diff --git a/src/vol/salvsync-server.c b/src/vol/salvsync-server.c index f3cdc23f2..1a9ab88a3 100644 --- a/src/vol/salvsync-server.c +++ b/src/vol/salvsync-server.c @@ -57,6 +57,7 @@ #include "vnode.h" #include "volume.h" #include "partition.h" +#include "common.h" #include #include @@ -73,8 +74,6 @@ #define WCOREDUMP(x) ((x) & 0200) #endif -/*@printflike@*/ extern void Log(const char *format, ...); - #define MAXHANDLERS 4 /* Up to 4 clients; must be at least 2, so that * move = dump+restore can run on single server */ diff --git a/src/vol/vnode.c b/src/vol/vnode.c index 3b1137747..3ae24e751 100644 --- a/src/vol/vnode.c +++ b/src/vol/vnode.c @@ -45,6 +45,7 @@ #include "vnode_inline.h" #include "partition.h" #include "salvsync.h" +#include "common.h" #if defined(AFS_SGI_ENV) #include "sys/types.h" #include "fcntl.h" @@ -68,11 +69,6 @@ # include #endif -/*@printflike@*/ extern void Log(const char *format, ...); - -/*@printflike@*/ extern void Abort(const char *format, ...) AFS_NORETURN; - - struct VnodeClassInfo VnodeClassInfo[nVNODECLASSES]; void VNLog(afs_int32 aop, afs_int32 anparms, ... ); @@ -1032,8 +1028,9 @@ VnStore(Error * ec, Volume * vp, Vnode * vnp, goto error_encountered; } if (FDH_SEEK(fdP, offset, SEEK_SET) < 0) { - Log("VnStore: can't seek on index file! fdp=0x%x offset=%d, errno=%d\n", - fdP, offset, errno); + Log("VnStore: can't seek on index file! fdp=%"AFS_PTR_FMT + " offset=%d, errno=%d\n", + fdP, (int) offset, errno); goto error_encountered; } @@ -1356,7 +1353,7 @@ VPutVnode_r(Error * ec, register Vnode * vnp) changed_oldTime) << 1) | vnp-> delete, 0, 0); if (thisProcess != vnp->writer) - Abort("VPutVnode: Vnode at 0x%x locked by another process!\n", + Abort("VPutVnode: Vnode at %"AFS_PTR_FMT" locked by another process!\n", vnp); @@ -1412,7 +1409,8 @@ VPutVnode_r(Error * ec, register Vnode * vnp) } else { /* Not write locked */ if (vnp->changed_newTime || vnp->changed_oldTime || vnp->delete) Abort - ("VPutVnode: Change or delete flag for vnode 0x%x is set but vnode is not write locked!\n", + ("VPutVnode: Change or delete flag for vnode " + "%"AFS_PTR_FMT" is set but vnode is not write locked!\n", vnp); #ifdef AFS_DEMAND_ATTACH_FS VnEndRead_r(vnp); @@ -1499,8 +1497,8 @@ VVnodeWriteToRead_r(Error * ec, register Vnode * vnp) LWP_CurrentProcess(&thisProcess); #endif /* AFS_PTHREAD_ENV */ if (thisProcess != vnp->writer) - Abort("VPutVnode: Vnode at 0x%x locked by another process!\n", - (intptr_t)vnp); + Abort("VPutVnode: Vnode at %"AFS_PTR_FMT + " locked by another process!\n", vnp); if (vnp->delete) { return 0; diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 1488bee11..408bc5ead 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -189,6 +189,7 @@ Vnodes with 0 inode pointers in RW volumes are now deleted. #include "salvage.h" #include "volinodes.h" /* header magic number, etc. stuff */ #include "vol-salvage.h" +#include "common.h" #include "vol_internal.h" #include #include @@ -305,8 +306,6 @@ char *tmpdir = NULL; /* Forward declarations */ -/*@printflike@*/ void Log(const char *format, ...); -/*@printflike@*/ void Abort(const char *format, ...) AFS_NORETURN; static int IsVnodeOrphaned(VnodeId vnode); static int AskVolumeSummary(VolumeId singleVolumeNumber); @@ -1255,7 +1254,7 @@ GetInodeSummary(FILE *inodeFile, VolumeId singleVolumeNumber) assert(ret == st_status); } nVolumesInInodeFile =(unsigned long)(status.st_size) / sizeof(struct InodeSummary); - Log("%d nVolumesInInodeFile %d \n",nVolumesInInodeFile,(unsigned long)(status.st_size)); + Log("%d nVolumesInInodeFile %lu \n",nVolumesInInodeFile,(unsigned long)(status.st_size)); fclose(summaryFile); return 0; } diff --git a/src/vol/volume.c b/src/vol/volume.c index 8df6bd2f8..93490e843 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -123,6 +123,8 @@ #include "volume.h" #include "partition.h" #include "volume_inline.h" +#include "common.h" + #ifdef AFS_PTHREAD_ENV #include #else /* AFS_PTHREAD_ENV */ @@ -174,8 +176,6 @@ static volatile sig_atomic_t vol_disallow_salvsync = 0; extern void *calloc(), *realloc(); #endif -/*@printflike@*/ extern void Log(const char *format, ...); - /* Forward declarations */ static Volume *attach2(Error * ec, VolId volumeId, char *path, struct DiskPartition64 *partp, Volume * vp, diff --git a/src/vol/vutil.c b/src/vol/vutil.c index 404273afe..7c58dad3f 100644 --- a/src/vol/vutil.c +++ b/src/vol/vutil.c @@ -58,6 +58,7 @@ #include "volinodes.h" #include "vol_prototypes.h" +#include "common.h" #ifdef AFS_AIX_ENV #include @@ -74,8 +75,6 @@ #define afs_open open #endif /* !O_LARGEFILE */ -/*@printflike@*/ extern void Log(const char *format, ...); - #define nFILES (sizeof (stuff)/sizeof(struct stuff)) /* Note: the volume creation functions herein leave the destroyMe flag in the -- 2.39.5