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"
24 #include "afs/sysincludes.h" /* Standard vendor system headers */
28 #include <netinet/in.h>
31 #include "h/hashing.h"
33 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV)
34 #include <netinet/in_var.h>
35 #endif /* ! AFS_HPUX110_ENV */
36 #endif /* !defined(UKERNEL) */
38 #include "afsincludes.h" /* Afs-based standard headers */
39 #include "afs/afs_stats.h" /* afs statistics */
41 #if defined(AFS_SUN56_ENV)
43 #include <inet/common.h>
44 #if defined(AFS_SUN58_ENV)
45 #include <netinet/ip6.h>
50 /* In case we don't have the vl error table yet. */
51 #ifndef ERROR_TABLE_BASE_VL
52 #define ERROR_TABLE_BASE_VL (363520L)
53 #define VL_NOENT (363524L)
54 #endif /* vlserver error base define */
56 /* Exported variables */
57 ino_t volumeInode; /*Inode for VolumeItems file*/
58 afs_rwlock_t afs_xvolume; /* allocation lock for volumes */
59 struct volume *afs_freeVolList;
60 struct volume *afs_volumes[NVOLS];
61 afs_int32 afs_volCounter = 1; /* for allocating volume indices */
62 afs_int32 fvTable[NFENTRIES];
64 /* Forward declarations */
65 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
66 struct vrequest *areq, afs_int32 locktype);
67 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
68 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 *vID, afs_int32 *cID);
71 /* Convert a volume name to a #; return 0 if can't parse as a number */
72 static int afs_vtoi(register char *aname)
74 register afs_int32 temp;
77 AFS_STATCNT(afs_vtoi);
78 while((tc = *aname++)) {
79 if (tc > '9' || tc < '0')
80 return 0; /* invalid name */
90 * All of the vol cache routines must be called with the afs_xvolume
91 * lock held in exclusive mode, since they use static variables.
92 * In addition, we don't want two people adding the same volume
96 static struct fvolume staticFVolume;
97 afs_int32 afs_FVIndex = -1;
99 /* UFS specific version of afs_GetVolSlot */
101 struct volume *afs_UFSGetVolSlot(void)
103 register struct volume *tv, **lv;
104 struct osi_file *tfile;
105 register afs_int32 i, code;
107 struct volume *bestVp, **bestLp;
109 AFS_STATCNT(afs_UFSGetVolSlot);
110 if (!afs_freeVolList) {
112 bestTime = 0x7fffffff;
115 for (i=0;i<NVOLS;i++) {
116 lv = &afs_volumes[i];
117 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
118 if (tv->refCount == 0) { /* is this one available? */
119 if (tv->accessTime < bestTime) { /* best one available? */
120 bestTime = tv->accessTime;
128 osi_Panic("getvolslot none");
132 afs_osi_Free(tv->name, strlen(tv->name)+1);
134 /* now write out volume structure to file */
136 tv->vtix = afs_volCounter++;
137 /* now put on hash chain */
138 i = FVHash(tv->cell, tv->volume);
139 staticFVolume.next = fvTable[i];
144 * Haul the guy in from disk so we don't overwrite hash table
147 if (afs_FVIndex != tv->vtix) {
148 tfile = osi_UFSOpen(volumeInode);
149 code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
150 &staticFVolume, sizeof(struct fvolume));
151 if (code != sizeof(struct fvolume))
152 osi_Panic("read volumeinfo");
154 afs_FVIndex = tv->vtix;
157 afs_FVIndex = tv->vtix;
158 staticFVolume.volume = tv->volume;
159 staticFVolume.cell = tv->cell;
160 staticFVolume.mtpoint = tv->mtpoint;
161 staticFVolume.dotdot = tv->dotdot;
162 staticFVolume.rootVnode = tv->rootVnode;
163 staticFVolume.rootUnique = tv->rootUnique;
164 tfile = osi_UFSOpen(volumeInode);
165 code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
166 &staticFVolume, sizeof(struct fvolume));
167 if (code != sizeof(struct fvolume))
168 osi_Panic("write volumeinfo");
172 tv = afs_freeVolList;
173 afs_freeVolList = tv->next;
177 } /*afs_UFSGetVolSlot*/
180 struct volume *afs_MemGetVolSlot(void)
182 register struct volume *tv;
184 AFS_STATCNT(afs_MemGetVolSlot);
185 if (!afs_freeVolList) {
186 struct volume *newVp;
188 newVp = (struct volume *) afs_osi_Alloc(sizeof(struct volume));
191 afs_freeVolList = newVp;
193 tv = afs_freeVolList;
194 afs_freeVolList = tv->next;
197 } /*afs_MemGetVolSlot*/
199 /* afs_ResetVolumes()
200 * Reset volume inforamation for all volume structs that
201 * point to a speicific server.
203 void afs_ResetVolumes(struct server *srvp)
208 /* Find any volumes residing on this server and flush their state */
209 for (j=0; j<NVOLS; j++) {
210 for (vp=afs_volumes[j]; vp; vp=vp->next) {
211 for (k=0; k<MAXHOSTS; k++) {
212 if (!srvp || (vp->serverHost[k] == srvp)) {
213 vp->serverHost[k] = 0;
214 afs_ResetVolumeInfo(vp);
223 /* reset volume name to volume id mapping cache */
224 void afs_CheckVolumeNames(int flags)
230 afs_int32 *volumeID, *cellID, vsize, nvols;
231 AFS_STATCNT(afs_CheckVolumeNames);
234 volumeID = cellID = NULL;
236 ObtainReadLock(&afs_xvolume);
237 if (flags & AFS_VOLCHECK_EXPIRED) {
239 * allocate space to hold the volumeIDs and cellIDs, only if
240 * we will be invalidating the mountpoints later on
242 for (i=0; i< NVOLS; i++)
243 for (tv = afs_volumes[i]; tv; tv=tv->next)
246 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
247 cellID = (volumeID) ? volumeID + vsize : 0;
251 for (i=0;i<NVOLS;i++) {
252 for (tv = afs_volumes[i]; tv; tv=tv->next) {
253 if (flags & AFS_VOLCHECK_EXPIRED) {
254 if ( ((tv->expireTime<(now+10)) && (tv->states & VRO)) ||
255 (flags & AFS_VOLCHECK_FORCE)){
256 afs_ResetVolumeInfo(tv); /* also resets status */
258 volumeID[nvols] = tv->volume;
259 cellID[nvols] = tv->cell;
265 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
266 for (j=0; j<MAXHOSTS; j++)
267 tv->status[j] = not_busy;
272 ReleaseReadLock(&afs_xvolume);
275 /* next ensure all mt points are re-evaluated */
276 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
277 ObtainReadLock(&afs_xvcache);
278 for(i=0;i<VCSIZE;i++) {
279 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
281 /* if the volume of "mvid" of the vcache entry is among the
282 * ones we found earlier, then we re-evaluate it. Also, if the
283 * force bit is set or we explicitly asked to reevaluate the
284 * mt-pts, we clean the cmvalid bit */
286 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS)) ||
288 inVolList(tvc->mvid, nvols, volumeID, cellID)))
289 tvc->states &= ~CMValid;
291 /* If the volume that this file belongs to was reset earlier,
292 * then we should remove its callback.
293 * Again, if forced, always do it.
295 if ((tvc->states & CRO) &&
296 (inVolList(&tvc->fid, nvols, volumeID, cellID) ||
297 (flags & AFS_VOLCHECK_FORCE))) {
300 ReleaseReadLock(&afs_xvcache);
302 ObtainWriteLock(&afs_xcbhash, 485);
303 /* LOCKXXX: We aren't holding tvc write lock? */
304 afs_DequeueCallback(tvc);
305 tvc->states &= ~CStatd;
306 ReleaseWriteLock(&afs_xcbhash);
307 if (tvc->fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
308 osi_dnlc_purgedp(tvc);
310 ObtainReadLock(&afs_xvcache);
312 /* our tvc ptr is still good until now */
317 osi_dnlc_purge (); /* definitely overkill, but it's safer this way. */
318 ReleaseReadLock(&afs_xvcache);
322 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
324 } /*afs_CheckVolumeNames*/
327 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 *vID, afs_int32 *cID)
331 /* if no arrays present, be conservative and return true */
332 if ( nvols && (!vID || !cID))
335 for (i=0; i< nvols; ++i) {
336 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
343 /* afs_PutVolume is now a macro in afs.h */
347 * return volume struct if we have it cached and it's up-to-date
349 * Environment: Must be called with afs_xvolume unlocked.
351 struct volume *afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
359 i = VHash(afid->Fid.Volume);
360 ObtainWriteLock(&afs_xvolume,106);
361 for (tv = afs_volumes[i]; tv; tv=tv->next) {
362 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
363 && (tv->states & VRecheck) == 0) {
368 ReleaseWriteLock(&afs_xvolume);
369 return tv; /* NULL if we didn't find it */
375 * Note that areq may be null, in which case we don't bother to set any
376 * request status information.
378 struct volume *afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
382 char *bp, tbuf[CVBS];
383 AFS_STATCNT(afs_GetVolume);
385 tv = afs_FindVolume(afid, locktype);
387 if (afs_IsDynrootFid(afid)) {
388 tv = afs_NewDynrootVolume(afid);
390 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
391 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
399 static struct volume *afs_SetupVolume(afs_int32 volid, char *aname,
400 char *ve, struct cell *tcell, afs_int32 agood, afs_int32 type, struct vrequest *areq)
403 struct vldbentry *ove = (struct vldbentry *)ve;
404 struct nvldbentry *nve = (struct nvldbentry *)ve;
405 struct uvldbentry *uve = (struct uvldbentry *)ve;
407 int whichType; /* which type of volume to look for */
412 /* special hint from file server to use vlserver */
414 if (len >= 8 && strcmp(aname+len-7, ".backup") == 0)
416 else if (len >= 10 && strcmp(aname+len-9, ".readonly")==0)
421 /* figure out which one we're really interested in (a set is returned) */
422 volid = afs_vtoi(aname);
425 volid = uve->volumeId[whichType];
427 else if (type == 1) {
428 volid = nve->volumeId[whichType];
431 volid = ove->volumeId[whichType];
437 ObtainWriteLock(&afs_xvolume,108);
439 for (tv = afs_volumes[i]; tv; tv=tv->next) {
440 if (tv->volume == volid && tv->cell == tcell->cellNum) {
445 struct fvolume *tf=0;
447 tv = afs_GetVolSlot();
448 memset((char *)tv, 0, sizeof(struct volume));
449 tv->cell = tcell->cellNum;
450 RWLOCK_INIT(&tv->lock, "volume lock");
451 tv->next = afs_volumes[i]; /* thread into list */
454 for (j=fvTable[FVHash(tv->cell,volid)]; j!=0; j=tf->next) {
455 if (afs_FVIndex != j) {
456 struct osi_file *tfile;
457 tfile = osi_UFSOpen(volumeInode);
458 err = afs_osi_Read(tfile, sizeof(struct fvolume) * j, &staticFVolume, sizeof(struct fvolume));
459 if (err != sizeof(struct fvolume))
460 osi_Panic("read volumeinfo2");
465 if (tf->cell == tv->cell && tf->volume == volid)
468 if (tf && (j != 0)) {
469 tv->vtix = afs_FVIndex;
470 tv->mtpoint = tf->mtpoint;
471 tv->dotdot = tf->dotdot;
472 tv->rootVnode = tf->rootVnode;
473 tv->rootUnique = tf->rootUnique;
476 tv->rootVnode = tv->rootUnique = 0;
480 tv->states &= ~VRecheck; /* just checked it */
481 tv->accessTime = osi_Time();
482 ReleaseWriteLock(&afs_xvolume);
483 ObtainWriteLock(&tv->lock,111);
485 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
488 InstallNVolumeEntry(tv, nve, tcell->cellNum);
490 InstallVolumeEntry(tv, ove, tcell->cellNum);
493 tv->name = afs_osi_Alloc(strlen(aname) + 1);
494 strcpy(tv->name, aname);
497 for (i=0; i<NMAXNSERVERS; i++) {
498 tv->status[i] = not_busy;
500 ReleaseWriteLock(&tv->lock);
505 struct volume *afs_GetVolumeByName(register char *aname, afs_int32 acell,
506 int agood, struct vrequest *areq, afs_int32 locktype)
511 AFS_STATCNT(afs_GetVolumeByName);
512 ObtainWriteLock(&afs_xvolume,112);
513 for (i=0;i<NVOLS;i++) {
514 for (tv = afs_volumes[i]; tv; tv=tv->next) {
515 if (tv->name && !strcmp(aname,tv->name) && tv->cell == acell
516 && (tv->states&VRecheck) == 0) {
518 ReleaseWriteLock(&afs_xvolume);
524 ReleaseWriteLock(&afs_xvolume);
526 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
530 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid)
534 struct vldbentry tve;
535 char *bp, tbuf[CVBS];
537 tcell = afs_GetCell(fid->Cell, READ_LOCK);
540 if (!(tcell->states & CHasVolRef))
541 tcell->states |= CHasVolRef;
543 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
544 memset(&tve, 0, sizeof(tve));
545 strcpy(tve.name, "local-dynroot");
546 tve.volumeId[ROVOL] = fid->Fid.Volume;
547 tve.flags = VLF_ROEXISTS;
549 tv = afs_SetupVolume(0, bp, (char *) &tve, tcell, 0, 0, 0);
550 afs_PutCell(tcell, READ_LOCK);
555 static struct volume *afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
556 struct vrequest *areq, afs_int32 locktype)
558 afs_int32 code, type=0;
559 struct volume *tv, *tv1;
560 struct vldbentry *tve;
561 struct nvldbentry *ntve;
562 struct uvldbentry *utve;
566 struct vrequest treq;
568 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
571 tcell = afs_GetCell(acell, READ_LOCK);
576 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
577 if (!areq) areq = &treq;
580 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
581 ICL_TYPE_POINTER, aname);
582 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
583 tve = (struct vldbentry *) (tbuffer+1024);
584 ntve = (struct nvldbentry *)tve;
585 utve = (struct uvldbentry *)tve;
586 afs_InitReq(&treq, &afs_osi_cred); /* *must* be unauth for vldb */
588 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
589 tcell->cellNum, &treq, SHARED_LOCK);
591 if (tconn->srvr->server->flags & SNO_LHOSTS) {
594 code = VL_GetEntryByNameO(tconn->id, aname, tve);
596 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
599 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
604 code = VL_GetEntryByNameU(tconn->id, aname, utve);
606 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
607 if (code == RXGEN_OPCODE) {
610 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
612 if (code == RXGEN_OPCODE) {
614 tconn->srvr->server->flags |= SNO_LHOSTS;
616 code = VL_GetEntryByNameO(tconn->id, aname, tve);
619 tconn->srvr->server->flags |= SYES_LHOSTS;
621 tconn->srvr->server->flags |= SVLSRV_UUID;
628 (afs_Analyze(tconn, code, NULL, &treq,
629 -1, /* no op code for this */
630 SHARED_LOCK, tcell));
633 /* If the client has yet to contact this cell and contact failed due
634 * to network errors, mark the VLDB servers as back up.
635 * That the client tried and failed can be determined from the
636 * fact that there was a downtime incident, but CHasVolRef is not set.
638 if (areq->networkError && !(tcell->states & CHasVolRef)) {
642 for (i=0; i<MAXCELLHOSTS; i++) {
643 if ((sp = tcell->cellHosts[i]) == NULL) break;
644 for (sap = sp->addr; sap; sap = sap->next_sa)
645 afs_MarkServerUpOrDown(sap, 0);
648 afs_CopyError(&treq, areq);
649 osi_FreeLargeSpace(tbuffer);
650 afs_PutCell(tcell, READ_LOCK);
654 * Check to see if this cell has not yet referenced a volume. If
655 * it hasn't, it's just about to change its status, and we need to mark
656 * this fact down. Note that it is remotely possible that afs_SetupVolume
657 * could fail and we would still not have a volume reference.
659 if (!(tcell->states & CHasVolRef)) {
660 tcell->states |= CHasVolRef;
661 afs_stats_cmperf.numCellsContacted++;
662 } /*First time a volume in this cell has been referenced*/
670 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
671 if ((agood == 2) && tv->roVol) {
673 * This means that very soon we'll ask for the RO volume so
674 * we'll prefetch it (well we did already.)
676 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
679 osi_FreeLargeSpace(tbuffer);
680 afs_PutCell(tcell, READ_LOCK);
683 } /*afs_NewVolumeByName*/
687 /* call this with the volume structure locked; used for new-style vldb requests */
688 void InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
690 register struct server *ts;
696 AFS_STATCNT(InstallVolumeEntry);
698 /* Determine the type of volume we want */
699 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
702 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
706 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
707 /* backup always is on the same volume as parent */
709 av->states |= (VRO|VBackup);
712 mask = 0; /* Can't find volume in vldb entry */
715 /* fill in volume types */
716 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
717 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
718 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
720 if (ve->flags & VLF_DFSFILESET)
721 av->states |= VForeign;
723 cellp = afs_GetCell(acell, 0);
725 /* This volume, av, is locked. Zero out the serverHosts[] array
726 * so that if afs_GetServer() decides to replace the server
727 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
730 for (j=0; j<MAXHOSTS; j++) {
731 av->serverHost[j] = 0;
734 /* Step through the VLDB entry making sure each server listed is there */
735 for (i=0,j=0; i<ve->nServers; i++) {
736 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
737 continue; /* wrong volume or don't use this volume */
740 temp = htonl(ve->serverNumber[i]);
741 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0, 0);
742 av->serverHost[j] = ts;
745 * The cell field could be 0 if the server entry was created
746 * first with the 'fs setserverprefs' call which doesn't set
747 * the cell field. Thus if the afs_GetServer call above
748 * follows later on it will find the server entry thus it will
749 * simply return without setting any fields, so we set the
750 * field ourselves below.
754 afs_PutServer(ts, WRITE_LOCK);
758 av->serverHost[j++] = 0;
760 afs_SortServers(av->serverHost, MAXHOSTS);
761 } /*InstallVolumeEntry*/
764 void InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
766 register struct server *ts;
772 AFS_STATCNT(InstallVolumeEntry);
774 /* Determine type of volume we want */
775 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
778 else if ((ve->flags & VLF_ROEXISTS) && (av->volume == ve->volumeId[ROVOL])) {
782 else if ((ve->flags&VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
783 /* backup always is on the same volume as parent */
785 av->states |= (VRO|VBackup);
788 mask = 0; /* Can't find volume in vldb entry */
791 /* fill in volume types */
792 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
793 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
794 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
796 if (ve->flags & VLF_DFSFILESET)
797 av->states |= VForeign;
799 cellp = afs_GetCell(acell, 0);
801 /* This volume, av, is locked. Zero out the serverHosts[] array
802 * so that if afs_GetServer() decides to replace the server
803 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
806 for (j=0; j<MAXHOSTS; j++) {
807 av->serverHost[j] = 0;
810 /* Step through the VLDB entry making sure each server listed is there */
811 for (i=0,j=0; i<ve->nServers; i++) {
812 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
813 continue; /* wrong volume or don't use this volume */
816 temp = htonl(ve->serverNumber[i]);
817 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
818 av->serverHost[j] = ts;
820 * The cell field could be 0 if the server entry was created
821 * first with the 'fs setserverprefs' call which doesn't set
822 * the cell field. Thus if the afs_GetServer call above
823 * follows later on it will find the server entry thus it will
824 * simply return without setting any fields, so we set the
825 * field ourselves below.
829 afs_PutServer(ts, WRITE_LOCK);
833 av->serverHost[j++] = 0;
835 afs_SortServers(av->serverHost, MAXHOSTS);
836 } /*InstallNVolumeEntry*/
839 void InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve,
840 int acell, struct cell *tcell, struct vrequest *areq)
842 register struct server *ts;
850 AFS_STATCNT(InstallVolumeEntry);
852 /* Determine type of volume we want */
853 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
856 else if ((ve->flags & VLF_ROEXISTS) && av->volume == ve->volumeId[ROVOL]) {
860 else if ((ve->flags & VLF_BACKEXISTS) && (av->volume == ve->volumeId[BACKVOL])) {
861 /* backup always is on the same volume as parent */
863 av->states |= (VRO|VBackup);
866 mask = 0; /* Can't find volume in vldb entry */
869 /* fill in volume types */
870 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
871 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
872 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
874 if (ve->flags & VLF_DFSFILESET)
875 av->states |= VForeign;
877 cellp = afs_GetCell(acell, 0);
879 /* This volume, av, is locked. Zero out the serverHosts[] array
880 * so that if afs_GetServer() decides to replace the server
881 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
884 for (j=0; j<MAXHOSTS; j++) {
885 av->serverHost[j] = 0;
888 /* Gather the list of servers the VLDB says the volume is on
889 * and initialize the ve->serverHost[] array. If a server struct
890 * is not found, then get the list of addresses for the
891 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
893 for (i=0,j=0; i<ve->nServers; i++) {
894 if ( ((ve->serverFlags[i] & mask) == 0) || (ve->serverFlags[i] & VLSF_DONTUSE) ) {
895 continue; /* wrong volume don't use this volume */
898 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
899 /* The server has no uuid */
900 serverid = htonl(ve->serverNumber[i].time_low);
901 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK, (afsUUID *)0,0);
903 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
904 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i]) && ts->addr) {
905 /* uuid, uniquifier, and portal are the same */
907 afs_uint32 *addrp, nentries, code, unique;
909 ListAddrByAttributes attrs;
912 memset((char *)&attrs, 0, sizeof(attrs));
913 attrs.Mask = VLADDR_UUID;
914 attrs.uuid = ve->serverNumber[i];
915 memset((char *)&uuid, 0, sizeof(uuid));
916 memset((char *)&addrs, 0, sizeof(addrs));
918 tconn = afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
919 tcell->cellNum, areq, SHARED_LOCK);
922 code = VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique, &nentries, &addrs);
928 /* Handle corrupt VLDB (defect 7393) */
929 if (code == 0 && nentries == 0)
932 } while (afs_Analyze(tconn, code, NULL, areq,
933 -1, SHARED_LOCK, tcell));
935 /* Better handing of such failures; for now we'll simply retry this call */
936 areq->volumeError = 1;
940 addrp = addrs.bulkaddrs_val;
941 for (k = 0; k < nentries; k++) {
942 addrp[k] = htonl(addrp[k]);
944 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
945 WRITE_LOCK, &ve->serverNumber[i],
946 ve->serverUnique[i]);
947 afs_osi_Free(addrs.bulkaddrs_val, addrs.bulkaddrs_len*sizeof(*addrp));
950 av->serverHost[j] = ts;
952 /* The cell field could be 0 if the server entry was created
953 * first with the 'fs setserverprefs' call which doesn't set
954 * the cell field. Thus if the afs_GetServer call above
955 * follows later on it will find the server entry thus it will
956 * simply return without setting any fields, so we set the
957 * field ourselves below.
961 afs_PutServer(ts, WRITE_LOCK);
965 afs_SortServers(av->serverHost, MAXHOSTS);
966 } /*InstallVolumeEntry*/
969 void afs_ResetVolumeInfo(struct volume *tv)
973 AFS_STATCNT(afs_ResetVolumeInfo);
974 ObtainWriteLock(&tv->lock,117);
975 tv->states |= VRecheck;
976 for (i=0; i<MAXHOSTS; i++)
977 tv->status[i] = not_busy;
979 afs_osi_Free(tv->name, strlen(tv->name)+1);
982 ReleaseWriteLock(&tv->lock);