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>
26 #include <afs/afsint.h>
29 #include <sys/param.h>
30 #if !defined(AFS_SGI_ENV)
33 #else /* AFS_OSF_ENV */
34 #ifdef AFS_VFSINCL_ENV
37 #include <sys/fs/ufs_fs.h>
39 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
40 #include <ufs/ufs/dinode.h>
41 #include <ufs/ffs/fs.h>
46 #else /* AFS_VFSINCL_ENV */
47 #if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_XBSD_ENV)
50 #endif /* AFS_VFSINCL_ENV */
51 #endif /* AFS_OSF_ENV */
52 #endif /* AFS_SGI_ENV */
53 #endif /* AFS_NT40_ENV */
71 #if defined(AFS_SUN_ENV) || defined(AFS_SUN5_ENV)
73 #include <sys/mnttab.h>
74 #include <sys/mntent.h>
80 #if defined(AFS_SGI_ENV)
83 #ifdef AFS_SGI_EFS_IOPS_ENV
84 #define ROOTINO EFS_ROOTINO
85 #include <sys/fs/efs.h>
86 #include "sgiefs/efs.h" /* until 5.1 release */
91 #ifndef AFS_LINUX20_ENV
92 #include <fstab.h> /* Need to find in libc 5, present in libc 6 */
95 #endif /* AFS_SGI_ENV */
97 #endif /* AFS_HPUX_ENV */
101 #include <netinet/in.h>
102 #include <sys/wait.h>
105 #include <sys/time.h>
106 #endif /* ITIMER_REAL */
107 #endif /* AFS_NT40_ENV */
108 #if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV) || defined(AFS_LINUX20_ENV)
115 #include <afs/errors.h>
118 #include <afs/afssyscalls.h>
120 #include <afs/afsutil.h>
126 #include "partition.h"
127 #ifdef AFS_PTHREAD_ENV
129 #else /* AFS_PTHREAD_ENV */
130 #include "afs/assert.h"
131 #endif /* AFS_PTHREAD_ENV */
138 #ifdef AFS_PTHREAD_ENV
139 pthread_mutex_t vol_glock_mutex;
140 pthread_mutex_t vol_attach_mutex;
141 pthread_cond_t vol_put_volume_cond;
142 pthread_cond_t vol_sleep_cond;
143 #endif /* AFS_PTHREAD_ENV */
146 extern void *calloc(), *realloc();
149 /*@printflike@*/ extern void Log(const char *format, ...);
151 /* Forward declarations */
152 static Volume *attach2();
153 static void FreeVolume();
154 static void VScanUpdateList();
155 static void InitLRU();
156 static int GetVolumeHeader();
157 static void ReleaseVolumeHeader();
158 static void FreeVolumeHeader();
159 static void AddVolumeToHashTable();
160 static void DeleteVolumeFromHashTable();
161 static int VHold(Volume * vp);
162 static int VHold_r(Volume * vp);
163 static void GetBitmap(Error * ec, Volume * vp, VnodeClass class);
164 static void GetVolumePath(Error * ec, VolId volumeId, char **partitionp,
166 static void VReleaseVolumeHandles_r(Volume * vp);
167 static void VCloseVolumeHandles_r(Volume * vp);
169 int LogLevel; /* Vice loglevel--not defined as extern so that it will be
170 * defined when not linked with vice, XXXX */
171 ProgramType programType; /* The type of program using the package */
174 #define VOLUME_BITMAP_GROWSIZE 16 /* bytes, => 128vnodes */
175 /* Must be a multiple of 4 (1 word) !! */
176 #define VOLUME_HASH_TABLE_SIZE 128 /* Must be a power of 2!! */
177 #define VOLUME_HASH(volumeId) (volumeId&(VOLUME_HASH_TABLE_SIZE-1))
178 private Volume *VolumeHashTable[VOLUME_HASH_TABLE_SIZE];
181 /* This macro is used where an ffs() call does not exist. Was in util/ffs.c */
185 afs_int32 ffs_tmp = x;
189 for (ffs_i = 1;; ffs_i++) {
196 #endif /* !AFS_HAVE_FFS */
198 struct Lock vol_listLock; /* Lock obtained when listing volumes: prevents a volume from being missed if the volume is attached during a list volumes */
200 extern struct Lock FSYNC_handler_lock;
202 static int TimeZoneCorrection; /* Number of seconds west of GMT */
204 /* Common message used when the volume goes off line */
205 char *VSalvageMessage =
206 "Files in this volume are currently unavailable; call operations";
208 int VInit; /* 0 - uninitialized,
209 * 1 - initialized but not all volumes have been attached,
210 * 2 - initialized and all volumes have been attached,
211 * 3 - initialized, all volumes have been attached, and
212 * VConnectFS() has completed. */
215 bit32 VolumeCacheCheck; /* Incremented everytime a volume goes on line--
216 * used to stamp volume headers and in-core
217 * vnodes. When the volume goes on-line the
218 * vnode will be invalidated */
220 int VolumeCacheSize = 200, VolumeGets = 0, VolumeReplacements = 0, Vlooks = 0;
224 VInitVolumePackage(ProgramType pt, int nLargeVnodes, int nSmallVnodes,
225 int connect, int volcache)
227 int errors = 0; /* Number of errors while finding vice partitions. */
233 #ifdef AFS_PTHREAD_ENV
234 assert(pthread_mutex_init(&vol_glock_mutex, NULL) == 0);
235 assert(pthread_mutex_init(&vol_attach_mutex, NULL) == 0);
236 assert(pthread_cond_init(&vol_put_volume_cond, NULL) == 0);
237 assert(pthread_cond_init(&vol_sleep_cond, NULL) == 0);
238 #else /* AFS_PTHREAD_ENV */
240 #endif /* AFS_PTHREAD_ENV */
241 Lock_Init(&vol_listLock);
242 Lock_Init(&FSYNC_handler_lock);
243 srandom(time(0)); /* For VGetVolumeInfo */
244 gettimeofday(&tv, &tz);
245 TimeZoneCorrection = tz.tz_minuteswest * 60;
247 /* Ok, we have done enough initialization that fileserver can
248 * start accepting calls, even though the volumes may not be
249 * available just yet.
253 if (programType == fileServer) {
254 /* File server or "stand" */
258 if (volcache > VolumeCacheSize)
259 VolumeCacheSize = volcache;
260 InitLRU(VolumeCacheSize);
262 VInitVnodes(vLarge, nLargeVnodes);
263 VInitVnodes(vSmall, nSmallVnodes);
266 errors = VAttachPartitions();
270 if (programType == fileServer) {
273 struct DiskPartition *diskP;
276 /* Attach all the volumes in this partition */
277 for (diskP = DiskPartitionList; diskP; diskP = diskP->next) {
278 int nAttached = 0, nUnattached = 0;
279 Log("Partition %s: attaching volumes\n", diskP->name);
280 dirp = opendir(VPartitionPath(diskP));
282 while ((dp = readdir(dirp))) {
284 p = strrchr(dp->d_name, '.');
285 if (p != NULL && strcmp(p, VHDREXT) == 0) {
288 vp = VAttachVolumeByName(&error, diskP->name, dp->d_name,
290 (*(vp ? &nAttached : &nUnattached))++;
291 if (error == VOFFLINE)
292 Log("Volume %d stays offline (/vice/offline/%s exists)\n", VolumeNumber(dp->d_name), dp->d_name);
293 else if (LogLevel >= 5) {
294 Log("Partition %s: attached volume %d (%s)\n",
295 diskP->name, VolumeNumber(dp->d_name),
303 Log("Partition %s: attached %d volumes; %d volumes not attached\n", diskP->name, nAttached, nUnattached);
308 VInit = 2; /* Initialized, and all volumes have been attached */
309 if (programType == volumeUtility && connect) {
311 Log("Unable to connect to file server; aborted\n");
318 /* This must be called by any volume utility which needs to run while the
319 file server is also running. This is separated from VInitVolumePackage so
320 that a utility can fork--and each of the children can independently
321 initialize communication with the file server */
326 VOL_LOCK retVal = VConnectFS_r();
327 VOL_UNLOCK return retVal;
334 assert(VInit == 2 && programType == volumeUtility);
335 rc = FSYNC_clientInit();
342 VDisconnectFS_r(void)
344 assert(programType == volumeUtility);
352 VOL_LOCK VDisconnectFS_r();
359 register Volume *vp, *np;
360 register afs_int32 code;
362 Log("VShutdown: shutting down on-line volumes...\n");
363 for (i = 0; i < VOLUME_HASH_TABLE_SIZE; i++) {
364 /* try to hold first volume in the hash table */
365 for (vp = VolumeHashTable[i]; vp; vp = vp->hashNext) {
369 /* otherwise we go around again, trying another volume */
373 Log("VShutdown: Attempting to take volume %u offline.\n",
375 /* first compute np before releasing vp, in case vp disappears
376 * after releasing. Hold it, so it doesn't disapear. If we
377 * can't hold it, try the next one in the chain. Invariant
378 * at the top of this loop is that vp is held (has extra ref count).
380 for (np = vp->hashNext; np; np = np->hashNext) {
385 /* next, take the volume offline (drops reference count) */
386 VOffline_r(vp, "File server was shut down");
387 vp = np; /* next guy to try */
390 Log("VShutdown: complete.\n");
396 VOL_LOCK VShutdown_r();
401 ReadHeader(Error * ec, IHandle_t * h, char *to, int size, bit32 magic,
404 struct versionStamp *vsn;
419 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
421 FDH_REALLYCLOSE(fdP);
424 vsn = (struct versionStamp *)to;
425 if (FDH_READ(fdP, to, size) != size || vsn->magic != magic) {
427 FDH_REALLYCLOSE(fdP);
432 /* Check is conditional, in case caller wants to inspect version himself */
433 if (version && vsn->version != version) {
438 /* VolumeHeaderToDisk
439 * Allows for storing 64 bit inode numbers in on-disk volume header
443 VolumeHeaderToDisk(VolumeDiskHeader_t * dh, VolumeHeader_t * h)
446 memset((char *)dh, 0, sizeof(VolumeDiskHeader_t));
447 dh->stamp = h->stamp;
449 dh->parent = h->parent;
451 #ifdef AFS_64BIT_IOPS_ENV
452 dh->volumeInfo_lo = (afs_int32) h->volumeInfo & 0xffffffff;
453 dh->volumeInfo_hi = (afs_int32) (h->volumeInfo >> 32) & 0xffffffff;
454 dh->smallVnodeIndex_lo = (afs_int32) h->smallVnodeIndex & 0xffffffff;
455 dh->smallVnodeIndex_hi =
456 (afs_int32) (h->smallVnodeIndex >> 32) & 0xffffffff;
457 dh->largeVnodeIndex_lo = (afs_int32) h->largeVnodeIndex & 0xffffffff;
458 dh->largeVnodeIndex_hi =
459 (afs_int32) (h->largeVnodeIndex >> 32) & 0xffffffff;
460 dh->linkTable_lo = (afs_int32) h->linkTable & 0xffffffff;
461 dh->linkTable_hi = (afs_int32) (h->linkTable >> 32) & 0xffffffff;
463 dh->volumeInfo_lo = h->volumeInfo;
464 dh->smallVnodeIndex_lo = h->smallVnodeIndex;
465 dh->largeVnodeIndex_lo = h->largeVnodeIndex;
466 dh->linkTable_lo = h->linkTable;
470 /* DiskToVolumeHeader
471 * Reads volume header file from disk, convering 64 bit inodes
472 * if required. Makes the assumption that AFS has *always*
473 * zero'd the volume header file so that high parts of inode
474 * numbers are 0 in older (SGI EFS) volume header files.
477 DiskToVolumeHeader(VolumeHeader_t * h, VolumeDiskHeader_t * dh)
479 memset((char *)h, 0, sizeof(VolumeHeader_t));
480 h->stamp = dh->stamp;
482 h->parent = dh->parent;
484 #ifdef AFS_64BIT_IOPS_ENV
486 (Inode) dh->volumeInfo_lo | ((Inode) dh->volumeInfo_hi << 32);
489 (Inode) dh->smallVnodeIndex_lo | ((Inode) dh->
490 smallVnodeIndex_hi << 32);
493 (Inode) dh->largeVnodeIndex_lo | ((Inode) dh->
494 largeVnodeIndex_hi << 32);
496 (Inode) dh->linkTable_lo | ((Inode) dh->linkTable_hi << 32);
498 h->volumeInfo = dh->volumeInfo_lo;
499 h->smallVnodeIndex = dh->smallVnodeIndex_lo;
500 h->largeVnodeIndex = dh->largeVnodeIndex_lo;
501 h->linkTable = dh->linkTable_lo;
507 WriteVolumeHeader_r(ec, vp)
511 IHandle_t *h = V_diskDataHandle(vp);
521 if (FDH_SEEK(fdP, 0, SEEK_SET) < 0) {
523 FDH_REALLYCLOSE(fdP);
526 if (FDH_WRITE(fdP, (char *)&V_disk(vp), sizeof(V_disk(vp)))
527 != sizeof(V_disk(vp))) {
529 FDH_REALLYCLOSE(fdP);
535 /* Attach an existing volume, given its pathname, and return a
536 pointer to the volume header information. The volume also
537 normally goes online at this time. An offline volume
538 must be reattached to make it go online */
540 VAttachVolumeByName(Error * ec, char *partition, char *name, int mode)
543 VATTACH_LOCK VOL_LOCK retVal =
544 VAttachVolumeByName_r(ec, partition, name, mode);
545 VOL_UNLOCK VATTACH_UNLOCK return retVal;
549 VAttachVolumeByName_r(Error * ec, char *partition, char *name, int mode)
554 struct VolumeDiskHeader diskHeader;
555 struct VolumeHeader iheader;
556 struct DiskPartition *partp;
560 if (programType == volumeUtility) {
562 VLockPartition_r(partition);
564 if (programType == fileServer) {
565 vp = VGetVolume_r(ec, VolumeNumber(name));
569 if (vp->specialStatus == VBUSY)
571 VDetachVolume_r(ec, vp);
573 Log("VAttachVolume: Error detaching volume (%s)\n", name);
578 if (!(partp = VGetPartition_r(partition, 0))) {
580 Log("VAttachVolume: Error getting partition (%s)\n", partition);
585 strcpy(path, VPartitionPath(partp));
588 VOL_UNLOCK if ((fd = open(path, O_RDONLY)) == -1
589 || fstat(fd, &status) == -1) {
590 Log("VAttachVolume: Failed to open %s (errno %d)\n", path, errno);
593 VOL_LOCK *ec = VNOVOL;
596 n = read(fd, &diskHeader, sizeof(diskHeader));
598 VOL_LOCK if (n != sizeof(diskHeader)
599 || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) {
600 Log("VAttachVolume: Error reading volume header %s\n", path);
604 if (diskHeader.stamp.version != VOLUMEHEADERVERSION) {
605 Log("VAttachVolume: Volume %s, version number is incorrect; volume needs salvaged\n", path);
610 DiskToVolumeHeader(&iheader, &diskHeader);
611 if (programType == volumeUtility && mode != V_SECRETLY) {
612 if (FSYNC_askfs(iheader.id, partition, FSYNC_NEEDVOLUME, mode)
614 Log("VAttachVolume: attach of volume %u apparently denied by file server\n", iheader.id);
615 *ec = VNOVOL; /* XXXX */
620 vp = attach2(ec, path, &iheader, partp, isbusy);
621 if (programType == volumeUtility && vp) {
622 /* duplicate computation in fssync.c about whether the server
623 * takes the volume offline or not. If the volume isn't
624 * offline, we must not return it when we detach the volume,
625 * or the server will abort */
626 if (mode == V_READONLY
627 || (!VolumeWriteable(vp) && (mode == V_CLONE || mode == V_DUMP)))
628 vp->needsPutBack = 0;
630 vp->needsPutBack = 1;
632 /* OK, there's a problem here, but one that I don't know how to
633 * fix right now, and that I don't think should arise often.
634 * Basically, we should only put back this volume to the server if
635 * it was given to us by the server, but since we don't have a vp,
636 * we can't run the VolumeWriteable function to find out as we do
637 * above when computing vp->needsPutBack. So we send it back, but
638 * there's a path in VAttachVolume on the server which may abort
639 * if this volume doesn't have a header. Should be pretty rare
640 * for all of that to happen, but if it does, probably the right
641 * fix is for the server to allow the return of readonly volumes
642 * that it doesn't think are really checked out. */
643 if (programType == volumeUtility && vp == NULL && mode != V_SECRETLY) {
644 FSYNC_askfs(iheader.id, partition, FSYNC_ON, 0);
645 } else if (programType == fileServer && vp) {
646 V_needsCallback(vp) = 0;
648 if (VInit >= 2 && V_BreakVolumeCallbacks) {
649 Log("VAttachVolume: Volume %u was changed externally; breaking callbacks\n", V_id(vp));
650 (*V_BreakVolumeCallbacks) (V_id(vp));
653 VUpdateVolume_r(ec, vp);
655 Log("VAttachVolume: Error updating volume\n");
660 if (VolumeWriteable(vp) && V_dontSalvage(vp) == 0) {
661 /* This is a hack: by temporarily settint the incore
662 * dontSalvage flag ON, the volume will be put back on the
663 * Update list (with dontSalvage OFF again). It will then
664 * come back in N minutes with DONT_SALVAGE eventually
665 * set. This is the way that volumes that have never had
666 * it set get it set; or that volumes that have been
667 * offline without DONT SALVAGE having been set also
668 * eventually get it set */
669 V_dontSalvage(vp) = DONT_SALVAGE;
670 VAddToVolumeUpdateList_r(ec, vp);
672 Log("VAttachVolume: Error adding volume to update list\n");
679 Log("VOnline: volume %u (%s) attached and online\n", V_id(vp),
683 if (programType == volumeUtility) {
684 VUnlockPartition_r(partition);
693 attach2(Error * ec, char *path, register struct VolumeHeader * header,
694 struct DiskPartition * partp, int isbusy)
698 VOL_UNLOCK vp = (Volume *) calloc(1, sizeof(Volume));
700 vp->specialStatus = (byte) (isbusy ? VBUSY : 0);
701 vp->device = partp->device;
702 vp->partition = partp;
703 IH_INIT(vp->vnodeIndex[vLarge].handle, partp->device, header->parent,
704 header->largeVnodeIndex);
705 IH_INIT(vp->vnodeIndex[vSmall].handle, partp->device, header->parent,
706 header->smallVnodeIndex);
707 IH_INIT(vp->diskDataHandle, partp->device, header->parent,
709 IH_INIT(vp->linkHandle, partp->device, header->parent, header->linkTable);
710 vp->cacheCheck = ++VolumeCacheCheck;
711 /* just in case this ever rolls over */
713 vp->cacheCheck = ++VolumeCacheCheck;
714 vp->shuttingDown = 0;
715 vp->goingOffline = 0;
717 VOL_LOCK GetVolumeHeader(vp);
718 VOL_UNLOCK(void) ReadHeader(ec, V_diskDataHandle(vp), (char *)&V_disk(vp),
719 sizeof(V_disk(vp)), VOLUMEINFOMAGIC,
722 Log("VAttachVolume: Error reading diskDataHandle vol header %s; error=%u\n", path, *ec);
725 struct IndexFileHeader iHead;
727 #if OPENAFS_VOL_STATS
729 * We just read in the diskstuff part of the header. If the detailed
730 * volume stats area has not yet been initialized, we should bzero the
731 * area and mark it as initialized.
733 if (!(V_stat_initialized(vp))) {
734 memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES);
735 V_stat_initialized(vp) = 1;
737 #endif /* OPENAFS_VOL_STATS */
738 VOL_UNLOCK(void) ReadHeader(ec, vp->vnodeIndex[vSmall].handle,
739 (char *)&iHead, sizeof(iHead),
740 SMALLINDEXMAGIC, SMALLINDEXVERSION);
742 Log("VAttachVolume: Error reading smallVnode vol header %s; error=%u\n", path, *ec);
746 struct IndexFileHeader iHead;
747 VOL_UNLOCK(void) ReadHeader(ec, vp->vnodeIndex[vLarge].handle,
748 (char *)&iHead, sizeof(iHead),
749 LARGEINDEXMAGIC, LARGEINDEXVERSION);
751 Log("VAttachVolume: Error reading largeVnode vol header %s; error=%u\n", path, *ec);
756 struct versionStamp stamp;
757 VOL_UNLOCK(void) ReadHeader(ec, V_linkHandle(vp), (char *)&stamp,
758 sizeof(stamp), LINKTABLEMAGIC,
761 Log("VAttachVolume: Error reading namei vol header %s; error=%u\n", path, *ec);
766 Log("VAttachVolume: Error attaching volume %s; volume needs salvage; error=%u\n", path, *ec);
770 if (V_needsSalvaged(vp)) {
771 if (vp->specialStatus)
772 vp->specialStatus = 0;
773 Log("VAttachVolume: volume salvage flag is ON for %s; volume needs salvage\n", path);
777 if (programType == fileServer) {
779 if (V_inUse(vp) && VolumeWriteable(vp)) {
780 if (!V_needsSalvaged(vp)) {
781 V_needsSalvaged(vp) = 1;
782 VUpdateVolume_r(ec, vp);
785 Log("VAttachVolume: volume %s needs to be salvaged; not attached.\n", path);
789 #endif /* FAST_RESTART */
790 if (V_destroyMe(vp) == DESTROY_ME) {
792 Log("VAttachVolume: volume %s is junk; it should be destroyed at next salvage\n", path);
798 AddVolumeToHashTable(vp, V_id(vp));
799 vp->nextVnodeUnique = V_uniquifier(vp);
800 vp->vnodeIndex[vSmall].bitmap = vp->vnodeIndex[vLarge].bitmap = NULL;
802 if (programType == fileServer && VolumeWriteable(vp)) {
804 for (i = 0; i < nVNODECLASSES; i++) {
805 VOL_UNLOCK GetBitmap(ec, vp, i);
808 Log("VAttachVolume: error getting bitmap for volume (%s)\n",
814 #endif /* BITMAP_LATER */
816 if (programType == fileServer) {
817 if (vp->specialStatus)
818 vp->specialStatus = 0;
819 if (V_blessed(vp) && V_inService(vp) && !V_needsSalvaged(vp)) {
821 V_offlineMessage(vp)[0] = '\0';
828 /* Attach an existing volume.
829 The volume also normally goes online at this time.
830 An offline volume must be reattached to make it go online.
834 VAttachVolume(Error * ec, VolumeId volumeId, int mode)
837 VATTACH_LOCK VOL_LOCK retVal = VAttachVolume_r(ec, volumeId, mode);
838 VOL_UNLOCK VATTACH_UNLOCK return retVal;
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).
868 VHold_r(register Volume * vp)
872 if (vp->nUsers == 0 && !GetVolumeHeader(vp)) {
873 VolumeReplacements++;
874 ReadHeader(&error, V_diskDataHandle(vp), (char *)&V_disk(vp),
875 sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
884 VHold(register Volume * vp)
887 VOL_LOCK retVal = VHold_r(vp);
888 VOL_UNLOCK return retVal;
892 VTakeOffline_r(register Volume * vp)
894 assert(vp->nUsers > 0);
895 assert(programType == fileServer);
896 vp->goingOffline = 1;
897 V_needsSalvaged(vp) = 1;
901 VTakeOffline(register Volume * vp)
903 VOL_LOCK VTakeOffline_r(vp);
907 VPutVolume_r(register Volume * vp)
909 assert(--vp->nUsers >= 0);
910 if (vp->nUsers == 0) {
911 ReleaseVolumeHeader(vp->header);
912 if (vp->goingOffline) {
914 assert(programType == fileServer);
915 vp->goingOffline = 0;
917 VUpdateVolume_r(&error, vp);
918 VCloseVolumeHandles_r(vp);
920 Log("VOffline: Volume %u (%s) is now offline", V_id(vp),
922 if (V_offlineMessage(vp)[0])
923 Log(" (%s)", V_offlineMessage(vp));
926 #ifdef AFS_PTHREAD_ENV
927 assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0);
928 #else /* AFS_PTHREAD_ENV */
929 LWP_NoYieldSignal(VPutVolume);
930 #endif /* AFS_PTHREAD_ENV */
932 if (vp->shuttingDown) {
933 VReleaseVolumeHandles_r(vp);
935 if (programType == fileServer)
936 #ifdef AFS_PTHREAD_ENV
937 assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0);
938 #else /* AFS_PTHREAD_ENV */
939 LWP_NoYieldSignal(VPutVolume);
940 #endif /* AFS_PTHREAD_ENV */
946 VPutVolume(register Volume * vp)
948 VOL_LOCK VPutVolume_r(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 */
955 VGetVolume(Error * ec, VolId volumeId)
958 VOL_LOCK retVal = VGetVolume_r(ec, volumeId);
959 VOL_UNLOCK return retVal;
963 VGetVolume_r(Error * ec, VolId volumeId)
966 unsigned short V0 = 0, V1 = 0, V2 = 0, V3 = 0, V4 = 0, V5 = 0, V6 =
967 0, V7 = 0, V8 = 0, V9 = 0;
968 unsigned short V10 = 0, V11 = 0, V12 = 0, V13 = 0, V14 = 0, V15 = 0;
973 for (vp = VolumeHashTable[VOLUME_HASH(volumeId)];
974 vp && vp->hashid != volumeId; vp = vp->hashNext)
981 /* Until we have reached an initialization level of 2
982 * we don't know whether this volume exists or not.
983 * We can't sleep and retry later because before a volume
984 * is attached, the caller tries to get it first. Just
985 * return VOFFLINE and the caller can choose whether to
986 * retry the command or not. */
997 if (vp->nUsers == 0 && !GetVolumeHeader(vp)) {
999 VolumeReplacements++;
1000 ReadHeader(ec, V_diskDataHandle(vp), (char *)&V_disk(vp),
1001 sizeof(V_disk(vp)), VOLUMEINFOMAGIC,
1005 /* Only log the error if it was a totally unexpected error. Simply
1006 * a missing inode is likely to be caused by the volume being deleted */
1007 if (errno != ENXIO || LogLevel)
1008 Log("Volume %u: couldn't reread volume header\n",
1016 if (vp->shuttingDown) {
1022 if (programType == fileServer) {
1024 if (vp->goingOffline) {
1026 #ifdef AFS_PTHREAD_ENV
1027 pthread_cond_wait(&vol_put_volume_cond, &vol_glock_mutex);
1028 #else /* AFS_PTHREAD_ENV */
1029 LWP_WaitProcess(VPutVolume);
1030 #endif /* AFS_PTHREAD_ENV */
1033 if (vp->specialStatus) {
1035 *ec = vp->specialStatus;
1036 } else if (V_inService(vp) == 0 || V_blessed(vp) == 0) {
1039 } else if (V_inUse(vp) == 0) {
1049 /* if no error, bump 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.
1063 VReleaseVolumeHandles_r(Volume * vp)
1065 DFlushVolume(V_id(vp));
1066 VReleaseVnodeFiles_r(vp);
1068 /* Too time consuming and unnecessary for the volserver */
1069 if (programType != volumeUtility) {
1070 IH_CONDSYNC(vp->vnodeIndex[vLarge].handle);
1071 IH_CONDSYNC(vp->vnodeIndex[vSmall].handle);
1072 IH_CONDSYNC(vp->diskDataHandle);
1074 IH_CONDSYNC(vp->linkHandle);
1075 #endif /* AFS_NT40_ENV */
1078 IH_RELEASE(vp->vnodeIndex[vLarge].handle);
1079 IH_RELEASE(vp->vnodeIndex[vSmall].handle);
1080 IH_RELEASE(vp->diskDataHandle);
1081 IH_RELEASE(vp->linkHandle);
1084 /* Force the volume offline, set the salvage flag. No further references to
1085 * the volume through the volume package will be honored. */
1087 VForceOffline_r(Volume * vp)
1092 strcpy(V_offlineMessage(vp),
1093 "Forced offline due to internal error: volume needs to be salvaged");
1094 Log("Volume %u forced offline: it needs salvaging!\n", V_id(vp));
1096 vp->goingOffline = 0;
1097 V_needsSalvaged(vp) = 1;
1098 VUpdateVolume_r(&error, vp);
1099 #ifdef AFS_PTHREAD_ENV
1100 assert(pthread_cond_broadcast(&vol_put_volume_cond) == 0);
1101 #else /* AFS_PTHREAD_ENV */
1102 LWP_NoYieldSignal(VPutVolume);
1103 #endif /* AFS_PTHREAD_ENV */
1105 VReleaseVolumeHandles_r(vp);
1110 VForceOffline(Volume * vp)
1112 VOL_LOCK VForceOffline_r(vp);
1115 /* The opposite of VAttachVolume. The volume header is written to disk, with
1116 the inUse bit turned off. A copy of the header is maintained in memory,
1117 however (which is why this is VOffline, not VDetach).
1120 VOffline_r(Volume * vp, char *message)
1123 VolumeId vid = V_id(vp);
1124 assert(programType != volumeUtility);
1129 if (V_offlineMessage(vp)[0] == '\0')
1130 strncpy(V_offlineMessage(vp), message, sizeof(V_offlineMessage(vp)));
1131 V_offlineMessage(vp)[sizeof(V_offlineMessage(vp)) - 1] = '\0';
1132 vp->goingOffline = 1;
1134 vp = VGetVolume_r(&error, vid); /* Wait for it to go offline */
1135 if (vp) /* In case it was reattached... */
1140 VOffline(Volume * vp, char *message)
1142 VOL_LOCK VOffline_r(vp, message);
1145 /* For VDetachVolume, we close all cached file descriptors, but keep
1146 * the Inode handles in case we need to read from a busy volume.
1149 VCloseVolumeHandles_r(Volume * vp)
1151 DFlushVolume(V_id(vp));
1152 VCloseVnodeFiles_r(vp);
1154 /* Too time consuming and unnecessary for the volserver */
1155 if (programType != volumeUtility) {
1156 IH_CONDSYNC(vp->vnodeIndex[vLarge].handle);
1157 IH_CONDSYNC(vp->vnodeIndex[vSmall].handle);
1158 IH_CONDSYNC(vp->diskDataHandle);
1160 IH_CONDSYNC(vp->linkHandle);
1161 #endif /* AFS_NT40_ENV */
1164 IH_REALLYCLOSE(vp->vnodeIndex[vLarge].handle);
1165 IH_REALLYCLOSE(vp->vnodeIndex[vSmall].handle);
1166 IH_REALLYCLOSE(vp->diskDataHandle);
1167 IH_REALLYCLOSE(vp->linkHandle);
1170 /* This gets used for the most part by utility routines that don't want
1171 * to keep all the volume headers around. Generally, the file server won't
1172 * call this routine, because then the offline message in the volume header
1173 * (or other information) will still be available to clients. For NAMEI, also
1174 * close the file handles.
1177 VDetachVolume_r(Error * ec, Volume * vp)
1180 struct DiskPartition *tpartp;
1181 int notifyServer, useDone;
1183 *ec = 0; /* always "succeeds" */
1184 if (programType == volumeUtility) {
1185 notifyServer = vp->needsPutBack;
1186 useDone = (V_destroyMe(vp) == DESTROY_ME);
1188 tpartp = vp->partition;
1190 DeleteVolumeFromHashTable(vp);
1191 vp->shuttingDown = 1;
1193 /* Will be detached sometime in the future--this is OK since volume is offline */
1195 if (programType == volumeUtility && notifyServer) {
1197 * Note: The server is not notified in the case of a bogus volume
1198 * explicitly to make it possible to create a volume, do a partial
1199 * restore, then abort the operation without ever putting the volume
1200 * online. This is essential in the case of a volume move operation
1201 * between two partitions on the same server. In that case, there
1202 * would be two instances of the same volume, one of them bogus,
1203 * which the file server would attempt to put on line
1206 /* don't put online */
1207 FSYNC_askfs(volume, tpartp->name, FSYNC_DONE, 0);
1209 /* fs can use it again */
1210 FSYNC_askfs(volume, tpartp->name, FSYNC_ON, 0);
1211 /* Dettaching it so break all callbacks on it */
1212 if (V_BreakVolumeCallbacks) {
1213 Log("volume %u detached; breaking all call backs\n", volume);
1214 (*V_BreakVolumeCallbacks) (volume);
1221 VDetachVolume(Error * ec, Volume * vp)
1223 VOL_LOCK VDetachVolume_r(ec, vp);
1228 VAllocBitmapEntry_r(Error * ec, Volume * vp, register struct vnodeIndex
1231 register byte *bp, *ep;
1233 /* This test is probably redundant */
1234 if (!VolumeWriteable(vp)) {
1235 *ec = (bit32) VREADONLY;
1239 if ((programType == fileServer) && !index->bitmap) {
1242 if (vp->specialStatus == VBUSY) {
1243 if (vp->goingOffline) { /* vos dump waiting for the volume to
1244 * go offline. We probably come here
1245 * from AddNewReadableResidency */
1248 VOL_UNLOCK while (vp->specialStatus == VBUSY)
1249 #ifdef AFS_PTHREAD_ENV
1251 #else /* AFS_PTHREAD_ENV */
1253 #endif /* AFS_PTHREAD_ENV */
1256 if (!index->bitmap) {
1257 vp->specialStatus = VBUSY; /* Stop anyone else from using it. */
1258 for (i = 0; i < nVNODECLASSES; i++) {
1259 VOL_UNLOCK GetBitmap(ec, vp, i);
1261 vp->specialStatus = 0;
1262 vp->shuttingDown = 1; /* Let who has it free it. */
1267 vp->specialStatus = 0; /* Allow others to have access. */
1270 #endif /* BITMAP_LATER */
1271 bp = index->bitmap + index->bitmapOffset;
1272 ep = index->bitmap + index->bitmapSize;
1274 if ((*(bit32 *) bp) != (bit32) 0xffffffff) {
1276 index->bitmapOffset = (afs_uint32) (bp - index->bitmap);
1279 o = ffs(~*bp) - 1; /* ffs is documented in BSTRING(3) */
1281 return (VnodeId) ((bp - index->bitmap) * 8 + o);
1283 bp += sizeof(bit32) /* i.e. 4 */ ;
1285 /* No bit map entry--must grow bitmap */
1287 realloc(index->bitmap, index->bitmapSize + VOLUME_BITMAP_GROWSIZE);
1290 bp += index->bitmapSize;
1291 memset(bp, 0, VOLUME_BITMAP_GROWSIZE);
1292 index->bitmapOffset = index->bitmapSize;
1293 index->bitmapSize += VOLUME_BITMAP_GROWSIZE;
1295 return index->bitmapOffset * 8;
1299 VAllocBitmapEntry(Error * ec, Volume * vp, register struct vnodeIndex * index)
1302 VOL_LOCK retVal = VAllocBitmapEntry_r(ec, vp, index);
1303 VOL_UNLOCK return retVal;
1307 VFreeBitMapEntry_r(Error * ec, register struct vnodeIndex *index,
1310 unsigned int offset;
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));
1327 VFreeBitMapEntry(Error * ec, register struct vnodeIndex *index,
1330 VOL_LOCK VFreeBitMapEntry_r(ec, index, bitNumber);
1334 VUpdateVolume_r(Error * ec, Volume * vp)
1337 if (programType == fileServer)
1339 (V_inUse(vp) ? V_nextVnodeUnique(vp) +
1340 200 : V_nextVnodeUnique(vp));
1341 /*printf("Writing volume header for '%s'\n", V_name(vp)); */
1342 WriteVolumeHeader_r(ec, vp);
1344 Log("VUpdateVolume: error updating volume header, volume %u (%s)\n",
1345 V_id(vp), V_name(vp));
1346 VForceOffline_r(vp);
1351 VUpdateVolume(Error * ec, Volume * vp)
1353 VOL_LOCK VUpdateVolume_r(ec, vp);
1357 VSyncVolume_r(Error * ec, Volume * vp)
1360 VUpdateVolume_r(ec, vp);
1363 fdP = IH_OPEN(V_diskDataHandle(vp));
1364 assert(fdP != NULL);
1365 code = FDH_SYNC(fdP);
1372 VSyncVolume(Error * ec, Volume * vp)
1374 VOL_LOCK VSyncVolume_r(ec, vp);
1378 FreeVolume(Volume * vp)
1383 for (i = 0; i < nVNODECLASSES; i++)
1384 if (vp->vnodeIndex[i].bitmap)
1385 free(vp->vnodeIndex[i].bitmap);
1386 FreeVolumeHeader(vp);
1387 DeleteVolumeFromHashTable(vp);
1392 GetBitmap(Error * ec, Volume * vp, VnodeClass class)
1394 StreamHandle_t *file;
1397 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
1398 struct vnodeIndex *vip = &vp->vnodeIndex[class];
1399 struct VnodeDiskObject *vnode;
1400 unsigned int unique = 0;
1404 #endif /* BITMAP_LATER */
1408 fdP = IH_OPEN(vip->handle);
1409 assert(fdP != NULL);
1410 file = FDH_FDOPEN(fdP, "r");
1411 assert(file != NULL);
1412 vnode = (VnodeDiskObject *) malloc(vcp->diskSize);
1413 assert(vnode != NULL);
1414 size = OS_SIZE(fdP->fd_fd);
1416 nVnodes = (size <= vcp->diskSize ? 0 : size - vcp->diskSize)
1418 vip->bitmapSize = ((nVnodes / 8) + 10) / 4 * 4; /* The 10 is a little extra so
1419 * a few files can be created in this volume,
1420 * the whole thing is rounded up to nearest 4
1421 * bytes, because the bit map allocator likes
1424 BitMap = (byte *) calloc(1, vip->bitmapSize);
1425 assert(BitMap != NULL);
1426 #else /* BITMAP_LATER */
1427 vip->bitmap = (byte *) calloc(1, vip->bitmapSize);
1428 assert(vip->bitmap != NULL);
1429 vip->bitmapOffset = 0;
1430 #endif /* BITMAP_LATER */
1431 if (STREAM_SEEK(file, vcp->diskSize, 0) != -1) {
1433 for (bitNumber = 0; bitNumber < nVnodes + 100; bitNumber++) {
1434 if (STREAM_READ(vnode, vcp->diskSize, 1, file) != 1)
1436 if (vnode->type != vNull) {
1437 if (vnode->vnodeMagic != vcp->magic) {
1438 Log("GetBitmap: addled vnode index in volume %s; volume needs salvage\n", V_name(vp));
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 */
1482 GetVolumePath(Error * ec, VolId volumeId, char **partitionp, char **namep)
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;
1506 *partitionp = partition;
1512 VolumeNumber(char *name)
1516 return atoi(name + 1);
1520 VolumeExternalName(VolumeId volumeId)
1522 static char name[15];
1523 sprintf(name, VFORMAT, volumeId);
1527 #if OPENAFS_VOL_STATS
1528 #define OneDay (86400) /* 24 hours' worth of seconds */
1530 #define OneDay (24*60*60) /* 24 hours */
1531 #endif /* OPENAFS_VOL_STATS */
1533 #define Midnight(date) ((date-TimeZoneCorrection)/OneDay*OneDay+TimeZoneCorrection)
1535 /*------------------------------------------------------------------------
1536 * [export] VAdjustVolumeStatistics
1539 * If we've passed midnight, we need to update all the day use
1540 * statistics as well as zeroing the detailed volume statistics
1541 * (if we are implementing them).
1544 * vp : Pointer to the volume structure describing the lucky
1545 * volume being considered for update.
1551 * Nothing interesting.
1555 *------------------------------------------------------------------------*/
1558 VAdjustVolumeStatistics_r(register Volume * vp)
1560 unsigned int now = FT_ApproxTime();
1562 if (now - V_dayUseDate(vp) > OneDay) {
1565 ndays = (now - V_dayUseDate(vp)) / OneDay;
1566 for (i = 6; i > ndays - 1; i--)
1567 V_weekUse(vp)[i] = V_weekUse(vp)[i - ndays];
1568 for (i = 0; i < ndays - 1 && i < 7; i++)
1569 V_weekUse(vp)[i] = 0;
1571 V_weekUse(vp)[ndays - 1] = V_dayUse(vp);
1573 V_dayUseDate(vp) = Midnight(now);
1575 #if OPENAFS_VOL_STATS
1577 * All we need to do is bzero the entire VOL_STATS_BYTES of
1578 * the detailed volume statistics area.
1580 memset((char *)(V_stat_area(vp)), 0, VOL_STATS_BYTES);
1581 #endif /* OPENAFS_VOL_STATS */
1584 /*It's been more than a day of collection */
1586 * Always return happily.
1589 } /*VAdjustVolumeStatistics */
1592 VAdjustVolumeStatistics(register Volume * vp)
1595 VOL_LOCK retVal = VAdjustVolumeStatistics_r(vp);
1596 VOL_UNLOCK return retVal;
1600 VBumpVolumeUsage_r(register Volume * vp)
1602 unsigned int now = FT_ApproxTime();
1603 if (now - V_dayUseDate(vp) > OneDay)
1604 VAdjustVolumeStatistics_r(vp);
1606 * Save the volume header image to disk after every 128 bumps to dayUse.
1608 if ((V_dayUse(vp)++ & 127) == 0) {
1610 VUpdateVolume_r(&error, vp);
1615 VBumpVolumeUsage(register Volume * vp)
1617 VOL_LOCK VBumpVolumeUsage_r(vp);
1621 VSetDiskUsage_r(void)
1623 static int FifteenMinuteCounter = 0;
1626 /* NOTE: Don't attempt to access the partitions list until the
1627 * initialization level indicates that all volumes are attached,
1628 * which implies that all partitions are initialized. */
1629 #ifdef AFS_PTHREAD_ENV
1631 #else /* AFS_PTHREAD_ENV */
1633 #endif /* AFS_PTHREAD_ENV */
1636 VResetDiskUsage_r();
1637 if (++FifteenMinuteCounter == 3) {
1638 FifteenMinuteCounter = 0;
1646 VOL_LOCK VSetDiskUsage_r();
1649 /* The number of minutes that a volume hasn't been updated before the
1650 * "Dont salvage" flag in the volume header will be turned on */
1651 #define SALVAGE_INTERVAL (10*60)
1653 static VolumeId *UpdateList; /* Pointer to array of Volume ID's */
1654 static int nUpdatedVolumes; /* Updated with entry in UpdateList, salvage after crash flag on */
1655 static int updateSize; /* number of entries possible */
1656 #define UPDATE_LIST_SIZE 100 /* size increment */
1659 VAddToVolumeUpdateList_r(Error * ec, Volume * vp)
1662 vp->updateTime = FT_ApproxTime();
1663 if (V_dontSalvage(vp) == 0)
1665 V_dontSalvage(vp) = 0;
1666 VSyncVolume_r(ec, vp);
1670 updateSize = UPDATE_LIST_SIZE;
1671 UpdateList = (VolumeId *) malloc(sizeof(VolumeId) * updateSize);
1673 if (nUpdatedVolumes == updateSize) {
1674 updateSize += UPDATE_LIST_SIZE;
1676 (VolumeId *) realloc(UpdateList,
1677 sizeof(VolumeId) * updateSize);
1680 assert(UpdateList != NULL);
1681 UpdateList[nUpdatedVolumes++] = V_id(vp);
1685 VScanUpdateList(void)
1687 register int i, gap;
1688 register Volume *vp;
1690 afs_uint32 now = FT_ApproxTime();
1691 /* Be careful with this code, since it works with interleaved calls to AddToVolumeUpdateList */
1692 for (i = gap = 0; i < nUpdatedVolumes; i++) {
1693 vp = VGetVolume_r(&error, UpdateList[i - gap] = UpdateList[i]);
1696 } else if (vp->nUsers == 1 && now - vp->updateTime > SALVAGE_INTERVAL) {
1697 V_dontSalvage(vp) = DONT_SALVAGE;
1698 VUpdateVolume_r(&error, vp); /* No need to fsync--not critical */
1703 #ifndef AFS_PTHREAD_ENV
1705 #endif /* !AFS_PTHREAD_ENV */
1707 nUpdatedVolumes -= gap;
1710 /***************************************************/
1711 /* Add on routines to manage a volume header cache */
1712 /***************************************************/
1714 static struct volHeader *volumeLRU;
1716 /* Allocate a bunch of headers; string them together */
1718 InitLRU(int howMany)
1720 register struct volHeader *hp;
1721 if (programType != fileServer)
1723 hp = (struct volHeader *)(calloc(howMany, sizeof(struct volHeader)));
1725 ReleaseVolumeHeader(hp++);
1728 /* Get a volume header from the LRU list; update the old one if necessary */
1729 /* Returns 1 if there was already a header, which is removed from the LRU list */
1731 GetVolumeHeader(register Volume * vp)
1734 register struct volHeader *hd;
1736 static int everLogged = 0;
1738 old = (vp->header != 0); /* old == volume already has a header */
1739 if (programType != fileServer) {
1741 hd = (struct volHeader *)calloc(1, sizeof(*vp->header));
1749 if (volumeLRU == hd)
1750 volumeLRU = hd->next;
1751 assert(hd->back == vp);
1754 /* not currently in use and least recently used */
1755 hd = volumeLRU->prev;
1757 hd = (struct volHeader *)calloc(1, sizeof(*vp->header));
1758 /* make it look like single elt LRU */
1759 hd->prev = hd->next = hd;
1761 Log("****Allocated more volume headers, probably leak****\n");
1766 if (hd->diskstuff.inUse) {
1767 WriteVolumeHeader_r(&error, hd->back);
1768 /* Ignore errors; catch them later */
1770 hd->back->header = 0;
1775 if (hd->next) { /* hd->next != 0 --> in LRU chain (we zero it later) */
1776 hd->prev->next = hd->next; /* pull hd out of LRU list */
1777 hd->next->prev = hd->prev; /* if hd only element, this is noop */
1779 hd->next = hd->prev = 0;
1780 /* if not in LRU chain, next test won't be true */
1781 if (hd == volumeLRU) /* last header item, turn into empty list */
1787 /* Put it at the top of the LRU chain */
1789 ReleaseVolumeHeader(register struct volHeader *hd)
1791 if (programType != fileServer)
1793 if (!hd || hd->next) /* no header, or header already released */
1796 hd->next = hd->prev = hd;
1798 hd->prev = volumeLRU->prev;
1799 hd->next = volumeLRU;
1800 hd->prev->next = hd->next->prev = hd;
1806 FreeVolumeHeader(register Volume * vp)
1808 register struct volHeader *hd = vp->header;
1811 if (programType == fileServer) {
1812 ReleaseVolumeHeader(hd);
1821 /***************************************************/
1822 /* Routines to add volume to hash chain, delete it */
1823 /***************************************************/
1826 AddVolumeToHashTable(register Volume * vp, int hashid)
1828 int hash = VOLUME_HASH(hashid);
1829 vp->hashid = hashid;
1830 vp->hashNext = VolumeHashTable[hash];
1831 VolumeHashTable[hash] = vp;
1832 vp->vnodeHashOffset = VolumeHashOffset_r();
1836 DeleteVolumeFromHashTable(register Volume * vp)
1838 int hash = VOLUME_HASH(vp->hashid);
1839 if (VolumeHashTable[hash] == vp)
1840 VolumeHashTable[hash] = vp->hashNext;
1842 Volume *tvp = VolumeHashTable[hash];
1845 while (tvp->hashNext && tvp->hashNext != vp)
1846 tvp = tvp->hashNext;
1847 if (tvp->hashNext == NULL)
1849 tvp->hashNext = vp->hashNext;
1855 VPrintCacheStats_r(void)
1857 register struct VnodeClassInfo *vcp;
1858 vcp = &VnodeClassInfo[vLarge];
1859 Log("Large vnode cache, %d entries, %d allocs, %d gets (%d reads), %d writes\n", vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes);
1860 vcp = &VnodeClassInfo[vSmall];
1861 Log("Small vnode cache,%d entries, %d allocs, %d gets (%d reads), %d writes\n", vcp->cacheSize, vcp->allocs, vcp->gets, vcp->reads, vcp->writes);
1862 Log("Volume header cache, %d entries, %d gets, %d replacements\n",
1863 VolumeCacheSize, VolumeGets, VolumeReplacements);
1867 VPrintCacheStats(void)
1869 VOL_LOCK VPrintCacheStats_r();