From 644c4935f89ae1c5de6837ec2f8e2322c77612b3 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Mon, 10 Mar 2003 02:08:33 +0000 Subject: [PATCH] vol-prototyping-20030309 prototype much of the vol package --- src/vol/vol-salvage.c | 79 ++++++++++++++---------------- src/vol/volume.c | 130 ++++++++++++++++++-------------------------------- src/vol/volume.h | 18 +++---- 3 files changed, 91 insertions(+), 136 deletions(-) diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index e659ec1..c3b9d79 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -450,8 +450,7 @@ int UseTheForceLuke(char *path); static int IsVnodeOrphaned(VnodeId vnode); /* Uniquifier stored in the Inode */ -static Unique IUnique(u) - Unique u; +static Unique IUnique(Unique u) { #ifdef AFS_3DISPARES return(u & 0x3fffff); @@ -464,8 +463,8 @@ static Unique IUnique(u) #endif } -static int BadError(aerror) -register int aerror; { +static int BadError(register int aerror) +{ if (aerror == EPERM || aerror == ENXIO || aerror == ENOENT) return 1; return 0; /* otherwise may be transient, e.g. EMFILE */ @@ -473,8 +472,7 @@ register int aerror; { char *tmpdir = 0; -static handleit(as) - struct cmd_syndesc *as; +static int handleit(struct cmd_syndesc *as) { register struct cmd_item *ti; char pname[100], *temp; @@ -666,8 +664,7 @@ int n_save_args = 0; pthread_t main_thread; #endif -main(argc,argv) -char **argv; +int main(int argc, char **argv) { struct cmd_syndesc *ts; int err = 0; @@ -834,12 +831,12 @@ int IsPartitionMounted(char *part) #endif /* Check if the given inode is the root of the filesystem. */ #ifndef AFS_SGI_XFS_IOPS_ENV -int IsRootInode(status) -struct stat *status; +int IsRootInode(struct stat *status) { - /* The root inode is not a fixed value in XFS partitions. So we need to see if - * the partition is in the list of mounted partitions. This only affects the - * SalvageFileSys path, so we check there. + /* + * The root inode is not a fixed value in XFS partitions. So we need to + * see if the partition is in the list of mounted partitions. This only + * affects the SalvageFileSys path, so we check there. */ return (status->st_ino == ROOTINODE); } @@ -850,9 +847,7 @@ struct stat *status; /* We don't want to salvage big files filesystems, since we can't put volumes on * them. */ -int CheckIfBigFilesFS(mountPoint, devName) - char *mountPoint; - char *devName; +int CheckIfBigFilesFS(char *mountPoint, char *devName) { struct superblock fs; char name[128]; @@ -1114,8 +1109,7 @@ void SalvageFileSys(struct DiskPartition *partP, VolumeId singleVolumeNumber) Wait("SalvageFileSys"); } -char *get_DevName(pbuffer, wpath) -char *wpath, *pbuffer; +char *get_DevName(char *pbuffer, char *wpath) { char pbuf[128], *ptr; strcpy(pbuf, pbuffer); @@ -1305,8 +1299,7 @@ void DeleteExtraVolumeHeaderFile(register struct VolumeSummary *vsp) vsp->fileName = 0; } -CompareInodes(_p1,_p2) - const void *_p1,*_p2; +CompareInodes(const void *_p1, const void *_p2) { register const struct ViceInodeInfo *p1 = _p1; register const struct ViceInodeInfo *p2 = _p2; @@ -1430,9 +1423,7 @@ void CountVolumeInodes(register struct ViceInodeInfo *ip, int maxInodes, summary->maxUniquifier = maxunique; } -int OnlyOneVolume(inodeinfo, singleVolumeNumber) - struct ViceInodeInfo *inodeinfo; - VolumeId singleVolumeNumber; +int OnlyOneVolume(struct ViceInodeInfo *inodeinfo, VolumeId singleVolumeNumber) { if (inodeinfo->u.vnode.vnodeNumber == INODESPECIAL) return (inodeinfo->u.special.parentId == singleVolumeNumber); @@ -1602,8 +1593,7 @@ int GetInodeSummary(char *path, VolumeId singleVolumeNumber) /* Comparison routine for volume sort. This is setup so that a read-write volume comes immediately before any read-only clones of that volume */ -CompareVolumes(_p1,_p2) - const void *_p1,*_p2; +int CompareVolumes(const void *_p1, const void *_p2) { register const struct VolumeSummary *p1 = _p1; register const struct VolumeSummary *p2 = _p2; @@ -2643,8 +2633,7 @@ zooks: return err; } -struct VnodeEssence *CheckVnodeNumber(vnodeNumber) - VnodeId vnodeNumber; +struct VnodeEssence *CheckVnodeNumber(VnodeId vnodeNumber) { VnodeClass class; struct VnodeInfo *vip; @@ -2656,7 +2645,6 @@ struct VnodeEssence *CheckVnodeNumber(vnodeNumber) return (offset >= vip->nVnodes? NULL: &vip->vnodes[offset]); } - void CopyOnWrite(register struct DirSummary *dir) { /* Copy the directory unconditionally if we are going to change it: @@ -2700,9 +2688,11 @@ void CopyOnWrite(register struct DirSummary *dir) dir->copied = 1; } -/* This function should either successfully create a new dir, or give up and leave - * things the way they were. In particular, if it fails to write the new dir properly, - * it should return w/o changing the reference to the old dir. +/* + * This function should either successfully create a new dir, or give up + * and leave things the way they were. In particular, if it fails to write + * the new dir properly, it should return w/o changing the reference to the + * old dir. */ void CopyAndSalvage(register struct DirSummary *dir) { @@ -2931,8 +2921,11 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, else { if (ShowSuid && (vnodeEssence->modeBits & 06000)) Log("FOUND suid/sgid file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name?dir->name:"??", name, - vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author,vnodeNumber, dir->vnodeNumber); - if (ShowMounts && (vnodeEssence->type == vSymlink) && !(vnodeEssence->modeBits & 0111)) { + vnodeEssence->owner, vnodeEssence->group, + vnodeEssence->modeBits, vnodeEssence->author,vnodeNumber, + dir->vnodeNumber); + if (ShowMounts && (vnodeEssence->type == vSymlink) && + !(vnodeEssence->modeBits & 0111)) { int code, size; char buf[1024]; IHandle_t *ihP; @@ -2956,8 +2949,11 @@ void JudgeEntry(struct DirSummary *dir, char *name, VnodeId vnodeNumber, } if (ShowRootFiles && vnodeEssence->owner==0 && vnodeNumber != 1) Log("FOUND root file: %s/%s (%u.%u %05o) author %u (vnode %u dir %u)\n", dir->name?dir->name:"??", name, - vnodeEssence->owner, vnodeEssence->group, vnodeEssence->modeBits, vnodeEssence->author, vnodeNumber, dir->vnodeNumber); - if (vnodeIdToClass(vnodeNumber) == vLarge && vnodeEssence->name == NULL) { + vnodeEssence->owner, vnodeEssence->group, + vnodeEssence->modeBits, vnodeEssence->author, vnodeNumber, + dir->vnodeNumber); + if (vnodeIdToClass(vnodeNumber) == vLarge && + vnodeEssence->name == NULL) { char *n; if (n = (char*)malloc(strlen(name)+1)) strcpy(n, name); @@ -3084,10 +3080,7 @@ void DistilVnodeEssence(VolumeId rwVId, VnodeClass class, Inode ino, FDH_CLOSE(fdP); } -static char *GetDirName(vnode, vp, path) - VnodeId vnode; - struct VnodeEssence *vp; - char *path; +static char *GetDirName(VnodeId vnode, struct VnodeEssence *vp, char *path) { struct VnodeEssence *parentvp; @@ -3106,8 +3099,7 @@ static char *GetDirName(vnode, vp, path) /* To determine if a vnode is orhpaned or not, the vnode and all its parent * vnodes must be "claimed". The vep->claimed flag is set in JudgeEntry(). */ -static int IsVnodeOrphaned(vnode) - VnodeId vnode; +static int IsVnodeOrphaned(VnodeId vnode) { struct VnodeEssence *vep; @@ -3496,8 +3488,7 @@ void ClearROInUseBit(struct VolumeSummary *summary) * deleteMe - Always do so, only a partial volume. */ void MaybeZapVolume(register struct InodeSummary *isp, char *message, - int deleteMe, - int check) + int deleteMe, int check) { if (readOnly(isp) || deleteMe) { if (isp->volSummary && isp->volSummary->fileName) { @@ -3766,7 +3757,7 @@ char *a, *b, *c, *d, *e, *f, *g, *h, *i, *j, *k; Exit(1); } -char * ToString(char *s) +char *ToString(char *s) { register char *p; p = (char *) malloc(strlen(s)+1); diff --git a/src/vol/volume.c b/src/vol/volume.c index 709ced5..cd1602b 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -512,11 +512,7 @@ void WriteVolumeHeader_r(ec, vp) normally goes online at this time. An offline volume must be reattached to make it go online */ Volume * -VAttachVolumeByName(ec, partition, name, mode) - Error *ec; - char *partition; - char *name; - int mode; +VAttachVolumeByName(Error *ec, char *partition, char *name, int mode) { Volume *retVal; VATTACH_LOCK @@ -528,11 +524,7 @@ VAttachVolumeByName(ec, partition, name, mode) } Volume * -VAttachVolumeByName_r(ec, partition, name, mode) - Error *ec; - char *partition; - char *name; - int mode; +VAttachVolumeByName_r(Error *ec, char *partition, char *name, int mode) { register Volume *vp; int fd,n; @@ -685,12 +677,8 @@ done: return vp; } -private Volume *attach2(ec, path, header, partp, isbusy) - Error *ec; - char *path; - register struct VolumeHeader *header; - struct DiskPartition *partp; - int isbusy; +private Volume *attach2(Error *ec, char *path, register struct VolumeHeader + *header, struct DiskPartition *partp, int isbusy) { register Volume *vp; @@ -729,7 +717,7 @@ private Volume *attach2(ec, path, header, partp, isbusy) if (!*ec) { struct IndexFileHeader iHead; -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS /* * We just read in the diskstuff part of the header. If the detailed * volume stats area has not yet been initialized, we should bzero the @@ -739,7 +727,7 @@ private Volume *attach2(ec, path, header, partp, isbusy) memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES); V_stat_initialized(vp) = 1; } -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ VOL_UNLOCK (void) ReadHeader(ec, vp->vnodeIndex[vSmall].handle, (char *)&iHead, sizeof(iHead), @@ -845,10 +833,7 @@ private Volume *attach2(ec, path, header, partp, isbusy) */ Volume * -VAttachVolume(ec,volumeId, mode) - Error *ec; - VolumeId volumeId; - int mode; +VAttachVolume(Error *ec, VolumeId volumeId, int mode) { Volume *retVal; VATTACH_LOCK @@ -860,10 +845,7 @@ VAttachVolume(ec,volumeId, mode) } Volume * -VAttachVolume_r(ec,volumeId, mode) - Error *ec; - VolumeId volumeId; - int mode; +VAttachVolume_r(Error *ec, VolumeId volumeId, int mode) { char *part, *name; GetVolumePath(ec,volumeId, &part, &name); @@ -975,9 +957,7 @@ void VPutVolume(register Volume *vp) /* Get a pointer to an attached volume. The pointer is returned regardless of whether or not the volume is in service or on/off line. An error code, however, is returned with an indication of the volume's status */ -Volume *VGetVolume(ec,volumeId) - Error *ec; - VolId volumeId; +Volume *VGetVolume(Error *ec, VolId volumeId) { Volume *retVal; VOL_LOCK @@ -986,9 +966,7 @@ Volume *VGetVolume(ec,volumeId) return retVal; } -Volume *VGetVolume_r(ec,volumeId) - Error *ec; - VolId volumeId; +Volume *VGetVolume_r(Error *ec, VolId volumeId) { Volume *vp; unsigned short V0=0, V1=0, V2=0, V3=0, V4=0, V5=0, V6=0, V7=0, V8=0, V9=0; @@ -1218,16 +1196,21 @@ void VDetachVolume_r(Error *ec, Volume *vp) /* Will be detached sometime in the future--this is OK since volume is offline */ if (programType == volumeUtility && notifyServer) { - /* Note: The server is not notified in the case of a bogus volume explicitly to - make it possible to create a volume, do a partial restore, then abort the - operation without ever putting the volume online. This is essential in the - case of a volume move operation between two partitions on the same server. In - that case, there would be two instances of the same volume, one of them bogus, - which the file server would attempt to put on line */ + /* + * Note: The server is not notified in the case of a bogus volume + * explicitly to make it possible to create a volume, do a partial + * restore, then abort the operation without ever putting the volume + * online. This is essential in the case of a volume move operation + * between two partitions on the same server. In that case, there + * would be two instances of the same volume, one of them bogus, + * which the file server would attempt to put on line + */ if (useDone) - FSYNC_askfs(volume, tpartp->name, FSYNC_DONE, 0); /* don't put online */ + /* don't put online */ + FSYNC_askfs(volume, tpartp->name, FSYNC_DONE, 0); else { - FSYNC_askfs(volume, tpartp->name, FSYNC_ON, 0); /* fs can use it again */ + /* fs can use it again */ + FSYNC_askfs(volume, tpartp->name, FSYNC_ON, 0); /* Dettaching it so break all callbacks on it*/ if (V_BreakVolumeCallbacks) { Log("volume %u detached; breaking all call backs\n", volume); @@ -1245,10 +1228,8 @@ void VDetachVolume(Error *ec, Volume *vp) } -int VAllocBitmapEntry_r(ec,vp,index) - Error *ec; - Volume *vp; - register struct vnodeIndex *index; +int VAllocBitmapEntry_r(Error *ec, Volume *vp, register struct vnodeIndex + *index) { register byte *bp,*ep; *ec = 0; @@ -1321,10 +1302,7 @@ int VAllocBitmapEntry_r(ec,vp,index) return index->bitmapOffset*8; } -int VAllocBitmapEntry(ec,vp,index) - Error *ec; - Volume *vp; - register struct vnodeIndex *index; +int VAllocBitmapEntry(Error *ec, Volume *vp, register struct vnodeIndex *index) { int retVal; VOL_LOCK @@ -1402,8 +1380,7 @@ void VSyncVolume(Error *ec, Volume *vp) VOL_UNLOCK } -static void FreeVolume(vp) - Volume *vp; +static void FreeVolume(Volume *vp) { int i; if (!vp) @@ -1547,27 +1524,25 @@ static void GetVolumePath(Error *ec, VolId volumeId, char **partitionp, } } -VolumeNumber(name) - char *name; +int VolumeNumber(char *name) { if (*name == '/') name++; return atoi(name+1); } -char *VolumeExternalName(volumeId) - VolumeId volumeId; +char *VolumeExternalName(VolumeId volumeId) { static char name[15]; sprintf(name,VFORMAT,volumeId); return name; } -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS #define OneDay (86400) /* 24 hours' worth of seconds */ #else #define OneDay (24*60*60) /* 24 hours */ -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ #define Midnight(date) ((date-TimeZoneCorrection)/OneDay*OneDay+TimeZoneCorrection) @@ -1593,11 +1568,8 @@ char *VolumeExternalName(volumeId) * As described. *------------------------------------------------------------------------*/ -VAdjustVolumeStatistics_r(vp) - register Volume *vp; - -{ /*VAdjustVolumeStatistics*/ - +int VAdjustVolumeStatistics_r(register Volume *vp) +{ unsigned int now = FT_ApproxTime(); if (now - V_dayUseDate(vp) > OneDay) { @@ -1613,30 +1585,26 @@ VAdjustVolumeStatistics_r(vp) V_dayUse(vp) = 0; V_dayUseDate(vp) = Midnight(now); -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS /* * All we need to do is bzero the entire VOL_STATS_BYTES of * the detailed volume statistics area. */ memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES); -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ } /*It's been more than a day of collection*/ -#if TRANSARC_VOL_STATS /* * Always return happily. */ return(0); -#endif /* TRANSARC_VOL_STATS */ - } /*VAdjustVolumeStatistics*/ -VAdjustVolumeStatistics(vp) - register Volume *vp; +int VAdjustVolumeStatistics(register Volume *vp) { int retVal; VOL_LOCK - VAdjustVolumeStatistics_r(vp); + retVal = VAdjustVolumeStatistics_r(vp); VOL_UNLOCK return retVal; } @@ -1754,8 +1722,7 @@ static void VScanUpdateList() { static struct volHeader *volumeLRU; /* Allocate a bunch of headers; string them together */ -static void InitLRU(howMany) -int howMany; +static void InitLRU(int howMany) { register struct volHeader *hp; if (programType != fileServer) @@ -1767,8 +1734,7 @@ int howMany; /* Get a volume header from the LRU list; update the old one if necessary */ /* Returns 1 if there was already a header, which is removed from the LRU list */ -static int GetVolumeHeader(vp) -register Volume *vp; +static int GetVolumeHeader(register Volume *vp) { Error error; register struct volHeader *hd; @@ -1793,10 +1759,12 @@ register Volume *vp; } else { if (volumeLRU) - hd = volumeLRU->prev; /* not currently in use and least recently used */ + /* not currently in use and least recently used */ + hd = volumeLRU->prev; else { hd = (struct volHeader *) calloc(1, sizeof(*vp->header)); - hd->prev = hd->next = hd; /* make it look like single elt LRU */ + /* make it look like single elt LRU */ + hd->prev = hd->next = hd; if (!everLogged) { Log("****Allocated more volume headers, probably leak****\n"); everLogged=1; @@ -1825,8 +1793,7 @@ register Volume *vp; } /* Put it at the top of the LRU chain */ -static void ReleaseVolumeHeader(hd) - register struct volHeader *hd; +static void ReleaseVolumeHeader(register struct volHeader *hd) { if (programType != fileServer) return; @@ -1842,8 +1809,7 @@ static void ReleaseVolumeHeader(hd) volumeLRU = hd; } -static void FreeVolumeHeader(vp) -register Volume *vp; +static void FreeVolumeHeader(register Volume *vp) { register struct volHeader *hd = vp->header; if (!hd) @@ -1863,8 +1829,7 @@ register Volume *vp; /* Routines to add volume to hash chain, delete it */ /***************************************************/ -static void AddVolumeToHashTable(vp, hashid) -register Volume *vp; +static void AddVolumeToHashTable(register Volume *vp, int hashid) { int hash = VOLUME_HASH(hashid); vp->hashid = hashid; @@ -1873,8 +1838,7 @@ register Volume *vp; vp->vnodeHashOffset = VolumeHashOffset_r(); } -static void DeleteVolumeFromHashTable(vp) -register Volume *vp; +static void DeleteVolumeFromHashTable(register Volume *vp) { int hash = VOLUME_HASH(vp->hashid); if (VolumeHashTable[hash] == vp) diff --git a/src/vol/volume.h b/src/vol/volume.h index 9b6adbd..cecba13 100644 --- a/src/vol/volume.h +++ b/src/vol/volume.h @@ -82,9 +82,9 @@ struct versionStamp { /* Version stamp for critical volume files */ /* * Define whether we are keeping detailed statistics on volume dealings. */ -#define TRANSARC_VOL_STATS 1 +#define OPENAFS_VOL_STATS 1 -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS /* * Define various indices and counts used in keeping volume-level statistics. */ @@ -113,7 +113,7 @@ struct versionStamp { /* Version stamp for critical volume files */ #define VOL_STATS_TIME_IDX_3 3 /*1 hr to 24 hrs*/ #define VOL_STATS_TIME_IDX_4 4 /*1 day to 7 days*/ #define VOL_STATS_TIME_IDX_5 5 /*Greater than 1 week*/ -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ /* Volume header. This is the contents of the named file representing * the volume. Read-only by the file server! @@ -250,17 +250,17 @@ typedef struct VolumeDiskData { set when the copy is created */ Date copyDate; -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS bit32 stat_initialized; /*Are the stat fields below set up?*/ bit32 reserved4[7]; #else bit32 reserved4[8]; -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ /* messages */ #define VMSGSIZE 128 char offlineMessage[VMSGSIZE]; /* Why the volume is offline */ -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS #define VOL_STATS_BYTES 128 /* * Keep per-volume aggregate statistics on type and distance of access, @@ -274,7 +274,7 @@ typedef struct VolumeDiskData { bit32 stat_dirDiffAuthor[VOL_STATS_NUM_TIME_FIELDS]; #else char motd[VMSGSIZE]; /* Volume "message of the day" */ -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ } VolumeDiskData; @@ -378,7 +378,7 @@ struct volHeader { #define V_offlineMessage(vp) ((vp)->header->diskstuff.offlineMessage) #define V_disk(vp) ((vp)->header->diskstuff) #define V_motd(vp) ((vp)->header->diskstuff.motd) -#if TRANSARC_VOL_STATS +#if OPENAFS_VOL_STATS #define V_stat_initialized(vp) ((vp)->header->diskstuff.stat_initialized) #define V_stat_area(vp) (((vp)->header->diskstuff.stat_reads)) #define V_stat_reads(vp, idx) (((vp)->header->diskstuff.stat_reads)[idx]) @@ -387,7 +387,7 @@ struct volHeader { #define V_stat_fileDiffAuthor(vp, idx) (((vp)->header->diskstuff.stat_fileDiffAuthor)[idx]) #define V_stat_dirSameAuthor(vp, idx) (((vp)->header->diskstuff.stat_dirSameAuthor)[idx]) #define V_stat_dirDiffAuthor(vp, idx) (((vp)->header->diskstuff.stat_dirDiffAuthor)[idx]) -#endif /* TRANSARC_VOL_STATS */ +#endif /* OPENAFS_VOL_STATS */ /* File offset computations. The offset values in the volume header are computed with these macros -- when the file is written only!! */ -- 1.9.4