1 /* Copyright (C) 1995, 1989, 1998 Transarc Corporation - All rights reserved */
3 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
4 * LICENSED MATERIALS - PROPERTY OF IBM
13 * afs_CheckVolumeNames
16 #include "../afs/param.h" /* Should be always first */
17 #include "../afs/stds.h"
18 #include "../afs/sysincludes.h" /* Standard vendor system headers */
22 #include <netinet/in.h>
25 #include "../h/hashing.h"
27 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV)
28 #include <netinet/in_var.h>
29 #endif /* ! AFS_HPUX110_ENV */
30 #endif /* !defined(UKERNEL) */
32 #include "../afs/afsincludes.h" /* Afs-based standard headers */
33 #include "../afs/afs_stats.h" /* afs statistics */
35 #if defined(AFS_SUN56_ENV)
37 #include <inet/common.h>
41 /* Imported variables */
42 extern afs_rwlock_t afs_xserver;
43 extern afs_rwlock_t afs_xsrvAddr;
44 extern afs_rwlock_t afs_xvcache;
45 extern afs_rwlock_t afs_xcbhash;
46 extern struct srvAddr *afs_srvAddrs[NSERVERS]; /* Hashed by server's ip */
47 extern int afs_totalSrvAddrs;
49 /* In case we don't have the vl error table yet. */
50 #ifndef ERROR_TABLE_BASE_vl
51 #define ERROR_TABLE_BASE_vl (363520L)
52 #define VL_NOENT (363524L)
53 #endif /* vlserver error base define */
56 /* Exported variables */
57 ino_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, int agood,
66 struct vrequest *areq, afs_int32 locktype);
70 /* Convert a volume name to a #; return 0 if can't parse as a number */
71 static int afs_vtoi(aname)
75 register afs_int32 temp;
78 AFS_STATCNT(afs_vtoi);
79 while(tc = *aname++) {
80 if (tc > '9' || tc < '0')
81 return 0; /* invalid name */
91 * All of the vol cache routines must be called with the afs_xvolume
92 * lock held in exclusive mode, since they use static variables.
93 * In addition, we don't want two people adding the same volume
97 static struct fvolume staticFVolume;
98 afs_int32 afs_FVIndex = -1;
100 /* UFS specific version of afs_GetVolSlot */
102 struct volume *afs_UFSGetVolSlot()
105 register struct volume *tv, **lv;
106 register char *tfile;
107 register afs_int32 i, code;
109 struct volume *bestVp, **bestLp;
111 AFS_STATCNT(afs_UFSGetVolSlot);
112 if (!afs_freeVolList) {
114 bestTime = 0x7fffffff;
117 for (i=0;i<NVOLS;i++) {
118 lv = &afs_volumes[i];
119 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
120 if (tv->refCount == 0) { /* is this one available? */
121 if (tv->accessTime < bestTime) { /* best one available? */
122 bestTime = tv->accessTime;
130 osi_Panic("getvolslot none");
134 afs_osi_Free(tv->name, strlen(tv->name)+1);
135 tv->name = (char *) 0;
136 /* now write out volume structure to file */
138 tv->vtix = afs_volCounter++;
139 /* now put on hash chain */
140 i = FVHash(tv->cell, tv->volume);
141 staticFVolume.next = fvTable[i];
146 * Haul the guy in from disk so we don't overwrite hash table
149 if (afs_FVIndex != tv->vtix) {
150 tfile = osi_UFSOpen(volumeInode);
151 code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
152 &staticFVolume, sizeof(struct fvolume));
153 if (code != sizeof(struct fvolume))
154 osi_Panic("read volumeinfo");
156 afs_FVIndex = tv->vtix;
159 afs_FVIndex = tv->vtix;
160 staticFVolume.volume = tv->volume;
161 staticFVolume.cell = tv->cell;
162 staticFVolume.mtpoint = tv->mtpoint;
163 staticFVolume.dotdot = tv->dotdot;
164 staticFVolume.rootVnode = tv->rootVnode;
165 staticFVolume.rootUnique = tv->rootUnique;
166 tfile = osi_UFSOpen(volumeInode);
167 code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
168 &staticFVolume, sizeof(struct fvolume));
169 if (code != sizeof(struct fvolume))
170 osi_Panic("write volumeinfo");
174 tv = afs_freeVolList;
175 afs_freeVolList = tv->next;
179 } /*afs_UFSGetVolSlot*/
182 struct volume *afs_MemGetVolSlot()
185 register struct volume *tv, **lv;
186 register afs_int32 i;
188 struct volume *bestVp, **bestLp;
190 AFS_STATCNT(afs_MemGetVolSlot);
191 if (!afs_freeVolList) {
192 struct volume *newVp;
194 newVp = (struct volume *) afs_osi_Alloc(sizeof(struct volume));
196 newVp->next = (struct volume *)0;
197 afs_freeVolList = newVp;
199 tv = afs_freeVolList;
200 afs_freeVolList = tv->next;
203 } /*afs_MemGetVolSlot*/
205 /* afs_ResetVolumes()
206 * Reset volume inforamation for all volume structs that
207 * point to a speicific server.
209 void afs_ResetVolumes(struct server *srvp)
214 /* Find any volumes residing on this server and flush their state */
215 for (j=0; j<NVOLS; j++) {
216 for (vp=afs_volumes[j]; vp; vp=vp->next) {
217 for (k=0; k<MAXHOSTS; k++) {
218 if (!srvp || (vp->serverHost[k] == srvp)) {
219 afs_ResetVolumeInfo(vp);
228 /* reset volume name to volume id mapping cache */
229 void afs_CheckVolumeNames(flags)
233 extern int osi_dnlc_purge();
237 afs_int32 *volumeID, *cellID, vsize, nvols;
238 AFS_STATCNT(afs_CheckVolumeNames);
241 volumeID = cellID = NULL;
243 ObtainReadLock(&afs_xvolume);
244 if (flags & AFS_VOLCHECK_EXPIRED) {
246 * allocate space to hold the volumeIDs and cellIDs, only if
247 * we will be invalidating the mountpoints later on
249 for (i=0; i< NVOLS; i++)
250 for (tv = afs_volumes[i]; tv; tv=tv->next)
253 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
254 cellID = (volumeID) ? volumeID + vsize : 0;
258 for (i=0;i<NVOLS;i++) {
259 for (tv = afs_volumes[i]; tv; tv=tv->next) {
260 if (flags & AFS_VOLCHECK_EXPIRED) {
261 if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) ||
262 (flags & AFS_VOLCHECK_FORCE)){
263 afs_ResetVolumeInfo(tv); /* also resets status */
265 volumeID[nvols] = tv->volume;
266 cellID[nvols] = tv->cell;
272 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
273 for (j=0; j<MAXHOSTS; j++)
274 tv->status[j] = not_busy;
279 ReleaseReadLock(&afs_xvolume);
282 /* next ensure all mt points are re-evaluated */
283 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
284 ObtainReadLock(&afs_xvcache);
285 for(i=0;i<VCSIZE;i++) {
286 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
288 /* if the volume of "mvid" of the vcache entry is among the
289 * ones we found earlier, then we re-evaluate it. Also, if the
290 * force bit is set or we explicitly asked to reevaluate the
291 * mt-pts, we clean the cmvalid bit */
293 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) ||
295 inVolList(tvc->mvid, nvols, volumeID, cellID)))
296 tvc->states &= ~CMValid;
298 /* If the volume that this file belongs to was reset earlier,
299 * then we should remove its callback.
300 * Again, if forced, always do it.
302 if ((tvc->states & CRO) &&
303 (inVolList(&tvc->fid, nvols, volumeID, cellID) ||
304 (flags & AFS_VOLCHECK_FORCE))) {
307 ReleaseReadLock(&afs_xvcache);
309 ObtainWriteLock(&afs_xcbhash, 485);
310 afs_DequeueCallback(tvc);
311 tvc->states &= ~CStatd;
312 ReleaseWriteLock(&afs_xcbhash);
313 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
314 osi_dnlc_purgedp(tvc);
316 ObtainReadLock(&afs_xvcache);
318 /* our tvc ptr is still good until now */
323 osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */
324 ReleaseReadLock(&afs_xvcache);
328 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
330 } /*afs_CheckVolumeNames*/
333 static inVolList(fid, nvols, vID, cID)
334 struct VenusFid *fid;
335 afs_int32 nvols, *vID, *cID;
339 /* if no arrays present, be conservative and return true */
340 if ( nvols && (!vID || !cID))
343 for (i=0; i< nvols; ++i) {
344 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
351 /* afs_PutVolume is now a macro in afs.h */
355 * return volume struct if we have it cached and it's up-to-date
357 * Environment: Must be called with afs_xvolume unlocked.
359 struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
367 i = VHash(afid->Fid.Volume);
368 ObtainWriteLock(&afs_xvolume,106);
369 for (tv = afs_volumes[i]; tv; tv=tv->next) {
370 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
371 && (tv->states & VRecheck) == 0) {
376 ReleaseWriteLock(&afs_xvolume);
377 return tv; /* NULL if we didn't find it */
383 * Note that areq may be null, in which case we don't bother to set any
384 * request status information.
386 struct volume *afs_GetVolume(afid, areq, locktype)
387 struct vrequest *areq;
388 struct VenusFid *afid;
392 char *bp, tbuf[CVBS];
393 AFS_STATCNT(afs_GetVolume);
395 tv = afs_FindVolume(afid, locktype);
397 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
398 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
405 static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq)
408 afs_int32 volid, agood, type;
410 struct vrequest *areq;
413 struct vldbentry *ove = (struct vldbentry *)ve;
414 struct nvldbentry *nve = (struct nvldbentry *)ve;
415 struct uvldbentry *uve = (struct uvldbentry *)ve;
417 int whichType; /* which type of volume to look for */
422 /* special hint from file server to use vlserver */
424 if (len >= 8 && strcmp(aname+len-7, ".backup") == 0)
426 else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0)
431 /* figure out which one we're really interested in (a set is returned) */
432 volid = afs_vtoi(aname);
435 volid = uve->volumeId[whichType];
437 else if (type == 1) {
438 volid = nve->volumeId[whichType];
441 volid = ove->volumeId[whichType];
447 ObtainWriteLock(&afs_xvolume,108);
449 for (tv = afs_volumes[i]; tv; tv=tv->next) {
450 if (tv->volume == volid && tv->cell == tcell->cell) {
455 struct fvolume *tf=0;
457 tv = afs_GetVolSlot();
458 bzero((char *)tv, sizeof(struct volume));
459 tv->cell = tcell->cell;
460 RWLOCK_INIT(&tv->lock, "volume lock");
461 tv->next = afs_volumes[i]; /* thread into list */
464 for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) {
465 if (afs_FVIndex != j) {
467 tfile = osi_UFSOpen(volumeInode);
468 err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume));
469 if (err != sizeof(struct fvolume))
470 osi_Panic("read volumeinfo2");
475 if (tf->cell == tv->cell && tf->volume == volid)
478 if (tf && (j != 0)) {
479 tv->vtix = afs_FVIndex;
480 tv->mtpoint = tf->mtpoint;
481 tv->dotdot = tf->dotdot;
482 tv->rootVnode = tf->rootVnode;
483 tv->rootUnique = tf->rootUnique;
486 tv->rootVnode = tv->rootUnique = 0;
490 tv->states &= ~VRecheck; /* just checked it */
491 tv->accessTime = osi_Time();
492 ReleaseWriteLock(&afs_xvolume);
493 ObtainWriteLock(&tv->lock,111);
495 InstallUVolumeEntry(tv, uve, tcell->cell, tcell, areq);
498 InstallNVolumeEntry(tv, nve, tcell->cell);
500 InstallVolumeEntry(tv, ove, tcell->cell);
503 tv->name = afs_osi_Alloc(strlen(aname) + 1);
504 strcpy(tv->name, aname);
507 for (i=0; i<NMAXNSERVERS; i++) {
508 tv->status[i] = not_busy;
510 ReleaseWriteLock(&tv->lock);
515 struct volume *afs_GetVolumeByName(aname, acell, agood, areq, locktype)
516 struct vrequest *areq;
519 register char *aname;
525 AFS_STATCNT(afs_GetVolumeByName);
526 ObtainWriteLock(&afs_xvolume,112);
527 for (i=0;i<NVOLS;i++) {
528 for (tv = afs_volumes[i]; tv; tv=tv->next) {
529 if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell
530 && (tv->states&VRecheck) == 0) {
532 ReleaseWriteLock(&afs_xvolume);
538 ReleaseWriteLock(&afs_xvolume);
540 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
545 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
546 struct vrequest *areq, afs_int32 locktype)
548 afs_int32 code, i, type=0;
549 struct volume *tv, *tv1;
550 struct vldbentry *tve;
551 struct nvldbentry *ntve;
552 struct uvldbentry *utve;
556 struct vrequest treq;
559 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
560 return (struct volume *) 0;
562 tcell = afs_GetCell(acell, READ_LOCK);
564 return (struct volume *) 0;
567 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
568 if (!areq) areq = &treq;
571 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
572 ICL_TYPE_POINTER, aname);
573 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
574 tve = (struct vldbentry *) (tbuffer+1024);
575 ntve = (struct nvldbentry *)tve;
576 utve = (struct uvldbentry *)tve;
577 afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
579 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
580 tcell->cell, &treq, SHARED_LOCK);
582 if (tconn->srvr->server->flags & SNO_LHOSTS) {
584 #ifdef RX_ENABLE_LOCKS
586 #endif /* RX_ENABLE_LOCKS */
587 code = VL_GetEntryByNameO(tconn->id, aname, tve);
588 #ifdef RX_ENABLE_LOCKS
590 #endif /* RX_ENABLE_LOCKS */
591 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
593 #ifdef RX_ENABLE_LOCKS
595 #endif /* RX_ENABLE_LOCKS */
596 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
597 #ifdef RX_ENABLE_LOCKS
599 #endif /* RX_ENABLE_LOCKS */
602 #ifdef RX_ENABLE_LOCKS
604 #endif /* RX_ENABLE_LOCKS */
605 code = VL_GetEntryByNameU(tconn->id, aname, utve);
606 #ifdef RX_ENABLE_LOCKS
608 #endif /* RX_ENABLE_LOCKS */
609 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
610 if (code == RXGEN_OPCODE) {
612 #ifdef RX_ENABLE_LOCKS
614 #endif /* RX_ENABLE_LOCKS */
615 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
616 #ifdef RX_ENABLE_LOCKS
618 #endif /* RX_ENABLE_LOCKS */
619 if (code == RXGEN_OPCODE) {
621 tconn->srvr->server->flags |= SNO_LHOSTS;
622 #ifdef RX_ENABLE_LOCKS
624 #endif /* RX_ENABLE_LOCKS */
625 code = VL_GetEntryByNameO(tconn->id, aname, tve);
626 #ifdef RX_ENABLE_LOCKS
628 #endif /* RX_ENABLE_LOCKS */
630 tconn->srvr->server->flags |= SYES_LHOSTS;
632 tconn->srvr->server->flags |= SVLSRV_UUID;
639 (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
640 -1, /* no op code for this */
641 SHARED_LOCK, tcell));
644 /* If the client has yet to contact this cell and contact failed due
645 * to network errors, mark the VLDB servers as back up.
646 * That the client tried and failed can be determined from the
647 * fact that there was a downtime incident, but CHasVolRef is not set.
649 if (areq->networkError && !(tcell->states & CHasVolRef)) {
653 for (i=0; i<MAXCELLHOSTS; i++) {
654 if ((sp = tcell->cellHosts[i]) == (struct server *) 0) break;
655 for (sap = sp->addr; sap; sap = sap->next_sa)
656 afs_MarkServerUpOrDown(sap, 0);
659 afs_CopyError(&treq, areq);
660 osi_FreeLargeSpace(tbuffer);
661 afs_PutCell(tcell, READ_LOCK);
662 return (struct volume *) 0;
665 * Check to see if this cell has not yet referenced a volume. If
666 * it hasn't, it's just about to change its status, and we need to mark
667 * this fact down. Note that it is remotely possible that afs_SetupVolume
668 * could fail and we would still not have a volume reference.
670 if (!(tcell->states & CHasVolRef)) {
671 tcell->states |= CHasVolRef;
672 afs_stats_cmperf.numCellsContacted++;
673 } /*First time a volume in this cell has been referenced*/
681 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
682 if ((agood == 2) && tv->roVol) {
684 * This means that very soon we'll ask for the RO volume so
685 * we'll prefetch it (well we did already.)
687 tv1 = afs_SetupVolume(tv->roVol, (char *)0, ve, tcell, 0, type, areq);
690 osi_FreeLargeSpace(tbuffer);
691 afs_PutCell(tcell, READ_LOCK);
694 } /*afs_NewVolumeByName*/
698 /* call this with the volume structure locked; used for new-style vldb requests */
699 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
701 register struct server *ts;
707 AFS_STATCNT(InstallVolumeEntry);
709 /* Determine the type of volume we want */
710 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
713 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
717 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
718 /* backup always is on the same volume as parent */
720 av->states |= (VRO|VBackup);
723 mask = 0; /* Can't find volume in vldb entry */
726 /* fill in volume types */
727 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
728 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
729 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
731 if (ve->flags & VLF_DFSFILESET)
732 av->states |= VForeign;
734 cellp = afs_GetCell(acell, 0);
736 /* Step through the VLDB entry making sure each server listed is there */
737 for (i=0,j=0; i<ve->nServers; i++) {
738 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
739 continue; /* wrong volume or don't use this volume */
742 temp = htonl(ve->serverNumber[i]);
743 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
744 av->serverHost[j] = ts;
747 * The cell field could be 0 if the server entry was created
748 * first with the 'fs setserverprefs' call which doesn't set
749 * the cell field. Thus if the afs_GetServer call above
750 * follows later on it will find the server entry thus it will
751 * simply return without setting any fields, so we set the
752 * field ourselves below.
756 afs_PutServer(ts, WRITE_LOCK);
760 av->serverHost[j++] = 0;
762 afs_SortServers(av->serverHost, MAXHOSTS);
763 } /*InstallVolumeEntry*/
766 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
768 register struct server *ts;
774 AFS_STATCNT(InstallVolumeEntry);
776 /* Determine type of volume we want */
777 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
780 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
784 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
785 /* backup always is on the same volume as parent */
787 av->states |= (VRO|VBackup);
790 mask = 0; /* Can't find volume in vldb entry */
793 /* fill in volume types */
794 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
795 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
796 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
798 if (ve->flags & VLF_DFSFILESET)
799 av->states |= VForeign;
801 cellp = afs_GetCell(acell, 0);
803 /* Step through the VLDB entry making sure each server listed is there */
804 for (i=0,j=0; i<ve->nServers; i++) {
805 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
806 continue; /* wrong volume or don't use this volume */
809 temp = htonl(ve->serverNumber[i]);
810 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
811 av->serverHost[j] = ts;
813 * The cell field could be 0 if the server entry was created
814 * first with the 'fs setserverprefs' call which doesn't set
815 * the cell field. Thus if the afs_GetServer call above
816 * follows later on it will find the server entry thus it will
817 * simply return without setting any fields, so we set the
818 * field ourselves below.
822 afs_PutServer(ts, WRITE_LOCK);
826 av->serverHost[j++] = 0;
828 afs_SortServers(av->serverHost, MAXHOSTS);
829 } /*InstallNVolumeEntry*/
832 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
833 int acell, struct cell *tcell, struct vrequest *areq)
835 register struct srvAddr *sa;
836 register struct server *ts;
844 AFS_STATCNT(InstallVolumeEntry);
846 /* Determine type of volume we want */
847 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
850 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
854 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
855 /* backup always is on the same volume as parent */
857 av->states |= (VRO|VBackup);
860 mask = 0; /* Can't find volume in vldb entry */
863 /* fill in volume types */
864 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
865 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
866 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
868 if (ve->flags & VLF_DFSFILESET)
869 av->states |= VForeign;
871 cellp = afs_GetCell(acell, 0);
873 /* This volume, av, is locked. Zero out the serverHosts[] array
874 * so that if afs_GetServer() decides to replace the server
875 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
878 for (j=0; j<MAXHOSTS; j++) {
879 av->serverHost[j] = 0;
882 /* Gather the list of servers the VLDB says the volume is on
883 * and initialize the ve->serverHost[] array. If a server struct
884 * is not found, then get the list of addresses for the
885 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
887 for (i=0,j=0; i<ve->nServers; i++) {
888 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
889 continue; /* wrong volume don't use this volume */
892 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
893 /* The server has no uuid */
894 serverid = htonl(ve->serverNumber[i].time_low);
895 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
897 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
898 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
899 /* uuid, uniquifier, and portal are the same */
901 afs_uint32 *addrp, nentries, code, unique;
903 ListAddrByAttributes attrs;
906 bzero((char *)&attrs, sizeof(attrs));
907 attrs.Mask = VLADDR_UUID;
908 attrs.uuid = ve->serverNumber[i];
909 bzero((char *)&uuid, sizeof(uuid));
910 bzero((char *)&addrs, sizeof(addrs));
912 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
913 tcell->cell, areq, SHARED_LOCK);
915 #ifdef RX_ENABLE_LOCKS
917 #endif /* RX_ENABLE_LOCKS */
918 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
919 #ifdef RX_ENABLE_LOCKS
921 #endif /* RX_ENABLE_LOCKS */
926 /* Handle corrupt VLDB (defect 7393) */
927 if (code == 0 && nentries == 0)
930 } while (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
931 -1, SHARED_LOCK, tcell));
933 /* Better handing of such failures; for now we'll simply retry this call */
934 areq->volumeError = 1;
938 addrp = addrs.bulkaddrs_val;
939 for (k = 0; k < nentries; k++) {
940 addrp[k] = htonl(addrp[k]);
942 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
943 WRITE_LOCK, &ve->serverNumber[i],
944 ve->serverUnique[i]);
945 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
948 av->serverHost[j] = ts;
950 /* The cell field could be 0 if the server entry was created
951 * first with the 'fs setserverprefs' call which doesn't set
952 * the cell field. Thus if the afs_GetServer call above
953 * follows later on it will find the server entry thus it will
954 * simply return without setting any fields, so we set the
955 * field ourselves below.
959 afs_PutServer(ts, WRITE_LOCK);
963 afs_SortServers(av->serverHost, MAXHOSTS);
964 } /*InstallVolumeEntry*/
967 void afs_ResetVolumeInfo(struct volume *tv)
971 AFS_STATCNT(afs_ResetVolumeInfo);
972 ObtainWriteLock(&tv->lock,117);
973 tv->states |= VRecheck;
974 for (i=0; i<MAXHOSTS; i++)
975 tv->status[i] = not_busy;
977 afs_osi_Free(tv->name, strlen(tv->name)+1);
978 tv->name = (char *) 0;
980 ReleaseWriteLock(&tv->lock);
981 } /*afs_ResetVolumeInfo*/