dlm for 4.6
Previous changes introduced the use of socket error reporting for dlm sockets. This set includes two fixes in how the socket error callbacks are used. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJW4ISmAAoJEDgbc8f8gGmqnWgQANnS13rXt4NxnRtNqzrEUmjk NbvP4BxeWKinxhc9ObUnV0CzDllYa2A6Te2AageCQr/qhRKfnnaQJczJ39Xp+289 oSgJJOo4HGCPjshrq9BwGo8ufijUIc0MsT64TzeI3ww58b1eK2CLoC9uiLDyYwjM Hw0PRXU/MAxzOWJIIWgkh78FQmx8fswOSNyK49/p3/INMVNFxn75bd+shtxUOuCp 50gmI6DG4gGJDK3vtIjZStJhW4lcaM3tjGZ9+mcLQF2PZK5zIeHSr3nEfzJ4Qwps 0p55JeiXdfff6RTrxqnJewc+xysmD9594wG0G0VqLsWaLWulDrHZMFsVg1J10frk bk0WwLjsYG/wLVZtKRe+3QwOyqgTxx1Cea8ZYB2yMcFBkDYxFmh8a00kJcVuucnS W+w4rhI9blk1cc4eHhnuBIi5m2jbelu4NPG5722ORtv+gNpBl2ptecqIjfuhr8xE IIF5tnkZb8lBuLyhCmg8in2mKnY5aKSk3kuQ98rDXZUMCLT0PKG2ZNsXJjpX6G38 uQ+sB9rH6c5pIe0S3keS2f2Ly3V7gtBErA0otyxaq/XlxnJeFlLU5G1chHUeW8VP qxhtjDShPuIA97MxE2GA3ehr7r3jbOb+8qOc13E9ygXDyXNN0tb4JIeB0beNLdRx db8Lt+OR10IUawNyuFB9 =qvzY -----END PGP SIGNATURE----- Merge tag 'dlm-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm Pull dlm updates from David Teigland: "Previous changes introduced the use of socket error reporting for dlm sockets. This set includes two fixes in how the socket error callbacks are used" * tag 'dlm-4.6' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm: DLM: Save and restore socket callbacks properly DLM: Replace nodeid_to_addr with kernel_getpeername
This commit is contained in:
commit
d77bed0d4c
|
@ -124,7 +124,10 @@ struct connection {
|
|||
struct connection *othercon;
|
||||
struct work_struct rwork; /* Receive workqueue */
|
||||
struct work_struct swork; /* Send workqueue */
|
||||
void (*orig_error_report)(struct sock *sk);
|
||||
void (*orig_error_report)(struct sock *);
|
||||
void (*orig_data_ready)(struct sock *);
|
||||
void (*orig_state_change)(struct sock *);
|
||||
void (*orig_write_space)(struct sock *);
|
||||
};
|
||||
#define sock2con(x) ((struct connection *)(x)->sk_user_data)
|
||||
|
||||
|
@ -467,16 +470,24 @@ int dlm_lowcomms_connect_node(int nodeid)
|
|||
|
||||
static void lowcomms_error_report(struct sock *sk)
|
||||
{
|
||||
struct connection *con = sock2con(sk);
|
||||
struct connection *con;
|
||||
struct sockaddr_storage saddr;
|
||||
int buflen;
|
||||
void (*orig_report)(struct sock *) = NULL;
|
||||
|
||||
if (nodeid_to_addr(con->nodeid, &saddr, NULL, false)) {
|
||||
read_lock_bh(&sk->sk_callback_lock);
|
||||
con = sock2con(sk);
|
||||
if (con == NULL)
|
||||
goto out;
|
||||
|
||||
orig_report = con->orig_error_report;
|
||||
if (con->sock == NULL ||
|
||||
kernel_getpeername(con->sock, (struct sockaddr *)&saddr, &buflen)) {
|
||||
printk_ratelimited(KERN_ERR "dlm: node %d: socket error "
|
||||
"sending to node %d, port %d, "
|
||||
"sk_err=%d/%d\n", dlm_our_nodeid(),
|
||||
con->nodeid, dlm_config.ci_tcp_port,
|
||||
sk->sk_err, sk->sk_err_soft);
|
||||
return;
|
||||
} else if (saddr.ss_family == AF_INET) {
|
||||
struct sockaddr_in *sin4 = (struct sockaddr_in *)&saddr;
|
||||
|
||||
|
@ -499,22 +510,54 @@ static void lowcomms_error_report(struct sock *sk)
|
|||
dlm_config.ci_tcp_port, sk->sk_err,
|
||||
sk->sk_err_soft);
|
||||
}
|
||||
con->orig_error_report(sk);
|
||||
out:
|
||||
read_unlock_bh(&sk->sk_callback_lock);
|
||||
if (orig_report)
|
||||
orig_report(sk);
|
||||
}
|
||||
|
||||
/* Note: sk_callback_lock must be locked before calling this function. */
|
||||
static void save_callbacks(struct connection *con, struct sock *sk)
|
||||
{
|
||||
lock_sock(sk);
|
||||
con->orig_data_ready = sk->sk_data_ready;
|
||||
con->orig_state_change = sk->sk_state_change;
|
||||
con->orig_write_space = sk->sk_write_space;
|
||||
con->orig_error_report = sk->sk_error_report;
|
||||
release_sock(sk);
|
||||
}
|
||||
|
||||
static void restore_callbacks(struct connection *con, struct sock *sk)
|
||||
{
|
||||
write_lock_bh(&sk->sk_callback_lock);
|
||||
lock_sock(sk);
|
||||
sk->sk_user_data = NULL;
|
||||
sk->sk_data_ready = con->orig_data_ready;
|
||||
sk->sk_state_change = con->orig_state_change;
|
||||
sk->sk_write_space = con->orig_write_space;
|
||||
sk->sk_error_report = con->orig_error_report;
|
||||
release_sock(sk);
|
||||
write_unlock_bh(&sk->sk_callback_lock);
|
||||
}
|
||||
|
||||
/* Make a socket active */
|
||||
static void add_sock(struct socket *sock, struct connection *con)
|
||||
{
|
||||
struct sock *sk = sock->sk;
|
||||
|
||||
write_lock_bh(&sk->sk_callback_lock);
|
||||
con->sock = sock;
|
||||
|
||||
sk->sk_user_data = con;
|
||||
if (!test_bit(CF_IS_OTHERCON, &con->flags))
|
||||
save_callbacks(con, sk);
|
||||
/* Install a data_ready callback */
|
||||
con->sock->sk->sk_data_ready = lowcomms_data_ready;
|
||||
con->sock->sk->sk_write_space = lowcomms_write_space;
|
||||
con->sock->sk->sk_state_change = lowcomms_state_change;
|
||||
con->sock->sk->sk_user_data = con;
|
||||
con->sock->sk->sk_allocation = GFP_NOFS;
|
||||
con->orig_error_report = con->sock->sk->sk_error_report;
|
||||
con->sock->sk->sk_error_report = lowcomms_error_report;
|
||||
sk->sk_data_ready = lowcomms_data_ready;
|
||||
sk->sk_write_space = lowcomms_write_space;
|
||||
sk->sk_state_change = lowcomms_state_change;
|
||||
sk->sk_allocation = GFP_NOFS;
|
||||
sk->sk_error_report = lowcomms_error_report;
|
||||
write_unlock_bh(&sk->sk_callback_lock);
|
||||
}
|
||||
|
||||
/* Add the port number to an IPv6 or 4 sockaddr and return the address
|
||||
|
@ -549,6 +592,8 @@ static void close_connection(struct connection *con, bool and_other,
|
|||
|
||||
mutex_lock(&con->sock_mutex);
|
||||
if (con->sock) {
|
||||
if (!test_bit(CF_IS_OTHERCON, &con->flags))
|
||||
restore_callbacks(con, con->sock->sk);
|
||||
sock_release(con->sock);
|
||||
con->sock = NULL;
|
||||
}
|
||||
|
@ -1190,6 +1235,8 @@ static struct socket *tcp_create_listen_sock(struct connection *con,
|
|||
if (result < 0) {
|
||||
log_print("Failed to set SO_REUSEADDR on socket: %d", result);
|
||||
}
|
||||
sock->sk->sk_user_data = con;
|
||||
|
||||
con->rx_action = tcp_accept_from_sock;
|
||||
con->connect_action = tcp_connect_to_sock;
|
||||
|
||||
|
@ -1271,6 +1318,7 @@ static int sctp_listen_for_all(void)
|
|||
if (result < 0)
|
||||
log_print("Could not set SCTP NODELAY error %d\n", result);
|
||||
|
||||
write_lock_bh(&sock->sk->sk_callback_lock);
|
||||
/* Init con struct */
|
||||
sock->sk->sk_user_data = con;
|
||||
con->sock = sock;
|
||||
|
@ -1278,6 +1326,8 @@ static int sctp_listen_for_all(void)
|
|||
con->rx_action = sctp_accept_from_sock;
|
||||
con->connect_action = sctp_connect_to_sock;
|
||||
|
||||
write_unlock_bh(&sock->sk->sk_callback_lock);
|
||||
|
||||
/* Bind to all addresses. */
|
||||
if (sctp_bind_addrs(con, dlm_config.ci_tcp_port))
|
||||
goto create_delsock;
|
||||
|
|
Loading…
Reference in New Issue
Block a user