* [Ocfs2-devel] [PATCH] ocfs2: fix a tiny race case when fire callbacks
@ 2013-08-27 6:17 Joseph Qi
2013-08-27 20:54 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Joseph Qi @ 2013-08-27 6:17 UTC (permalink / raw)
To: ocfs2-devel
In o2hb_shutdown_slot() and o2hb_check_slot(), since event is defined
as local, it is only valid during the call stack. So the following tiny
race case may happen in a multi-volumes mounted environment:
o2hb-vol1 o2hb-vol2
1) o2hb_shutdown_slot
allocate local event1
2) queue_node_event
add event1 to global o2hb_node_events
3) o2hb_shutdown_slot
allocate local event2
4) queue_node_event
add event2 to global o2hb_node_events
5) o2hb_run_event_list
delete event1 from o2hb_node_events
6) o2hb_run_event_list
event1 empty, return
7) o2hb_shutdown_slot
event1 lifecycle ends
8) o2hb_fire_callbacks
event1 is already *invalid*
This patch lets it wait o2hb_callback_sem when another thread is firing
callbacks. And for performance consideration, we only call
o2hb_run_event_list when there is an event queued.
Signed-off-by: Joyce <xuejiufei@huawei.com>
Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
---
fs/ocfs2/cluster/heartbeat.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 42252bf..af5cd3b 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -641,16 +641,9 @@ static void o2hb_fire_callbacks(struct o2hb_callback *hbcall,
/* Will run the list in order until we process the passed event */
static void o2hb_run_event_list(struct o2hb_node_event *queued_event)
{
- int empty;
struct o2hb_callback *hbcall;
struct o2hb_node_event *event;
- spin_lock(&o2hb_live_lock);
- empty = list_empty(&queued_event->hn_item);
- spin_unlock(&o2hb_live_lock);
- if (empty)
- return;
-
/* Holding callback sem assures we don't alter the callback
* lists when doing this, and serializes ourselves with other
* processes wanting callbacks. */
@@ -709,6 +702,7 @@ static void o2hb_shutdown_slot(struct o2hb_disk_slot *slot)
struct o2hb_node_event event =
{ .hn_item = LIST_HEAD_INIT(event.hn_item), };
struct o2nm_node *node;
+ int queued = 0;
node = o2nm_get_node_by_num(slot->ds_node_num);
if (!node)
@@ -726,11 +720,13 @@ static void o2hb_shutdown_slot(struct o2hb_disk_slot *slot)
o2hb_queue_node_event(&event, O2HB_NODE_DOWN_CB, node,
slot->ds_node_num);
+ queued = 1;
}
}
spin_unlock(&o2hb_live_lock);
- o2hb_run_event_list(&event);
+ if (queued)
+ o2hb_run_event_list(&event);
o2nm_node_put(node);
}
@@ -790,6 +786,7 @@ static int o2hb_check_slot(struct o2hb_region *reg,
unsigned int dead_ms = o2hb_dead_threshold * O2HB_REGION_TIMEOUT_MS;
unsigned int slot_dead_ms;
int tmp;
+ int queued = 0;
memcpy(hb_block, slot->ds_raw_block, reg->hr_block_bytes);
@@ -883,6 +880,7 @@ fire_callbacks:
slot->ds_node_num);
changed = 1;
+ queued = 1;
}
list_add_tail(&slot->ds_live_item,
@@ -934,6 +932,7 @@ fire_callbacks:
node, slot->ds_node_num);
changed = 1;
+ queued = 1;
}
/* We don't clear this because the node is still
@@ -949,7 +948,8 @@ fire_callbacks:
out:
spin_unlock(&o2hb_live_lock);
- o2hb_run_event_list(&event);
+ if (queued)
+ o2hb_run_event_list(&event);
if (node)
o2nm_node_put(node);
-- 1.7.9.7
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Ocfs2-devel] [PATCH] ocfs2: fix a tiny race case when fire callbacks
2013-08-27 6:17 [Ocfs2-devel] [PATCH] ocfs2: fix a tiny race case when fire callbacks Joseph Qi
@ 2013-08-27 20:54 ` Andrew Morton
2013-08-28 1:59 ` Joseph Qi
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2013-08-27 20:54 UTC (permalink / raw)
To: ocfs2-devel
On Tue, 27 Aug 2013 14:17:17 +0800 Joseph Qi <joseph.qi@huawei.com> wrote:
> Signed-off-by: Joyce <xuejiufei@huawei.com>
> Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
This signoff trail makes me wonder: which of you was the primary
author of this patch?
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Ocfs2-devel] [PATCH] ocfs2: fix a tiny race case when fire callbacks
2013-08-27 20:54 ` Andrew Morton
@ 2013-08-28 1:59 ` Joseph Qi
2013-08-28 3:13 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Joseph Qi @ 2013-08-28 1:59 UTC (permalink / raw)
To: ocfs2-devel
On 2013/8/28 4:54, Andrew Morton wrote:
> On Tue, 27 Aug 2013 14:17:17 +0800 Joseph Qi <joseph.qi@huawei.com> wrote:
>
>> Signed-off-by: Joyce <xuejiufei@huawei.com>
>> Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
>
> This signoff trail makes me wonder: which of you was the primary
> author of this patch?
>
>
Sorry for the misleading signoff trail. Joyce fixed this bug and I
rearranged the patch and sent it.
Please refer Joyce as the primary author, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Ocfs2-devel] [PATCH] ocfs2: fix a tiny race case when fire callbacks
2013-08-28 1:59 ` Joseph Qi
@ 2013-08-28 3:13 ` Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2013-08-28 3:13 UTC (permalink / raw)
To: ocfs2-devel
On Wed, 28 Aug 2013 09:59:21 +0800 Joseph Qi <joseph.qi@huawei.com> wrote:
> On 2013/8/28 4:54, Andrew Morton wrote:
> > On Tue, 27 Aug 2013 14:17:17 +0800 Joseph Qi <joseph.qi@huawei.com> wrote:
> >
> >> Signed-off-by: Joyce <xuejiufei@huawei.com>
> >> Signed-off-by: Joseph Qi <joseph.qi@huawei.com>
> >
> > This signoff trail makes me wonder: which of you was the primary
> > author of this patch?
> >
> >
> Sorry for the misleading signoff trail. Joyce fixed this bug and I
> rearranged the patch and sent it.
> Please refer Joyce as the primary author, thanks.
No problems. Damn, am I good, or what ;)
The way to handle this situation is to put an explicit From:Joyce line
at the very start of the changelog. If that is present, the person who
receives the patch should prioritize that From: line over the one which
is present in the email envelope.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-08-28 3:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-27 6:17 [Ocfs2-devel] [PATCH] ocfs2: fix a tiny race case when fire callbacks Joseph Qi
2013-08-27 20:54 ` Andrew Morton
2013-08-28 1:59 ` Joseph Qi
2013-08-28 3:13 ` Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.