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.
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 struct volume *tv = NULL, **lv;
117 struct osi_file *tfile;
118 afs_int32 i = -1, code;
120 struct volume *bestVp, *oldLp = NULL, **bestLp = NULL;
121 char *oldname = NULL;
122 afs_int32 oldvtix = -2; /* Initialize to a value that doesn't occur */
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;
211 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
220 fvTable[i] = staticFVolume.next;
226 /* we messed with staticFVolume, so make sure someone else
227 * doesn't think it's fine to use */
231 } /*afs_UFSGetVolSlot */
235 * Get an available volume list slot. If the list does not exist,
236 * create one containing a single element.
240 afs_MemGetVolSlot(void)
244 AFS_STATCNT(afs_MemGetVolSlot);
245 if (!afs_freeVolList) {
246 struct volume *newVp;
248 newVp = afs_osi_Alloc(sizeof(struct volume));
249 osi_Assert(newVp != NULL);
252 afs_freeVolList = newVp;
254 tv = afs_freeVolList;
255 afs_freeVolList = tv->next;
258 } /*afs_MemGetVolSlot */
261 * Reset volume information for all volume structs that
262 * point to a speicific server.
266 afs_ResetVolumes(struct server *srvp)
271 /* Find any volumes residing on this server and flush their state */
272 for (j = 0; j < NVOLS; j++) {
273 for (vp = afs_volumes[j]; vp; vp = vp->next) {
274 for (k = 0; k < AFS_MAXHOSTS; k++) {
275 if (!srvp || (vp->serverHost[k] == srvp)) {
276 vp->serverHost[k] = 0;
277 afs_ResetVolumeInfo(vp);
287 * Reset volume name to volume id mapping cache.
291 afs_CheckVolumeNames(int flags)
297 afs_int32 *volumeID, *cellID, vsize, nvols;
298 #ifdef AFS_DARWIN80_ENV
301 AFS_STATCNT(afs_CheckVolumeNames);
304 volumeID = cellID = NULL;
306 ObtainReadLock(&afs_xvolume);
307 if (flags & AFS_VOLCHECK_EXPIRED) {
309 * allocate space to hold the volumeIDs and cellIDs, only if
310 * we will be invalidating the mountpoints later on
312 for (i = 0; i < NVOLS; i++)
313 for (tv = afs_volumes[i]; tv; tv = tv->next)
316 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
317 cellID = (volumeID) ? volumeID + vsize : 0;
321 for (i = 0; i < NVOLS; i++) {
322 for (tv = afs_volumes[i]; tv; tv = tv->next) {
323 if (flags & AFS_VOLCHECK_EXPIRED) {
324 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
325 || (flags & AFS_VOLCHECK_FORCE)) {
326 afs_ResetVolumeInfo(tv); /* also resets status */
328 volumeID[nvols] = tv->volume;
329 cellID[nvols] = tv->cell;
336 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
337 for (j = 0; j < AFS_MAXHOSTS; j++)
338 tv->status[j] = not_busy;
343 ReleaseReadLock(&afs_xvolume);
346 /* next ensure all mt points are re-evaluated */
347 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
349 ObtainReadLock(&afs_xvcache);
350 for (i = 0; i < VCSIZE; i++) {
351 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
353 /* if the volume of "mvid" of the vcache entry is among the
354 * ones we found earlier, then we re-evaluate it. Also, if the
355 * force bit is set or we explicitly asked to reevaluate the
356 * mt-pts, we clean the cmvalid bit */
358 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
360 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
361 tvc->f.states &= ~CMValid;
363 /* If the volume that this file belongs to was reset earlier,
364 * then we should remove its callback.
365 * Again, if forced, always do it.
367 if ((tvc->f.states & CRO)
368 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
369 || (flags & AFS_VOLCHECK_FORCE))) {
371 if (tvc->f.states & CVInit) {
372 ReleaseReadLock(&afs_xvcache);
373 afs_osi_Sleep(&tvc->f.states);
376 #ifdef AFS_DARWIN80_ENV
377 if (tvc->f.states & CDeadVnode) {
378 ReleaseReadLock(&afs_xvcache);
379 afs_osi_Sleep(&tvc->f.states);
385 if (vnode_ref(tvp)) {
387 /* AFSTOV(tvc) may be NULL */
395 ReleaseReadLock(&afs_xvcache);
397 ObtainWriteLock(&afs_xcbhash, 485);
398 /* LOCKXXX: We aren't holding tvc write lock? */
399 afs_DequeueCallback(tvc);
400 tvc->f.states &= ~CStatd;
401 ReleaseWriteLock(&afs_xcbhash);
402 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
403 osi_dnlc_purgedp(tvc);
405 #ifdef AFS_DARWIN80_ENV
406 vnode_put(AFSTOV(tvc));
407 /* our tvc ptr is still good until now */
409 ObtainReadLock(&afs_xvcache);
411 ObtainReadLock(&afs_xvcache);
413 /* our tvc ptr is still good until now */
419 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
420 ReleaseReadLock(&afs_xvcache);
424 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
426 } /*afs_CheckVolumeNames */
430 * Check if volume is in the specified list.
431 * @param fid File FID.
432 * @param nvols Nomber of volumes???
433 * @param vID Array of volume IDs.
434 * @param cID Array of cache IDs.
435 * @return 1 - true, 0 - false.
438 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
443 /* if no arrays present, be conservative and return true */
444 if (nvols && (!vID || !cID))
447 for (i = 0; i < nvols; ++i) {
448 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
455 /* afs_PutVolume is now a macro in afs.h */
459 * Return volume struct if we have it cached and it's up-to-date.
460 * Environment: Must be called with afs_xvolume unlocked.
461 * @param afid Volume FID.
463 * @return Volume or NULL if no result.
466 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
474 i = VHash(afid->Fid.Volume);
475 ObtainWriteLock(&afs_xvolume, 106);
476 for (tv = afs_volumes[i]; tv; tv = tv->next) {
477 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
478 && (tv->states & VRecheck) == 0) {
483 ReleaseWriteLock(&afs_xvolume);
484 return tv; /* NULL if we didn't find it */
485 } /*afs_FindVolume */
490 * Note that areq may be null, in which case we don't bother to set any
491 * request status information.
492 * @param afid Volume FID.
493 * @param areq Request type.
494 * @param locktype Lock to be used.
495 * @return Volume or NULL if no result.
498 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
502 char *bp, tbuf[CVBS];
503 AFS_STATCNT(afs_GetVolume);
505 tv = afs_FindVolume(afid, locktype);
507 /* Do a dynroot check and add dynroot volume if found. */
508 if (afs_IsDynrootAnyFid(afid)) {
509 tv = afs_NewDynrootVolume(afid);
511 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
512 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
522 * @param volid Volume ID. If it's 0, get it from the name.
523 * @param aname Volume name.
524 * @param ve Volume entry.
525 * @param tcell The cell containing this volume.
527 * @param type Type of volume.
528 * @param areq Request.
529 * @return Volume or NULL if failure.
531 static struct volume *
532 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
533 afs_int32 agood, afs_int32 type, struct vrequest *areq)
536 struct vldbentry *ove = (struct vldbentry *)ve;
537 struct nvldbentry *nve = (struct nvldbentry *)ve;
538 struct uvldbentry *uve = (struct uvldbentry *)ve;
540 int whichType; /* which type of volume to look for */
545 /* special hint from file server to use vlserver */
547 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
549 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
554 /* figure out which one we're really interested in (a set is returned) */
555 volid = afs_vtoi(aname);
558 volid = uve->volumeId[whichType];
559 } else if (type == 1) {
560 volid = nve->volumeId[whichType];
562 volid = ove->volumeId[whichType];
564 } /* end of if (volid == 0) */
565 } /* end of if (!volid) */
568 ObtainWriteLock(&afs_xvolume, 108);
570 for (tv = afs_volumes[i]; tv; tv = tv->next) {
571 if (tv->volume == volid && tv->cell == tcell->cellNum) {
576 struct fvolume *tf = 0;
578 tv = afs_GetVolSlot();
580 ReleaseWriteLock(&afs_xvolume);
583 memset(tv, 0, sizeof(struct volume));
584 tv->cell = tcell->cellNum;
585 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
586 tv->next = afs_volumes[i]; /* thread into list */
589 for (j = fvTable[FVHash(tv->cell, volid)]; j != 0; j = tf->next) {
590 if (afs_FVIndex != j) {
591 struct osi_file *tfile;
592 tfile = osi_UFSOpen(&volumeInode);
594 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
595 &staticFVolume, sizeof(struct fvolume));
596 if (err != sizeof(struct fvolume))
597 osi_Panic("read volumeinfo2");
602 if (tf->cell == tv->cell && tf->volume == volid)
605 if (tf && (j != 0)) {
606 tv->vtix = afs_FVIndex;
607 tv->mtpoint = tf->mtpoint;
608 tv->dotdot = tf->dotdot;
609 tv->rootVnode = tf->rootVnode;
610 tv->rootUnique = tf->rootUnique;
613 tv->rootVnode = tv->rootUnique = 0;
614 afs_GetDynrootMountFid(&tv->dotdot);
615 afs_GetDynrootMountFid(&tv->mtpoint);
616 tv->mtpoint.Fid.Vnode =
617 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
618 tv->mtpoint.Fid.Unique = volid;
622 tv->states &= ~VRecheck; /* just checked it */
623 tv->accessTime = osi_Time();
624 ReleaseWriteLock(&afs_xvolume);
625 ObtainWriteLock(&tv->lock, 111);
627 InstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
628 } else if (type == 1)
629 InstallNVolumeEntry(tv, nve, tcell->cellNum);
631 InstallVolumeEntry(tv, ove, tcell->cellNum);
634 tv->name = afs_osi_Alloc(strlen(aname) + 1);
635 osi_Assert(tv->name != NULL);
636 strcpy(tv->name, aname);
639 for (i = 0; i < NMAXNSERVERS; i++) {
640 tv->status[i] = not_busy;
642 ReleaseWriteLock(&tv->lock);
648 * Seek volume by it's name and attributes.
649 * If volume not found, try to add one.
650 * @param aname Volume name.
654 * @param locktype Type of lock to be used.
658 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
659 struct vrequest *areq, afs_int32 locktype)
664 AFS_STATCNT(afs_GetVolumeByName);
665 ObtainWriteLock(&afs_xvolume, 112);
666 for (i = 0; i < NVOLS; i++) {
667 for (tv = afs_volumes[i]; tv; tv = tv->next) {
668 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
669 && (tv->states & VRecheck) == 0) {
671 ReleaseWriteLock(&afs_xvolume);
677 ReleaseWriteLock(&afs_xvolume);
679 if (AFS_IS_DISCONNECTED)
682 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
687 * Init a new dynroot volume.
689 * @return Volume or NULL if not found.
691 static struct volume *
692 afs_NewDynrootVolume(struct VenusFid *fid)
696 struct vldbentry *tve;
697 char *bp, tbuf[CVBS];
699 tcell = afs_GetCell(fid->Cell, READ_LOCK);
702 tve = afs_osi_Alloc(sizeof(*tve));
703 osi_Assert(tve != NULL);
704 if (!(tcell->states & CHasVolRef))
705 tcell->states |= CHasVolRef;
707 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
708 memset(tve, 0, sizeof(*tve));
709 strcpy(tve->name, "local-dynroot");
710 tve->volumeId[ROVOL] = fid->Fid.Volume;
711 tve->flags = VLF_ROEXISTS;
713 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
714 afs_PutCell(tcell, READ_LOCK);
715 afs_osi_Free(tve, sizeof(*tve));
722 * @param aname Volume name.
723 * @param acell Cell id.
725 * @param areq Request type.
726 * @param locktype Type of lock to be used.
727 * @return Volume or NULL if failure.
729 static struct volume *
730 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
731 struct vrequest *areq, afs_int32 locktype)
733 afs_int32 code, type = 0;
734 struct volume *tv, *tv1;
735 struct vldbentry *tve;
736 struct nvldbentry *ntve;
737 struct uvldbentry *utve;
740 struct afs_conn *tconn;
741 struct vrequest treq;
742 struct rx_connection *rxconn;
744 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
747 tcell = afs_GetCell(acell, READ_LOCK);
752 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
757 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
758 ICL_TYPE_POINTER, aname);
759 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
760 tve = (struct vldbentry *)(tbuffer + 1024);
761 ntve = (struct nvldbentry *)tve;
762 utve = (struct uvldbentry *)tve;
763 afs_InitReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
766 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
767 &treq, SHARED_LOCK, &rxconn);
769 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
772 code = VL_GetEntryByNameO(rxconn, aname, tve);
774 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
777 code = VL_GetEntryByNameN(rxconn, aname, ntve);
782 code = VL_GetEntryByNameU(rxconn, aname, utve);
784 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
785 if (code == RXGEN_OPCODE) {
788 code = VL_GetEntryByNameN(rxconn, aname, ntve);
790 if (code == RXGEN_OPCODE) {
792 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
794 code = VL_GetEntryByNameO(rxconn, aname, tve);
797 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
799 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
805 } while (afs_Analyze(tconn, rxconn, code, NULL, &treq, -1, /* no op code for this */
806 SHARED_LOCK, tcell));
809 /* If the client has yet to contact this cell and contact failed due
810 * to network errors, mark the VLDB servers as back up.
811 * That the client tried and failed can be determined from the
812 * fact that there was a downtime incident, but CHasVolRef is not set.
814 /* RT 48959 - unclear if this should really go */
816 if (areq->networkError && !(tcell->states & CHasVolRef)) {
820 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
821 if ((sp = tcell->cellHosts[i]) == NULL)
823 for (sap = sp->addr; sap; sap = sap->next_sa)
824 afs_MarkServerUpOrDown(sap, 0);
828 afs_CopyError(&treq, areq);
829 osi_FreeLargeSpace(tbuffer);
830 afs_PutCell(tcell, READ_LOCK);
834 * Check to see if this cell has not yet referenced a volume. If
835 * it hasn't, it's just about to change its status, and we need to mark
836 * this fact down. Note that it is remotely possible that afs_SetupVolume
837 * could fail and we would still not have a volume reference.
839 if (!(tcell->states & CHasVolRef)) {
840 tcell->states |= CHasVolRef;
841 afs_stats_cmperf.numCellsContacted++;
843 /*First time a volume in this cell has been referenced */
850 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, &treq);
851 if ((agood == 3) && tv && tv->backVol) {
853 * This means that very soon we'll ask for the BK volume so
854 * we'll prefetch it (well we did already.)
857 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, &treq);
862 if ((agood >= 2) && tv && tv->roVol) {
864 * This means that very soon we'll ask for the RO volume so
865 * we'll prefetch it (well we did already.)
867 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, &treq);
872 osi_FreeLargeSpace(tbuffer);
873 afs_PutCell(tcell, READ_LOCK);
876 } /*afs_NewVolumeByName */
881 * Call this with the volume structure locked; used for new-style vldb requests.
887 InstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
895 AFS_STATCNT(InstallVolumeEntry);
897 /* Determine the type of volume we want */
898 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
900 } else if ((ve->flags & VLF_ROEXISTS)
901 && (av->volume == ve->volumeId[ROVOL])) {
904 } else if ((ve->flags & VLF_BACKEXISTS)
905 && (av->volume == ve->volumeId[BACKVOL])) {
906 /* backup always is on the same volume as parent */
908 av->states |= (VRO | VBackup);
910 mask = 0; /* Can't find volume in vldb entry */
913 /* fill in volume types */
914 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
915 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
916 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
918 if (ve->flags & VLF_DFSFILESET)
919 av->states |= VForeign;
921 cellp = afs_GetCell(acell, 0);
923 /* This volume, av, is locked. Zero out the serverHosts[] array
924 * so that if afs_GetServer() decides to replace the server
925 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
928 for (j = 0; j < AFS_MAXHOSTS; j++) {
929 av->serverHost[j] = 0;
932 /* Step through the VLDB entry making sure each server listed is there */
933 for (i = 0, j = 0; i < ve->nServers; i++) {
934 if (((ve->serverFlags[i] & mask) == 0)
935 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
936 continue; /* wrong volume or don't use this volume */
939 temp = htonl(ve->serverNumber[i]);
940 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
942 av->serverHost[j] = ts;
945 * The cell field could be 0 if the server entry was created
946 * first with the 'fs setserverprefs' call which doesn't set
947 * the cell field. Thus if the afs_GetServer call above
948 * follows later on it will find the server entry thus it will
949 * simply return without setting any fields, so we set the
950 * field ourselves below.
954 afs_PutServer(ts, WRITE_LOCK);
957 if (j < AFS_MAXHOSTS) {
958 av->serverHost[j++] = 0;
960 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
961 } /*InstallVolumeEntry */
965 InstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
973 AFS_STATCNT(InstallVolumeEntry);
975 /* Determine type of volume we want */
976 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
978 } else if ((ve->flags & VLF_ROEXISTS)
979 && (av->volume == ve->volumeId[ROVOL])) {
982 } else if ((ve->flags & VLF_BACKEXISTS)
983 && (av->volume == ve->volumeId[BACKVOL])) {
984 /* backup always is on the same volume as parent */
986 av->states |= (VRO | VBackup);
988 mask = 0; /* Can't find volume in vldb entry */
991 /* fill in volume types */
992 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
993 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
994 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
996 if (ve->flags & VLF_DFSFILESET)
997 av->states |= VForeign;
999 cellp = afs_GetCell(acell, 0);
1001 /* This volume, av, is locked. Zero out the serverHosts[] array
1002 * so that if afs_GetServer() decides to replace the server
1003 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1006 for (j = 0; j < AFS_MAXHOSTS; j++) {
1007 av->serverHost[j] = 0;
1010 /* Step through the VLDB entry making sure each server listed is there */
1011 for (i = 0, j = 0; i < ve->nServers; i++) {
1012 if (((ve->serverFlags[i] & mask) == 0)
1013 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1014 continue; /* wrong volume or don't use this volume */
1017 temp = htonl(ve->serverNumber[i]);
1018 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1020 av->serverHost[j] = ts;
1022 * The cell field could be 0 if the server entry was created
1023 * first with the 'fs setserverprefs' call which doesn't set
1024 * the cell field. Thus if the afs_GetServer call above
1025 * follows later on it will find the server entry thus it will
1026 * simply return without setting any fields, so we set the
1027 * field ourselves below.
1031 afs_PutServer(ts, WRITE_LOCK);
1034 if (j < AFS_MAXHOSTS) {
1035 av->serverHost[j++] = 0;
1037 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1038 } /*InstallNVolumeEntry */
1042 InstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1043 struct cell *tcell, struct vrequest *areq)
1046 struct afs_conn *tconn;
1049 afs_uint32 serverid;
1053 AFS_STATCNT(InstallVolumeEntry);
1055 /* Determine type of volume we want */
1056 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1058 } else if ((ve->flags & VLF_ROEXISTS)
1059 && av->volume == ve->volumeId[ROVOL]) {
1062 } else if ((ve->flags & VLF_BACKEXISTS)
1063 && (av->volume == ve->volumeId[BACKVOL])) {
1064 /* backup always is on the same volume as parent */
1066 av->states |= (VRO | VBackup);
1068 mask = 0; /* Can't find volume in vldb entry */
1071 /* fill in volume types */
1072 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1073 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1074 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1076 if (ve->flags & VLF_DFSFILESET)
1077 av->states |= VForeign;
1079 cellp = afs_GetCell(acell, 0);
1081 /* This volume, av, is locked. Zero out the serverHosts[] array
1082 * so that if afs_GetServer() decides to replace the server
1083 * struct, we don't deadlock trying to afs_ResetVolumeInfo()
1086 for (j = 0; j < AFS_MAXHOSTS; j++) {
1087 av->serverHost[j] = 0;
1090 /* Gather the list of servers the VLDB says the volume is on
1091 * and initialize the ve->serverHost[] array. If a server struct
1092 * is not found, then get the list of addresses for the
1093 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1095 for (i = 0, j = 0; i < ve->nServers; i++) {
1096 if (((ve->serverFlags[i] & mask) == 0)
1097 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1098 continue; /* wrong volume don't use this volume */
1101 if (!(ve->serverFlags[i] & VLSERVER_FLAG_UUID)) {
1102 /* The server has no uuid */
1103 serverid = htonl(ve->serverNumber[i].time_low);
1104 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport, WRITE_LOCK,
1107 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1108 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1110 /* uuid, uniquifier, and portal are the same */
1112 afs_uint32 *addrp, code;
1113 afs_int32 nentries, unique;
1115 ListAddrByAttributes attrs;
1117 struct rx_connection *rxconn;
1119 memset(&attrs, 0, sizeof(attrs));
1120 attrs.Mask = VLADDR_UUID;
1121 attrs.uuid = ve->serverNumber[i];
1122 memset(&uuid, 0, sizeof(uuid));
1123 memset(&addrs, 0, sizeof(addrs));
1126 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1127 tcell->cellNum, areq, SHARED_LOCK,
1132 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1139 /* Handle corrupt VLDB (defect 7393) */
1140 if (code == 0 && nentries == 0)
1143 } while (afs_Analyze
1144 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1146 /* Better handing of such failures; for now we'll simply retry this call */
1147 areq->volumeError = 1;
1151 addrp = addrs.bulkaddrs_val;
1152 for (k = 0; k < nentries; k++) {
1153 addrp[k] = htonl(addrp[k]);
1155 ts = afs_GetServer(addrp, nentries, acell, cellp->fsport,
1156 WRITE_LOCK, &ve->serverNumber[i],
1157 ve->serverUnique[i]);
1158 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1161 av->serverHost[j] = ts;
1163 /* The cell field could be 0 if the server entry was created
1164 * first with the 'fs setserverprefs' call which doesn't set
1165 * the cell field. Thus if the afs_GetServer call above
1166 * follows later on it will find the server entry thus it will
1167 * simply return without setting any fields, so we set the
1168 * field ourselves below.
1172 afs_PutServer(ts, WRITE_LOCK);
1176 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1177 } /*InstallVolumeEntry */
1181 * Reset volume info for the specified volume strecture. Mark volume
1182 * to be rechecked next time.
1186 afs_ResetVolumeInfo(struct volume *tv)
1190 AFS_STATCNT(afs_ResetVolumeInfo);
1191 ObtainWriteLock(&tv->lock, 117);
1192 tv->states |= VRecheck;
1193 for (i = 0; i < AFS_MAXHOSTS; i++)
1194 tv->status[i] = not_busy;
1196 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1199 ReleaseWriteLock(&tv->lock);