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" 492309e9e0SSunil Mushran 502309e9e0SSunil Mushran static struct dentry *o2net_dentry; 512309e9e0SSunil Mushran static struct dentry *sc_dentry; 522309e9e0SSunil Mushran static struct dentry *nst_dentry; 532309e9e0SSunil Mushran 542309e9e0SSunil Mushran static DEFINE_SPINLOCK(o2net_debug_lock); 552309e9e0SSunil Mushran 562309e9e0SSunil Mushran static LIST_HEAD(sock_containers); 572309e9e0SSunil Mushran static LIST_HEAD(send_tracking); 582309e9e0SSunil Mushran 592309e9e0SSunil Mushran void o2net_debug_add_nst(struct o2net_send_tracking *nst) 602309e9e0SSunil Mushran { 612309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 622309e9e0SSunil Mushran list_add(&nst->st_net_debug_item, &send_tracking); 632309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 642309e9e0SSunil Mushran } 652309e9e0SSunil Mushran 662309e9e0SSunil Mushran void o2net_debug_del_nst(struct o2net_send_tracking *nst) 672309e9e0SSunil Mushran { 682309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 692309e9e0SSunil Mushran if (!list_empty(&nst->st_net_debug_item)) 702309e9e0SSunil Mushran list_del_init(&nst->st_net_debug_item); 712309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 722309e9e0SSunil Mushran } 732309e9e0SSunil Mushran 742309e9e0SSunil Mushran static struct o2net_send_tracking 752309e9e0SSunil Mushran *next_nst(struct o2net_send_tracking *nst_start) 762309e9e0SSunil Mushran { 772309e9e0SSunil Mushran struct o2net_send_tracking *nst, *ret = NULL; 782309e9e0SSunil Mushran 792309e9e0SSunil Mushran assert_spin_locked(&o2net_debug_lock); 802309e9e0SSunil Mushran 812309e9e0SSunil Mushran list_for_each_entry(nst, &nst_start->st_net_debug_item, 822309e9e0SSunil Mushran st_net_debug_item) { 832309e9e0SSunil Mushran /* discover the head of the list */ 842309e9e0SSunil Mushran if (&nst->st_net_debug_item == &send_tracking) 852309e9e0SSunil Mushran break; 862309e9e0SSunil Mushran 872309e9e0SSunil Mushran /* use st_task to detect real nsts in the list */ 882309e9e0SSunil Mushran if (nst->st_task != NULL) { 892309e9e0SSunil Mushran ret = nst; 902309e9e0SSunil Mushran break; 912309e9e0SSunil Mushran } 922309e9e0SSunil Mushran } 932309e9e0SSunil Mushran 942309e9e0SSunil Mushran return ret; 952309e9e0SSunil Mushran } 962309e9e0SSunil Mushran 972309e9e0SSunil Mushran static void *nst_seq_start(struct seq_file *seq, loff_t *pos) 982309e9e0SSunil Mushran { 992309e9e0SSunil Mushran struct o2net_send_tracking *nst, *dummy_nst = seq->private; 1002309e9e0SSunil Mushran 1012309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 1022309e9e0SSunil Mushran nst = next_nst(dummy_nst); 1032309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 1042309e9e0SSunil Mushran 1052309e9e0SSunil Mushran return nst; 1062309e9e0SSunil Mushran } 1072309e9e0SSunil Mushran 1082309e9e0SSunil Mushran static void *nst_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1092309e9e0SSunil Mushran { 1102309e9e0SSunil Mushran struct o2net_send_tracking *nst, *dummy_nst = seq->private; 1112309e9e0SSunil Mushran 1122309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 1132309e9e0SSunil Mushran nst = next_nst(dummy_nst); 1142309e9e0SSunil Mushran list_del_init(&dummy_nst->st_net_debug_item); 1152309e9e0SSunil Mushran if (nst) 1162309e9e0SSunil Mushran list_add(&dummy_nst->st_net_debug_item, 1172309e9e0SSunil Mushran &nst->st_net_debug_item); 1182309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 1192309e9e0SSunil Mushran 1202309e9e0SSunil Mushran return nst; /* unused, just needs to be null when done */ 1212309e9e0SSunil Mushran } 1222309e9e0SSunil Mushran 1232309e9e0SSunil Mushran static int nst_seq_show(struct seq_file *seq, void *v) 1242309e9e0SSunil Mushran { 1252309e9e0SSunil Mushran struct o2net_send_tracking *nst, *dummy_nst = seq->private; 1262309e9e0SSunil Mushran 1272309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 1282309e9e0SSunil Mushran nst = next_nst(dummy_nst); 1292309e9e0SSunil Mushran 1302309e9e0SSunil Mushran if (nst != NULL) { 1312309e9e0SSunil Mushran /* get_task_comm isn't exported. oh well. */ 1322309e9e0SSunil Mushran seq_printf(seq, "%p:\n" 1332309e9e0SSunil Mushran " pid: %lu\n" 1342309e9e0SSunil Mushran " tgid: %lu\n" 1352309e9e0SSunil Mushran " process name: %s\n" 1362309e9e0SSunil Mushran " node: %u\n" 1372309e9e0SSunil Mushran " sc: %p\n" 1382309e9e0SSunil Mushran " message id: %d\n" 1392309e9e0SSunil Mushran " message type: %u\n" 1402309e9e0SSunil Mushran " message key: 0x%08x\n" 141a57a874bSAlexander Beregalov " sock acquiry: %lu.%ld\n" 142a57a874bSAlexander Beregalov " send start: %lu.%ld\n" 143a57a874bSAlexander Beregalov " wait start: %lu.%ld\n", 144*37096a79SSunil Mushran nst, (unsigned long)task_pid_nr(nst->st_task), 1452309e9e0SSunil Mushran (unsigned long)nst->st_task->tgid, 1462309e9e0SSunil Mushran nst->st_task->comm, nst->st_node, 1472309e9e0SSunil Mushran nst->st_sc, nst->st_id, nst->st_msg_type, 1482309e9e0SSunil Mushran nst->st_msg_key, 149461c6a30SSunil Mushran nst->st_sock_time.tv_sec, 150a57a874bSAlexander Beregalov (long)nst->st_sock_time.tv_usec, 151461c6a30SSunil Mushran nst->st_send_time.tv_sec, 152a57a874bSAlexander Beregalov (long)nst->st_send_time.tv_usec, 1532309e9e0SSunil Mushran nst->st_status_time.tv_sec, 154a57a874bSAlexander Beregalov (long)nst->st_status_time.tv_usec); 1552309e9e0SSunil Mushran } 1562309e9e0SSunil Mushran 1572309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 1582309e9e0SSunil Mushran 1592309e9e0SSunil Mushran return 0; 1602309e9e0SSunil Mushran } 1612309e9e0SSunil Mushran 1622309e9e0SSunil Mushran static void nst_seq_stop(struct seq_file *seq, void *v) 1632309e9e0SSunil Mushran { 1642309e9e0SSunil Mushran } 1652309e9e0SSunil Mushran 16688e9d34cSJames Morris static const struct seq_operations nst_seq_ops = { 1672309e9e0SSunil Mushran .start = nst_seq_start, 1682309e9e0SSunil Mushran .next = nst_seq_next, 1692309e9e0SSunil Mushran .stop = nst_seq_stop, 1702309e9e0SSunil Mushran .show = nst_seq_show, 1712309e9e0SSunil Mushran }; 1722309e9e0SSunil Mushran 1732309e9e0SSunil Mushran static int nst_fop_open(struct inode *inode, struct file *file) 1742309e9e0SSunil Mushran { 1752309e9e0SSunil Mushran struct o2net_send_tracking *dummy_nst; 1762309e9e0SSunil Mushran struct seq_file *seq; 1772309e9e0SSunil Mushran int ret; 1782309e9e0SSunil Mushran 1792309e9e0SSunil Mushran dummy_nst = kmalloc(sizeof(struct o2net_send_tracking), GFP_KERNEL); 1802309e9e0SSunil Mushran if (dummy_nst == NULL) { 1812309e9e0SSunil Mushran ret = -ENOMEM; 1822309e9e0SSunil Mushran goto out; 1832309e9e0SSunil Mushran } 1842309e9e0SSunil Mushran dummy_nst->st_task = NULL; 1852309e9e0SSunil Mushran 1862309e9e0SSunil Mushran ret = seq_open(file, &nst_seq_ops); 1872309e9e0SSunil Mushran if (ret) 1882309e9e0SSunil Mushran goto out; 1892309e9e0SSunil Mushran 1902309e9e0SSunil Mushran seq = file->private_data; 1912309e9e0SSunil Mushran seq->private = dummy_nst; 1922309e9e0SSunil Mushran o2net_debug_add_nst(dummy_nst); 1932309e9e0SSunil Mushran 1942309e9e0SSunil Mushran dummy_nst = NULL; 1952309e9e0SSunil Mushran 1962309e9e0SSunil Mushran out: 1972309e9e0SSunil Mushran kfree(dummy_nst); 1982309e9e0SSunil Mushran return ret; 1992309e9e0SSunil Mushran } 2002309e9e0SSunil Mushran 2012309e9e0SSunil Mushran static int nst_fop_release(struct inode *inode, struct file *file) 2022309e9e0SSunil Mushran { 2032309e9e0SSunil Mushran struct seq_file *seq = file->private_data; 2042309e9e0SSunil Mushran struct o2net_send_tracking *dummy_nst = seq->private; 2052309e9e0SSunil Mushran 2062309e9e0SSunil Mushran o2net_debug_del_nst(dummy_nst); 2072309e9e0SSunil Mushran return seq_release_private(inode, file); 2082309e9e0SSunil Mushran } 2092309e9e0SSunil Mushran 210828c0950SAlexey Dobriyan static const struct file_operations nst_seq_fops = { 2112309e9e0SSunil Mushran .open = nst_fop_open, 2122309e9e0SSunil Mushran .read = seq_read, 2132309e9e0SSunil Mushran .llseek = seq_lseek, 2142309e9e0SSunil Mushran .release = nst_fop_release, 2152309e9e0SSunil Mushran }; 2162309e9e0SSunil Mushran 2172309e9e0SSunil Mushran void o2net_debug_add_sc(struct o2net_sock_container *sc) 2182309e9e0SSunil Mushran { 2192309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2202309e9e0SSunil Mushran list_add(&sc->sc_net_debug_item, &sock_containers); 2212309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2222309e9e0SSunil Mushran } 2232309e9e0SSunil Mushran 2242309e9e0SSunil Mushran void o2net_debug_del_sc(struct o2net_sock_container *sc) 2252309e9e0SSunil Mushran { 2262309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2272309e9e0SSunil Mushran list_del_init(&sc->sc_net_debug_item); 2282309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2292309e9e0SSunil Mushran } 2302309e9e0SSunil Mushran 2312309e9e0SSunil Mushran static struct o2net_sock_container 2322309e9e0SSunil Mushran *next_sc(struct o2net_sock_container *sc_start) 2332309e9e0SSunil Mushran { 2342309e9e0SSunil Mushran struct o2net_sock_container *sc, *ret = NULL; 2352309e9e0SSunil Mushran 2362309e9e0SSunil Mushran assert_spin_locked(&o2net_debug_lock); 2372309e9e0SSunil Mushran 2382309e9e0SSunil Mushran list_for_each_entry(sc, &sc_start->sc_net_debug_item, 2392309e9e0SSunil Mushran sc_net_debug_item) { 2402309e9e0SSunil Mushran /* discover the head of the list miscast as a sc */ 2412309e9e0SSunil Mushran if (&sc->sc_net_debug_item == &sock_containers) 2422309e9e0SSunil Mushran break; 2432309e9e0SSunil Mushran 2442309e9e0SSunil Mushran /* use sc_page to detect real scs in the list */ 2452309e9e0SSunil Mushran if (sc->sc_page != NULL) { 2462309e9e0SSunil Mushran ret = sc; 2472309e9e0SSunil Mushran break; 2482309e9e0SSunil Mushran } 2492309e9e0SSunil Mushran } 2502309e9e0SSunil Mushran 2512309e9e0SSunil Mushran return ret; 2522309e9e0SSunil Mushran } 2532309e9e0SSunil Mushran 2542309e9e0SSunil Mushran static void *sc_seq_start(struct seq_file *seq, loff_t *pos) 2552309e9e0SSunil Mushran { 2562309e9e0SSunil Mushran struct o2net_sock_container *sc, *dummy_sc = seq->private; 2572309e9e0SSunil Mushran 2582309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2592309e9e0SSunil Mushran sc = next_sc(dummy_sc); 2602309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2612309e9e0SSunil Mushran 2622309e9e0SSunil Mushran return sc; 2632309e9e0SSunil Mushran } 2642309e9e0SSunil Mushran 2652309e9e0SSunil Mushran static void *sc_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2662309e9e0SSunil Mushran { 2672309e9e0SSunil Mushran struct o2net_sock_container *sc, *dummy_sc = seq->private; 2682309e9e0SSunil Mushran 2692309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2702309e9e0SSunil Mushran sc = next_sc(dummy_sc); 2712309e9e0SSunil Mushran list_del_init(&dummy_sc->sc_net_debug_item); 2722309e9e0SSunil Mushran if (sc) 2732309e9e0SSunil Mushran list_add(&dummy_sc->sc_net_debug_item, &sc->sc_net_debug_item); 2742309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 2752309e9e0SSunil Mushran 2762309e9e0SSunil Mushran return sc; /* unused, just needs to be null when done */ 2772309e9e0SSunil Mushran } 2782309e9e0SSunil Mushran 279a57a874bSAlexander Beregalov #define TV_SEC_USEC(TV) TV.tv_sec, (long)TV.tv_usec 2802309e9e0SSunil Mushran 2812309e9e0SSunil Mushran static int sc_seq_show(struct seq_file *seq, void *v) 2822309e9e0SSunil Mushran { 2832309e9e0SSunil Mushran struct o2net_sock_container *sc, *dummy_sc = seq->private; 2842309e9e0SSunil Mushran 2852309e9e0SSunil Mushran spin_lock(&o2net_debug_lock); 2862309e9e0SSunil Mushran sc = next_sc(dummy_sc); 2872309e9e0SSunil Mushran 2882309e9e0SSunil Mushran if (sc != NULL) { 2892309e9e0SSunil Mushran struct inet_sock *inet = NULL; 2902309e9e0SSunil Mushran 2912309e9e0SSunil Mushran __be32 saddr = 0, daddr = 0; 2922309e9e0SSunil Mushran __be16 sport = 0, dport = 0; 2932309e9e0SSunil Mushran 2942309e9e0SSunil Mushran if (sc->sc_sock) { 2952309e9e0SSunil Mushran inet = inet_sk(sc->sc_sock->sk); 2962309e9e0SSunil Mushran /* the stack's structs aren't sparse endian clean */ 297c720c7e8SEric Dumazet saddr = (__force __be32)inet->inet_saddr; 298c720c7e8SEric Dumazet daddr = (__force __be32)inet->inet_daddr; 299c720c7e8SEric Dumazet sport = (__force __be16)inet->inet_sport; 300c720c7e8SEric Dumazet dport = (__force __be16)inet->inet_dport; 3012309e9e0SSunil Mushran } 3022309e9e0SSunil Mushran 3032309e9e0SSunil Mushran /* XXX sigh, inet-> doesn't have sparse annotation so any 3042309e9e0SSunil Mushran * use of it here generates a warning with -Wbitwise */ 3052309e9e0SSunil Mushran seq_printf(seq, "%p:\n" 3062309e9e0SSunil Mushran " krefs: %d\n" 307be859405SHarvey Harrison " sock: %pI4:%u -> " 308be859405SHarvey Harrison "%pI4:%u\n" 3092309e9e0SSunil Mushran " remote node: %s\n" 3102309e9e0SSunil Mushran " page off: %zu\n" 3112309e9e0SSunil Mushran " handshake ok: %u\n" 312a57a874bSAlexander Beregalov " timer: %lu.%ld\n" 313a57a874bSAlexander Beregalov " data ready: %lu.%ld\n" 314a57a874bSAlexander Beregalov " advance start: %lu.%ld\n" 315a57a874bSAlexander Beregalov " advance stop: %lu.%ld\n" 316a57a874bSAlexander Beregalov " func start: %lu.%ld\n" 317a57a874bSAlexander Beregalov " func stop: %lu.%ld\n" 3182309e9e0SSunil Mushran " func key: %u\n" 3192309e9e0SSunil Mushran " func type: %u\n", 3202309e9e0SSunil Mushran sc, 3212309e9e0SSunil Mushran atomic_read(&sc->sc_kref.refcount), 322be859405SHarvey Harrison &saddr, inet ? ntohs(sport) : 0, 323be859405SHarvey Harrison &daddr, inet ? ntohs(dport) : 0, 3242309e9e0SSunil Mushran sc->sc_node->nd_name, 3252309e9e0SSunil Mushran sc->sc_page_off, 3262309e9e0SSunil Mushran sc->sc_handshake_ok, 3272309e9e0SSunil Mushran TV_SEC_USEC(sc->sc_tv_timer), 3282309e9e0SSunil Mushran TV_SEC_USEC(sc->sc_tv_data_ready), 3292309e9e0SSunil Mushran TV_SEC_USEC(sc->sc_tv_advance_start), 3302309e9e0SSunil Mushran TV_SEC_USEC(sc->sc_tv_advance_stop), 3312309e9e0SSunil Mushran TV_SEC_USEC(sc->sc_tv_func_start), 3322309e9e0SSunil Mushran TV_SEC_USEC(sc->sc_tv_func_stop), 3332309e9e0SSunil Mushran sc->sc_msg_key, 3342309e9e0SSunil Mushran sc->sc_msg_type); 3352309e9e0SSunil Mushran } 3362309e9e0SSunil Mushran 3372309e9e0SSunil Mushran 3382309e9e0SSunil Mushran spin_unlock(&o2net_debug_lock); 3392309e9e0SSunil Mushran 3402309e9e0SSunil Mushran return 0; 3412309e9e0SSunil Mushran } 3422309e9e0SSunil Mushran 3432309e9e0SSunil Mushran static void sc_seq_stop(struct seq_file *seq, void *v) 3442309e9e0SSunil Mushran { 3452309e9e0SSunil Mushran } 3462309e9e0SSunil Mushran 34788e9d34cSJames Morris static const struct seq_operations sc_seq_ops = { 3482309e9e0SSunil Mushran .start = sc_seq_start, 3492309e9e0SSunil Mushran .next = sc_seq_next, 3502309e9e0SSunil Mushran .stop = sc_seq_stop, 3512309e9e0SSunil Mushran .show = sc_seq_show, 3522309e9e0SSunil Mushran }; 3532309e9e0SSunil Mushran 3542309e9e0SSunil Mushran static int sc_fop_open(struct inode *inode, struct file *file) 3552309e9e0SSunil Mushran { 3562309e9e0SSunil Mushran struct o2net_sock_container *dummy_sc; 3572309e9e0SSunil Mushran struct seq_file *seq; 3582309e9e0SSunil Mushran int ret; 3592309e9e0SSunil Mushran 3602309e9e0SSunil Mushran dummy_sc = kmalloc(sizeof(struct o2net_sock_container), GFP_KERNEL); 3612309e9e0SSunil Mushran if (dummy_sc == NULL) { 3622309e9e0SSunil Mushran ret = -ENOMEM; 3632309e9e0SSunil Mushran goto out; 3642309e9e0SSunil Mushran } 3652309e9e0SSunil Mushran dummy_sc->sc_page = NULL; 3662309e9e0SSunil Mushran 3672309e9e0SSunil Mushran ret = seq_open(file, &sc_seq_ops); 3682309e9e0SSunil Mushran if (ret) 3692309e9e0SSunil Mushran goto out; 3702309e9e0SSunil Mushran 3712309e9e0SSunil Mushran seq = file->private_data; 3722309e9e0SSunil Mushran seq->private = dummy_sc; 3732309e9e0SSunil Mushran o2net_debug_add_sc(dummy_sc); 3742309e9e0SSunil Mushran 3752309e9e0SSunil Mushran dummy_sc = NULL; 3762309e9e0SSunil Mushran 3772309e9e0SSunil Mushran out: 3782309e9e0SSunil Mushran kfree(dummy_sc); 3792309e9e0SSunil Mushran return ret; 3802309e9e0SSunil Mushran } 3812309e9e0SSunil Mushran 3822309e9e0SSunil Mushran static int sc_fop_release(struct inode *inode, struct file *file) 3832309e9e0SSunil Mushran { 3842309e9e0SSunil Mushran struct seq_file *seq = file->private_data; 3852309e9e0SSunil Mushran struct o2net_sock_container *dummy_sc = seq->private; 3862309e9e0SSunil Mushran 3872309e9e0SSunil Mushran o2net_debug_del_sc(dummy_sc); 3882309e9e0SSunil Mushran return seq_release_private(inode, file); 3892309e9e0SSunil Mushran } 3902309e9e0SSunil Mushran 391828c0950SAlexey Dobriyan static const struct file_operations sc_seq_fops = { 3922309e9e0SSunil Mushran .open = sc_fop_open, 3932309e9e0SSunil Mushran .read = seq_read, 3942309e9e0SSunil Mushran .llseek = seq_lseek, 3952309e9e0SSunil Mushran .release = sc_fop_release, 3962309e9e0SSunil Mushran }; 3972309e9e0SSunil Mushran 3982309e9e0SSunil Mushran int o2net_debugfs_init(void) 3992309e9e0SSunil Mushran { 4002309e9e0SSunil Mushran o2net_dentry = debugfs_create_dir(O2NET_DEBUG_DIR, NULL); 4012309e9e0SSunil Mushran if (!o2net_dentry) { 4022309e9e0SSunil Mushran mlog_errno(-ENOMEM); 4032309e9e0SSunil Mushran goto bail; 4042309e9e0SSunil Mushran } 4052309e9e0SSunil Mushran 4062309e9e0SSunil Mushran nst_dentry = debugfs_create_file(NST_DEBUG_NAME, S_IFREG|S_IRUSR, 4072309e9e0SSunil Mushran o2net_dentry, NULL, 4082309e9e0SSunil Mushran &nst_seq_fops); 4092309e9e0SSunil Mushran if (!nst_dentry) { 4102309e9e0SSunil Mushran mlog_errno(-ENOMEM); 4112309e9e0SSunil Mushran goto bail; 4122309e9e0SSunil Mushran } 4132309e9e0SSunil Mushran 4142309e9e0SSunil Mushran sc_dentry = debugfs_create_file(SC_DEBUG_NAME, S_IFREG|S_IRUSR, 4152309e9e0SSunil Mushran o2net_dentry, NULL, 4162309e9e0SSunil Mushran &sc_seq_fops); 4172309e9e0SSunil Mushran if (!sc_dentry) { 4182309e9e0SSunil Mushran mlog_errno(-ENOMEM); 4192309e9e0SSunil Mushran goto bail; 4202309e9e0SSunil Mushran } 4212309e9e0SSunil Mushran 4222309e9e0SSunil Mushran return 0; 4232309e9e0SSunil Mushran bail: 4242309e9e0SSunil Mushran debugfs_remove(sc_dentry); 4252309e9e0SSunil Mushran debugfs_remove(nst_dentry); 4262309e9e0SSunil Mushran debugfs_remove(o2net_dentry); 4272309e9e0SSunil Mushran return -ENOMEM; 4282309e9e0SSunil Mushran } 4292309e9e0SSunil Mushran 4302309e9e0SSunil Mushran void o2net_debugfs_exit(void) 4312309e9e0SSunil Mushran { 4322309e9e0SSunil Mushran debugfs_remove(sc_dentry); 4332309e9e0SSunil Mushran debugfs_remove(nst_dentry); 4342309e9e0SSunil Mushran debugfs_remove(o2net_dentry); 4352309e9e0SSunil Mushran } 4362309e9e0SSunil Mushran 4372309e9e0SSunil Mushran #endif /* CONFIG_DEBUG_FS */ 438