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,
77 /* Convert a volume name to a #; return 0 if can't parse as a number */
79 afs_vtoi(register char *aname)
81 register afs_int32 temp;
84 AFS_STATCNT(afs_vtoi);
85 while ((tc = *aname++)) {
86 if (tc > '9' || tc < '0')
87 return 0; /* invalid name */
97 * All of the vol cache routines must be called with the afs_xvolume
98 * lock held in exclusive mode, since they use static variables.
99 * In addition, we don't want two people adding the same volume
103 static struct fvolume staticFVolume;
104 afs_int32 afs_FVIndex = -1;
106 /* UFS specific version of afs_GetVolSlot */
109 afs_UFSGetVolSlot(void)
111 register struct volume *tv, **lv;
112 struct osi_file *tfile;
113 register afs_int32 i, code;
115 struct volume *bestVp, **bestLp;
117 AFS_STATCNT(afs_UFSGetVolSlot);
118 if (!afs_freeVolList) {
120 bestTime = 0x7fffffff;
123 for (i = 0; i < NVOLS; i++) {
124 lv = &afs_volumes[i];
125 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
126 if (tv->refCount == 0) { /* is this one available? */
127 if (tv->accessTime < bestTime) { /* best one available? */
128 bestTime = tv->accessTime;
136 osi_Panic("getvolslot none");
140 afs_osi_Free(tv->name, strlen(tv->name) + 1);
142 /* now write out volume structure to file */
144 tv->vtix = afs_volCounter++;
145 /* now put on hash chain */
146 i = FVHash(tv->cell, tv->volume);
147 staticFVolume.next = fvTable[i];
148 fvTable[i] = tv->vtix;
151 * Haul the guy in from disk so we don't overwrite hash table
154 if (afs_FVIndex != tv->vtix) {
155 tfile = osi_UFSOpen(volumeInode);
157 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
158 &staticFVolume, sizeof(struct fvolume));
159 if (code != sizeof(struct fvolume))
160 osi_Panic("read volumeinfo");
162 afs_FVIndex = tv->vtix;
165 afs_FVIndex = tv->vtix;
166 staticFVolume.volume = tv->volume;
167 staticFVolume.cell = tv->cell;
168 staticFVolume.mtpoint = tv->mtpoint;
169 staticFVolume.dotdot = tv->dotdot;
170 staticFVolume.rootVnode = tv->rootVnode;
171 staticFVolume.rootUnique = tv->rootUnique;
172 tfile = osi_UFSOpen(volumeInode);
174 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
175 &staticFVolume, sizeof(struct fvolume));
176 if (code != sizeof(struct fvolume))
177 osi_Panic("write volumeinfo");
180 tv = afs_freeVolList;
181 afs_freeVolList = tv->next;
185 } /*afs_UFSGetVolSlot */
189 afs_MemGetVolSlot(void)
191 register struct volume *tv;
193 AFS_STATCNT(afs_MemGetVolSlot);
194 if (!afs_freeVolList) {
195 struct volume *newVp;
197 newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume));
200 afs_freeVolList = newVp;
202 tv = afs_freeVolList;
203 afs_freeVolList = tv->next;
206 } /*afs_MemGetVolSlot */
208 /* afs_ResetVolumes()
209 * Reset volume inforamation for all volume structs that
210 * point to a speicific server.
213 afs_ResetVolumes(struct server *srvp)
218 /* Find any volumes residing on this server and flush their state */
219 for (j = 0; j < NVOLS; j++) {
220 for (vp = afs_volumes[j]; vp; vp = vp->next) {
221 for (k = 0; k < MAXHOSTS; k++) {
222 if (!srvp || (vp->serverHost[k] == srvp)) {
223 vp->serverHost[k] = 0;
224 afs_ResetVolumeInfo(vp);
233 /* reset volume name to volume id mapping cache */
235 afs_CheckVolumeNames(int flags)
241 afs_int32 *volumeID, *cellID, vsize, nvols;
242 #ifdef AFS_DARWIN80_ENV
245 AFS_STATCNT(afs_CheckVolumeNames);
248 volumeID = cellID = NULL;
250 ObtainReadLock(&afs_xvolume);
251 if (flags & AFS_VOLCHECK_EXPIRED) {
253 * allocate space to hold the volumeIDs and cellIDs, only if
254 * we will be invalidating the mountpoints later on
256 for (i = 0; i < NVOLS; i++)
257 for (tv = afs_volumes[i]; tv; tv = tv->next)
260 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
261 cellID = (volumeID) ? volumeID + vsize : 0;
265 for (i = 0; i < NVOLS; i++) {
266 for (tv = afs_volumes[i]; tv; tv = tv->next) {
267 if (flags & AFS_VOLCHECK_EXPIRED) {
268 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
269 || (flags & AFS_VOLCHECK_FORCE)) {
270 afs_ResetVolumeInfo(tv); /* also resets status */
272 volumeID[nvols] = tv->volume;
273 cellID[nvols] = tv->cell;
279 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
280 for (j = 0; j < MAXHOSTS; j++)
281 tv->status[j] = not_busy;
286 ReleaseReadLock(&afs_xvolume);
289 /* next ensure all mt points are re-evaluated */
290 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
292 ObtainReadLock(&afs_xvcache);
293 for (i = 0; i < VCSIZE; i++) {
294 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
296 /* if the volume of "mvid" of the vcache entry is among the
297 * ones we found earlier, then we re-evaluate it. Also, if the
298 * force bit is set or we explicitly asked to reevaluate the
299 * mt-pts, we clean the cmvalid bit */
301 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
303 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
304 tvc->states &= ~CMValid;
306 /* If the volume that this file belongs to was reset earlier,
307 * then we should remove its callback.
308 * Again, if forced, always do it.
310 if ((tvc->states & CRO)
311 && (inVolList(&tvc->fid, nvols, volumeID, cellID)
312 || (flags & AFS_VOLCHECK_FORCE))) {
314 if (tvc->states & CVInit) {
315 ReleaseReadLock(&afs_xvcache);
316 afs_osi_Sleep(&tvc->states);
319 #ifdef AFS_DARWIN80_ENV
320 if (tvc->states & CDeadVnode) {
321 ReleaseReadLock(&afs_xvcache);
322 afs_osi_Sleep(&tvc->states);
328 if (vnode_ref(tvp)) {
330 /* AFSTOV(tvc) may be NULL */
338 ReleaseReadLock(&afs_xvcache);
340 ObtainWriteLock(&afs_xcbhash, 485);
341 /* LOCKXXX: We aren't holding tvc write lock? */
342 afs_DequeueCallback(tvc);
343 tvc->states &= ~CStatd;
344 ReleaseWriteLock(&afs_xcbhash);
345 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
346 osi_dnlc_purgedp(tvc);
348 #ifdef AFS_DARWIN80_ENV
349 vnode_put(AFSTOV(tvc));
350 /* our tvc ptr is still good until now */
352 ObtainReadLock(&afs_xvcache);
354 ObtainReadLock(&afs_xvcache);
356 /* our tvc ptr is still good until now */
362 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
363 ReleaseReadLock(&afs_xvcache);
367 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
369 } /*afs_CheckVolumeNames */
373 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
378 /* if no arrays present, be conservative and return true */
379 if (nvols && (!vID || !cID))
382 for (i = 0; i < nvols; ++i) {
383 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
390 /* afs_PutVolume is now a macro in afs.h */
394 * return volume struct if we have it cached and it's up-to-date
396 * Environment: Must be called with afs_xvolume unlocked.
399 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
407 i = VHash(afid->Fid.Volume);
408 ObtainWriteLock(&afs_xvolume, 106);
409 for (tv = afs_volumes[i]; tv; tv = tv->next) {
410 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
411 && (tv->states & VRecheck) == 0) {
416 ReleaseWriteLock(&afs_xvolume);
417 return tv; /* NULL if we didn't find it */
418 } /*afs_FindVolume */
423 * Note that areq may be null, in which case we don't bother to set any
424 * request status information.
427 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
431 char *bp, tbuf[CVBS];
432 AFS_STATCNT(afs_GetVolume);
434 tv = afs_FindVolume(afid, locktype);
436 if (afs_IsDynrootAnyFid(afid)) {
437 tv = afs_NewDynrootVolume(afid);
439 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
440 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
448 static struct volume *
449 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
450 afs_int32 agood, afs_int32 type, struct vrequest *areq)
453 struct vldbentry *ove = (struct vldbentry *)ve;
454 struct nvldbentry *nve = (struct nvldbentry *)ve;
455 struct uvldbentry *uve = (struct uvldbentry *)ve;
457 int whichType; /* which type of volume to look for */
462 /* special hint from file server to use vlserver */
464 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
466 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
471 /* figure out which one we're really interested in (a set is returned) */
472 volid = afs_vtoi(aname);
475 volid = uve->volumeId[whichType];
476 } else if (type == 1) {
477 volid = nve->volumeId[whichType];
479 volid = ove->volumeId[whichType];
485 ObtainWriteLock(&afs_xvolume, 108);
487 for (tv = afs_volumes[i]; tv; tv = tv->next) {
488 if (tv->volume == volid && tv->cell == tcell->cellNum) {
493 struct fvolume *tf = 0;
495 tv = afs_GetVolSlot();
496 memset((char *)tv, 0, sizeof(struct volume));
497 tv->cell = tcell->cellNum;
498 RWLOCK_INIT(&tv->lock, "volume lock");
499 tv->next = afs_volumes[i]; /* thread into list */
502 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
503 if (afs_FVIndex != j) {
504 struct osi_file *tfile;
505 tfile = osi_UFSOpen(volumeInode);
507 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
508 &staticFVolume, sizeof(struct fvolume));
509 if (err != sizeof(struct fvolume))
510 osi_Panic("read volumeinfo2");
515 if (tf->cell == tv->cell && tf->volume == volid)
518 if (tf && (j != 0)) {
519 tv->vtix = afs_FVIndex;
520 tv->mtpoint = tf->mtpoint;
521 tv->dotdot = tf->dotdot;
522 tv->rootVnode = tf->rootVnode;
523 tv->rootUnique = tf->rootUnique;
526 tv->rootVnode = tv->rootUnique = 0;
527 afs_GetDynrootMountFid(&tv->dotdot);
528 afs_GetDynrootMountFid(&tv->mtpoint);
529 tv->mtpoint.Fid.Vnode =
530 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
531 tv->mtpoint.Fid.Unique = volid;
535 tv->states &= ~VRecheck; /* just checked it */
536 tv->accessTime = osi_Time();
537 ReleaseWriteLock(&afs_xvolume);
538 ObtainWriteLock(&tv->lock, 111);
540 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
541 } else if (type == 1)
542 InstallNVolumeEntry(tv, nve, tcell->cellNum);
544 InstallVolumeEntry(tv, ove, tcell->cellNum);
547 tv->name = afs_osi_Alloc(strlen(aname) + 1);
548 strcpy(tv->name, aname);
551 for (i = 0; i < NMAXNSERVERS; i++) {
552 tv->status[i] = not_busy;
554 ReleaseWriteLock(&tv->lock);
560 afs_GetVolumeByName(register char *aname, afs_int32 acell, int agood,
561 struct vrequest *areq, afs_int32 locktype)
566 AFS_STATCNT(afs_GetVolumeByName);
567 ObtainWriteLock(&afs_xvolume, 112);
568 for (i = 0; i < NVOLS; i++) {
569 for (tv = afs_volumes[i]; tv; tv = tv->next) {
570 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
571 && (tv->states & VRecheck) == 0) {
573 ReleaseWriteLock(&afs_xvolume);
579 ReleaseWriteLock(&afs_xvolume);
581 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
585 static struct volume *
586 afs_NewDynrootVolume(struct VenusFid *fid)
590 struct vldbentry *tve;
591 char *bp, tbuf[CVBS];
593 tcell = afs_GetCell(fid->Cell, READ_LOCK);
596 tve = afs_osi_Alloc(sizeof(*tve));
597 if (!(tcell->states & CHasVolRef))
598 tcell->states |= CHasVolRef;
600 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
601 memset(tve, 0, sizeof(*tve));
602 strcpy(tve->name, "local-dynroot");
603 tve->volumeId[ROVOL] = fid->Fid.Volume;
604 tve->flags = VLF_ROEXISTS;
606 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
607 afs_PutCell(tcell, READ_LOCK);
608 afs_osi_Free(tve, sizeof(*tve));
613 static struct volume *
614 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
615 struct vrequest *areq, afs_int32 locktype)
617 afs_int32 code, type = 0;
618 struct volume *tv, *tv1;
619 struct vldbentry *tve;
620 struct nvldbentry *ntve;
621 struct uvldbentry *utve;
625 struct vrequest treq;
627 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
630 tcell = afs_GetCell(acell, READ_LOCK);
635 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
640 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
641 ICL_TYPE_POINTER, aname);
642 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
643 tve = (struct vldbentry *)(tbuffer + 1024);
644 ntve = (struct nvldbentry *)tve;
645 utve = (struct uvldbentry *)tve;
646 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
649 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
652 if (tconn->srvr->server->flags & SNO_LHOSTS) {
655 code = VL_GetEntryByNameO(tconn->id, aname, tve);
657 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
660 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
665 code = VL_GetEntryByNameU(tconn->id, aname, utve);
667 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
668 if (code == RXGEN_OPCODE) {
671 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
673 if (code == RXGEN_OPCODE) {
675 tconn->srvr->server->flags |= SNO_LHOSTS;
677 code = VL_GetEntryByNameO(tconn->id, aname, tve);
680 tconn->srvr->server->flags |= SYES_LHOSTS;
682 tconn->srvr->server->flags |= SVLSRV_UUID;
688 } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */
689 SHARED_LOCK, tcell));
692 /* If the client has yet to contact this cell and contact failed due
693 * to network errors, mark the VLDB servers as back up.
694 * That the client tried and failed can be determined from the
695 * fact that there was a downtime incident, but CHasVolRef is not set.
697 /* RT 48959 - unclear if this should really go */
699 if (areq->networkError && !(tcell->states & CHasVolRef)) {
703 for (i = 0; i < MAXCELLHOSTS; i++) {
704 if ((sp = tcell->cellHosts[i]) == NULL)
706 for (sap = sp->addr; sap; sap = sap->next_sa)
707 afs_MarkServerUpOrDown(sap, 0);
711 afs_CopyError(&treq, areq);
712 osi_FreeLargeSpace(tbuffer);
713 afs_PutCell(tcell, READ_LOCK);
717 * Check to see if this cell has not yet referenced a volume. If
718 * it hasn't, it's just about to change its status, and we need to mark
719 * this fact down. Note that it is remotely possible that afs_SetupVolume
720 * could fail and we would still not have a volume reference.
722 if (!(tcell->states & CHasVolRef)) {
723 tcell->states |= CHasVolRef;
724 afs_stats_cmperf.numCellsContacted++;
726 /*First time a volume in this cell has been referenced */
733 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
734 if ((agood == 3) && tv->backVol) {
736 * This means that very soon we'll ask for the BK volume so
737 * we'll prefetch it (well we did already.)
740 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, areq);
743 if ((agood >= 2) && tv->roVol) {
745 * This means that very soon we'll ask for the RO volume so
746 * we'll prefetch it (well we did already.)
748 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
751 osi_FreeLargeSpace(tbuffer);
752 afs_PutCell(tcell, READ_LOCK);
755 } /*afs_NewVolumeByName */
759 /* call this with the volume structure locked; used for new-style vldb requests */
761 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
763 register struct server *ts;
769 AFS_STATCNT(InstallVolumeEntry);
771 /* Determine the type of volume we want */
772 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
774 } else if ((ve->flags & VLF_ROEXISTS)
775 && (av->volume == ve->volumeId[ROVOL])) {
778 } else if ((ve->flags & VLF_BACKEXISTS)
779 && (av->volume == ve->volumeId[BACKVOL])) {
780 /* backup always is on the same volume as parent */
782 av->states |= (VRO | VBackup);
784 mask = 0; /* Can't find volume in vldb entry */
787 /* fill in volume types */
788 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
789 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
790 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
792 if (ve->flags & VLF_DFSFILESET)
793 av->states |= VForeign;
795 cellp = afs_GetCell(acell, 0);
797 /* This volume, av, is locked. Zero out the serverHosts[] array
798 * so that if afs_GetServer() decides to replace the server
799 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
802 for (j = 0; j < MAXHOSTS; j++) {
803 av->serverHost[j] = 0;
806 /* Step through the VLDB entry making sure each server listed is there */
807 for (i = 0, j = 0; i < ve->nServers; i++) {
808 if (((ve->serverFlags[i] & mask) == 0)
809 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
810 continue; /* wrong volume or don't use this volume */
813 temp = htonl(ve->serverNumber[i]);
814 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
816 av->serverHost[j] = ts;
819 * The cell field could be 0 if the server entry was created
820 * first with the 'fs setserverprefs' call which doesn't set
821 * the cell field. Thus if the afs_GetServer call above
822 * follows later on it will find the server entry thus it will
823 * simply return without setting any fields, so we set the
824 * field ourselves below.
828 afs_PutServer(ts, WRITE_LOCK);
832 av->serverHost[j++] = 0;
834 afs_SortServers(av->serverHost, MAXHOSTS);
835 } /*InstallVolumeEntry */
839 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
841 register struct server *ts;
847 AFS_STATCNT(InstallVolumeEntry);
849 /* Determine type of volume we want */
850 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
852 } else if ((ve->flags & VLF_ROEXISTS)
853 && (av->volume == ve->volumeId[ROVOL])) {
856 } else if ((ve->flags & VLF_BACKEXISTS)
857 && (av->volume == ve->volumeId[BACKVOL])) {
858 /* backup always is on the same volume as parent */
860 av->states |= (VRO | VBackup);
862 mask = 0; /* Can't find volume in vldb entry */
865 /* fill in volume types */
866 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
867 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
868 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
870 if (ve->flags & VLF_DFSFILESET)
871 av->states |= VForeign;
873 cellp = afs_GetCell(acell, 0);
875 /* This volume, av, is locked. Zero out the serverHosts[] array
876 * so that if afs_GetServer() decides to replace the server
877 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
880 for (j = 0; j < MAXHOSTS; j++) {
881 av->serverHost[j] = 0;
884 /* Step through the VLDB entry making sure each server listed is there */
885 for (i = 0, j = 0; i < ve->nServers; i++) {
886 if (((ve->serverFlags[i] & mask) == 0)
887 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
888 continue; /* wrong volume or don't use this volume */
891 temp = htonl(ve->serverNumber[i]);
892 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
894 av->serverHost[j] = ts;
896 * The cell field could be 0 if the server entry was created
897 * first with the 'fs setserverprefs' call which doesn't set
898 * the cell field. Thus if the afs_GetServer call above
899 * follows later on it will find the server entry thus it will
900 * simply return without setting any fields, so we set the
901 * field ourselves below.
905 afs_PutServer(ts, WRITE_LOCK);
909 av->serverHost[j++] = 0;
911 afs_SortServers(av->serverHost, MAXHOSTS);
912 } /*InstallNVolumeEntry */
916 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
917 struct cell *tcell, struct vrequest *areq)
919 register struct server *ts;
927 AFS_STATCNT(InstallVolumeEntry);
929 /* Determine type of volume we want */
930 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
932 } else if ((ve->flags & VLF_ROEXISTS)
933 && av->volume == ve->volumeId[ROVOL]) {
936 } else if ((ve->flags & VLF_BACKEXISTS)
937 && (av->volume == ve->volumeId[BACKVOL])) {
938 /* backup always is on the same volume as parent */
940 av->states |= (VRO | VBackup);
942 mask = 0; /* Can't find volume in vldb entry */
945 /* fill in volume types */
946 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
947 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
948 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
950 if (ve->flags & VLF_DFSFILESET)
951 av->states |= VForeign;
953 cellp = afs_GetCell(acell, 0);
955 /* This volume, av, is locked. Zero out the serverHosts[] array
956 * so that if afs_GetServer() decides to replace the server
957 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
960 for (j = 0; j < MAXHOSTS; j++) {
961 av->serverHost[j] = 0;
964 /* Gather the list of servers the VLDB says the volume is on
965 * and initialize the ve->serverHost[] array. If a server struct
966 * is not found, then get the list of addresses for the
967 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
969 for (i = 0, j = 0; i < ve->nServers; i++) {
970 if (((ve->serverFlags[i] & mask) == 0)
971 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
972 continue; /* wrong volume don't use this volume */
975 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
976 /* The server has no uuid */
977 serverid = htonl(ve->serverNumber[i].time_low);
978 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
981 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
982 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
984 /* uuid, uniquifier, and portal are the same */
986 afs_uint32 *addrp, nentries, code, unique;
988 ListAddrByAttributes attrs;
991 memset((char *)&attrs, 0, sizeof(attrs));
992 attrs.Mask = VLADDR_UUID;
993 attrs.uuid = ve->serverNumber[i];
994 memset((char *)&uuid, 0, sizeof(uuid));
995 memset((char *)&addrs, 0, sizeof(addrs));
998 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
999 tcell->cellNum, areq, SHARED_LOCK);
1003 VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique,
1010 /* Handle corrupt VLDB (defect 7393) */
1011 if (code == 0 && nentries == 0)
1014 } while (afs_Analyze
1015 (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1017 /* Better handing of such failures; for now we'll simply retry this call */
1018 areq->volumeError = 1;
1022 addrp = addrs.bulkaddrs_val;
1023 for (k = 0; k < nentries; k++) {
1024 addrp[k] = htonl(addrp[k]);
1026 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1027 WRITE_LOCK, &ve->serverNumber[i],
1028 ve->serverUnique[i]);
1029 afs_osi_Free(addrs.bulkaddrs_val,
1030 addrs.bulkaddrs_len * sizeof(*addrp));
1033 av->serverHost[j] = ts;
1035 /* The cell field could be 0 if the server entry was created
1036 * first with the 'fs setserverprefs' call which doesn't set
1037 * the cell field. Thus if the afs_GetServer call above
1038 * follows later on it will find the server entry thus it will
1039 * simply return without setting any fields, so we set the
1040 * field ourselves below.
1044 afs_PutServer(ts, WRITE_LOCK);
1048 afs_SortServers(av->serverHost, MAXHOSTS);
1049 } /*InstallVolumeEntry */
1053 afs_ResetVolumeInfo(struct volume *tv)
1057 AFS_STATCNT(afs_ResetVolumeInfo);
1058 ObtainWriteLock(&tv->lock, 117);
1059 tv->states |= VRecheck;
1060 for (i = 0; i < MAXHOSTS; i++)
1061 tv->status[i] = not_busy;
1063 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1066 ReleaseWriteLock(&tv->lock);