[sheepdog] [PATCH] local: update queue in correct order

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Sep 8 05:05:10 CEST 2012


This updates the current queue position after writing queue data.
Otherwise, if a sheep process exists during pushing data into the
queue, other sheeps can read invalid data.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/cluster/local.c |   32 ++++++++++++++++----------------
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index 5d2f423..8a53abc 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -123,24 +123,24 @@ static struct local_event *shm_queue_peek(void)
 
 static void shm_queue_push(struct local_event *ev)
 {
+	int pos;
+
 	if (ev->type == EVENT_BLOCK) {
-		shm_queue->block_event_pos =
-			(shm_queue->block_event_pos + 1) % MAX_EVENTS;
-		shm_queue->block_events[shm_queue->block_event_pos] = *ev;
-
-		msync(shm_queue->block_events +
-		      shm_queue->block_event_pos, sizeof(*ev), MS_SYNC);
-		msync(&shm_queue->block_event_pos,
-		      sizeof(shm_queue->block_event_pos), MS_SYNC);
+		pos = (shm_queue->block_event_pos + 1) % MAX_EVENTS;
+
+		shm_queue->block_events[pos] = *ev;
+		msync(shm_queue->block_events + pos, sizeof(*ev), MS_SYNC);
+
+		shm_queue->block_event_pos = pos;
+		msync(&shm_queue->block_event_pos, sizeof(pos), MS_SYNC);
 	} else {
-		shm_queue->nonblock_event_pos =
-			(shm_queue->nonblock_event_pos + 1) % MAX_EVENTS;
-		shm_queue->nonblock_events[shm_queue->nonblock_event_pos] = *ev;
-
-		msync(shm_queue->nonblock_events +
-		      shm_queue->nonblock_event_pos, sizeof(*ev), MS_SYNC);
-		msync(&shm_queue->nonblock_event_pos,
-		      sizeof(shm_queue->nonblock_event_pos), MS_SYNC);
+		pos = (shm_queue->nonblock_event_pos + 1) % MAX_EVENTS;
+
+		shm_queue->nonblock_events[pos] = *ev;
+		msync(shm_queue->nonblock_events + pos, sizeof(*ev), MS_SYNC);
+
+		shm_queue->nonblock_event_pos = pos;
+		msync(&shm_queue->nonblock_event_pos, sizeof(pos), MS_SYNC);
 	}
 }
 
-- 
1.7.2.5




More information about the sheepdog mailing list