netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] (4/4) convert irlan to seq_file interface
@ 2003-08-18 19:27 Stephen Hemminger
  2003-08-18 21:25 ` Francois Romieu
  2003-08-20  4:17 ` David S. Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Stephen Hemminger @ 2003-08-18 19:27 UTC (permalink / raw)
  To: Jean Tourrilhes, David S. Miller; +Cc: irda-users, netdev

Convert irlan /proc interface to safer seq_file library.


diff -Nru a/include/net/irda/irlan_filter.h b/include/net/irda/irlan_filter.h
--- a/include/net/irda/irlan_filter.h	Mon Aug 18 11:11:02 2003
+++ b/include/net/irda/irlan_filter.h	Mon Aug 18 11:11:02 2003
@@ -28,6 +28,6 @@
 void irlan_check_command_param(struct irlan_cb *self, char *param, 
 			       char *value);
 void handle_filter_request(struct irlan_cb *self, struct sk_buff *skb);
-int irlan_print_filter(int filter_type, char *buf);
+int irlan_print_filter(struct seq_file *seq, int filter_type);
 
 #endif /* IRLAN_FILTER_H */
diff -Nru a/net/irda/irlan/irlan_common.c b/net/irda/irlan/irlan_common.c
--- a/net/irda/irlan/irlan_common.c	Mon Aug 18 11:11:02 2003
+++ b/net/irda/irlan/irlan_common.c	Mon Aug 18 11:11:02 2003
@@ -31,6 +31,7 @@
 #include <linux/init.h>
 #include <linux/errno.h>
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/rtnetlink.h>
@@ -86,6 +87,20 @@
 	"802.3",
 	"802.5"
 };
+
+extern struct proc_dir_entry *proc_irda;
+
+static int irlan_seq_open(struct inode *inode, struct file *file);
+
+static struct file_operations irlan_fops = {
+	.owner	 = THIS_MODULE,
+	.open    = irlan_seq_open,
+	.read    = seq_read,
+	.llseek  = seq_lseek,
+	.release = seq_release,
+};
+
+extern struct proc_dir_entry *proc_irda;
 #endif /* CONFIG_PROC_FS */
 
 static void __irlan_close(struct irlan_cb *self);
@@ -94,12 +109,6 @@
 				__u8 *value_array, __u16 value_len);
 void irlan_close_tsaps(struct irlan_cb *self);
 
-#ifdef CONFIG_PROC_FS
-static int irlan_proc_read(char *buf, char **start, off_t offset, int len);
-
-extern struct proc_dir_entry *proc_irda;
-#endif /* CONFIG_PROC_FS */
-
 /*
  * Function irlan_init (void)
  *
@@ -112,8 +121,17 @@
 	__u16 hints;
 
 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ );
+
 #ifdef CONFIG_PROC_FS
-	create_proc_info_entry("irlan", 0, proc_irda, irlan_proc_read);
+	{ struct proc_dir_entry *proc;
+	proc = create_proc_entry("irlan", 0, proc_irda);
+	if (!proc) {
+		printk(KERN_ERR "irlan_init: can't create /proc entry!\n");
+		return -ENODEV;
+	}
+
+	proc->proc_fops = &irlan_fops;
+	}
 #endif /* CONFIG_PROC_FS */
 
 	IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
@@ -1050,55 +1068,104 @@
 }
 
 #ifdef CONFIG_PROC_FS
+#define IRLAN_PROC_START_TOKEN	((void *)1)
+
 /*
- * Function irlan_client_proc_read (buf, start, offset, len, unused)
- *
- *    Give some info to the /proc file system
+ * Start of reading /proc entries.
+ * Return entry at pos, 
+ *	or start_token to indicate print header line
+ *	or NULL if end of file
  */
-static int irlan_proc_read(char *buf, char **start, off_t offset, int len)
+static void *irlan_seq_start(struct seq_file *seq, loff_t *pos)
 {
+	int i = 1;
 	struct irlan_cb *self;
-     
-	len = 0;
-	
+
 	rcu_read_lock();
+	if (*pos == 0)
+		return IRLAN_PROC_START_TOKEN;
+
+	list_for_each_entry(self, &irlans, dev_list) {
+		if (*pos == i) 
+			return self;
+		++i;
+	}
+	return NULL;
+}
+
+/* Return entry after v, and increment pos */
+static void *irlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+	struct list_head *nxt;
+
+	++*pos;
+	if (v == IRLAN_PROC_START_TOKEN) 
+		nxt = irlans.next;
+	else
+		nxt = ((struct irlan_cb *)v)->dev_list.next;
+
+	return (nxt == &irlans) ? NULL 
+		: list_entry(nxt, struct irlan_cb, dev_list);
+}
+
+/* End of reading /proc file */
+static void irlan_seq_stop(struct seq_file *seq, void *v)
+{
+	rcu_read_unlock();
+}
 
