浏览代码

libceph: prevent the race of incoming work during teardown

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>
Guanjun He 13 年之前
父节点
当前提交
a2a3258417
共有 3 个文件被更改,包括 8 次插入0 次删除
  1. 1 0
      include/linux/ceph/messenger.h
  2. 2 0
      net/ceph/ceph_common.c
  3. 5 0
      net/ceph/messenger.c

+ 1 - 0
include/linux/ceph/messenger.h

@@ -50,6 +50,7 @@ struct ceph_messenger {
 	struct ceph_entity_inst inst;    /* my name+address */
 	struct ceph_entity_inst inst;    /* my name+address */
 	struct ceph_entity_addr my_enc_addr;
 	struct ceph_entity_addr my_enc_addr;
 
 
+	atomic_t stopping;
 	bool nocrc;
 	bool nocrc;
 
 
 	/*
 	/*

+ 2 - 0
net/ceph/ceph_common.c

@@ -495,6 +495,8 @@ void ceph_destroy_client(struct ceph_client *client)
 {
 {
 	dout("destroy_client %p\n", client);
 	dout("destroy_client %p\n", client);
 
 
+	atomic_set(&client->msgr.stopping, 1);
+
 	/* unmount */
 	/* unmount */
 	ceph_osdc_stop(&client->osdc);
 	ceph_osdc_stop(&client->osdc);
 
 

+ 5 - 0
net/ceph/messenger.c

@@ -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)
 static void ceph_sock_data_ready(struct sock *sk, int count_unused)
 {
 {
 	struct ceph_connection *con = sk->sk_user_data;
 	struct ceph_connection *con = sk->sk_user_data;
+	if (atomic_read(&con->msgr->stopping)) {
+		return;
+	}
 
 
 	if (sk->sk_state != TCP_CLOSE_WAIT) {
 	if (sk->sk_state != TCP_CLOSE_WAIT) {
 		dout("%s on %p state = %lu, queueing work\n", __func__,
 		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);
 	encode_my_addr(msgr);
 	msgr->nocrc = nocrc;
 	msgr->nocrc = nocrc;
 
 
+	atomic_set(&msgr->stopping, 0);
+
 	dout("%s %p\n", __func__, msgr);
 	dout("%s %p\n", __func__, msgr);
 }
 }
 EXPORT_SYMBOL(ceph_messenger_init);
 EXPORT_SYMBOL(ceph_messenger_init);