2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
13 #include <afsconfig.h>
14 #include <afs/param.h>
18 #include <sys/types.h>
20 #if !defined(AFS_SUN3_ENV) && !defined(sys_vax_ul43)
22 /*#ifdef AFS_AIX_ENV*/
33 #include <afs/afs_args.h>
35 #include <afs/afsutil.h>
38 #include <afs/sys_prototypes.h>
40 #if defined(AFS_OSF_ENV) || defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
41 /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */
42 int afs_icl_sizeofLong = 2;
44 int afs_icl_sizeofLong = 1;
47 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
48 int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */
49 extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */
53 /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */
55 set_kernel_sizeof_long(void)
60 retval = sysconf(_SC_KERN_POINTERS);
63 afs_icl_sizeofLong = 2;
66 afs_icl_sizeofLong = 1;
70 #endif /* AFS_SGI62_ENV */
71 #endif /* AFS_SGI61_ENV */
73 int afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
74 long parm4, long parm5, long parm6);
75 void dce1_error_inq_text(afs_uint32 status_to_convert,
76 char *error_text, int *status);
77 int icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
78 struct afs_icl_log *fatalLogp, afs_uint32 flags,
79 struct afs_icl_set **outSetpp);
80 int icl_LogHold(register struct afs_icl_log *logp);
81 int icl_LogUse(register struct afs_icl_log *logp);
82 int icl_LogReleNL(register struct afs_icl_log *logp);
83 int icl_LogRele(register struct afs_icl_log *logp);
84 int icl_ZeroLog(register struct afs_icl_log *logp);
85 int icl_LogFreeUse(register struct afs_icl_log *logp);
87 #define BUFFER_MULTIPLIER 1024
89 /* make it big enough to snapshot everything at once, since
90 * decoding takes so long.
92 #define IBSIZE 100000 /* default size */
95 struct logInfo *nextp;
99 char dumpFileName[256] = "";
101 RegisterIclDumpFileName(char *name)
103 (void)sprintf(dumpFileName, "icl.%.250s", name);
106 /* define globals to use for bulk info */
107 afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *) 0;
108 afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *) 0;
110 struct afs_icl_set *icl_allSets = 0;
114 /* given a type and an address, get the size of the thing
118 icl_GetSize(afs_int32 type, char *addr)
124 ICL_SIZEHACK(type, addr);
128 /* Check types in printf string "bufferp", making sure that each
129 * is compatible with the corresponding parameter type described
130 * by typesp. Also watch for prematurely running out of parameters
131 * before the string is gone.
133 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
135 CheckTypes(char *bufferp, int *typesp, int typeCount, char *outMsgBuffer)
143 for (tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) {
146 /* hit end of string. We win as long as we aren't
155 inPercent = 1 - inPercent;
159 if (tc >= '0' && tc <= '9') {
160 /* skip digits in % string */
165 /* 'l' is a type modifier. */
169 /* otherwise, we've finally gotten to the type-describing
170 * character. Make sure there's a type descriptor, and then
171 * check the type descriptor.
175 return 0; /* no more type descriptors left */
177 if (typesp[tix] != 1) /* not a string descriptor */
180 *outMsgBuffer = (char)1;
182 if (tc == 'u' || tc == 'x' || tc == 'd' || tc == 'o') {
183 if (typesp[tix] != 0)
184 return 0; /* not an integer descriptor */
188 *outMsgBuffer = (char)2;
191 *outMsgBuffer = (char)3;
194 *outMsgBuffer = (char)4;
198 *outMsgBuffer = (char)5;
202 /* otherwise we're fine, so eat this descriptor */
208 #else /* AFS_SGI61_ENV */
210 CheckTypes(char *bufferp, int *typesp, int typeCount)
218 for (tc = *bufferp;; tc = *(++bufferp)) {
220 /* hit end of string. We win as long as we aren't
229 inPercent = 1 - inPercent;
233 if (tc >= '0' && tc <= '9')
234 continue; /* skip digits in % string */
235 /* otherwise, we've finally gotten to the type-describing
236 * character. Make sure there's a type descriptor, and then
237 * check the type descriptor.
241 return 0; /* no more type descriptors left */
242 if (tc == 's' && typesp[tix] != 1) /* not a string descriptor */
244 if ((tc == 'u' || tc == 'l' || tc == 'x' || tc == 'd')
245 && (typesp[tix] != 0))
246 return 0; /* not an integer descriptor */
247 /* otherwise we're fine, so eat this descriptor */
253 #endif /* AFS_SGI61_ENV */
255 /* display a single record.
256 * alp points at the first word in the array to be interpreted
257 * rsize gives the # of words in the array
259 #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV)
260 #define uint64_t long long
263 DisplayRecord(FILE *outFilep, register afs_int32 *alp, afs_int32 rsize)
265 char msgBuffer[1024];
266 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
267 char outMsgBuffer[1024];
269 uint64_t printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
270 char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4];
271 #else /* AFS_SGI61_ENV */
272 long printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
273 #endif /* AFS_SGI61_ENV */
274 int printfTypes[ICL_MAXEXPANSION * 4];
280 int pix; /* index in alp */
281 int pfpix; /* index in printfParms */
282 int pftix; /* index in printfTypes */
284 int printed; /* did we print the string yet? */
287 /* decode parameters */
288 temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */
294 for (i = 0; i < 4 * ICL_MAXEXPANSION; i++)
296 /* decode each parameter, getting addrs for afs_hyper_t and strings */
297 for (i = 0; !done && i < 4; i++) {
298 type = (temp >> (18 - i * 6)) & 0x3f;
304 case ICL_TYPE_POINTER:
305 printfTypes[pftix++] = 0;
306 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
307 printfParms[pfpix] = alp[pix];
308 printfParms[pfpix] &= 0xffffffff;
309 if (afs_64bit_kernel) {
310 printfParms[pfpix] <<= 32;
311 printfParms[pfpix] |= alp[pix + 1];
313 #elif defined(AFS_OSF_ENV)
314 printfParms[pfpix] = alp[pix + 1];
315 printfParms[pfpix] |= (alp[pix] <<= 32);
316 #else /* !AFS_OSF_ENV && !AFS_SGI61_ENV */
317 printfParms[pfpix] = alp[pix];
322 printfTypes[pftix++] = 0;
323 printfParms[pfpix++] = alp[pix];
327 printfTypes[pftix++] = 0;
328 printfParms[pfpix++] = alp[pix];
329 printfTypes[pftix++] = 0;
330 printfParms[pfpix++] = alp[pix + 1];
333 printfTypes[pftix++] = 0;
334 printfParms[pfpix++] = alp[pix];
335 printfTypes[pftix++] = 0;
336 printfParms[pfpix++] = alp[pix + 1];
337 printfTypes[pftix++] = 0;
338 printfParms[pfpix++] = alp[pix + 2];
339 printfTypes[pftix++] = 0;
340 printfParms[pfpix++] = alp[pix + 3];
342 case ICL_TYPE_STRING:
343 printfTypes[pftix++] = 1;
345 printfStrings[pfpix++] = (char *)&alp[pix];
346 #else /* AFS_SGI64_ENV */
347 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
348 printfStrings[pfpix++] = (char *)&alp[pix];
349 #else /* AFS_SGI61_ENV */
350 printfParms[pfpix++] = (long)&alp[pix];
351 #endif /* AFS_SGI61_ENV */
352 #endif /* AFS_SGI64_ENV */
354 case ICL_TYPE_UNIXDATE:
356 printfParms[pfpix++] = (long)ctime(&tmv);
359 printf("DisplayRecord: Bad type %d in decode switch.\n", type);
366 pix += icl_GetSize(type, (char *)&alp[pix]);
369 /* next, try to decode the opcode into a printf string */
370 dce1_error_inq_text(alp[1], msgBuffer, &status);
372 /* if we got a string back, and it is compatible with the
373 * parms we've got, then print it.
377 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
378 if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) {
379 /* we have a string to use, but it ends "(dfs / zcm)",
380 * so we remove the extra gunk.
382 j = strlen(outMsgBuffer);
384 outMsgBuffer[j - 11] = 0;
388 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
389 alp[3] % 1000000, alp[2]);
390 for (i = 0; i < j; i++) {
391 if ((int)outMsgBuffer[i] > 5)
392 fputc(outMsgBuffer[i], outFilep);
394 switch (outMsgBuffer[i]) {
398 fprintf(outFilep, "%s", printfStrings[pfpix++]);
400 case 2: /* signed integer */
401 fprintf(outFilep, "%" AFS_INT64_FMT, printfParms[pfpix++]);
403 case 3: /* unsigned integer */
404 fprintf(outFilep, "%llu", printfParms[pfpix++]);
406 case 4: /* octal integer */
407 fprintf(outFilep, "%llo", printfParms[pfpix++]);
409 case 5: /* hex integer */
410 fprintf(outFilep, "%llx", printfParms[pfpix++]);
414 "fstrace: Bad char %d in outMsgBuffer for parm %d\n",
415 outMsgBuffer[i], pfpix);
416 fprintf(outFilep, "fstrace: msgBuffer='%s'\n",
422 fprintf(outFilep, "\n");
425 #else /* AFS_SGI61_ENV */
426 if (CheckTypes(msgBuffer, printfTypes, pftix)) {
427 /* we have a string to use, but it ends "(dfs / zcm)",
428 * so we remove the extra gunk.
430 j = strlen(msgBuffer);
432 msgBuffer[j - 11] = 0;
433 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
434 alp[3] % 1000000, alp[2]);
435 fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1],
436 printfParms[2], printfParms[3], printfParms[4],
437 printfParms[5], printfParms[6], printfParms[7],
438 printfParms[8], printfParms[9], printfParms[10],
439 printfParms[11], printfParms[12], printfParms[13],
440 printfParms[14], printfParms[15]);
441 fprintf(outFilep, "\n");
444 #endif /* AFS_SGI61_ENV */
446 fprintf(outFilep, "Type mismatch, using raw print.\n");
447 fprintf(outFilep, "%s", msgBuffer);
451 if (alp[1] == ICL_INFO_TIMESTAMP) {
453 fprintf(outFilep, "time %d.%06d, pid %u: %s\n", alp[3] / 1000000,
454 alp[3] % 1000000, alp[2], ctime(&tmv));
456 fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n", alp[1],
457 alp[3] / 1000000, alp[3] % 1000000, alp[2]);
458 /* now decode each parameter and print it */
461 for (i = 0; !done && i < 4; i++) {
462 type = (temp >> (18 - i * 6)) & 0x3f;
468 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
472 tempParam = alp[pix];
474 tempParam |= alp[pix + 1];
475 fprintf(outFilep, "p%d:%" AFS_INT64_FMT " ", i, tempParam);
476 #else /* AFS_SGI61_ENV */
477 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
478 #endif /* AFS_SGI61_ENV */
480 case ICL_TYPE_POINTER:
482 tempParam = alp[pix];
484 tempParam |= alp[pix + 1];
485 fprintf(outFilep, "p%d:0x%llx ", i, tempParam);
486 #else /* AFS_SGI61_ENV */
487 fprintf(outFilep, "p%d:0x%x ", i, alp[pix]);
488 #endif /* AFS_SGI61_ENV */
492 fprintf(outFilep, "p%d:%x.%x ", i, alp[pix],
496 fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix],
497 alp[pix + 1], alp[pix + 2], alp[pix + 3]);
499 case ICL_TYPE_STRING:
500 fprintf(outFilep, "p%d:%s ", i, (char *)&alp[pix]);
502 case ICL_TYPE_UNIXDATE:
504 fprintf(outFilep, "p%d:%s ", i,
509 ("DisplayRecord: Bad type %d in raw print switch.\n",
517 pix += icl_GetSize(type, (char *)&alp[pix]);
520 fprintf(outFilep, "\n"); /* done with line */
530 #include <nl_types.h>
532 #define FACILITY_CODE_MASK 0xF0000000
533 #define FACILITY_CODE_SHIFT 28
535 #define COMPONENT_CODE_MASK 0x0FFFF000
536 #define COMPONENT_CODE_SHIFT 12
538 #define STATUS_CODE_MASK 0x00000FFF
539 #define STATUS_CODE_SHIFT 0
541 #define NO_MESSAGE "THIS IS NOT A MESSAGE"
544 * We use NLS message catalog functions to convert numbers to human-readable
545 * strings. The message catalog will be in AFSDIR_DATA_DIR, which is
546 * ${datadir}/openafs with normal paths and /usr/vice/etc (for historical
547 * compatibility) for Transarc paths.
551 dce1_error_inq_text(afs_uint32 status_to_convert,
552 char *error_text, int *status)
554 unsigned short facility_code;
555 unsigned short component_code;
556 unsigned short status_code;
559 char component_name[4];
561 char filename_prefix[7];
562 char nls_filename[80];
564 static char *facility_names[] = {
570 * set up output status for future error returns
572 if (status != NULL) {
576 * check for ok input status
578 if (status_to_convert == 0) {
579 if (status != NULL) {
582 strcpy((char *)error_text, "successful completion");
587 * extract the component, facility and status codes
590 (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT;
592 (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT;
593 status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT;
596 * see if this is a recognized facility
598 if (facility_code == 0
599 || facility_code > sizeof(facility_names) / sizeof(char *)) {
600 sprintf((char *)error_text, "status %08x (unknown facility)",
604 facility_name = facility_names[facility_code - 1];
606 * Convert component name from RAD-50 component code. (Mapping is:
607 * 0 => 'a', ..., 25 => 'z', 26 => '{', 27 => '0', ..., 36 => '9'.)
609 component_name[3] = 0;
610 component_name[2] = component_code % 40;
611 component_code /= 40;
612 component_name[1] = component_code % 40;
613 component_name[0] = component_code / 40;
614 for (i = 0; i < 3; i++) {
615 component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27);
617 sprintf(filename_prefix, "%3s%3s", facility_name, component_name);
620 * We do not use the normal NLS message catalog search path since our use
621 * message catalogs isn't a typical use. It wouldn't make sense to
622 * install this special message catalog in with internationalization
625 afs_snprintf(nls_filename, sizeof(nls_filename), "%s/C/%s.cat",
626 AFSDIR_CLIENT_DATA_DIRPATH, filename_prefix);
628 catd = catopen(nls_filename, 0);
629 if (catd == (nl_catd) -1) {
630 sprintf((char *)error_text, "status %08x (%s / %s)",
631 status_to_convert, facility_name, component_name);
635 * try to get the specified message from the file
637 message = (char *)catgets(catd, 1, status_code, NO_MESSAGE);
639 * if everything went well, return the resulting message
641 if (strcmp(message, NO_MESSAGE) != 0) {
642 sprintf((char *)error_text, "%s (%s / %s)", message, facility_name,
644 if (status != NULL) {
648 sprintf((char *)error_text, "status %08x (%s / %s)",
649 status_to_convert, facility_name, component_name);
655 icl_DumpKernel(FILE *outFilep, char *setname)
657 afs_int32 bufferSize = 0;
660 afs_int32 code, retVal = 0;
665 afs_int32 dummy, dummy2;
668 /* first, enumerate the logs we're interested in */
671 /* dump logs for a particular set */
672 for (i = 0; i < ICL_LOGSPERSET; i++) {
674 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname,
675 i, (long)tname, sizeof(tname), 0, 0);
677 if (errno == EBADF) {
679 continue; /* missing slot, nothing to worry about */
684 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
685 (long)&dummy, (long)&dummy2, 0, 0, 0);
689 if (dummy > bufferSize) /* find biggest log */
691 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
692 memset((char *)lip, 0, sizeof(*lip));
693 lip->nextp = allInfo;
695 lip->name = (char *)malloc(strlen(tname) + 1);
696 strcpy(lip->name, tname);
701 for (i = 0; i < 1000; i++) {
703 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
704 sizeof(tname), (long)&dummy, 0, 0);
707 if (dummy > bufferSize) /* find biggest log */
709 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
710 memset((char *)lip, 0, sizeof(*lip));
711 lip->nextp = allInfo;
713 lip->name = (char *)malloc(strlen(tname) + 1);
714 strcpy(lip->name, tname);
720 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
724 fprintf(outFilep, "Found %d logs.\n", i);
726 /* now print out the contents of each log */
727 for (lip = allInfo; lip; lip = lip->nextp) {
728 fprintf(outFilep, "\nContents of log %s:\n", lip->name);
729 /* read out everything first; gets a more consistent
732 nwords = 0; /* total words copied out */
734 /* display all the entries in the log */
735 if (bufferSize - nwords <= 0)
736 break; /* filled whole buffer */
738 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT, (long)lip->name,
739 (long)(bufferp + nwords), bufferSize - nwords,
742 /* otherwise we've got an error */
743 fprintf(outFilep, "Returned error %d dumping log.\n", errno);
746 /* otherwise, we have flags in the high order byte, and
747 * a length (in words) in the remainder.
749 if ((code >> 24) & ICL_COPYOUTF_MISSEDSOME)
750 fprintf(outFilep, "Log wrapped; data missing.\n");
758 } /* for loop over all cookies */
760 /* otherwise we should display all of the log entries here.
761 * Note that a record may end in the middle, in which case
762 * we should start over with the cookie value of the start
765 for (ix = 0; ix < nwords;) {
766 /* start of a record */
767 rlength = (bufferp[ix] >> 24) & 0xff;
769 fprintf(outFilep, "Internal error: 0 length record\n");
773 /* ensure that entire record fits */
774 if (ix + rlength > nwords) {
775 /* doesn't fit, adjust cookie and break */
778 /* print the record */
779 DisplayRecord(outFilep, &bufferp[ix], rlength);
782 /* obsolete: read entire buffer first */
783 i += rlength; /* update cookie value, too */
785 } /* for loop displaying buffer */
786 } /* for loop over all logs */
793 /* clear out log 'name' */
795 icl_ClearLog(char *name)
799 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRLOG, (long)name, 0, 0, 0, 0, 0);
803 /* clear out set 'name' */
805 icl_ClearSet(char *name)
809 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long)name, 0, 0, 0, 0, 0);
813 /* clear out all logs */
819 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRALL, 0, 0, 0, 0, 0, 0);
823 /* list out all available sets to outFileP */
825 icl_ListSets(FILE *outFileP)
832 for (i = 0; i < 1000; i++) {
834 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS, i, (long)tname,
835 sizeof(tname), (long)&states, 0, 0);
838 (void)fprintf(outFileP, "%s %s%s%s\n", tname,
839 (states & ICL_SETF_ACTIVE) ? "active" : "inactive",
840 (states & ICL_SETF_FREED) ? " (dormant)" : "",
841 (states & ICL_SETF_PERSISTENT) ? " persistent" : "");
847 /* list out all available logs to outFileP */
849 icl_ListLogs(FILE *outFileP, int int32flg)
857 for (i = 0; i < 1000; i++) {
859 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
860 sizeof(tname), (long)&logSize, 0, 0);
864 /* get more information on the log */
866 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
867 (long)&logSize, (long)&allocated, 0, 0, 0);
870 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
872 allocated ? "allocated" : "unallocated");
874 (void)fprintf(outFileP, "%s\n", tname);
880 /* list out all available logs to outFileP */
882 icl_ListLogsBySet(FILE *outFileP, char *setname, int int32flg)
890 for (i = 0; i < ICL_LOGSPERSET; i++) {
892 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname, i,
893 (long)tname, sizeof(tname), 0, 0);
895 if (errno == EBADF) {
897 continue; /* missing */
902 /* get more information on the log */
904 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
905 (long)&logSize, (long)&allocated, 0, 0, 0);
908 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
910 allocated ? "allocated" : "unallocated");
912 (void)fprintf(outFileP, "%s\n", tname);
918 /* activate/deactivate/free specified set */
920 icl_ChangeSetState(char *name, afs_int32 op)
924 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long)name, op, 0, 0, 0, 0);
928 /* activate/deactivate/free all sets */
930 icl_ChangeAllSetState(afs_int32 op)
934 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTATALL, op, 0, 0, 0, 0, 0);
938 /* set size if log */
940 icl_ChangeLogSize(char *name, afs_int32 logSize)
945 afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0,
950 /* get logsize of specified log */
952 icl_GetLogsize(char *logname, afs_int32 *logSizeP, int *allocatedP)
956 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
957 (long)logSizeP, (long)allocatedP, 0, 0, 0);
961 /* get state of specified set */
963 icl_GetSetState(char *setname, afs_int32 *stateP)
967 afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long)setname,
968 (long)stateP, 0, 0, 0, 0);
973 icl_TailKernel(FILE *outFilep, char *logname, afs_int32 waitTime)
975 afs_int32 bufferSize = 0;
976 afs_int32 newBufferSize;
979 afs_int32 code, retVal = 0;
985 /* get information about the specified log */
987 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
988 (long)&bufferSize, (long)&allocated, 0, 0, 0);
991 (void)fprintf(stderr, "'%s' not found\n", logname);
993 (void)fprintf(stderr,
994 "cannot get information on log '%s' (errno = %d)\n",
1000 (void)fprintf(stderr, "'%s' not allocated\n", logname);
1004 if (bufferSize == 0)
1006 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1008 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
1013 /* start "infinite" loop */
1015 /* read out all that's currently there */
1016 nwords = 0; /* total words copied out */
1017 i = 0; /* initialize cookie */
1019 /* display all the entries in the log */
1020 if (bufferSize - nwords <= 0)
1021 break; /* filled whole buffer, clear when done */
1023 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR, (long)logname,
1024 (long)(bufferp + nwords), bufferSize - nwords,
1027 /* otherwise we've got an error */
1028 fprintf(stderr, "returned error %d dumping log.\n", errno);
1032 /* otherwise, we have flags in the high order byte, and
1033 * a length (in words) in the remainder.
1042 } /* for loop over all cookies */
1044 /* otherwise we should display all of the log entries here.
1045 * Note that a record may end in the middle, in which case
1046 * we should start over with the cookie value of the start
1049 for (ix = 0; ix < nwords;) {
1050 /* start of a record */
1051 rlength = (bufferp[ix] >> 24) & 0xff;
1052 /* ensure that entire record fits */
1053 if (ix + rlength > nwords) {
1054 /* doesn't fit, adjust cookie and break */
1056 fprintf(stderr, "BOGUS: 0 length record\n");
1062 /* print the record */
1063 DisplayRecord(outFilep, &bufferp[ix], rlength);
1065 } /* for loop displaying buffer */
1070 /* see if things have changed */
1072 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
1073 (long)&newBufferSize, (long)&allocated, 0, 0, 0);
1075 if (errno == ENOENT)
1076 (void)fprintf(stderr, "'%s' not found\n", logname);
1078 (void)fprintf(stderr,
1079 "cannot get information on log '%s' (errno = %d)\n",
1086 (void)fprintf(stderr, "'%s' no int32er allocated\n", logname);
1091 if (bufferSize == 0) {
1092 (void)fprintf(stderr, "buffer size has become 0\n");
1096 if (bufferSize != newBufferSize) {
1097 /* have to reallocate a buffer */
1098 bufferSize = newBufferSize;
1100 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1102 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
1108 } /* infinite loop */
1115 #if !defined(AFS_SGI_ENV)
1117 afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
1118 long parm4, long parm5, long parm6)
1121 #ifdef AFS_LINUX20_ENV
1122 #if defined AFS_LINUX_64BIT_KERNEL
1124 /* don't want to sign extend it to 64bit, so using ulong */
1125 eparm[0] = (unsigned long)parm3;
1126 eparm[1] = (unsigned long)parm4;
1127 eparm[2] = (unsigned long)parm5;
1128 eparm[3] = (unsigned long)parm6;
1136 /* Linux can only handle 5 arguments in the actual syscall. */
1137 if (call == AFSCALL_ICL) {
1138 rval = proc_afs_syscall(call, parm0, parm1, parm2, (long)eparm, &code);
1140 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm);
1142 rval = proc_afs_syscall(call, parm0, parm1, parm2, parm3, &code);
1144 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3);
1146 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV)
1147 /* on sparc this function returns none value, so do it myself */
1148 __asm__ __volatile__("mov %o0, %i0; ret; restore");
1151 #ifdef AFS_DARWIN80_ENV
1152 code = ioctl_afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, &rval);
1153 if (!code) code = rval;
1155 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
1156 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4);
1158 #if defined(AFS_SGI_ENV)
1159 code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */
1161 code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4);
1165 #endif /* AFS_LINUX20_ENV */
1173 /* init function, called once, under icl_lock */
1180 /* setup signal handler, in user space */
1187 icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
1188 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
1190 return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags */ 0,
1194 /* create a set, given pointers to base and fatal logs, if any.
1195 * Logs are unlocked, but referenced, and *outSetpp is returned
1196 * referenced. Function bumps reference count on logs, since it
1197 * addds references from the new icl_set. When the set is destroyed,
1198 * those references will be released.
1201 icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
1202 struct afs_icl_log *fatalLogp, afs_uint32 flags,
1203 struct afs_icl_set **outSetpp)
1205 register struct afs_icl_set *setp;
1207 afs_int32 states = ICL_DEFAULT_SET_STATES;
1212 for (setp = icl_allSets; setp; setp = setp->nextp) {
1213 if (strcmp(setp->name, name) == 0) {
1216 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
1217 setp->states |= ICL_SETF_PERSISTENT;
1223 /* determine initial state */
1224 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
1225 states = ICL_SETF_ACTIVE;
1226 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
1227 states = ICL_SETF_FREED;
1228 if (flags & ICL_CRSET_FLAG_PERSISTENT)
1229 states |= ICL_SETF_PERSISTENT;
1231 setp = (struct afs_icl_set *)osi_Alloc(sizeof(struct afs_icl_set));
1232 memset((caddr_t) setp, 0, sizeof(*setp));
1234 if (states & ICL_SETF_FREED)
1235 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
1236 setp->states = states;
1238 setp->name = (char *)osi_Alloc(strlen(name) + 1);
1239 strcpy(setp->name, name);
1240 setp->nevents = ICL_DEFAULTEVENTS;
1241 setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS);
1242 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
1243 setp->eventFlags[i] = 0xff; /* default to enabled */
1245 /* update this global info under the icl_lock */
1246 setp->nextp = icl_allSets;
1249 /* set's basic lock is still held, so we can finish init */
1251 setp->logs[0] = baseLogp;
1252 icl_LogHold(baseLogp);
1253 if (!(setp->states & ICL_SETF_FREED))
1254 icl_LogUse(baseLogp); /* log is actually being used */
1257 setp->logs[1] = fatalLogp;
1258 icl_LogHold(fatalLogp);
1259 if (!(setp->states & ICL_SETF_FREED))
1260 icl_LogUse(fatalLogp); /* log is actually being used */
1267 /* function to change event enabling information for a particular set */
1269 icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
1273 if (!ICL_EVENTOK(setp, eventID)) {
1276 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
1278 *tp |= ICL_EVENTMASK(eventID);
1280 *tp &= ~(ICL_EVENTMASK(eventID));
1284 /* return indication of whether a particular event ID is enabled
1285 * for tracing. If *getValuep is set to 0, the event is disabled,
1286 * otherwise it is enabled. All events start out enabled by default.
1289 icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep)
1291 if (!ICL_EVENTOK(setp, eventID)) {
1294 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
1301 /* hold and release event sets */
1303 icl_SetHold(register struct afs_icl_set *setp)
1309 /* free a set. Called with icl_lock locked */
1311 icl_ZapSet(register struct afs_icl_set *setp)
1313 register struct afs_icl_set **lpp, *tp;
1315 register struct afs_icl_log *tlp;
1317 for (lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1319 /* found the dude we want to remove */
1321 osi_Free(setp->name, 1 + strlen(setp->name));
1322 osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents));
1323 for (i = 0; i < ICL_LOGSPERSET; i++) {
1324 if ((tlp = setp->logs[i]))
1327 osi_Free(setp, sizeof(struct afs_icl_set));
1328 break; /* won't find it twice */
1334 /* do the release, watching for deleted entries */
1336 icl_SetRele(register struct afs_icl_set *setp)
1338 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
1339 icl_ZapSet(setp); /* destroys setp's lock! */
1344 /* free a set entry, dropping its reference count */
1346 icl_SetFree(register struct afs_icl_set *setp)
1348 setp->states |= ICL_SETF_DELETED;
1353 /* find a set by name, returning it held */
1354 struct afs_icl_set *
1355 icl_FindSet(char *name)
1357 register struct afs_icl_set *tp;
1359 for (tp = icl_allSets; tp; tp = tp->nextp) {
1360 if (strcmp(tp->name, name) == 0) {
1361 /* this is the dude we want */
1369 /* zero out all the logs in the set */
1371 icl_ZeroSet(struct afs_icl_set *setp)
1376 struct afs_icl_log *logp;
1378 for (i = 0; i < ICL_LOGSPERSET; i++) {
1379 logp = setp->logs[i];
1382 tcode = icl_ZeroLog(logp);
1384 code = tcode; /* save the last bad one */
1392 icl_EnumerateSets(int (*aproc) (char *, void *, struct afs_icl_set *),
1395 register struct afs_icl_set *tp, *np;
1396 register afs_int32 code;
1399 for (tp = icl_allSets; tp; tp = np) {
1400 tp->refCount++; /* hold this guy */
1401 code = (*aproc) (tp->name, arock, tp);
1402 np = tp->nextp; /* tp may disappear next, but not np */
1403 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
1412 icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
1417 for (i = 0; i < ICL_LOGSPERSET; i++) {
1418 if (!setp->logs[i]) {
1419 setp->logs[i] = newlogp;
1421 icl_LogHold(newlogp);
1422 if (!(setp->states & ICL_SETF_FREED)) {
1423 /* bump up the number of sets using the log */
1424 icl_LogUse(newlogp);
1433 icl_SetSetStat(struct afs_icl_set *setp, int op)
1437 struct afs_icl_log *logp;
1440 case ICL_OP_SS_ACTIVATE: /* activate a log */
1442 * If we are not already active, see if we have released
1443 * our demand that the log be allocated (FREED set). If
1444 * we have, reassert our desire.
1446 if (!(setp->states & ICL_SETF_ACTIVE)) {
1447 if (setp->states & ICL_SETF_FREED) {
1448 /* have to reassert desire for logs */
1449 for (i = 0; i < ICL_LOGSPERSET; i++) {
1450 logp = setp->logs[i];
1457 setp->states &= ~ICL_SETF_FREED;
1459 setp->states |= ICL_SETF_ACTIVE;
1464 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
1465 /* this doesn't require anything beyond clearing the ACTIVE flag */
1466 setp->states &= ~ICL_SETF_ACTIVE;
1470 case ICL_OP_SS_FREE: /* deassert design for log */
1472 * if we are already in this state, do nothing; otherwise
1473 * deassert desire for log
1475 if (setp->states & ICL_SETF_ACTIVE)
1478 if (!(setp->states & ICL_SETF_FREED)) {
1479 for (i = 0; i < ICL_LOGSPERSET; i++) {
1480 logp = setp->logs[i];
1483 icl_LogFreeUse(logp);
1487 setp->states |= ICL_SETF_FREED;
1500 struct afs_icl_log *afs_icl_allLogs = 0;
1502 /* hold and release logs */
1504 icl_LogHold(register struct afs_icl_log *logp)
1510 /* hold and release logs, called with lock already held */
1512 icl_LogHoldNL(register struct afs_icl_log *logp)
1518 /* keep track of how many sets believe the log itself is allocated */
1520 icl_LogUse(register struct afs_icl_log *logp)
1522 if (logp->setCount == 0) {
1523 /* this is the first set actually using the log -- allocate it */
1524 if (logp->logSize == 0) {
1525 /* we weren't passed in a hint and it wasn't set */
1526 logp->logSize = ICL_DEFAULT_LOGSIZE;
1529 (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize);
1535 /* decrement the number of real users of the log, free if possible */
1537 icl_LogFreeUse(register struct afs_icl_log *logp)
1539 if (--logp->setCount == 0) {
1540 /* no more users -- free it (but keep log structure around) */
1541 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1542 logp->firstUsed = logp->firstFree = 0;
1543 logp->logElements = 0;
1549 /* set the size of the log to 'logSize' */
1551 icl_LogSetSize(register struct afs_icl_log *logp, afs_int32 logSize)
1554 /* nothing to worry about since it's not allocated */
1555 logp->logSize = logSize;
1558 logp->firstUsed = logp->firstFree = 0;
1559 logp->logElements = 0;
1561 /* free and allocate a new one */
1562 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1563 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logSize);
1564 logp->logSize = logSize;
1570 /* free a log. Called with icl_lock locked. */
1572 icl_ZapLog(register struct afs_icl_log *logp)
1574 register struct afs_icl_log **lpp, *tp;
1576 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1578 /* found the dude we want to remove */
1580 osi_Free(logp->name, 1 + strlen(logp->name));
1581 osi_Free(logp->datap, logp->logSize * sizeof(afs_int32));
1582 osi_Free(logp, sizeof(struct icl_log));
1583 break; /* won't find it twice */
1589 /* do the release, watching for deleted entries */
1591 icl_LogRele(register struct afs_icl_log *logp)
1593 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1594 icl_ZapLog(logp); /* destroys logp's lock! */
1599 /* do the release, watching for deleted entries, log already held */
1601 icl_LogReleNL(register struct afs_icl_log *logp)
1603 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1604 icl_ZapLog(logp); /* destroys logp's lock! */
1609 /* zero out the log */
1611 icl_ZeroLog(register struct afs_icl_log *logp)
1613 logp->firstUsed = logp->firstFree = 0;
1614 logp->logElements = 0;
1618 /* free a log entry, and drop its reference count */
1620 icl_LogFree(register struct afs_icl_log *logp)
1622 logp->states |= ICL_LOGF_DELETED;
1629 icl_EnumerateLogs(int (*aproc)
1630 (char *name, void *arock, struct afs_icl_log * tp),
1633 register struct afs_icl_log *tp;
1634 register afs_int32 code;
1637 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
1638 tp->refCount++; /* hold this guy */
1639 code = (*aproc) (tp->name, arock, tp);
1640 if (--tp->refCount == 0)
1649 afs_icl_bulkSetinfo_t *
1650 GetBulkSetInfo(void)
1652 unsigned int infoSize;
1655 sizeof(afs_icl_bulkSetinfo_t) + (ICL_RPC_MAX_SETS -
1656 1) * sizeof(afs_icl_setinfo_t);
1658 setInfo = (afs_icl_bulkSetinfo_t *) malloc(infoSize);
1660 (void)fprintf(stderr,
1661 "Could not allocate the memory for bulk set info structure\n");
1665 memset((char *)setInfo, 0, infoSize);
1670 afs_icl_bulkLoginfo_t *
1671 GetBulkLogInfo(void)
1673 unsigned int infoSize;
1676 sizeof(afs_icl_bulkLoginfo_t) + (ICL_RPC_MAX_LOGS -
1677 1) * sizeof(afs_icl_loginfo_t);
1679 logInfo = (afs_icl_bulkLoginfo_t *) malloc(infoSize);
1681 (void)fprintf(stderr,
1682 "Could not allocate the memory for bulk log info structure\n");
1687 memset((char *)logInfo, 0, infoSize);
1693 DoDump(struct cmd_syndesc *as, void *arock)
1697 afs_int32 waitTime = 10 /* seconds */ ;
1699 FILE *outfp = stdout;
1701 struct cmd_item *itemp;
1703 if (geteuid() != 0) {
1704 printf("fstrace must be run as root\n");
1708 if (as->parms[3].items) {
1709 if (!as->parms[1].items) {
1710 (void)fprintf(stderr, "-sleep can only be used with -follow\n");
1713 waitTime = strtol(as->parms[3].items->data, NULL, 0);
1716 if (as->parms[2].items) {
1717 /* try to open the specified output file */
1718 if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL) {
1719 (void)fprintf(stderr, "Cannot open file '%s' for writing\n",
1720 as->parms[2].items->data);
1724 #ifdef AFS_SGI64_ENV
1725 startTime = time((time_t *) 0);
1727 startTime = time(0);
1729 (void)fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n",
1732 if (as->parms[0].items) {
1733 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1734 tcode = icl_DumpKernel(outfp, itemp->data);
1736 (void)fprintf(stderr, "Unable to dump set %s (errno = %d)\n",
1737 itemp->data, errno);
1741 } else if (as->parms[1].items) {
1742 logname = as->parms[1].items->data;
1743 code = icl_TailKernel(outfp, logname, waitTime);
1745 (void)fprintf(stderr,
1746 "Error tailing kernel log '%s' (errno = %d)\n",
1750 code = icl_DumpKernel(outfp, NULL);
1752 (void)fprintf(outfp, "\nAFS Trace Dump - %s\n",
1753 code ? "FAILED" : "Completed");
1755 if (outfp != stdout)
1756 (void)fclose(outfp);
1764 struct cmd_syndesc *dumpSyntax;
1767 cmd_CreateSyntax("dump", DoDump, NULL, "dump AFS trace logs");
1768 (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
1769 (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL,
1771 (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL,
1773 (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL,
1774 "seconds_between_reads");
1778 DoShowLog(register struct cmd_syndesc *as, void *arock)
1780 afs_int32 retVal = 0;
1785 struct cmd_item *itemp;
1787 if (geteuid() != 0) {
1788 printf("fstrace must be run as root\n");
1791 if (as->parms[2].items)
1794 if (as->parms[0].items) {
1795 /* enumerate logs for the specified sets */
1796 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1797 (void)fprintf(stdout, "Logs for set '%s':\n", itemp->data);
1798 code = icl_ListLogsBySet(stdout, itemp->data, int32flg);
1800 (void)fprintf(stderr,
1801 "Error in enumerating set %s (errno = %d)\n",
1802 itemp->data, errno);
1806 } else if (as->parms[1].items) {
1807 /* print out log information */
1808 for (itemp = as->parms[1].items; itemp; itemp = itemp->next) {
1809 code = icl_GetLogsize(itemp->data, &logSize, &allocated);
1811 (void)fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data,
1813 allocated ? "allocated" : "unallocated");
1815 (void)fprintf(stderr,
1816 "Could not find log '%s' (errno = %d)\n",
1817 itemp->data, errno);
1823 (void)fprintf(stdout, "Available logs:\n");
1824 code = icl_ListLogs(stdout, int32flg);
1826 (void)fprintf(stderr, "Error in listing logs (errno = %d)\n",
1838 struct cmd_syndesc *showSyntax;
1841 cmd_CreateSyntax("lslog", DoShowLog, NULL,
1842 "list available logs");
1843 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
1844 (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name");
1845 (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL, "");
1849 DoShowSet(register struct cmd_syndesc *as, void *arock)
1851 afs_int32 retVal = 0;
1854 struct cmd_item *itemp;
1856 if (geteuid() != 0) {
1857 printf("fstrace must be run as root\n");
1860 if (as->parms[0].items) {
1861 /* print information on the specified sets */
1862 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1863 code = icl_GetSetState(itemp->data, &state);
1865 (void)fprintf(stderr,
1866 "Error getting status on set %s (errno = %d)\n",
1867 itemp->data, errno);
1870 (void)fprintf(stdout, "Set %s: %s%s%s\n", itemp->data,
1871 (state & ICL_SETF_ACTIVE) ? "active" :
1873 (state & ICL_SETF_FREED) ? " (dormant)" : "",
1874 (state & ICL_SETF_PERSISTENT) ? " persistent" :
1879 (void)fprintf(stdout, "Available sets:\n");
1880 code = icl_ListSets(stdout);
1882 (void)fprintf(stderr, "Error in listing sets (errno = %d)\n",
1894 struct cmd_syndesc *showSyntax;
1897 cmd_CreateSyntax("lsset", DoShowSet, NULL,
1898 "list available event sets");
1899 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
1903 DoClear(register struct cmd_syndesc *as, void *arock)
1905 afs_int32 retVal = 0;
1907 struct cmd_item *itemp;
1909 if (geteuid() != 0) {
1910 printf("fstrace must be run as root\n");
1913 if (as->parms[0].items) {
1914 /* clear logs for the specified sets */
1915 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1916 code = icl_ClearSet(itemp->data);
1918 (void)fprintf(stderr,
1919 "Error in clearing set %s (errno = %d)\n",
1920 itemp->data, errno);
1924 } else if (as->parms[1].items) {
1925 /* clear specified log */
1926 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1927 code = icl_ClearLog(itemp->data);
1929 (void)fprintf(stderr,
1930 "Error in clearing log %s (errno = %d)\n",
1931 itemp->data, errno);
1936 /* clear all logs */
1937 code = icl_ClearAll();
1939 (void)fprintf(stderr, "Error in clearing logs (errno = %d)\n",
1951 struct cmd_syndesc *clearSyntax;
1954 cmd_CreateSyntax("clear", DoClear, NULL,
1955 "clear logs by logname or by event set");
1956 (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
1958 (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
1963 DoSet(register struct cmd_syndesc *as, void *arock)
1965 afs_int32 retVal = 0;
1970 struct cmd_item *itemp;
1972 if (geteuid() != 0) {
1973 printf("fstrace must be run as root\n");
1976 if (as->parms[1].items) {
1977 op = ICL_OP_SS_ACTIVATE;
1978 operation = "active";
1979 } else if (as->parms[2].items) {
1980 op = ICL_OP_SS_DEACTIVATE;
1981 operation = "inactive";
1982 } else if (as->parms[3].items) {
1983 op = ICL_OP_SS_DEACTIVATE;
1984 operation = "inactive";
1987 /* assume active" */
1988 op = ICL_OP_SS_ACTIVATE;
1989 operation = "active";
1992 if (as->parms[0].items) {
1993 /* activate specified sets */
1994 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1995 code = icl_ChangeSetState(itemp->data, op);
1997 (void)fprintf(stderr,
1998 "cannot set state of %s to %s (errno = %d)\n",
1999 itemp->data, operation, errno);
2001 } else if (doFree) {
2002 /* try to make it dormant as well */
2003 code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE);
2005 (void)fprintf(stderr,
2006 "cannot set state of %s to dormant (errno = %d)\n",
2007 itemp->data, errno);
2014 code = icl_ChangeAllSetState(op);
2016 (void)fprintf(stderr,
2017 "cannot set the state of all sets to %s (errno = %d)\n",
2020 } else if (doFree) {
2021 /* try to make it dormant as well */
2022 code = icl_ChangeAllSetState(ICL_OP_SS_FREE);
2024 (void)fprintf(stderr,
2025 "cannot set the state of all sets to dormant (errno = %d)\n",
2038 struct cmd_syndesc *setSyntax;
2041 cmd_CreateSyntax("setset", DoSet, NULL,
2042 "set state of event sets");
2043 (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2044 (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL, "");
2045 (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL, "");
2046 (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL, "");
2050 DoResize(register 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,
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 "1-kilobyte_units");
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));
2127 #include "AFS_component_version_number.c"
2130 main(int argc, char *argv[])
2132 printf("fstrace is NOT supported for this OS\n");