Skip to contentSkip to conversation

client: prevent the race of incoming work during teardown

PATCH In review Guanjun He 3 participants 4 messages Jun 21, 2012 – Jul 2, 2012 Ceph common code (libceph)

lore
Share & tools
lore

Guanjun He

author
#0 lore raw

PATCH 1/1 client: prevent the race of incoming work during teardown

Add an atomic variable 'teardowning' 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.

---
 include/linux/ceph/messenger.h |    1 +
 net/ceph/ceph_common.c         |    5 +++--
 net/ceph/messenger.c           |    5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)
include/linux/ceph/messenger.h +1 -0
index 2521a95..70ff3b7 100644
@@ -54,6 +54,7 @@ struct ceph_messenger {
 	struct ceph_entity_addr my_enc_addr;
 
 	bool nocrc;
+	atomic_t teardowning;
 
 	/*
 	 * the global_seq counts connections i (attempt to) initiate
net/ceph/ceph_common.c +3 -2
index a776f75..7225e42 100644
@@ -501,6 +501,9 @@ void ceph_destroy_client(struct ceph_client *client)
 {
 	dout("destroy_client %p\n", client);
 
+	atomic_set(&client->msgr->teardowning, 1);
+	ceph_msgr_flush();
+
 	/* unmount */
 	ceph_osdc_stop(&client->osdc);
 
@@ -509,8 +512,6 @@ void ceph_destroy_client(struct ceph_client *client)
 	 * auth module, which is needed to free those connections'
 	 * ceph_authorizers.
 	 */
-	ceph_msgr_flush();
-
 	ceph_monc_stop(&client->monc);
 
 	ceph_debugfs_client_cleanup(client);
net/ceph/messenger.c +5 -0
index 524f4e4..89a96e7 100644
@@ -156,6 +156,9 @@ EXPORT_SYMBOL(ceph_msgr_flush);
 static void ceph_data_ready(struct sock *sk, int count_unused)
 {
 	struct ceph_connection *con = sk->sk_user_data;
+	if (atomic_read(&con->msgr->teardowning)) {
+		return;
+	}
 
 	if (sk->sk_state != TCP_CLOSE_WAIT) {
 		dout("ceph_data_ready on %p state = %lu, queueing work\n",
@@ -2281,6 +2284,8 @@ struct ceph_messenger *ceph_messenger_create(struct ceph_entity_addr *myaddr,
 	get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce));
 	encode_my_addr(msgr);
 
+	atomic_set(&msgr->teardowning, 0);
+
 	dout("messenger_create %p\n", msgr);
 	return msgr;
 }
Signature · 1 line
1.7.3.4
#1 lore raw

Hi,

Do you think atomic_t variable is necessary here?
or a normal bool variable will ok? or others?

thanks a lot for your reply!

thanks,
Guanjun

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/21/2012 at 04:20 PM, in message

<[email protected]>, Guanjun He

Quoted 72 lines · <[email protected]> wrote:

Add an atomic variable 'teardowning' 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.

---
 include/linux/ceph/messenger.h |    1 +
 net/ceph/ceph_common.c         |    5 +++--
 net/ceph/messenger.c           |    5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)
include/linux/ceph/messenger.h +1 -0
index 2521a95..70ff3b7 100644
@@ -54,6 +54,7 @@ struct ceph_messenger {
 	struct ceph_entity_addr my_enc_addr;
 
 	bool nocrc;
+	atomic_t teardowning;
 
 	/*
 	 * the global_seq counts connections i (attempt to) initiate
net/ceph/ceph_common.c +3 -2
index a776f75..7225e42 100644
@@ -501,6 +501,9 @@ void ceph_destroy_client(struct ceph_client *client)
 {
 	dout("destroy_client %p\n", client);
 
+	atomic_set(&client->msgr->teardowning, 1);
+	ceph_msgr_flush();
+
 	/* unmount */
 	ceph_osdc_stop(&client->osdc);
 
@@ -509,8 +512,6 @@ void ceph_destroy_client(struct ceph_client *client)
 	 * auth module, which is needed to free those connections'
 	 * ceph_authorizers.
 	 */
-	ceph_msgr_flush();
-
 	ceph_monc_stop(&client->monc);
 
 	ceph_debugfs_client_cleanup(client);
net/ceph/messenger.c +5 -0
index 524f4e4..89a96e7 100644
@@ -156,6 +156,9 @@ EXPORT_SYMBOL(ceph_msgr_flush);
 static void ceph_data_ready(struct sock *sk, int count_unused)
 {
 	struct ceph_connection *con = sk->sk_user_data;
+	if (atomic_read(&con->msgr->teardowning)) {
+		return;
+	}
 
 	if (sk->sk_state != TCP_CLOSE_WAIT) {
 		dout("ceph_data_ready on %p state = %lu, queueing work\n",
@@ -2281,6 +2284,8 @@ struct ceph_messenger *ceph_messenger_create(struct 
 ceph_entity_addr *myaddr,
 	get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce));
 	encode_my_addr(msgr);
 
+	atomic_set(&msgr->teardowning, 0);
+
 	dout("messenger_create %p\n", msgr);
 	return msgr;

}

#2 lore raw
In reply to Guanjun He

I take it back; this is pretty straightforward :)

Quoted 16 lines · Guanjun He

Add an atomic variable 'teardowning' 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.

---
 include/linux/ceph/messenger.h |    1 +
 net/ceph/ceph_common.c         |    5 +++--
 net/ceph/messenger.c           |    5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)
include/linux/ceph/messenger.h +0 -0
index 2521a95..70ff3b7 100644

include/linux/ceph/messenger.h struct ceph_messenger { · line 57

Quoted 4 lines
include/linux/ceph/messenger.h +1 -0
@@ -54,6 +54,7 @@ struct ceph_messenger {
 	struct ceph_entity_addr my_enc_addr;
 
 	bool nocrc;
+	atomic_t teardowning;

Can we call this 'stopping'?

Quoted 8 lines
include/linux/ceph/messenger.h +0 -0
 	/*
 	 * the global_seq counts connections i (attempt to) initiate
net/ceph/ceph_common.c +0 -0
index a776f75..7225e42 100644

net/ceph/ceph_common.c void ceph_destroy_client(struct ceph_client *client) · line 506

Quoted 6 lines
net/ceph/ceph_common.c +3 -0
@@ -501,6 +501,9 @@ void ceph_destroy_client(struct ceph_client *client)
 {
 	dout("destroy_client %p\n", client);
 
+	atomic_set(&client->msgr->teardowning, 1);
+	ceph_msgr_flush();
+

There is another patch in the master or testing branch of ceph-client.git htat moves the ceph_msgr_flush() around; can you make sure this patch is rebased against that? In particular, it should add the atomic set and checks, but not move the flush calls around (which is unrelated).

Otherwise, this looks good to me! Please resend with those changes and we'll stick it in the tree.

Thanks!
sage

Quoted 39 lines
net/ceph/ceph_common.c +0 -2
 	/* unmount */
 	ceph_osdc_stop(&client->osdc);
 
@@ -509,8 +512,6 @@ void ceph_destroy_client(struct ceph_client *client)
 	 * auth module, which is needed to free those connections'
 	 * ceph_authorizers.
 	 */
-	ceph_msgr_flush();
-
 	ceph_monc_stop(&client->monc);
 
 	ceph_debugfs_client_cleanup(client);
net/ceph/messenger.c +5 -0
index 524f4e4..89a96e7 100644
@@ -156,6 +156,9 @@ EXPORT_SYMBOL(ceph_msgr_flush);
 static void ceph_data_ready(struct sock *sk, int count_unused)
 {
 	struct ceph_connection *con = sk->sk_user_data;
+	if (atomic_read(&con->msgr->teardowning)) {
+		return;
+	}
 
 	if (sk->sk_state != TCP_CLOSE_WAIT) {
 		dout("ceph_data_ready on %p state = %lu, queueing work\n",
@@ -2281,6 +2284,8 @@ struct ceph_messenger *ceph_messenger_create(struct ceph_entity_addr *myaddr,
 	get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce));
 	encode_my_addr(msgr);
 
+	atomic_set(&msgr->teardowning, 0);
+
 	dout("messenger_create %p\n", msgr);
 	return msgr;
 }
Signature · 1 line
1.7.3.4
#3 lore raw

Hi Sage,

Thanks a lot for your reply!

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/29/2012 at 12:24 PM, in message

<[email protected]>, Sage Weil

Quoted 24 lines · <[email protected]> wrote:

I take it back; this is pretty straightforward :)

Quoted 2 lines · Guanjun He

Add an atomic variable 'teardowning' as flag in struct ceph_messenger,
set this flag to 1 in function ceph_destroy_client(), and add the condition

code

Quoted 1 line

in function ceph_data_ready() to test the flag value, if true(1), just

return.

Quoted 15 lines
---
 include/linux/ceph/messenger.h |    1 +
 net/ceph/ceph_common.c         |    5 +++--
 net/ceph/messenger.c           |    5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)
include/linux/ceph/messenger.h +0 -0
index 2521a95..70ff3b7 100644
@@ -54,6 +54,7 @@ struct ceph_messenger {
 	struct ceph_entity_addr my_enc_addr;
 
Quoted 4 lines

include/linux/ceph/messenger.h struct ceph_messenger { · line 57

Quoted 2 lines
include/linux/ceph/messenger.h +1 -0
 	bool nocrc;
+	atomic_t teardowning;

Can we call this 'stopping'?

Of course we can.

Quoted 12 lines
Quoted 12 lines
include/linux/ceph/messenger.h +0 -0
 	/*
 	 * the global_seq counts connections i (attempt to) initiate
net/ceph/ceph_common.c +0 -0
index a776f75..7225e42 100644
@@ -501,6 +501,9 @@ void ceph_destroy_client(struct ceph_client *client)
 {
 	dout("destroy_client %p\n", client);
 
Quoted 8 lines

net/ceph/ceph_common.c void ceph_destroy_client(struct ceph_client *client) · line 506

Quoted 3 lines
net/ceph/ceph_common.c +3 -0
+	atomic_set(&client->msgr->teardowning, 1);
+	ceph_msgr_flush();
+

There is another patch in the master or testing branch of ceph-client.git htat moves the ceph_msgr_flush() around; can you make sure this patch is rebased against that? In particular, it should add the atomic set and checks, but not move the flush calls around (which is unrelated).

Just checked, this patch is not rebased against the latest branch.

Quoted 3 lines

Otherwise, this looks good to me! Please resend with those changes and we'll stick it in the tree.

I will re-produce the patch against the latest branch, and make a simply test and re-send the new patch hours later.

best,
Guanjun

Quoted 46 lines

Thanks!
sage

net/ceph/messenger.c struct ceph_messenger *ceph_messenger_create(struct

Quoted 27 lines
net/ceph/ceph_common.c +0 -2
 	/* unmount */
 	ceph_osdc_stop(&client->osdc);
 
@@ -509,8 +512,6 @@ void ceph_destroy_client(struct ceph_client *client)
 	 * auth module, which is needed to free those connections'
 	 * ceph_authorizers.
 	 */
-	ceph_msgr_flush();
-
 	ceph_monc_stop(&client->monc);
 
 	ceph_debugfs_client_cleanup(client);
net/ceph/messenger.c +3 -0
index 524f4e4..89a96e7 100644
@@ -156,6 +156,9 @@ EXPORT_SYMBOL(ceph_msgr_flush);
 static void ceph_data_ready(struct sock *sk, int count_unused)
 {
 	struct ceph_connection *con = sk->sk_user_data;
+	if (atomic_read(&con->msgr->teardowning)) {
+		return;
+	}
 
 	if (sk->sk_state != TCP_CLOSE_WAIT) {
 		dout("ceph_data_ready on %p state = %lu, queueing work\n",
@@ -2281,6 +2284,8 @@ struct ceph_messenger *ceph_messenger_create(struct 

ceph_entity_addr *myaddr,

Quoted 12 lines
net/ceph/messenger.c +2 -0
 	get_random_bytes(&msgr->inst.addr.nonce, sizeof(msgr->inst.addr.nonce));
 	encode_my_addr(msgr);
 
+	atomic_set(&msgr->teardowning, 0);
+
 	dout("messenger_create %p\n", msgr);
 	return msgr;
 }
Signature · 1 line
1.7.3.4