RDS: add a sock_destruct callback debug aid
authorsantosh.shilimkar@oracle.com <santosh.shilimkar@oracle.com>
Sat, 22 Aug 2015 22:45:28 +0000 (15:45 -0700)
committerDavid S. Miller <davem@davemloft.net>
Tue, 25 Aug 2015 20:35:30 +0000 (13:35 -0700)
This helps to detect the accidental processes/apps trying to destroy
the RDS socket which they are sharing with other processes/apps.

Reviewed-by: Ajaykumar Hotchandani <ajaykumar.hotchandani@oracle.com>
Signed-off-by: Santosh Shilimkar <ssantosh@kernel.org>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/rds/af_rds.c

index 896834cd3b9adaef201d7d4ee41c0a59dd6206f1..a2f28a6d4dc579a6026e7506c80fd22d11e973a9 100644 (file)
@@ -438,6 +438,14 @@ static const struct proto_ops rds_proto_ops = {
        .sendpage =     sock_no_sendpage,
 };
 
+static void rds_sock_destruct(struct sock *sk)
+{
+       struct rds_sock *rs = rds_sk_to_rs(sk);
+
+       WARN_ON((&rs->rs_item != rs->rs_item.next ||
+                &rs->rs_item != rs->rs_item.prev));
+}
+
 static int __rds_create(struct socket *sock, struct sock *sk, int protocol)
 {
        struct rds_sock *rs;
@@ -445,6 +453,7 @@ static int __rds_create(struct socket *sock, struct sock *sk, int protocol)
        sock_init_data(sock, sk);
        sock->ops               = &rds_proto_ops;
        sk->sk_protocol         = protocol;
+       sk->sk_destruct         = rds_sock_destruct;
 
        rs = rds_sk_to_rs(sk);
        spin_lock_init(&rs->rs_lock);