All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Phonet: sockets list through proc_fs
@ 2009-07-21 11:57 Rémi Denis-Courmont
  2009-07-21 11:57 ` [PATCH] Phonet: dropped datagrams accounting Rémi Denis-Courmont
  2009-07-21 19:34 ` [PATCH] Phonet: sockets list through proc_fs David Miller
  0 siblings, 2 replies; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-21 11:57 UTC (permalink / raw)
  To: netdev

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

This provides a list of sockets with their Phonet bind addresses and
some socket debug informations through /proc/net/phonet.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/net/phonet/pn_dev.h |    2 +
 net/phonet/pn_dev.c         |    7 +++
 net/phonet/socket.c         |   96 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 0 deletions(-)

diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index 29d1267..44c923c 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -49,4 +49,6 @@ void phonet_address_notify(int event, struct net_device *dev, u8 addr);
 
 #define PN_NO_ADDR	0xff
 
+extern const struct file_operations pn_sock_seq_fops;
+
 #endif
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index b0d6ddd..5107b79 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -218,6 +218,11 @@ static int phonet_init_net(struct net *net)
 	if (!pnn)
 		return -ENOMEM;
 
+	if (!proc_net_fops_create(net, "phonet", 0, &pn_sock_seq_fops)) {
+		kfree(pnn);
+		return -ENOMEM;
+	}
+
 	INIT_LIST_HEAD(&pnn->pndevs.list);
 	spin_lock_init(&pnn->pndevs.lock);
 	net_assign_generic(net, phonet_net_id, pnn);
@@ -233,6 +238,8 @@ static void phonet_exit_net(struct net *net)
 	for_each_netdev(net, dev)
 		phonet_device_destroy(dev);
 	rtnl_unlock();
+
+	proc_net_remove(net, "phonet");
 	kfree(pnn);
 }
 
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index ada2a35..aa1617a 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -412,3 +412,99 @@ found:
 	return 0;
 }
 EXPORT_SYMBOL(pn_sock_get_port);
+
+static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos)
+{
+	struct net *net = seq_file_net(seq);
+	struct hlist_node *node;
+	struct sock *sknode;
+
+	sk_for_each(sknode, node, &pnsocks.hlist) {
+		if (!net_eq(net, sock_net(sknode)))
+			continue;
+		if (!pos)
+			return sknode;
+		pos--;
+	}
+	return NULL;
+}
+
+static struct sock *pn_sock_get_next(struct seq_file *seq, struct sock *sk)
+{
+	struct net *net = seq_file_net(seq);
+
+	do
+		sk = sk_next(sk);
+	while (sk && !net_eq(net, sock_net(sk)));
+
+	return sk;
+}
+
+static void *pn_sock_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(pnsocks.lock)
+{
+	spin_lock_bh(&pnsocks.lock);
+	return *pos ? pn_sock_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
+}
+
+static void *pn_sock_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+	struct sock *sk;
+
+	if (v == SEQ_START_TOKEN)
+		sk = pn_sock_get_idx(seq, 0);
+	else
+		sk = pn_sock_get_next(seq, v);
+	(*pos)++;
+	return sk;
+}
+
+static void pn_sock_seq_stop(struct seq_file *seq, void *v)
+	__releases(pnsocks.lock)
+{
+	spin_unlock_bh(&pnsocks.lock);
+}
+
+static int pn_sock_seq_show(struct seq_file *seq, void *v)
+{
+	int len;
+
+	if (v == SEQ_START_TOKEN)
+		seq_printf(seq, "%s%n", "pt  loc  rem rs st tx_queue rx_queue "
+			"  uid inode ref pointer drops", &len);
+	else {
+		struct sock *sk = v;
+		struct pn_sock *pn = pn_sk(sk);
+
+		seq_printf(seq, "%2d %04X:%04X:%02X %02X %08X:%08X %5d %lu "
+			"%d %p %d%n",
+			sk->sk_protocol, pn->sobject, 0, pn->resource,
+			sk->sk_state,
+			sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
+			sock_i_uid(sk), sock_i_ino(sk),
+			atomic_read(&sk->sk_refcnt), sk,
+			atomic_read(&sk->sk_drops), &len);
+	}
+	seq_printf(seq, "%*s\n", 127 - len, "");
+	return 0;
+}
+
+static const struct seq_operations pn_sock_seq_ops = {
+	.start = pn_sock_seq_start,
+	.next = pn_sock_seq_next,
+	.stop = pn_sock_seq_stop,
+	.show = pn_sock_seq_show,
+};
+
+static int pn_sock_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &pn_sock_seq_ops);
+}
+
+const struct file_operations pn_sock_seq_fops = {
+	.owner = THIS_MODULE,
+	.open = pn_sock_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
-- 
1.6.0.4


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

* [PATCH] Phonet: dropped datagrams accounting
  2009-07-21 11:57 [PATCH] Phonet: sockets list through proc_fs Rémi Denis-Courmont
@ 2009-07-21 11:57 ` Rémi Denis-Courmont
  2009-07-21 11:57   ` [PATCH] Phonet: account for dropped RX packets Rémi Denis-Courmont
  2009-07-21 19:35   ` [PATCH] Phonet: dropped datagrams accounting David Miller
  2009-07-21 19:34 ` [PATCH] Phonet: sockets list through proc_fs David Miller
  1 sibling, 2 replies; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-21 11:57 UTC (permalink / raw)
  To: netdev

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

The per-socket drop count is visible via /proc/net/phonet.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/datagram.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
index e087862..ef5c75c 100644
--- a/net/phonet/datagram.c
+++ b/net/phonet/datagram.c
@@ -159,8 +159,11 @@ out_nofree:
 static int pn_backlog_rcv(struct sock *sk, struct sk_buff *skb)
 {
 	int err = sock_queue_rcv_skb(sk, skb);
-	if (err < 0)
+	if (err < 0) {
 		kfree_skb(skb);
+		if (err == -ENOMEM)
+			atomic_inc(&sk->sk_drops);
+	}
 	return err ? NET_RX_DROP : NET_RX_SUCCESS;
 }
 
-- 
1.6.0.4


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

* [PATCH] Phonet: account for dropped RX packets
  2009-07-21 11:57 ` [PATCH] Phonet: dropped datagrams accounting Rémi Denis-Courmont
@ 2009-07-21 11:57   ` Rémi Denis-Courmont
  2009-07-21 19:34     ` David Miller
  2009-07-21 19:35   ` [PATCH] Phonet: dropped datagrams accounting David Miller
  1 sibling, 1 reply; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-21 11:57 UTC (permalink / raw)
  To: netdev

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/pep.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index eef833e..b8252d2 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -346,8 +346,10 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 		break;
 
 	case PNS_PEP_CTRL_REQ:
-		if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX)
+		if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
+			atomic_inc(&sk->sk_drops);
 			break;
