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"
25 #include "afs/sysincludes.h" /* Standard vendor system headers */
28 #if !defined(AFS_LINUX20_ENV)
31 #include <netinet/in.h>
34 #include "h/hashing.h"
36 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV)
37 #include <netinet/in_var.h>
38 #endif /* ! AFS_HPUX110_ENV */
39 #endif /* !defined(UKERNEL) */
41 #include "afsincludes.h" /* Afs-based standard headers */
42 #include "afs/afs_stats.h" /* afs statistics */
44 #if defined(AFS_SUN56_ENV)
46 #include <inet/common.h>
47 #if defined(AFS_SUN58_ENV)
48 #include <netinet/ip6.h>
53 /* In case we don't have the vl error table yet. */
54 #ifndef ERROR_TABLE_BASE_VL
55 #define ERROR_TABLE_BASE_VL (363520L)
56 #define VL_NOENT (363524L)
57 #endif /* vlserver error base define */
59 /* Exported variables */
60 ino_t volumeInode; /*Inode for VolumeItems file */
61 afs_rwlock_t afs_xvolume; /* allocation lock for volumes */
62 struct volume *afs_freeVolList;
63 struct volume *afs_volumes[NVOLS];
64 afs_int32 afs_volCounter = 1; /* for allocating volume indices */
65 afs_int32 fvTable[NFENTRIES];
67 /* Forward declarations */
68 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell,
69 int agood, struct vrequest *areq,
71 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
72 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
76 /* Convert a volume name to a #; return 0 if can't parse as a number */
78 afs_vtoi(register char *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 */
108 afs_UFSGetVolSlot(void)
110 register struct volume *tv, **lv;
111 struct osi_file *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);
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];
147 fvTable[i] = tv->vtix;
150 * Haul the guy in from disk so we don't overwrite hash table
153 if (afs_FVIndex != tv->vtix) {
154 tfile = osi_UFSOpen(volumeInode);
156 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);
173 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
174 &staticFVolume, sizeof(struct fvolume));
175 if (code != sizeof(struct fvolume))
176 osi_Panic("write volumeinfo");
179 tv = afs_freeVolList;
180 afs_freeVolList = tv->next;
184 } /*afs_UFSGetVolSlot */
188 afs_MemGetVolSlot(void)
190 register struct volume *tv;
192 AFS_STATCNT(afs_MemGetVolSlot);
193 if (!afs_freeVolList) {
194 struct volume *newVp;
196 newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume));
199 afs_freeVolList = newVp;
201 tv = afs_freeVolList;
202 afs_freeVolList = tv->next;
205 } /*afs_MemGetVolSlot */
207 /* afs_ResetVolumes()
208 * Reset volume inforamation for all volume structs that
209 * point to a speicific server.
212 afs_ResetVolumes(struct server *srvp)
217 /* Find any volumes residing on this server and flush their state */
218 for (j = 0; j < NVOLS; j++) {
219 for (vp = afs_volumes[j]; vp; vp = vp->next) {
220 for (k = 0; k < MAXHOSTS; k++) {
221 if (!srvp || (vp->serverHost[k] == srvp)) {
222 vp->serverHost[k] = 0;
223 afs_ResetVolumeInfo(vp);
232 /* reset volume name to volume id mapping cache */
234 afs_CheckVolumeNames(int flags)
240 afs_int32 *volumeID, *cellID, vsize, nvols;
241 AFS_STATCNT(afs_CheckVolumeNames);
244 volumeID = cellID = NULL;
246 ObtainReadLock(&afs_xvolume);
247 if (flags & AFS_VOLCHECK_EXPIRED) {
249 * allocate space to hold the volumeIDs and cellIDs, only if
250 * we will be invalidating the mountpoints later on
252 for (i = 0; i < NVOLS; i++)
253 for (tv = afs_volumes[i]; tv; tv = tv->next)
256 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
257 cellID = (volumeID) ? volumeID + vsize : 0;
261 for (i = 0; i < NVOLS; i++) {
262 for (tv = afs_volumes[i]; tv; tv = tv->next) {
263 if (flags & AFS_VOLCHECK_EXPIRED) {
264 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
265 || (flags & AFS_VOLCHECK_FORCE)) {
266 afs_ResetVolumeInfo(tv); /* also resets status */
268 volumeID[nvols] = tv->volume;
269 cellID[nvols] = tv->cell;
275 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
276 for (j = 0; j < MAXHOSTS; j++)
277 tv->status[j] = not_busy;
282 ReleaseReadLock(&afs_xvolume);
285 /* next ensure all mt points are re-evaluated */
286 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
287 ObtainReadLock(&afs_xvcache);
288 for (i = 0; i < VCSIZE; i++) {
289 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
291 /* if the volume of "mvid" of the vcache entry is among the
292 * ones we found earlier, then we re-evaluate it. Also, if the
293 * force bit is set or we explicitly asked to reevaluate the
294 * mt-pts, we clean the cmvalid bit */
296 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
298 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
299 tvc->states &= ~CMValid;
301 /* If the volume that this file belongs to was reset earlier,
302 * then we should remove its callback.
303 * Again, if forced, always do it.
305 if ((tvc->states & CRO)
306 && (inVolList(&tvc->fid, nvols, volumeID, cellID)
307 || (flags & AFS_VOLCHECK_FORCE))) {
310 ReleaseReadLock(&afs_xvcache);
312 ObtainWriteLock(&afs_xcbhash, 485);
313 /* LOCKXXX: We aren't holding tvc write lock? */
314 afs_DequeueCallback(tvc);
315 tvc->states &= ~CStatd;
316 ReleaseWriteLock(&afs_xcbhash);
317 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
318 osi_dnlc_purgedp(tvc);
320 ObtainReadLock(&afs_xvcache);
322 /* our tvc ptr is still good until now */
327 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
328 ReleaseReadLock(&afs_xvcache);
332 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
334 } /*afs_CheckVolumeNames */
338 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
343 /* if no arrays present, be conservative and return true */
344 if (nvols && (!vID || !cID))
347 for (i = 0; i < nvols; ++i) {
348 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
355 /* afs_PutVolume is now a macro in afs.h */
359 * return volume struct if we have it cached and it's up-to-date
361 * Environment: Must be called with afs_xvolume unlocked.
364 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 */
383 } /*afs_FindVolume */
388 * Note that areq may be null, in which case we don't bother to set any
389 * request status information.
392 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
396 char *bp, tbuf[CVBS];
397 AFS_STATCNT(afs_GetVolume);
399 tv = afs_FindVolume(afid, locktype);
401 if (afs_IsDynrootFid(afid)) {
402 tv = afs_NewDynrootVolume(afid);
404 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
405 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
413 static struct volume *
414 afs_SetupVolume(afs_int32 volid, char *aname, char *ve, struct cell *tcell,
415 afs_int32 agood, afs_int32 type, 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];
441 } else if (type == 1) {
442 volid = nve->volumeId[whichType];
444 volid = ove->volumeId[whichType];
450 ObtainWriteLock(&afs_xvolume, 108);
452 for (tv = afs_volumes[i]; tv; tv = tv->next) {
453 if (tv->volume == volid && tv->cell == tcell->cellNum) {
458 struct fvolume *tf = 0;
460 tv = afs_GetVolSlot();
461 memset((char *)tv, 0, sizeof(struct volume));
462 tv->cell = tcell->cellNum;
463 RWLOCK_INIT(&tv->lock, "volume lock");
464 tv->next = afs_volumes[i]; /* thread into list */
467 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
468 if (afs_FVIndex != j) {
469 struct osi_file *tfile;
470 tfile = osi_UFSOpen(volumeInode);
472 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
473 &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->cellNum, tcell, areq);
501 } else if (type == 1)
502 InstallNVolumeEntry(tv, nve, tcell->cellNum);
504 InstallVolumeEntry(tv, ove, tcell->cellNum);
507 tv->name = afs_osi_Alloc(strlen(aname) + 1);
508 strcpy(tv->name, aname);
511 for (i = 0; i < NMAXNSERVERS; i++) {
512 tv->status[i] = not_busy;
514 ReleaseWriteLock(&tv->lock);
520 afs_GetVolumeByName(register char *aname, afs_int32 acell, int agood,
521 struct vrequest *areq, afs_int32 locktype)
526 AFS_STATCNT(afs_GetVolumeByName);
527 ObtainWriteLock(&afs_xvolume, 112);
528 for (i = 0; i < NVOLS; i++) {
529 for (tv = afs_volumes[i]; tv; tv = tv->next) {
530 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
531 && (tv->states & VRecheck) == 0) {
533 ReleaseWriteLock(&afs_xvolume);
539 ReleaseWriteLock(&afs_xvolume);
541 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
545 static struct volume *
546 afs_NewDynrootVolume(struct VenusFid *fid)
550 struct vldbentry *tve;
551 char *bp, tbuf[CVBS];
553 tcell = afs_GetCell(fid->Cell, READ_LOCK);
556 tve = afs_osi_Alloc(sizeof(*tve));
557 if (!(tcell->states & CHasVolRef))
558 tcell->states |= CHasVolRef;
560 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
561 memset(tve, 0, sizeof(*tve));
562 strcpy(tve->name, "local-dynroot");
563 tve->volumeId[ROVOL] = fid->Fid.Volume;
564 tve->flags = VLF_ROEXISTS;
566 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
567 afs_PutCell(tcell, READ_LOCK);
568 afs_osi_Free(tve, sizeof(*tve));
573 static struct volume *
574 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
575 struct vrequest *areq, afs_int32 locktype)
577 afs_int32 code, type = 0;
578 struct volume *tv, *tv1;
579 struct vldbentry *tve;
580 struct nvldbentry *ntve;
581 struct uvldbentry *utve;
585 struct vrequest treq;
587 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
590 tcell = afs_GetCell(acell, READ_LOCK);
595 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
600 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
601 ICL_TYPE_POINTER, aname);
602 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
603 tve = (struct vldbentry *)(tbuffer + 1024);
604 ntve = (struct nvldbentry *)tve;
605 utve = (struct uvldbentry *)tve;
606 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
609 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
612 if (tconn->srvr->server->flags & SNO_LHOSTS) {
615 code = VL_GetEntryByNameO(tconn->id, aname, tve);
617 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
620 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
625 code = VL_GetEntryByNameU(tconn->id, aname, utve);
627 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
628 if (code == RXGEN_OPCODE) {
631 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
633 if (code == RXGEN_OPCODE) {
635 tconn->srvr->server->flags |= SNO_LHOSTS;
637 code = VL_GetEntryByNameO(tconn->id, aname, tve);
640 tconn->srvr->server->flags |= SYES_LHOSTS;
642 tconn->srvr->server->flags |= SVLSRV_UUID;
648 } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */
649 SHARED_LOCK, tcell));
652 /* If the client has yet to contact this cell and contact failed due
653 * to network errors, mark the VLDB servers as back up.
654 * That the client tried and failed can be determined from the
655 * fact that there was a downtime incident, but CHasVolRef is not set.
657 if (areq->networkError && !(tcell->states & CHasVolRef)) {
661 for (i = 0; i < MAXCELLHOSTS; i++) {
662 if ((sp = tcell->cellHosts[i]) == NULL)
664 for (sap = sp->addr; sap; sap = sap->next_sa)
665 afs_MarkServerUpOrDown(sap, 0);
668 afs_CopyError(&treq, areq);
669 osi_FreeLargeSpace(tbuffer);
670 afs_PutCell(tcell, READ_LOCK);
674 * Check to see if this cell has not yet referenced a volume. If
675 * it hasn't, it's just about to change its status, and we need to mark
676 * this fact down. Note that it is remotely possible that afs_SetupVolume
677 * could fail and we would still not have a volume reference.
679 if (!(tcell->states & CHasVolRef)) {
680 tcell->states |= CHasVolRef;
681 afs_stats_cmperf.numCellsContacted++;
683 /*First time a volume in this cell has been referenced */
690 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
691 if ((agood == 3) && tv->backVol) {
693 * This means that very soon we'll ask for the BK volume so
694 * we'll prefetch it (well we did already.)
697 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, 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, NULL, 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 */
718 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
720 register struct server *ts;
726 AFS_STATCNT(InstallVolumeEntry);
728 /* Determine the type of volume we want */
729 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
731 } else if ((ve->flags & VLF_ROEXISTS)
732 && (av->volume == ve->volumeId[ROVOL])) {
735 } else if ((ve->flags & VLF_BACKEXISTS)
736 && (av->volume == ve->volumeId[BACKVOL])) {
737 /* backup always is on the same volume as parent */
739 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)
766 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
767 continue; /* wrong volume or don't use this volume */
770 temp = htonl(ve->serverNumber[i]);
771 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
773 av->serverHost[j] = ts;
776 * The cell field could be 0 if the server entry was created
777 * first with the 'fs setserverprefs' call which doesn't set
778 * the cell field. Thus if the afs_GetServer call above
779 * follows later on it will find the server entry thus it will
780 * simply return without setting any fields, so we set the
781 * field ourselves below.
785 afs_PutServer(ts, WRITE_LOCK);
789 av->serverHost[j++] = 0;
791 afs_SortServers(av->serverHost, MAXHOSTS);
792 } /*InstallVolumeEntry */
796 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
798 register struct server *ts;
804 AFS_STATCNT(InstallVolumeEntry);
806 /* Determine type of volume we want */
807 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
809 } else if ((ve->flags & VLF_ROEXISTS)
810 && (av->volume == ve->volumeId[ROVOL])) {
813 } else if ((ve->flags & VLF_BACKEXISTS)
814 && (av->volume == ve->volumeId[BACKVOL])) {
815 /* backup always is on the same volume as parent */
817 av->states |= (VRO | VBackup);
819 mask = 0; /* Can't find volume in vldb entry */
822 /* fill in volume types */
823 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
824 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
825 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
827 if (ve->flags & VLF_DFSFILESET)
828 av->states |= VForeign;
830 cellp = afs_GetCell(acell, 0);
832 /* This volume, av, is locked. Zero out the serverHosts[] array
833 * so that if afs_GetServer() decides to replace the server
834 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
837 for (j = 0; j < MAXHOSTS; j++) {
838 av->serverHost[j] = 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)
844 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
845 continue; /* wrong volume or don't use this volume */
848 temp = htonl(ve->serverNumber[i]);
849 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
851 av->serverHost[j] = ts;
853 * The cell field could be 0 if the server entry was created
854 * first with the 'fs setserverprefs' call which doesn't set
855 * the cell field. Thus if the afs_GetServer call above
856 * follows later on it will find the server entry thus it will
857 * simply return without setting any fields, so we set the
858 * field ourselves below.
862 afs_PutServer(ts, WRITE_LOCK);
866 av->serverHost[j++] = 0;
868 afs_SortServers(av->serverHost, MAXHOSTS);
869 } /*InstallNVolumeEntry */
873 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
874 struct cell *tcell, struct vrequest *areq)
876 register struct server *ts;
884 AFS_STATCNT(InstallVolumeEntry);
886 /* Determine type of volume we want */
887 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
889 } else if ((ve->flags & VLF_ROEXISTS)
890 && av->volume == ve->volumeId[ROVOL]) {
893 } else if ((ve->flags & VLF_BACKEXISTS)
894 && (av->volume == ve->volumeId[BACKVOL])) {
895 /* backup always is on the same volume as parent */
897 av->states |= (VRO | VBackup);
899 mask = 0; /* Can't find volume in vldb entry */
902 /* fill in volume types */
903 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
904 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
905 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
907 if (ve->flags & VLF_DFSFILESET)
908 av->states |= VForeign;
910 cellp = afs_GetCell(acell, 0);
912 /* This volume, av, is locked. Zero out the serverHosts[] array
913 * so that if afs_GetServer() decides to replace the server
914 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
917 for (j = 0; j < MAXHOSTS; j++) {
918 av->serverHost[j] = 0;
921 /* Gather the list of servers the VLDB says the volume is on
922 * and initialize the ve->serverHost[] array. If a server struct
923 * is not found, then get the list of addresses for the
924 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
926 for (i = 0, j = 0; i < ve->nServers; i++) {
927 if (((ve->serverFlags[i] & mask) == 0)
928 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
929 continue; /* wrong volume don't use this volume */
932 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
933 /* The server has no uuid */
934 serverid = htonl(ve->serverNumber[i].time_low);
935 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
938 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
939 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
941 /* uuid, uniquifier, and portal are the same */
943 afs_uint32 *addrp, nentries, code, unique;
945 ListAddrByAttributes attrs;
948 memset((char *)&attrs, 0, sizeof(attrs));
949 attrs.Mask = VLADDR_UUID;
950 attrs.uuid = ve->serverNumber[i];
951 memset((char *)&uuid, 0, sizeof(uuid));
952 memset((char *)&addrs, 0, sizeof(addrs));
955 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
956 tcell->cellNum, areq, SHARED_LOCK);
960 VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique,
967 /* Handle corrupt VLDB (defect 7393) */
968 if (code == 0 && nentries == 0)
972 (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
974 /* Better handing of such failures; for now we'll simply retry this call */
975 areq->volumeError = 1;
979 addrp = addrs.bulkaddrs_val;
980 for (k = 0; k < nentries; k++) {
981 addrp[k] = htonl(addrp[k]);
983 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
984 WRITE_LOCK, &ve->serverNumber[i],
985 ve->serverUnique[i]);
986 afs_osi_Free(addrs.bulkaddrs_val,
987 addrs.bulkaddrs_len * sizeof(*addrp));
990 av->serverHost[j] = ts;
992 /* The cell field could be 0 if the server entry was created
993 * first with the 'fs setserverprefs' call which doesn't set
994 * the cell field. Thus if the afs_GetServer call above
995 * follows later on it will find the server entry thus it will
996 * simply return without setting any fields, so we set the
997 * field ourselves below.
1001 afs_PutServer(ts, WRITE_LOCK);
1005 afs_SortServers(av->serverHost, MAXHOSTS);
1006 } /*InstallVolumeEntry */
1010 afs_ResetVolumeInfo(struct volume *tv)
1014 AFS_STATCNT(afs_ResetVolumeInfo);
1015 ObtainWriteLock(&tv->lock, 117);
1016 tv->states |= VRecheck;
1017 for (i = 0; i < MAXHOSTS; i++)
1018 tv->status[i] = not_busy;
1020 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1023 ReleaseWriteLock(&tv->lock);