[sheepdog] [PATCH 1/4] sheep: let add_vdi_state() be a thread safe

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Mon Oct 20 09:07:11 CEST 2014


add_vdi_state() can be called by worker threads. So ec_max_data_strip
should be protected by a mutex.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 sheep/vdi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sheep/vdi.c b/sheep/vdi.c
index c8fdf4a..4252585 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -163,9 +163,13 @@ int add_vdi_state(uint32_t vid, int nr_copies, bool snapshot, uint8_t cp)
 
 	if (cp) {
 		int d;
+		static struct sd_mutex m = SD_MUTEX_INITIALIZER;
 
 		ec_policy_to_dp(cp, &d, NULL);
+
+		sd_mutex_lock(&m);
 		ec_max_data_strip = max(d, ec_max_data_strip);
+		sd_mutex_unlock(&m);
 	}
 
 	sd_debug("%" PRIx32 ", %d, %d", vid, nr_copies, cp);
-- 
1.8.3.2




More information about the sheepdog mailing list