2002-11-24 20:48:29

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: [PATCH] wireless: convert /proc/net/wireless to seq_file

Hi David,

Please pull from:

master.kernel.org:/home/acme/BK/net-2.5

Now there are four 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.

===================================================================


[email protected], 2002-11-24 18:47:45-02:00, [email protected]
o wireless: convert /proc/net/wireless to seq_file


dev.c | 22 +++++++---
wireless.c | 133 +++++++++++++++++++++++++++++++------------------------------
2 files changed, 84 insertions(+), 71 deletions(-)


diff -Nru a/net/core/dev.c b/net/core/dev.c
--- a/net/core/dev.c Sun Nov 24 18:51:15 2002
+++ b/net/core/dev.c Sun Nov 24 18:51:15 2002
@@ -1737,18 +1737,18 @@
return i == pos ? dev : NULL;
}

-static void *dev_seq_start(struct seq_file *seq, loff_t *pos)
+void *dev_seq_start(struct seq_file *seq, loff_t *pos)
{
read_lock(&dev_base_lock);
return *pos ? dev_get_idx(seq, *pos) : (void *)1;
}

-static void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
return v == (void *)1 ? dev_base : ((struct net_device *)v)->next;
}

-static void dev_seq_stop(struct seq_file *seq, void *v)
+void dev_seq_stop(struct seq_file *seq, void *v)
{
read_unlock(&dev_base_lock);
}
@@ -1856,6 +1856,14 @@
.release = seq_release,
};

+#ifdef WIRELESS_EXT
+extern int wireless_proc_init(void);
+extern int wireless_proc_exit(void);
+#else
+#define wireless_proc_init() 0
+#define wireless_proc_exit()
+#endif
+
static int __init dev_proc_init(void)
{
struct proc_dir_entry *p;
@@ -1865,13 +1873,15 @@
if (!p)
goto out;
p->proc_fops = &dev_seq_fops;
+ if (wireless_proc_init())
+ goto out_dev;
create_proc_read_entry("net/softnet_stat", 0, 0, dev_proc_stats, NULL);
-#ifdef WIRELESS_EXT
- proc_net_create("wireless", 0, dev_get_wireless_info);
-#endif
rc = 0;
out:
return rc;
+out_dev:
+ remove_proc_entry("dev", proc_net);
+ goto out;
}
#else
#define dev_proc_init() 0
diff -Nru a/net/core/wireless.c b/net/core/wireless.c
--- a/net/core/wireless.c Sun Nov 24 18:51:15 2002
+++ b/net/core/wireless.c Sun Nov 24 18:51:15 2002
@@ -47,15 +47,18 @@

/***************************** INCLUDES *****************************/

-#include <asm/uaccess.h> /* copy_to_user() */
#include <linux/config.h> /* Not needed ??? */
#include <linux/types.h> /* off_t */
#include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
+#include <linux/proc_fs.h>
#include <linux/rtnetlink.h> /* rtnetlink stuff */
-
+#include <linux/seq_file.h>
#include <linux/wireless.h> /* Pretty obvious */
+
#include <net/iw_handler.h> /* New driver API */

+#include <asm/uaccess.h> /* copy_to_user() */
+
/**************************** CONSTANTS ****************************/

/* Enough lenience, let's make sure things are proper... */
@@ -330,83 +333,83 @@
/*
* Print one entry (line) of /proc/net/wireless
*/
-static inline int sprintf_wireless_stats(char *buffer, struct net_device *dev)
+static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
+ struct net_device *dev)
{
/* Get stats from the driver */
- struct iw_statistics *stats;
- int size;
+ struct iw_statistics *stats = get_wireless_stats(dev);

- stats = get_wireless_stats(dev);
- if (stats != (struct iw_statistics *) NULL) {
- size = sprintf(buffer,
- "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d %6d %6d %6d\n",
- dev->name,
- stats->status,
- stats->qual.qual,
- stats->qual.updated & 1 ? '.' : ' ',
- ((__u8) stats->qual.level),
- stats->qual.updated & 2 ? '.' : ' ',
- ((__u8) stats->qual.noise),
- stats->qual.updated & 4 ? '.' : ' ',
- stats->discard.nwid,
- stats->discard.code,
- stats->discard.fragment,
- stats->discard.retries,
- stats->discard.misc,
- stats->miss.beacon);
+ if (stats) {
+ seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
+ "%6d %6d %6d\n",
+ dev->name, stats->status, stats->qual.qual,
+ stats->qual.updated & 1 ? '.' : ' ',
+ ((__u8) stats->qual.level),
+ stats->qual.updated & 2 ? '.' : ' ',
+ ((__u8) stats->qual.noise),
+ stats->qual.updated & 4 ? '.' : ' ',
+ stats->discard.nwid, stats->discard.code,
+ stats->discard.fragment, stats->discard.retries,
+ stats->discard.misc, stats->miss.beacon);
stats->qual.updated = 0;
}
- else
- size = 0;
-
- return size;
}

