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 */
64 /* Exported variables */
65 ino_t volumeInode; /*Inode for VolumeItems file*/
66 afs_rwlock_t afs_xvolume; /* allocation lock for volumes */
67 struct volume *afs_freeVolList;
68 struct volume *afs_volumes[NVOLS];
69 afs_int32 afs_volCounter = 1; /* for allocating volume indices */
70 afs_int32 fvTable[NFENTRIES];
72 /* Forward declarations */
73 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
74 struct vrequest *areq, afs_int32 locktype);
78 /* Convert a volume name to a #; return 0 if can't parse as a number */
79 static int afs_vtoi(aname)
83 register afs_int32 temp;
86 AFS_STATCNT(afs_vtoi);
87 while(tc = *aname++) {
88 if (tc > '9' || tc < '0')
89 return 0; /* invalid name */
99 * All of the vol cache routines must be called with the afs_xvolume
100 * lock held in exclusive mode, since they use static variables.
101 * In addition, we don't want two people adding the same volume
105 static struct fvolume staticFVolume;
106 afs_int32 afs_FVIndex = -1;
108 /* UFS specific version of afs_GetVolSlot */
110 struct volume *afs_UFSGetVolSlot()
113 register struct volume *tv, **lv;
114 register char *tfile;
115 register afs_int32 i, code;
117 struct volume *bestVp, **bestLp;
119 AFS_STATCNT(afs_UFSGetVolSlot);
120 if (!afs_freeVolList) {
122 bestTime = 0x7fffffff;
125 for (i=0;i<NVOLS;i++) {
126 lv = &afs_volumes[i];
127 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
128 if (tv->refCount == 0) { /* is this one available? */
129 if (tv->accessTime < bestTime) { /* best one available? */
130 bestTime = tv->accessTime;
138 osi_Panic("getvolslot none");
142 afs_osi_Free(tv->name, strlen(tv->name)+1);
143 tv->name = (char *) 0;
144 /* now write out volume structure to file */
146 tv->vtix = afs_volCounter++;
147 /* now put on hash chain */
148 i = FVHash(tv->cell, tv->volume);
149 staticFVolume.next = fvTable[i];
154 * Haul the guy in from disk so we don't overwrite hash table
157 if (afs_FVIndex != tv->vtix) {
158 tfile = osi_UFSOpen(volumeInode);
159 code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
160 &staticFVolume, sizeof(struct fvolume));
161 if (code != sizeof(struct fvolume))
162 osi_Panic("read volumeinfo");
164 afs_FVIndex = tv->vtix;
167 afs_FVIndex = tv->vtix;
168 staticFVolume.volume = tv->volume;
169 staticFVolume.cell = tv->cell;
170 staticFVolume.mtpoint = tv->mtpoint;
171 staticFVolume.dotdot = tv->dotdot;
172 staticFVolume.rootVnode = tv->rootVnode;
173 staticFVolume.rootUnique = tv->rootUnique;
174 tfile = osi_UFSOpen(volumeInode);
175 code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
176 &staticFVolume, sizeof(struct fvolume));
177 if (code != sizeof(struct fvolume))
178 osi_Panic("write volumeinfo");
182 tv = afs_freeVolList;
183 afs_freeVolList = tv->next;
187 } /*afs_UFSGetVolSlot*/
190 struct volume *afs_MemGetVolSlot()
193 register struct volume *tv, **lv;
194 register afs_int32 i;
196 struct volume *bestVp, **bestLp;
198 AFS_STATCNT(afs_MemGetVolSlot);
199 if (!afs_freeVolList) {
200 struct volume *newVp;
202 newVp = (struct volume *) afs_osi_Alloc(sizeof(struct volume));
204 newVp->next = (struct volume *)0;
205 afs_freeVolList = newVp;
207 tv = afs_freeVolList;
208 afs_freeVolList = tv->next;
211 } /*afs_MemGetVolSlot*/
213 /* afs_ResetVolumes()
214 * Reset volume inforamation for all volume structs that
215 * point to a speicific server.
217 void afs_ResetVolumes(struct server *srvp)
222 /* Find any volumes residing on this server and flush their state */
223 for (j=0; j<NVOLS; j++) {
224 for (vp=afs_volumes[j]; vp; vp=vp->next) {
225 for (k=0; k<MAXHOSTS; k++) {
226 if (!srvp || (vp->serverHost[k] == srvp)) {
227 afs_ResetVolumeInfo(vp);
236 /* reset volume name to volume id mapping cache */
237 void afs_CheckVolumeNames(flags)
241 extern int osi_dnlc_purge();
245 afs_int32 *volumeID, *cellID, vsize, nvols;
246 AFS_STATCNT(afs_CheckVolumeNames);
249 volumeID = cellID = NULL;
251 ObtainReadLock(&afs_xvolume);
252 if (flags & AFS_VOLCHECK_EXPIRED) {
254 * allocate space to hold the volumeIDs and cellIDs, only if
255 * we will be invalidating the mountpoints later on
257 for (i=0; i< NVOLS; i++)
258 for (tv = afs_volumes[i]; tv; tv=tv->next)
261 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
262 cellID = (volumeID) ? volumeID + vsize : 0;
266 for (i=0;i<NVOLS;i++) {
267 for (tv = afs_volumes[i]; tv; tv=tv->next) {
268 if (flags & AFS_VOLCHECK_EXPIRED) {
269 if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) ||
270 (flags & AFS_VOLCHECK_FORCE)){
271 afs_ResetVolumeInfo(tv); /* also resets status */
273 volumeID[nvols] = tv->volume;
274 cellID[nvols] = tv->cell;
280 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
281 for (j=0; j<MAXHOSTS; j++)
282 tv->status[j] = not_busy;
287 ReleaseReadLock(&afs_xvolume);
290 /* next ensure all mt points are re-evaluated */
291 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
292 ObtainReadLock(&afs_xvcache);
293 for(i=0;i<VCSIZE;i++) {
294 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
296 /* if the volume of "mvid" of the vcache entry is among the
297 * ones we found earlier, then we re-evaluate it. Also, if the
298 * force bit is set or we explicitly asked to reevaluate the
299 * mt-pts, we clean the cmvalid bit */
301 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) ||
303 inVolList(tvc->mvid, nvols, volumeID, cellID)))
304 tvc->states &= ~CMValid;
306 /* If the volume that this file belongs to was reset earlier,
307 * then we should remove its callback.
308 * Again, if forced, always do it.
310 if ((tvc->states & CRO) &&
311 (inVolList(&tvc->fid, nvols, volumeID, cellID) ||
312 (flags & AFS_VOLCHECK_FORCE))) {
315 ReleaseReadLock(&afs_xvcache);
317 ObtainWriteLock(&afs_xcbhash, 485);
318 afs_DequeueCallback(tvc);
319 tvc->states &= ~CStatd;
320 ReleaseWriteLock(&afs_xcbhash);
321 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
322 osi_dnlc_purgedp(tvc);
324 ObtainReadLock(&afs_xvcache);
326 /* our tvc ptr is still good until now */
331 osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */
332 ReleaseReadLock(&afs_xvcache);
336 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
338 } /*afs_CheckVolumeNames*/
341 static inVolList(fid, nvols, vID, cID)
342 struct VenusFid *fid;
343 afs_int32 nvols, *vID, *cID;
347 /* if no arrays present, be conservative and return true */
348 if ( nvols && (!vID || !cID))
351 for (i=0; i< nvols; ++i) {
352 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
359 /* afs_PutVolume is now a macro in afs.h */
363 * return volume struct if we have it cached and it's up-to-date
365 * Environment: Must be called with afs_xvolume unlocked.
367 struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
375 i = VHash(afid->Fid.Volume);
376 ObtainWriteLock(&afs_xvolume,106);
377 for (tv = afs_volumes[i]; tv; tv=tv->next) {
378 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
379 && (tv->states & VRecheck) == 0) {
384 ReleaseWriteLock(&afs_xvolume);
385 return tv; /* NULL if we didn't find it */
391 * Note that areq may be null, in which case we don't bother to set any
392 * request status information.
394 struct volume *afs_GetVolume(afid, areq, locktype)
395 struct vrequest *areq;
396 struct VenusFid *afid;
400 char *bp, tbuf[CVBS];
401 AFS_STATCNT(afs_GetVolume);
403 tv = afs_FindVolume(afid, locktype);
405 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
406 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
413 static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq)
416 afs_int32 volid, agood, type;
418 struct vrequest *areq;
421 struct vldbentry *ove = (struct vldbentry *)ve;
422 struct nvldbentry *nve = (struct nvldbentry *)ve;
423 struct uvldbentry *uve = (struct uvldbentry *)ve;
425 int whichType; /* which type of volume to look for */
430 /* special hint from file server to use vlserver */
432 if (len >= 8 && strcmp(aname+len-7, ".backup") == 0)
434 else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0)
439 /* figure out which one we're really interested in (a set is returned) */
440 volid = afs_vtoi(aname);
443 volid = uve->volumeId[whichType];
445 else if (type == 1) {
446 volid = nve->volumeId[whichType];
449 volid = ove->volumeId[whichType];
455 ObtainWriteLock(&afs_xvolume,108);
457 for (tv = afs_volumes[i]; tv; tv=tv->next) {
458 if (tv->volume == volid && tv->cell == tcell->cell) {
463 struct fvolume *tf=0;
465 tv = afs_GetVolSlot();
466 memset((char *)tv, 0, sizeof(struct volume));
467 tv->cell = tcell->cell;
468 RWLOCK_INIT(&tv->lock, "volume lock");
469 tv->next = afs_volumes[i]; /* thread into list */
472 for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) {
473 if (afs_FVIndex != j) {
475 tfile = osi_UFSOpen(volumeInode);
476 err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume));
477 if (err != sizeof(struct fvolume))
478 osi_Panic("read volumeinfo2");
483 if (tf->cell == tv->cell && tf->volume == volid)
486 if (tf && (j != 0)) {
487 tv->vtix = afs_FVIndex;
488 tv->mtpoint = tf->mtpoint;
489 tv->dotdot = tf->dotdot;
490 tv->rootVnode = tf->rootVnode;
491 tv->rootUnique = tf->rootUnique;
494 tv->rootVnode = tv->rootUnique = 0;
498 tv->states &= ~VRecheck; /* just checked it */
499 tv->accessTime = osi_Time();
500 ReleaseWriteLock(&afs_xvolume);
501 ObtainWriteLock(&tv->lock,111);
503 InstallUVolumeEntry(tv, uve, tcell->cell, tcell, areq);
506 InstallNVolumeEntry(tv, nve, tcell->cell);
508 InstallVolumeEntry(tv, ove, tcell->cell);
511 tv->name = afs_osi_Alloc(strlen(aname) + 1);
512 strcpy(tv->name, aname);
515 for (i=0; i<NMAXNSERVERS; i++) {
516 tv->status[i] = not_busy;
518 ReleaseWriteLock(&tv->lock);
523 struct volume *afs_GetVolumeByName(aname, acell, agood, areq, locktype)
524 struct vrequest *areq;
527 register char *aname;
533 AFS_STATCNT(afs_GetVolumeByName);
534 ObtainWriteLock(&afs_xvolume,112);
535 for (i=0;i<NVOLS;i++) {
536 for (tv = afs_volumes[i]; tv; tv=tv->next) {
537 if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell
538 && (tv->states&VRecheck) == 0) {
540 ReleaseWriteLock(&afs_xvolume);
546 ReleaseWriteLock(&afs_xvolume);
548 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
553 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
554 struct vrequest *areq, afs_int32 locktype)
556 afs_int32 code, i, type=0;
557 struct volume *tv, *tv1;
558 struct vldbentry *tve;
559 struct nvldbentry *ntve;
560 struct uvldbentry *utve;
564 struct vrequest treq;
567 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
568 return (struct volume *) 0;
570 tcell = afs_GetCell(acell, READ_LOCK);
572 return (struct volume *) 0;
575 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
576 if (!areq) areq = &treq;
579 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
580 ICL_TYPE_POINTER, aname);
581 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
582 tve = (struct vldbentry *) (tbuffer+1024);
583 ntve = (struct nvldbentry *)tve;
584 utve = (struct uvldbentry *)tve;
585 afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
587 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
588 tcell->cell, &treq, SHARED_LOCK);
590 if (tconn->srvr->server->flags & SNO_LHOSTS) {
592 #ifdef RX_ENABLE_LOCKS
594 #endif /* RX_ENABLE_LOCKS */
595 code = VL_GetEntryByNameO(tconn->id, aname, tve);
596 #ifdef RX_ENABLE_LOCKS
598 #endif /* RX_ENABLE_LOCKS */
599 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
601 #ifdef RX_ENABLE_LOCKS
603 #endif /* RX_ENABLE_LOCKS */
604 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
605 #ifdef RX_ENABLE_LOCKS
607 #endif /* RX_ENABLE_LOCKS */
610 #ifdef RX_ENABLE_LOCKS
612 #endif /* RX_ENABLE_LOCKS */
613 code = VL_GetEntryByNameU(tconn->id, aname, utve);
614 #ifdef RX_ENABLE_LOCKS
616 #endif /* RX_ENABLE_LOCKS */
617 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
618 if (code == RXGEN_OPCODE) {
620 #ifdef RX_ENABLE_LOCKS
622 #endif /* RX_ENABLE_LOCKS */
623 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
624 #ifdef RX_ENABLE_LOCKS
626 #endif /* RX_ENABLE_LOCKS */
627 if (code == RXGEN_OPCODE) {
629 tconn->srvr->server->flags |= SNO_LHOSTS;
630 #ifdef RX_ENABLE_LOCKS
632 #endif /* RX_ENABLE_LOCKS */
633 code = VL_GetEntryByNameO(tconn->id, aname, tve);
634 #ifdef RX_ENABLE_LOCKS
636 #endif /* RX_ENABLE_LOCKS */
638 tconn->srvr->server->flags |= SYES_LHOSTS;
640 tconn->srvr->server->flags |= SVLSRV_UUID;
647 (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
648 -1, /* no op code for this */
649 SHARED_LOCK, tcell));
652 /* If the client has yet to contact this cell and contact failed due
653 * to network errors, mark the VLDB servers as back up.
654 * That the client tried and failed can be determined from the
655 * fact that there was a downtime incident, but CHasVolRef is not set.
657 if (areq->networkError && !(tcell->states & CHasVolRef)) {
661 for (i=0; i<MAXCELLHOSTS; i++) {
662 if ((sp = tcell->cellHosts[i]) == (struct server *) 0) break;
663 for (sap = sp->addr; sap; sap = sap->next_sa)
664 afs_MarkServerUpOrDown(sap, 0);
667 afs_CopyError(&treq, areq);
668 osi_FreeLargeSpace(tbuffer);
669 afs_PutCell(tcell, READ_LOCK);
670 return (struct volume *) 0;
673 * Check to see if this cell has not yet referenced a volume. If
674 * it hasn't, it's just about to change its status, and we need to mark
675 * this fact down. Note that it is remotely possible that afs_SetupVolume
676 * could fail and we would still not have a volume reference.
678 if (!(tcell->states & CHasVolRef)) {
679 tcell->states |= CHasVolRef;
680 afs_stats_cmperf.numCellsContacted++;
681 } /*First time a volume in this cell has been referenced*/
689 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
690 if ((agood == 2) && tv->roVol) {
692 * This means that very soon we'll ask for the RO volume so
693 * we'll prefetch it (well we did already.)
695 tv1 = afs_SetupVolume(tv->roVol, (char *)0, ve, tcell, 0, type, areq);
698 osi_FreeLargeSpace(tbuffer);
699 afs_PutCell(tcell, READ_LOCK);
702 } /*afs_NewVolumeByName*/
706 /* call this with the volume structure locked; used for new-style vldb requests */
707 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
709 register struct server *ts;
715 AFS_STATCNT(InstallVolumeEntry);
717 /* Determine the type of volume we want */
718 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
721 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
725 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
726 /* backup always is on the same volume as parent */
728 av->states |= (VRO|VBackup);
731 mask = 0; /* Can't find volume in vldb entry */
734 /* fill in volume types */
735 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
736 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
737 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
739 if (ve->flags & VLF_DFSFILESET)
740 av->states |= VForeign;
742 cellp = afs_GetCell(acell, 0);
744 /* Step through the VLDB entry making sure each server listed is there */
745 for (i=0,j=0; i<ve->nServers; i++) {
746 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
747 continue; /* wrong volume or don't use this volume */
750 temp = htonl(ve->serverNumber[i]);
751 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
752 av->serverHost[j] = ts;
755 * The cell field could be 0 if the server entry was created
756 * first with the 'fs setserverprefs' call which doesn't set
757 * the cell field. Thus if the afs_GetServer call above
758 * follows later on it will find the server entry thus it will
759 * simply return without setting any fields, so we set the
760 * field ourselves below.
764 afs_PutServer(ts, WRITE_LOCK);
768 av->serverHost[j++] = 0;
770 afs_SortServers(av->serverHost, MAXHOSTS);
771 } /*InstallVolumeEntry*/
774 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
776 register struct server *ts;
782 AFS_STATCNT(InstallVolumeEntry);
784 /* Determine type of volume we want */
785 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
788 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
792 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
793 /* backup always is on the same volume as parent */
795 av->states |= (VRO|VBackup);
798 mask = 0; /* Can't find volume in vldb entry */
801 /* fill in volume types */
802 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
803 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
804 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
806 if (ve->flags & VLF_DFSFILESET)
807 av->states |= VForeign;
809 cellp = afs_GetCell(acell, 0);
811 /* Step through the VLDB entry making sure each server listed is there */
812 for (i=0,j=0; i<ve->nServers; i++) {
813 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
814 continue; /* wrong volume or don't use this volume */
817 temp = htonl(ve->serverNumber[i]);
818 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
819 av->serverHost[j] = ts;
821 * The cell field could be 0 if the server entry was created
822 * first with the 'fs setserverprefs' call which doesn't set
823 * the cell field. Thus if the afs_GetServer call above
824 * follows later on it will find the server entry thus it will
825 * simply return without setting any fields, so we set the
826 * field ourselves below.
830 afs_PutServer(ts, WRITE_LOCK);
834 av->serverHost[j++] = 0;
836 afs_SortServers(av->serverHost, MAXHOSTS);
837 } /*InstallNVolumeEntry*/
840 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
841 int acell, struct cell *tcell, struct vrequest *areq)
843 register struct srvAddr *sa;
844 register struct server *ts;
852 AFS_STATCNT(InstallVolumeEntry);
854 /* Determine type of volume we want */
855 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
858 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
862 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
863 /* backup always is on the same volume as parent */
865 av->states |= (VRO|VBackup);
868 mask = 0; /* Can't find volume in vldb entry */
871 /* fill in volume types */
872 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
873 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
874 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
876 if (ve->flags & VLF_DFSFILESET)
877 av->states |= VForeign;
879 cellp = afs_GetCell(acell, 0);
881 /* This volume, av, is locked. Zero out the serverHosts[] array
882 * so that if afs_GetServer() decides to replace the server
883 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
886 for (j=0; j<MAXHOSTS; j++) {
887 av->serverHost[j] = 0;
890 /* Gather the list of servers the VLDB says the volume is on
891 * and initialize the ve->serverHost[] array. If a server struct
892 * is not found, then get the list of addresses for the
893 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
895 for (i=0,j=0; i<ve->nServers; i++) {
896 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
897 continue; /* wrong volume don't use this volume */
900 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
901 /* The server has no uuid */
902 serverid = htonl(ve->serverNumber[i].time_low);
903 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
905 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
906 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
907 /* uuid, uniquifier, and portal are the same */
909 afs_uint32 *addrp, nentries, code, unique;
911 ListAddrByAttributes attrs;
914 memset((char *)&attrs, 0, sizeof(attrs));
915 attrs.Mask = VLADDR_UUID;
916 attrs.uuid = ve->serverNumber[i];
917 memset((char *)&uuid, 0, sizeof(uuid));
918 memset((char *)&addrs, 0, sizeof(addrs));
920 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
921 tcell->cell, areq, SHARED_LOCK);
923 #ifdef RX_ENABLE_LOCKS
925 #endif /* RX_ENABLE_LOCKS */
926 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
927 #ifdef RX_ENABLE_LOCKS
929 #endif /* RX_ENABLE_LOCKS */
934 /* Handle corrupt VLDB (defect 7393) */
935 if (code == 0 && nentries == 0)
938 } while (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
939 -1, SHARED_LOCK, tcell));
941 /* Better handing of such failures; for now we'll simply retry this call */
942 areq->volumeError = 1;
946 addrp = addrs.bulkaddrs_val;
947 for (k = 0; k < nentries; k++) {
948 addrp[k] = htonl(addrp[k]);
950 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
951 WRITE_LOCK, &ve->serverNumber[i],
952 ve->serverUnique[i]);
953 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
956 av->serverHost[j] = ts;
958 /* The cell field could be 0 if the server entry was created
959 * first with the 'fs setserverprefs' call which doesn't set
960 * the cell field. Thus if the afs_GetServer call above
961 * follows later on it will find the server entry thus it will
962 * simply return without setting any fields, so we set the
963 * field ourselves below.
967 afs_PutServer(ts, WRITE_LOCK);
971 afs_SortServers(av->serverHost, MAXHOSTS);
972 } /*InstallVolumeEntry*/
975 void afs_ResetVolumeInfo(struct volume *tv)
979 AFS_STATCNT(afs_ResetVolumeInfo);
980 ObtainWriteLock(&tv->lock,117);
981 tv->states |= VRecheck;
982 for (i=0; i<MAXHOSTS; i++)
983 tv->status[i] = not_busy;
985 afs_osi_Free(tv->name, strlen(tv->name)+1);
986 tv->name = (char *) 0;
988 ReleaseWriteLock(&tv->lock);
989 } /*afs_ResetVolumeInfo*/