+		}
 		__skb_pull(skb, 4);
 		queue = &pn->ctrlreq_queue;
 		goto queue;
@@ -358,10 +360,13 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
 			err = sock_queue_rcv_skb(sk, skb);
 			if (!err)
 				return 0;
+			if (err == -ENOMEM)
+				atomic_inc(&sk->sk_drops);
 			break;
 		}
 
 		if (pn->rx_credits == 0) {
+			atomic_inc(&sk->sk_drops);
 			err = -ENOBUFS;
 			break;
 		}
-- 
1.6.0.4


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-21 11:57 [PATCH] Phonet: sockets list through proc_fs Rémi Denis-Courmont
  2009-07-21 11:57 ` [PATCH] Phonet: dropped datagrams accounting Rémi Denis-Courmont
@ 2009-07-21 19:34 ` David Miller
  2009-08-12 11:02   ` Rémi Denis-Courmont
  1 sibling, 1 reply; 25+ messages in thread
From: David Miller @ 2009-07-21 19:34 UTC (permalink / raw)
  To: remi.denis-courmont; +Cc: netdev

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Date: Tue, 21 Jul 2009 14:57:57 +0300

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> This provides a list of sockets with their Phonet bind addresses and
> some socket debug informations through /proc/net/phonet.
> 
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Applied.

But why don't you create a pn_sock_init() function so you don't
have to export so many things from socket.c?

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

* Re: [PATCH] Phonet: account for dropped RX packets
  2009-07-21 11:57   ` [PATCH] Phonet: account for dropped RX packets Rémi Denis-Courmont
@ 2009-07-21 19:34     ` David Miller
  0 siblings, 0 replies; 25+ messages in thread
From: David Miller @ 2009-07-21 19:34 UTC (permalink / raw)
  To: remi.denis-courmont; +Cc: netdev

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Date: Tue, 21 Jul 2009 14:57:59 +0300

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Applied.

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

* Re: [PATCH] Phonet: dropped datagrams accounting
  2009-07-21 11:57 ` [PATCH] Phonet: dropped datagrams accounting Rémi Denis-Courmont
  2009-07-21 11:57   ` [PATCH] Phonet: account for dropped RX packets Rémi Denis-Courmont
@ 2009-07-21 19:35   ` David Miller
  1 sibling, 0 replies; 25+ messages in thread
