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 */
43 #include "afs/afs_dynroot.h"
45 #if defined(AFS_SUN56_ENV)
47 #include <inet/common.h>
48 #if defined(AFS_SUN58_ENV)
49 #include <netinet/ip6.h>
54 /* In case we don't have the vl error table yet. */
55 #ifndef ERROR_TABLE_BASE_VL
56 #define ERROR_TABLE_BASE_VL (363520L)
57 #define VL_NOENT (363524L)
58 #endif /* vlserver error base define */
60 /* Exported variables */
61 #if defined(LINUX_USE_FH)
62 struct fid volumeinfo_fh; /* File handle for VolumeItems file */
63 int volumeinfo_fh_type;
65 ino_t volumeInode; /* Inode for VolumeItems file */
67 afs_rwlock_t afs_xvolume; /** allocation lock for volumes */
68 struct volume *afs_freeVolList;
69 struct volume *afs_volumes[NVOLS];
70 afs_int32 afs_volCounter = 1; /** for allocating volume indices */
71 afs_int32 fvTable[NFENTRIES];
73 /* Forward declarations */
74 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell,
75 int agood, struct vrequest *areq,
77 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
78 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
84 * Convert a volume name to a number;
85 * @param aname Volume name.
86 * @return return 0 if can't parse as a number.
89 afs_vtoi(register char *aname)
91 register afs_int32 temp;
94 AFS_STATCNT(afs_vtoi);
95 while ((tc = *aname++)) {
96 if (tc > '9' || tc < '0')
97 return 0; /* invalid name */
107 * All of the vol cache routines must be called with the afs_xvolume
108 * lock held in exclusive mode, since they use static variables.
109 * In addition, we don't want two people adding the same volume
113 static struct fvolume staticFVolume;
114 afs_int32 afs_FVIndex = -1;
117 * UFS specific version of afs_GetVolSlot
121 afs_UFSGetVolSlot(void)
123 register struct volume *tv, **lv;
124 struct osi_file *tfile;
125 register afs_int32 i, code;
127 struct volume *bestVp, **bestLp;
129 AFS_STATCNT(afs_UFSGetVolSlot);
130 if (!afs_freeVolList) {
132 bestTime = 0x7fffffff;
135 for (i = 0; i < NVOLS; i++) {
136 lv = &afs_volumes[i];
137 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
138 if (tv->refCount == 0) { /* is this one available? */
139 if (tv->accessTime < bestTime) { /* best one available? */
140 bestTime = tv->accessTime;
148 osi_Panic("getvolslot none");
152 afs_osi_Free(tv->name, strlen(tv->name) + 1);
154 /* now write out volume structure to file */
156 tv->vtix = afs_volCounter++;
157 /* now put on hash chain */
158 i = FVHash(tv->cell, tv->volume);
159 staticFVolume.next = fvTable[i];
160 fvTable[i] = tv->vtix;
163 * Haul the guy in from disk so we don't overwrite hash table
166 if (afs_FVIndex != tv->vtix) {
167 #if defined(LINUX_USE_FH)
168 tfile = osi_UFSOpen_fh(&volumeinfo_fh, volumeinfo_fh_type);
170 tfile = osi_UFSOpen(volumeInode);
173 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
174 &staticFVolume, sizeof(struct fvolume));
175 if (code != sizeof(struct fvolume))
176 osi_Panic("read volumeinfo");
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 #if defined(LINUX_USE_FH)
189 tfile = osi_UFSOpen_fh(&volumeinfo_fh, volumeinfo_fh_type);
191 tfile = osi_UFSOpen(volumeInode);
194 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
195 &staticFVolume, sizeof(struct fvolume));
196 if (code != sizeof(struct fvolume))
197 osi_Panic("write volumeinfo");
200 tv = afs_freeVolList;
201 afs_freeVolList = tv->next;
205 } /*afs_UFSGetVolSlot */
209 * Get an available volume list slot. If the list does not exist,
210 * create one containing a single element.
214 afs_MemGetVolSlot(void)
216 register struct volume *tv;
218 AFS_STATCNT(afs_MemGetVolSlot);
219 if (!afs_freeVolList) {
220 struct volume *newVp;
222 newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume));
225 afs_freeVolList = newVp;
227 tv = afs_freeVolList;
228 afs_freeVolList = tv->next;
231 } /*afs_MemGetVolSlot */
234 * Reset volume information for all volume structs that
235 * point to a speicific server.
239 afs_ResetVolumes(struct server *srvp)
244 /* Find any volumes residing on this server and flush their state */
245 for (j = 0; j < NVOLS; j++) {
246 for (vp = afs_volumes[j]; vp; vp = vp->next) {
247 for (k = 0; k < MAXHOSTS; k++) {
248 if (!srvp || (vp->serverHost[k] == srvp)) {
249 vp->serverHost[k] = 0;
250 afs_ResetVolumeInfo(vp);
260 * Reset volume name to volume id mapping cache.
264 afs_CheckVolumeNames(int flags)
270 afs_int32 *volumeID, *cellID, vsize, nvols;
271 #ifdef AFS_DARWIN80_ENV
274 AFS_STATCNT(afs_CheckVolumeNames);
277 volumeID = cellID = NULL;
279 ObtainReadLock(&afs_xvolume);
280 if (flags & AFS_VOLCHECK_EXPIRED) {
282 * allocate space to hold the volumeIDs and cellIDs, only if
283 * we will be invalidating the mountpoints later on
285 for (i = 0; i < NVOLS; i++)
286 for (tv = afs_volumes[i]; tv; tv = tv->next)
289 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
290 cellID = (volumeID) ? volumeID + vsize : 0;
294 for (i = 0; i < NVOLS; i++) {
295 for (tv = afs_volumes[i]; tv; tv = tv->next) {
296 if (flags & AFS_VOLCHECK_EXPIRED) {
297 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
298 || (flags & AFS_VOLCHECK_FORCE)) {
299 afs_ResetVolumeInfo(tv); /* also resets status */
301 volumeID[nvols] = tv->volume;
302 cellID[nvols] = tv->cell;
309 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
310 for (j = 0; j < MAXHOSTS; j++)
311 tv->status[j] = not_busy;
316 ReleaseReadLock(&afs_xvolume);
319 /* next ensure all mt points are re-evaluated */
320 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
322 ObtainReadLock(&afs_xvcache);
323 for (i = 0; i < VCSIZE; i++) {
324 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
326 /* if the volume of "mvid" of the vcache entry is among the
327 * ones we found earlier, then we re-evaluate it. Also, if the
328 * force bit is set or we explicitly asked to reevaluate the
329 * mt-pts, we clean the cmvalid bit */
331 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
333 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
334 tvc->states &= ~CMValid;
336 /* If the volume that this file belongs to was reset earlier,
337 * then we should remove its callback.
338 * Again, if forced, always do it.
340 if ((tvc->states & CRO)
341 && (inVolList(&tvc->fid, nvols, volumeID, cellID)
342 || (flags & AFS_VOLCHECK_FORCE))) {
344 if (tvc->states & CVInit) {
345 ReleaseReadLock(&afs_xvcache);
346 afs_osi_Sleep(&tvc->states);
349 #ifdef AFS_DARWIN80_ENV
350 if (tvc->states & CDeadVnode) {
351 ReleaseReadLock(&afs_xvcache);
352 afs_osi_Sleep(&tvc->states);
358 if (vnode_ref(tvp)) {
360 /* AFSTOV(tvc) may be NULL */
368 ReleaseReadLock(&afs_xvcache);
370 ObtainWriteLock(&afs_xcbhash, 485);
371 /* LOCKXXX: We aren't holding tvc write lock? */
372 afs_DequeueCallback(tvc);
373 tvc->states &= ~CStatd;
374 ReleaseWriteLock(&afs_xcbhash);
375 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
376 osi_dnlc_purgedp(tvc);
378 #ifdef AFS_DARWIN80_ENV
379 vnode_put(AFSTOV(tvc));
380 /* our tvc ptr is still good until now */
382 ObtainReadLock(&afs_xvcache);
384 ObtainReadLock(&afs_xvcache);
386 /* our tvc ptr is still good until now */
392 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
393 ReleaseReadLock(&afs_xvcache);
397 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
399 } /*afs_CheckVolumeNames */
403 * Check if volume is in the specified list.
404 * @param fid File FID.
405 * @param nvols Nomber of volumes???
406 * @param vID Array of volume IDs.
407 * @param cID Array of cache IDs.
408 * @return 1 - true, 0 - false.
411 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
416 /* if no arrays present, be conservative and return true */
417 if (nvols && (!vID || !cID))
420 for (i = 0; i < nvols; ++i) {
421 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
428 /* afs_PutVolume is now a macro in afs.h */
432 * Return volume struct if we have it cached and it's up-to-date.
433 * Environment: Must be called with afs_xvolume unlocked.
434 * @param afid Volume FID.
436 * @return Volume or NULL if no result.
439 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
447 i = VHash(afid->Fid.Volume);
448 ObtainWriteLock(&afs_xvolume, 106);
449 for (tv = afs_volumes[i]; tv; tv = tv->next) {
450 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
451 && (tv->states & VRecheck) == 0) {
456 ReleaseWriteLock(&afs_xvolume);
457 return tv; /* NULL if we didn't find it */
458 } /*afs_FindVolume */
463 * Note that areq may be null, in which case we don't bother to set any
464 * request status information.
465 * @param afid Volume FID.
466 * @param areq Request type.
467 * @param locktype Lock to be used.
468 * @return Volume or NULL if no result.
471 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
475 char *bp, tbuf[CVBS];
476 AFS_STATCNT(afs_GetVolume);
478 tv = afs_FindVolume(afid, locktype);
480 /* Do a dynroot check and add dynroot volume if found. */
481 if (afs_IsDynrootAnyFid(afid)) {
482 tv = afs_NewDynrootVolume(afid);
484 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
485 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
495 * @param volid Volume ID. If it's 0, get it from the name.
496 * @param aname Volume name.
497 * @param ve Volume entry.
498 * @param tcell The cell containing this volume.
500 * @param type Type of volume.
501 * @param areq Request.
502 * @return Volume or NULL if failure.
504 static struct volume *
505 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
506 afs_int32 agood, afs_int32 type, struct vrequest *areq)
509 struct vldbentry *ove = (struct vldbentry *)ve;
510 struct nvldbentry *nve = (struct nvldbentry *)ve;
511 struct uvldbentry *uve = (struct uvldbentry *)ve;
513 int whichType; /* which type of volume to look for */
518 /* special hint from file server to use vlserver */
520 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
522 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
527 /* figure out which one we're really interested in (a set is returned) */
528 volid = afs_vtoi(aname);
531 volid = uve->volumeId[whichType];
532 } else if (type == 1) {
533 volid = nve->volumeId[whichType];
535 volid = ove->volumeId[whichType];
537 } /* end of if (volid == 0) */
538 } /* end of if (!volid) */
541 ObtainWriteLock(&afs_xvolume, 108);
543 for (tv = afs_volumes[i]; tv; tv = tv->next) {
544 if (tv->volume == volid && tv->cell == tcell->cellNum) {
549 struct fvolume *tf = 0;
551 tv = afs_GetVolSlot();
552 memset((char *)tv, 0, sizeof(struct volume));
553 tv->cell = tcell->cellNum;
554 RWLOCK_INIT(&tv->lock, "volume lock");
555 tv->next = afs_volumes[i]; /* thread into list */
558 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
559 if (afs_FVIndex != j) {
560 struct osi_file *tfile;
561 #if defined(LINUX_USE_FH)
562 tfile = osi_UFSOpen_fh(&volumeinfo_fh, volumeinfo_fh_type);
564 tfile = osi_UFSOpen(volumeInode);
567 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
568 &staticFVolume, sizeof(struct fvolume));
569 if (err != sizeof(struct fvolume))
570 osi_Panic("read volumeinfo2");
575 if (tf->cell == tv->cell && tf->volume == volid)
578 if (tf && (j != 0)) {
579 tv->vtix = afs_FVIndex;
580 tv->mtpoint = tf->mtpoint;
581 tv->dotdot = tf->dotdot;
582 tv->rootVnode = tf->rootVnode;
583 tv->rootUnique = tf->rootUnique;
586 tv->rootVnode = tv->rootUnique = 0;
587 afs_GetDynrootMountFid(&tv->dotdot);
588 afs_GetDynrootMountFid(&tv->mtpoint);
589 tv->mtpoint.Fid.Vnode =
590 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
591 tv->mtpoint.Fid.Unique = volid;
595 tv->states &= ~VRecheck; /* just checked it */
596 tv->accessTime = osi_Time();
597 ReleaseWriteLock(&afs_xvolume);
598 ObtainWriteLock(&tv->lock, 111);
600 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
601 } else if (type == 1)
602 InstallNVolumeEntry(tv, nve, tcell->cellNum);
604 InstallVolumeEntry(tv, ove, tcell->cellNum);
607 tv->name = afs_osi_Alloc(strlen(aname) + 1);
608 strcpy(tv->name, aname);
611 for (i = 0; i < NMAXNSERVERS; i++) {
612 tv->status[i] = not_busy;
614 ReleaseWriteLock(&tv->lock);
620 * Seek volume by it's name and attributes.
621 * If volume not found, try to add one.
622 * @param aname Volume name.
626 * @param locktype Type of lock to be used.
630 afs_GetVolumeByName(register char *aname, afs_int32 acell, int agood,
631 struct vrequest *areq, afs_int32 locktype)
636 AFS_STATCNT(afs_GetVolumeByName);
637 ObtainWriteLock(&afs_xvolume, 112);
638 for (i = 0; i < NVOLS; i++) {
639 for (tv = afs_volumes[i]; tv; tv = tv->next) {
640 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
641 && (tv->states & VRecheck) == 0) {
643 ReleaseWriteLock(&afs_xvolume);
649 ReleaseWriteLock(&afs_xvolume);
651 if (AFS_IS_DISCONNECTED)
654 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
659 * Init a new dynroot volume.
661 * @return Volume or NULL if not found.
663 static struct volume *
664 afs_NewDynrootVolume(struct VenusFid *fid)
668 struct vldbentry *tve;
669 char *bp, tbuf[CVBS];
671 tcell = afs_GetCell(fid->Cell, READ_LOCK);
674 tve = afs_osi_Alloc(sizeof(*tve));
675 if (!(tcell->states & CHasVolRef))
676 tcell->states |= CHasVolRef;
678 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
679 memset(tve, 0, sizeof(*tve));
680 strcpy(tve->name, "local-dynroot");
681 tve->volumeId[ROVOL] = fid->Fid.Volume;
682 tve->flags = VLF_ROEXISTS;
684 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
685 afs_PutCell(tcell, READ_LOCK);
686 afs_osi_Free(tve, sizeof(*tve));
693 * @param aname Volume name.
694 * @param acell Cell id.
696 * @param areq Request type.
697 * @param locktype Type of lock to be used.
698 * @return Volume or NULL if failure.
700 static struct volume *
701 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
702 struct vrequest *areq, afs_int32 locktype)
704 afs_int32 code, type = 0;
705 struct volume *tv, *tv1;
706 struct vldbentry *tve;
707 struct nvldbentry *ntve;
708 struct uvldbentry *utve;
712 struct vrequest treq;
714 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
717 tcell = afs_GetCell(acell, READ_LOCK);
722 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
727 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
728 ICL_TYPE_POINTER, aname);
729 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
730 tve = (struct vldbentry *)(tbuffer + 1024);
731 ntve = (struct nvldbentry *)tve;
732 utve = (struct uvldbentry *)tve;
733 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
736 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
739 if (tconn->srvr->server->flags & SNO_LHOSTS) {
742 code = VL_GetEntryByNameO(tconn->id, aname, tve);
744 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
747 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
752 code = VL_GetEntryByNameU(tconn->id, aname, utve);
754 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
755 if (code == RXGEN_OPCODE) {
758 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
760 if (code == RXGEN_OPCODE) {
762 tconn->srvr->server->flags |= SNO_LHOSTS;
764 code = VL_GetEntryByNameO(tconn->id, aname, tve);
767 tconn->srvr->server->flags |= SYES_LHOSTS;
769 tconn->srvr->server->flags |= SVLSRV_UUID;
775 } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */
776 SHARED_LOCK, tcell));
779 /* If the client has yet to contact this cell and contact failed due
780 * to network errors, mark the VLDB servers as back up.
781 * That the client tried and failed can be determined from the
782 * fact that there was a downtime incident, but CHasVolRef is not set.
784 /* RT 48959 - unclear if this should really go */
786 if (areq->networkError && !(tcell->states & CHasVolRef)) {
790 for (i = 0; i < MAXCELLHOSTS; i++) {
791 if ((sp = tcell->cellHosts[i]) == NULL)
793 for (sap = sp->addr; sap; sap = sap->next_sa)
794 afs_MarkServerUpOrDown(sap, 0);
798 afs_CopyError(&treq, areq);
799 osi_FreeLargeSpace(tbuffer);
800 afs_PutCell(tcell, READ_LOCK);
804 * Check to see if this cell has not yet referenced a volume. If
805 * it hasn't, it's just about to change its status, and we need to mark
806 * this fact down. Note that it is remotely possible that afs_SetupVolume
807 * could fail and we would still not have a volume reference.
809 if (!(tcell->states & CHasVolRef)) {
810 tcell->states |= CHasVolRef;
811 afs_stats_cmperf.numCellsContacted++;
813 /*First time a volume in this cell has been referenced */
820 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
821 if ((agood == 3) && tv->backVol) {
823 * This means that very soon we'll ask for the BK volume so
824 * we'll prefetch it (well we did already.)
827 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, areq);
830 if ((agood >= 2) && tv->roVol) {
832 * This means that very soon we'll ask for the RO volume so
833 * we'll prefetch it (well we did already.)
835 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
838 osi_FreeLargeSpace(tbuffer);
839 afs_PutCell(tcell, READ_LOCK);
842 } /*afs_NewVolumeByName */
847 * Call this with the volume structure locked; used for new-style vldb requests.
853 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
855 register struct server *ts;
861 AFS_STATCNT(InstallVolumeEntry);
863 /* Determine the type of volume we want */
864 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
866 } else if ((ve->flags & VLF_ROEXISTS)
867 && (av->volume == ve->volumeId[ROVOL])) {
870 } else if ((ve->flags & VLF_BACKEXISTS)
871 && (av->volume == ve->volumeId[BACKVOL])) {
872 /* backup always is on the same volume as parent */
874 av->states |= (VRO | VBackup);
876 mask = 0; /* Can't find volume in vldb entry */
879 /* fill in volume types */
880 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
881 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
882 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
884 if (ve->flags & VLF_DFSFILESET)
885 av->states |= VForeign;
887 cellp = afs_GetCell(acell, 0);
889 /* This volume, av, is locked. Zero out the serverHosts[] array
890 * so that if afs_GetServer() decides to replace the server
891 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
894 for (j = 0; j < MAXHOSTS; j++) {
895 av->serverHost[j] = 0;
898 /* Step through the VLDB entry making sure each server listed is there */
899 for (i = 0, j = 0; i < ve->nServers; i++) {
900 if (((ve->serverFlags[i] & mask) == 0)
901 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
902 continue; /* wrong volume or don't use this volume */
905 temp = htonl(ve->serverNumber[i]);
906 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
908 av->serverHost[j] = ts;
911 * The cell field could be 0 if the server entry was created
912 * first with the 'fs setserverprefs' call which doesn't set
913 * the cell field. Thus if the afs_GetServer call above
914 * follows later on it will find the server entry thus it will
915 * simply return without setting any fields, so we set the
916 * field ourselves below.
920 afs_PutServer(ts, WRITE_LOCK);
924 av->serverHost[j++] = 0;
926 afs_SortServers(av->serverHost, MAXHOSTS);
927 } /*InstallVolumeEntry */
931 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
933 register struct server *ts;
939 AFS_STATCNT(InstallVolumeEntry);
941 /* Determine type of volume we want */
942 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
944 } else if ((ve->flags & VLF_ROEXISTS)
945 && (av->volume == ve->volumeId[ROVOL])) {
948 } else if ((ve->flags & VLF_BACKEXISTS)
949 && (av->volume == ve->volumeId[BACKVOL])) {
950 /* backup always is on the same volume as parent */
952 av->states |= (VRO | VBackup);
954 mask = 0; /* Can't find volume in vldb entry */
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 cellp = afs_GetCell(acell, 0);
967 /* This volume, av, is locked. Zero out the serverHosts[] array
968 * so that if afs_GetServer() decides to replace the server
969 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
972 for (j = 0; j < MAXHOSTS; j++) {
973 av->serverHost[j] = 0;
976 /* Step through the VLDB entry making sure each server listed is there */
977 for (i = 0, j = 0; i < ve->nServers; i++) {
978 if (((ve->serverFlags[i] & mask) == 0)
979 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
980 continue; /* wrong volume or don't use this volume */
983 temp = htonl(ve->serverNumber[i]);
984 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
986 av->serverHost[j] = ts;
988 * The cell field could be 0 if the server entry was created
989 * first with the 'fs setserverprefs' call which doesn't set
990 * the cell field. Thus if the afs_GetServer call above
991 * follows later on it will find the server entry thus it will
992 * simply return without setting any fields, so we set the
993 * field ourselves below.
997 afs_PutServer(ts, WRITE_LOCK);
1001 av->serverHost[j++] = 0;
1003 afs_SortServers(av->serverHost, MAXHOSTS);
1004 } /*InstallNVolumeEntry */
1008 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1009 struct cell *tcell, struct vrequest *areq)
1011 register struct server *ts;
1015 afs_uint32 serverid;
1019 AFS_STATCNT(InstallVolumeEntry);
1021 /* Determine type of volume we want */
1022 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1024 } else if ((ve->flags & VLF_ROEXISTS)
1025 && av->volume == ve->volumeId[ROVOL]) {
1028 } else if ((ve->flags & VLF_BACKEXISTS)
1029 && (av->volume == ve->volumeId[BACKVOL])) {
1030 /* backup always is on the same volume as parent */
1032 av->states |= (VRO | VBackup);
1034 mask = 0; /* Can't find volume in vldb entry */
1037 /* fill in volume types */
1038 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1039 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1040 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1042 if (ve->flags & VLF_DFSFILESET)
1043 av->states |= VForeign;
1045 cellp = afs_GetCell(acell, 0);
1047 /* This volume, av, is locked. Zero out the serverHosts[] array
1048 * so that if afs_GetServer() decides to replace the server
1049 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1052 for (j = 0; j < MAXHOSTS; j++) {
1053 av->serverHost[j] = 0;
1056 /* Gather the list of servers the VLDB says the volume is on
1057 * and initialize the ve->serverHost[] array. If a server struct
1058 * is not found, then get the list of addresses for the
1059 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1061 for (i = 0, j = 0; i < ve->nServers; i++) {
1062 if (((ve->serverFlags[i] & mask) == 0)
1063 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1064 continue; /* wrong volume don't use this volume */
1067 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
1068 /* The server has no uuid */
1069 serverid = htonl(ve->serverNumber[i].time_low);
1070 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
1073 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1074 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1076 /* uuid, uniquifier, and portal are the same */
1078 afs_uint32 *addrp, nentries, code, unique;
1080 ListAddrByAttributes attrs;
1083 memset((char *)&attrs, 0, sizeof(attrs));
1084 attrs.Mask = VLADDR_UUID;
1085 attrs.uuid = ve->serverNumber[i];
1086 memset((char *)&uuid, 0, sizeof(uuid));
1087 memset((char *)&addrs, 0, sizeof(addrs));
1090 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1091 tcell->cellNum, areq, SHARED_LOCK);
1095 VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique,
1102 /* Handle corrupt VLDB (defect 7393) */
1103 if (code == 0 && nentries == 0)
1106 } while (afs_Analyze
1107 (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1109 /* Better handing of such failures; for now we'll simply retry this call */
1110 areq->volumeError = 1;
1114 addrp = addrs.bulkaddrs_val;
1115 for (k = 0; k < nentries; k++) {
1116 addrp[k] = htonl(addrp[k]);
1118 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1119 WRITE_LOCK, &ve->serverNumber[i],
1120 ve->serverUnique[i]);
1121 afs_osi_Free(addrs.bulkaddrs_val,
1122 addrs.bulkaddrs_len * sizeof(*addrp));
1125 av->serverHost[j] = ts;
1127 /* The cell field could be 0 if the server entry was created
1128 * first with the 'fs setserverprefs' call which doesn't set
1129 * the cell field. Thus if the afs_GetServer call above
1130 * follows later on it will find the server entry thus it will
1131 * simply return without setting any fields, so we set the
1132 * field ourselves below.
1136 afs_PutServer(ts, WRITE_LOCK);
1140 afs_SortServers(av->serverHost, MAXHOSTS);
1141 } /*InstallVolumeEntry */
1145 * Reset volume info for the specified volume strecture. Mark volume
1146 * to be rechecked next time.
1150 afs_ResetVolumeInfo(struct volume *tv)
1154 AFS_STATCNT(afs_ResetVolumeInfo);
1155 ObtainWriteLock(&tv->lock, 117);
1156 tv->states |= VRecheck;
1157 for (i = 0; i < MAXHOSTS; i++)
1158 tv->status[i] = not_busy;
1160 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1163 ReleaseWriteLock(&tv->lock);