/* ---------------------------------------------------------------- */
/*
* Print info for /proc/net/wireless (print all entries)
*/
-int dev_get_wireless_info(char * buffer, char **start, off_t offset,
- int length)
+static int wireless_seq_show(struct seq_file *seq, void *v)
{
- int len = 0;
- off_t begin = 0;
- off_t pos = 0;
- int size;
-
- struct net_device * dev;
-
- size = sprintf(buffer,
- "Inter-| sta-| Quality | Discarded packets | Missed\n"
- " face | tus | link level noise | nwid crypt frag retry misc | beacon\n"
- );
-
- pos += size;
- len += size;
-
- read_lock(&dev_base_lock);
- for (dev = dev_base; dev != NULL; dev = dev->next) {
- size = sprintf_wireless_stats(buffer + len, dev);
- len += size;
- pos = begin + len;
-
- if (pos < offset) {
- len = 0;
- begin = pos;
- }
- if (pos > offset + length)
- break;
- }
- read_unlock(&dev_base_lock);
+ if (v == (void *)1)
+ seq_printf(seq, "Inter-| sta-| Quality | Discarded "
+ "packets | Missed\n"
+ " face | tus | link level noise | nwid "
+ "crypt frag retry misc | beacon\n");
+ else
+ wireless_seq_printf_stats(seq, v);
+ return 0;
+}
+
+extern void *dev_seq_start(struct seq_file *seq, loff_t *pos);
+extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos);
+extern void dev_seq_stop(struct seq_file *seq, void *v);
+
+static struct seq_operations wireless_seq_ops = {
+ .start = dev_seq_start,
+ .next = dev_seq_next,
+ .stop = dev_seq_stop,
+ .show = wireless_seq_show,
+};
+
+static int wireless_seq_open(struct inode *inode, struct file *file)
+{
+ return seq_open(file, &wireless_seq_ops);
+}

- *start = buffer + (offset - begin); /* Start of wanted data */
- len -= (offset - begin); /* Start slop */
- if (len > length)
- len = length; /* Ending slop */
- if (len < 0)
- len = 0;
+static struct file_operations wireless_seq_fops = {
+ .open = wireless_seq_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};

- return len;
+int __init wireless_proc_init(void)
+{
+ struct proc_dir_entry *p;
+ int rc = 0;
+
+ p = create_proc_entry("wireless", S_IRUGO, proc_net);
+ if (p)
+ p->proc_fops = &wireless_seq_fops;
+ else
+ rc = -ENOMEM;
+ return rc;
+}
+
+void __init wireless_proc_exit(void)
+{
+ remove_proc_entry("wireless", proc_net);
}
#endif /* CONFIG_PROC_FS */


===================================================================


This BitKeeper patch contains the following changesets:
1.861
## Wrapped with gzip_uu ##


begin 664 bkpatch16624
M'XL(`,,[X3T``\U8;7.;1A#^+'[%CCV.)55"'._(M9LF]J2:)$UJ-]-^R`R#
MCY-%C8``DNT)^>_=/?1JO;CQM#,E"2?N]IY]N6>7)8?PJ1!YOQ'PL5`.X9>T
M*/L-GB:"E]$T4'DZ5J]S7+A,4USHC=*QZ+UZVTM$V=552\&5CT')1S`5>=%O
M,-58S)0/F>@W+B_>?'KW\Z6BG)["ZU&0W(@K4<+IJ5*F^32(P^)E4([B-%'+
M/$B*L2BESFHA6NF:IN,?BSF&9MD5LS73J3@+&0M,)D)--UW;5,C\EX_-?H3"
MF&XR$R^CLC3+=95S8*IK,]#T'F,]W03F]DVG;UI=3>]K&FP%A1]TZ&K**_AW
M'7BM<$CA+LI%+(JB#Z@60UI"+\M33N'NS==0,13BBS^,8J&\!8L9KJ9\7`97
MZ7[GI2A:H"EGD-&Q;?>&]/,T%PLC5#[WR]8T9AMV96B::U1.8%NFQTV#>SRT
MG.TAW`E')Z1C>$R]TFS/--"H_5%>`(5BNC2)0NU9;L5TAYF5:UB.-W1Y:-KA
MM>$]9=(2:6$-JTQ-]YCD\!;3B<W_0>R4O\J7HRQ61]E^&(]YFFX8NE,9ML=L
MR6IK@]/Z?D[;+G1MZ__#:GGZ'Z";W\F_2-*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