From: David Miller @ 2009-07-21 19:35 UTC (permalink / raw)
  To: remi.denis-courmont; +Cc: netdev

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Date: Tue, 21 Jul 2009 14:57:58 +0300

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> The per-socket drop count is visible via /proc/net/phonet.
> 
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Applied.

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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-21 19:34 ` [PATCH] Phonet: sockets list through proc_fs David Miller
@ 2009-08-12 11:02   ` Rémi Denis-Courmont
  2009-08-12 18:06     ` David Miller
  0 siblings, 1 reply; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-08-12 11:02 UTC (permalink / raw)
  To: netdev

On Tuesday 21 July 2009 22:34:49 ext David Miller wrote:
> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> Date: Tue, 21 Jul 2009 14:57:57 +0300
>
> > From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> >
> > This provides a list of sockets with their Phonet bind addresses and
> > some socket debug informations through /proc/net/phonet.
> >
> > Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
>
> Applied.
>
> But why don't you create a pn_sock_init() function so you don't
> have to export so many things from socket.c?

I simply did not think of the sole pn_sock_seq_fops as "so many things"... But 
I can change it if you think it would be better.

-- 
Rémi Denis-Courmont
Nokia Devices R&D, Maemo Software, Helsinki


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-08-12 11:02   ` Rémi Denis-Courmont
@ 2009-08-12 18:06     ` David Miller
  0 siblings, 0 replies; 25+ messages in thread
From: David Miller @ 2009-08-12 18:06 UTC (permalink / raw)
  To: remi.denis-courmont; +Cc: netdev

From: "Rémi Denis-Courmont" <remi.denis-courmont@nokia.com>
Date: Wed, 12 Aug 2009 14:02:25 +0300

> On Tuesday 21 July 2009 22:34:49 ext David Miller wrote:
>> But why don't you create a pn_sock_init() function so you don't
>> have to export so many things from socket.c?
>
> I simply did not think of the sole pn_sock_seq_fops as "so many
> things"... But I can change it if you think it would be better.

Maybe I'm exaggerating, but in any event the less you export from
a file the cleaner it tends to be.

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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 10:31           ` Eric Dumazet
@ 2009-08-03  2:42             ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 25+ messages in thread
From: Arnaldo Carvalho de Melo @ 2009-08-03  2:42 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Marcel Holtmann, Rémi Denis-Courmont, netdev

Em Mon, Jul 20, 2009 at 12:31:41PM +0200, Eric Dumazet escreveu:
> Marcel Holtmann a écrit :
> > Hi Remi,
> > 
> >>>>>> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> >>>>> isn't there are proper explaining commit message missing here?
> >>>> AFAIK, a one-liners stick to the Subject line.
> >>>>
> >>>> (I use explicit From: due to my broken Microsoft-provided MTA).
> >>> the From: is not the problem here. However it would be nice to have a
> >>> description of the change. Especially details like this is for debugging
> >>> or this is a public API or etc.
> >> It's just like most network protocols exposing their sockets list in 
> >> /proc/net. Debugging/monitoring indeed.
> > 
> > I think that for new protocols, we should not do this anymore and just
> > use debugfs. Since that is exactly its job.
> 
> netstat uses /proc/net
> 
> iproute2 uses netlink
> 
> Now you suggest adding debugfs support ?
> 
> What a mess...

Exactly, the proper way to do that is to have a base class for
inet_diag, net_diag, from where phone would be derived. But yeah, that
requires more work than cut'n'pasting from the old, /proc based way of
doing things 8-)

- Arnaldo

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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 14:09                     ` David Miller
@ 2009-07-20 14:25                       ` Marcel Holtmann
  0 siblings, 0 replies; 25+ messages in thread
From: Marcel Holtmann @ 2009-07-20 14:25 UTC (permalink / raw)
  To: David Miller; +Cc: remi.denis-courmont, netdev

Hi Dave,

> > in the end it is up to Dave, however I would put these things into
> > debugfs.
> 
> You're being rediculious.
> 
> Listing sockets is a standard facility, not a debugging thing.
> Just like listing processes.

fair enough. I would still have used debugfs ;)

Regards

Marcel



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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 13:00                   ` Marcel Holtmann
@ 2009-07-20 14:09                     ` David Miller
  2009-07-20 14:25                       ` Marcel Holtmann
  0 siblings, 1 reply; 25+ messages in thread
From: David Miller @ 2009-07-20 14:09 UTC (permalink / raw)
  To: marcel; +Cc: remi.denis-courmont, netdev

From: Marcel Holtmann <marcel@holtmann.org>
Date: Mon, 20 Jul 2009 15:00:40 +0200

> in the end it is up to Dave, however I would put these things into
> debugfs.

You're being rediculious.

Listing sockets is a standard facility, not a debugging thing.
Just like listing processes.


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 12:07               ` Marcel Holtmann
  2009-07-20 12:49                 ` Rémi Denis-Courmont
@ 2009-07-20 14:05                 ` David Miller
  1 sibling, 0 replies; 25+ messages in thread
From: David Miller @ 2009-07-20 14:05 UTC (permalink / raw)
  To: marcel; +Cc: remi.denis-courmont, netdev

From: Marcel Holtmann <marcel@holtmann.org>
Date: Mon, 20 Jul 2009 14:07:30 +0200

> And if we are talking about debugging information, then they should go
> into debugfs and not /proc. At least for new protocols.

Getting a list of active sockets is not, and never will be,
"debugging" information.

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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 12:49                 ` Rémi Denis-Courmont
@ 2009-07-20 13:00                   ` Marcel Holtmann
  2009-07-20 14:09                     ` David Miller
  0 siblings, 1 reply; 25+ messages in thread
From: Marcel Holtmann @ 2009-07-20 13:00 UTC (permalink / raw)
  To: Rémi Denis-Courmont; +Cc: netdev

Hi Remi,

> > > > On Monday 20 July 2009 13:21:01 ext Marcel Holtmann wrote:
> > > >> > It's just like most network protocols exposing their sockets list in
> > > >> > /proc/net. Debugging/monitoring indeed.
> > > >>
> > > >> I think that for new protocols, we should not do this anymore and just
> > > >> use debugfs. Since that is exactly its job.
> > > >
> > > > Requiring debugfs for something like 'netstat' sounds restrictive to
> > > > me...
> > >
> > > Me too.
> >
> > hold on, what has netstat to do with Phonet support?
> 
> First, I said "*like* netstat". Second, *net*stat has at least as much to do 
> with Pho*net* than it has with Unix sockets. I'm interested in monitoring 
> userland usage of Phonet sockets, not so much in debugging the kernel-mode 
> Phonet stack. I am not convinced that debugfs is the right tool at all here - 
> regardless whether we extend netstat or write a Phonet-specific tool.

in the end it is up to Dave, however I would put these things into
debugfs. Note that even something like mac80211 still provides a
wireless file here while most debugging is nowaydays in debugfs and it
might be better removed.

Regards

Marcel



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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 12:07               ` Marcel Holtmann
@ 2009-07-20 12:49                 ` Rémi Denis-Courmont
  2009-07-20 13:00                   ` Marcel Holtmann
  2009-07-20 14:05                 ` David Miller
  1 sibling, 1 reply; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-20 12:49 UTC (permalink / raw)
  To: netdev

On Monday 20 July 2009 15:07:30 ext Marcel Holtmann wrote:
> Hi Dave,
>
> > > On Monday 20 July 2009 13:21:01 ext Marcel Holtmann wrote:
> > >> > It's just like most network protocols exposing their sockets list in
> > >> > /proc/net. Debugging/monitoring indeed.
> > >>
> > >> I think that for new protocols, we should not do this anymore and just
> > >> use debugfs. Since that is exactly its job.
> > >
> > > Requiring debugfs for something like 'netstat' sounds restrictive to
> > > me...
> >
> > Me too.
>
> hold on, what has netstat to do with Phonet support?

First, I said "*like* netstat". Second, *net*stat has at least as much to do 
with Pho*net* than it has with Unix sockets. I'm interested in monitoring 
userland usage of Phonet sockets, not so much in debugging the kernel-mode 
Phonet stack. I am not convinced that debugfs is the right tool at all here - 
regardless whether we extend netstat or write a Phonet-specific tool.

> Does netstat now support Phonet or what are we trying to achieve here?

There is currently no Phonet socket monitoring hook. I guess you refer to 
backward compatibility, which -I would agree- is a non-issue.

-- 
Rémi Denis-Courmont
Nokia Devices R&D, Maemo Software, Helsinki


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 10:43             ` David Miller
@ 2009-07-20 12:07               ` Marcel Holtmann
  2009-07-20 12:49                 ` Rémi Denis-Courmont
  2009-07-20 14:05                 ` David Miller
  0 siblings, 2 replies; 25+ messages in thread
From: Marcel Holtmann @ 2009-07-20 12:07 UTC (permalink / raw)
  To: David Miller; +Cc: remi.denis-courmont, netdev

Hi Dave,

> > On Monday 20 July 2009 13:21:01 ext Marcel Holtmann wrote:
> >> > It's just like most network protocols exposing their sockets list in
> >> > /proc/net. Debugging/monitoring indeed.
> >>
> >> I think that for new protocols, we should not do this anymore and just
> >> use debugfs. Since that is exactly its job.
> > 
> > Requiring debugfs for something like 'netstat' sounds restrictive to me...
> 
> Me too.

hold on, what has netstat to do with Phonet support? Does netstat now
support Phonet or what are we trying to achieve here?

And if we are talking about debugging information, then they should go
into debugfs and not /proc. At least for new protocols.

Regards

Marcel



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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 10:32           ` Rémi Denis-Courmont
@ 2009-07-20 10:43             ` David Miller
  2009-07-20 12:07               ` Marcel Holtmann
  0 siblings, 1 reply; 25+ messages in thread
From: David Miller @ 2009-07-20 10:43 UTC (permalink / raw)
  To: remi.denis-courmont; +Cc: netdev

From: "Rémi Denis-Courmont" <remi.denis-courmont@nokia.com>
Date: Mon, 20 Jul 2009 13:32:04 +0300

