2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* 1/1/89: NB: this stuff is all going to be replaced. Don't take it too seriously */
15 Institution: The Information Technology Center, Carnegie-Mellon University
19 #include <afsconfig.h>
20 #include <afs/param.h>
25 #include <afs/afsint.h>
28 #include <sys/param.h>
29 #if !defined(AFS_SGI_ENV)
32 #else /* AFS_OSF_ENV */
33 #ifdef AFS_VFSINCL_ENV
36 #include <sys/fs/ufs_fs.h>
38 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
39 #include <ufs/ufs/dinode.h>
40 #include <ufs/ffs/fs.h>
45 #else /* AFS_VFSINCL_ENV */
46 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
49 #endif /* AFS_VFSINCL_ENV */
50 #endif /* AFS_OSF_ENV */
51 #endif /* AFS_SGI_ENV */
52 #endif /* AFS_NT40_ENV */
70 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
72 #include <sys/mnttab.h>
73 #include <sys/mntent.h>
79 #if defined(AFS_SGI_ENV)
82 #ifdef AFS_SGI_EFS_IOPS_ENV
83 #define ROOTINO EFS_ROOTINO
84 #include <sys/fs/efs.h>
85 #include "sgiefs/efs.h" /* until 5.1 release */
90 #ifndef AFS_LINUX20_ENV
91 #include <fstab.h> /* Need to find in libc 5, present in libc 6 */
94 #endif /* AFS_SGI_ENV */
96 #endif /* AFS_HPUX_ENV */
100 #include <netinet/in.h>
101 #include <sys/wait.h>
104 #include <sys/time.h>
105 #endif /* ITIMER_REAL */
106 #endif /* AFS_NT40_ENV */
107 #if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV) || defined(AFS_LINUX20_ENV)
114 #include <afs/errors.h>
117 #include <afs/afssyscalls.h>
120 #include <afs/afsutil.h>
125 #include "partition.h"
126 #ifdef AFS_PTHREAD_ENV
128 #else /* AFS_PTHREAD_ENV */
129 #include "afs/assert.h"
130 #endif /* AFS_PTHREAD_ENV */
137 #ifdef AFS_PTHREAD_ENV
138 pthread_mutex_t vol_glock_mutex;
139 pthread_mutex_t vol_attach_mutex;
140 pthread_cond_t vol_put_volume_cond;
141 pthread_cond_t vol_sleep_cond;
142 #endif /* AFS_PTHREAD_ENV */
145 extern void *calloc(), *realloc();
148 /* Forward declarations */
149 static Volume *attach2();
150 static void FreeVolume();
151 static void VScanUpdateList();
152 static void InitLRU();
153 static int GetVolumeHeader();
154 static void ReleaseVolumeHeader();
155 static void FreeVolumeHeader();
156 static void AddVolumeToHashTable();
157 static void DeleteVolumeFromHashTable();
158 static int VHold(Volume *vp);
159 static int VHold_r(Volume *vp);
160 static void GetBitmap(Error *ec, Volume *vp, VnodeClass class);
161 static void GetVolumePath(Error *ec, VolId volumeId, char **partitionp,
163 static void VReleaseVolumeHandles_r(Volume *vp);
164 static void VCloseVolumeHandles_r(Volume *vp);
166 int LogLevel; /* Vice loglevel--not defined as extern so that it will be
167 defined when not linked with vice, XXXX */
168 ProgramType programType; /* The type of program using the package */
171 #define VOLUME_BITMAP_GROWSIZE 16 /* bytes, => 128vnodes */
172 /* Must be a multiple of 4 (1 word) !!*/
173 #define VOLUME_HASH_TABLE_SIZE 128 /* Must be a power of 2!! */
174 #define VOLUME_HASH(volumeId) (volumeId&(VOLUME_HASH_TABLE_SIZE-1))
175 private Volume *VolumeHashTable[VOLUME_HASH_TABLE_SIZE];
178 /* This macro is used where an ffs() call does not exist. Was in util/ffs.c */
181 afs_int32 ffs_tmp = x; \
182 if (ffs_tmp == 0) return(-1); \
184 for (ffs_i = 1;; ffs_i++) { \
185 if (ffs_tmp & 1) return(ffs_i); \
186 else ffs_tmp >>= 1; \
189 #endif /* !AFS_HAVE_FFS */
191 struct Lock vol_listLock; /* Lock obtained when listing volumes: prevents a volume from being missed if the volume is attached during a list volumes */
193 extern struct Lock FSYNC_handler_lock;
195 Volume *VAttachVolumeByName();
196 Volume *VAttachVolumeByName_r();
198 static int TimeZoneCorrection; /* Number of seconds west of GMT */
200 /* Common message used when the volume goes off line */
201 char *VSalvageMessage =
202 "Files in this volume are currently unavailable; call operations";
204 int VInit; /* 0 - uninitialized,
205 1 - initialized but not all volumes have been attached,
206 2 - initialized and all volumes have been attached,
207 3 - initialized, all volumes have been attached, and
208 VConnectFS() has completed. */
211 int VolumeCacheCheck; /* Incremented everytime a volume goes on line--
212 * used to stamp volume headers and in-core
213 * vnodes. When the volume goes on-line the
214 * vnode will be invalidated */
216 int VolumeCacheSize = 200, VolumeGets=0, VolumeReplacements=0, Vlooks = 0;
219 int VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes,
220 int connect, int volcache)
222 int errors = 0; /* Number of errors while finding vice partitions. */
228 #ifdef AFS_PTHREAD_ENV
229 assert(pthread_mutex_init(&vol_glock_mutex, NULL) == 0);
230 assert(pthread_mutex_init(&vol_attach_mutex, NULL) == 0);
231 assert(pthread_cond_init(&vol_put_volume_cond, NULL) == 0);
232 assert(pthread_cond_init(&vol_sleep_cond, NULL) == 0);
233 #else /* AFS_PTHREAD_ENV */
235 #endif /* AFS_PTHREAD_ENV */
236 Lock_Init(&vol_listLock);
237 Lock_Init(&FSYNC_handler_lock);
238 srandom(time(0)); /* For VGetVolumeInfo */
239 gettimeofday(&tv, &tz);
240 TimeZoneCorrection = tz.tz_minuteswest*60;
242 /* Ok, we have done enough initialization that fileserver can
243 * start accepting calls, even though the volumes may not be
244 * available just yet.
248 if (programType == fileServer) {
249 /* File server or "stand" */
253 if (volcache > VolumeCacheSize)
254 VolumeCacheSize = volcache;
255 InitLRU(VolumeCacheSize);
257 VInitVnodes(vLarge, nLargeVnodes);
258 VInitVnodes(vSmall, nSmallVnodes);
261 errors = VAttachPartitions();
265 if (programType == fileServer) {
268 struct DiskPartition *diskP;
271 /* Attach all the volumes in this partition */
272 for (diskP = DiskPartitionList; diskP; diskP = diskP->next) {
273 int nAttached = 0, nUnattached = 0;
274 Log("Partition %s: attaching volumes\n", diskP->name);
275 dirp = opendir(VPartitionPath(diskP));
277 while ((dp = readdir(dirp))) {
279 p = strrchr(dp->d_name, '.');
280 if (p != NULL && strcmp(p, VHDREXT) == 0) {
283 vp = VAttachVolumeByName(&error, diskP->name, dp->d_name,
285 (*(vp?&nAttached:&nUnattached))++;
286 if (error == VOFFLINE)
287 Log("Volume %u stays offline (/vice/offline/%s exists)\n",
288 VolumeNumber(dp->d_name), dp->d_name);
290 Log("Partition %s: attached volume %u (%s)\n", diskP->name,
291 VolumeNumber(dp->d_name), dp->d_name);
297 Log("Partition %s: attached %d volumes; %d volumes not attached\n",
298 diskP->name, nAttached, nUnattached);
303 VInit = 2; /* Initialized, and all volumes have been attached */
304 if (programType == volumeUtility && connect) {
306 Log("Unable to connect to file server; aborted\n");
313 /* This must be called by any volume utility which needs to run while the
314 file server is also running. This is separated from VInitVolumePackage so
315 that a utility can fork--and each of the children can independently
316 initialize communication with the file server */
321 retVal = VConnectFS_r();
326 int VConnectFS_r(void)
329 assert(VInit == 2 && programType == volumeUtility);
330 rc = FSYNC_clientInit();
336 void VDisconnectFS_r(void) {
337 assert(programType == volumeUtility);
342 void VDisconnectFS(void) {
348 void VShutdown_r(void)
351 register Volume *vp, *np;
352 register afs_int32 code;
354 Log("VShutdown: shutting down on-line volumes...\n");
355 for (i=0; i<VOLUME_HASH_TABLE_SIZE; i++) {
356 /* try to hold first volume in the hash table */
357 for(vp = VolumeHashTable[i]; vp; vp=vp->hashNext) {
359 if (code == 0) break; /* got it */
360 /* otherwise we go around again, trying another volume */
363 /* first compute np before releasing vp, in case vp disappears
364 * after releasing. Hold it, so it doesn't disapear. If we
365 * can't hold it, try the next one in the chain. Invariant
366 * at the top of this loop is that vp is held (has extra ref count).
368 for(np=vp->hashNext; np; np=np->hashNext) {
370 if (code == 0) break; /* got it */
372 /* next, take the volume offline (drops reference count) */
373 VOffline_r(vp, "File server was shut down");
374 vp = np; /* next guy to try */
377 Log("VShutdown: complete.\n");
388 static void ReadHeader(Error *ec, IHandle_t *h, char *to, int size,
389 int magic, int version)
391 struct versionStamp *vsn;
406 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
408 FDH_REALLYCLOSE(fdP);
411 vsn = (struct versionStamp *) to;
412 if (FDH_READ(fdP, to, size) != size || vsn->magic != magic) {
414 FDH_REALLYCLOSE(fdP);
419 /* Check is conditional, in case caller wants to inspect version himself */
420 if (version && vsn->version != version) {
425 /* VolumeHeaderToDisk
426 * Allows for storing 64 bit inode numbers in on-disk volume header
429 void VolumeHeaderToDisk(VolumeDiskHeader_t *dh, VolumeHeader_t *h)
432 memset((char*)dh, 0, sizeof(VolumeDiskHeader_t));
433 dh->stamp = h->stamp;
435 dh->parent = h->parent;
437 #ifdef AFS_64BIT_IOPS_ENV
438 dh->volumeInfo_lo = (afs_int32) h->volumeInfo & 0xffffffff;
439 dh->volumeInfo_hi = (afs_int32) (h->volumeInfo >> 32) & 0xffffffff;
440 dh->smallVnodeIndex_lo = (afs_int32) h->smallVnodeIndex & 0xffffffff;
441 dh->smallVnodeIndex_hi = (afs_int32) (h->smallVnodeIndex >> 32) & 0xffffffff;
442 dh->largeVnodeIndex_lo = (afs_int32) h->largeVnodeIndex & 0xffffffff;
443 dh->largeVnodeIndex_hi = (afs_int32) (h->largeVnodeIndex >> 32) & 0xffffffff;
444 dh->linkTable_lo = (afs_int32) h->linkTable & 0xffffffff;
445 dh->linkTable_hi = (afs_int32) (h->linkTable >> 32) & 0xffffffff;
447 dh->volumeInfo_lo = h->volumeInfo;
448 dh->smallVnodeIndex_lo = h->smallVnodeIndex;
449 dh->largeVnodeIndex_lo = h->largeVnodeIndex;
450 dh->linkTable_lo = h->linkTable;
454 /* DiskToVolumeHeader
455 * Reads volume header file from disk, convering 64 bit inodes
456 * if required. Makes the assumption that AFS has *always*
457 * zero'd the volume header file so that high parts of inode
458 * numbers are 0 in older (SGI EFS) volume header files.
460 void DiskToVolumeHeader(VolumeHeader_t *h, VolumeDiskHeader_t *dh)
462 memset((char*)h, 0, sizeof(VolumeHeader_t));
463 h->stamp = dh->stamp;
465 h->parent = dh->parent;
467 #ifdef AFS_64BIT_IOPS_ENV
468 h->volumeInfo = dh->volumeInfo_lo | ((Inode)dh->volumeInfo_hi << 32);
470 h->smallVnodeIndex = dh->smallVnodeIndex_lo |
471 ((Inode)dh->smallVnodeIndex_hi << 32);
473 h->largeVnodeIndex = dh->largeVnodeIndex_lo |
474 ((Inode)dh->largeVnodeIndex_hi << 32);
475 h->linkTable = dh->linkTable_lo |
476 ((Inode)dh->linkTable_hi << 32);
478 h->volumeInfo = dh->volumeInfo_lo;
479 h->smallVnodeIndex = dh->smallVnodeIndex_lo;
480 h->largeVnodeIndex = dh->largeVnodeIndex_lo;
481 h->linkTable = dh->linkTable_lo;
486 void WriteVolumeHeader_r(ec, vp)
490 IHandle_t *h = V_diskDataHandle(vp);
500 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
502 FDH_REALLYCLOSE(fdP);
505 if (FDH_WRITE(fdP, (char*)&V_disk(vp), sizeof(V_disk(vp)))
506 != sizeof(V_disk(vp))) {
508 FDH_REALLYCLOSE(fdP);
514 /* Attach an existing volume, given its pathname, and return a
515 pointer to the volume header information. The volume also
516 normally goes online at this time. An offline volume
517 must be reattached to make it go online */
519 VAttachVolumeByName(Error *ec, char *partition, char *name, int mode)
524 retVal = VAttachVolumeByName_r(ec, partition, name, mode);
531 VAttachVolumeByName_r(Error *ec, char *partition, char *name, int mode)
536 struct VolumeDiskHeader diskHeader;
537 struct VolumeHeader iheader;
538 struct DiskPartition *partp;
542 if (programType == volumeUtility) {
544 VLockPartition_r(partition);
546 if (programType == fileServer) {
547 vp = VGetVolume_r(ec, VolumeNumber(name));
551 if (vp->specialStatus == VBUSY)
553 VDetachVolume_r(ec, vp);
555 Log("VAttachVolume: Error detaching volume (%s)\n", name);
560 if (!(partp = VGetPartition_r(partition, 0))) {
562 Log("VAttachVolume: Error getting partition (%s)\n", partition);
567 strcpy(path, VPartitionPath(partp));
571 if ((fd = open(path, O_RDONLY)) == -1 || fstat(fd,&status) == -1) {
577 n = read(fd, &diskHeader, sizeof (diskHeader));
580 if (n != sizeof (diskHeader) || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
581 Log("VAttachVolume: Error reading volume header %s\n", path);
585 if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
586 Log("VAttachVolume: Volume %s, version number is incorrect; volume needs salvaged\n",path);
591 DiskToVolumeHeader(&iheader, &diskHeader);
592 if (programType == volumeUtility && mode != V_SECRETLY) {
593 if (FSYNC_askfs(iheader.id, partition, FSYNC_NEEDVOLUME, mode)
595 Log("VAttachVolume: attach of volume %u apparently denied by file server\n",
597 *ec = VNOVOL; /* XXXX */
602 vp = attach2(ec, path, &iheader, partp, isbusy);
603 if (programType == volumeUtility && vp) {
604 /* duplicate computation in fssync.c about whether the server
605 * takes the volume offline or not. If the volume isn't
606 * offline, we must not return it when we detach the volume,
607 * or the server will abort */
608 if (mode == V_READONLY || (!VolumeWriteable(vp) && (mode==V_CLONE || mode==V_DUMP)))
609 vp->needsPutBack = 0;
611 vp->needsPutBack = 1;
613 /* OK, there's a problem here, but one that I don't know how to
614 * fix right now, and that I don't think should arise often.
615 * Basically, we should only put back this volume to the server if
616 * it was given to us by the server, but since we don't have a vp,
617 * we can't run the VolumeWriteable function to find out as we do
618 * above when computing vp->needsPutBack. So we send it back, but
619 * there's a path in VAttachVolume on the server which may abort
620 * if this volume doesn't have a header. Should be pretty rare
621 * for all of that to happen, but if it does, probably the right
622 * fix is for the server to allow the return of readonly volumes
623 * that it doesn't think are really checked out. */
624 if (programType == volumeUtility && vp == NULL && mode != V_SECRETLY) {
625 FSYNC_askfs(iheader.id, partition, FSYNC_ON, 0);
627 else if (programType == fileServer && vp) {
628 V_needsCallback(vp) = 0;
630 if (VInit >= 2 && V_BreakVolumeCallbacks) {
631 Log("VAttachVolume: Volume %u was changed externally; breaking callbacks\n", V_id(vp));
632 (*V_BreakVolumeCallbacks)(V_id(vp));
635 VUpdateVolume_r(ec,vp);
637 Log("VAttachVolume: Error updating volume\n");
642 if (VolumeWriteable(vp) && V_dontSalvage(vp) == 0) {
643 /* This is a hack: by temporarily settint the incore
644 * dontSalvage flag ON, the volume will be put back on the
645 * Update list (with dontSalvage OFF again). It will then
646 * come back in N minutes with DONT_SALVAGE eventually
647 * set. This is the way that volumes that have never had
648 * it set get it set; or that volumes that have been
649 * offline without DONT SALVAGE having been set also
650 * eventually get it set */
651 V_dontSalvage(vp) = DONT_SALVAGE;
652 VAddToVolumeUpdateList_r(ec,vp);
654 Log("VAttachVolume: Error adding volume to update list\n");
661 Log("VOnline: volume %u (%s) attached and online\n",
662 V_id(vp), V_name(vp));
665 if (programType == volumeUtility) {
666 VUnlockPartition_r(partition);
674 private Volume *attach2(Error *ec, char *path, register struct VolumeHeader
675 *header, struct DiskPartition *partp, int isbusy)
680 vp = (Volume *) calloc(1, sizeof(Volume));
682 vp->specialStatus = (isbusy ? VBUSY : 0);
683 vp->device = partp->device;
684 vp->partition = partp;
685 IH_INIT(vp->vnodeIndex[vLarge].handle, partp->device, header->parent,
686 header->largeVnodeIndex);
687 IH_INIT(vp->vnodeIndex[vSmall].handle, partp->device, header->parent,
688 header->smallVnodeIndex);
689 IH_INIT(vp->diskDataHandle, partp->device, header->parent,
691 IH_INIT(vp->linkHandle, partp->device, header->parent,
693 vp->cacheCheck = ++VolumeCacheCheck;
694 /* just in case this ever rolls over */
696 vp->cacheCheck = ++VolumeCacheCheck;
697 vp->shuttingDown = 0;
698 vp->goingOffline = 0;
703 (void) ReadHeader(ec, V_diskDataHandle(vp),
704 (char *)&V_disk(vp), sizeof(V_disk(vp)),
705 VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
708 Log("VAttachVolume: Error reading diskDataHandle vol header %s; error=%d\n",
712 struct IndexFileHeader iHead;
714 #if OPENAFS_VOL_STATS
716 * We just read in the diskstuff part of the header. If the detailed
717 * volume stats area has not yet been initialized, we should bzero the
718 * area and mark it as initialized.
720 if (! (V_stat_initialized(vp))) {
721 memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES);
722 V_stat_initialized(vp) = 1;
724 #endif /* OPENAFS_VOL_STATS */
726 (void) ReadHeader(ec, vp->vnodeIndex[vSmall].handle,
727 (char *)&iHead, sizeof(iHead),
728 SMALLINDEXMAGIC, SMALLINDEXVERSION);
731 Log("VAttachVolume: Error reading smallVnode vol header %s; error=%d\n",
736 struct IndexFileHeader iHead;
738 (void) ReadHeader(ec, vp->vnodeIndex[vLarge].handle,
739 (char *)&iHead, sizeof(iHead),
740 LARGEINDEXMAGIC, LARGEINDEXVERSION);
743 Log("VAttachVolume: Error reading largeVnode vol header %s; error=%d\n",
749 struct versionStamp stamp;
751 (void) ReadHeader(ec, V_linkHandle(vp),
752 (char *)&stamp, sizeof(stamp),
753 LINKTABLEMAGIC, LINKTABLEVERSION);
756 Log("VAttachVolume: Error reading namei vol header %s; error=%d\n",
762 Log("VAttachVolume: Error attaching volume %s; volume needs salvage; error=%d\n",
767 if (V_needsSalvaged(vp)) {
768 if (vp->specialStatus) vp->specialStatus = 0;
769 Log("VAttachVolume: volume salvage flag is ON for %s; volume needs salvage\n", path);
773 if (programType == fileServer) {
775 if (V_inUse(vp) && VolumeWriteable(vp)) {
776 if (!V_needsSalvaged(vp)) {
777 V_needsSalvaged(vp) = 1;
778 VUpdateVolume_r(ec,vp);
781 Log("VAttachVolume: volume %s needs to be salvaged; not attached.\n", path);
785 #endif /* FAST_RESTART */
786 if (V_destroyMe(vp) == DESTROY_ME) {
788 Log("VAttachVolume: volume %s is junk; it should be destroyed at next salvage\n", path);
794 AddVolumeToHashTable(vp, V_id(vp));
795 vp->nextVnodeUnique = V_uniquifier(vp);
796 vp->vnodeIndex[vSmall].bitmap = vp->vnodeIndex[vLarge].bitmap = NULL;
798 if (programType == fileServer && VolumeWriteable(vp)) {
800 for (i = 0; i<nVNODECLASSES; i++) {
806 Log("VAttachVolume: error getting bitmap for volume (%s)\n", path);
811 #endif /* BITMAP_LATER */
813 if (programType == fileServer) {
814 if (vp->specialStatus) vp->specialStatus = 0;
815 if (V_blessed(vp) && V_inService(vp) && !V_needsSalvaged(vp)) {
817 V_offlineMessage(vp)[0] = '\0';
824 /* Attach an existing volume.
825 The volume also normally goes online at this time.
826 An offline volume must be reattached to make it go online.
830 VAttachVolume(Error *ec, VolumeId volumeId, int mode)
835 retVal = VAttachVolume_r(ec, volumeId, mode);
842 VAttachVolume_r(Error *ec, VolumeId volumeId, int mode)
845 GetVolumePath(ec,volumeId, &part, &name);
849 vp = VGetVolume_r(&error, volumeId);
851 assert(V_inUse(vp) == 0);
852 VDetachVolume_r(ec, vp);
856 return VAttachVolumeByName_r(ec, part, name, mode);
859 /* Increment a reference count to a volume, sans context swaps. Requires
860 * possibly reading the volume header in from the disk, since there's
861 * an invariant in the volume package that nUsers>0 ==> vp->header is valid.
863 * N.B. This call can fail if we can't read in the header!! In this case
864 * we still guarantee we won't context swap, but the ref count won't be
865 * incremented (otherwise we'd violate the invariant).
867 static int VHold_r(register Volume *vp)
871 if (vp->nUsers == 0 && !GetVolumeHeader(vp)) {
872 VolumeReplacements++;
873 ReadHeader(&error, V_diskDataHandle(vp),
874 (char *)&V_disk(vp), sizeof(V_disk(vp)),
875 VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
876 if (error) return error;
882 static int VHold(register Volume *vp)
886 retVal = VHold_r(vp);
891 void VTakeOffline_r(register Volume *vp)
893 assert(vp->nUsers > 0);
894 assert(programType == fileServer);
895 vp->goingOffline = 1;
896 V_needsSalvaged(vp) = 1;
899 void VTakeOffline(register Volume *vp)
906 void VPutVolume_r(register Volume *vp)
908 assert(--vp->nUsers >= 0);
909 if (vp->nUsers == 0) {
910 ReleaseVolumeHeader(vp->header);
911 if (vp->goingOffline) {
913 assert(programType == fileServer);
914 vp->goingOffline = 0;
916 VUpdateVolume_r(&error, vp);
917 VCloseVolumeHandles_r(vp);
919 Log("VOffline: Volume %u (%s) is now offline",
920 V_id(vp), V_name(vp));
921 if (V_offlineMessage(vp)[0])
922 Log(" (%s)", V_offlineMessage(vp));
925 #ifdef AFS_PTHREAD_ENV
926 assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0);
927 #else /* AFS_PTHREAD_ENV */
928 LWP_NoYieldSignal(VPutVolume);
929 #endif /* AFS_PTHREAD_ENV */
931 if (vp->shuttingDown) {
932 VReleaseVolumeHandles_r(vp);
934 if (programType == fileServer)
935 #ifdef AFS_PTHREAD_ENV
936 assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0);
937 #else /* AFS_PTHREAD_ENV */
938 LWP_NoYieldSignal(VPutVolume);
939 #endif /* AFS_PTHREAD_ENV */
944 void VPutVolume(register Volume *vp)
951 /* Get a pointer to an attached volume. The pointer is returned regardless
952 of whether or not the volume is in service or on/off line. An error
953 code, however, is returned with an indication of the volume's status */
954 Volume *VGetVolume(Error *ec, VolId volumeId)
958 retVal = VGetVolume_r(ec,volumeId);
963 Volume *VGetVolume_r(Error *ec, VolId volumeId)
966 unsigned short V0=0, V1=0, V2=0, V3=0, V4=0, V5=0, V6=0, V7=0, V8=0, V9=0;
967 unsigned short V10=0, V11=0, V12=0, V13=0, V14=0, V15=0;
972 for (vp = VolumeHashTable[VOLUME_HASH(volumeId)];
973 vp && vp->hashid != volumeId; vp = vp->hashNext)
980 /* Until we have reached an initialization level of 2
981 we don't know whether this volume exists or not.
982 We can't sleep and retry later because before a volume
983 is attached, the caller tries to get it first. Just
984 return VOFFLINE and the caller can choose whether to
985 retry the command or not.*/
996 if (vp->nUsers == 0 && !GetVolumeHeader(vp)) {
998 VolumeReplacements++;
999 ReadHeader(ec, V_diskDataHandle(vp),
1000 (char *)&V_disk(vp), sizeof(V_disk(vp)), VOLUMEINFOMAGIC,
1004 /* Only log the error if it was a totally unexpected error. Simply
1005 a missing inode is likely to be caused by the volume being deleted */
1006 if (errno != ENXIO || LogLevel)
1007 Log("Volume %u: couldn't reread volume header\n", vp->hashid);
1014 if (vp->shuttingDown) {
1020 if (programType == fileServer) {
1022 if (vp->goingOffline) {
1024 #ifdef AFS_PTHREAD_ENV
1025 pthread_cond_wait(&vol_put_volume_cond, &vol_glock_mutex);
1026 #else /* AFS_PTHREAD_ENV */
1027 LWP_WaitProcess(VPutVolume);
1028 #endif /* AFS_PTHREAD_ENV */
1031 if (vp->specialStatus) {
1033 *ec = vp->specialStatus;
1035 else if (V_inService(vp)==0 || V_blessed(vp)==0) {
1039 else if (V_inUse(vp)==0) {
1050 /* if no error, bump nUsers */
1051 if (vp) vp->nUsers++;
1058 /* For both VForceOffline and VOffline, we close all relevant handles.
1059 * For VOffline, if we re-attach the volume, the files may possible be
1060 * different than before.
1062 static void VReleaseVolumeHandles_r(Volume *vp)
1064 DFlushVolume(V_id(vp));
1065 VReleaseVnodeFiles_r(vp);
1067 /* Too time consuming and unnecessary for the volserver */
1068 if (programType != volumeUtility) {
1069 IH_CONDSYNC(vp->vnodeIndex[vLarge].handle);
1070 IH_CONDSYNC(vp->vnodeIndex[vSmall].handle);
1071 IH_CONDSYNC(vp->diskDataHandle);
1073 IH_CONDSYNC(vp->linkHandle);
1074 #endif /* AFS_NT40_ENV */
1077 IH_RELEASE(vp->vnodeIndex[vLarge].handle);
1078 IH_RELEASE(vp->vnodeIndex[vSmall].handle);
1079 IH_RELEASE(vp->diskDataHandle);
1080 IH_RELEASE(vp->linkHandle);
1083 /* Force the volume offline, set the salvage flag. No further references to
1084 * the volume through the volume package will be honored. */
1085 void VForceOffline_r(Volume *vp)
1090 strcpy(V_offlineMessage(vp), "Forced offline due to internal error: volume needs to be salvaged");
1091 Log("Volume %u forced offline: it needs salvaging!\n", V_id(vp));
1093 vp->goingOffline = 0;
1094 V_needsSalvaged(vp) = 1;
1095 VUpdateVolume_r(&error, vp);
1096 #ifdef AFS_PTHREAD_ENV
1097 assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0);
1098 #else /* AFS_PTHREAD_ENV */
1099 LWP_NoYieldSignal(VPutVolume);
1100 #endif /* AFS_PTHREAD_ENV */
1102 VReleaseVolumeHandles_r(vp);
1106 void VForceOffline(Volume *vp)
1109 VForceOffline_r(vp);
1113 /* The opposite of VAttachVolume. The volume header is written to disk, with
1114 the inUse bit turned off. A copy of the header is maintained in memory,
1115 however (which is why this is VOffline, not VDetach).
1117 void VOffline_r(Volume *vp, char *message)
1120 VolumeId vid = V_id(vp);
1121 assert(programType != volumeUtility);
1126 if (V_offlineMessage(vp)[0] == '\0')
1127 strncpy(V_offlineMessage(vp),message,
1128 sizeof(V_offlineMessage(vp)));
1129 V_offlineMessage(vp)[sizeof(V_offlineMessage(vp))-1] = '\0';
1130 vp->goingOffline = 1;
1132 vp = VGetVolume_r(&error, vid); /* Wait for it to go offline */
1133 if (vp) /* In case it was reattached... */
1137 void VOffline(Volume *vp, char *message)
1140 VOffline_r(vp, message);
1144 /* For VDetachVolume, we close all cached file descriptors, but keep
1145 * the Inode handles in case we need to read from a busy volume.
1147 static void VCloseVolumeHandles_r(Volume *vp)
1149 DFlushVolume(V_id(vp));
1150 VCloseVnodeFiles_r(vp);
1152 /* Too time consuming and unnecessary for the volserver */
1153 if (programType != volumeUtility) {
1154 IH_CONDSYNC(vp->vnodeIndex[vLarge].handle);
1155 IH_CONDSYNC(vp->vnodeIndex[vSmall].handle);
1156 IH_CONDSYNC(vp->diskDataHandle);
1158 IH_CONDSYNC(vp->linkHandle);
1159 #endif /* AFS_NT40_ENV */
1162 IH_REALLYCLOSE(vp->vnodeIndex[vLarge].handle);
1163 IH_REALLYCLOSE(vp->vnodeIndex[vSmall].handle);
1164 IH_REALLYCLOSE(vp->diskDataHandle);
1165 IH_REALLYCLOSE(vp->linkHandle);
1168 /* This gets used for the most part by utility routines that don't want
1169 * to keep all the volume headers around. Generally, the file server won't
1170 * call this routine, because then the offline message in the volume header
1171 * (or other information) will still be available to clients. For NAMEI, also
1172 * close the file handles.
1174 void VDetachVolume_r(Error *ec, Volume *vp)
1177 struct DiskPartition *tpartp;
1178 int notifyServer, useDone;
1180 *ec = 0; /* always "succeeds" */
1181 if (programType == volumeUtility) {
1182 notifyServer = vp->needsPutBack;
1183 useDone = (V_destroyMe(vp) == DESTROY_ME);
1185 tpartp = vp->partition;
1187 DeleteVolumeFromHashTable(vp);
1188 vp->shuttingDown = 1;
1190 /* Will be detached sometime in the future--this is OK since volume is offline */
1192 if (programType == volumeUtility && notifyServer) {
1194 * Note: The server is not notified in the case of a bogus volume
1195 * explicitly to make it possible to create a volume, do a partial
1196 * restore, then abort the operation without ever putting the volume
1197 * online. This is essential in the case of a volume move operation
1198 * between two partitions on the same server. In that case, there
1199 * would be two instances of the same volume, one of them bogus,
1200 * which the file server would attempt to put on line
1203 /* don't put online */
1204 FSYNC_askfs(volume, tpartp->name, FSYNC_DONE, 0);
1206 /* fs can use it again */
1207 FSYNC_askfs(volume, tpartp->name, FSYNC_ON, 0);
1208 /* Dettaching it so break all callbacks on it*/
1209 if (V_BreakVolumeCallbacks) {
1210 Log("volume %u detached; breaking all call backs\n", volume);
1211 (*V_BreakVolumeCallbacks)(volume);
1217 void VDetachVolume(Error *ec, Volume *vp)
1220 VDetachVolume_r(ec, vp);
1225 int VAllocBitmapEntry_r(Error *ec, Volume *vp, register struct vnodeIndex
1228 register byte *bp,*ep;
1230 /* This test is probably redundant */
1231 if (!VolumeWriteable(vp)) {
1236 if ((programType == fileServer) && !index->bitmap) {
1239 if (vp->specialStatus == VBUSY) {
1240 if (vp->goingOffline) { /* vos dump waiting for the volume to
1241 go offline. We probably come here
1242 from AddNewReadableResidency */
1246 while (vp->specialStatus == VBUSY)
1247 #ifdef AFS_PTHREAD_ENV
1249 #else /* AFS_PTHREAD_ENV */
1251 #endif /* AFS_PTHREAD_ENV */
1255 if (!index->bitmap) {
1256 vp->specialStatus = VBUSY; /* Stop anyone else from using it.*/
1257 for (i = 0; i<nVNODECLASSES; i++) {
1262 vp->specialStatus = 0;
1263 vp->shuttingDown = 1; /* Let who has it free it. */
1268 vp->specialStatus = 0; /* Allow others to have access. */
1271 #endif /* BITMAP_LATER */
1272 bp = index->bitmap + index->bitmapOffset;
1273 ep = index->bitmap + index->bitmapSize;
1275 if ((*(bit32 *)bp) != 0xffffffff) {
1277 index->bitmapOffset = bp - index->bitmap;
1280 o = ffs(~*bp)-1; /* ffs is documented in BSTRING(3) */
1282 return (bp - index->bitmap)*8 + o;
1284 bp += sizeof(bit32) /* i.e. 4 */;
1286 /* No bit map entry--must grow bitmap */
1288 realloc(index->bitmap, index->bitmapSize+VOLUME_BITMAP_GROWSIZE);
1291 bp += index->bitmapSize;
1292 memset(bp, 0, VOLUME_BITMAP_GROWSIZE);
1293 index->bitmapOffset = index->bitmapSize;
1294 index->bitmapSize += VOLUME_BITMAP_GROWSIZE;
1296 return index->bitmapOffset*8;
1299 int VAllocBitmapEntry(Error *ec, Volume *vp, register struct vnodeIndex *index)
1303 retVal = VAllocBitmapEntry_r(ec,vp,index);
1308 void VFreeBitMapEntry_r(Error *ec, register struct vnodeIndex *index,
1311 unsigned int offset;
1314 if (!index->bitmap) return;
1315 #endif /* BITMAP_LATER */
1316 offset = bitNumber>>3;
1317 if (offset >= index->bitmapSize) {
1321 if (offset < index->bitmapOffset)
1322 index->bitmapOffset = offset&~3; /* Truncate to nearest bit32 */
1323 *(index->bitmap + offset) &= ~(1 << (bitNumber & 0x7));
1326 void VFreeBitMapEntry(Error *ec, register struct vnodeIndex *index,
1330 VFreeBitMapEntry_r(ec, index, bitNumber);
1334 void VUpdateVolume_r(Error *ec,Volume *vp)
1337 if (programType == fileServer)
1338 V_uniquifier(vp) = (V_inUse(vp)? V_nextVnodeUnique(vp) + 200: V_nextVnodeUnique(vp));
1339 /*printf("Writing volume header for '%s'\n", V_name(vp));*/
1340 WriteVolumeHeader_r(ec, vp);
1343 "VUpdateVolume: error updating volume header, volume %u (%s)\n",
1344 V_id(vp), V_name(vp));
1345 VForceOffline_r(vp);
1349 void VUpdateVolume(Error *ec, Volume *vp)
1352 VUpdateVolume_r(ec, vp);
1356 void VSyncVolume_r(Error *ec, Volume *vp)
1359 VUpdateVolume_r(ec, vp);
1362 fdP = IH_OPEN(V_diskDataHandle(vp));
1363 assert(fdP != NULL);
1364 code = FDH_SYNC(fdP);
1370 void VSyncVolume(Error *ec, Volume *vp)
1373 VSyncVolume_r(ec, vp);
1377 static void FreeVolume(Volume *vp)
1382 for (i = 0; i<nVNODECLASSES; i++)
1383 if (vp->vnodeIndex[i].bitmap)
1384 free(vp->vnodeIndex[i].bitmap);
1385 FreeVolumeHeader(vp);
1386 DeleteVolumeFromHashTable(vp);
1390 static void GetBitmap(Error *ec, Volume *vp, VnodeClass class)
1392 StreamHandle_t *file;
1396 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1397 struct vnodeIndex *vip = &vp->vnodeIndex[class];
1398 struct VnodeDiskObject *vnode;
1399 unsigned int unique = 0;
1403 #endif /* BITMAP_LATER */
1407 fdP = IH_OPEN(vip->handle);
1408 assert (fdP != NULL);
1409 file = FDH_FDOPEN(fdP, "r");
1410 assert (file != NULL);
1411 vnode = (VnodeDiskObject *) malloc(vcp->diskSize);
1412 assert(vnode != NULL);
1413 size = OS_SIZE(fdP->fd_fd);
1415 nVnodes = (size <= vcp->diskSize? 0: size-vcp->diskSize)
1417 vip->bitmapSize = ((nVnodes/8)+10)/4*4; /* The 10 is a little extra so
1418 a few files can be created in this volume,
1419 the whole thing is rounded up to nearest 4
1420 bytes, because the bit map allocator likes
1423 BitMap = (byte *) calloc(1, vip->bitmapSize);
1424 assert(BitMap != NULL);
1425 #else /* BITMAP_LATER */
1426 vip->bitmap = (byte *) calloc(1, vip->bitmapSize);
1427 assert(vip->bitmap != NULL);
1428 vip->bitmapOffset = 0;
1429 #endif /* BITMAP_LATER */
1430 if (STREAM_SEEK(file,vcp->diskSize,0) != -1) {
1432 for (bitNumber = 0; bitNumber < nVnodes+100; bitNumber++) {
1433 if (STREAM_READ(vnode, vcp->diskSize, 1, file) != 1)
1435 if (vnode->type != vNull) {
1436 if (vnode->vnodeMagic != vcp->magic) {
1437 Log("GetBitmap: addled vnode index in volume %s; volume needs salvage\n",
1443 *(BitMap + (bitNumber>>3)) |= (1 << (bitNumber & 0x7));
1444 #else /* BITMAP_LATER */
1445 *(vip->bitmap + (bitNumber>>3)) |= (1 << (bitNumber & 0x7));
1446 #endif /* BITMAP_LATER */
1447 if (unique <= vnode->uniquifier)
1448 unique = vnode->uniquifier + 1;
1450 #ifndef AFS_PTHREAD_ENV
1451 if ((bitNumber & 0x00ff) == 0x0ff) { /* every 256 iterations */
1454 #endif /* !AFS_PTHREAD_ENV */
1457 if (vp->nextVnodeUnique < unique) {
1458 Log("GetBitmap: bad volume uniquifier for volume %s; volume needs salvage\n", V_name(vp));
1461 /* Paranoia, partly justified--I think fclose after fdopen
1462 * doesn't seem to close fd. In any event, the documentation
1463 * doesn't specify, so it's safer to close it twice.
1469 /* There may have been a racing condition with some other thread, both
1470 * creating the bitmaps for this volume. If the other thread was faster
1471 * the pointer to bitmap should already be filled and we can free ours.
1473 if (vip->bitmap == NULL) {
1474 vip->bitmap = BitMap;
1475 vip->bitmapOffset = 0;
1477 free((byte *)BitMap);
1478 #endif /* BITMAP_LATER */
1481 static void GetVolumePath(Error *ec, VolId volumeId, char **partitionp,
1484 static char partition[VMAXPATHLEN], name[VMAXPATHLEN];
1485 char path[VMAXPATHLEN];
1487 struct DiskPartition *dp;
1491 sprintf(&name[1],VFORMAT,volumeId);
1492 for (dp = DiskPartitionList; dp; dp = dp->next) {
1494 strcpy(path, VPartitionPath(dp));
1496 if (stat(path,&status) == 0) {
1497 strcpy(partition, dp->name);
1504 *partitionp = *namep = NULL;
1507 *partitionp = partition;
1512 int VolumeNumber(char *name)
1516 return atoi(name+1);
1519 char *VolumeExternalName(VolumeId volumeId)
1521 static char name[15];
1522 sprintf(name,VFORMAT,volumeId);
1526 #if OPENAFS_VOL_STATS
1527 #define OneDay (86400) /* 24 hours' worth of seconds */
1529 #define OneDay (24*60*60) /* 24 hours */
1530 #endif /* OPENAFS_VOL_STATS */
1532 #define Midnight(date) ((date-TimeZoneCorrection)/OneDay*OneDay+TimeZoneCorrection)
1534 /*------------------------------------------------------------------------
1535 * [export] VAdjustVolumeStatistics
1538 * If we've passed midnight, we need to update all the day use
1539 * statistics as well as zeroing the detailed volume statistics
1540 * (if we are implementing them).
1543 * vp : Pointer to the volume structure describing the lucky
1544 * volume being considered for update.
1550 * Nothing interesting.
1554 *------------------------------------------------------------------------*/
1556 int VAdjustVolumeStatistics_r(register Volume *vp)
1558 unsigned int now = FT_ApproxTime();
1560 if (now - V_dayUseDate(vp) > OneDay) {
1563 ndays = (now - V_dayUseDate(vp)) / OneDay;
1564 for (i = 6; i>ndays-1; i--)
1565 V_weekUse(vp)[i] = V_weekUse(vp)[i-ndays];
1566 for (i = 0; i<ndays-1 && i<7; i++)
1567 V_weekUse(vp)[i] = 0;
1569 V_weekUse(vp)[ndays-1] = V_dayUse(vp);
1571 V_dayUseDate(vp) = Midnight(now);
1573 #if OPENAFS_VOL_STATS
1575 * All we need to do is bzero the entire VOL_STATS_BYTES of
1576 * the detailed volume statistics area.
1578 memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES);
1579 #endif /* OPENAFS_VOL_STATS */
1580 } /*It's been more than a day of collection*/
1583 * Always return happily.
1586 } /*VAdjustVolumeStatistics*/
1588 int VAdjustVolumeStatistics(register Volume *vp)
1592 retVal = VAdjustVolumeStatistics_r(vp);
1597 void VBumpVolumeUsage_r(register Volume *vp)
1599 unsigned int now = FT_ApproxTime();
1600 if (now - V_dayUseDate(vp) > OneDay)
1601 VAdjustVolumeStatistics_r(vp);
1603 * Save the volume header image to disk after every 128 bumps to dayUse.
1605 if ((V_dayUse(vp)++ & 127) == 0) {
1607 VUpdateVolume_r(&error, vp);
1611 void VBumpVolumeUsage(register Volume *vp)
1614 VBumpVolumeUsage_r(vp);
1618 void VSetDiskUsage_r(void)
1620 static int FifteenMinuteCounter = 0;
1623 /* NOTE: Don't attempt to access the partitions list until the
1624 initialization level indicates that all volumes are attached,
1625 which implies that all partitions are initialized. */
1626 #ifdef AFS_PTHREAD_ENV
1628 #else /* AFS_PTHREAD_ENV */
1630 #endif /* AFS_PTHREAD_ENV */
1633 VResetDiskUsage_r();
1634 if (++FifteenMinuteCounter == 3) {
1635 FifteenMinuteCounter = 0;
1640 void VSetDiskUsage(void)
1647 /* The number of minutes that a volume hasn't been updated before the
1648 * "Dont salvage" flag in the volume header will be turned on */
1649 #define SALVAGE_INTERVAL (10*60)
1651 static VolumeId *UpdateList; /* Pointer to array of Volume ID's */
1652 static int nUpdatedVolumes; /* Updated with entry in UpdateList, salvage after crash flag on */
1653 static int updateSize; /* number of entries possible */
1654 #define UPDATE_LIST_SIZE 100 /* size increment */
1656 void VAddToVolumeUpdateList_r(Error *ec, Volume *vp)
1659 vp->updateTime = FT_ApproxTime();
1660 if (V_dontSalvage(vp) == 0)
1662 V_dontSalvage(vp) = 0;
1663 VSyncVolume_r(ec, vp);
1667 updateSize = UPDATE_LIST_SIZE;
1668 UpdateList = (VolumeId *) malloc(sizeof (VolumeId) * updateSize);
1670 if (nUpdatedVolumes == updateSize) {
1671 updateSize += UPDATE_LIST_SIZE;
1672 UpdateList = (VolumeId *) realloc(UpdateList, sizeof (VolumeId) * updateSize);
1675 assert(UpdateList != NULL);
1676 UpdateList[nUpdatedVolumes++] = V_id(vp);
1679 static void VScanUpdateList() {
1680 register int i, gap;
1681 register Volume *vp;
1683 afs_int32 now = FT_ApproxTime();
1684 /* Be careful with this code, since it works with interleaved calls to AddToVolumeUpdateList */
1685 for (i = gap = 0; i<nUpdatedVolumes; i++) {
1686 vp = VGetVolume_r(&error, UpdateList[i-gap] = UpdateList[i]);
1689 } else if (vp->nUsers == 1 && now - vp->updateTime > SALVAGE_INTERVAL) {
1690 V_dontSalvage(vp) = DONT_SALVAGE;
1691 VUpdateVolume_r(&error, vp); /* No need to fsync--not critical */
1696 #ifndef AFS_PTHREAD_ENV
1698 #endif /* !AFS_PTHREAD_ENV */
1700 nUpdatedVolumes -= gap;
1703 /***************************************************/
1704 /* Add on routines to manage a volume header cache */
1705 /***************************************************/
1707 static struct volHeader *volumeLRU;
1709 /* Allocate a bunch of headers; string them together */
1710 static void InitLRU(int howMany)
1712 register struct volHeader *hp;
1713 if (programType != fileServer)
1715 hp = (struct volHeader *)(calloc(howMany, sizeof(struct volHeader)));
1717 ReleaseVolumeHeader(hp++);
1720 /* Get a volume header from the LRU list; update the old one if necessary */
1721 /* Returns 1 if there was already a header, which is removed from the LRU list */
1722 static int GetVolumeHeader(register Volume *vp)
1725 register struct volHeader *hd;
1727 static int everLogged = 0;
1729 old = (vp->header != 0); /* old == volume already has a header */
1730 if (programType != fileServer) {
1732 hd = (struct volHeader *) calloc(1, sizeof(*vp->header));
1741 if (volumeLRU == hd)
1742 volumeLRU = hd->next;
1743 assert(hd->back == vp);
1747 /* not currently in use and least recently used */
1748 hd = volumeLRU->prev;
1750 hd = (struct volHeader *) calloc(1, sizeof(*vp->header));
1751 /* make it look like single elt LRU */
1752 hd->prev = hd->next = hd;
1754 Log("****Allocated more volume headers, probably leak****\n");
1759 if (hd->diskstuff.inUse) {
1760 WriteVolumeHeader_r(&error, hd->back);
1761 /* Ignore errors; catch them later */
1763 hd->back->header = 0;
1768 if (hd->next) { /* hd->next != 0 --> in LRU chain (we zero it later) */
1769 hd->prev->next = hd->next; /* pull hd out of LRU list */
1770 hd->next->prev = hd->prev; /* if hd only element, this is noop */
1772 hd->next = hd->prev = 0;
1773 /* if not in LRU chain, next test won't be true */
1774 if (hd == volumeLRU) /* last header item, turn into empty list */
1780 /* Put it at the top of the LRU chain */
1781 static void ReleaseVolumeHeader(register struct volHeader *hd)
1783 if (programType != fileServer)
1785 if (!hd || hd->next) /* no header, or header already released */
1788 hd->next = hd->prev = hd;
1790 hd->prev = volumeLRU->prev;
1791 hd->next = volumeLRU;
1792 hd->prev->next = hd->next->prev = hd;
1797 static void FreeVolumeHeader(register Volume *vp)
1799 register struct volHeader *hd = vp->header;
1802 if (programType == fileServer) {
1803 ReleaseVolumeHeader(hd);
1813 /***************************************************/
1814 /* Routines to add volume to hash chain, delete it */
1815 /***************************************************/
1817 static void AddVolumeToHashTable(register Volume *vp, int hashid)
1819 int hash = VOLUME_HASH(hashid);
1820 vp->hashid = hashid;
1821 vp->hashNext = VolumeHashTable[hash];
1822 VolumeHashTable[hash] = vp;
1823 vp->vnodeHashOffset = VolumeHashOffset_r();
1826 static void DeleteVolumeFromHashTable(register Volume *vp)
1828 int hash = VOLUME_HASH(vp->hashid);
1829 if (VolumeHashTable[hash] == vp)
1830 VolumeHashTable[hash] = vp->hashNext;
1832 Volume *tvp = VolumeHashTable[hash];
1835 while (tvp->hashNext && tvp->hashNext != vp)
1836 tvp = tvp->hashNext;
1837 if (tvp->hashNext == NULL)
1839 tvp->hashNext = vp->hashNext;
1844 void VPrintCacheStats_r(void)
1846 register struct VnodeClassInfo *vcp;
1847 vcp = &VnodeClassInfo[vLarge];
1848 Log("Large vnode cache, %d entries, %d allocs, %d gets (%d reads), %d writes\n",
1849 vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes);
1850 vcp = &VnodeClassInfo[vSmall];
1851 Log("Small vnode cache,%d entries, %d allocs, %d gets (%d reads), %d writes\n",
1852 vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes);
1853 Log("Volume header cache, %d entries, %d gets, %d replacements\n",
1854 VolumeCacheSize, VolumeGets, VolumeReplacements);
1857 void VPrintCacheStats(void)
1860 VPrintCacheStats_r();