[sheepdog] [PATCH v3] sheep: set bit in vdi_inuse in atomic manner

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Wed Aug 28 10:52:29 CEST 2013


sys->vdi_inuse must be operated in atomic manner because it is
manipulated by multiple threads. This patch implements a new bit
operator atomic_set_bit() and let get_vdis_from() use this.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---

v2:
 - removed needless variable
 - replace more set_bit() for vdi_inuse

v3:
 - fixed a silly compilation error

 include/bitops.h    |    5 +++++
 sheep/group.c       |    2 +-
 sheep/ops.c         |    4 ++--
 sheep/plain_store.c |    2 +-
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/bitops.h b/include/bitops.h
index c4e8f74..775643c 100644
--- a/include/bitops.h
+++ b/include/bitops.h
@@ -135,6 +135,11 @@ static inline void set_bit(int nr, unsigned long *addr)
 	addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
 }
 
+static inline void atomic_set_bit(int nr, unsigned long *addr)
+{
+	uatomic_or(addr + nr / BITS_PER_LONG, 1UL << (nr % BITS_PER_LONG));
+}
+
 static inline int test_bit(unsigned int nr, const unsigned long *addr)
 {
 	return ((1UL << (nr % BITS_PER_LONG)) &
diff --git a/sheep/group.c b/sheep/group.c
index cd56cb6..44e4058 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -445,7 +445,7 @@ static int get_vdis_from(struct sd_node *node)
 
 	count = rsp->data_length / sizeof(*vs);
 	for (i = 0; i < count; i++) {
-		set_bit(vs[i].vid, sys->vdi_inuse);
+		atomic_set_bit(vs[i].vid, sys->vdi_inuse);
 		add_vdi_state(vs[i].vid, vs[i].nr_copies, vs[i].snapshot);
 	}
 out:
diff --git a/sheep/ops.c b/sheep/ops.c
index b180425..f2d0a4d 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -96,7 +96,7 @@ static int post_cluster_new_vdi(const struct sd_req *req, struct sd_rsp *rsp,
 
 	sd_debug("done %d %lx", ret, nr);
 	if (ret == SD_RES_SUCCESS)
-		set_bit(nr, sys->vdi_inuse);
+		atomic_set_bit(nr, sys->vdi_inuse);
 
 	return ret;
 }
@@ -579,7 +579,7 @@ static int cluster_notify_vdi_add(const struct sd_req *req, struct sd_rsp *rsp,
 			      true);
 
 	if (req->vdi_state.set_bitmap)
-		set_bit(req->vdi_state.new_vid, sys->vdi_inuse);
+		atomic_set_bit(req->vdi_state.new_vid, sys->vdi_inuse);
 
 	add_vdi_state(req->vdi_state.new_vid, req->vdi_state.copies, false);
 
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index e35a7e7..8265b29 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -191,7 +191,7 @@ static int init_vdi_state(uint64_t oid, char *wd, uint32_t epoch)
 
 	add_vdi_state(oid_to_vid(oid), inode->nr_copies,
 		      vdi_is_snapshot(inode));
-	set_bit(oid_to_vid(oid), sys->vdi_inuse);
+	atomic_set_bit(oid_to_vid(oid), sys->vdi_inuse);
 
 	ret = SD_RES_SUCCESS;
 out:
-- 
1.7.10.4




More information about the sheepdog mailing list