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->setupTime < bestTime) { /* best one available? */
170 bestTime = tv->setupTime;
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_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
209 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
210 &staticFVolume, sizeof(struct fvolume));
212 if (code != sizeof(struct fvolume)) {
213 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
219 afs_FVIndex = tv->vtix;
220 staticFVolume.volume = tv->volume;
221 staticFVolume.cell = tv->cell;
222 staticFVolume.mtpoint = tv->mtpoint;
223 staticFVolume.dotdot = tv->dotdot;
224 staticFVolume.rootVnode = tv->rootVnode;
225 staticFVolume.rootUnique = tv->rootUnique;
226 tfile = osi_UFSOpen(&volumeInode);
228 afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
232 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
233 &staticFVolume, sizeof(struct fvolume));
235 if (code != sizeof(struct fvolume)) {
236 afs_warn("afs_UFSGetVolSlot: error %d writing volumeinfo\n",
241 afs_osi_Free(oldname, strlen(oldname) + 1);
245 tv = afs_freeVolList;
246 afs_freeVolList = tv->next;
249 /* read volume item data from disk for the gotten slot */
250 for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) {
251 if (afs_FVIndex != j) {
252 tfile = osi_UFSOpen(&volumeInode);
254 afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
255 code = -1; /* indicate error */
258 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
259 &staticFVolume, sizeof(struct fvolume));
261 if (code != sizeof(struct fvolume)) {
262 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
266 if (code != sizeof(struct fvolume)) {
267 /* put tv back on the free list; the data in it is not valid */
268 tv->next = afs_freeVolList;
269 afs_freeVolList = tv;
270 /* staticFVolume contents are not valid */
276 if (j != 0) { /* volume items record 0 is not used */
278 if (tf->cell == tcell->cellNum && tf->volume == volid) {
284 afs_InitVolSlot(tv, tf, volid, tcell);
290 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
299 fvTable[i] = staticFVolume.next;
305 /* we messed with staticFVolume, so make sure someone else
306 * doesn't think it's fine to use */
310 } /*afs_UFSGetVolSlot */
314 * Get an available volume list slot. If the list does not exist,
315 * create one containing a single element.
319 afs_MemGetVolSlot(afs_int32 volid, struct cell *tcell)
323 AFS_STATCNT(afs_MemGetVolSlot);
324 if (!afs_freeVolList) {
325 struct volume *newVp;
327 newVp = afs_osi_Alloc(sizeof(struct volume));
328 osi_Assert(newVp != NULL);
331 afs_freeVolList = newVp;
333 tv = afs_freeVolList;
334 afs_freeVolList = tv->next;
336 afs_InitVolSlot(tv, NULL, volid, tcell);
339 } /*afs_MemGetVolSlot */
342 * Setup a volume slot for cell:volume.
344 * Find the volume slot for the cell:volume, otherwise get
345 * and initialize a new slot.
347 * \param volid volume id
351 static struct volume *
352 afs_SetupVolSlot(afs_int32 volid, struct cell *tcell)
357 AFS_STATCNT(afs_SetupVolSlot);
358 ObtainWriteLock(&afs_xvolume, 108);
360 for (tv = afs_volumes[i]; tv; tv = tv->next) {
361 if (tv->volume == volid && tv->cell == tcell->cellNum) {
366 tv = afs_GetVolSlot(volid, tcell);
368 ReleaseWriteLock(&afs_xvolume);
371 tv->next = afs_volumes[i]; /* thread into list */
375 tv->states &= ~VRecheck; /* just checked it */
376 tv->setupTime = osi_Time();
377 ReleaseWriteLock(&afs_xvolume);
382 * Reset volume information for all volume structs that
383 * point to a speicific server, skipping a given volume if provided.
386 * The server to reset volume info about
388 * The volume to skip resetting info about
391 afs_ResetVolumes(struct server *srvp, struct volume *tv)
396 /* Find any volumes residing on this server and flush their state */
397 for (j = 0; j < NVOLS; j++) {
398 for (vp = afs_volumes[j]; vp; vp = vp->next) {
399 for (k = 0; k < AFS_MAXHOSTS; k++) {
400 if (!srvp || (vp->serverHost[k] == srvp)) {
401 if (tv && tv != vp) {
402 vp->serverHost[k] = 0;
403 afs_ResetVolumeInfo(vp);
413 * Returns non-zero if the volume information is expired.
415 * Dynroot volumes are not setup from vldb queries, so never expire.
416 * Read-only volume expiry is tied to the volume callback.
418 * \param tv volume to check
419 * \param now current time
421 * \return non-zero if the volume should be reset
424 IsExpired(struct volume *tv, afs_int32 now)
426 return (tv->expireTime < (now + 10)) && (tv->states & VRO)
427 && !afs_IsDynrootVolume(tv);
431 * Reset volume name to volume id mapping cache.
435 afs_CheckVolumeNames(int flags)
441 afs_int32 *volumeID, *cellID, vsize, nvols;
442 #ifdef AFS_DARWIN80_ENV
445 AFS_STATCNT(afs_CheckVolumeNames);
448 volumeID = cellID = NULL;
450 ObtainReadLock(&afs_xvolume);
451 if (flags & AFS_VOLCHECK_EXPIRED) {
453 * allocate space to hold the volumeIDs and cellIDs, only if
454 * we will be invalidating the mountpoints later on
456 for (i = 0; i < NVOLS; i++)
457 for (tv = afs_volumes[i]; tv; tv = tv->next)
460 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
461 cellID = (volumeID) ? volumeID + vsize : 0;
465 for (i = 0; i < NVOLS; i++) {
466 for (tv = afs_volumes[i]; tv; tv = tv->next) {
467 if (flags & AFS_VOLCHECK_EXPIRED) {
468 if (IsExpired(tv, now) || (flags & AFS_VOLCHECK_FORCE)) {
469 afs_ResetVolumeInfo(tv); /* also resets status */
471 volumeID[nvols] = tv->volume;
472 cellID[nvols] = tv->cell;
479 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
480 for (j = 0; j < AFS_MAXHOSTS; j++)
481 tv->status[j] = not_busy;
486 ReleaseReadLock(&afs_xvolume);
489 /* next ensure all mt points are re-evaluated */
490 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
492 ObtainReadLock(&afs_xvcache);
493 for (i = 0; i < VCSIZE; i++) {
494 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
496 /* if the volume of "mvid.target_root" of the vcache entry is
497 * among the ones we found earlier, then we re-evaluate it.
498 * Also, if the force bit is set or we explicitly asked to
499 * reevaluate the mt-pts, we clean the cmvalid bit */
501 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
502 || (tvc->mvid.target_root
503 && inVolList(tvc->mvid.target_root, nvols, volumeID, cellID)))
504 tvc->f.states &= ~CMValid;
506 /* If the volume that this file belongs to was reset earlier,
507 * then we should remove its callback.
508 * Again, if forced, always do it.
510 if ((tvc->f.states & CRO)
511 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
512 || (flags & AFS_VOLCHECK_FORCE))) {
514 if (tvc->f.states & CVInit) {
515 ReleaseReadLock(&afs_xvcache);
516 afs_osi_Sleep(&tvc->f.states);
519 #ifdef AFS_DARWIN80_ENV
520 if (tvc->f.states & CDeadVnode) {
521 ReleaseReadLock(&afs_xvcache);
522 afs_osi_Sleep(&tvc->f.states);
528 if (vnode_ref(tvp)) {
530 /* AFSTOV(tvc) may be NULL */
538 ReleaseReadLock(&afs_xvcache);
540 /* LOCKXXX: We aren't holding tvc write lock? */
541 afs_StaleVCache(tvc);
543 #ifdef AFS_DARWIN80_ENV
544 vnode_put(AFSTOV(tvc));
545 /* our tvc ptr is still good until now */
547 ObtainReadLock(&afs_xvcache);
549 ObtainReadLock(&afs_xvcache);
551 /* our tvc ptr is still good until now */
557 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
558 ReleaseReadLock(&afs_xvcache);
562 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
564 } /*afs_CheckVolumeNames */
568 * Check if volume is in the specified list.
569 * @param fid File FID.
570 * @param nvols Nomber of volumes???
571 * @param vID Array of volume IDs.
572 * @param cID Array of cache IDs.
573 * @return 1 - true, 0 - false.
576 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
581 /* if no arrays present, be conservative and return true */
582 if (nvols && (!vID || !cID))
585 for (i = 0; i < nvols; ++i) {
586 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
593 /* afs_PutVolume is now a macro in afs.h */
597 * Return volume struct if we have it cached and it's up-to-date.
598 * Environment: Must be called with afs_xvolume unlocked.
599 * @param afid Volume FID.
601 * @return Volume or NULL if no result.
604 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
612 i = VHash(afid->Fid.Volume);
613 ObtainWriteLock(&afs_xvolume, 106);
614 for (tv = afs_volumes[i]; tv; tv = tv->next) {
615 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
616 && (tv->states & VRecheck) == 0) {
621 ReleaseWriteLock(&afs_xvolume);
622 return tv; /* NULL if we didn't find it */
623 } /*afs_FindVolume */
628 * Note that areq may be null, in which case we don't bother to set any
629 * request status information.
630 * @param afid Volume FID.
631 * @param areq Request type.
632 * @param locktype Lock to be used.
633 * @return Volume or NULL if no result.
636 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
640 char *bp, tbuf[CVBS];
641 AFS_STATCNT(afs_GetVolume);
643 tv = afs_FindVolume(afid, locktype);
645 /* Do a dynroot check and add dynroot volume if found. */
646 if (afs_IsDynrootAnyFid(afid)) {
647 tv = afs_NewDynrootVolume(afid);
649 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
650 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
660 * @param volid Volume ID. If it's 0, get it from the name.
661 * @param aname Volume name.
662 * @param ve Volume entry.
663 * @param tcell The cell containing this volume.
665 * @param type Type of volume.
666 * @param areq Request.
667 * @return Volume or NULL if failure.
669 static struct volume *
670 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
671 afs_int32 agood, afs_int32 type, struct vrequest *areq)
674 struct vldbentry *ove = (struct vldbentry *)ve;
675 struct nvldbentry *nve = (struct nvldbentry *)ve;
676 struct uvldbentry *uve = (struct uvldbentry *)ve;
678 int whichType; /* which type of volume to look for */
683 /* special hint from file server to use vlserver */
685 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
687 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
692 /* figure out which one we're really interested in (a set is returned) */
693 volid = afs_vtoi(aname);
696 volid = uve->volumeId[whichType];
697 } else if (type == 1) {
698 volid = nve->volumeId[whichType];
700 volid = ove->volumeId[whichType];
702 } /* end of if (volid == 0) */
703 } /* end of if (!volid) */
705 tv = afs_SetupVolSlot(volid, tcell);
711 LockAndInstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
712 } else if (type == 1)
713 LockAndInstallNVolumeEntry(tv, nve, tcell->cellNum);
715 LockAndInstallVolumeEntry(tv, ove, tcell->cellNum);
718 tv->name = afs_osi_Alloc(strlen(aname) + 1);
719 osi_Assert(tv->name != NULL);
720 strcpy(tv->name, aname);
723 for (i = 0; i < NMAXNSERVERS; i++) {
724 tv->status[i] = not_busy;
726 ReleaseWriteLock(&tv->lock);
732 * Seek volume by it's name and attributes.
733 * If volume not found, try to add one.
734 * @param aname Volume name.
738 * @param locktype Type of lock to be used.
742 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
743 struct vrequest *areq, afs_int32 locktype)
748 AFS_STATCNT(afs_GetVolumeByName);
749 ObtainWriteLock(&afs_xvolume, 112);
750 for (i = 0; i < NVOLS; i++) {
751 for (tv = afs_volumes[i]; tv; tv = tv->next) {
752 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
753 && (tv->states & VRecheck) == 0) {
755 ReleaseWriteLock(&afs_xvolume);
761 ReleaseWriteLock(&afs_xvolume);
763 if (AFS_IS_DISCONNECTED)
766 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
771 * Init a new dynroot volume.
773 * @return Volume or NULL if not found.
775 static struct volume *
776 afs_NewDynrootVolume(struct VenusFid *fid)
780 struct vldbentry *tve;
781 char *bp, tbuf[CVBS];
783 tcell = afs_GetCell(fid->Cell, READ_LOCK);
786 tve = afs_osi_Alloc(sizeof(*tve));
787 osi_Assert(tve != NULL);
788 if (!(tcell->states & CHasVolRef))
789 tcell->states |= CHasVolRef;
791 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
792 memset(tve, 0, sizeof(*tve));
793 strcpy(tve->name, "local-dynroot");
794 tve->volumeId[ROVOL] = fid->Fid.Volume;
795 tve->flags = VLF_ROEXISTS;
797 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
798 afs_PutCell(tcell, READ_LOCK);
799 afs_osi_Free(tve, sizeof(*tve));
806 * @param aname Volume name.
807 * @param acell Cell id.
809 * @param areq Request type.
810 * @param locktype Type of lock to be used.
811 * @return Volume or NULL if failure.
813 static struct volume *
814 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
815 struct vrequest *areq, afs_int32 locktype)
817 afs_int32 code, type = 0;
818 struct volume *tv, *tv1;
819 struct vldbentry *tve;
820 struct nvldbentry *ntve;
821 struct uvldbentry *utve;
824 struct afs_conn *tconn;
825 struct vrequest *treq = NULL;
826 struct rx_connection *rxconn;
828 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
831 tcell = afs_GetCell(acell, READ_LOCK);
836 code = afs_CreateReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
841 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
846 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
847 ICL_TYPE_POINTER, aname);
848 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
849 tve = (struct vldbentry *)(tbuffer + 1024);
850 ntve = (struct nvldbentry *)tve;
851 utve = (struct uvldbentry *)tve;
855 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
856 treq, SHARED_LOCK, 0, &rxconn);
858 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
861 code = VL_GetEntryByNameO(rxconn, aname, tve);
863 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
866 code = VL_GetEntryByNameN(rxconn, aname, ntve);
871 code = VL_GetEntryByNameU(rxconn, aname, utve);
873 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
874 if (code == RXGEN_OPCODE) {
877 code = VL_GetEntryByNameN(rxconn, aname, ntve);
879 if (code == RXGEN_OPCODE) {
881 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
883 code = VL_GetEntryByNameO(rxconn, aname, tve);
886 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
888 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
894 } while (afs_Analyze(tconn, rxconn, code, NULL, treq, -1, /* no op code for this */
895 SHARED_LOCK, tcell));
898 /* If the client has yet to contact this cell and contact failed due
899 * to network errors, mark the VLDB servers as back up.
900 * That the client tried and failed can be determined from the
901 * fact that there was a downtime incident, but CHasVolRef is not set.
903 /* RT 48959 - unclear if this should really go */
905 if (areq->networkError && !(tcell->states & CHasVolRef)) {
909 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
910 if ((sp = tcell->cellHosts[i]) == NULL)
912 for (sap = sp->addr; sap; sap = sap->next_sa)
913 afs_MarkServerUpOrDown(sap, 0);
917 afs_CopyError(treq, areq);
918 osi_FreeLargeSpace(tbuffer);
919 afs_PutCell(tcell, READ_LOCK);
920 afs_DestroyReq(treq);
924 * Check to see if this cell has not yet referenced a volume. If
925 * it hasn't, it's just about to change its status, and we need to mark
926 * this fact down. Note that it is remotely possible that afs_SetupVolume
927 * could fail and we would still not have a volume reference.
929 if (!(tcell->states & CHasVolRef)) {
930 tcell->states |= CHasVolRef;
931 afs_stats_cmperf.numCellsContacted++;
933 /*First time a volume in this cell has been referenced */
940 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, treq);
941 if ((agood == 3) && tv && tv->backVol) {
943 * This means that very soon we'll ask for the BK volume so
944 * we'll prefetch it (well we did already.)
947 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, treq);
952 if ((agood >= 2) && tv && tv->roVol) {
954 * This means that very soon we'll ask for the RO volume so
955 * we'll prefetch it (well we did already.)
957 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, treq);
962 osi_FreeLargeSpace(tbuffer);
963 afs_PutCell(tcell, READ_LOCK);
964 afs_DestroyReq(treq);
967 } /*afs_NewVolumeByName */
972 * Call this with the volume structure locked; used for new-style vldb requests.
978 LockAndInstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
986 struct server *serverHost[AFS_MAXHOSTS];
988 AFS_STATCNT(InstallVolumeEntry);
990 memset(serverHost, 0, sizeof(serverHost));
992 /* Determine the type of volume we want */
993 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
995 } else if ((ve->flags & VLF_ROEXISTS)
996 && (av->volume == ve->volumeId[ROVOL])) {
999 } else if ((ve->flags & VLF_BACKEXISTS)
1000 && (av->volume == ve->volumeId[BACKVOL])) {
1001 /* backup always is on the same volume as parent */
1003 types |= (VRO | VBackup);
1005 mask = 0; /* Can't find volume in vldb entry */
1008 cellp = afs_GetCell(acell, 0);
1010 /* Step through the VLDB entry making sure each server listed is there */
1011 for (i = 0, j = 0; i < ve->nServers; i++) {
1012 if (((ve->serverFlags[i] & mask) == 0)
1013 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1014 continue; /* wrong volume or don't use this volume */
1017 temp = htonl(ve->serverNumber[i]);
1018 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1019 (afsUUID *) 0, 0, av);
1023 * The cell field could be 0 if the server entry was created
1024 * first with the 'fs setserverprefs' call which doesn't set
1025 * the cell field. Thus if the afs_GetServer call above
1026 * follows later on it will find the server entry thus it will
1027 * simply return without setting any fields, so we set the
1028 * field ourselves below.
1032 afs_PutServer(ts, WRITE_LOCK);
1036 ObtainWriteLock(&av->lock, 109);
1038 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1041 av->states |= types;
1043 /* fill in volume types */
1044 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1045 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1046 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1048 if (ve->flags & VLF_DFSFILESET)
1049 av->states |= VForeign;
1051 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1052 } /*InstallVolumeEntry */
1056 LockAndInstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
1064 struct server *serverHost[AFS_MAXHOSTS];
1066 AFS_STATCNT(InstallVolumeEntry);
1068 memset(serverHost, 0, sizeof(serverHost));
1070 /* Determine type of volume we want */
1071 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1073 } else if ((ve->flags & VLF_ROEXISTS)
1074 && (av->volume == ve->volumeId[ROVOL])) {
1077 } else if ((ve->flags & VLF_BACKEXISTS)
1078 && (av->volume == ve->volumeId[BACKVOL])) {
1079 /* backup always is on the same volume as parent */
1081 types |= (VRO | VBackup);
1083 mask = 0; /* Can't find volume in vldb entry */
1086 cellp = afs_GetCell(acell, 0);
1088 /* Step through the VLDB entry making sure each server listed is there */
1089 for (i = 0, j = 0; i < ve->nServers; i++) {
1090 if (((ve->serverFlags[i] & mask) == 0)
1091 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1092 continue; /* wrong volume or don't use this volume */
1095 temp = htonl(ve->serverNumber[i]);
1096 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1097 (afsUUID *) 0, 0, av);
1100 * The cell field could be 0 if the server entry was created
1101 * first with the 'fs setserverprefs' call which doesn't set
1102 * the cell field. Thus if the afs_GetServer call above
1103 * follows later on it will find the server entry thus it will
1104 * simply return without setting any fields, so we set the
1105 * field ourselves below.
1109 afs_PutServer(ts, WRITE_LOCK);
1113 ObtainWriteLock(&av->lock, 110);
1115 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1118 av->states |= types;
1120 /* fill in volume types */
1121 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1122 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1123 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1125 if (ve->flags & VLF_DFSFILESET)
1126 av->states |= VForeign;
1128 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1129 } /*InstallNVolumeEntry */
1133 LockAndInstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1134 struct cell *tcell, struct vrequest *areq)
1137 struct afs_conn *tconn;
1140 afs_uint32 serverid;
1144 struct server *serverHost[AFS_MAXHOSTS];
1146 AFS_STATCNT(InstallVolumeEntry);
1148 memset(serverHost, 0, sizeof(serverHost));
1150 /* Determine type of volume we want */
1151 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1153 } else if ((ve->flags & VLF_ROEXISTS)
1154 && av->volume == ve->volumeId[ROVOL]) {
1157 } else if ((ve->flags & VLF_BACKEXISTS)
1158 && (av->volume == ve->volumeId[BACKVOL])) {
1159 /* backup always is on the same volume as parent */
1161 type |= (VRO | VBackup);
1163 mask = 0; /* Can't find volume in vldb entry */
1166 cellp = afs_GetCell(acell, 0);
1168 /* Gather the list of servers the VLDB says the volume is on
1169 * and initialize the ve->serverHost[] array. If a server struct
1170 * is not found, then get the list of addresses for the
1171 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1173 for (i = 0, j = 0; i < ve->nServers; i++) {
1174 if (((ve->serverFlags[i] & mask) == 0)
1175 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1176 continue; /* wrong volume don't use this volume */
1179 if (!(ve->serverFlags[i] & VLSF_UUID)) {
1180 /* The server has no uuid */
1181 serverid = htonl(ve->serverNumber[i].time_low);
1182 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport,
1183 WRITE_LOCK, (afsUUID *) 0, 0, av);
1185 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1186 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1188 /* uuid, uniquifier, and portal are the same */
1190 afs_uint32 *addrp, code;
1191 afs_int32 nentries, unique;
1193 ListAddrByAttributes attrs;
1195 struct rx_connection *rxconn;
1197 memset(&attrs, 0, sizeof(attrs));
1198 attrs.Mask = VLADDR_UUID;
1199 attrs.uuid = ve->serverNumber[i];
1200 memset(&uuid, 0, sizeof(uuid));
1201 memset(&addrs, 0, sizeof(addrs));
1204 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1205 tcell->cellNum, areq, SHARED_LOCK,
1210 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1217 /* Handle corrupt VLDB (defect 7393) */
1218 if (code == 0 && nentries == 0)
1221 } while (afs_Analyze
1222 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1224 /* Better handing of such failures; for now we'll simply retry this call */
1225 areq->volumeError = 1;
1229 addrp = addrs.bulkaddrs_val;
1230 for (k = 0; k < nentries; k++) {
1231 addrp[k] = htonl(addrp[k]);
1233 ts = afs_GetServer(addrp, nentries, acell,
1234 cellp->fsport, WRITE_LOCK,
1235 &ve->serverNumber[i],
1236 ve->serverUnique[i], av);
1237 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1242 /* The cell field could be 0 if the server entry was created
1243 * first with the 'fs setserverprefs' call which doesn't set
1244 * the cell field. Thus if the afs_GetServer call above
1245 * follows later on it will find the server entry thus it will
1246 * simply return without setting any fields, so we set the
1247 * field ourselves below.
1251 afs_PutServer(ts, WRITE_LOCK);
1255 ObtainWriteLock(&av->lock, 111);
1257 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1262 /* fill in volume types */
1263 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1264 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1265 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1267 if (ve->flags & VLF_DFSFILESET)
1268 av->states |= VForeign;
1270 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1271 } /*InstallVolumeEntry */
1275 * Reset volume info for the specified volume strecture. Mark volume
1276 * to be rechecked next time.
1280 afs_ResetVolumeInfo(struct volume *tv)
1284 AFS_STATCNT(afs_ResetVolumeInfo);
1285 ObtainWriteLock(&tv->lock, 117);
1286 tv->states |= VRecheck;
1288 /* the hard-mount code in afs_Analyze may not be able to reset this flag
1289 * when VRecheck is set, so clear it here to ensure it gets cleared. */
1290 tv->states &= ~VHardMount;
1292 for (i = 0; i < AFS_MAXHOSTS; i++)
1293 tv->status[i] = not_busy;
1295 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1298 ReleaseWriteLock(&tv->lock);