* [PATCH 1/8] /proc/net/ entries for bluetooth protocols
@ 2012-06-14 17:15 Masatake YAMATO
2012-06-15 8:00 ` Andrei Emeltchenko
0 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-14 17:15 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
lsof command can tell the type of socket processes are using. Internally
lsof uses inode numbers on socket fs as key to resolve the type of
sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
such inode information.
Unfortunately bluetooth related protocols don't provide such inode
information. This patch series introduces /proc/net/* files for the protocols.
This patch against af_bluetooth.c provides facility to the implementation
of protocols. This patch extends bt_sock_list and introduces two exported
function bt_procfs_init, bt_procfs_cleanup.
The type bt_sock_list is already used in some implementations of
protocols. bt_procfs_init prepares seq_operations which converts
protocol own bt_sock_list data to /proc/net proc entry for the
protocol when the entry is accessed by cat or something process.
What I, lsof user, need is just inode number of bluetooth
socket. Therefore default show handler of seq_operations
prints bluetooth socket common informations including inode
number.
However, people may want more information. The bt_procfs_init
takes a function pointer for customizing the show handler of
seq_operations.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
include/net/bluetooth/bluetooth.h | 12 ++++
net/bluetooth/af_bluetooth.c | 136 +++++++++++++++++++++++++++++++++++++
2 files changed, 148 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 961669b..83a1d1a 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -30,6 +30,9 @@
#include <linux/list.h>
#include <linux/poll.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
+
+
#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
@@ -205,6 +208,10 @@ enum {
struct bt_sock_list {
struct hlist_head head;
rwlock_t lock;
+#ifdef CONFIG_PROC_FS
+ struct file_operations fops;
+ int (* custom_seq_show)(struct seq_file *, void *);
+#endif
};
int bt_sock_register(int proto, const struct net_proto_family *ops);
@@ -293,6 +300,11 @@ extern void hci_sock_cleanup(void);
extern int bt_sysfs_init(void);
extern void bt_sysfs_cleanup(void);
+extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
+ struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *));
+extern void bt_procfs_cleanup(struct net *net, const char *name);
+
extern struct dentry *bt_debugfs;
int l2cap_init(void);
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 46e7f86..81a2094 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -542,6 +543,141 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
}
EXPORT_SYMBOL(bt_sock_wait_state);
+#ifdef CONFIG_PROC_FS
+struct bt_seq_state {
+ struct bt_sock_list *l;
+};
+
+static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+
+ read_lock(&s->l->lock);
+ return seq_hlist_start_head(&s->l->head, *pos);
+}
+
+static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+
+ return seq_hlist_next(v, &s->l->head, pos);
+}
+
+static void bt_seq_stop(struct seq_file *seq, void *v)
+{
+ struct bt_seq_state *s = seq->private;
+
+ read_unlock(&s->l->lock);
+}
+
+static int bt_seq_show(struct seq_file *seq, void *v)
+{
+ struct sock *sk;
+ struct bt_sock *bt;
+ struct bt_seq_state *s = seq->private;
+
+
+ if (v == SEQ_START_TOKEN) {
+ seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
+
+ if (s->l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ s->l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ }
+ else {
+ sk = sk_entry(v);
+ bt = bt_sk(sk);
+ seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu",
+ sk,
+ atomic_read(&sk->sk_refcnt),
+ sk_rmem_alloc_get(sk),
+ sk_wmem_alloc_get(sk),
+ sock_i_uid(sk),
+ sock_i_ino(sk)
+ );
+ seq_puts(seq, batostr(&bt->src));
+ seq_putc(seq, ' ');
+ seq_puts(seq, batostr(&bt->dst));
+ seq_putc(seq, ' ');
+ seq_printf(seq, "%-6lu", bt->parent? sock_i_ino(bt->parent): 0LU);
+
+ if (s->l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ s->l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ }
+ return 0;
+}
+
+static struct seq_operations bt_seq_ops = {
+ .start = bt_seq_start,
+ .next = bt_seq_next,
+ .stop = bt_seq_stop,
+ .show = bt_seq_show,
+};
+
+static int bt_seq_open(struct inode *inode, struct file *file)
+{
+ struct bt_sock_list *sk_list;
+ struct bt_seq_state *s;
+
+ sk_list = PDE(inode)->data;
+ s = __seq_open_private(file, &bt_seq_ops,
+ sizeof(struct bt_seq_state));
+ if (s == NULL)
+ return -ENOMEM;
+
+ s->l = sk_list;
+ return 0;
+}
+
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ struct proc_dir_entry * pde;
+
+ sk_list->custom_seq_show = seq_show;
+
+ sk_list->fops.owner = module;
+ sk_list->fops.open = bt_seq_open;
+ sk_list->fops.read = seq_read;
+ sk_list->fops.llseek = seq_lseek;
+ sk_list->fops.release = seq_release_private;
+
+ pde = proc_net_fops_create(net, name, 0, &sk_list->fops);
+ if (pde == NULL)
+ return -ENOMEM;
+
+ pde->data = sk_list;
+
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+ proc_net_remove(net, name);
+}
+#else
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+}
+#endif
+
+EXPORT_SYMBOL(bt_procfs_init);
+EXPORT_SYMBOL(bt_procfs_cleanup);
+
+
static struct net_proto_family bt_sock_family_ops = {
.owner = THIS_MODULE,
.family = PF_BLUETOOTH,
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH 1/8] /proc/net/ entries for bluetooth protocols
2012-06-14 17:15 [PATCH 1/8] /proc/net/ entries for bluetooth protocols Masatake YAMATO
@ 2012-06-15 8:00 ` Andrei Emeltchenko
2012-06-17 0:26 ` Masatake YAMATO
` (8 more replies)
0 siblings, 9 replies; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-06-15 8:00 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
small nitpicks
On Fri, Jun 15, 2012 at 02:15:53AM +0900, Masatake YAMATO wrote:
> lsof command can tell the type of socket processes are using. Internally
> lsof uses inode numbers on socket fs as key to resolve the type of
> sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
> such inode information.
>
> Unfortunately bluetooth related protocols don't provide such inode
> information. This patch series introduces /proc/net/* files for the protocols.
>
>
> This patch against af_bluetooth.c provides facility to the implementation
> of protocols. This patch extends bt_sock_list and introduces two exported
> function bt_procfs_init, bt_procfs_cleanup.
>
> The type bt_sock_list is already used in some implementations of
> protocols. bt_procfs_init prepares seq_operations which converts
> protocol own bt_sock_list data to /proc/net proc entry for the
> protocol when the entry is accessed by cat or something process.
>
> What I, lsof user, need is just inode number of bluetooth
> socket. Therefore default show handler of seq_operations
> prints bluetooth socket common informations including inode
> number.
>
> However, people may want more information. The bt_procfs_init
> takes a function pointer for customizing the show handler of
> seq_operations.
>
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
> include/net/bluetooth/bluetooth.h | 12 ++++
> net/bluetooth/af_bluetooth.c | 136 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 148 insertions(+)
>
> diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> index 961669b..83a1d1a 100644
> --- a/include/net/bluetooth/bluetooth.h
> +++ b/include/net/bluetooth/bluetooth.h
> @@ -30,6 +30,9 @@
> #include <linux/list.h>
> #include <linux/poll.h>
> #include <net/sock.h>
> +#include <linux/seq_file.h>
> +
> +
>
Too much spaces here!
> #ifndef AF_BLUETOOTH
> #define AF_BLUETOOTH 31
> @@ -205,6 +208,10 @@ enum {
> struct bt_sock_list {
> struct hlist_head head;
> rwlock_t lock;
> +#ifdef CONFIG_PROC_FS
> + struct file_operations fops;
> + int (* custom_seq_show)(struct seq_file *, void *);
> +#endif
> };
>
> int bt_sock_register(int proto, const struct net_proto_family *ops);
> @@ -293,6 +300,11 @@ extern void hci_sock_cleanup(void);
> extern int bt_sysfs_init(void);
> extern void bt_sysfs_cleanup(void);
>
> +extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
> + struct bt_sock_list* sk_list,
> + int (* seq_show)(struct seq_file *, void *));
> +extern void bt_procfs_cleanup(struct net *net, const char *name);
> +
> extern struct dentry *bt_debugfs;
>
> int l2cap_init(void);
> diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
> index 46e7f86..81a2094 100644
> --- a/net/bluetooth/af_bluetooth.c
> +++ b/net/bluetooth/af_bluetooth.c
> @@ -542,6 +543,141 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
> }
> EXPORT_SYMBOL(bt_sock_wait_state);
>
> +#ifdef CONFIG_PROC_FS
> +struct bt_seq_state {
> + struct bt_sock_list *l;
> +};
> +
> +static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
> +{
> + struct bt_seq_state *s = seq->private;
> +
> + read_lock(&s->l->lock);
> + return seq_hlist_start_head(&s->l->head, *pos);
maybe define s->l as a local variable?
> +}
> +
> +static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
> +{
> + struct bt_seq_state *s = seq->private;
> +
> + return seq_hlist_next(v, &s->l->head, pos);
> +}
> +
> +static void bt_seq_stop(struct seq_file *seq, void *v)
> +{
> + struct bt_seq_state *s = seq->private;
> +
> + read_unlock(&s->l->lock);
> +}
> +
> +static int bt_seq_show(struct seq_file *seq, void *v)
> +{
> + struct sock *sk;
> + struct bt_sock *bt;
> + struct bt_seq_state *s = seq->private;
> +
> +
> + if (v == SEQ_START_TOKEN) {
> + seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
> +
> + if (s->l->custom_seq_show) {
> + seq_putc(seq, ' ');
> + s->l->custom_seq_show(seq, v);
> + }
> +
> + seq_putc(seq, '\n');
> + }
> + else {
shall be "} else {"
> + sk = sk_entry(v);
> + bt = bt_sk(sk);
> + seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu",
> + sk,
> + atomic_read(&sk->sk_refcnt),
> + sk_rmem_alloc_get(sk),
> + sk_wmem_alloc_get(sk),
> + sock_i_uid(sk),
> + sock_i_ino(sk)
> + );
> + seq_puts(seq, batostr(&bt->src));
batostr looks OK now but this will be outdated soon by %pMR.
> + seq_putc(seq, ' ');
> + seq_puts(seq, batostr(&bt->dst));
> + seq_putc(seq, ' ');
> + seq_printf(seq, "%-6lu", bt->parent? sock_i_ino(bt->parent): 0LU);
> +
> + if (s->l->custom_seq_show) {
> + seq_putc(seq, ' ');
> + s->l->custom_seq_show(seq, v);
> + }
> +
> + seq_putc(seq, '\n');
> + }
> + return 0;
> +}
> +
> +static struct seq_operations bt_seq_ops = {
> + .start = bt_seq_start,
> + .next = bt_seq_next,
> + .stop = bt_seq_stop,
> + .show = bt_seq_show,
> +};
> +
> +static int bt_seq_open(struct inode *inode, struct file *file)
> +{
> + struct bt_sock_list *sk_list;
> + struct bt_seq_state *s;
> +
> + sk_list = PDE(inode)->data;
> + s = __seq_open_private(file, &bt_seq_ops,
> + sizeof(struct bt_seq_state));
> + if (s == NULL)
> + return -ENOMEM;
> +
> + s->l = sk_list;
> + return 0;
> +}
> +
> +int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
> + int (* seq_show)(struct seq_file *, void *))
> +{
> + struct proc_dir_entry * pde;
> +
> + sk_list->custom_seq_show = seq_show;
> +
> + sk_list->fops.owner = module;
> + sk_list->fops.open = bt_seq_open;
> + sk_list->fops.read = seq_read;
> + sk_list->fops.llseek = seq_lseek;
> + sk_list->fops.release = seq_release_private;
> +
> + pde = proc_net_fops_create(net, name, 0, &sk_list->fops);
> + if (pde == NULL)
> + return -ENOMEM;
> +
> + pde->data = sk_list;
> +
> + return 0;
> +}
> +
> +void bt_procfs_cleanup(struct net *net, const char *name)
> +{
> + proc_net_remove(net, name);
> +}
> +#else
> +int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
> + int (* seq_show)(struct seq_file *, void *))
> +{
> + return 0;
> +}
> +
> +void bt_procfs_cleanup(struct net *net, const char *name)
> +{
> +}
> +#endif
> +
> +EXPORT_SYMBOL(bt_procfs_init);
> +EXPORT_SYMBOL(bt_procfs_cleanup);
> +
> +
too much spaces
> static struct net_proto_family bt_sock_family_ops = {
> .owner = THIS_MODULE,
> .family = PF_BLUETOOTH,
> --
> 1.7.10.2
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH 1/8] /proc/net/ entries for bluetooth protocols
2012-06-15 8:00 ` Andrei Emeltchenko
@ 2012-06-17 0:26 ` Masatake YAMATO
2012-06-18 8:28 ` Andrei Emeltchenko
2012-06-18 10:00 ` [PATCH v2 1/8] " Masatake YAMATO
` (7 subsequent siblings)
8 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-17 0:26 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Hi,
Thank you for reviewing.
I have a question.
>> + sk = sk_entry(v);
>> + bt = bt_sk(sk);
>> + seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu",
>> + sk,
>> + atomic_read(&sk->sk_refcnt),
>> + sk_rmem_alloc_get(sk),
>> + sk_wmem_alloc_get(sk),
>> + sock_i_uid(sk),
>> + sock_i_ino(sk)
>> + );
>> + seq_puts(seq, batostr(&bt->src));
>
> batostr looks OK now but this will be outdated soon by %pMR.
As far as reading Documentation/printk-formats.txt and
pointer() in lib/vsprintf.c, %pMR is not defined.
I guess you mean %pM, don't you?
I've tried following code, and it works as expected.
baswap(&src_baswapped, &bt->src);
baswap(&dst_baswapped, &bt->dst);
seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
sk,
atomic_read(&sk->sk_refcnt),
sk_rmem_alloc_get(sk),
sk_wmem_alloc_get(sk),
sock_i_uid(sk),
sock_i_ino(sk),
&src_baswapped,
&dst_baswapped,
bt->parent? sock_i_ino(bt->parent): 0LU);
Masatake YAMATO
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH 1/8] /proc/net/ entries for bluetooth protocols
2012-06-17 0:26 ` Masatake YAMATO
@ 2012-06-18 8:28 ` Andrei Emeltchenko
2012-06-28 17:02 ` Masatake YAMATO
0 siblings, 1 reply; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-06-18 8:28 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Sun, Jun 17, 2012 at 09:26:37AM +0900, Masatake YAMATO wrote:
> Hi,
>
> Thank you for reviewing.
> I have a question.
>
> >> + sk = sk_entry(v);
> >> + bt = bt_sk(sk);
> >> + seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu",
> >> + sk,
> >> + atomic_read(&sk->sk_refcnt),
> >> + sk_rmem_alloc_get(sk),
> >> + sk_wmem_alloc_get(sk),
> >> + sock_i_uid(sk),
> >> + sock_i_ino(sk)
> >> + );
> >> + seq_puts(seq, batostr(&bt->src));
> >
> > batostr looks OK now but this will be outdated soon by %pMR.
>
> As far as reading Documentation/printk-formats.txt and
> pointer() in lib/vsprintf.c, %pMR is not defined.
> I guess you mean %pM, don't you?
Sorry for confusion, I meant my patch adding new printf specifier which
is not yet in the tree. I think it will take longer time to be accepted
then your patch.
> I've tried following code, and it works as expected.
>
> baswap(&src_baswapped, &bt->src);
> baswap(&dst_baswapped, &bt->dst);
>
> seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
> sk,
> atomic_read(&sk->sk_refcnt),
> sk_rmem_alloc_get(sk),
> sk_wmem_alloc_get(sk),
> sock_i_uid(sk),
> sock_i_ino(sk),
> &src_baswapped,
> &dst_baswapped,
> bt->parent? sock_i_ino(bt->parent): 0LU);
>
Please use whatever method best suits for you although I prefer second
solution since it is easier to change to %pMR later.
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v2 1/8] /proc/net/ entries for bluetooth protocols
2012-06-15 8:00 ` Andrei Emeltchenko
2012-06-17 0:26 ` Masatake YAMATO
@ 2012-06-18 10:00 ` Masatake YAMATO
2012-07-10 14:06 ` Andrei Emeltchenko
2012-06-18 10:00 ` [PATCH v2 2/8] Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
` (6 subsequent siblings)
8 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:00 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
(I reflected the result of reviewing by Andrei.)
lsof command can tell the type of socket processes are using.
Internal lsof uses inode numbers on socket fs to resolve the type of
sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
such inode information.
Unfortunately bluetooth related protocols don't provide such inode
information. This patch series introduces /proc/net files for the protocols.
This patch against af_bluetooth.c provides facility to the implementation
of protocols. This patch extends bt_sock_list and introduces two exported
function bt_procfs_init, bt_procfs_cleanup.
The type bt_sock_list is already used in some of implementation of
protocols. bt_procfs_init prepare seq_operations which converts
protocol own bt_sock_list data to protocol own proc entry when the
entry is accessed.
What I, lsof user, need is just inode number of bluetooth
socket. However, people may want more information. The bt_procfs_init
takes a function pointer for customizing the show handler of
seq_operations.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
include/net/bluetooth/bluetooth.h | 10 +++
net/bluetooth/af_bluetooth.c | 136 +++++++++++++++++++++++++++++++++++++
2 files changed, 146 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 961669b..9c44977 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -30,6 +30,7 @@
#include <linux/list.h>
#include <linux/poll.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
@@ -205,6 +206,10 @@ enum {
struct bt_sock_list {
struct hlist_head head;
rwlock_t lock;
+#ifdef CONFIG_PROC_FS
+ struct file_operations fops;
+ int (* custom_seq_show)(struct seq_file *, void *);
+#endif
};
int bt_sock_register(int proto, const struct net_proto_family *ops);
@@ -293,6 +298,11 @@ extern void hci_sock_cleanup(void);
extern int bt_sysfs_init(void);
extern void bt_sysfs_cleanup(void);
+extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
+ struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *));
+extern void bt_procfs_cleanup(struct net *net, const char *name);
+
extern struct dentry *bt_debugfs;
int l2cap_init(void);
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 46e7f86..679cdd0 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -542,6 +542,142 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
}
EXPORT_SYMBOL(bt_sock_wait_state);
+#ifdef CONFIG_PROC_FS
+struct bt_seq_state {
+ struct bt_sock_list *l;
+};
+
+static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_lock(&l->lock);
+ return seq_hlist_start_head(&l->head, *pos);
+}
+
+static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ return seq_hlist_next(v, &l->head, pos);
+}
+
+static void bt_seq_stop(struct seq_file *seq, void *v)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_unlock(&l->lock);
+}
+
+static int bt_seq_show(struct seq_file *seq, void *v)
+{
+ struct sock *sk;
+ struct bt_sock *bt;
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+ bdaddr_t src_baswapped, dst_baswapped;
+
+ if (v == SEQ_START_TOKEN) {
+ seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ } else {
+ sk = sk_entry(v);
+ bt = bt_sk(sk);
+ baswap(&src_baswapped, &bt->src);
+ baswap(&dst_baswapped, &bt->dst);
+
+ seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
+ sk,
+ atomic_read(&sk->sk_refcnt),
+ sk_rmem_alloc_get(sk),
+ sk_wmem_alloc_get(sk),
+ sock_i_uid(sk),
+ sock_i_ino(sk),
+ &src_baswapped,
+ &dst_baswapped,
+ bt->parent? sock_i_ino(bt->parent): 0LU);
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ }
+ return 0;
+}
+
+static struct seq_operations bt_seq_ops = {
+ .start = bt_seq_start,
+ .next = bt_seq_next,
+ .stop = bt_seq_stop,
+ .show = bt_seq_show,
+};
+
+static int bt_seq_open(struct inode *inode, struct file *file)
+{
+ struct bt_sock_list *sk_list;
+ struct bt_seq_state *s;
+
+ sk_list = PDE(inode)->data;
+ s = __seq_open_private(file, &bt_seq_ops,
+ sizeof(struct bt_seq_state));
+ if (s == NULL)
+ return -ENOMEM;
+
+ s->l = sk_list;
+ return 0;
+}
+
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ struct proc_dir_entry * pde;
+
+ sk_list->custom_seq_show = seq_show;
+
+ sk_list->fops.owner = module;
+ sk_list->fops.open = bt_seq_open;
+ sk_list->fops.read = seq_read;
+ sk_list->fops.llseek = seq_lseek;
+ sk_list->fops.release = seq_release_private;
+
+ pde = proc_net_fops_create(net, name, 0, &sk_list->fops);
+ if (pde == NULL)
+ return -ENOMEM;
+
+ pde->data = sk_list;
+
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+ proc_net_remove(net, name);
+}
+#else
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+}
+#endif
+EXPORT_SYMBOL(bt_procfs_init);
+EXPORT_SYMBOL(bt_procfs_cleanup);
+
static struct net_proto_family bt_sock_family_ops = {
.owner = THIS_MODULE,
.family = PF_BLUETOOTH,
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v2 2/8] Added /proc/net/bnep via bt_procfs_init()
2012-06-15 8:00 ` Andrei Emeltchenko
2012-06-17 0:26 ` Masatake YAMATO
2012-06-18 10:00 ` [PATCH v2 1/8] " Masatake YAMATO
@ 2012-06-18 10:00 ` Masatake YAMATO
2012-06-18 10:01 ` [PATCH v2 3/8] Added /proc/net/cmtp " Masatake YAMATO
` (5 subsequent siblings)
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:00 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/bnep/sock.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index 180bfc4..b5bccd2 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -45,6 +45,10 @@
#include "bnep.h"
+static struct bt_sock_list bnep_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(bnep_sk_list.lock)
+};
+
static int bnep_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -54,6 +58,8 @@ static int bnep_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&bnep_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
return 0;
@@ -220,6 +226,7 @@ static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&bnep_sk_list, sk);
return 0;
}
@@ -238,19 +245,30 @@ int __init bnep_sock_init(void)
return err;
err = bt_sock_register(BTPROTO_BNEP, &bnep_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register BNEP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "bnep", &bnep_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create BNEP proc file");
+ bt_sock_unregister(BTPROTO_BNEP);
+ goto error;
+ }
+
+ BT_INFO("BNEP socket layer initialized");
return 0;
error:
- BT_ERR("Can't register BNEP socket");
proto_unregister(&bnep_proto);
return err;
}
void __exit bnep_sock_cleanup(void)
{
+ bt_procfs_cleanup(&init_net, "bnep");
if (bt_sock_unregister(BTPROTO_BNEP) < 0)
BT_ERR("Can't unregister BNEP socket");
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v2 3/8] Added /proc/net/cmtp via bt_procfs_init()
2012-06-15 8:00 ` Andrei Emeltchenko
` (2 preceding siblings ...)
2012-06-18 10:00 ` [PATCH v2 2/8] Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
@ 2012-06-18 10:01 ` Masatake YAMATO
2012-06-18 10:01 ` [PATCH v2 4/8] Added /proc/net/hci " Masatake YAMATO
` (4 subsequent siblings)
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:01 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/cmtp/sock.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 311668d..880ba45 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -42,6 +42,10 @@
#include "cmtp.h"
+static struct bt_sock_list cmtp_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(cmtp_sk_list.lock)
+};
+
static int cmtp_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -51,6 +55,8 @@ static int cmtp_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&cmtp_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
@@ -214,6 +220,8 @@ static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&cmtp_sk_list, sk);
+
return 0;
}
@@ -232,19 +240,30 @@ int cmtp_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_CMTP, &cmtp_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register CMTP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "cmtp", &cmtp_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create CMTP proc file");
+ bt_sock_unregister(BTPROTO_HIDP);
+ goto error;
+ }
+
+ BT_INFO("CMTP socket layer initialized");
return 0;
error:
- BT_ERR("Can't register CMTP socket");
proto_unregister(&cmtp_proto);
return err;
}
void cmtp_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "cmtp");
if (bt_sock_unregister(BTPROTO_CMTP) < 0)
BT_ERR("Can't unregister CMTP socket");
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v2 4/8] Added /proc/net/hci via bt_procfs_init()
2012-06-15 8:00 ` Andrei Emeltchenko
` (3 preceding siblings ...)
2012-06-18 10:01 ` [PATCH v2 3/8] Added /proc/net/cmtp " Masatake YAMATO
@ 2012-06-18 10:01 ` Masatake YAMATO
2012-06-18 10:03 ` [PATCH v2 5/8] Added /proc/net/hidp " Masatake YAMATO
` (3 subsequent siblings)
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:01 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/hci_sock.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 5914623..63bedec 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1107,21 +1107,31 @@ int __init hci_sock_init(void)
return err;
err = bt_sock_register(BTPROTO_HCI, &hci_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("HCI socket registration failed");
+ goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "hci", &hci_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create HCI proc file");
+ bt_sock_unregister(BTPROTO_HCI);
goto error;
+ }
BT_INFO("HCI socket layer initialized");
return 0;
error:
- BT_ERR("HCI socket registration failed");
proto_unregister(&hci_sk_proto);
return err;
}
void hci_sock_cleanup(void)
{
+ bt_procfs_cleanup(&init_net, "hci");
+
if (bt_sock_unregister(BTPROTO_HCI) < 0)
BT_ERR("HCI socket unregistration failed");
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v2 5/8] Added /proc/net/hidp via bt_procfs_init()
2012-06-15 8:00 ` Andrei Emeltchenko
` (4 preceding siblings ...)
2012-06-18 10:01 ` [PATCH v2 4/8] Added /proc/net/hci " Masatake YAMATO
@ 2012-06-18 10:03 ` Masatake YAMATO
2012-06-18 10:03 ` [PATCH v2 6/8] Added /proc/net/l2cap " Masatake YAMATO
` (2 subsequent siblings)
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:03 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/hidp/sock.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 73a32d7..3bd5d63 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -39,6 +39,10 @@
#include "hidp.h"
+static struct bt_sock_list hidp_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(hidp_sk_list.lock)
+};
+
static int hidp_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -48,6 +52,8 @@ static int hidp_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&hidp_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
@@ -267,6 +273,8 @@ static int hidp_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&hidp_sk_list, sk);
+
return 0;
}
@@ -285,19 +293,30 @@ int __init hidp_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_HIDP, &hidp_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register HIDP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "hidp", &hidp_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create HIDP proc file");
+ bt_sock_unregister(BTPROTO_HIDP);
+ goto error;
+ }
+
+ BT_INFO("HIDP socket layer initialized");
return 0;
error:
- BT_ERR("Can't register HIDP socket");
proto_unregister(&hidp_proto);
return err;
}
void __exit hidp_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "hidp");
if (bt_sock_unregister(BTPROTO_HIDP) < 0)
BT_ERR("Can't unregister HIDP socket");
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v2 6/8] Added /proc/net/l2cap via bt_procfs_init()
2012-06-15 8:00 ` Andrei Emeltchenko
` (5 preceding siblings ...)
2012-06-18 10:03 ` [PATCH v2 5/8] Added /proc/net/hidp " Masatake YAMATO
@ 2012-06-18 10:03 ` Masatake YAMATO
2012-06-18 10:04 ` [PATCH v2 7/8] Added /proc/net/rfcomm " Masatake YAMATO
2012-06-18 10:04 ` [PATCH v2 8/8] Added /proc/net/sco " Masatake YAMATO
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:03 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/l2cap_sock.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 3bb1611..b5e1966 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -35,6 +35,10 @@
#include <net/bluetooth/l2cap.h>
#include <net/bluetooth/smp.h>
+static struct bt_sock_list l2cap_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock)
+};
+
static const struct proto_ops l2cap_sock_ops;
static void l2cap_sock_init(struct sock *sk, struct sock *parent);
static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio);
@@ -866,6 +870,8 @@ static int l2cap_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&l2cap_sk_list, sk);
+
err = l2cap_sock_shutdown(sock, 2);
sock_orphan(sk);
@@ -1102,6 +1108,7 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
return -ENOMEM;
l2cap_sock_init(sk, NULL);
+ bt_sock_link(&l2cap_sk_list, sk);
return 0;
}
@@ -1140,21 +1147,30 @@ int __init l2cap_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("L2CAP socket registration failed");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "l2cap", &l2cap_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create L2CAP proc file");
+ bt_sock_unregister(BTPROTO_L2CAP);
+ goto error;
+ }
BT_INFO("L2CAP socket layer initialized");
return 0;
error:
- BT_ERR("L2CAP socket registration failed");
proto_unregister(&l2cap_proto);
return err;
}
void l2cap_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "l2cap");
if (bt_sock_unregister(BTPROTO_L2CAP) < 0)
BT_ERR("L2CAP socket unregistration failed");
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v2 7/8] Added /proc/net/rfcomm via bt_procfs_init()
2012-06-15 8:00 ` Andrei Emeltchenko
` (6 preceding siblings ...)
2012-06-18 10:03 ` [PATCH v2 6/8] Added /proc/net/l2cap " Masatake YAMATO
@ 2012-06-18 10:04 ` Masatake YAMATO
2012-06-18 10:04 ` [PATCH v2 8/8] Added /proc/net/sco " Masatake YAMATO
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:04 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/rfcomm/sock.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index e8707de..feded05 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -1052,8 +1052,17 @@ int __init rfcomm_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_RFCOMM, &rfcomm_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("RFCOMM socket layer registration failed");
+ goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "rfcomm", &rfcomm_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create RFCOMM proc file");
+ bt_sock_unregister(BTPROTO_RFCOMM);
goto error;
+ }
if (bt_debugfs) {
rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444,
@@ -1067,13 +1076,14 @@ int __init rfcomm_init_sockets(void)
return 0;
error:
- BT_ERR("RFCOMM socket layer registration failed");
proto_unregister(&rfcomm_proto);
return err;
}
void __exit rfcomm_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "rfcomm");
+
debugfs_remove(rfcomm_sock_debugfs);
if (bt_sock_unregister(BTPROTO_RFCOMM) < 0)
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v2 8/8] Added /proc/net/sco via bt_procfs_init()
2012-06-15 8:00 ` Andrei Emeltchenko
` (7 preceding siblings ...)
2012-06-18 10:04 ` [PATCH v2 7/8] Added /proc/net/rfcomm " Masatake YAMATO
@ 2012-06-18 10:04 ` Masatake YAMATO
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-18 10:04 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/sco.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index cbdd313..4f55867 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -1043,6 +1043,13 @@ int __init sco_init(void)
goto error;
}
+ err = bt_procfs_init(THIS_MODULE, &init_net, "sco", &sco_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create SCO proc file");
+ bt_sock_unregister(BTPROTO_SCO);
+ goto error;
+ }
+
if (bt_debugfs) {
sco_debugfs = debugfs_create_file("sco", 0444,
bt_debugfs, NULL, &sco_debugfs_fops);
@@ -1061,6 +1068,8 @@ error:
void __exit sco_exit(void)
{
+ bt_procfs_cleanup(&init_net, "sco");
+
debugfs_remove(sco_debugfs);
if (bt_sock_unregister(BTPROTO_SCO) < 0)
--
1.7.10.2
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH 1/8] /proc/net/ entries for bluetooth protocols
2012-06-18 8:28 ` Andrei Emeltchenko
@ 2012-06-28 17:02 ` Masatake YAMATO
2012-07-10 14:04 ` Andrei Emeltchenko
0 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-06-28 17:02 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Hi, Andrei
Could you review my v2 patch set I submitted?
https://lkml.org/lkml/2012/6/18/170
Masatake YAMATO
> Hi Masatake,
>
> On Sun, Jun 17, 2012 at 09:26:37AM +0900, Masatake YAMATO wrote:
>> Hi,
>>
>> Thank you for reviewing.
>> I have a question.
>>
>> >> + sk = sk_entry(v);
>> >> + bt = bt_sk(sk);
>> >> + seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu",
>> >> + sk,
>> >> + atomic_read(&sk->sk_refcnt),
>> >> + sk_rmem_alloc_get(sk),
>> >> + sk_wmem_alloc_get(sk),
>> >> + sock_i_uid(sk),
>> >> + sock_i_ino(sk)
>> >> + );
>> >> + seq_puts(seq, batostr(&bt->src));
>> >
>> > batostr looks OK now but this will be outdated soon by %pMR.
>>
>> As far as reading Documentation/printk-formats.txt and
>> pointer() in lib/vsprintf.c, %pMR is not defined.
>> I guess you mean %pM, don't you?
>
> Sorry for confusion, I meant my patch adding new printf specifier which
> is not yet in the tree. I think it will take longer time to be accepted
> then your patch.
>
>> I've tried following code, and it works as expected.
>>
>> baswap(&src_baswapped, &bt->src);
>> baswap(&dst_baswapped, &bt->dst);
>>
>> seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
>> sk,
>> atomic_read(&sk->sk_refcnt),
>> sk_rmem_alloc_get(sk),
>> sk_wmem_alloc_get(sk),
>> sock_i_uid(sk),
>> sock_i_ino(sk),
>> &src_baswapped,
>> &dst_baswapped,
>> bt->parent? sock_i_ino(bt->parent): 0LU);
>>
>
> Please use whatever method best suits for you although I prefer second
> solution since it is easier to change to %pMR later.
>
> Best regards
> Andrei Emeltchenko
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH 1/8] /proc/net/ entries for bluetooth protocols
2012-06-28 17:02 ` Masatake YAMATO
@ 2012-07-10 14:04 ` Andrei Emeltchenko
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
0 siblings, 1 reply; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-10 14:04 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Fri, Jun 29, 2012 at 02:02:53AM +0900, Masatake YAMATO wrote:
> Hi, Andrei
>
> Could you review my v2 patch set I submitted?
It does not apply, trailing white spaces and it also seems that they are
based on different repository. Please rebase against bluetooth-next.
Applying: /proc/net/ entries for bluetooth protocols
bluetooth-next-orig.git/.git/rebase-apply/patch:33:
trailing whitespace.
extern int bt_procfs_init(struct module* module, struct net *net, const
char *name,
bluetooth-next-orig.git/.git/rebase-apply/patch:140:
trailing whitespace.
bluetooth-next-orig.git/.git/rebase-apply/patch:157:
trailing whitespace.
bluetooth-next-orig.git/.git/rebase-apply/patch:163:
trailing whitespace.
error: patch failed: include/net/bluetooth/bluetooth.h:30
error: include/net/bluetooth/bluetooth.h: patch does not apply
Patch failed at 0001 /proc/net/ entries for bluetooth protocols
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".
>
> https://lkml.org/lkml/2012/6/18/170
>
> Masatake YAMATO
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v2 1/8] /proc/net/ entries for bluetooth protocols
2012-06-18 10:00 ` [PATCH v2 1/8] " Masatake YAMATO
@ 2012-07-10 14:06 ` Andrei Emeltchenko
0 siblings, 0 replies; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-10 14:06 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Mon, Jun 18, 2012 at 07:00:14PM +0900, Masatake YAMATO wrote:
> (I reflected the result of reviewing by Andrei.)
>
> lsof command can tell the type of socket processes are using.
> Internal lsof uses inode numbers on socket fs to resolve the type of
> sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
> such inode information.
>
> Unfortunately bluetooth related protocols don't provide such inode
> information. This patch series introduces /proc/net files for the protocols.
>
> This patch against af_bluetooth.c provides facility to the implementation
> of protocols. This patch extends bt_sock_list and introduces two exported
> function bt_procfs_init, bt_procfs_cleanup.
>
> The type bt_sock_list is already used in some of implementation of
> protocols. bt_procfs_init prepare seq_operations which converts
> protocol own bt_sock_list data to protocol own proc entry when the
> entry is accessed.
>
> What I, lsof user, need is just inode number of bluetooth
> socket. However, people may want more information. The bt_procfs_init
> takes a function pointer for customizing the show handler of
> seq_operations.
>
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
> include/net/bluetooth/bluetooth.h | 10 +++
> net/bluetooth/af_bluetooth.c | 136 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 146 insertions(+)
>
> diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> index 961669b..9c44977 100644
> --- a/include/net/bluetooth/bluetooth.h
> +++ b/include/net/bluetooth/bluetooth.h
> @@ -30,6 +30,7 @@
> #include <linux/list.h>
The line above was removed by commit
commit 8c520a59927a5600973782505dbb750d985057c4
Author: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Date: Wed May 23 04:04:22 2012 -0300
Bluetooth: Remove unnecessary headers include
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-10 14:04 ` Andrei Emeltchenko
@ 2012-07-11 4:58 ` Masatake YAMATO
2012-07-11 4:59 ` [PATCH v3 2/8] bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
` (8 more replies)
0 siblings, 9 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 4:58 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth, yamato
(The patch sets are rebased to bluetooth-next. Unnecessary white
spaces are trimmed.)
lsof command can tell the type of socket processes are using.
Internal lsof uses inode numbers on socket fs to resolve the type of
sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
such inode information.
Unfortunately bluetooth related protocols don't provide such inode
information. This patch series introduces /proc/net files for the protocols.
This patch against af_bluetooth.c provides facility to the implementation
of protocols. This patch extends bt_sock_list and introduces two exported
function bt_procfs_init, bt_procfs_cleanup.
The type bt_sock_list is already used in some of implementation of
protocols. bt_procfs_init prepare seq_operations which converts
protocol own bt_sock_list data to protocol own proc entry when the
entry is accessed.
What I, lsof user, need is just inode number of bluetooth
socket. However, people may want more information. The bt_procfs_init
takes a function pointer for customizing the show handler of
seq_operations.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
include/net/bluetooth/bluetooth.h | 10 +++
net/bluetooth/af_bluetooth.c | 136 +++++++++++++++++++++++++++++++++++++
2 files changed, 146 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 565d4be..ede0369 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -27,6 +27,7 @@
#include <linux/poll.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
@@ -202,6 +203,10 @@ enum {
struct bt_sock_list {
struct hlist_head head;
rwlock_t lock;
+#ifdef CONFIG_PROC_FS
+ struct file_operations fops;
+ int (* custom_seq_show)(struct seq_file *, void *);
+#endif
};
int bt_sock_register(int proto, const struct net_proto_family *ops);
@@ -292,6 +297,11 @@ extern void hci_sock_cleanup(void);
extern int bt_sysfs_init(void);
extern void bt_sysfs_cleanup(void);
+extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
+ struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *));
+extern void bt_procfs_cleanup(struct net *net, const char *name);
+
extern struct dentry *bt_debugfs;
int l2cap_init(void);
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index f7db579..269fc3d 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -532,6 +532,142 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
}
EXPORT_SYMBOL(bt_sock_wait_state);
+#ifdef CONFIG_PROC_FS
+struct bt_seq_state {
+ struct bt_sock_list *l;
+};
+
+static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_lock(&l->lock);
+ return seq_hlist_start_head(&l->head, *pos);
+}
+
+static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ return seq_hlist_next(v, &l->head, pos);
+}
+
+static void bt_seq_stop(struct seq_file *seq, void *v)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_unlock(&l->lock);
+}
+
+static int bt_seq_show(struct seq_file *seq, void *v)
+{
+ struct sock *sk;
+ struct bt_sock *bt;
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+ bdaddr_t src_baswapped, dst_baswapped;
+
+ if (v == SEQ_START_TOKEN) {
+ seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ } else {
+ sk = sk_entry(v);
+ bt = bt_sk(sk);
+ baswap(&src_baswapped, &bt->src);
+ baswap(&dst_baswapped, &bt->dst);
+
+ seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
+ sk,
+ atomic_read(&sk->sk_refcnt),
+ sk_rmem_alloc_get(sk),
+ sk_wmem_alloc_get(sk),
+ sock_i_uid(sk),
+ sock_i_ino(sk),
+ &src_baswapped,
+ &dst_baswapped,
+ bt->parent? sock_i_ino(bt->parent): 0LU);
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ }
+ return 0;
+}
+
+static struct seq_operations bt_seq_ops = {
+ .start = bt_seq_start,
+ .next = bt_seq_next,
+ .stop = bt_seq_stop,
+ .show = bt_seq_show,
+};
+
+static int bt_seq_open(struct inode *inode, struct file *file)
+{
+ struct bt_sock_list *sk_list;
+ struct bt_seq_state *s;
+
+ sk_list = PDE(inode)->data;
+ s = __seq_open_private(file, &bt_seq_ops,
+ sizeof(struct bt_seq_state));
+ if (s == NULL)
+ return -ENOMEM;
+
+ s->l = sk_list;
+ return 0;
+}
+
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ struct proc_dir_entry * pde;
+
+ sk_list->custom_seq_show = seq_show;
+
+ sk_list->fops.owner = module;
+ sk_list->fops.open = bt_seq_open;
+ sk_list->fops.read = seq_read;
+ sk_list->fops.llseek = seq_lseek;
+ sk_list->fops.release = seq_release_private;
+
+ pde = proc_net_fops_create(net, name, 0, &sk_list->fops);
+ if (pde == NULL)
+ return -ENOMEM;
+
+ pde->data = sk_list;
+
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+ proc_net_remove(net, name);
+}
+#else
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+}
+#endif
+EXPORT_SYMBOL(bt_procfs_init);
+EXPORT_SYMBOL(bt_procfs_cleanup);
+
static struct net_proto_family bt_sock_family_ops = {
.owner = THIS_MODULE,
.family = PF_BLUETOOTH,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v3 2/8] bluetooth: Added /proc/net/bnep via bt_procfs_init()
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
@ 2012-07-11 4:59 ` Masatake YAMATO
2012-07-25 0:20 ` Gustavo Padovan
2012-07-11 5:02 ` [PATCH v3 3/8] bluetooth: Added /proc/net/cmtp " Masatake YAMATO
` (7 subsequent siblings)
8 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 4:59 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/bnep/sock.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index 5e5f5b4..5b6cc0b 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -29,6 +29,10 @@
#include "bnep.h"
+static struct bt_sock_list bnep_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(bnep_sk_list.lock)
+};
+
static int bnep_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -38,6 +42,8 @@ static int bnep_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&bnep_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
return 0;
@@ -204,6 +210,7 @@ static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&bnep_sk_list, sk);
return 0;
}
@@ -222,19 +229,30 @@ int __init bnep_sock_init(void)
return err;
err = bt_sock_register(BTPROTO_BNEP, &bnep_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register BNEP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "bnep", &bnep_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create BNEP proc file");
+ bt_sock_unregister(BTPROTO_BNEP);
+ goto error;
+ }
+
+ BT_INFO("BNEP socket layer initialized");
return 0;
error:
- BT_ERR("Can't register BNEP socket");
proto_unregister(&bnep_proto);
return err;
}
void __exit bnep_sock_cleanup(void)
{
+ bt_procfs_cleanup(&init_net, "bnep");
if (bt_sock_unregister(BTPROTO_BNEP) < 0)
BT_ERR("Can't unregister BNEP socket");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v3 3/8] bluetooth: Added /proc/net/cmtp via bt_procfs_init()
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
2012-07-11 4:59 ` [PATCH v3 2/8] bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
@ 2012-07-11 5:02 ` Masatake YAMATO
2012-07-11 5:02 ` [PATCH v3 4/8] bluetooth: Added /proc/net/hci " Masatake YAMATO
` (6 subsequent siblings)
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 5:02 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/cmtp/sock.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 311668d..d5cacef 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -42,6 +42,10 @@
#include "cmtp.h"
+static struct bt_sock_list cmtp_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(cmtp_sk_list.lock)
+};
+
static int cmtp_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -51,6 +55,8 @@ static int cmtp_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&cmtp_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
@@ -214,6 +220,8 @@ static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&cmtp_sk_list, sk);
+
return 0;
}
@@ -232,19 +240,30 @@ int cmtp_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_CMTP, &cmtp_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register CMTP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "cmtp", &cmtp_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create CMTP proc file");
+ bt_sock_unregister(BTPROTO_HIDP);
+ goto error;
+ }
+
+ BT_INFO("CMTP socket layer initialized");
return 0;
error:
- BT_ERR("Can't register CMTP socket");
proto_unregister(&cmtp_proto);
return err;
}
void cmtp_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "cmtp");
if (bt_sock_unregister(BTPROTO_CMTP) < 0)
BT_ERR("Can't unregister CMTP socket");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v3 4/8] bluetooth: Added /proc/net/hci via bt_procfs_init()
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
2012-07-11 4:59 ` [PATCH v3 2/8] bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
2012-07-11 5:02 ` [PATCH v3 3/8] bluetooth: Added /proc/net/cmtp " Masatake YAMATO
@ 2012-07-11 5:02 ` Masatake YAMATO
2012-07-11 5:03 ` [PATCH v3 5/8] bluetooth: Added /proc/net/hidp " Masatake YAMATO
` (5 subsequent siblings)
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 5:02 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/hci_sock.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index a7f04de..7c3d6c7 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1100,21 +1100,30 @@ int __init hci_sock_init(void)
return err;
err = bt_sock_register(BTPROTO_HCI, &hci_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("HCI socket registration failed");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "hci", &hci_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create HCI proc file");
+ bt_sock_unregister(BTPROTO_HCI);
+ goto error;
+ }
BT_INFO("HCI socket layer initialized");
return 0;
error:
- BT_ERR("HCI socket registration failed");
proto_unregister(&hci_sk_proto);
return err;
}
void hci_sock_cleanup(void)
{
+ bt_procfs_cleanup(&init_net, "hci");
if (bt_sock_unregister(BTPROTO_HCI) < 0)
BT_ERR("HCI socket unregistration failed");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v3 5/8] bluetooth: Added /proc/net/hidp via bt_procfs_init()
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
` (2 preceding siblings ...)
2012-07-11 5:02 ` [PATCH v3 4/8] bluetooth: Added /proc/net/hci " Masatake YAMATO
@ 2012-07-11 5:03 ` Masatake YAMATO
2012-07-11 5:03 ` [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap " Masatake YAMATO
` (4 subsequent siblings)
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 5:03 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/hidp/sock.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 18b3f68..a481f8d 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -25,6 +25,10 @@
#include "hidp.h"
+static struct bt_sock_list hidp_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(hidp_sk_list.lock)
+};
+
static int hidp_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -34,6 +38,8 @@ static int hidp_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&hidp_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
@@ -253,6 +259,8 @@ static int hidp_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&hidp_sk_list, sk);
+
return 0;
}
@@ -271,9 +279,20 @@ int __init hidp_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_HIDP, &hidp_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register HIDP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "hidp", &hidp_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create HIDP proc file");
+ bt_sock_unregister(BTPROTO_HIDP);
+ goto error;
+ }
+ BT_INFO("HIDP socket layer initialized");
+
return 0;
error:
@@ -284,6 +303,7 @@ error:
void __exit hidp_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "hidp");
if (bt_sock_unregister(BTPROTO_HIDP) < 0)
BT_ERR("Can't unregister HIDP socket");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap via bt_procfs_init()
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
` (3 preceding siblings ...)
2012-07-11 5:03 ` [PATCH v3 5/8] bluetooth: Added /proc/net/hidp " Masatake YAMATO
@ 2012-07-11 5:03 ` Masatake YAMATO
2012-07-11 8:48 ` Andrei Emeltchenko
2012-07-11 5:04 ` [PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm " Masatake YAMATO
` (3 subsequent siblings)
8 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 5:03 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/l2cap_sock.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index a4bb27e..c9a9f1c 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -34,6 +34,10 @@
#include <net/bluetooth/l2cap.h>
#include <net/bluetooth/smp.h>
+static struct bt_sock_list l2cap_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock)
+};
+
static const struct proto_ops l2cap_sock_ops;
static void l2cap_sock_init(struct sock *sk, struct sock *parent);
static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio);
@@ -886,6 +890,8 @@ static int l2cap_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&l2cap_sk_list, sk);
+
err = l2cap_sock_shutdown(sock, 2);
sock_orphan(sk);
@@ -1210,6 +1216,7 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
return -ENOMEM;
l2cap_sock_init(sk, NULL);
+ bt_sock_link(&l2cap_sk_list, sk);
return 0;
}
@@ -1248,22 +1255,30 @@ int __init l2cap_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("L2CAP socket registration failed");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "l2cap", &l2cap_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create L2CAP proc file");
+ bt_sock_unregister(BTPROTO_L2CAP);
+ goto error;
+ }
BT_INFO("L2CAP socket layer initialized");
return 0;
error:
- BT_ERR("L2CAP socket registration failed");
proto_unregister(&l2cap_proto);
return err;
}
void l2cap_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "l2cap");
if (bt_sock_unregister(BTPROTO_L2CAP) < 0)
BT_ERR("L2CAP socket unregistration failed");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm via bt_procfs_init()
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
` (4 preceding siblings ...)
2012-07-11 5:03 ` [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap " Masatake YAMATO
@ 2012-07-11 5:04 ` Masatake YAMATO
2012-07-11 8:49 ` Andrei Emeltchenko
2012-07-11 5:04 ` [PATCH v3 8/8] bluetooth: Added /proc/net/sco " Masatake YAMATO
` (2 subsequent siblings)
8 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 5:04 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/rfcomm/sock.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 7e1e596..260821a 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -1033,8 +1033,17 @@ int __init rfcomm_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_RFCOMM, &rfcomm_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("RFCOMM socket layer registration failed");
+ goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "rfcomm", &rfcomm_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create RFCOMM proc file");
+ bt_sock_unregister(BTPROTO_RFCOMM);
goto error;
+ }
if (bt_debugfs) {
rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444,
@@ -1048,13 +1057,14 @@ int __init rfcomm_init_sockets(void)
return 0;
error:
- BT_ERR("RFCOMM socket layer registration failed");
proto_unregister(&rfcomm_proto);
return err;
}
void __exit rfcomm_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "rfcomm");
+
debugfs_remove(rfcomm_sock_debugfs);
if (bt_sock_unregister(BTPROTO_RFCOMM) < 0)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v3 8/8] bluetooth: Added /proc/net/sco via bt_procfs_init()
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
` (5 preceding siblings ...)
2012-07-11 5:04 ` [PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm " Masatake YAMATO
@ 2012-07-11 5:04 ` Masatake YAMATO
2012-07-11 11:23 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Andrei Emeltchenko
2012-07-24 13:08 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Masatake YAMATO
8 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 5:04 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/sco.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 40bbe25..85efd9f 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -1026,6 +1026,13 @@ int __init sco_init(void)
goto error;
}
+ err = bt_procfs_init(THIS_MODULE, &init_net, "sco", &sco_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create SCO proc file");
+ bt_sock_unregister(BTPROTO_SCO);
+ goto error;
+ }
+
if (bt_debugfs) {
sco_debugfs = debugfs_create_file("sco", 0444, bt_debugfs,
NULL, &sco_debugfs_fops);
@@ -1044,6 +1051,8 @@ error:
void __exit sco_exit(void)
{
+ bt_procfs_cleanup(&init_net, "sco");
+
debugfs_remove(sco_debugfs);
if (bt_sock_unregister(BTPROTO_SCO) < 0)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap via bt_procfs_init()
2012-07-11 5:03 ` [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap " Masatake YAMATO
@ 2012-07-11 8:48 ` Andrei Emeltchenko
2012-07-11 9:19 ` Masatake YAMATO
0 siblings, 1 reply; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-11 8:48 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Wed, Jul 11, 2012 at 02:03:37PM +0900, Masatake YAMATO wrote:
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
> net/bluetooth/l2cap_sock.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
error: patch failed: net/bluetooth/l2cap_sock.c:1248
error: net/bluetooth/l2cap_sock.c: patch does not apply
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm via bt_procfs_init()
2012-07-11 5:04 ` [PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm " Masatake YAMATO
@ 2012-07-11 8:49 ` Andrei Emeltchenko
0 siblings, 0 replies; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-11 8:49 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Wed, Jul 11, 2012 at 02:04:01PM +0900, Masatake YAMATO wrote:
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
> net/bluetooth/rfcomm/sock.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
error: patch failed: net/bluetooth/rfcomm/sock.c:1033
error: net/bluetooth/rfcomm/sock.c: patch does not apply
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap via bt_procfs_init()
2012-07-11 8:48 ` Andrei Emeltchenko
@ 2012-07-11 9:19 ` Masatake YAMATO
2012-07-11 9:49 ` Andrei Emeltchenko
0 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 9:19 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Andrei, thank you for taking time.
I've rebased again and I applied my patches with git am.
They are applied without problem.
I've regenerated the patches again and compared the new
ones with the older ones.
About
[PATCH v3 6/8] bluetooth: Added /proc/net/l2cap via bt_procfs_init()
One line slided. I've paste the new one to this mail. About
[PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm via bt_procfs_init()
I cannot find any change between new one and older one.
What can I do?
Masatake YAMATO
>From c56754680ec4005de7586b6afa7155228e0bbd6e Mon Sep 17 00:00:00 2001
From: Masatake YAMATO <yamato@redhat.com>
Date: Thu, 14 Jun 2012 23:52:08 +0900
Subject: [PATCH 6/8] Added /proc/net/l2cap via bt_procfs_init()
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/l2cap_sock.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index a4bb27e..04bd647 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -34,6 +34,10 @@
#include <net/bluetooth/l2cap.h>
#include <net/bluetooth/smp.h>
+static struct bt_sock_list l2cap_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock)
+};
+
static const struct proto_ops l2cap_sock_ops;
static void l2cap_sock_init(struct sock *sk, struct sock *parent);
static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio);
@@ -886,6 +890,8 @@ static int l2cap_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&l2cap_sk_list, sk);
+
err = l2cap_sock_shutdown(sock, 2);
sock_orphan(sk);
@@ -1210,6 +1216,7 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
return -ENOMEM;
l2cap_sock_init(sk, NULL);
+ bt_sock_link(&l2cap_sk_list, sk);
return 0;
}
@@ -1248,21 +1255,30 @@ int __init l2cap_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("L2CAP socket registration failed");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "l2cap", &l2cap_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create L2CAP proc file");
+ bt_sock_unregister(BTPROTO_L2CAP);
+ goto error;
+ }
BT_INFO("L2CAP socket layer initialized");
return 0;
error:
- BT_ERR("L2CAP socket registration failed");
proto_unregister(&l2cap_proto);
return err;
}
void l2cap_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "l2cap");
if (bt_sock_unregister(BTPROTO_L2CAP) < 0)
BT_ERR("L2CAP socket unregistration failed");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap via bt_procfs_init()
2012-07-11 9:19 ` Masatake YAMATO
@ 2012-07-11 9:49 ` Andrei Emeltchenko
0 siblings, 0 replies; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-11 9:49 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Wed, Jul 11, 2012 at 06:19:31PM +0900, Masatake YAMATO wrote:
> Andrei, thank you for taking time.
>
> I've rebased again and I applied my patches with git am.
> They are applied without problem.
>
> I've regenerated the patches again and compared the new
> ones with the older ones.
>
> About
>
> [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap via bt_procfs_init()
>
> One line slided. I've paste the new one to this mail.
Thanks, this one works.
> About
>
> [PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm via bt_procfs_init()
>
> I cannot find any change between new one and older one.
> What can I do?
Sorry, my fault, rfcomm patch is OK, I was applying it second time...
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
` (6 preceding siblings ...)
2012-07-11 5:04 ` [PATCH v3 8/8] bluetooth: Added /proc/net/sco " Masatake YAMATO
@ 2012-07-11 11:23 ` Andrei Emeltchenko
2012-07-11 12:19 ` Masatake YAMATO
2012-07-24 13:08 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Masatake YAMATO
8 siblings, 1 reply; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-11 11:23 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Wed, Jul 11, 2012 at 01:58:31PM +0900, Masatake YAMATO wrote:
> (The patch sets are rebased to bluetooth-next. Unnecessary white
> spaces are trimmed.)
>
> lsof command can tell the type of socket processes are using.
> Internal lsof uses inode numbers on socket fs to resolve the type of
> sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
> such inode information.
>
> Unfortunately bluetooth related protocols don't provide such inode
> information. This patch series introduces /proc/net files for the protocols.
>
> This patch against af_bluetooth.c provides facility to the implementation
> of protocols. This patch extends bt_sock_list and introduces two exported
> function bt_procfs_init, bt_procfs_cleanup.
>
> The type bt_sock_list is already used in some of implementation of
> protocols. bt_procfs_init prepare seq_operations which converts
> protocol own bt_sock_list data to protocol own proc entry when the
> entry is accessed.
>
> What I, lsof user, need is just inode number of bluetooth
> socket. However, people may want more information. The bt_procfs_init
> takes a function pointer for customizing the show handler of
> seq_operations.
I've tested the patch and it creates entries in /proc/net
BTW: Shall lsof be able to identify l2cap protocol?
for l2test it prints: "can't identify protocol"
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-11 11:23 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Andrei Emeltchenko
@ 2012-07-11 12:19 ` Masatake YAMATO
2012-07-12 7:42 ` Andrei Emeltchenko
0 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-11 12:19 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
Hi,
> Hi Masatake,
>
> On Wed, Jul 11, 2012 at 01:58:31PM +0900, Masatake YAMATO wrote:
>> (The patch sets are rebased to bluetooth-next. Unnecessary white
>> spaces are trimmed.)
>>
>> lsof command can tell the type of socket processes are using.
>> Internal lsof uses inode numbers on socket fs to resolve the type of
>> sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
>> such inode information.
>>
>> Unfortunately bluetooth related protocols don't provide such inode
>> information. This patch series introduces /proc/net files for the protocols.
>>
>> This patch against af_bluetooth.c provides facility to the implementation
>> of protocols. This patch extends bt_sock_list and introduces two exported
>> function bt_procfs_init, bt_procfs_cleanup.
>>
>> The type bt_sock_list is already used in some of implementation of
>> protocols. bt_procfs_init prepare seq_operations which converts
>> protocol own bt_sock_list data to protocol own proc entry when the
>> entry is accessed.
>>
>> What I, lsof user, need is just inode number of bluetooth
>> socket. However, people may want more information. The bt_procfs_init
>> takes a function pointer for customizing the show handler of
>> seq_operations.
>
> I've tested the patch and it creates entries in /proc/net
Thanks.
> BTW: Shall lsof be able to identify l2cap protocol?
>
> for l2test it prints: "can't identify protocol"
No. I'll work on lsof side after the kernel side
patches are merged to the main line.
Masatake YAMATO
> Best regards
> Andrei Emeltchenko
>
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-11 12:19 ` Masatake YAMATO
@ 2012-07-12 7:42 ` Andrei Emeltchenko
2012-07-16 13:20 ` [PATCH v4 " Masatake YAMATO
0 siblings, 1 reply; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-12 7:42 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Wed, Jul 11, 2012 at 09:19:06PM +0900, Masatake YAMATO wrote:
> > I've tested the patch and it creates entries in /proc/net
>
> Thanks.
>
> > BTW: Shall lsof be able to identify l2cap protocol?
> >
> > for l2test it prints: "can't identify protocol"
>
> No. I'll work on lsof side after the kernel side
> patches are merged to the main line.
OK, patch looks good though I would eliminate 2 new sparse warnings with
__acquires and __releases attributes.
net/bluetooth/af_bluetooth.c:540:13: warning: context imbalance in
'bt_seq_start' - wrong count at exit
net/bluetooth/af_bluetooth.c:557:13: warning: context imbalance in
'bt_seq_stop' - unexpected unlock
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v4 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-12 7:42 ` Andrei Emeltchenko
@ 2012-07-16 13:20 ` Masatake YAMATO
2012-07-25 0:12 ` Gustavo Padovan
0 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-16 13:20 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth
(I resend this mail becasue I got some troubles in mail sending.
Andrei, [PATCH v4 [2-8]/8] are the same as [PATCH v3 [2-8]/8]. So
I send [PATCH v4 1/8] only here. If I should the rest of v4 patches,
please, let me know that.)
lsof command can tell the type of socket processes are using.
Internal lsof uses inode numbers on socket fs to resolve the type of
sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
such inode information.
Unfortunately bluetooth related protocols don't provide such inode
information. This patch series introduces /proc/net files for the protocols.
This patch against af_bluetooth.c provides facility to the implementation
of protocols. This patch extends bt_sock_list and introduces two exported
function bt_procfs_init, bt_procfs_cleanup.
The type bt_sock_list is already used in some of implementation of
protocols. bt_procfs_init prepare seq_operations which converts
protocol own bt_sock_list data to protocol own proc entry when the
entry is accessed.
What I, lsof user, need is just inode number of bluetooth
socket. However, people may want more information. The bt_procfs_init
takes a function pointer for customizing the show handler of
seq_operations.
In v4 patch, __acquires and __releases attributes are added to suppress
sparse warning. Suggested by Andrei Emeltchenko.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
include/net/bluetooth/bluetooth.h | 10 +++
net/bluetooth/af_bluetooth.c | 138 +++++++++++++++++++++++++++++++++++++
2 files changed, 148 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 565d4be..ede0369 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -27,6 +27,7 @@
#include <linux/poll.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
@@ -202,6 +203,10 @@ enum {
struct bt_sock_list {
struct hlist_head head;
rwlock_t lock;
+#ifdef CONFIG_PROC_FS
+ struct file_operations fops;
+ int (* custom_seq_show)(struct seq_file *, void *);
+#endif
};
int bt_sock_register(int proto, const struct net_proto_family *ops);
@@ -292,6 +297,11 @@ extern void hci_sock_cleanup(void);
extern int bt_sysfs_init(void);
extern void bt_sysfs_cleanup(void);
+extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
+ struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *));
+extern void bt_procfs_cleanup(struct net *net, const char *name);
+
extern struct dentry *bt_debugfs;
int l2cap_init(void);
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index f7db579..f76cf2f 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -532,6 +532,144 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
}
EXPORT_SYMBOL(bt_sock_wait_state);
+#ifdef CONFIG_PROC_FS
+struct bt_seq_state {
+ struct bt_sock_list *l;
+};
+
+static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
+ __acquires(seq->private->l->lock)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_lock(&l->lock);
+ return seq_hlist_start_head(&l->head, *pos);
+}
+
+static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ return seq_hlist_next(v, &l->head, pos);
+}
+
+static void bt_seq_stop(struct seq_file *seq, void *v)
+ __releases(seq->private->l->lock)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_unlock(&l->lock);
+}
+
+static int bt_seq_show(struct seq_file *seq, void *v)
+{
+ struct sock *sk;
+ struct bt_sock *bt;
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+ bdaddr_t src_baswapped, dst_baswapped;
+
+ if (v == SEQ_START_TOKEN) {
+ seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ } else {
+ sk = sk_entry(v);
+ bt = bt_sk(sk);
+ baswap(&src_baswapped, &bt->src);
+ baswap(&dst_baswapped, &bt->dst);
+
+ seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
+ sk,
+ atomic_read(&sk->sk_refcnt),
+ sk_rmem_alloc_get(sk),
+ sk_wmem_alloc_get(sk),
+ sock_i_uid(sk),
+ sock_i_ino(sk),
+ &src_baswapped,
+ &dst_baswapped,
+ bt->parent? sock_i_ino(bt->parent): 0LU);
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ }
+ return 0;
+}
+
+static struct seq_operations bt_seq_ops = {
+ .start = bt_seq_start,
+ .next = bt_seq_next,
+ .stop = bt_seq_stop,
+ .show = bt_seq_show,
+};
+
+static int bt_seq_open(struct inode *inode, struct file *file)
+{
+ struct bt_sock_list *sk_list;
+ struct bt_seq_state *s;
+
+ sk_list = PDE(inode)->data;
+ s = __seq_open_private(file, &bt_seq_ops,
+ sizeof(struct bt_seq_state));
+ if (s == NULL)
+ return -ENOMEM;
+
+ s->l = sk_list;
+ return 0;
+}
+
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ struct proc_dir_entry * pde;
+
+ sk_list->custom_seq_show = seq_show;
+
+ sk_list->fops.owner = module;
+ sk_list->fops.open = bt_seq_open;
+ sk_list->fops.read = seq_read;
+ sk_list->fops.llseek = seq_lseek;
+ sk_list->fops.release = seq_release_private;
+
+ pde = proc_net_fops_create(net, name, 0, &sk_list->fops);
+ if (pde == NULL)
+ return -ENOMEM;
+
+ pde->data = sk_list;
+
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+ proc_net_remove(net, name);
+}
+#else
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+}
+#endif
+EXPORT_SYMBOL(bt_procfs_init);
+EXPORT_SYMBOL(bt_procfs_cleanup);
+
static struct net_proto_family bt_sock_family_ops = {
.owner = THIS_MODULE,
.family = PF_BLUETOOTH,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
` (7 preceding siblings ...)
2012-07-11 11:23 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Andrei Emeltchenko
@ 2012-07-24 13:08 ` Masatake YAMATO
2012-07-24 13:15 ` Andrei Emeltchenko
8 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-24 13:08 UTC (permalink / raw)
To: andrei.emeltchenko.news; +Cc: linux-kernel, linux-bluetooth, yamato
(I have got no reply since 11th Jul. So I resend this mail here.
Please, review this patch and merge it if no problem.)
(The patch sets are rebased to bluetooth-next. Unnecessary white
spaces are trimmed.)
lsof command can tell the type of socket processes are using.
Internal lsof uses inode numbers on socket fs to resolve the type of
sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
such inode information.
Unfortunately bluetooth related protocols don't provide such inode
information. This patch series introduces /proc/net files for the protocols.
This patch against af_bluetooth.c provides facility to the implementation
of protocols. This patch extends bt_sock_list and introduces two exported
function bt_procfs_init, bt_procfs_cleanup.
The type bt_sock_list is already used in some of implementation of
protocols. bt_procfs_init prepare seq_operations which converts
protocol own bt_sock_list data to protocol own proc entry when the
entry is accessed.
What I, lsof user, need is just inode number of bluetooth
socket. However, people may want more information. The bt_procfs_init
takes a function pointer for customizing the show handler of
seq_operations.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
include/net/bluetooth/bluetooth.h | 10 +++
net/bluetooth/af_bluetooth.c | 136 +++++++++++++++++++++++++++++++++++++
2 files changed, 146 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 565d4be..ede0369 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -27,6 +27,7 @@
#include <linux/poll.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
@@ -202,6 +203,10 @@ enum {
struct bt_sock_list {
struct hlist_head head;
rwlock_t lock;
+#ifdef CONFIG_PROC_FS
+ struct file_operations fops;
+ int (* custom_seq_show)(struct seq_file *, void *);
+#endif
};
int bt_sock_register(int proto, const struct net_proto_family *ops);
@@ -292,6 +297,11 @@ extern void hci_sock_cleanup(void);
extern int bt_sysfs_init(void);
extern void bt_sysfs_cleanup(void);
+extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
+ struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *));
+extern void bt_procfs_cleanup(struct net *net, const char *name);
+
extern struct dentry *bt_debugfs;
int l2cap_init(void);
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index f7db579..269fc3d 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -532,6 +532,142 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
}
EXPORT_SYMBOL(bt_sock_wait_state);
+#ifdef CONFIG_PROC_FS
+struct bt_seq_state {
+ struct bt_sock_list *l;
+};
+
+static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_lock(&l->lock);
+ return seq_hlist_start_head(&l->head, *pos);
+}
+
+static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ return seq_hlist_next(v, &l->head, pos);
+}
+
+static void bt_seq_stop(struct seq_file *seq, void *v)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_unlock(&l->lock);
+}
+
+static int bt_seq_show(struct seq_file *seq, void *v)
+{
+ struct sock *sk;
+ struct bt_sock *bt;
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+ bdaddr_t src_baswapped, dst_baswapped;
+
+ if (v == SEQ_START_TOKEN) {
+ seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ } else {
+ sk = sk_entry(v);
+ bt = bt_sk(sk);
+ baswap(&src_baswapped, &bt->src);
+ baswap(&dst_baswapped, &bt->dst);
+
+ seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
+ sk,
+ atomic_read(&sk->sk_refcnt),
+ sk_rmem_alloc_get(sk),
+ sk_wmem_alloc_get(sk),
+ sock_i_uid(sk),
+ sock_i_ino(sk),
+ &src_baswapped,
+ &dst_baswapped,
+ bt->parent? sock_i_ino(bt->parent): 0LU);
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ }
+ return 0;
+}
+
+static struct seq_operations bt_seq_ops = {
+ .start = bt_seq_start,
+ .next = bt_seq_next,
+ .stop = bt_seq_stop,
+ .show = bt_seq_show,
+};
+
+static int bt_seq_open(struct inode *inode, struct file *file)
+{
+ struct bt_sock_list *sk_list;
+ struct bt_seq_state *s;
+
+ sk_list = PDE(inode)->data;
+ s = __seq_open_private(file, &bt_seq_ops,
+ sizeof(struct bt_seq_state));
+ if (s == NULL)
+ return -ENOMEM;
+
+ s->l = sk_list;
+ return 0;
+}
+
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ struct proc_dir_entry * pde;
+
+ sk_list->custom_seq_show = seq_show;
+
+ sk_list->fops.owner = module;
+ sk_list->fops.open = bt_seq_open;
+ sk_list->fops.read = seq_read;
+ sk_list->fops.llseek = seq_lseek;
+ sk_list->fops.release = seq_release_private;
+
+ pde = proc_net_fops_create(net, name, 0, &sk_list->fops);
+ if (pde == NULL)
+ return -ENOMEM;
+
+ pde->data = sk_list;
+
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+ proc_net_remove(net, name);
+}
+#else
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+}
+#endif
+EXPORT_SYMBOL(bt_procfs_init);
+EXPORT_SYMBOL(bt_procfs_cleanup);
+
static struct net_proto_family bt_sock_family_ops = {
.owner = THIS_MODULE,
.family = PF_BLUETOOTH,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-24 13:08 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Masatake YAMATO
@ 2012-07-24 13:15 ` Andrei Emeltchenko
0 siblings, 0 replies; 46+ messages in thread
From: Andrei Emeltchenko @ 2012-07-24 13:15 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: linux-kernel, linux-bluetooth
Hi Masatake,
On Tue, Jul 24, 2012 at 10:08:31PM +0900, Masatake YAMATO wrote:
> (I have got no reply since 11th Jul. So I resend this mail here.
> Please, review this patch and merge it if no problem.)
>
> (The patch sets are rebased to bluetooth-next. Unnecessary white
> spaces are trimmed.)
>
> lsof command can tell the type of socket processes are using.
> Internal lsof uses inode numbers on socket fs to resolve the type of
> sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
> such inode information.
>
> Unfortunately bluetooth related protocols don't provide such inode
> information. This patch series introduces /proc/net files for the protocols.
>
> This patch against af_bluetooth.c provides facility to the implementation
> of protocols. This patch extends bt_sock_list and introduces two exported
> function bt_procfs_init, bt_procfs_cleanup.
>
> The type bt_sock_list is already used in some of implementation of
> protocols. bt_procfs_init prepare seq_operations which converts
> protocol own bt_sock_list data to protocol own proc entry when the
> entry is accessed.
>
> What I, lsof user, need is just inode number of bluetooth
> socket. However, people may want more information. The bt_procfs_init
> takes a function pointer for customizing the show handler of
> seq_operations.
>
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Tested-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v4 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-16 13:20 ` [PATCH v4 " Masatake YAMATO
@ 2012-07-25 0:12 ` Gustavo Padovan
2012-07-25 0:35 ` Gustavo Padovan
0 siblings, 1 reply; 46+ messages in thread
From: Gustavo Padovan @ 2012-07-25 0:12 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Hi Masatake,
* Masatake YAMATO <yamato@redhat.com> [2012-07-16 22:20:18 +0900]:
> (I resend this mail becasue I got some troubles in mail sending.
> Andrei, [PATCH v4 [2-8]/8] are the same as [PATCH v3 [2-8]/8]. So
> I send [PATCH v4 1/8] only here. If I should the rest of v4 patches,
> please, let me know that.)
Please keep this kind of information after the --- line, so git am
automatically skip this when applying, otherwise I have to edit the commit
message by hand.
>
> lsof command can tell the type of socket processes are using.
> Internal lsof uses inode numbers on socket fs to resolve the type of
> sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
> such inode information.
>
> Unfortunately bluetooth related protocols don't provide such inode
> information. This patch series introduces /proc/net files for the protocols.
>
> This patch against af_bluetooth.c provides facility to the implementation
> of protocols. This patch extends bt_sock_list and introduces two exported
> function bt_procfs_init, bt_procfs_cleanup.
>
> The type bt_sock_list is already used in some of implementation of
> protocols. bt_procfs_init prepare seq_operations which converts
> protocol own bt_sock_list data to protocol own proc entry when the
> entry is accessed.
>
> What I, lsof user, need is just inode number of bluetooth
> socket. However, people may want more information. The bt_procfs_init
> takes a function pointer for customizing the show handler of
> seq_operations.
>
> In v4 patch, __acquires and __releases attributes are added to suppress
> sparse warning. Suggested by Andrei Emeltchenko.
>
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
> include/net/bluetooth/bluetooth.h | 10 +++
> net/bluetooth/af_bluetooth.c | 138 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 148 insertions(+)
Patch has been applied to bluetooth-next, however I had to fix a minor
issue...
>
> diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> index 565d4be..ede0369 100644
> --- a/include/net/bluetooth/bluetooth.h
> +++ b/include/net/bluetooth/bluetooth.h
> @@ -27,6 +27,7 @@
>
> #include <linux/poll.h>
> #include <net/sock.h>
> +#include <linux/seq_file.h>
>
> #ifndef AF_BLUETOOTH
> #define AF_BLUETOOTH 31
> @@ -202,6 +203,10 @@ enum {
> struct bt_sock_list {
> struct hlist_head head;
> rwlock_t lock;
> +#ifdef CONFIG_PROC_FS
> + struct file_operations fops;
> + int (* custom_seq_show)(struct seq_file *, void *);
> +#endif
> };
>
> int bt_sock_register(int proto, const struct net_proto_family *ops);
> @@ -292,6 +297,11 @@ extern void hci_sock_cleanup(void);
> extern int bt_sysfs_init(void);
> extern void bt_sysfs_cleanup(void);
>
> +extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
> + struct bt_sock_list* sk_list,
> + int (* seq_show)(struct seq_file *, void *));
> +extern void bt_procfs_cleanup(struct net *net, const char *name);
> +
> extern struct dentry *bt_debugfs;
>
> int l2cap_init(void);
> diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
> index f7db579..f76cf2f 100644
> --- a/net/bluetooth/af_bluetooth.c
> +++ b/net/bluetooth/af_bluetooth.c
> @@ -532,6 +532,144 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
> }
> EXPORT_SYMBOL(bt_sock_wait_state);
>
> +#ifdef CONFIG_PROC_FS
> +struct bt_seq_state {
> + struct bt_sock_list *l;
> +};
> +
> +static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
> + __acquires(seq->private->l->lock)
> +{
> + struct bt_seq_state *s = seq->private;
> + struct bt_sock_list *l = s->l;
> +
> + read_lock(&l->lock);
> + return seq_hlist_start_head(&l->head, *pos);
> +}
> +
> +static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
> +{
> + struct bt_seq_state *s = seq->private;
> + struct bt_sock_list *l = s->l;
> +
> + return seq_hlist_next(v, &l->head, pos);
> +}
> +
> +static void bt_seq_stop(struct seq_file *seq, void *v)
> + __releases(seq->private->l->lock)
> +{
> + struct bt_seq_state *s = seq->private;
> + struct bt_sock_list *l = s->l;
> +
> + read_unlock(&l->lock);
> +}
> +
> +static int bt_seq_show(struct seq_file *seq, void *v)
> +{
> + struct sock *sk;
> + struct bt_sock *bt;
> + struct bt_seq_state *s = seq->private;
> + struct bt_sock_list *l = s->l;
> + bdaddr_t src_baswapped, dst_baswapped;
> +
> + if (v == SEQ_START_TOKEN) {
> + seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
> +
> + if (l->custom_seq_show) {
> + seq_putc(seq, ' ');
> + l->custom_seq_show(seq, v);
> + }
> +
> + seq_putc(seq, '\n');
> + } else {
> + sk = sk_entry(v);
> + bt = bt_sk(sk);
> + baswap(&src_baswapped, &bt->src);
> + baswap(&dst_baswapped, &bt->dst);
> +
> + seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
> + sk,
> + atomic_read(&sk->sk_refcnt),
> + sk_rmem_alloc_get(sk),
> + sk_wmem_alloc_get(sk),
> + sock_i_uid(sk),
> + sock_i_ino(sk),
> + &src_baswapped,
> + &dst_baswapped,
> + bt->parent? sock_i_ino(bt->parent): 0LU);
> +
> + if (l->custom_seq_show) {
> + seq_putc(seq, ' ');
> + l->custom_seq_show(seq, v);
> + }
> +
> + seq_putc(seq, '\n');
> + }
> + return 0;
> +}
> +
> +static struct seq_operations bt_seq_ops = {
> + .start = bt_seq_start,
> + .next = bt_seq_next,
> + .stop = bt_seq_stop,
> + .show = bt_seq_show,
> +};
> +
> +static int bt_seq_open(struct inode *inode, struct file *file)
> +{
> + struct bt_sock_list *sk_list;
> + struct bt_seq_state *s;
> +
> + sk_list = PDE(inode)->data;
> + s = __seq_open_private(file, &bt_seq_ops,
> + sizeof(struct bt_seq_state));
> + if (s == NULL)
> + return -ENOMEM;
> +
> + s->l = sk_list;
> + return 0;
> +}
> +
> +int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
> + int (* seq_show)(struct seq_file *, void *))
... the identation here is a bit wrong, I fixed it. Thanks for doing this
work.
Gustavo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v3 2/8] bluetooth: Added /proc/net/bnep via bt_procfs_init()
2012-07-11 4:59 ` [PATCH v3 2/8] bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
@ 2012-07-25 0:20 ` Gustavo Padovan
0 siblings, 0 replies; 46+ messages in thread
From: Gustavo Padovan @ 2012-07-25 0:20 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Hi Masatake,
* Masatake YAMATO <yamato@redhat.com> [2012-07-11 13:59:35 +0900]:
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
> net/bluetooth/bnep/sock.c | 22 ++++++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
For the rest of the series I'd like you add some commit message to your patch,
only a commit title is not acceptable, even if in a simple patch. Also use
"Bluetooth" and not "bluetooth" in the subject line please.
Gustavo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v4 1/8] bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-25 0:12 ` Gustavo Padovan
@ 2012-07-25 0:35 ` Gustavo Padovan
2012-07-25 16:26 ` [PATCH v5 1/8] Bluetooth: " Masatake YAMATO
` (7 more replies)
0 siblings, 8 replies; 46+ messages in thread
From: Gustavo Padovan @ 2012-07-25 0:35 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
* Gustavo Padovan <gustavo@padovan.org> [2012-07-24 21:12:14 -0300]:
> Hi Masatake,
>
> * Masatake YAMATO <yamato@redhat.com> [2012-07-16 22:20:18 +0900]:
>
> > (I resend this mail becasue I got some troubles in mail sending.
> > Andrei, [PATCH v4 [2-8]/8] are the same as [PATCH v3 [2-8]/8]. So
> > I send [PATCH v4 1/8] only here. If I should the rest of v4 patches,
> > please, let me know that.)
>
> Please keep this kind of information after the --- line, so git am
> automatically skip this when applying, otherwise I have to edit the commit
> message by hand.
>
> >
> > lsof command can tell the type of socket processes are using.
> > Internal lsof uses inode numbers on socket fs to resolve the type of
> > sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
> > such inode information.
> >
> > Unfortunately bluetooth related protocols don't provide such inode
> > information. This patch series introduces /proc/net files for the protocols.
> >
> > This patch against af_bluetooth.c provides facility to the implementation
> > of protocols. This patch extends bt_sock_list and introduces two exported
> > function bt_procfs_init, bt_procfs_cleanup.
> >
> > The type bt_sock_list is already used in some of implementation of
> > protocols. bt_procfs_init prepare seq_operations which converts
> > protocol own bt_sock_list data to protocol own proc entry when the
> > entry is accessed.
> >
> > What I, lsof user, need is just inode number of bluetooth
> > socket. However, people may want more information. The bt_procfs_init
> > takes a function pointer for customizing the show handler of
> > seq_operations.
> >
> > In v4 patch, __acquires and __releases attributes are added to suppress
> > sparse warning. Suggested by Andrei Emeltchenko.
> >
> > Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> > ---
> > include/net/bluetooth/bluetooth.h | 10 +++
> > net/bluetooth/af_bluetooth.c | 138 +++++++++++++++++++++++++++++++++++++
> > 2 files changed, 148 insertions(+)
>
> Patch has been applied to bluetooth-next, however I had to fix a minor
> issue...
>
> >
> > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> > index 565d4be..ede0369 100644
> > --- a/include/net/bluetooth/bluetooth.h
> > +++ b/include/net/bluetooth/bluetooth.h
> > @@ -27,6 +27,7 @@
> >
> > #include <linux/poll.h>
> > #include <net/sock.h>
> > +#include <linux/seq_file.h>
> >
> > #ifndef AF_BLUETOOTH
> > #define AF_BLUETOOTH 31
> > @@ -202,6 +203,10 @@ enum {
> > struct bt_sock_list {
> > struct hlist_head head;
> > rwlock_t lock;
> > +#ifdef CONFIG_PROC_FS
> > + struct file_operations fops;
> > + int (* custom_seq_show)(struct seq_file *, void *);
> > +#endif
> > };
> >
> > int bt_sock_register(int proto, const struct net_proto_family *ops);
> > @@ -292,6 +297,11 @@ extern void hci_sock_cleanup(void);
> > extern int bt_sysfs_init(void);
> > extern void bt_sysfs_cleanup(void);
> >
> > +extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
> > + struct bt_sock_list* sk_list,
> > + int (* seq_show)(struct seq_file *, void *));
> > +extern void bt_procfs_cleanup(struct net *net, const char *name);
> > +
> > extern struct dentry *bt_debugfs;
> >
> > int l2cap_init(void);
> > diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
> > index f7db579..f76cf2f 100644
> > --- a/net/bluetooth/af_bluetooth.c
> > +++ b/net/bluetooth/af_bluetooth.c
> > @@ -532,6 +532,144 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
> > }
> > EXPORT_SYMBOL(bt_sock_wait_state);
> >
> > +#ifdef CONFIG_PROC_FS
> > +struct bt_seq_state {
> > + struct bt_sock_list *l;
> > +};
> > +
> > +static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
> > + __acquires(seq->private->l->lock)
> > +{
> > + struct bt_seq_state *s = seq->private;
> > + struct bt_sock_list *l = s->l;
> > +
> > + read_lock(&l->lock);
> > + return seq_hlist_start_head(&l->head, *pos);
> > +}
> > +
> > +static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
> > +{
> > + struct bt_seq_state *s = seq->private;
> > + struct bt_sock_list *l = s->l;
> > +
> > + return seq_hlist_next(v, &l->head, pos);
> > +}
> > +
> > +static void bt_seq_stop(struct seq_file *seq, void *v)
> > + __releases(seq->private->l->lock)
> > +{
> > + struct bt_seq_state *s = seq->private;
> > + struct bt_sock_list *l = s->l;
> > +
> > + read_unlock(&l->lock);
> > +}
> > +
> > +static int bt_seq_show(struct seq_file *seq, void *v)
> > +{
> > + struct sock *sk;
> > + struct bt_sock *bt;
> > + struct bt_seq_state *s = seq->private;
> > + struct bt_sock_list *l = s->l;
> > + bdaddr_t src_baswapped, dst_baswapped;
> > +
> > + if (v == SEQ_START_TOKEN) {
> > + seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
> > +
> > + if (l->custom_seq_show) {
> > + seq_putc(seq, ' ');
> > + l->custom_seq_show(seq, v);
> > + }
> > +
> > + seq_putc(seq, '\n');
> > + } else {
> > + sk = sk_entry(v);
> > + bt = bt_sk(sk);
> > + baswap(&src_baswapped, &bt->src);
> > + baswap(&dst_baswapped, &bt->dst);
> > +
> > + seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
> > + sk,
> > + atomic_read(&sk->sk_refcnt),
> > + sk_rmem_alloc_get(sk),
> > + sk_wmem_alloc_get(sk),
> > + sock_i_uid(sk),
> > + sock_i_ino(sk),
> > + &src_baswapped,
> > + &dst_baswapped,
> > + bt->parent? sock_i_ino(bt->parent): 0LU);
> > +
> > + if (l->custom_seq_show) {
> > + seq_putc(seq, ' ');
> > + l->custom_seq_show(seq, v);
> > + }
> > +
> > + seq_putc(seq, '\n');
> > + }
> > + return 0;
> > +}
> > +
> > +static struct seq_operations bt_seq_ops = {
> > + .start = bt_seq_start,
> > + .next = bt_seq_next,
> > + .stop = bt_seq_stop,
> > + .show = bt_seq_show,
> > +};
> > +
> > +static int bt_seq_open(struct inode *inode, struct file *file)
> > +{
> > + struct bt_sock_list *sk_list;
> > + struct bt_seq_state *s;
> > +
> > + sk_list = PDE(inode)->data;
> > + s = __seq_open_private(file, &bt_seq_ops,
> > + sizeof(struct bt_seq_state));
> > + if (s == NULL)
> > + return -ENOMEM;
> > +
> > + s->l = sk_list;
> > + return 0;
> > +}
> > +
> > +int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
> > + int (* seq_show)(struct seq_file *, void *))
>
> ... the identation here is a bit wrong, I fixed it. Thanks for doing this
> work.
I reverted this patch, it is not building.
Gustavo
^ permalink raw reply [flat|nested] 46+ messages in thread
* [PATCH v5 1/8] Bluetooth: /proc/net/ entries for bluetooth protocols
2012-07-25 0:35 ` Gustavo Padovan
@ 2012-07-25 16:26 ` Masatake YAMATO
2012-07-25 16:27 ` [PATCH v5 2/8] Bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
` (6 subsequent siblings)
7 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:26 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
lsof command can tell the type of socket processes are using.
Internal lsof uses inode numbers on socket fs to resolve the type of
sockets. Files under /proc/net/, such as tcp, udp, unix, etc provides
such inode information.
Unfortunately bluetooth related protocols don't provide such inode
information. This patch series introduces /proc/net files for the protocols.
This patch against af_bluetooth.c provides facility to the implementation
of protocols. This patch extends bt_sock_list and introduces two exported
function bt_procfs_init, bt_procfs_cleanup.
The type bt_sock_list is already used in some of implementation of
protocols. bt_procfs_init prepare seq_operations which converts
protocol own bt_sock_list data to protocol own proc entry when the
entry is accessed.
What I, lsof user, need is just inode number of bluetooth
socket. However, people may want more information. The bt_procfs_init
takes a function pointer for customizing the show handler of
seq_operations.
In v4 patch, __acquires and __releases attributes are added to suppress
sparse warning. Suggested by Andrei Emeltchenko.
In v5 patch, linux/proc_fs.h is included to use PDE. Build error is
reported by Fengguang Wu.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
include/net/bluetooth/bluetooth.h | 10 +++
net/bluetooth/af_bluetooth.c | 139 +++++++++++++++++++++++++++++++++++++
2 files changed, 149 insertions(+)
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 565d4be..ede0369 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -27,6 +27,7 @@
#include <linux/poll.h>
#include <net/sock.h>
+#include <linux/seq_file.h>
#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
@@ -202,6 +203,10 @@ enum {
struct bt_sock_list {
struct hlist_head head;
rwlock_t lock;
+#ifdef CONFIG_PROC_FS
+ struct file_operations fops;
+ int (* custom_seq_show)(struct seq_file *, void *);
+#endif
};
int bt_sock_register(int proto, const struct net_proto_family *ops);
@@ -292,6 +297,11 @@ extern void hci_sock_cleanup(void);
extern int bt_sysfs_init(void);
extern void bt_sysfs_cleanup(void);
+extern int bt_procfs_init(struct module* module, struct net *net, const char *name,
+ struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *));
+extern void bt_procfs_cleanup(struct net *net, const char *name);
+
extern struct dentry *bt_debugfs;
int l2cap_init(void);
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index f7db579..1a03c81 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -28,6 +28,7 @@
#include <asm/ioctls.h>
#include <net/bluetooth/bluetooth.h>
+#include <linux/proc_fs.h>
#define VERSION "2.16"
@@ -532,6 +533,144 @@ int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo)
}
EXPORT_SYMBOL(bt_sock_wait_state);
+#ifdef CONFIG_PROC_FS
+struct bt_seq_state {
+ struct bt_sock_list *l;
+};
+
+static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
+ __acquires(seq->private->l->lock)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_lock(&l->lock);
+ return seq_hlist_start_head(&l->head, *pos);
+}
+
+static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ return seq_hlist_next(v, &l->head, pos);
+}
+
+static void bt_seq_stop(struct seq_file *seq, void *v)
+ __releases(seq->private->l->lock)
+{
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+
+ read_unlock(&l->lock);
+}
+
+static int bt_seq_show(struct seq_file *seq, void *v)
+{
+ struct sock *sk;
+ struct bt_sock *bt;
+ struct bt_seq_state *s = seq->private;
+ struct bt_sock_list *l = s->l;
+ bdaddr_t src_baswapped, dst_baswapped;
+
+ if (v == SEQ_START_TOKEN) {
+ seq_puts(seq ,"sk RefCnt Rmem Wmem User Inode Src Dst Parent");
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ } else {
+ sk = sk_entry(v);
+ bt = bt_sk(sk);
+ baswap(&src_baswapped, &bt->src);
+ baswap(&dst_baswapped, &bt->dst);
+
+ seq_printf(seq, "%pK %-6d %-6u %-6u %-6u %-6lu %pM %pM %-6lu",
+ sk,
+ atomic_read(&sk->sk_refcnt),
+ sk_rmem_alloc_get(sk),
+ sk_wmem_alloc_get(sk),
+ sock_i_uid(sk),
+ sock_i_ino(sk),
+ &src_baswapped,
+ &dst_baswapped,
+ bt->parent? sock_i_ino(bt->parent): 0LU);
+
+ if (l->custom_seq_show) {
+ seq_putc(seq, ' ');
+ l->custom_seq_show(seq, v);
+ }
+
+ seq_putc(seq, '\n');
+ }
+ return 0;
+}
+
+static struct seq_operations bt_seq_ops = {
+ .start = bt_seq_start,
+ .next = bt_seq_next,
+ .stop = bt_seq_stop,
+ .show = bt_seq_show,
+};
+
+static int bt_seq_open(struct inode *inode, struct file *file)
+{
+ struct bt_sock_list *sk_list;
+ struct bt_seq_state *s;
+
+ sk_list = PDE(inode)->data;
+ s = __seq_open_private(file, &bt_seq_ops,
+ sizeof(struct bt_seq_state));
+ if (s == NULL)
+ return -ENOMEM;
+
+ s->l = sk_list;
+ return 0;
+}
+
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ struct proc_dir_entry * pde;
+
+ sk_list->custom_seq_show = seq_show;
+
+ sk_list->fops.owner = module;
+ sk_list->fops.open = bt_seq_open;
+ sk_list->fops.read = seq_read;
+ sk_list->fops.llseek = seq_lseek;
+ sk_list->fops.release = seq_release_private;
+
+ pde = proc_net_fops_create(net, name, 0, &sk_list->fops);
+ if (pde == NULL)
+ return -ENOMEM;
+
+ pde->data = sk_list;
+
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+ proc_net_remove(net, name);
+}
+#else
+int bt_procfs_init(struct module* module, struct net *net, const char *name, struct bt_sock_list* sk_list,
+ int (* seq_show)(struct seq_file *, void *))
+{
+ return 0;
+}
+
+void bt_procfs_cleanup(struct net *net, const char *name)
+{
+}
+#endif
+EXPORT_SYMBOL(bt_procfs_init);
+EXPORT_SYMBOL(bt_procfs_cleanup);
+
static struct net_proto_family bt_sock_family_ops = {
.owner = THIS_MODULE,
.family = PF_BLUETOOTH,
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v5 2/8] Bluetooth: Added /proc/net/bnep via bt_procfs_init()
2012-07-25 0:35 ` Gustavo Padovan
2012-07-25 16:26 ` [PATCH v5 1/8] Bluetooth: " Masatake YAMATO
@ 2012-07-25 16:27 ` Masatake YAMATO
2012-07-25 16:28 ` [PATCH v5 3/8] Bluetooth: Added /proc/net/cmtp " Masatake YAMATO
` (5 subsequent siblings)
7 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:27 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Added /proc/net/bnep via bt_procfs_init().
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/bnep/sock.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index 5e5f5b4..5b6cc0b 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -29,6 +29,10 @@
#include "bnep.h"
+static struct bt_sock_list bnep_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(bnep_sk_list.lock)
+};
+
static int bnep_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -38,6 +42,8 @@ static int bnep_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&bnep_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
return 0;
@@ -204,6 +210,7 @@ static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&bnep_sk_list, sk);
return 0;
}
@@ -222,19 +229,30 @@ int __init bnep_sock_init(void)
return err;
err = bt_sock_register(BTPROTO_BNEP, &bnep_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register BNEP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "bnep", &bnep_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create BNEP proc file");
+ bt_sock_unregister(BTPROTO_BNEP);
+ goto error;
+ }
+
+ BT_INFO("BNEP socket layer initialized");
return 0;
error:
- BT_ERR("Can't register BNEP socket");
proto_unregister(&bnep_proto);
return err;
}
void __exit bnep_sock_cleanup(void)
{
+ bt_procfs_cleanup(&init_net, "bnep");
if (bt_sock_unregister(BTPROTO_BNEP) < 0)
BT_ERR("Can't unregister BNEP socket");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v5 3/8] Bluetooth: Added /proc/net/cmtp via bt_procfs_init()
2012-07-25 0:35 ` Gustavo Padovan
2012-07-25 16:26 ` [PATCH v5 1/8] Bluetooth: " Masatake YAMATO
2012-07-25 16:27 ` [PATCH v5 2/8] Bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
@ 2012-07-25 16:28 ` Masatake YAMATO
2012-07-25 16:28 ` [PATCH v5 4/8] Bluetooth: Added /proc/net/hci " Masatake YAMATO
` (4 subsequent siblings)
7 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:28 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Added /proc/net/cmtp via bt_procfs_init().
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/cmtp/sock.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c
index 311668d..d5cacef 100644
--- a/net/bluetooth/cmtp/sock.c
+++ b/net/bluetooth/cmtp/sock.c
@@ -42,6 +42,10 @@
#include "cmtp.h"
+static struct bt_sock_list cmtp_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(cmtp_sk_list.lock)
+};
+
static int cmtp_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -51,6 +55,8 @@ static int cmtp_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&cmtp_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
@@ -214,6 +220,8 @@ static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&cmtp_sk_list, sk);
+
return 0;
}
@@ -232,19 +240,30 @@ int cmtp_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_CMTP, &cmtp_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register CMTP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "cmtp", &cmtp_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create CMTP proc file");
+ bt_sock_unregister(BTPROTO_HIDP);
+ goto error;
+ }
+
+ BT_INFO("CMTP socket layer initialized");
return 0;
error:
- BT_ERR("Can't register CMTP socket");
proto_unregister(&cmtp_proto);
return err;
}
void cmtp_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "cmtp");
if (bt_sock_unregister(BTPROTO_CMTP) < 0)
BT_ERR("Can't unregister CMTP socket");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v5 4/8] Bluetooth: Added /proc/net/hci via bt_procfs_init()
2012-07-25 0:35 ` Gustavo Padovan
` (2 preceding siblings ...)
2012-07-25 16:28 ` [PATCH v5 3/8] Bluetooth: Added /proc/net/cmtp " Masatake YAMATO
@ 2012-07-25 16:28 ` Masatake YAMATO
2012-07-25 16:29 ` [PATCH v5 5/8] Bluetooth: Added /proc/net/hidp " Masatake YAMATO
` (3 subsequent siblings)
7 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:28 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Added /proc/net/hci via bt_procfs_init().
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/hci_sock.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index a7f04de..7c3d6c7 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1100,21 +1100,30 @@ int __init hci_sock_init(void)
return err;
err = bt_sock_register(BTPROTO_HCI, &hci_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("HCI socket registration failed");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "hci", &hci_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create HCI proc file");
+ bt_sock_unregister(BTPROTO_HCI);
+ goto error;
+ }
BT_INFO("HCI socket layer initialized");
return 0;
error:
- BT_ERR("HCI socket registration failed");
proto_unregister(&hci_sk_proto);
return err;
}
void hci_sock_cleanup(void)
{
+ bt_procfs_cleanup(&init_net, "hci");
if (bt_sock_unregister(BTPROTO_HCI) < 0)
BT_ERR("HCI socket unregistration failed");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v5 5/8] Bluetooth: Added /proc/net/hidp via bt_procfs_init()
2012-07-25 0:35 ` Gustavo Padovan
` (3 preceding siblings ...)
2012-07-25 16:28 ` [PATCH v5 4/8] Bluetooth: Added /proc/net/hci " Masatake YAMATO
@ 2012-07-25 16:29 ` Masatake YAMATO
2012-07-25 16:29 ` [PATCH v5 6/8] Bluetooth: Added /proc/net/l2cap " Masatake YAMATO
` (2 subsequent siblings)
7 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:29 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Added /proc/net/hidp via bt_procfs_init().
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/hidp/sock.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 18b3f68..eca3889 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -25,6 +25,10 @@
#include "hidp.h"
+static struct bt_sock_list hidp_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(hidp_sk_list.lock)
+};
+
static int hidp_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
@@ -34,6 +38,8 @@ static int hidp_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&hidp_sk_list, sk);
+
sock_orphan(sk);
sock_put(sk);
@@ -253,6 +259,8 @@ static int hidp_sock_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
sk->sk_state = BT_OPEN;
+ bt_sock_link(&hidp_sk_list, sk);
+
return 0;
}
@@ -271,8 +279,19 @@ int __init hidp_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_HIDP, &hidp_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("Can't register HIDP socket");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "hidp", &hidp_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create HIDP proc file");
+ bt_sock_unregister(BTPROTO_HIDP);
+ goto error;
+ }
+
+ BT_INFO("HIDP socket layer initialized");
return 0;
@@ -284,6 +303,7 @@ error:
void __exit hidp_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "hidp");
if (bt_sock_unregister(BTPROTO_HIDP) < 0)
BT_ERR("Can't unregister HIDP socket");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v5 6/8] Bluetooth: Added /proc/net/l2cap via bt_procfs_init()
2012-07-25 0:35 ` Gustavo Padovan
` (4 preceding siblings ...)
2012-07-25 16:29 ` [PATCH v5 5/8] Bluetooth: Added /proc/net/hidp " Masatake YAMATO
@ 2012-07-25 16:29 ` Masatake YAMATO
2012-07-25 16:29 ` [PATCH v5 7/8] Bluetooth: Added /proc/net/rfcomm " Masatake YAMATO
2012-07-25 16:30 ` [PATCH v5 8/8] Added /proc/net/sco " Masatake YAMATO
7 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:29 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Added /proc/net/l2cap via bt_procfs_init().
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/l2cap_sock.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index a4bb27e..04bd647 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -34,6 +34,10 @@
#include <net/bluetooth/l2cap.h>
#include <net/bluetooth/smp.h>
+static struct bt_sock_list l2cap_sk_list = {
+ .lock = __RW_LOCK_UNLOCKED(l2cap_sk_list.lock)
+};
+
static const struct proto_ops l2cap_sock_ops;
static void l2cap_sock_init(struct sock *sk, struct sock *parent);
static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio);
@@ -886,6 +890,8 @@ static int l2cap_sock_release(struct socket *sock)
if (!sk)
return 0;
+ bt_sock_unlink(&l2cap_sk_list, sk);
+
err = l2cap_sock_shutdown(sock, 2);
sock_orphan(sk);
@@ -1210,6 +1216,7 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
return -ENOMEM;
l2cap_sock_init(sk, NULL);
+ bt_sock_link(&l2cap_sk_list, sk);
return 0;
}
@@ -1248,21 +1255,30 @@ int __init l2cap_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_L2CAP, &l2cap_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("L2CAP socket registration failed");
goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "l2cap", &l2cap_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create L2CAP proc file");
+ bt_sock_unregister(BTPROTO_L2CAP);
+ goto error;
+ }
BT_INFO("L2CAP socket layer initialized");
return 0;
error:
- BT_ERR("L2CAP socket registration failed");
proto_unregister(&l2cap_proto);
return err;
}
void l2cap_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "l2cap");
if (bt_sock_unregister(BTPROTO_L2CAP) < 0)
BT_ERR("L2CAP socket unregistration failed");
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v5 7/8] Bluetooth: Added /proc/net/rfcomm via bt_procfs_init()
2012-07-25 0:35 ` Gustavo Padovan
` (5 preceding siblings ...)
2012-07-25 16:29 ` [PATCH v5 6/8] Bluetooth: Added /proc/net/l2cap " Masatake YAMATO
@ 2012-07-25 16:29 ` Masatake YAMATO
2012-07-25 16:30 ` [PATCH v5 8/8] Added /proc/net/sco " Masatake YAMATO
7 siblings, 0 replies; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:29 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Added /proc/net/rfcomm via bt_procfs_init().
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/rfcomm/sock.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 7e1e596..260821a 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -1033,8 +1033,17 @@ int __init rfcomm_init_sockets(void)
return err;
err = bt_sock_register(BTPROTO_RFCOMM, &rfcomm_sock_family_ops);
- if (err < 0)
+ if (err < 0) {
+ BT_ERR("RFCOMM socket layer registration failed");
+ goto error;
+ }
+
+ err = bt_procfs_init(THIS_MODULE, &init_net, "rfcomm", &rfcomm_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create RFCOMM proc file");
+ bt_sock_unregister(BTPROTO_RFCOMM);
goto error;
+ }
if (bt_debugfs) {
rfcomm_sock_debugfs = debugfs_create_file("rfcomm", 0444,
@@ -1048,13 +1057,14 @@ int __init rfcomm_init_sockets(void)
return 0;
error:
- BT_ERR("RFCOMM socket layer registration failed");
proto_unregister(&rfcomm_proto);
return err;
}
void __exit rfcomm_cleanup_sockets(void)
{
+ bt_procfs_cleanup(&init_net, "rfcomm");
+
debugfs_remove(rfcomm_sock_debugfs);
if (bt_sock_unregister(BTPROTO_RFCOMM) < 0)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* [PATCH v5 8/8] Added /proc/net/sco via bt_procfs_init()
2012-07-25 0:35 ` Gustavo Padovan
` (6 preceding siblings ...)
2012-07-25 16:29 ` [PATCH v5 7/8] Bluetooth: Added /proc/net/rfcomm " Masatake YAMATO
@ 2012-07-25 16:30 ` Masatake YAMATO
2012-07-26 4:24 ` Gustavo Padovan
7 siblings, 1 reply; 46+ messages in thread
From: Masatake YAMATO @ 2012-07-25 16:30 UTC (permalink / raw)
To: gustavo; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Added /proc/net/sco via bt_procfs_init().
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
net/bluetooth/sco.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 0ef5a78..caa109d 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -1023,6 +1023,13 @@ int __init sco_init(void)
goto error;
}
+ err = bt_procfs_init(THIS_MODULE, &init_net, "sco", &sco_sk_list, NULL);
+ if (err < 0) {
+ BT_ERR("Failed to create SCO proc file");
+ bt_sock_unregister(BTPROTO_SCO);
+ goto error;
+ }
+
if (bt_debugfs) {
sco_debugfs = debugfs_create_file("sco", 0444, bt_debugfs,
NULL, &sco_debugfs_fops);
@@ -1041,6 +1048,8 @@ error:
void __exit sco_exit(void)
{
+ bt_procfs_cleanup(&init_net, "sco");
+
debugfs_remove(sco_debugfs);
if (bt_sock_unregister(BTPROTO_SCO) < 0)
--
1.7.10.4
^ permalink raw reply related [flat|nested] 46+ messages in thread
* Re: [PATCH v5 8/8] Added /proc/net/sco via bt_procfs_init()
2012-07-25 16:30 ` [PATCH v5 8/8] Added /proc/net/sco " Masatake YAMATO
@ 2012-07-26 4:24 ` Gustavo Padovan
2012-08-15 15:22 ` Jan Engelhardt
0 siblings, 1 reply; 46+ messages in thread
From: Gustavo Padovan @ 2012-07-26 4:24 UTC (permalink / raw)
To: Masatake YAMATO; +Cc: andrei.emeltchenko.news, linux-kernel, linux-bluetooth
Hi Masatake,
* Masatake YAMATO <yamato@redhat.com> [2012-07-26 01:30:12 +0900]:
> Added /proc/net/sco via bt_procfs_init().
>
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
> net/bluetooth/sco.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
All 8 patches have been applied to bluetooth-next. Thanks.
Gustavo
^ permalink raw reply [flat|nested] 46+ messages in thread
* Re: [PATCH v5 8/8] Added /proc/net/sco via bt_procfs_init()
2012-07-26 4:24 ` Gustavo Padovan
@ 2012-08-15 15:22 ` Jan Engelhardt
0 siblings, 0 replies; 46+ messages in thread
From: Jan Engelhardt @ 2012-08-15 15:22 UTC (permalink / raw)
To: Gustavo Padovan
Cc: Masatake YAMATO, andrei.emeltchenko.news, linux-kernel,
linux-bluetooth
On Thursday 2012-07-26 06:24, Gustavo Padovan wrote:
>Hi Masatake,
>
>* Masatake YAMATO <yamato@redhat.com> [2012-07-26 01:30:12 +0900]:
>
>> Added /proc/net/sco via bt_procfs_init().
>>
>> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
>> ---
>> net/bluetooth/sco.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>
>All 8 patches have been applied to bluetooth-next. Thanks.
It may have been raised before, but: should not the info be exported
over netlink rather than the oldfashioned and overabused procfs?
^ permalink raw reply [flat|nested] 46+ messages in thread
end of thread, other threads:[~2012-08-15 15:22 UTC | newest]
Thread overview: 46+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-14 17:15 [PATCH 1/8] /proc/net/ entries for bluetooth protocols Masatake YAMATO
2012-06-15 8:00 ` Andrei Emeltchenko
2012-06-17 0:26 ` Masatake YAMATO
2012-06-18 8:28 ` Andrei Emeltchenko
2012-06-28 17:02 ` Masatake YAMATO
2012-07-10 14:04 ` Andrei Emeltchenko
2012-07-11 4:58 ` [PATCH v3 1/8] bluetooth: " Masatake YAMATO
2012-07-11 4:59 ` [PATCH v3 2/8] bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
2012-07-25 0:20 ` Gustavo Padovan
2012-07-11 5:02 ` [PATCH v3 3/8] bluetooth: Added /proc/net/cmtp " Masatake YAMATO
2012-07-11 5:02 ` [PATCH v3 4/8] bluetooth: Added /proc/net/hci " Masatake YAMATO
2012-07-11 5:03 ` [PATCH v3 5/8] bluetooth: Added /proc/net/hidp " Masatake YAMATO
2012-07-11 5:03 ` [PATCH v3 6/8] bluetooth: Added /proc/net/l2cap " Masatake YAMATO
2012-07-11 8:48 ` Andrei Emeltchenko
2012-07-11 9:19 ` Masatake YAMATO
2012-07-11 9:49 ` Andrei Emeltchenko
2012-07-11 5:04 ` [PATCH v3 7/8] bluetooth: Added /proc/net/rfcomm " Masatake YAMATO
2012-07-11 8:49 ` Andrei Emeltchenko
2012-07-11 5:04 ` [PATCH v3 8/8] bluetooth: Added /proc/net/sco " Masatake YAMATO
2012-07-11 11:23 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Andrei Emeltchenko
2012-07-11 12:19 ` Masatake YAMATO
2012-07-12 7:42 ` Andrei Emeltchenko
2012-07-16 13:20 ` [PATCH v4 " Masatake YAMATO
2012-07-25 0:12 ` Gustavo Padovan
2012-07-25 0:35 ` Gustavo Padovan
2012-07-25 16:26 ` [PATCH v5 1/8] Bluetooth: " Masatake YAMATO
2012-07-25 16:27 ` [PATCH v5 2/8] Bluetooth: Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
2012-07-25 16:28 ` [PATCH v5 3/8] Bluetooth: Added /proc/net/cmtp " Masatake YAMATO
2012-07-25 16:28 ` [PATCH v5 4/8] Bluetooth: Added /proc/net/hci " Masatake YAMATO
2012-07-25 16:29 ` [PATCH v5 5/8] Bluetooth: Added /proc/net/hidp " Masatake YAMATO
2012-07-25 16:29 ` [PATCH v5 6/8] Bluetooth: Added /proc/net/l2cap " Masatake YAMATO
2012-07-25 16:29 ` [PATCH v5 7/8] Bluetooth: Added /proc/net/rfcomm " Masatake YAMATO
2012-07-25 16:30 ` [PATCH v5 8/8] Added /proc/net/sco " Masatake YAMATO
2012-07-26 4:24 ` Gustavo Padovan
2012-08-15 15:22 ` Jan Engelhardt
2012-07-24 13:08 ` [PATCH v3 1/8] bluetooth: /proc/net/ entries for bluetooth protocols Masatake YAMATO
2012-07-24 13:15 ` Andrei Emeltchenko
2012-06-18 10:00 ` [PATCH v2 1/8] " Masatake YAMATO
2012-07-10 14:06 ` Andrei Emeltchenko
2012-06-18 10:00 ` [PATCH v2 2/8] Added /proc/net/bnep via bt_procfs_init() Masatake YAMATO
2012-06-18 10:01 ` [PATCH v2 3/8] Added /proc/net/cmtp " Masatake YAMATO
2012-06-18 10:01 ` [PATCH v2 4/8] Added /proc/net/hci " Masatake YAMATO
2012-06-18 10:03 ` [PATCH v2 5/8] Added /proc/net/hidp " Masatake YAMATO
2012-06-18 10:03 ` [PATCH v2 6/8] Added /proc/net/l2cap " Masatake YAMATO
2012-06-18 10:04 ` [PATCH v2 7/8] Added /proc/net/rfcomm " Masatake YAMATO
2012-06-18 10:04 ` [PATCH v2 8/8] Added /proc/net/sco " Masatake YAMATO
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).