Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Wed, 13 Nov 2002 06:41:16 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Wed, 13 Nov 2002 06:41:16 -0500 Received: from orion.netbank.com.br ([200.203.199.90]:40459 "EHLO orion.netbank.com.br") by vger.kernel.org with ESMTP id ; Wed, 13 Nov 2002 06:41:10 -0500 Date: Wed, 13 Nov 2002 09:47:54 -0200 From: Arnaldo Carvalho de Melo To: "David S. Miller" Cc: Linux Kernel Mailing List Subject: [PATCH] ipv4: convert /proc/net/sockstat to seq_file Message-ID: <20021113114753.GB3440@conectiva.com.br> Mail-Followup-To: Arnaldo Carvalho de Melo , "David S. Miller" , Linux Kernel Mailing List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-Url: http://advogato.org/person/acme Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8547 Lines: 279 Hi David, Please pull from: master.kernel.org:/home/acme/BK/net-2.5 Now there are two outstanding changesets. - Arnaldo You can import this changeset into BK by piping this whole message to: '| bk receive [path to repository]' or apply the patch as usual. =================================================================== ChangeSet@1.826, 2002-11-13 09:38:15-02:00, acme@conectiva.com.br o ipv4: convert /proc/net/sockstat to seq_file Also only compile/link socket_seq_show (previously socket_get_info) in net/socket.c if CONFIG_PROC_FS is enabled. ipv4/proc.c | 85 ++++++++++++++++++++++++++---------------------------------- socket.c | 22 ++++----------- 2 files changed, 43 insertions(+), 64 deletions(-) diff -Nru a/net/ipv4/proc.c b/net/ipv4/proc.c --- a/net/ipv4/proc.c Wed Nov 13 09:44:17 2002 +++ b/net/ipv4/proc.c Wed Nov 13 09:44:17 2002 @@ -23,7 +23,7 @@ * Alan Cox : Handle dead sockets properly. * Gerhard Koerting : Show both timers * Alan Cox : Allow inode to be NULL (kernel socket) - * Andi Kleen : Add support for open_requests and + * Andi Kleen : Add support for open_requests and * split functions for more readibility. * Andi Kleen : Add support for /proc/net/netstat * Arnaldo C. Melo : Convert to seq_file @@ -33,21 +33,11 @@ * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include #include -#include #include #include #include @@ -58,7 +48,7 @@ int res = 0; int cpu; - for (cpu=0; cpustats[cpu].inuse; return res; @@ -67,38 +57,35 @@ /* * Report socket allocation statistics [mea@utu.fi] */ -int afinet_get_info(char *buffer, char **start, off_t offset, int length) +static int sockstat_seq_show(struct seq_file *seq, void *v) { - /* From net/socket.c */ - extern int socket_get_info(char *, char **, off_t, int); + /* From net/socket.c */ + extern void socket_seq_show(struct seq_file *seq); - int len = socket_get_info(buffer,start,offset,length); + socket_seq_show(seq); + seq_printf(seq, "TCP: inuse %d orphan %d tw %d alloc %d mem %d\n", + fold_prot_inuse(&tcp_prot), atomic_read(&tcp_orphan_count), + tcp_tw_count, atomic_read(&tcp_sockets_allocated), + atomic_read(&tcp_memory_allocated)); + seq_printf(seq, "UDP: inuse %d\n", fold_prot_inuse(&udp_prot)); + seq_printf(seq, "RAW: inuse %d\n", fold_prot_inuse(&raw_prot)); + seq_printf(seq, "FRAG: inuse %d memory %d\n", ip_frag_nqueues, + atomic_read(&ip_frag_mem)); + return 0; +} - len += sprintf(buffer+len,"TCP: inuse %d orphan %d tw %d alloc %d mem %d\n", - fold_prot_inuse(&tcp_prot), - atomic_read(&tcp_orphan_count), tcp_tw_count, - atomic_read(&tcp_sockets_allocated), - atomic_read(&tcp_memory_allocated)); - len += sprintf(buffer+len,"UDP: inuse %d\n", - fold_prot_inuse(&udp_prot)); - len += sprintf(buffer+len,"RAW: inuse %d\n", - fold_prot_inuse(&raw_prot)); - len += sprintf(buffer+len, "FRAG: inuse %d memory %d\n", - ip_frag_nqueues, atomic_read(&ip_frag_mem)); - if (offset >= len) - { - *start = buffer; - return 0; - } - *start = buffer + offset; - len -= offset; - if (len > length) - len = length; - if (len < 0) - len = 0; - return len; +static int sockstat_seq_open(struct inode *inode, struct file *file) +{ + return single_open(file, sockstat_seq_show, NULL); } +static struct file_operations sockstat_seq_fops = { + .open = sockstat_seq_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + static unsigned long fold_field(unsigned long *begin, int sz, int nr) { unsigned long res = 0; @@ -106,14 +93,14 @@ sz /= sizeof(unsigned long); - for (i=0; iproc_fops = &snmp_seq_fops; - if (!proc_net_create("sockstat", 0, afinet_get_info)) + p = create_proc_entry("sockstat", S_IRUGO, proc_net); + if (!p) goto out_sockstat; + p->proc_fops = &sockstat_seq_fops; out: return rc; out_sockstat: diff -Nru a/net/socket.c b/net/socket.c --- a/net/socket.c Wed Nov 13 09:44:17 2002 +++ b/net/socket.c Wed Nov 13 09:44:17 2002 @@ -1839,29 +1839,19 @@ #endif } -int socket_get_info(char *buffer, char **start, off_t offset, int length) +#ifdef CONFIG_PROC_FS +void socket_seq_show(struct seq_file *seq) { - int len, cpu; + int cpu; int counter = 0; - for (cpu=0; cpu= len) - { - *start = buffer; - return 0; - } - *start = buffer + offset; - len -= offset; - if (len > length) - len = length; - if (len < 0) - len = 0; - return len; + seq_printf(seq, "sockets: used %d\n", counter); } +#endif /* CONFIG_PROC_FS */ =================================================================== This BitKeeper patch contains the following changesets: 1.826 ## Wrapped with gzip_uu ## begin 664 bkpatch15114 M'XL(`!$[TCT``^57;6_;-A#^+/Z*6X(5MN,74N]VZJ)IW&1&BR9P%NS#.AB* M1"="95*5:*?9W/^^(V5[KNVT:;%O3122.MX=']ZK<@C7)2]Z5A1/.3F$WV2I M>E8L!8]5.H_:L9RV;PK<&$F)&YT[.>6=5V\Z@JN6W?8([EQ&*KZ#.2_*GL7: MSIJB'G+>LT:OSZ_?GHP(Z??A]"X2M_R**^CWB9+%/,J2\F6D[C(IVJJ(1#GE MRIRY6+,N;$IM_/58X%#/7S"?NL$B9@ECD,S,@#6#FT?J-UAK,,$_:8UZ)VCU+8JQ2.;&A1\@K^WPNB>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UA7I2*_^^;Q^21',^?2EFJFP+[&!1 M&W7L^_2A^`W,NMA"T9#,-SW<<;^WB?O00MF?NX=7GXY[>OA*PX\T357DV;8H7IL*%OC[ND./'R02P@6\9&;OW^M_(^(ZCSV?3OA\X&*TW +-^1?]!#&)[,.```` ` end - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/