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_SUN5_ENV)
45 #include <inet/common.h>
46 #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 afs_dcache_id_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,
66 int agood, struct vrequest *areq,
68 static struct volume *afs_NewDynrootVolume(struct VenusFid *fid);
69 static int inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
75 * Convert a volume name to a number;
76 * @param aname Volume name.
77 * @return return 0 if can't parse as a number.
85 AFS_STATCNT(afs_vtoi);
86 while ((tc = *aname++)) {
87 if (tc > '9' || tc < '0')
88 return 0; /* invalid name */
98 * All of the vol cache routines must be called with the afs_xvolume
99 * lock held in exclusive mode, since they use static variables.
100 * In addition, we don't want two people adding the same volume
104 static struct fvolume staticFVolume;
105 afs_int32 afs_FVIndex = -1;
108 * Initialize a newly gotten volume slot.
110 * \param tv volume slot to be initialized
111 * \param tf volume item data; null if none
112 * \param volid volume id for this volume slot
113 * \param cell cell for this volume slot
117 afs_InitVolSlot(struct volume *tv, struct fvolume *tf, afs_int32 volid,
120 AFS_STATCNT(afs_InitVolSlot);
121 memset(tv, 0, sizeof(struct volume));
122 tv->cell = tcell->cellNum;
123 AFS_RWLOCK_INIT(&tv->lock, "volume lock");
126 tv->vtix = afs_FVIndex;
127 tv->mtpoint = tf->mtpoint;
128 tv->dotdot = tf->dotdot;
129 tv->rootVnode = tf->rootVnode;
130 tv->rootUnique = tf->rootUnique;
133 tv->rootVnode = tv->rootUnique = 0;
134 afs_GetDynrootMountFid(&tv->dotdot);
135 afs_GetDynrootMountFid(&tv->mtpoint);
136 tv->mtpoint.Fid.Vnode =
137 VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2);
138 tv->mtpoint.Fid.Unique = volid;
143 * UFS specific version of afs_GetVolSlot
147 afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell)
149 struct volume *tv = NULL, **lv;
150 struct osi_file *tfile;
151 afs_int32 i = -1, code;
153 struct volume *bestVp, *oldLp = NULL, **bestLp = NULL;
154 char *oldname = NULL;
155 afs_int32 oldvtix = -2; /* Initialize to a value that doesn't occur */
156 struct fvolume *tf = NULL;
159 AFS_STATCNT(afs_UFSGetVolSlot);
160 if (!afs_freeVolList) {
162 bestTime = 0x7fffffff;
165 for (i = 0; i < NVOLS; i++) {
166 lv = &afs_volumes[i];
167 for (tv = *lv; tv; lv = &tv->next, tv = *lv) {
168 if (tv->refCount == 0) { /* is this one available? */
169 if (tv->accessTime < bestTime) { /* best one available? */
170 bestTime = tv->accessTime;
178 afs_warn("afs_UFSGetVolSlot: no vol slots available\n");
190 /* now write out volume structure to file */
192 tv->vtix = afs_volCounter++;
193 /* now put on hash chain */
194 i = FVHash(tv->cell, tv->volume);
195 staticFVolume.next = fvTable[i];
196 fvTable[i] = tv->vtix;
199 * Haul the guy in from disk so we don't overwrite hash table
202 if (afs_FVIndex != tv->vtix) {
203 tfile = osi_UFSOpen(&volumeInode);
205 afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
209 afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix,
210 &staticFVolume, sizeof(struct fvolume));
212 if (code != sizeof(struct fvolume)) {
213 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
219 afs_FVIndex = tv->vtix;
220 staticFVolume.volume = tv->volume;
221 staticFVolume.cell = tv->cell;
222 staticFVolume.mtpoint = tv->mtpoint;
223 staticFVolume.dotdot = tv->dotdot;
224 staticFVolume.rootVnode = tv->rootVnode;
225 staticFVolume.rootUnique = tv->rootUnique;
226 tfile = osi_UFSOpen(&volumeInode);
228 afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
232 afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex,
233 &staticFVolume, sizeof(struct fvolume));
235 if (code != sizeof(struct fvolume)) {
236 afs_warn("afs_UFSGetVolSlot: error %d writing volumeinfo\n",
241 afs_osi_Free(oldname, strlen(oldname) + 1);
245 tv = afs_freeVolList;
246 afs_freeVolList = tv->next;
249 /* read volume item data from disk for the gotten slot */
250 for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) {
251 if (afs_FVIndex != j) {
252 tfile = osi_UFSOpen(&volumeInode);
254 afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n");
255 code = -1; /* indicate error */
258 afs_osi_Read(tfile, sizeof(struct fvolume) * j,
259 &staticFVolume, sizeof(struct fvolume));
261 if (code != sizeof(struct fvolume)) {
262 afs_warn("afs_UFSGetVolSlot: error %d reading volumeinfo\n",
266 if (code != sizeof(struct fvolume)) {
267 /* put tv back on the free list; the data in it is not valid */
268 tv->next = afs_freeVolList;
269 afs_freeVolList = tv;
270 /* staticFVolume contents are not valid */
276 if (j != 0) { /* volume items record 0 is not used */
278 if (tf->cell == tcell->cellNum && tf->volume == volid) {
284 afs_InitVolSlot(tv, tf, volid, tcell);
290 afs_warn("afs_UFSGetVolSlot: oldvtix is uninitialized\n");
299 fvTable[i] = staticFVolume.next;
305 /* we messed with staticFVolume, so make sure someone else
306 * doesn't think it's fine to use */
310 } /*afs_UFSGetVolSlot */
314 * Get an available volume list slot. If the list does not exist,
315 * create one containing a single element.
319 afs_MemGetVolSlot(afs_int32 volid, struct cell *tcell)
323 AFS_STATCNT(afs_MemGetVolSlot);
324 if (!afs_freeVolList) {
325 struct volume *newVp;
327 newVp = afs_osi_Alloc(sizeof(struct volume));
328 osi_Assert(newVp != NULL);
331 afs_freeVolList = newVp;
333 tv = afs_freeVolList;
334 afs_freeVolList = tv->next;
336 afs_InitVolSlot(tv, NULL, volid, tcell);
339 } /*afs_MemGetVolSlot */
342 * Setup a volume slot for cell:volume.
344 * Find the volume slot for the cell:volume, otherwise get
345 * and initialize a new slot.
347 * \param volid volume id
351 static struct volume *
352 afs_SetupVolSlot(afs_int32 volid, struct cell *tcell)
357 AFS_STATCNT(afs_SetupVolSlot);
358 ObtainWriteLock(&afs_xvolume, 108);
360 for (tv = afs_volumes[i]; tv; tv = tv->next) {
361 if (tv->volume == volid && tv->cell == tcell->cellNum) {
366 tv = afs_GetVolSlot(volid, tcell);
368 ReleaseWriteLock(&afs_xvolume);
371 tv->next = afs_volumes[i]; /* thread into list */
375 tv->states &= ~VRecheck; /* just checked it */
376 tv->accessTime = osi_Time();
377 ReleaseWriteLock(&afs_xvolume);
382 * Reset volume information for all volume structs that
383 * point to a speicific server, skipping a given volume if provided.
386 * The server to reset volume info about
388 * The volume to skip resetting info about
391 afs_ResetVolumes(struct server *srvp, struct volume *tv)
396 /* Find any volumes residing on this server and flush their state */
397 for (j = 0; j < NVOLS; j++) {
398 for (vp = afs_volumes[j]; vp; vp = vp->next) {
399 for (k = 0; k < AFS_MAXHOSTS; k++) {
400 if (!srvp || (vp->serverHost[k] == srvp)) {
401 if (tv && tv != vp) {
402 vp->serverHost[k] = 0;
403 afs_ResetVolumeInfo(vp);
413 * Reset volume name to volume id mapping cache.
417 afs_CheckVolumeNames(int flags)
423 afs_int32 *volumeID, *cellID, vsize, nvols;
424 #ifdef AFS_DARWIN80_ENV
427 AFS_STATCNT(afs_CheckVolumeNames);
430 volumeID = cellID = NULL;
432 ObtainReadLock(&afs_xvolume);
433 if (flags & AFS_VOLCHECK_EXPIRED) {
435 * allocate space to hold the volumeIDs and cellIDs, only if
436 * we will be invalidating the mountpoints later on
438 for (i = 0; i < NVOLS; i++)
439 for (tv = afs_volumes[i]; tv; tv = tv->next)
442 volumeID = afs_osi_Alloc(2 * vsize * sizeof(*volumeID));
443 cellID = (volumeID) ? volumeID + vsize : 0;
447 for (i = 0; i < NVOLS; i++) {
448 for (tv = afs_volumes[i]; tv; tv = tv->next) {
449 if (flags & AFS_VOLCHECK_EXPIRED) {
450 if (((tv->expireTime < (now + 10)) && (tv->states & VRO))
451 || (flags & AFS_VOLCHECK_FORCE)) {
452 afs_ResetVolumeInfo(tv); /* also resets status */
454 volumeID[nvols] = tv->volume;
455 cellID[nvols] = tv->cell;
462 if (flags & (AFS_VOLCHECK_BUSY | AFS_VOLCHECK_FORCE)) {
463 for (j = 0; j < AFS_MAXHOSTS; j++)
464 tv->status[j] = not_busy;
469 ReleaseReadLock(&afs_xvolume);
472 /* next ensure all mt points are re-evaluated */
473 if (nvols || (flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))) {
475 ObtainReadLock(&afs_xvcache);
476 for (i = 0; i < VCSIZE; i++) {
477 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
479 /* if the volume of "mvid" of the vcache entry is among the
480 * ones we found earlier, then we re-evaluate it. Also, if the
481 * force bit is set or we explicitly asked to reevaluate the
482 * mt-pts, we clean the cmvalid bit */
484 if ((flags & (AFS_VOLCHECK_FORCE | AFS_VOLCHECK_MTPTS))
486 && inVolList(tvc->mvid, nvols, volumeID, cellID)))
487 tvc->f.states &= ~CMValid;
489 /* If the volume that this file belongs to was reset earlier,
490 * then we should remove its callback.
491 * Again, if forced, always do it.
493 if ((tvc->f.states & CRO)
494 && (inVolList(&tvc->f.fid, nvols, volumeID, cellID)
495 || (flags & AFS_VOLCHECK_FORCE))) {
497 if (tvc->f.states & CVInit) {
498 ReleaseReadLock(&afs_xvcache);
499 afs_osi_Sleep(&tvc->f.states);
502 #ifdef AFS_DARWIN80_ENV
503 if (tvc->f.states & CDeadVnode) {
504 ReleaseReadLock(&afs_xvcache);
505 afs_osi_Sleep(&tvc->f.states);
511 if (vnode_ref(tvp)) {
513 /* AFSTOV(tvc) may be NULL */
521 ReleaseReadLock(&afs_xvcache);
523 ObtainWriteLock(&afs_xcbhash, 485);
524 /* LOCKXXX: We aren't holding tvc write lock? */
525 afs_DequeueCallback(tvc);
526 tvc->f.states &= ~CStatd;
527 ReleaseWriteLock(&afs_xcbhash);
528 if (tvc->f.fid.Fid.Vnode & 1 || (vType(tvc) == VDIR))
529 osi_dnlc_purgedp(tvc);
531 #ifdef AFS_DARWIN80_ENV
532 vnode_put(AFSTOV(tvc));
533 /* our tvc ptr is still good until now */
535 ObtainReadLock(&afs_xvcache);
537 ObtainReadLock(&afs_xvcache);
539 /* our tvc ptr is still good until now */
545 osi_dnlc_purge(); /* definitely overkill, but it's safer this way. */
546 ReleaseReadLock(&afs_xvcache);
550 afs_osi_Free(volumeID, 2 * vsize * sizeof(*volumeID));
552 } /*afs_CheckVolumeNames */
556 * Check if volume is in the specified list.
557 * @param fid File FID.
558 * @param nvols Nomber of volumes???
559 * @param vID Array of volume IDs.
560 * @param cID Array of cache IDs.
561 * @return 1 - true, 0 - false.
564 inVolList(struct VenusFid *fid, afs_int32 nvols, afs_int32 * vID,
569 /* if no arrays present, be conservative and return true */
570 if (nvols && (!vID || !cID))
573 for (i = 0; i < nvols; ++i) {
574 if (fid->Fid.Volume == vID[i] && fid->Cell == cID[i])
581 /* afs_PutVolume is now a macro in afs.h */
585 * Return volume struct if we have it cached and it's up-to-date.
586 * Environment: Must be called with afs_xvolume unlocked.
587 * @param afid Volume FID.
589 * @return Volume or NULL if no result.
592 afs_FindVolume(struct VenusFid *afid, afs_int32 locktype)
600 i = VHash(afid->Fid.Volume);
601 ObtainWriteLock(&afs_xvolume, 106);
602 for (tv = afs_volumes[i]; tv; tv = tv->next) {
603 if (tv->volume == afid->Fid.Volume && tv->cell == afid->Cell
604 && (tv->states & VRecheck) == 0) {
609 ReleaseWriteLock(&afs_xvolume);
610 return tv; /* NULL if we didn't find it */
611 } /*afs_FindVolume */
616 * Note that areq may be null, in which case we don't bother to set any
617 * request status information.
618 * @param afid Volume FID.
619 * @param areq Request type.
620 * @param locktype Lock to be used.
621 * @return Volume or NULL if no result.
624 afs_GetVolume(struct VenusFid *afid, struct vrequest *areq,
628 char *bp, tbuf[CVBS];
629 AFS_STATCNT(afs_GetVolume);
631 tv = afs_FindVolume(afid, locktype);
633 /* Do a dynroot check and add dynroot volume if found. */
634 if (afs_IsDynrootAnyFid(afid)) {
635 tv = afs_NewDynrootVolume(afid);
637 bp = afs_cv2string(&tbuf[CVBS], afid->Fid.Volume);
638 tv = afs_NewVolumeByName(bp, afid->Cell, 0, areq, locktype);
648 * @param volid Volume ID. If it's 0, get it from the name.
649 * @param aname Volume name.
650 * @param ve Volume entry.
651 * @param tcell The cell containing this volume.
653 * @param type Type of volume.
654 * @param areq Request.
655 * @return Volume or NULL if failure.
657 static struct volume *
658 afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
659 afs_int32 agood, afs_int32 type, struct vrequest *areq)
662 struct vldbentry *ove = (struct vldbentry *)ve;
663 struct nvldbentry *nve = (struct nvldbentry *)ve;
664 struct uvldbentry *uve = (struct uvldbentry *)ve;
666 int whichType; /* which type of volume to look for */
671 /* special hint from file server to use vlserver */
673 if (len >= 8 && strcmp(aname + len - 7, ".backup") == 0)
675 else if (len >= 10 && strcmp(aname + len - 9, ".readonly") == 0)
680 /* figure out which one we're really interested in (a set is returned) */
681 volid = afs_vtoi(aname);
684 volid = uve->volumeId[whichType];
685 } else if (type == 1) {
686 volid = nve->volumeId[whichType];
688 volid = ove->volumeId[whichType];
690 } /* end of if (volid == 0) */
691 } /* end of if (!volid) */
693 tv = afs_SetupVolSlot(volid, tcell);
699 LockAndInstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
700 } else if (type == 1)
701 LockAndInstallNVolumeEntry(tv, nve, tcell->cellNum);
703 LockAndInstallVolumeEntry(tv, ove, tcell->cellNum);
706 tv->name = afs_osi_Alloc(strlen(aname) + 1);
707 osi_Assert(tv->name != NULL);
708 strcpy(tv->name, aname);
711 for (i = 0; i < NMAXNSERVERS; i++) {
712 tv->status[i] = not_busy;
714 ReleaseWriteLock(&tv->lock);
720 * Seek volume by it's name and attributes.
721 * If volume not found, try to add one.
722 * @param aname Volume name.
726 * @param locktype Type of lock to be used.
730 afs_GetVolumeByName(char *aname, afs_int32 acell, int agood,
731 struct vrequest *areq, afs_int32 locktype)
736 AFS_STATCNT(afs_GetVolumeByName);
737 ObtainWriteLock(&afs_xvolume, 112);
738 for (i = 0; i < NVOLS; i++) {
739 for (tv = afs_volumes[i]; tv; tv = tv->next) {
740 if (tv->name && !strcmp(aname, tv->name) && tv->cell == acell
741 && (tv->states & VRecheck) == 0) {
743 ReleaseWriteLock(&afs_xvolume);
749 ReleaseWriteLock(&afs_xvolume);
751 if (AFS_IS_DISCONNECTED)
754 tv = afs_NewVolumeByName(aname, acell, agood, areq, locktype);
759 * Init a new dynroot volume.
761 * @return Volume or NULL if not found.
763 static struct volume *
764 afs_NewDynrootVolume(struct VenusFid *fid)
768 struct vldbentry *tve;
769 char *bp, tbuf[CVBS];
771 tcell = afs_GetCell(fid->Cell, READ_LOCK);
774 tve = afs_osi_Alloc(sizeof(*tve));
775 osi_Assert(tve != NULL);
776 if (!(tcell->states & CHasVolRef))
777 tcell->states |= CHasVolRef;
779 bp = afs_cv2string(&tbuf[CVBS], fid->Fid.Volume);
780 memset(tve, 0, sizeof(*tve));
781 strcpy(tve->name, "local-dynroot");
782 tve->volumeId[ROVOL] = fid->Fid.Volume;
783 tve->flags = VLF_ROEXISTS;
785 tv = afs_SetupVolume(0, bp, tve, tcell, 0, 0, 0);
786 afs_PutCell(tcell, READ_LOCK);
787 afs_osi_Free(tve, sizeof(*tve));
794 * @param aname Volume name.
795 * @param acell Cell id.
797 * @param areq Request type.
798 * @param locktype Type of lock to be used.
799 * @return Volume or NULL if failure.
801 static struct volume *
802 afs_NewVolumeByName(char *aname, afs_int32 acell, int agood,
803 struct vrequest *areq, afs_int32 locktype)
805 afs_int32 code, type = 0;
806 struct volume *tv, *tv1;
807 struct vldbentry *tve;
808 struct nvldbentry *ntve;
809 struct uvldbentry *utve;
812 struct afs_conn *tconn;
813 struct vrequest *treq = NULL;
814 struct rx_connection *rxconn;
816 if (strlen(aname) > VL_MAXNAMELEN) /* Invalid volume name */
819 tcell = afs_GetCell(acell, READ_LOCK);
824 code = afs_CreateReq(&treq, afs_osi_credp); /* *must* be unauth for vldb */
829 /* allow null request if we don't care about ENODEV/ETIMEDOUT distinction */
834 afs_Trace2(afs_iclSetp, CM_TRACE_GETVOL, ICL_TYPE_STRING, aname,
835 ICL_TYPE_POINTER, aname);
836 tbuffer = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
837 tve = (struct vldbentry *)(tbuffer + 1024);
838 ntve = (struct nvldbentry *)tve;
839 utve = (struct uvldbentry *)tve;
843 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
844 treq, SHARED_LOCK, 0, &rxconn);
846 if (tconn->parent->srvr->server->flags & SNO_LHOSTS) {
849 code = VL_GetEntryByNameO(rxconn, aname, tve);
851 } else if (tconn->parent->srvr->server->flags & SYES_LHOSTS) {
854 code = VL_GetEntryByNameN(rxconn, aname, ntve);
859 code = VL_GetEntryByNameU(rxconn, aname, utve);
861 if (!(tconn->parent->srvr->server->flags & SVLSRV_UUID)) {
862 if (code == RXGEN_OPCODE) {
865 code = VL_GetEntryByNameN(rxconn, aname, ntve);
867 if (code == RXGEN_OPCODE) {
869 tconn->parent->srvr->server->flags |= SNO_LHOSTS;
871 code = VL_GetEntryByNameO(rxconn, aname, tve);
874 tconn->parent->srvr->server->flags |= SYES_LHOSTS;
876 tconn->parent->srvr->server->flags |= SVLSRV_UUID;
882 } while (afs_Analyze(tconn, rxconn, code, NULL, treq, -1, /* no op code for this */
883 SHARED_LOCK, tcell));
886 /* If the client has yet to contact this cell and contact failed due
887 * to network errors, mark the VLDB servers as back up.
888 * That the client tried and failed can be determined from the
889 * fact that there was a downtime incident, but CHasVolRef is not set.
891 /* RT 48959 - unclear if this should really go */
893 if (areq->networkError && !(tcell->states & CHasVolRef)) {
897 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
898 if ((sp = tcell->cellHosts[i]) == NULL)
900 for (sap = sp->addr; sap; sap = sap->next_sa)
901 afs_MarkServerUpOrDown(sap, 0);
905 afs_CopyError(treq, areq);
906 osi_FreeLargeSpace(tbuffer);
907 afs_PutCell(tcell, READ_LOCK);
908 afs_DestroyReq(treq);
912 * Check to see if this cell has not yet referenced a volume. If
913 * it hasn't, it's just about to change its status, and we need to mark
914 * this fact down. Note that it is remotely possible that afs_SetupVolume
915 * could fail and we would still not have a volume reference.
917 if (!(tcell->states & CHasVolRef)) {
918 tcell->states |= CHasVolRef;
919 afs_stats_cmperf.numCellsContacted++;
921 /*First time a volume in this cell has been referenced */
928 tv = afs_SetupVolume(0, aname, ve, tcell, agood, type, treq);
929 if ((agood == 3) && tv && tv->backVol) {
931 * This means that very soon we'll ask for the BK volume so
932 * we'll prefetch it (well we did already.)
935 afs_SetupVolume(tv->backVol, (char *)0, ve, tcell, 0, type, treq);
940 if ((agood >= 2) && tv && tv->roVol) {
942 * This means that very soon we'll ask for the RO volume so
943 * we'll prefetch it (well we did already.)
945 tv1 = afs_SetupVolume(tv->roVol, NULL, ve, tcell, 0, type, treq);
950 osi_FreeLargeSpace(tbuffer);
951 afs_PutCell(tcell, READ_LOCK);
952 afs_DestroyReq(treq);
955 } /*afs_NewVolumeByName */
960 * Call this with the volume structure locked; used for new-style vldb requests.
966 LockAndInstallVolumeEntry(struct volume *av, struct vldbentry *ve, int acell)
974 struct server *serverHost[AFS_MAXHOSTS];
976 AFS_STATCNT(InstallVolumeEntry);
978 memset(serverHost, 0, sizeof(serverHost));
980 /* Determine the type of volume we want */
981 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
983 } else if ((ve->flags & VLF_ROEXISTS)
984 && (av->volume == ve->volumeId[ROVOL])) {
987 } else if ((ve->flags & VLF_BACKEXISTS)
988 && (av->volume == ve->volumeId[BACKVOL])) {
989 /* backup always is on the same volume as parent */
991 types |= (VRO | VBackup);
993 mask = 0; /* Can't find volume in vldb entry */
996 cellp = afs_GetCell(acell, 0);
998 /* Step through the VLDB entry making sure each server listed is there */
999 for (i = 0, j = 0; i < ve->nServers; i++) {
1000 if (((ve->serverFlags[i] & mask) == 0)
1001 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1002 continue; /* wrong volume or don't use this volume */
1005 temp = htonl(ve->serverNumber[i]);
1006 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1007 (afsUUID *) 0, 0, av);
1011 * The cell field could be 0 if the server entry was created
1012 * first with the 'fs setserverprefs' call which doesn't set
1013 * the cell field. Thus if the afs_GetServer call above
1014 * follows later on it will find the server entry thus it will
1015 * simply return without setting any fields, so we set the
1016 * field ourselves below.
1020 afs_PutServer(ts, WRITE_LOCK);
1024 ObtainWriteLock(&av->lock, 109);
1026 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1029 av->states |= types;
1031 /* fill in volume types */
1032 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1033 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1034 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1036 if (ve->flags & VLF_DFSFILESET)
1037 av->states |= VForeign;
1039 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1040 } /*InstallVolumeEntry */
1044 LockAndInstallNVolumeEntry(struct volume *av, struct nvldbentry *ve, int acell)
1052 struct server *serverHost[AFS_MAXHOSTS];
1054 AFS_STATCNT(InstallVolumeEntry);
1056 memset(serverHost, 0, sizeof(serverHost));
1058 /* Determine type of volume we want */
1059 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1061 } else if ((ve->flags & VLF_ROEXISTS)
1062 && (av->volume == ve->volumeId[ROVOL])) {
1065 } else if ((ve->flags & VLF_BACKEXISTS)
1066 && (av->volume == ve->volumeId[BACKVOL])) {
1067 /* backup always is on the same volume as parent */
1069 types |= (VRO | VBackup);
1071 mask = 0; /* Can't find volume in vldb entry */
1074 cellp = afs_GetCell(acell, 0);
1076 /* Step through the VLDB entry making sure each server listed is there */
1077 for (i = 0, j = 0; i < ve->nServers; i++) {
1078 if (((ve->serverFlags[i] & mask) == 0)
1079 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1080 continue; /* wrong volume or don't use this volume */
1083 temp = htonl(ve->serverNumber[i]);
1084 ts = afs_GetServer(&temp, 1, acell, cellp->fsport, WRITE_LOCK,
1085 (afsUUID *) 0, 0, av);
1088 * The cell field could be 0 if the server entry was created
1089 * first with the 'fs setserverprefs' call which doesn't set
1090 * the cell field. Thus if the afs_GetServer call above
1091 * follows later on it will find the server entry thus it will
1092 * simply return without setting any fields, so we set the
1093 * field ourselves below.
1097 afs_PutServer(ts, WRITE_LOCK);
1101 ObtainWriteLock(&av->lock, 110);
1103 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1106 av->states |= types;
1108 /* fill in volume types */
1109 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1110 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1111 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1113 if (ve->flags & VLF_DFSFILESET)
1114 av->states |= VForeign;
1116 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1117 } /*InstallNVolumeEntry */
1121 LockAndInstallUVolumeEntry(struct volume *av, struct uvldbentry *ve, int acell,
1122 struct cell *tcell, struct vrequest *areq)
1125 struct afs_conn *tconn;
1128 afs_uint32 serverid;
1132 struct server *serverHost[AFS_MAXHOSTS];
1134 AFS_STATCNT(InstallVolumeEntry);
1136 memset(serverHost, 0, sizeof(serverHost));
1138 /* Determine type of volume we want */
1139 if ((ve->flags & VLF_RWEXISTS) && (av->volume == ve->volumeId[RWVOL])) {
1141 } else if ((ve->flags & VLF_ROEXISTS)
1142 && av->volume == ve->volumeId[ROVOL]) {
1145 } else if ((ve->flags & VLF_BACKEXISTS)
1146 && (av->volume == ve->volumeId[BACKVOL])) {
1147 /* backup always is on the same volume as parent */
1149 type |= (VRO | VBackup);
1151 mask = 0; /* Can't find volume in vldb entry */
1154 cellp = afs_GetCell(acell, 0);
1156 /* Gather the list of servers the VLDB says the volume is on
1157 * and initialize the ve->serverHost[] array. If a server struct
1158 * is not found, then get the list of addresses for the
1159 * server, VL_GetAddrsU(), and create a server struct, afs_GetServer().
1161 for (i = 0, j = 0; i < ve->nServers; i++) {
1162 if (((ve->serverFlags[i] & mask) == 0)
1163 || (ve->serverFlags[i] & VLSF_DONTUSE)) {
1164 continue; /* wrong volume don't use this volume */
1167 if (!(ve->serverFlags[i] & VLSF_UUID)) {
1168 /* The server has no uuid */
1169 serverid = htonl(ve->serverNumber[i].time_low);
1170 ts = afs_GetServer(&serverid, 1, acell, cellp->fsport,
1171 WRITE_LOCK, (afsUUID *) 0, 0, av);
1173 ts = afs_FindServer(0, cellp->fsport, &ve->serverNumber[i], 0);
1174 if (ts && (ts->sr_addr_uniquifier == ve->serverUnique[i])
1176 /* uuid, uniquifier, and portal are the same */
1178 afs_uint32 *addrp, code;
1179 afs_int32 nentries, unique;
1181 ListAddrByAttributes attrs;
1183 struct rx_connection *rxconn;
1185 memset(&attrs, 0, sizeof(attrs));
1186 attrs.Mask = VLADDR_UUID;
1187 attrs.uuid = ve->serverNumber[i];
1188 memset(&uuid, 0, sizeof(uuid));
1189 memset(&addrs, 0, sizeof(addrs));
1192 afs_ConnByMHosts(tcell->cellHosts, tcell->vlport,
1193 tcell->cellNum, areq, SHARED_LOCK,
1198 VL_GetAddrsU(rxconn, &attrs, &uuid, &unique,
1205 /* Handle corrupt VLDB (defect 7393) */
1206 if (code == 0 && nentries == 0)
1209 } while (afs_Analyze
1210 (tconn, rxconn, code, NULL, areq, -1, SHARED_LOCK, tcell));
1212 /* Better handing of such failures; for now we'll simply retry this call */
1213 areq->volumeError = 1;
1217 addrp = addrs.bulkaddrs_val;
1218 for (k = 0; k < nentries; k++) {
1219 addrp[k] = htonl(addrp[k]);
1221 ts = afs_GetServer(addrp, nentries, acell,
1222 cellp->fsport, WRITE_LOCK,
1223 &ve->serverNumber[i],
1224 ve->serverUnique[i], av);
1225 xdr_free((xdrproc_t) xdr_bulkaddrs, &addrs);
1230 /* The cell field could be 0 if the server entry was created
1231 * first with the 'fs setserverprefs' call which doesn't set
1232 * the cell field. Thus if the afs_GetServer call above
1233 * follows later on it will find the server entry thus it will
1234 * simply return without setting any fields, so we set the
1235 * field ourselves below.
1239 afs_PutServer(ts, WRITE_LOCK);
1243 ObtainWriteLock(&av->lock, 111);
1245 memcpy(av->serverHost, serverHost, sizeof(serverHost));
1250 /* fill in volume types */
1251 av->rwVol = ((ve->flags & VLF_RWEXISTS) ? ve->volumeId[RWVOL] : 0);
1252 av->roVol = ((ve->flags & VLF_ROEXISTS) ? ve->volumeId[ROVOL] : 0);
1253 av->backVol = ((ve->flags & VLF_BACKEXISTS) ? ve->volumeId[BACKVOL] : 0);
1255 if (ve->flags & VLF_DFSFILESET)
1256 av->states |= VForeign;
1258 afs_SortServers(av->serverHost, AFS_MAXHOSTS);
1259 } /*InstallVolumeEntry */
1263 * Reset volume info for the specified volume strecture. Mark volume
1264 * to be rechecked next time.
1268 afs_ResetVolumeInfo(struct volume *tv)
1272 AFS_STATCNT(afs_ResetVolumeInfo);
1273 ObtainWriteLock(&tv->lock, 117);
1274 tv->states |= VRecheck;
1276 /* the hard-mount code in afs_Analyze may not be able to reset this flag
1277 * when VRecheck is set, so clear it here to ensure it gets cleared. */
1278 tv->states &= ~VHardMount;
1280 for (i = 0; i < AFS_MAXHOSTS; i++)
1281 tv->status[i] = not_busy;
1283 afs_osi_Free(tv->name, strlen(tv->name) + 1);
1286 ReleaseWriteLock(&tv->lock);