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>
19 #include <sys/types.h>
21 #if !defined(AFS_SUN3_ENV) && !defined(sys_vax_ul43)
23 /*#ifdef AFS_AIX_ENV*/
34 #include <afs/afs_args.h>
36 #include <afs/afsutil.h>
39 #include <afs/sys_prototypes.h>
41 #if defined(AFS_OSF_ENV) || defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
42 /* For SGI 6.2, this is changed to 1 if it's a 32 bit kernel. */
43 int afs_icl_sizeofLong = 2;
45 int afs_icl_sizeofLong = 1;
48 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
49 int afs_64bit_kernel = 1; /* Default for 6.2+, and always for 6.1 */
50 extern int afs_icl_sizeofLong; /* Used in ICL_SIZEHACK() */
54 /* If _SC_KERN_POINTERS not in sysconf, then we can assume a 32 bit abi. */
56 set_kernel_sizeof_long(void)
61 retval = sysconf(_SC_KERN_POINTERS);
64 afs_icl_sizeofLong = 2;
67 afs_icl_sizeofLong = 1;
71 #endif /* AFS_SGI62_ENV */
72 #endif /* AFS_SGI61_ENV */
74 int afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
75 long parm4, long parm5, long parm6);
76 void dce1_error_inq_text(afs_uint32 status_to_convert,
77 char *error_text, int *status);
78 int icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
79 struct afs_icl_log *fatalLogp, afs_uint32 flags,
80 struct afs_icl_set **outSetpp);
81 int icl_LogHold(struct afs_icl_log *logp);
82 int icl_LogUse(struct afs_icl_log *logp);
83 int icl_LogReleNL(struct afs_icl_log *logp);
84 int icl_LogRele(struct afs_icl_log *logp);
85 int icl_ZeroLog(struct afs_icl_log *logp);
86 int icl_LogFreeUse(struct afs_icl_log *logp);
88 #define BUFFER_MULTIPLIER 1024
90 /* make it big enough to snapshot everything at once, since
91 * decoding takes so long.
93 #define IBSIZE 100000 /* default size */
96 struct logInfo *nextp;
100 char dumpFileName[256] = "";
102 RegisterIclDumpFileName(char *name)
104 (void)sprintf(dumpFileName, "icl.%.250s", name);
107 /* define globals to use for bulk info */
108 afs_icl_bulkSetinfo_t *setInfo = (afs_icl_bulkSetinfo_t *) 0;
109 afs_icl_bulkLoginfo_t *logInfo = (afs_icl_bulkLoginfo_t *) 0;
111 struct afs_icl_set *icl_allSets = 0;
115 /* given a type and an address, get the size of the thing
119 icl_GetSize(afs_int32 type, char *addr)
125 ICL_SIZEHACK(type, addr, tsize, rsize);
129 /* Check types in printf string "bufferp", making sure that each
130 * is compatible with the corresponding parameter type described
131 * by typesp. Also watch for prematurely running out of parameters
132 * before the string is gone.
134 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
136 CheckTypes(char *bufferp, int *typesp, int typeCount, char *outMsgBuffer)
144 for (tc = *bufferp;; outMsgBuffer++, tc = *(++bufferp)) {
147 /* hit end of string. We win as long as we aren't
156 inPercent = 1 - inPercent;
160 if (tc >= '0' && tc <= '9') {
161 /* skip digits in % string */
166 /* 'l' is a type modifier. */
170 /* otherwise, we've finally gotten to the type-describing
171 * character. Make sure there's a type descriptor, and then
172 * check the type descriptor.
176 return 0; /* no more type descriptors left */
178 if (typesp[tix] != 1) /* not a string descriptor */
181 *outMsgBuffer = (char)1;
183 if (tc == 'u' || tc == 'x' || tc == 'd' || tc == 'o') {
184 if (typesp[tix] != 0)
185 return 0; /* not an integer descriptor */
189 *outMsgBuffer = (char)2;
192 *outMsgBuffer = (char)3;
195 *outMsgBuffer = (char)4;
199 *outMsgBuffer = (char)5;
203 /* otherwise we're fine, so eat this descriptor */
209 #else /* AFS_SGI61_ENV */
211 CheckTypes(char *bufferp, int *typesp, int typeCount)
219 for (tc = *bufferp;; tc = *(++bufferp)) {
221 /* hit end of string. We win as long as we aren't
230 inPercent = 1 - inPercent;
234 if (tc >= '0' && tc <= '9')
235 continue; /* skip digits in % string */
236 /* otherwise, we've finally gotten to the type-describing
237 * character. Make sure there's a type descriptor, and then
238 * check the type descriptor.
242 return 0; /* no more type descriptors left */
243 if (tc == 's' && typesp[tix] != 1) /* not a string descriptor */
245 if ((tc == 'u' || tc == 'l' || tc == 'x' || tc == 'd')
246 && (typesp[tix] != 0))
247 return 0; /* not an integer descriptor */
248 /* otherwise we're fine, so eat this descriptor */
254 #endif /* AFS_SGI61_ENV */
256 /* display a single record.
257 * alp points at the first word in the array to be interpreted
258 * rsize gives the # of words in the array
260 #if defined(AFS_SGI61_ENV) && !defined(AFS_SGI62_ENV)
261 #define uint64_t long long
264 DisplayRecord(FILE *outFilep, afs_int32 *alp, afs_int32 rsize)
266 char msgBuffer[1024];
267 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
268 char outMsgBuffer[1024];
270 uint64_t printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
271 char *printfStrings[ICL_MAXEXPANSION * /* max parms */ 4];
272 #else /* AFS_SGI61_ENV */
273 long printfParms[ICL_MAXEXPANSION * /* max parms */ 4];
274 #endif /* AFS_SGI61_ENV */
275 int printfTypes[ICL_MAXEXPANSION * 4];
281 int pix; /* index in alp */
282 int pfpix; /* index in printfParms */
283 int pftix; /* index in printfTypes */
285 int printed; /* did we print the string yet? */
288 /* decode parameters */
289 temp = alp[0]; /* type encoded in low-order 24 bits, t0 high */
295 for (i = 0; i < 4 * ICL_MAXEXPANSION; i++)
297 /* decode each parameter, getting addrs for afs_hyper_t and strings */
298 for (i = 0; !done && i < 4; i++) {
299 type = (temp >> (18 - i * 6)) & 0x3f;
305 case ICL_TYPE_POINTER:
306 printfTypes[pftix++] = 0;
307 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
308 printfParms[pfpix] = alp[pix];
309 printfParms[pfpix] &= 0xffffffff;
310 if (afs_64bit_kernel) {
311 printfParms[pfpix] <<= 32;
312 printfParms[pfpix] |= alp[pix + 1];
314 #elif defined(AFS_OSF_ENV)
315 printfParms[pfpix] = alp[pix + 1];
316 printfParms[pfpix] |= (alp[pix] <<= 32);
317 #else /* !AFS_OSF_ENV && !AFS_SGI61_ENV */
318 printfParms[pfpix] = alp[pix];
323 printfTypes[pftix++] = 0;
324 printfParms[pfpix++] = alp[pix];
328 printfTypes[pftix++] = 0;
329 printfParms[pfpix++] = alp[pix];
330 printfTypes[pftix++] = 0;
331 printfParms[pfpix++] = alp[pix + 1];
334 printfTypes[pftix++] = 0;
335 printfParms[pfpix++] = alp[pix];
336 printfTypes[pftix++] = 0;
337 printfParms[pfpix++] = alp[pix + 1];
338 printfTypes[pftix++] = 0;
339 printfParms[pfpix++] = alp[pix + 2];
340 printfTypes[pftix++] = 0;
341 printfParms[pfpix++] = alp[pix + 3];
343 case ICL_TYPE_STRING:
344 printfTypes[pftix++] = 1;
346 printfStrings[pfpix++] = (char *)&alp[pix];
347 #else /* AFS_SGI64_ENV */
348 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
349 printfStrings[pfpix++] = (char *)&alp[pix];
350 #else /* AFS_SGI61_ENV */
351 printfParms[pfpix++] = (long)&alp[pix];
352 #endif /* AFS_SGI61_ENV */
353 #endif /* AFS_SGI64_ENV */
355 case ICL_TYPE_UNIXDATE:
357 printfParms[pfpix++] = (long)ctime(&tmv);
360 printf("DisplayRecord: Bad type %d in decode switch.\n", type);
367 pix += icl_GetSize(type, (char *)&alp[pix]);
370 /* next, try to decode the opcode into a printf string */
371 dce1_error_inq_text(alp[1], msgBuffer, &status);
373 /* if we got a string back, and it is compatible with the
374 * parms we've got, then print it.
378 #if defined(AFS_SGI61_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
379 if (CheckTypes(msgBuffer, printfTypes, pftix, outMsgBuffer)) {
380 /* we have a string to use, but it ends "(dfs / zcm)",
381 * so we remove the extra gunk.
383 j = strlen(outMsgBuffer);
385 outMsgBuffer[j - 11] = 0;
389 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
390 alp[3] % 1000000, alp[2]);
391 for (i = 0; i < j; i++) {
392 if ((int)outMsgBuffer[i] > 5)
393 fputc(outMsgBuffer[i], outFilep);
395 switch (outMsgBuffer[i]) {
399 fprintf(outFilep, "%s", printfStrings[pfpix++]);
401 case 2: /* signed integer */
402 fprintf(outFilep, "%" AFS_INT64_FMT, printfParms[pfpix++]);
404 case 3: /* unsigned integer */
405 fprintf(outFilep, "%llu", printfParms[pfpix++]);
407 case 4: /* octal integer */
408 fprintf(outFilep, "%llo", printfParms[pfpix++]);
410 case 5: /* hex integer */
411 fprintf(outFilep, "%llx", printfParms[pfpix++]);
415 "fstrace: Bad char %d in outMsgBuffer for parm %d\n",
416 outMsgBuffer[i], pfpix);
417 fprintf(outFilep, "fstrace: msgBuffer='%s'\n",
423 fprintf(outFilep, "\n");
426 #else /* AFS_SGI61_ENV */
427 if (CheckTypes(msgBuffer, printfTypes, pftix)) {
428 /* we have a string to use, but it ends "(dfs / zcm)",
429 * so we remove the extra gunk.
431 j = strlen(msgBuffer);
433 msgBuffer[j - 11] = 0;
434 fprintf(outFilep, "time %d.%06d, pid %u: ", alp[3] / 1000000,
435 alp[3] % 1000000, alp[2]);
436 fprintf(outFilep, msgBuffer, printfParms[0], printfParms[1],
437 printfParms[2], printfParms[3], printfParms[4],
438 printfParms[5], printfParms[6], printfParms[7],
439 printfParms[8], printfParms[9], printfParms[10],
440 printfParms[11], printfParms[12], printfParms[13],
441 printfParms[14], printfParms[15]);
442 fprintf(outFilep, "\n");
445 #endif /* AFS_SGI61_ENV */
447 fprintf(outFilep, "Type mismatch, using raw print.\n");
448 fprintf(outFilep, "%s", msgBuffer);
452 if (alp[1] == ICL_INFO_TIMESTAMP) {
454 fprintf(outFilep, "time %d.%06d, pid %u: %s\n", alp[3] / 1000000,
455 alp[3] % 1000000, alp[2], ctime(&tmv));
457 fprintf(outFilep, "raw op %d, time %d.%06d, pid %u\n", alp[1],
458 alp[3] / 1000000, alp[3] % 1000000, alp[2]);
459 /* now decode each parameter and print it */
462 for (i = 0; !done && i < 4; i++) {
463 type = (temp >> (18 - i * 6)) & 0x3f;
469 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
473 tempParam = alp[pix];
475 tempParam |= alp[pix + 1];
476 fprintf(outFilep, "p%d:%" AFS_INT64_FMT " ", i, tempParam);
477 #else /* AFS_SGI61_ENV */
478 fprintf(outFilep, "p%d:%d ", i, alp[pix]);
479 #endif /* AFS_SGI61_ENV */
481 case ICL_TYPE_POINTER:
483 tempParam = alp[pix];
485 tempParam |= alp[pix + 1];
486 fprintf(outFilep, "p%d:0x%llx ", i, tempParam);
487 #else /* AFS_SGI61_ENV */
488 fprintf(outFilep, "p%d:0x%x ", i, alp[pix]);
489 #endif /* AFS_SGI61_ENV */
493 fprintf(outFilep, "p%d:%x.%x ", i, alp[pix],
497 fprintf(outFilep, "p%d:%d.%d.%d.%d ", i, alp[pix],
498 alp[pix + 1], alp[pix + 2], alp[pix + 3]);
500 case ICL_TYPE_STRING:
501 fprintf(outFilep, "p%d:%s ", i, (char *)&alp[pix]);
503 case ICL_TYPE_UNIXDATE:
505 fprintf(outFilep, "p%d:%s ", i,
510 ("DisplayRecord: Bad type %d in raw print switch.\n",
518 pix += icl_GetSize(type, (char *)&alp[pix]);
521 fprintf(outFilep, "\n"); /* done with line */
531 #include <nl_types.h>
533 #define FACILITY_CODE_MASK 0xF0000000
534 #define FACILITY_CODE_SHIFT 28
536 #define COMPONENT_CODE_MASK 0x0FFFF000
537 #define COMPONENT_CODE_SHIFT 12
539 #define STATUS_CODE_MASK 0x00000FFF
540 #define STATUS_CODE_SHIFT 0
542 #define NO_MESSAGE "THIS IS NOT A MESSAGE"
545 * We use NLS message catalog functions to convert numbers to human-readable
546 * strings. The message catalog will be in AFSDIR_DATA_DIR, which is
547 * ${datadir}/openafs with normal paths and /usr/vice/etc (for historical
548 * compatibility) for Transarc paths.
552 dce1_error_inq_text(afs_uint32 status_to_convert,
553 char *error_text, int *status)
555 unsigned short facility_code;
556 unsigned short component_code;
557 unsigned short status_code;
560 char component_name[4];
562 char filename_prefix[7];
563 char nls_filename[80];
565 static char *facility_names[] = {
571 * set up output status for future error returns
573 if (status != NULL) {
577 * check for ok input status
579 if (status_to_convert == 0) {
580 if (status != NULL) {
583 strcpy((char *)error_text, "successful completion");
588 * extract the component, facility and status codes
591 (status_to_convert & FACILITY_CODE_MASK) >> FACILITY_CODE_SHIFT;
593 (status_to_convert & COMPONENT_CODE_MASK) >> COMPONENT_CODE_SHIFT;
594 status_code = (status_to_convert & STATUS_CODE_MASK) >> STATUS_CODE_SHIFT;
597 * see if this is a recognized facility
599 if (facility_code == 0
600 || facility_code > sizeof(facility_names) / sizeof(char *)) {
601 sprintf((char *)error_text, "status %08x (unknown facility)",
605 facility_name = facility_names[facility_code - 1];
607 * Convert component name from RAD-50 component code. (Mapping is:
608 * 0 => 'a', ..., 25 => 'z', 26 => '{', 27 => '0', ..., 36 => '9'.)
610 component_name[3] = 0;
611 component_name[2] = component_code % 40;
612 component_code /= 40;
613 component_name[1] = component_code % 40;
614 component_name[0] = component_code / 40;
615 for (i = 0; i < 3; i++) {
616 component_name[i] += (component_name[i] <= 26) ? 'a' : ('0' - 27);
618 sprintf(filename_prefix, "%3s%3s", facility_name, component_name);
621 * We do not use the normal NLS message catalog search path since our use
622 * message catalogs isn't a typical use. It wouldn't make sense to
623 * install this special message catalog in with internationalization
626 snprintf(nls_filename, sizeof(nls_filename), "%s/C/%s.cat",
627 AFSDIR_CLIENT_DATA_DIRPATH, filename_prefix);
629 catd = catopen(nls_filename, 0);
630 if (catd == (nl_catd) -1) {
631 sprintf((char *)error_text, "status %08x (%s / %s)",
632 status_to_convert, facility_name, component_name);
636 * try to get the specified message from the file
638 message = (char *)catgets(catd, 1, status_code, NO_MESSAGE);
640 * if everything went well, return the resulting message
642 if (strcmp(message, NO_MESSAGE) != 0) {
643 sprintf((char *)error_text, "%s (%s / %s)", message, facility_name,
645 if (status != NULL) {
649 sprintf((char *)error_text, "status %08x (%s / %s)",
650 status_to_convert, facility_name, component_name);
656 icl_DumpKernel(FILE *outFilep, char *setname)
658 afs_int32 bufferSize = 0;
661 afs_int32 code, retVal = 0;
666 afs_int32 dummy, dummy2;
669 /* first, enumerate the logs we're interested in */
672 /* dump logs for a particular set */
673 for (i = 0; i < ICL_LOGSPERSET; i++) {
675 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname,
676 i, (long)tname, sizeof(tname), 0, 0);
678 if (errno == EBADF) {
680 continue; /* missing slot, nothing to worry about */
685 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
686 (long)&dummy, (long)&dummy2, 0, 0, 0);
690 if (dummy > bufferSize) /* find biggest log */
692 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
693 memset(lip, 0, sizeof(*lip));
694 lip->nextp = allInfo;
696 lip->name = (char *)malloc(strlen(tname) + 1);
697 strcpy(lip->name, tname);
702 for (i = 0; i < 1000; i++) {
704 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
705 sizeof(tname), (long)&dummy, 0, 0);
708 if (dummy > bufferSize) /* find biggest log */
710 lip = (struct logInfo *)malloc(sizeof(struct logInfo));
711 memset(lip, 0, sizeof(*lip));
712 lip->nextp = allInfo;
714 lip->name = (char *)malloc(strlen(tname) + 1);
715 strcpy(lip->name, tname);
721 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
725 fprintf(outFilep, "Found %d logs.\n", i);
727 /* now print out the contents of each log */
728 for (lip = allInfo; lip; lip = lip->nextp) {
729 fprintf(outFilep, "\nContents of log %s:\n", lip->name);
730 /* read out everything first; gets a more consistent
733 nwords = 0; /* total words copied out */
735 /* display all the entries in the log */
736 if (bufferSize - nwords <= 0)
737 break; /* filled whole buffer */
739 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUT, (long)lip->name,
740 (long)(bufferp + nwords), bufferSize - nwords,
743 /* otherwise we've got an error */
744 fprintf(outFilep, "Returned error %d dumping log.\n", errno);
747 /* otherwise, we have flags in the high order byte, and
748 * a length (in words) in the remainder.
750 if ((code >> 24) & ICL_COPYOUTF_MISSEDSOME)
751 fprintf(outFilep, "Log wrapped; data missing.\n");
759 } /* for loop over all cookies */
761 /* otherwise we should display all of the log entries here.
762 * Note that a record may end in the middle, in which case
763 * we should start over with the cookie value of the start
766 for (ix = 0; ix < nwords;) {
767 /* start of a record */
768 rlength = (bufferp[ix] >> 24) & 0xff;
770 fprintf(outFilep, "Internal error: 0 length record\n");
774 /* ensure that entire record fits */
775 if (ix + rlength > nwords) {
776 /* doesn't fit, adjust cookie and break */
779 /* print the record */
780 DisplayRecord(outFilep, &bufferp[ix], rlength);
783 /* obsolete: read entire buffer first */
784 i += rlength; /* update cookie value, too */
786 } /* for loop displaying buffer */
787 } /* for loop over all logs */
794 /* clear out log 'name' */
796 icl_ClearLog(char *name)
800 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRLOG, (long)name, 0, 0, 0, 0, 0);
804 /* clear out set 'name' */
806 icl_ClearSet(char *name)
810 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRSET, (long)name, 0, 0, 0, 0, 0);
814 /* clear out all logs */
820 code = afs_syscall(AFSCALL_ICL, ICL_OP_CLRALL, 0, 0, 0, 0, 0, 0);
824 /* list out all available sets to outFileP */
826 icl_ListSets(FILE *outFileP)
833 for (i = 0; i < 1000; i++) {
835 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMSETS, i, (long)tname,
836 sizeof(tname), (long)&states, 0, 0);
839 (void)fprintf(outFileP, "%s %s%s%s\n", tname,
840 (states & ICL_SETF_ACTIVE) ? "active" : "inactive",
841 (states & ICL_SETF_FREED) ? " (dormant)" : "",
842 (states & ICL_SETF_PERSISTENT) ? " persistent" : "");
848 /* list out all available logs to outFileP */
850 icl_ListLogs(FILE *outFileP, int int32flg)
858 for (i = 0; i < 1000; i++) {
860 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGS, i, (long)tname,
861 sizeof(tname), (long)&logSize, 0, 0);
865 /* get more information on the log */
867 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
868 (long)&logSize, (long)&allocated, 0, 0, 0);
871 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
873 allocated ? "allocated" : "unallocated");
875 (void)fprintf(outFileP, "%s\n", tname);
881 /* list out all available logs to outFileP */
883 icl_ListLogsBySet(FILE *outFileP, char *setname, int int32flg)
891 for (i = 0; i < ICL_LOGSPERSET; i++) {
893 afs_syscall(AFSCALL_ICL, ICL_OP_ENUMLOGSBYSET, (long)setname, i,
894 (long)tname, sizeof(tname), 0, 0);
896 if (errno == EBADF) {
898 continue; /* missing */
903 /* get more information on the log */
905 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)tname,
906 (long)&logSize, (long)&allocated, 0, 0, 0);
909 (void)fprintf(outFileP, "%s : %d kbytes (%s)\n", tname,
911 allocated ? "allocated" : "unallocated");
913 (void)fprintf(outFileP, "%s\n", tname);
919 /* activate/deactivate/free specified set */
921 icl_ChangeSetState(char *name, afs_int32 op)
925 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTAT, (long)name, op, 0, 0, 0, 0);
929 /* activate/deactivate/free all sets */
931 icl_ChangeAllSetState(afs_int32 op)
935 code = afs_syscall(AFSCALL_ICL, ICL_OP_SETSTATALL, op, 0, 0, 0, 0, 0);
939 /* set size if log */
941 icl_ChangeLogSize(char *name, afs_int32 logSize)
946 afs_syscall(AFSCALL_ICL, ICL_OP_SETLOGSIZE, (long)name, logSize, 0,
951 /* get logsize of specified log */
953 icl_GetLogsize(char *logname, afs_int32 *logSizeP, int *allocatedP)
957 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
958 (long)logSizeP, (long)allocatedP, 0, 0, 0);
962 /* get state of specified set */
964 icl_GetSetState(char *setname, afs_int32 *stateP)
968 afs_syscall(AFSCALL_ICL, ICL_OP_GETSETINFO, (long)setname,
969 (long)stateP, 0, 0, 0, 0);
974 icl_TailKernel(FILE *outFilep, char *logname, afs_int32 waitTime)
976 afs_int32 bufferSize = 0;
977 afs_int32 newBufferSize;
980 afs_int32 code, retVal = 0;
986 /* get information about the specified log */
988 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
989 (long)&bufferSize, (long)&allocated, 0, 0, 0);
992 (void)fprintf(stderr, "'%s' not found\n", logname);
994 (void)fprintf(stderr,
995 "cannot get information on log '%s' (errno = %d)\n",
1001 (void)fprintf(stderr, "'%s' not allocated\n", logname);
1005 if (bufferSize == 0)
1007 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1009 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
1014 /* start "infinite" loop */
1016 /* read out all that's currently there */
1017 nwords = 0; /* total words copied out */
1018 i = 0; /* initialize cookie */
1020 /* display all the entries in the log */
1021 if (bufferSize - nwords <= 0)
1022 break; /* filled whole buffer, clear when done */
1024 afs_syscall(AFSCALL_ICL, ICL_OP_COPYOUTCLR, (long)logname,
1025 (long)(bufferp + nwords), bufferSize - nwords,
1028 /* otherwise we've got an error */
1029 fprintf(stderr, "returned error %d dumping log.\n", errno);
1033 /* otherwise, we have flags in the high order byte, and
1034 * a length (in words) in the remainder.
1043 } /* for loop over all cookies */
1045 /* otherwise we should display all of the log entries here.
1046 * Note that a record may end in the middle, in which case
1047 * we should start over with the cookie value of the start
1050 for (ix = 0; ix < nwords;) {
1051 /* start of a record */
1052 rlength = (bufferp[ix] >> 24) & 0xff;
1053 /* ensure that entire record fits */
1054 if (ix + rlength > nwords) {
1055 /* doesn't fit, adjust cookie and break */
1057 fprintf(stderr, "BOGUS: 0 length record\n");
1063 /* print the record */
1064 DisplayRecord(outFilep, &bufferp[ix], rlength);
1066 } /* for loop displaying buffer */
1071 /* see if things have changed */
1073 afs_syscall(AFSCALL_ICL, ICL_OP_GETLOGINFO, (long)logname,
1074 (long)&newBufferSize, (long)&allocated, 0, 0, 0);
1076 if (errno == ENOENT)
1077 (void)fprintf(stderr, "'%s' not found\n", logname);
1079 (void)fprintf(stderr,
1080 "cannot get information on log '%s' (errno = %d)\n",
1087 (void)fprintf(stderr, "'%s' no int32er allocated\n", logname);
1092 if (bufferSize == 0) {
1093 (void)fprintf(stderr, "buffer size has become 0\n");
1097 if (bufferSize != newBufferSize) {
1098 /* have to reallocate a buffer */
1099 bufferSize = newBufferSize;
1101 bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize);
1103 (void)fprintf(stderr, "cannot allocate %d words for buffer\n",
1109 } /* infinite loop */
1116 #if !defined(AFS_SGI_ENV)
1118 afs_syscall(long call, long parm0, long parm1, long parm2, long parm3,
1119 long parm4, long parm5, long parm6)
1122 #ifdef AFS_LINUX20_ENV
1123 #if defined AFS_LINUX_64BIT_KERNEL
1125 /* don't want to sign extend it to 64bit, so using ulong */
1126 eparm[0] = (unsigned long)parm3;
1127 eparm[1] = (unsigned long)parm4;
1128 eparm[2] = (unsigned long)parm5;
1129 eparm[3] = (unsigned long)parm6;
1137 /* Linux can only handle 5 arguments in the actual syscall. */
1138 if (call == AFSCALL_ICL) {
1139 rval = proc_afs_syscall(call, parm0, parm1, parm2, (long)eparm, &code);
1141 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, eparm);
1143 rval = proc_afs_syscall(call, parm0, parm1, parm2, parm3, &code);
1145 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3);
1147 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_SPARC_LINUX20_ENV)
1148 /* on sparc this function returns none value, so do it myself */
1149 __asm__ __volatile__("mov %o0, %i0; ret; restore");
1152 #ifdef AFS_DARWIN80_ENV
1153 code = ioctl_afs_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, &rval);
1154 if (!code) code = rval;
1156 #if !defined(AFS_SGI_ENV) && !defined(AFS_AIX32_ENV)
1157 code = syscall(AFS_SYSCALL, call, parm0, parm1, parm2, parm3, parm4);
1159 #if defined(AFS_SGI_ENV)
1160 code = syscall(AFS_ICL, call, parm0, parm1, parm2, parm3, parm4); /* XXX */
1162 code = syscall(AFSCALL_ICL, parm0, parm1, parm2, parm3, parm4);
1166 #endif /* AFS_LINUX20_ENV */
1174 /* init function, called once, under icl_lock */
1181 /* setup signal handler, in user space */
1188 icl_CreateSet(char *name, struct afs_icl_log *baseLogp,
1189 struct afs_icl_log *fatalLogp, struct afs_icl_set **outSetpp)
1191 return icl_CreateSetWithFlags(name, baseLogp, fatalLogp, /*flags */ 0,
1195 /* create a set, given pointers to base and fatal logs, if any.
1196 * Logs are unlocked, but referenced, and *outSetpp is returned
1197 * referenced. Function bumps reference count on logs, since it
1198 * addds references from the new icl_set. When the set is destroyed,
1199 * those references will be released.
1202 icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp,
1203 struct afs_icl_log *fatalLogp, afs_uint32 flags,
1204 struct afs_icl_set **outSetpp)
1206 struct afs_icl_set *setp;
1208 afs_int32 states = ICL_DEFAULT_SET_STATES;
1213 for (setp = icl_allSets; setp; setp = setp->nextp) {
1214 if (strcmp(setp->name, name) == 0) {
1217 if (flags & ICL_CRSET_FLAG_PERSISTENT) {
1218 setp->states |= ICL_SETF_PERSISTENT;
1224 /* determine initial state */
1225 if (flags & ICL_CRSET_FLAG_DEFAULT_ON)
1226 states = ICL_SETF_ACTIVE;
1227 else if (flags & ICL_CRSET_FLAG_DEFAULT_OFF)
1228 states = ICL_SETF_FREED;
1229 if (flags & ICL_CRSET_FLAG_PERSISTENT)
1230 states |= ICL_SETF_PERSISTENT;
1232 setp = (struct afs_icl_set *)osi_Alloc(sizeof(struct afs_icl_set));
1233 memset((caddr_t) setp, 0, sizeof(*setp));
1235 if (states & ICL_SETF_FREED)
1236 states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */
1237 setp->states = states;
1239 setp->name = (char *)osi_Alloc(strlen(name) + 1);
1240 strcpy(setp->name, name);
1241 setp->nevents = ICL_DEFAULTEVENTS;
1242 setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS);
1243 for (i = 0; i < ICL_DEFAULTEVENTS; i++)
1244 setp->eventFlags[i] = 0xff; /* default to enabled */
1246 /* update this global info under the icl_lock */
1247 setp->nextp = icl_allSets;
1250 /* set's basic lock is still held, so we can finish init */
1252 setp->logs[0] = baseLogp;
1253 icl_LogHold(baseLogp);
1254 if (!(setp->states & ICL_SETF_FREED))
1255 icl_LogUse(baseLogp); /* log is actually being used */
1258 setp->logs[1] = fatalLogp;
1259 icl_LogHold(fatalLogp);
1260 if (!(setp->states & ICL_SETF_FREED))
1261 icl_LogUse(fatalLogp); /* log is actually being used */
1268 /* function to change event enabling information for a particular set */
1270 icl_SetEnable(struct afs_icl_set *setp, afs_int32 eventID, int setValue)
1274 if (!ICL_EVENTOK(setp, eventID)) {
1277 tp = &setp->eventFlags[ICL_EVENTBYTE(eventID)];
1279 *tp |= ICL_EVENTMASK(eventID);
1281 *tp &= ~(ICL_EVENTMASK(eventID));
1285 /* return indication of whether a particular event ID is enabled
1286 * for tracing. If *getValuep is set to 0, the event is disabled,
1287 * otherwise it is enabled. All events start out enabled by default.
1290 icl_GetEnable(struct afs_icl_set *setp, afs_int32 eventID, int *getValuep)
1292 if (!ICL_EVENTOK(setp, eventID)) {
1295 if (setp->eventFlags[ICL_EVENTBYTE(eventID)] & ICL_EVENTMASK(eventID))
1302 /* hold and release event sets */
1304 icl_SetHold(struct afs_icl_set *setp)
1310 /* free a set. Called with icl_lock locked */
1312 icl_ZapSet(struct afs_icl_set *setp)
1314 struct afs_icl_set **lpp, *tp;
1316 struct afs_icl_log *tlp;
1318 for (lpp = &icl_allSets, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1320 /* found the dude we want to remove */
1322 osi_Free(setp->name, 1 + strlen(setp->name));
1323 osi_Free(setp->eventFlags, ICL_EVENTBYTES(setp->nevents));
1324 for (i = 0; i < ICL_LOGSPERSET; i++) {
1325 if ((tlp = setp->logs[i]))
1328 osi_Free(setp, sizeof(struct afs_icl_set));
1329 break; /* won't find it twice */
1335 /* do the release, watching for deleted entries */
1337 icl_SetRele(struct afs_icl_set *setp)
1339 if (--setp->refCount == 0 && (setp->states & ICL_SETF_DELETED)) {
1340 icl_ZapSet(setp); /* destroys setp's lock! */
1345 /* free a set entry, dropping its reference count */
1347 icl_SetFree(struct afs_icl_set *setp)
1349 setp->states |= ICL_SETF_DELETED;
1354 /* find a set by name, returning it held */
1355 struct afs_icl_set *
1356 icl_FindSet(char *name)
1358 struct afs_icl_set *tp;
1360 for (tp = icl_allSets; tp; tp = tp->nextp) {
1361 if (strcmp(tp->name, name) == 0) {
1362 /* this is the dude we want */
1370 /* zero out all the logs in the set */
1372 icl_ZeroSet(struct afs_icl_set *setp)
1377 struct afs_icl_log *logp;
1379 for (i = 0; i < ICL_LOGSPERSET; i++) {
1380 logp = setp->logs[i];
1383 tcode = icl_ZeroLog(logp);
1385 code = tcode; /* save the last bad one */
1393 icl_EnumerateSets(int (*aproc) (char *, void *, struct afs_icl_set *),
1396 struct afs_icl_set *tp, *np;
1400 for (tp = icl_allSets; tp; tp = np) {
1401 tp->refCount++; /* hold this guy */
1402 code = (*aproc) (tp->name, arock, tp);
1403 np = tp->nextp; /* tp may disappear next, but not np */
1404 if (--tp->refCount == 0 && (tp->states & ICL_SETF_DELETED))
1413 icl_AddLogToSet(struct afs_icl_set *setp, struct afs_icl_log *newlogp)
1418 for (i = 0; i < ICL_LOGSPERSET; i++) {
1419 if (!setp->logs[i]) {
1420 setp->logs[i] = newlogp;
1422 icl_LogHold(newlogp);
1423 if (!(setp->states & ICL_SETF_FREED)) {
1424 /* bump up the number of sets using the log */
1425 icl_LogUse(newlogp);
1434 icl_SetSetStat(struct afs_icl_set *setp, int op)
1438 struct afs_icl_log *logp;
1441 case ICL_OP_SS_ACTIVATE: /* activate a log */
1443 * If we are not already active, see if we have released
1444 * our demand that the log be allocated (FREED set). If
1445 * we have, reassert our desire.
1447 if (!(setp->states & ICL_SETF_ACTIVE)) {
1448 if (setp->states & ICL_SETF_FREED) {
1449 /* have to reassert desire for logs */
1450 for (i = 0; i < ICL_LOGSPERSET; i++) {
1451 logp = setp->logs[i];
1458 setp->states &= ~ICL_SETF_FREED;
1460 setp->states |= ICL_SETF_ACTIVE;
1465 case ICL_OP_SS_DEACTIVATE: /* deactivate a log */
1466 /* this doesn't require anything beyond clearing the ACTIVE flag */
1467 setp->states &= ~ICL_SETF_ACTIVE;
1471 case ICL_OP_SS_FREE: /* deassert design for log */
1473 * if we are already in this state, do nothing; otherwise
1474 * deassert desire for log
1476 if (setp->states & ICL_SETF_ACTIVE)
1479 if (!(setp->states & ICL_SETF_FREED)) {
1480 for (i = 0; i < ICL_LOGSPERSET; i++) {
1481 logp = setp->logs[i];
1484 icl_LogFreeUse(logp);
1488 setp->states |= ICL_SETF_FREED;
1501 struct afs_icl_log *afs_icl_allLogs = 0;
1503 /* hold and release logs */
1505 icl_LogHold(struct afs_icl_log *logp)
1511 /* hold and release logs, called with lock already held */
1513 icl_LogHoldNL(struct afs_icl_log *logp)
1519 /* keep track of how many sets believe the log itself is allocated */
1521 icl_LogUse(struct afs_icl_log *logp)
1523 if (logp->setCount == 0) {
1524 /* this is the first set actually using the log -- allocate it */
1525 if (logp->logSize == 0) {
1526 /* we weren't passed in a hint and it wasn't set */
1527 logp->logSize = ICL_DEFAULT_LOGSIZE;
1530 (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize);
1536 /* decrement the number of real users of the log, free if possible */
1538 icl_LogFreeUse(struct afs_icl_log *logp)
1540 if (--logp->setCount == 0) {
1541 /* no more users -- free it (but keep log structure around) */
1542 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1543 logp->firstUsed = logp->firstFree = 0;
1544 logp->logElements = 0;
1550 /* set the size of the log to 'logSize' */
1552 icl_LogSetSize(struct afs_icl_log *logp, afs_int32 logSize)
1555 /* nothing to worry about since it's not allocated */
1556 logp->logSize = logSize;
1559 logp->firstUsed = logp->firstFree = 0;
1560 logp->logElements = 0;
1562 /* free and allocate a new one */
1563 osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize);
1564 logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logSize);
1565 logp->logSize = logSize;
1571 /* free a log. Called with icl_lock locked. */
1573 icl_ZapLog(struct afs_icl_log *logp)
1575 struct afs_icl_log **lpp, *tp;
1577 for (lpp = &afs_icl_allLogs, tp = *lpp; tp; lpp = &tp->nextp, tp = *lpp) {
1579 /* found the dude we want to remove */
1581 osi_Free(logp->name, 1 + strlen(logp->name));
1582 osi_Free(logp->datap, logp->logSize * sizeof(afs_int32));
1583 osi_Free(logp, sizeof(struct icl_log));
1584 break; /* won't find it twice */
1590 /* do the release, watching for deleted entries */
1592 icl_LogRele(struct afs_icl_log *logp)
1594 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1595 icl_ZapLog(logp); /* destroys logp's lock! */
1600 /* do the release, watching for deleted entries, log already held */
1602 icl_LogReleNL(struct afs_icl_log *logp)
1604 if (--logp->refCount == 0 && (logp->states & ICL_LOGF_DELETED)) {
1605 icl_ZapLog(logp); /* destroys logp's lock! */
1610 /* zero out the log */
1612 icl_ZeroLog(struct afs_icl_log *logp)
1614 logp->firstUsed = logp->firstFree = 0;
1615 logp->logElements = 0;
1619 /* free a log entry, and drop its reference count */
1621 icl_LogFree(struct afs_icl_log *logp)
1623 logp->states |= ICL_LOGF_DELETED;
1630 icl_EnumerateLogs(int (*aproc)
1631 (char *name, void *arock, struct afs_icl_log * tp),
1634 struct afs_icl_log *tp;
1638 for (tp = afs_icl_allLogs; tp; tp = tp->nextp) {
1639 tp->refCount++; /* hold this guy */
1640 code = (*aproc) (tp->name, arock, tp);
1641 if (--tp->refCount == 0)
1650 afs_icl_bulkSetinfo_t *
1651 GetBulkSetInfo(void)
1653 unsigned int infoSize;
1656 sizeof(afs_icl_bulkSetinfo_t) + (ICL_RPC_MAX_SETS -
1657 1) * sizeof(afs_icl_setinfo_t);
1659 setInfo = (afs_icl_bulkSetinfo_t *) malloc(infoSize);
1661 (void)fprintf(stderr,
1662 "Could not allocate the memory for bulk set info structure\n");
1666 memset(setInfo, 0, infoSize);
1671 afs_icl_bulkLoginfo_t *
1672 GetBulkLogInfo(void)
1674 unsigned int infoSize;
1677 sizeof(afs_icl_bulkLoginfo_t) + (ICL_RPC_MAX_LOGS -
1678 1) * sizeof(afs_icl_loginfo_t);
1680 logInfo = (afs_icl_bulkLoginfo_t *) malloc(infoSize);
1682 (void)fprintf(stderr,
1683 "Could not allocate the memory for bulk log info structure\n");
1688 memset(logInfo, 0, infoSize);
1694 DoDump(struct cmd_syndesc *as, void *arock)
1698 afs_int32 waitTime = 10 /* seconds */ ;
1700 FILE *outfp = stdout;
1702 struct cmd_item *itemp;
1704 if (geteuid() != 0) {
1705 printf("fstrace must be run as root\n");
1709 if (as->parms[3].items) {
1710 if (!as->parms[1].items) {
1711 (void)fprintf(stderr, "-sleep can only be used with -follow\n");
1714 waitTime = strtol(as->parms[3].items->data, NULL, 0);
1717 if (as->parms[2].items) {
1718 /* try to open the specified output file */
1719 if ((outfp = fopen(as->parms[2].items->data, "w")) == NULL) {
1720 (void)fprintf(stderr, "Cannot open file '%s' for writing\n",
1721 as->parms[2].items->data);
1725 #ifdef AFS_SGI64_ENV
1726 startTime = time((time_t *) 0);
1728 startTime = time(0);
1730 (void)fprintf(outfp, "AFS Trace Dump -\n\n Date: %s\n",
1733 if (as->parms[0].items) {
1734 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1735 tcode = icl_DumpKernel(outfp, itemp->data);
1737 (void)fprintf(stderr, "Unable to dump set %s (errno = %d)\n",
1738 itemp->data, errno);
1742 } else if (as->parms[1].items) {
1743 logname = as->parms[1].items->data;
1744 code = icl_TailKernel(outfp, logname, waitTime);
1746 (void)fprintf(stderr,
1747 "Error tailing kernel log '%s' (errno = %d)\n",
1751 code = icl_DumpKernel(outfp, NULL);
1753 (void)fprintf(outfp, "\nAFS Trace Dump - %s\n",
1754 code ? "FAILED" : "Completed");
1756 if (outfp != stdout)
1757 (void)fclose(outfp);
1765 struct cmd_syndesc *dumpSyntax;
1768 cmd_CreateSyntax("dump", DoDump, NULL, "dump AFS trace logs");
1769 (void)cmd_AddParm(dumpSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
1770 (void)cmd_AddParm(dumpSyntax, "-follow", CMD_SINGLE, CMD_OPTIONAL,
1772 (void)cmd_AddParm(dumpSyntax, "-file", CMD_SINGLE, CMD_OPTIONAL,
1774 (void)cmd_AddParm(dumpSyntax, "-sleep", CMD_SINGLE, CMD_OPTIONAL,
1775 "seconds_between_reads");
1779 DoShowLog(struct cmd_syndesc *as, void *arock)
1781 afs_int32 retVal = 0;
1786 struct cmd_item *itemp;
1788 if (geteuid() != 0) {
1789 printf("fstrace must be run as root\n");
1792 if (as->parms[2].items)
1795 if (as->parms[0].items) {
1796 /* enumerate logs for the specified sets */
1797 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1798 (void)fprintf(stdout, "Logs for set '%s':\n", itemp->data);
1799 code = icl_ListLogsBySet(stdout, itemp->data, int32flg);
1801 (void)fprintf(stderr,
1802 "Error in enumerating set %s (errno = %d)\n",
1803 itemp->data, errno);
1807 } else if (as->parms[1].items) {
1808 /* print out log information */
1809 for (itemp = as->parms[1].items; itemp; itemp = itemp->next) {
1810 code = icl_GetLogsize(itemp->data, &logSize, &allocated);
1812 (void)fprintf(stdout, "%s : %d kbytes (%s)\n", itemp->data,
1814 allocated ? "allocated" : "unallocated");
1816 (void)fprintf(stderr,
1817 "Could not find log '%s' (errno = %d)\n",
1818 itemp->data, errno);
1824 (void)fprintf(stdout, "Available logs:\n");
1825 code = icl_ListLogs(stdout, int32flg);
1827 (void)fprintf(stderr, "Error in listing logs (errno = %d)\n",
1839 struct cmd_syndesc *showSyntax;
1842 cmd_CreateSyntax("lslog", DoShowLog, NULL,
1843 "list available logs");
1844 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
1845 (void)cmd_AddParm(showSyntax, "-log", CMD_LIST, CMD_OPTIONAL, "log_name");
1846 (void)cmd_AddParm(showSyntax, "-long", CMD_FLAG, CMD_OPTIONAL, "");
1850 DoShowSet(struct cmd_syndesc *as, void *arock)
1852 afs_int32 retVal = 0;
1855 struct cmd_item *itemp;
1857 if (geteuid() != 0) {
1858 printf("fstrace must be run as root\n");
1861 if (as->parms[0].items) {
1862 /* print information on the specified sets */
1863 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1864 code = icl_GetSetState(itemp->data, &state);
1866 (void)fprintf(stderr,
1867 "Error getting status on set %s (errno = %d)\n",
1868 itemp->data, errno);
1871 (void)fprintf(stdout, "Set %s: %s%s%s\n", itemp->data,
1872 (state & ICL_SETF_ACTIVE) ? "active" :
1874 (state & ICL_SETF_FREED) ? " (dormant)" : "",
1875 (state & ICL_SETF_PERSISTENT) ? " persistent" :
1880 (void)fprintf(stdout, "Available sets:\n");
1881 code = icl_ListSets(stdout);
1883 (void)fprintf(stderr, "Error in listing sets (errno = %d)\n",
1895 struct cmd_syndesc *showSyntax;
1898 cmd_CreateSyntax("lsset", DoShowSet, NULL,
1899 "list available event sets");
1900 (void)cmd_AddParm(showSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
1904 DoClear(struct cmd_syndesc *as, void *arock)
1906 afs_int32 retVal = 0;
1908 struct cmd_item *itemp;
1910 if (geteuid() != 0) {
1911 printf("fstrace must be run as root\n");
1914 if (as->parms[0].items) {
1915 /* clear logs for the specified sets */
1916 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1917 code = icl_ClearSet(itemp->data);
1919 (void)fprintf(stderr,
1920 "Error in clearing set %s (errno = %d)\n",
1921 itemp->data, errno);
1925 } else if (as->parms[1].items) {
1926 /* clear specified log */
1927 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1928 code = icl_ClearLog(itemp->data);
1930 (void)fprintf(stderr,
1931 "Error in clearing log %s (errno = %d)\n",
1932 itemp->data, errno);
1937 /* clear all logs */
1938 code = icl_ClearAll();
1940 (void)fprintf(stderr, "Error in clearing logs (errno = %d)\n",
1952 struct cmd_syndesc *clearSyntax;
1955 cmd_CreateSyntax("clear", DoClear, NULL,
1956 "clear logs by logname or by event set");
1957 (void)cmd_AddParm(clearSyntax, "-set", CMD_LIST, CMD_OPTIONAL,
1959 (void)cmd_AddParm(clearSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
1964 DoSet(struct cmd_syndesc *as, void *arock)
1966 afs_int32 retVal = 0;
1971 struct cmd_item *itemp;
1973 if (geteuid() != 0) {
1974 printf("fstrace must be run as root\n");
1977 if (as->parms[1].items) {
1978 op = ICL_OP_SS_ACTIVATE;
1979 operation = "active";
1980 } else if (as->parms[2].items) {
1981 op = ICL_OP_SS_DEACTIVATE;
1982 operation = "inactive";
1983 } else if (as->parms[3].items) {
1984 op = ICL_OP_SS_DEACTIVATE;
1985 operation = "inactive";
1988 /* assume active" */
1989 op = ICL_OP_SS_ACTIVATE;
1990 operation = "active";
1993 if (as->parms[0].items) {
1994 /* activate specified sets */
1995 for (itemp = as->parms[0].items; itemp; itemp = itemp->next) {
1996 code = icl_ChangeSetState(itemp->data, op);
1998 (void)fprintf(stderr,
1999 "cannot set state of %s to %s (errno = %d)\n",
2000 itemp->data, operation, errno);
2002 } else if (doFree) {
2003 /* try to make it dormant as well */
2004 code = icl_ChangeSetState(itemp->data, ICL_OP_SS_FREE);
2006 (void)fprintf(stderr,
2007 "cannot set state of %s to dormant (errno = %d)\n",
2008 itemp->data, errno);
2015 code = icl_ChangeAllSetState(op);
2017 (void)fprintf(stderr,
2018 "cannot set the state of all sets to %s (errno = %d)\n",
2021 } else if (doFree) {
2022 /* try to make it dormant as well */
2023 code = icl_ChangeAllSetState(ICL_OP_SS_FREE);
2025 (void)fprintf(stderr,
2026 "cannot set the state of all sets to dormant (errno = %d)\n",
2039 struct cmd_syndesc *setSyntax;
2042 cmd_CreateSyntax("setset", DoSet, NULL,
2043 "set state of event sets");
2044 (void)cmd_AddParm(setSyntax, "-set", CMD_LIST, CMD_OPTIONAL, "set_name");
2045 (void)cmd_AddParm(setSyntax, "-active", CMD_FLAG, CMD_OPTIONAL, "");
2046 (void)cmd_AddParm(setSyntax, "-inactive", CMD_FLAG, CMD_OPTIONAL, "");
2047 (void)cmd_AddParm(setSyntax, "-dormant", CMD_FLAG, CMD_OPTIONAL, "");
2051 DoResize(struct cmd_syndesc *as, void *arock)
2053 afs_int32 retVal = 0;
2055 afs_int32 bufferSize;
2056 struct cmd_item *itemp;
2058 if (geteuid() != 0) {
2059 printf("fstrace must be run as root\n");
2062 /* get buffer size */
2063 bufferSize = atoi(as->parms[1].items->data);
2064 bufferSize *= BUFFER_MULTIPLIER;
2065 if (bufferSize == 0)
2066 bufferSize = ICL_DEFAULT_LOGSIZE;
2068 /* set the size of the specified logs */
2069 if ((itemp = as->parms[0].items)) {
2070 for (; itemp; itemp = itemp->next) {
2071 code = icl_ChangeLogSize(itemp->data, bufferSize);
2073 (void)fprintf(stderr,
2074 "Error in changing log %s buffer size (errno = %d)\n",
2075 itemp->data, errno);
2080 /* Use the only current support log, "cmfx" */
2081 code = icl_ChangeLogSize("cmfx", bufferSize);
2083 (void)fprintf(stderr,
2084 "Error in changing log cmfx buffer size (errno = %d)\n",
2096 struct cmd_syndesc *setsizeSyntax;
2099 cmd_CreateSyntax("setlog", DoResize, NULL,
2100 "set the size of a log");
2101 (void)cmd_AddParm(setsizeSyntax, "-log", CMD_LIST, CMD_OPTIONAL,
2103 (void)cmd_AddParm(setsizeSyntax, "-buffersize", CMD_SINGLE, CMD_REQUIRED,
2104 "1-kilobyte_units");
2107 #include "AFS_component_version_number.c"
2110 main(int argc, char *argv[])
2112 setlocale(LC_ALL, "");
2113 #ifdef AFS_SGI62_ENV
2114 set_kernel_sizeof_long();
2117 /* set up user interface then dispatch */
2125 return (cmd_Dispatch(argc, argv));
2128 #include "AFS_component_version_number.c"
2131 main(int argc, char *argv[])
2133 printf("fstrace is NOT supported for this OS\n");