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, skipping a given volume if provided.
263 * The server to reset volume info about
265 * The volume to skip resetting info about
268 afs_ResetVolumes(struct server *srvp, struct volume *tv)
273 /* Find any volumes residing on this server and flush their state */
274 for (j = 0; j < NVOLS; j++) {
275 for (vp = afs_volumes[j]; vp; vp = vp->next) {
276 for (k = 0; k < AFS_MAXHOSTS; k++) {
277 if (!srvp || (vp->serverHost[k] == srvp)) {
278 if (tv && tv != vp) {
279 vp->serverHost[k] = 0;
280 afs_ResetVolumeInfo(vp);
290 * Reset volume name to volume id mapping cache.
294 afs_CheckVolumeNames(int flags)
300 afs_int32 *volumeID, *cellID, vsize, nvols;
301 #ifdef AFS_DARWIN80_ENV
304 AFS_STATCNT(afs_CheckVolumeNames);
307 volumeID = cellID = NULL;
309 ObtainReadLock(&afs_xvolume);
310 if (flags & AFS_VOLCHECK_EXPIRED) {
312 * allocate space to hold the volumeIDs and cellIDs, only if
313 * we will be invalidating the mountpoints later on
315 for (i = 0; i < NVOLS; i++)
316 for (tv = afs_volumes[i]; tv; tv = tv->next)
319 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
320 cellID = (volumeID) ? volumeID + vsize : 0;
324 for (i = 0; i < NVOLS; i++) {
325 for (tv = afs_volumes[i]; tv; tv = tv->next) {
326 if (flags & AFS_VOLCHECK_EXPIRED) {
327 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
328 || (flags & AFS_VOLCHECK_FORCE)) {
329 afs_ResetVolumeInfo(tv); /* also resets status */
331 volumeID[nvols] = tv->volume;
332 cellID[nvols] = tv->cell;
339 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
340 for (j = 0; j < AFS_MAXHOSTS; j++)
341 tv->status[j] = not_busy;
346 ReleaseReadLock(&afs_xvolume);
349 /* next ensure all mt points are re-evaluated */
350 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
352 ObtainReadLock(&afs_xvcache);
353 for (i = 0; i < VCSIZE; i++) {
354 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
356 /* if the volume of "mvid" of the vcache entry is among the
357 * ones we found earlier, then we re-evaluate it. Also, if the
358 * force bit is set or we explicitly asked to reevaluate the
359 * mt-pts, we clean the cmvalid bit */
361 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
363 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
364 tvc->f.states &= ~CMValid;
366 /* If the volume that this file belongs to was reset earlier,
367 * then we should remove its callback.
368 * Again, if forced, always do it.
370 if ((tvc->f.states & CRO)
371 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
372 || (flags & AFS_VOLCHECK_FORCE))) {
374 if (tvc->f.states & CVInit) {
375 ReleaseReadLock(&afs_xvcache);
376 afs_osi_Sleep(&tvc->f.states);
379 #ifdef AFS_DARWIN80_ENV
380 if (tvc->f.states & CDeadVnode) {
381 ReleaseReadLock(&afs_xvcache);
382 afs_osi_Sleep(&tvc->f.states);
388 if (vnode_ref(tvp)) {
390 /* AFSTOV(tvc) may be NULL */
398 ReleaseReadLock(&afs_xvcache);
400 ObtainWriteLock(&afs_xcbhash, 485);
401 /* LOCKXXX: We aren't holding tvc write lock? */
402 afs_DequeueCallback(tvc);
403 tvc->f.states &= ~CStatd;
404 ReleaseWriteLock(&afs_xcbhash);
405 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
406 osi_dnlc_purgedp(tvc);
408 #ifdef AFS_DARWIN80_ENV
409 vnode_put(AFSTOV(tvc));
410 /* our tvc ptr is still good until now */
412 ObtainReadLock(&afs_xvcache);
414 ObtainReadLock(&afs_xvcache);
416 /* our tvc ptr is still good until now */
422 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
423 ReleaseReadLock(&afs_xvcache);
427 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
429 } /*afs_CheckVolumeNames */
433 * Check if volume is in the specified list.
434 * @param fid File FID.
435 * @param nvols Nomber of volumes???
436 * @param vID Array of volume IDs.
437 * @param cID Array of cache IDs.
438 * @return 1 - true, 0 - false.
441 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
446 /* if no arrays present, be conservative and return true */
447 if (nvols && (!vID || !cID))
450 for (i = 0; i < nvols; ++i) {
451 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
458 /* afs_PutVolume is now a macro in afs.h */
462 * Return volume struct if we have it cached and it's up-to-date.
463 * Environment: Must be called with afs_xvolume unlocked.
464 * @param afid Volume FID.
466 * @return Volume or NULL if no result.
469 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
477 i = VHash(afid->Fid.Volume);
478 ObtainWriteLock(&afs_xvolume, 106);
479 for (tv = afs_volumes[i]; tv; tv = tv->next) {
480 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
481 && (tv->states & VRecheck) == 0) {
486 ReleaseWriteLock(&afs_xvolume);
487 return tv; /* NULL if we didn't find it */
488 } /*afs_FindVolume */
493 * Note that areq may be null, in which case we don't bother to set any
494 * request status information.
495 * @param afid Volume FID.
496 * @param areq Request type.
497 * @param locktype Lock to be used.
498 * @return Volume or NULL if no result.
501 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
505 char *bp, tbuf[CVBS];
506 AFS_STATCNT(afs_GetVolume);
508 tv = afs_FindVolume(afid, locktype);
510 /* Do a dynroot check and add dynroot volume if found. */
511 if (afs_IsDynrootAnyFid(afid)) {
512 tv = afs_NewDynrootVolume(afid);
514 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
515 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
525 * @param volid Volume ID. If it's 0, get it from the name.
526 * @param aname Volume name.
527 * @param ve Volume entry.
528 * @param tcell The cell containing this volume.
530 * @param type Type of volume.
531 * @param areq Request.
532 * @return Volume or NULL if failure.
534 static struct volume *
535 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
536 afs_int32 agood, afs_int32 type, struct vrequest *areq)
539 struct vldbentry *ove = (struct vldbentry *)ve;
540 struct nvldbentry *nve = (struct nvldbentry *)ve;
541 struct uvldbentry *uve = (struct uvldbentry *)ve;
543 int whichType; /* which type of volume to look for */
548 /* special hint from file server to use vlserver */
550 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
552 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
557 /* figure out which one we're really interested in (a set is returned) */
558 volid = afs_vtoi(aname);
561 volid = uve->volumeId[whichType];
562 } else if (type == 1) {
563 volid = nve->volumeId[whichType];
565 volid = ove->volumeId[whichType];
567 } /* end of if (volid == 0) */
568 } /* end of if (!volid) */
571 ObtainWriteLock(&afs_xvolume, 108);
573 for (tv = afs_volumes[i]; tv; tv = tv->next) {
574 if (tv->volume == volid && tv->cell == tcell->cellNum) {
579 struct fvolume *tf = 0;
581 tv = afs_GetVolSlot();
583 ReleaseWriteLock(&afs_xvolume);
586 memset(tv, 0, sizeof(struct volume));
588 for (j = fvTable[FVHash(tcell->cellNum, 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 == tcell->cellNum && tf->volume == volid)
605 tv->cell = tcell->cellNum;
606 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
607 tv->next = afs_volumes[i]; /* thread into list */
611 if (tf && (j != 0)) {
612 tv->vtix = afs_FVIndex;
613 tv->mtpoint = tf->mtpoint;
614 tv->dotdot = tf->dotdot;
615 tv->rootVnode = tf->rootVnode;
616 tv->rootUnique = tf->rootUnique;
619 tv->rootVnode = tv->rootUnique = 0;
620 afs_GetDynrootMountFid(&tv->dotdot);
621 afs_GetDynrootMountFid(&tv->mtpoint);
622 tv->mtpoint.Fid.Vnode =
623 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
624 tv->mtpoint.Fid.Unique = volid;
628 tv->states &= ~VRecheck; /* just checked it */
629 tv->accessTime = osi_Time();
630 ReleaseWriteLock(&afs_xvolume);
632 LockAndInstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
633 } else if (type == 1)
634 LockAndInstallNVolumeEntry(tv, nve, tcell->cellNum);
636 LockAndInstallVolumeEntry(tv, ove, tcell->cellNum);
639 tv->name = afs_osi_Alloc(strlen(aname) + 1);
640 osi_Assert(tv->name != NULL);
641 strcpy(tv->name, aname);
644 for (i = 0; i < NMAXNSERVERS; i++) {
645 tv->status[i] = not_busy;
647 ReleaseWriteLock(&tv->lock);
653 * Seek volume by it's name and attributes.
654 * If volume not found, try to add one.
655 * @param aname Volume name.
659 * @param locktype Type of lock to be used.
663 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
664 struct vrequest *areq, afs_int32 locktype)
669 AFS_STATCNT(afs_GetVolumeByName);
670 ObtainWriteLock(&afs_xvolume, 112);
671 for (i = 0; i < NVOLS; i++) {
672 for (tv = afs_volumes[i]; tv; tv = tv->next) {
673 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
674 && (tv->states & VRecheck) == 0) {
676 ReleaseWriteLock(&afs_xvolume);
682 ReleaseWriteLock(&afs_xvolume);
684 if (AFS_IS_DISCONNECTED)
687 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
692 * Init a new dynroot volume.
694 * @return Volume or NULL if not found.
696 static struct volume *
697 afs_NewDynrootVolume(struct VenusFid *fid)
701 struct vldbentry *tve;
702 char *bp, tbuf[CVBS];
704 tcell = afs_GetCell(fid->Cell, READ_LOCK);
707 tve = afs_osi_Alloc(sizeof(*tve));
708 osi_Assert(tve != NULL);
709 if (!(tcell->states & CHasVolRef))
710 tcell->states |= CHasVolRef;
712 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
713 memset(tve, 0, sizeof(*tve));
714 strcpy(tve->name, "local-dynroot");
715 tve->volumeId[ROVOL] = fid->Fid.Volume;
716 tve->flags = VLF_ROEXISTS;
718 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
719 afs_PutCell(tcell, READ_LOCK);
720 afs_osi_Free(tve, sizeof(*tve));
727 * @param aname Volume name.
728 * @param acell Cell id.
730 * @param areq Request type.
731 * @param locktype Type of lock to be used.
732 * @return Volume or NULL if failure.
734 static struct volume *
735 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
736 struct vrequest *areq, afs_int32 locktype)
738 afs_int32 code, type = 0;
739 struct volume *tv, *tv1;
740 struct vldbentry *tve;
741 struct nvldbentry *ntve;
742 struct uvldbentry *utve;
745 struct afs_conn *tconn;
746 struct vrequest treq;
747 struct rx_connection *rxconn;
749 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
752 tcell = afs_GetCell(acell, READ_LOCK);
757 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
762 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
763 ICL_TYPE_POINTER, aname);
764 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
765 tve = (struct vldbentry *)(tbuffer + 1024);
766 ntve = (struct nvldbentry *)tve;
767 utve = (struct uvldbentry *)tve;
768 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
771 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
772 &treq, SHARED_LOCK, 0, &rxconn);
774 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
777 code = VL_GetEntryByNameO(rxconn, aname, tve);
779 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
782 code = VL_GetEntryByNameN(rxconn, aname, ntve);
787 code = VL_GetEntryByNameU(rxconn, aname, utve);
789 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
790 if (code == RXGEN_OPCODE) {
793 code = VL_GetEntryByNameN(rxconn, aname, ntve);
795 if (code == RXGEN_OPCODE) {
797 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
799 code = VL_GetEntryByNameO(rxconn, aname, tve);
802 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
804 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
810 } while (afs_Analyze(tconn, rxconn, code, NULL, &treq, -1, /* no op code for this */
811 SHARED_LOCK, tcell));
814 /* If the client has yet to contact this cell and contact failed due
815 * to network errors, mark the VLDB servers as back up.
816 * That the client tried and failed can be determined from the
817 * fact that there was a downtime incident, but CHasVolRef is not set.
819 /* RT 48959 - unclear if this should really go */
821 if (areq->networkError && !(tcell->states & CHasVolRef)) {
825 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
826 if ((sp = tcell->cellHosts[i]) == NULL)
828 for (sap = sp->addr; sap; sap = sap->next_sa)
829 afs_MarkServerUpOrDown(sap, 0);
833 afs_CopyError(&treq, areq);
834 osi_FreeLargeSpace(tbuffer);
835 afs_PutCell(tcell, READ_LOCK);
839 * Check to see if this cell has not yet referenced a volume. If
840 * it hasn't, it's just about to change its status, and we need to mark
841 * this fact down. Note that it is remotely possible that afs_SetupVolume
842 * could fail and we would still not have a volume reference.
844 if (!(tcell->states & CHasVolRef)) {
845 tcell->states |= CHasVolRef;
846 afs_stats_cmperf.numCellsContacted++;
848 /*First time a volume in this cell has been referenced */
855 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, &treq);
856 if ((agood == 3) && tv && tv->backVol) {
858 * This means that very soon we'll ask for the BK volume so
859 * we'll prefetch it (well we did already.)
862 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, &treq);
867 if ((agood >= 2) && tv && tv->roVol) {
869 * This means that very soon we'll ask for the RO volume so
870 * we'll prefetch it (well we did already.)
872 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, &treq);
877 osi_FreeLargeSpace(tbuffer);
878 afs_PutCell(tcell, READ_LOCK);
881 } /*afs_NewVolumeByName */
886 * Call this with the volume structure locked; used for new-style vldb requests.
892 LockAndInstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
900 struct server *serverHost[AFS_MAXHOSTS];
902 AFS_STATCNT(InstallVolumeEntry);
904 memset(serverHost, 0, sizeof(serverHost));
906 /* Determine the type of volume we want */
907 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
909 } else if ((ve->flags & VLF_ROEXISTS)
910 && (av->volume == ve->volumeId[ROVOL])) {
913 } else if ((ve->flags & VLF_BACKEXISTS)
914 && (av->volume == ve->volumeId[BACKVOL])) {
915 /* backup always is on the same volume as parent */
917 types |= (VRO | VBackup);
919 mask = 0; /* Can't find volume in vldb entry */
922 cellp = afs_GetCell(acell, 0);
924 /* Step through the VLDB entry making sure each server listed is there */
925 for (i = 0, j = 0; i < ve->nServers; i++) {
926 if (((ve->serverFlags[i] & mask) == 0)
927 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
928 continue; /* wrong volume or don't use this volume */
931 temp = htonl(ve->serverNumber[i]);
932 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
933 (afsUUID *) 0, 0, av);
937 * The cell field could be 0 if the server entry was created
938 * first with the 'fs setserverprefs' call which doesn't set
939 * the cell field. Thus if the afs_GetServer call above
940 * follows later on it will find the server entry thus it will
941 * simply return without setting any fields, so we set the
942 * field ourselves below.
946 afs_PutServer(ts, WRITE_LOCK);
950 ObtainWriteLock(&av->lock, 109);
952 memcpy(av->serverHost, serverHost, sizeof(serverHost));
957 /* fill in volume types */
958 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
959 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
960 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
962 if (ve->flags & VLF_DFSFILESET)
963 av->states |= VForeign;
965 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
966 } /*InstallVolumeEntry */
970 LockAndInstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
978 struct server *serverHost[AFS_MAXHOSTS];
980 AFS_STATCNT(InstallVolumeEntry);
982 memset(serverHost, 0, sizeof(serverHost));
984 /* Determine type of volume we want */
985 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
987 } else if ((ve->flags & VLF_ROEXISTS)
988 && (av->volume == ve->volumeId[ROVOL])) {
991 } else if ((ve->flags & VLF_BACKEXISTS)
992 && (av->volume == ve->volumeId[BACKVOL])) {
993 /* backup always is on the same volume as parent */
995 types |= (VRO | VBackup);
997 mask = 0; /* Can't find volume in vldb entry */
1000 cellp = afs_GetCell(acell, 0);
1002 /* Step through the VLDB entry making sure each server listed is there */
1003 for (i = 0, j = 0; i < ve->nServers; i++) {
1004 if (((ve->serverFlags[i] & mask) == 0)
1005 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1006 continue; /* wrong volume or don't use this volume */
1009 temp = htonl(ve->serverNumber[i]);
1010 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1011 (afsUUID *) 0, 0, av);
1014 * The cell field could be 0 if the server entry was created
1015 * first with the 'fs setserverprefs' call which doesn't set
1016 * the cell field. Thus if the afs_GetServer call above
1017 * follows later on it will find the server entry thus it will
1018 * simply return without setting any fields, so we set the
1019 * field ourselves below.
1023 afs_PutServer(ts, WRITE_LOCK);
1027 ObtainWriteLock(&av->lock, 110);
1029 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1032 av->states |= types;
1034 /* fill in volume types */
1035 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1036 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1037 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1039 if (ve->flags & VLF_DFSFILESET)
1040 av->states |= VForeign;
1042 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1043 } /*InstallNVolumeEntry */
1047 LockAndInstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1048 struct cell *tcell, struct vrequest *areq)
1051 struct afs_conn *tconn;
1054 afs_uint32 serverid;
1058 struct server *serverHost[AFS_MAXHOSTS];
1060 AFS_STATCNT(InstallVolumeEntry);
1062 memset(serverHost, 0, sizeof(serverHost));
1064 /* Determine type of volume we want */
1065 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1067 } else if ((ve->flags & VLF_ROEXISTS)
1068 && av->volume == ve->volumeId[ROVOL]) {
1071 } else if ((ve->flags & VLF_BACKEXISTS)
1072 && (av->volume == ve->volumeId[BACKVOL])) {
1073 /* backup always is on the same volume as parent */
1075 type |= (VRO | VBackup);
1077 mask = 0; /* Can't find volume in vldb entry */
1080 cellp = afs_GetCell(acell, 0);
1082 /* Gather the list of servers the VLDB says the volume is on
1083 * and initialize the ve->serverHost[] array. If a server struct
1084 * is not found, then get the list of addresses for the
1085 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1087 for (i = 0, j = 0; i < ve->nServers; i++) {
1088 if (((ve->serverFlags[i] & mask) == 0)
1089 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1090 continue; /* wrong volume don't use this volume */
1093 if (!(ve->serverFlags[i] & VLSF_UUID)) {
1094 /* The server has no uuid */
1095 serverid = htonl(ve->serverNumber[i].time_low);
1096 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport,
1097 WRITE_LOCK, (afsUUID *) 0, 0, av);
1099 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1100 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1102 /* uuid, uniquifier, and portal are the same */
1104 afs_uint32 *addrp, code;
1105 afs_int32 nentries, unique;
1107 ListAddrByAttributes attrs;
1109 struct rx_connection *rxconn;
1111 memset(&attrs, 0, sizeof(attrs));
1112 attrs.Mask = VLADDR_UUID;
1113 attrs.uuid = ve->serverNumber[i];
1114 memset(&uuid, 0, sizeof(uuid));
1115 memset(&addrs, 0, sizeof(addrs));
1118 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1119 tcell->cellNum, areq, SHARED_LOCK,
1124 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1131 /* Handle corrupt VLDB (defect 7393) */
1132 if (code == 0 && nentries == 0)
1135 } while (afs_Analyze
1136 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1138 /* Better handing of such failures; for now we'll simply retry this call */
1139 areq->volumeError = 1;
1143 addrp = addrs.bulkaddrs_val;
1144 for (k = 0; k < nentries; k++) {
1145 addrp[k] = htonl(addrp[k]);
1147 ts = afs_GetServer(addrp, nentries, acell,
1148 cellp->fsport, WRITE_LOCK,
1149 &ve->serverNumber[i],
1150 ve->serverUnique[i], av);
1151 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1156 /* The cell field could be 0 if the server entry was created
1157 * first with the 'fs setserverprefs' call which doesn't set
1158 * the cell field. Thus if the afs_GetServer call above
1159 * follows later on it will find the server entry thus it will
1160 * simply return without setting any fields, so we set the
1161 * field ourselves below.
1165 afs_PutServer(ts, WRITE_LOCK);
1169 ObtainWriteLock(&av->lock, 111);
1171 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1176 /* fill in volume types */
1177 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1178 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1179 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1181 if (ve->flags & VLF_DFSFILESET)
1182 av->states |= VForeign;
1184 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1185 } /*InstallVolumeEntry */
1189 * Reset volume info for the specified volume strecture. Mark volume
1190 * to be rechecked next time.
1194 afs_ResetVolumeInfo(struct volume *tv)
1198 AFS_STATCNT(afs_ResetVolumeInfo);
1199 ObtainWriteLock(&tv->lock, 117);
1200 tv->states |= VRecheck;
1202 /* the hard-mount code in afs_Analyze may not be able to reset this flag
1203 * when VRecheck is set, so clear it here to ensure it gets cleared. */
1204 tv->states &= ~VHardMount;
1206 for (i = 0; i < AFS_MAXHOSTS; i++)
1207 tv->status[i] = not_busy;
1209 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1212 ReleaseWriteLock(&tv->lock);