_mb_id--) \
if (virtio_mem_mb_get_state(_vm, _mb_id) == _state)
+/*
+ * Calculate the bit number in the subblock bitmap for the given subblock
+ * inside the given memory block.
+ */
+static int virtio_mem_sb_bitmap_bit_nr(struct virtio_mem *vm,
+ unsigned long mb_id, int sb_id)
+{
+ return (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+}
+
/*
* Mark all selected subblocks plugged.
*
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
__bitmap_set(vm->sb_bitmap, bit, count);
}
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
__bitmap_clear(vm->sb_bitmap, bit, count);
}
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
if (count == 1)
return test_bit(bit, vm->sb_bitmap);
unsigned long mb_id, int sb_id,
int count)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb + sb_id;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, sb_id);
/* TODO: Helper similar to bitmap_set() */
return find_next_bit(vm->sb_bitmap, bit + count, bit) >= bit + count;
static int virtio_mem_mb_first_unplugged_sb(struct virtio_mem *vm,
unsigned long mb_id)
{
- const int bit = (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb;
+ const int bit = virtio_mem_sb_bitmap_bit_nr(vm, mb_id, 0);
return find_next_zero_bit(vm->sb_bitmap, bit + vm->nb_sb_per_mb, bit) -
bit;