Skip to content

Commit b964a29

Browse files
author
Sunil Mushran
committed
debugfs.ocfs2: net_stats reads user specified file
Patch adds -f option to the net_stats command to allow the user to specify a file that is a saved copy of /sys/kernel/debug/o2net/stats. Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com>
1 parent 1190241 commit b964a29

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

debugfs.ocfs2/commands.c

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static struct command commands[] = {
230230
},
231231
{ "net_stats",
232232
do_net_stats,
233-
"net_stats [interval [count]]",
233+
"net_stats [-f <file>] [interval [count]]",
234234
"Show net statistics",
235235
},
236236
{ "ncheck",
@@ -2189,20 +2189,39 @@ static void do_refcount(char **args)
21892189
static void do_net_stats(char **args)
21902190
{
21912191
int interval = 0, count = 0;
2192-
char *net_stats_usage = "usage: net_stats [interval [count]]";
2192+
char *net_stats_usage = "usage: net_stats [-f <file>] [interval [count]]";
21932193
char *endptr;
2194+
char *path = NULL;
2195+
int c, argc;
2196+
2197+
for (argc = 0; (args[argc]); ++argc);
2198+
optind = 0;
21942199

2195-
if (args[1]) {
2196-
interval = strtoul(args[1], &endptr, 0);
2197-
if (!*endptr && args[2])
2198-
count = strtoul(args[2], &endptr, 0);
2200+
while ((c = getopt(argc, args, "f:")) != -1) {
2201+
switch (c) {
2202+
case 'f':
2203+
path = optarg;
2204+
break;
2205+
default:
2206+
break;
2207+
}
2208+
}
2209+
2210+
if (args[optind]) {
2211+
interval = strtoul(args[optind], &endptr, 0);
2212+
if (!*endptr && args[++optind])
2213+
count = strtoul(args[optind], &endptr, 0);
21992214
if (*endptr) {
22002215
fprintf(stderr, "%s\n", net_stats_usage);
22012216
return ;
22022217
}
22032218
}
22042219

2205-
dump_net_stats(stdout, interval, count);
2220+
/* Ignore device is user specifies the stats file */
2221+
if (path == NULL && check_device_open())
2222+
return;
2223+
2224+
dump_net_stats(stdout, path, interval, count);
22062225
}
22072226

22082227
static void do_stat_sysdir(char **args)

debugfs.ocfs2/debugfs.ocfs2.8.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ Print the listing of the files in the directory \fIfilespec\fR. The
229229
\fI\-l\fR flag will list files in the long format.
230230

231231
.TP
232-
\fInet_stats [interval [count]]\fR
233-
Display net statistics.
232+
\fInet_stats [-f <file>] [interval [count]]\fR
233+
Display the net statistics. This command expects the debugfs filesystem to be
234+
mounted at \fI/sys/kernel/debug\fR. The \fIinterval\fR is in seconds. Use the
235+
\fI-f\fR parameter to specify a saved copy of /sys/kernel/debug/o2net/stats.
234236

235237
.TP
236238
\fIncheck [<lockname>|<inode#>] ...\fR

debugfs.ocfs2/dump_net_stats.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ static void show_net_stats(FILE *out, struct net_stats *prev,
119119
#define CURRENT_O2NET_STATS_PROTO 1
120120
#define MAX_O2NET_STATS_STR_LEN 1024
121121

122-
static int read_net_stats(const char *debugfs_path, struct net_stats *stats,
123-
int num_entries, unsigned long *proto)
122+
static int read_net_stats(const char *debugfs_path, char *path,
123+
struct net_stats *stats, int num_entries,
124+
unsigned long *proto)
124125
{
125126
FILE *file = NULL;
126127
char rec1[MAX_O2NET_STATS_STR_LEN], rec2[MAX_O2NET_STATS_STR_LEN];
@@ -129,11 +130,21 @@ static int read_net_stats(const char *debugfs_path, struct net_stats *stats,
129130

130131
memset(stats, 0, sizeof(struct net_stats) * num_entries);
131132

132-
ret = open_debugfs_file(debugfs_path, "o2net", NULL, "stats", &file);
133-
if (ret) {
134-
com_err(cmd, ret, "Could not open %s/o2net/stats\n",
135-
debugfs_path);
136-
goto bail;
133+
if (!path) {
134+
ret = open_debugfs_file(debugfs_path, "o2net", NULL, "stats",
135+
&file);
136+
if (ret) {
137+
com_err(cmd, ret, "; could not open %s/o2net/stats",
138+
debugfs_path);
139+
goto bail;
140+
}
141+
} else {
142+
file = fopen(path, "r");
143+
if (!file) {
144+
ret = errno;
145+
com_err(cmd, ret, "\"%s\"", path);
146+
goto bail;
147+
}
137148
}
138149

139150
while (fgets(rec1, sizeof(rec1), file)) {
@@ -196,7 +207,7 @@ static int read_net_stats(const char *debugfs_path, struct net_stats *stats,
196207
return ret;
197208
}
198209

199-
void dump_net_stats(FILE *out, int interval, int count)
210+
void dump_net_stats(FILE *out, char *path, int interval, int count)
200211
{
201212
errcode_t ret;
202213
char debugfs_path[PATH_MAX];
@@ -216,7 +227,8 @@ void dump_net_stats(FILE *out, int interval, int count)
216227
memset(prev, 0 , sizeof(buf1));
217228

218229
do {
219-
ret = read_net_stats(debugfs_path, curr, O2NM_MAX_NODES, &proto);
230+
ret = read_net_stats(debugfs_path, path, curr, O2NM_MAX_NODES,
231+
&proto);
220232
if (ret)
221233
break;
222234

debugfs.ocfs2/include/dump_net_stats.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ struct net_stats {
3535
long long ns_proc_time;
3636
};
3737

38-
void dump_net_stats(FILE *out, int interval, int count);
38+
void dump_net_stats(FILE *out, char *path, int interval, int count);
3939

4040
#endif /* _DUMP_NET_STATS_H_ */

0 commit comments

Comments
 (0)