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/afs_args.h>
22 #include <afs/afsutil.h>
25 #include <afs/sys_prototypes.h>
27 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
28 /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */
29 int afs_icl_sizeofLong = 2;
31 int afs_icl_sizeofLong = 1;
34 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
35 int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */
36 extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */
39 /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */
41 set_kernel_sizeof_long(void)
46 retval = sysconf(_SC_KERN_POINTERS);
49 afs_icl_sizeofLong = 2;
52 afs_icl_sizeofLong = 1;
56 #endif /* AFS_SGI62_ENV */
57 #endif /* AFS_SGI61_ENV */
59 int afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
60 long parm4, long parm5, long parm6);
61 void dce1_error_inq_text(afs_uint32 status_to_convert,
62 char *error_text, int *status);
63 int icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
64 struct afs_icl_log *fatalLogp, afs_uint32 flags,
65 struct afs_icl_set **outSetpp);
66 int icl_LogHold(struct afs_icl_log *logp);
67 int icl_LogUse(struct afs_icl_log *logp);
68 int icl_LogReleNL(struct afs_icl_log *logp);
69 int icl_LogRele(struct afs_icl_log *logp);
70 int icl_ZeroLog(struct afs_icl_log *logp);
71 int icl_LogFreeUse(struct afs_icl_log *logp);
73 #define BUFFER_MULTIPLIER 1024
75 /* make it big enough to snapshot everything at once, since
76 * decoding takes so long.
78 #define IBSIZE 100000 /* default size */
81 struct logInfo *nextp;
85 char dumpFileName[256] = "";
87 RegisterIclDumpFileName(char *name)
89 (void)sprintf(dumpFileName, "icl.%.250s", name);
92 /* define globals to use for bulk info */
93 afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *) 0;
94 afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *) 0;
96 struct afs_icl_set *icl_allSets = 0;
100 /* given a type and an address, get the size of the thing
104 icl_GetSize(afs_int32 type, char *addr)
110 ICL_SIZEHACK(type, addr, tsize, rsize);
114 /* Check types in printf string "bufferp", making sure that each
115 * is compatible with the corresponding parameter type described
116 * by typesp. Also watch for prematurely running out of parameters
117 * before the string is gone.
119 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
121 CheckTypes(char *bufferp, int *typesp, int typeCount, char *outMsgBuffer)
129 for (tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) {
132 /* hit end of string. We win as long as we aren't
141 inPercent = 1 - inPercent;
145 if (tc >= '0' && tc <= '9') {
146 /* skip digits in % string */
151 /* 'l' is a type modifier. */
155 /* otherwise, we've finally gotten to the type-describing
156 * character. Make sure there's a type descriptor, and then
157 * check the type descriptor.
160 if (tix >= typeCount)
161 return 0; /* no more type descriptors left */
163 if (typesp[tix] != 1) /* not a string descriptor */
166 *outMsgBuffer = (char)1;
168 if (tc == 'u' || tc == 'x' || tc == 'd' || tc == 'o') {
169 if (typesp[tix] != 0)
170 return 0; /* not an integer descriptor */
174 *outMsgBuffer = (char)2;
177 *outMsgBuffer = (char)3;
180 *outMsgBuffer = (char)4;
184 *outMsgBuffer = (char)5;
188 /* otherwise we're fine, so eat this descriptor */
194 #else /* AFS_SGI61_ENV */
196 CheckTypes(char *bufferp, int *typesp, int typeCount)
204 for (tc = *bufferp;; tc = *(++bufferp)) {
206 /* hit end of string. We win as long as we aren't
215 inPercent = 1 - inPercent;
219 if (tc >= '0' && tc <= '9')
220 continue; /* skip digits in % string */
221 /* otherwise, we've finally gotten to the type-describing
222 * character. Make sure there's a type descriptor, and then
223 * check the type descriptor.
226 if (tix >= typeCount)
227 return 0; /* no more type descriptors left */
228 if (tc == 's' && typesp[tix] != 1) /* not a string descriptor */
230 if ((tc == 'u' || tc == 'l' || tc == 'x' || tc == 'd')
231 && (typesp[tix] != 0))
232 return 0; /* not an integer descriptor */
233 /* otherwise we're fine, so eat this descriptor */
239 #endif /* AFS_SGI61_ENV */
241 /* display a single record.
242 * alp points at the first word in the array to be interpreted
243 * rsize gives the # of words in the array
245 #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV)
246 #define uint64_t long long
249 DisplayRecord(FILE *outFilep, afs_int32 *alp, afs_int32 rsize)
251 char msgBuffer[1024];
252 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
253 char outMsgBuffer[1024];
255 uint64_t printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
256 char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4];
257 #else /* AFS_SGI61_ENV */
258 long printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
259 #endif /* AFS_SGI61_ENV */
260 int printfTypes[ICL_MAXEXPANSION * 4];
266 int pix; /* index in alp */
267 int pfpix; /* index in printfParms */
268 int pftix; /* index in printfTypes */
270 int printed; /* did we print the string yet? */
273 /* decode parameters */
274 temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */
280 for (i = 0; i < 4 * ICL_MAXEXPANSION; i++)
282 /* decode each parameter, getting addrs for afs_hyper_t and strings */
283 for (i = 0; !done && i < 4; i++) {
284 type = (temp >> (18 - i * 6)) & 0x3f;
290 case ICL_TYPE_POINTER:
291 printfTypes[pftix++] = 0;
292 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
293 printfParms[pfpix] = alp[pix];
294 printfParms[pfpix] &= 0xffffffff;
295 if (afs_64bit_kernel) {
296 printfParms[pfpix] <<= 32;
297 printfParms[pfpix] |= alp[pix + 1];
299 #else /* !AFS_SGI61_ENV */
300 printfParms[pfpix] = alp[pix];
305 printfTypes[pftix++] = 0;
306 printfParms[pfpix++] = alp[pix];
310 printfTypes[pftix++] = 0;
311 printfParms[pfpix++] = alp[pix];
312 printfTypes[pftix++] = 0;
313 printfParms[pfpix++] = alp[pix + 1];
316 printfTypes[pftix++] = 0;
317 printfParms[pfpix++] = alp[pix];
318 printfTypes[pftix++] = 0;
319 printfParms[pfpix++] = alp[pix + 1];
320 printfTypes[pftix++] = 0;
321 printfParms[pfpix++] = alp[pix + 2];
322 printfTypes[pftix++] = 0;
323 printfParms[pfpix++] = alp[pix + 3];
325 case ICL_TYPE_STRING:
326 printfTypes[pftix++] = 1;
328 printfStrings[pfpix++] = (char *)&alp[pix];
329 #else /* AFS_SGI64_ENV */
330 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
331 printfStrings[pfpix++] = (char *)&alp[pix];
332 #else /* AFS_SGI61_ENV */
333 printfParms[pfpix++] = (long)&alp[pix];
334 #endif /* AFS_SGI61_ENV */
335 #endif /* AFS_SGI64_ENV */
337 case ICL_TYPE_UNIXDATE:
339 printfParms[pfpix++] = (long)ctime(&tmv);
342 printf("DisplayRecord: Bad type %d in decode switch.\n", type);
349 pix += icl_GetSize(type, (char *)&alp[pix]);
352 /* next, try to decode the opcode into a printf string */
353 dce1_error_inq_text(alp[1], msgBuffer, &status);
355 /* if we got a string back, and it is compatible with the
356 * parms we've got, then print it.
360 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
361 if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) {
362 /* we have a string to use, but it ends "(dfs / zcm)",
363 * so we remove the extra gunk.
365 j = strlen(outMsgBuffer);
367 outMsgBuffer[j - 11] = 0;
371 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
372 alp[3] % 1000000, alp[2]);
373 for (i = 0; i < j; i++) {
374 if ((int)outMsgBuffer[i] > 5)
375 fputc(outMsgBuffer[i], outFilep);
377 switch (outMsgBuffer[i]) {
381 fprintf(outFilep, "%s", printfStrings[pfpix++]);
383 case 2: /* signed integer */
384 fprintf(outFilep, "%" AFS_INT64_FMT, printfParms[pfpix++]);
386 case 3: /* unsigned integer */
387 fprintf(outFilep, "%llu", printfParms[pfpix++]);
389 case 4: /* octal integer */
390 fprintf(outFilep, "%llo", printfParms[pfpix++]);
392 case 5: /* hex integer */
393 fprintf(outFilep, "%llx", printfParms[pfpix++]);
397 "fstrace: Bad char %d in outMsgBuffer for parm %d\n",
398 outMsgBuffer[i], pfpix);
399 fprintf(outFilep, "fstrace: msgBuffer='%s'\n",
405 fprintf(outFilep, "\n");
408 #else /* AFS_SGI61_ENV */
409 if (CheckTypes(msgBuffer, printfTypes, pftix)) {
410 /* we have a string to use, but it ends "(dfs / zcm)",
411 * so we remove the extra gunk.
413 j = strlen(msgBuffer);
415 msgBuffer[j - 11] = 0;
416 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
417 alp[3] % 1000000, alp[2]);
418 fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1],
419 printfParms[2], printfParms[3], printfParms[4],
420 printfParms[5], printfParms[6], printfParms[7],
421 printfParms[8], printfParms[9], printfParms[10],
422 printfParms[11], printfParms[12], printfParms[13],
423 printfParms[14], printfParms[15]);
424 fprintf(outFilep, "\n");
427 #endif /* AFS_SGI61_ENV */
429 fprintf(outFilep, "Type mismatch, using raw print.\n");
430 fprintf(outFilep, "%s", msgBuffer);
434 if (alp[1] == ICL_INFO_TIMESTAMP) {
436 fprintf(outFilep, "time %d.%06d, pid %u: %s\n", alp[3] / 1000000,
437 alp[3] % 1000000, alp[2], ctime(&tmv));
439 fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n", alp[1],
440 alp[3] / 1000000, alp[3] % 1000000, alp[2]);
441 /* now decode each parameter and print it */
444 for (i = 0; !done && i < 4; i++) {
445 type = (temp >> (18 - i * 6)) & 0x3f;
451 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
455 tempParam = alp[pix];
457 tempParam |= alp[pix + 1];
458 fprintf(outFilep, "p%d:%" AFS_INT64_FMT " ", i, tempParam);
459 #else /* AFS_SGI61_ENV */
460 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
461 #endif /* AFS_SGI61_ENV */
463 case ICL_TYPE_POINTER:
465 tempParam = alp[pix];
467 tempParam |= alp[pix + 1];
468 fprintf(outFilep, "p%d:0x%llx ", i, tempParam);
469 #else /* AFS_SGI61_ENV */
470 fprintf(outFilep, "p%d:0x%x ", i, alp[pix]);
471 #endif /* AFS_SGI61_ENV */
475 fprintf(outFilep, "p%d:%x.%x ", i, alp[pix],
479 fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix],
480 alp[pix + 1], alp[pix + 2], alp[pix + 3]);
482 case ICL_TYPE_STRING:
483 fprintf(outFilep, "p%d:%s ", i, (char *)&alp[pix]);
485 case ICL_TYPE_UNIXDATE:
487 fprintf(outFilep, "p%d:%s ", i,
492 ("DisplayRecord: Bad type %d in raw print switch.\n",
500 pix += icl_GetSize(type, (char *)&alp[pix]);
503 fprintf(outFilep, "\n"); /* done with line */
510 #include <nl_types.h>
512 #define FACILITY_CODE_MASK 0xF0000000
513 #define FACILITY_CODE_SHIFT 28
515 #define COMPONENT_CODE_MASK 0x0FFFF000
516 #define COMPONENT_CODE_SHIFT 12
518 #define STATUS_CODE_MASK 0x00000FFF
519 #define STATUS_CODE_SHIFT 0
521 #define NO_MESSAGE "THIS IS NOT A MESSAGE"
524 * We use NLS message catalog functions to convert numbers to human-readable
525 * strings. The message catalog will be in AFSDIR_DATA_DIR, which is
526 * ${datadir}/openafs with normal paths and /usr/vice/etc (for historical
527 * compatibility) for Transarc paths.
531 dce1_error_inq_text(afs_uint32 status_to_convert,
532 char *error_text, int *status)
534 unsigned short facility_code;
535 unsigned short component_code;
536 unsigned short status_code;
539 char component_name[4];
541 char filename_prefix[7];
542 char nls_filename[80];
544 static char *facility_names[] = {
550 * set up output status for future error returns
552 if (status != NULL) {
556 * check for ok input status
558 if (status_to_convert == 0) {
559 if (status != NULL) {
562 strcpy((char *)error_text, "successful completion");
567 * extract the component, facility and status codes
570 (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT;
572 (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT;
573 status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT;
576 * see if this is a recognized facility
578 if (facility_code == 0
579 || facility_code > sizeof(facility_names) / sizeof(char *)) {
580 sprintf((char *)error_text, "status %08x (unknown facility)",
584 facility_name = facility_names[facility_code - 1];
586 * Convert component name from RAD-50 component code. (Mapping is:
587 * 0 => 'a', ..., 25 => 'z', 26 => '{', 27 => '0', ..., 36 => '9'.)
589 component_name[3] = 0;
590 component_name[2] = component_code % 40;
591 component_code /= 40;
592 component_name[1] = component_code % 40;
593 component_name[0] = component_code / 40;
594 for (i = 0; i < 3; i++) {
595 component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27);
597 sprintf(filename_prefix, "%3s%3s", facility_name, component_name);
600 * We do not use the normal NLS message catalog search path since our use
601 * message catalogs isn't a typical use. It wouldn't make sense to
602 * install this special message catalog in with internationalization
605 snprintf(nls_filename, sizeof(nls_filename), "%s/C/%s.cat",
606 AFSDIR_CLIENT_DATA_DIRPATH, filename_prefix);
608 catd = catopen(nls_filename, 0);
609 if (catd == (nl_catd) -1) {
610 sprintf((char *)error_text, "status %08x (%s / %s)",
611 status_to_convert, facility_name, component_name);
615 * try to get the specified message from the file
617 message = (char *)catgets(catd, 1, status_code, NO_MESSAGE);
619 * if everything went well, return the resulting message
621 if (strcmp(message, NO_MESSAGE) != 0) {
622 sprintf((char *)error_text, "%s (%s / %s)", message, facility_name,
624 if (status != NULL) {
628 sprintf((char *)error_text, "status %08x (%s / %s)",
629 status_to_convert, facility_name, component_name);
635 icl_DumpKernel(FILE *outFilep, char *setname)
637 afs_int32 bufferSize = 0;
640 afs_int32 code, retVal = 0;
645 afs_int32 dummy, dummy2;
648 /* first, enumerate the logs we're interested in */
651 /* dump logs for a particular set */
652 for (i = 0; i < ICL_LOGSPERSET; i++) {
654 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname,
655 i, (long)tname, sizeof(tname), 0, 0);
657 if (errno == EBADF) {
658 continue; /* missing slot, nothing to worry about */
663 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
664 (long)&dummy, (long)&dummy2, 0, 0, 0);
668 if (dummy > bufferSize) /* find biggest log */
670 lip = calloc(1, sizeof(struct logInfo));
671 lip->nextp = allInfo;
673 lip->name = strdup(tname);
678 for (i = 0; i < 1000; i++) {
680 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
681 sizeof(tname), (long)&dummy, 0, 0);
684 if (dummy > bufferSize) /* find biggest log */
686 lip = calloc(1, sizeof(struct logInfo));
687 lip->nextp = allInfo;
689 lip->name = strdup(tname);
695 bufferp = malloc(sizeof(afs_int32) * bufferSize);
699 fprintf(outFilep, "Found %d logs.\n", i);
701 /* now print out the contents of each log */
702 for (lip = allInfo; lip; lip = lip->nextp) {
703 fprintf(outFilep, "\nContents of log %s:\n", lip->name);
704 /* read out everything first; gets a more consistent
707 nwords = 0; /* total words copied out */
709 /* display all the entries in the log */
710 if (bufferSize - nwords <= 0)
711 break; /* filled whole buffer */
713 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT, (long)lip->name,
714 (long)(bufferp + nwords), bufferSize - nwords,
717 /* otherwise we've got an error */
718 fprintf(outFilep, "Returned error %d dumping log.\n", errno);
721 /* otherwise, we have flags in the high order byte, and
722 * a length (in words) in the remainder.
724 if ((code >> 24) & ICL_COPYOUTF_MISSEDSOME)
725 fprintf(outFilep, "Log wrapped; data missing.\n");
733 } /* for loop over all cookies */
735 /* otherwise we should display all of the log entries here.
736 * Note that a record may end in the middle, in which case
737 * we should start over with the cookie value of the start
740 for (ix = 0; ix < nwords;) {
741 /* start of a record */
742 rlength = (bufferp[ix] >> 24) & 0xff;
744 fprintf(outFilep, "Internal error: 0 length record\n");
748 /* ensure that entire record fits */
749 if (ix + rlength > nwords) {
750 /* doesn't fit, adjust cookie and break */
753 /* print the record */
754 DisplayRecord(outFilep, &bufferp[ix], rlength);
757 /* obsolete: read entire buffer first */
758 i += rlength; /* update cookie value, too */
760 } /* for loop displaying buffer */
761 } /* for loop over all logs */
768 /* clear out log 'name' */
770 icl_ClearLog(char *name)
774 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRLOG, (long)name, 0, 0, 0, 0, 0);
778 /* clear out set 'name' */
780 icl_ClearSet(char *name)
784 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long)name, 0, 0, 0, 0, 0);
788 /* clear out all logs */
794 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRALL, 0, 0, 0, 0, 0, 0);
798 /* list out all available sets to outFileP */
800 icl_ListSets(FILE *outFileP)
807 for (i = 0; i < 1000; i++) {
809 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS, i, (long)tname,
810 sizeof(tname), (long)&states, 0, 0);
813 (void)fprintf(outFileP, "%s %s%s%s\n", tname,
814 (states & ICL_SETF_ACTIVE) ? "active" : "inactive",
815 (states & ICL_SETF_FREED) ? " (dormant)" : "",
816 (states & ICL_SETF_PERSISTENT) ? " persistent" : "");
822 /* list out all available logs to outFileP */
824 icl_ListLogs(FILE *outFileP, int int32flg)
832 for (i = 0; i < 1000; i++) {
834 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
835 sizeof(tname), (long)&logSize, 0, 0);
839 /* get more information on the log */
841 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
842 (long)&logSize, (long)&allocated, 0, 0, 0);
845 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
847 allocated ? "allocated" : "unallocated");
849 (void)fprintf(outFileP, "%s\n", tname);
855 /* list out all available logs to outFileP */
857 icl_ListLogsBySet(FILE *outFileP, char *setname, int int32flg)
865 for (i = 0; i < ICL_LOGSPERSET; i++) {
867 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname, i,
868 (long)tname, sizeof(tname), 0, 0);
870 if (errno == EBADF) {
872 continue; /* missing */
877 /* get more information on the log */
879 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
880 (long)&logSize, (long)&allocated, 0, 0, 0);
883 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
885 allocated ? "allocated" : "unallocated");
887 (void)fprintf(outFileP, "%s\n", tname);
893 /* activate/deactivate/free specified set */
895 icl_ChangeSetState(char *name, afs_int32 op)
899 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long)name, op, 0, 0, 0, 0);
903 /* activate/deactivate/free all sets */
905 icl_ChangeAllSetState(afs_int32 op)
909 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTATALL, op, 0, 0, 0, 0, 0);
913 /* set size if log */
915 icl_ChangeLogSize(char *name, afs_int32 logSize)
920 afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0,
925 /* get logsize of specified log */
927 icl_GetLogsize(char *logname, afs_int32 *logSizeP, int *allocatedP)
931 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
932 (long)logSizeP, (long)allocatedP, 0, 0, 0);
936 /* get state of specified set */
938 icl_GetSetState(char *setname, afs_int32 *stateP)
942 afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long)setname,
943 (long)stateP, 0, 0, 0, 0);
948 icl_TailKernel(FILE *outFilep, char *logname, afs_int32 waitTime)
950 afs_int32 bufferSize = 0;
951 afs_int32 newBufferSize;
954 afs_int32 code, retVal = 0;
960 /* get information about the specified log */
962 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
963 (long)&bufferSize, (long)&allocated, 0, 0, 0);
966 (void)fprintf(stderr, "'%s' not found\n", logname);
968 (void)fprintf(stderr,
969 "cannot get information on log '%s' (errno = %d)\n",
975 (void)fprintf(stderr, "'%s' not allocated\n", logname);
981 bufferp = malloc(sizeof(afs_int32) * bufferSize);
983 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
988 /* start "infinite" loop */
990 /* read out all that's currently there */
991 nwords = 0; /* total words copied out */
992 i = 0; /* initialize cookie */
994 /* display all the entries in the log */
995 if (bufferSize - nwords <= 0)
996 break; /* filled whole buffer, clear when done */
998 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR, (long)logname,
999 (long)(bufferp + nwords), bufferSize - nwords,
1002 /* otherwise we've got an error */
1003 fprintf(stderr, "returned error %d dumping log.\n", errno);
1007 /* otherwise, we have flags in the high order byte, and
1008 * a length (in words) in the remainder.
1017 } /* for loop over all cookies */
1019 /* otherwise we should display all of the log entries here.
1020 * Note that a record may end in the middle, in which case
1021 * we should start over with the cookie value of the start
1024 for (ix = 0; ix < nwords;) {
1025 /* start of a record */
1026 rlength = (bufferp[ix] >> 24) & 0xff;
1027 /* ensure that entire record fits */
1028 if (ix + rlength > nwords) {
1029 /* doesn't fit, adjust cookie and break */
1031 fprintf(stderr, "BOGUS: 0 length record\n");
1037 /* print the record */
1038 DisplayRecord(outFilep, &bufferp[ix], rlength);
1040 } /* for loop displaying buffer */
1045 /* see if things have changed */
1047 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
1048 (long)&newBufferSize, (long)&allocated, 0, 0, 0);
1050 if (errno == ENOENT)
1051 (void)fprintf(stderr, "'%s' not found\n", logname);
1053 (void)fprintf(stderr,
1054 "cannot get information on log '%s' (errno = %d)\n",
1061 (void)fprintf(stderr, "'%s' no int32er allocated\n", logname);
1066 if (bufferSize == 0) {
1067 (void)fprintf(stderr, "buffer size has become 0\n");
1071 if (bufferSize != newBufferSize) {
1072 /* have to reallocate a buffer */
1073 bufferSize = newBufferSize;
1075 bufferp = malloc(sizeof(afs_int32) * bufferSize);
1077 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
1083 } /* infinite loop */
1090 #if !defined(AFS_SGI_ENV)
1092 afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
1093 long parm4, long parm5, long parm6)
1096 #if defined(AFS_DARWIN80_ENV) || defined(AFS_LINUX20_ENV)
1099 #ifdef AFS_LINUX20_ENV
1100 #if defined AFS_LINUX_64BIT_KERNEL
1102 /* don't want to sign extend it to 64bit, so using ulong */
1103 eparm[0] = (unsigned long)parm3;
1104 eparm[1] = (unsigned long)parm4;
1105 eparm[2] = (unsigned long)parm5;
1106 eparm[3] = (unsigned long)parm6;
1114 /* Linux can only handle 5 arguments in the actual syscall. */
1115 if (call == AFSCALL_ICL) {
1116 rval = proc_afs_syscall(call, parm0, parm1, parm2, (long)eparm, &code);
1119 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm);
1125 rval = proc_afs_syscall(call, parm0, parm1, parm2, parm3, &code);
1128 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3);
1134 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV)
1135 /* on sparc this function returns none value, so do it myself */
1136 __asm__ __volatile__("mov %o0, %i0; ret; restore");
1139 #ifdef AFS_DARWIN80_ENV
1140 code = ioctl_afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, &rval);
1141 if (!code) code = rval;
1143 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
1144 # if defined(AFS_SYSCALL)
1145 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4);
1150 #if defined(AFS_SGI_ENV)
1151 code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */
1153 code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4);
1157 #endif /* AFS_LINUX20_ENV */
1165 /* init function, called once, under icl_lock */
1172 /* setup signal handler, in user space */
1179 icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
1180 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
1182 return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags */ 0,
1186 /* create a set, given pointers to base and fatal logs, if any.
1187 * Logs are unlocked, but referenced, and *outSetpp is returned
1188 * referenced. Function bumps reference count on logs, since it
1189 * addds references from the new icl_set. When the set is destroyed,
1190 * those references will be released.
1193 icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
1194 struct afs_icl_log *fatalLogp, afs_uint32 flags,
1195 struct afs_icl_set **outSetpp)
1197 struct afs_icl_set *setp;
1199 afs_int32 states = ICL_DEFAULT_SET_STATES;
1204 for (setp = icl_allSets; setp; setp = setp->nextp) {
1205 if (strcmp(setp->name, name) == 0) {
1208 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
1209 setp->states |= ICL_SETF_PERSISTENT;
1215 /* determine initial state */
1216 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
1217 states = ICL_SETF_ACTIVE;
1218 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
1219 states = ICL_SETF_FREED;
1220 if (flags & ICL_CRSET_FLAG_PERSISTENT)
1221 states |= ICL_SETF_PERSISTENT;
1223 setp = osi_Alloc(sizeof(struct afs_icl_set));
1224 memset((caddr_t) setp, 0, sizeof(*setp));
1226 if (states & ICL_SETF_FREED)
1227 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
1228 setp->states = states;
1230 setp->name = osi_Alloc(strlen(name) + 1);
1231 strcpy(setp->name, name);
1232 setp->nevents = ICL_DEFAULTEVENTS;
1233 setp->eventFlags = osi_Alloc(ICL_DEFAULTEVENTS);
1234 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
1235 setp->eventFlags[i] = 0xff; /* default to enabled */
1237 /* update this global info under the icl_lock */
1238 setp->nextp = icl_allSets;
1241 /* set's basic lock is still held, so we can finish init */
1243 setp->logs[0] = baseLogp;
1244 icl_LogHold(baseLogp);
1245 if (!(setp->states & ICL_SETF_FREED))
1246 icl_LogUse(baseLogp); /* log is actually being used */
1249 setp->logs[1] = fatalLogp;
1250 icl_LogHold(fatalLogp);
1251 if (!(setp->states & ICL_SETF_FREED))
1252 icl_LogUse(fatalLogp); /* log is actually being used */
1259 /* function to change event enabling information for a particular set */
1261 icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
1265 if (!ICL_EVENTOK(setp, eventID)) {
1268 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
1270 *tp |= ICL_EVENTMASK(eventID);
1272 *tp &= ~(ICL_EVENTMASK(eventID));
1276 /* return indication of whether a particular event ID is enabled
1277 * for tracing. If *getValuep is set to 0, the event is disabled,
1278 * otherwise it is enabled. All events start out enabled by default.
1281 icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep)
1283 if (!ICL_EVENTOK(setp, eventID)) {
1286 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
1293 /* hold and release event sets */
1295 icl_SetHold(struct afs_icl_set *setp)
1301 /* free a set. Called with icl_lock locked */
1303 icl_ZapSet(struct afs_icl_set *setp)
1305 struct afs_icl_set **lpp, *tp;
1307 struct afs_icl_log *tlp;
1309 for (lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1311 /* found the dude we want to remove */
1313 osi_Free(setp->name, 1 + strlen(setp->name));
1314 osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents));
1315 for (i = 0; i < ICL_LOGSPERSET; i++) {
1316 if ((tlp = setp->logs[i]))
1319 osi_Free(setp, sizeof(struct afs_icl_set));
1320 break; /* won't find it twice */
1326 /* do the release, watching for deleted entries */
1328 icl_SetRele(struct afs_icl_set *setp)
1330 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
1331 icl_ZapSet(setp); /* destroys setp's lock! */
1336 /* free a set entry, dropping its reference count */
1338 icl_SetFree(struct afs_icl_set *setp)
1340 setp->states |= ICL_SETF_DELETED;
1345 /* find a set by name, returning it held */
1346 struct afs_icl_set *
1347 icl_FindSet(char *name)
1349 struct afs_icl_set *tp;
1351 for (tp = icl_allSets; tp; tp = tp->nextp) {
1352 if (strcmp(tp->name, name) == 0) {
1353 /* this is the dude we want */
1361 /* zero out all the logs in the set */
1363 icl_ZeroSet(struct afs_icl_set *setp)
1368 struct afs_icl_log *logp;
1370 for (i = 0; i < ICL_LOGSPERSET; i++) {
1371 logp = setp->logs[i];
1374 tcode = icl_ZeroLog(logp);
1376 code = tcode; /* save the last bad one */
1384 icl_EnumerateSets(int (*aproc) (char *, void *, struct afs_icl_set *),
1387 struct afs_icl_set *tp, *np;
1391 for (tp = icl_allSets; tp; tp = np) {
1392 tp->refCount++; /* hold this guy */
1393 code = (*aproc) (tp->name, arock, tp);
1394 np = tp->nextp; /* tp may disappear next, but not np */
1395 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
1404 icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
1409 for (i = 0; i < ICL_LOGSPERSET; i++) {
1410 if (!setp->logs[i]) {
1411 setp->logs[i] = newlogp;
1413 icl_LogHold(newlogp);
1414 if (!(setp->states & ICL_SETF_FREED)) {
1415 /* bump up the number of sets using the log */
1416 icl_LogUse(newlogp);
1425 icl_SetSetStat(struct afs_icl_set *setp, int op)
1429 struct afs_icl_log *logp;
1432 case ICL_OP_SS_ACTIVATE: /* activate a log */
1434 * If we are not already active, see if we have released
1435 * our demand that the log be allocated (FREED set). If
1436 * we have, reassert our desire.
1438 if (!(setp->states & ICL_SETF_ACTIVE)) {
1439 if (setp->states & ICL_SETF_FREED) {
1440 /* have to reassert desire for logs */
1441 for (i = 0; i < ICL_LOGSPERSET; i++) {
1442 logp = setp->logs[i];
1449 setp->states &= ~ICL_SETF_FREED;
1451 setp->states |= ICL_SETF_ACTIVE;
1456 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
1457 /* this doesn't require anything beyond clearing the ACTIVE flag */
1458 setp->states &= ~ICL_SETF_ACTIVE;
1462 case ICL_OP_SS_FREE: /* deassert design for log */
1464 * if we are already in this state, do nothing; otherwise
1465 * deassert desire for log
1467 if (setp->states & ICL_SETF_ACTIVE)
1470 if (!(setp->states & ICL_SETF_FREED)) {
1471 for (i = 0; i < ICL_LOGSPERSET; i++) {
1472 logp = setp->logs[i];
1475 icl_LogFreeUse(logp);
1479 setp->states |= ICL_SETF_FREED;
1492 struct afs_icl_log *afs_icl_allLogs = 0;
1494 /* hold and release logs */
1496 icl_LogHold(struct afs_icl_log *logp)
1502 /* hold and release logs, called with lock already held */
1504 icl_LogHoldNL(struct afs_icl_log *logp)
1510 /* keep track of how many sets believe the log itself is allocated */
1512 icl_LogUse(struct afs_icl_log *logp)
1514 if (logp->setCount == 0) {
1515 /* this is the first set actually using the log -- allocate it */
1516 if (logp->logSize == 0) {
1517 /* we weren't passed in a hint and it wasn't set */
1518 logp->logSize = ICL_DEFAULT_LOGSIZE;
1520 logp->datap = osi_Alloc(sizeof(afs_int32) * logp->logSize);
1526 /* decrement the number of real users of the log, free if possible */
1528 icl_LogFreeUse(struct afs_icl_log *logp)
1530 if (--logp->setCount == 0) {
1531 /* no more users -- free it (but keep log structure around) */
1532 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1533 logp->firstUsed = logp->firstFree = 0;
1534 logp->logElements = 0;
1540 /* set the size of the log to 'logSize' */
1542 icl_LogSetSize(struct afs_icl_log *logp, afs_int32 logSize)
1545 /* nothing to worry about since it's not allocated */
1546 logp->logSize = logSize;
1549 logp->firstUsed = logp->firstFree = 0;
1550 logp->logElements = 0;
1552 /* free and allocate a new one */
1553 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1554 logp->datap = osi_Alloc(sizeof(afs_int32) * logSize);
1555 logp->logSize = logSize;
1561 /* free a log. Called with icl_lock locked. */
1563 icl_ZapLog(struct afs_icl_log *logp)
1565 struct afs_icl_log **lpp, *tp;
1567 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1569 /* found the dude we want to remove */
1571 osi_Free(logp->name, 1 + strlen(logp->name));
1572 osi_Free(logp->datap, logp->logSize * sizeof(afs_int32));
1573 osi_Free(logp, sizeof(struct icl_log));
1574 break; /* won't find it twice */
1580 /* do the release, watching for deleted entries */
1582 icl_LogRele(struct afs_icl_log *logp)
1584 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1585 icl_ZapLog(logp); /* destroys logp's lock! */
1590 /* do the release, watching for deleted entries, log already held */
1592 icl_LogReleNL(struct afs_icl_log *logp)
1594 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1595 icl_ZapLog(logp); /* destroys logp's lock! */
1600 /* zero out the log */
1602 icl_ZeroLog(struct afs_icl_log *logp)
1604 logp->firstUsed = logp->firstFree = 0;
1605 logp->logElements = 0;
1609 /* free a log entry, and drop its reference count */
1611 icl_LogFree(struct afs_icl_log *logp)
1613 logp->states |= ICL_LOGF_DELETED;
1620 icl_EnumerateLogs(int (*aproc)
1621 (char *name, void *arock, struct afs_icl_log * tp),
1624 struct afs_icl_log *tp, *np;
1628 for (tp = afs_icl_allLogs; tp; tp = np) {
1629 tp->refCount++; /* hold this guy */
1631 code = (*aproc) (tp->name, arock, tp);
1632 if (--tp->refCount == 0)
1641 afs_icl_bulkSetinfo_t *
1642 GetBulkSetInfo(void)
1644 unsigned int infoSize;
1647 sizeof(afs_icl_bulkSetinfo_t) + (ICL_RPC_MAX_SETS -
1648 1) * sizeof(afs_icl_setinfo_t);
1650 setInfo = calloc(1, infoSize);
1652 (void)fprintf(stderr,
1653 "Could not allocate the memory for bulk set info structure\n");
1661 afs_icl_bulkLoginfo_t *
1662 GetBulkLogInfo(void)
1664 unsigned int infoSize;
1667 sizeof(afs_icl_bulkLoginfo_t) + (ICL_RPC_MAX_LOGS -
1668 1) * sizeof(afs_icl_loginfo_t);
1670 logInfo = calloc(1, infoSize);
1672 (void)fprintf(stderr,
1673 "Could not allocate the memory for bulk log info structure\n");
1683 DoDump(struct cmd_syndesc *as, void *arock)
1687 afs_int32 waitTime = 10 /* seconds */ ;
1689 FILE *outfp = stdout;
1691 struct cmd_item *itemp;
1693 if (geteuid() != 0) {
1694 printf("fstrace must be run as root\n");
1698 if (as->parms[3].items) {
1699 if (!as->parms[1].items) {
1700 (void)fprintf(stderr, "-sleep can only be used with -follow\n");
1703 waitTime = strtol(as->parms[3].items->data, NULL, 0);
1706 if (as->parms[2].items) {
1707 /* try to open the specified output file */
1708 if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL) {
1709 (void)fprintf(stderr, "Cannot open file '%s' for writing\n",
1710 as->parms[2].items->data);
1714 #ifdef AFS_SGI64_ENV
1715 startTime = time((time_t *) 0);
1717 startTime = time(0);
1719 (void)fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n",
1722 if (as->parms[0].items) {
1723 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1724 tcode = icl_DumpKernel(outfp, itemp->data);
1726 (void)fprintf(stderr, "Unable to dump set %s (errno = %d)\n",
1727 itemp->data, errno);
1731 } else if (as->parms[1].items) {
1732 logname = as->parms[1].items->data;
1733 code = icl_TailKernel(outfp, logname, waitTime);
1735 (void)fprintf(stderr,
1736 "Error tailing kernel log '%s' (errno = %d)\n",
1740 code = icl_DumpKernel(outfp, NULL);
1742 (void)fprintf(outfp, "\nAFS Trace Dump - %s\n",
1743 code ? "FAILED" : "Completed");
1745 if (outfp != stdout)
1746 (void)fclose(outfp);
1754 struct cmd_syndesc *dumpSyntax;
1757 cmd_CreateSyntax("dump", DoDump, NULL, 0, "dump AFS trace logs");
1758 (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
1760 (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL,
1762 (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL,
1763 "path to trace log file for writing");
1764 (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL,
1765 "interval (secs) for writes when using -follow");
1770 DoShowLog(struct cmd_syndesc *as, void *arock)
1772 afs_int32 retVal = 0;
1777 struct cmd_item *itemp;
1779 if (geteuid() != 0) {
1780 printf("fstrace must be run as root\n");
1783 if (as->parms[2].items)
1786 if (as->parms[0].items) {
1787 /* enumerate logs for the specified sets */
1788 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1789 (void)fprintf(stdout, "Logs for set '%s':\n", itemp->data);
1790 code = icl_ListLogsBySet(stdout, itemp->data, int32flg);
1792 (void)fprintf(stderr,
1793 "Error in enumerating set %s (errno = %d)\n",
1794 itemp->data, errno);
1798 } else if (as->parms[1].items) {
1799 /* print out log information */
1800 for (itemp = as->parms[1].items; itemp; itemp = itemp->next) {
1801 code = icl_GetLogsize(itemp->data, &logSize, &allocated);
1803 (void)fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data,
1805 allocated ? "allocated" : "unallocated");
1807 (void)fprintf(stderr,
1808 "Could not find log '%s' (errno = %d)\n",
1809 itemp->data, errno);
1815 (void)fprintf(stdout, "Available logs:\n");
1816 code = icl_ListLogs(stdout, int32flg);
1818 (void)fprintf(stderr, "Error in listing logs (errno = %d)\n",
1830 struct cmd_syndesc *showSyntax;
1833 cmd_CreateSyntax("lslog", DoShowLog, NULL, 0,
1834 "list available logs");
1835 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
1837 (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
1839 (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL,
1840 "show defined log size in kbytes & if it is allocated in kernel mem");
1844 DoShowSet(struct cmd_syndesc *as, void *arock)
1846 afs_int32 retVal = 0;
1849 struct cmd_item *itemp;
1851 if (geteuid() != 0) {
1852 printf("fstrace must be run as root\n");
1855 if (as->parms[0].items) {
1856 /* print information on the specified sets */
1857 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1858 code = icl_GetSetState(itemp->data, &state);
1860 (void)fprintf(stderr,
1861 "Error getting status on set %s (errno = %d)\n",
1862 itemp->data, errno);
1865 (void)fprintf(stdout, "Set %s: %s%s%s\n", itemp->data,
1866 (state & ICL_SETF_ACTIVE) ? "active" :
1868 (state & ICL_SETF_FREED) ? " (dormant)" : "",
1869 (state & ICL_SETF_PERSISTENT) ? " persistent" :
1874 (void)fprintf(stdout, "Available sets:\n");
1875 code = icl_ListSets(stdout);
1877 (void)fprintf(stderr, "Error in listing sets (errno = %d)\n",
1889 struct cmd_syndesc *showSyntax;
1892 cmd_CreateSyntax("lsset", DoShowSet, NULL, 0,
1893 "list available event sets");
1894 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
1899 DoClear(struct cmd_syndesc *as, void *arock)
1901 afs_int32 retVal = 0;
1903 struct cmd_item *itemp;
1905 if (geteuid() != 0) {
1906 printf("fstrace must be run as root\n");
1909 if (as->parms[0].items) {
1910 /* clear logs for the specified sets */
1911 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1912 code = icl_ClearSet(itemp->data);
1914 (void)fprintf(stderr,
1915 "Error in clearing set %s (errno = %d)\n",
1916 itemp->data, errno);
1920 } else if (as->parms[1].items) {
1921 /* clear specified log */
1922 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1923 code = icl_ClearLog(itemp->data);
1925 (void)fprintf(stderr,
1926 "Error in clearing log %s (errno = %d)\n",
1927 itemp->data, errno);
1932 /* clear all logs */
1933 code = icl_ClearAll();
1935 (void)fprintf(stderr, "Error in clearing logs (errno = %d)\n",
1947 struct cmd_syndesc *clearSyntax;
1950 cmd_CreateSyntax("clear", DoClear, NULL, 0,
1951 "clear logs by logname or by event set");
1952 (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
1954 (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
1959 DoSet(struct cmd_syndesc *as, void *arock)
1961 afs_int32 retVal = 0;
1966 struct cmd_item *itemp;
1968 if (geteuid() != 0) {
1969 printf("fstrace must be run as root\n");
1972 if (as->parms[1].items) {
1973 op = ICL_OP_SS_ACTIVATE;
1974 operation = "active";
1975 } else if (as->parms[2].items) {
1976 op = ICL_OP_SS_DEACTIVATE;
1977 operation = "inactive";
1978 } else if (as->parms[3].items) {
1979 op = ICL_OP_SS_DEACTIVATE;
1980 operation = "inactive";
1983 /* assume active" */
1984 op = ICL_OP_SS_ACTIVATE;
1985 operation = "active";
1988 if (as->parms[0].items) {
1989 /* activate specified sets */
1990 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1991 code = icl_ChangeSetState(itemp->data, op);
1993 (void)fprintf(stderr,
1994 "cannot set state of %s to %s (errno = %d)\n",
1995 itemp->data, operation, errno);
1997 } else if (doFree) {
1998 /* try to make it dormant as well */
1999 code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE);
2001 (void)fprintf(stderr,
2002 "cannot set state of %s to dormant (errno = %d)\n",
2003 itemp->data, errno);
2010 code = icl_ChangeAllSetState(op);
2012 (void)fprintf(stderr,
2013 "cannot set the state of all sets to %s (errno = %d)\n",
2016 } else if (doFree) {
2017 /* try to make it dormant as well */
2018 code = icl_ChangeAllSetState(ICL_OP_SS_FREE);
2020 (void)fprintf(stderr,
2021 "cannot set the state of all sets to dormant (errno = %d)\n",
2034 struct cmd_syndesc *setSyntax;
2037 cmd_CreateSyntax("setset", DoSet, NULL, 0,
2038 "set state of event sets");
2039 (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
2041 (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL,
2042 "enable tracing for event set & allocate kernel memory");
2043 (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL,
2044 "disables tracing for event set, keep kernel memory");
2045 (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL,
2046 "disable tracing for event set & free kernel memory");
2050 DoResize(struct cmd_syndesc *as, void *arock)
2052 afs_int32 retVal = 0;
2054 afs_int32 bufferSize;
2055 struct cmd_item *itemp;
2057 if (geteuid() != 0) {
2058 printf("fstrace must be run as root\n");
2061 /* get buffer size */
2062 bufferSize = atoi(as->parms[1].items->data);
2063 bufferSize *= BUFFER_MULTIPLIER;
2064 if (bufferSize == 0)
2065 bufferSize = ICL_DEFAULT_LOGSIZE;
2067 /* set the size of the specified logs */
2068 if ((itemp = as->parms[0].items)) {
2069 for (; itemp; itemp = itemp->next) {
2070 code = icl_ChangeLogSize(itemp->data, bufferSize);
2072 (void)fprintf(stderr,
2073 "Error in changing log %s buffer size (errno = %d)\n",
2074 itemp->data, errno);
2079 /* Use the only current support log, "cmfx" */
2080 code = icl_ChangeLogSize("cmfx", bufferSize);
2082 (void)fprintf(stderr,
2083 "Error in changing log cmfx buffer size (errno = %d)\n",
2095 struct cmd_syndesc *setsizeSyntax;
2098 cmd_CreateSyntax("setlog", DoResize, NULL, 0,
2099 "set the size of a log");
2100 (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
2102 (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED,
2103 "# of 1-kbyte blocks to allocate for log");
2106 #include "AFS_component_version_number.c"
2109 main(int argc, char *argv[])
2111 setlocale(LC_ALL, "");
2112 #ifdef AFS_SGI62_ENV
2113 set_kernel_sizeof_long();
2116 /* set up user interface then dispatch */
2124 return (cmd_Dispatch(argc, argv));