[sheepdog] [PATCH stable-0.7 2/2] sheep: set bit in vdi_inuse in atomic manner
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Thu Aug 29 04:47:41 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>
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
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 c2ff3e7..309469e 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 ca5c5e4..78fd713 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 d0937f8..5baa7fd 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