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 <[email protected]> --- include/bitops.h | 6 ++++++ sheep/group.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/bitops.h b/include/bitops.h index c4e8f74..8eb5d53 100644 --- a/include/bitops.h +++ b/include/bitops.h @@ -135,6 +135,12 @@ 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) +{ + unsigned long val = 1UL << (nr % BITS_PER_LONG); + uatomic_or(addr + nr / BITS_PER_LONG, val); +} + 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: -- 1.7.10.4 -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
