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.
82 afs_vtoi(register char *aname)
84 register afs_int32 temp;
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 register struct volume *tv = NULL, **lv;
117 struct osi_file *tfile;
118 register afs_int32 i = -1, code;
120 struct volume *bestVp, *oldLp = NULL, **bestLp = NULL;
121 char *oldname = NULL;
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;
216 fvTable[i] = staticFVolume.next;
222 /* we messed with staticFVolume, so make sure someone else
223 * doesn't think it's fine to use */
227 } /*afs_UFSGetVolSlot */
231 * Get an available volume list slot. If the list does not exist,
232 * create one containing a single element.
236 afs_MemGetVolSlot(void)
238 register struct volume *tv;
240 AFS_STATCNT(afs_MemGetVolSlot);
241 if (!afs_freeVolList) {
242 struct volume *newVp;
244 newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume));
247 afs_freeVolList = newVp;
249 tv = afs_freeVolList;
250 afs_freeVolList = tv->next;
253 } /*afs_MemGetVolSlot */
256 * Reset volume information for all volume structs that
257 * point to a speicific server.
261 afs_ResetVolumes(struct server *srvp)
266 /* Find any volumes residing on this server and flush their state */
267 for (j = 0; j < NVOLS; j++) {
268 for (vp = afs_volumes[j]; vp; vp = vp->next) {
269 for (k = 0; k < AFS_MAXHOSTS; k++) {
270 if (!srvp || (vp->serverHost[k] == srvp)) {
271 vp->serverHost[k] = 0;
272 afs_ResetVolumeInfo(vp);
282 * Reset volume name to volume id mapping cache.
286 afs_CheckVolumeNames(int flags)
292 afs_int32 *volumeID, *cellID, vsize, nvols;
293 #ifdef AFS_DARWIN80_ENV
296 AFS_STATCNT(afs_CheckVolumeNames);
299 volumeID = cellID = NULL;
301 ObtainReadLock(&afs_xvolume);
302 if (flags & AFS_VOLCHECK_EXPIRED) {
304 * allocate space to hold the volumeIDs and cellIDs, only if
305 * we will be invalidating the mountpoints later on
307 for (i = 0; i < NVOLS; i++)
308 for (tv = afs_volumes[i]; tv; tv = tv->next)
311 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
312 cellID = (volumeID) ? volumeID + vsize : 0;
316 for (i = 0; i < NVOLS; i++) {
317 for (tv = afs_volumes[i]; tv; tv = tv->next) {
318 if (flags & AFS_VOLCHECK_EXPIRED) {
319 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
320 || (flags & AFS_VOLCHECK_FORCE)) {
321 afs_ResetVolumeInfo(tv); /* also resets status */
323 volumeID[nvols] = tv->volume;
324 cellID[nvols] = tv->cell;
331 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
332 for (j = 0; j < AFS_MAXHOSTS; j++)
333 tv->status[j] = not_busy;
338 ReleaseReadLock(&afs_xvolume);
341 /* next ensure all mt points are re-evaluated */
342 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
344 ObtainReadLock(&afs_xvcache);
345 for (i = 0; i < VCSIZE; i++) {
346 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
348 /* if the volume of "mvid" of the vcache entry is among the
349 * ones we found earlier, then we re-evaluate it. Also, if the
350 * force bit is set or we explicitly asked to reevaluate the
351 * mt-pts, we clean the cmvalid bit */
353 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
355 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
356 tvc->f.states &= ~CMValid;
358 /* If the volume that this file belongs to was reset earlier,
359 * then we should remove its callback.
360 * Again, if forced, always do it.
362 if ((tvc->f.states & CRO)
363 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
364 || (flags & AFS_VOLCHECK_FORCE))) {
366 if (tvc->f.states & CVInit) {
367 ReleaseReadLock(&afs_xvcache);
368 afs_osi_Sleep(&tvc->f.states);
371 #ifdef AFS_DARWIN80_ENV
372 if (tvc->f.states & CDeadVnode) {
373 ReleaseReadLock(&afs_xvcache);
374 afs_osi_Sleep(&tvc->f.states);
380 if (vnode_ref(tvp)) {
382 /* AFSTOV(tvc) may be NULL */
390 ReleaseReadLock(&afs_xvcache);
392 ObtainWriteLock(&afs_xcbhash, 485);
393 /* LOCKXXX: We aren't holding tvc write lock? */
394 afs_DequeueCallback(tvc);
395 tvc->f.states &= ~CStatd;
396 ReleaseWriteLock(&afs_xcbhash);
397 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
398 osi_dnlc_purgedp(tvc);
400 #ifdef AFS_DARWIN80_ENV
401 vnode_put(AFSTOV(tvc));
402 /* our tvc ptr is still good until now */
404 ObtainReadLock(&afs_xvcache);
406 ObtainReadLock(&afs_xvcache);
408 /* our tvc ptr is still good until now */
414 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
415 ReleaseReadLock(&afs_xvcache);
419 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
421 } /*afs_CheckVolumeNames */
425 * Check if volume is in the specified list.
426 * @param fid File FID.
427 * @param nvols Nomber of volumes???
428 * @param vID Array of volume IDs.
429 * @param cID Array of cache IDs.
430 * @return 1 - true, 0 - false.
433 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
438 /* if no arrays present, be conservative and return true */
439 if (nvols && (!vID || !cID))
442 for (i = 0; i < nvols; ++i) {
443 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
450 /* afs_PutVolume is now a macro in afs.h */
454 * Return volume struct if we have it cached and it's up-to-date.
455 * Environment: Must be called with afs_xvolume unlocked.
456 * @param afid Volume FID.
458 * @return Volume or NULL if no result.
461 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
469 i = VHash(afid->Fid.Volume);
470 ObtainWriteLock(&afs_xvolume, 106);
471 for (tv = afs_volumes[i]; tv; tv = tv->next) {
472 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
473 && (tv->states & VRecheck) == 0) {
478 ReleaseWriteLock(&afs_xvolume);
479 return tv; /* NULL if we didn't find it */
480 } /*afs_FindVolume */
485 * Note that areq may be null, in which case we don't bother to set any
486 * request status information.
487 * @param afid Volume FID.
488 * @param areq Request type.
489 * @param locktype Lock to be used.
490 * @return Volume or NULL if no result.
493 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
497 char *bp, tbuf[CVBS];
498 AFS_STATCNT(afs_GetVolume);
500 tv = afs_FindVolume(afid, locktype);
502 /* Do a dynroot check and add dynroot volume if found. */
503 if (afs_IsDynrootAnyFid(afid)) {
504 tv = afs_NewDynrootVolume(afid);
506 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
507 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
517 * @param volid Volume ID. If it's 0, get it from the name.
518 * @param aname Volume name.
519 * @param ve Volume entry.
520 * @param tcell The cell containing this volume.
522 * @param type Type of volume.
523 * @param areq Request.
524 * @return Volume or NULL if failure.
526 static struct volume *
527 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
528 afs_int32 agood, afs_int32 type, struct vrequest *areq)
531 struct vldbentry *ove = (struct vldbentry *)ve;
532 struct nvldbentry *nve = (struct nvldbentry *)ve;
533 struct uvldbentry *uve = (struct uvldbentry *)ve;
535 int whichType; /* which type of volume to look for */
540 /* special hint from file server to use vlserver */
542 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
544 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
549 /* figure out which one we're really interested in (a set is returned) */
550 volid = afs_vtoi(aname);
553 volid = uve->volumeId[whichType];
554 } else if (type == 1) {
555 volid = nve->volumeId[whichType];
557 volid = ove->volumeId[whichType];
559 } /* end of if (volid == 0) */
560 } /* end of if (!volid) */
563 ObtainWriteLock(&afs_xvolume, 108);
565 for (tv = afs_volumes[i]; tv; tv = tv->next) {
566 if (tv->volume == volid && tv->cell == tcell->cellNum) {
571 struct fvolume *tf = 0;
573 tv = afs_GetVolSlot();
575 ReleaseWriteLock(&afs_xvolume);
578 memset(tv, 0, sizeof(struct volume));
579 tv->cell = tcell->cellNum;
580 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
581 tv->next = afs_volumes[i]; /* thread into list */
584 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
585 if (afs_FVIndex != j) {
586 struct osi_file *tfile;
587 tfile = osi_UFSOpen(&volumeInode);
589 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
590 &staticFVolume, sizeof(struct fvolume));
591 if (err != sizeof(struct fvolume))
592 osi_Panic("read volumeinfo2");
597 if (tf->cell == tv->cell && tf->volume == volid)
600 if (tf && (j != 0)) {
601 tv->vtix = afs_FVIndex;
602 tv->mtpoint = tf->mtpoint;
603 tv->dotdot = tf->dotdot;
604 tv->rootVnode = tf->rootVnode;
605 tv->rootUnique = tf->rootUnique;
608 tv->rootVnode = tv->rootUnique = 0;
609 afs_GetDynrootMountFid(&tv->dotdot);
610 afs_GetDynrootMountFid(&tv->mtpoint);
611 tv->mtpoint.Fid.Vnode =
612 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
613 tv->mtpoint.Fid.Unique = volid;
617 tv->states &= ~VRecheck; /* just checked it */
618 tv->accessTime = osi_Time();
619 ReleaseWriteLock(&afs_xvolume);
620 ObtainWriteLock(&tv->lock, 111);
622 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
623 } else if (type == 1)
624 InstallNVolumeEntry(tv, nve, tcell->cellNum);
626 InstallVolumeEntry(tv, ove, tcell->cellNum);
629 tv->name = afs_osi_Alloc(strlen(aname) + 1);
630 strcpy(tv->name, aname);
633 for (i = 0; i < NMAXNSERVERS; i++) {
634 tv->status[i] = not_busy;
636 ReleaseWriteLock(&tv->lock);
642 * Seek volume by it's name and attributes.
643 * If volume not found, try to add one.
644 * @param aname Volume name.
648 * @param locktype Type of lock to be used.
652 afs_GetVolumeByName(register char *aname, afs_int32 acell, int agood,
653 struct vrequest *areq, afs_int32 locktype)
658 AFS_STATCNT(afs_GetVolumeByName);
659 ObtainWriteLock(&afs_xvolume, 112);
660 for (i = 0; i < NVOLS; i++) {
661 for (tv = afs_volumes[i]; tv; tv = tv->next) {
662 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
663 && (tv->states & VRecheck) == 0) {
665 ReleaseWriteLock(&afs_xvolume);
671 ReleaseWriteLock(&afs_xvolume);
673 if (AFS_IS_DISCONNECTED)
676 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
681 * Init a new dynroot volume.
683 * @return Volume or NULL if not found.
685 static struct volume *
686 afs_NewDynrootVolume(struct VenusFid *fid)
690 struct vldbentry *tve;
691 char *bp, tbuf[CVBS];
693 tcell = afs_GetCell(fid->Cell, READ_LOCK);
696 tve = afs_osi_Alloc(sizeof(*tve));
697 if (!(tcell->states & CHasVolRef))
698 tcell->states |= CHasVolRef;
700 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
701 memset(tve, 0, sizeof(*tve));
702 strcpy(tve->name, "local-dynroot");
703 tve->volumeId[ROVOL] = fid->Fid.Volume;
704 tve->flags = VLF_ROEXISTS;
706 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
707 afs_PutCell(tcell, READ_LOCK);
708 afs_osi_Free(tve, sizeof(*tve));
715 * @param aname Volume name.
716 * @param acell Cell id.
718 * @param areq Request type.
719 * @param locktype Type of lock to be used.
720 * @return Volume or NULL if failure.
722 static struct volume *
723 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
724 struct vrequest *areq, afs_int32 locktype)
726 afs_int32 code, type = 0;
727 struct volume *tv, *tv1;
728 struct vldbentry *tve;
729 struct nvldbentry *ntve;
730 struct uvldbentry *utve;
733 struct afs_conn *tconn;
734 struct vrequest treq;
736 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
739 tcell = afs_GetCell(acell, READ_LOCK);
744 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
749 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
750 ICL_TYPE_POINTER, aname);
751 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
752 tve = (struct vldbentry *)(tbuffer + 1024);
753 ntve = (struct nvldbentry *)tve;
754 utve = (struct uvldbentry *)tve;
755 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
758 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
761 if (tconn->srvr->server->flags & SNO_LHOSTS) {
764 code = VL_GetEntryByNameO(tconn->id, aname, tve);
766 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
769 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
774 code = VL_GetEntryByNameU(tconn->id, aname, utve);
776 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
777 if (code == RXGEN_OPCODE) {
780 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
782 if (code == RXGEN_OPCODE) {
784 tconn->srvr->server->flags |= SNO_LHOSTS;
786 code = VL_GetEntryByNameO(tconn->id, aname, tve);
789 tconn->srvr->server->flags |= SYES_LHOSTS;
791 tconn->srvr->server->flags |= SVLSRV_UUID;
797 } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */
798 SHARED_LOCK, tcell));
801 /* If the client has yet to contact this cell and contact failed due
802 * to network errors, mark the VLDB servers as back up.
803 * That the client tried and failed can be determined from the
804 * fact that there was a downtime incident, but CHasVolRef is not set.
806 /* RT 48959 - unclear if this should really go */
808 if (areq->networkError && !(tcell->states & CHasVolRef)) {
812 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
813 if ((sp = tcell->cellHosts[i]) == NULL)
815 for (sap = sp->addr; sap; sap = sap->next_sa)
816 afs_MarkServerUpOrDown(sap, 0);
820 afs_CopyError(&treq, areq);
821 osi_FreeLargeSpace(tbuffer);
822 afs_PutCell(tcell, READ_LOCK);
826 * Check to see if this cell has not yet referenced a volume. If
827 * it hasn't, it's just about to change its status, and we need to mark
828 * this fact down. Note that it is remotely possible that afs_SetupVolume
829 * could fail and we would still not have a volume reference.
831 if (!(tcell->states & CHasVolRef)) {
832 tcell->states |= CHasVolRef;
833 afs_stats_cmperf.numCellsContacted++;
835 /*First time a volume in this cell has been referenced */
842 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
843 if ((agood == 3) && tv && tv->backVol) {
845 * This means that very soon we'll ask for the BK volume so
846 * we'll prefetch it (well we did already.)
849 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, areq);
854 if ((agood >= 2) && tv && tv->roVol) {
856 * This means that very soon we'll ask for the RO volume so
857 * we'll prefetch it (well we did already.)
859 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
864 osi_FreeLargeSpace(tbuffer);
865 afs_PutCell(tcell, READ_LOCK);
868 } /*afs_NewVolumeByName */
873 * Call this with the volume structure locked; used for new-style vldb requests.
879 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
881 register struct server *ts;
887 AFS_STATCNT(InstallVolumeEntry);
889 /* Determine the type of volume we want */
890 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
892 } else if ((ve->flags & VLF_ROEXISTS)
893 && (av->volume == ve->volumeId[ROVOL])) {
896 } else if ((ve->flags & VLF_BACKEXISTS)
897 && (av->volume == ve->volumeId[BACKVOL])) {
898 /* backup always is on the same volume as parent */
900 av->states |= (VRO | VBackup);
902 mask = 0; /* Can't find volume in vldb entry */
905 /* fill in volume types */
906 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
907 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
908 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
910 if (ve->flags & VLF_DFSFILESET)
911 av->states |= VForeign;
913 cellp = afs_GetCell(acell, 0);
915 /* This volume, av, is locked. Zero out the serverHosts[] array
916 * so that if afs_GetServer() decides to replace the server
917 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
920 for (j = 0; j < AFS_MAXHOSTS; j++) {
921 av->serverHost[j] = 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,
934 av->serverHost[j] = ts;
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);
949 if (j < AFS_MAXHOSTS) {
950 av->serverHost[j++] = 0;
952 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
953 } /*InstallVolumeEntry */
957 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
959 register struct server *ts;
965 AFS_STATCNT(InstallVolumeEntry);
967 /* Determine type of volume we want */
968 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
970 } else if ((ve->flags & VLF_ROEXISTS)
971 && (av->volume == ve->volumeId[ROVOL])) {
974 } else if ((ve->flags & VLF_BACKEXISTS)
975 && (av->volume == ve->volumeId[BACKVOL])) {
976 /* backup always is on the same volume as parent */
978 av->states |= (VRO | VBackup);
980 mask = 0; /* Can't find volume in vldb entry */
983 /* fill in volume types */
984 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
985 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
986 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
988 if (ve->flags & VLF_DFSFILESET)
989 av->states |= VForeign;
991 cellp = afs_GetCell(acell, 0);
993 /* This volume, av, is locked. Zero out the serverHosts[] array
994 * so that if afs_GetServer() decides to replace the server
995 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
998 for (j = 0; j < AFS_MAXHOSTS; j++) {
999 av->serverHost[j] = 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,
1012 av->serverHost[j] = ts;
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);
1026 if (j < AFS_MAXHOSTS) {
1027 av->serverHost[j++] = 0;
1029 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1030 } /*InstallNVolumeEntry */
1034 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1035 struct cell *tcell, struct vrequest *areq)
1037 register struct server *ts;
1038 struct afs_conn *tconn;
1041 afs_uint32 serverid;
1045 AFS_STATCNT(InstallVolumeEntry);
1047 /* Determine type of volume we want */
1048 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1050 } else if ((ve->flags & VLF_ROEXISTS)
1051 && av->volume == ve->volumeId[ROVOL]) {
1054 } else if ((ve->flags & VLF_BACKEXISTS)
1055 && (av->volume == ve->volumeId[BACKVOL])) {
1056 /* backup always is on the same volume as parent */
1058 av->states |= (VRO | VBackup);
1060 mask = 0; /* Can't find volume in vldb entry */
1063 /* fill in volume types */
1064 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1065 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1066 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1068 if (ve->flags & VLF_DFSFILESET)
1069 av->states |= VForeign;
1071 cellp = afs_GetCell(acell, 0);
1073 /* This volume, av, is locked. Zero out the serverHosts[] array
1074 * so that if afs_GetServer() decides to replace the server
1075 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1078 for (j = 0; j < AFS_MAXHOSTS; j++) {
1079 av->serverHost[j] = 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] & VLSERVER_FLAG_UUID)) {
1094 /* The server has no uuid */
1095 serverid = htonl(ve->serverNumber[i].time_low);
1096 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
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;
1110 memset(&attrs, 0, sizeof(attrs));
1111 attrs.Mask = VLADDR_UUID;
1112 attrs.uuid = ve->serverNumber[i];
1113 memset(&uuid, 0, sizeof(uuid));
1114 memset(&addrs, 0, sizeof(addrs));
1117 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1118 tcell->cellNum, areq, SHARED_LOCK);
1122 VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique,
1129 /* Handle corrupt VLDB (defect 7393) */
1130 if (code == 0 && nentries == 0)
1133 } while (afs_Analyze
1134 (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1136 /* Better handing of such failures; for now we'll simply retry this call */
1137 areq->volumeError = 1;
1141 addrp = addrs.bulkaddrs_val;
1142 for (k = 0; k < nentries; k++) {
1143 addrp[k] = htonl(addrp[k]);
1145 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1146 WRITE_LOCK, &ve->serverNumber[i],
1147 ve->serverUnique[i]);
1148 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1151 av->serverHost[j] = ts;
1153 /* The cell field could be 0 if the server entry was created
1154 * first with the 'fs setserverprefs' call which doesn't set
1155 * the cell field. Thus if the afs_GetServer call above
1156 * follows later on it will find the server entry thus it will
1157 * simply return without setting any fields, so we set the
1158 * field ourselves below.
1162 afs_PutServer(ts, WRITE_LOCK);
1166 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1167 } /*InstallVolumeEntry */
1171 * Reset volume info for the specified volume strecture. Mark volume
1172 * to be rechecked next time.
1176 afs_ResetVolumeInfo(struct volume *tv)
1180 AFS_STATCNT(afs_ResetVolumeInfo);
1181 ObtainWriteLock(&tv->lock, 117);
1182 tv->states |= VRecheck;
1183 for (i = 0; i < AFS_MAXHOSTS; i++)
1184 tv->status[i] = not_busy;
1186 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1189 ReleaseWriteLock(&tv->lock);