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 <afsconfig.h>
11 #include <afs/param.h>
17 #include <afs/afs_Admin.h>
20 #include <afs/afs_Admin.h>
21 #include "afs_AdminInternal.h"
22 #include "afs_utilAdmin.h"
23 #include <afs/pthread_glock.h>
24 #include <afs/cellconfig.h>
25 #include <afs/dirpath.h>
26 #include <afs/com_err.h>
27 #include <afs/kautils.h>
29 #include <afs/vlserver.h>
30 #include <afs/pterror.h>
31 #include <afs/bnode.h>
32 #include <afs/volser.h>
33 #include <afs/afsint.h>
35 #include <rx/rxstat.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
47 * AIX 4.2 has PTHREAD_CREATE_UNDETACHED and not PTHREAD_CREATE_JOINABLE
49 * This fix should be done more centrally, but there's no time right now.
51 #if defined(AFS_AIX_ENV)
52 # if !defined(PTHREAD_CREATE_JOINABLE) && defined(PTHREAD_CREATE_UNDETACHED)
53 # define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED
57 #define ERRCODE_RANGE 8
58 static pthread_once_t error_init_once = PTHREAD_ONCE_INIT;
59 static int error_init_done;
65 initialize_KA_error_table();
66 initialize_RXK_error_table();
67 initialize_KTC_error_table();
68 initialize_ACFG_error_table();
69 initialize_CMD_error_table();
70 initialize_VL_error_table();
71 initialize_PT_error_table();
72 initialize_BZ_error_table();
73 initialize_U_error_table();
74 initialize_AB_error_table();
75 initialize_AF_error_table();
76 initialize_AL_error_table();
77 initialize_AC_error_table();
78 initialize_AK_error_table();
79 initialize_AM_error_table();
80 initialize_AP_error_table();
81 initialize_AU_error_table();
82 initialize_AV_error_table();
83 initialize_VOLS_error_table();
88 util_AdminErrorCodeTranslate(afs_status_t errorCode, int langId,
89 const char **errorTextP, afs_status_p st)
95 if (errorTextP == NULL) {
96 tst = ADMUTILERRORTEXTPNULL;
97 goto fail_util_AdminErrorCodeTranslate;
101 * Translate the error
104 if (!error_init_done)
105 pthread_once(&error_init_once, init_once);
106 code = (afs_int32) errorCode;
107 *errorTextP = error_message(code);
110 fail_util_AdminErrorCodeTranslate:
119 * The iterator functions and data for the database server retrieval functions.
122 typedef struct database_server_get {
125 struct afsconf_dir *conf;
126 struct afsconf_cell cell;
127 util_databaseServerEntry_t server[CACHED_ITEMS];
128 } database_server_get_t, *database_server_get_p;
131 GetDatabaseServerRPC(void *rpc_specific, int slot, int *last_item,
132 int *last_item_contains_data, afs_status_p st)
135 afs_status_t tst = 0;
136 database_server_get_p serv = (database_server_get_p) rpc_specific;
138 serv->server[slot].serverAddress =
139 ntohl(serv->cell.hostAddr[serv->index].sin_addr.s_addr);
140 strcpy(serv->server[slot].serverName, serv->cell.hostName[serv->index]);
144 * See if we've processed all the entries
147 if (serv->index == serv->total) {
149 *last_item_contains_data = 1;
160 GetDatabaseServerFromCache(void *rpc_specific, int slot, void *dest,
164 afs_status_t tst = 0;
165 database_server_get_p serv = (database_server_get_p) rpc_specific;
167 memcpy(dest, (const void *)&serv->server[slot],
168 sizeof(util_databaseServerEntry_t));
178 DestroyDatabaseServer(void *rpc_specific, afs_status_p st)
181 afs_status_t tst = 0;
182 database_server_get_p serv = (database_server_get_p) rpc_specific;
184 afsconf_Close(serv->conf);
194 * util_DatabaseServerGetBegin - begin iterating over the database
195 * server machines in a cell.
199 * IN cellName - the cell where database servers reside.
201 * OUT iterationIdP - upon successful completion contains an iterator that
202 * can be passed to util_DatabaseServerGetNext.
206 * No locks are obtained or released by this function
214 * Returns != 0 upon successful completion.
218 util_DatabaseServerGetBegin(const char *cellName, void **iterationIdP,
222 afs_status_t tst = 0;
223 afs_admin_iterator_p iter =
224 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
225 database_server_get_p serv =
226 (database_server_get_p) calloc(1, sizeof(database_server_get_t));
227 char copyCell[MAXCELLCHARS];
233 if ((cellName == NULL) || (*cellName == 0)) {
234 tst = ADMUTILCELLNAMENULL;
235 goto fail_util_DatabaseServerGetBegin;
238 if (iterationIdP == NULL) {
239 goto fail_util_DatabaseServerGetBegin;
242 if ((iter == NULL) || (serv == NULL)) {
244 goto fail_util_DatabaseServerGetBegin;
248 * Fill in the serv structure
251 serv->conf = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
252 if (serv->conf == NULL) {
253 tst = ADMUTILCANTOPENCELLSERVDB;
254 goto fail_util_DatabaseServerGetBegin;
258 * We must copy the cellname because afsconf_GetCellInfo
259 * actually writes over the cell name it is passed.
261 strncpy(copyCell, cellName, MAXCELLCHARS - 1);
263 afsconf_GetCellInfo(serv->conf, copyCell, AFSCONF_KAUTHSERVICE,
266 goto fail_util_DatabaseServerGetBegin;
269 serv->total = serv->cell.numServers;
271 (iter, (void *)serv, GetDatabaseServerRPC, GetDatabaseServerFromCache,
272 NULL, DestroyDatabaseServer, &tst)) {
273 *iterationIdP = (void *)iter;
275 goto fail_util_DatabaseServerGetBegin;
279 fail_util_DatabaseServerGetBegin:
297 * util_DatabaseServerGetNext - get the next server address.
301 * IN iterationId - an iterator returned by util_DatabaseServerGetBegin
303 * OUT serverAddressP - upon successful completion contains the next
304 * server address in the cell.
308 * This function locks the iterator for the duration of its processing.
316 * Returns != 0 upon successful completion.
321 util_DatabaseServerGetNext(const void *iterationId,
322 util_databaseServerEntry_p serverP,
326 afs_status_t tst = 0;
327 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
330 tst = ADMITERATORNULL;
331 goto fail_util_DatabaseServerGetNext;
334 if (serverP == NULL) {
335 tst = ADMUTILSERVERADDRESSPNULL;
336 goto fail_util_DatabaseServerGetNext;
339 rc = IteratorNext(iter, (void *)serverP, &tst);
341 fail_util_DatabaseServerGetNext:
350 * util_DatabaseServerGetDone - stop using a database iterator.
354 * IN iterationId - an iterator returned by util_DatabaseServerGetBegin
358 * This function locks the iterator for the duration of its processing.
359 * And then destroys it before returning.
367 * Returns != 0 upon successful completion.
371 util_DatabaseServerGetDone(const void *iterationId, afs_status_p st)
374 afs_status_t tst = 0;
375 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
378 * Validate parameters
382 tst = ADMITERATORNULL;
383 goto fail_util_DatabaseServerGetDone;
386 rc = IteratorDone(iter, &tst);
388 fail_util_DatabaseServerGetDone:
397 * GetServerAddressFromName - translate a character string server name
398 * to an integer representation of an IP address.
402 * IN serverName - the character string server name in either foo.com
403 * format, or 123.12.1.1 format.
405 * OUT serverAddress - an integer that is filled with the correct address
406 * in host byte order upon successful completion.
410 * No locks are obtained or released by this function
414 * On many platforms, gethostbyname is not thread safe. Since we are
415 * only working under NT for now I'll use it directly. In future UNIX
416 * ports, a wrapper function should be written to call the correct function
417 * on the particular platform.
421 * Returns != 0 upon successful completion.
425 util_AdminServerAddressGetFromName(const char *serverName, int *serverAddress,
429 afs_status_t tst = 0;
430 struct hostent *server;
431 int part1, part2, part3, part4;
434 if ((serverName == NULL) || (*serverName == 0)) {
435 tst = ADMUTILSERVERNAMENULL;
436 goto fail_util_AdminServerAddressGetFromName;
439 if (serverAddress == NULL) {
440 tst = ADMUTILSERVERADDRESSNULL;
441 goto fail_util_AdminServerAddressGetFromName;
445 sscanf(serverName, "%d.%d.%d.%d", &part1, &part2, &part3, &part4);
446 if (num_converted == 4) {
447 *serverAddress = (part1 << 24) | (part2 << 16) | (part3 << 8) | part4;
449 LOCK_GLOBAL_MUTEX server = gethostbyname(serverName);
450 if (server != NULL) {
451 memcpy((void *)serverAddress, (const void *)server->h_addr,
452 sizeof(serverAddress));
453 *serverAddress = ntohl(*serverAddress);
455 tst = ADMUTILCANTGETSERVERNAME;
457 goto fail_util_AdminServerAddressGetFromName;
462 fail_util_AdminServerAddressGetFromName:
472 * This file contains functions that can be used to create iterator
473 * functions within the api. I have attempted to make these functions
474 * generic so that they can be used across the admin components.
476 * The functions in this file are a generalized producer/consumer
477 * implementation. They manage access to a queue of data. The only
478 * assumption these functions make about this data is that it is
479 * stored in a queue which is implemented via an array. These functions
480 * know about the index into the array, but they know nothing about
481 * the contents of the array.
483 * The data specific functions you implement will have to create some
484 * data specific storage structure that will have an array
485 * of size CACHED_ITEMS data items. This structure will also need to
486 * store any necessary parameters/state variables you need to issue the
487 * rpc to retrieve the next item.
489 * In order to use the generic functions, you must implement four functions
490 * for each type of data you wish to retrieve. The functions are:
492 * validate_specific_data_func - this function is handed a void pointer
493 * that points to the rpc specific data you've allocated. The function
494 * should examine the data for validity and return an appropriate error.
495 * This function is called every time the iterator is validated.
497 * destroy_specific_data_func - this function is handed a void pointer
498 * that points to the rpc specific data you've allocated. It should
499 * destroy any components of the specific data as required and then
500 * return. The void pointer is free'd by the generic functions.
502 * get_cached_data_func - this function is handed a void pointer
503 * that points to the rpc specific data you've allocated, an index
504 * into the cache of the item to be copied to the caller, and a void
505 * pointer where the cache item should be copied.
507 * make_rpc_func - this function is handed a void pointer that points
508 * to the rpc specific data you've allocated, an index into the cache
509 * of the item to be filled with the next retrieved item, and an int
510 * pointer that should be set to 1 if there are no more items to be
511 * retrieved. The assumption made by the generic functions is that
512 * the last_item status requires an individual rpc - the data isn't
513 * piggybacked on the last data item.
517 * IteratorDelete - delete an iterator.
521 * IN interator - the iterator to delete.
525 * No locks are held by this function.
529 * Returns != 0 upon successful completion.
533 IteratorDelete(afs_admin_iterator_p iter, afs_status_p st)
536 afs_status_t tst = 0;
538 if (pthread_mutex_destroy(&iter->mutex)) {
539 tst = ADMMUTEXDESTROY;
540 goto fail_IteratorDelete;
542 if (pthread_cond_destroy(&iter->add_item)) {
543 tst = ADMCONDDESTROY;
544 goto fail_IteratorDelete;
546 if (pthread_cond_destroy(&iter->remove_item)) {
547 tst = ADMCONDDESTROY;
548 goto fail_IteratorDelete;
551 if (iter->destroy_specific != NULL) {
552 iter->destroy_specific(iter->rpc_specific, &tst);
554 free(iter->rpc_specific);
567 * DataGet - the background thread that is spawned for every
568 * IteratorBegin call that is successful. This thread tries
569 * to fetch the data from the server ahead of the
570 * IteratorNext calls.
574 * IN arg - the address of the iterator structure to be used for this
579 * The iterator mutex is used by this function to protect elements
580 * of the iterator structure.
584 * Returns != 0 upon successful completion.
590 afs_admin_iterator_p iter = (afs_admin_iterator_p) arg;
592 afs_status_t tst = 0;
593 int mutex_locked = 0;
595 int last_item_contains_data = 0;
597 if (pthread_mutex_lock(&iter->mutex)) {
598 iter->st = ADMMUTEXLOCK;
607 * Check to see if there's room for this datum. If not, wait
608 * on the consumer to free up another slot.
611 while (iter->cache_slots_used == CACHED_ITEMS) {
612 if (pthread_cond_wait(&iter->remove_item, &iter->mutex)) {
613 iter->st = ADMCONDWAIT;
619 * Check to see if someone called Done and terminated the request.
620 * We could have gone to sleep above when the buffer was full and
621 * instead of being awoken because another slot is open, we were
622 * awoken because the request was terminated.
625 if (iter->request_terminated) {
629 if (pthread_mutex_unlock(&iter->mutex)) {
630 iter->st = ADMMUTEXUNLOCK;
637 * Make an rpc without holding the iter mutex
638 * We reference an item in the principal cache here without
639 * holding the mutex. This is safe because:
640 * 1. The iter structure is ref counted and won't be deleted
641 * from underneath us.
642 * 2. cache_queue_tail is always one item ahead of the consumer
643 * thread so we are the only thread accessing this member.
646 iter->make_rpc(iter->rpc_specific, iter->cache_queue_tail, &last_item,
647 &last_item_contains_data, &tst);
649 if (pthread_mutex_lock(&iter->mutex)) {
650 iter->st = ADMMUTEXLOCK;
657 * Check to see if someone called Done and terminated the request
660 if (iter->request_terminated) {
665 * Check the rc of the rpc, and see if there are no more items
675 * Check to see if this is the last item produced by the rpc.
676 * If it isn't, add the item to the cache and proceed.
677 * If it is, check to see if the last item contains valid data.
678 * If it contains valid data, we need to add it to our cache.
679 * If it doesn't, we mark the iterator as complete.
682 if ((!last_item) || ((last_item) && (last_item_contains_data))) {
683 iter->cache_queue_tail =
684 (iter->cache_queue_tail + 1) % CACHED_ITEMS;
685 iter->cache_slots_used++;
688 iter->st = ADMITERATORDONE;
689 iter->done_iterating = 1;
691 * There's a small chance that the consumer emptied the
692 * cache queue while we were making the last rpc and has
693 * since gone to sleep waiting for more data. In this case
694 * there will never be more data so we signal him here.
696 pthread_cond_signal(&iter->add_item);
702 * If the cache was empty and we just added another item, signal
706 if (iter->cache_slots_used == 1) {
707 if (pthread_cond_signal(&iter->add_item)) {
708 iter->st = ADMCONDSIGNAL;
718 * If we are exiting with an error, signal the consumer in the event
719 * they were waiting for us to produce more data
723 pthread_cond_signal(&iter->add_item);
727 pthread_mutex_unlock(&iter->mutex);
734 * IsValidIterator - verify the validity of a afs_admin_iterator_t.
738 * IN interator - the interator to be verified.
742 * We assume the iter->mutex lock is already held.
746 * Returns != 0 upon successful completion.
750 IsValidIterator(const afs_admin_iterator_p iterator, afs_status_p st)
753 afs_status_t tst = 0;
756 * Validate input parameters
759 if (iterator == NULL) {
760 tst = ADMITERATORNULL;
761 goto fail_IsValidIterator;
764 if ((iterator->begin_magic != BEGIN_MAGIC)
765 || (iterator->end_magic != END_MAGIC)) {
766 tst = ADMITERATORBADMAGICNULL;
767 goto fail_IsValidIterator;
770 if (iterator->is_valid == 0) {
771 tst = ADMITERATORINVALID;
772 goto fail_IsValidIterator;
776 * Call the iterator specific validation function
779 if (iterator->validate_specific != NULL) {
780 if (!iterator->validate_specific(iterator->rpc_specific, &tst)) {
781 goto fail_IsValidIterator;
786 fail_IsValidIterator:
795 * IteratorNext - return the next datum in an interator.
799 * IN interator - the iterator containing the data.
801 * IN dest - the address where the data should be copied.
805 * Lock the iterator upon entry, and hold it during the duration of this
810 * Returns != 0 upon successful completion.
814 IteratorNext(afs_admin_iterator_p iter, void *dest, afs_status_p st)
817 afs_status_t tst = 0;
821 * We have to lock the iterator before we validate it
824 if (pthread_mutex_lock(&iter->mutex)) {
826 goto fail_IteratorNext;
831 if (!IsValidIterator(iter, &tst)) {
832 goto fail_IteratorNext;
835 if (iter->request_terminated == 1) {
836 tst = ADMITERATORTERMINATED;
837 goto fail_IteratorNext;
840 if ((iter->st != AFS_STATUS_OK) && (iter->st != ADMITERATORDONE)) {
842 goto fail_IteratorNext;
846 * Check to see if there are any queue'd items. If not, wait here
847 * until signalled by the producer.
850 while (iter->cache_slots_used == 0) {
853 * Maybe the producer experienced an rpc failure.
856 if ((!iter->done_iterating) && (iter->st != 0)) {
858 goto fail_IteratorNext;
862 * Maybe there are no queue'd items because the producer is done
865 if (iter->done_iterating) {
867 goto fail_IteratorNext;
870 if (pthread_cond_wait(&iter->add_item, &iter->mutex)) {
872 goto fail_IteratorNext;
877 * Copy the next cached item and update the cached item count
878 * and the index into the cache array
882 get_cached_data(iter->rpc_specific, iter->cache_queue_head, dest,
884 goto fail_IteratorNext;
887 iter->cache_queue_head = (iter->cache_queue_head + 1) % CACHED_ITEMS;
888 iter->cache_slots_used--;
891 * If the cache was full before we removed the item above, the
892 * producer may have been waiting for us to remove an item.
893 * Signal the producer letting him know that we've opened a slot
897 if (iter->cache_slots_used == (CACHED_ITEMS - 1)) {
898 if (pthread_cond_signal(&iter->remove_item)) {
900 goto fail_IteratorNext;
908 if (locked_iter == 1) {
909 pthread_mutex_unlock(&iter->mutex);
919 * IteratorDone - mark the iterator done.
923 * IN interator - the iterator to mark done.
927 * Lock the iterator upon entry, and hold it during the duration of this
932 * Returns != 0 upon successful completion.
936 IteratorDone(afs_admin_iterator_p iter, afs_status_p st)
939 afs_status_t tst = 0;
940 int mutex_locked = 1;
942 if (pthread_mutex_lock(&iter->mutex)) {
944 goto fail_IteratorDone;
950 if (!IsValidIterator(iter, &tst)) {
951 goto fail_IteratorDone;
956 * Depending upon the status of the background worker thread,
957 * we can either join with him immediately (if we know he has
958 * terminated), or we need to tell him the request has been
959 * terminated and then join with him.
962 if (!iter->done_iterating) {
963 iter->request_terminated = 1;
964 iter->cache_slots_used = 0;
965 pthread_cond_signal(&iter->remove_item);
969 * We have to unlock the mutex to allow the background thread to
973 if (pthread_mutex_unlock(&iter->mutex)) {
974 tst = ADMMUTEXUNLOCK;
975 goto fail_IteratorDone;
978 if (iter->make_rpc != NULL) {
979 if (pthread_join(iter->bg_worker, (void **)0)) {
981 goto fail_IteratorDone;
986 * We don't relock the mutex here since we are the only thread
987 * that has access to the iter now
990 rc = IteratorDelete(iter, &tst);
996 pthread_mutex_unlock(&iter->mutex);
1006 * IteratorInit - initialize an iterator.
1010 * IN interator - the iterator to initialize.
1014 * No locks are held by this function.
1018 * Returns != 0 upon successful completion.
1022 IteratorInit(afs_admin_iterator_p iter, void *rpc_specific,
1023 make_rpc_func make_rpc, get_cached_data_func get_cached_data,
1024 validate_specific_data_func validate_specific_data,
1025 destroy_specific_data_func destroy_specific_data,
1029 afs_status_t tst = 0;
1030 int mutex_inited = 0;
1031 int add_item_cond_inited = 0;
1032 int remove_item_cond_inited = 0;
1035 tst = ADMITERATORNULL;
1036 goto fail_IteratorInit;
1039 if (rpc_specific == NULL) {
1040 tst = ADMITERATORRPCSPECIFICNULL;
1041 goto fail_IteratorInit;
1045 * Initialize the iterator structure
1047 iter->begin_magic = BEGIN_MAGIC;
1048 iter->end_magic = END_MAGIC;
1050 iter->cache_slots_used = 0;
1051 iter->done_iterating = 0;
1052 iter->request_terminated = 0;
1053 iter->st = AFS_STATUS_OK;
1054 iter->cache_queue_head = 0;
1055 iter->cache_queue_tail = 0;
1056 iter->cache_slots_used = 0;
1057 iter->rpc_specific = rpc_specific;
1058 iter->make_rpc = make_rpc;
1059 iter->get_cached_data = get_cached_data;
1060 iter->validate_specific = validate_specific_data;
1061 iter->destroy_specific = destroy_specific_data;
1063 if (pthread_mutex_init(&iter->mutex, (const pthread_mutexattr_t *)0)) {
1065 goto fail_IteratorInit;
1070 if (pthread_cond_init(&iter->add_item, (const pthread_condattr_t *)0)) {
1072 goto fail_IteratorInit;
1074 add_item_cond_inited = 1;
1077 if (pthread_cond_init(&iter->remove_item, (const pthread_condattr_t *)0)) {
1079 goto fail_IteratorInit;
1081 remove_item_cond_inited = 1;
1085 * Create a worker thread that will begin to query the server
1086 * and cache responses.
1089 if (iter->make_rpc != NULL) {
1090 pthread_attr_t tattr;
1092 if (pthread_attr_init(&tattr)) {
1093 tst = ADMTHREADATTRINIT;
1094 goto fail_IteratorInit;
1097 if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE)) {
1098 tst = ADMTHREADATTRSETDETACHSTATE;
1099 goto fail_IteratorInit;
1102 if (pthread_create(&iter->bg_worker, &tattr, DataGet, (void *)iter)) {
1103 tst = ADMTHREADCREATE;
1104 goto fail_IteratorInit;
1113 pthread_mutex_destroy(&iter->mutex);
1115 if (remove_item_cond_inited) {
1116 pthread_cond_destroy(&iter->remove_item);
1118 if (add_item_cond_inited) {
1119 pthread_cond_destroy(&iter->add_item);
1130 CellHandleIsValid(const void *cellHandle, afs_status_p st)
1133 afs_status_t tst = 0;
1134 afs_cell_handle_p c_handle = (afs_cell_handle_p) cellHandle;
1137 * Validate input parameters
1140 if (c_handle == NULL) {
1141 tst = ADMCLIENTCELLHANDLENULL;
1142 goto fail_CellHandleIsValid;
1145 if ((c_handle->begin_magic != BEGIN_MAGIC)
1146 || (c_handle->end_magic != END_MAGIC)) {
1147 tst = ADMCLIENTCELLHANDLEBADMAGIC;
1148 goto fail_CellHandleIsValid;
1151 if (c_handle->is_valid == 0) {
1152 tst = ADMCLIENTCELLINVALID;
1153 goto fail_CellHandleIsValid;
1157 fail_CellHandleIsValid:
1166 * The iterator functions and data for the rpc statistic retrieval functions
1169 typedef struct rpc_stat_get {
1170 afs_uint32 clock_sec;
1171 afs_uint32 clock_usec;
1174 afs_uint32 clientVersion;
1175 afs_uint32 serverVersion;
1176 struct rpcStats stat_list;
1177 afs_RPCStats_t stats[CACHED_ITEMS];
1178 afs_uint32 *pointer;
1179 } rpc_stat_get_t, *rpc_stat_get_p;
1182 UnmarshallRPCStats(afs_uint32 serverVersion, afs_uint32 ** ptrP,
1186 unsigned int hi, lo;
1189 * Server must always match lower versions. We are version 1.
1192 s->stats_v1.remote_peer = *(ptr++);
1193 s->stats_v1.remote_port = *(ptr++);
1194 s->stats_v1.remote_is_server = *(ptr++);
1195 s->stats_v1.interfaceId = *(ptr++);
1196 s->stats_v1.func_total = *(ptr++);
1197 s->stats_v1.func_index = *(ptr++);
1200 hset64(s->stats_v1.invocations, hi, lo);
1203 hset64(s->stats_v1.bytes_sent, hi, lo);
1206 hset64(s->stats_v1.bytes_rcvd, hi, lo);
1207 s->stats_v1.queue_time_sum.sec = *(ptr++);
1208 s->stats_v1.queue_time_sum.usec = *(ptr++);
1209 s->stats_v1.queue_time_sum_sqr.sec = *(ptr++);
1210 s->stats_v1.queue_time_sum_sqr.usec = *(ptr++);
1211 s->stats_v1.queue_time_min.sec = *(ptr++);
1212 s->stats_v1.queue_time_min.usec = *(ptr++);
1213 s->stats_v1.queue_time_max.sec = *(ptr++);
1214 s->stats_v1.queue_time_max.usec = *(ptr++);
1215 s->stats_v1.execution_time_sum.sec = *(ptr++);
1216 s->stats_v1.execution_time_sum.usec = *(ptr++);
1217 s->stats_v1.execution_time_sum_sqr.sec = *(ptr++);
1218 s->stats_v1.execution_time_sum_sqr.usec = *(ptr++);
1219 s->stats_v1.execution_time_min.sec = *(ptr++);
1220 s->stats_v1.execution_time_min.usec = *(ptr++);
1221 s->stats_v1.execution_time_max.sec = *(ptr++);
1222 s->stats_v1.execution_time_max.usec = *(ptr++);
1227 GetRPCStatsRPC(void *rpc_specific, int slot, int *last_item,
1228 int *last_item_contains_data, afs_status_p st)
1231 afs_status_t tst = 0;
1232 rpc_stat_get_p t = (rpc_stat_get_p) rpc_specific;
1234 t->stats[slot].clientVersion = t->clientVersion;
1235 t->stats[slot].serverVersion = t->serverVersion;
1236 t->stats[slot].statCount = t->total;
1239 * If the server stat version is greater than or equal to my version
1240 * number, it is required to return the values in the client's current
1244 UnmarshallRPCStats(t->serverVersion, &t->pointer, &t->stats[slot].s);
1249 * See if we've processed all the entries
1252 if (t->index == t->total) {
1254 *last_item_contains_data = 1;
1265 GetRPCStatsFromCache(void *rpc_specific, int slot, void *dest,
1269 afs_status_t tst = 0;
1270 rpc_stat_get_p stat = (rpc_stat_get_p) rpc_specific;
1272 memcpy(dest, (const void *)&stat->stats[slot], sizeof(afs_RPCStats_t));
1282 DestroyRPCStats(void *rpc_specific, afs_status_p st)
1285 afs_status_t tst = 0;
1286 rpc_stat_get_p stat = (rpc_stat_get_p) rpc_specific;
1288 if (stat->stat_list.rpcStats_val != NULL) {
1289 free(stat->stat_list.rpcStats_val);
1300 * util_RPCStatsGetBegin - begin retrieving rpc stats for a process
1304 * IN conn - an rx connection to the process to be queried
1306 * IN rpc - the function to call to make the actual rpc
1308 * OUT iterationIdP - an iteration id that can be passed to
1309 * util_RPCStatsGetNext to get the next rpc stat
1313 * No locks are obtained or released by this function
1317 * Returns != 0 upon successful completion.
1322 util_RPCStatsGetBegin(struct rx_connection *conn, int (*rpc) (),
1323 void **iterationIdP, afs_status_p st)
1326 afs_status_t tst = 0;
1327 afs_admin_iterator_p iter =
1328 (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1329 rpc_stat_get_p stat = (rpc_stat_get_p) malloc(sizeof(rpc_stat_get_t));
1332 tst = ADMRXCONNNULL;
1333 goto fail_util_RPCStatsGetBegin;
1337 tst = ADMRPCPTRNULL;
1338 goto fail_util_RPCStatsGetBegin;
1341 if (iterationIdP == NULL) {
1342 tst = ADMITERATIONIDPNULL;
1343 goto fail_util_RPCStatsGetBegin;
1346 if ((iter == NULL) || (stat == NULL)) {
1348 goto fail_util_RPCStatsGetBegin;
1351 stat->stat_list.rpcStats_len = 0;
1352 stat->stat_list.rpcStats_val = 0;
1354 stat->clientVersion = RX_STATS_RETRIEVAL_VERSION;
1357 (*rpc) (conn, stat->clientVersion, &stat->serverVersion,
1358 &stat->clock_sec, &stat->clock_usec, &stat->total,
1362 goto fail_util_RPCStatsGetBegin;
1366 * If there are no statistics, just mark the iterator done and
1370 if (stat->stat_list.rpcStats_len == 0) {
1371 stat->pointer = NULL;
1372 if (!IteratorInit(iter, (void *)stat, NULL, NULL, NULL, NULL, &tst)) {
1373 goto fail_util_RPCStatsGetBegin;
1375 iter->done_iterating = 1;
1376 iter->st = ADMITERATORDONE;
1378 stat->pointer = stat->stat_list.rpcStats_val;
1380 (iter, (void *)stat, GetRPCStatsRPC, GetRPCStatsFromCache, NULL,
1381 DestroyRPCStats, &tst)) {
1382 goto fail_util_RPCStatsGetBegin;
1385 *iterationIdP = (void *)iter;
1388 fail_util_RPCStatsGetBegin:
1406 * util_RPCStatsGetNext - retrieve the next rpc stat from the server
1410 * IN iterationId - an iterator previously returned by
1411 * util_RPCStatsGetBegin.
1413 * OUT stats - upon successful completion contains the next set of stats
1418 * No locks are obtained or released by this function
1422 * Returns != 0 upon successful completion.
1427 util_RPCStatsGetNext(const void *iterationId, afs_RPCStats_p stats,
1431 afs_status_t tst = 0;
1432 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1434 if (iterationId == NULL) {
1435 tst = ADMITERATIONIDPNULL;
1436 goto fail_util_RPCStatsGetNext;
1439 if (stats == NULL) {
1440 tst = ADMUTILRPCSTATSNULL;
1441 goto fail_util_RPCStatsGetNext;
1444 rc = IteratorNext(iter, (void *)stats, &tst);
1446 fail_util_RPCStatsGetNext:
1455 * util_RPCStatsGetDone - finish using a stats iterator
1459 * IN iterationId - an iterator previously returned by
1460 * util_RPCStatsGetBegin.
1464 * No locks are obtained or released by this function
1468 * Returns != 0 upon successful completion.
1473 util_RPCStatsGetDone(const void *iterationId, afs_status_p st)
1476 afs_status_t tst = 0;
1477 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1479 if (iterationId == NULL) {
1480 tst = ADMITERATIONIDPNULL;
1481 goto fail_util_RPCStatsGetDone;
1484 rc = IteratorDone(iter, &tst);
1486 fail_util_RPCStatsGetDone:
1495 * util_RPCStatsStateGet - get the current state of rpc stat collection
1499 * IN conn - an rx connection to the process to be queried
1501 * IN rpc - the function to call to make the actual rpc
1503 * OUT state - the rpc stat collection state.
1507 * No locks are obtained or released by this function
1511 * Returns != 0 upon successful completion.
1516 util_RPCStatsStateGet(struct rx_connection *conn, int (*rpc) (),
1517 afs_RPCStatsState_p state, afs_status_p st)
1520 afs_status_t tst = 0;
1523 tst = ADMRXCONNNULL;
1524 goto fail_util_RPCStatsStateGet;
1528 tst = ADMRPCPTRNULL;
1529 goto fail_util_RPCStatsStateGet;
1532 if (state == NULL) {
1533 tst = ADMRPCSTATENULL;
1534 goto fail_util_RPCStatsStateGet;
1537 tst = (*rpc) (conn, state);
1543 fail_util_RPCStatsStateGet:
1552 * util_RPCStatsStateEnable - enable rpc stat collection
1557 * IN conn - an rx connection to the process to be modified
1559 * IN rpc - the function to call to make the actual rpc
1563 * No locks are obtained or released by this function
1567 * Returns != 0 upon successful completion.
1572 util_RPCStatsStateEnable(struct rx_connection *conn, int (*rpc) (),
1576 afs_status_t tst = 0;
1579 tst = ADMRXCONNNULL;
1580 goto fail_util_RPCStatsStateEnable;
1584 tst = ADMRPCPTRNULL;
1585 goto fail_util_RPCStatsStateEnable;
1588 tst = (*rpc) (conn);
1594 fail_util_RPCStatsStateEnable:
1603 * util_RPCStatsStateDisable - set the current state of rpc stat collection
1608 * IN conn - an rx connection to the process to be modified
1610 * IN rpc - the function to call to make the actual rpc
1614 * No locks are obtained or released by this function
1618 * Returns != 0 upon successful completion.
1623 util_RPCStatsStateDisable(struct rx_connection *conn, int (*rpc) (),
1627 afs_status_t tst = 0;
1630 tst = ADMRXCONNNULL;
1631 goto fail_util_RPCStatsStateDisable;
1635 tst = ADMRPCPTRNULL;
1636 goto fail_util_RPCStatsStateDisable;
1639 tst = (*rpc) (conn);
1645 fail_util_RPCStatsStateDisable:
1654 * util_RPCStatsClear - clear some or all of the fields in the rpc stat
1655 * collection at a server
1659 * IN conn - an rx connection to the process to be modified
1661 * IN rpc - the function to call to make the actual rpc
1663 * IN flag - a flag containing the fields to be cleared
1668 * No locks are obtained or released by this function
1672 * Returns != 0 upon successful completion.
1677 util_RPCStatsClear(struct rx_connection *conn, int (*rpc) (),
1678 afs_RPCStatsClearFlag_t flag, afs_status_p st)
1681 afs_status_t tst = 0;
1684 tst = ADMRXCONNNULL;
1685 goto fail_util_RPCStatsClear;
1689 tst = ADMRPCPTRNULL;
1690 goto fail_util_RPCStatsClear;
1693 tst = (*rpc) (conn, flag);
1699 fail_util_RPCStatsClear:
1708 * util_RPCStatsVersionGet - get the current version of rpc stat collection
1712 * IN conn - an rx connection to the process to be modified
1714 * OUT version - the version of rpc stat collection at the remote process
1718 * No locks are obtained or released by this function
1722 * Returns != 0 upon successful completion.
1727 util_RPCStatsVersionGet(struct rx_connection *conn,
1728 afs_RPCStatsVersion_p version, afs_status_p st)
1731 afs_status_t tst = 0;
1734 tst = ADMRXCONNNULL;
1735 goto fail_util_RPCStatsVersionGet;
1738 if (version == NULL) {
1739 tst = ADMRPCVERSIONNULL;
1740 goto fail_util_RPCStatsVersionGet;
1743 tst = RXSTATS_QueryRPCStatsVersion(conn, version);
1749 fail_util_RPCStatsVersionGet:
1758 * The iterator for listing CM server preferences
1761 typedef struct cm_srvr_pref_get {
1762 struct rx_connection *conn;
1764 afs_CMServerPref_t srvrPrefs[CACHED_ITEMS];
1765 } cm_srvr_pref_get_t, *cm_srvr_pref_get_p;
1768 GetServerPrefsRPC(void *rpc_specific, int slot, int *last_item,
1769 int *last_item_contains_data, afs_status_p st)
1772 afs_status_t tst = 0;
1773 cm_srvr_pref_get_p t = (cm_srvr_pref_get_p) rpc_specific;
1776 * Get the next entry in the list of server preferences.
1779 RXAFSCB_GetServerPrefs(t->conn, t->index, &t->srvrPrefs[slot].ipAddr,
1780 &t->srvrPrefs[slot].ipRank);
1782 goto fail_GetServerPrefsRPC;
1786 * See if we've processed all the entries
1788 if (t->srvrPrefs[slot].ipAddr == 0xffffffff) {
1790 *last_item_contains_data = 0;
1796 fail_GetServerPrefsRPC:
1805 GetServerPrefsFromCache(void *rpc_specific, int slot, void *dest,
1809 afs_status_t tst = 0;
1810 cm_srvr_pref_get_p prefs = (cm_srvr_pref_get_p) rpc_specific;
1812 memcpy(dest, (const void *)&prefs->srvrPrefs[slot],
1813 sizeof(afs_CMServerPref_t));
1823 * util_CMGetServerPrefsBegin - Begin listing cache manager server preferences
1827 * IN conn - an rx connection to the process to be queried
1829 * OUT iterationIdP - an iteration id that can be passed to
1830 * util_CMGetServerPrefsNext to get the next server preference
1834 * No locks are obtained or released by this function
1838 * Returns != 0 upon successful completion.
1843 util_CMGetServerPrefsBegin(struct rx_connection *conn, void **iterationIdP,
1847 afs_status_t tst = 0;
1848 afs_admin_iterator_p iter;
1849 cm_srvr_pref_get_p pref;
1852 tst = ADMRXCONNNULL;
1853 goto fail_util_CMGetServerPrefsBegin;
1856 iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
1859 goto fail_util_CMGetServerPrefsBegin;
1862 pref = (cm_srvr_pref_get_p) malloc(sizeof(cm_srvr_pref_get_t));
1866 goto fail_util_CMGetServerPrefsBegin;
1872 (iter, (void *)pref, GetServerPrefsRPC, GetServerPrefsFromCache, NULL,
1876 goto fail_util_CMGetServerPrefsBegin;
1878 *iterationIdP = (void *)iter;
1881 fail_util_CMGetServerPrefsBegin:
1890 * util_CMGetServerPrefsNext - Get next entry in cache manager server
1895 * IN iterationId - Iteration id created by util_CMGetServerPrefsBegin.
1897 * OUT prefs - Next entry in cache manager server preferences.
1901 * No locks are obtained or released by this function
1905 * Returns != 0 upon successful completion.
1910 util_CMGetServerPrefsNext(const void *iterationId, afs_CMServerPref_p prefs,
1914 afs_status_t tst = 0;
1915 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1917 if (iterationId == NULL) {
1918 tst = ADMITERATIONIDPNULL;
1919 goto fail_util_CMGetServerPrefsNext;
1922 rc = IteratorNext(iter, (void *)prefs, &tst);
1924 fail_util_CMGetServerPrefsNext:
1933 * util_CMGetServerPrefsDone - Finish listing cache manager server
1938 * IN iterationId - Iteration id created by util_CMGetServerPrefsBegin.
1942 * No locks are obtained or released by this function
1946 * Returns != 0 upon successful completion.
1951 util_CMGetServerPrefsDone(const void *iterationId, afs_status_p st)
1954 afs_status_t tst = 0;
1955 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
1957 if (iterationId == NULL) {
1958 tst = ADMITERATIONIDPNULL;
1959 goto fail_util_CMGetServerPrefsDone;
1962 rc = IteratorDone(iter, &tst);
1965 fail_util_CMGetServerPrefsDone:
1974 * The iterator for listing CM CellServDB
1977 typedef struct cm_list_cell_get {
1978 struct rx_connection *conn;
1980 afs_CMListCell_t cell[CACHED_ITEMS];
1981 } cm_list_cell_get_t, *cm_list_cell_get_p;
1984 ListCellsRPC(void *rpc_specific, int slot, int *last_item,
1985 int *last_item_contains_data, afs_status_p st)
1988 afs_status_t tst = 0;
1989 cm_list_cell_get_p t = (cm_list_cell_get_p) rpc_specific;
1993 * Get the next entry in the CellServDB.
1995 name = t->cell[slot].cellname;
1997 RXAFSCB_GetCellServDB(t->conn, t->index, &name,
1998 t->cell[slot].serverAddr);
2000 goto fail_ListCellsRPC;
2002 strcpy(t->cell[slot].cellname, name);
2005 * See if we've processed all the entries
2007 if (strlen(t->cell[slot].cellname) == 0) {
2009 *last_item_contains_data = 0;
2024 ListCellsFromCache(void *rpc_specific, int slot, void *dest, afs_status_p st)
2027 afs_status_t tst = 0;
2028 cm_list_cell_get_p cell = (cm_list_cell_get_p) rpc_specific;
2030 memcpy(dest, (const void *)&cell->cell[slot], sizeof(afs_CMListCell_t));
2040 * util_CMListCellsBegin - Begin listing cache manager CellServDB
2044 * IN conn - an rx connection to the process to be queried
2046 * OUT iterationIdP - an iteration id that can be passed to
2047 * util_CMListCellsNext to get the next cell
2051 * No locks are obtained or released by this function
2055 * Returns != 0 upon successful completion.
2060 util_CMListCellsBegin(struct rx_connection *conn, void **iterationIdP,
2064 afs_status_t tst = 0;
2065 afs_admin_iterator_p iter;
2066 cm_list_cell_get_p cell;
2069 tst = ADMRXCONNNULL;
2070 goto fail_util_CMListCellsBegin;
2073 iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2076 goto fail_util_CMListCellsBegin;
2079 cell = (cm_list_cell_get_p) malloc(sizeof(cm_list_cell_get_t));
2083 goto fail_util_CMListCellsBegin;
2089 (iter, (void *)cell, ListCellsRPC, ListCellsFromCache, NULL, NULL,
2093 goto fail_util_CMListCellsBegin;
2095 *iterationIdP = (void *)iter;
2098 fail_util_CMListCellsBegin:
2107 * util_CMListCellsNext - Get next entry in cache manager cells
2111 * IN iterationId - Iteration id created by util_CMGetServerPrefsBegin.
2113 * OUT cell - Next entry in cache manager cells.
2117 * No locks are obtained or released by this function
2121 * Returns != 0 upon successful completion.
2126 util_CMListCellsNext(const void *iterationId, afs_CMListCell_p cell,
2130 afs_status_t tst = 0;
2131 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2133 if (iterationId == NULL) {
2134 tst = ADMITERATIONIDPNULL;
2135 goto fail_util_CMListCellsNext;
2138 rc = IteratorNext(iter, (void *)cell, &tst);
2140 fail_util_CMListCellsNext:
2149 * util_CMListCellsDone - Finish listing cache manager cells
2153 * IN iterationId - Iteration id created by util_CMGetServerPrefsBegin.
2157 * No locks are obtained or released by this function
2161 * Returns != 0 upon successful completion.
2166 util_CMListCellsDone(const void *iterationId, afs_status_p st)
2169 afs_status_t tst = 0;
2170 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2172 if (iterationId == NULL) {
2173 tst = ADMITERATIONIDPNULL;
2174 goto fail_util_CMListCellsDone;
2177 rc = IteratorDone(iter, &tst);
2180 fail_util_CMListCellsDone:
2189 * util_CMLocalCell - Get the name of the cache manager's local cell.
2193 * IN conn - an rx connection to the process to be queried
2195 * OUT cellName - the name of the cache manager's local cell.
2199 * No locks are obtained or released by this function
2203 * Returns != 0 upon successful completion.
2208 util_CMLocalCell(struct rx_connection *conn, afs_CMCellName_p cellName,
2212 afs_status_t tst = 0;
2213 afs_CMCellName_p name;
2216 tst = ADMRXCONNNULL;
2217 goto fail_util_CMLocalCell;
2220 if (cellName == NULL) {
2221 tst = ADMCLIENTCMCELLNAMENULL;
2222 goto fail_util_CMLocalCell;
2226 tst = RXAFSCB_GetLocalCell(conn, &name);
2232 fail_util_CMLocalCell:
2241 UnmarshallCMClientConfig(afs_uint32 serverVersion, afs_uint32 * ptr,
2242 afs_ClientConfigUnion_p config)
2245 * We currently only support version 1.
2247 config->config_v1.nChunkFiles = *(ptr++);
2248 config->config_v1.nStatCaches = *(ptr++);
2249 config->config_v1.nDataCaches = *(ptr++);
2250 config->config_v1.nVolumeCaches = *(ptr++);
2251 config->config_v1.firstChunkSize = *(ptr++);
2252 config->config_v1.otherChunkSize = *(ptr++);
2253 config->config_v1.cacheSize = *(ptr++);
2254 config->config_v1.setTime = *(ptr++);
2255 config->config_v1.memCache = *(ptr++);
2259 * util_CMClientConfig - Get the cache manager's configuration parameters.
2263 * IN conn - an rx connection to the process to be queried
2265 * OUT config - the cache manager's configuration parameters.
2269 * No locks are obtained or released by this function
2273 * Returns != 0 upon successful completion.
2278 util_CMClientConfig(struct rx_connection *conn, afs_ClientConfig_p config,
2282 afs_status_t tst = 0;
2283 afs_int32 allocbytes;
2284 struct cacheConfig tconfig;
2287 tst = ADMRXCONNNULL;
2288 goto fail_util_CMClientConfig;
2291 if (config == NULL) {
2292 tst = ADMCLIENTCMCELLNAMENULL;
2293 goto fail_util_CMClientConfig;
2296 config->clientVersion = AFS_CLIENT_RETRIEVAL_VERSION;
2297 tconfig.cacheConfig_val = NULL;
2298 tconfig.cacheConfig_len = 0;
2300 RXAFSCB_GetCacheConfig(conn, config->clientVersion,
2301 &config->serverVersion, &allocbytes, &tconfig);
2304 goto fail_util_CMClientConfig;
2307 UnmarshallCMClientConfig(config->serverVersion, tconfig.cacheConfig_val,
2310 free(tconfig.cacheConfig_val);
2312 fail_util_CMClientConfig:
2321 * util_RXDebugVersion - Get the rxdebug version string.
2325 * IN handle - an rxdebug handle for the process to be queried.
2327 * OUT version - the rxdebug version string.
2331 * No locks are obtained or released by this function
2335 * Returns != 0 upon successful completion.
2340 util_RXDebugVersion(rxdebugHandle_p handle, rxdebugVersion_p version,
2344 afs_status_t tst = 0;
2347 if (handle == NULL) {
2348 tst = ADMRXDEBUGHANDLENULL;
2349 goto fail_util_RXDebugVersion;
2352 if (version == NULL) {
2353 tst = ADMRXDEBUGVERSIONNULL;
2354 goto fail_util_RXDebugVersion;
2358 rx_GetServerVersion(handle->sock, handle->ipAddr, handle->udpPort,
2359 UTIL_MAX_RXDEBUG_VERSION_LEN, version);
2361 tst = ADMCLIENTRXDEBUGTIMEOUT;
2362 goto fail_util_RXDebugVersion;
2367 fail_util_RXDebugVersion:
2376 * util_RXDebugSupportedStats - Get the rxdebug statistics supported by
2381 * IN handle - an rxdebug handle for the process to be queried.
2383 * OUT supportedStats - bit mask with supported rxstats.
2387 * No locks are obtained or released by this function
2391 * Returns != 0 upon successful completion.
2396 util_RXDebugSupportedStats(rxdebugHandle_p handle,
2397 afs_uint32 * supportedStats, afs_status_p st)
2400 afs_status_t tst = 0;
2401 struct rx_debugStats tstats;
2403 if (handle == NULL) {
2404 tst = ADMRXDEBUGHANDLENULL;
2405 goto fail_util_RXDebugSupportedStats;
2408 if (supportedStats == NULL) {
2409 tst = ADMRXDEBUGSTATSNULL;
2410 goto fail_util_RXDebugSupportedStats;
2413 if (handle->firstFlag) {
2414 rc = util_RXDebugBasicStats(handle, &tstats, &tst);
2416 goto fail_util_RXDebugSupportedStats;
2420 *supportedStats = handle->supportedStats;
2423 fail_util_RXDebugSupportedStats:
2433 * util_RXDebugBasicStats - Get the basic rxdebug statistics for the process.
2437 * IN handle - an rxdebug handle for the process to be queried.
2439 * OUT stats - Basic rxdebug statistics for the process.
2443 * No locks are obtained or released by this function
2447 * Returns != 0 upon successful completion.
2452 util_RXDebugBasicStats(rxdebugHandle_p handle, struct rx_debugStats *stats,
2456 afs_status_t tst = 0;
2459 if (handle == NULL) {
2460 tst = ADMRXDEBUGHANDLENULL;
2461 goto fail_util_RXDebugBasicStats;
2464 if (stats == NULL) {
2465 tst = ADMRXDEBUGSTATSNULL;
2466 goto fail_util_RXDebugBasicStats;
2470 rx_GetServerDebug(handle->sock, handle->ipAddr, handle->udpPort,
2471 stats, &handle->supportedStats);
2473 tst = ADMCLIENTRXDEBUGTIMEOUT;
2474 goto fail_util_RXDebugBasicStats;
2477 handle->firstFlag = 0;
2480 fail_util_RXDebugBasicStats:
2490 * util_RXDebugRxStats - Get the detailed rxdebug statistics for the process.
2494 * IN handle - an rxdebug handle for the process to be queried.
2496 * OUT stats - Detailed rxdebug statistics for the process.
2500 * No locks are obtained or released by this function
2504 * Returns != 0 upon successful completion.
2509 util_RXDebugRxStats(rxdebugHandle_p handle, struct rx_stats *stats,
2510 afs_uint32 * supportedValues, afs_status_p st)
2514 afs_status_t tst = 0;
2516 afs_uint32 tsupported;
2518 if (handle == NULL) {
2519 tst = ADMRXDEBUGHANDLENULL;
2520 goto fail_util_RXDebugRxStats;
2523 if (supportedValues == NULL) {
2524 tst = ADMRXDEBUGSTATSNULL;
2525 goto fail_util_RXDebugRxStats;
2528 if (stats == NULL) {
2529 tst = ADMRXDEBUGSTATSNULL;
2530 goto fail_util_RXDebugRxStats;
2533 if (handle->firstFlag) {
2534 trc = util_RXDebugSupportedStats(handle, &tsupported, &tst);
2537 goto fail_util_RXDebugRxStats;
2541 if (!(handle->supportedStats & RX_SERVER_DEBUG_RX_STATS)) {
2542 tst = ADMCLIENTRXDEBUGNOTSUPPORTED;
2543 goto fail_util_RXDebugRxStats;
2547 rx_GetServerStats(handle->sock, handle->ipAddr, handle->udpPort,
2548 stats, &handle->supportedStats);
2550 tst = ADMCLIENTRXDEBUGTIMEOUT;
2551 goto fail_util_RXDebugRxStats;
2556 fail_util_RXDebugRxStats:
2565 * The iterator for listing RXDebug connections
2568 typedef struct rxdebug_conn_item {
2569 struct rx_debugConn conn;
2570 afs_uint32 supportedValues;
2571 } rxdebug_conn_item_t, *rxdebug_conn_item_p;
2573 typedef struct rxdebug_conn_get {
2575 rxdebugHandle_p handle;
2577 rxdebug_conn_item_t items[CACHED_ITEMS];
2578 } rxdebug_conn_get_t, *rxdebug_conn_get_p;
2581 RXDebugConnsFromServer(void *rpc_specific, int slot, int *last_item,
2582 int *last_item_contains_data, afs_status_p st)
2586 afs_status_t tst = 0;
2587 rxdebug_conn_get_p t = (rxdebug_conn_get_p) rpc_specific;
2590 * Get the next entry the list of connections
2593 rx_GetServerConnections(t->handle->sock, t->handle->ipAddr,
2594 t->handle->udpPort, &t->index, t->allconns,
2595 t->handle->supportedStats,
2596 &t->items[slot].conn,
2597 &t->items[slot].supportedValues);
2599 tst = ADMCLIENTRXDEBUGTIMEOUT;
2600 goto fail_ListCellsRPC;
2604 * See if we've processed all the entries
2606 if (t->items[slot].conn.cid == 0xffffffff) {
2608 *last_item_contains_data = 0;
2621 RXDebugConnsFromCache(void *rpc_specific, int slot, void *dest,
2625 afs_status_t tst = 0;
2626 rxdebug_conn_get_p t = (rxdebug_conn_get_p) rpc_specific;
2628 memcpy(dest, (const void *)&t->items[slot], sizeof(rxdebug_conn_item_t));
2638 * util_RXDebugConnectionsBegin - Begin listing rxdebug connection information
2643 * IN handle - an rxdebug handle for the process to be queried
2645 * IN allcons - non-zero to list all connections. If zero, only
2646 * "interesting" connections will be listed.
2648 * OUT iterationIdP - an iteration id that can be passed to
2649 * util_RXDebugConnectionsNext.
2653 * No locks are obtained or released by this function
2657 * Returns != 0 upon successful completion.
2662 util_RXDebugConnectionsBegin(rxdebugHandle_p handle, int allconns,
2663 void **iterationIdP, afs_status_p st)
2667 afs_uint32 tsupported;
2668 afs_status_t tst = 0;
2669 afs_admin_iterator_p iter;
2670 rxdebug_conn_get_p t;
2672 if (handle == NULL) {
2673 tst = ADMRXDEBUGHANDLENULL;
2674 goto fail_util_RXDebugConnectionsBegin;
2677 iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2680 goto fail_util_RXDebugConnectionsBegin;
2683 if (handle->firstFlag) {
2684 trc = util_RXDebugSupportedStats(handle, &tsupported, &tst);
2687 goto fail_util_RXDebugConnectionsBegin;
2691 if (allconns && !(handle->supportedStats & RX_SERVER_DEBUG_ALL_CONN)) {
2692 tst = ADMCLIENTRXDEBUGNOTSUPPORTED;
2693 goto fail_util_RXDebugConnectionsBegin;
2696 t = (rxdebug_conn_get_p) malloc(sizeof(rxdebug_conn_get_t));
2700 goto fail_util_RXDebugConnectionsBegin;
2703 t->allconns = allconns;
2707 (iter, (void *)t, RXDebugConnsFromServer, RXDebugConnsFromCache, NULL,
2709 goto fail_util_RXDebugConnectionsBegin;
2711 *iterationIdP = (void *)iter;
2714 fail_util_RXDebugConnectionsBegin:
2724 * util_RXDebugConnectionsNext - Get rxdebug information for the next
2729 * IN iterationId - Iteration id created by util_RXDebugConnectionsNext.
2731 * OUT conn - Rxdebug information for the next connection.
2733 * OUT supportedValues - Bit mask of supported rxdebug values.
2737 * No locks are obtained or released by this function
2741 * Returns != 0 upon successful completion.
2746 util_RXDebugConnectionsNext(const void *iterationId,
2747 struct rx_debugConn *conn,
2748 afs_uint32 * supportedValues, afs_status_p st)
2751 afs_status_t tst = 0;
2752 rxdebug_conn_item_t item;
2753 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2755 if (iterationId == NULL) {
2756 tst = ADMITERATIONIDPNULL;
2757 goto fail_util_RXDebugConnectionsNext;
2761 tst = ADMRXDEBUGHANDLENULL;
2762 goto fail_util_RXDebugConnectionsNext;
2765 if (supportedValues == NULL) {
2766 tst = ADMRXDEBUGHANDLENULL;
2767 goto fail_util_RXDebugConnectionsNext;
2770 rc = IteratorNext(iter, (void *)&item, &tst);
2772 goto fail_util_RXDebugConnectionsNext;
2776 *supportedValues = item.supportedValues;
2778 fail_util_RXDebugConnectionsNext:
2788 * util_RXDebugConnectionsDone - Finish listing rxdebug connection information.
2792 * IN iterationId - Iteration id created by util_RXDebugConnectionsBegin.
2796 * No locks are obtained or released by this function
2800 * Returns != 0 upon successful completion.
2805 util_RXDebugConnectionsDone(const void *iterationId, afs_status_p st)
2808 afs_status_t tst = 0;
2809 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
2812 * Validate parameters
2816 tst = ADMITERATORNULL;
2817 goto fail_util_RXDebugConnectionsDone;
2820 rc = IteratorDone(iter, &tst);
2822 fail_util_RXDebugConnectionsDone:
2832 * The iterator for listing RXDebug peer
2835 typedef struct rxdebug_peer_item {
2836 struct rx_debugPeer peer;
2837 afs_uint32 supportedValues;
2838 } rxdebug_peer_item_t, *rxdebug_peer_item_p;
2840 typedef struct rxdebug_peer_get {
2841 rxdebugHandle_p handle;
2843 rxdebug_peer_item_t items[CACHED_ITEMS];
2844 } rxdebug_peer_get_t, *rxdebug_peer_get_p;
2847 RXDebugPeersFromServer(void *rpc_specific, int slot, int *last_item,
2848 int *last_item_contains_data, afs_status_p st)
2852 afs_status_t tst = 0;
2853 rxdebug_peer_get_p t = (rxdebug_peer_get_p) rpc_specific;
2856 * Get the next entry the list of peers
2859 rx_GetServerPeers(t->handle->sock, t->handle->ipAddr,
2860 t->handle->udpPort, &t->index,
2861 t->handle->supportedStats, &t->items[slot].peer,
2862 &t->items[slot].supportedValues);
2864 tst = ADMCLIENTRXDEBUGTIMEOUT;
2865 goto fail_ListCellsRPC;
2869 * See if we've processed all the entries
2871 if (t->items[slot].peer.host == 0xffffffff) {
2873 *last_item_contains_data = 0;
2886 RXDebugPeersFromCache(void *rpc_specific, int slot, void *dest,
2890 afs_status_t tst = 0;
2891 rxdebug_peer_get_p t = (rxdebug_peer_get_p) rpc_specific;
2893 memcpy(dest, (const void *)&t->items[slot], sizeof(rxdebug_peer_item_t));
2904 * util_RXDebugPeersBegin - Begin listing rxdebug peer information for
2909 * IN handle - an rxdebug handle for the process to be queried
2911 * OUT iterationIdP - an iteration id that can be passed to
2912 * util_RXDebugPeersNext.
2916 * No locks are obtained or released by this function
2920 * Returns != 0 upon successful completion.
2925 util_RXDebugPeersBegin(rxdebugHandle_p handle, void **iterationIdP,
2930 afs_uint32 tsupported;
2931 afs_status_t tst = 0;
2932 afs_admin_iterator_p iter;
2933 rxdebug_peer_get_p t;
2935 if (handle == NULL) {
2936 tst = ADMRXDEBUGHANDLENULL;
2937 goto fail_util_RXDebugPeersBegin;
2940 iter = (afs_admin_iterator_p) malloc(sizeof(afs_admin_iterator_t));
2943 goto fail_util_RXDebugPeersBegin;
2946 if (handle->firstFlag) {
2947 trc = util_RXDebugSupportedStats(handle, &tsupported, &tst);
2950 goto fail_util_RXDebugPeersBegin;
2954 if (!(handle->supportedStats & RX_SERVER_DEBUG_ALL_PEER)) {
2955 tst = ADMCLIENTRXDEBUGNOTSUPPORTED;
2956 goto fail_util_RXDebugPeersBegin;
2959 t = (rxdebug_peer_get_p) malloc(sizeof(rxdebug_peer_get_t));
2963 goto fail_util_RXDebugPeersBegin;
2969 (iter, (void *)t, RXDebugPeersFromServer, RXDebugPeersFromCache, NULL,
2971 goto fail_util_RXDebugPeersBegin;
2973 *iterationIdP = (void *)iter;
2976 fail_util_RXDebugPeersBegin:
2985 * util_RXDebugPeersNext - Get rxdebug information for the next peer.
2989 * IN iterationId - Iteration id created by util_RXDebugPeersBegin.
2991 * OUT peer - Rxdebug information for the next peer.
2993 * OUT supportedValues - Bit mask of supported rxdebug values.
2997 * No locks are obtained or released by this function
3001 * Returns != 0 upon successful completion.
3005 util_RXDebugPeersNext(const void *iterationId, struct rx_debugPeer *peer,
3006 afs_uint32 * supportedValues, afs_status_p st)
3009 afs_status_t tst = 0;
3010 rxdebug_peer_item_t item;
3011 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
3013 if (iterationId == NULL) {
3014 tst = ADMITERATIONIDPNULL;
3015 goto fail_util_RXDebugPeersNext;
3019 tst = ADMRXDEBUGHANDLENULL;
3020 goto fail_util_RXDebugPeersNext;
3023 if (supportedValues == NULL) {
3024 tst = ADMRXDEBUGHANDLENULL;
3025 goto fail_util_RXDebugPeersNext;
3028 rc = IteratorNext(iter, (void *)&item, &tst);
3030 goto fail_util_RXDebugPeersNext;
3034 *supportedValues = item.supportedValues;
3036 fail_util_RXDebugPeersNext:
3045 * util_RXDebugPeersDone - Finish listing rxdebug peer information.
3049 * IN iterationId - Iteration id created by util_RXDebugPeersBegin.
3053 * No locks are obtained or released by this function
3057 * Returns != 0 upon successful completion.
3062 util_RXDebugPeersDone(const void *iterationId, afs_status_p st)
3065 afs_status_t tst = 0;
3066 afs_admin_iterator_p iter = (afs_admin_iterator_p) iterationId;
3069 * Validate parameters
3073 tst = ADMITERATORNULL;
3074 goto fail_util_RXDebugPeersDone;
3077 rc = IteratorDone(iter, &tst);
3079 fail_util_RXDebugPeersDone: