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 "../afs/param.h" /* Should be always first */
19 #include "../afs/stds.h"
20 #include "../afs/sysincludes.h" /* Standard vendor system headers */
24 #include <netinet/in.h>
27 #include "../h/hashing.h"
29 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV)
30 #include <netinet/in_var.h>
31 #endif /* ! AFS_HPUX110_ENV */
32 #endif /* !defined(UKERNEL) */
34 #include "../afs/afsincludes.h" /* Afs-based standard headers */
35 #include "../afs/afs_stats.h" /* afs statistics */
37 #if defined(AFS_SUN56_ENV)
39 #include <inet/common.h>
40 #if defined(AFS_SUN58_ENV)
41 #include <netinet/ip6.h>
46 /* Imported variables */
47 extern afs_rwlock_t afs_xserver;
48 extern afs_rwlock_t afs_xsrvAddr;
49 extern afs_rwlock_t afs_xvcache;
50 extern afs_rwlock_t afs_xcbhash;
51 extern struct srvAddr *afs_srvAddrs[NSERVERS]; /* Hashed by server's ip */
52 extern int afs_totalSrvAddrs;
54 /* In case we don't have the vl error table yet. */
55 #ifndef ERROR_TABLE_BASE_vl
56 #define ERROR_TABLE_BASE_vl (363520L)
57 #define VL_NOENT (363524L)
58 #endif /* vlserver error base define */
61 /* Exported variables */
62 ino_t volumeInode; /*Inode for VolumeItems file*/
63 afs_rwlock_t afs_xvolume; /* allocation lock for volumes */
64 struct volume *afs_freeVolList;
65 struct volume *afs_volumes[NVOLS];
66 afs_int32 afs_volCounter = 1; /* for allocating volume indices */
67 afs_int32 fvTable[NFENTRIES];
69 /* Forward declarations */
70 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
71 struct vrequest *areq, afs_int32 locktype);
75 /* Convert a volume name to a #; return 0 if can't parse as a number */
76 static int afs_vtoi(aname)
80 register afs_int32 temp;
83 AFS_STATCNT(afs_vtoi);
84 while(tc = *aname++) {
85 if (tc > '9' || tc < '0')
86 return 0; /* invalid name */
96 * All of the vol cache routines must be called with the afs_xvolume
97 * lock held in exclusive mode, since they use static variables.
98 * In addition, we don't want two people adding the same volume
102 static struct fvolume staticFVolume;
103 afs_int32 afs_FVIndex = -1;
105 /* UFS specific version of afs_GetVolSlot */
107 struct volume *afs_UFSGetVolSlot()
110 register struct volume *tv, **lv;
111 register char *tfile;
112 register afs_int32 i, code;
114 struct volume *bestVp, **bestLp;
116 AFS_STATCNT(afs_UFSGetVolSlot);
117 if (!afs_freeVolList) {
119 bestTime = 0x7fffffff;
122 for (i=0;i<NVOLS;i++) {
123 lv = &afs_volumes[i];
124 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
125 if (tv->refCount == 0) { /* is this one available? */
126 if (tv->accessTime < bestTime) { /* best one available? */
127 bestTime = tv->accessTime;
135 osi_Panic("getvolslot none");
139 afs_osi_Free(tv->name, strlen(tv->name)+1);
140 tv->name = (char *) 0;
141 /* now write out volume structure to file */
143 tv->vtix = afs_volCounter++;
144 /* now put on hash chain */
145 i = FVHash(tv->cell, tv->volume);
146 staticFVolume.next = fvTable[i];
151 * Haul the guy in from disk so we don't overwrite hash table
154 if (afs_FVIndex != tv->vtix) {
155 tfile = osi_UFSOpen(volumeInode);
156 code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
157 &staticFVolume, sizeof(struct fvolume));
158 if (code != sizeof(struct fvolume))
159 osi_Panic("read volumeinfo");
161 afs_FVIndex = tv->vtix;
164 afs_FVIndex = tv->vtix;
165 staticFVolume.volume = tv->volume;
166 staticFVolume.cell = tv->cell;
167 staticFVolume.mtpoint = tv->mtpoint;
168 staticFVolume.dotdot = tv->dotdot;
169 staticFVolume.rootVnode = tv->rootVnode;
170 staticFVolume.rootUnique = tv->rootUnique;
171 tfile = osi_UFSOpen(volumeInode);
172 code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
173 &staticFVolume, sizeof(struct fvolume));
174 if (code != sizeof(struct fvolume))
175 osi_Panic("write volumeinfo");
179 tv = afs_freeVolList;
180 afs_freeVolList = tv->next;
184 } /*afs_UFSGetVolSlot*/
187 struct volume *afs_MemGetVolSlot()
190 register struct volume *tv, **lv;
191 register afs_int32 i;
193 struct volume *bestVp, **bestLp;
195 AFS_STATCNT(afs_MemGetVolSlot);
196 if (!afs_freeVolList) {
197 struct volume *newVp;
199 newVp = (struct volume *) afs_osi_Alloc(sizeof(struct volume));
201 newVp->next = (struct volume *)0;
202 afs_freeVolList = newVp;
204 tv = afs_freeVolList;
205 afs_freeVolList = tv->next;
208 } /*afs_MemGetVolSlot*/
210 /* afs_ResetVolumes()
211 * Reset volume inforamation for all volume structs that
212 * point to a speicific server.
214 void afs_ResetVolumes(struct server *srvp)
219 /* Find any volumes residing on this server and flush their state */
220 for (j=0; j<NVOLS; j++) {
221 for (vp=afs_volumes[j]; vp; vp=vp->next) {
222 for (k=0; k<MAXHOSTS; k++) {
223 if (!srvp || (vp->serverHost[k] == srvp)) {
224 afs_ResetVolumeInfo(vp);
233 /* reset volume name to volume id mapping cache */
234 void afs_CheckVolumeNames(flags)
238 extern int osi_dnlc_purge();
242 afs_int32 *volumeID, *cellID, vsize, nvols;
243 AFS_STATCNT(afs_CheckVolumeNames);
246 volumeID = cellID = NULL;
248 ObtainReadLock(&afs_xvolume);
249 if (flags & AFS_VOLCHECK_EXPIRED) {
251 * allocate space to hold the volumeIDs and cellIDs, only if
252 * we will be invalidating the mountpoints later on
254 for (i=0; i< NVOLS; i++)
255 for (tv = afs_volumes[i]; tv; tv=tv->next)
258 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
259 cellID = (volumeID) ? volumeID + vsize : 0;
263 for (i=0;i<NVOLS;i++) {
264 for (tv = afs_volumes[i]; tv; tv=tv->next) {
265 if (flags & AFS_VOLCHECK_EXPIRED) {
266 if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) ||
267 (flags & AFS_VOLCHECK_FORCE)){
268 afs_ResetVolumeInfo(tv); /* also resets status */
270 volumeID[nvols] = tv->volume;
271 cellID[nvols] = tv->cell;
277 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
278 for (j=0; j<MAXHOSTS; j++)
279 tv->status[j] = not_busy;
284 ReleaseReadLock(&afs_xvolume);
287 /* next ensure all mt points are re-evaluated */
288 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
289 ObtainReadLock(&afs_xvcache);
290 for(i=0;i<VCSIZE;i++) {
291 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
293 /* if the volume of "mvid" of the vcache entry is among the
294 * ones we found earlier, then we re-evaluate it. Also, if the
295 * force bit is set or we explicitly asked to reevaluate the
296 * mt-pts, we clean the cmvalid bit */
298 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) ||
300 inVolList(tvc->mvid, nvols, volumeID, cellID)))
301 tvc->states &= ~CMValid;
303 /* If the volume that this file belongs to was reset earlier,
304 * then we should remove its callback.
305 * Again, if forced, always do it.
307 if ((tvc->states & CRO) &&
308 (inVolList(&tvc->fid, nvols, volumeID, cellID) ||
309 (flags & AFS_VOLCHECK_FORCE))) {
312 ReleaseReadLock(&afs_xvcache);
314 ObtainWriteLock(&afs_xcbhash, 485);
315 afs_DequeueCallback(tvc);
316 tvc->states &= ~CStatd;
317 ReleaseWriteLock(&afs_xcbhash);
318 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
319 osi_dnlc_purgedp(tvc);
321 ObtainReadLock(&afs_xvcache);
323 /* our tvc ptr is still good until now */
328 osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */
329 ReleaseReadLock(&afs_xvcache);
333 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
335 } /*afs_CheckVolumeNames*/
338 static inVolList(fid, nvols, vID, cID)
339 struct VenusFid *fid;
340 afs_int32 nvols, *vID, *cID;
344 /* if no arrays present, be conservative and return true */
345 if ( nvols && (!vID || !cID))
348 for (i=0; i< nvols; ++i) {
349 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
356 /* afs_PutVolume is now a macro in afs.h */
360 * return volume struct if we have it cached and it's up-to-date
362 * Environment: Must be called with afs_xvolume unlocked.
364 struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
372 i = VHash(afid->Fid.Volume);
373 ObtainWriteLock(&afs_xvolume,106);
374 for (tv = afs_volumes[i]; tv; tv=tv->next) {
375 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
376 && (tv->states & VRecheck) == 0) {
381 ReleaseWriteLock(&afs_xvolume);
382 return tv; /* NULL if we didn't find it */
388 * Note that areq may be null, in which case we don't bother to set any
389 * request status information.
391 struct volume *afs_GetVolume(afid, areq, locktype)
392 struct vrequest *areq;
393 struct VenusFid *afid;
397 char *bp, tbuf[CVBS];
398 AFS_STATCNT(afs_GetVolume);
400 tv = afs_FindVolume(afid, locktype);
402 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
403 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
410 static struct volume *afs_SetupVolume(volid, aname, ve, tcell, agood, type, areq)
413 afs_int32 volid, agood, type;
415 struct vrequest *areq;
418 struct vldbentry *ove = (struct vldbentry *)ve;
419 struct nvldbentry *nve = (struct nvldbentry *)ve;
420 struct uvldbentry *uve = (struct uvldbentry *)ve;
422 int whichType; /* which type of volume to look for */
427 /* special hint from file server to use vlserver */
429 if (len >= 8 && strcmp(aname+len-7, ".backup") == 0)
431 else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0)
436 /* figure out which one we're really interested in (a set is returned) */
437 volid = afs_vtoi(aname);
440 volid = uve->volumeId[whichType];
442 else if (type == 1) {
443 volid = nve->volumeId[whichType];
446 volid = ove->volumeId[whichType];
452 ObtainWriteLock(&afs_xvolume,108);
454 for (tv = afs_volumes[i]; tv; tv=tv->next) {
455 if (tv->volume == volid && tv->cell == tcell->cell) {
460 struct fvolume *tf=0;
462 tv = afs_GetVolSlot();
463 bzero((char *)tv, sizeof(struct volume));
464 tv->cell = tcell->cell;
465 RWLOCK_INIT(&tv->lock, "volume lock");
466 tv->next = afs_volumes[i]; /* thread into list */
469 for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) {
470 if (afs_FVIndex != j) {
472 tfile = osi_UFSOpen(volumeInode);
473 err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume));
474 if (err != sizeof(struct fvolume))
475 osi_Panic("read volumeinfo2");
480 if (tf->cell == tv->cell && tf->volume == volid)
483 if (tf && (j != 0)) {
484 tv->vtix = afs_FVIndex;
485 tv->mtpoint = tf->mtpoint;
486 tv->dotdot = tf->dotdot;
487 tv->rootVnode = tf->rootVnode;
488 tv->rootUnique = tf->rootUnique;
491 tv->rootVnode = tv->rootUnique = 0;
495 tv->states &= ~VRecheck; /* just checked it */
496 tv->accessTime = osi_Time();
497 ReleaseWriteLock(&afs_xvolume);
498 ObtainWriteLock(&tv->lock,111);
500 InstallUVolumeEntry(tv, uve, tcell->cell, tcell, areq);
503 InstallNVolumeEntry(tv, nve, tcell->cell);
505 InstallVolumeEntry(tv, ove, tcell->cell);
508 tv->name = afs_osi_Alloc(strlen(aname) + 1);
509 strcpy(tv->name, aname);
512 for (i=0; i<NMAXNSERVERS; i++) {
513 tv->status[i] = not_busy;
515 ReleaseWriteLock(&tv->lock);
520 struct volume *afs_GetVolumeByName(aname, acell, agood, areq, locktype)
521 struct vrequest *areq;
524 register char *aname;
530 AFS_STATCNT(afs_GetVolumeByName);
531 ObtainWriteLock(&afs_xvolume,112);
532 for (i=0;i<NVOLS;i++) {
533 for (tv = afs_volumes[i]; tv; tv=tv->next) {
534 if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell
535 && (tv->states&VRecheck) == 0) {
537 ReleaseWriteLock(&afs_xvolume);
543 ReleaseWriteLock(&afs_xvolume);
545 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
550 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
551 struct vrequest *areq, afs_int32 locktype)
553 afs_int32 code, i, type=0;
554 struct volume *tv, *tv1;
555 struct vldbentry *tve;
556 struct nvldbentry *ntve;
557 struct uvldbentry *utve;
561 struct vrequest treq;
564 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
565 return (struct volume *) 0;
567 tcell = afs_GetCell(acell, READ_LOCK);
569 return (struct volume *) 0;
572 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
573 if (!areq) areq = &treq;
576 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
577 ICL_TYPE_POINTER, aname);
578 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
579 tve = (struct vldbentry *) (tbuffer+1024);
580 ntve = (struct nvldbentry *)tve;
581 utve = (struct uvldbentry *)tve;
582 afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
584 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
585 tcell->cell, &treq, SHARED_LOCK);
587 if (tconn->srvr->server->flags & SNO_LHOSTS) {
589 #ifdef RX_ENABLE_LOCKS
591 #endif /* RX_ENABLE_LOCKS */
592 code = VL_GetEntryByNameO(tconn->id, aname, tve);
593 #ifdef RX_ENABLE_LOCKS
595 #endif /* RX_ENABLE_LOCKS */
596 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
598 #ifdef RX_ENABLE_LOCKS
600 #endif /* RX_ENABLE_LOCKS */
601 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
602 #ifdef RX_ENABLE_LOCKS
604 #endif /* RX_ENABLE_LOCKS */
607 #ifdef RX_ENABLE_LOCKS
609 #endif /* RX_ENABLE_LOCKS */
610 code = VL_GetEntryByNameU(tconn->id, aname, utve);
611 #ifdef RX_ENABLE_LOCKS
613 #endif /* RX_ENABLE_LOCKS */
614 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
615 if (code == RXGEN_OPCODE) {
617 #ifdef RX_ENABLE_LOCKS
619 #endif /* RX_ENABLE_LOCKS */
620 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
621 #ifdef RX_ENABLE_LOCKS
623 #endif /* RX_ENABLE_LOCKS */
624 if (code == RXGEN_OPCODE) {
626 tconn->srvr->server->flags |= SNO_LHOSTS;
627 #ifdef RX_ENABLE_LOCKS
629 #endif /* RX_ENABLE_LOCKS */
630 code = VL_GetEntryByNameO(tconn->id, aname, tve);
631 #ifdef RX_ENABLE_LOCKS
633 #endif /* RX_ENABLE_LOCKS */
635 tconn->srvr->server->flags |= SYES_LHOSTS;
637 tconn->srvr->server->flags |= SVLSRV_UUID;
644 (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
645 -1, /* no op code for this */
646 SHARED_LOCK, tcell));
649 /* If the client has yet to contact this cell and contact failed due
650 * to network errors, mark the VLDB servers as back up.
651 * That the client tried and failed can be determined from the
652 * fact that there was a downtime incident, but CHasVolRef is not set.
654 if (areq->networkError && !(tcell->states & CHasVolRef)) {
658 for (i=0; i<MAXCELLHOSTS; i++) {
659 if ((sp = tcell->cellHosts[i]) == (struct server *) 0) break;
660 for (sap = sp->addr; sap; sap = sap->next_sa)
661 afs_MarkServerUpOrDown(sap, 0);
664 afs_CopyError(&treq, areq);
665 osi_FreeLargeSpace(tbuffer);
666 afs_PutCell(tcell, READ_LOCK);
667 return (struct volume *) 0;
670 * Check to see if this cell has not yet referenced a volume. If
671 * it hasn't, it's just about to change its status, and we need to mark
672 * this fact down. Note that it is remotely possible that afs_SetupVolume
673 * could fail and we would still not have a volume reference.
675 if (!(tcell->states & CHasVolRef)) {
676 tcell->states |= CHasVolRef;
677 afs_stats_cmperf.numCellsContacted++;
678 } /*First time a volume in this cell has been referenced*/
686 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
687 if ((agood == 2) && tv->roVol) {
689 * This means that very soon we'll ask for the RO volume so
690 * we'll prefetch it (well we did already.)
692 tv1 = afs_SetupVolume(tv->roVol, (char *)0, ve, tcell, 0, type, areq);
695 osi_FreeLargeSpace(tbuffer);
696 afs_PutCell(tcell, READ_LOCK);
699 } /*afs_NewVolumeByName*/
703 /* call this with the volume structure locked; used for new-style vldb requests */
704 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
706 register struct server *ts;
712 AFS_STATCNT(InstallVolumeEntry);
714 /* Determine the type of volume we want */
715 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
718 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
722 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
723 /* backup always is on the same volume as parent */
725 av->states |= (VRO|VBackup);
728 mask = 0; /* Can't find volume in vldb entry */
731 /* fill in volume types */
732 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
733 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
734 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
736 if (ve->flags & VLF_DFSFILESET)
737 av->states |= VForeign;
739 cellp = afs_GetCell(acell, 0);
741 /* Step through the VLDB entry making sure each server listed is there */
742 for (i=0,j=0; i<ve->nServers; i++) {
743 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
744 continue; /* wrong volume or don't use this volume */
747 temp = htonl(ve->serverNumber[i]);
748 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
749 av->serverHost[j] = ts;
752 * The cell field could be 0 if the server entry was created
753 * first with the 'fs setserverprefs' call which doesn't set
754 * the cell field. Thus if the afs_GetServer call above
755 * follows later on it will find the server entry thus it will
756 * simply return without setting any fields, so we set the
757 * field ourselves below.
761 afs_PutServer(ts, WRITE_LOCK);
765 av->serverHost[j++] = 0;
767 afs_SortServers(av->serverHost, MAXHOSTS);
768 } /*InstallVolumeEntry*/
771 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
773 register struct server *ts;
779 AFS_STATCNT(InstallVolumeEntry);
781 /* Determine type of volume we want */
782 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
785 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
789 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
790 /* backup always is on the same volume as parent */
792 av->states |= (VRO|VBackup);
795 mask = 0; /* Can't find volume in vldb entry */
798 /* fill in volume types */
799 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
800 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
801 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
803 if (ve->flags & VLF_DFSFILESET)
804 av->states |= VForeign;
806 cellp = afs_GetCell(acell, 0);
808 /* Step through the VLDB entry making sure each server listed is there */
809 for (i=0,j=0; i<ve->nServers; i++) {
810 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
811 continue; /* wrong volume or don't use this volume */
814 temp = htonl(ve->serverNumber[i]);
815 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
816 av->serverHost[j] = ts;
818 * The cell field could be 0 if the server entry was created
819 * first with the 'fs setserverprefs' call which doesn't set
820 * the cell field. Thus if the afs_GetServer call above
821 * follows later on it will find the server entry thus it will
822 * simply return without setting any fields, so we set the
823 * field ourselves below.
827 afs_PutServer(ts, WRITE_LOCK);
831 av->serverHost[j++] = 0;
833 afs_SortServers(av->serverHost, MAXHOSTS);
834 } /*InstallNVolumeEntry*/
837 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
838 int acell, struct cell *tcell, struct vrequest *areq)
840 register struct srvAddr *sa;
841 register struct server *ts;
849 AFS_STATCNT(InstallVolumeEntry);
851 /* Determine type of volume we want */
852 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
855 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
859 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
860 /* backup always is on the same volume as parent */
862 av->states |= (VRO|VBackup);
865 mask = 0; /* Can't find volume in vldb entry */
868 /* fill in volume types */
869 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
870 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
871 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
873 if (ve->flags & VLF_DFSFILESET)
874 av->states |= VForeign;
876 cellp = afs_GetCell(acell, 0);
878 /* This volume, av, is locked. Zero out the serverHosts[] array
879 * so that if afs_GetServer() decides to replace the server
880 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
883 for (j=0; j<MAXHOSTS; j++) {
884 av->serverHost[j] = 0;
887 /* Gather the list of servers the VLDB says the volume is on
888 * and initialize the ve->serverHost[] array. If a server struct
889 * is not found, then get the list of addresses for the
890 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
892 for (i=0,j=0; i<ve->nServers; i++) {
893 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
894 continue; /* wrong volume don't use this volume */
897 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
898 /* The server has no uuid */
899 serverid = htonl(ve->serverNumber[i].time_low);
900 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
902 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
903 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
904 /* uuid, uniquifier, and portal are the same */
906 afs_uint32 *addrp, nentries, code, unique;
908 ListAddrByAttributes attrs;
911 bzero((char *)&attrs, sizeof(attrs));
912 attrs.Mask = VLADDR_UUID;
913 attrs.uuid = ve->serverNumber[i];
914 bzero((char *)&uuid, sizeof(uuid));
915 bzero((char *)&addrs, sizeof(addrs));
917 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
918 tcell->cell, areq, SHARED_LOCK);
920 #ifdef RX_ENABLE_LOCKS
922 #endif /* RX_ENABLE_LOCKS */
923 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
924 #ifdef RX_ENABLE_LOCKS
926 #endif /* RX_ENABLE_LOCKS */
931 /* Handle corrupt VLDB (defect 7393) */
932 if (code == 0 && nentries == 0)
935 } while (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
936 -1, SHARED_LOCK, tcell));
938 /* Better handing of such failures; for now we'll simply retry this call */
939 areq->volumeError = 1;
943 addrp = addrs.bulkaddrs_val;
944 for (k = 0; k < nentries; k++) {
945 addrp[k] = htonl(addrp[k]);
947 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
948 WRITE_LOCK, &ve->serverNumber[i],
949 ve->serverUnique[i]);
950 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
953 av->serverHost[j] = ts;
955 /* The cell field could be 0 if the server entry was created
956 * first with the 'fs setserverprefs' call which doesn't set
957 * the cell field. Thus if the afs_GetServer call above
958 * follows later on it will find the server entry thus it will
959 * simply return without setting any fields, so we set the
960 * field ourselves below.
964 afs_PutServer(ts, WRITE_LOCK);
968 afs_SortServers(av->serverHost, MAXHOSTS);
969 } /*InstallVolumeEntry*/
972 void afs_ResetVolumeInfo(struct volume *tv)
976 AFS_STATCNT(afs_ResetVolumeInfo);
977 ObtainWriteLock(&tv->lock,117);
978 tv->states |= VRecheck;
979 for (i=0; i<MAXHOSTS; i++)
980 tv->status[i] = not_busy;
982 afs_osi_Free(tv->name, strlen(tv->name)+1);
983 tv->name = (char *) 0;
985 ReleaseWriteLock(&tv->lock);
986 } /*afs_ResetVolumeInfo*/