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) {
622 #ifdef RX_ENABLE_LOCKS
624 #endif /* RX_ENABLE_LOCKS */
625 code = VL_GetEntryByNameO(tconn->id, aname, tve);
626 #ifdef RX_ENABLE_LOCKS
628 #endif /* RX_ENABLE_LOCKS */
629 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
631 #ifdef RX_ENABLE_LOCKS
633 #endif /* RX_ENABLE_LOCKS */
634 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
635 #ifdef RX_ENABLE_LOCKS
637 #endif /* RX_ENABLE_LOCKS */
640 #ifdef RX_ENABLE_LOCKS
642 #endif /* RX_ENABLE_LOCKS */
643 code = VL_GetEntryByNameU(tconn->id, aname, utve);
644 #ifdef RX_ENABLE_LOCKS
646 #endif /* RX_ENABLE_LOCKS */
647 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
648 if (code == RXGEN_OPCODE) {
650 #ifdef RX_ENABLE_LOCKS
652 #endif /* RX_ENABLE_LOCKS */
653 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
654 #ifdef RX_ENABLE_LOCKS
656 #endif /* RX_ENABLE_LOCKS */
657 if (code == RXGEN_OPCODE) {
659 tconn->srvr->server->flags |= SNO_LHOSTS;
660 #ifdef RX_ENABLE_LOCKS
662 #endif /* RX_ENABLE_LOCKS */
663 code = VL_GetEntryByNameO(tconn->id, aname, tve);
664 #ifdef RX_ENABLE_LOCKS
666 #endif /* RX_ENABLE_LOCKS */
668 tconn->srvr->server->flags |= SYES_LHOSTS;
670 tconn->srvr->server->flags |= SVLSRV_UUID;
677 (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
678 -1, /* no op code for this */
679 SHARED_LOCK, tcell));
682 /* If the client has yet to contact this cell and contact failed due
683 * to network errors, mark the VLDB servers as back up.
684 * That the client tried and failed can be determined from the
685 * fact that there was a downtime incident, but CHasVolRef is not set.
687 if (areq->networkError && !(tcell->states & CHasVolRef)) {
691 for (i=0; i<MAXCELLHOSTS; i++) {
692 if ((sp = tcell->cellHosts[i]) == (struct server *) 0) break;
693 for (sap = sp->addr; sap; sap = sap->next_sa)
694 afs_MarkServerUpOrDown(sap, 0);
697 afs_CopyError(&treq, areq);
698 osi_FreeLargeSpace(tbuffer);
699 afs_PutCell(tcell, READ_LOCK);
700 return (struct volume *) 0;
703 * Check to see if this cell has not yet referenced a volume. If
704 * it hasn't, it's just about to change its status, and we need to mark
705 * this fact down. Note that it is remotely possible that afs_SetupVolume
706 * could fail and we would still not have a volume reference.
708 if (!(tcell->states & CHasVolRef)) {
709 tcell->states |= CHasVolRef;
710 afs_stats_cmperf.numCellsContacted++;
711 } /*First time a volume in this cell has been referenced*/
719 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
720 if ((agood == 2) && tv->roVol) {
722 * This means that very soon we'll ask for the RO volume so
723 * we'll prefetch it (well we did already.)
725 tv1 = afs_SetupVolume(tv->roVol, (char *)0, ve, tcell, 0, type, areq);
728 osi_FreeLargeSpace(tbuffer);
729 afs_PutCell(tcell, READ_LOCK);
732 } /*afs_NewVolumeByName*/
736 /* call this with the volume structure locked; used for new-style vldb requests */
737 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
739 register struct server *ts;
745 AFS_STATCNT(InstallVolumeEntry);
747 /* Determine the type of volume we want */
748 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
751 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
755 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
756 /* backup always is on the same volume as parent */
758 av->states |= (VRO|VBackup);
761 mask = 0; /* Can't find volume in vldb entry */
764 /* fill in volume types */
765 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
766 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
767 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
769 if (ve->flags & VLF_DFSFILESET)
770 av->states |= VForeign;
772 cellp = afs_GetCell(acell, 0);
774 /* Step through the VLDB entry making sure each server listed is there */
775 for (i=0,j=0; i<ve->nServers; i++) {
776 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
777 continue; /* wrong volume or don't use this volume */
780 temp = htonl(ve->serverNumber[i]);
781 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
782 av->serverHost[j] = ts;
785 * The cell field could be 0 if the server entry was created
786 * first with the 'fs setserverprefs' call which doesn't set
787 * the cell field. Thus if the afs_GetServer call above
788 * follows later on it will find the server entry thus it will
789 * simply return without setting any fields, so we set the
790 * field ourselves below.
794 afs_PutServer(ts, WRITE_LOCK);
798 av->serverHost[j++] = 0;
800 afs_SortServers(av->serverHost, MAXHOSTS);
801 } /*InstallVolumeEntry*/
804 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
806 register struct server *ts;
812 AFS_STATCNT(InstallVolumeEntry);
814 /* Determine type of volume we want */
815 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
818 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
822 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
823 /* backup always is on the same volume as parent */
825 av->states |= (VRO|VBackup);
828 mask = 0; /* Can't find volume in vldb entry */
831 /* fill in volume types */
832 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
833 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
834 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
836 if (ve->flags & VLF_DFSFILESET)
837 av->states |= VForeign;
839 cellp = afs_GetCell(acell, 0);
841 /* Step through the VLDB entry making sure each server listed is there */
842 for (i=0,j=0; i<ve->nServers; i++) {
843 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
844 continue; /* wrong volume or don't use this volume */
847 temp = htonl(ve->serverNumber[i]);
848 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
849 av->serverHost[j] = ts;
851 * The cell field could be 0 if the server entry was created
852 * first with the 'fs setserverprefs' call which doesn't set
853 * the cell field. Thus if the afs_GetServer call above
854 * follows later on it will find the server entry thus it will
855 * simply return without setting any fields, so we set the
856 * field ourselves below.
860 afs_PutServer(ts, WRITE_LOCK);
864 av->serverHost[j++] = 0;
866 afs_SortServers(av->serverHost, MAXHOSTS);
867 } /*InstallNVolumeEntry*/
870 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
871 int acell, struct cell *tcell, struct vrequest *areq)
873 register struct srvAddr *sa;
874 register struct server *ts;
882 AFS_STATCNT(InstallVolumeEntry);
884 /* Determine type of volume we want */
885 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
888 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
892 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
893 /* backup always is on the same volume as parent */
895 av->states |= (VRO|VBackup);
898 mask = 0; /* Can't find volume in vldb entry */
901 /* fill in volume types */
902 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
903 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
904 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
906 if (ve->flags & VLF_DFSFILESET)
907 av->states |= VForeign;
909 cellp = afs_GetCell(acell, 0);
911 /* This volume, av, is locked. Zero out the serverHosts[] array
912 * so that if afs_GetServer() decides to replace the server
913 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
916 for (j=0; j<MAXHOSTS; j++) {
917 av->serverHost[j] = 0;
920 /* Gather the list of servers the VLDB says the volume is on
921 * and initialize the ve->serverHost[] array. If a server struct
922 * is not found, then get the list of addresses for the
923 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
925 for (i=0,j=0; i<ve->nServers; i++) {
926 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
927 continue; /* wrong volume don't use this volume */
930 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
931 /* The server has no uuid */
932 serverid = htonl(ve->serverNumber[i].time_low);
933 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
935 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
936 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
937 /* uuid, uniquifier, and portal are the same */
939 afs_uint32 *addrp, nentries, code, unique;
941 ListAddrByAttributes attrs;
944 memset((char *)&attrs, 0, sizeof(attrs));
945 attrs.Mask = VLADDR_UUID;
946 attrs.uuid = ve->serverNumber[i];
947 memset((char *)&uuid, 0, sizeof(uuid));
948 memset((char *)&addrs, 0, sizeof(addrs));
950 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
951 tcell->cell, areq, SHARED_LOCK);
953 #ifdef RX_ENABLE_LOCKS
955 #endif /* RX_ENABLE_LOCKS */
956 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
957 #ifdef RX_ENABLE_LOCKS
959 #endif /* RX_ENABLE_LOCKS */
964 /* Handle corrupt VLDB (defect 7393) */
965 if (code == 0 && nentries == 0)
968 } while (afs_Analyze(tconn, code, (struct VenusFid *) 0, areq,
969 -1, SHARED_LOCK, tcell));
971 /* Better handing of such failures; for now we'll simply retry this call */
972 areq->volumeError = 1;
976 addrp = addrs.bulkaddrs_val;
977 for (k = 0; k < nentries; k++) {
978 addrp[k] = htonl(addrp[k]);
980 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
981 WRITE_LOCK, &ve->serverNumber[i],
982 ve->serverUnique[i]);
983 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
986 av->serverHost[j] = ts;
988 /* The cell field could be 0 if the server entry was created
989 * first with the 'fs setserverprefs' call which doesn't set
990 * the cell field. Thus if the afs_GetServer call above
991 * follows later on it will find the server entry thus it will
992 * simply return without setting any fields, so we set the
993 * field ourselves below.
997 afs_PutServer(ts, WRITE_LOCK);
1001 afs_SortServers(av->serverHost, MAXHOSTS);
1002 } /*InstallVolumeEntry*/
1005 void afs_ResetVolumeInfo(struct volume *tv)
1009 AFS_STATCNT(afs_ResetVolumeInfo);
1010 ObtainWriteLock(&tv->lock,117);
1011 tv->states |= VRecheck;
1012 for (i=0; i<MAXHOSTS; i++)
1013 tv->status[i] = not_busy;
1015 afs_osi_Free(tv->name, strlen(tv->name)+1);
1016 tv->name = (char *) 0;
1018 ReleaseWriteLock(&tv->lock);
1019 } /*afs_ResetVolumeInfo*/