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 /* In case we don't have the vl error table yet. */
51 #ifndef ERROR_TABLE_BASE_VL
52 #define ERROR_TABLE_BASE_VL (363520L)
53 #define VL_NOENT (363524L)
54 #endif /* vlserver error base define */
56 /* Exported variables */
57 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);
67 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
71 /* Convert a volume name to a #; return 0 if can't parse as a number */
72 static int afs_vtoi(register char *aname)
74 register afs_int32 temp;
77 AFS_STATCNT(afs_vtoi);
78 while((tc = *aname++)) {
79 if (tc > '9' || tc < '0')
80 return 0; /* invalid name */
90 * All of the vol cache routines must be called with the afs_xvolume
91 * lock held in exclusive mode, since they use static variables.
92 * In addition, we don't want two people adding the same volume
96 static struct fvolume staticFVolume;
97 afs_int32 afs_FVIndex = -1;
99 /* UFS specific version of afs_GetVolSlot */
101 struct volume *afs_UFSGetVolSlot(void)
103 register struct volume *tv, **lv;
104 register char *tfile;
105 register afs_int32 i, code;
107 struct volume *bestVp, **bestLp;
109 AFS_STATCNT(afs_UFSGetVolSlot);
110 if (!afs_freeVolList) {
112 bestTime = 0x7fffffff;
115 for (i=0;i<NVOLS;i++) {
116 lv = &afs_volumes[i];
117 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
118 if (tv->refCount == 0) { /* is this one available? */
119 if (tv->accessTime < bestTime) { /* best one available? */
120 bestTime = tv->accessTime;
128 osi_Panic("getvolslot none");
132 afs_osi_Free(tv->name, strlen(tv->name)+1);
134 /* now write out volume structure to file */
136 tv->vtix = afs_volCounter++;
137 /* now put on hash chain */
138 i = FVHash(tv->cell, tv->volume);
139 staticFVolume.next = fvTable[i];
144 * Haul the guy in from disk so we don't overwrite hash table
147 if (afs_FVIndex != tv->vtix) {
148 tfile = osi_UFSOpen(volumeInode);
149 code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
150 &staticFVolume, sizeof(struct fvolume));
151 if (code != sizeof(struct fvolume))
152 osi_Panic("read volumeinfo");
154 afs_FVIndex = tv->vtix;
157 afs_FVIndex = tv->vtix;
158 staticFVolume.volume = tv->volume;
159 staticFVolume.cell = tv->cell;
160 staticFVolume.mtpoint = tv->mtpoint;
161 staticFVolume.dotdot = tv->dotdot;
162 staticFVolume.rootVnode = tv->rootVnode;
163 staticFVolume.rootUnique = tv->rootUnique;
164 tfile = osi_UFSOpen(volumeInode);
165 code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
166 &staticFVolume, sizeof(struct fvolume));
167 if (code != sizeof(struct fvolume))
168 osi_Panic("write volumeinfo");
172 tv = afs_freeVolList;
173 afs_freeVolList = tv->next;
177 } /*afs_UFSGetVolSlot*/
180 struct volume *afs_MemGetVolSlot(void)
182 register struct volume *tv, **lv;
183 register afs_int32 i;
185 struct volume *bestVp, **bestLp;
187 AFS_STATCNT(afs_MemGetVolSlot);
188 if (!afs_freeVolList) {
189 struct volume *newVp;
191 newVp = (struct volume *) afs_osi_Alloc(sizeof(struct volume));
194 afs_freeVolList = newVp;
196 tv = afs_freeVolList;
197 afs_freeVolList = tv->next;
200 } /*afs_MemGetVolSlot*/
202 /* afs_ResetVolumes()
203 * Reset volume inforamation for all volume structs that
204 * point to a speicific server.
206 void afs_ResetVolumes(struct server *srvp)
211 /* Find any volumes residing on this server and flush their state */
212 for (j=0; j<NVOLS; j++) {
213 for (vp=afs_volumes[j]; vp; vp=vp->next) {
214 for (k=0; k<MAXHOSTS; k++) {
215 if (!srvp || (vp->serverHost[k] == srvp)) {
216 vp->serverHost[k] = 0;
217 afs_ResetVolumeInfo(vp);
226 /* reset volume name to volume id mapping cache */
227 void afs_CheckVolumeNames(int flags)
233 afs_int32 *volumeID, *cellID, vsize, nvols;
234 AFS_STATCNT(afs_CheckVolumeNames);
237 volumeID = cellID = NULL;
239 ObtainReadLock(&afs_xvolume);
240 if (flags & AFS_VOLCHECK_EXPIRED) {
242 * allocate space to hold the volumeIDs and cellIDs, only if
243 * we will be invalidating the mountpoints later on
245 for (i=0; i< NVOLS; i++)
246 for (tv = afs_volumes[i]; tv; tv=tv->next)
249 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
250 cellID = (volumeID) ? volumeID + vsize : 0;
254 for (i=0;i<NVOLS;i++) {
255 for (tv = afs_volumes[i]; tv; tv=tv->next) {
256 if (flags & AFS_VOLCHECK_EXPIRED) {
257 if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) ||
258 (flags & AFS_VOLCHECK_FORCE)){
259 afs_ResetVolumeInfo(tv); /* also resets status */
261 volumeID[nvols] = tv->volume;
262 cellID[nvols] = tv->cell;
268 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
269 for (j=0; j<MAXHOSTS; j++)
270 tv->status[j] = not_busy;
275 ReleaseReadLock(&afs_xvolume);
278 /* next ensure all mt points are re-evaluated */
279 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
280 ObtainReadLock(&afs_xvcache);
281 for(i=0;i<VCSIZE;i++) {
282 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
284 /* if the volume of "mvid" of the vcache entry is among the
285 * ones we found earlier, then we re-evaluate it. Also, if the
286 * force bit is set or we explicitly asked to reevaluate the
287 * mt-pts, we clean the cmvalid bit */
289 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) ||
291 inVolList(tvc->mvid, nvols, volumeID, cellID)))
292 tvc->states &= ~CMValid;
294 /* If the volume that this file belongs to was reset earlier,
295 * then we should remove its callback.
296 * Again, if forced, always do it.
298 if ((tvc->states & CRO) &&
299 (inVolList(&tvc->fid, nvols, volumeID, cellID) ||
300 (flags & AFS_VOLCHECK_FORCE))) {
303 ReleaseReadLock(&afs_xvcache);
305 ObtainWriteLock(&afs_xcbhash, 485);
306 /* LOCKXXX: We aren't holding tvc write lock? */
307 afs_DequeueCallback(tvc);
308 tvc->states &= ~CStatd;
309 ReleaseWriteLock(&afs_xcbhash);
310 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
311 osi_dnlc_purgedp(tvc);
313 ObtainReadLock(&afs_xvcache);
315 /* our tvc ptr is still good until now */
320 osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */
321 ReleaseReadLock(&afs_xvcache);
325 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
327 } /*afs_CheckVolumeNames*/
330 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 *vID, afs_int32 *cID)
334 /* if no arrays present, be conservative and return true */
335 if ( nvols && (!vID || !cID))
338 for (i=0; i< nvols; ++i) {
339 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
346 /* afs_PutVolume is now a macro in afs.h */
350 * return volume struct if we have it cached and it's up-to-date
352 * Environment: Must be called with afs_xvolume unlocked.
354 struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
362 i = VHash(afid->Fid.Volume);
363 ObtainWriteLock(&afs_xvolume,106);
364 for (tv = afs_volumes[i]; tv; tv=tv->next) {
365 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
366 && (tv->states & VRecheck) == 0) {
371 ReleaseWriteLock(&afs_xvolume);
372 return tv; /* NULL if we didn't find it */
378 * Note that areq may be null, in which case we don't bother to set any
379 * request status information.
381 struct volume *afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
385 char *bp, tbuf[CVBS];
386 AFS_STATCNT(afs_GetVolume);
388 tv = afs_FindVolume(afid, locktype);
390 if (afs_IsDynrootFid(afid)) {
391 tv = afs_NewDynrootVolume(afid);
393 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
394 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
402 static struct volume *afs_SetupVolume(afs_int32 volid, char *aname,
403 char *ve, struct cell *tcell, afs_int32 agood, afs_int32 type, struct vrequest *areq)
406 struct vldbentry *ove = (struct vldbentry *)ve;
407 struct nvldbentry *nve = (struct nvldbentry *)ve;
408 struct uvldbentry *uve = (struct uvldbentry *)ve;
410 int whichType; /* which type of volume to look for */
415 /* special hint from file server to use vlserver */
417 if (len >= 8 && strcmp(aname+len-7, ".backup") == 0)
419 else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0)
424 /* figure out which one we're really interested in (a set is returned) */
425 volid = afs_vtoi(aname);
428 volid = uve->volumeId[whichType];
430 else if (type == 1) {
431 volid = nve->volumeId[whichType];
434 volid = ove->volumeId[whichType];
440 ObtainWriteLock(&afs_xvolume,108);
442 for (tv = afs_volumes[i]; tv; tv=tv->next) {
443 if (tv->volume == volid && tv->cell == tcell->cell) {
448 struct fvolume *tf=0;
450 tv = afs_GetVolSlot();
451 memset((char *)tv, 0, sizeof(struct volume));
452 tv->cell = tcell->cell;
453 RWLOCK_INIT(&tv->lock, "volume lock");
454 tv->next = afs_volumes[i]; /* thread into list */
457 for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) {
458 if (afs_FVIndex != j) {
460 tfile = osi_UFSOpen(volumeInode);
461 err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume));
462 if (err != sizeof(struct fvolume))
463 osi_Panic("read volumeinfo2");
468 if (tf->cell == tv->cell && tf->volume == volid)
471 if (tf && (j != 0)) {
472 tv->vtix = afs_FVIndex;
473 tv->mtpoint = tf->mtpoint;
474 tv->dotdot = tf->dotdot;
475 tv->rootVnode = tf->rootVnode;
476 tv->rootUnique = tf->rootUnique;
479 tv->rootVnode = tv->rootUnique = 0;
483 tv->states &= ~VRecheck; /* just checked it */
484 tv->accessTime = osi_Time();
485 ReleaseWriteLock(&afs_xvolume);
486 ObtainWriteLock(&tv->lock,111);
488 InstallUVolumeEntry(tv, uve, tcell->cell, tcell, areq);
491 InstallNVolumeEntry(tv, nve, tcell->cell);
493 InstallVolumeEntry(tv, ove, tcell->cell);
496 tv->name = afs_osi_Alloc(strlen(aname) + 1);
497 strcpy(tv->name, aname);
500 for (i=0; i<NMAXNSERVERS; i++) {
501 tv->status[i] = not_busy;
503 ReleaseWriteLock(&tv->lock);
508 struct volume *afs_GetVolumeByName(register char *aname, afs_int32 acell,
509 int agood, struct vrequest *areq, afs_int32 locktype)
514 AFS_STATCNT(afs_GetVolumeByName);
515 ObtainWriteLock(&afs_xvolume,112);
516 for (i=0;i<NVOLS;i++) {
517 for (tv = afs_volumes[i]; tv; tv=tv->next) {
518 if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell
519 && (tv->states&VRecheck) == 0) {
521 ReleaseWriteLock(&afs_xvolume);
527 ReleaseWriteLock(&afs_xvolume);
529 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
533 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid)
537 struct vldbentry tve;
538 char *bp, tbuf[CVBS];
540 tcell = afs_GetCell(fid->Cell, READ_LOCK);
543 if (!(tcell->states & CHasVolRef))
544 tcell->states |= CHasVolRef;
546 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
547 memset(&tve, 0, sizeof(tve));
548 strcpy(tve.name, "local-dynroot");
549 tve.volumeId[ROVOL] = fid->Fid.Volume;
550 tve.flags = VLF_ROEXISTS;
552 tv = afs_SetupVolume(0, bp, &tve, tcell, 0, 0, 0);
553 afs_PutCell(tcell, READ_LOCK);
558 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
559 struct vrequest *areq, afs_int32 locktype)
561 afs_int32 code, i, type=0;
562 struct volume *tv, *tv1;
563 struct vldbentry *tve;
564 struct nvldbentry *ntve;
565 struct uvldbentry *utve;
569 struct vrequest treq;
572 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
575 tcell = afs_GetCell(acell, READ_LOCK);
580 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
581 if (!areq) areq = &treq;
584 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
585 ICL_TYPE_POINTER, aname);
586 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
587 tve = (struct vldbentry *) (tbuffer+1024);
588 ntve = (struct nvldbentry *)tve;
589 utve = (struct uvldbentry *)tve;
590 afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
592 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
593 tcell->cell, &treq, SHARED_LOCK);
595 if (tconn->srvr->server->flags & SNO_LHOSTS) {
598 code = VL_GetEntryByNameO(tconn->id, aname, tve);
600 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
603 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
608 code = VL_GetEntryByNameU(tconn->id, aname, utve);
610 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
611 if (code == RXGEN_OPCODE) {
614 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
616 if (code == RXGEN_OPCODE) {
618 tconn->srvr->server->flags |= SNO_LHOSTS;
620 code = VL_GetEntryByNameO(tconn->id, aname, tve);
623 tconn->srvr->server->flags |= SYES_LHOSTS;
625 tconn->srvr->server->flags |= SVLSRV_UUID;
632 (afs_Analyze(tconn, code, NULL, &treq,
633 -1, /* no op code for this */
634 SHARED_LOCK, tcell));
637 /* If the client has yet to contact this cell and contact failed due
638 * to network errors, mark the VLDB servers as back up.
639 * That the client tried and failed can be determined from the
640 * fact that there was a downtime incident, but CHasVolRef is not set.
642 if (areq->networkError && !(tcell->states & CHasVolRef)) {
646 for (i=0; i<MAXCELLHOSTS; i++) {
647 if ((sp = tcell->cellHosts[i]) == NULL) break;
648 for (sap = sp->addr; sap; sap = sap->next_sa)
649 afs_MarkServerUpOrDown(sap, 0);
652 afs_CopyError(&treq, areq);
653 osi_FreeLargeSpace(tbuffer);
654 afs_PutCell(tcell, READ_LOCK);
658 * Check to see if this cell has not yet referenced a volume. If
659 * it hasn't, it's just about to change its status, and we need to mark
660 * this fact down. Note that it is remotely possible that afs_SetupVolume
661 * could fail and we would still not have a volume reference.
663 if (!(tcell->states & CHasVolRef)) {
664 tcell->states |= CHasVolRef;
665 afs_stats_cmperf.numCellsContacted++;
666 } /*First time a volume in this cell has been referenced*/
674 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
675 if ((agood == 2) && tv->roVol) {
677 * This means that very soon we'll ask for the RO volume so
678 * we'll prefetch it (well we did already.)
680 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
683 osi_FreeLargeSpace(tbuffer);
684 afs_PutCell(tcell, READ_LOCK);
687 } /*afs_NewVolumeByName*/
691 /* call this with the volume structure locked; used for new-style vldb requests */
692 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
694 register struct server *ts;
700 AFS_STATCNT(InstallVolumeEntry);
702 /* Determine the type of volume we want */
703 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
706 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
710 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
711 /* backup always is on the same volume as parent */
713 av->states |= (VRO|VBackup);
716 mask = 0; /* Can't find volume in vldb entry */
719 /* fill in volume types */
720 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
721 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
722 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
724 if (ve->flags & VLF_DFSFILESET)
725 av->states |= VForeign;
727 cellp = afs_GetCell(acell, 0);
729 /* This volume, av, is locked. Zero out the serverHosts[] array
730 * so that if afs_GetServer() decides to replace the server
731 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
734 for (j=0; j<MAXHOSTS; j++) {
735 av->serverHost[j] = 0;
738 /* Step through the VLDB entry making sure each server listed is there */
739 for (i=0,j=0; i<ve->nServers; i++) {
740 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
741 continue; /* wrong volume or don't use this volume */
744 temp = htonl(ve->serverNumber[i]);
745 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
746 av->serverHost[j] = ts;
749 * The cell field could be 0 if the server entry was created
750 * first with the 'fs setserverprefs' call which doesn't set
751 * the cell field. Thus if the afs_GetServer call above
752 * follows later on it will find the server entry thus it will
753 * simply return without setting any fields, so we set the
754 * field ourselves below.
758 afs_PutServer(ts, WRITE_LOCK);
762 av->serverHost[j++] = 0;
764 afs_SortServers(av->serverHost, MAXHOSTS);
765 } /*InstallVolumeEntry*/
768 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
770 register struct server *ts;
776 AFS_STATCNT(InstallVolumeEntry);
778 /* Determine type of volume we want */
779 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
782 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
786 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
787 /* backup always is on the same volume as parent */
789 av->states |= (VRO|VBackup);
792 mask = 0; /* Can't find volume in vldb entry */
795 /* fill in volume types */
796 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
797 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
798 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
800 if (ve->flags & VLF_DFSFILESET)
801 av->states |= VForeign;
803 cellp = afs_GetCell(acell, 0);
805 /* This volume, av, is locked. Zero out the serverHosts[] array
806 * so that if afs_GetServer() decides to replace the server
807 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
810 for (j=0; j<MAXHOSTS; j++) {
811 av->serverHost[j] = 0;
814 /* Step through the VLDB entry making sure each server listed is there */
815 for (i=0,j=0; i<ve->nServers; i++) {
816 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
817 continue; /* wrong volume or don't use this volume */
820 temp = htonl(ve->serverNumber[i]);
821 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
822 av->serverHost[j] = ts;
824 * The cell field could be 0 if the server entry was created
825 * first with the 'fs setserverprefs' call which doesn't set
826 * the cell field. Thus if the afs_GetServer call above
827 * follows later on it will find the server entry thus it will
828 * simply return without setting any fields, so we set the
829 * field ourselves below.
833 afs_PutServer(ts, WRITE_LOCK);
837 av->serverHost[j++] = 0;
839 afs_SortServers(av->serverHost, MAXHOSTS);
840 } /*InstallNVolumeEntry*/
843 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
844 int acell, struct cell *tcell, struct vrequest *areq)
846 register struct srvAddr *sa;
847 register struct server *ts;
855 AFS_STATCNT(InstallVolumeEntry);
857 /* Determine type of volume we want */
858 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
861 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
865 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
866 /* backup always is on the same volume as parent */
868 av->states |= (VRO|VBackup);
871 mask = 0; /* Can't find volume in vldb entry */
874 /* fill in volume types */
875 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
876 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
877 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
879 if (ve->flags & VLF_DFSFILESET)
880 av->states |= VForeign;
882 cellp = afs_GetCell(acell, 0);
884 /* This volume, av, is locked. Zero out the serverHosts[] array
885 * so that if afs_GetServer() decides to replace the server
886 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
889 for (j=0; j<MAXHOSTS; j++) {
890 av->serverHost[j] = 0;
893 /* Gather the list of servers the VLDB says the volume is on
894 * and initialize the ve->serverHost[] array. If a server struct
895 * is not found, then get the list of addresses for the
896 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
898 for (i=0,j=0; i<ve->nServers; i++) {
899 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
900 continue; /* wrong volume don't use this volume */
903 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
904 /* The server has no uuid */
905 serverid = htonl(ve->serverNumber[i].time_low);
906 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
908 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
909 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
910 /* uuid, uniquifier, and portal are the same */
912 afs_uint32 *addrp, nentries, code, unique;
914 ListAddrByAttributes attrs;
917 memset((char *)&attrs, 0, sizeof(attrs));
918 attrs.Mask = VLADDR_UUID;
919 attrs.uuid = ve->serverNumber[i];
920 memset((char *)&uuid, 0, sizeof(uuid));
921 memset((char *)&addrs, 0, sizeof(addrs));
923 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
924 tcell->cell, areq, SHARED_LOCK);
927 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
933 /* Handle corrupt VLDB (defect 7393) */
934 if (code == 0 && nentries == 0)
937 } while (afs_Analyze(tconn, code, NULL, areq,
938 -1, SHARED_LOCK, tcell));
940 /* Better handing of such failures; for now we'll simply retry this call */
941 areq->volumeError = 1;
945 addrp = addrs.bulkaddrs_val;
946 for (k = 0; k < nentries; k++) {
947 addrp[k] = htonl(addrp[k]);
949 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
950 WRITE_LOCK, &ve->serverNumber[i],
951 ve->serverUnique[i]);
952 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
955 av->serverHost[j] = ts;
957 /* The cell field could be 0 if the server entry was created
958 * first with the 'fs setserverprefs' call which doesn't set
959 * the cell field. Thus if the afs_GetServer call above
960 * follows later on it will find the server entry thus it will
961 * simply return without setting any fields, so we set the
962 * field ourselves below.
966 afs_PutServer(ts, WRITE_LOCK);
970 afs_SortServers(av->serverHost, MAXHOSTS);
971 } /*InstallVolumeEntry*/
974 void afs_ResetVolumeInfo(struct volume *tv)
978 AFS_STATCNT(afs_ResetVolumeInfo);
979 ObtainWriteLock(&tv->lock,117);
980 tv->states |= VRecheck;
981 for (i=0; i<MAXHOSTS; i++)
982 tv->status[i] = not_busy;
984 afs_osi_Free(tv->name, strlen(tv->name)+1);
987 ReleaseWriteLock(&tv->lock);