Skip to contentSkip to conversation

net/ceph/osd_client.c add sem to osdmap destroy

PATCH In review Guanjun He 3 participants 6 messages Jun 15, 2012 – Jun 21, 2012 Ceph common code (libceph)

lore
Share & tools
lore

Guanjun He

author
#0 lore raw

PATCH 1/1 net/ceph/osd_client.c add sem to osdmap destroy

From: Guanjun He <[email protected]>

I think the osdmap destroy code shoule be protected by map_sem.
If I was wrong, please correct me, thanks!

---
 net/ceph/osd_client.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
net/ceph/osd_client.c +2 -0
index 1ffebed..718b100 100644
@@ -1872,11 +1872,13 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
 	destroy_workqueue(osdc->notify_wq);
 	cancel_delayed_work_sync(&osdc->timeout_work);
 	cancel_delayed_work_sync(&osdc->osds_timeout_work);
+	down_write(&osdc->map_sem);
 	if (osdc->osdmap) {
 		ceph_osdmap_destroy(osdc->osdmap);
 		osdc->osdmap = NULL;
 	}
 	remove_all_osds(osdc);
+	up_write(&osdc->map_sem);
 	mempool_destroy(osdc->req_mempool);
 	ceph_msgpool_destroy(&osdc->msgpool_op);
 	ceph_msgpool_destroy(&osdc->msgpool_op_reply);
Signature · 1 line
1.7.3.4
#1 lore raw

Hi,

Do you think this is needed?
The osdmap update need to hold this sem.As in function
void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) and
function static int __map_request(),
etc.

Thanks a lot for your reply!

thanks,
Guanjun

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/15/2012 at 04:32 PM, in message

<[email protected]>, Guanjun He

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

From: Guanjun He <[email protected]>

I think the osdmap destroy code shoule be protected by map_sem.
If I was wrong, please correct me, thanks!

---
 net/ceph/osd_client.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
net/ceph/osd_client.c +2 -0
index 1ffebed..718b100 100644
@@ -1872,11 +1872,13 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
 	destroy_workqueue(osdc->notify_wq);
 	cancel_delayed_work_sync(&osdc->timeout_work);
 	cancel_delayed_work_sync(&osdc->osds_timeout_work);
+	down_write(&osdc->map_sem);
 	if (osdc->osdmap) {
 		ceph_osdmap_destroy(osdc->osdmap);
 		osdc->osdmap = NULL;
 	}
 	remove_all_osds(osdc);
+	up_write(&osdc->map_sem);
 	mempool_destroy(osdc->req_mempool);
 	ceph_msgpool_destroy(&osdc->msgpool_op);
 	ceph_msgpool_destroy(&osdc->msgpool_op_reply);
#2 lore raw

[Sorry for not responding earlier!]

Quoted 8 lines · Guan Jun He

Hi,

Do you think this is needed?
The osdmap update need to hold this sem.As in function
void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg) and
function static int __map_request(),
etc.

I'm skeptical that this is necessary. At the point that we're tearing down the osd_client there shouldn't be anybody else referencing us, or the osdmap.

Actually, looking at the code a bit, I think the only kind of race we need to worry about is an incoming message. The correct fix is probably a call to the messenger to drop all incoming traffic before we start to shut everything else down. Even with this, we might still end up with a new osdmap that we leak, but stopping the msgr earlier would fix both issues.

sage

Quoted 40 lines

Thanks a lot for your reply!

thanks,
Guanjun

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/15/2012 at 04:32 PM, in message

<[email protected]>, Guanjun He

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

From: Guanjun He <[email protected]>

I think the osdmap destroy code shoule be protected by map_sem.
If I was wrong, please correct me, thanks!

---
 net/ceph/osd_client.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
net/ceph/osd_client.c +2 -0
index 1ffebed..718b100 100644
@@ -1872,11 +1872,13 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
 	destroy_workqueue(osdc->notify_wq);
 	cancel_delayed_work_sync(&osdc->timeout_work);
 	cancel_delayed_work_sync(&osdc->osds_timeout_work);
