1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * debug functionality for o2net
8 * Copyright (C) 2005, 2008 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
27 #ifdef CONFIG_DEBUG_FS
29 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/slab.h>
32 #include <linux/idr.h>
33 #include <linux/kref.h>
34 #include <linux/seq_file.h>
35 #include <linux/debugfs.h>
37 #include <linux/uaccess.h>
40 #include "nodemanager.h"
41 #define MLOG_MASK_PREFIX ML_TCP
44 #include "tcp_internal.h"
46 #define O2NET_DEBUG_DIR "o2net"
47 #define SC_DEBUG_NAME "sock_containers"
48 #define NST_DEBUG_NAME "send_tracking"
50 static struct dentry
*o2net_dentry
;
51 static struct dentry
*sc_dentry
;
52 static struct dentry
*nst_dentry
;
54 static DEFINE_SPINLOCK(o2net_debug_lock
);
56 static LIST_HEAD(sock_containers
);
57 static LIST_HEAD(send_tracking
);
59 void o2net_debug_add_nst(struct o2net_send_tracking
*nst
)
61 spin_lock(&o2net_debug_lock
);
62 list_add(&nst
->st_net_debug_item
, &send_tracking
);
63 spin_unlock(&o2net_debug_lock
);
66 void o2net_debug_del_nst(struct o2net_send_tracking
*nst
)
68 spin_lock(&o2net_debug_lock
);
69 if (!list_empty(&nst
->st_net_debug_item
))
70 list_del_init(&nst
->st_net_debug_item
);
71 spin_unlock(&o2net_debug_lock
);
74 static struct o2net_send_tracking
75 *next_nst(struct o2net_send_tracking
*nst_start
)
77 struct o2net_send_tracking
*nst
, *ret
= NULL
;
79 assert_spin_locked(&o2net_debug_lock
);
81 list_for_each_entry(nst
, &nst_start
->st_net_debug_item
,
83 /* discover the head of the list */
84 if (&nst
->st_net_debug_item
== &send_tracking
)
87 /* use st_task to detect real nsts in the list */
88 if (nst
->st_task
!= NULL
) {
97 static void *nst_seq_start(struct seq_file
*seq
, loff_t
*pos
)
99 struct o2net_send_tracking
*nst
, *dummy_nst
= seq
->private;
101 spin_lock(&o2net_debug_lock
);
102 nst
= next_nst(dummy_nst
);
103 spin_unlock(&o2net_debug_lock
);
108 static void *nst_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
110 struct o2net_send_tracking
*nst
, *dummy_nst
= seq
->private;
112 spin_lock(&o2net_debug_lock
);
113 nst
= next_nst(dummy_nst
);
114 list_del_init(&dummy_nst
->st_net_debug_item
);
116 list_add(&dummy_nst
->st_net_debug_item
,
117 &nst
->st_net_debug_item
);
118 spin_unlock(&o2net_debug_lock
);
120 return nst
; /* unused, just needs to be null when done */
123 static int nst_seq_show(struct seq_file
*seq
, void *v
)
125 struct o2net_send_tracking
*nst
, *dummy_nst
= seq
->private;
127 spin_lock(&o2net_debug_lock
);
128 nst
= next_nst(dummy_nst
);
131 /* get_task_comm isn't exported. oh well. */
132 seq_printf(seq
, "%p:\n"
135 " process name: %s\n"
139 " message type: %u\n"
140 " message key: 0x%08x\n"
141 " sock acquiry: %lu.%lu\n"
142 " send start: %lu.%lu\n"
143 " wait start: %lu.%lu\n",
144 nst
, (unsigned long)nst
->st_task
->pid
,
145 (unsigned long)nst
->st_task
->tgid
,
146 nst
->st_task
->comm
, nst
->st_node
,
147 nst
->st_sc
, nst
->st_id
, nst
->st_msg_type
,
149 nst
->st_sock_time
.tv_sec
, nst
->st_sock_time
.tv_usec
,
150 nst
->st_send_time
.tv_sec
, nst
->st_send_time
.tv_usec
,
151 nst
->st_status_time
.tv_sec
,
152 nst
->st_status_time
.tv_usec
);
155 spin_unlock(&o2net_debug_lock
);
160 static void nst_seq_stop(struct seq_file
*seq
, void *v
)
164 static struct seq_operations nst_seq_ops
= {
165 .start
= nst_seq_start
,
166 .next
= nst_seq_next
,
167 .stop
= nst_seq_stop
,
168 .show
= nst_seq_show
,
171 static int nst_fop_open(struct inode
*inode
, struct file
*file
)
173 struct o2net_send_tracking
*dummy_nst
;
174 struct seq_file
*seq
;
177 dummy_nst
= kmalloc(sizeof(struct o2net_send_tracking
), GFP_KERNEL
);
178 if (dummy_nst
== NULL
) {
182 dummy_nst
->st_task
= NULL
;
184 ret
= seq_open(file
, &nst_seq_ops
);
188 seq
= file
->private_data
;
189 seq
->private = dummy_nst
;
190 o2net_debug_add_nst(dummy_nst
);
199 static int nst_fop_release(struct inode
*inode
, struct file
*file
)
201 struct seq_file
*seq
= file
->private_data
;
202 struct o2net_send_tracking
*dummy_nst
= seq
->private;
204 o2net_debug_del_nst(dummy_nst
);
205 return seq_release_private(inode
, file
);
208 static struct file_operations nst_seq_fops
= {
209 .open
= nst_fop_open
,
212 .release
= nst_fop_release
,
215 void o2net_debug_add_sc(struct o2net_sock_container
*sc
)
217 spin_lock(&o2net_debug_lock
);
218 list_add(&sc
->sc_net_debug_item
, &sock_containers
);
219 spin_unlock(&o2net_debug_lock
);
222 void o2net_debug_del_sc(struct o2net_sock_container
*sc
)
224 spin_lock(&o2net_debug_lock
);
225 list_del_init(&sc
->sc_net_debug_item
);
226 spin_unlock(&o2net_debug_lock
);
229 static struct o2net_sock_container
230 *next_sc(struct o2net_sock_container
*sc_start
)
232 struct o2net_sock_container
*sc
, *ret
= NULL
;
234 assert_spin_locked(&o2net_debug_lock
);
236 list_for_each_entry(sc
, &sc_start
->sc_net_debug_item
,
238 /* discover the head of the list miscast as a sc */
239 if (&sc
->sc_net_debug_item
== &sock_containers
)
242 /* use sc_page to detect real scs in the list */
243 if (sc
->sc_page
!= NULL
) {
252 static void *sc_seq_start(struct seq_file
*seq
, loff_t
*pos
)
254 struct o2net_sock_container
*sc
, *dummy_sc
= seq
->private;
256 spin_lock(&o2net_debug_lock
);
257 sc
= next_sc(dummy_sc
);
258 spin_unlock(&o2net_debug_lock
);
263 static void *sc_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
265 struct o2net_sock_container
*sc
, *dummy_sc
= seq
->private;
267 spin_lock(&o2net_debug_lock
);
268 sc
= next_sc(dummy_sc
);
269 list_del_init(&dummy_sc
->sc_net_debug_item
);
271 list_add(&dummy_sc
->sc_net_debug_item
, &sc
->sc_net_debug_item
);
272 spin_unlock(&o2net_debug_lock
);
274 return sc
; /* unused, just needs to be null when done */
277 #define TV_SEC_USEC(TV) TV.tv_sec, TV.tv_usec
279 static int sc_seq_show(struct seq_file
*seq
, void *v
)
281 struct o2net_sock_container
*sc
, *dummy_sc
= seq
->private;
283 spin_lock(&o2net_debug_lock
);
284 sc
= next_sc(dummy_sc
);
287 struct inet_sock
*inet
= NULL
;
289 __be32 saddr
= 0, daddr
= 0;
290 __be16 sport
= 0, dport
= 0;
293 inet
= inet_sk(sc
->sc_sock
->sk
);
294 /* the stack's structs aren't sparse endian clean */
295 saddr
= (__force __be32
)inet
->saddr
;
296 daddr
= (__force __be32
)inet
->daddr
;
297 sport
= (__force __be16
)inet
->sport
;
298 dport
= (__force __be16
)inet
->dport
;
301 /* XXX sigh, inet-> doesn't have sparse annotation so any
302 * use of it here generates a warning with -Wbitwise */
303 seq_printf(seq
, "%p:\n"
305 " sock: %u.%u.%u.%u:%u -> "
309 " handshake ok: %u\n"
311 " data ready: %lu.%lu\n"
312 " advance start: %lu.%lu\n"
313 " advance stop: %lu.%lu\n"
314 " func start: %lu.%lu\n"
315 " func stop: %lu.%lu\n"
319 atomic_read(&sc
->sc_kref
.refcount
),
320 NIPQUAD(saddr
), inet
? ntohs(sport
) : 0,
321 NIPQUAD(daddr
), inet
? ntohs(dport
) : 0,
322 sc
->sc_node
->nd_name
,
325 TV_SEC_USEC(sc
->sc_tv_timer
),
326 TV_SEC_USEC(sc
->sc_tv_data_ready
),
327 TV_SEC_USEC(sc
->sc_tv_advance_start
),
328 TV_SEC_USEC(sc
->sc_tv_advance_stop
),
329 TV_SEC_USEC(sc
->sc_tv_func_start
),
330 TV_SEC_USEC(sc
->sc_tv_func_stop
),
336 spin_unlock(&o2net_debug_lock
);
341 static void sc_seq_stop(struct seq_file
*seq
, void *v
)
345 static struct seq_operations sc_seq_ops
= {
346 .start
= sc_seq_start
,
352 static int sc_fop_open(struct inode
*inode
, struct file
*file
)
354 struct o2net_sock_container
*dummy_sc
;
355 struct seq_file
*seq
;
358 dummy_sc
= kmalloc(sizeof(struct o2net_sock_container
), GFP_KERNEL
);
359 if (dummy_sc
== NULL
) {
363 dummy_sc
->sc_page
= NULL
;
365 ret
= seq_open(file
, &sc_seq_ops
);
369 seq
= file
->private_data
;
370 seq
->private = dummy_sc
;
371 o2net_debug_add_sc(dummy_sc
);
380 static int sc_fop_release(struct inode
*inode
, struct file
*file
)
382 struct seq_file
*seq
= file
->private_data
;
383 struct o2net_sock_container
*dummy_sc
= seq
->private;
385 o2net_debug_del_sc(dummy_sc
);
386 return seq_release_private(inode
, file
);
389 static struct file_operations sc_seq_fops
= {
393 .release
= sc_fop_release
,
396 int o2net_debugfs_init(void)
398 o2net_dentry
= debugfs_create_dir(O2NET_DEBUG_DIR
, NULL
);
404 nst_dentry
= debugfs_create_file(NST_DEBUG_NAME
, S_IFREG
|S_IRUSR
,
412 sc_dentry
= debugfs_create_file(SC_DEBUG_NAME
, S_IFREG
|S_IRUSR
,
423 debugfs_remove(sc_dentry
);
425 debugfs_remove(nst_dentry
);
427 debugfs_remove(o2net_dentry
);
431 void o2net_debugfs_exit(void)
434 debugfs_remove(sc_dentry
);
436 debugfs_remove(nst_dentry
);
438 debugfs_remove(o2net_dentry
);
441 #endif /* CONFIG_DEBUG_FS */