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"
20 #include "afs/sysincludes.h" /* Standard vendor system headers */
21 #include "afsincludes.h" /* Afs-based standard headers */
22 #include "afs/afs_stats.h" /* afs statistics */
23 #include "afs/afs_osi.h"
24 #include "afs/afs_md5.h"
26 /* Local variables. */
27 afs_rwlock_t afs_xcell; /* Export for cmdebug peeking at locks */
30 * AFSDB implementation:
32 * afs_StopAFSDB: terminate the AFSDB handler, used on shutdown
33 * afs_AFSDBHandler: entry point for user-space AFSDB request handler
34 * afs_GetCellHostsAFSDB: query the AFSDB handler and wait for response
35 * afs_LookupAFSDB: look up AFSDB for given cell name and create locally
39 afs_rwlock_t afsdb_client_lock; /* Serializes client requests */
40 afs_rwlock_t afsdb_req_lock; /* Serializes client requests */
41 static char afsdb_handler_running; /* Protected by GLOCK */
42 static char afsdb_handler_shutdown; /* Protected by GLOCK */
44 /* from cellconfig.h */
45 #define MAXCELLCHARS 64
47 /* lock moved to afsdb_req_lock for cmdebug */
54 * Terminate the AFSDB handler, used on shutdown.
59 if (afsdb_handler_running) {
60 afs_osi_Wakeup(&afsdb_req);
62 afsdb_handler_shutdown = 1;
63 afs_termState = AFSOP_STOP_RXEVENT;
68 * \brief Entry point for user-space AFSDB request handler.
69 * Reads cell data from kerlenMsg and add new cell, or alias.
70 * \param acellName Cell name. If a cell is found, it's name will be filled in here.
71 * \param acellNameLen Cell name length.
72 * \param kernelMsg Buffer containing data about host count, time out, and cell hosts ids.
73 * \return 0 for success, < 0 for error.
76 afs_AFSDBHandler(char *acellName, int acellNameLen, afs_int32 * kernelMsg)
78 afs_int32 timeout, code;
79 afs_int32 cellHosts[MAXCELLHOSTS];
81 if (afsdb_handler_shutdown)
83 afsdb_handler_running = 1;
85 ObtainSharedLock(&afsdb_req_lock, 683);
86 if (afsdb_req.pending) {
89 UpgradeSToWLock(&afsdb_req_lock, 684);
90 hostCount = kernelMsg[0];
91 timeout = kernelMsg[1];
93 timeout += osi_Time();
95 for (i = 0; i < MAXCELLHOSTS; i++) {
99 cellHosts[i] = kernelMsg[2 + i];
103 code = afs_NewCell(acellName, cellHosts, CNoSUID, NULL, 0, 0,
106 if (!hostCount || (code && code != EEXIST))
107 /* null out the cellname if the lookup failed */
108 afsdb_req.cellname = NULL;
110 /* If we found an alias, create it */
111 if (afs_strcasecmp(afsdb_req.cellname, acellName))
112 afs_NewCellAlias(afsdb_req.cellname, acellName);
114 /* Request completed, wake up the relevant thread */
115 afsdb_req.pending = 0;
116 afsdb_req.complete = 1;
117 afs_osi_Wakeup(&afsdb_req);
118 ConvertWToSLock(&afsdb_req_lock);
120 ConvertSToRLock(&afsdb_req_lock);
122 /* Wait for a request */
123 while (afsdb_req.pending == 0 && afs_termState != AFSOP_STOP_AFSDB) {
124 ReleaseReadLock(&afsdb_req_lock);
125 afs_osi_Sleep(&afsdb_req);
126 ObtainReadLock(&afsdb_req_lock);
129 /* Check if we're shutting down */
130 if (afs_termState == AFSOP_STOP_AFSDB) {
131 ReleaseReadLock(&afsdb_req_lock);
133 /* Inform anyone waiting for us that we're going away */
134 afsdb_handler_shutdown = 1;
135 afsdb_handler_running = 0;
136 afs_osi_Wakeup(&afsdb_req);
138 afs_termState = AFSOP_STOP_RXEVENT;
139 afs_osi_Wakeup(&afs_termState);
143 /* Return the lookup request to userspace */
144 strncpy(acellName, afsdb_req.cellname, acellNameLen);
145 ReleaseReadLock(&afsdb_req_lock);
150 * \brief Query the AFSDB handler and wait for response.
152 * \return 0 for success. < 0 is error.
155 afs_GetCellHostsAFSDB(char *acellName)
158 if (!afsdb_handler_running)
161 ObtainWriteLock(&afsdb_client_lock, 685);
162 ObtainWriteLock(&afsdb_req_lock, 686);
164 afsdb_req.cellname = acellName;
166 afsdb_req.complete = 0;
167 afsdb_req.pending = 1;
168 afs_osi_Wakeup(&afsdb_req);
169 ConvertWToRLock(&afsdb_req_lock);
171 while (afsdb_handler_running && !afsdb_req.complete) {
172 ReleaseReadLock(&afsdb_req_lock);
173 afs_osi_Sleep(&afsdb_req);
174 ObtainReadLock(&afsdb_req_lock);
177 ReleaseReadLock(&afsdb_req_lock);
178 ReleaseWriteLock(&afsdb_client_lock);
180 if (afsdb_req.cellname) {
189 * Look up AFSDB for given cell name and create locally.
190 * \param acellName Cell name.
193 afs_LookupAFSDB(char *acellName)
197 char *cellName = afs_strdup(acellName);
199 code = afs_GetCellHostsAFSDB(cellName);
200 afs_Trace2(afs_iclSetp, CM_TRACE_AFSDB, ICL_TYPE_STRING, cellName,
201 ICL_TYPE_INT32, code);
202 afs_osi_FreeStr(cellName);
207 * Cell name-to-ID mapping
209 * afs_cellname_new: create a new cell name, optional cell number
210 * afs_cellname_lookup_id: look up a cell name
211 * afs_cellname_lookup_name: look up a cell number
212 * afs_cellname_ref: note that this cell name was referenced somewhere
213 * afs_cellname_init: load the list of cells from given inode
214 * afs_cellname_write: write in-kernel list of cells to disk
217 struct cell_name *afs_cellname_head; /* Export for kdump */
218 static ino_t afs_cellname_inode;
219 static int afs_cellname_inode_set;
220 static int afs_cellname_dirty;
221 static afs_int32 afs_cellnum_next;
224 * Create a new cell name, optional cell number.
225 * \param name Name of cell.
226 * \param cellnum Cellname number.
227 * \return Initialized structure.
229 static struct cell_name *
230 afs_cellname_new(char *name, afs_int32 cellnum)
232 struct cell_name *cn;
235 cellnum = afs_cellnum_next;
237 cn = (struct cell_name *)afs_osi_Alloc(sizeof(*cn));
238 cn->next = afs_cellname_head;
239 cn->cellnum = cellnum;
240 cn->cellname = afs_strdup(name);
242 afs_cellname_head = cn;
244 if (cellnum >= afs_cellnum_next)
245 afs_cellnum_next = cellnum + 1;
251 * Look up a cell name by id.
255 static struct cell_name *
256 afs_cellname_lookup_id(afs_int32 cellnum)
258 struct cell_name *cn;
260 for (cn = afs_cellname_head; cn; cn = cn->next)
261 if (cn->cellnum == cellnum)
268 * Look up a cell name.
269 * \param name Cell name.
272 static struct cell_name *
273 afs_cellname_lookup_name(char *name)
275 struct cell_name *cn;
277 for (cn = afs_cellname_head; cn; cn = cn->next)
278 if (strcmp(cn->cellname, name) == 0)
285 * Note that this cell name was referenced somewhere.
289 afs_cellname_ref(struct cell_name *cn)
293 afs_cellname_dirty = 1;
298 * \brief Load the list of cells from given inode.
299 * \param inode Source inode.
301 * \return 0 for success. < 0 for error.
304 afs_cellname_init(ino_t inode, int lookupcode)
306 struct osi_file *tfile;
309 ObtainWriteLock(&afs_xcell, 692);
311 afs_cellnum_next = 1;
312 afs_cellname_dirty = 0;
314 if (cacheDiskType == AFS_FCACHE_TYPE_MEM) {
315 ReleaseWriteLock(&afs_xcell);
319 ReleaseWriteLock(&afs_xcell);
323 tfile = osi_UFSOpen(inode);
325 ReleaseWriteLock(&afs_xcell);
329 afs_cellname_inode = inode;
330 afs_cellname_inode_set = 1;
333 afs_int32 cellnum, clen, magic;
334 struct cell_name *cn;
337 cc = afs_osi_Read(tfile, off, &magic, sizeof(magic));
338 if (cc != sizeof(magic))
340 if (magic != AFS_CELLINFO_MAGIC)
344 cc = afs_osi_Read(tfile, off, &cellnum, sizeof(cellnum));
345 if (cc != sizeof(cellnum))
349 cc = afs_osi_Read(tfile, off, &clen, sizeof(clen));
350 if (cc != sizeof(clen))
354 cellname = afs_osi_Alloc(clen + 1);
358 cc = afs_osi_Read(tfile, off, cellname, clen);
360 afs_osi_Free(cellname, clen + 1);
364 cellname[clen] = '\0';
366 if (afs_cellname_lookup_name(cellname)
367 || afs_cellname_lookup_id(cellnum)) {
368 afs_osi_Free(cellname, clen + 1);
372 cn = afs_cellname_new(cellname, cellnum);
373 afs_osi_Free(cellname, clen + 1);
377 ReleaseWriteLock(&afs_xcell);
382 * Write in-kernel list of cells to disk.
385 afs_cellname_write(void)
387 struct osi_file *tfile;
388 struct cell_name *cn;
391 if (!afs_cellname_dirty || !afs_cellname_inode_set)
393 if (afs_initState != 300)
396 ObtainWriteLock(&afs_xcell, 693);
397 afs_cellname_dirty = 0;
399 tfile = osi_UFSOpen(afs_cellname_inode);
401 ReleaseWriteLock(&afs_xcell);
405 for (cn = afs_cellname_head; cn; cn = cn->next) {
406 afs_int32 magic, cellnum, clen;
412 magic = AFS_CELLINFO_MAGIC;
413 cc = afs_osi_Write(tfile, off, &magic, sizeof(magic));
414 if (cc != sizeof(magic))
418 cellnum = cn->cellnum;
419 cc = afs_osi_Write(tfile, off, &cellnum, sizeof(cellnum));
420 if (cc != sizeof(cellnum))
424 clen = strlen(cn->cellname);
425 cc = afs_osi_Write(tfile, off, &clen, sizeof(clen));
426 if (cc != sizeof(clen))
430 cc = afs_osi_Write(tfile, off, cn->cellname, clen);
437 ReleaseWriteLock(&afs_xcell);
442 * Cell alias implementation
444 * afs_FindCellAlias: look up cell alias by alias name
445 * afs_GetCellAlias: get cell alias by index (starting at 0)
446 * afs_PutCellAlias: put back a cell alias returned by Find or Get
447 * afs_NewCellAlias: create new cell alias entry
450 struct cell_alias *afs_cellalias_head; /* Export for kdump */
451 static afs_int32 afs_cellalias_index;
452 static int afs_CellOrAliasExists_nl(char *aname); /* Forward declaration */
455 * Look up cell alias by alias name.
457 * \return Found struct or NULL.
459 static struct cell_alias *
460 afs_FindCellAlias(char *alias)
462 struct cell_alias *tc;
464 for (tc = afs_cellalias_head; tc != NULL; tc = tc->next)
465 if (!strcmp(alias, tc->alias))
471 * Get cell alias by index (starting at 0).
472 * \param index Cell index.
473 * \return Found struct or null.
476 afs_GetCellAlias(int index)
478 struct cell_alias *tc;
480 ObtainReadLock(&afs_xcell);
481 for (tc = afs_cellalias_head; tc != NULL; tc = tc->next)
482 if (tc->index == index)
484 ReleaseReadLock(&afs_xcell);
491 * Put back a cell alias returned by Find or Get.
496 afs_PutCellAlias(struct cell_alias *a)
502 * Create new cell alias entry and update dynroot vnode.
508 afs_NewCellAlias(char *alias, char *cell)
510 struct cell_alias *tc;
512 ObtainSharedLock(&afs_xcell, 681);
513 if (afs_CellOrAliasExists_nl(alias)) {
514 ReleaseSharedLock(&afs_xcell);
518 UpgradeSToWLock(&afs_xcell, 682);
519 tc = (struct cell_alias *)afs_osi_Alloc(sizeof(struct cell_alias));
520 tc->alias = afs_strdup(alias);
521 tc->cell = afs_strdup(cell);
522 tc->next = afs_cellalias_head;
523 tc->index = afs_cellalias_index++;
524 afs_cellalias_head = tc;
525 ReleaseWriteLock(&afs_xcell);
527 afs_DynrootInvalidate();
532 * Actual cell list implementation
534 * afs_UpdateCellLRU: bump given cell up to the front of the LRU queue
535 * afs_RefreshCell: look up cell information in AFSDB if timeout expired
537 * afs_TraverseCells: execute a callback for each existing cell
538 * afs_TraverseCells_nl: same as above except without locking afs_xcell
539 * afs_choose_cell_by_{name,num,index}: useful traversal callbacks
541 * afs_FindCellByName: return a cell with a given name, if it exists
542 * afs_FindCellByName_nl: same as above, without locking afs_xcell
543 * afs_GetCellByName: same as FindCellByName but tries AFSDB if not found
544 * afs_GetCell: return a cell with a given cell number
545 * afs_GetCellStale: same as GetCell, but does not try to refresh the data
546 * afs_GetCellByIndex: return a cell with a given index number (starting at 0)
548 * afs_GetPrimaryCell: return the primary cell, if any
549 * afs_IsPrimaryCell: returns true iff the given cell is the primary cell
550 * afs_IsPrimaryCellNum: returns afs_IsPrimaryCell(afs_GetCell(cellnum))
551 * afs_SetPrimaryCell: set the primary cell name to the given cell name
553 * afs_NewCell: create or update a cell entry
556 struct afs_q CellLRU; /* Export for kdump */
557 static char *afs_thiscell;
558 afs_int32 afs_cellindex; /* Export for kdump */
561 * Bump given cell up to the front of the LRU queue.
562 * \param c Cell to set.
565 afs_UpdateCellLRU(struct cell *c)
567 ObtainWriteLock(&afs_xcell, 100);
569 QAdd(&CellLRU, &c->lruq);
570 ReleaseWriteLock(&afs_xcell);
574 * Look up cell information in AFSDB if timeout expired
575 * \param ac Cell to be refreshed.
579 afs_RefreshCell(struct cell *ac)
581 if (ac->states & CNoAFSDB)
583 if (!ac->cellHosts[0] || (ac->timeout && ac->timeout <= osi_Time()))
584 afs_LookupAFSDB(ac->cellName);
588 * Execute a callback for each existing cell, without a lock on afs_xcell.
589 * Iterate on CellLRU, and execute a callback for each cell until given arguments are met.
590 * \see afs_TraverseCells
591 * \param cb Traversal callback for each cell.
592 * \param arg Callback arguments.
593 * \return Found data or NULL.
596 afs_TraverseCells_nl(void *(*cb) (struct cell *, void *), void *arg)
598 struct afs_q *cq, *tq;
602 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
605 /* This is assuming that a NULL return is acceptable. */
621 * Execute a callback for each existing cell, with a lock on afs_xcell.
622 * \see afs_TraverseCells_nl
623 * \param cb Traversal callback for each cell.
625 * \return Found data or NULL.
628 afs_TraverseCells(void *(*cb) (struct cell *, void *), void *arg)
632 ObtainReadLock(&afs_xcell);
633 ret = afs_TraverseCells_nl(cb, arg);
634 ReleaseReadLock(&afs_xcell);
640 * Useful traversal callback: Match by name.
642 * \param arg Cell name (compared with cell->cellName).
643 * \return Returns found cell or NULL.
646 afs_choose_cell_by_name(struct cell *cell, void *arg)
652 return strcmp(cell->cellName, (char *)arg) ? NULL : cell;
657 * Useful traversal callback: Match by handle.
659 * \param arg Cell handle (compared with cell->cellHandle).
660 * \return Returns found cell or NULL.
663 afs_choose_cell_by_handle(struct cell *cell, void *arg)
669 return memcmp(cell->cellHandle, (char *)arg, 16) ? NULL : cell;
674 * Useful traversal callback: Match by cell number.
676 * \param arg Cell number (compared with cell->cellNum).
677 * \return Returns found cell or NULL.
680 afs_choose_cell_by_num(struct cell *cell, void *arg)
682 return (cell->cellNum == *((afs_int32 *) arg)) ? cell : NULL;
686 * Useful traversal callback: Match by index.
688 * \param arg Cell index (compared with cell->cellIndex).
689 * \return Returns found cell or NULL.
692 afs_choose_cell_by_index(struct cell *cell, void *arg)
694 return (cell->cellIndex == *((afs_int32 *) arg)) ? cell : NULL;
698 * Return a cell with a given name, if it exists. No lock version.
699 * Does not check AFSDB.
700 * \param acellName Cell name.
701 * \param locktype Type of lock to be used (not used).
705 afs_FindCellByName_nl(char *acellName, afs_int32 locktype)
707 return afs_TraverseCells_nl(&afs_choose_cell_by_name, acellName);
711 * Return a cell with a given name, if it exists.It uses locks.
712 * Does not check AFSDB.
713 * \param acellName Cell name.
714 * \param locktype Type of lock to be used.
718 afs_FindCellByName(char *acellName, afs_int32 locktype)
720 return afs_TraverseCells(&afs_choose_cell_by_name, acellName);
724 * Same as FindCellByName but tries AFSDB if not found.
725 * \param acellName Cell name.
726 * \param locktype Type of lock to be used.
730 afs_GetCellByName(char *acellName, afs_int32 locktype)
734 tc = afs_FindCellByName(acellName, locktype);
736 afs_LookupAFSDB(acellName);
737 tc = afs_FindCellByName(acellName, locktype);
740 afs_cellname_ref(tc->cnamep);
741 afs_UpdateCellLRU(tc);
749 * Return a cell with a given cell number.
750 * \param cellnum Cell number.
751 * \param locktype Lock to be used.
755 afs_GetCell(afs_int32 cellnum, afs_int32 locktype)
758 struct cell_name *cn;
760 tc = afs_GetCellStale(cellnum, locktype);
764 ObtainReadLock(&afs_xcell);
765 cn = afs_cellname_lookup_id(cellnum);
766 ReleaseReadLock(&afs_xcell);
768 tc = afs_GetCellByName(cn->cellname, locktype);
774 * Same as GetCell, but does not try to refresh the data.
775 * \param cellnum Cell number.
776 * \param locktype What lock should be used.
780 afs_GetCellStale(afs_int32 cellnum, afs_int32 locktype)
784 tc = afs_TraverseCells(&afs_choose_cell_by_num, &cellnum);
786 afs_cellname_ref(tc->cnamep);
787 afs_UpdateCellLRU(tc);
793 * Return a cell with a given index number (starting at 0). Update CellLRU as well.
795 * \param locktype Type of lock used.
799 afs_GetCellByIndex(afs_int32 index, afs_int32 locktype)
803 tc = afs_TraverseCells(&afs_choose_cell_by_index, &index);
805 afs_UpdateCellLRU(tc);
810 * Return a cell with a given handle..
812 * \param locktype Type of lock used.
816 afs_GetCellByHandle(void *handle, afs_int32 locktype)
820 tc = afs_TraverseCells(&afs_choose_cell_by_handle, handle);
822 afs_UpdateCellLRU(tc);
827 * Return primary cell, if any.
828 * \param locktype Type of lock used.
832 afs_GetPrimaryCell(afs_int32 locktype)
834 return afs_GetCellByName(afs_thiscell, locktype);
838 * Returns true if the given cell is the primary cell.
843 afs_IsPrimaryCell(struct cell *cell)
845 /* Simple safe checking */
848 } else if (!afs_thiscell) {
849 /* This is simply a safety net to avoid seg faults especially when
850 * using a user-space library. afs_SetPrimaryCell() should be set
851 * prior to this call. */
852 afs_SetPrimaryCell(cell->cellName);
855 return strcmp(cell->cellName, afs_thiscell) ? 0 : 1;
860 * Returns afs_IsPrimaryCell(afs_GetCell(cellnum)).
865 afs_IsPrimaryCellNum(afs_int32 cellnum)
870 tc = afs_GetCellStale(cellnum, READ_LOCK);
872 primary = afs_IsPrimaryCell(tc);
873 afs_PutCell(tc, READ_LOCK);
880 * Set the primary cell name to the given cell name.
881 * \param acellName Cell name.
882 * \return 0 for success, < 0 for error.
885 afs_SetPrimaryCell(char *acellName)
887 ObtainWriteLock(&afs_xcell, 691);
889 afs_osi_FreeStr(afs_thiscell);
890 afs_thiscell = afs_strdup(acellName);
891 ReleaseWriteLock(&afs_xcell);
896 * Create or update a cell entry.
897 * \param acellName Name of cell.
898 * \param acellHosts Array of hosts that this cell has.
899 * \param aflags Cell flags.
901 * \param fsport File server port.
902 * \param vlport Volume server port.
903 * \param timeout Cell timeout value, 0 means static AFSDB entry.
907 afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags,
908 char *linkedcname, u_short fsport, u_short vlport, int timeout)
910 struct cell *tc, *tcl = 0;
911 afs_int32 i, newc = 0, code = 0;
913 AFS_STATCNT(afs_NewCell);
915 ObtainWriteLock(&afs_xcell, 103);
917 tc = afs_FindCellByName_nl(acellName, READ_LOCK);
921 tc = (struct cell *)afs_osi_Alloc(sizeof(struct cell));
922 memset((char *)tc, 0, sizeof(*tc));
923 tc->cellName = afs_strdup(acellName);
924 tc->fsport = AFS_FSPORT;
925 tc->vlport = AFS_VLPORT;
926 AFS_MD5_String(tc->cellHandle, tc->cellName, strlen(tc->cellName));
927 RWLOCK_INIT(&tc->lock, "cell lock");
931 ObtainWriteLock(&tc->lock, 688);
933 /* If the cell we've found has the correct name but no timeout,
934 * and we're called with a non-zero timeout, bail out: never
935 * override static configuration entries with AFSDB ones.
936 * One exception: if the original cell entry had no servers,
937 * it must get servers from AFSDB.
939 if (timeout && !tc->timeout && tc->cellHosts[0]) {
940 code = EEXIST; /* This code is checked for in afs_LookupAFSDB */
944 /* we don't want to keep pinging old vlservers which were down,
945 * since they don't matter any more. It's easier to do this than
946 * to remove the server from its various hash tables. */
947 for (i = 0; i < MAXCELLHOSTS; i++) {
948 if (!tc->cellHosts[i])
950 tc->cellHosts[i]->flags &= ~SRVR_ISDOWN;
951 tc->cellHosts[i]->flags |= SRVR_ISGONE;
959 if (aflags & CLinkedCell) {
964 tcl = afs_FindCellByName_nl(linkedcname, READ_LOCK);
969 if (tcl->lcellp) { /* XXX Overwriting if one existed before! XXX */
970 tcl->lcellp->lcellp = (struct cell *)0;
971 tcl->lcellp->states &= ~CLinkedCell;
976 tc->states |= aflags;
977 tc->timeout = timeout;
979 memset((char *)tc->cellHosts, 0, sizeof(tc->cellHosts));
980 for (i = 0; i < MAXCELLHOSTS; i++) {
981 /* Get server for each host and link this cell in.*/
983 afs_uint32 temp = acellHosts[i];
986 ts = afs_GetServer(&temp, 1, 0, tc->vlport, WRITE_LOCK, NULL, 0);
988 ts->flags &= ~SRVR_ISGONE;
989 /* Set the server as a host of the new cell. */
990 tc->cellHosts[i] = ts;
991 afs_PutServer(ts, WRITE_LOCK);
993 afs_SortServers(tc->cellHosts, MAXCELLHOSTS); /* randomize servers */
995 /* New cell: Build and add to LRU cell queue. */
997 struct cell_name *cn;
999 cn = afs_cellname_lookup_name(acellName);
1001 cn = afs_cellname_new(acellName, 0);
1004 tc->cellNum = cn->cellnum;
1005 tc->cellIndex = afs_cellindex++;
1006 afs_stats_cmperf.numCellsVisible++;
1007 QAdd(&CellLRU, &tc->lruq);
1010 ReleaseWriteLock(&tc->lock);
1011 ReleaseWriteLock(&afs_xcell);
1013 afs_DynrootInvalidate();
1018 afs_osi_FreeStr(tc->cellName);
1019 afs_osi_Free(tc, sizeof(struct cell));
1021 ReleaseWriteLock(&tc->lock);
1022 ReleaseWriteLock(&afs_xcell);
1027 * Miscellaneous stuff
1029 * afs_CellInit: perform whatever initialization is necessary
1030 * shutdown_cell: called on shutdown, should deallocate memory, etc
1031 * afs_RemoveCellEntry: remove a server from a cell's server list
1032 * afs_CellOrAliasExists: check if the given name exists as a cell or alias
1033 * afs_CellOrAliasExists_nl: same as above without locking afs_xcell
1034 * afs_CellNumValid: check if a cell number is valid (also set the used flag)
1038 * Perform whatever initialization is necessary.
1043 RWLOCK_INIT(&afs_xcell, "afs_xcell");
1044 #ifdef AFS_AFSDB_ENV
1045 RWLOCK_INIT(&afsdb_client_lock, "afsdb_client_lock");
1046 RWLOCK_INIT(&afsdb_req_lock, "afsdb_req_lock");
1051 afs_cellalias_index = 0;
1055 * Called on shutdown, should deallocate memory, etc.
1060 struct afs_q *cq, *tq;
1063 RWLOCK_INIT(&afs_xcell, "afs_xcell");
1065 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
1069 afs_osi_FreeStr(tc->cellName);
1070 afs_osi_Free(tc, sizeof(struct cell));
1075 struct cell_name *cn = afs_cellname_head;
1078 struct cell_name *next = cn->next;
1080 afs_osi_FreeStr(cn->cellname);
1081 afs_osi_Free(cn, sizeof(struct cell_name));
1088 * Remove a server from a cell's server list.
1089 * \param srvp Server to be removed.
1093 afs_RemoveCellEntry(struct server *srvp)
1102 /* Remove the server structure from the cell list - if there */
1103 ObtainWriteLock(&tc->lock, 200);
1104 for (j = k = 0; j < MAXCELLHOSTS; j++) {
1105 if (!tc->cellHosts[j])
1107 if (tc->cellHosts[j] != srvp) {
1108 tc->cellHosts[k++] = tc->cellHosts[j];
1112 /* What do we do if we remove the last one? */
1114 for (; k < MAXCELLHOSTS; k++) {
1115 tc->cellHosts[k] = 0;
1117 ReleaseWriteLock(&tc->lock);
1121 * Check if the given name exists as a cell or alias. Does not lock afs_xcell.
1126 afs_CellOrAliasExists_nl(char *aname)
1129 struct cell_alias *ca;
1131 c = afs_FindCellByName_nl(aname, READ_LOCK);
1133 afs_PutCell(c, READ_LOCK);
1137 ca = afs_FindCellAlias(aname);
1139 afs_PutCellAlias(ca);
1147 * Check if the given name exists as a cell or alias. Locks afs_xcell.
1152 afs_CellOrAliasExists(char *aname)
1156 ObtainReadLock(&afs_xcell);
1157 ret = afs_CellOrAliasExists_nl(aname);
1158 ReleaseReadLock(&afs_xcell);
1164 * Check if a cell number is valid (also set the used flag).
1166 * \return 1 - true, 0 - false
1169 afs_CellNumValid(afs_int32 cellnum)
1171 struct cell_name *cn;
1173 ObtainReadLock(&afs_xcell);
1174 cn = afs_cellname_lookup_id(cellnum);
1175 ReleaseReadLock(&afs_xcell);