12309e9e0SSunil Mushran /* -*- mode: c; c-basic-offset: 8; -*- 22309e9e0SSunil Mushran * vim: noexpandtab sw=8 ts=8 sts=0: 32309e9e0SSunil Mushran * 42309e9e0SSunil Mushran * netdebug.c 52309e9e0SSunil Mushran * 62309e9e0SSunil Mushran * debug functionality for o2net 72309e9e0SSunil Mushran * 82309e9e0SSunil Mushran * Copyright (C) 2005, 2008 Oracle. All rights reserved. 92309e9e0SSunil Mushran * 102309e9e0SSunil Mushran * This program is free software; you can redistribute it and/or 112309e9e0SSunil Mushran * modify it under the terms of the GNU General Public 122309e9e0SSunil Mushran * License as published by the Free Software Foundation; either 132309e9e0SSunil Mushran * version 2 of the License, or (at your option) any later version. 142309e9e0SSunil Mushran * 152309e9e0SSunil Mushran * This program is distributed in the hope that it will be useful, 162309e9e0SSunil Mushran * but WITHOUT ANY WARRANTY; without even the implied warranty of 172309e9e0SSunil Mushran * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 182309e9e0SSunil Mushran * General Public License for more details. 192309e9e0SSunil Mushran * 202309e9e0SSunil Mushran * You should have received a copy of the GNU General Public 212309e9e0SSunil Mushran * License along with this program; if not, write to the 222309e9e0SSunil Mushran * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 232309e9e0SSunil Mushran * Boston, MA 021110-1307, USA. 242309e9e0SSunil Mushran * 252309e9e0SSunil Mushran */ 262309e9e0SSunil Mushran 272309e9e0SSunil Mushran #ifdef CONFIG_DEBUG_FS 282309e9e0SSunil Mushran 292309e9e0SSunil Mushran #include <linux/module.h> 302309e9e0SSunil Mushran #include <linux/types.h> 312309e9e0SSunil Mushran #include <linux/slab.h> 322309e9e0SSunil Mushran #include <linux/idr.h> 332309e9e0SSunil Mushran #include <linux/kref.h> 342309e9e0SSunil Mushran #include <linux/seq_file.h> 352309e9e0SSunil Mushran #include <linux/debugfs.h> 362309e9e0SSunil Mushran 372309e9e0SSunil Mushran #include <linux/uaccess.h> 382309e9e0SSunil Mushran 392309e9e0SSunil Mushran #include "tcp.h" 402309e9e0SSunil Mushran #include "nodemanager.h" 412309e9e0SSunil Mushran #define MLOG_MASK_PREFIX ML_TCP 422309e9e0SSunil Mushran #include "masklog.h" 432309e9e0SSunil Mushran 442309e9e0SSunil Mushran #include "tcp_internal.h" 452309e9e0SSunil Mushran 462309e9e0SSunil Mushran #define O2NET_DEBUG_DIR "o2net" 472309e9e0SSunil Mushran #define SC_DEBUG_NAME "sock_containers" 482309e9e0SSunil Mushran #define NST_DEBUG_NAME "send_tracking" 49db02754cSSunil Mushran #define STATS_DEBUG_NAME "stats" 50*3ba169ccSSunil Mushran #define NODES_DEBUG_NAME "connected_nodes" 51db02754cSSunil Mushran 52db02754cSSunil Mushran #define SHOW_SOCK_CONTAINERS 0 53db02754cSSunil Mushran #define SHOW_SOCK_STATS 1 542309e9e0SSunil Mushran 552309e9e0SSunil Mushran static struct dentry *o2net_dentry; 562309e9e0SSunil Mushran static struct dentry *sc_dentry; 572309e9e0SSunil Mushran static struct dentry *nst_dentry; 58db02754cSSunil Mushran static struct dentry *stats_dentry; 59*3ba169ccSSunil Mushran static struct dentry *nodes_dentry; 602309e9e0SSunil Mushran 612309e9e0SSunil Mushran static DEFINE_SPINLOCK(o2net_debug_lock); 622309e9e0SSunil Mushran 632309e9e0SSunil Mushran static LIST_HEAD(sock_containers); 642309e9e0SSunil Mushran static LIST_HEAD(send_tracking); 652309e9e0SSunil Mushran 662309e9e0SSunil Mushran void o2net_debug_add_nst(struct o2net_send_tracking *nst) 672309e9e0SSunil Mushran { 682309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 692309e9e0SSunil Mushran list_add(&nst->st_net_debug_item, &send_tracking); 702309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 712309e9e0SSunil Mushran } 722309e9e0SSunil Mushran 732309e9e0SSunil Mushran void o2net_debug_del_nst(struct o2net_send_tracking *nst) 742309e9e0SSunil Mushran { 752309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 762309e9e0SSunil Mushran if (!list_empty(&nst->st_net_debug_item)) 772309e9e0SSunil Mushran list_del_init(&nst->st_net_debug_item); 782309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 792309e9e0SSunil Mushran } 802309e9e0SSunil Mushran 812309e9e0SSunil Mushran static struct o2net_send_tracking 822309e9e0SSunil Mushran *next_nst(struct o2net_send_tracking *nst_start) 832309e9e0SSunil Mushran { 842309e9e0SSunil Mushran struct o2net_send_tracking *nst, *ret = NULL; 852309e9e0SSunil Mushran 862309e9e0SSunil Mushran assert_spin_locked(&o2net_debug_lock); 872309e9e0SSunil Mushran 882309e9e0SSunil Mushran list_for_each_entry(nst, &nst_start->st_net_debug_item, 892309e9e0SSunil Mushran st_net_debug_item) { 902309e9e0SSunil Mushran /* discover the head of the list */ 912309e9e0SSunil Mushran if (&nst->st_net_debug_item == &send_tracking) 922309e9e0SSunil Mushran break; 932309e9e0SSunil Mushran 942309e9e0SSunil Mushran /* use st_task to detect real nsts in the list */ 952309e9e0SSunil Mushran if (nst->st_task != NULL) { 962309e9e0SSunil Mushran ret = nst; 972309e9e0SSunil Mushran break; 982309e9e0SSunil Mushran } 992309e9e0SSunil Mushran } 1002309e9e0SSunil Mushran 1012309e9e0SSunil Mushran return ret; 1022309e9e0SSunil Mushran } 1032309e9e0SSunil Mushran 1042309e9e0SSunil Mushran static void *nst_seq_start(struct seq_file *seq, loff_t *pos) 1052309e9e0SSunil Mushran { 1062309e9e0SSunil Mushran struct o2net_send_tracking *nst, *dummy_nst = seq->private; 1072309e9e0SSunil Mushran 1082309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 1092309e9e0SSunil Mushran nst = next_nst(dummy_nst); 1102309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 1112309e9e0SSunil Mushran 1122309e9e0SSunil Mushran return nst; 1132309e9e0SSunil Mushran } 1142309e9e0SSunil Mushran 1152309e9e0SSunil Mushran static void *nst_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1162309e9e0SSunil Mushran { 1172309e9e0SSunil Mushran struct o2net_send_tracking *nst, *dummy_nst = seq->private; 1182309e9e0SSunil Mushran 1192309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 1202309e9e0SSunil Mushran nst = next_nst(dummy_nst); 1212309e9e0SSunil Mushran list_del_init(&dummy_nst->st_net_debug_item); 1222309e9e0SSunil Mushran if (nst) 1232309e9e0SSunil Mushran list_add(&dummy_nst->st_net_debug_item, 1242309e9e0SSunil Mushran &nst->st_net_debug_item); 1252309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 1262309e9e0SSunil Mushran 1272309e9e0SSunil Mushran return nst; /* unused, just needs to be null when done */ 1282309e9e0SSunil Mushran } 1292309e9e0SSunil Mushran 1302309e9e0SSunil Mushran static int nst_seq_show(struct seq_file *seq, void *v) 1312309e9e0SSunil Mushran { 1322309e9e0SSunil Mushran struct o2net_send_tracking *nst, *dummy_nst = seq->private; 1333f9c14faSSunil Mushran ktime_t now; 1343f9c14faSSunil Mushran s64 sock, send, status; 1352309e9e0SSunil Mushran 1362309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 1372309e9e0SSunil Mushran nst = next_nst(dummy_nst); 138cc548166SDan Carpenter if (!nst) 139cc548166SDan Carpenter goto out; 1402309e9e0SSunil Mushran 1413f9c14faSSunil Mushran now = ktime_get(); 1423f9c14faSSunil Mushran sock = ktime_to_us(ktime_sub(now, nst->st_sock_time)); 1433f9c14faSSunil Mushran send = ktime_to_us(ktime_sub(now, nst->st_send_time)); 1443f9c14faSSunil Mushran status = ktime_to_us(ktime_sub(now, nst->st_status_time)); 1453f9c14faSSunil Mushran 1462309e9e0SSunil Mushran /* get_task_comm isn't exported. oh well. */ 1472309e9e0SSunil Mushran seq_printf(seq, "%p:\n" 1482309e9e0SSunil Mushran " pid: %lu\n" 1492309e9e0SSunil Mushran " tgid: %lu\n" 1502309e9e0SSunil Mushran " process name: %s\n" 1512309e9e0SSunil Mushran " node: %u\n" 1522309e9e0SSunil Mushran " sc: %p\n" 1532309e9e0SSunil Mushran " message id: %d\n" 1542309e9e0SSunil Mushran " message type: %u\n" 1552309e9e0SSunil Mushran " message key: 0x%08x\n" 1563f9c14faSSunil Mushran " sock acquiry: %lld usecs ago\n" 1573f9c14faSSunil Mushran " send start: %lld usecs ago\n" 1583f9c14faSSunil Mushran " wait start: %lld usecs ago\n", 15937096a79SSunil Mushran nst, (unsigned long)task_pid_nr(nst->st_task), 1602309e9e0SSunil Mushran (unsigned long)nst->st_task->tgid, 1612309e9e0SSunil Mushran nst->st_task->comm, nst->st_node, 1622309e9e0SSunil Mushran nst->st_sc, nst->st_id, nst->st_msg_type, 1632309e9e0SSunil Mushran nst->st_msg_key, 1643f9c14faSSunil Mushran (long long)sock, 1653f9c14faSSunil Mushran (long long)send, 1663f9c14faSSunil Mushran (long long)status); 1672309e9e0SSunil Mushran 168cc548166SDan Carpenter out: 1692309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 1702309e9e0SSunil Mushran 1712309e9e0SSunil Mushran return 0; 1722309e9e0SSunil Mushran } 1732309e9e0SSunil Mushran 1742309e9e0SSunil Mushran static void nst_seq_stop(struct seq_file *seq, void *v) 1752309e9e0SSunil Mushran { 1762309e9e0SSunil Mushran } 1772309e9e0SSunil Mushran 17888e9d34cSJames Morris static const struct seq_operations nst_seq_ops = { 1792309e9e0SSunil Mushran .start = nst_seq_start, 1802309e9e0SSunil Mushran .next = nst_seq_next, 1812309e9e0SSunil Mushran .stop = nst_seq_stop, 1822309e9e0SSunil Mushran .show = nst_seq_show, 1832309e9e0SSunil Mushran }; 1842309e9e0SSunil Mushran 1852309e9e0SSunil Mushran static int nst_fop_open(struct inode *inode, struct file *file) 1862309e9e0SSunil Mushran { 1872309e9e0SSunil Mushran struct o2net_send_tracking *dummy_nst; 1882309e9e0SSunil Mushran struct seq_file *seq; 1892309e9e0SSunil Mushran int ret; 1902309e9e0SSunil Mushran 1912309e9e0SSunil Mushran dummy_nst = kmalloc(sizeof(struct o2net_send_tracking), GFP_KERNEL); 1922309e9e0SSunil Mushran if (dummy_nst == NULL) { 1932309e9e0SSunil Mushran ret = -ENOMEM; 1942309e9e0SSunil Mushran goto out; 1952309e9e0SSunil Mushran } 1962309e9e0SSunil Mushran dummy_nst->st_task = NULL; 1972309e9e0SSunil Mushran 1982309e9e0SSunil Mushran ret = seq_open(file, &nst_seq_ops); 1992309e9e0SSunil Mushran if (ret) 2002309e9e0SSunil Mushran goto out; 2012309e9e0SSunil Mushran 2022309e9e0SSunil Mushran seq = file->private_data; 2032309e9e0SSunil Mushran seq->private = dummy_nst; 2042309e9e0SSunil Mushran o2net_debug_add_nst(dummy_nst); 2052309e9e0SSunil Mushran 2062309e9e0SSunil Mushran dummy_nst = NULL; 2072309e9e0SSunil Mushran 2082309e9e0SSunil Mushran out: 2092309e9e0SSunil Mushran kfree(dummy_nst); 2102309e9e0SSunil Mushran return ret; 2112309e9e0SSunil Mushran } 2122309e9e0SSunil Mushran 2132309e9e0SSunil Mushran static int nst_fop_release(struct inode *inode, struct file *file) 2142309e9e0SSunil Mushran { 2152309e9e0SSunil Mushran struct seq_file *seq = file->private_data; 2162309e9e0SSunil Mushran struct o2net_send_tracking *dummy_nst = seq->private; 2172309e9e0SSunil Mushran 2182309e9e0SSunil Mushran o2net_debug_del_nst(dummy_nst); 2192309e9e0SSunil Mushran return seq_release_private(inode, file); 2202309e9e0SSunil Mushran } 2212309e9e0SSunil Mushran 222828c0950SAlexey Dobriyan static const struct file_operations nst_seq_fops = { 2232309e9e0SSunil Mushran .open = nst_fop_open, 2242309e9e0SSunil Mushran .read = seq_read, 2252309e9e0SSunil Mushran .llseek = seq_lseek, 2262309e9e0SSunil Mushran .release = nst_fop_release, 2272309e9e0SSunil Mushran }; 2282309e9e0SSunil Mushran 2292309e9e0SSunil Mushran void o2net_debug_add_sc(struct o2net_sock_container *sc) 2302309e9e0SSunil Mushran { 2312309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2322309e9e0SSunil Mushran list_add(&sc->sc_net_debug_item, &sock_containers); 2332309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2342309e9e0SSunil Mushran } 2352309e9e0SSunil Mushran 2362309e9e0SSunil Mushran void o2net_debug_del_sc(struct o2net_sock_container *sc) 2372309e9e0SSunil Mushran { 2382309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2392309e9e0SSunil Mushran list_del_init(&sc->sc_net_debug_item); 2402309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2412309e9e0SSunil Mushran } 2422309e9e0SSunil Mushran 243db02754cSSunil Mushran struct o2net_sock_debug { 244db02754cSSunil Mushran int dbg_ctxt; 245db02754cSSunil Mushran struct o2net_sock_container *dbg_sock; 246db02754cSSunil Mushran }; 247db02754cSSunil Mushran 2482309e9e0SSunil Mushran static struct o2net_sock_container 2492309e9e0SSunil Mushran *next_sc(struct o2net_sock_container *sc_start) 2502309e9e0SSunil Mushran { 2512309e9e0SSunil Mushran struct o2net_sock_container *sc, *ret = NULL; 2522309e9e0SSunil Mushran 2532309e9e0SSunil Mushran assert_spin_locked(&o2net_debug_lock); 2542309e9e0SSunil Mushran 2552309e9e0SSunil Mushran list_for_each_entry(sc, &sc_start->sc_net_debug_item, 2562309e9e0SSunil Mushran sc_net_debug_item) { 2572309e9e0SSunil Mushran /* discover the head of the list miscast as a sc */ 2582309e9e0SSunil Mushran if (&sc->sc_net_debug_item == &sock_containers) 2592309e9e0SSunil Mushran break; 2602309e9e0SSunil Mushran 2612309e9e0SSunil Mushran /* use sc_page to detect real scs in the list */ 2622309e9e0SSunil Mushran if (sc->sc_page != NULL) { 2632309e9e0SSunil Mushran ret = sc; 2642309e9e0SSunil Mushran break; 2652309e9e0SSunil Mushran } 2662309e9e0SSunil Mushran } 2672309e9e0SSunil Mushran 2682309e9e0SSunil Mushran return ret; 2692309e9e0SSunil Mushran } 2702309e9e0SSunil Mushran 2712309e9e0SSunil Mushran static void *sc_seq_start(struct seq_file *seq, loff_t *pos) 2722309e9e0SSunil Mushran { 273db02754cSSunil Mushran struct o2net_sock_debug *sd = seq->private; 274db02754cSSunil Mushran struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock; 2752309e9e0SSunil Mushran 2762309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2772309e9e0SSunil Mushran sc = next_sc(dummy_sc); 2782309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2792309e9e0SSunil Mushran 2802309e9e0SSunil Mushran return sc; 2812309e9e0SSunil Mushran } 2822309e9e0SSunil Mushran 2832309e9e0SSunil Mushran static void *sc_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2842309e9e0SSunil Mushran { 285db02754cSSunil Mushran struct o2net_sock_debug *sd = seq->private; 286db02754cSSunil Mushran struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock; 2872309e9e0SSunil Mushran 2882309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2892309e9e0SSunil Mushran sc = next_sc(dummy_sc); 2902309e9e0SSunil Mushran list_del_init(&dummy_sc->sc_net_debug_item); 2912309e9e0SSunil Mushran if (sc) 2922309e9e0SSunil Mushran list_add(&dummy_sc->sc_net_debug_item, &sc->sc_net_debug_item); 2932309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2942309e9e0SSunil Mushran 2952309e9e0SSunil Mushran return sc; /* unused, just needs to be null when done */ 2962309e9e0SSunil Mushran } 2972309e9e0SSunil Mushran 298db02754cSSunil Mushran #ifdef CONFIG_OCFS2_FS_STATS 299db02754cSSunil Mushran # define sc_send_count(_s) ((_s)->sc_send_count) 300db02754cSSunil Mushran # define sc_recv_count(_s) ((_s)->sc_recv_count) 301db02754cSSunil Mushran # define sc_tv_acquiry_total_ns(_s) (ktime_to_ns((_s)->sc_tv_acquiry_total)) 302db02754cSSunil Mushran # define sc_tv_send_total_ns(_s) (ktime_to_ns((_s)->sc_tv_send_total)) 303db02754cSSunil Mushran # define sc_tv_status_total_ns(_s) (ktime_to_ns((_s)->sc_tv_status_total)) 304db02754cSSunil Mushran # define sc_tv_process_total_ns(_s) (ktime_to_ns((_s)->sc_tv_process_total)) 305db02754cSSunil Mushran #else 306db02754cSSunil Mushran # define sc_send_count(_s) (0U) 307db02754cSSunil Mushran # define sc_recv_count(_s) (0U) 308db02754cSSunil Mushran # define sc_tv_acquiry_total_ns(_s) (0LL) 309db02754cSSunil Mushran # define sc_tv_send_total_ns(_s) (0LL) 310db02754cSSunil Mushran # define sc_tv_status_total_ns(_s) (0LL) 311db02754cSSunil Mushran # define sc_tv_process_total_ns(_s) (0LL) 312db02754cSSunil Mushran #endif 313db02754cSSunil Mushran 314db02754cSSunil Mushran /* So that debugfs.ocfs2 can determine which format is being used */ 315db02754cSSunil Mushran #define O2NET_STATS_STR_VERSION 1 316db02754cSSunil Mushran static void sc_show_sock_stats(struct seq_file *seq, 317db02754cSSunil Mushran struct o2net_sock_container *sc) 3182309e9e0SSunil Mushran { 319db02754cSSunil Mushran if (!sc) 320db02754cSSunil Mushran return; 3212309e9e0SSunil Mushran 322db02754cSSunil Mushran seq_printf(seq, "%d,%u,%lu,%lld,%lld,%lld,%lu,%lld\n", O2NET_STATS_STR_VERSION, 323db02754cSSunil Mushran sc->sc_node->nd_num, (unsigned long)sc_send_count(sc), 324db02754cSSunil Mushran (long long)sc_tv_acquiry_total_ns(sc), 325db02754cSSunil Mushran (long long)sc_tv_send_total_ns(sc), 326db02754cSSunil Mushran (long long)sc_tv_status_total_ns(sc), 327db02754cSSunil Mushran (unsigned long)sc_recv_count(sc), 328db02754cSSunil Mushran (long long)sc_tv_process_total_ns(sc)); 329db02754cSSunil Mushran } 3302309e9e0SSunil Mushran 331db02754cSSunil Mushran static void sc_show_sock_container(struct seq_file *seq, 332db02754cSSunil Mushran struct o2net_sock_container *sc) 333db02754cSSunil Mushran { 3342309e9e0SSunil Mushran struct inet_sock *inet = NULL; 3352309e9e0SSunil Mushran __be32 saddr = 0, daddr = 0; 3362309e9e0SSunil Mushran __be16 sport = 0, dport = 0; 3372309e9e0SSunil Mushran 338db02754cSSunil Mushran if (!sc) 339db02754cSSunil Mushran return; 340db02754cSSunil Mushran 3412309e9e0SSunil Mushran if (sc->sc_sock) { 3422309e9e0SSunil Mushran inet = inet_sk(sc->sc_sock->sk); 3432309e9e0SSunil Mushran /* the stack's structs aren't sparse endian clean */ 344c720c7e8SEric Dumazet saddr = (__force __be32)inet->inet_saddr; 345c720c7e8SEric Dumazet daddr = (__force __be32)inet->inet_daddr; 346c720c7e8SEric Dumazet sport = (__force __be16)inet->inet_sport; 347c720c7e8SEric Dumazet dport = (__force __be16)inet->inet_dport; 3482309e9e0SSunil Mushran } 3492309e9e0SSunil Mushran 3502309e9e0SSunil Mushran /* XXX sigh, inet-> doesn't have sparse annotation so any 3512309e9e0SSunil Mushran * use of it here generates a warning with -Wbitwise */ 3522309e9e0SSunil Mushran seq_printf(seq, "%p:\n" 3532309e9e0SSunil Mushran " krefs: %d\n" 354be859405SHarvey Harrison " sock: %pI4:%u -> " 355be859405SHarvey Harrison "%pI4:%u\n" 3562309e9e0SSunil Mushran " remote node: %s\n" 3572309e9e0SSunil Mushran " page off: %zu\n" 3582309e9e0SSunil Mushran " handshake ok: %u\n" 359ff1becbfSSunil Mushran " timer: %lld usecs\n" 360ff1becbfSSunil Mushran " data ready: %lld usecs\n" 361ff1becbfSSunil Mushran " advance start: %lld usecs\n" 362ff1becbfSSunil Mushran " advance stop: %lld usecs\n" 363ff1becbfSSunil Mushran " func start: %lld usecs\n" 364ff1becbfSSunil Mushran " func stop: %lld usecs\n" 365ff1becbfSSunil Mushran " func key: 0x%08x\n" 3662309e9e0SSunil Mushran " func type: %u\n", 3672309e9e0SSunil Mushran sc, 3682309e9e0SSunil Mushran atomic_read(&sc->sc_kref.refcount), 369be859405SHarvey Harrison &saddr, inet ? ntohs(sport) : 0, 370be859405SHarvey Harrison &daddr, inet ? ntohs(dport) : 0, 3712309e9e0SSunil Mushran sc->sc_node->nd_name, 3722309e9e0SSunil Mushran sc->sc_page_off, 3732309e9e0SSunil Mushran sc->sc_handshake_ok, 374ff1becbfSSunil Mushran (long long)ktime_to_us(sc->sc_tv_timer), 375ff1becbfSSunil Mushran (long long)ktime_to_us(sc->sc_tv_data_ready), 376ff1becbfSSunil Mushran (long long)ktime_to_us(sc->sc_tv_advance_start), 377ff1becbfSSunil Mushran (long long)ktime_to_us(sc->sc_tv_advance_stop), 378ff1becbfSSunil Mushran (long long)ktime_to_us(sc->sc_tv_func_start), 379ff1becbfSSunil Mushran (long long)ktime_to_us(sc->sc_tv_func_stop), 3802309e9e0SSunil Mushran sc->sc_msg_key, 3812309e9e0SSunil Mushran sc->sc_msg_type); 3822309e9e0SSunil Mushran } 3832309e9e0SSunil Mushran 384db02754cSSunil Mushran static int sc_seq_show(struct seq_file *seq, void *v) 385db02754cSSunil Mushran { 386db02754cSSunil Mushran struct o2net_sock_debug *sd = seq->private; 387db02754cSSunil Mushran struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock; 388db02754cSSunil Mushran 389db02754cSSunil Mushran spin_lock(&o2net_debug_lock); 390db02754cSSunil Mushran sc = next_sc(dummy_sc); 391db02754cSSunil Mushran 392db02754cSSunil Mushran if (sc) { 393db02754cSSunil Mushran if (sd->dbg_ctxt == SHOW_SOCK_CONTAINERS) 394db02754cSSunil Mushran sc_show_sock_container(seq, sc); 395db02754cSSunil Mushran else 396db02754cSSunil Mushran sc_show_sock_stats(seq, sc); 397db02754cSSunil Mushran } 3982309e9e0SSunil Mushran 3992309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 4002309e9e0SSunil Mushran 4012309e9e0SSunil Mushran return 0; 4022309e9e0SSunil Mushran } 4032309e9e0SSunil Mushran 4042309e9e0SSunil Mushran static void sc_seq_stop(struct seq_file *seq, void *v) 4052309e9e0SSunil Mushran { 4062309e9e0SSunil Mushran } 4072309e9e0SSunil Mushran 40888e9d34cSJames Morris static const struct seq_operations sc_seq_ops = { 4092309e9e0SSunil Mushran .start = sc_seq_start, 4102309e9e0SSunil Mushran .next = sc_seq_next, 4112309e9e0SSunil Mushran .stop = sc_seq_stop, 4122309e9e0SSunil Mushran .show = sc_seq_show, 4132309e9e0SSunil Mushran }; 4142309e9e0SSunil Mushran 415db02754cSSunil Mushran static int sc_common_open(struct file *file, struct o2net_sock_debug *sd) 4162309e9e0SSunil Mushran { 4172309e9e0SSunil Mushran struct o2net_sock_container *dummy_sc; 4182309e9e0SSunil Mushran struct seq_file *seq; 4192309e9e0SSunil Mushran int ret; 4202309e9e0SSunil Mushran 4212309e9e0SSunil Mushran dummy_sc = kmalloc(sizeof(struct o2net_sock_container), GFP_KERNEL); 4222309e9e0SSunil Mushran if (dummy_sc == NULL) { 4232309e9e0SSunil Mushran ret = -ENOMEM; 4242309e9e0SSunil Mushran goto out; 4252309e9e0SSunil Mushran } 4262309e9e0SSunil Mushran dummy_sc->sc_page = NULL; 4272309e9e0SSunil Mushran 4282309e9e0SSunil Mushran ret = seq_open(file, &sc_seq_ops); 4292309e9e0SSunil Mushran if (ret) 4302309e9e0SSunil Mushran goto out; 4312309e9e0SSunil Mushran 4322309e9e0SSunil Mushran seq = file->private_data; 433db02754cSSunil Mushran seq->private = sd; 434db02754cSSunil Mushran sd->dbg_sock = dummy_sc; 4352309e9e0SSunil Mushran o2net_debug_add_sc(dummy_sc); 4362309e9e0SSunil Mushran 4372309e9e0SSunil Mushran dummy_sc = NULL; 4382309e9e0SSunil Mushran 4392309e9e0SSunil Mushran out: 4402309e9e0SSunil Mushran kfree(dummy_sc); 4412309e9e0SSunil Mushran return ret; 4422309e9e0SSunil Mushran } 4432309e9e0SSunil Mushran 4442309e9e0SSunil Mushran static int sc_fop_release(struct inode *inode, struct file *file) 4452309e9e0SSunil Mushran { 4462309e9e0SSunil Mushran struct seq_file *seq = file->private_data; 447db02754cSSunil Mushran struct o2net_sock_debug *sd = seq->private; 448db02754cSSunil Mushran struct o2net_sock_container *dummy_sc = sd->dbg_sock; 4492309e9e0SSunil Mushran 4502309e9e0SSunil Mushran o2net_debug_del_sc(dummy_sc); 4512309e9e0SSunil Mushran return seq_release_private(inode, file); 4522309e9e0SSunil Mushran } 4532309e9e0SSunil Mushran 454db02754cSSunil Mushran static int stats_fop_open(struct inode *inode, struct file *file) 455db02754cSSunil Mushran { 456db02754cSSunil Mushran struct o2net_sock_debug *sd; 457db02754cSSunil Mushran 458db02754cSSunil Mushran sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL); 459db02754cSSunil Mushran if (sd == NULL) 460db02754cSSunil Mushran return -ENOMEM; 461db02754cSSunil Mushran 462db02754cSSunil Mushran sd->dbg_ctxt = SHOW_SOCK_STATS; 463db02754cSSunil Mushran sd->dbg_sock = NULL; 464db02754cSSunil Mushran 465db02754cSSunil Mushran return sc_common_open(file, sd); 466db02754cSSunil Mushran } 467db02754cSSunil Mushran 468db02754cSSunil Mushran static const struct file_operations stats_seq_fops = { 469db02754cSSunil Mushran .open = stats_fop_open, 470db02754cSSunil Mushran .read = seq_read, 471db02754cSSunil Mushran .llseek = seq_lseek, 472db02754cSSunil Mushran .release = sc_fop_release, 473db02754cSSunil Mushran }; 474db02754cSSunil Mushran 475db02754cSSunil Mushran static int sc_fop_open(struct inode *inode, struct file *file) 476db02754cSSunil Mushran { 477db02754cSSunil Mushran struct o2net_sock_debug *sd; 478db02754cSSunil Mushran 479db02754cSSunil Mushran sd = kmalloc(sizeof(struct o2net_sock_debug), GFP_KERNEL); 480db02754cSSunil Mushran if (sd == NULL) 481db02754cSSunil Mushran return -ENOMEM; 482db02754cSSunil Mushran 483db02754cSSunil Mushran sd->dbg_ctxt = SHOW_SOCK_CONTAINERS; 484db02754cSSunil Mushran sd->dbg_sock = NULL; 485db02754cSSunil Mushran 486db02754cSSunil Mushran return sc_common_open(file, sd); 487db02754cSSunil Mushran } 488db02754cSSunil Mushran 489828c0950SAlexey Dobriyan static const struct file_operations sc_seq_fops = { 4902309e9e0SSunil Mushran .open = sc_fop_open, 4912309e9e0SSunil Mushran .read = seq_read, 4922309e9e0SSunil Mushran .llseek = seq_lseek, 4932309e9e0SSunil Mushran .release = sc_fop_release, 4942309e9e0SSunil Mushran }; 4952309e9e0SSunil Mushran 496*3ba169ccSSunil Mushran static int o2net_fill_bitmap(char *buf, int len) 4972309e9e0SSunil Mushran { 498*3ba169ccSSunil Mushran unsigned long map[BITS_TO_LONGS(O2NM_MAX_NODES)]; 499*3ba169ccSSunil Mushran int i = -1, out = 0; 500*3ba169ccSSunil Mushran 501*3ba169ccSSunil Mushran o2net_fill_node_map(map, sizeof(map)); 502*3ba169ccSSunil Mushran 503*3ba169ccSSunil Mushran while ((i = find_next_bit(map, O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) 504*3ba169ccSSunil Mushran out += snprintf(buf + out, PAGE_SIZE - out, "%d ", i); 505*3ba169ccSSunil Mushran out += snprintf(buf + out, PAGE_SIZE - out, "\n"); 506*3ba169ccSSunil Mushran 507*3ba169ccSSunil Mushran return out; 5082309e9e0SSunil Mushran } 5092309e9e0SSunil Mushran 510*3ba169ccSSunil Mushran static int nodes_fop_open(struct inode *inode, struct file *file) 511*3ba169ccSSunil Mushran { 512*3ba169ccSSunil Mushran char *buf; 5132309e9e0SSunil Mushran 514*3ba169ccSSunil Mushran buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 515*3ba169ccSSunil Mushran if (!buf) 516*3ba169ccSSunil Mushran return -ENOMEM; 5172309e9e0SSunil Mushran 518*3ba169ccSSunil Mushran i_size_write(inode, o2net_fill_bitmap(buf, PAGE_SIZE)); 519*3ba169ccSSunil Mushran 520*3ba169ccSSunil Mushran file->private_data = buf; 521db02754cSSunil Mushran 5222309e9e0SSunil Mushran return 0; 5232309e9e0SSunil Mushran } 5242309e9e0SSunil Mushran 525*3ba169ccSSunil Mushran static int o2net_debug_release(struct inode *inode, struct file *file) 526*3ba169ccSSunil Mushran { 527*3ba169ccSSunil Mushran kfree(file->private_data); 528*3ba169ccSSunil Mushran return 0; 529*3ba169ccSSunil Mushran } 530*3ba169ccSSunil Mushran 531*3ba169ccSSunil Mushran static ssize_t o2net_debug_read(struct file *file, char __user *buf, 532*3ba169ccSSunil Mushran size_t nbytes, loff_t *ppos) 533*3ba169ccSSunil Mushran { 534*3ba169ccSSunil Mushran return simple_read_from_buffer(buf, nbytes, ppos, file->private_data, 535*3ba169ccSSunil Mushran i_size_read(file->f_mapping->host)); 536*3ba169ccSSunil Mushran } 537*3ba169ccSSunil Mushran 538*3ba169ccSSunil Mushran static const struct file_operations nodes_fops = { 539*3ba169ccSSunil Mushran .open = nodes_fop_open, 540*3ba169ccSSunil Mushran .release = o2net_debug_release, 541*3ba169ccSSunil Mushran .read = o2net_debug_read, 542*3ba169ccSSunil Mushran .llseek = generic_file_llseek, 543*3ba169ccSSunil Mushran }; 544*3ba169ccSSunil Mushran 5452309e9e0SSunil Mushran void o2net_debugfs_exit(void) 5462309e9e0SSunil Mushran { 547*3ba169ccSSunil Mushran debugfs_remove(nodes_dentry); 548db02754cSSunil Mushran debugfs_remove(stats_dentry); 5492309e9e0SSunil Mushran debugfs_remove(sc_dentry); 5502309e9e0SSunil Mushran debugfs_remove(nst_dentry); 5512309e9e0SSunil Mushran debugfs_remove(o2net_dentry); 5522309e9e0SSunil Mushran } 5532309e9e0SSunil Mushran 554*3ba169ccSSunil Mushran int o2net_debugfs_init(void) 555*3ba169ccSSunil Mushran { 556*3ba169ccSSunil Mushran mode_t mode = S_IFREG|S_IRUSR; 557*3ba169ccSSunil Mushran 558*3ba169ccSSunil Mushran o2net_dentry = debugfs_create_dir(O2NET_DEBUG_DIR, NULL); 559*3ba169ccSSunil Mushran if (o2net_dentry) 560*3ba169ccSSunil Mushran nst_dentry = debugfs_create_file(NST_DEBUG_NAME, mode, 561*3ba169ccSSunil Mushran o2net_dentry, NULL, &nst_seq_fops); 562*3ba169ccSSunil Mushran if (nst_dentry) 563*3ba169ccSSunil Mushran sc_dentry = debugfs_create_file(SC_DEBUG_NAME, mode, 564*3ba169ccSSunil Mushran o2net_dentry, NULL, &sc_seq_fops); 565*3ba169ccSSunil Mushran if (sc_dentry) 566*3ba169ccSSunil Mushran stats_dentry = debugfs_create_file(STATS_DEBUG_NAME, mode, 567*3ba169ccSSunil Mushran o2net_dentry, NULL, &stats_seq_fops); 568*3ba169ccSSunil Mushran if (stats_dentry) 569*3ba169ccSSunil Mushran nodes_dentry = debugfs_create_file(NODES_DEBUG_NAME, mode, 570*3ba169ccSSunil Mushran o2net_dentry, NULL, &nodes_fops); 571*3ba169ccSSunil Mushran if (nodes_dentry) 572*3ba169ccSSunil Mushran return 0; 573*3ba169ccSSunil Mushran 574*3ba169ccSSunil Mushran o2net_debugfs_exit(); 575*3ba169ccSSunil Mushran mlog_errno(-ENOMEM); 576*3ba169ccSSunil Mushran return -ENOMEM; 577*3ba169ccSSunil Mushran } 578*3ba169ccSSunil Mushran 5792309e9e0SSunil Mushran #endif /* CONFIG_DEBUG_FS */ 580