[linux-cifs-client] [PATCH 2/2]: Utility program to dump cifs Debug
data and Statistics
Suresh Jayaraman
sjayaraman at suse.de
Mon Jan 7 15:39:03 GMT 2008
This patch provides a utility program that allows to display
cifs debug data (active sessions and shares) and statistics
that are available in /proc/fs/cifs.
Signed-off-by: Suresh Jayaraman <sjayaraman at suse.de>
---
/*
* cifsinfo.c - Dump cifs statistics from /proc/fs/cifs.
*
* Copyright (C) 2008 Suresh Jayaraman (sjayaraman at suse.de)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#define CIFS_DEBUGDATA "/proc/fs/cifs/DebugData"
#define CIFS_STATS "/proc/fs/cifs/Stats"
#define BUFLEN 4096
static char *progname;
static void usage(void)
{
fprintf(stderr,
"Usage: %s [OPTION]\n"
"OPTIONS:\n"
"\t-d\tShow cifs debug data\n"
"\t-s\tShow cifs statistics\n"
"\t-h\tShow help information\n",
progname);
exit(1);
}
/*Just dump, don't pretty-format as it is already formatted */
static int dump_info(char *file)
{
FILE *fp;
char buf[BUFLEN];
fp = fopen(file, "r");
if (fp != NULL) {
while ((fgets(buf, sizeof(buf), fp)) != NULL)
fprintf(stdout, "%s", buf);
fclose(fp);
} else if (errno == ENOENT) {
fprintf(stderr, "%s: failed to open %s : %s\n", progname, file,
strerror(errno));
fprintf(stderr, "Hint: Check whether cifs module is loaded\n");
exit(1);
} else {
fprintf(stderr, "%s: failed to open %s: %s\n", progname, file,
strerror(errno));
exit(1);
}
return 0;
}
int main(int argc, char *argv[])
{
int i;
int opt;
progname = argv[0];
if (argc != 2)
usage();
while ((opt = getopt(argc, argv, "dsh")) != -1) {
switch (opt) {
case 'd':
if (dump_info(CIFS_DEBUGDATA) != 0)
return -1;
break;
case 's':
if (dump_info(CIFS_STATS) != 0)
return -1;
break;
case 'h':
usage();
case '?':
fprintf(stderr, "Try `%s -h' for more information.\n",
progname);
return -1;
default:
usage();
}
}
for (i = optind; i < argc; i++) {
fprintf(stderr, "%s: invalid option %s\n", progname, argv[i]);
fprintf(stderr, "Try `%s -h' for more information.\n", progname);
return -1;
}
exit(0);
}
More information about the linux-cifs-client
mailing list