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/stds.h"
24 #include "../afs/sysincludes.h" /* Standard vendor system headers */
28 #include <netinet/in.h>
31 #include "../h/hashing.h"
33 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV)
34 #include <netinet/in_var.h>
35 #endif /* ! AFS_HPUX110_ENV */
36 #endif /* !defined(UKERNEL) */
38 #include "../afs/afsincludes.h" /* Afs-based standard headers */
39 #include "../afs/afs_stats.h" /* afs statistics */
41 #if defined(AFS_SUN56_ENV)
43 #include <inet/common.h>
44 #if defined(AFS_SUN58_ENV)
45 #include <netinet/ip6.h>
50 /* Imported variables */
51 extern afs_rwlock_t afs_xserver;
52 extern afs_rwlock_t afs_xsrvAddr;
53 extern afs_rwlock_t afs_xvcache;
54 extern afs_rwlock_t afs_xcbhash;
55 extern struct srvAddr *afs_srvAddrs[NSERVERS]; /* Hashed by server's ip */
56 extern int afs_totalSrvAddrs;
58 /* In case we don't have the vl error table yet. */
59 #ifndef ERROR_TABLE_BASE_vl
60 #define ERROR_TABLE_BASE_vl (363520L)
61 #define VL_NOENT (363524L)
62 #endif /* vlserver error base define */
65 /* Exported variables */
66 ino_t volumeInode; /*Inode for VolumeItems file*/
67 afs_rwlock_t afs_xvolume; /* allocation lock for volumes */
68 struct volume *afs_freeVolList;
69 struct volume *afs_volumes[NVOLS];
70 afs_int32 afs_volCounter = 1; /* for allocating volume indices */
71 afs_int32 fvTable[NFENTRIES];
73 /* Forward declarations */
74 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
75 struct vrequest *areq, afs_int32 locktype);
79 /* Convert a volume name to a #; return 0 if can't parse as a number */
80 static int afs_vtoi(aname)
84 register afs_int32 temp;
87 AFS_STATCNT(afs_vtoi);
88 while(tc = *aname++) {
89 if (tc > '9' || tc < '0')
90 return 0; /* invalid name */
100 * All of the vol cache routines must be called with the afs_xvolume
101 * lock held in exclusive mode, since they use static variables.
102 * In addition, we don't want two people adding the same volume
106 static struct fvolume staticFVolume;
107 afs_int32 afs_FVIndex = -1;
109 /* UFS specific version of afs_GetVolSlot */
111 struct volume *afs_UFSGetVolSlot()
114 register struct volume *tv, **lv;
115 register char *tfile;
116 register afs_int32 i, code;
118 struct volume *bestVp, **bestLp;
120 AFS_STATCNT(afs_UFSGetVolSlot);
121 if (!afs_freeVolList) {
123 bestTime = 0x7fffffff;
126 for (i=0;i<NVOLS;i++) {
127 lv = &afs_volumes[i];
128 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
129 if (tv->refCount == 0) { /* is this one available? */
130 if (tv->accessTime < bestTime) { /* best one available? */
131 bestTime = tv->accessTime;
139 osi_Panic("getvolslot none");
143 afs_osi_Free(tv->name, strlen(tv->name)+1);
144 tv->name = (char *) 0;
145 /* now write out volume structure to file */
147 tv->vtix = afs_volCounter++;
148 /* now put on hash chain */
149 i = FVHash(tv->cell, tv->volume);
150 staticFVolume.next = fvTable[i];
155 * Haul the guy in from disk so we don't overwrite hash table
158 if (afs_FVIndex != tv->vtix) {
159 tfile = osi_UFSOpen(volumeInode);
160 code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
161 &staticFVolume, sizeof(struct fvolume));
162 if (code != sizeof(struct fvolume))
163 osi_Panic("read volumeinfo");
165 afs_FVIndex = tv->vtix;
168 afs_FVIndex = tv->vtix;
169 staticFVolume.volume = tv->volume;
170 staticFVolume.cell = tv->cell;
171 staticFVolume.mtpoint = tv->mtpoint;
172 staticFVolume.dotdot = tv->dotdot;
173 staticFVolume.rootVnode = tv->rootVnode;
174 staticFVolume.rootUnique = tv->rootUnique;
175 tfile = osi_UFSOpen(volumeInode);
176 code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
177 &staticFVolume, sizeof(struct fvolume));
178 if (code != sizeof(struct fvolume))
179 osi_Panic("write volumeinfo");
183 tv = afs_freeVolList;
184 afs_freeVolList = tv->next;
188 } /*afs_UFSGetVolSlot*/
191 struct volume *afs_MemGetVolSlot()
194 register struct volume *tv, **lv;
195 register afs_int32 i;
197 struct volume *bestVp, **bestLp;
199 AFS_STATCNT(afs_MemGetVolSlot);
200 if (!afs_freeVolList) {
201 struct volume *newVp;
203 newVp = (struct volume *) afs_osi_Alloc(sizeof(struct volume));
205 newVp->next = (struct volume *)0;
206 afs_freeVolList = newVp;
208 tv = afs_freeVolList;
209 afs_freeVolList = tv->next;
212 } /*afs_MemGetVolSlot*/
214 /* afs_ResetVolumes()
215 * Reset volume inforamation for all volume structs that
216 * point to a speicific server.
218 void afs_ResetVolumes(struct server *srvp)
223 /* Find any volumes residing on this server and flush their state */
224 for (j=0; j<NVOLS; j++) {
225 for (vp=afs_volumes[j]; vp; vp=vp->next) {
226 for (k=0; k<MAXHOSTS; k++) {
227 if (!srvp || (vp->serverHost[k] == srvp)) {
228 afs_ResetVolumeInfo(vp);
237 /* reset volume name to volume id mapping cache */
238 void afs_CheckVolumeNames(flags)
242 extern int osi_dnlc_purge();
246 afs_int32 *volumeID, *cellID, vsize, nvols;
247 AFS_STATCNT(afs_CheckVolumeNames);
250 volumeID = cellID = NULL;
252 ObtainReadLock(&afs_xvolume);
253 if (flags & AFS_VOLCHECK_EXPIRED) {
255 * allocate space to hold the volumeIDs and cellIDs, only if
256 * we will be invalidating the mountpoints later on
258 for (i=0; i< NVOLS; i++)
259 for (tv = afs_volumes[i]; tv; tv=tv->next)
262 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
263 cellID = (volumeID) ? volumeID + vsize : 0;
267 for (i=0;i<NVOLS;i++) {
268 for (tv = afs_volumes[i]; tv; tv=tv->next) {
269 if (flags & AFS_VOLCHECK_EXPIRED) {
270 if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) ||
271 (flags & AFS_VOLCHECK_FORCE)){
272 afs_ResetVolumeInfo(tv); /* also resets status */
274 volumeID[nvols] = tv->volume;
275 cellID[nvols] = tv->cell;
281 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
282 for (j=0; j<MAXHOSTS; j++)
283 tv->status[j] = not_busy;
288 ReleaseReadLock(&afs_xvolume);
291 /* next ensure all mt points are re-evaluated */
292 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
293 ObtainReadLock(&afs_xvcache);
294 for(i=0;i<VCSIZE;i++) {
295 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
297 /* if the volume of "mvid" of the vcache entry is among the
298 * ones we found earlier, then we re-evaluate it. Also, if the
299 * force bit is set or we explicitly asked to reevaluate the
300 * mt-pts, we clean the cmvalid bit */
302 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) ||
304 inVolList(tvc->mvid, nvols, volumeID, cellID)))
305 tvc->states &= ~CMValid;
307 /* If the volume that this file belongs to was reset earlier,
308 * then we should remove its callback.
309 * Again, if forced, always do it.
311 if ((tvc->states & CRO) &&
312 (inVolList(&tvc->fid, nvols, volumeID, cellID) ||
313 (flags & AFS_VOLCHECK_FORCE))) {
316 ReleaseReadLock(&afs_xvcache);
318 ObtainWriteLock(&afs_xcbhash, 485);
319 afs_DequeueCallback(tvc);
320 tvc->states &= ~CStatd;
321 ReleaseWriteLock(&afs_xcbhash);
322 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
323 osi_dnlc_purgedp(tvc);
325 ObtainReadLock(&afs_xvcache);
327 /* our tvc ptr is still good until now */
332 osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */
333 ReleaseReadLock(&afs_xvcache);
337 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
339 } /*afs_CheckVolumeNames*/
342 static inVolList(fid, nvols, vID, cID)
343 struct VenusFid *fid;
344 afs_int32 nvols, *vID, *cID;
348 /* if no arrays present, be conservative and return true */
349 if ( nvols && (!vID || !cID))
352 for (i=0; i< nvols; ++i) {
353 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
360 /* afs_PutVolume is now a macro in afs.h */
364 * return volume struct if we have it cached and it's up-to-date
366 * Environment: Must be called with afs_xvolume unlocked.
368 struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
376 i = VHash(afid->Fid.Volume);
377 ObtainWriteLock(&afs_xvolume,106);
378 for (tv = afs_volumes[i]; tv; tv=tv->next) {
379 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
380 && (tv->states & VRecheck) == 0) {
385 ReleaseWriteLock(&afs_xvolume);
386 return tv; /* NULL if we didn't find it */
392 * Note that areq may be null, in which case we don't bother to set any
393 * request status information.
395 struct volume *afs_GetVolume(afid, areq, locktype)
396 struct vrequest *areq;
397 struct VenusFid *afid;
401 char *bp, tbuf[CVBS];
402 AFS_STATCNT(afs_GetVolume);
404 tv = afs_FindVolume(afid, locktype);
406 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
407 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
414 static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq)
417 afs_int32 volid, agood, type;
419 struct vrequest *areq;
422 struct vldbentry *ove = (struct vldbentry *)ve;
423 struct nvldbentry *nve = (struct nvldbentry *)ve;
424 struct uvldbentry *uve = (struct uvldbentry *)ve;
426 int whichType; /* which type of volume to look for */
431 /* special hint from file server to use vlserver */
433 if (len >= 8 && strcmp(aname+len-7, ".backup") == 0)
435 else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0)
440 /* figure out which one we're really interested in (a set is returned) */
441 volid = afs_vtoi(aname);
444 volid = uve->volumeId[whichType];
446 else if (type == 1) {
447 volid = nve->volumeId[whichType];
450 volid = ove->volumeId[whichType];
456 ObtainWriteLock(&afs_xvolume,108);
458 for (tv = afs_volumes[i]; tv; tv=tv->next) {
459 if (tv->volume == volid && tv->cell == tcell->cell) {
464 struct fvolume *tf=0;
466 tv = afs_GetVolSlot();
467 memset((char *)tv, 0, sizeof(struct volume));
468 tv->cell = tcell->cell;
469 RWLOCK_INIT(&tv->lock, "volume lock");
470 tv->next = afs_volumes[i]; /* thread into list */
473 for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) {
474 if (afs_FVIndex != j) {
476 tfile = osi_UFSOpen(volumeInode);
477 err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume));
478 if (err != sizeof(struct fvolume))
479 osi_Panic("read volumeinfo2");
484 if (tf->cell == tv->cell && tf->volume == volid)
487 if (tf && (j != 0)) {
488 tv->vtix = afs_FVIndex;
489 tv->mtpoint = tf->mtpoint;
490 tv->dotdot = tf->dotdot;
491 tv->rootVnode = tf->rootVnode;
492 tv->rootUnique = tf->rootUnique;
495 tv->rootVnode = tv->rootUnique = 0;
499 tv->states &= ~VRecheck; /* just checked it */
500 tv->accessTime = osi_Time();
501 ReleaseWriteLock(&afs_xvolume);
502 ObtainWriteLock(&tv->lock,111);
504 InstallUVolumeEntry(tv, uve, tcell->cell, tcell, areq);
507 InstallNVolumeEntry(tv, nve, tcell->cell);
509 InstallVolumeEntry(tv, ove, tcell->cell);
512 tv->name = afs_osi_Alloc(strlen(aname) + 1);
513 strcpy(tv->name, aname);
516 for (i=0; i<NMAXNSERVERS; i++) {
517 tv->status[i] = not_busy;
519 ReleaseWriteLock(&tv->lock);
524 struct volume *afs_GetVolumeByName(aname, acell, agood, areq, locktype)
525 struct vrequest *areq;
528 register char *aname;
534 AFS_STATCNT(afs_GetVolumeByName);
535 ObtainWriteLock(&afs_xvolume,112);
536 for (i=0;i<NVOLS;i++) {
537 for (tv = afs_volumes[i]; tv; tv=tv->next) {
538 if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell
539 && (tv->states&VRecheck) == 0) {
541 ReleaseWriteLock(&afs_xvolume);
547 ReleaseWriteLock(&afs_xvolume);
549 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
554 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
555 struct vrequest *areq, afs_int32 locktype)
557 afs_int32 code, i, type=0;
558 struct volume *tv, *tv1;
559 struct vldbentry *tve;
560 struct nvldbentry *ntve;
561 struct uvldbentry *utve;
565 struct vrequest treq;
568 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
569 return (struct volume *) 0;
571 tcell = afs_GetCell(acell, READ_LOCK);
573 return (struct volume *) 0;
576 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
577 if (!areq) areq = &treq;
580 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
581 ICL_TYPE_POINTER, aname);
582 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
583 tve = (struct vldbentry *) (tbuffer+1024);
584 ntve = (struct nvldbentry *)tve;
585 utve = (struct uvldbentry *)tve;
586 afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
588 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
589 tcell->cell, &treq, SHARED_LOCK);
591 if (tconn->srvr->server->flags & SNO_LHOSTS) {
593 #ifdef RX_ENABLE_LOCKS
595 #endif /* RX_ENABLE_LOCKS */
596 code = VL_GetEntryByNameO(tconn->id, aname, tve);
597 #ifdef RX_ENABLE_LOCKS
599 #endif /* RX_ENABLE_LOCKS */
600 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
602 #ifdef RX_ENABLE_LOCKS
604 #endif /* RX_ENABLE_LOCKS */
605 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
606 #ifdef RX_ENABLE_LOCKS
608 #endif /* RX_ENABLE_LOCKS */
611 #ifdef RX_ENABLE_LOCKS
613 #endif /* RX_ENABLE_LOCKS */
614 code = VL_GetEntryByNameU(tconn->id, aname, utve);
615 #ifdef RX_ENABLE_LOCKS
617 #endif /* RX_ENABLE_LOCKS */
618 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
619 if (code == RXGEN_OPCODE) {
621 #ifdef RX_ENABLE_LOCKS
623 #endif /* RX_ENABLE_LOCKS */
624 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
625 #ifdef RX_ENABLE_LOCKS
627 #endif /* RX_ENABLE_LOCKS */
628 if (code == RXGEN_OPCODE) {
630 tconn->srvr->server->flags |= SNO_LHOSTS;
631 #ifdef RX_ENABLE_LOCKS
633 #endif /* RX_ENABLE_LOCKS */
634 code = VL_GetEntryByNameO(tconn->id, aname, tve);
635 #ifdef RX_ENABLE_LOCKS
637 #endif /* RX_ENABLE_LOCKS */
639 tconn->srvr->server->flags |= SYES_LHOSTS;
641 tconn->srvr->server->flags |= SVLSRV_UUID;
648 (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
649 -1, /* no op code for this */
650 SHARED_LOCK, tcell));
653 /* If the client has yet to contact this cell and contact failed due
654 * to network errors, mark the VLDB servers as back up.
655 * That the client tried and failed can be determined from the
656 * fact that there was a downtime incident, but CHasVolRef is not set.
658 if (areq->networkError && !(tcell->states & CHasVolRef)) {
662 for (i=0; i<MAXCELLHOSTS; i++) {
663 if ((sp = tcell->cellHosts[i]) == (struct server *) 0) break;
664 for (sap = sp->addr; sap; sap = sap->next_sa)
665 afs_MarkServerUpOrDown(sap, 0);
668 afs_CopyError(&treq, areq);
669 osi_FreeLargeSpace(tbuffer);
670 afs_PutCell(tcell, READ_LOCK);
671 return (struct volume *) 0;
674 * Check to see if this cell has not yet referenced a volume. If
675 * it hasn't, it's just about to change its status, and we need to mark
676 * this fact down. Note that it is remotely possible that afs_SetupVolume
677 * could fail and we would still not have a volume reference.
679 if (!(tcell->states & CHasVolRef)) {
680 tcell->states |= CHasVolRef;
681 afs_stats_cmperf.numCellsContacted++;
682 } /*First time a volume in this cell has been referenced*/
690 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
691 if ((agood == 2) && tv->roVol) {
693 * This means that very soon we'll ask for the RO volume so
694 * we'll prefetch it (well we did already.)
696 tv1 = afs_SetupVolume(tv->roVol, (char *)0, ve, tcell, 0, type, areq);
699 osi_FreeLargeSpace(tbuffer);
700 afs_PutCell(tcell, READ_LOCK);
703 } /*afs_NewVolumeByName*/
707 /* call this with the volume structure locked; used for new-style vldb requests */
708 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
710 register struct server *ts;
716 AFS_STATCNT(InstallVolumeEntry);
718 /* Determine the type of volume we want */
719 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
722 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
726 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
727 /* backup always is on the same volume as parent */
729 av->states |= (VRO|VBackup);
732 mask = 0; /* Can't find volume in vldb entry */
735 /* fill in volume types */
736 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
737 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
738 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
740 if (ve->flags & VLF_DFSFILESET)
741 av->states |= VForeign;
743 cellp = afs_GetCell(acell, 0);
745 /* Step through the VLDB entry making sure each server listed is there */
746 for (i=0,j=0; i<ve->nServers; i++) {
747 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
748 continue; /* wrong volume or don't use this volume */
751 temp = htonl(ve->serverNumber[i]);
752 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
753 av->serverHost[j] = ts;
756 * The cell field could be 0 if the server entry was created
757 * first with the 'fs setserverprefs' call which doesn't set
758 * the cell field. Thus if the afs_GetServer call above
759 * follows later on it will find the server entry thus it will
760 * simply return without setting any fields, so we set the
761 * field ourselves below.
765 afs_PutServer(ts, WRITE_LOCK);
769 av->serverHost[j++] = 0;
771 afs_SortServers(av->serverHost, MAXHOSTS);
772 } /*InstallVolumeEntry*/
775 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
777 register struct server *ts;
783 AFS_STATCNT(InstallVolumeEntry);
785 /* Determine type of volume we want */
786 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
789 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
793 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
794 /* backup always is on the same volume as parent */
796 av->states |= (VRO|VBackup);
799 mask = 0; /* Can't find volume in vldb entry */
802 /* fill in volume types */
803 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
804 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
805 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
807 if (ve->flags & VLF_DFSFILESET)
808 av->states |= VForeign;
810 cellp = afs_GetCell(acell, 0);
812 /* Step through the VLDB entry making sure each server listed is there */
813 for (i=0,j=0; i<ve->nServers; i++) {
814 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
815 continue; /* wrong volume or don't use this volume */
818 temp = htonl(ve->serverNumber[i]);
819 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
820 av->serverHost[j] = ts;
822 * The cell field could be 0 if the server entry was created
823 * first with the 'fs setserverprefs' call which doesn't set
824 * the cell field. Thus if the afs_GetServer call above
825 * follows later on it will find the server entry thus it will
826 * simply return without setting any fields, so we set the
827 * field ourselves below.
831 afs_PutServer(ts, WRITE_LOCK);
835 av->serverHost[j++] = 0;
837 afs_SortServers(av->serverHost, MAXHOSTS);
838 } /*InstallNVolumeEntry*/
841 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
842 int acell, struct cell *tcell, struct vrequest *areq)
844 register struct srvAddr *sa;
845 register struct server *ts;
853 AFS_STATCNT(InstallVolumeEntry);
855 /* Determine type of volume we want */
856 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
859 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
863 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
864 /* backup always is on the same volume as parent */
866 av->states |= (VRO|VBackup);
869 mask = 0; /* Can't find volume in vldb entry */
872 /* fill in volume types */
873 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
874 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
875 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
877 if (ve->flags & VLF_DFSFILESET)
878 av->states |= VForeign;
880 cellp = afs_GetCell(acell, 0);
882 /* This volume, av, is locked. Zero out the serverHosts[] array
883 * so that if afs_GetServer() decides to replace the server
884 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
887 for (j=0; j<MAXHOSTS; j++) {
888 av->serverHost[j] = 0;
891 /* Gather the list of servers the VLDB says the volume is on
892 * and initialize the ve->serverHost[] array. If a server struct
893 * is not found, then get the list of addresses for the
894 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
896 for (i=0,j=0; i<ve->nServers; i++) {
897 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
898 continue; /* wrong volume don't use this volume */
901 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
902 /* The server has no uuid */
903 serverid = htonl(ve->serverNumber[i].time_low);
904 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
906 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
907 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
908 /* uuid, uniquifier, and portal are the same */
910 afs_uint32 *addrp, nentries, code, unique;
912 ListAddrByAttributes attrs;
915 memset((char *)&attrs, 0, sizeof(attrs));
916 attrs.Mask = VLADDR_UUID;
917 attrs.uuid = ve->serverNumber[i];
918 memset((char *)&uuid, 0, sizeof(uuid));
919 memset((char *)&addrs, 0, sizeof(addrs));
921 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
922 tcell->cell, areq, SHARED_LOCK);
924 #ifdef RX_ENABLE_LOCKS
926 #endif /* RX_ENABLE_LOCKS */
927 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
928 #ifdef RX_ENABLE_LOCKS
930 #endif /* RX_ENABLE_LOCKS */
935 /* Handle corrupt VLDB (defect 7393) */
936 if (code == 0 && nentries == 0)
939 } while (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
940 -1, SHARED_LOCK, tcell));
942 /* Better handing of such failures; for now we'll simply retry this call */
943 areq->volumeError = 1;
947 addrp = addrs.bulkaddrs_val;
948 for (k = 0; k < nentries; k++) {
949 addrp[k] = htonl(addrp[k]);
951 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
952 WRITE_LOCK, &ve->serverNumber[i],
953 ve->serverUnique[i]);
954 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
957 av->serverHost[j] = ts;
959 /* The cell field could be 0 if the server entry was created
960 * first with the 'fs setserverprefs' call which doesn't set
961 * the cell field. Thus if the afs_GetServer call above
962 * follows later on it will find the server entry thus it will
963 * simply return without setting any fields, so we set the
964 * field ourselves below.
968 afs_PutServer(ts, WRITE_LOCK);
972 afs_SortServers(av->serverHost, MAXHOSTS);
973 } /*InstallVolumeEntry*/
976 void afs_ResetVolumeInfo(struct volume *tv)
980 AFS_STATCNT(afs_ResetVolumeInfo);
981 ObtainWriteLock(&tv->lock,117);
982 tv->states |= VRecheck;
983 for (i=0; i<MAXHOSTS; i++)
984 tv->status[i] = not_busy;
986 afs_osi_Free(tv->name, strlen(tv->name)+1);
987 tv->name = (char *) 0;
989 ReleaseWriteLock(&tv->lock);
990 } /*afs_ResetVolumeInfo*/