-	len += sprintf(buf+len, "IrLAN instances:\n");
-	
-	list_for_each_entry_rcu(self, &irlans, dev_list) {
 
-		ASSERT(self->magic == IRLAN_MAGIC, break;);
+/*
+ * Show one entry in /proc file.
+ */
+static int irlan_seq_show(struct seq_file *seq, void *v)
+{
+	if (v == IRLAN_PROC_START_TOKEN)
+		seq_puts(seq, "IrLAN instances:\n");
+	else {
+		struct irlan_cb *self = v;
 		
-		len += sprintf(buf+len, "ifname: %s,\n",
+		ASSERT(self != NULL, return -1;);
+		ASSERT(self->magic == IRLAN_MAGIC, return -1;);
+
+		seq_printf(seq,"ifname: %s,\n",
 			       self->dev->name);
-		len += sprintf(buf+len, "client state: %s, ",
+		seq_printf(seq,"client state: %s, ",
 			       irlan_state[ self->client.state]);
-		len += sprintf(buf+len, "provider state: %s,\n",
+		seq_printf(seq,"provider state: %s,\n",
 			       irlan_state[ self->provider.state]);
-		len += sprintf(buf+len, "saddr: %#08x, ",
+		seq_printf(seq,"saddr: %#08x, ",
 			       self->saddr);
-		len += sprintf(buf+len, "daddr: %#08x\n",
+		seq_printf(seq,"daddr: %#08x\n",
 			       self->daddr);
-		len += sprintf(buf+len, "version: %d.%d,\n",
+		seq_printf(seq,"version: %d.%d,\n",
 			       self->version[1], self->version[0]);
-		len += sprintf(buf+len, "access type: %s\n", 
+		seq_printf(seq,"access type: %s\n", 
 			       irlan_access[self->client.access_type]);
-		len += sprintf(buf+len, "media: %s\n", 
+		seq_printf(seq,"media: %s\n", 
 			       irlan_media[self->media]);
 		
-		len += sprintf(buf+len, "local filter:\n");
-		len += sprintf(buf+len, "remote filter: ");
-		len += irlan_print_filter(self->client.filter_type, 
-					  buf+len);
-			
-		len += sprintf(buf+len, "tx busy: %s\n", 
+		seq_printf(seq,"local filter:\n");
+		seq_printf(seq,"remote filter: ");
+		irlan_print_filter(seq, self->client.filter_type);
+		seq_printf(seq,"tx busy: %s\n", 
 			       netif_queue_stopped(self->dev) ? "TRUE" : "FALSE");
 			
-		len += sprintf(buf+len, "\n");
- 	} 
-	rcu_read_unlock();
+		seq_putc(seq,'\n');
+	}
+	return 0;
+}
 
-	return len;
+static struct seq_operations irlan_seq_ops = {
+	.start = irlan_seq_start,
+	.next  = irlan_seq_next,
+	.stop  = irlan_seq_stop,
+	.show  = irlan_seq_show,
+};
+
+static int irlan_seq_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &irlan_seq_ops);
 }
 #endif
 
diff -Nru a/net/irda/irlan/irlan_filter.c b/net/irda/irlan/irlan_filter.c
--- a/net/irda/irlan/irlan_filter.c	Mon Aug 18 11:11:02 2003
+++ b/net/irda/irlan/irlan_filter.c	Mon Aug 18 11:11:02 2003
@@ -24,6 +24,7 @@
 
 #include <linux/skbuff.h>
 #include <linux/random.h>
+#include <linux/seq_file.h>
 
 #include <net/irda/irlan_common.h>
 
@@ -216,26 +217,24 @@
  *    Print status of filter. Used by /proc file system
  *
  */
-int irlan_print_filter(int filter_type, char *buf)
+#ifdef CONFIG_PROC_FS
+void irlan_print_filter(struct seq_file *seq, int filter_type)
 {
-	int len = 0;
-
 	if (filter_type & IRLAN_DIRECTED)
-		len += sprintf(buf+len, "%s", "DIRECTED ");
+		seq_printf(seq, "%s", "DIRECTED ");
 	if (filter_type & IRLAN_FUNCTIONAL)
-		len += sprintf(buf+len, "%s", "FUNCTIONAL ");
+		seq_printf(seq, "%s", "FUNCTIONAL ");
 	if (filter_type & IRLAN_GROUP)
-		len += sprintf(buf+len, "%s", "GROUP ");
+		seq_printf(seq, "%s", "GROUP ");
 	if (filter_type & IRLAN_MAC_FRAME)
-		len += sprintf(buf+len, "%s", "MAC_FRAME ");
+		seq_printf(seq, "%s", "MAC_FRAME ");
 	if (filter_type & IRLAN_MULTICAST)
-		len += sprintf(buf+len, "%s", "MULTICAST ");
+		seq_printf(seq, "%s", "MULTICAST ");
 	if (filter_type & IRLAN_BROADCAST)
-		len += sprintf(buf+len, "%s", "BROADCAST ");
+		seq_printf(seq, "%s", "BROADCAST ");
 	if (filter_type & IRLAN_IPX_SOCKET)
-		len += sprintf(buf+len, "%s", "IPX_SOCKET");
-
-	len += sprintf(buf+len, "\n");
+		seq_printf(seq, "%s", "IPX_SOCKET");
 
-	return len;
+	seq_putc(seq, '\n');
 }
+#endif

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (4/4) convert irlan to seq_file interface
  2003-08-18 19:27 [PATCH] (4/4) convert irlan to seq_file interface Stephen Hemminger
@ 2003-08-18 21:25 ` Francois Romieu
  2003-08-18 22:05   ` Stephen Hemminger
  2003-08-20  4:17 ` David S. Miller
  1 sibling, 1 reply; 8+ messages in thread
From: Francois Romieu @ 2003-08-18 21:25 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Jean Tourrilhes, David S. Miller, irda-users, netdev

Stephen Hemminger <shemminger@osdl.org> :
> Convert irlan /proc interface to safer seq_file library.
[...]
> diff -Nru a/net/irda/irlan/irlan_filter.c b/net/irda/irlan/irlan_filter.c
> --- a/net/irda/irlan/irlan_filter.c	Mon Aug 18 11:11:02 2003
> +++ b/net/irda/irlan/irlan_filter.c	Mon Aug 18 11:11:02 2003
[...]
> @@ -216,26 +217,24 @@
>   *    Print status of filter. Used by /proc file system
>   *
>   */
> -int irlan_print_filter(int filter_type, char *buf)
> +#ifdef CONFIG_PROC_FS
> +void irlan_print_filter(struct seq_file *seq, int filter_type)
>  {
> -	int len = 0;
> -
>  	if (filter_type & IRLAN_DIRECTED)
> -		len += sprintf(buf+len, "%s", "DIRECTED ");
> +		seq_printf(seq, "%s", "DIRECTED ");
>  	if (filter_type & IRLAN_FUNCTIONAL)
> -		len += sprintf(buf+len, "%s", "FUNCTIONAL ");
> +		seq_printf(seq, "%s", "FUNCTIONAL ");
>  	if (filter_type & IRLAN_GROUP)
> -		len += sprintf(buf+len, "%s", "GROUP ");
> +		seq_printf(seq, "%s", "GROUP ");
>  	if (filter_type & IRLAN_MAC_FRAME)
> -		len += sprintf(buf+len, "%s", "MAC_FRAME ");
> +		seq_printf(seq, "%s", "MAC_FRAME ");
>  	if (filter_type & IRLAN_MULTICAST)
> -		len += sprintf(buf+len, "%s", "MULTICAST ");
> +		seq_printf(seq, "%s", "MULTICAST ");
>  	if (filter_type & IRLAN_BROADCAST)
> -		len += sprintf(buf+len, "%s", "BROADCAST ");
> +		seq_printf(seq, "%s", "BROADCAST ");
>  	if (filter_type & IRLAN_IPX_SOCKET)
> -		len += sprintf(buf+len, "%s", "IPX_SOCKET");
> -
> -	len += sprintf(buf+len, "\n");
> +		seq_printf(seq, "%s", "IPX_SOCKET");
>  
> -	return len;
> +	seq_putc(seq, '\n');
>  }
> +#endif

(Ugly) variable naming apart, what about:

void irlan_print_filter(struct seq_file *seq, int filter_type)
{
	static struct {
		int mask;
		char *str;
	} filter_mask2str[] = {
		{ IRLAN_DIRECTED,	"DIRECTED" },
		{ IRLAN_FUNCTIONAL,	"FUNCTIONAL" },
		{ IRLAN_GROUP,		"GROUP" },
		{ IRLAN_MAC_FRAME,	"MAC_FRAME" },
		{ IRLAN_MULTICAST,	"MULTICAST" },
		{ IRLAN_BROADCAST,	"BROADCAST" },
		{ IRLAN_IPX_SOCKET,	"IPX_SOCKET" },
		{ 0,			NULL }
	}, *p;

	for (p = filter_mask2str; p->str; p++) {
		if (filter_type & p->mask)
			seq_printf(seq, "%s ", p->str);
	}
	seq_putc(seq, '\n');
}

--
Ueimor

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (4/4) convert irlan to seq_file interface
  2003-08-18 21:25 ` Francois Romieu
@ 2003-08-18 22:05   ` Stephen Hemminger
  2003-08-18 22:26     ` Francois Romieu
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2003-08-18 22:05 UTC (permalink / raw)
  To: Francois Romieu; +Cc: Jean Tourrilhes, David S. Miller, irda-users, netdev

I did a one step at a time conversion. 

> void irlan_print_filter(struct seq_file *seq, int filter_type)
> {
> 	static struct {
> 		int mask;
> 		char *str;
> 	} filter_mask2str[] = {
> 		{ IRLAN_DIRECTED,	"DIRECTED" },
> 		{ IRLAN_FUNCTIONAL,	"FUNCTIONAL" },
> 		{ IRLAN_GROUP,		"GROUP" },
> 		{ IRLAN_MAC_FRAME,	"MAC_FRAME" },
> 		{ IRLAN_MULTICAST,	"MULTICAST" },
> 		{ IRLAN_BROADCAST,	"BROADCAST" },
> 		{ IRLAN_IPX_SOCKET,	"IPX_SOCKET" },
> 		{ 0,			NULL }
> 	}, *p;
> 
> 	for (p = filter_mask2str; p->str; p++) {
> 		if (filter_type & p->mask)
> 			seq_printf(seq, "%s ", p->str);
> 	}
> 	seq_putc(seq, '\n');
> }

If you are going to do that (and it looks good).  Make the str a const
and use C99 initializers?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (4/4) convert irlan to seq_file interface
  2003-08-18 22:05   ` Stephen Hemminger
@ 2003-08-18 22:26     ` Francois Romieu
  2003-08-19 22:36       ` Francois Romieu
  0 siblings, 1 reply; 8+ messages in thread
From: Francois Romieu @ 2003-08-18 22:26 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Jean Tourrilhes, David S. Miller, irda-users, netdev

Stephen Hemminger <shemminger@osdl.org> :
[...]
> If you are going to do that (and it looks good).  Make the str a const
> and use C99 initializers?

I'll add a #define MASK2STR(m,s) { .mask = m, .str = s } and push it as an
incremental patch once the bk-commit mail is here (tomorrow evening then).

--
Ueimor

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (4/4) convert irlan to seq_file interface
  2003-08-18 22:26     ` Francois Romieu
@ 2003-08-19 22:36       ` Francois Romieu
  2003-08-20  0:41         ` Jean Tourrilhes
  2003-08-20  4:19         ` David S. Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Francois Romieu @ 2003-08-19 22:36 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Jean Tourrilhes, David S. Miller, irda-users, netdev

Apply on top of Stephen's serie [1-4]. Compile ok.

Style: separate data from code.


 net/irda/irlan/irlan_filter.c |   34 ++++++++++++++++++++--------------
 1 files changed, 20 insertions(+), 14 deletions(-)

diff -puN net/irda/irlan/irlan_filter.c~irlan-fr-0 net/irda/irlan/irlan_filter.c
--- linux-2.6.0-test3/net/irda/irlan/irlan_filter.c~irlan-fr-0	Wed Aug 20 00:07:37 2003
+++ linux-2.6.0-test3-fr/net/irda/irlan/irlan_filter.c	Wed Aug 20 00:18:50 2003
@@ -218,23 +218,29 @@ void irlan_check_command_param(struct ir
  *
  */
 #ifdef CONFIG_PROC_FS
+#define MASK2STR(m,s)	{ .mask = m, .str = s }
+
 void irlan_print_filter(struct seq_file *seq, int filter_type)
 {
-	if (filter_type & IRLAN_DIRECTED)
-		seq_printf(seq, "%s", "DIRECTED ");
-	if (filter_type & IRLAN_FUNCTIONAL)
-		seq_printf(seq, "%s", "FUNCTIONAL ");
-	if (filter_type & IRLAN_GROUP)
-		seq_printf(seq, "%s", "GROUP ");
-	if (filter_type & IRLAN_MAC_FRAME)
-		seq_printf(seq, "%s", "MAC_FRAME ");
-	if (filter_type & IRLAN_MULTICAST)
-		seq_printf(seq, "%s", "MULTICAST ");
-	if (filter_type & IRLAN_BROADCAST)
-		seq_printf(seq, "%s", "BROADCAST ");
-	if (filter_type & IRLAN_IPX_SOCKET)
-		seq_printf(seq, "%s", "IPX_SOCKET");
+	static struct {
+		int mask;
+		const char *str;
+	} filter_mask2str[] = {
+		MASK2STR(IRLAN_DIRECTED,	"DIRECTED"),
+		MASK2STR(IRLAN_FUNCTIONAL,	"FUNCTIONAL"),
+		MASK2STR(IRLAN_GROUP,		"GROUP"),
+		MASK2STR(IRLAN_MAC_FRAME,	"MAC_FRAME"),
+		MASK2STR(IRLAN_MULTICAST,	"MULTICAST"),
+		MASK2STR(IRLAN_BROADCAST,	"BROADCAST"),
+		MASK2STR(IRLAN_IPX_SOCKET,	"IPX_SOCKET"),
+		MASK2STR(0,			NULL)
+	}, *p;
 
+	for (p = filter_mask2str; p->str; p++) {
+		if (filter_type & p->mask)
+			seq_printf(seq, "%s ", p->str);
+	}
 	seq_putc(seq, '\n');
 }
+#undef MASK2STR
 #endif

_

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (4/4) convert irlan to seq_file interface
  2003-08-19 22:36       ` Francois Romieu
@ 2003-08-20  0:41         ` Jean Tourrilhes
  2003-08-20  4:19         ` David S. Miller
  1 sibling, 0 replies; 8+ messages in thread
From: Jean Tourrilhes @ 2003-08-20  0:41 UTC (permalink / raw)
  To: Francois Romieu, Stephen Hemminger; +Cc: David S. Miller, irda-users, netdev

On Wed, Aug 20, 2003 at 12:36:48AM +0200, Francois Romieu wrote:
> Apply on top of Stephen's serie [1-4]. Compile ok.
> 
> Style: separate data from code.

	By the way, I've totally lost track of who does what. If David
Miller doesn't process your patch, send it to me and I'll push it
through the usual channels.
	If any of you guys have issues setting up a testbed, either
with real IrDA hardware or a serial cross-over cable, please
yell. Testing is one of my hot button, and I don't want to give much
excuse ;-)
	By the way, I'm on vacation starting this thursday, I'll be
back in september.

	Have fun...

	Jean

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (4/4) convert irlan to seq_file interface
  2003-08-18 19:27 [PATCH] (4/4) convert irlan to seq_file interface Stephen Hemminger
  2003-08-18 21:25 ` Francois Romieu
@ 2003-08-20  4:17 ` David S. Miller
  1 sibling, 0 replies; 8+ messages in thread
From: David S. Miller @ 2003-08-20  4:17 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: jt, irda-users, netdev

On Mon, 18 Aug 2003 12:27:02 -0700
Stephen Hemminger <shemminger@osdl.org> wrote:

> Convert irlan /proc interface to safer seq_file library.

Applied, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] (4/4) convert irlan to seq_file interface
  2003-08-19 22:36       ` Francois Romieu
  2003-08-20  0:41         ` Jean Tourrilhes
@ 2003-08-20  4:19         ` David S. Miller
  1 sibling, 0 replies; 8+ messages in thread
From: David S. Miller @ 2003-08-20  4:19 UTC (permalink / raw)
  To: Francois Romieu; +Cc: shemminger, jt, irda-users, netdev

On Wed, 20 Aug 2003 00:36:48 +0200
Francois Romieu <romieu@fr.zoreil.com> wrote:

> Apply on top of Stephen's serie [1-4]. Compile ok.
> 
> Style: separate data from code.

Applied, thanks Francois.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-08-20  4:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-18 19:27 [PATCH] (4/4) convert irlan to seq_file interface Stephen Hemminger
2003-08-18 21:25 ` Francois Romieu
2003-08-18 22:05   ` Stephen Hemminger
2003-08-18 22:26     ` Francois Romieu
2003-08-19 22:36       ` Francois Romieu
2003-08-20  0:41         ` Jean Tourrilhes
2003-08-20  4:19         ` David S. Miller
2003-08-20  4:17 ` David S. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).