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
13 #include <afsconfig.h>
14 #include "afs/param.h"
18 #include "afs/sysincludes.h" /* Standard vendor system headers */
19 #include "afsincludes.h" /* Afs-based standard headers */
20 #include "afs/afs_stats.h" /* afs statistics */
21 #include "afs/afs_osi.h"
22 #include "afs/afs_md5.h"
24 /* Local variables. */
25 afs_rwlock_t afs_xcell; /* Export for cmdebug peeking at locks */
28 * AFSDB implementation:
30 * afs_StopAFSDB: terminate the AFSDB handler, used on shutdown
31 * afs_AFSDBHandler: entry point for user-space AFSDB request handler
32 * afs_GetCellHostsAFSDB: query the AFSDB handler and wait for response
33 * afs_LookupAFSDB: look up AFSDB for given cell name and create locally
37 afs_rwlock_t afsdb_client_lock; /* Serializes client requests */
38 afs_rwlock_t afsdb_req_lock; /* Serializes client requests */
39 static char afsdb_handler_running; /* Protected by GLOCK */
40 static char afsdb_handler_shutdown; /* Protected by GLOCK */
42 /* from cellconfig.h */
43 #define MAXCELLCHARS 64
45 /* lock moved to afsdb_req_lock for cmdebug */
52 * Terminate the AFSDB handler, used on shutdown.
57 if (afsdb_handler_running) {
58 afs_osi_Wakeup(&afsdb_req);
60 afsdb_handler_shutdown = 1;
61 afs_termState = AFSOP_STOP_RXEVENT;
66 * \brief Entry point for user-space AFSDB request handler.
67 * Reads cell data from kerlenMsg and add new cell, or alias.
68 * \param acellName Cell name. If a cell is found, it's name will be filled in here.
69 * \param acellNameLen Cell name length.
70 * \param kernelMsg Buffer containing data about host count, time out, and cell hosts ids.
71 * \return 0 for success, < 0 for error.
74 afs_AFSDBHandler(char *acellName, int acellNameLen, afs_int32 * kernelMsg)
76 afs_int32 timeout, code;
77 afs_int32 cellHosts[MAXCELLHOSTS];
79 if (afsdb_handler_shutdown)
81 afsdb_handler_running = 1;
83 ObtainSharedLock(&afsdb_req_lock, 683);
84 if (afsdb_req.pending) {
87 UpgradeSToWLock(&afsdb_req_lock, 684);
88 hostCount = kernelMsg[0];
89 timeout = kernelMsg[1];
91 timeout += osi_Time();
93 for (i = 0; i < MAXCELLHOSTS; i++) {
97 cellHosts[i] = kernelMsg[2 + i];
101 code = afs_NewCell(acellName, cellHosts, CNoSUID, NULL, 0, 0,
104 if (!hostCount || (code && code != EEXIST))
105 /* null out the cellname if the lookup failed */
106 afsdb_req.cellname = NULL;
108 /* If we found an alias, create it */
109 if (afs_strcasecmp(afsdb_req.cellname, acellName))
110 afs_NewCellAlias(afsdb_req.cellname, acellName);
112 /* Request completed, wake up the relevant thread */
113 afsdb_req.pending = 0;
114 afsdb_req.complete = 1;
115 afs_osi_Wakeup(&afsdb_req);
116 ConvertWToSLock(&afsdb_req_lock);
118 ConvertSToRLock(&afsdb_req_lock);
120 /* Wait for a request */
121 while (afsdb_req.pending == 0 && afs_termState != AFSOP_STOP_AFSDB) {
122 ReleaseReadLock(&afsdb_req_lock);
123 afs_osi_Sleep(&afsdb_req);
124 ObtainReadLock(&afsdb_req_lock);
127 /* Check if we're shutting down */
128 if (afs_termState == AFSOP_STOP_AFSDB) {
129 ReleaseReadLock(&afsdb_req_lock);
131 /* Inform anyone waiting for us that we're going away */
132 afsdb_handler_shutdown = 1;
133 afsdb_handler_running = 0;
134 afs_osi_Wakeup(&afsdb_req);
136 afs_termState = AFSOP_STOP_RXEVENT;
137 afs_osi_Wakeup(&afs_termState);
141 /* Return the lookup request to userspace */
142 strncpy(acellName, afsdb_req.cellname, acellNameLen);
143 ReleaseReadLock(&afsdb_req_lock);
148 * \brief Query the AFSDB handler and wait for response.
150 * \return 0 for success. < 0 is error.
153 afs_GetCellHostsAFSDB(char *acellName)
156 if (!afsdb_handler_running)
159 ObtainWriteLock(&afsdb_client_lock, 685);
160 ObtainWriteLock(&afsdb_req_lock, 686);
162 afsdb_req.cellname = acellName;
164 afsdb_req.complete = 0;
165 afsdb_req.pending = 1;
166 afs_osi_Wakeup(&afsdb_req);
167 ConvertWToRLock(&afsdb_req_lock);
169 while (afsdb_handler_running && !afsdb_req.complete) {
170 ReleaseReadLock(&afsdb_req_lock);
171 afs_osi_Sleep(&afsdb_req);
172 ObtainReadLock(&afsdb_req_lock);
175 ReleaseReadLock(&afsdb_req_lock);
176 ReleaseWriteLock(&afsdb_client_lock);
178 if (afsdb_req.cellname) {
187 * Look up AFSDB for given cell name and create locally.
188 * \param acellName Cell name.
191 afs_LookupAFSDB(char *acellName)
195 char *cellName = afs_strdup(acellName);
197 code = afs_GetCellHostsAFSDB(cellName);
198 afs_Trace2(afs_iclSetp, CM_TRACE_AFSDB, ICL_TYPE_STRING, cellName,
199 ICL_TYPE_INT32, code);
200 afs_osi_FreeStr(cellName);
205 * Cell name-to-ID mapping
207 * afs_cellname_new: create a new cell name, optional cell number
208 * afs_cellname_lookup_id: look up a cell name
209 * afs_cellname_lookup_name: look up a cell number
210 * afs_cellname_ref: note that this cell name was referenced somewhere
211 * afs_cellname_init: load the list of cells from given inode
212 * afs_cellname_write: write in-kernel list of cells to disk
215 struct cell_name *afs_cellname_head; /* Export for kdump */
216 static afs_dcache_id_t afs_cellname_inode;
217 static int afs_cellname_inode_set;
218 static int afs_cellname_dirty;
219 static afs_int32 afs_cellnum_next;
222 * Create a new cell name, optional cell number.
223 * \param name Name of cell.
224 * \param cellnum Cellname number.
225 * \return Initialized structure.
227 static struct cell_name *
228 afs_cellname_new(char *name, afs_int32 cellnum)
230 struct cell_name *cn;
233 cellnum = afs_cellnum_next;
235 cn = (struct cell_name *)afs_osi_Alloc(sizeof(*cn));
236 cn->next = afs_cellname_head;
237 cn->cellnum = cellnum;
238 cn->cellname = afs_strdup(name);
240 afs_cellname_head = cn;
242 if (cellnum >= afs_cellnum_next)
243 afs_cellnum_next = cellnum + 1;
249 * Look up a cell name by id.
253 static struct cell_name *
254 afs_cellname_lookup_id(afs_int32 cellnum)
256 struct cell_name *cn;
258 for (cn = afs_cellname_head; cn; cn = cn->next)
259 if (cn->cellnum == cellnum)
266 * Look up a cell name.
267 * \param name Cell name.
270 static struct cell_name *
271 afs_cellname_lookup_name(char *name)
273 struct cell_name *cn;
275 for (cn = afs_cellname_head; cn; cn = cn->next)
276 if (strcmp(cn->cellname, name) == 0)
283 * Note that this cell name was referenced somewhere.
287 afs_cellname_ref(struct cell_name *cn)
291 afs_cellname_dirty = 1;
296 * \brief Load the list of cells from given inode.
297 * \param inode Source inode.
299 * \return 0 for success. < 0 for error.
302 afs_cellname_init(afs_dcache_id_t *inode, int lookupcode)
304 struct osi_file *tfile;
307 ObtainWriteLock(&afs_xcell, 692);
309 afs_cellnum_next = 1;
310 afs_cellname_dirty = 0;
312 if (cacheDiskType == AFS_FCACHE_TYPE_MEM) {
313 ReleaseWriteLock(&afs_xcell);
317 ReleaseWriteLock(&afs_xcell);
321 tfile = osi_UFSOpen(inode);
323 ReleaseWriteLock(&afs_xcell);
327 afs_copy_inode(&afs_cellname_inode, inode);
328 afs_cellname_inode_set = 1;
331 afs_int32 cellnum, clen, magic;
332 struct cell_name *cn;
335 cc = afs_osi_Read(tfile, off, &magic, sizeof(magic));
336 if (cc != sizeof(magic))
338 if (magic != AFS_CELLINFO_MAGIC)
342 cc = afs_osi_Read(tfile, off, &cellnum, sizeof(cellnum));
343 if (cc != sizeof(cellnum))
347 cc = afs_osi_Read(tfile, off, &clen, sizeof(clen));
348 if (cc != sizeof(clen))
352 cellname = afs_osi_Alloc(clen + 1);
356 cc = afs_osi_Read(tfile, off, cellname, clen);
358 afs_osi_Free(cellname, clen + 1);
362 cellname[clen] = '\0';
364 if (afs_cellname_lookup_name(cellname)
365 || afs_cellname_lookup_id(cellnum)) {
366 afs_osi_Free(cellname, clen + 1);
370 cn = afs_cellname_new(cellname, cellnum);
371 afs_osi_Free(cellname, clen + 1);
375 ReleaseWriteLock(&afs_xcell);
380 * Write in-kernel list of cells to disk.
383 afs_cellname_write(void)
385 struct osi_file *tfile;
386 struct cell_name *cn;
389 if (!afs_cellname_dirty || !afs_cellname_inode_set)
391 if (afs_initState != 300)
394 ObtainWriteLock(&afs_xcell, 693);
395 afs_cellname_dirty = 0;
397 tfile = osi_UFSOpen(&afs_cellname_inode);
399 ReleaseWriteLock(&afs_xcell);
403 for (cn = afs_cellname_head; cn; cn = cn->next) {
404 afs_int32 magic, cellnum, clen;
410 magic = AFS_CELLINFO_MAGIC;
411 cc = afs_osi_Write(tfile, off, &magic, sizeof(magic));
412 if (cc != sizeof(magic))
416 cellnum = cn->cellnum;
417 cc = afs_osi_Write(tfile, off, &cellnum, sizeof(cellnum));
418 if (cc != sizeof(cellnum))
422 clen = strlen(cn->cellname);
423 cc = afs_osi_Write(tfile, off, &clen, sizeof(clen));
424 if (cc != sizeof(clen))
428 cc = afs_osi_Write(tfile, off, cn->cellname, clen);
435 ReleaseWriteLock(&afs_xcell);
440 * Cell alias implementation
442 * afs_FindCellAlias: look up cell alias by alias name
443 * afs_GetCellAlias: get cell alias by index (starting at 0)
444 * afs_PutCellAlias: put back a cell alias returned by Find or Get
445 * afs_NewCellAlias: create new cell alias entry
448 struct cell_alias *afs_cellalias_head; /* Export for kdump */
449 static afs_int32 afs_cellalias_index;
450 static int afs_CellOrAliasExists_nl(char *aname); /* Forward declaration */
453 * Look up cell alias by alias name.
455 * \return Found struct or NULL.
457 static struct cell_alias *
458 afs_FindCellAlias(char *alias)
460 struct cell_alias *tc;
462 for (tc = afs_cellalias_head; tc != NULL; tc = tc->next)
463 if (!strcmp(alias, tc->alias))
469 * Get cell alias by index (starting at 0).
470 * \param index Cell index.
471 * \return Found struct or null.
474 afs_GetCellAlias(int index)
476 struct cell_alias *tc;
478 ObtainReadLock(&afs_xcell);
479 for (tc = afs_cellalias_head; tc != NULL; tc = tc->next)
480 if (tc->index == index)
482 ReleaseReadLock(&afs_xcell);
489 * Put back a cell alias returned by Find or Get.
494 afs_PutCellAlias(struct cell_alias *a)
500 * Create new cell alias entry and update dynroot vnode.
506 afs_NewCellAlias(char *alias, char *cell)
508 struct cell_alias *tc;
510 ObtainSharedLock(&afs_xcell, 681);
511 if (afs_CellOrAliasExists_nl(alias)) {
512 ReleaseSharedLock(&afs_xcell);
516 UpgradeSToWLock(&afs_xcell, 682);
517 tc = (struct cell_alias *)afs_osi_Alloc(sizeof(struct cell_alias));
518 tc->alias = afs_strdup(alias);
519 tc->cell = afs_strdup(cell);
520 tc->next = afs_cellalias_head;
521 tc->index = afs_cellalias_index++;
522 afs_cellalias_head = tc;
523 ReleaseWriteLock(&afs_xcell);
525 afs_DynrootInvalidate();
530 * Actual cell list implementation
532 * afs_UpdateCellLRU: bump given cell up to the front of the LRU queue
533 * afs_RefreshCell: look up cell information in AFSDB if timeout expired
535 * afs_TraverseCells: execute a callback for each existing cell
536 * afs_TraverseCells_nl: same as above except without locking afs_xcell
537 * afs_choose_cell_by_{name,num,index}: useful traversal callbacks
539 * afs_FindCellByName: return a cell with a given name, if it exists
540 * afs_FindCellByName_nl: same as above, without locking afs_xcell
541 * afs_GetCellByName: same as FindCellByName but tries AFSDB if not found
542 * afs_GetCell: return a cell with a given cell number
543 * afs_GetCellStale: same as GetCell, but does not try to refresh the data
544 * afs_GetCellByIndex: return a cell with a given index number (starting at 0)
546 * afs_GetPrimaryCell: return the primary cell, if any
547 * afs_IsPrimaryCell: returns true iff the given cell is the primary cell
548 * afs_IsPrimaryCellNum: returns afs_IsPrimaryCell(afs_GetCell(cellnum))
549 * afs_SetPrimaryCell: set the primary cell name to the given cell name
551 * afs_NewCell: create or update a cell entry
554 struct afs_q CellLRU; /* Export for kdump */
555 static char *afs_thiscell;
556 afs_int32 afs_cellindex; /* Export for kdump */
559 * Bump given cell up to the front of the LRU queue.
560 * \param c Cell to set.
563 afs_UpdateCellLRU(struct cell *c)
565 ObtainWriteLock(&afs_xcell, 100);
567 QAdd(&CellLRU, &c->lruq);
568 ReleaseWriteLock(&afs_xcell);
572 * Look up cell information in AFSDB if timeout expired
573 * \param ac Cell to be refreshed.
577 afs_RefreshCell(struct cell *ac)
579 if (ac->states & CNoAFSDB)
581 if (!ac->cellHosts[0] || (ac->timeout && ac->timeout <= osi_Time()))
582 afs_LookupAFSDB(ac->cellName);
586 * Execute a callback for each existing cell, without a lock on afs_xcell.
587 * Iterate on CellLRU, and execute a callback for each cell until given arguments are met.
588 * \see afs_TraverseCells
589 * \param cb Traversal callback for each cell.
590 * \param arg Callback arguments.
591 * \return Found data or NULL.
594 afs_TraverseCells_nl(void *(*cb) (struct cell *, void *), void *arg)
596 struct afs_q *cq, *tq;
600 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
603 /* This is assuming that a NULL return is acceptable. */
619 * Execute a callback for each existing cell, with a lock on afs_xcell.
620 * \see afs_TraverseCells_nl
621 * \param cb Traversal callback for each cell.
623 * \return Found data or NULL.
626 afs_TraverseCells(void *(*cb) (struct cell *, void *), void *arg)
630 ObtainReadLock(&afs_xcell);
631 ret = afs_TraverseCells_nl(cb, arg);
632 ReleaseReadLock(&afs_xcell);
638 * Useful traversal callback: Match by name.
640 * \param arg Cell name (compared with cell->cellName).
641 * \return Returns found cell or NULL.
644 afs_choose_cell_by_name(struct cell *cell, void *arg)
650 return strcmp(cell->cellName, (char *)arg) ? NULL : cell;
655 * Useful traversal callback: Match by handle.
657 * \param arg Cell handle (compared with cell->cellHandle).
658 * \return Returns found cell or NULL.
661 afs_choose_cell_by_handle(struct cell *cell, void *arg)
667 return memcmp(cell->cellHandle, (char *)arg, 16) ? NULL : cell;
672 * Useful traversal callback: Match by cell number.
674 * \param arg Cell number (compared with cell->cellNum).
675 * \return Returns found cell or NULL.
678 afs_choose_cell_by_num(struct cell *cell, void *arg)
680 return (cell->cellNum == *((afs_int32 *) arg)) ? cell : NULL;
684 * Useful traversal callback: Match by index.
686 * \param arg Cell index (compared with cell->cellIndex).
687 * \return Returns found cell or NULL.
690 afs_choose_cell_by_index(struct cell *cell, void *arg)
692 return (cell->cellIndex == *((afs_int32 *) arg)) ? cell : NULL;
696 * Return a cell with a given name, if it exists. No lock version.
697 * Does not check AFSDB.
698 * \param acellName Cell name.
699 * \param locktype Type of lock to be used (not used).
703 afs_FindCellByName_nl(char *acellName, afs_int32 locktype)
705 return afs_TraverseCells_nl(&afs_choose_cell_by_name, acellName);
709 * Return a cell with a given name, if it exists.It uses locks.
710 * Does not check AFSDB.
711 * \param acellName Cell name.
712 * \param locktype Type of lock to be used.
716 afs_FindCellByName(char *acellName, afs_int32 locktype)
718 return afs_TraverseCells(&afs_choose_cell_by_name, acellName);
722 * Same as FindCellByName but tries AFSDB if not found.
723 * \param acellName Cell name.
724 * \param locktype Type of lock to be used.
728 afs_GetCellByName(char *acellName, afs_int32 locktype)
732 tc = afs_FindCellByName(acellName, locktype);
734 afs_LookupAFSDB(acellName);
735 tc = afs_FindCellByName(acellName, locktype);
738 afs_cellname_ref(tc->cnamep);
739 afs_UpdateCellLRU(tc);
747 * Return a cell with a given cell number.
748 * \param cellnum Cell number.
749 * \param locktype Lock to be used.
753 afs_GetCell(afs_int32 cellnum, afs_int32 locktype)
756 struct cell_name *cn;
758 tc = afs_GetCellStale(cellnum, locktype);
762 ObtainReadLock(&afs_xcell);
763 cn = afs_cellname_lookup_id(cellnum);
764 ReleaseReadLock(&afs_xcell);
766 tc = afs_GetCellByName(cn->cellname, locktype);
772 * Same as GetCell, but does not try to refresh the data.
773 * \param cellnum Cell number.
774 * \param locktype What lock should be used.
778 afs_GetCellStale(afs_int32 cellnum, afs_int32 locktype)
782 tc = afs_TraverseCells(&afs_choose_cell_by_num, &cellnum);
784 afs_cellname_ref(tc->cnamep);
785 afs_UpdateCellLRU(tc);
791 * Return a cell with a given index number (starting at 0). Update CellLRU as well.
793 * \param locktype Type of lock used.
797 afs_GetCellByIndex(afs_int32 index, afs_int32 locktype)
801 tc = afs_TraverseCells(&afs_choose_cell_by_index, &index);
803 afs_UpdateCellLRU(tc);
808 * Return a cell with a given handle..
810 * \param locktype Type of lock used.
814 afs_GetCellByHandle(void *handle, afs_int32 locktype)
818 tc = afs_TraverseCells(&afs_choose_cell_by_handle, handle);
820 afs_UpdateCellLRU(tc);
825 * Return primary cell, if any.
826 * \param locktype Type of lock used.
830 afs_GetPrimaryCell(afs_int32 locktype)
832 return afs_GetCellByName(afs_thiscell, locktype);
836 * Returns true if the given cell is the primary cell.
841 afs_IsPrimaryCell(struct cell *cell)
843 /* Simple safe checking */
846 } else if (!afs_thiscell) {
847 /* This is simply a safety net to avoid seg faults especially when
848 * using a user-space library. afs_SetPrimaryCell() should be set
849 * prior to this call. */
850 afs_SetPrimaryCell(cell->cellName);
853 return strcmp(cell->cellName, afs_thiscell) ? 0 : 1;
858 * Returns afs_IsPrimaryCell(afs_GetCell(cellnum)).
863 afs_IsPrimaryCellNum(afs_int32 cellnum)
868 tc = afs_GetCellStale(cellnum, READ_LOCK);
870 primary = afs_IsPrimaryCell(tc);
871 afs_PutCell(tc, READ_LOCK);
878 * Set the primary cell name to the given cell name.
879 * \param acellName Cell name.
880 * \return 0 for success, < 0 for error.
883 afs_SetPrimaryCell(char *acellName)
885 ObtainWriteLock(&afs_xcell, 691);
887 afs_osi_FreeStr(afs_thiscell);
888 afs_thiscell = afs_strdup(acellName);
889 ReleaseWriteLock(&afs_xcell);
894 * Create or update a cell entry.
895 * \param acellName Name of cell.
896 * \param acellHosts Array of hosts that this cell has.
897 * \param aflags Cell flags.
899 * \param fsport File server port.
900 * \param vlport Volume server port.
901 * \param timeout Cell timeout value, 0 means static AFSDB entry.
905 afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags,
906 char *linkedcname, u_short fsport, u_short vlport, int timeout)
908 struct cell *tc, *tcl = 0;
909 afs_int32 i, newc = 0, code = 0;
911 AFS_STATCNT(afs_NewCell);
913 ObtainWriteLock(&afs_xcell, 103);
915 tc = afs_FindCellByName_nl(acellName, READ_LOCK);
919 tc = (struct cell *)afs_osi_Alloc(sizeof(struct cell));
920 memset((char *)tc, 0, sizeof(*tc));
921 tc->cellName = afs_strdup(acellName);
922 tc->fsport = AFS_FSPORT;
923 tc->vlport = AFS_VLPORT;
924 AFS_MD5_String(tc->cellHandle, tc->cellName, strlen(tc->cellName));
925 AFS_RWLOCK_INIT(&tc->lock, "cell lock");
929 ObtainWriteLock(&tc->lock, 688);
931 /* If the cell we've found has the correct name but no timeout,
932 * and we're called with a non-zero timeout, bail out: never
933 * override static configuration entries with AFSDB ones.
934 * One exception: if the original cell entry had no servers,
935 * it must get servers from AFSDB.
937 if (timeout && !tc->timeout && tc->cellHosts[0]) {
938 code = EEXIST; /* This code is checked for in afs_LookupAFSDB */
942 /* we don't want to keep pinging old vlservers which were down,
943 * since they don't matter any more. It's easier to do this than
944 * to remove the server from its various hash tables. */
945 for (i = 0; i < MAXCELLHOSTS; i++) {
946 if (!tc->cellHosts[i])
948 tc->cellHosts[i]->flags &= ~SRVR_ISDOWN;
949 tc->cellHosts[i]->flags |= SRVR_ISGONE;
957 if (aflags & CLinkedCell) {
962 tcl = afs_FindCellByName_nl(linkedcname, READ_LOCK);
967 if (tcl->lcellp) { /* XXX Overwriting if one existed before! XXX */
968 tcl->lcellp->lcellp = (struct cell *)0;
969 tcl->lcellp->states &= ~CLinkedCell;
974 tc->states |= aflags;
975 tc->timeout = timeout;
977 memset((char *)tc->cellHosts, 0, sizeof(tc->cellHosts));
978 for (i = 0; i < MAXCELLHOSTS; i++) {
979 /* Get server for each host and link this cell in.*/
981 afs_uint32 temp = acellHosts[i];
984 ts = afs_GetServer(&temp, 1, 0, tc->vlport, WRITE_LOCK, NULL, 0);
986 ts->flags &= ~SRVR_ISGONE;
987 /* Set the server as a host of the new cell. */
988 tc->cellHosts[i] = ts;
989 afs_PutServer(ts, WRITE_LOCK);
991 afs_SortServers(tc->cellHosts, MAXCELLHOSTS); /* randomize servers */
993 /* New cell: Build and add to LRU cell queue. */
995 struct cell_name *cn;
997 cn = afs_cellname_lookup_name(acellName);
999 cn = afs_cellname_new(acellName, 0);
1002 tc->cellNum = cn->cellnum;
1003 tc->cellIndex = afs_cellindex++;
1004 afs_stats_cmperf.numCellsVisible++;
1005 QAdd(&CellLRU, &tc->lruq);
1008 ReleaseWriteLock(&tc->lock);
1009 ReleaseWriteLock(&afs_xcell);
1011 afs_DynrootInvalidate();
1016 afs_osi_FreeStr(tc->cellName);
1017 afs_osi_Free(tc, sizeof(struct cell));
1019 ReleaseWriteLock(&tc->lock);
1020 ReleaseWriteLock(&afs_xcell);
1025 * Miscellaneous stuff
1027 * afs_CellInit: perform whatever initialization is necessary
1028 * shutdown_cell: called on shutdown, should deallocate memory, etc
1029 * afs_RemoveCellEntry: remove a server from a cell's server list
1030 * afs_CellOrAliasExists: check if the given name exists as a cell or alias
1031 * afs_CellOrAliasExists_nl: same as above without locking afs_xcell
1032 * afs_CellNumValid: check if a cell number is valid (also set the used flag)
1036 * Perform whatever initialization is necessary.
1041 AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
1042 #ifdef AFS_AFSDB_ENV
1043 AFS_RWLOCK_INIT(&afsdb_client_lock, "afsdb_client_lock");
1044 AFS_RWLOCK_INIT(&afsdb_req_lock, "afsdb_req_lock");
1049 afs_cellalias_index = 0;
1053 * Called on shutdown, should deallocate memory, etc.
1058 struct afs_q *cq, *tq;
1061 AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
1063 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
1067 afs_osi_FreeStr(tc->cellName);
1068 afs_osi_Free(tc, sizeof(struct cell));
1073 struct cell_name *cn = afs_cellname_head;
1076 struct cell_name *next = cn->next;
1078 afs_osi_FreeStr(cn->cellname);
1079 afs_osi_Free(cn, sizeof(struct cell_name));
1086 * Remove a server from a cell's server list.
1087 * \param srvp Server to be removed.
1091 afs_RemoveCellEntry(struct server *srvp)
1100 /* Remove the server structure from the cell list - if there */
1101 ObtainWriteLock(&tc->lock, 200);
1102 for (j = k = 0; j < MAXCELLHOSTS; j++) {
1103 if (!tc->cellHosts[j])
1105 if (tc->cellHosts[j] != srvp) {
1106 tc->cellHosts[k++] = tc->cellHosts[j];
1110 /* What do we do if we remove the last one? */
1112 for (; k < MAXCELLHOSTS; k++) {
1113 tc->cellHosts[k] = 0;
1115 ReleaseWriteLock(&tc->lock);
1119 * Check if the given name exists as a cell or alias. Does not lock afs_xcell.
1124 afs_CellOrAliasExists_nl(char *aname)
1127 struct cell_alias *ca;
1129 c = afs_FindCellByName_nl(aname, READ_LOCK);
1131 afs_PutCell(c, READ_LOCK);
1135 ca = afs_FindCellAlias(aname);
1137 afs_PutCellAlias(ca);
1145 * Check if the given name exists as a cell or alias. Locks afs_xcell.
1150 afs_CellOrAliasExists(char *aname)
1154 ObtainReadLock(&afs_xcell);
1155 ret = afs_CellOrAliasExists_nl(aname);
1156 ReleaseReadLock(&afs_xcell);
1162 * Check if a cell number is valid (also set the used flag).
1164 * \return 1 - true, 0 - false
1167 afs_CellNumValid(afs_int32 cellnum)
1169 struct cell_name *cn;
1171 ObtainReadLock(&afs_xcell);
1172 cn = afs_cellname_lookup_id(cellnum);
1173 ReleaseReadLock(&afs_xcell);