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 ino_t volumeInode; /** Inode for VolumeItems file */
62 afs_rwlock_t afs_xvolume; /** allocation lock for volumes */
63 struct volume *afs_freeVolList;
64 struct volume *afs_volumes[NVOLS];
65 afs_int32 afs_volCounter = 1; /** for allocating volume indices */
66 afs_int32 fvTable[NFENTRIES];
68 /* Forward declarations */
69 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell,
70 int agood, struct vrequest *areq,
72 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
73 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
79 * Convert a volume name to a number;
80 * @param aname Volume name.
81 * @return return 0 if can't parse as a number.
84 afs_vtoi(register char *aname)
86 register afs_int32 temp;
89 AFS_STATCNT(afs_vtoi);
90 while ((tc = *aname++)) {
91 if (tc > '9' || tc < '0')
92 return 0; /* invalid name */
102 * All of the vol cache routines must be called with the afs_xvolume
103 * lock held in exclusive mode, since they use static variables.
104 * In addition, we don't want two people adding the same volume
108 static struct fvolume staticFVolume;
109 afs_int32 afs_FVIndex = -1;
112 * UFS specific version of afs_GetVolSlot
116 afs_UFSGetVolSlot(void)
118 register struct volume *tv, **lv;
119 struct osi_file *tfile;
120 register afs_int32 i, code;
122 struct volume *bestVp, **bestLp;
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 osi_Panic("getvolslot none");
147 afs_osi_Free(tv->name, strlen(tv->name) + 1);
149 /* now write out volume structure to file */
151 tv->vtix = afs_volCounter++;
152 /* now put on hash chain */
153 i = FVHash(tv->cell, tv->volume);
154 staticFVolume.next = fvTable[i];
155 fvTable[i] = tv->vtix;
158 * Haul the guy in from disk so we don't overwrite hash table
161 if (afs_FVIndex != tv->vtix) {
162 tfile = osi_UFSOpen(volumeInode);
164 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
165 &staticFVolume, sizeof(struct fvolume));
166 if (code != sizeof(struct fvolume))
167 osi_Panic("read volumeinfo");
169 afs_FVIndex = tv->vtix;
172 afs_FVIndex = tv->vtix;
173 staticFVolume.volume = tv->volume;
174 staticFVolume.cell = tv->cell;
175 staticFVolume.mtpoint = tv->mtpoint;
176 staticFVolume.dotdot = tv->dotdot;
177 staticFVolume.rootVnode = tv->rootVnode;
178 staticFVolume.rootUnique = tv->rootUnique;
179 tfile = osi_UFSOpen(volumeInode);
181 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
182 &staticFVolume, sizeof(struct fvolume));
183 if (code != sizeof(struct fvolume))
184 osi_Panic("write volumeinfo");
187 tv = afs_freeVolList;
188 afs_freeVolList = tv->next;
192 } /*afs_UFSGetVolSlot */
196 * Get an available volume list slot. If the list does not exist,
197 * create one containing a single element.
201 afs_MemGetVolSlot(void)
203 register struct volume *tv;
205 AFS_STATCNT(afs_MemGetVolSlot);
206 if (!afs_freeVolList) {
207 struct volume *newVp;
209 newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume));
212 afs_freeVolList = newVp;
214 tv = afs_freeVolList;
215 afs_freeVolList = tv->next;
218 } /*afs_MemGetVolSlot */
221 * Reset volume information for all volume structs that
222 * point to a speicific server.
226 afs_ResetVolumes(struct server *srvp)
231 /* Find any volumes residing on this server and flush their state */
232 for (j = 0; j < NVOLS; j++) {
233 for (vp = afs_volumes[j]; vp; vp = vp->next) {
234 for (k = 0; k < MAXHOSTS; k++) {
235 if (!srvp || (vp->serverHost[k] == srvp)) {
236 vp->serverHost[k] = 0;
237 afs_ResetVolumeInfo(vp);
247 * Reset volume name to volume id mapping cache.
251 afs_CheckVolumeNames(int flags)
257 afs_int32 *volumeID, *cellID, vsize, nvols;
258 #ifdef AFS_DARWIN80_ENV
261 AFS_STATCNT(afs_CheckVolumeNames);
264 volumeID = cellID = NULL;
266 ObtainReadLock(&afs_xvolume);
267 if (flags & AFS_VOLCHECK_EXPIRED) {
269 * allocate space to hold the volumeIDs and cellIDs, only if
270 * we will be invalidating the mountpoints later on
272 for (i = 0; i < NVOLS; i++)
273 for (tv = afs_volumes[i]; tv; tv = tv->next)
276 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
277 cellID = (volumeID) ? volumeID + vsize : 0;
281 for (i = 0; i < NVOLS; i++) {
282 for (tv = afs_volumes[i]; tv; tv = tv->next) {
283 if (flags & AFS_VOLCHECK_EXPIRED) {
284 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
285 || (flags & AFS_VOLCHECK_FORCE)) {
286 afs_ResetVolumeInfo(tv); /* also resets status */
288 volumeID[nvols] = tv->volume;
289 cellID[nvols] = tv->cell;
296 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
297 for (j = 0; j < MAXHOSTS; j++)
298 tv->status[j] = not_busy;
303 ReleaseReadLock(&afs_xvolume);
306 /* next ensure all mt points are re-evaluated */
307 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
309 ObtainReadLock(&afs_xvcache);
310 for (i = 0; i < VCSIZE; i++) {
311 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
313 /* if the volume of "mvid" of the vcache entry is among the
314 * ones we found earlier, then we re-evaluate it. Also, if the
315 * force bit is set or we explicitly asked to reevaluate the
316 * mt-pts, we clean the cmvalid bit */
318 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
320 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
321 tvc->states &= ~CMValid;
323 /* If the volume that this file belongs to was reset earlier,
324 * then we should remove its callback.
325 * Again, if forced, always do it.
327 if ((tvc->states & CRO)
328 && (inVolList(&tvc->fid, nvols, volumeID, cellID)
329 || (flags & AFS_VOLCHECK_FORCE))) {
331 if (tvc->states & CVInit) {
332 ReleaseReadLock(&afs_xvcache);
333 afs_osi_Sleep(&tvc->states);
336 #ifdef AFS_DARWIN80_ENV
337 if (tvc->states & CDeadVnode) {
338 ReleaseReadLock(&afs_xvcache);
339 afs_osi_Sleep(&tvc->states);
345 if (vnode_ref(tvp)) {
347 /* AFSTOV(tvc) may be NULL */
355 ReleaseReadLock(&afs_xvcache);
357 ObtainWriteLock(&afs_xcbhash, 485);
358 /* LOCKXXX: We aren't holding tvc write lock? */
359 afs_DequeueCallback(tvc);
360 tvc->states &= ~CStatd;
361 ReleaseWriteLock(&afs_xcbhash);
362 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
363 osi_dnlc_purgedp(tvc);
365 #ifdef AFS_DARWIN80_ENV
366 vnode_put(AFSTOV(tvc));
367 /* our tvc ptr is still good until now */
369 ObtainReadLock(&afs_xvcache);
371 ObtainReadLock(&afs_xvcache);
373 /* our tvc ptr is still good until now */
379 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
380 ReleaseReadLock(&afs_xvcache);
384 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
386 } /*afs_CheckVolumeNames */
390 * Check if volume is in the specified list.
391 * @param fid File FID.
392 * @param nvols Nomber of volumes???
393 * @param vID Array of volume IDs.
394 * @param cID Array of cache IDs.
395 * @return 1 - true, 0 - false.
398 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
403 /* if no arrays present, be conservative and return true */
404 if (nvols && (!vID || !cID))
407 for (i = 0; i < nvols; ++i) {
408 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
415 /* afs_PutVolume is now a macro in afs.h */
419 * Return volume struct if we have it cached and it's up-to-date.
420 * Environment: Must be called with afs_xvolume unlocked.
421 * @param afid Volume FID.
423 * @return Volume or NULL if no result.
426 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
434 i = VHash(afid->Fid.Volume);
435 ObtainWriteLock(&afs_xvolume, 106);
436 for (tv = afs_volumes[i]; tv; tv = tv->next) {
437 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
438 && (tv->states & VRecheck) == 0) {
443 ReleaseWriteLock(&afs_xvolume);
444 return tv; /* NULL if we didn't find it */
445 } /*afs_FindVolume */
450 * Note that areq may be null, in which case we don't bother to set any
451 * request status information.
452 * @param afid Volume FID.
453 * @param areq Request type.
454 * @param locktype Lock to be used.
455 * @return Volume or NULL if no result.
458 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
462 char *bp, tbuf[CVBS];
463 AFS_STATCNT(afs_GetVolume);
465 tv = afs_FindVolume(afid, locktype);
467 /* Do a dynroot check and add dynroot volume if found. */
468 if (afs_IsDynrootAnyFid(afid)) {
469 tv = afs_NewDynrootVolume(afid);
471 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
472 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
482 * @param volid Volume ID. If it's 0, get it from the name.
483 * @param aname Volume name.
484 * @param ve Volume entry.
485 * @param tcell The cell containing this volume.
487 * @param type Type of volume.
488 * @param areq Request.
489 * @return Volume or NULL if failure.
491 static struct volume *
492 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
493 afs_int32 agood, afs_int32 type, struct vrequest *areq)
496 struct vldbentry *ove = (struct vldbentry *)ve;
497 struct nvldbentry *nve = (struct nvldbentry *)ve;
498 struct uvldbentry *uve = (struct uvldbentry *)ve;
500 int whichType; /* which type of volume to look for */
505 /* special hint from file server to use vlserver */
507 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
509 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
514 /* figure out which one we're really interested in (a set is returned) */
515 volid = afs_vtoi(aname);
518 volid = uve->volumeId[whichType];
519 } else if (type == 1) {
520 volid = nve->volumeId[whichType];
522 volid = ove->volumeId[whichType];
524 } /* end of if (volid == 0) */
525 } /* end of if (!volid) */
528 ObtainWriteLock(&afs_xvolume, 108);
530 for (tv = afs_volumes[i]; tv; tv = tv->next) {
531 if (tv->volume == volid && tv->cell == tcell->cellNum) {
536 struct fvolume *tf = 0;
538 tv = afs_GetVolSlot();
539 memset((char *)tv, 0, sizeof(struct volume));
540 tv->cell = tcell->cellNum;
541 RWLOCK_INIT(&tv->lock, "volume lock");
542 tv->next = afs_volumes[i]; /* thread into list */
545 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
546 if (afs_FVIndex != j) {
547 struct osi_file *tfile;
548 tfile = osi_UFSOpen(volumeInode);
550 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
551 &staticFVolume, sizeof(struct fvolume));
552 if (err != sizeof(struct fvolume))
553 osi_Panic("read volumeinfo2");
558 if (tf->cell == tv->cell && tf->volume == volid)
561 if (tf && (j != 0)) {
562 tv->vtix = afs_FVIndex;
563 tv->mtpoint = tf->mtpoint;
564 tv->dotdot = tf->dotdot;
565 tv->rootVnode = tf->rootVnode;
566 tv->rootUnique = tf->rootUnique;
569 tv->rootVnode = tv->rootUnique = 0;
570 afs_GetDynrootMountFid(&tv->dotdot);
571 afs_GetDynrootMountFid(&tv->mtpoint);
572 tv->mtpoint.Fid.Vnode =
573 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
574 tv->mtpoint.Fid.Unique = volid;
578 tv->states &= ~VRecheck; /* just checked it */
579 tv->accessTime = osi_Time();
580 ReleaseWriteLock(&afs_xvolume);
581 ObtainWriteLock(&tv->lock, 111);
583 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
584 } else if (type == 1)
585 InstallNVolumeEntry(tv, nve, tcell->cellNum);
587 InstallVolumeEntry(tv, ove, tcell->cellNum);
590 tv->name = afs_osi_Alloc(strlen(aname) + 1);
591 strcpy(tv->name, aname);
594 for (i = 0; i < NMAXNSERVERS; i++) {
595 tv->status[i] = not_busy;
597 ReleaseWriteLock(&tv->lock);
603 * Seek volume by it's name and attributes.
604 * If volume not found, try to add one.
605 * @param aname Volume name.
609 * @param locktype Type of lock to be used.
613 afs_GetVolumeByName(register char *aname, afs_int32 acell, int agood,
614 struct vrequest *areq, afs_int32 locktype)
619 AFS_STATCNT(afs_GetVolumeByName);
620 ObtainWriteLock(&afs_xvolume, 112);
621 for (i = 0; i < NVOLS; i++) {
622 for (tv = afs_volumes[i]; tv; tv = tv->next) {
623 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
624 && (tv->states & VRecheck) == 0) {
626 ReleaseWriteLock(&afs_xvolume);
632 ReleaseWriteLock(&afs_xvolume);
634 if (AFS_IS_DISCONNECTED)
637 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
642 * Init a new dynroot volume.
644 * @return Volume or NULL if not found.
646 static struct volume *
647 afs_NewDynrootVolume(struct VenusFid *fid)
651 struct vldbentry *tve;
652 char *bp, tbuf[CVBS];
654 tcell = afs_GetCell(fid->Cell, READ_LOCK);
657 tve = afs_osi_Alloc(sizeof(*tve));
658 if (!(tcell->states & CHasVolRef))
659 tcell->states |= CHasVolRef;
661 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
662 memset(tve, 0, sizeof(*tve));
663 strcpy(tve->name, "local-dynroot");
664 tve->volumeId[ROVOL] = fid->Fid.Volume;
665 tve->flags = VLF_ROEXISTS;
667 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
668 afs_PutCell(tcell, READ_LOCK);
669 afs_osi_Free(tve, sizeof(*tve));
676 * @param aname Volume name.
677 * @param acell Cell id.
679 * @param areq Request type.
680 * @param locktype Type of lock to be used.
681 * @return Volume or NULL if failure.
683 static struct volume *
684 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
685 struct vrequest *areq, afs_int32 locktype)
687 afs_int32 code, type = 0;
688 struct volume *tv, *tv1;
689 struct vldbentry *tve;
690 struct nvldbentry *ntve;
691 struct uvldbentry *utve;
695 struct vrequest treq;
697 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
700 tcell = afs_GetCell(acell, READ_LOCK);
705 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
710 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
711 ICL_TYPE_POINTER, aname);
712 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
713 tve = (struct vldbentry *)(tbuffer + 1024);
714 ntve = (struct nvldbentry *)tve;
715 utve = (struct uvldbentry *)tve;
716 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
719 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
722 if (tconn->srvr->server->flags & SNO_LHOSTS) {
725 code = VL_GetEntryByNameO(tconn->id, aname, tve);
727 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
730 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
735 code = VL_GetEntryByNameU(tconn->id, aname, utve);
737 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
738 if (code == RXGEN_OPCODE) {
741 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
743 if (code == RXGEN_OPCODE) {
745 tconn->srvr->server->flags |= SNO_LHOSTS;
747 code = VL_GetEntryByNameO(tconn->id, aname, tve);
750 tconn->srvr->server->flags |= SYES_LHOSTS;
752 tconn->srvr->server->flags |= SVLSRV_UUID;
758 } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */
759 SHARED_LOCK, tcell));
762 /* If the client has yet to contact this cell and contact failed due
763 * to network errors, mark the VLDB servers as back up.
764 * That the client tried and failed can be determined from the
765 * fact that there was a downtime incident, but CHasVolRef is not set.
767 /* RT 48959 - unclear if this should really go */
769 if (areq->networkError && !(tcell->states & CHasVolRef)) {
773 for (i = 0; i < MAXCELLHOSTS; i++) {
774 if ((sp = tcell->cellHosts[i]) == NULL)
776 for (sap = sp->addr; sap; sap = sap->next_sa)
777 afs_MarkServerUpOrDown(sap, 0);
781 afs_CopyError(&treq, areq);
782 osi_FreeLargeSpace(tbuffer);
783 afs_PutCell(tcell, READ_LOCK);
787 * Check to see if this cell has not yet referenced a volume. If
788 * it hasn't, it's just about to change its status, and we need to mark
789 * this fact down. Note that it is remotely possible that afs_SetupVolume
790 * could fail and we would still not have a volume reference.
792 if (!(tcell->states & CHasVolRef)) {
793 tcell->states |= CHasVolRef;
794 afs_stats_cmperf.numCellsContacted++;
796 /*First time a volume in this cell has been referenced */
803 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
804 if ((agood == 3) && tv->backVol) {
806 * This means that very soon we'll ask for the BK volume so
807 * we'll prefetch it (well we did already.)
810 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, areq);
813 if ((agood >= 2) && tv->roVol) {
815 * This means that very soon we'll ask for the RO volume so
816 * we'll prefetch it (well we did already.)
818 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
821 osi_FreeLargeSpace(tbuffer);
822 afs_PutCell(tcell, READ_LOCK);
825 } /*afs_NewVolumeByName */
830 * Call this with the volume structure locked; used for new-style vldb requests.
836 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
838 register struct server *ts;
844 AFS_STATCNT(InstallVolumeEntry);
846 /* Determine the type of volume we want */
847 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
849 } else if ((ve->flags & VLF_ROEXISTS)
850 && (av->volume == ve->volumeId[ROVOL])) {
853 } else if ((ve->flags & VLF_BACKEXISTS)
854 && (av->volume == ve->volumeId[BACKVOL])) {
855 /* backup always is on the same volume as parent */
857 av->states |= (VRO | VBackup);
859 mask = 0; /* Can't find volume in vldb entry */
862 /* fill in volume types */
863 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
864 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
865 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
867 if (ve->flags & VLF_DFSFILESET)
868 av->states |= VForeign;
870 cellp = afs_GetCell(acell, 0);
872 /* This volume, av, is locked. Zero out the serverHosts[] array
873 * so that if afs_GetServer() decides to replace the server
874 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
877 for (j = 0; j < MAXHOSTS; j++) {
878 av->serverHost[j] = 0;
881 /* Step through the VLDB entry making sure each server listed is there */
882 for (i = 0, j = 0; i < ve->nServers; i++) {
883 if (((ve->serverFlags[i] & mask) == 0)
884 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
885 continue; /* wrong volume or don't use this volume */
888 temp = htonl(ve->serverNumber[i]);
889 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
891 av->serverHost[j] = ts;
894 * The cell field could be 0 if the server entry was created
895 * first with the 'fs setserverprefs' call which doesn't set
896 * the cell field. Thus if the afs_GetServer call above
897 * follows later on it will find the server entry thus it will
898 * simply return without setting any fields, so we set the
899 * field ourselves below.
903 afs_PutServer(ts, WRITE_LOCK);
907 av->serverHost[j++] = 0;
909 afs_SortServers(av->serverHost, MAXHOSTS);
910 } /*InstallVolumeEntry */
914 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
916 register struct server *ts;
922 AFS_STATCNT(InstallVolumeEntry);
924 /* Determine type of volume we want */
925 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
927 } else if ((ve->flags & VLF_ROEXISTS)
928 && (av->volume == ve->volumeId[ROVOL])) {
931 } else if ((ve->flags & VLF_BACKEXISTS)
932 && (av->volume == ve->volumeId[BACKVOL])) {
933 /* backup always is on the same volume as parent */
935 av->states |= (VRO | VBackup);
937 mask = 0; /* Can't find volume in vldb entry */
940 /* fill in volume types */
941 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
942 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
943 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
945 if (ve->flags & VLF_DFSFILESET)
946 av->states |= VForeign;
948 cellp = afs_GetCell(acell, 0);
950 /* This volume, av, is locked. Zero out the serverHosts[] array
951 * so that if afs_GetServer() decides to replace the server
952 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
955 for (j = 0; j < MAXHOSTS; j++) {
956 av->serverHost[j] = 0;
959 /* Step through the VLDB entry making sure each server listed is there */
960 for (i = 0, j = 0; i < ve->nServers; i++) {
961 if (((ve->serverFlags[i] & mask) == 0)
962 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
963 continue; /* wrong volume or don't use this volume */
966 temp = htonl(ve->serverNumber[i]);
967 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
969 av->serverHost[j] = ts;
971 * The cell field could be 0 if the server entry was created
972 * first with the 'fs setserverprefs' call which doesn't set
973 * the cell field. Thus if the afs_GetServer call above
974 * follows later on it will find the server entry thus it will
975 * simply return without setting any fields, so we set the
976 * field ourselves below.
980 afs_PutServer(ts, WRITE_LOCK);
984 av->serverHost[j++] = 0;
986 afs_SortServers(av->serverHost, MAXHOSTS);
987 } /*InstallNVolumeEntry */
991 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
992 struct cell *tcell, struct vrequest *areq)
994 register struct server *ts;
1002 AFS_STATCNT(InstallVolumeEntry);
1004 /* Determine type of volume we want */
1005 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1007 } else if ((ve->flags & VLF_ROEXISTS)
1008 && av->volume == ve->volumeId[ROVOL]) {
1011 } else if ((ve->flags & VLF_BACKEXISTS)
1012 && (av->volume == ve->volumeId[BACKVOL])) {
1013 /* backup always is on the same volume as parent */
1015 av->states |= (VRO | VBackup);
1017 mask = 0; /* Can't find volume in vldb entry */
1020 /* fill in volume types */
1021 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1022 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1023 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1025 if (ve->flags & VLF_DFSFILESET)
1026 av->states |= VForeign;
1028 cellp = afs_GetCell(acell, 0);
1030 /* This volume, av, is locked. Zero out the serverHosts[] array
1031 * so that if afs_GetServer() decides to replace the server
1032 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1035 for (j = 0; j < MAXHOSTS; j++) {
1036 av->serverHost[j] = 0;
1039 /* Gather the list of servers the VLDB says the volume is on
1040 * and initialize the ve->serverHost[] array. If a server struct
1041 * is not found, then get the list of addresses for the
1042 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1044 for (i = 0, j = 0; i < ve->nServers; i++) {
1045 if (((ve->serverFlags[i] & mask) == 0)
1046 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1047 continue; /* wrong volume don't use this volume */
1050 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
1051 /* The server has no uuid */
1052 serverid = htonl(ve->serverNumber[i].time_low);
1053 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
1056 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1057 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1059 /* uuid, uniquifier, and portal are the same */
1061 afs_uint32 *addrp, nentries, code, unique;
1063 ListAddrByAttributes attrs;
1066 memset((char *)&attrs, 0, sizeof(attrs));
1067 attrs.Mask = VLADDR_UUID;
1068 attrs.uuid = ve->serverNumber[i];
1069 memset((char *)&uuid, 0, sizeof(uuid));
1070 memset((char *)&addrs, 0, sizeof(addrs));
1073 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1074 tcell->cellNum, areq, SHARED_LOCK);
1078 VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique,
1085 /* Handle corrupt VLDB (defect 7393) */
1086 if (code == 0 && nentries == 0)
1089 } while (afs_Analyze
1090 (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1092 /* Better handing of such failures; for now we'll simply retry this call */
1093 areq->volumeError = 1;
1097 addrp = addrs.bulkaddrs_val;
1098 for (k = 0; k < nentries; k++) {
1099 addrp[k] = htonl(addrp[k]);
1101 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1102 WRITE_LOCK, &ve->serverNumber[i],
1103 ve->serverUnique[i]);
1104 afs_osi_Free(addrs.bulkaddrs_val,
1105 addrs.bulkaddrs_len * sizeof(*addrp));
1108 av->serverHost[j] = ts;
1110 /* The cell field could be 0 if the server entry was created
1111 * first with the 'fs setserverprefs' call which doesn't set
1112 * the cell field. Thus if the afs_GetServer call above
1113 * follows later on it will find the server entry thus it will
1114 * simply return without setting any fields, so we set the
1115 * field ourselves below.
1119 afs_PutServer(ts, WRITE_LOCK);
1123 afs_SortServers(av->serverHost, MAXHOSTS);
1124 } /*InstallVolumeEntry */
1128 * Reset volume info for the specified volume strecture. Mark volume
1129 * to be rechecked next time.
1133 afs_ResetVolumeInfo(struct volume *tv)
1137 AFS_STATCNT(afs_ResetVolumeInfo);
1138 ObtainWriteLock(&tv->lock, 117);
1139 tv->states |= VRecheck;
1140 for (i = 0; i < MAXHOSTS; i++)
1141 tv->status[i] = not_busy;
1143 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1146 ReleaseWriteLock(&tv->lock);