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);
75 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
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 vp->serverHost[k] = 0;
229 afs_ResetVolumeInfo(vp);
238 /* reset volume name to volume id mapping cache */
239 void afs_CheckVolumeNames(flags)
243 extern int osi_dnlc_purge();
247 afs_int32 *volumeID, *cellID, vsize, nvols;
248 AFS_STATCNT(afs_CheckVolumeNames);
251 volumeID = cellID = NULL;
253 ObtainReadLock(&afs_xvolume);
254 if (flags & AFS_VOLCHECK_EXPIRED) {
256 * allocate space to hold the volumeIDs and cellIDs, only if
257 * we will be invalidating the mountpoints later on
259 for (i=0; i< NVOLS; i++)
260 for (tv = afs_volumes[i]; tv; tv=tv->next)
263 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
264 cellID = (volumeID) ? volumeID + vsize : 0;
268 for (i=0;i<NVOLS;i++) {
269 for (tv = afs_volumes[i]; tv; tv=tv->next) {
270 if (flags & AFS_VOLCHECK_EXPIRED) {
271 if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) ||
272 (flags & AFS_VOLCHECK_FORCE)){
273 afs_ResetVolumeInfo(tv); /* also resets status */
275 volumeID[nvols] = tv->volume;
276 cellID[nvols] = tv->cell;
282 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
283 for (j=0; j<MAXHOSTS; j++)
284 tv->status[j] = not_busy;
289 ReleaseReadLock(&afs_xvolume);
292 /* next ensure all mt points are re-evaluated */
293 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
294 ObtainReadLock(&afs_xvcache);
295 for(i=0;i<VCSIZE;i++) {
296 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
298 /* if the volume of "mvid" of the vcache entry is among the
299 * ones we found earlier, then we re-evaluate it. Also, if the
300 * force bit is set or we explicitly asked to reevaluate the
301 * mt-pts, we clean the cmvalid bit */
303 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) ||
305 inVolList(tvc->mvid, nvols, volumeID, cellID)))
306 tvc->states &= ~CMValid;
308 /* If the volume that this file belongs to was reset earlier,
309 * then we should remove its callback.
310 * Again, if forced, always do it.
312 if ((tvc->states & CRO) &&
313 (inVolList(&tvc->fid, nvols, volumeID, cellID) ||
314 (flags & AFS_VOLCHECK_FORCE))) {
317 ReleaseReadLock(&afs_xvcache);
319 ObtainWriteLock(&afs_xcbhash, 485);
320 /* LOCKXXX: We aren't holding tvc write lock? */
321 afs_DequeueCallback(tvc);
322 tvc->states &= ~CStatd;
323 ReleaseWriteLock(&afs_xcbhash);
324 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
325 osi_dnlc_purgedp(tvc);
327 ObtainReadLock(&afs_xvcache);
329 /* our tvc ptr is still good until now */
334 osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */
335 ReleaseReadLock(&afs_xvcache);
339 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
341 } /*afs_CheckVolumeNames*/
344 static inVolList(fid, nvols, vID, cID)
345 struct VenusFid *fid;
346 afs_int32 nvols, *vID, *cID;
350 /* if no arrays present, be conservative and return true */
351 if ( nvols && (!vID || !cID))
354 for (i=0; i< nvols; ++i) {
355 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
362 /* afs_PutVolume is now a macro in afs.h */
366 * return volume struct if we have it cached and it's up-to-date
368 * Environment: Must be called with afs_xvolume unlocked.
370 struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
378 i = VHash(afid->Fid.Volume);
379 ObtainWriteLock(&afs_xvolume,106);
380 for (tv = afs_volumes[i]; tv; tv=tv->next) {
381 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
382 && (tv->states & VRecheck) == 0) {
387 ReleaseWriteLock(&afs_xvolume);
388 return tv; /* NULL if we didn't find it */
394 * Note that areq may be null, in which case we don't bother to set any
395 * request status information.
397 struct volume *afs_GetVolume(afid, areq, locktype)
398 struct vrequest *areq;
399 struct VenusFid *afid;
403 char *bp, tbuf[CVBS];
404 AFS_STATCNT(afs_GetVolume);
406 tv = afs_FindVolume(afid, locktype);
408 if (afs_IsDynrootFid(afid)) {
409 tv = afs_NewDynrootVolume(afid);
411 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
412 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
420 static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq)
423 afs_int32 volid, agood, type;
425 struct vrequest *areq;
428 struct vldbentry *ove = (struct vldbentry *)ve;
429 struct nvldbentry *nve = (struct nvldbentry *)ve;
430 struct uvldbentry *uve = (struct uvldbentry *)ve;
432 int whichType; /* which type of volume to look for */
437 /* special hint from file server to use vlserver */
439 if (len >= 8 && strcmp(aname+len-7, ".backup") == 0)
441 else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0)
446 /* figure out which one we're really interested in (a set is returned) */
447 volid = afs_vtoi(aname);
450 volid = uve->volumeId[whichType];
452 else if (type == 1) {
453 volid = nve->volumeId[whichType];
456 volid = ove->volumeId[whichType];
462 ObtainWriteLock(&afs_xvolume,108);
464 for (tv = afs_volumes[i]; tv; tv=tv->next) {
465 if (tv->volume == volid && tv->cell == tcell->cell) {
470 struct fvolume *tf=0;
472 tv = afs_GetVolSlot();
473 memset((char *)tv, 0, sizeof(struct volume));
474 tv->cell = tcell->cell;
475 RWLOCK_INIT(&tv->lock, "volume lock");
476 tv->next = afs_volumes[i]; /* thread into list */
479 for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) {
480 if (afs_FVIndex != j) {
482 tfile = osi_UFSOpen(volumeInode);
483 err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume));
484 if (err != sizeof(struct fvolume))
485 osi_Panic("read volumeinfo2");
490 if (tf->cell == tv->cell && tf->volume == volid)
493 if (tf && (j != 0)) {
494 tv->vtix = afs_FVIndex;
495 tv->mtpoint = tf->mtpoint;
496 tv->dotdot = tf->dotdot;
497 tv->rootVnode = tf->rootVnode;
498 tv->rootUnique = tf->rootUnique;
501 tv->rootVnode = tv->rootUnique = 0;
505 tv->states &= ~VRecheck; /* just checked it */
506 tv->accessTime = osi_Time();
507 ReleaseWriteLock(&afs_xvolume);
508 ObtainWriteLock(&tv->lock,111);
510 InstallUVolumeEntry(tv, uve, tcell->cell, tcell, areq);
513 InstallNVolumeEntry(tv, nve, tcell->cell);
515 InstallVolumeEntry(tv, ove, tcell->cell);
518 tv->name = afs_osi_Alloc(strlen(aname) + 1);
519 strcpy(tv->name, aname);
522 for (i=0; i<NMAXNSERVERS; i++) {
523 tv->status[i] = not_busy;
525 ReleaseWriteLock(&tv->lock);
530 struct volume *afs_GetVolumeByName(aname, acell, agood, areq, locktype)
531 struct vrequest *areq;
534 register char *aname;
540 AFS_STATCNT(afs_GetVolumeByName);
541 ObtainWriteLock(&afs_xvolume,112);
542 for (i=0;i<NVOLS;i++) {
543 for (tv = afs_volumes[i]; tv; tv=tv->next) {
544 if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell
545 && (tv->states&VRecheck) == 0) {
547 ReleaseWriteLock(&afs_xvolume);
553 ReleaseWriteLock(&afs_xvolume);
555 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
559 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid) {
562 struct vldbentry tve;
563 char *bp, tbuf[CVBS];
565 tcell = afs_GetCell(fid->Cell, READ_LOCK);
567 return (struct volume *) 0;
568 if (!(tcell->states & CHasVolRef))
569 tcell->states |= CHasVolRef;
571 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
572 memset(&tve, 0, sizeof(tve));
573 strcpy(tve.name, "local-dynroot");
574 tve.volumeId[ROVOL] = fid->Fid.Volume;
575 tve.flags = VLF_ROEXISTS;
577 tv = afs_SetupVolume(0, bp, &tve, tcell, 0, 0, 0);
578 afs_PutCell(tcell, READ_LOCK);
583 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
584 struct vrequest *areq, afs_int32 locktype)
586 afs_int32 code, i, type=0;
587 struct volume *tv, *tv1;
588 struct vldbentry *tve;
589 struct nvldbentry *ntve;
590 struct uvldbentry *utve;
594 struct vrequest treq;
597 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
598 return (struct volume *) 0;
600 tcell = afs_GetCell(acell, READ_LOCK);
602 return (struct volume *) 0;
605 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
606 if (!areq) areq = &treq;
609 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
610 ICL_TYPE_POINTER, aname);
611 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
612 tve = (struct vldbentry *) (tbuffer+1024);
613 ntve = (struct nvldbentry *)tve;
614 utve = (struct uvldbentry *)tve;
615 afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
617 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
618 tcell->cell, &treq, SHARED_LOCK);
620 if (tconn->srvr->server->flags & SNO_LHOSTS) {
623 code = VL_GetEntryByNameO(tconn->id, aname, tve);
625 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
628 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
633 code = VL_GetEntryByNameU(tconn->id, aname, utve);
635 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
636 if (code == RXGEN_OPCODE) {
639 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
641 if (code == RXGEN_OPCODE) {
643 tconn->srvr->server->flags |= SNO_LHOSTS;
645 code = VL_GetEntryByNameO(tconn->id, aname, tve);
648 tconn->srvr->server->flags |= SYES_LHOSTS;
650 tconn->srvr->server->flags |= SVLSRV_UUID;
657 (afs_Analyze(tconn, code, (struct VenusFid *) 0, &treq,
658 -1, /* no op code for this */
659 SHARED_LOCK, tcell));
662 /* If the client has yet to contact this cell and contact failed due
663 * to network errors, mark the VLDB servers as back up.
664 * That the client tried and failed can be determined from the
665 * fact that there was a downtime incident, but CHasVolRef is not set.
667 if (areq->networkError && !(tcell->states & CHasVolRef)) {
671 for (i=0; i<MAXCELLHOSTS; i++) {
672 if ((sp = tcell->cellHosts[i]) == (struct server *) 0) break;
673 for (sap = sp->addr; sap; sap = sap->next_sa)
674 afs_MarkServerUpOrDown(sap, 0);
677 afs_CopyError(&treq, areq);
678 osi_FreeLargeSpace(tbuffer);
679 afs_PutCell(tcell, READ_LOCK);
680 return (struct volume *) 0;
683 * Check to see if this cell has not yet referenced a volume. If
684 * it hasn't, it's just about to change its status, and we need to mark
685 * this fact down. Note that it is remotely possible that afs_SetupVolume
686 * could fail and we would still not have a volume reference.
688 if (!(tcell->states & CHasVolRef)) {
689 tcell->states |= CHasVolRef;
690 afs_stats_cmperf.numCellsContacted++;
691 } /*First time a volume in this cell has been referenced*/
699 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
700 if ((agood == 2) && tv->roVol) {
702 * This means that very soon we'll ask for the RO volume so
703 * we'll prefetch it (well we did already.)
705 tv1 = afs_SetupVolume(tv->roVol, (char *)0, ve, tcell, 0, type, areq);
708 osi_FreeLargeSpace(tbuffer);
709 afs_PutCell(tcell, READ_LOCK);
712 } /*afs_NewVolumeByName*/
716 /* call this with the volume structure locked; used for new-style vldb requests */
717 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
719 register struct server *ts;
725 AFS_STATCNT(InstallVolumeEntry);
727 /* Determine the type of volume we want */
728 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
731 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
735 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
736 /* backup always is on the same volume as parent */
738 av->states |= (VRO|VBackup);
741 mask = 0; /* Can't find volume in vldb entry */
744 /* fill in volume types */
745 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
746 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
747 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
749 if (ve->flags & VLF_DFSFILESET)
750 av->states |= VForeign;
752 cellp = afs_GetCell(acell, 0);
754 /* This volume, av, is locked. Zero out the serverHosts[] array
755 * so that if afs_GetServer() decides to replace the server
756 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
759 for (j=0; j<MAXHOSTS; j++) {
760 av->serverHost[j] = 0;
763 /* Step through the VLDB entry making sure each server listed is there */
764 for (i=0,j=0; i<ve->nServers; i++) {
765 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
766 continue; /* wrong volume or don't use this volume */
769 temp = htonl(ve->serverNumber[i]);
770 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
771 av->serverHost[j] = ts;
774 * The cell field could be 0 if the server entry was created
775 * first with the 'fs setserverprefs' call which doesn't set
776 * the cell field. Thus if the afs_GetServer call above
777 * follows later on it will find the server entry thus it will
778 * simply return without setting any fields, so we set the
779 * field ourselves below.
783 afs_PutServer(ts, WRITE_LOCK);
787 av->serverHost[j++] = 0;
789 afs_SortServers(av->serverHost, MAXHOSTS);
790 } /*InstallVolumeEntry*/
793 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
795 register struct server *ts;
801 AFS_STATCNT(InstallVolumeEntry);
803 /* Determine type of volume we want */
804 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
807 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
811 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
812 /* backup always is on the same volume as parent */
814 av->states |= (VRO|VBackup);
817 mask = 0; /* Can't find volume in vldb entry */
820 /* fill in volume types */
821 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
822 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
823 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
825 if (ve->flags & VLF_DFSFILESET)
826 av->states |= VForeign;
828 cellp = afs_GetCell(acell, 0);
830 /* This volume, av, is locked. Zero out the serverHosts[] array
831 * so that if afs_GetServer() decides to replace the server
832 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
835 for (j=0; j<MAXHOSTS; j++) {
836 av->serverHost[j] = 0;
839 /* Step through the VLDB entry making sure each server listed is there */
840 for (i=0,j=0; i<ve->nServers; i++) {
841 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
842 continue; /* wrong volume or don't use this volume */
845 temp = htonl(ve->serverNumber[i]);
846 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
847 av->serverHost[j] = ts;
849 * The cell field could be 0 if the server entry was created
850 * first with the 'fs setserverprefs' call which doesn't set
851 * the cell field. Thus if the afs_GetServer call above
852 * follows later on it will find the server entry thus it will
853 * simply return without setting any fields, so we set the
854 * field ourselves below.
858 afs_PutServer(ts, WRITE_LOCK);
862 av->serverHost[j++] = 0;
864 afs_SortServers(av->serverHost, MAXHOSTS);
865 } /*InstallNVolumeEntry*/
868 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
869 int acell, struct cell *tcell, struct vrequest *areq)
871 register struct srvAddr *sa;
872 register struct server *ts;
880 AFS_STATCNT(InstallVolumeEntry);
882 /* Determine type of volume we want */
883 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
886 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
890 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
891 /* backup always is on the same volume as parent */
893 av->states |= (VRO|VBackup);
896 mask = 0; /* Can't find volume in vldb entry */
899 /* fill in volume types */
900 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
901 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
902 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
904 if (ve->flags & VLF_DFSFILESET)
905 av->states |= VForeign;
907 cellp = afs_GetCell(acell, 0);
909 /* This volume, av, is locked. Zero out the serverHosts[] array
910 * so that if afs_GetServer() decides to replace the server
911 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
914 for (j=0; j<MAXHOSTS; j++) {
915 av->serverHost[j] = 0;
918 /* Gather the list of servers the VLDB says the volume is on
919 * and initialize the ve->serverHost[] array. If a server struct
920 * is not found, then get the list of addresses for the
921 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
923 for (i=0,j=0; i<ve->nServers; i++) {
924 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
925 continue; /* wrong volume don't use this volume */
928 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
929 /* The server has no uuid */
930 serverid = htonl(ve->serverNumber[i].time_low);
931 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
933 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
934 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
935 /* uuid, uniquifier, and portal are the same */
937 afs_uint32 *addrp, nentries, code, unique;
939 ListAddrByAttributes attrs;
942 memset((char *)&attrs, 0, sizeof(attrs));
943 attrs.Mask = VLADDR_UUID;
944 attrs.uuid = ve->serverNumber[i];
945 memset((char *)&uuid, 0, sizeof(uuid));
946 memset((char *)&addrs, 0, sizeof(addrs));
948 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
949 tcell->cell, areq, SHARED_LOCK);
952 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
958 /* Handle corrupt VLDB (defect 7393) */
959 if (code == 0 && nentries == 0)
962 } while (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
963 -1, SHARED_LOCK, tcell));
965 /* Better handing of such failures; for now we'll simply retry this call */
966 areq->volumeError = 1;
970 addrp = addrs.bulkaddrs_val;
971 for (k = 0; k < nentries; k++) {
972 addrp[k] = htonl(addrp[k]);
974 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
975 WRITE_LOCK, &ve->serverNumber[i],
976 ve->serverUnique[i]);
977 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
980 av->serverHost[j] = ts;
982 /* The cell field could be 0 if the server entry was created
983 * first with the 'fs setserverprefs' call which doesn't set
984 * the cell field. Thus if the afs_GetServer call above
985 * follows later on it will find the server entry thus it will
986 * simply return without setting any fields, so we set the
987 * field ourselves below.
991 afs_PutServer(ts, WRITE_LOCK);
995 afs_SortServers(av->serverHost, MAXHOSTS);
996 } /*InstallVolumeEntry*/
999 void afs_ResetVolumeInfo(struct volume *tv)
1003 AFS_STATCNT(afs_ResetVolumeInfo);
1004 ObtainWriteLock(&tv->lock,117);
1005 tv->states |= VRecheck;
1006 for (i=0; i<MAXHOSTS; i++)
1007 tv->status[i] = not_busy;
1009 afs_osi_Free(tv->name, strlen(tv->name)+1);
1010 tv->name = (char *) 0;
1012 ReleaseWriteLock(&tv->lock);
1013 } /*afs_ResetVolumeInfo*/