netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] CONNECTOR: add a proc entry to list connectors
@ 2008-06-24  1:30 Li Zefan
  2008-06-24  1:45 ` David Miller
  2008-06-24  6:49 ` Evgeniy Polyakov
  0 siblings, 2 replies; 4+ messages in thread
From: Li Zefan @ 2008-06-24  1:30 UTC (permalink / raw)
  To: David Miller; +Cc: LKML, netdev, Evgeniy Polyakov

I got a problem when I wanted to check if the kernel supports process
event connector, and It seems there's no way to do this check.

At best I can check if the kernel supports connector or not, by looking
into /proc/net/netlink, or maybe checking the return value of bind() to
see if it's ENOENT.

So how about add /proc/net/connector to list all supported connectors?
 # cat /proc/net/connector
 Name      ID
 connector 4294967295:4294967295
 cn_proc   1:1
 w1        3:1

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
 drivers/connector/connector.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 85e2ba7..08f9983 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -27,6 +27,8 @@
 #include <linux/moduleparam.h>
 #include <linux/connector.h>
 #include <linux/mutex.h>
+#include <linux/proc_fs.h>
+#include <linux/spinlock.h>
 
 #include <net/sock.h>
 
@@ -403,6 +405,41 @@ static void cn_callback(void *data)
 	mutex_unlock(&notify_lock);
 }
 
+static int cn_proc_show(struct seq_file *m, void *v)
+{
+	struct cn_queue_dev *dev = cdev.cbdev;
+	struct cn_callback_entry *cbq;
+	unsigned long flags;
+
+	seq_printf(m, "Name      ID\n");
+
+	spin_lock_irqsave(&dev->queue_lock, flags);
+
+	list_for_each_entry(cbq, &dev->queue_list, callback_entry) {
+		seq_printf(m, "%-9s %u:%u\n",
+			   cbq->id.name,
+			   cbq->id.id.idx,
+			   cbq->id.id.val);
+	}
+
+	spin_unlock_irqrestore(&dev->queue_lock, flags);
+
+	return 0;
+}
+
+static int cn_proc_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, cn_proc_show, NULL);
+}
+
+static const struct file_operations cn_file_ops = {
+	.owner   = THIS_MODULE,
+	.open    = cn_proc_open,
+	.read    = seq_read,
+	.llseek  = seq_lseek,
+	.release = seq_release
+};
+
 static int __devinit cn_init(void)
 {
 	struct cn_dev *dev = &cdev;
@@ -434,6 +471,8 @@ static int __devinit cn_init(void)
 		return -EINVAL;
 	}
 
+	proc_net_fops_create(&init_net, "connector", S_IRUGO, &cn_file_ops);
+
 	return 0;
 }
 
@@ -443,6 +482,8 @@ static void __devexit cn_fini(void)
 
 	cn_already_initialized = 0;
 
+	proc_net_remove(&init_net, "connector");
+
 	cn_del_callback(&dev->id);
 	cn_queue_free_dev(dev->cbdev);
 	netlink_kernel_release(dev->nls);
-- 
1.5.4.rc3


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

* Re: [PATCH] CONNECTOR: add a proc entry to list connectors
  2008-06-24  1:30 [PATCH] CONNECTOR: add a proc entry to list connectors Li Zefan
@ 2008-06-24  1:45 ` David Miller
  2008-06-24  1:57   ` Li Zefan
  2008-06-24  6:49 ` Evgeniy Polyakov
  1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2008-06-24  1:45 UTC (permalink / raw)
  To: lizf; +Cc: linux-kernel, netdev, johnpol

From: Li Zefan <lizf@cn.fujitsu.com>
Date: Tue, 24 Jun 2008 09:30:44 +0800

> I got a problem when I wanted to check if the kernel supports process
> event connector, and It seems there's no way to do this check.

Try to create a connector socket.

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

* Re: [PATCH] CONNECTOR: add a proc entry to list connectors
  2008-06-24  1:45 ` David Miller
@ 2008-06-24  1:57   ` Li Zefan
  0 siblings, 0 replies; 4+ messages in thread
From: Li Zefan @ 2008-06-24  1:57 UTC (permalink / raw)
  To: David Miller; +Cc: linux-kernel, netdev, johnpol

David Miller wrote:
> From: Li Zefan <lizf@cn.fujitsu.com>
> Date: Tue, 24 Jun 2008 09:30:44 +0800
> 
>> I got a problem when I wanted to check if the kernel supports process
>> event connector, and It seems there's no way to do this check.
> 
> Try to create a connector socket.
>  

Do you mean socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); ?

But this has nothing to do with process event connector. If it's not
supported, both socket() and bind() return successfully, just I can
recv() nothing.

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

* Re: [PATCH] CONNECTOR: add a proc entry to list connectors
  2008-06-24  1:30 [PATCH] CONNECTOR: add a proc entry to list connectors Li Zefan
  2008-06-24  1:45 ` David Miller
@ 2008-06-24  6:49 ` Evgeniy Polyakov
  1 sibling, 0 replies; 4+ messages in thread
From: Evgeniy Polyakov @ 2008-06-24  6:49 UTC (permalink / raw)
  To: Li Zefan; +Cc: David Miller, LKML, netdev

Hi.

On Tue, Jun 24, 2008 at 09:30:44AM +0800, Li Zefan (lizf@cn.fujitsu.com) wrote:
> I got a problem when I wanted to check if the kernel supports process
> event connector, and It seems there's no way to do this check.
> 
> At best I can check if the kernel supports connector or not, by looking
> into /proc/net/netlink, or maybe checking the return value of bind() to
> see if it's ENOENT.
> 
> So how about add /proc/net/connector to list all supported connectors?
>  # cat /proc/net/connector
>  Name      ID
>  connector 4294967295:4294967295
>  cn_proc   1:1
>  w1        3:1

I like the idea, but if it is not appropriate way, I can extend
connector core itself so it will support not only add/remove
notification of added/removed users, but will also allow to query if
given user exists.

> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>

Ack.

> +static int cn_proc_show(struct seq_file *m, void *v)
> +{
> +	struct cn_queue_dev *dev = cdev.cbdev;
> +	struct cn_callback_entry *cbq;
> +	unsigned long flags;
> +
> +	seq_printf(m, "Name      ID\n");
> +
> +	spin_lock_irqsave(&dev->queue_lock, flags);

It can be BH lock only.

-- 
	Evgeniy Polyakov

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

end of thread, other threads:[~2008-06-24  6:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-24  1:30 [PATCH] CONNECTOR: add a proc entry to list connectors Li Zefan
2008-06-24  1:45 ` David Miller
2008-06-24  1:57   ` Li Zefan
2008-06-24  6:49 ` Evgeniy Polyakov

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).