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_SUN56_ENV)
45 #include <inet/common.h>
46 #if defined(AFS_SUN58_ENV)
47 #include <netinet/ip6.h>
52 /* In case we don't have the vl error table yet. */
53 #ifndef ERROR_TABLE_BASE_VL
54 #define ERROR_TABLE_BASE_VL (363520L)
55 #define VL_NOENT (363524L)
56 #endif /* vlserver error base define */
58 /* Exported variables */
59 afs_dcache_id_t volumeInode; /* Inode for VolumeItems file */
60 afs_rwlock_t afs_xvolume; /** allocation lock for volumes */
61 struct volume *afs_freeVolList;
62 struct volume *afs_volumes[NVOLS];
63 afs_int32 afs_volCounter = 1; /** for allocating volume indices */
64 afs_int32 fvTable[NFENTRIES];
66 /* Forward declarations */
67 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell,
68 int agood, struct vrequest *areq,
70 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
71 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
77 * Convert a volume name to a number;
78 * @param aname Volume name.
79 * @return return 0 if can't parse as a number.
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;
110 * UFS specific version of afs_GetVolSlot
114 afs_UFSGetVolSlot(void)
116 struct volume *tv = NULL, **lv;
117 struct osi_file *tfile;
118 afs_int32 i = -1, code;
120 struct volume *bestVp, *oldLp = NULL, **bestLp = NULL;
121 char *oldname = NULL;
122 afs_int32 oldvtix = -2; /* Initialize to a value that doesn't occur */
124 AFS_STATCNT(afs_UFSGetVolSlot);
125 if (!afs_freeVolList) {
127 bestTime = 0x7fffffff;
130 for (i = 0; i < NVOLS; i++) {
131 lv = &afs_volumes[i];
132 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
133 if (tv->refCount == 0) { /* is this one available? */
134 if (tv->accessTime < bestTime) { /* best one available? */
135 bestTime = tv->accessTime;
143 afs_warn("afs_UFSGetVolSlot: no vol slots available\n");
155 /* now write out volume structure to file */
157 tv->vtix = afs_volCounter++;
158 /* now put on hash chain */
159 i = FVHash(tv->cell, tv->volume);
160 staticFVolume.next = fvTable[i];
161 fvTable[i] = tv->vtix;
164 * Haul the guy in from disk so we don't overwrite hash table
167 if (afs_FVIndex != tv->vtix) {
168 tfile = osi_UFSOpen(&volumeInode);
170 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
171 &staticFVolume, sizeof(struct fvolume));
173 if (code != sizeof(struct fvolume)) {
174 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
178 afs_FVIndex = tv->vtix;
181 afs_FVIndex = tv->vtix;
182 staticFVolume.volume = tv->volume;
183 staticFVolume.cell = tv->cell;
184 staticFVolume.mtpoint = tv->mtpoint;
185 staticFVolume.dotdot = tv->dotdot;
186 staticFVolume.rootVnode = tv->rootVnode;
187 staticFVolume.rootUnique = tv->rootUnique;
188 tfile = osi_UFSOpen(&volumeInode);
190 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
191 &staticFVolume, sizeof(struct fvolume));
193 if (code != sizeof(struct fvolume)) {
194 afs_warn("afs_UFSGetVolSlot: error %d writing volumeinfo\n",
199 afs_osi_Free(oldname, strlen(oldname) + 1);
203 tv = afs_freeVolList;
204 afs_freeVolList = tv->next;
211 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
220 fvTable[i] = staticFVolume.next;
226 /* we messed with staticFVolume, so make sure someone else
227 * doesn't think it's fine to use */
231 } /*afs_UFSGetVolSlot */
235 * Get an available volume list slot. If the list does not exist,
236 * create one containing a single element.
240 afs_MemGetVolSlot(void)
244 AFS_STATCNT(afs_MemGetVolSlot);
245 if (!afs_freeVolList) {
246 struct volume *newVp;
248 newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume));
251 afs_freeVolList = newVp;
253 tv = afs_freeVolList;
254 afs_freeVolList = tv->next;
257 } /*afs_MemGetVolSlot */
260 * Reset volume information for all volume structs that
261 * point to a speicific server.
265 afs_ResetVolumes(struct server *srvp)
270 /* Find any volumes residing on this server and flush their state */
271 for (j = 0; j < NVOLS; j++) {
272 for (vp = afs_volumes[j]; vp; vp = vp->next) {
273 for (k = 0; k < AFS_MAXHOSTS; k++) {
274 if (!srvp || (vp->serverHost[k] == srvp)) {
275 vp->serverHost[k] = 0;
276 afs_ResetVolumeInfo(vp);
286 * Reset volume name to volume id mapping cache.
290 afs_CheckVolumeNames(int flags)
296 afs_int32 *volumeID, *cellID, vsize, nvols;
297 #ifdef AFS_DARWIN80_ENV
300 AFS_STATCNT(afs_CheckVolumeNames);
303 volumeID = cellID = NULL;
305 ObtainReadLock(&afs_xvolume);
306 if (flags & AFS_VOLCHECK_EXPIRED) {
308 * allocate space to hold the volumeIDs and cellIDs, only if
309 * we will be invalidating the mountpoints later on
311 for (i = 0; i < NVOLS; i++)
312 for (tv = afs_volumes[i]; tv; tv = tv->next)
315 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
316 cellID = (volumeID) ? volumeID + vsize : 0;
320 for (i = 0; i < NVOLS; i++) {
321 for (tv = afs_volumes[i]; tv; tv = tv->next) {
322 if (flags & AFS_VOLCHECK_EXPIRED) {
323 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
324 || (flags & AFS_VOLCHECK_FORCE)) {
325 afs_ResetVolumeInfo(tv); /* also resets status */
327 volumeID[nvols] = tv->volume;
328 cellID[nvols] = tv->cell;
335 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
336 for (j = 0; j < AFS_MAXHOSTS; j++)
337 tv->status[j] = not_busy;
342 ReleaseReadLock(&afs_xvolume);
345 /* next ensure all mt points are re-evaluated */
346 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
348 ObtainReadLock(&afs_xvcache);
349 for (i = 0; i < VCSIZE; i++) {
350 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
352 /* if the volume of "mvid" of the vcache entry is among the
353 * ones we found earlier, then we re-evaluate it. Also, if the
354 * force bit is set or we explicitly asked to reevaluate the
355 * mt-pts, we clean the cmvalid bit */
357 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
359 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
360 tvc->f.states &= ~CMValid;
362 /* If the volume that this file belongs to was reset earlier,
363 * then we should remove its callback.
364 * Again, if forced, always do it.
366 if ((tvc->f.states & CRO)
367 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
368 || (flags & AFS_VOLCHECK_FORCE))) {
370 if (tvc->f.states & CVInit) {
371 ReleaseReadLock(&afs_xvcache);
372 afs_osi_Sleep(&tvc->f.states);
375 #ifdef AFS_DARWIN80_ENV
376 if (tvc->f.states & CDeadVnode) {
377 ReleaseReadLock(&afs_xvcache);
378 afs_osi_Sleep(&tvc->f.states);
384 if (vnode_ref(tvp)) {
386 /* AFSTOV(tvc) may be NULL */
394 ReleaseReadLock(&afs_xvcache);
396 ObtainWriteLock(&afs_xcbhash, 485);
397 /* LOCKXXX: We aren't holding tvc write lock? */
398 afs_DequeueCallback(tvc);
399 tvc->f.states &= ~CStatd;
400 ReleaseWriteLock(&afs_xcbhash);
401 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
402 osi_dnlc_purgedp(tvc);
404 #ifdef AFS_DARWIN80_ENV
405 vnode_put(AFSTOV(tvc));
406 /* our tvc ptr is still good until now */
408 ObtainReadLock(&afs_xvcache);
410 ObtainReadLock(&afs_xvcache);
412 /* our tvc ptr is still good until now */
418 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
419 ReleaseReadLock(&afs_xvcache);
423 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
425 } /*afs_CheckVolumeNames */
429 * Check if volume is in the specified list.
430 * @param fid File FID.
431 * @param nvols Nomber of volumes???
432 * @param vID Array of volume IDs.
433 * @param cID Array of cache IDs.
434 * @return 1 - true, 0 - false.
437 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
442 /* if no arrays present, be conservative and return true */
443 if (nvols && (!vID || !cID))
446 for (i = 0; i < nvols; ++i) {
447 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
454 /* afs_PutVolume is now a macro in afs.h */
458 * Return volume struct if we have it cached and it's up-to-date.
459 * Environment: Must be called with afs_xvolume unlocked.
460 * @param afid Volume FID.
462 * @return Volume or NULL if no result.
465 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
473 i = VHash(afid->Fid.Volume);
474 ObtainWriteLock(&afs_xvolume, 106);
475 for (tv = afs_volumes[i]; tv; tv = tv->next) {
476 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
477 && (tv->states & VRecheck) == 0) {
482 ReleaseWriteLock(&afs_xvolume);
483 return tv; /* NULL if we didn't find it */
484 } /*afs_FindVolume */
489 * Note that areq may be null, in which case we don't bother to set any
490 * request status information.
491 * @param afid Volume FID.
492 * @param areq Request type.
493 * @param locktype Lock to be used.
494 * @return Volume or NULL if no result.
497 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
501 char *bp, tbuf[CVBS];
502 AFS_STATCNT(afs_GetVolume);
504 tv = afs_FindVolume(afid, locktype);
506 /* Do a dynroot check and add dynroot volume if found. */
507 if (afs_IsDynrootAnyFid(afid)) {
508 tv = afs_NewDynrootVolume(afid);
510 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
511 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
521 * @param volid Volume ID. If it's 0, get it from the name.
522 * @param aname Volume name.
523 * @param ve Volume entry.
524 * @param tcell The cell containing this volume.
526 * @param type Type of volume.
527 * @param areq Request.
528 * @return Volume or NULL if failure.
530 static struct volume *
531 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
532 afs_int32 agood, afs_int32 type, struct vrequest *areq)
535 struct vldbentry *ove = (struct vldbentry *)ve;
536 struct nvldbentry *nve = (struct nvldbentry *)ve;
537 struct uvldbentry *uve = (struct uvldbentry *)ve;
539 int whichType; /* which type of volume to look for */
544 /* special hint from file server to use vlserver */
546 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
548 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
553 /* figure out which one we're really interested in (a set is returned) */
554 volid = afs_vtoi(aname);
557 volid = uve->volumeId[whichType];
558 } else if (type == 1) {
559 volid = nve->volumeId[whichType];
561 volid = ove->volumeId[whichType];
563 } /* end of if (volid == 0) */
564 } /* end of if (!volid) */
567 ObtainWriteLock(&afs_xvolume, 108);
569 for (tv = afs_volumes[i]; tv; tv = tv->next) {
570 if (tv->volume == volid && tv->cell == tcell->cellNum) {
575 struct fvolume *tf = 0;
577 tv = afs_GetVolSlot();
579 ReleaseWriteLock(&afs_xvolume);
582 memset(tv, 0, sizeof(struct volume));
583 tv->cell = tcell->cellNum;
584 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
585 tv->next = afs_volumes[i]; /* thread into list */
588 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
589 if (afs_FVIndex != j) {
590 struct osi_file *tfile;
591 tfile = osi_UFSOpen(&volumeInode);
593 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
594 &staticFVolume, sizeof(struct fvolume));
595 if (err != sizeof(struct fvolume))
596 osi_Panic("read volumeinfo2");
601 if (tf->cell == tv->cell && tf->volume == volid)
604 if (tf && (j != 0)) {
605 tv->vtix = afs_FVIndex;
606 tv->mtpoint = tf->mtpoint;
607 tv->dotdot = tf->dotdot;
608 tv->rootVnode = tf->rootVnode;
609 tv->rootUnique = tf->rootUnique;
612 tv->rootVnode = tv->rootUnique = 0;
613 afs_GetDynrootMountFid(&tv->dotdot);
614 afs_GetDynrootMountFid(&tv->mtpoint);
615 tv->mtpoint.Fid.Vnode =
616 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
617 tv->mtpoint.Fid.Unique = volid;
621 tv->states &= ~VRecheck; /* just checked it */
622 tv->accessTime = osi_Time();
623 ReleaseWriteLock(&afs_xvolume);
624 ObtainWriteLock(&tv->lock, 111);
626 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
627 } else if (type == 1)
628 InstallNVolumeEntry(tv, nve, tcell->cellNum);
630 InstallVolumeEntry(tv, ove, tcell->cellNum);
633 tv->name = afs_osi_Alloc(strlen(aname) + 1);
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 if (!(tcell->states & CHasVolRef))
702 tcell->states |= CHasVolRef;
704 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
705 memset(tve, 0, sizeof(*tve));
706 strcpy(tve->name, "local-dynroot");
707 tve->volumeId[ROVOL] = fid->Fid.Volume;
708 tve->flags = VLF_ROEXISTS;
710 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
711 afs_PutCell(tcell, READ_LOCK);
712 afs_osi_Free(tve, sizeof(*tve));
719 * @param aname Volume name.
720 * @param acell Cell id.
722 * @param areq Request type.
723 * @param locktype Type of lock to be used.
724 * @return Volume or NULL if failure.
726 static struct volume *
727 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
728 struct vrequest *areq, afs_int32 locktype)
730 afs_int32 code, type = 0;
731 struct volume *tv, *tv1;
732 struct vldbentry *tve;
733 struct nvldbentry *ntve;
734 struct uvldbentry *utve;
737 struct afs_conn *tconn;
738 struct vrequest treq;
740 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
743 tcell = afs_GetCell(acell, READ_LOCK);
748 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
753 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
754 ICL_TYPE_POINTER, aname);
755 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
756 tve = (struct vldbentry *)(tbuffer + 1024);
757 ntve = (struct nvldbentry *)tve;
758 utve = (struct uvldbentry *)tve;
759 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
762 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
765 if (tconn->srvr->server->flags & SNO_LHOSTS) {
768 code = VL_GetEntryByNameO(tconn->id, aname, tve);
770 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
773 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
778 code = VL_GetEntryByNameU(tconn->id, aname, utve);
780 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
781 if (code == RXGEN_OPCODE) {
784 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
786 if (code == RXGEN_OPCODE) {
788 tconn->srvr->server->flags |= SNO_LHOSTS;
790 code = VL_GetEntryByNameO(tconn->id, aname, tve);
793 tconn->srvr->server->flags |= SYES_LHOSTS;
795 tconn->srvr->server->flags |= SVLSRV_UUID;
801 } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */
802 SHARED_LOCK, tcell));
805 /* If the client has yet to contact this cell and contact failed due
806 * to network errors, mark the VLDB servers as back up.
807 * That the client tried and failed can be determined from the
808 * fact that there was a downtime incident, but CHasVolRef is not set.
810 /* RT 48959 - unclear if this should really go */
812 if (areq->networkError && !(tcell->states & CHasVolRef)) {
816 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
817 if ((sp = tcell->cellHosts[i]) == NULL)
819 for (sap = sp->addr; sap; sap = sap->next_sa)
820 afs_MarkServerUpOrDown(sap, 0);
824 afs_CopyError(&treq, areq);
825 osi_FreeLargeSpace(tbuffer);
826 afs_PutCell(tcell, READ_LOCK);
830 * Check to see if this cell has not yet referenced a volume. If
831 * it hasn't, it's just about to change its status, and we need to mark
832 * this fact down. Note that it is remotely possible that afs_SetupVolume
833 * could fail and we would still not have a volume reference.
835 if (!(tcell->states & CHasVolRef)) {
836 tcell->states |= CHasVolRef;
837 afs_stats_cmperf.numCellsContacted++;
839 /*First time a volume in this cell has been referenced */
846 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
847 if ((agood == 3) && tv && tv->backVol) {
849 * This means that very soon we'll ask for the BK volume so
850 * we'll prefetch it (well we did already.)
853 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, areq);
858 if ((agood >= 2) && tv && tv->roVol) {
860 * This means that very soon we'll ask for the RO volume so
861 * we'll prefetch it (well we did already.)
863 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
868 osi_FreeLargeSpace(tbuffer);
869 afs_PutCell(tcell, READ_LOCK);
872 } /*afs_NewVolumeByName */
877 * Call this with the volume structure locked; used for new-style vldb requests.
883 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
891 AFS_STATCNT(InstallVolumeEntry);
893 /* Determine the type of volume we want */
894 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
896 } else if ((ve->flags & VLF_ROEXISTS)
897 && (av->volume == ve->volumeId[ROVOL])) {
900 } else if ((ve->flags & VLF_BACKEXISTS)
901 && (av->volume == ve->volumeId[BACKVOL])) {
902 /* backup always is on the same volume as parent */
904 av->states |= (VRO | VBackup);
906 mask = 0; /* Can't find volume in vldb entry */
909 /* fill in volume types */
910 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
911 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
912 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
914 if (ve->flags & VLF_DFSFILESET)
915 av->states |= VForeign;
917 cellp = afs_GetCell(acell, 0);
919 /* This volume, av, is locked. Zero out the serverHosts[] array
920 * so that if afs_GetServer() decides to replace the server
921 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
924 for (j = 0; j < AFS_MAXHOSTS; j++) {
925 av->serverHost[j] = 0;
928 /* Step through the VLDB entry making sure each server listed is there */
929 for (i = 0, j = 0; i < ve->nServers; i++) {
930 if (((ve->serverFlags[i] & mask) == 0)
931 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
932 continue; /* wrong volume or don't use this volume */
935 temp = htonl(ve->serverNumber[i]);
936 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
938 av->serverHost[j] = ts;
941 * The cell field could be 0 if the server entry was created
942 * first with the 'fs setserverprefs' call which doesn't set
943 * the cell field. Thus if the afs_GetServer call above
944 * follows later on it will find the server entry thus it will
945 * simply return without setting any fields, so we set the
946 * field ourselves below.
950 afs_PutServer(ts, WRITE_LOCK);
953 if (j < AFS_MAXHOSTS) {
954 av->serverHost[j++] = 0;
956 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
957 } /*InstallVolumeEntry */
961 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
969 AFS_STATCNT(InstallVolumeEntry);
971 /* Determine type of volume we want */
972 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
974 } else if ((ve->flags & VLF_ROEXISTS)
975 && (av->volume == ve->volumeId[ROVOL])) {
978 } else if ((ve->flags & VLF_BACKEXISTS)
979 && (av->volume == ve->volumeId[BACKVOL])) {
980 /* backup always is on the same volume as parent */
982 av->states |= (VRO | VBackup);
984 mask = 0; /* Can't find volume in vldb entry */
987 /* fill in volume types */
988 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
989 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
990 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
992 if (ve->flags & VLF_DFSFILESET)
993 av->states |= VForeign;
995 cellp = afs_GetCell(acell, 0);
997 /* This volume, av, is locked. Zero out the serverHosts[] array
998 * so that if afs_GetServer() decides to replace the server
999 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1002 for (j = 0; j < AFS_MAXHOSTS; j++) {
1003 av->serverHost[j] = 0;
1006 /* Step through the VLDB entry making sure each server listed is there */
1007 for (i = 0, j = 0; i < ve->nServers; i++) {
1008 if (((ve->serverFlags[i] & mask) == 0)
1009 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1010 continue; /* wrong volume or don't use this volume */
1013 temp = htonl(ve->serverNumber[i]);
1014 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1016 av->serverHost[j] = ts;
1018 * The cell field could be 0 if the server entry was created
1019 * first with the 'fs setserverprefs' call which doesn't set
1020 * the cell field. Thus if the afs_GetServer call above
1021 * follows later on it will find the server entry thus it will
1022 * simply return without setting any fields, so we set the
1023 * field ourselves below.
1027 afs_PutServer(ts, WRITE_LOCK);
1030 if (j < AFS_MAXHOSTS) {
1031 av->serverHost[j++] = 0;
1033 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1034 } /*InstallNVolumeEntry */
1038 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1039 struct cell *tcell, struct vrequest *areq)
1042 struct afs_conn *tconn;
1045 afs_uint32 serverid;
1049 AFS_STATCNT(InstallVolumeEntry);
1051 /* Determine type of volume we want */
1052 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1054 } else if ((ve->flags & VLF_ROEXISTS)
1055 && av->volume == ve->volumeId[ROVOL]) {
1058 } else if ((ve->flags & VLF_BACKEXISTS)
1059 && (av->volume == ve->volumeId[BACKVOL])) {
1060 /* backup always is on the same volume as parent */
1062 av->states |= (VRO | VBackup);
1064 mask = 0; /* Can't find volume in vldb entry */
1067 /* fill in volume types */
1068 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1069 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1070 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1072 if (ve->flags & VLF_DFSFILESET)
1073 av->states |= VForeign;
1075 cellp = afs_GetCell(acell, 0);
1077 /* This volume, av, is locked. Zero out the serverHosts[] array
1078 * so that if afs_GetServer() decides to replace the server
1079 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1082 for (j = 0; j < AFS_MAXHOSTS; j++) {
1083 av->serverHost[j] = 0;
1086 /* Gather the list of servers the VLDB says the volume is on
1087 * and initialize the ve->serverHost[] array. If a server struct
1088 * is not found, then get the list of addresses for the
1089 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1091 for (i = 0, j = 0; i < ve->nServers; i++) {
1092 if (((ve->serverFlags[i] & mask) == 0)
1093 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1094 continue; /* wrong volume don't use this volume */
1097 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
1098 /* The server has no uuid */
1099 serverid = htonl(ve->serverNumber[i].time_low);
1100 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
1103 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1104 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1106 /* uuid, uniquifier, and portal are the same */
1108 afs_uint32 *addrp, code;
1109 afs_int32 nentries, unique;
1111 ListAddrByAttributes attrs;
1114 memset(&attrs, 0, sizeof(attrs));
1115 attrs.Mask = VLADDR_UUID;
1116 attrs.uuid = ve->serverNumber[i];
1117 memset(&uuid, 0, sizeof(uuid));
1118 memset(&addrs, 0, sizeof(addrs));
1121 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1122 tcell->cellNum, areq, SHARED_LOCK);
1126 VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique,
1133 /* Handle corrupt VLDB (defect 7393) */
1134 if (code == 0 && nentries == 0)
1137 } while (afs_Analyze
1138 (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1140 /* Better handing of such failures; for now we'll simply retry this call */
1141 areq->volumeError = 1;
1145 addrp = addrs.bulkaddrs_val;
1146 for (k = 0; k < nentries; k++) {
1147 addrp[k] = htonl(addrp[k]);
1149 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1150 WRITE_LOCK, &ve->serverNumber[i],
1151 ve->serverUnique[i]);
1152 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1155 av->serverHost[j] = ts;
1157 /* The cell field could be 0 if the server entry was created
1158 * first with the 'fs setserverprefs' call which doesn't set
1159 * the cell field. Thus if the afs_GetServer call above
1160 * follows later on it will find the server entry thus it will
1161 * simply return without setting any fields, so we set the
1162 * field ourselves below.
1166 afs_PutServer(ts, WRITE_LOCK);
1170 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1171 } /*InstallVolumeEntry */
1175 * Reset volume info for the specified volume strecture. Mark volume
1176 * to be rechecked next time.
1180 afs_ResetVolumeInfo(struct volume *tv)
1184 AFS_STATCNT(afs_ResetVolumeInfo);
1185 ObtainWriteLock(&tv->lock, 117);
1186 tv->states |= VRecheck;
1187 for (i = 0; i < AFS_MAXHOSTS; i++)
1188 tv->status[i] = not_busy;
1190 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1193 ReleaseWriteLock(&tv->lock);