]> Pileus Git - ~andy/linux/blobdiff - fs/dlm/lowcomms.c
[DLM] Clear othercon pointers when a connection is closed
[~andy/linux] / fs / dlm / lowcomms.c
index 27970a58d29b255aa1d09ebb71a9c11697f9e0c5..d15fd5f9f5c562f17f9a275a2c7646c948d72a83 100644 (file)
@@ -260,7 +260,7 @@ static int nodeid_to_addr(int nodeid, struct sockaddr *retaddr)
 static void lowcomms_data_ready(struct sock *sk, int count_unused)
 {
        struct connection *con = sock2con(sk);
-       if (!test_and_set_bit(CF_READ_PENDING, &con->flags))
+       if (con && !test_and_set_bit(CF_READ_PENDING, &con->flags))
                queue_work(recv_workqueue, &con->rwork);
 }
 
@@ -268,7 +268,7 @@ static void lowcomms_write_space(struct sock *sk)
 {
        struct connection *con = sock2con(sk);
 
-       if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags))
+       if (con && !test_and_set_bit(CF_WRITE_PENDING, &con->flags))
                queue_work(send_workqueue, &con->swork);
 }
 
@@ -327,6 +327,8 @@ static void close_connection(struct connection *con, bool and_other)
        if (con->othercon && and_other) {
                /* Will only re-enter once. */
                close_connection(con->othercon, false);
+               kmem_cache_free(con_cache, con->othercon);
+               con->othercon = NULL;
        }
        if (con->rx_page) {
                __free_page(con->rx_page);
@@ -720,11 +722,17 @@ static int tcp_accept_from_sock(struct connection *con)
                        INIT_WORK(&othercon->rwork, process_recv_sockets);
                        set_bit(CF_IS_OTHERCON, &othercon->flags);
                        newcon->othercon = othercon;
+                       othercon->sock = newsock;
+                       newsock->sk->sk_user_data = othercon;
+                       add_sock(newsock, othercon);
+                       addcon = othercon;
+               }
+               else {
+                       printk("Extra connection from node %d attempted\n", nodeid);
+                       result = -EAGAIN;
+                       mutex_unlock(&newcon->sock_mutex);
+                       goto accept_err;
                }
-               othercon->sock = newsock;
-               newsock->sk->sk_user_data = othercon;
-               add_sock(newsock, othercon);
-               addcon = othercon;
        }
        else {
                newsock->sk->sk_user_data = newcon;
@@ -1400,8 +1408,11 @@ void dlm_lowcomms_stop(void)
        down(&connections_lock);
        for (i = 0; i <= max_nodeid; i++) {
                con = __nodeid2con(i, 0);
-               if (con)
+               if (con) {
                        con->flags |= 0xFF;
+                       if (con->sock)
+                               con->sock->sk->sk_user_data = NULL;
+               }
        }
        up(&connections_lock);
 
@@ -1440,7 +1451,7 @@ int dlm_lowcomms_start(void)
        error = -ENOMEM;
        con_cache = kmem_cache_create("dlm_conn", sizeof(struct connection),
                                      __alignof__(struct connection), 0,
-                                     NULL, NULL);
+                                     NULL);
        if (!con_cache)
                goto out;