> On Monday 20 July 2009 13:21:01 ext Marcel Holtmann wrote:
>> > It's just like most network protocols exposing their sockets list in
>> > /proc/net. Debugging/monitoring indeed.
>>
>> I think that for new protocols, we should not do this anymore and just
>> use debugfs. Since that is exactly its job.
> 
> Requiring debugfs for something like 'netstat' sounds restrictive to me...

Me too.

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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 10:21         ` Marcel Holtmann
  2009-07-20 10:31           ` Eric Dumazet
@ 2009-07-20 10:32           ` Rémi Denis-Courmont
  2009-07-20 10:43             ` David Miller
  1 sibling, 1 reply; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-20 10:32 UTC (permalink / raw)
  To: netdev

On Monday 20 July 2009 13:21:01 ext Marcel Holtmann wrote:
> > It's just like most network protocols exposing their sockets list in
> > /proc/net. Debugging/monitoring indeed.
>
> I think that for new protocols, we should not do this anymore and just
> use debugfs. Since that is exactly its job.

Requiring debugfs for something like 'netstat' sounds restrictive to me...

-- 
Rémi Denis-Courmont
Nokia Devices R&D, Maemo Software, Helsinki


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20 10:21         ` Marcel Holtmann
@ 2009-07-20 10:31           ` Eric Dumazet
  2009-08-03  2:42             ` Arnaldo Carvalho de Melo
  2009-07-20 10:32           ` Rémi Denis-Courmont
  1 sibling, 1 reply; 25+ messages in thread
From: Eric Dumazet @ 2009-07-20 10:31 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Rémi Denis-Courmont, netdev

Marcel Holtmann a écrit :
> Hi Remi,
> 
>>>>>> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
>>>>> isn't there are proper explaining commit message missing here?
>>>> AFAIK, a one-liners stick to the Subject line.
>>>>
>>>> (I use explicit From: due to my broken Microsoft-provided MTA).
>>> the From: is not the problem here. However it would be nice to have a
>>> description of the change. Especially details like this is for debugging
>>> or this is a public API or etc.
>> It's just like most network protocols exposing their sockets list in 
>> /proc/net. Debugging/monitoring indeed.
> 
> I think that for new protocols, we should not do this anymore and just
> use debugfs. Since that is exactly its job.

netstat uses /proc/net

iproute2 uses netlink

Now you suggest adding debugfs support ?

What a mess...


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20  9:47       ` Rémi Denis-Courmont
@ 2009-07-20 10:21         ` Marcel Holtmann
  2009-07-20 10:31           ` Eric Dumazet
  2009-07-20 10:32           ` Rémi Denis-Courmont
  0 siblings, 2 replies; 25+ messages in thread
From: Marcel Holtmann @ 2009-07-20 10:21 UTC (permalink / raw)
  To: Rémi Denis-Courmont; +Cc: netdev

Hi Remi,

> > > > > From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> > > >
> > > > isn't there are proper explaining commit message missing here?
> > >
> > > AFAIK, a one-liners stick to the Subject line.
> > >
> > > (I use explicit From: due to my broken Microsoft-provided MTA).
> >
> > the From: is not the problem here. However it would be nice to have a
> > description of the change. Especially details like this is for debugging
> > or this is a public API or etc.
> 
> It's just like most network protocols exposing their sockets list in 
> /proc/net. Debugging/monitoring indeed.

I think that for new protocols, we should not do this anymore and just
use debugfs. Since that is exactly its job.

Regards

Marcel



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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20  9:34     ` Marcel Holtmann
@ 2009-07-20  9:47       ` Rémi Denis-Courmont
  2009-07-20 10:21         ` Marcel Holtmann
  0 siblings, 1 reply; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-20  9:47 UTC (permalink / raw)
  To: netdev

On Monday 20 July 2009 12:34:47 ext Marcel Holtmann wrote:
> Hi Remi,
>
> > > > From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> > >
> > > isn't there are proper explaining commit message missing here?
> >
> > AFAIK, a one-liners stick to the Subject line.
> >
> > (I use explicit From: due to my broken Microsoft-provided MTA).
>
> the From: is not the problem here. However it would be nice to have a
> description of the change. Especially details like this is for debugging
> or this is a public API or etc.

It's just like most network protocols exposing their sockets list in 
/proc/net. Debugging/monitoring indeed.

-- 
Rémi Denis-Courmont
Nokia Devices R&D, Maemo Software, Helsinki


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20  9:28   ` Rémi Denis-Courmont
@ 2009-07-20  9:34     ` Marcel Holtmann
  2009-07-20  9:47       ` Rémi Denis-Courmont
  0 siblings, 1 reply; 25+ messages in thread
From: Marcel Holtmann @ 2009-07-20  9:34 UTC (permalink / raw)
  To: Rémi Denis-Courmont; +Cc: netdev

Hi Remi,

