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
36 afs_rwlock_t afsdb_client_lock; /* Serializes client requests */
37 afs_rwlock_t afsdb_req_lock; /* Serializes client requests */
38 static char afsdb_handler_running; /* Protected by GLOCK */
39 static char afsdb_handler_shutdown; /* Protected by GLOCK */
41 /* from cellconfig.h */
42 #define MAXCELLCHARS 64
44 /* lock moved to afsdb_req_lock for cmdebug */
51 * Terminate the AFSDB handler, used on shutdown.
56 if (afsdb_handler_running) {
57 afs_osi_Wakeup(&afsdb_req);
59 afsdb_handler_shutdown = 1;
60 afs_termState = AFSOP_STOP_RXEVENT;
61 afs_osi_Wakeup(&afs_termState);
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[AFS_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 < AFS_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) {
186 * Look up AFSDB for given cell name and create locally.
187 * \param acellName Cell name.
190 afs_LookupAFSDB(char *acellName)
193 char *cellName = afs_strdup(acellName);
195 code = afs_GetCellHostsAFSDB(cellName);
196 afs_Trace2(afs_iclSetp, CM_TRACE_AFSDB, ICL_TYPE_STRING, cellName,
197 ICL_TYPE_INT32, code);
198 afs_osi_FreeStr(cellName);
202 * Cell name-to-ID mapping
204 * afs_cellname_new: create a new cell name, optional cell number
205 * afs_cellname_lookup_id: look up a cell name
206 * afs_cellname_lookup_name: look up a cell number
207 * afs_cellname_ref: note that this cell name was referenced somewhere
208 * afs_cellname_init: load the list of cells from given inode
209 * afs_cellname_write: write in-kernel list of cells to disk
212 struct cell_name *afs_cellname_head; /* Export for kdump */
213 static afs_dcache_id_t afs_cellname_inode;
214 static int afs_cellname_inode_set;
215 static int afs_cellname_dirty;
216 static afs_int32 afs_cellnum_next;
219 * Create a new cell name, optional cell number.
220 * \param name Name of cell.
221 * \param cellnum Cellname number.
222 * \return Initialized structure.
224 static struct cell_name *
225 afs_cellname_new(char *name, afs_int32 cellnum)
227 struct cell_name *cn;
230 cellnum = afs_cellnum_next;
232 cn = (struct cell_name *)afs_osi_Alloc(sizeof(*cn));
233 cn->next = afs_cellname_head;
234 cn->cellnum = cellnum;
235 cn->cellname = afs_strdup(name);
237 afs_cellname_head = cn;
239 if (cellnum >= afs_cellnum_next)
240 afs_cellnum_next = cellnum + 1;
246 * Look up a cell name by id.
250 static struct cell_name *
251 afs_cellname_lookup_id(afs_int32 cellnum)
253 struct cell_name *cn;
255 for (cn = afs_cellname_head; cn; cn = cn->next)
256 if (cn->cellnum == cellnum)
263 * Look up a cell name.
264 * \param name Cell name.
267 static struct cell_name *
268 afs_cellname_lookup_name(char *name)
270 struct cell_name *cn;
272 for (cn = afs_cellname_head; cn; cn = cn->next)
273 if (strcmp(cn->cellname, name) == 0)
280 * Note that this cell name was referenced somewhere.
284 afs_cellname_ref(struct cell_name *cn)
288 afs_cellname_dirty = 1;
293 * \brief Load the list of cells from given inode.
294 * \param inode Source inode.
296 * \return 0 for success. < 0 for error.
299 afs_cellname_init(afs_dcache_id_t *inode, int lookupcode)
301 struct osi_file *tfile;
304 ObtainWriteLock(&afs_xcell, 692);
306 afs_cellnum_next = 1;
307 afs_cellname_dirty = 0;
309 if (cacheDiskType == AFS_FCACHE_TYPE_MEM) {
310 ReleaseWriteLock(&afs_xcell);
314 ReleaseWriteLock(&afs_xcell);
318 tfile = osi_UFSOpen(inode);
320 ReleaseWriteLock(&afs_xcell);
324 afs_copy_inode(&afs_cellname_inode, inode);
325 afs_cellname_inode_set = 1;
328 afs_int32 cellnum, clen, magic;
329 struct cell_name *cn;
332 cc = afs_osi_Read(tfile, off, &magic, sizeof(magic));
333 if (cc != sizeof(magic))
335 if (magic != AFS_CELLINFO_MAGIC)
339 cc = afs_osi_Read(tfile, off, &cellnum, sizeof(cellnum));
340 if (cc != sizeof(cellnum))
344 cc = afs_osi_Read(tfile, off, &clen, sizeof(clen));
345 if (cc != sizeof(clen))
349 cellname = afs_osi_Alloc(clen + 1);
353 cc = afs_osi_Read(tfile, off, cellname, clen);
355 afs_osi_Free(cellname, clen + 1);
359 cellname[clen] = '\0';
361 if (afs_cellname_lookup_name(cellname)
362 || afs_cellname_lookup_id(cellnum)) {
363 afs_osi_Free(cellname, clen + 1);
367 cn = afs_cellname_new(cellname, cellnum);
368 afs_osi_Free(cellname, clen + 1);
372 ReleaseWriteLock(&afs_xcell);
377 * Write in-kernel list of cells to disk.
380 afs_cellname_write(void)
382 struct osi_file *tfile;
383 struct cell_name *cn;
386 if (!afs_cellname_dirty || !afs_cellname_inode_set)
388 if (afs_initState != 300)
391 ObtainWriteLock(&afs_xcell, 693);
392 afs_cellname_dirty = 0;
394 tfile = osi_UFSOpen(&afs_cellname_inode);
396 ReleaseWriteLock(&afs_xcell);
400 for (cn = afs_cellname_head; cn; cn = cn->next) {
401 afs_int32 magic, cellnum, clen;
407 magic = AFS_CELLINFO_MAGIC;
408 cc = afs_osi_Write(tfile, off, &magic, sizeof(magic));
409 if (cc != sizeof(magic))
413 cellnum = cn->cellnum;
414 cc = afs_osi_Write(tfile, off, &cellnum, sizeof(cellnum));
415 if (cc != sizeof(cellnum))
419 clen = strlen(cn->cellname);
420 cc = afs_osi_Write(tfile, off, &clen, sizeof(clen));
421 if (cc != sizeof(clen))
425 cc = afs_osi_Write(tfile, off, cn->cellname, clen);
432 ReleaseWriteLock(&afs_xcell);
437 * Cell alias implementation
439 * afs_FindCellAlias: look up cell alias by alias name
440 * afs_GetCellAlias: get cell alias by index (starting at 0)
441 * afs_PutCellAlias: put back a cell alias returned by Find or Get
442 * afs_NewCellAlias: create new cell alias entry
445 struct cell_alias *afs_cellalias_head; /* Export for kdump */
446 static afs_int32 afs_cellalias_index;
447 static int afs_CellOrAliasExists_nl(char *aname); /* Forward declaration */
450 * Look up cell alias by alias name.
452 * \return Found struct or NULL.
454 static struct cell_alias *
455 afs_FindCellAlias(char *alias)
457 struct cell_alias *tc;
459 for (tc = afs_cellalias_head; tc != NULL; tc = tc->next)
460 if (!strcmp(alias, tc->alias))
466 * Get cell alias by index (starting at 0).
467 * \param index Cell index.
468 * \return Found struct or null.
471 afs_GetCellAlias(int index)
473 struct cell_alias *tc;
475 ObtainReadLock(&afs_xcell);
476 for (tc = afs_cellalias_head; tc != NULL; tc = tc->next)
477 if (tc->index == index)
479 ReleaseReadLock(&afs_xcell);
486 * Put back a cell alias returned by Find or Get.
491 afs_PutCellAlias(struct cell_alias *a)
497 * Create new cell alias entry and update dynroot vnode.
503 afs_NewCellAlias(char *alias, char *cell)
505 struct cell_alias *tc;
507 ObtainSharedLock(&afs_xcell, 681);
508 if (afs_CellOrAliasExists_nl(alias)) {
509 ReleaseSharedLock(&afs_xcell);
513 UpgradeSToWLock(&afs_xcell, 682);
514 tc = (struct cell_alias *)afs_osi_Alloc(sizeof(struct cell_alias));
515 tc->alias = afs_strdup(alias);
516 tc->cell = afs_strdup(cell);
517 tc->next = afs_cellalias_head;
518 tc->index = afs_cellalias_index++;
519 afs_cellalias_head = tc;
520 ReleaseWriteLock(&afs_xcell);
522 afs_DynrootInvalidate();
527 * Actual cell list implementation
529 * afs_UpdateCellLRU: bump given cell up to the front of the LRU queue
530 * afs_RefreshCell: look up cell information in AFSDB if timeout expired
532 * afs_TraverseCells: execute a callback for each existing cell
533 * afs_TraverseCells_nl: same as above except without locking afs_xcell
534 * afs_choose_cell_by_{name,num,index}: useful traversal callbacks
536 * afs_FindCellByName: return a cell with a given name, if it exists
537 * afs_FindCellByName_nl: same as above, without locking afs_xcell
538 * afs_GetCellByName: same as FindCellByName but tries AFSDB if not found
539 * afs_GetCell: return a cell with a given cell number
540 * afs_GetCellStale: same as GetCell, but does not try to refresh the data
541 * afs_GetCellByIndex: return a cell with a given index number (starting at 0)
543 * afs_GetPrimaryCell: return the primary cell, if any
544 * afs_IsPrimaryCell: returns true iff the given cell is the primary cell
545 * afs_IsPrimaryCellNum: returns afs_IsPrimaryCell(afs_GetCell(cellnum))
546 * afs_SetPrimaryCell: set the primary cell name to the given cell name
548 * afs_NewCell: create or update a cell entry
551 struct afs_q CellLRU; /* Export for kdump */
552 static char *afs_thiscell = NULL;
553 afs_int32 afs_cellindex; /* Export for kdump */
556 * Bump given cell up to the front of the LRU queue.
557 * \param c Cell to set.
560 afs_UpdateCellLRU(struct cell *c)
562 ObtainWriteLock(&afs_xcell, 100);
564 QAdd(&CellLRU, &c->lruq);
565 ReleaseWriteLock(&afs_xcell);
569 * Look up cell information in AFSDB if timeout expired
570 * \param ac Cell to be refreshed.
574 afs_RefreshCell(struct cell *ac)
576 if (ac->states & CNoAFSDB)
578 if (!ac->cellHosts[0] || (ac->timeout && ac->timeout <= osi_Time()))
579 afs_LookupAFSDB(ac->cellName);
583 * Execute a callback for each existing cell, without a lock on afs_xcell.
584 * Iterate on CellLRU, and execute a callback for each cell until given arguments are met.
585 * \see afs_TraverseCells
586 * \param cb Traversal callback for each cell.
587 * \param arg Callback arguments.
588 * \return Found data or NULL.
591 afs_TraverseCells_nl(void *(*cb) (struct cell *, void *), void *arg)
593 struct afs_q *cq, *tq;
597 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
600 /* This is assuming that a NULL return is acceptable. */
616 * Execute a callback for each existing cell, with a lock on afs_xcell.
617 * \see afs_TraverseCells_nl
618 * \param cb Traversal callback for each cell.
620 * \return Found data or NULL.
623 afs_TraverseCells(void *(*cb) (struct cell *, void *), void *arg)
627 ObtainReadLock(&afs_xcell);
628 ret = afs_TraverseCells_nl(cb, arg);
629 ReleaseReadLock(&afs_xcell);
635 * Useful traversal callback: Match by name.
637 * \param arg Cell name (compared with cell->cellName).
638 * \return Returns found cell or NULL.
641 afs_choose_cell_by_name(struct cell *cell, void *arg)
647 return strcmp(cell->cellName, (char *)arg) ? NULL : cell;
652 * Useful traversal callback: Match by handle.
654 * \param arg Cell handle (compared with cell->cellHandle).
655 * \return Returns found cell or NULL.
658 afs_choose_cell_by_handle(struct cell *cell, void *arg)
664 return memcmp(cell->cellHandle, (char *)arg, 16) ? NULL : cell;
669 * Useful traversal callback: Match by cell number.
671 * \param arg Cell number (compared with cell->cellNum).
672 * \return Returns found cell or NULL.
675 afs_choose_cell_by_num(struct cell *cell, void *arg)
677 return (cell->cellNum == *((afs_int32 *) arg)) ? cell : NULL;
681 * Useful traversal callback: Match by index.
683 * \param arg Cell index (compared with cell->cellIndex).
684 * \return Returns found cell or NULL.
687 afs_choose_cell_by_index(struct cell *cell, void *arg)
689 return (cell->cellIndex == *((afs_int32 *) arg)) ? cell : NULL;
693 * Return a cell with a given name, if it exists. No lock version.
694 * Does not check AFSDB.
695 * \param acellName Cell name.
696 * \param locktype Type of lock to be used (not used).
700 afs_FindCellByName_nl(char *acellName, afs_int32 locktype)
702 return afs_TraverseCells_nl(&afs_choose_cell_by_name, acellName);
706 * Return a cell with a given name, if it exists.It uses locks.
707 * Does not check AFSDB.
708 * \param acellName Cell name.
709 * \param locktype Type of lock to be used.
713 afs_FindCellByName(char *acellName, afs_int32 locktype)
715 return afs_TraverseCells(&afs_choose_cell_by_name, acellName);
719 * Same as FindCellByName but tries AFSDB if not found.
720 * \param acellName Cell name.
721 * \param locktype Type of lock to be used.
725 afs_GetCellByName(char *acellName, afs_int32 locktype)
729 tc = afs_FindCellByName(acellName, locktype);
731 afs_LookupAFSDB(acellName);
732 tc = afs_FindCellByName(acellName, locktype);
735 afs_cellname_ref(tc->cnamep);
736 afs_UpdateCellLRU(tc);
744 * Return a cell with a given cell number.
745 * \param cellnum Cell number.
746 * \param locktype Lock to be used.
750 afs_GetCell(afs_int32 cellnum, afs_int32 locktype)
753 struct cell_name *cn;
755 tc = afs_GetCellStale(cellnum, locktype);
759 ObtainReadLock(&afs_xcell);
760 cn = afs_cellname_lookup_id(cellnum);
761 ReleaseReadLock(&afs_xcell);
763 tc = afs_GetCellByName(cn->cellname, locktype);
769 * Same as GetCell, but does not try to refresh the data.
770 * \param cellnum Cell number.
771 * \param locktype What lock should be used.
775 afs_GetCellStale(afs_int32 cellnum, afs_int32 locktype)
779 tc = afs_TraverseCells(&afs_choose_cell_by_num, &cellnum);
781 afs_cellname_ref(tc->cnamep);
782 afs_UpdateCellLRU(tc);
788 * Return a cell with a given index number (starting at 0). Update CellLRU as well.
790 * \param locktype Type of lock used.
794 afs_GetCellByIndex(afs_int32 index, afs_int32 locktype)
798 tc = afs_TraverseCells(&afs_choose_cell_by_index, &index);
800 afs_UpdateCellLRU(tc);
805 * Return a cell with a given handle..
807 * \param locktype Type of lock used.
811 afs_GetCellByHandle(void *handle, afs_int32 locktype)
815 tc = afs_TraverseCells(&afs_choose_cell_by_handle, handle);
817 afs_UpdateCellLRU(tc);
822 * Return primary cell, if any.
823 * \param locktype Type of lock used.
827 afs_GetPrimaryCell(afs_int32 locktype)
829 return afs_GetCellByName(afs_thiscell, locktype);
833 * Returns true if the given cell is the primary cell.
838 afs_IsPrimaryCell(struct cell *cell)
840 /* Simple safe checking */
843 } else if (!afs_thiscell) {
844 /* This is simply a safety net to avoid seg faults especially when
845 * using a user-space library. afs_SetPrimaryCell() should be set
846 * prior to this call. */
847 afs_SetPrimaryCell(cell->cellName);
850 return strcmp(cell->cellName, afs_thiscell) ? 0 : 1;
855 * Returns afs_IsPrimaryCell(afs_GetCell(cellnum)).
860 afs_IsPrimaryCellNum(afs_int32 cellnum)
865 tc = afs_GetCellStale(cellnum, READ_LOCK);
867 primary = afs_IsPrimaryCell(tc);
868 afs_PutCell(tc, READ_LOCK);
875 * Set the primary cell name to the given cell name.
876 * \param acellName Cell name.
877 * \return 0 for success, < 0 for error.
880 afs_SetPrimaryCell(char *acellName)
882 ObtainWriteLock(&afs_xcell, 691);
884 afs_osi_FreeStr(afs_thiscell);
885 afs_thiscell = afs_strdup(acellName);
886 ReleaseWriteLock(&afs_xcell);
891 * Create or update a cell entry.
892 * \param acellName Name of cell.
893 * \param acellHosts Array of hosts that this cell has.
894 * \param aflags Cell flags.
896 * \param fsport File server port.
897 * \param vlport Volume server port.
898 * \param timeout Cell timeout value, 0 means static AFSDB entry.
902 afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags,
903 char *linkedcname, u_short fsport, u_short vlport, int timeout)
905 struct cell *tc, *tcl = 0;
906 afs_int32 i, newc = 0, code = 0;
908 AFS_STATCNT(afs_NewCell);
910 ObtainWriteLock(&afs_xcell, 103);
912 tc = afs_FindCellByName_nl(acellName, READ_LOCK);
916 tc = (struct cell *)afs_osi_Alloc(sizeof(struct cell));
917 memset(tc, 0, sizeof(*tc));
918 tc->cellName = afs_strdup(acellName);
919 tc->fsport = AFS_FSPORT;
920 tc->vlport = AFS_VLPORT;
921 AFS_MD5_String(tc->cellHandle, tc->cellName, strlen(tc->cellName));
922 AFS_RWLOCK_INIT(&tc->lock, "cell lock");
926 ObtainWriteLock(&tc->lock, 688);
928 /* If the cell we've found has the correct name but no timeout,
929 * and we're called with a non-zero timeout, bail out: never
930 * override static configuration entries with AFSDB ones.
931 * One exception: if the original cell entry had no servers,
932 * it must get servers from AFSDB.
934 if (timeout && !tc->timeout && tc->cellHosts[0]) {
935 code = EEXIST; /* This code is checked for in afs_LookupAFSDB */
939 /* we don't want to keep pinging old vlservers which were down,
940 * since they don't matter any more. It's easier to do this than
941 * to remove the server from its various hash tables. */
942 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
943 if (!tc->cellHosts[i])
945 tc->cellHosts[i]->flags &= ~SRVR_ISDOWN;
946 tc->cellHosts[i]->flags |= SRVR_ISGONE;
954 if (aflags & CLinkedCell) {
959 tcl = afs_FindCellByName_nl(linkedcname, READ_LOCK);
964 if (tcl->lcellp) { /* XXX Overwriting if one existed before! XXX */
965 tcl->lcellp->lcellp = (struct cell *)0;
966 tcl->lcellp->states &= ~CLinkedCell;
971 tc->states |= aflags;
972 tc->timeout = timeout;
974 memset(tc->cellHosts, 0, sizeof(tc->cellHosts));
975 for (i = 0; i < AFS_MAXCELLHOSTS; i++) {
976 /* Get server for each host and link this cell in.*/
978 afs_uint32 temp = acellHosts[i];
981 ts = afs_GetServer(&temp, 1, 0, tc->vlport, WRITE_LOCK, NULL, 0);
983 ts->flags &= ~SRVR_ISGONE;
984 /* Set the server as a host of the new cell. */
985 tc->cellHosts[i] = ts;
986 afs_PutServer(ts, WRITE_LOCK);
988 afs_SortServers(tc->cellHosts, AFS_MAXCELLHOSTS); /* randomize servers */
990 /* New cell: Build and add to LRU cell queue. */
992 struct cell_name *cn;
994 cn = afs_cellname_lookup_name(acellName);
996 cn = afs_cellname_new(acellName, 0);
999 tc->cellNum = cn->cellnum;
1000 tc->cellIndex = afs_cellindex++;
1001 afs_stats_cmperf.numCellsVisible++;
1002 QAdd(&CellLRU, &tc->lruq);
1005 ReleaseWriteLock(&tc->lock);
1006 ReleaseWriteLock(&afs_xcell);
1008 if (!(aflags & CHush))
1009 afs_DynrootInvalidate();
1014 afs_osi_FreeStr(tc->cellName);
1015 afs_osi_Free(tc, sizeof(struct cell));
1017 ReleaseWriteLock(&tc->lock);
1018 ReleaseWriteLock(&afs_xcell);
1023 * Miscellaneous stuff
1025 * afs_CellInit: perform whatever initialization is necessary
1026 * shutdown_cell: called on shutdown, should deallocate memory, etc
1027 * afs_RemoveCellEntry: remove a server from a cell's server list
1028 * afs_CellOrAliasExists: check if the given name exists as a cell or alias
1029 * afs_CellOrAliasExists_nl: same as above without locking afs_xcell
1030 * afs_CellNumValid: check if a cell number is valid (also set the used flag)
1034 * Perform whatever initialization is necessary.
1039 static char CellInit_done = 0;
1046 AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
1047 AFS_RWLOCK_INIT(&afsdb_client_lock, "afsdb_client_lock");
1048 AFS_RWLOCK_INIT(&afsdb_req_lock, "afsdb_req_lock");
1052 afs_cellalias_index = 0;
1056 * Called on shutdown, should deallocate memory, etc.
1061 struct afs_q *cq, *tq;
1064 #ifdef AFS_CACHE_VNODE_PATH
1065 if (cacheDiskType != AFS_FCACHE_TYPE_MEM) {
1066 afs_osi_FreeStr(afs_cellname_inode.ufs);
1069 AFS_RWLOCK_INIT(&afs_xcell, "afs_xcell");
1071 for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
1075 afs_osi_FreeStr(tc->cellName);
1076 afs_osi_Free(tc, sizeof(struct cell));
1081 struct cell_name *cn = afs_cellname_head;
1084 struct cell_name *next = cn->next;
1086 afs_osi_FreeStr(cn->cellname);
1087 afs_osi_Free(cn, sizeof(struct cell_name));
1094 * Remove a server from a cell's server list.
1095 * \param srvp Server to be removed.
1099 afs_RemoveCellEntry(struct server *srvp)
1108 /* Remove the server structure from the cell list - if there */
1109 ObtainWriteLock(&tc->lock, 200);
1110 for (j = k = 0; j < AFS_MAXCELLHOSTS; j++) {
1111 if (!tc->cellHosts[j])
1113 if (tc->cellHosts[j] != srvp) {
1114 tc->cellHosts[k++] = tc->cellHosts[j];
1118 /* What do we do if we remove the last one? */
1120 for (; k < AFS_MAXCELLHOSTS; k++) {
1121 tc->cellHosts[k] = 0;
1123 ReleaseWriteLock(&tc->lock);
1127 * Check if the given name exists as a cell or alias. Does not lock afs_xcell.
1132 afs_CellOrAliasExists_nl(char *aname)
1135 struct cell_alias *ca;
1137 c = afs_FindCellByName_nl(aname, READ_LOCK);
1139 afs_PutCell(c, READ_LOCK);
1143 ca = afs_FindCellAlias(aname);
1145 afs_PutCellAlias(ca);
1153 * Check if the given name exists as a cell or alias. Locks afs_xcell.
1158 afs_CellOrAliasExists(char *aname)
1162 ObtainReadLock(&afs_xcell);
1163 ret = afs_CellOrAliasExists_nl(aname);
1164 ReleaseReadLock(&afs_xcell);
1170 * Check if a cell number is valid (also set the used flag).
1172 * \return 1 - true, 0 - false
1175 afs_CellNumValid(afs_int32 cellnum)
1177 struct cell_name *cn;
1179 ObtainReadLock(&afs_xcell);
1180 cn = afs_cellname_lookup_id(cellnum);
1181 ReleaseReadLock(&afs_xcell);