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/sysincludes.h" /* Standard vendor system headers */
26 #if !defined(AFS_LINUX20_ENV)
29 #include <netinet/in.h>
32 #include "h/hashing.h"
34 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV)
35 #include <netinet/in_var.h>
36 #endif /* ! AFS_HPUX110_ENV */
37 #endif /* !defined(UKERNEL) */
39 #include "afsincludes.h" /* Afs-based standard headers */
40 #include "afs/afs_stats.h" /* afs statistics */
41 #include "afs/afs_dynroot.h"
43 #if defined(AFS_SUN5_ENV)
45 #include <inet/common.h>
46 #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 afs_dcache_id_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,
66 int agood, struct vrequest *areq,
68 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
69 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
75 * Convert a volume name to a number;
76 * @param aname Volume name.
77 * @return return 0 if can't parse as a number.
85 AFS_STATCNT(afs_vtoi);
86 while ((tc = *aname++)) {
87 if (tc > '9' || tc < '0')
88 return 0; /* invalid name */
98 * All of the vol cache routines must be called with the afs_xvolume
99 * lock held in exclusive mode, since they use static variables.
100 * In addition, we don't want two people adding the same volume
104 static struct fvolume staticFVolume;
105 afs_int32 afs_FVIndex = -1;
108 * UFS specific version of afs_GetVolSlot
112 afs_UFSGetVolSlot(void)
114 struct volume *tv = NULL, **lv;
115 struct osi_file *tfile;
116 afs_int32 i = -1, code;
118 struct volume *bestVp, *oldLp = NULL, **bestLp = NULL;
119 char *oldname = NULL;
120 afs_int32 oldvtix = -2; /* Initialize to a value that doesn't occur */
122 AFS_STATCNT(afs_UFSGetVolSlot);
123 if (!afs_freeVolList) {
125 bestTime = 0x7fffffff;
128 for (i = 0; i < NVOLS; i++) {
129 lv = &afs_volumes[i];
130 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
131 if (tv->refCount == 0) { /* is this one available? */
132 if (tv->accessTime < bestTime) { /* best one available? */
133 bestTime = tv->accessTime;
141 afs_warn("afs_UFSGetVolSlot: no vol slots available\n");
153 /* now write out volume structure to file */
155 tv->vtix = afs_volCounter++;
156 /* now put on hash chain */
157 i = FVHash(tv->cell, tv->volume);
158 staticFVolume.next = fvTable[i];
159 fvTable[i] = tv->vtix;
162 * Haul the guy in from disk so we don't overwrite hash table
165 if (afs_FVIndex != tv->vtix) {
166 tfile = osi_UFSOpen(&volumeInode);
168 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
169 &staticFVolume, sizeof(struct fvolume));
171 if (code != sizeof(struct fvolume)) {
172 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
176 afs_FVIndex = tv->vtix;
179 afs_FVIndex = tv->vtix;
180 staticFVolume.volume = tv->volume;
181 staticFVolume.cell = tv->cell;
182 staticFVolume.mtpoint = tv->mtpoint;
183 staticFVolume.dotdot = tv->dotdot;
184 staticFVolume.rootVnode = tv->rootVnode;
185 staticFVolume.rootUnique = tv->rootUnique;
186 tfile = osi_UFSOpen(&volumeInode);
188 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
189 &staticFVolume, sizeof(struct fvolume));
191 if (code != sizeof(struct fvolume)) {
192 afs_warn("afs_UFSGetVolSlot: error %d writing volumeinfo\n",
197 afs_osi_Free(oldname, strlen(oldname) + 1);
201 tv = afs_freeVolList;
202 afs_freeVolList = tv->next;
209 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
218 fvTable[i] = staticFVolume.next;
224 /* we messed with staticFVolume, so make sure someone else
225 * doesn't think it's fine to use */
229 } /*afs_UFSGetVolSlot */
233 * Get an available volume list slot. If the list does not exist,
234 * create one containing a single element.
238 afs_MemGetVolSlot(void)
242 AFS_STATCNT(afs_MemGetVolSlot);
243 if (!afs_freeVolList) {
244 struct volume *newVp;
246 newVp = afs_osi_Alloc(sizeof(struct volume));
247 osi_Assert(newVp != NULL);
250 afs_freeVolList = newVp;
252 tv = afs_freeVolList;
253 afs_freeVolList = tv->next;
256 } /*afs_MemGetVolSlot */
259 * Reset volume information for all volume structs that
260 * point to a speicific server.
264 afs_ResetVolumes(struct server *srvp)
269 /* Find any volumes residing on this server and flush their state */
270 for (j = 0; j < NVOLS; j++) {
271 for (vp = afs_volumes[j]; vp; vp = vp->next) {
272 for (k = 0; k < AFS_MAXHOSTS; k++) {
273 if (!srvp || (vp->serverHost[k] == srvp)) {
274 vp->serverHost[k] = 0;
275 afs_ResetVolumeInfo(vp);
285 * Reset volume name to volume id mapping cache.
289 afs_CheckVolumeNames(int flags)
295 afs_int32 *volumeID, *cellID, vsize, nvols;
296 #ifdef AFS_DARWIN80_ENV
299 AFS_STATCNT(afs_CheckVolumeNames);
302 volumeID = cellID = NULL;
304 ObtainReadLock(&afs_xvolume);
305 if (flags & AFS_VOLCHECK_EXPIRED) {
307 * allocate space to hold the volumeIDs and cellIDs, only if
308 * we will be invalidating the mountpoints later on
310 for (i = 0; i < NVOLS; i++)
311 for (tv = afs_volumes[i]; tv; tv = tv->next)
314 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
315 cellID = (volumeID) ? volumeID + vsize : 0;
319 for (i = 0; i < NVOLS; i++) {
320 for (tv = afs_volumes[i]; tv; tv = tv->next) {
321 if (flags & AFS_VOLCHECK_EXPIRED) {
322 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
323 || (flags & AFS_VOLCHECK_FORCE)) {
324 afs_ResetVolumeInfo(tv); /* also resets status */
326 volumeID[nvols] = tv->volume;
327 cellID[nvols] = tv->cell;
334 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
335 for (j = 0; j < AFS_MAXHOSTS; j++)
336 tv->status[j] = not_busy;
341 ReleaseReadLock(&afs_xvolume);
344 /* next ensure all mt points are re-evaluated */
345 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
347 ObtainReadLock(&afs_xvcache);
348 for (i = 0; i < VCSIZE; i++) {
349 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
351 /* if the volume of "mvid" of the vcache entry is among the
352 * ones we found earlier, then we re-evaluate it. Also, if the
353 * force bit is set or we explicitly asked to reevaluate the
354 * mt-pts, we clean the cmvalid bit */
356 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
358 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
359 tvc->f.states &= ~CMValid;
361 /* If the volume that this file belongs to was reset earlier,
362 * then we should remove its callback.
363 * Again, if forced, always do it.
365 if ((tvc->f.states & CRO)
366 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
367 || (flags & AFS_VOLCHECK_FORCE))) {
369 if (tvc->f.states & CVInit) {
370 ReleaseReadLock(&afs_xvcache);
371 afs_osi_Sleep(&tvc->f.states);
374 #ifdef AFS_DARWIN80_ENV
375 if (tvc->f.states & CDeadVnode) {
376 ReleaseReadLock(&afs_xvcache);
377 afs_osi_Sleep(&tvc->f.states);
383 if (vnode_ref(tvp)) {
385 /* AFSTOV(tvc) may be NULL */
393 ReleaseReadLock(&afs_xvcache);
395 ObtainWriteLock(&afs_xcbhash, 485);
396 /* LOCKXXX: We aren't holding tvc write lock? */
397 afs_DequeueCallback(tvc);
398 tvc->f.states &= ~CStatd;
399 ReleaseWriteLock(&afs_xcbhash);
400 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
401 osi_dnlc_purgedp(tvc);
403 #ifdef AFS_DARWIN80_ENV
404 vnode_put(AFSTOV(tvc));
405 /* our tvc ptr is still good until now */
407 ObtainReadLock(&afs_xvcache);
409 ObtainReadLock(&afs_xvcache);
411 /* our tvc ptr is still good until now */
417 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
418 ReleaseReadLock(&afs_xvcache);
422 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
424 } /*afs_CheckVolumeNames */
428 * Check if volume is in the specified list.
429 * @param fid File FID.
430 * @param nvols Nomber of volumes???
431 * @param vID Array of volume IDs.
432 * @param cID Array of cache IDs.
433 * @return 1 - true, 0 - false.
436 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
441 /* if no arrays present, be conservative and return true */
442 if (nvols && (!vID || !cID))
445 for (i = 0; i < nvols; ++i) {
446 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
453 /* afs_PutVolume is now a macro in afs.h */
457 * Return volume struct if we have it cached and it's up-to-date.
458 * Environment: Must be called with afs_xvolume unlocked.
459 * @param afid Volume FID.
461 * @return Volume or NULL if no result.
464 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
472 i = VHash(afid->Fid.Volume);
473 ObtainWriteLock(&afs_xvolume, 106);
474 for (tv = afs_volumes[i]; tv; tv = tv->next) {
475 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
476 && (tv->states & VRecheck) == 0) {
481 ReleaseWriteLock(&afs_xvolume);
482 return tv; /* NULL if we didn't find it */
483 } /*afs_FindVolume */
488 * Note that areq may be null, in which case we don't bother to set any
489 * request status information.
490 * @param afid Volume FID.
491 * @param areq Request type.
492 * @param locktype Lock to be used.
493 * @return Volume or NULL if no result.
496 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
500 char *bp, tbuf[CVBS];
501 AFS_STATCNT(afs_GetVolume);
503 tv = afs_FindVolume(afid, locktype);
505 /* Do a dynroot check and add dynroot volume if found. */
506 if (afs_IsDynrootAnyFid(afid)) {
507 tv = afs_NewDynrootVolume(afid);
509 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
510 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
520 * @param volid Volume ID. If it's 0, get it from the name.
521 * @param aname Volume name.
522 * @param ve Volume entry.
523 * @param tcell The cell containing this volume.
525 * @param type Type of volume.
526 * @param areq Request.
527 * @return Volume or NULL if failure.
529 static struct volume *
530 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
531 afs_int32 agood, afs_int32 type, struct vrequest *areq)
534 struct vldbentry *ove = (struct vldbentry *)ve;
535 struct nvldbentry *nve = (struct nvldbentry *)ve;
536 struct uvldbentry *uve = (struct uvldbentry *)ve;
538 int whichType; /* which type of volume to look for */
543 /* special hint from file server to use vlserver */
545 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
547 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
552 /* figure out which one we're really interested in (a set is returned) */
553 volid = afs_vtoi(aname);
556 volid = uve->volumeId[whichType];
557 } else if (type == 1) {
558 volid = nve->volumeId[whichType];
560 volid = ove->volumeId[whichType];
562 } /* end of if (volid == 0) */
563 } /* end of if (!volid) */
566 ObtainWriteLock(&afs_xvolume, 108);
568 for (tv = afs_volumes[i]; tv; tv = tv->next) {
569 if (tv->volume == volid && tv->cell == tcell->cellNum) {
574 struct fvolume *tf = 0;
576 tv = afs_GetVolSlot();
578 ReleaseWriteLock(&afs_xvolume);
581 memset(tv, 0, sizeof(struct volume));
582 tv->cell = tcell->cellNum;
583 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
584 tv->next = afs_volumes[i]; /* thread into list */
587 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
588 if (afs_FVIndex != j) {
589 struct osi_file *tfile;
590 tfile = osi_UFSOpen(&volumeInode);
592 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
593 &staticFVolume, sizeof(struct fvolume));
594 if (err != sizeof(struct fvolume))
595 osi_Panic("read volumeinfo2");
600 if (tf->cell == tv->cell && tf->volume == volid)
603 if (tf && (j != 0)) {
604 tv->vtix = afs_FVIndex;
605 tv->mtpoint = tf->mtpoint;
606 tv->dotdot = tf->dotdot;
607 tv->rootVnode = tf->rootVnode;
608 tv->rootUnique = tf->rootUnique;
611 tv->rootVnode = tv->rootUnique = 0;
612 afs_GetDynrootMountFid(&tv->dotdot);
613 afs_GetDynrootMountFid(&tv->mtpoint);
614 tv->mtpoint.Fid.Vnode =
615 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
616 tv->mtpoint.Fid.Unique = volid;
620 tv->states &= ~VRecheck; /* just checked it */
621 tv->accessTime = osi_Time();
622 ReleaseWriteLock(&afs_xvolume);
623 ObtainWriteLock(&tv->lock, 111);
625 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
626 } else if (type == 1)
627 InstallNVolumeEntry(tv, nve, tcell->cellNum);
629 InstallVolumeEntry(tv, ove, tcell->cellNum);
632 tv->name = afs_osi_Alloc(strlen(aname) + 1);
633 osi_Assert(tv->name != NULL);
634 strcpy(tv->name, aname);
637 for (i = 0; i < NMAXNSERVERS; i++) {
638 tv->status[i] = not_busy;
640 ReleaseWriteLock(&tv->lock);
646 * Seek volume by it's name and attributes.
647 * If volume not found, try to add one.
648 * @param aname Volume name.
652 * @param locktype Type of lock to be used.
656 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
657 struct vrequest *areq, afs_int32 locktype)
662 AFS_STATCNT(afs_GetVolumeByName);
663 ObtainWriteLock(&afs_xvolume, 112);
664 for (i = 0; i < NVOLS; i++) {
665 for (tv = afs_volumes[i]; tv; tv = tv->next) {
666 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
667 && (tv->states & VRecheck) == 0) {
669 ReleaseWriteLock(&afs_xvolume);
675 ReleaseWriteLock(&afs_xvolume);
677 if (AFS_IS_DISCONNECTED)
680 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
685 * Init a new dynroot volume.
687 * @return Volume or NULL if not found.
689 static struct volume *
690 afs_NewDynrootVolume(struct VenusFid *fid)
694 struct vldbentry *tve;
695 char *bp, tbuf[CVBS];
697 tcell = afs_GetCell(fid->Cell, READ_LOCK);
700 tve = afs_osi_Alloc(sizeof(*tve));
701 osi_Assert(tve != NULL);
702 if (!(tcell->states & CHasVolRef))
703 tcell->states |= CHasVolRef;
705 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
706 memset(tve, 0, sizeof(*tve));
707 strcpy(tve->name, "local-dynroot");
708 tve->volumeId[ROVOL] = fid->Fid.Volume;
709 tve->flags = VLF_ROEXISTS;
711 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
712 afs_PutCell(tcell, READ_LOCK);
713 afs_osi_Free(tve, sizeof(*tve));
720 * @param aname Volume name.
721 * @param acell Cell id.
723 * @param areq Request type.
724 * @param locktype Type of lock to be used.
725 * @return Volume or NULL if failure.
727 static struct volume *
728 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
729 struct vrequest *areq, afs_int32 locktype)
731 afs_int32 code, type = 0;
732 struct volume *tv, *tv1;
733 struct vldbentry *tve;
734 struct nvldbentry *ntve;
735 struct uvldbentry *utve;
738 struct afs_conn *tconn;
739 struct vrequest treq;
740 struct rx_connection *rxconn;
742 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
745 tcell = afs_GetCell(acell, READ_LOCK);
750 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
755 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
756 ICL_TYPE_POINTER, aname);
757 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
758 tve = (struct vldbentry *)(tbuffer + 1024);
759 ntve = (struct nvldbentry *)tve;
760 utve = (struct uvldbentry *)tve;
761 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
764 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
765 &treq, SHARED_LOCK, &rxconn);
767 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
770 code = VL_GetEntryByNameO(rxconn, aname, tve);
772 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
775 code = VL_GetEntryByNameN(rxconn, aname, ntve);
780 code = VL_GetEntryByNameU(rxconn, aname, utve);
782 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
783 if (code == RXGEN_OPCODE) {
786 code = VL_GetEntryByNameN(rxconn, aname, ntve);
788 if (code == RXGEN_OPCODE) {
790 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
792 code = VL_GetEntryByNameO(rxconn, aname, tve);
795 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
797 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
803 } while (afs_Analyze(tconn, rxconn, code, NULL, &treq, -1, /* no op code for this */
804 SHARED_LOCK, tcell));
807 /* If the client has yet to contact this cell and contact failed due
808 * to network errors, mark the VLDB servers as back up.
809 * That the client tried and failed can be determined from the
810 * fact that there was a downtime incident, but CHasVolRef is not set.
812 /* RT 48959 - unclear if this should really go */
814 if (areq->networkError && !(tcell->states & CHasVolRef)) {
818 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
819 if ((sp = tcell->cellHosts[i]) == NULL)
821 for (sap = sp->addr; sap; sap = sap->next_sa)
822 afs_MarkServerUpOrDown(sap, 0);
826 afs_CopyError(&treq, areq);
827 osi_FreeLargeSpace(tbuffer);
828 afs_PutCell(tcell, READ_LOCK);
832 * Check to see if this cell has not yet referenced a volume. If
833 * it hasn't, it's just about to change its status, and we need to mark
834 * this fact down. Note that it is remotely possible that afs_SetupVolume
835 * could fail and we would still not have a volume reference.
837 if (!(tcell->states & CHasVolRef)) {
838 tcell->states |= CHasVolRef;
839 afs_stats_cmperf.numCellsContacted++;
841 /*First time a volume in this cell has been referenced */
848 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, &treq);
849 if ((agood == 3) && tv && tv->backVol) {
851 * This means that very soon we'll ask for the BK volume so
852 * we'll prefetch it (well we did already.)
855 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, &treq);
860 if ((agood >= 2) && tv && tv->roVol) {
862 * This means that very soon we'll ask for the RO volume so
863 * we'll prefetch it (well we did already.)
865 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, &treq);
870 osi_FreeLargeSpace(tbuffer);
871 afs_PutCell(tcell, READ_LOCK);
874 } /*afs_NewVolumeByName */
879 * Call this with the volume structure locked; used for new-style vldb requests.
885 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
893 AFS_STATCNT(InstallVolumeEntry);
895 /* Determine the type of volume we want */
896 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
898 } else if ((ve->flags & VLF_ROEXISTS)
899 && (av->volume == ve->volumeId[ROVOL])) {
902 } else if ((ve->flags & VLF_BACKEXISTS)
903 && (av->volume == ve->volumeId[BACKVOL])) {
904 /* backup always is on the same volume as parent */
906 av->states |= (VRO | VBackup);
908 mask = 0; /* Can't find volume in vldb entry */
911 /* fill in volume types */
912 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
913 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
914 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
916 if (ve->flags & VLF_DFSFILESET)
917 av->states |= VForeign;
919 cellp = afs_GetCell(acell, 0);
921 /* This volume, av, is locked. Zero out the serverHosts[] array
922 * so that if afs_GetServer() decides to replace the server
923 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
926 for (j = 0; j < AFS_MAXHOSTS; j++) {
927 av->serverHost[j] = 0;
930 /* Step through the VLDB entry making sure each server listed is there */
931 for (i = 0, j = 0; i < ve->nServers; i++) {
932 if (((ve->serverFlags[i] & mask) == 0)
933 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
934 continue; /* wrong volume or don't use this volume */
937 temp = htonl(ve->serverNumber[i]);
938 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
940 av->serverHost[j] = ts;
943 * The cell field could be 0 if the server entry was created
944 * first with the 'fs setserverprefs' call which doesn't set
945 * the cell field. Thus if the afs_GetServer call above
946 * follows later on it will find the server entry thus it will
947 * simply return without setting any fields, so we set the
948 * field ourselves below.
952 afs_PutServer(ts, WRITE_LOCK);
955 if (j < AFS_MAXHOSTS) {
956 av->serverHost[j++] = 0;
958 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
959 } /*InstallVolumeEntry */
963 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
971 AFS_STATCNT(InstallVolumeEntry);
973 /* Determine type of volume we want */
974 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
976 } else if ((ve->flags & VLF_ROEXISTS)
977 && (av->volume == ve->volumeId[ROVOL])) {
980 } else if ((ve->flags & VLF_BACKEXISTS)
981 && (av->volume == ve->volumeId[BACKVOL])) {
982 /* backup always is on the same volume as parent */
984 av->states |= (VRO | VBackup);
986 mask = 0; /* Can't find volume in vldb entry */
989 /* fill in volume types */
990 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
991 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
992 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
994 if (ve->flags & VLF_DFSFILESET)
995 av->states |= VForeign;
997 cellp = afs_GetCell(acell, 0);
999 /* This volume, av, is locked. Zero out the serverHosts[] array
1000 * so that if afs_GetServer() decides to replace the server
1001 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1004 for (j = 0; j < AFS_MAXHOSTS; j++) {
1005 av->serverHost[j] = 0;
1008 /* Step through the VLDB entry making sure each server listed is there */
1009 for (i = 0, j = 0; i < ve->nServers; i++) {
1010 if (((ve->serverFlags[i] & mask) == 0)
1011 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1012 continue; /* wrong volume or don't use this volume */
1015 temp = htonl(ve->serverNumber[i]);
1016 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1018 av->serverHost[j] = ts;
1020 * The cell field could be 0 if the server entry was created
1021 * first with the 'fs setserverprefs' call which doesn't set
1022 * the cell field. Thus if the afs_GetServer call above
1023 * follows later on it will find the server entry thus it will
1024 * simply return without setting any fields, so we set the
1025 * field ourselves below.
1029 afs_PutServer(ts, WRITE_LOCK);
1032 if (j < AFS_MAXHOSTS) {
1033 av->serverHost[j++] = 0;
1035 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1036 } /*InstallNVolumeEntry */
1040 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1041 struct cell *tcell, struct vrequest *areq)
1044 struct afs_conn *tconn;
1047 afs_uint32 serverid;
1051 AFS_STATCNT(InstallVolumeEntry);
1053 /* Determine type of volume we want */
1054 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1056 } else if ((ve->flags & VLF_ROEXISTS)
1057 && av->volume == ve->volumeId[ROVOL]) {
1060 } else if ((ve->flags & VLF_BACKEXISTS)
1061 && (av->volume == ve->volumeId[BACKVOL])) {
1062 /* backup always is on the same volume as parent */
1064 av->states |= (VRO | VBackup);
1066 mask = 0; /* Can't find volume in vldb entry */
1069 /* fill in volume types */
1070 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1071 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1072 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1074 if (ve->flags & VLF_DFSFILESET)
1075 av->states |= VForeign;
1077 cellp = afs_GetCell(acell, 0);
1079 /* This volume, av, is locked. Zero out the serverHosts[] array
1080 * so that if afs_GetServer() decides to replace the server
1081 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1084 for (j = 0; j < AFS_MAXHOSTS; j++) {
1085 av->serverHost[j] = 0;
1088 /* Gather the list of servers the VLDB says the volume is on
1089 * and initialize the ve->serverHost[] array. If a server struct
1090 * is not found, then get the list of addresses for the
1091 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1093 for (i = 0, j = 0; i < ve->nServers; i++) {
1094 if (((ve->serverFlags[i] & mask) == 0)
1095 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1096 continue; /* wrong volume don't use this volume */
1099 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
1100 /* The server has no uuid */
1101 serverid = htonl(ve->serverNumber[i].time_low);
1102 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
1105 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1106 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1108 /* uuid, uniquifier, and portal are the same */
1110 afs_uint32 *addrp, code;
1111 afs_int32 nentries, unique;
1113 ListAddrByAttributes attrs;
1115 struct rx_connection *rxconn;
1117 memset(&attrs, 0, sizeof(attrs));
1118 attrs.Mask = VLADDR_UUID;
1119 attrs.uuid = ve->serverNumber[i];
1120 memset(&uuid, 0, sizeof(uuid));
1121 memset(&addrs, 0, sizeof(addrs));
1124 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1125 tcell->cellNum, areq, SHARED_LOCK,
1130 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1137 /* Handle corrupt VLDB (defect 7393) */
1138 if (code == 0 && nentries == 0)
1141 } while (afs_Analyze
1142 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1144 /* Better handing of such failures; for now we'll simply retry this call */
1145 areq->volumeError = 1;
1149 addrp = addrs.bulkaddrs_val;
1150 for (k = 0; k < nentries; k++) {
1151 addrp[k] = htonl(addrp[k]);
1153 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1154 WRITE_LOCK, &ve->serverNumber[i],
1155 ve->serverUnique[i]);
1156 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1159 av->serverHost[j] = ts;
1161 /* The cell field could be 0 if the server entry was created
1162 * first with the 'fs setserverprefs' call which doesn't set
1163 * the cell field. Thus if the afs_GetServer call above
1164 * follows later on it will find the server entry thus it will
1165 * simply return without setting any fields, so we set the
1166 * field ourselves below.
1170 afs_PutServer(ts, WRITE_LOCK);
1174 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1175 } /*InstallVolumeEntry */
1179 * Reset volume info for the specified volume strecture. Mark volume
1180 * to be rechecked next time.
1184 afs_ResetVolumeInfo(struct volume *tv)
1188 AFS_STATCNT(afs_ResetVolumeInfo);
1189 ObtainWriteLock(&tv->lock, 117);
1190 tv->states |= VRecheck;
1191 for (i = 0; i < AFS_MAXHOSTS; i++)
1192 tv->status[i] = not_busy;
1194 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1197 ReleaseWriteLock(&tv->lock);