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 * UFS specific version of afs_GetVolSlot
112 afs_UFSGetVolSlot(void)
114 struct volume *tv = NULL, **lv;
115 struct osi_file *tfile;
116 afs_int32 i = -1, code;
118 struct volume *bestVp, *oldLp = NULL, **bestLp = NULL;
119 char *oldname = NULL;
120 afs_int32 oldvtix = -2; /* Initialize to a value that doesn't occur */
122 AFS_STATCNT(afs_UFSGetVolSlot);
123 if (!afs_freeVolList) {
125 bestTime = 0x7fffffff;
128 for (i = 0; i < NVOLS; i++) {
129 lv = &afs_volumes[i];
130 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
131 if (tv->refCount == 0) { /* is this one available? */
132 if (tv->accessTime < bestTime) { /* best one available? */
133 bestTime = tv->accessTime;
141 afs_warn("afs_UFSGetVolSlot: no vol slots available\n");
153 /* now write out volume structure to file */
155 tv->vtix = afs_volCounter++;
156 /* now put on hash chain */
157 i = FVHash(tv->cell, tv->volume);
158 staticFVolume.next = fvTable[i];
159 fvTable[i] = tv->vtix;
162 * Haul the guy in from disk so we don't overwrite hash table
165 if (afs_FVIndex != tv->vtix) {
166 tfile = osi_UFSOpen(&volumeInode);
168 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
169 &staticFVolume, sizeof(struct fvolume));
171 if (code != sizeof(struct fvolume)) {
172 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
176 afs_FVIndex = tv->vtix;
179 afs_FVIndex = tv->vtix;
180 staticFVolume.volume = tv->volume;
181 staticFVolume.cell = tv->cell;
182 staticFVolume.mtpoint = tv->mtpoint;
183 staticFVolume.dotdot = tv->dotdot;
184 staticFVolume.rootVnode = tv->rootVnode;
185 staticFVolume.rootUnique = tv->rootUnique;
186 tfile = osi_UFSOpen(&volumeInode);
188 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
189 &staticFVolume, sizeof(struct fvolume));
191 if (code != sizeof(struct fvolume)) {
192 afs_warn("afs_UFSGetVolSlot: error %d writing volumeinfo\n",
197 afs_osi_Free(oldname, strlen(oldname) + 1);
201 tv = afs_freeVolList;
202 afs_freeVolList = tv->next;
209 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
218 fvTable[i] = staticFVolume.next;
224 /* we messed with staticFVolume, so make sure someone else
225 * doesn't think it's fine to use */
229 } /*afs_UFSGetVolSlot */
233 * Get an available volume list slot. If the list does not exist,
234 * create one containing a single element.
238 afs_MemGetVolSlot(void)
242 AFS_STATCNT(afs_MemGetVolSlot);
243 if (!afs_freeVolList) {
244 struct volume *newVp;
246 newVp = afs_osi_Alloc(sizeof(struct volume));
247 osi_Assert(newVp != NULL);
250 afs_freeVolList = newVp;
252 tv = afs_freeVolList;
253 afs_freeVolList = tv->next;
256 } /*afs_MemGetVolSlot */
259 * Reset volume information for all volume structs that
260 * point to a speicific server, skipping a given volume if provided.
263 * The server to reset volume info about
265 * The volume to skip resetting info about
268 afs_ResetVolumes(struct server *srvp, struct volume *tv)
273 /* Find any volumes residing on this server and flush their state */
274 for (j = 0; j < NVOLS; j++) {
275 for (vp = afs_volumes[j]; vp; vp = vp->next) {
276 for (k = 0; k < AFS_MAXHOSTS; k++) {
277 if (!srvp || (vp->serverHost[k] == srvp)) {
278 if (tv && tv != vp) {
279 vp->serverHost[k] = 0;
280 afs_ResetVolumeInfo(vp);
290 * Reset volume name to volume id mapping cache.
294 afs_CheckVolumeNames(int flags)
300 afs_int32 *volumeID, *cellID, vsize, nvols;
301 #ifdef AFS_DARWIN80_ENV
304 AFS_STATCNT(afs_CheckVolumeNames);
307 volumeID = cellID = NULL;
309 ObtainReadLock(&afs_xvolume);
310 if (flags & AFS_VOLCHECK_EXPIRED) {
312 * allocate space to hold the volumeIDs and cellIDs, only if
313 * we will be invalidating the mountpoints later on
315 for (i = 0; i < NVOLS; i++)
316 for (tv = afs_volumes[i]; tv; tv = tv->next)
319 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
320 cellID = (volumeID) ? volumeID + vsize : 0;
324 for (i = 0; i < NVOLS; i++) {
325 for (tv = afs_volumes[i]; tv; tv = tv->next) {
326 if (flags & AFS_VOLCHECK_EXPIRED) {
327 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
328 || (flags & AFS_VOLCHECK_FORCE)) {
329 afs_ResetVolumeInfo(tv); /* also resets status */
331 volumeID[nvols] = tv->volume;
332 cellID[nvols] = tv->cell;
339 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
340 for (j = 0; j < AFS_MAXHOSTS; j++)
341 tv->status[j] = not_busy;
346 ReleaseReadLock(&afs_xvolume);
349 /* next ensure all mt points are re-evaluated */
350 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
352 ObtainReadLock(&afs_xvcache);
353 for (i = 0; i < VCSIZE; i++) {
354 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
356 /* if the volume of "mvid" of the vcache entry is among the
357 * ones we found earlier, then we re-evaluate it. Also, if the
358 * force bit is set or we explicitly asked to reevaluate the
359 * mt-pts, we clean the cmvalid bit */
361 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
363 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
364 tvc->f.states &= ~CMValid;
366 /* If the volume that this file belongs to was reset earlier,
367 * then we should remove its callback.
368 * Again, if forced, always do it.
370 if ((tvc->f.states & CRO)
371 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
372 || (flags & AFS_VOLCHECK_FORCE))) {
374 if (tvc->f.states & CVInit) {
375 ReleaseReadLock(&afs_xvcache);
376 afs_osi_Sleep(&tvc->f.states);
379 #ifdef AFS_DARWIN80_ENV
380 if (tvc->f.states & CDeadVnode) {
381 ReleaseReadLock(&afs_xvcache);
382 afs_osi_Sleep(&tvc->f.states);
388 if (vnode_ref(tvp)) {
390 /* AFSTOV(tvc) may be NULL */
398 ReleaseReadLock(&afs_xvcache);
400 ObtainWriteLock(&afs_xcbhash, 485);
401 /* LOCKXXX: We aren't holding tvc write lock? */
402 afs_DequeueCallback(tvc);
403 tvc->f.states &= ~CStatd;
404 ReleaseWriteLock(&afs_xcbhash);
405 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
406 osi_dnlc_purgedp(tvc);
408 #ifdef AFS_DARWIN80_ENV
409 vnode_put(AFSTOV(tvc));
410 /* our tvc ptr is still good until now */
412 ObtainReadLock(&afs_xvcache);
414 ObtainReadLock(&afs_xvcache);
416 /* our tvc ptr is still good until now */
422 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
423 ReleaseReadLock(&afs_xvcache);
427 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
429 } /*afs_CheckVolumeNames */
433 * Check if volume is in the specified list.
434 * @param fid File FID.
435 * @param nvols Nomber of volumes???
436 * @param vID Array of volume IDs.
437 * @param cID Array of cache IDs.
438 * @return 1 - true, 0 - false.
441 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
446 /* if no arrays present, be conservative and return true */
447 if (nvols && (!vID || !cID))
450 for (i = 0; i < nvols; ++i) {
451 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
458 /* afs_PutVolume is now a macro in afs.h */
462 * Return volume struct if we have it cached and it's up-to-date.
463 * Environment: Must be called with afs_xvolume unlocked.
464 * @param afid Volume FID.
466 * @return Volume or NULL if no result.
469 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
477 i = VHash(afid->Fid.Volume);
478 ObtainWriteLock(&afs_xvolume, 106);
479 for (tv = afs_volumes[i]; tv; tv = tv->next) {
480 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
481 && (tv->states & VRecheck) == 0) {
486 ReleaseWriteLock(&afs_xvolume);
487 return tv; /* NULL if we didn't find it */
488 } /*afs_FindVolume */
493 * Note that areq may be null, in which case we don't bother to set any
494 * request status information.
495 * @param afid Volume FID.
496 * @param areq Request type.
497 * @param locktype Lock to be used.
498 * @return Volume or NULL if no result.
501 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
505 char *bp, tbuf[CVBS];
506 AFS_STATCNT(afs_GetVolume);
508 tv = afs_FindVolume(afid, locktype);
510 /* Do a dynroot check and add dynroot volume if found. */
511 if (afs_IsDynrootAnyFid(afid)) {
512 tv = afs_NewDynrootVolume(afid);
514 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
515 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
525 * @param volid Volume ID. If it's 0, get it from the name.
526 * @param aname Volume name.
527 * @param ve Volume entry.
528 * @param tcell The cell containing this volume.
530 * @param type Type of volume.
531 * @param areq Request.
532 * @return Volume or NULL if failure.
534 static struct volume *
535 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
536 afs_int32 agood, afs_int32 type, struct vrequest *areq)
539 struct vldbentry *ove = (struct vldbentry *)ve;
540 struct nvldbentry *nve = (struct nvldbentry *)ve;
541 struct uvldbentry *uve = (struct uvldbentry *)ve;
543 int whichType; /* which type of volume to look for */
548 /* special hint from file server to use vlserver */
550 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
552 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
557 /* figure out which one we're really interested in (a set is returned) */
558 volid = afs_vtoi(aname);
561 volid = uve->volumeId[whichType];
562 } else if (type == 1) {
563 volid = nve->volumeId[whichType];
565 volid = ove->volumeId[whichType];
567 } /* end of if (volid == 0) */
568 } /* end of if (!volid) */
571 ObtainWriteLock(&afs_xvolume, 108);
573 for (tv = afs_volumes[i]; tv; tv = tv->next) {
574 if (tv->volume == volid && tv->cell == tcell->cellNum) {
579 struct fvolume *tf = 0;
581 tv = afs_GetVolSlot();
583 ReleaseWriteLock(&afs_xvolume);
586 memset(tv, 0, sizeof(struct volume));
588 for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) {
589 if (afs_FVIndex != j) {
590 struct osi_file *tfile;
591 tfile = osi_UFSOpen(&volumeInode);
593 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
594 &staticFVolume, sizeof(struct fvolume));
596 if (err != sizeof(struct fvolume)) {
597 afs_warn("afs_SetupVolume: error %d reading volumeinfo\n",
599 /* put tv back on the free list; the data in it is not valid */
600 tv->next = afs_freeVolList;
601 afs_freeVolList = tv;
602 /* staticFVolume contents are not valid */
604 ReleaseWriteLock(&afs_xvolume);
610 if (tf->cell == tcell->cellNum && tf->volume == volid)
614 tv->cell = tcell->cellNum;
615 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
616 tv->next = afs_volumes[i]; /* thread into list */
620 if (tf && (j != 0)) {
621 tv->vtix = afs_FVIndex;
622 tv->mtpoint = tf->mtpoint;
623 tv->dotdot = tf->dotdot;
624 tv->rootVnode = tf->rootVnode;
625 tv->rootUnique = tf->rootUnique;
628 tv->rootVnode = tv->rootUnique = 0;
629 afs_GetDynrootMountFid(&tv->dotdot);
630 afs_GetDynrootMountFid(&tv->mtpoint);
631 tv->mtpoint.Fid.Vnode =
632 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
633 tv->mtpoint.Fid.Unique = volid;
637 tv->states &= ~VRecheck; /* just checked it */
638 tv->accessTime = osi_Time();
639 ReleaseWriteLock(&afs_xvolume);
641 LockAndInstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
642 } else if (type == 1)
643 LockAndInstallNVolumeEntry(tv, nve, tcell->cellNum);
645 LockAndInstallVolumeEntry(tv, ove, tcell->cellNum);
648 tv->name = afs_osi_Alloc(strlen(aname) + 1);
649 osi_Assert(tv->name != NULL);
650 strcpy(tv->name, aname);
653 for (i = 0; i < NMAXNSERVERS; i++) {
654 tv->status[i] = not_busy;
656 ReleaseWriteLock(&tv->lock);
662 * Seek volume by it's name and attributes.
663 * If volume not found, try to add one.
664 * @param aname Volume name.
668 * @param locktype Type of lock to be used.
672 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
673 struct vrequest *areq, afs_int32 locktype)
678 AFS_STATCNT(afs_GetVolumeByName);
679 ObtainWriteLock(&afs_xvolume, 112);
680 for (i = 0; i < NVOLS; i++) {
681 for (tv = afs_volumes[i]; tv; tv = tv->next) {
682 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
683 && (tv->states & VRecheck) == 0) {
685 ReleaseWriteLock(&afs_xvolume);
691 ReleaseWriteLock(&afs_xvolume);
693 if (AFS_IS_DISCONNECTED)
696 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
701 * Init a new dynroot volume.
703 * @return Volume or NULL if not found.
705 static struct volume *
706 afs_NewDynrootVolume(struct VenusFid *fid)
710 struct vldbentry *tve;
711 char *bp, tbuf[CVBS];
713 tcell = afs_GetCell(fid->Cell, READ_LOCK);
716 tve = afs_osi_Alloc(sizeof(*tve));
717 osi_Assert(tve != NULL);
718 if (!(tcell->states & CHasVolRef))
719 tcell->states |= CHasVolRef;
721 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
722 memset(tve, 0, sizeof(*tve));
723 strcpy(tve->name, "local-dynroot");
724 tve->volumeId[ROVOL] = fid->Fid.Volume;
725 tve->flags = VLF_ROEXISTS;
727 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
728 afs_PutCell(tcell, READ_LOCK);
729 afs_osi_Free(tve, sizeof(*tve));
736 * @param aname Volume name.
737 * @param acell Cell id.
739 * @param areq Request type.
740 * @param locktype Type of lock to be used.
741 * @return Volume or NULL if failure.
743 static struct volume *
744 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
745 struct vrequest *areq, afs_int32 locktype)
747 afs_int32 code, type = 0;
748 struct volume *tv, *tv1;
749 struct vldbentry *tve;
750 struct nvldbentry *ntve;
751 struct uvldbentry *utve;
754 struct afs_conn *tconn;
755 struct vrequest treq;
756 struct rx_connection *rxconn;
758 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
761 tcell = afs_GetCell(acell, READ_LOCK);
766 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
771 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
772 ICL_TYPE_POINTER, aname);
773 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
774 tve = (struct vldbentry *)(tbuffer + 1024);
775 ntve = (struct nvldbentry *)tve;
776 utve = (struct uvldbentry *)tve;
777 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
780 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
781 &treq, SHARED_LOCK, 0, &rxconn);
783 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
786 code = VL_GetEntryByNameO(rxconn, aname, tve);
788 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
791 code = VL_GetEntryByNameN(rxconn, aname, ntve);
796 code = VL_GetEntryByNameU(rxconn, aname, utve);
798 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
799 if (code == RXGEN_OPCODE) {
802 code = VL_GetEntryByNameN(rxconn, aname, ntve);
804 if (code == RXGEN_OPCODE) {
806 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
808 code = VL_GetEntryByNameO(rxconn, aname, tve);
811 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
813 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
819 } while (afs_Analyze(tconn, rxconn, code, NULL, &treq, -1, /* no op code for this */
820 SHARED_LOCK, tcell));
823 /* If the client has yet to contact this cell and contact failed due
824 * to network errors, mark the VLDB servers as back up.
825 * That the client tried and failed can be determined from the
826 * fact that there was a downtime incident, but CHasVolRef is not set.
828 /* RT 48959 - unclear if this should really go */
830 if (areq->networkError && !(tcell->states & CHasVolRef)) {
834 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
835 if ((sp = tcell->cellHosts[i]) == NULL)
837 for (sap = sp->addr; sap; sap = sap->next_sa)
838 afs_MarkServerUpOrDown(sap, 0);
842 afs_CopyError(&treq, areq);
843 osi_FreeLargeSpace(tbuffer);
844 afs_PutCell(tcell, READ_LOCK);
848 * Check to see if this cell has not yet referenced a volume. If
849 * it hasn't, it's just about to change its status, and we need to mark
850 * this fact down. Note that it is remotely possible that afs_SetupVolume
851 * could fail and we would still not have a volume reference.
853 if (!(tcell->states & CHasVolRef)) {
854 tcell->states |= CHasVolRef;
855 afs_stats_cmperf.numCellsContacted++;
857 /*First time a volume in this cell has been referenced */
864 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, &treq);
865 if ((agood == 3) && tv && tv->backVol) {
867 * This means that very soon we'll ask for the BK volume so
868 * we'll prefetch it (well we did already.)
871 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, &treq);
876 if ((agood >= 2) && tv && tv->roVol) {
878 * This means that very soon we'll ask for the RO volume so
879 * we'll prefetch it (well we did already.)
881 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, &treq);
886 osi_FreeLargeSpace(tbuffer);
887 afs_PutCell(tcell, READ_LOCK);
890 } /*afs_NewVolumeByName */
895 * Call this with the volume structure locked; used for new-style vldb requests.
901 LockAndInstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
909 struct server *serverHost[AFS_MAXHOSTS];
911 AFS_STATCNT(InstallVolumeEntry);
913 memset(serverHost, 0, sizeof(serverHost));
915 /* Determine the type of volume we want */
916 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
918 } else if ((ve->flags & VLF_ROEXISTS)
919 && (av->volume == ve->volumeId[ROVOL])) {
922 } else if ((ve->flags & VLF_BACKEXISTS)
923 && (av->volume == ve->volumeId[BACKVOL])) {
924 /* backup always is on the same volume as parent */
926 types |= (VRO | VBackup);
928 mask = 0; /* Can't find volume in vldb entry */
931 cellp = afs_GetCell(acell, 0);
933 /* Step through the VLDB entry making sure each server listed is there */
934 for (i = 0, j = 0; i < ve->nServers; i++) {
935 if (((ve->serverFlags[i] & mask) == 0)
936 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
937 continue; /* wrong volume or don't use this volume */
940 temp = htonl(ve->serverNumber[i]);
941 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
942 (afsUUID *) 0, 0, av);
946 * The cell field could be 0 if the server entry was created
947 * first with the 'fs setserverprefs' call which doesn't set
948 * the cell field. Thus if the afs_GetServer call above
949 * follows later on it will find the server entry thus it will
950 * simply return without setting any fields, so we set the
951 * field ourselves below.
955 afs_PutServer(ts, WRITE_LOCK);
959 ObtainWriteLock(&av->lock, 109);
961 memcpy(av->serverHost, serverHost, sizeof(serverHost));
966 /* fill in volume types */
967 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
968 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
969 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
971 if (ve->flags & VLF_DFSFILESET)
972 av->states |= VForeign;
974 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
975 } /*InstallVolumeEntry */
979 LockAndInstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
987 struct server *serverHost[AFS_MAXHOSTS];
989 AFS_STATCNT(InstallVolumeEntry);
991 memset(serverHost, 0, sizeof(serverHost));
993 /* Determine type of volume we want */
994 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
996 } else if ((ve->flags & VLF_ROEXISTS)
997 && (av->volume == ve->volumeId[ROVOL])) {
1000 } else if ((ve->flags & VLF_BACKEXISTS)
1001 && (av->volume == ve->volumeId[BACKVOL])) {
1002 /* backup always is on the same volume as parent */
1004 types |= (VRO | VBackup);
1006 mask = 0; /* Can't find volume in vldb entry */
1009 cellp = afs_GetCell(acell, 0);
1011 /* Step through the VLDB entry making sure each server listed is there */
1012 for (i = 0, j = 0; i < ve->nServers; i++) {
1013 if (((ve->serverFlags[i] & mask) == 0)
1014 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1015 continue; /* wrong volume or don't use this volume */
1018 temp = htonl(ve->serverNumber[i]);
1019 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1020 (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, 110);
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 } /*InstallNVolumeEntry */
1056 LockAndInstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1057 struct cell *tcell, struct vrequest *areq)
1060 struct afs_conn *tconn;
1063 afs_uint32 serverid;
1067 struct server *serverHost[AFS_MAXHOSTS];
1069 AFS_STATCNT(InstallVolumeEntry);
1071 memset(serverHost, 0, sizeof(serverHost));
1073 /* Determine type of volume we want */
1074 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1076 } else if ((ve->flags & VLF_ROEXISTS)
1077 && av->volume == ve->volumeId[ROVOL]) {
1080 } else if ((ve->flags & VLF_BACKEXISTS)
1081 && (av->volume == ve->volumeId[BACKVOL])) {
1082 /* backup always is on the same volume as parent */
1084 type |= (VRO | VBackup);
1086 mask = 0; /* Can't find volume in vldb entry */
1089 cellp = afs_GetCell(acell, 0);
1091 /* Gather the list of servers the VLDB says the volume is on
1092 * and initialize the ve->serverHost[] array. If a server struct
1093 * is not found, then get the list of addresses for the
1094 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1096 for (i = 0, j = 0; i < ve->nServers; i++) {
1097 if (((ve->serverFlags[i] & mask) == 0)
1098 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1099 continue; /* wrong volume don't use this volume */
1102 if (!(ve->serverFlags[i] & VLSF_UUID)) {
1103 /* The server has no uuid */
1104 serverid = htonl(ve->serverNumber[i].time_low);
1105 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport,
1106 WRITE_LOCK, (afsUUID *) 0, 0, av);
1108 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1109 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1111 /* uuid, uniquifier, and portal are the same */
1113 afs_uint32 *addrp, code;
1114 afs_int32 nentries, unique;
1116 ListAddrByAttributes attrs;
1118 struct rx_connection *rxconn;
1120 memset(&attrs, 0, sizeof(attrs));
1121 attrs.Mask = VLADDR_UUID;
1122 attrs.uuid = ve->serverNumber[i];
1123 memset(&uuid, 0, sizeof(uuid));
1124 memset(&addrs, 0, sizeof(addrs));
1127 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1128 tcell->cellNum, areq, SHARED_LOCK,
1133 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1140 /* Handle corrupt VLDB (defect 7393) */
1141 if (code == 0 && nentries == 0)
1144 } while (afs_Analyze
1145 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1147 /* Better handing of such failures; for now we'll simply retry this call */
1148 areq->volumeError = 1;
1152 addrp = addrs.bulkaddrs_val;
1153 for (k = 0; k < nentries; k++) {
1154 addrp[k] = htonl(addrp[k]);
1156 ts = afs_GetServer(addrp, nentries, acell,
1157 cellp->fsport, WRITE_LOCK,
1158 &ve->serverNumber[i],
1159 ve->serverUnique[i], av);
1160 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1165 /* The cell field could be 0 if the server entry was created
1166 * first with the 'fs setserverprefs' call which doesn't set
1167 * the cell field. Thus if the afs_GetServer call above
1168 * follows later on it will find the server entry thus it will
1169 * simply return without setting any fields, so we set the
1170 * field ourselves below.
1174 afs_PutServer(ts, WRITE_LOCK);
1178 ObtainWriteLock(&av->lock, 111);
1180 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1185 /* fill in volume types */
1186 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1187 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1188 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1190 if (ve->flags & VLF_DFSFILESET)
1191 av->states |= VForeign;
1193 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1194 } /*InstallVolumeEntry */
1198 * Reset volume info for the specified volume strecture. Mark volume
1199 * to be rechecked next time.
1203 afs_ResetVolumeInfo(struct volume *tv)
1207 AFS_STATCNT(afs_ResetVolumeInfo);
1208 ObtainWriteLock(&tv->lock, 117);
1209 tv->states |= VRecheck;
1211 /* the hard-mount code in afs_Analyze may not be able to reset this flag
1212 * when VRecheck is set, so clear it here to ensure it gets cleared. */
1213 tv->states &= ~VHardMount;
1215 for (i = 0; i < AFS_MAXHOSTS; i++)
1216 tv->status[i] = not_busy;
1218 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1221 ReleaseWriteLock(&tv->lock);