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, **lv;
117 struct osi_file *tfile;
118 register afs_int32 i, code;
120 struct volume *bestVp, **bestLp;
122 AFS_STATCNT(afs_UFSGetVolSlot);
123 if (!afs_freeVolList) {
125 bestTime = 0x7fffffff;
128 for (i = 0; i < NVOLS; i++) {
129 lv = &afs_volumes[i];
130 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
131 if (tv->refCount == 0) { /* is this one available? */
132 if (tv->accessTime < bestTime) { /* best one available? */
133 bestTime = tv->accessTime;
141 osi_Panic("getvolslot none");
145 afs_osi_Free(tv->name, strlen(tv->name) + 1);
147 /* now write out volume structure to file */
149 tv->vtix = afs_volCounter++;
150 /* now put on hash chain */
151 i = FVHash(tv->cell, tv->volume);
152 staticFVolume.next = fvTable[i];
153 fvTable[i] = tv->vtix;
156 * Haul the guy in from disk so we don't overwrite hash table
159 if (afs_FVIndex != tv->vtix) {
160 tfile = osi_UFSOpen(&volumeInode);
162 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
163 &staticFVolume, sizeof(struct fvolume));
164 if (code != sizeof(struct fvolume))
165 osi_Panic("read volumeinfo");
167 afs_FVIndex = tv->vtix;
170 afs_FVIndex = tv->vtix;
171 staticFVolume.volume = tv->volume;
172 staticFVolume.cell = tv->cell;
173 staticFVolume.mtpoint = tv->mtpoint;
174 staticFVolume.dotdot = tv->dotdot;
175 staticFVolume.rootVnode = tv->rootVnode;
176 staticFVolume.rootUnique = tv->rootUnique;
177 tfile = osi_UFSOpen(&volumeInode);
179 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
180 &staticFVolume, sizeof(struct fvolume));
181 if (code != sizeof(struct fvolume))
182 osi_Panic("write volumeinfo");
185 tv = afs_freeVolList;
186 afs_freeVolList = tv->next;
190 } /*afs_UFSGetVolSlot */
194 * Get an available volume list slot. If the list does not exist,
195 * create one containing a single element.
199 afs_MemGetVolSlot(void)
201 register struct volume *tv;
203 AFS_STATCNT(afs_MemGetVolSlot);
204 if (!afs_freeVolList) {
205 struct volume *newVp;
207 newVp = (struct volume *)afs_osi_Alloc(sizeof(struct volume));
210 afs_freeVolList = newVp;
212 tv = afs_freeVolList;
213 afs_freeVolList = tv->next;
216 } /*afs_MemGetVolSlot */
219 * Reset volume information for all volume structs that
220 * point to a speicific server.
224 afs_ResetVolumes(struct server *srvp)
229 /* Find any volumes residing on this server and flush their state */
230 for (j = 0; j < NVOLS; j++) {
231 for (vp = afs_volumes[j]; vp; vp = vp->next) {
232 for (k = 0; k < AFS_MAXHOSTS; k++) {
233 if (!srvp || (vp->serverHost[k] == srvp)) {
234 vp->serverHost[k] = 0;
235 afs_ResetVolumeInfo(vp);
245 * Reset volume name to volume id mapping cache.
249 afs_CheckVolumeNames(int flags)
255 afs_int32 *volumeID, *cellID, vsize, nvols;
256 #ifdef AFS_DARWIN80_ENV
259 AFS_STATCNT(afs_CheckVolumeNames);
262 volumeID = cellID = NULL;
264 ObtainReadLock(&afs_xvolume);
265 if (flags & AFS_VOLCHECK_EXPIRED) {
267 * allocate space to hold the volumeIDs and cellIDs, only if
268 * we will be invalidating the mountpoints later on
270 for (i = 0; i < NVOLS; i++)
271 for (tv = afs_volumes[i]; tv; tv = tv->next)
274 volumeID = (afs_int32 *) afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
275 cellID = (volumeID) ? volumeID + vsize : 0;
279 for (i = 0; i < NVOLS; i++) {
280 for (tv = afs_volumes[i]; tv; tv = tv->next) {
281 if (flags & AFS_VOLCHECK_EXPIRED) {
282 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
283 || (flags & AFS_VOLCHECK_FORCE)) {
284 afs_ResetVolumeInfo(tv); /* also resets status */
286 volumeID[nvols] = tv->volume;
287 cellID[nvols] = tv->cell;
294 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
295 for (j = 0; j < AFS_MAXHOSTS; j++)
296 tv->status[j] = not_busy;
301 ReleaseReadLock(&afs_xvolume);
304 /* next ensure all mt points are re-evaluated */
305 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
307 ObtainReadLock(&afs_xvcache);
308 for (i = 0; i < VCSIZE; i++) {
309 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
311 /* if the volume of "mvid" of the vcache entry is among the
312 * ones we found earlier, then we re-evaluate it. Also, if the
313 * force bit is set or we explicitly asked to reevaluate the
314 * mt-pts, we clean the cmvalid bit */
316 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
318 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
319 tvc->f.states &= ~CMValid;
321 /* If the volume that this file belongs to was reset earlier,
322 * then we should remove its callback.
323 * Again, if forced, always do it.
325 if ((tvc->f.states & CRO)
326 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
327 || (flags & AFS_VOLCHECK_FORCE))) {
329 if (tvc->f.states & CVInit) {
330 ReleaseReadLock(&afs_xvcache);
331 afs_osi_Sleep(&tvc->f.states);
334 #ifdef AFS_DARWIN80_ENV
335 if (tvc->f.states & CDeadVnode) {
336 ReleaseReadLock(&afs_xvcache);
337 afs_osi_Sleep(&tvc->f.states);
343 if (vnode_ref(tvp)) {
345 /* AFSTOV(tvc) may be NULL */
353 ReleaseReadLock(&afs_xvcache);
355 ObtainWriteLock(&afs_xcbhash, 485);
356 /* LOCKXXX: We aren't holding tvc write lock? */
357 afs_DequeueCallback(tvc);
358 tvc->f.states &= ~CStatd;
359 ReleaseWriteLock(&afs_xcbhash);
360 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
361 osi_dnlc_purgedp(tvc);
363 #ifdef AFS_DARWIN80_ENV
364 vnode_put(AFSTOV(tvc));
365 /* our tvc ptr is still good until now */
367 ObtainReadLock(&afs_xvcache);
369 ObtainReadLock(&afs_xvcache);
371 /* our tvc ptr is still good until now */
377 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
378 ReleaseReadLock(&afs_xvcache);
382 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
384 } /*afs_CheckVolumeNames */
388 * Check if volume is in the specified list.
389 * @param fid File FID.
390 * @param nvols Nomber of volumes???
391 * @param vID Array of volume IDs.
392 * @param cID Array of cache IDs.
393 * @return 1 - true, 0 - false.
396 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
401 /* if no arrays present, be conservative and return true */
402 if (nvols && (!vID || !cID))
405 for (i = 0; i < nvols; ++i) {
406 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
413 /* afs_PutVolume is now a macro in afs.h */
417 * Return volume struct if we have it cached and it's up-to-date.
418 * Environment: Must be called with afs_xvolume unlocked.
419 * @param afid Volume FID.
421 * @return Volume or NULL if no result.
424 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
432 i = VHash(afid->Fid.Volume);
433 ObtainWriteLock(&afs_xvolume, 106);
434 for (tv = afs_volumes[i]; tv; tv = tv->next) {
435 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
436 && (tv->states & VRecheck) == 0) {
441 ReleaseWriteLock(&afs_xvolume);
442 return tv; /* NULL if we didn't find it */
443 } /*afs_FindVolume */
448 * Note that areq may be null, in which case we don't bother to set any
449 * request status information.
450 * @param afid Volume FID.
451 * @param areq Request type.
452 * @param locktype Lock to be used.
453 * @return Volume or NULL if no result.
456 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
460 char *bp, tbuf[CVBS];
461 AFS_STATCNT(afs_GetVolume);
463 tv = afs_FindVolume(afid, locktype);
465 /* Do a dynroot check and add dynroot volume if found. */
466 if (afs_IsDynrootAnyFid(afid)) {
467 tv = afs_NewDynrootVolume(afid);
469 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
470 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
480 * @param volid Volume ID. If it's 0, get it from the name.
481 * @param aname Volume name.
482 * @param ve Volume entry.
483 * @param tcell The cell containing this volume.
485 * @param type Type of volume.
486 * @param areq Request.
487 * @return Volume or NULL if failure.
489 static struct volume *
490 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
491 afs_int32 agood, afs_int32 type, struct vrequest *areq)
494 struct vldbentry *ove = (struct vldbentry *)ve;
495 struct nvldbentry *nve = (struct nvldbentry *)ve;
496 struct uvldbentry *uve = (struct uvldbentry *)ve;
498 int whichType; /* which type of volume to look for */
503 /* special hint from file server to use vlserver */
505 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
507 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
512 /* figure out which one we're really interested in (a set is returned) */
513 volid = afs_vtoi(aname);
516 volid = uve->volumeId[whichType];
517 } else if (type == 1) {
518 volid = nve->volumeId[whichType];
520 volid = ove->volumeId[whichType];
522 } /* end of if (volid == 0) */
523 } /* end of if (!volid) */
526 ObtainWriteLock(&afs_xvolume, 108);
528 for (tv = afs_volumes[i]; tv; tv = tv->next) {
529 if (tv->volume == volid && tv->cell == tcell->cellNum) {
534 struct fvolume *tf = 0;
536 tv = afs_GetVolSlot();
537 memset(tv, 0, sizeof(struct volume));
538 tv->cell = tcell->cellNum;
539 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
540 tv->next = afs_volumes[i]; /* thread into list */
543 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
544 if (afs_FVIndex != j) {
545 struct osi_file *tfile;
546 tfile = osi_UFSOpen(&volumeInode);
548 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
549 &staticFVolume, sizeof(struct fvolume));
550 if (err != sizeof(struct fvolume))
551 osi_Panic("read volumeinfo2");
556 if (tf->cell == tv->cell && tf->volume == volid)
559 if (tf && (j != 0)) {
560 tv->vtix = afs_FVIndex;
561 tv->mtpoint = tf->mtpoint;
562 tv->dotdot = tf->dotdot;
563 tv->rootVnode = tf->rootVnode;
564 tv->rootUnique = tf->rootUnique;
567 tv->rootVnode = tv->rootUnique = 0;
568 afs_GetDynrootMountFid(&tv->dotdot);
569 afs_GetDynrootMountFid(&tv->mtpoint);
570 tv->mtpoint.Fid.Vnode =
571 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
572 tv->mtpoint.Fid.Unique = volid;
576 tv->states &= ~VRecheck; /* just checked it */
577 tv->accessTime = osi_Time();
578 ReleaseWriteLock(&afs_xvolume);
579 ObtainWriteLock(&tv->lock, 111);
581 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
582 } else if (type == 1)
583 InstallNVolumeEntry(tv, nve, tcell->cellNum);
585 InstallVolumeEntry(tv, ove, tcell->cellNum);
588 tv->name = afs_osi_Alloc(strlen(aname) + 1);
589 strcpy(tv->name, aname);
592 for (i = 0; i < NMAXNSERVERS; i++) {
593 tv->status[i] = not_busy;
595 ReleaseWriteLock(&tv->lock);
601 * Seek volume by it's name and attributes.
602 * If volume not found, try to add one.
603 * @param aname Volume name.
607 * @param locktype Type of lock to be used.
611 afs_GetVolumeByName(register char *aname, afs_int32 acell, int agood,
612 struct vrequest *areq, afs_int32 locktype)
617 AFS_STATCNT(afs_GetVolumeByName);
618 ObtainWriteLock(&afs_xvolume, 112);
619 for (i = 0; i < NVOLS; i++) {
620 for (tv = afs_volumes[i]; tv; tv = tv->next) {
621 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
622 && (tv->states & VRecheck) == 0) {
624 ReleaseWriteLock(&afs_xvolume);
630 ReleaseWriteLock(&afs_xvolume);
632 if (AFS_IS_DISCONNECTED)
635 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
640 * Init a new dynroot volume.
642 * @return Volume or NULL if not found.
644 static struct volume *
645 afs_NewDynrootVolume(struct VenusFid *fid)
649 struct vldbentry *tve;
650 char *bp, tbuf[CVBS];
652 tcell = afs_GetCell(fid->Cell, READ_LOCK);
655 tve = afs_osi_Alloc(sizeof(*tve));
656 if (!(tcell->states & CHasVolRef))
657 tcell->states |= CHasVolRef;
659 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
660 memset(tve, 0, sizeof(*tve));
661 strcpy(tve->name, "local-dynroot");
662 tve->volumeId[ROVOL] = fid->Fid.Volume;
663 tve->flags = VLF_ROEXISTS;
665 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
666 afs_PutCell(tcell, READ_LOCK);
667 afs_osi_Free(tve, sizeof(*tve));
674 * @param aname Volume name.
675 * @param acell Cell id.
677 * @param areq Request type.
678 * @param locktype Type of lock to be used.
679 * @return Volume or NULL if failure.
681 static struct volume *
682 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
683 struct vrequest *areq, afs_int32 locktype)
685 afs_int32 code, type = 0;
686 struct volume *tv, *tv1;
687 struct vldbentry *tve;
688 struct nvldbentry *ntve;
689 struct uvldbentry *utve;
692 struct afs_conn *tconn;
693 struct vrequest treq;
695 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
698 tcell = afs_GetCell(acell, READ_LOCK);
703 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
708 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
709 ICL_TYPE_POINTER, aname);
710 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
711 tve = (struct vldbentry *)(tbuffer + 1024);
712 ntve = (struct nvldbentry *)tve;
713 utve = (struct uvldbentry *)tve;
714 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
717 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
720 if (tconn->srvr->server->flags & SNO_LHOSTS) {
723 code = VL_GetEntryByNameO(tconn->id, aname, tve);
725 } else if (tconn->srvr->server->flags & SYES_LHOSTS) {
728 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
733 code = VL_GetEntryByNameU(tconn->id, aname, utve);
735 if (!(tconn->srvr->server->flags & SVLSRV_UUID)) {
736 if (code == RXGEN_OPCODE) {
739 code = VL_GetEntryByNameN(tconn->id, aname, ntve);
741 if (code == RXGEN_OPCODE) {
743 tconn->srvr->server->flags |= SNO_LHOSTS;
745 code = VL_GetEntryByNameO(tconn->id, aname, tve);
748 tconn->srvr->server->flags |= SYES_LHOSTS;
750 tconn->srvr->server->flags |= SVLSRV_UUID;
756 } while (afs_Analyze(tconn, code, NULL, &treq, -1, /* no op code for this */
757 SHARED_LOCK, tcell));
760 /* If the client has yet to contact this cell and contact failed due
761 * to network errors, mark the VLDB servers as back up.
762 * That the client tried and failed can be determined from the
763 * fact that there was a downtime incident, but CHasVolRef is not set.
765 /* RT 48959 - unclear if this should really go */
767 if (areq->networkError && !(tcell->states & CHasVolRef)) {
771 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
772 if ((sp = tcell->cellHosts[i]) == NULL)
774 for (sap = sp->addr; sap; sap = sap->next_sa)
775 afs_MarkServerUpOrDown(sap, 0);
779 afs_CopyError(&treq, areq);
780 osi_FreeLargeSpace(tbuffer);
781 afs_PutCell(tcell, READ_LOCK);
785 * Check to see if this cell has not yet referenced a volume. If
786 * it hasn't, it's just about to change its status, and we need to mark
787 * this fact down. Note that it is remotely possible that afs_SetupVolume
788 * could fail and we would still not have a volume reference.
790 if (!(tcell->states & CHasVolRef)) {
791 tcell->states |= CHasVolRef;
792 afs_stats_cmperf.numCellsContacted++;
794 /*First time a volume in this cell has been referenced */
801 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, areq);
802 if ((agood == 3) && tv->backVol) {
804 * This means that very soon we'll ask for the BK volume so
805 * we'll prefetch it (well we did already.)
808 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, areq);
811 if ((agood >= 2) && tv->roVol) {
813 * This means that very soon we'll ask for the RO volume so
814 * we'll prefetch it (well we did already.)
816 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, areq);
819 osi_FreeLargeSpace(tbuffer);
820 afs_PutCell(tcell, READ_LOCK);
823 } /*afs_NewVolumeByName */
828 * Call this with the volume structure locked; used for new-style vldb requests.
834 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
836 register struct server *ts;
842 AFS_STATCNT(InstallVolumeEntry);
844 /* Determine the type of volume we want */
845 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
847 } else if ((ve->flags & VLF_ROEXISTS)
848 && (av->volume == ve->volumeId[ROVOL])) {
851 } else if ((ve->flags & VLF_BACKEXISTS)
852 && (av->volume == ve->volumeId[BACKVOL])) {
853 /* backup always is on the same volume as parent */
855 av->states |= (VRO | VBackup);
857 mask = 0; /* Can't find volume in vldb entry */
860 /* fill in volume types */
861 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
862 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
863 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
865 if (ve->flags & VLF_DFSFILESET)
866 av->states |= VForeign;
868 cellp = afs_GetCell(acell, 0);
870 /* This volume, av, is locked. Zero out the serverHosts[] array
871 * so that if afs_GetServer() decides to replace the server
872 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
875 for (j = 0; j < AFS_MAXHOSTS; j++) {
876 av->serverHost[j] = 0;
879 /* Step through the VLDB entry making sure each server listed is there */
880 for (i = 0, j = 0; i < ve->nServers; i++) {
881 if (((ve->serverFlags[i] & mask) == 0)
882 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
883 continue; /* wrong volume or don't use this volume */
886 temp = htonl(ve->serverNumber[i]);
887 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
889 av->serverHost[j] = ts;
892 * The cell field could be 0 if the server entry was created
893 * first with the 'fs setserverprefs' call which doesn't set
894 * the cell field. Thus if the afs_GetServer call above
895 * follows later on it will find the server entry thus it will
896 * simply return without setting any fields, so we set the
897 * field ourselves below.
901 afs_PutServer(ts, WRITE_LOCK);
904 if (j < AFS_MAXHOSTS) {
905 av->serverHost[j++] = 0;
907 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
908 } /*InstallVolumeEntry */
912 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
914 register struct server *ts;
920 AFS_STATCNT(InstallVolumeEntry);
922 /* Determine type of volume we want */
923 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
925 } else if ((ve->flags & VLF_ROEXISTS)
926 && (av->volume == ve->volumeId[ROVOL])) {
929 } else if ((ve->flags & VLF_BACKEXISTS)
930 && (av->volume == ve->volumeId[BACKVOL])) {
931 /* backup always is on the same volume as parent */
933 av->states |= (VRO | VBackup);
935 mask = 0; /* Can't find volume in vldb entry */
938 /* fill in volume types */
939 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
940 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
941 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
943 if (ve->flags & VLF_DFSFILESET)
944 av->states |= VForeign;
946 cellp = afs_GetCell(acell, 0);
948 /* This volume, av, is locked. Zero out the serverHosts[] array
949 * so that if afs_GetServer() decides to replace the server
950 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
953 for (j = 0; j < AFS_MAXHOSTS; j++) {
954 av->serverHost[j] = 0;
957 /* Step through the VLDB entry making sure each server listed is there */
958 for (i = 0, j = 0; i < ve->nServers; i++) {
959 if (((ve->serverFlags[i] & mask) == 0)
960 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
961 continue; /* wrong volume or don't use this volume */
964 temp = htonl(ve->serverNumber[i]);
965 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
967 av->serverHost[j] = ts;
969 * The cell field could be 0 if the server entry was created
970 * first with the 'fs setserverprefs' call which doesn't set
971 * the cell field. Thus if the afs_GetServer call above
972 * follows later on it will find the server entry thus it will
973 * simply return without setting any fields, so we set the
974 * field ourselves below.
978 afs_PutServer(ts, WRITE_LOCK);
981 if (j < AFS_MAXHOSTS) {
982 av->serverHost[j++] = 0;
984 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
985 } /*InstallNVolumeEntry */
989 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
990 struct cell *tcell, struct vrequest *areq)
992 register struct server *ts;
993 struct afs_conn *tconn;
1000 AFS_STATCNT(InstallVolumeEntry);
1002 /* Determine type of volume we want */
1003 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1005 } else if ((ve->flags & VLF_ROEXISTS)
1006 && av->volume == ve->volumeId[ROVOL]) {
1009 } else if ((ve->flags & VLF_BACKEXISTS)
1010 && (av->volume == ve->volumeId[BACKVOL])) {
1011 /* backup always is on the same volume as parent */
1013 av->states |= (VRO | VBackup);
1015 mask = 0; /* Can't find volume in vldb entry */
1018 /* fill in volume types */
1019 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1020 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1021 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1023 if (ve->flags & VLF_DFSFILESET)
1024 av->states |= VForeign;
1026 cellp = afs_GetCell(acell, 0);
1028 /* This volume, av, is locked. Zero out the serverHosts[] array
1029 * so that if afs_GetServer() decides to replace the server
1030 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1033 for (j = 0; j < AFS_MAXHOSTS; j++) {
1034 av->serverHost[j] = 0;
1037 /* Gather the list of servers the VLDB says the volume is on
1038 * and initialize the ve->serverHost[] array. If a server struct
1039 * is not found, then get the list of addresses for the
1040 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1042 for (i = 0, j = 0; i < ve->nServers; i++) {
1043 if (((ve->serverFlags[i] & mask) == 0)
1044 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1045 continue; /* wrong volume don't use this volume */
1048 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
1049 /* The server has no uuid */
1050 serverid = htonl(ve->serverNumber[i].time_low);
1051 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
1054 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1055 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1057 /* uuid, uniquifier, and portal are the same */
1059 afs_uint32 *addrp, code;
1060 afs_int32 nentries, unique;
1062 ListAddrByAttributes attrs;
1065 memset(&attrs, 0, sizeof(attrs));
1066 attrs.Mask = VLADDR_UUID;
1067 attrs.uuid = ve->serverNumber[i];
1068 memset(&uuid, 0, sizeof(uuid));
1069 memset(&addrs, 0, sizeof(addrs));
1072 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1073 tcell->cellNum, areq, SHARED_LOCK);
1077 VL_GetAddrsU(tconn->id, &attrs, &uuid, &unique,
1084 /* Handle corrupt VLDB (defect 7393) */
1085 if (code == 0 && nentries == 0)
1088 } while (afs_Analyze
1089 (tconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1091 /* Better handing of such failures; for now we'll simply retry this call */
1092 areq->volumeError = 1;
1096 addrp = addrs.bulkaddrs_val;
1097 for (k = 0; k < nentries; k++) {
1098 addrp[k] = htonl(addrp[k]);
1100 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1101 WRITE_LOCK, &ve->serverNumber[i],
1102 ve->serverUnique[i]);
1103 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1106 av->serverHost[j] = ts;
1108 /* The cell field could be 0 if the server entry was created
1109 * first with the 'fs setserverprefs' call which doesn't set
1110 * the cell field. Thus if the afs_GetServer call above
1111 * follows later on it will find the server entry thus it will
1112 * simply return without setting any fields, so we set the
1113 * field ourselves below.
1117 afs_PutServer(ts, WRITE_LOCK);
1121 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1122 } /*InstallVolumeEntry */
1126 * Reset volume info for the specified volume strecture. Mark volume
1127 * to be rechecked next time.
1131 afs_ResetVolumeInfo(struct volume *tv)
1135 AFS_STATCNT(afs_ResetVolumeInfo);
1136 ObtainWriteLock(&tv->lock, 117);
1137 tv->states |= VRecheck;
1138 for (i = 0; i < AFS_MAXHOSTS; i++)
1139 tv->status[i] = not_busy;
1141 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1144 ReleaseWriteLock(&tv->lock);