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(void)
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 */
157 AFS_STATCNT(afs_UFSGetVolSlot);
158 if (!afs_freeVolList) {
160 bestTime = 0x7fffffff;
163 for (i = 0; i < NVOLS; i++) {
164 lv = &afs_volumes[i];
165 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
166 if (tv->refCount == 0) { /* is this one available? */
167 if (tv->accessTime < bestTime) { /* best one available? */
168 bestTime = tv->accessTime;
176 afs_warn("afs_UFSGetVolSlot: no vol slots available\n");
188 /* now write out volume structure to file */
190 tv->vtix = afs_volCounter++;
191 /* now put on hash chain */
192 i = FVHash(tv->cell, tv->volume);
193 staticFVolume.next = fvTable[i];
194 fvTable[i] = tv->vtix;
197 * Haul the guy in from disk so we don't overwrite hash table
200 if (afs_FVIndex != tv->vtix) {
201 tfile = osi_UFSOpen(&volumeInode);
203 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
204 &staticFVolume, sizeof(struct fvolume));
206 if (code != sizeof(struct fvolume)) {
207 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
211 afs_FVIndex = tv->vtix;
214 afs_FVIndex = tv->vtix;
215 staticFVolume.volume = tv->volume;
216 staticFVolume.cell = tv->cell;
217 staticFVolume.mtpoint = tv->mtpoint;
218 staticFVolume.dotdot = tv->dotdot;
219 staticFVolume.rootVnode = tv->rootVnode;
220 staticFVolume.rootUnique = tv->rootUnique;
221 tfile = osi_UFSOpen(&volumeInode);
223 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
224 &staticFVolume, sizeof(struct fvolume));
226 if (code != sizeof(struct fvolume)) {
227 afs_warn("afs_UFSGetVolSlot: error %d writing volumeinfo\n",
232 afs_osi_Free(oldname, strlen(oldname) + 1);
236 tv = afs_freeVolList;
237 afs_freeVolList = tv->next;
244 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
253 fvTable[i] = staticFVolume.next;
259 /* we messed with staticFVolume, so make sure someone else
260 * doesn't think it's fine to use */
264 } /*afs_UFSGetVolSlot */
268 * Get an available volume list slot. If the list does not exist,
269 * create one containing a single element.
273 afs_MemGetVolSlot(void)
277 AFS_STATCNT(afs_MemGetVolSlot);
278 if (!afs_freeVolList) {
279 struct volume *newVp;
281 newVp = afs_osi_Alloc(sizeof(struct volume));
282 osi_Assert(newVp != NULL);
285 afs_freeVolList = newVp;
287 tv = afs_freeVolList;
288 afs_freeVolList = tv->next;
291 } /*afs_MemGetVolSlot */
294 * Reset volume information for all volume structs that
295 * point to a speicific server, skipping a given volume if provided.
298 * The server to reset volume info about
300 * The volume to skip resetting info about
303 afs_ResetVolumes(struct server *srvp, struct volume *tv)
308 /* Find any volumes residing on this server and flush their state */
309 for (j = 0; j < NVOLS; j++) {
310 for (vp = afs_volumes[j]; vp; vp = vp->next) {
311 for (k = 0; k < AFS_MAXHOSTS; k++) {
312 if (!srvp || (vp->serverHost[k] == srvp)) {
313 if (tv && tv != vp) {
314 vp->serverHost[k] = 0;
315 afs_ResetVolumeInfo(vp);
325 * Reset volume name to volume id mapping cache.
329 afs_CheckVolumeNames(int flags)
335 afs_int32 *volumeID, *cellID, vsize, nvols;
336 #ifdef AFS_DARWIN80_ENV
339 AFS_STATCNT(afs_CheckVolumeNames);
342 volumeID = cellID = NULL;
344 ObtainReadLock(&afs_xvolume);
345 if (flags & AFS_VOLCHECK_EXPIRED) {
347 * allocate space to hold the volumeIDs and cellIDs, only if
348 * we will be invalidating the mountpoints later on
350 for (i = 0; i < NVOLS; i++)
351 for (tv = afs_volumes[i]; tv; tv = tv->next)
354 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
355 cellID = (volumeID) ? volumeID + vsize : 0;
359 for (i = 0; i < NVOLS; i++) {
360 for (tv = afs_volumes[i]; tv; tv = tv->next) {
361 if (flags & AFS_VOLCHECK_EXPIRED) {
362 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
363 || (flags & AFS_VOLCHECK_FORCE)) {
364 afs_ResetVolumeInfo(tv); /* also resets status */
366 volumeID[nvols] = tv->volume;
367 cellID[nvols] = tv->cell;
374 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
375 for (j = 0; j < AFS_MAXHOSTS; j++)
376 tv->status[j] = not_busy;
381 ReleaseReadLock(&afs_xvolume);
384 /* next ensure all mt points are re-evaluated */
385 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
387 ObtainReadLock(&afs_xvcache);
388 for (i = 0; i < VCSIZE; i++) {
389 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
391 /* if the volume of "mvid" of the vcache entry is among the
392 * ones we found earlier, then we re-evaluate it. Also, if the
393 * force bit is set or we explicitly asked to reevaluate the
394 * mt-pts, we clean the cmvalid bit */
396 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
398 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
399 tvc->f.states &= ~CMValid;
401 /* If the volume that this file belongs to was reset earlier,
402 * then we should remove its callback.
403 * Again, if forced, always do it.
405 if ((tvc->f.states & CRO)
406 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
407 || (flags & AFS_VOLCHECK_FORCE))) {
409 if (tvc->f.states & CVInit) {
410 ReleaseReadLock(&afs_xvcache);
411 afs_osi_Sleep(&tvc->f.states);
414 #ifdef AFS_DARWIN80_ENV
415 if (tvc->f.states & CDeadVnode) {
416 ReleaseReadLock(&afs_xvcache);
417 afs_osi_Sleep(&tvc->f.states);
423 if (vnode_ref(tvp)) {
425 /* AFSTOV(tvc) may be NULL */
433 ReleaseReadLock(&afs_xvcache);
435 ObtainWriteLock(&afs_xcbhash, 485);
436 /* LOCKXXX: We aren't holding tvc write lock? */
437 afs_DequeueCallback(tvc);
438 tvc->f.states &= ~CStatd;
439 ReleaseWriteLock(&afs_xcbhash);
440 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
441 osi_dnlc_purgedp(tvc);
443 #ifdef AFS_DARWIN80_ENV
444 vnode_put(AFSTOV(tvc));
445 /* our tvc ptr is still good until now */
447 ObtainReadLock(&afs_xvcache);
449 ObtainReadLock(&afs_xvcache);
451 /* our tvc ptr is still good until now */
457 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
458 ReleaseReadLock(&afs_xvcache);
462 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
464 } /*afs_CheckVolumeNames */
468 * Check if volume is in the specified list.
469 * @param fid File FID.
470 * @param nvols Nomber of volumes???
471 * @param vID Array of volume IDs.
472 * @param cID Array of cache IDs.
473 * @return 1 - true, 0 - false.
476 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
481 /* if no arrays present, be conservative and return true */
482 if (nvols && (!vID || !cID))
485 for (i = 0; i < nvols; ++i) {
486 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
493 /* afs_PutVolume is now a macro in afs.h */
497 * Return volume struct if we have it cached and it's up-to-date.
498 * Environment: Must be called with afs_xvolume unlocked.
499 * @param afid Volume FID.
501 * @return Volume or NULL if no result.
504 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
512 i = VHash(afid->Fid.Volume);
513 ObtainWriteLock(&afs_xvolume, 106);
514 for (tv = afs_volumes[i]; tv; tv = tv->next) {
515 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
516 && (tv->states & VRecheck) == 0) {
521 ReleaseWriteLock(&afs_xvolume);
522 return tv; /* NULL if we didn't find it */
523 } /*afs_FindVolume */
528 * Note that areq may be null, in which case we don't bother to set any
529 * request status information.
530 * @param afid Volume FID.
531 * @param areq Request type.
532 * @param locktype Lock to be used.
533 * @return Volume or NULL if no result.
536 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
540 char *bp, tbuf[CVBS];
541 AFS_STATCNT(afs_GetVolume);
543 tv = afs_FindVolume(afid, locktype);
545 /* Do a dynroot check and add dynroot volume if found. */
546 if (afs_IsDynrootAnyFid(afid)) {
547 tv = afs_NewDynrootVolume(afid);
549 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
550 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
560 * @param volid Volume ID. If it's 0, get it from the name.
561 * @param aname Volume name.
562 * @param ve Volume entry.
563 * @param tcell The cell containing this volume.
565 * @param type Type of volume.
566 * @param areq Request.
567 * @return Volume or NULL if failure.
569 static struct volume *
570 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
571 afs_int32 agood, afs_int32 type, struct vrequest *areq)
574 struct vldbentry *ove = (struct vldbentry *)ve;
575 struct nvldbentry *nve = (struct nvldbentry *)ve;
576 struct uvldbentry *uve = (struct uvldbentry *)ve;
578 int whichType; /* which type of volume to look for */
583 /* special hint from file server to use vlserver */
585 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
587 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
592 /* figure out which one we're really interested in (a set is returned) */
593 volid = afs_vtoi(aname);
596 volid = uve->volumeId[whichType];
597 } else if (type == 1) {
598 volid = nve->volumeId[whichType];
600 volid = ove->volumeId[whichType];
602 } /* end of if (volid == 0) */
603 } /* end of if (!volid) */
606 ObtainWriteLock(&afs_xvolume, 108);
608 for (tv = afs_volumes[i]; tv; tv = tv->next) {
609 if (tv->volume == volid && tv->cell == tcell->cellNum) {
614 struct fvolume *tf = 0;
616 tv = afs_GetVolSlot();
618 ReleaseWriteLock(&afs_xvolume);
622 for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) {
623 if (afs_FVIndex != j) {
624 struct osi_file *tfile;
625 tfile = osi_UFSOpen(&volumeInode);
627 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
628 &staticFVolume, sizeof(struct fvolume));
630 if (err != sizeof(struct fvolume)) {
631 afs_warn("afs_SetupVolume: error %d reading volumeinfo\n",
633 /* put tv back on the free list; the data in it is not valid */
634 tv->next = afs_freeVolList;
635 afs_freeVolList = tv;
636 /* staticFVolume contents are not valid */
638 ReleaseWriteLock(&afs_xvolume);
643 if (j != 0) { /* volume items record 0 is not used */
645 if (tf->cell == tcell->cellNum && tf->volume == volid) {
651 afs_InitVolSlot(tv, tf, volid, tcell);
652 tv->next = afs_volumes[i]; /* thread into list */
656 tv->states &= ~VRecheck; /* just checked it */
657 tv->accessTime = osi_Time();
658 ReleaseWriteLock(&afs_xvolume);
660 LockAndInstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
661 } else if (type == 1)
662 LockAndInstallNVolumeEntry(tv, nve, tcell->cellNum);
664 LockAndInstallVolumeEntry(tv, ove, tcell->cellNum);
667 tv->name = afs_osi_Alloc(strlen(aname) + 1);
668 osi_Assert(tv->name != NULL);
669 strcpy(tv->name, aname);
672 for (i = 0; i < NMAXNSERVERS; i++) {
673 tv->status[i] = not_busy;
675 ReleaseWriteLock(&tv->lock);
681 * Seek volume by it's name and attributes.
682 * If volume not found, try to add one.
683 * @param aname Volume name.
687 * @param locktype Type of lock to be used.
691 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
692 struct vrequest *areq, afs_int32 locktype)
697 AFS_STATCNT(afs_GetVolumeByName);
698 ObtainWriteLock(&afs_xvolume, 112);
699 for (i = 0; i < NVOLS; i++) {
700 for (tv = afs_volumes[i]; tv; tv = tv->next) {
701 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
702 && (tv->states & VRecheck) == 0) {
704 ReleaseWriteLock(&afs_xvolume);
710 ReleaseWriteLock(&afs_xvolume);
712 if (AFS_IS_DISCONNECTED)
715 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
720 * Init a new dynroot volume.
722 * @return Volume or NULL if not found.
724 static struct volume *
725 afs_NewDynrootVolume(struct VenusFid *fid)
729 struct vldbentry *tve;
730 char *bp, tbuf[CVBS];
732 tcell = afs_GetCell(fid->Cell, READ_LOCK);
735 tve = afs_osi_Alloc(sizeof(*tve));
736 osi_Assert(tve != NULL);
737 if (!(tcell->states & CHasVolRef))
738 tcell->states |= CHasVolRef;
740 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
741 memset(tve, 0, sizeof(*tve));
742 strcpy(tve->name, "local-dynroot");
743 tve->volumeId[ROVOL] = fid->Fid.Volume;
744 tve->flags = VLF_ROEXISTS;
746 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
747 afs_PutCell(tcell, READ_LOCK);
748 afs_osi_Free(tve, sizeof(*tve));
755 * @param aname Volume name.
756 * @param acell Cell id.
758 * @param areq Request type.
759 * @param locktype Type of lock to be used.
760 * @return Volume or NULL if failure.
762 static struct volume *
763 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
764 struct vrequest *areq, afs_int32 locktype)
766 afs_int32 code, type = 0;
767 struct volume *tv, *tv1;
768 struct vldbentry *tve;
769 struct nvldbentry *ntve;
770 struct uvldbentry *utve;
773 struct afs_conn *tconn;
774 struct vrequest treq;
775 struct rx_connection *rxconn;
777 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
780 tcell = afs_GetCell(acell, READ_LOCK);
785 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
790 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
791 ICL_TYPE_POINTER, aname);
792 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
793 tve = (struct vldbentry *)(tbuffer + 1024);
794 ntve = (struct nvldbentry *)tve;
795 utve = (struct uvldbentry *)tve;
796 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
799 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
800 &treq, SHARED_LOCK, 0, &rxconn);
802 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
805 code = VL_GetEntryByNameO(rxconn, aname, tve);
807 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
810 code = VL_GetEntryByNameN(rxconn, aname, ntve);
815 code = VL_GetEntryByNameU(rxconn, aname, utve);
817 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
818 if (code == RXGEN_OPCODE) {
821 code = VL_GetEntryByNameN(rxconn, aname, ntve);
823 if (code == RXGEN_OPCODE) {
825 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
827 code = VL_GetEntryByNameO(rxconn, aname, tve);
830 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
832 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
838 } while (afs_Analyze(tconn, rxconn, code, NULL, &treq, -1, /* no op code for this */
839 SHARED_LOCK, tcell));
842 /* If the client has yet to contact this cell and contact failed due
843 * to network errors, mark the VLDB servers as back up.
844 * That the client tried and failed can be determined from the
845 * fact that there was a downtime incident, but CHasVolRef is not set.
847 /* RT 48959 - unclear if this should really go */
849 if (areq->networkError && !(tcell->states & CHasVolRef)) {
853 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
854 if ((sp = tcell->cellHosts[i]) == NULL)
856 for (sap = sp->addr; sap; sap = sap->next_sa)
857 afs_MarkServerUpOrDown(sap, 0);
861 afs_CopyError(&treq, areq);
862 osi_FreeLargeSpace(tbuffer);
863 afs_PutCell(tcell, READ_LOCK);
867 * Check to see if this cell has not yet referenced a volume. If
868 * it hasn't, it's just about to change its status, and we need to mark
869 * this fact down. Note that it is remotely possible that afs_SetupVolume
870 * could fail and we would still not have a volume reference.
872 if (!(tcell->states & CHasVolRef)) {
873 tcell->states |= CHasVolRef;
874 afs_stats_cmperf.numCellsContacted++;
876 /*First time a volume in this cell has been referenced */
883 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, &treq);
884 if ((agood == 3) && tv && tv->backVol) {
886 * This means that very soon we'll ask for the BK volume so
887 * we'll prefetch it (well we did already.)
890 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, &treq);
895 if ((agood >= 2) && tv && tv->roVol) {
897 * This means that very soon we'll ask for the RO volume so
898 * we'll prefetch it (well we did already.)
900 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, &treq);
905 osi_FreeLargeSpace(tbuffer);
906 afs_PutCell(tcell, READ_LOCK);
909 } /*afs_NewVolumeByName */
914 * Call this with the volume structure locked; used for new-style vldb requests.
920 LockAndInstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
928 struct server *serverHost[AFS_MAXHOSTS];
930 AFS_STATCNT(InstallVolumeEntry);
932 memset(serverHost, 0, sizeof(serverHost));
934 /* Determine the type of volume we want */
935 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
937 } else if ((ve->flags & VLF_ROEXISTS)
938 && (av->volume == ve->volumeId[ROVOL])) {
941 } else if ((ve->flags & VLF_BACKEXISTS)
942 && (av->volume == ve->volumeId[BACKVOL])) {
943 /* backup always is on the same volume as parent */
945 types |= (VRO | VBackup);
947 mask = 0; /* Can't find volume in vldb entry */
950 cellp = afs_GetCell(acell, 0);
952 /* Step through the VLDB entry making sure each server listed is there */
953 for (i = 0, j = 0; i < ve->nServers; i++) {
954 if (((ve->serverFlags[i] & mask) == 0)
955 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
956 continue; /* wrong volume or don't use this volume */
959 temp = htonl(ve->serverNumber[i]);
960 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
961 (afsUUID *) 0, 0, av);
965 * The cell field could be 0 if the server entry was created
966 * first with the 'fs setserverprefs' call which doesn't set
967 * the cell field. Thus if the afs_GetServer call above
968 * follows later on it will find the server entry thus it will
969 * simply return without setting any fields, so we set the
970 * field ourselves below.
974 afs_PutServer(ts, WRITE_LOCK);
978 ObtainWriteLock(&av->lock, 109);
980 memcpy(av->serverHost, serverHost, sizeof(serverHost));
985 /* fill in volume types */
986 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
987 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
988 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
990 if (ve->flags & VLF_DFSFILESET)
991 av->states |= VForeign;
993 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
994 } /*InstallVolumeEntry */
998 LockAndInstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
1006 struct server *serverHost[AFS_MAXHOSTS];
1008 AFS_STATCNT(InstallVolumeEntry);
1010 memset(serverHost, 0, sizeof(serverHost));
1012 /* Determine type of volume we want */
1013 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1015 } else if ((ve->flags & VLF_ROEXISTS)
1016 && (av->volume == ve->volumeId[ROVOL])) {
1019 } else if ((ve->flags & VLF_BACKEXISTS)
1020 && (av->volume == ve->volumeId[BACKVOL])) {
1021 /* backup always is on the same volume as parent */
1023 types |= (VRO | VBackup);
1025 mask = 0; /* Can't find volume in vldb entry */
1028 cellp = afs_GetCell(acell, 0);
1030 /* Step through the VLDB entry making sure each server listed is there */
1031 for (i = 0, j = 0; i < ve->nServers; i++) {
1032 if (((ve->serverFlags[i] & mask) == 0)
1033 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1034 continue; /* wrong volume or don't use this volume */
1037 temp = htonl(ve->serverNumber[i]);
1038 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1039 (afsUUID *) 0, 0, av);
1042 * The cell field could be 0 if the server entry was created
1043 * first with the 'fs setserverprefs' call which doesn't set
1044 * the cell field. Thus if the afs_GetServer call above
1045 * follows later on it will find the server entry thus it will
1046 * simply return without setting any fields, so we set the
1047 * field ourselves below.
1051 afs_PutServer(ts, WRITE_LOCK);
1055 ObtainWriteLock(&av->lock, 110);
1057 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1060 av->states |= types;
1062 /* fill in volume types */
1063 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1064 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1065 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1067 if (ve->flags & VLF_DFSFILESET)
1068 av->states |= VForeign;
1070 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1071 } /*InstallNVolumeEntry */
1075 LockAndInstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1076 struct cell *tcell, struct vrequest *areq)
1079 struct afs_conn *tconn;
1082 afs_uint32 serverid;
1086 struct server *serverHost[AFS_MAXHOSTS];
1088 AFS_STATCNT(InstallVolumeEntry);
1090 memset(serverHost, 0, sizeof(serverHost));
1092 /* Determine type of volume we want */
1093 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1095 } else if ((ve->flags & VLF_ROEXISTS)
1096 && av->volume == ve->volumeId[ROVOL]) {
1099 } else if ((ve->flags & VLF_BACKEXISTS)
1100 && (av->volume == ve->volumeId[BACKVOL])) {
1101 /* backup always is on the same volume as parent */
1103 type |= (VRO | VBackup);
1105 mask = 0; /* Can't find volume in vldb entry */
1108 cellp = afs_GetCell(acell, 0);
1110 /* Gather the list of servers the VLDB says the volume is on
1111 * and initialize the ve->serverHost[] array. If a server struct
1112 * is not found, then get the list of addresses for the
1113 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1115 for (i = 0, j = 0; i < ve->nServers; i++) {
1116 if (((ve->serverFlags[i] & mask) == 0)
1117 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1118 continue; /* wrong volume don't use this volume */
1121 if (!(ve->serverFlags[i] & VLSF_UUID)) {
1122 /* The server has no uuid */
1123 serverid = htonl(ve->serverNumber[i].time_low);
1124 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport,
1125 WRITE_LOCK, (afsUUID *) 0, 0, av);
1127 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1128 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1130 /* uuid, uniquifier, and portal are the same */
1132 afs_uint32 *addrp, code;
1133 afs_int32 nentries, unique;
1135 ListAddrByAttributes attrs;
1137 struct rx_connection *rxconn;
1139 memset(&attrs, 0, sizeof(attrs));
1140 attrs.Mask = VLADDR_UUID;
1141 attrs.uuid = ve->serverNumber[i];
1142 memset(&uuid, 0, sizeof(uuid));
1143 memset(&addrs, 0, sizeof(addrs));
1146 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1147 tcell->cellNum, areq, SHARED_LOCK,
1152 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1159 /* Handle corrupt VLDB (defect 7393) */
1160 if (code == 0 && nentries == 0)
1163 } while (afs_Analyze
1164 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1166 /* Better handing of such failures; for now we'll simply retry this call */
1167 areq->volumeError = 1;
1171 addrp = addrs.bulkaddrs_val;
1172 for (k = 0; k < nentries; k++) {
1173 addrp[k] = htonl(addrp[k]);
1175 ts = afs_GetServer(addrp, nentries, acell,
1176 cellp->fsport, WRITE_LOCK,
1177 &ve->serverNumber[i],
1178 ve->serverUnique[i], av);
1179 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1184 /* The cell field could be 0 if the server entry was created
1185 * first with the 'fs setserverprefs' call which doesn't set
1186 * the cell field. Thus if the afs_GetServer call above
1187 * follows later on it will find the server entry thus it will
1188 * simply return without setting any fields, so we set the
1189 * field ourselves below.
1193 afs_PutServer(ts, WRITE_LOCK);
1197 ObtainWriteLock(&av->lock, 111);
1199 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1204 /* fill in volume types */
1205 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1206 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1207 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1209 if (ve->flags & VLF_DFSFILESET)
1210 av->states |= VForeign;
1212 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1213 } /*InstallVolumeEntry */
1217 * Reset volume info for the specified volume strecture. Mark volume
1218 * to be rechecked next time.
1222 afs_ResetVolumeInfo(struct volume *tv)
1226 AFS_STATCNT(afs_ResetVolumeInfo);
1227 ObtainWriteLock(&tv->lock, 117);
1228 tv->states |= VRecheck;
1230 /* the hard-mount code in afs_Analyze may not be able to reset this flag
1231 * when VRecheck is set, so clear it here to ensure it gets cleared. */
1232 tv->states &= ~VHardMount;
1234 for (i = 0; i < AFS_MAXHOSTS; i++)
1235 tv->status[i] = not_busy;
1237 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1240 ReleaseWriteLock(&tv->lock);