Blame view

net/sctp/objcnt.c 4.24 KB
60c778b25   Vlad Yasevich   [SCTP]: Stop clai...
1
  /* SCTP kernel implementation
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
   * (C) Copyright IBM Corp. 2001, 2004
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
3
   *
60c778b25   Vlad Yasevich   [SCTP]: Stop clai...
4
   * This file is part of the SCTP kernel implementation
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
5
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
   * Support for memory object debugging.  This allows one to monitor the
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
7
8
9
   * object allocations/deallocations for types instrumented for this
   * via the proc fs.
   *
60c778b25   Vlad Yasevich   [SCTP]: Stop clai...
10
   * This SCTP implementation is free software;
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
11
   * you can redistribute it and/or modify it under the terms of
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
13
14
   * the GNU General Public License as published by
   * the Free Software Foundation; either version 2, or (at your option)
   * any later version.
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
15
   *
60c778b25   Vlad Yasevich   [SCTP]: Stop clai...
16
   * This SCTP implementation is distributed in the hope that it
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
20
   * will be useful, but WITHOUT ANY WARRANTY; without even the implied
   *                 ************************
   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   * See the GNU General Public License for more details.
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
21
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
24
   * You should have received a copy of the GNU General Public License
   * along with GNU CC; see the file COPYING.  If not, write to
   * the Free Software Foundation, 59 Temple Place - Suite 330,
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
25
26
   * Boston, MA 02111-1307, USA.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
29
   * Please send any bug reports or fixes you make to the
   * email address(es):
   *    lksctp developers <lksctp-developers@lists.sourceforge.net>
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
30
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
   * Or submit a bug report through the following website:
   *    http://www.sf.net/projects/lksctp
   *
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
34
   * Written or modified by:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
   *    Jon Grimm             <jgrimm@us.ibm.com>
d808ad9ab   YOSHIFUJI Hideaki   [NET] SCTP: Fix w...
36
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
   * Any bugs reported given to us we will try to fix... any fixes shared will
   * be incorporated into the next SCTP release.
   */
145ce502e   Joe Perches   net/sctp: Use pr_...
40
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <linux/kernel.h>
  #include <net/sctp/sctp.h>
  
  /*
   * Global counters to count raw object allocation counts.
   * To add new counters, choose a unique suffix for the variable
   * name as the helper macros key off this suffix to make
   * life easier for the programmer.
   */
  
  SCTP_DBG_OBJCNT(sock);
  SCTP_DBG_OBJCNT(ep);
  SCTP_DBG_OBJCNT(transport);
  SCTP_DBG_OBJCNT(assoc);
  SCTP_DBG_OBJCNT(bind_addr);
  SCTP_DBG_OBJCNT(bind_bucket);
  SCTP_DBG_OBJCNT(chunk);
  SCTP_DBG_OBJCNT(addr);
  SCTP_DBG_OBJCNT(ssnmap);
  SCTP_DBG_OBJCNT(datamsg);
1f485649f   Vlad Yasevich   [SCTP]: Implement...
61
  SCTP_DBG_OBJCNT(keys);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  
  /* An array to make it easy to pretty print the debug information
   * to the proc fs.
   */
  static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = {
  	SCTP_DBG_OBJCNT_ENTRY(sock),
  	SCTP_DBG_OBJCNT_ENTRY(ep),
  	SCTP_DBG_OBJCNT_ENTRY(assoc),
  	SCTP_DBG_OBJCNT_ENTRY(transport),
  	SCTP_DBG_OBJCNT_ENTRY(chunk),
  	SCTP_DBG_OBJCNT_ENTRY(bind_addr),
  	SCTP_DBG_OBJCNT_ENTRY(bind_bucket),
  	SCTP_DBG_OBJCNT_ENTRY(addr),
  	SCTP_DBG_OBJCNT_ENTRY(ssnmap),
  	SCTP_DBG_OBJCNT_ENTRY(datamsg),
1f485649f   Vlad Yasevich   [SCTP]: Implement...
77
  	SCTP_DBG_OBJCNT_ENTRY(keys),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
81
82
  };
  
  /* Callback from procfs to read out objcount information.
   * Walk through the entries in the sctp_dbg_objcnt array, dumping
   * the raw object counts for each monitored type.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
   */
8ff65b460   Pavel Emelyanov   [SCTP]: Convert s...
84
  static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  {
5e659e4cb   Pavel Emelyanov   [NET]: Fix heavy ...
86
  	int i, len;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87

8ff65b460   Pavel Emelyanov   [SCTP]: Convert s...
88
  	i = (int)*(loff_t *)v;
5e659e4cb   Pavel Emelyanov   [NET]: Fix heavy ...
89
90
91
92
  	seq_printf(seq, "%s: %d%n", sctp_dbg_objcnt[i].label,
  				atomic_read(sctp_dbg_objcnt[i].counter), &len);
  	seq_printf(seq, "%*s
  ", 127 - len, "");
8ff65b460   Pavel Emelyanov   [SCTP]: Convert s...
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  	return 0;
  }
  
  static void *sctp_objcnt_seq_start(struct seq_file *seq, loff_t *pos)
  {
  	return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
  }
  
  static void sctp_objcnt_seq_stop(struct seq_file *seq, void *v)
  {
  }
  
  static void * sctp_objcnt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
  {
  	++*pos;
  	return (*pos >= ARRAY_SIZE(sctp_dbg_objcnt)) ? NULL : (void *)pos;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  }
8ff65b460   Pavel Emelyanov   [SCTP]: Convert s...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  static const struct seq_operations sctp_objcnt_seq_ops = {
  	.start = sctp_objcnt_seq_start,
  	.next  = sctp_objcnt_seq_next,
  	.stop  = sctp_objcnt_seq_stop,
  	.show  = sctp_objcnt_seq_show,
  };
  
  static int sctp_objcnt_seq_open(struct inode *inode, struct file *file)
  {
  	return seq_open(file, &sctp_objcnt_seq_ops);
  }
  
  static const struct file_operations sctp_objcnt_ops = {
  	.open	 = sctp_objcnt_seq_open,
  	.read	 = seq_read,
  	.llseek	 = seq_lseek,
  	.release = seq_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
129
130
  /* Initialize the objcount in the proc filesystem.  */
  void sctp_dbg_objcnt_init(void)
  {
ee71a29eb   Christophe Lucas   [SCTP]: Audit ret...
131
  	struct proc_dir_entry *ent;
8ff65b460   Pavel Emelyanov   [SCTP]: Convert s...
132

160f17e34   Wang Chen   [SCTP]: Use proc_...
133
134
  	ent = proc_create("sctp_dbg_objcnt", 0,
  			  proc_net_sctp, &sctp_objcnt_ops);
ee71a29eb   Christophe Lucas   [SCTP]: Audit ret...
135
  	if (!ent)
145ce502e   Joe Perches   net/sctp: Use pr_...
136
137
  		pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
138
139
140
141
142
143
144
  }
  
  /* Cleanup the objcount entry in the proc filesystem.  */
  void sctp_dbg_objcnt_exit(void)
  {
  	remove_proc_entry("sctp_dbg_objcnt", proc_net_sctp);
  }