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
10 #include <afs/param.h>
24 osi_rwlock_t cm_cellLock;
26 cm_cell_t *cm_allCellsp;
28 /* function called as callback proc from cm_SearchCellFile. Return 0 to
29 * continue processing.
31 long cm_AddCellProc(void *rockp, struct sockaddr_in *addrp, char *namep)
39 /* if this server was previously created by fs setserverprefs */
40 if ( tsp = cm_FindServer(addrp, CM_SERVER_VLDB))
46 tsp = cm_NewServer(addrp, CM_SERVER_VLDB, cellp);
48 /* Insert the vlserver into a sorted list, sorted by server rank */
49 tsrp = cm_NewServerRef(tsp);
50 cm_InsertServerList(&cellp->vlServersp, tsrp);
55 /* load up a cell structure from the cell database, afsdcell.ini */
56 cm_cell_t *cm_GetCell(char *namep, long flags)
60 static cellCounter = 1; /* locked by cm_cellLock */
62 lock_ObtainWrite(&cm_cellLock);
63 for(cp = cm_allCellsp; cp; cp=cp->nextp) {
64 if (strcmp(namep, cp->namep) == 0) break;
66 if (!cp && (flags & CM_FLAG_CREATE)) {
67 cp = malloc(sizeof(*cp));
68 memset(cp, 0, sizeof(*cp));
69 code = cm_SearchCellFile(namep, NULL, cm_AddCellProc, cp);
76 /* randomise among those vlservers having the same rank*/
77 cm_RandomizeServer(&cp->vlServersp);
79 /* otherwise we found the cell, and so we're nearly done */
80 lock_InitializeMutex(&cp->mx, "cm_cell_t mutex");
83 cp->namep = malloc(strlen(namep)+1);
84 strcpy(cp->namep, namep);
86 /* thread on global list */
87 cp->nextp = cm_allCellsp;
90 cp->cellID = cellCounter++;
94 lock_ReleaseWrite(&cm_cellLock);
98 cm_cell_t *cm_FindCellByID(long cellID)
102 lock_ObtainWrite(&cm_cellLock);
103 for(cp = cm_allCellsp; cp; cp=cp->nextp) {
104 if (cellID == cp->cellID) break;
106 lock_ReleaseWrite(&cm_cellLock);
111 void cm_InitCell(void)
113 static osi_once_t once;
115 if (osi_Once(&once)) {
116 lock_InitializeRWLock(&cm_cellLock, "cell global lock");
121 void cm_ChangeRankCellVLServer(cm_server_t *tsp)
126 cp = tsp->cellp; /* cell that this vlserver belongs to */
129 lock_ObtainMutex(&cp->mx);
130 code = cm_ChangeRankServer(&cp->vlServersp, tsp);
132 if ( !code ) /* if the server list was rearranged */
133 cm_RandomizeServer(&cp->vlServersp);
135 lock_ReleaseMutex(&cp->mx);