From 8f2fa9d6393a958080387e8d84f6b8cd032b5ff8 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 24 Sep 2014 17:50:02 -0500 Subject: [PATCH] afs: Consolidate fheader initialization We were initializing an afs_fheader structure in two different places, with the same values. Consolidate these into a single function, so updating the structure is easier. Also zero the whole structure, just to make sure everything is initialized, even if the structure changes. This commit should have no behavior impact; it is just code reorganization. Change-Id: If90757166d8490eaa053aa086c7b95349a62332e Reviewed-on: http://gerrit.openafs.org/11510 Reviewed-by: Benjamin Kaduk Reviewed-by: Perry Ruiter Tested-by: BuildBot --- src/afs/afs_dcache.c | 6 +----- src/afs/afs_init.c | 17 ++++++++++++----- src/afs/afs_prototypes.h | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index 235dce6e8..4a9edbdd8 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -2681,11 +2681,7 @@ afs_WriteThroughDSlots(void) */ struct afs_fheader theader; - theader.magic = AFS_FHMAGIC; - theader.firstCSize = AFS_FIRSTCSIZE; - theader.otherCSize = AFS_OTHERCSIZE; - theader.version = AFS_CI_VERSION; - theader.dataSize = sizeof(struct fcache); + afs_InitFHeader(&theader); afs_osi_Write(afs_cacheInodep, 0, &theader, sizeof(theader)); } ReleaseWriteLock(&afs_xdcache); diff --git a/src/afs/afs_init.c b/src/afs/afs_init.c index d588c75fb..acc7bef66 100644 --- a/src/afs/afs_init.c +++ b/src/afs/afs_init.c @@ -335,6 +335,17 @@ afs_InitVolumeInfo(char *afile) return 0; } +void +afs_InitFHeader(struct afs_fheader *aheader) +{ + memset(aheader, 0, sizeof(*aheader)); + aheader->magic = AFS_FHMAGIC; + aheader->version = AFS_CI_VERSION; + aheader->dataSize = sizeof(struct fcache); + aheader->firstCSize = AFS_FIRSTCSIZE; + aheader->otherCSize = AFS_OTHERCSIZE; +} + /* * afs_InitCacheInfo * @@ -490,11 +501,7 @@ afs_InitCacheInfo(char *afile) } if (!goodFile) { /* write out a good file label */ - theader.magic = AFS_FHMAGIC; - theader.firstCSize = AFS_FIRSTCSIZE; - theader.otherCSize = AFS_OTHERCSIZE; - theader.dataSize = sizeof(struct fcache); - theader.version = AFS_CI_VERSION; + afs_InitFHeader(&theader); afs_osi_Write(tfile, 0, &theader, sizeof(theader)); /* * Truncate the rest of the file, since it may be arbitrarily diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index 4495a914f..178223b7c 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -442,6 +442,7 @@ extern int afs_CacheInit(afs_int32 astatSize, afs_int32 afiles, afs_int32 aflags, afs_int32 ninodes, afs_int32 nusers, afs_int32 dynamic_vcaches); extern void afs_ComputeCacheParms(void); +extern void afs_InitFHeader(struct afs_fheader *aheader); extern int afs_InitCacheInfo(char *afile); extern int afs_InitVolumeInfo(char *afile); extern int afs_InitCellInfo(char *afile); -- 2.39.5