Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* -*- mode: c; c-basic-offset: 8; -*-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * vim: noexpandtab sw=8 ts=8 sts=0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * netdebug.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * debug functionality for o2net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2005, 2008 Oracle.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "tcp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "nodemanager.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define MLOG_MASK_PREFIX ML_TCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include "masklog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include "tcp_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define O2NET_DEBUG_DIR		"o2net"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define SC_DEBUG_NAME		"sock_containers"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define NST_DEBUG_NAME		"send_tracking"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define STATS_DEBUG_NAME	"stats"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define NODES_DEBUG_NAME	"connected_nodes"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define SHOW_SOCK_CONTAINERS	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define SHOW_SOCK_STATS		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static struct dentry *o2net_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static DEFINE_SPINLOCK(o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static LIST_HEAD(sock_containers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static LIST_HEAD(send_tracking);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) void o2net_debug_add_nst(struct o2net_send_tracking *nst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	list_add(&nst->st_net_debug_item, &send_tracking);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) void o2net_debug_del_nst(struct o2net_send_tracking *nst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (!list_empty(&nst->st_net_debug_item))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		list_del_init(&nst->st_net_debug_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static struct o2net_send_tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 			*next_nst(struct o2net_send_tracking *nst_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct o2net_send_tracking *nst, *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	assert_spin_locked(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	list_for_each_entry(nst, &nst_start->st_net_debug_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			    st_net_debug_item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		/* discover the head of the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		if (&nst->st_net_debug_item == &send_tracking)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		/* use st_task to detect real nsts in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (nst->st_task != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			ret = nst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static void *nst_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct o2net_send_tracking *nst, *dummy_nst = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	nst = next_nst(dummy_nst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return nst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static void *nst_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct o2net_send_tracking *nst, *dummy_nst = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	nst = next_nst(dummy_nst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	list_del_init(&dummy_nst->st_net_debug_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (nst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		list_add(&dummy_nst->st_net_debug_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			 &nst->st_net_debug_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return nst; /* unused, just needs to be null when done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int nst_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct o2net_send_tracking *nst, *dummy_nst = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ktime_t now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	s64 sock, send, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	nst = next_nst(dummy_nst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (!nst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	now = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	sock = ktime_to_us(ktime_sub(now, nst->st_sock_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	send = ktime_to_us(ktime_sub(now, nst->st_send_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	status = ktime_to_us(ktime_sub(now, nst->st_status_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	/* get_task_comm isn't exported.  oh well. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	seq_printf(seq, "%p:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		   "  pid:          %lu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		   "  tgid:         %lu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		   "  process name: %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		   "  node:         %u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		   "  sc:           %p\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		   "  message id:   %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		   "  message type: %u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		   "  message key:  0x%08x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		   "  sock acquiry: %lld usecs ago\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		   "  send start:   %lld usecs ago\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		   "  wait start:   %lld usecs ago\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		   nst, (unsigned long)task_pid_nr(nst->st_task),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		   (unsigned long)nst->st_task->tgid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		   nst->st_task->comm, nst->st_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		   nst->st_sc, nst->st_id, nst->st_msg_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		   nst->st_msg_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		   (long long)sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		   (long long)send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		   (long long)status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static void nst_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static const struct seq_operations nst_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.start = nst_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.next = nst_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.stop = nst_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.show = nst_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int nst_fop_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct o2net_send_tracking *dummy_nst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	dummy_nst = __seq_open_private(file, &nst_seq_ops, sizeof(*dummy_nst));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	if (!dummy_nst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	o2net_debug_add_nst(dummy_nst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static int nst_fop_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct seq_file *seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct o2net_send_tracking *dummy_nst = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	o2net_debug_del_nst(dummy_nst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return seq_release_private(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static const struct file_operations nst_seq_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	.open = nst_fop_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	.release = nst_fop_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) void o2net_debug_add_sc(struct o2net_sock_container *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	list_add(&sc->sc_net_debug_item, &sock_containers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) void o2net_debug_del_sc(struct o2net_sock_container *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	list_del_init(&sc->sc_net_debug_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct o2net_sock_debug {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	int dbg_ctxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct o2net_sock_container *dbg_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static struct o2net_sock_container
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 			*next_sc(struct o2net_sock_container *sc_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct o2net_sock_container *sc, *ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	assert_spin_locked(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	list_for_each_entry(sc, &sc_start->sc_net_debug_item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			    sc_net_debug_item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		/* discover the head of the list miscast as a sc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		if (&sc->sc_net_debug_item == &sock_containers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		/* use sc_page to detect real scs in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (sc->sc_page != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			ret = sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static void *sc_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct o2net_sock_debug *sd = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	sc = next_sc(dummy_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	return sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static void *sc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct o2net_sock_debug *sd = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	sc = next_sc(dummy_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	list_del_init(&dummy_sc->sc_net_debug_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		list_add(&dummy_sc->sc_net_debug_item, &sc->sc_net_debug_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	return sc; /* unused, just needs to be null when done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #ifdef CONFIG_OCFS2_FS_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) # define sc_send_count(_s)		((_s)->sc_send_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) # define sc_recv_count(_s)		((_s)->sc_recv_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) # define sc_tv_acquiry_total_ns(_s)	(ktime_to_ns((_s)->sc_tv_acquiry_total))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) # define sc_tv_send_total_ns(_s)	(ktime_to_ns((_s)->sc_tv_send_total))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) # define sc_tv_status_total_ns(_s)	(ktime_to_ns((_s)->sc_tv_status_total))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) # define sc_tv_process_total_ns(_s)	(ktime_to_ns((_s)->sc_tv_process_total))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) # define sc_send_count(_s)		(0U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) # define sc_recv_count(_s)		(0U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) # define sc_tv_acquiry_total_ns(_s)	(0LL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) # define sc_tv_send_total_ns(_s)	(0LL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) # define sc_tv_status_total_ns(_s)	(0LL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) # define sc_tv_process_total_ns(_s)	(0LL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* So that debugfs.ocfs2 can determine which format is being used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #define O2NET_STATS_STR_VERSION		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static void sc_show_sock_stats(struct seq_file *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			       struct o2net_sock_container *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (!sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	seq_printf(seq, "%d,%u,%lu,%lld,%lld,%lld,%lu,%lld\n", O2NET_STATS_STR_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		   sc->sc_node->nd_num, (unsigned long)sc_send_count(sc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		   (long long)sc_tv_acquiry_total_ns(sc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		   (long long)sc_tv_send_total_ns(sc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		   (long long)sc_tv_status_total_ns(sc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		   (unsigned long)sc_recv_count(sc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		   (long long)sc_tv_process_total_ns(sc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) static void sc_show_sock_container(struct seq_file *seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 				   struct o2net_sock_container *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct inet_sock *inet = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	__be32 saddr = 0, daddr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	__be16 sport = 0, dport = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (!sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	if (sc->sc_sock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		inet = inet_sk(sc->sc_sock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		/* the stack's structs aren't sparse endian clean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		saddr = (__force __be32)inet->inet_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		daddr = (__force __be32)inet->inet_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		sport = (__force __be16)inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		dport = (__force __be16)inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	/* XXX sigh, inet-> doesn't have sparse annotation so any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	 * use of it here generates a warning with -Wbitwise */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	seq_printf(seq, "%p:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		   "  krefs:           %d\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		   "  sock:            %pI4:%u -> "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				      "%pI4:%u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		   "  remote node:     %s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		   "  page off:        %zu\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		   "  handshake ok:    %u\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		   "  timer:           %lld usecs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		   "  data ready:      %lld usecs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		   "  advance start:   %lld usecs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		   "  advance stop:    %lld usecs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		   "  func start:      %lld usecs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		   "  func stop:       %lld usecs\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		   "  func key:        0x%08x\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		   "  func type:       %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		   sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		   kref_read(&sc->sc_kref),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		   &saddr, inet ? ntohs(sport) : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		   &daddr, inet ? ntohs(dport) : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		   sc->sc_node->nd_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		   sc->sc_page_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		   sc->sc_handshake_ok,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		   (long long)ktime_to_us(sc->sc_tv_timer),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		   (long long)ktime_to_us(sc->sc_tv_data_ready),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		   (long long)ktime_to_us(sc->sc_tv_advance_start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		   (long long)ktime_to_us(sc->sc_tv_advance_stop),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		   (long long)ktime_to_us(sc->sc_tv_func_start),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		   (long long)ktime_to_us(sc->sc_tv_func_stop),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		   sc->sc_msg_key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		   sc->sc_msg_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static int sc_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct o2net_sock_debug *sd = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	struct o2net_sock_container *sc, *dummy_sc = sd->dbg_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	spin_lock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	sc = next_sc(dummy_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	if (sc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		if (sd->dbg_ctxt == SHOW_SOCK_CONTAINERS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 			sc_show_sock_container(seq, sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			sc_show_sock_stats(seq, sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	spin_unlock(&o2net_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) static void sc_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static const struct seq_operations sc_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	.start = sc_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	.next = sc_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	.stop = sc_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	.show = sc_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static int sc_common_open(struct file *file, int ctxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	struct o2net_sock_debug *sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	struct o2net_sock_container *dummy_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	dummy_sc = kzalloc(sizeof(*dummy_sc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (!dummy_sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	sd = __seq_open_private(file, &sc_seq_ops, sizeof(*sd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	if (!sd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		kfree(dummy_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	sd->dbg_ctxt = ctxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	sd->dbg_sock = dummy_sc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	o2net_debug_add_sc(dummy_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static int sc_fop_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct seq_file *seq = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct o2net_sock_debug *sd = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct o2net_sock_container *dummy_sc = sd->dbg_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	o2net_debug_del_sc(dummy_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	kfree(dummy_sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return seq_release_private(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) static int stats_fop_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return sc_common_open(file, SHOW_SOCK_STATS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static const struct file_operations stats_seq_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	.open = stats_fop_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	.release = sc_fop_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) static int sc_fop_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	return sc_common_open(file, SHOW_SOCK_CONTAINERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static const struct file_operations sc_seq_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	.open = sc_fop_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	.read = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	.llseek = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	.release = sc_fop_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static int o2net_fill_bitmap(char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	unsigned long map[BITS_TO_LONGS(O2NM_MAX_NODES)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	int i = -1, out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	o2net_fill_node_map(map, sizeof(map));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	while ((i = find_next_bit(map, O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		out += scnprintf(buf + out, PAGE_SIZE - out, "%d ", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	out += scnprintf(buf + out, PAGE_SIZE - out, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static int nodes_fop_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	i_size_write(inode, o2net_fill_bitmap(buf, PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	file->private_data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static int o2net_debug_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	kfree(file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static ssize_t o2net_debug_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				size_t nbytes, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 				       i_size_read(file->f_mapping->host));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static const struct file_operations nodes_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	.open		= nodes_fop_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	.release	= o2net_debug_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	.read		= o2net_debug_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	.llseek		= generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) void o2net_debugfs_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	debugfs_remove_recursive(o2net_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) void o2net_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	umode_t mode = S_IFREG|S_IRUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	o2net_dentry = debugfs_create_dir(O2NET_DEBUG_DIR, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	debugfs_create_file(NST_DEBUG_NAME, mode, o2net_dentry, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			    &nst_seq_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	debugfs_create_file(SC_DEBUG_NAME, mode, o2net_dentry, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 			    &sc_seq_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	debugfs_create_file(STATS_DEBUG_NAME, mode, o2net_dentry, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 			    &stats_seq_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	debugfs_create_file(NODES_DEBUG_NAME, mode, o2net_dentry, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			    &nodes_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) #endif	/* CONFIG_DEBUG_FS */