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
9 * Portions Copyright (c) 2005-2008 Sine Nomine Associates
15 Institution: The Information Technology Center, Carnegie-Mellon University
18 #include <afsconfig.h>
19 #include <afs/param.h>
25 #ifdef HAVE_SYS_FILE_H
30 #ifdef AFS_PTHREAD_ENV
33 #include "rx/rx_queue.h"
34 #include <afs/afsint.h>
36 #include <afs/errors.h>
39 #include <afs/afssyscalls.h>
43 #include "volume_inline.h"
44 #include "vnode_inline.h"
45 #include "partition.h"
52 struct VnodeClassInfo VnodeClassInfo[nVNODECLASSES];
54 void VNLog(afs_int32 aop, afs_int32 anparms, ... );
61 #define BAD_IGET -1000
63 /* There are two separate vnode queue types defined here:
64 * Each hash conflict chain -- is singly linked, with a single head
65 * pointer. New entries are added at the beginning. Old
66 * entries are removed by linear search, which generally
67 * only occurs after a disk read).
68 * LRU chain -- is doubly linked, single head pointer.
69 * Entries are added at the head, reclaimed from the tail,
70 * or removed from anywhere in the queue.
74 /* Vnode hash table. Find hash chain by taking lower bits of
75 * (volume_hash_offset + vnode).
76 * This distributes the root inodes of the volumes over the
77 * hash table entries and also distributes the vnodes of
78 * volumes reasonably fairly. The volume_hash_offset field
79 * for each volume is established as the volume comes on line
80 * by using the VOLUME_HASH_OFFSET macro. This distributes the
81 * volumes fairly among the cache entries, both when servicing
82 * a small number of volumes and when servicing a large number.
85 /* logging stuff for finding bugs */
86 #define THELOGSIZE 5120
87 static afs_int32 theLog[THELOGSIZE];
88 static afs_int32 vnLogPtr = 0;
90 VNLog(afs_int32 aop, afs_int32 anparms, ... )
95 va_start(ap, anparms);
98 anparms = 4; /* do bounds checking */
100 temp = (aop << 16) | anparms;
101 theLog[vnLogPtr++] = temp;
102 if (vnLogPtr >= THELOGSIZE)
104 for (temp = 0; temp < anparms; temp++) {
105 theLog[vnLogPtr++] = va_arg(ap, afs_int32);
106 if (vnLogPtr >= THELOGSIZE)
112 /* VolumeHashOffset -- returns a new value to be stored in the
113 * volumeHashOffset of a Volume structure. Called when a
114 * volume is initialized. Sets the volumeHashOffset so that
115 * vnode cache entries are distributed reasonably between
116 * volumes (the root vnodes of the volumes will hash to
117 * different values, and spacing is maintained between volumes
118 * when there are not many volumes represented), and spread
119 * equally amongst vnodes within a single volume.
122 VolumeHashOffset_r(void)
124 static int nextVolumeHashOffset = 0;
125 /* hashindex Must be power of two in size */
127 # define hashMask ((1<<hashShift)-1)
128 static byte hashindex[1 << hashShift] =
129 { 0, 128, 64, 192, 32, 160, 96, 224 };
131 offset = hashindex[nextVolumeHashOffset & hashMask]
132 + (nextVolumeHashOffset >> hashShift);
133 nextVolumeHashOffset++;
137 /* Change hashindex (above) if you change this constant */
138 #define VNODE_HASH_TABLE_SIZE 256
139 private Vnode *VnodeHashTable[VNODE_HASH_TABLE_SIZE];
140 #define VNODE_HASH(volumeptr,vnodenumber)\
141 ((volumeptr->vnodeHashOffset + vnodenumber)&(VNODE_HASH_TABLE_SIZE-1))
145 * add a vnode to the volume's vnode list.
147 * @param[in] vp volume object pointer
148 * @param[in] vnp vnode object pointer
150 * @note for DAFS, it may seem like we should be acquiring a lightweight ref
151 * on vp, but this would actually break things. Right now, this is ok
152 * because we destroy all vnode cache contents during during volume
157 * @internal volume package internal use only
160 AddToVVnList(Volume * vp, Vnode * vnp)
162 if (queue_IsOnQueue(vnp))
166 Vn_cacheCheck(vnp) = vp->cacheCheck;
167 queue_Append(&vp->vnode_list, vnp);
168 Vn_stateFlags(vnp) |= VN_ON_VVN;
172 * delete a vnode from the volume's vnode list.
176 * @internal volume package internal use only
179 DeleteFromVVnList(Vnode * vnp)
181 Vn_volume(vnp) = NULL;
183 if (!queue_IsOnQueue(vnp))
187 Vn_stateFlags(vnp) &= ~(VN_ON_VVN);
191 * add a vnode to the end of the lru.
193 * @param[in] vcp vnode class info object pointer
194 * @param[in] vnp vnode object pointer
196 * @internal vnode package internal use only
199 AddToVnLRU(struct VnodeClassInfo * vcp, Vnode * vnp)
201 if (Vn_stateFlags(vnp) & VN_ON_LRU) {
205 /* Add it to the circular LRU list */
206 if (vcp->lruHead == NULL)
207 Abort("VPutVnode: vcp->lruHead==NULL");
209 vnp->lruNext = vcp->lruHead;
210 vnp->lruPrev = vcp->lruHead->lruPrev;
211 vcp->lruHead->lruPrev = vnp;
212 vnp->lruPrev->lruNext = vnp;
216 /* If the vnode was just deleted, put it at the end of the chain so it
217 * will be reused immediately */
219 vcp->lruHead = vnp->lruNext;
221 Vn_stateFlags(vnp) |= VN_ON_LRU;
225 * delete a vnode from the lru.
227 * @param[in] vcp vnode class info object pointer
228 * @param[in] vnp vnode object pointer
230 * @internal vnode package internal use only
233 DeleteFromVnLRU(struct VnodeClassInfo * vcp, Vnode * vnp)
235 if (!(Vn_stateFlags(vnp) & VN_ON_LRU)) {
239 if (vnp == vcp->lruHead)
240 vcp->lruHead = vcp->lruHead->lruNext;
242 if ((vnp == vcp->lruHead) ||
243 (vcp->lruHead == NULL))
244 Abort("DeleteFromVnLRU: lru chain addled!\n");
246 vnp->lruPrev->lruNext = vnp->lruNext;
247 vnp->lruNext->lruPrev = vnp->lruPrev;
249 Vn_stateFlags(vnp) &= ~(VN_ON_LRU);
253 * add a vnode to the vnode hash table.
255 * @param[in] vnp vnode object pointer
259 * @post vnode on hash
261 * @internal vnode package internal use only
264 AddToVnHash(Vnode * vnp)
266 unsigned int newHash;
268 if (!(Vn_stateFlags(vnp) & VN_ON_HASH)) {
269 newHash = VNODE_HASH(Vn_volume(vnp), Vn_id(vnp));
270 vnp->hashNext = VnodeHashTable[newHash];
271 VnodeHashTable[newHash] = vnp;
272 vnp->hashIndex = newHash;
274 Vn_stateFlags(vnp) |= VN_ON_HASH;
279 * delete a vnode from the vnode hash table.
286 * @post vnode removed from hash
288 * @internal vnode package internal use only
291 DeleteFromVnHash(Vnode * vnp)
295 if (Vn_stateFlags(vnp) & VN_ON_HASH) {
296 tvnp = VnodeHashTable[vnp->hashIndex];
298 VnodeHashTable[vnp->hashIndex] = vnp->hashNext;
300 while (tvnp && tvnp->hashNext != vnp)
301 tvnp = tvnp->hashNext;
303 tvnp->hashNext = vnp->hashNext;
306 vnp->hashNext = NULL;
308 Vn_stateFlags(vnp) &= ~(VN_ON_HASH);
314 * invalidate a vnode cache entry.
316 * @param[in] avnode vnode object pointer
320 * @post vnode metadata invalidated.
321 * vnode removed from hash table.
322 * DAFS: vnode state set to VN_STATE_INVALID.
324 * @internal vnode package internal use only
327 VInvalidateVnode_r(struct Vnode *avnode)
329 avnode->changed_newTime = 0; /* don't let it get flushed out again */
330 avnode->changed_oldTime = 0;
331 avnode->delete = 0; /* it isn't deleted, really */
332 avnode->cacheCheck = 0; /* invalid: prevents future vnode searches from working */
333 DeleteFromVnHash(avnode);
334 #ifdef AFS_DEMAND_ATTACH_FS
335 VnChangeState_r(avnode, VN_STATE_INVALID);
341 * initialize vnode cache for a given vnode class.
343 * @param[in] class vnode class
344 * @param[in] nVnodes size of cache
346 * @post vnode cache allocated and initialized
348 * @internal volume package internal use only
350 * @note generally called by VInitVolumePackage_r
352 * @see VInitVolumePackage_r
355 VInitVnodes(VnodeClass class, int nVnodes)
358 struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
360 vcp->allocs = vcp->gets = vcp->reads = vcp->writes = 0;
361 vcp->cacheSize = nVnodes;
364 opr_Assert(CHECKSIZE_SMALLVNODE);
366 vcp->residentSize = SIZEOF_SMALLVNODE;
367 vcp->diskSize = SIZEOF_SMALLDISKVNODE;
368 vcp->magic = SMALLVNODEMAGIC;
372 vcp->residentSize = SIZEOF_LARGEVNODE;
373 vcp->diskSize = SIZEOF_LARGEDISKVNODE;
374 vcp->magic = LARGEVNODEMAGIC;
378 int s = vcp->diskSize - 1;
388 va = (byte *) calloc(nVnodes, vcp->residentSize);
389 opr_Assert(va != NULL);
391 Vnode *vnp = (Vnode *) va;
392 Vn_refcount(vnp) = 0; /* no context switches */
393 Vn_stateFlags(vnp) |= VN_ON_LRU;
394 #ifdef AFS_DEMAND_ATTACH_FS
395 CV_INIT(&Vn_stateCV(vnp), "vnode state", CV_DEFAULT, 0);
396 Vn_state(vnp) = VN_STATE_INVALID;
398 #else /* !AFS_DEMAND_ATTACH_FS */
399 Lock_Init(&vnp->lock);
400 #endif /* !AFS_DEMAND_ATTACH_FS */
401 vnp->changed_oldTime = 0;
402 vnp->changed_newTime = 0;
403 Vn_volume(vnp) = NULL;
404 Vn_cacheCheck(vnp) = 0;
405 vnp->delete = Vn_id(vnp) = 0;
406 #ifdef AFS_PTHREAD_ENV
407 vnp->writer = (pthread_t) 0;
408 #else /* AFS_PTHREAD_ENV */
409 vnp->writer = (PROCESS) 0;
410 #endif /* AFS_PTHREAD_ENV */
414 if (vcp->lruHead == NULL)
415 vcp->lruHead = vnp->lruNext = vnp->lruPrev = vnp;
417 vnp->lruNext = vcp->lruHead;
418 vnp->lruPrev = vcp->lruHead->lruPrev;
419 vcp->lruHead->lruPrev = vnp;
420 vnp->lruPrev->lruNext = vnp;
423 va += vcp->residentSize;
430 * allocate an unused vnode from the lru chain.
432 * @param[in] vcp vnode class info object pointer
433 * @param[in] vp volume pointer
434 * @param[in] vnodeNumber new vnode number that the vnode will be used for
436 * @pre VOL_LOCK is held
438 * @post vnode object is removed from lru
439 * vnode is disassociated with its old volume, and associated with its
441 * vnode is removed from its old vnode hash table, and for DAFS, it is
442 * added to its new hash table
443 * state is set to VN_STATE_INVALID.
444 * inode handle is released.
445 * a reservation is held on the vnode object
447 * @note we traverse backwards along the lru circlist. It shouldn't
448 * be necessary to specify that nUsers == 0 since if it is in the list,
449 * nUsers should be 0. Things shouldn't be in lruq unless no one is
452 * @warning DAFS: VOL_LOCK is dropped while doing inode handle release
454 * @warning for non-DAFS, the vnode is _not_ hashed on the vnode hash table;
455 * non-DAFS must hash the vnode itself after loading data
457 * @return vnode object pointer
460 VGetFreeVnode_r(struct VnodeClassInfo * vcp, struct Volume *vp,
465 vnp = vcp->lruHead->lruPrev;
466 #ifdef AFS_DEMAND_ATTACH_FS
467 if (Vn_refcount(vnp) != 0 || VnIsExclusiveState(Vn_state(vnp)) ||
468 Vn_readers(vnp) != 0)
469 Abort("VGetFreeVnode_r: in-use vnode in lruq");
471 if (Vn_refcount(vnp) != 0 || CheckLock(&vnp->lock))
472 Abort("VGetFreeVnode_r: locked vnode in lruq");
474 VNLog(1, 2, Vn_id(vnp), (intptr_t)vnp, 0, 0);
477 * it's going to be overwritten soon enough.
478 * remove from LRU, delete hash entry, and
479 * disassociate from old parent volume before
480 * we have a chance to drop the vol glock
482 DeleteFromVnLRU(vcp, vnp);
483 DeleteFromVnHash(vnp);
484 if (Vn_volume(vnp)) {
485 DeleteFromVVnList(vnp);
488 /* we must re-hash the vnp _before_ we drop the glock again; otherwise,
489 * someone else might try to grab the same vnode id, and we'll both alloc
490 * a vnode object for the same vn id, bypassing vnode locking */
491 Vn_id(vnp) = vnodeNumber;
492 VnCreateReservation_r(vnp);
493 AddToVVnList(vp, vnp);
494 #ifdef AFS_DEMAND_ATTACH_FS
498 /* drop the file descriptor */
500 #ifdef AFS_DEMAND_ATTACH_FS
501 VnChangeState_r(vnp, VN_STATE_RELEASING);
504 /* release is, potentially, a highly latent operation due to a couple
506 * - ihandle package lock contention
507 * - closing file descriptor(s) associated with ih
509 * Hance, we perform outside of the volume package lock in order to
510 * reduce the probability of contention.
512 IH_RELEASE(vnp->handle);
513 #ifdef AFS_DEMAND_ATTACH_FS
518 #ifdef AFS_DEMAND_ATTACH_FS
519 VnChangeState_r(vnp, VN_STATE_INVALID);
527 * lookup a vnode in the vnode cache hash table.
529 * @param[in] vp pointer to volume object
530 * @param[in] vnodeId vnode id
534 * @post matching vnode object or NULL is returned
536 * @return vnode object pointer
537 * @retval NULL no matching vnode object was found in the cache
539 * @internal vnode package internal use only
541 * @note this symbol is exported strictly for fssync debug protocol use
544 VLookupVnode(Volume * vp, VnodeId vnodeId)
547 unsigned int newHash;
549 newHash = VNODE_HASH(vp, vnodeId);
550 for (vnp = VnodeHashTable[newHash];
552 ((Vn_id(vnp) != vnodeId) ||
553 (Vn_volume(vnp) != vp) ||
554 (vp->cacheCheck != Vn_cacheCheck(vnp))));
555 vnp = vnp->hashNext);
562 VAllocVnode(Error * ec, Volume * vp, VnodeType type, VnodeId in_vnode, Unique in_unique)
566 retVal = VAllocVnode_r(ec, vp, type, in_vnode, in_unique);
572 * allocate a new vnode.
574 * @param[out] ec error code return
575 * @param[in] vp volume object pointer
576 * @param[in] type desired vnode type
577 * @param[in] type desired vnode ID (optional)
578 * @param[in] type desired vnode Unique (optional)
580 * @return vnode object pointer
582 * @pre VOL_LOCK held;
583 * heavyweight ref held on vp
585 * @post vnode allocated and returned
588 VAllocVnode_r(Error * ec, Volume * vp, VnodeType type, VnodeId in_vnode, Unique in_unique)
593 struct VnodeClassInfo *vcp;
596 struct vnodeIndex *index;
599 #ifdef AFS_DEMAND_ATTACH_FS
600 VolState vol_state_save;
605 #ifdef AFS_DEMAND_ATTACH_FS
607 * once a volume has entered an error state, don't permit
608 * further operations to proceed
609 * -- tkeiser 11/21/2007
611 VWaitExclusiveState_r(vp);
612 if (VIsErrorState(V_attachState(vp))) {
613 /* XXX is VSALVAGING acceptable here? */
619 if (programType == fileServer && !V_inUse(vp)) {
620 if (vp->specialStatus) {
621 *ec = vp->specialStatus;
627 class = vnodeTypeToClass(type);
628 vcp = &VnodeClassInfo[class];
630 if (!VolumeWriteable(vp)) {
631 *ec = (bit32) VREADONLY;
635 if (vp->nextVnodeUnique > V_uniquifier(vp)) {
636 VUpdateVolume_r(ec, vp, 0);
641 if (programType == fileServer) {
642 VAddToVolumeUpdateList_r(ec, vp);
648 * If in_vnode and in_unique are specified, we are asked to
649 * allocate a specifc vnode slot. Used by RW replication to
650 * keep vnode IDs consistent with the master.
654 unique = vp->nextVnodeUnique++;
656 unique = vp->nextVnodeUnique++;
658 if (vp->nextVnodeUnique > V_uniquifier(vp)) {
659 VUpdateVolume_r(ec, vp, 0);
664 /* Find a slot in the bit map */
665 bitNumber = VAllocBitmapEntry_r(ec, vp, &vp->vnodeIndex[class],
666 VOL_ALLOC_BITMAP_WAIT);
670 vnodeNumber = bitNumberToVnodeNumber(bitNumber, class);
672 index = &vp->vnodeIndex[class];
677 /* Catch us up to where the master is */
678 if (in_unique > vp->nextVnodeUnique)
679 vp->nextVnodeUnique = in_unique+1;
681 if (vp->nextVnodeUnique > V_uniquifier(vp)) {
682 VUpdateVolume_r(ec, vp, 0);
688 bitNumber = vnodeIdToBitNumber(in_vnode);
689 offset = bitNumber >> 3;
691 /* Mark vnode in use. Grow bitmap if needed. */
692 if ((offset >= index->bitmapSize)
693 || ((*(index->bitmap + offset) & (1 << (bitNumber & 0x7))) == 0))
695 /* Should not happen */
696 if (*(index->bitmap + offset) & (1 << (bitNumber & 0x7))) {
701 *(index->bitmap + offset) |= (1 << (bitNumber & 0x7));
702 vnodeNumber = in_vnode;
707 * at this point we should be assured that V_attachState(vp) is non-exclusive
711 VNLog(2, 1, vnodeNumber, 0, 0, 0);
712 /* Prepare to move it to the new hash chain */
713 vnp = VLookupVnode(vp, vnodeNumber);
715 /* slot already exists. May even not be in lruq (consider store file locking a file being deleted)
716 * so we may have to wait for it below */
717 VNLog(3, 2, vnodeNumber, (intptr_t)vnp, 0, 0);
719 VnCreateReservation_r(vnp);
720 if (Vn_refcount(vnp) == 1) {
721 /* we're the only user */
722 /* This won't block */
723 VnLock(vnp, WRITE_LOCK, VOL_LOCK_HELD, WILL_NOT_DEADLOCK);
725 #ifdef AFS_DEMAND_ATTACH_FS
728 * vnode was cached, wait for any existing exclusive ops to finish.
729 * once we have reacquired the lock, re-verify volume state.
731 * note: any vnode error state is related to the old vnode; disregard.
733 VnWaitQuiescent_r(vnp);
734 if (VIsErrorState(V_attachState(vp))) {
735 VnUnlock(vnp, WRITE_LOCK);
736 VnCancelReservation_r(vnp);
742 /* other users present; follow locking hierarchy */
743 VnLock(vnp, WRITE_LOCK, VOL_LOCK_HELD, MIGHT_DEADLOCK);
746 * verify state of the world hasn't changed
748 * (technically, this should never happen because cachecheck
749 * is only updated during a volume attach, which should not
750 * happen when refs are held)
752 if (Vn_volume(vnp)->cacheCheck != Vn_cacheCheck(vnp)) {
753 VnUnlock(vnp, WRITE_LOCK);
754 VnCancelReservation_r(vnp);
759 /* sanity check: vnode should be blank if it was deleted. If it's
760 * not blank, it is still in use somewhere; but the bitmap told us
761 * this vnode number was free, so something is wrong. */
762 if (vnp->disk.type != vNull) {
764 Log("VAllocVnode: addled bitmap or vnode object! (vol %" AFS_VOLID_FMT ", "
765 "vnode %p, number %ld, type %ld)\n", afs_printable_VolumeId_lu(vp->hashid), vnp,
766 (long)Vn_id(vnp), (long)vnp->disk.type);
768 VFreeBitMapEntry_r(&tmp, vp, &vp->vnodeIndex[class], bitNumber,
769 VOL_FREE_BITMAP_WAIT);
770 VInvalidateVnode_r(vnp);
771 VnUnlock(vnp, WRITE_LOCK);
772 VnCancelReservation_r(vnp);
773 #ifdef AFS_DEMAND_ATTACH_FS
774 VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0);
776 VForceOffline_r(vp, 0);
782 /* no such vnode in the cache */
784 vnp = VGetFreeVnode_r(vcp, vp, vnodeNumber);
786 /* This will never block (guaranteed by check in VGetFreeVnode_r() */
787 VnLock(vnp, WRITE_LOCK, VOL_LOCK_HELD, WILL_NOT_DEADLOCK);
789 #ifdef AFS_DEMAND_ATTACH_FS
790 VnChangeState_r(vnp, VN_STATE_ALLOC);
793 /* Sanity check: is this vnode really not in use? */
796 IHandle_t *ihP = vp->vnodeIndex[class].handle;
798 afs_foff_t off = vnodeIndexOffset(vcp, vnodeNumber);
801 /* XXX we have a potential race here if two threads
802 * allocate new vnodes at the same time, and they
803 * both decide it's time to extend the index
806 #ifdef AFS_DEMAND_ATTACH_FS
808 * this race has been eliminated for the DAFS case
809 * using exclusive state VOL_STATE_VNODE_ALLOC
811 * if this becomes a bottleneck, there are ways to
812 * improve parallelism for this code path
813 * -- tkeiser 11/28/2007
815 VCreateReservation_r(vp);
816 VWaitExclusiveState_r(vp);
817 vol_state_save = VChangeState_r(vp, VOL_STATE_VNODE_ALLOC);
823 Log("VAllocVnode: can't open index file!\n");
825 goto error_encountered;
827 if ((size = FDH_SIZE(fdP)) < 0) {
828 Log("VAllocVnode: can't stat index file!\n");
830 goto error_encountered;
832 if (off + vcp->diskSize <= size) {
833 if (FDH_PREAD(fdP, &vnp->disk, vcp->diskSize, off) != vcp->diskSize) {
834 Log("VAllocVnode: can't read index file!\n");
836 goto error_encountered;
838 if (vnp->disk.type != vNull) {
839 Log("VAllocVnode: addled bitmap or index!\n");
841 goto error_encountered;
844 /* growing file - grow in a reasonable increment */
845 char *buf = malloc(16 * 1024);
847 Log("VAllocVnode: can't grow vnode index: out of memory\n");
849 goto error_encountered;
851 memset(buf, 0, 16 * 1024);
852 if ((FDH_PWRITE(fdP, buf, 16 * 1024, off)) != 16 * 1024) {
853 Log("VAllocVnode: can't grow vnode index: write failed\n");
856 goto error_encountered;
863 #ifdef AFS_DEMAND_ATTACH_FS
864 VChangeState_r(vp, vol_state_save);
865 VCancelReservation_r(vp);
872 * close the file handle
874 * invalidate the vnode
875 * free up the bitmap entry (although salvager should take care of it)
877 * drop vnode lock and refs
882 VFreeBitMapEntry_r(&tmp, vp, &vp->vnodeIndex[class], bitNumber, 0 /*flags*/);
883 VInvalidateVnode_r(vnp);
884 VnUnlock(vnp, WRITE_LOCK);
885 VnCancelReservation_r(vnp);
886 #ifdef AFS_DEMAND_ATTACH_FS
887 VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0);
888 VCancelReservation_r(vp);
890 VForceOffline_r(vp, 0);
895 VNLog(4, 2, vnodeNumber, (intptr_t)vnp, 0, 0);
896 #ifndef AFS_DEMAND_ATTACH_FS
901 VNLog(5, 1, (intptr_t)vnp, 0, 0, 0);
902 memset(&vnp->disk, 0, sizeof(vnp->disk));
903 vnp->changed_newTime = 0; /* set this bit when vnode is updated */
904 vnp->changed_oldTime = 0; /* set this on CopyOnWrite. */
906 vnp->disk.vnodeMagic = vcp->magic;
907 vnp->disk.type = type;
908 vnp->disk.uniquifier = unique;
912 #ifdef AFS_DEMAND_ATTACH_FS
913 VnChangeState_r(vnp, VN_STATE_EXCLUSIVE);
919 * load a vnode from disk.
921 * @param[out] ec client error code return
922 * @param[in] vp volume object pointer
923 * @param[in] vnp vnode object pointer
924 * @param[in] vcp vnode class info object pointer
925 * @param[in] class vnode class enumeration
927 * @pre vnode is registered in appropriate data structures;
928 * caller holds a ref on vnode; VOL_LOCK is held
930 * @post vnode data is loaded from disk.
931 * vnode state is set to VN_STATE_ONLINE.
932 * on failure, vnode is invalidated.
934 * @internal vnode package internal use only
937 VnLoad(Error * ec, Volume * vp, Vnode * vnp,
938 struct VnodeClassInfo * vcp, VnodeClass class)
940 /* vnode not cached */
944 IHandle_t *ihP = vp->vnodeIndex[class].handle;
951 #ifdef AFS_DEMAND_ATTACH_FS
952 VnChangeState_r(vnp, VN_STATE_LOAD);
955 /* This will never block */
956 VnLock(vnp, WRITE_LOCK, VOL_LOCK_HELD, WILL_NOT_DEADLOCK);
961 Log("VnLoad: can't open index dev=%u, i=%s\n", vp->device,
962 PrintInode(stmp, vp->vnodeIndex[class].handle->ih_ino));
964 goto error_encountered_nolock;
965 } else if ((nBytes = FDH_PREAD(fdP, (char *)&vnp->disk, vcp->diskSize, vnodeIndexOffset(vcp, Vn_id(vnp))))
967 /* Don't take volume off line if the inumber is out of range
968 * or the inode table is full. */
969 if (nBytes == BAD_IGET) {
970 Log("VnLoad: bad inumber %s\n",
971 PrintInode(stmp, vp->vnodeIndex[class].handle->ih_ino));
974 } else if (nBytes == -1 && errno == EIO) {
975 /* disk error; salvage */
976 Log("VnLoad: Couldn't read vnode %u, volume %" AFS_VOLID_FMT " (%s); volume needs salvage\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
978 /* vnode is not allocated */
980 Log("VnLoad: Couldn't read vnode %u, volume %" AFS_VOLID_FMT " (%s); read %d bytes, errno %d\n",
981 Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp), (int)nBytes, errno);
985 goto error_encountered_nolock;
990 /* Quick check to see that the data is reasonable */
991 if (vnp->disk.vnodeMagic != vcp->magic || vnp->disk.type == vNull) {
992 if (vnp->disk.type == vNull) {
996 struct vnodeIndex *index = &vp->vnodeIndex[class];
997 unsigned int bitNumber = vnodeIdToBitNumber(Vn_id(vnp));
998 unsigned int offset = bitNumber >> 3;
1000 #ifdef AFS_DEMAND_ATTACH_FS
1001 /* Make sure the volume bitmap isn't getting updated while we are
1003 VWaitExclusiveState_r(vp);
1006 /* Test to see if vnode number is valid. */
1007 if ((offset >= index->bitmapSize)
1008 || ((*(index->bitmap + offset) & (1 << (bitNumber & 0x7)))
1010 Log("VnLoad: Request for unallocated vnode %u, volume %" AFS_VOLID_FMT " (%s) denied.\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
1014 Log("VnLoad: Bad magic number, vnode %u, volume %" AFS_VOLID_FMT " (%s); volume needs salvage\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
1017 goto error_encountered;
1020 IH_INIT(vnp->handle, V_device(vp), afs_printable_VolumeId_lu(V_parentId(vp)), VN_GET_INO(vnp));
1021 VnUnlock(vnp, WRITE_LOCK);
1022 #ifdef AFS_DEMAND_ATTACH_FS
1023 VnChangeState_r(vnp, VN_STATE_ONLINE);
1028 error_encountered_nolock:
1030 FDH_REALLYCLOSE(fdP);
1036 #ifdef AFS_DEMAND_ATTACH_FS
1037 VRequestSalvage_r(&error, vp, SALVSYNC_ERROR, 0);
1039 VForceOffline_r(vp, 0);
1046 VInvalidateVnode_r(vnp);
1047 VnUnlock(vnp, WRITE_LOCK);
1051 * store a vnode to disk.
1053 * @param[out] ec error code output
1054 * @param[in] vp volume object pointer
1055 * @param[in] vnp vnode object pointer
1056 * @param[in] vcp vnode class info object pointer
1057 * @param[in] class vnode class enumeration
1059 * @pre VOL_LOCK held.
1060 * caller holds refs to volume and vnode.
1061 * DAFS: caller is responsible for performing state sanity checks.
1063 * @post vnode state is stored to disk.
1065 * @internal vnode package internal use only
1068 VnStore(Error * ec, Volume * vp, Vnode * vnp,
1069 struct VnodeClassInfo * vcp, VnodeClass class)
1073 IHandle_t *ihP = vp->vnodeIndex[class].handle;
1076 #ifdef AFS_DEMAND_ATTACH_FS
1077 VnState vn_state_save;
1082 #ifdef AFS_DEMAND_ATTACH_FS
1083 vn_state_save = VnChangeState_r(vnp, VN_STATE_STORE);
1086 offset = vnodeIndexOffset(vcp, Vn_id(vnp));
1090 Log("VnStore: can't open index file!\n");
1091 goto error_encountered;
1093 nBytes = FDH_PWRITE(fdP, &vnp->disk, vcp->diskSize, offset);
1094 if (nBytes != vcp->diskSize) {
1095 /* Don't force volume offline if the inumber is out of
1096 * range or the inode table is full.
1098 FDH_REALLYCLOSE(fdP);
1099 if (nBytes == BAD_IGET) {
1100 Log("VnStore: bad inumber %s\n",
1102 vp->vnodeIndex[class].handle->ih_ino));
1105 #ifdef AFS_DEMAND_ATTACH_FS
1106 VnChangeState_r(vnp, VN_STATE_ERROR);
1109 Log("VnStore: Couldn't write vnode %u, volume %" AFS_VOLID_FMT " (%s) (error %d)\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(Vn_volume(vnp))), V_name(Vn_volume(vnp)), (int)nBytes);
1110 #ifdef AFS_DEMAND_ATTACH_FS
1111 goto error_encountered;
1114 VForceOffline_r(vp, 0);
1124 #ifdef AFS_DEMAND_ATTACH_FS
1125 VnChangeState_r(vnp, vn_state_save);
1130 #ifdef AFS_DEMAND_ATTACH_FS
1131 /* XXX instead of dumping core, let's try to request a salvage
1132 * and just fail the putvnode */
1136 VnChangeState_r(vnp, VN_STATE_ERROR);
1137 VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0);
1144 * get a handle to a vnode object.
1146 * @param[out] ec error code
1147 * @param[in] vp volume object
1148 * @param[in] vnodeNumber vnode id
1149 * @param[in] locktype type of lock to acquire
1151 * @return vnode object pointer
1156 VGetVnode(Error * ec, Volume * vp, VnodeId vnodeNumber, int locktype)
1157 { /* READ_LOCK or WRITE_LOCK, as defined in lock.h */
1160 retVal = VGetVnode_r(ec, vp, vnodeNumber, locktype);
1166 * get a handle to a vnode object.
1168 * @param[out] ec error code
1169 * @param[in] vp volume object
1170 * @param[in] vnodeNumber vnode id
1171 * @param[in] locktype type of lock to acquire
1173 * @return vnode object pointer
1175 * @internal vnode package internal use only
1177 * @pre VOL_LOCK held.
1178 * heavyweight ref held on volume object.
1181 VGetVnode_r(Error * ec, Volume * vp, VnodeId vnodeNumber, int locktype)
1182 { /* READ_LOCK or WRITE_LOCK, as defined in lock.h */
1185 struct VnodeClassInfo *vcp;
1189 if (vnodeNumber == 0) {
1194 VNLog(100, 1, vnodeNumber, 0, 0, 0);
1196 #ifdef AFS_DEMAND_ATTACH_FS
1198 * once a volume has entered an error state, don't permit
1199 * further operations to proceed
1200 * -- tkeiser 11/21/2007
1202 VWaitExclusiveState_r(vp);
1203 if (VIsErrorState(V_attachState(vp))) {
1204 /* XXX is VSALVAGING acceptable here? */
1210 if (programType == fileServer && !V_inUse(vp)) {
1211 *ec = (vp->specialStatus ? vp->specialStatus : VOFFLINE);
1213 /* If the volume is VBUSY (being cloned or dumped) and this is
1214 * a READ operation, then don't fail.
1216 if ((*ec != VBUSY) || (locktype != READ_LOCK)) {
1221 class = vnodeIdToClass(vnodeNumber);
1222 vcp = &VnodeClassInfo[class];
1223 if (locktype == WRITE_LOCK && !VolumeWriteable(vp)) {
1224 *ec = (bit32) VREADONLY;
1228 if (locktype == WRITE_LOCK && programType == fileServer) {
1229 VAddToVolumeUpdateList_r(ec, vp);
1237 /* See whether the vnode is in the cache. */
1238 vnp = VLookupVnode(vp, vnodeNumber);
1240 /* vnode is in cache */
1242 VNLog(101, 2, vnodeNumber, (intptr_t)vnp, 0, 0);
1243 VnCreateReservation_r(vnp);
1245 #ifdef AFS_DEMAND_ATTACH_FS
1247 * this is the one DAFS case where we may run into contention.
1248 * here's the basic control flow:
1250 * if locktype is READ_LOCK:
1251 * wait until vnode is not exclusive
1252 * set to VN_STATE_READ
1253 * increment read count
1256 * wait until vnode is quiescent
1257 * set to VN_STATE_EXCLUSIVE
1260 if (locktype == READ_LOCK) {
1261 VnWaitExclusiveState_r(vnp);
1263 VnWaitQuiescent_r(vnp);
1266 if (VnIsErrorState(Vn_state(vnp))) {
1267 VnCancelReservation_r(vnp);
1271 #endif /* AFS_DEMAND_ATTACH_FS */
1273 /* vnode not cached */
1275 /* Not in cache; tentatively grab most distantly used one from the LRU
1278 vnp = VGetFreeVnode_r(vcp, vp, vnodeNumber);
1281 vnp->changed_newTime = vnp->changed_oldTime = 0;
1285 * XXX for non-DAFS, there is a serious
1286 * race condition here:
1288 * two threads can race to load a vnode. the net
1289 * result is two struct Vnodes can be allocated
1290 * and hashed, which point to the same underlying
1291 * disk data store. conflicting vnode locks can
1292 * thus be held concurrently.
1294 * for non-DAFS to be safe, VOL_LOCK really shouldn't
1295 * be dropped in VnLoad. Of course, this would likely
1296 * lead to an unacceptable slow-down.
1299 VnLoad(ec, vp, vnp, vcp, class);
1301 VnCancelReservation_r(vnp);
1304 #ifndef AFS_DEMAND_ATTACH_FS
1309 * there is no possibility for contention. we "own" this vnode.
1315 * it is imperative that nothing drop vol lock between here
1316 * and the VnBeginRead/VnChangeState stanza below
1319 VnLock(vnp, locktype, VOL_LOCK_HELD, MIGHT_DEADLOCK);
1321 /* Check that the vnode hasn't been removed while we were obtaining
1323 VNLog(102, 2, vnodeNumber, (intptr_t) vnp, 0, 0);
1324 if ((vnp->disk.type == vNull) || (Vn_cacheCheck(vnp) == 0)) {
1325 VnUnlock(vnp, locktype);
1326 VnCancelReservation_r(vnp);
1328 /* vnode is labelled correctly by now, so we don't have to invalidate it */
1332 #ifdef AFS_DEMAND_ATTACH_FS
1333 if (locktype == READ_LOCK) {
1336 VnChangeState_r(vnp, VN_STATE_EXCLUSIVE);
1340 if (programType == fileServer)
1341 VBumpVolumeUsage_r(Vn_volume(vnp)); /* Hack; don't know where it should be
1342 * called from. Maybe VGetVolume */
1347 int TrustVnodeCacheEntry = 1;
1348 /* This variable is bogus--when it's set to 0, the hash chains fill
1349 up with multiple versions of the same vnode. Should fix this!! */
1351 VPutVnode(Error * ec, Vnode * vnp)
1354 VPutVnode_r(ec, vnp);
1359 * put back a handle to a vnode object.
1361 * @param[out] ec client error code
1362 * @param[in] vnp vnode object pointer
1364 * @pre VOL_LOCK held.
1365 * ref held on vnode.
1367 * @post ref dropped on vnode.
1368 * if vnode was modified or deleted, it is written out to disk
1369 * (assuming a write lock was held).
1371 * @internal volume package internal use only
1374 VPutVnode_r(Error * ec, Vnode * vnp)
1378 struct VnodeClassInfo *vcp;
1381 opr_Assert(Vn_refcount(vnp) != 0);
1382 class = vnodeIdToClass(Vn_id(vnp));
1383 vcp = &VnodeClassInfo[class];
1384 opr_Assert(vnp->disk.vnodeMagic == vcp->magic);
1385 VNLog(200, 2, Vn_id(vnp), (intptr_t) vnp, 0, 0);
1387 #ifdef AFS_DEMAND_ATTACH_FS
1388 writeLocked = (Vn_state(vnp) == VN_STATE_EXCLUSIVE);
1390 writeLocked = WriteLocked(&vnp->lock);
1395 #ifdef AFS_PTHREAD_ENV
1396 pthread_t thisProcess = pthread_self();
1397 #else /* AFS_PTHREAD_ENV */
1398 PROCESS thisProcess;
1399 LWP_CurrentProcess(&thisProcess);
1400 #endif /* AFS_PTHREAD_ENV */
1401 VNLog(201, 2, (intptr_t) vnp,
1402 ((vnp->changed_newTime) << 1) | ((vnp->
1403 changed_oldTime) << 1) | vnp->
1405 if (thisProcess != vnp->writer)
1406 Abort("VPutVnode: Vnode at %"AFS_PTR_FMT" locked by another process!\n",
1410 if (vnp->changed_oldTime || vnp->changed_newTime || vnp->delete) {
1411 Volume *vp = Vn_volume(vnp);
1412 afs_uint32 now = FT_ApproxTime();
1413 opr_Assert(Vn_cacheCheck(vnp) == vp->cacheCheck);
1416 /* No longer any directory entries for this vnode. Free the Vnode */
1417 memset(&vnp->disk, 0, sizeof(vnp->disk));
1418 /* delete flag turned off further down */
1419 VNLog(202, 2, Vn_id(vnp), (intptr_t) vnp, 0, 0);
1420 } else if (vnp->changed_newTime) {
1421 vnp->disk.serverModifyTime = now;
1423 if (vnp->changed_newTime)
1425 V_updateDate(vp) = vp->updateTime = now;
1426 if(V_volUpCounter(vp)< UINT_MAX)
1427 V_volUpCounter(vp)++;
1430 /* The vnode has been changed. Write it out to disk */
1432 #ifdef AFS_DEMAND_ATTACH_FS
1433 VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0);
1435 opr_Assert(V_needsSalvaged(vp));
1439 VnStore(ec, vp, vnp, vcp, class);
1441 /* If the vnode is to be deleted, and we wrote the vnode out,
1442 * free its bitmap entry. Do after the vnode is written so we
1443 * don't allocate from bitmap before the vnode is written
1444 * (doing so could cause a "addled bitmap" message).
1446 if (vnp->delete && !*ec) {
1447 if (V_filecount(Vn_volume(vnp))-- < 1)
1448 V_filecount(Vn_volume(vnp)) = 0;
1449 VFreeBitMapEntry_r(ec, vp, &vp->vnodeIndex[class],
1450 vnodeIdToBitNumber(Vn_id(vnp)),
1451 VOL_FREE_BITMAP_WAIT);
1455 vnp->changed_newTime = vnp->changed_oldTime = 0;
1457 #ifdef AFS_DEMAND_ATTACH_FS
1458 VnChangeState_r(vnp, VN_STATE_ONLINE);
1460 } else { /* Not write locked */
1461 if (vnp->changed_newTime || vnp->changed_oldTime || vnp->delete)
1463 ("VPutVnode: Change or delete flag for vnode "
1464 "%"AFS_PTR_FMT" is set but vnode is not write locked!\n",
1466 #ifdef AFS_DEMAND_ATTACH_FS
1471 /* Do not look at disk portion of vnode after this point; it may
1472 * have been deleted above */
1474 VnUnlock(vnp, ((writeLocked) ? WRITE_LOCK : READ_LOCK));
1475 VnCancelReservation_r(vnp);
1479 * Make an attempt to convert a vnode lock from write to read.
1480 * Do nothing if the vnode isn't write locked or the vnode has
1484 VVnodeWriteToRead(Error * ec, Vnode * vnp)
1488 retVal = VVnodeWriteToRead_r(ec, vnp);
1494 * convert vnode handle from mutually exclusive to shared access.
1496 * @param[out] ec client error code
1497 * @param[in] vnp vnode object pointer
1499 * @return unspecified use (see out argument 'ec' for error code return)
1501 * @pre VOL_LOCK held.
1502 * ref held on vnode.
1503 * write lock held on vnode.
1505 * @post read lock held on vnode.
1506 * if vnode was modified, it has been written to disk.
1508 * @internal volume package internal use only
1511 VVnodeWriteToRead_r(Error * ec, Vnode * vnp)
1515 struct VnodeClassInfo *vcp;
1516 #ifdef AFS_PTHREAD_ENV
1517 pthread_t thisProcess;
1518 #else /* AFS_PTHREAD_ENV */
1519 PROCESS thisProcess;
1520 #endif /* AFS_PTHREAD_ENV */
1523 opr_Assert(Vn_refcount(vnp) != 0);
1524 class = vnodeIdToClass(Vn_id(vnp));
1525 vcp = &VnodeClassInfo[class];
1526 opr_Assert(vnp->disk.vnodeMagic == vcp->magic);
1527 VNLog(300, 2, Vn_id(vnp), (intptr_t) vnp, 0, 0);
1529 #ifdef AFS_DEMAND_ATTACH_FS
1530 writeLocked = (Vn_state(vnp) == VN_STATE_EXCLUSIVE);
1532 writeLocked = WriteLocked(&vnp->lock);
1539 VNLog(301, 2, (intptr_t) vnp,
1540 ((vnp->changed_newTime) << 1) | ((vnp->
1541 changed_oldTime) << 1) | vnp->
1545 #ifdef AFS_PTHREAD_ENV
1546 thisProcess = pthread_self();
1547 #else /* AFS_PTHREAD_ENV */
1548 LWP_CurrentProcess(&thisProcess);
1549 #endif /* AFS_PTHREAD_ENV */
1550 if (thisProcess != vnp->writer)
1551 Abort("VPutVnode: Vnode at %"AFS_PTR_FMT
1552 " locked by another process!\n", vnp);
1557 if (vnp->changed_oldTime || vnp->changed_newTime) {
1558 Volume *vp = Vn_volume(vnp);
1559 afs_uint32 now = FT_ApproxTime();
1560 opr_Assert(Vn_cacheCheck(vnp) == vp->cacheCheck);
1561 if (vnp->changed_newTime)
1562 vnp->disk.serverModifyTime = now;
1563 if (vnp->changed_newTime)
1564 V_updateDate(vp) = vp->updateTime = now;
1566 /* The inode has been changed. Write it out to disk */
1568 #ifdef AFS_DEMAND_ATTACH_FS
1569 VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0);
1571 opr_Assert(V_needsSalvaged(vp));
1575 VnStore(ec, vp, vnp, vcp, class);
1578 vnp->changed_newTime = vnp->changed_oldTime = 0;
1582 #ifdef AFS_DEMAND_ATTACH_FS
1583 VnChangeState_r(vnp, VN_STATE_ONLINE);
1586 ConvertWriteToReadLock(&vnp->lock);
1592 * initial size of ihandle pointer vector.
1594 * @see VInvalidateVnodesByVolume_r
1596 #define IH_VEC_BASE_SIZE 256
1599 * increment amount for growing ihandle pointer vector.
1601 * @see VInvalidateVnodesByVolume_r
1603 #define IH_VEC_INCREMENT 256
1606 * Compile list of ihandles to be released/reallyclosed at a later time.
1608 * @param[in] vp volume object pointer
1609 * @param[out] vec_out vector of ihandle pointers to be released/reallyclosed
1610 * @param[out] vec_len_out number of valid elements in ihandle vector
1612 * @pre - VOL_LOCK is held
1613 * - volume is in appropriate exclusive state (e.g. VOL_STATE_VNODE_CLOSE,
1614 * VOL_STATE_VNODE_RELEASE)
1616 * @post - all vnodes on VVn list are invalidated
1617 * - ih_vec is populated with all valid ihandles
1619 * @return operation status
1621 * @retval ENOMEM out of memory
1623 * @todo we should handle out of memory conditions more gracefully.
1625 * @internal vnode package internal use only
1628 VInvalidateVnodesByVolume_r(Volume * vp,
1629 IHandle_t *** vec_out,
1630 size_t * vec_len_out)
1634 size_t i = 0, vec_len;
1635 IHandle_t **ih_vec, **ih_vec_new;
1637 #ifdef AFS_DEMAND_ATTACH_FS
1639 #endif /* AFS_DEMAND_ATTACH_FS */
1641 vec_len = IH_VEC_BASE_SIZE;
1642 ih_vec = malloc(sizeof(IHandle_t *) * vec_len);
1643 #ifdef AFS_DEMAND_ATTACH_FS
1650 * Traverse the volume's vnode list. Pull all the ihandles out into a
1651 * thread-private array for later asynchronous processing.
1653 #ifdef AFS_DEMAND_ATTACH_FS
1656 for (queue_Scan(&vp->vnode_list, vnp, nvnp, Vnode)) {
1657 if (vnp->handle != NULL) {
1659 #ifdef AFS_DEMAND_ATTACH_FS
1662 vec_len += IH_VEC_INCREMENT;
1663 ih_vec_new = realloc(ih_vec, sizeof(IHandle_t *) * vec_len);
1664 #ifdef AFS_DEMAND_ATTACH_FS
1667 if (ih_vec_new == NULL) {
1671 ih_vec = ih_vec_new;
1672 #ifdef AFS_DEMAND_ATTACH_FS
1674 * Theoretically, the volume's VVn list should not change
1675 * because the volume is in an exclusive state. For the
1676 * sake of safety, we will restart the traversal from the
1677 * the beginning (which is not expensive because we're
1678 * deleting the items from the list as we go).
1680 goto restart_traversal;
1683 ih_vec[i++] = vnp->handle;
1686 DeleteFromVVnList(vnp);
1687 VInvalidateVnode_r(vnp);
1697 /* VCloseVnodeFiles - called when a volume is going off line. All open
1698 * files for vnodes in that volume are closed. This might be excessive,
1699 * since we may only be taking one volume of a volume group offline.
1702 VCloseVnodeFiles_r(Volume * vp)
1704 #ifdef AFS_DEMAND_ATTACH_FS
1705 VolState vol_state_save;
1707 IHandle_t ** ih_vec;
1710 #ifdef AFS_DEMAND_ATTACH_FS
1711 vol_state_save = VChangeState_r(vp, VOL_STATE_VNODE_CLOSE);
1712 #endif /* AFS_DEMAND_ATTACH_FS */
1714 /* XXX need better error handling here */
1715 opr_Verify(VInvalidateVnodesByVolume_r(vp, &ih_vec,
1720 * now we drop VOL_LOCK while we perform some potentially very
1721 * expensive operations in the background
1723 #ifdef AFS_DEMAND_ATTACH_FS
1727 for (i = 0; i < vec_len; i++) {
1728 IH_REALLYCLOSE(ih_vec[i]);
1729 IH_RELEASE(ih_vec[i]);
1734 #ifdef AFS_DEMAND_ATTACH_FS
1736 VChangeState_r(vp, vol_state_save);
1737 #endif /* AFS_DEMAND_ATTACH_FS */
1742 * shut down all vnode cache state for a given volume.
1744 * @param[in] vp volume object pointer
1746 * @pre VOL_LOCK is held
1748 * @post all file descriptors closed.
1749 * all inode handles released.
1750 * all vnode cache objects disassociated from volume.
1752 * @note for DAFS, these operations are performed outside the vol glock under
1753 * volume exclusive state VOL_STATE_VNODE_RELEASE. Please further note
1754 * that it would be a bug to acquire and release a volume reservation
1755 * during this exclusive operation. This is due to the fact that we are
1756 * generally called during the refcount 1->0 transition.
1758 * @todo we should handle failures in VInvalidateVnodesByVolume_r more
1761 * @see VInvalidateVnodesByVolume_r
1763 * @internal this routine is internal to the volume package
1766 VReleaseVnodeFiles_r(Volume * vp)
1768 #ifdef AFS_DEMAND_ATTACH_FS
1769 VolState vol_state_save;
1771 IHandle_t ** ih_vec;
1774 #ifdef AFS_DEMAND_ATTACH_FS
1775 vol_state_save = VChangeState_r(vp, VOL_STATE_VNODE_RELEASE);
1776 #endif /* AFS_DEMAND_ATTACH_FS */
1778 /* XXX need better error handling here */
1779 opr_Verify(VInvalidateVnodesByVolume_r(vp, &ih_vec,
1784 * now we drop VOL_LOCK while we perform some potentially very
1785 * expensive operations in the background
1787 #ifdef AFS_DEMAND_ATTACH_FS
1791 for (i = 0; i < vec_len; i++) {
1792 IH_RELEASE(ih_vec[i]);
1797 #ifdef AFS_DEMAND_ATTACH_FS
1799 VChangeState_r(vp, vol_state_save);
1800 #endif /* AFS_DEMAND_ATTACH_FS */