+	down_write(&osdc->map_sem);
 	if (osdc->osdmap) {
 		ceph_osdmap_destroy(osdc->osdmap);
 		osdc->osdmap = NULL;
 	}
 	remove_all_osds(osdc);
+	up_write(&osdc->map_sem);
 	mempool_destroy(osdc->req_mempool);
 	ceph_msgpool_destroy(&osdc->msgpool_op);
 	ceph_msgpool_destroy(&osdc->msgpool_op_reply);
#3 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 6/19/2012 at 11:33 PM, in message

<[email protected]>, Sage Weil

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

[Sorry for not responding earlier!]

Quoted 5 lines · Guan Jun He

Hi,

Do you think this is needed?
The osdmap update need to hold this sem.As in function
void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg

*msg)

Quoted 3 lines

and
function static int __map_request(),
etc.

I'm skeptical that this is necessary. At the point that we're tearing down the osd_client there shouldn't be anybody else referencing us, or the osdmap.

Quoted 5 lines

Actually, looking at the code a bit, I think the only kind of race we need to worry about is an incoming message. The correct fix is probably a call to the messenger to drop all incoming traffic before we start to shut everything else down. Even with this, we might still end up with a new osdmap that we leak, but stopping the msgr earlier would fix both issues.

Yes, stopping the msgr earlier is a better fix. I will do some test and produce a new patch to this.

thanks,
Guanjun

Quoted 43 lines

sage

Quoted 40 lines

Thanks a lot for your reply!

thanks,
Guanjun

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/15/2012 at 04:32 PM, in message

<[email protected]>, Guanjun He

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

From: Guanjun He <[email protected]>

I think the osdmap destroy code shoule be protected by map_sem.
If I was wrong, please correct me, thanks!

---
 net/ceph/osd_client.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
net/ceph/osd_client.c +2 -0
index 1ffebed..718b100 100644
@@ -1872,11 +1872,13 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
 	destroy_workqueue(osdc->notify_wq);
 	cancel_delayed_work_sync(&osdc->timeout_work);
 	cancel_delayed_work_sync(&osdc->osds_timeout_work);
+	down_write(&osdc->map_sem);
 	if (osdc->osdmap) {
 		ceph_osdmap_destroy(osdc->osdmap);
 		osdc->osdmap = NULL;
 	}
 	remove_all_osds(osdc);
+	up_write(&osdc->map_sem);
 	mempool_destroy(osdc->req_mempool);
 	ceph_msgpool_destroy(&osdc->msgpool_op);
 	ceph_msgpool_destroy(&osdc->msgpool_op_reply);
#4 lore raw
Quoted 22 lines · Guan Jun He
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 6/19/2012 at 11:33 PM, in message

<[email protected]>, Sage Weil

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

[Sorry for not responding earlier!]

Quoted 5 lines · Guan Jun He

Hi,

Do you think this is needed?
The osdmap update need to hold this sem.As in function
void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg

*msg)

Quoted 3 lines

and
function static int __map_request(),
etc.

I'm skeptical that this is necessary. At the point that we're tearing down the osd_client there shouldn't be anybody else referencing us, or the osdmap.

Quoted 8 lines
Quoted 5 lines

Actually, looking at the code a bit, I think the only kind of race we need to worry about is an incoming message. The correct fix is probably a call to the messenger to drop all incoming traffic before we start to shut everything else down. Even with this, we might still end up with a new osdmap that we leak, but stopping the msgr earlier would fix both issues.

Yes, stopping the msgr earlier is a better fix. I will do some test and produce a new patch to this.

Ok. The trick here is that I think we want to set a flag to discard incoming messages and then flush the workqueue, do all this other tear down for osd_client etc., and then tear down the messenger. I don't think we can tear down the msgr fully before that, though, because osd_client etc have their fingers in it. We just need to prevent the race of incoming work during teardown...

Thanks for looking at this!
sage

Quoted 57 lines

thanks,
Guanjun

Quoted 43 lines

sage

Quoted 40 lines

Thanks a lot for your reply!

thanks,
Guanjun

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/15/2012 at 04:32 PM, in message

