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
15 * afs_CheckVolumeNames
18 #include <afsconfig.h>
19 #include "afs/param.h"
23 #include "afs/sysincludes.h" /* Standard vendor system headers */
26 #if !defined(AFS_LINUX20_ENV)
29 #include <netinet/in.h>
32 #include "h/hashing.h"
34 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
35 #include <netinet/in_var.h>
36 #endif /* ! AFS_HPUX110_ENV */
37 #endif /* !defined(UKERNEL) */
39 #include "afsincludes.h" /* Afs-based standard headers */
40 #include "afs/afs_stats.h" /* afs statistics */
41 #include "afs/afs_dynroot.h"
43 #if defined(AFS_SUN5_ENV)
45 #include <inet/common.h>
46 #include <netinet/ip6.h>
50 /* In case we don't have the vl error table yet. */
51 #ifndef ERROR_TABLE_BASE_VL
52 #define ERROR_TABLE_BASE_VL (363520L)
53 #define VL_NOENT (363524L)
54 #endif /* vlserver error base define */
56 /* Exported variables */
57 afs_dcache_id_t volumeInode; /* Inode for VolumeItems file */
58 afs_rwlock_t afs_xvolume; /** allocation lock for volumes */
59 struct volume *afs_freeVolList;
60 struct volume *afs_volumes[NVOLS];
61 afs_int32 afs_volCounter = 1; /** for allocating volume indices */
62 afs_int32 fvTable[NFENTRIES];
64 /* Forward declarations */
65 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell,
66 int agood, struct vrequest *areq,
68 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
69 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
75 * Convert a volume name to a number;
76 * @param aname Volume name.
77 * @return return 0 if can't parse as a number.
85 AFS_STATCNT(afs_vtoi);
86 while ((tc = *aname++)) {
87 if (tc > '9' || tc < '0')
88 return 0; /* invalid name */
98 * All of the vol cache routines must be called with the afs_xvolume
99 * lock held in exclusive mode, since they use static variables.
100 * In addition, we don't want two people adding the same volume
104 static struct fvolume staticFVolume;
105 afs_int32 afs_FVIndex = -1;
108 * Initialize a newly gotten volume slot.
110 * \param tv volume slot to be initialized
111 * \param tf volume item data; null if none
112 * \param volid volume id for this volume slot
113 * \param cell cell for this volume slot
117 afs_InitVolSlot(struct volume *tv, struct fvolume *tf, afs_int32 volid,
120 AFS_STATCNT(afs_InitVolSlot);
121 memset(tv, 0, sizeof(struct volume));
122 tv->cell = tcell->cellNum;
123 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
126 tv->vtix = afs_FVIndex;
127 tv->mtpoint = tf->mtpoint;
128 tv->dotdot = tf->dotdot;
129 tv->rootVnode = tf->rootVnode;
130 tv->rootUnique = tf->rootUnique;
133 tv->rootVnode = tv->rootUnique = 0;
134 afs_GetDynrootMountFid(&tv->dotdot);
135 afs_GetDynrootMountFid(&tv->mtpoint);
136 tv->mtpoint.Fid.Vnode =
137 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
138 tv->mtpoint.Fid.Unique = volid;
143 * UFS specific version of afs_GetVolSlot
147 afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell)
149 struct volume *tv = NULL, **lv;
150 struct osi_file *tfile;
151 afs_int32 i = -1, code;
153 struct volume *bestVp, *oldLp = NULL, **bestLp = NULL;
154 char *oldname = NULL;
155 afs_int32 oldvtix = -2; /* Initialize to a value that doesn't occur */
156 struct fvolume *tf = NULL;
159 AFS_STATCNT(afs_UFSGetVolSlot);
160 if (!afs_freeVolList) {
162 bestTime = 0x7fffffff;
165 for (i = 0; i < NVOLS; i++) {
166 lv = &afs_volumes[i];
167 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
168 if (tv->refCount == 0) { /* is this one available? */
169 if (tv->accessTime < bestTime) { /* best one available? */
170 bestTime = tv->accessTime;
178 afs_warn("afs_UFSGetVolSlot: no vol slots available\n");
190 /* now write out volume structure to file */
192 tv->vtix = afs_volCounter++;
193 /* now put on hash chain */
194 i = FVHash(tv->cell, tv->volume);
195 staticFVolume.next = fvTable[i];
196 fvTable[i] = tv->vtix;
199 * Haul the guy in from disk so we don't overwrite hash table
202 if (afs_FVIndex != tv->vtix) {
203 tfile = osi_UFSOpen(&volumeInode);
205 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
206 &staticFVolume, sizeof(struct fvolume));
208 if (code != sizeof(struct fvolume)) {
209 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
213 afs_FVIndex = tv->vtix;
216 afs_FVIndex = tv->vtix;
217 staticFVolume.volume = tv->volume;
218 staticFVolume.cell = tv->cell;
219 staticFVolume.mtpoint = tv->mtpoint;
220 staticFVolume.dotdot = tv->dotdot;
221 staticFVolume.rootVnode = tv->rootVnode;
222 staticFVolume.rootUnique = tv->rootUnique;
223 tfile = osi_UFSOpen(&volumeInode);
225 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
226 &staticFVolume, sizeof(struct fvolume));
228 if (code != sizeof(struct fvolume)) {
229 afs_warn("afs_UFSGetVolSlot: error %d writing volumeinfo\n",
234 afs_osi_Free(oldname, strlen(oldname) + 1);
238 tv = afs_freeVolList;
239 afs_freeVolList = tv->next;
242 /* read volume item data from disk for the gotten slot */
243 for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) {
244 if (afs_FVIndex != j) {
245 tfile = osi_UFSOpen(&volumeInode);
247 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
248 &staticFVolume, sizeof(struct fvolume));
250 if (code != sizeof(struct fvolume)) {
251 afs_warn("afs_SetupVolume: error %d reading volumeinfo\n",
253 /* put tv back on the free list; the data in it is not valid */
254 tv->next = afs_freeVolList;
255 afs_freeVolList = tv;
256 /* staticFVolume contents are not valid */
262 if (j != 0) { /* volume items record 0 is not used */
264 if (tf->cell == tcell->cellNum && tf->volume == volid) {
270 afs_InitVolSlot(tv, tf, volid, tcell);
276 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
285 fvTable[i] = staticFVolume.next;
291 /* we messed with staticFVolume, so make sure someone else
292 * doesn't think it's fine to use */
296 } /*afs_UFSGetVolSlot */
300 * Get an available volume list slot. If the list does not exist,
301 * create one containing a single element.
305 afs_MemGetVolSlot(afs_int32 volid, struct cell *tcell)
309 AFS_STATCNT(afs_MemGetVolSlot);
310 if (!afs_freeVolList) {
311 struct volume *newVp;
313 newVp = afs_osi_Alloc(sizeof(struct volume));
314 osi_Assert(newVp != NULL);
317 afs_freeVolList = newVp;
319 tv = afs_freeVolList;
320 afs_freeVolList = tv->next;
322 afs_InitVolSlot(tv, NULL, volid, tcell);
325 } /*afs_MemGetVolSlot */
328 * Setup a volume slot for cell:volume.
330 * Find the volume slot for the cell:volume, otherwise get
331 * and initialize a new slot.
333 * \param volid volume id
337 static struct volume *
338 afs_SetupVolSlot(afs_int32 volid, struct cell *tcell)
343 AFS_STATCNT(afs_SetupVolSlot);
344 ObtainWriteLock(&afs_xvolume, 108);
346 for (tv = afs_volumes[i]; tv; tv = tv->next) {
347 if (tv->volume == volid && tv->cell == tcell->cellNum) {
352 tv = afs_GetVolSlot(volid, tcell);
354 ReleaseWriteLock(&afs_xvolume);
357 tv->next = afs_volumes[i]; /* thread into list */
361 tv->states &= ~VRecheck; /* just checked it */
362 tv->accessTime = osi_Time();
363 ReleaseWriteLock(&afs_xvolume);
368 * Reset volume information for all volume structs that
369 * point to a speicific server, skipping a given volume if provided.
372 * The server to reset volume info about
374 * The volume to skip resetting info about
377 afs_ResetVolumes(struct server *srvp, struct volume *tv)
382 /* Find any volumes residing on this server and flush their state */
383 for (j = 0; j < NVOLS; j++) {
384 for (vp = afs_volumes[j]; vp; vp = vp->next) {
385 for (k = 0; k < AFS_MAXHOSTS; k++) {
386 if (!srvp || (vp->serverHost[k] == srvp)) {
387 if (tv && tv != vp) {
388 vp->serverHost[k] = 0;
389 afs_ResetVolumeInfo(vp);
399 * Reset volume name to volume id mapping cache.
403 afs_CheckVolumeNames(int flags)
409 afs_int32 *volumeID, *cellID, vsize, nvols;
410 #ifdef AFS_DARWIN80_ENV
413 AFS_STATCNT(afs_CheckVolumeNames);
416 volumeID = cellID = NULL;
418 ObtainReadLock(&afs_xvolume);
419 if (flags & AFS_VOLCHECK_EXPIRED) {
421 * allocate space to hold the volumeIDs and cellIDs, only if
422 * we will be invalidating the mountpoints later on
424 for (i = 0; i < NVOLS; i++)
425 for (tv = afs_volumes[i]; tv; tv = tv->next)
428 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
429 cellID = (volumeID) ? volumeID + vsize : 0;
433 for (i = 0; i < NVOLS; i++) {
434 for (tv = afs_volumes[i]; tv; tv = tv->next) {
435 if (flags & AFS_VOLCHECK_EXPIRED) {
436 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
437 || (flags & AFS_VOLCHECK_FORCE)) {
438 afs_ResetVolumeInfo(tv); /* also resets status */
440 volumeID[nvols] = tv->volume;
441 cellID[nvols] = tv->cell;
448 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
449 for (j = 0; j < AFS_MAXHOSTS; j++)
450 tv->status[j] = not_busy;
455 ReleaseReadLock(&afs_xvolume);
458 /* next ensure all mt points are re-evaluated */
459 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
461 ObtainReadLock(&afs_xvcache);
462 for (i = 0; i < VCSIZE; i++) {
463 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
465 /* if the volume of "mvid" of the vcache entry is among the
466 * ones we found earlier, then we re-evaluate it. Also, if the
467 * force bit is set or we explicitly asked to reevaluate the
468 * mt-pts, we clean the cmvalid bit */
470 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
472 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
473 tvc->f.states &= ~CMValid;
475 /* If the volume that this file belongs to was reset earlier,
476 * then we should remove its callback.
477 * Again, if forced, always do it.
479 if ((tvc->f.states & CRO)
480 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
481 || (flags & AFS_VOLCHECK_FORCE))) {
483 if (tvc->f.states & CVInit) {
484 ReleaseReadLock(&afs_xvcache);
485 afs_osi_Sleep(&tvc->f.states);
488 #ifdef AFS_DARWIN80_ENV
489 if (tvc->f.states & CDeadVnode) {
490 ReleaseReadLock(&afs_xvcache);
491 afs_osi_Sleep(&tvc->f.states);
497 if (vnode_ref(tvp)) {
499 /* AFSTOV(tvc) may be NULL */
507 ReleaseReadLock(&afs_xvcache);
509 ObtainWriteLock(&afs_xcbhash, 485);
510 /* LOCKXXX: We aren't holding tvc write lock? */
511 afs_DequeueCallback(tvc);
512 tvc->f.states &= ~CStatd;
513 ReleaseWriteLock(&afs_xcbhash);
514 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
515 osi_dnlc_purgedp(tvc);
517 #ifdef AFS_DARWIN80_ENV
518 vnode_put(AFSTOV(tvc));
519 /* our tvc ptr is still good until now */
521 ObtainReadLock(&afs_xvcache);
523 ObtainReadLock(&afs_xvcache);
525 /* our tvc ptr is still good until now */
531 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
532 ReleaseReadLock(&afs_xvcache);
536 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
538 } /*afs_CheckVolumeNames */
542 * Check if volume is in the specified list.
543 * @param fid File FID.
544 * @param nvols Nomber of volumes???
545 * @param vID Array of volume IDs.
546 * @param cID Array of cache IDs.
547 * @return 1 - true, 0 - false.
550 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
555 /* if no arrays present, be conservative and return true */
556 if (nvols && (!vID || !cID))
559 for (i = 0; i < nvols; ++i) {
560 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
567 /* afs_PutVolume is now a macro in afs.h */
571 * Return volume struct if we have it cached and it's up-to-date.
572 * Environment: Must be called with afs_xvolume unlocked.
573 * @param afid Volume FID.
575 * @return Volume or NULL if no result.
578 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
586 i = VHash(afid->Fid.Volume);
587 ObtainWriteLock(&afs_xvolume, 106);
588 for (tv = afs_volumes[i]; tv; tv = tv->next) {
589 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
590 && (tv->states & VRecheck) == 0) {
595 ReleaseWriteLock(&afs_xvolume);
596 return tv; /* NULL if we didn't find it */
597 } /*afs_FindVolume */
602 * Note that areq may be null, in which case we don't bother to set any
603 * request status information.
604 * @param afid Volume FID.
605 * @param areq Request type.
606 * @param locktype Lock to be used.
607 * @return Volume or NULL if no result.
610 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
614 char *bp, tbuf[CVBS];
615 AFS_STATCNT(afs_GetVolume);
617 tv = afs_FindVolume(afid, locktype);
619 /* Do a dynroot check and add dynroot volume if found. */
620 if (afs_IsDynrootAnyFid(afid)) {
621 tv = afs_NewDynrootVolume(afid);
623 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
624 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
634 * @param volid Volume ID. If it's 0, get it from the name.
635 * @param aname Volume name.
636 * @param ve Volume entry.
637 * @param tcell The cell containing this volume.
639 * @param type Type of volume.
640 * @param areq Request.
641 * @return Volume or NULL if failure.
643 static struct volume *
644 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
645 afs_int32 agood, afs_int32 type, struct vrequest *areq)
648 struct vldbentry *ove = (struct vldbentry *)ve;
649 struct nvldbentry *nve = (struct nvldbentry *)ve;
650 struct uvldbentry *uve = (struct uvldbentry *)ve;
652 int whichType; /* which type of volume to look for */
657 /* special hint from file server to use vlserver */
659 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
661 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
666 /* figure out which one we're really interested in (a set is returned) */
667 volid = afs_vtoi(aname);
670 volid = uve->volumeId[whichType];
671 } else if (type == 1) {
672 volid = nve->volumeId[whichType];
674 volid = ove->volumeId[whichType];
676 } /* end of if (volid == 0) */
677 } /* end of if (!volid) */
679 tv = afs_SetupVolSlot(volid, tcell);
685 LockAndInstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
686 } else if (type == 1)
687 LockAndInstallNVolumeEntry(tv, nve, tcell->cellNum);
689 LockAndInstallVolumeEntry(tv, ove, tcell->cellNum);
692 tv->name = afs_osi_Alloc(strlen(aname) + 1);
693 osi_Assert(tv->name != NULL);
694 strcpy(tv->name, aname);
697 for (i = 0; i < NMAXNSERVERS; i++) {
698 tv->status[i] = not_busy;
700 ReleaseWriteLock(&tv->lock);
706 * Seek volume by it's name and attributes.
707 * If volume not found, try to add one.
708 * @param aname Volume name.
712 * @param locktype Type of lock to be used.
716 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
717 struct vrequest *areq, afs_int32 locktype)
722 AFS_STATCNT(afs_GetVolumeByName);
723 ObtainWriteLock(&afs_xvolume, 112);
724 for (i = 0; i < NVOLS; i++) {
725 for (tv = afs_volumes[i]; tv; tv = tv->next) {
726 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
727 && (tv->states & VRecheck) == 0) {
729 ReleaseWriteLock(&afs_xvolume);
735 ReleaseWriteLock(&afs_xvolume);
737 if (AFS_IS_DISCONNECTED)
740 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
745 * Init a new dynroot volume.
747 * @return Volume or NULL if not found.
749 static struct volume *
750 afs_NewDynrootVolume(struct VenusFid *fid)
754 struct vldbentry *tve;
755 char *bp, tbuf[CVBS];
757 tcell = afs_GetCell(fid->Cell, READ_LOCK);
760 tve = afs_osi_Alloc(sizeof(*tve));
761 osi_Assert(tve != NULL);
762 if (!(tcell->states & CHasVolRef))
763 tcell->states |= CHasVolRef;
765 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
766 memset(tve, 0, sizeof(*tve));
767 strcpy(tve->name, "local-dynroot");
768 tve->volumeId[ROVOL] = fid->Fid.Volume;
769 tve->flags = VLF_ROEXISTS;
771 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
772 afs_PutCell(tcell, READ_LOCK);
773 afs_osi_Free(tve, sizeof(*tve));
780 * @param aname Volume name.
781 * @param acell Cell id.
783 * @param areq Request type.
784 * @param locktype Type of lock to be used.
785 * @return Volume or NULL if failure.
787 static struct volume *
788 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
789 struct vrequest *areq, afs_int32 locktype)
791 afs_int32 code, type = 0;
792 struct volume *tv, *tv1;
793 struct vldbentry *tve;
794 struct nvldbentry *ntve;
795 struct uvldbentry *utve;
798 struct afs_conn *tconn;
799 struct vrequest treq;
800 struct rx_connection *rxconn;
802 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
805 tcell = afs_GetCell(acell, READ_LOCK);
810 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
815 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
816 ICL_TYPE_POINTER, aname);
817 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
818 tve = (struct vldbentry *)(tbuffer + 1024);
819 ntve = (struct nvldbentry *)tve;
820 utve = (struct uvldbentry *)tve;
821 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
824 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
825 &treq, SHARED_LOCK, 0, &rxconn);
827 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
830 code = VL_GetEntryByNameO(rxconn, aname, tve);
832 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
835 code = VL_GetEntryByNameN(rxconn, aname, ntve);
840 code = VL_GetEntryByNameU(rxconn, aname, utve);
842 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
843 if (code == RXGEN_OPCODE) {
846 code = VL_GetEntryByNameN(rxconn, aname, ntve);
848 if (code == RXGEN_OPCODE) {
850 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
852 code = VL_GetEntryByNameO(rxconn, aname, tve);
855 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
857 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
863 } while (afs_Analyze(tconn, rxconn, code, NULL, &treq, -1, /* no op code for this */
864 SHARED_LOCK, tcell));
867 /* If the client has yet to contact this cell and contact failed due
868 * to network errors, mark the VLDB servers as back up.
869 * That the client tried and failed can be determined from the
870 * fact that there was a downtime incident, but CHasVolRef is not set.
872 /* RT 48959 - unclear if this should really go */
874 if (areq->networkError && !(tcell->states & CHasVolRef)) {
878 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
879 if ((sp = tcell->cellHosts[i]) == NULL)
881 for (sap = sp->addr; sap; sap = sap->next_sa)
882 afs_MarkServerUpOrDown(sap, 0);
886 afs_CopyError(&treq, areq);
887 osi_FreeLargeSpace(tbuffer);
888 afs_PutCell(tcell, READ_LOCK);
892 * Check to see if this cell has not yet referenced a volume. If
893 * it hasn't, it's just about to change its status, and we need to mark
894 * this fact down. Note that it is remotely possible that afs_SetupVolume
895 * could fail and we would still not have a volume reference.
897 if (!(tcell->states & CHasVolRef)) {
898 tcell->states |= CHasVolRef;
899 afs_stats_cmperf.numCellsContacted++;
901 /*First time a volume in this cell has been referenced */
908 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, &treq);
909 if ((agood == 3) && tv && tv->backVol) {
911 * This means that very soon we'll ask for the BK volume so
912 * we'll prefetch it (well we did already.)
915 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, &treq);
920 if ((agood >= 2) && tv && tv->roVol) {
922 * This means that very soon we'll ask for the RO volume so
923 * we'll prefetch it (well we did already.)
925 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, &treq);
930 osi_FreeLargeSpace(tbuffer);
931 afs_PutCell(tcell, READ_LOCK);
934 } /*afs_NewVolumeByName */
939 * Call this with the volume structure locked; used for new-style vldb requests.
945 LockAndInstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
953 struct server *serverHost[AFS_MAXHOSTS];
955 AFS_STATCNT(InstallVolumeEntry);
957 memset(serverHost, 0, sizeof(serverHost));
959 /* Determine the type of volume we want */
960 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
962 } else if ((ve->flags & VLF_ROEXISTS)
963 && (av->volume == ve->volumeId[ROVOL])) {
966 } else if ((ve->flags & VLF_BACKEXISTS)
967 && (av->volume == ve->volumeId[BACKVOL])) {
968 /* backup always is on the same volume as parent */
970 types |= (VRO | VBackup);
972 mask = 0; /* Can't find volume in vldb entry */
975 cellp = afs_GetCell(acell, 0);
977 /* Step through the VLDB entry making sure each server listed is there */
978 for (i = 0, j = 0; i < ve->nServers; i++) {
979 if (((ve->serverFlags[i] & mask) == 0)
980 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
981 continue; /* wrong volume or don't use this volume */
984 temp = htonl(ve->serverNumber[i]);
985 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
986 (afsUUID *) 0, 0, av);
990 * The cell field could be 0 if the server entry was created
991 * first with the 'fs setserverprefs' call which doesn't set
992 * the cell field. Thus if the afs_GetServer call above
993 * follows later on it will find the server entry thus it will
994 * simply return without setting any fields, so we set the
995 * field ourselves below.
999 afs_PutServer(ts, WRITE_LOCK);
1003 ObtainWriteLock(&av->lock, 109);
1005 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1008 av->states |= types;
1010 /* fill in volume types */
1011 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1012 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1013 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1015 if (ve->flags & VLF_DFSFILESET)
1016 av->states |= VForeign;
1018 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1019 } /*InstallVolumeEntry */
1023 LockAndInstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
1031 struct server *serverHost[AFS_MAXHOSTS];
1033 AFS_STATCNT(InstallVolumeEntry);
1035 memset(serverHost, 0, sizeof(serverHost));
1037 /* Determine type of volume we want */
1038 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1040 } else if ((ve->flags & VLF_ROEXISTS)
1041 && (av->volume == ve->volumeId[ROVOL])) {
1044 } else if ((ve->flags & VLF_BACKEXISTS)
1045 && (av->volume == ve->volumeId[BACKVOL])) {
1046 /* backup always is on the same volume as parent */
1048 types |= (VRO | VBackup);
1050 mask = 0; /* Can't find volume in vldb entry */
1053 cellp = afs_GetCell(acell, 0);
1055 /* Step through the VLDB entry making sure each server listed is there */
1056 for (i = 0, j = 0; i < ve->nServers; i++) {
1057 if (((ve->serverFlags[i] & mask) == 0)
1058 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1059 continue; /* wrong volume or don't use this volume */
1062 temp = htonl(ve->serverNumber[i]);
1063 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1064 (afsUUID *) 0, 0, av);
1067 * The cell field could be 0 if the server entry was created
1068 * first with the 'fs setserverprefs' call which doesn't set
1069 * the cell field. Thus if the afs_GetServer call above
1070 * follows later on it will find the server entry thus it will
1071 * simply return without setting any fields, so we set the
1072 * field ourselves below.
1076 afs_PutServer(ts, WRITE_LOCK);
1080 ObtainWriteLock(&av->lock, 110);
1082 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1085 av->states |= types;
1087 /* fill in volume types */
1088 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1089 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1090 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1092 if (ve->flags & VLF_DFSFILESET)
1093 av->states |= VForeign;
1095 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1096 } /*InstallNVolumeEntry */
1100 LockAndInstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1101 struct cell *tcell, struct vrequest *areq)
1104 struct afs_conn *tconn;
1107 afs_uint32 serverid;
1111 struct server *serverHost[AFS_MAXHOSTS];
1113 AFS_STATCNT(InstallVolumeEntry);
1115 memset(serverHost, 0, sizeof(serverHost));
1117 /* Determine type of volume we want */
1118 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1120 } else if ((ve->flags & VLF_ROEXISTS)
1121 && av->volume == ve->volumeId[ROVOL]) {
1124 } else if ((ve->flags & VLF_BACKEXISTS)
1125 && (av->volume == ve->volumeId[BACKVOL])) {
1126 /* backup always is on the same volume as parent */
1128 type |= (VRO | VBackup);
1130 mask = 0; /* Can't find volume in vldb entry */
1133 cellp = afs_GetCell(acell, 0);
1135 /* Gather the list of servers the VLDB says the volume is on
1136 * and initialize the ve->serverHost[] array. If a server struct
1137 * is not found, then get the list of addresses for the
1138 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1140 for (i = 0, j = 0; i < ve->nServers; i++) {
1141 if (((ve->serverFlags[i] & mask) == 0)
1142 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1143 continue; /* wrong volume don't use this volume */
1146 if (!(ve->serverFlags[i] & VLSF_UUID)) {
1147 /* The server has no uuid */
1148 serverid = htonl(ve->serverNumber[i].time_low);
1149 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport,
1150 WRITE_LOCK, (afsUUID *) 0, 0, av);
1152 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1153 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1155 /* uuid, uniquifier, and portal are the same */
1157 afs_uint32 *addrp, code;
1158 afs_int32 nentries, unique;
1160 ListAddrByAttributes attrs;
1162 struct rx_connection *rxconn;
1164 memset(&attrs, 0, sizeof(attrs));
1165 attrs.Mask = VLADDR_UUID;
1166 attrs.uuid = ve->serverNumber[i];
1167 memset(&uuid, 0, sizeof(uuid));
1168 memset(&addrs, 0, sizeof(addrs));
1171 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1172 tcell->cellNum, areq, SHARED_LOCK,
1177 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1184 /* Handle corrupt VLDB (defect 7393) */
1185 if (code == 0 && nentries == 0)
1188 } while (afs_Analyze
1189 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1191 /* Better handing of such failures; for now we'll simply retry this call */
1192 areq->volumeError = 1;
1196 addrp = addrs.bulkaddrs_val;
1197 for (k = 0; k < nentries; k++) {
1198 addrp[k] = htonl(addrp[k]);
1200 ts = afs_GetServer(addrp, nentries, acell,
1201 cellp->fsport, WRITE_LOCK,
1202 &ve->serverNumber[i],
1203 ve->serverUnique[i], av);
1204 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1209 /* The cell field could be 0 if the server entry was created
1210 * first with the 'fs setserverprefs' call which doesn't set
1211 * the cell field. Thus if the afs_GetServer call above
1212 * follows later on it will find the server entry thus it will
1213 * simply return without setting any fields, so we set the
1214 * field ourselves below.
1218 afs_PutServer(ts, WRITE_LOCK);
1222 ObtainWriteLock(&av->lock, 111);
1224 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1229 /* fill in volume types */
1230 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1231 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1232 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1234 if (ve->flags & VLF_DFSFILESET)
1235 av->states |= VForeign;
1237 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1238 } /*InstallVolumeEntry */
1242 * Reset volume info for the specified volume strecture. Mark volume
1243 * to be rechecked next time.
1247 afs_ResetVolumeInfo(struct volume *tv)
1251 AFS_STATCNT(afs_ResetVolumeInfo);
1252 ObtainWriteLock(&tv->lock, 117);
1253 tv->states |= VRecheck;
1255 /* the hard-mount code in afs_Analyze may not be able to reset this flag
1256 * when VRecheck is set, so clear it here to ensure it gets cleared. */
1257 tv->states &= ~VHardMount;
1259 for (i = 0; i < AFS_MAXHOSTS; i++)
1260 tv->status[i] = not_busy;
1262 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1265 ReleaseWriteLock(&tv->lock);