]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
libceph: prevent the race of incoming work during teardown
authorGuanjun He <gjhe@suse.com>
Mon, 9 Jul 2012 02:50:33 +0000 (19:50 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 26 Nov 2012 19:38:38 +0000 (11:38 -0800)
(cherry picked from commit a2a3258417eb6a1799cf893350771428875a8287)

Add an atomic variable 'stopping' as flag in struct ceph_messenger,
set this flag to 1 in function ceph_destroy_client(), and add the condition code
in function ceph_data_ready() to test the flag value, if true(1), just return.

Signed-off-by: Guanjun He <gjhe@suse.com>
Reviewed-by: Sage Weil <sage@inktank.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/ceph/messenger.h
net/ceph/ceph_common.c
net/ceph/messenger.c

index ec22abd51fa08ac2c8035b6073de71309d2fcfbb..de39cda6bd58f73dc471e15ea8d7b9f1bcd5b27e 100644 (file)
@@ -50,6 +50,7 @@ struct ceph_messenger {
        struct ceph_entity_inst inst;    /* my name+address */
        struct ceph_entity_addr my_enc_addr;
 
+       atomic_t stopping;
        bool nocrc;
 
        /*
index c815f31a1a3fc470c97ed1e66fb53a1ec5325043..52fe52cde606b244c42bef50d52bb5efbc59aa63 100644 (file)
@@ -495,6 +495,8 @@ void ceph_destroy_client(struct ceph_client *client)
 {
        dout("destroy_client %p\n", client);
 
+       atomic_set(&client->msgr.stopping, 1);
+
        /* unmount */
        ceph_osdc_stop(&client->osdc);
 
index 866645fa857f1c9783fab054965e829e04796085..edd51321ae189babc3b93206a39835ba9fc89cea 100644 (file)
@@ -254,6 +254,9 @@ static void con_sock_state_closed(struct ceph_connection *con)
 static void ceph_sock_data_ready(struct sock *sk, int count_unused)
 {
        struct ceph_connection *con = sk->sk_user_data;
+       if (atomic_read(&con->msgr->stopping)) {
+               return;
+       }
 
        if (sk->sk_state != TCP_CLOSE_WAIT) {
                dout("%s on %p state = %lu, queueing work\n", __func__,
@@ -2413,6 +2416,8 @@ void ceph_messenger_init(struct ceph_messenger *msgr,
        encode_my_addr(msgr);
        msgr->nocrc = nocrc;
 
+       atomic_set(&msgr->stopping, 0);
+
        dout("%s %p\n", __func__, msgr);
 }
 EXPORT_SYMBOL(ceph_messenger_init);