diff mbox

[v2,2/2] dlm: Do not allocate a fd for peeloff

Message ID 1331222159-28980-2-git-send-email-bpoirier@suse.de
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Benjamin Poirier March 8, 2012, 3:55 p.m. UTC
avoids allocating a fd that a) propagates to every kernel thread and
usermodehelper b) is not properly released.

References: http://article.gmane.org/gmane.linux.network.drbd/22529
Signed-off-by: Benjamin Poirier <bpoirier@suse.de>
---
 fs/dlm/lowcomms.c |   22 ++++++++--------------
 1 files changed, 8 insertions(+), 14 deletions(-)

Comments

Vlad Yasevich March 8, 2012, 8:08 p.m. UTC | #1
On 03/08/2012 10:55 AM, Benjamin Poirier wrote:
> avoids allocating a fd that a) propagates to every kernel thread and
> usermodehelper b) is not properly released.
> 
> References: http://article.gmane.org/gmane.linux.network.drbd/22529
> Signed-off-by: Benjamin Poirier <bpoirier@suse.de>

Looks much better.

-vlad

> ---
>  fs/dlm/lowcomms.c |   22 ++++++++--------------
>  1 files changed, 8 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
> index 0b3109e..ca0c59a 100644
> --- a/fs/dlm/lowcomms.c
> +++ b/fs/dlm/lowcomms.c
> @@ -52,6 +52,7 @@
>  #include <linux/mutex.h>
>  #include <linux/sctp.h>
>  #include <linux/slab.h>
> +#include <net/sctp/sctp.h>
>  #include <net/sctp/user.h>
>  #include <net/ipv6.h>
>  
> @@ -474,9 +475,6 @@ static void process_sctp_notification(struct connection *con,
>  			int prim_len, ret;
>  			int addr_len;
>  			struct connection *new_con;
> -			sctp_peeloff_arg_t parg;
> -			int parglen = sizeof(parg);
> -			int err;
>  
>  			/*
>  			 * We get this before any data for an association.
> @@ -525,23 +523,19 @@ static void process_sctp_notification(struct connection *con,
>  				return;
>  
>  			/* Peel off a new sock */
> -			parg.associd = sn->sn_assoc_change.sac_assoc_id;
> -			ret = kernel_getsockopt(con->sock, IPPROTO_SCTP,
> -						SCTP_SOCKOPT_PEELOFF,
> -						(void *)&parg, &parglen);
> +			sctp_lock_sock(con->sock->sk);
> +			ret = sctp_do_peeloff(con->sock->sk,
> +				sn->sn_assoc_change.sac_assoc_id,
> +				&new_con->sock);
> +			sctp_release_sock(con->sock->sk);
>  			if (ret < 0) {
>  				log_print("Can't peel off a socket for "
>  					  "connection %d to node %d: err=%d",
> -					  parg.associd, nodeid, ret);
> -				return;
> -			}
> -			new_con->sock = sockfd_lookup(parg.sd, &err);
> -			if (!new_con->sock) {
> -				log_print("sockfd_lookup error %d", err);
> +					  (int)sn->sn_assoc_change.sac_assoc_id,
> +					  nodeid, ret);
>  				return;
>  			}
>  			add_sock(new_con->sock, new_con);
> -			sockfd_put(new_con->sock);
>  
>  			log_print("connecting to %d sctp association %d",
>  				 nodeid, (int)sn->sn_assoc_change.sac_assoc_id);

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller March 8, 2012, 9:52 p.m. UTC | #2
From: Vladislav Yasevich <vladislav.yasevich@hp.com>
Date: Thu, 08 Mar 2012 15:08:17 -0500

> On 03/08/2012 10:55 AM, Benjamin Poirier wrote:
>> avoids allocating a fd that a) propagates to every kernel thread and
>> usermodehelper b) is not properly released.
>> 
>> References: http://article.gmane.org/gmane.linux.network.drbd/22529
>> Signed-off-by: Benjamin Poirier <bpoirier@suse.de>
> 
> Looks much better.

Also applied to net-next, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 0b3109e..ca0c59a 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -52,6 +52,7 @@ 
 #include <linux/mutex.h>
 #include <linux/sctp.h>
 #include <linux/slab.h>
+#include <net/sctp/sctp.h>
 #include <net/sctp/user.h>
 #include <net/ipv6.h>
 
@@ -474,9 +475,6 @@  static void process_sctp_notification(struct connection *con,
 			int prim_len, ret;
 			int addr_len;
 			struct connection *new_con;
-			sctp_peeloff_arg_t parg;
-			int parglen = sizeof(parg);
-			int err;
 
 			/*
 			 * We get this before any data for an association.
@@ -525,23 +523,19 @@  static void process_sctp_notification(struct connection *con,
 				return;
 
 			/* Peel off a new sock */
-			parg.associd = sn->sn_assoc_change.sac_assoc_id;
-			ret = kernel_getsockopt(con->sock, IPPROTO_SCTP,
-						SCTP_SOCKOPT_PEELOFF,
-						(void *)&parg, &parglen);
+			sctp_lock_sock(con->sock->sk);
+			ret = sctp_do_peeloff(con->sock->sk,
+				sn->sn_assoc_change.sac_assoc_id,
+				&new_con->sock);
+			sctp_release_sock(con->sock->sk);
 			if (ret < 0) {
 				log_print("Can't peel off a socket for "
 					  "connection %d to node %d: err=%d",
-					  parg.associd, nodeid, ret);
-				return;
-			}
-			new_con->sock = sockfd_lookup(parg.sd, &err);
-			if (!new_con->sock) {
-				log_print("sockfd_lookup error %d", err);
+					  (int)sn->sn_assoc_change.sac_assoc_id,
+					  nodeid, ret);
 				return;
 			}
 			add_sock(new_con->sock, new_con);
-			sockfd_put(new_con->sock);
 
 			log_print("connecting to %d sctp association %d",
 				 nodeid, (int)sn->sn_assoc_change.sac_assoc_id);