> > > From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> >
> > isn't there are proper explaining commit message missing here?
> 
> AFAIK, a one-liners stick to the Subject line.
> 
> (I use explicit From: due to my broken Microsoft-provided MTA).

the From: is not the problem here. However it would be nice to have a
description of the change. Especially details like this is for debugging
or this is a public API or etc.

Regards

Marcel



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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20  8:36 ` Marcel Holtmann
@ 2009-07-20  9:28   ` Rémi Denis-Courmont
  2009-07-20  9:34     ` Marcel Holtmann
  0 siblings, 1 reply; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-20  9:28 UTC (permalink / raw)
  To: netdev

On Monday 20 July 2009 11:36:55 ext Marcel Holtmann wrote:
> Hi Remi,
>
> > From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
>
> isn't there are proper explaining commit message missing here?

AFAIK, a one-liners stick to the Subject line.

(I use explicit From: due to my broken Microsoft-provided MTA).

-- 
Rémi Denis-Courmont
Nokia Devices R&D, Maemo Software, Helsinki


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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20  8:34 Rémi Denis-Courmont
  2009-07-20  8:36 ` Marcel Holtmann
@ 2009-07-20  9:05 ` Eric Dumazet
  1 sibling, 0 replies; 25+ messages in thread
From: Eric Dumazet @ 2009-07-20  9:05 UTC (permalink / raw)
  To: Rémi Denis-Courmont; +Cc: netdev

Rémi Denis-Courmont a écrit :
> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 

> +static int pn_sock_seq_show(struct seq_file *seq, void *v)
> +{
> +	int len;
> +
> +	if (v == SEQ_START_TOKEN)
> +		seq_printf(seq, "%s%n", "pt  loc  rem rs st tx_queue rx_queue "
> +			"  uid inode ref pointer drops", &len);
> +	else {
> +		struct sock *sk = v;
> +		struct pn_sock *pn = pn_sk(sk);
> +
> +		seq_printf(seq, "%2d %04X:%04X:%02X %02X %08X:%08X %5d %lu "
> +			"%d %p %d%n",
> +			sk->sk_protocol, pn->sobject, 0, pn->resource,
> +			sk->sk_state,
> +			atomic_read(&sk->sk_wmem_alloc),
> +			atomic_read(&sk->sk_rmem_alloc),

Please use sk_wmem_alloc_get(sk) and  sk_rmem_alloc_get(sk)

> +			sock_i_uid(sk), sock_i_ino(sk),
> +			atomic_read(&sk->sk_refcnt), sk,
> +			atomic_read(&sk->sk_drops), &len);
> +	}
> +	seq_printf(seq, "%*s\n", 127 - len, "");
> +	return 0;
> +}

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

* Re: [PATCH] Phonet: sockets list through proc_fs
  2009-07-20  8:34 Rémi Denis-Courmont
@ 2009-07-20  8:36 ` Marcel Holtmann
  2009-07-20  9:28   ` Rémi Denis-Courmont
  2009-07-20  9:05 ` Eric Dumazet
  1 sibling, 1 reply; 25+ messages in thread
From: Marcel Holtmann @ 2009-07-20  8:36 UTC (permalink / raw)
  To: Rémi Denis-Courmont; +Cc: netdev

Hi Remi,

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

isn't there are proper explaining commit message missing here?

> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> ---
>  include/net/phonet/pn_dev.h |    2 +
>  net/phonet/pn_dev.c         |    7 +++
>  net/phonet/socket.c         |   97 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 106 insertions(+), 0 deletions(-)
> 
> diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
> index 29d1267..44c923c 100644
> --- a/include/net/phonet/pn_dev.h
> +++ b/include/net/phonet/pn_dev.h
> @@ -49,4 +49,6 @@ void phonet_address_notify(int event, struct net_device *dev, u8 addr);
>  
>  #define PN_NO_ADDR	0xff
>  
> +extern const struct file_operations pn_sock_seq_fops;
> +
>  #endif
> diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
> index b0d6ddd..5107b79 100644
> --- a/net/phonet/pn_dev.c
> +++ b/net/phonet/pn_dev.c
> @@ -218,6 +218,11 @@ static int phonet_init_net(struct net *net)
>  	if (!pnn)
>  		return -ENOMEM;
>  
> +	if (!proc_net_fops_create(net, "phonet", 0, &pn_sock_seq_fops)) {
> +		kfree(pnn);
> +		return -ENOMEM;
> +	}
> +
>  	INIT_LIST_HEAD(&pnn->pndevs.list);
>  	spin_lock_init(&pnn->pndevs.lock);
>  	net_assign_generic(net, phonet_net_id, pnn);
> @@ -233,6 +238,8 @@ static void phonet_exit_net(struct net *net)
>  	for_each_netdev(net, dev)
>  		phonet_device_destroy(dev);
>  	rtnl_unlock();
> +
> +	proc_net_remove(net, "phonet");
>  	kfree(pnn);
>  }
>  
> diff --git a/net/phonet/socket.c b/net/phonet/socket.c
> index ada2a35..2a99851 100644
> --- a/net/phonet/socket.c
> +++ b/net/phonet/socket.c
> @@ -412,3 +412,100 @@ found:
>  	return 0;
>  }
>  EXPORT_SYMBOL(pn_sock_get_port);
> +
> +static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos)
> +{
> +	struct net *net = seq_file_net(seq);
> +	struct hlist_node *node;
> +	struct sock *sknode;
> +
> +	sk_for_each(sknode, node, &pnsocks.hlist) {
> +		if (!net_eq(net, sock_net(sknode)))
> +			continue;
> +		if (!pos)
> +			return sknode;
> +		pos--;
> +	}
> +	return NULL;
> +}
> +
> +static struct sock *pn_sock_get_next(struct seq_file *seq, struct sock *sk)
> +{
> +	struct net *net = seq_file_net(seq);
> +
> +	do
> +		sk = sk_next(sk);
> +	while (sk && !net_eq(net, sock_net(sk)));
> +
> +	return sk;
> +}
> +
> +static void *pn_sock_seq_start(struct seq_file *seq, loff_t *pos)
> +	__acquires(pnsocks.lock)
> +{
> +	spin_lock_bh(&pnsocks.lock);
> +	return *pos ? pn_sock_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
> +}
> +
> +static void *pn_sock_seq_next(struct seq_file *seq, void *v, loff_t *pos)
> +{
> +	struct sock *sk;
> +
> +	if (v == SEQ_START_TOKEN)
> +		sk = pn_sock_get_idx(seq, 0);
> +	else
> +		sk = pn_sock_get_next(seq, v);
> +	(*pos)++;
> +	return sk;
> +}
> +
> +static void pn_sock_seq_stop(struct seq_file *seq, void *v)
> +	__releases(pnsocks.lock)
> +{
> +	spin_unlock_bh(&pnsocks.lock);
> +}
> +
> +static int pn_sock_seq_show(struct seq_file *seq, void *v)
> +{
> +	int len;
> +
> +	if (v == SEQ_START_TOKEN)
> +		seq_printf(seq, "%s%n", "pt  loc  rem rs st tx_queue rx_queue "
> +			"  uid inode ref pointer drops", &len);
> +	else {
> +		struct sock *sk = v;
> +		struct pn_sock *pn = pn_sk(sk);
> +
> +		seq_printf(seq, "%2d %04X:%04X:%02X %02X %08X:%08X %5d %lu "
> +			"%d %p %d%n",
> +			sk->sk_protocol, pn->sobject, 0, pn->resource,
> +			sk->sk_state,
> +			atomic_read(&sk->sk_wmem_alloc),
> +			atomic_read(&sk->sk_rmem_alloc),
> +			sock_i_uid(sk), sock_i_ino(sk),
> +			atomic_read(&sk->sk_refcnt), sk,
> +			atomic_read(&sk->sk_drops), &len);
> +	}
> +	seq_printf(seq, "%*s\n", 127 - len, "");
> +	return 0;
> +}

The more appropriate place for this would be debugfs.

Regards

Marcel



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

* [PATCH] Phonet: sockets list through proc_fs
@ 2009-07-20  8:34 Rémi Denis-Courmont
  2009-07-20  8:36 ` Marcel Holtmann
  2009-07-20  9:05 ` Eric Dumazet
  0 siblings, 2 replies; 25+ messages in thread
From: Rémi Denis-Courmont @ 2009-07-20  8:34 UTC (permalink / raw)
  To: netdev

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/net/phonet/pn_dev.h |    2 +
 net/phonet/pn_dev.c         |    7 +++
 net/phonet/socket.c         |   97 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index 29d1267..44c923c 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -49,4 +49,6 @@ void phonet_address_notify(int event, struct net_device *dev, u8 addr);
 
 #define PN_NO_ADDR	0xff
 
+extern const struct file_operations pn_sock_seq_fops;
+
 #endif
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index b0d6ddd..5107b79 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -218,6 +218,11 @@ static int phonet_init_net(struct net *net)
 	if (!pnn)
 		return -ENOMEM;
 
+	if (!proc_net_fops_create(net, "phonet", 0, &pn_sock_seq_fops)) {
+		kfree(pnn);
+		return -ENOMEM;
+	}
+
 	INIT_LIST_HEAD(&pnn->pndevs.list);
 	spin_lock_init(&pnn->pndevs.lock);
 	net_assign_generic(net, phonet_net_id, pnn);
@@ -233,6 +238,8 @@ static void phonet_exit_net(struct net *net)
 	for_each_netdev(net, dev)
 		phonet_device_destroy(dev);
 	rtnl_unlock();