<[email protected]>, Guanjun He

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

From: Guanjun He <[email protected]>

I think the osdmap destroy code shoule be protected by map_sem.
If I was wrong, please correct me, thanks!

---
 net/ceph/osd_client.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
net/ceph/osd_client.c +2 -0
index 1ffebed..718b100 100644
@@ -1872,11 +1872,13 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
 	destroy_workqueue(osdc->notify_wq);
 	cancel_delayed_work_sync(&osdc->timeout_work);
 	cancel_delayed_work_sync(&osdc->osds_timeout_work);
+	down_write(&osdc->map_sem);
 	if (osdc->osdmap) {
 		ceph_osdmap_destroy(osdc->osdmap);
 		osdc->osdmap = NULL;
 	}
 	remove_all_osds(osdc);
+	up_write(&osdc->map_sem);
 	mempool_destroy(osdc->req_mempool);
 	ceph_msgpool_destroy(&osdc->msgpool_op);
 	ceph_msgpool_destroy(&osdc->msgpool_op_reply);

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 6/21/2012 at 12:04 AM, in message

<[email protected]>, Sage Weil

Quoted 32 lines · <[email protected]> wrote:
Quoted 22 lines · Guan Jun He
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 6/19/2012 at 11:33 PM, in message

<[email protected]>, Sage Weil

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

[Sorry for not responding earlier!]

Quoted 5 lines · Guan Jun He

Hi,

Do you think this is needed?
The osdmap update need to hold this sem.As in function
void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg

*msg)

Quoted 3 lines

and
function static int __map_request(),
etc.

I'm skeptical that this is necessary. At the point that we're tearing down the osd_client there shouldn't be anybody else referencing us, or the osdmap.

Quoted 8 lines
Quoted 5 lines

Actually, looking at the code a bit, I think the only kind of race we need to worry about is an incoming message. The correct fix is probably a call to the messenger to drop all incoming traffic before we start to shut everything else down. Even with this, we might still end up with a new osdmap that we leak, but stopping the msgr earlier would fix both issues.

Yes, stopping the msgr earlier is a better fix. I will do some test and produce a new patch to this.

Quoted 6 lines

Ok. The trick here is that I think we want to set a flag to discard incoming messages and then flush the workqueue, do all this other tear down for osd_client etc., and then tear down the messenger. I don't think we can tear down the msgr fully before that, though, because osd_client etc have their fingers in it. We just need to prevent the race of incoming work during teardown...

Have produced a new patch and sent in another mail, and the title is 'client: prevent the race of incoming work during teardown'

thanks,
Guanjun

Quoted 65 lines

Thanks for looking at this!
sage

Quoted 51 lines

thanks,
Guanjun

Quoted 43 lines

sage

Quoted 40 lines

Thanks a lot for your reply!

thanks,
Guanjun

Quoted 1 line
Quoted 1 line
Quoted 1 line

On 6/15/2012 at 04:32 PM, in message

<[email protected]>, Guanjun He

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

From: Guanjun He <[email protected]>

I think the osdmap destroy code shoule be protected by map_sem.
If I was wrong, please correct me, thanks!

---
 net/ceph/osd_client.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
net/ceph/osd_client.c +2 -0
index 1ffebed..718b100 100644
@@ -1872,11 +1872,13 @@ void ceph_osdc_stop(struct ceph_osd_client *osdc)
 	destroy_workqueue(osdc->notify_wq);
 	cancel_delayed_work_sync(&osdc->timeout_work);
 	cancel_delayed_work_sync(&osdc->osds_timeout_work);
+	down_write(&osdc->map_sem);
 	if (osdc->osdmap) {
 		ceph_osdmap_destroy(osdc->osdmap);
 		osdc->osdmap = NULL;
 	}
 	remove_all_osds(osdc);
+	up_write(&osdc->map_sem);
 	mempool_destroy(osdc->req_mempool);
 	ceph_msgpool_destroy(&osdc->msgpool_op);
 	ceph_msgpool_destroy(&osdc->msgpool_op_reply);
Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html