+
+	proc_net_remove(net, "phonet");
 	kfree(pnn);
 }
 
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index ada2a35..2a99851 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -412,3 +412,100 @@ found:
 	return 0;
 }
 EXPORT_SYMBOL(pn_sock_get_port);
+
+static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos)
+{
+	struct net *net = seq_file_net(seq);
+	struct hlist_node *node;
+	struct sock *sknode;
+
+	sk_for_each(sknode, node, &pnsocks.hlist) {
+		if (!net_eq(net, sock_net(sknode)))
+			continue;
+		if (!pos)
+			return sknode;
+		pos--;
+	}
+	return NULL;
+}
+
+static struct sock *pn_sock_get_next(struct seq_file *seq, struct sock *sk)
+{
+	struct net *net = seq_file_net(seq);
+
+	do
+		sk = sk_next(sk);
+	while (sk && !net_eq(net, sock_net(sk)));
+
+	return sk;
+}
+
+static void *pn_sock_seq_start(struct seq_file *seq, loff_t *pos)
+	__acquires(pnsocks.lock)
+{
+	spin_lock_bh(&pnsocks.lock);
+	return *pos ? pn_sock_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
+}
+
+static void *pn_sock_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+	struct sock *sk;
+
+	if (v == SEQ_START_TOKEN)
+		sk = pn_sock_get_idx(seq, 0);
+	else
+		sk = pn_sock_get_next(seq, v);
+	(*pos)++;
+	return sk;
+}
+
+static void pn_sock_seq_stop(struct seq_file *seq, void *v)
+	__releases(pnsocks.lock)
+{
+	spin_unlock_bh(&pnsocks.lock);
+}
+
+static int pn_sock_seq_show(struct seq_file *seq, void *v)
+{
+	int len;
+
+	if (v == SEQ_START_TOKEN)
+		seq_printf(seq, "%s%n", "pt  loc  rem rs st tx_queue rx_queue "
+			"  uid inode ref pointer drops", &len);
+	else {
+		struct sock *sk = v;
+		struct pn_sock *pn = pn_sk(sk);
+
+		seq_printf(seq, "%2d %04X:%04X:%02X %02X %08X:%08X %5d %lu "
+			"%d %p %d%n",
+			sk->sk_protocol, pn->sobject, 0, pn->resource,
+			sk->sk_state,
+			atomic_read(&sk->sk_wmem_alloc),
+			atomic_read(&sk->sk_rmem_alloc),
+			sock_i_uid(sk), sock_i_ino(sk),
+			atomic_read(&sk->sk_refcnt), sk,
+			atomic_read(&sk->sk_drops), &len);
+	}
+	seq_printf(seq, "%*s\n", 127 - len, "");
+	return 0;
+}
+
+static const struct seq_operations pn_sock_seq_ops = {
+	.start = pn_sock_seq_start,
+	.next = pn_sock_seq_next,
+	.stop = pn_sock_seq_stop,
+	.show = pn_sock_seq_show,
+};
+
+static int pn_sock_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &pn_sock_seq_ops);
+}
+
+const struct file_operations pn_sock_seq_fops = {
+	.owner = THIS_MODULE,
+	.open = pn_sock_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = seq_release,
+};
-- 
1.6.0.4


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

end of thread, other threads:[~2009-08-12 18:06 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-21 11:57 [PATCH] Phonet: sockets list through proc_fs Rémi Denis-Courmont
2009-07-21 11:57 ` [PATCH] Phonet: dropped datagrams accounting Rémi Denis-Courmont
2009-07-21 11:57   ` [PATCH] Phonet: account for dropped RX packets Rémi Denis-Courmont
2009-07-21 19:34     ` David Miller
2009-07-21 19:35   ` [PATCH] Phonet: dropped datagrams accounting David Miller
2009-07-21 19:34 ` [PATCH] Phonet: sockets list through proc_fs David Miller
2009-08-12 11:02   ` Rémi Denis-Courmont
2009-08-12 18:06     ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2009-07-20  8:34 Rémi Denis-Courmont
2009-07-20  8:36 ` Marcel Holtmann
2009-07-20  9:28   ` Rémi Denis-Courmont
2009-07-20  9:34     ` Marcel Holtmann
2009-07-20  9:47       ` Rémi Denis-Courmont
2009-07-20 10:21         ` Marcel Holtmann
2009-07-20 10:31           ` Eric Dumazet
2009-08-03  2:42             ` Arnaldo Carvalho de Melo
2009-07-20 10:32           ` Rémi Denis-Courmont
2009-07-20 10:43             ` David Miller
2009-07-20 12:07               ` Marcel Holtmann
2009-07-20 12:49                 ` Rémi Denis-Courmont
2009-07-20 13:00                   ` Marcel Holtmann
2009-07-20 14:09                     ` David Miller
2009-07-20 14:25                       ` Marcel Holtmann
2009-07-20 14:05                 ` David Miller
2009-07-20  9:05 ` Eric Dumazet

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.