hbitmap header

The documentation of QEMU’s qemu/hbitmap.h header.

HBitmap * hbitmap_alloc(uint64_t size, int granularity)

Parameters

uint64_t size
Number of bits in the bitmap.
int granularity
Granularity of the bitmap. Aligned groups of 2^**granularity** bits will be represented by a single bit. Each operation on a range of bits first rounds the bits to determine which group they land in, and then affect the entire set; iteration will only visit the first bit of each group.

Description

Allocate a new HBitmap.

void hbitmap_truncate(HBitmap * hb, uint64_t size)

Parameters

HBitmap * hb
The bitmap to change the size of.
uint64_t size
The number of elements to change the bitmap to accommodate.

Description

truncate or grow an existing bitmap to accommodate a new number of elements. This may invalidate existing HBitmapIterators.

bool hbitmap_merge(const HBitmap * a, const HBitmap * b, HBitmap * result)

Parameters

const HBitmap * a
undescribed
const HBitmap * b
undescribed
HBitmap * result
undescribed

Description

Store result of merging a and b into result. result is allowed to be equal to a or b.

Return true if the merge was successful,
false if it was not attempted.
bool hbitmap_can_merge(const HBitmap * a, const HBitmap * b)

Parameters

const HBitmap * a
undescribed
const HBitmap * b
undescribed

Description

hbitmap_can_merge(a, b) && hbitmap_can_merge(a, result) is sufficient and necessary for hbitmap_merge will not fail.

bool hbitmap_empty(const HBitmap * hb)

Parameters

const HBitmap * hb
HBitmap to operate on.

Description

Return whether the bitmap is empty.

int hbitmap_granularity(const HBitmap * hb)

Parameters

const HBitmap * hb
HBitmap to operate on.

Description

Return the granularity of the HBitmap.

uint64_t hbitmap_count(const HBitmap * hb)

Parameters

const HBitmap * hb
HBitmap to operate on.

Description

Return the number of bits set in the HBitmap.

void hbitmap_set(HBitmap * hb, uint64_t start, uint64_t count)

Parameters

HBitmap * hb
HBitmap to operate on.
uint64_t start
First bit to set (0-based).
uint64_t count
Number of bits to set.

Description

Set a consecutive range of bits in an HBitmap.

void hbitmap_reset(HBitmap * hb, uint64_t start, uint64_t count)

Parameters

HBitmap * hb
HBitmap to operate on.
uint64_t start
First bit to reset (0-based).
uint64_t count
Number of bits to reset.

Description

Reset a consecutive range of bits in an HBitmap.

void hbitmap_reset_all(HBitmap * hb)

Parameters

HBitmap * hb
HBitmap to operate on.

Description

Reset all bits in an HBitmap.

bool hbitmap_get(const HBitmap * hb, uint64_t item)

Parameters

const HBitmap * hb
HBitmap to operate on.
uint64_t item
Bit to query (0-based).

Description

Return whether the item-th bit in an HBitmap is set.

bool hbitmap_is_serializable(const HBitmap * hb)

Parameters

const HBitmap * hb
HBitmap which should be (de-)serialized.

Description

Returns whether the bitmap can actually be (de-)serialized. Other (de-)serialization functions may only be invoked if this function returns true.

Calling (de-)serialization functions does not affect a bitmap’s (de-)serializability.

uint64_t hbitmap_serialization_align(const HBitmap * hb)

Parameters

const HBitmap * hb
HBitmap to operate on.

Description

Required alignment of serialization chunks, used by other serialization functions. For every chunk: 1. Chunk start should be aligned to this granularity. 2. Chunk size should be aligned too, except for last chunk (for which

start + count == hb->size)
uint64_t hbitmap_serialization_size(const HBitmap * hb, uint64_t start, uint64_t count)

Parameters

const HBitmap * hb
HBitmap to operate on.
uint64_t start
Starting bit
uint64_t count
Number of bits

Description

Return number of bytes hbitmap_(de)serialize_part needs

void hbitmap_serialize_part(const HBitmap * hb, uint8_t * buf, uint64_t start, uint64_t count)

Parameters

const HBitmap * hb
HBitmap to operate on.
uint8_t * buf
Buffer to store serialized bitmap.
uint64_t start
First bit to store.
uint64_t count
Number of bits to store.

Description

Stores HBitmap data corresponding to given region. The format of saved data is linear sequence of bits, so it can be used by hbitmap_deserialize_part independently of endianness and size of HBitmap level array elements

void hbitmap_deserialize_part(HBitmap * hb, uint8_t * buf, uint64_t start, uint64_t count, bool finish)

Parameters

HBitmap * hb
HBitmap to operate on.
uint8_t * buf
Buffer to restore bitmap data from.
uint64_t start
First bit to restore.
uint64_t count
Number of bits to restore.
bool finish
Whether to call hbitmap_deserialize_finish automatically.

Description

Restores HBitmap data corresponding to given region. The format is the same as for hbitmap_serialize_part.

If finish is false, caller must call hbitmap_serialize_finish before using the bitmap.

void hbitmap_deserialize_zeroes(HBitmap * hb, uint64_t start, uint64_t count, bool finish)

Parameters

HBitmap * hb
HBitmap to operate on.
uint64_t start
First bit to restore.
uint64_t count
Number of bits to restore.
bool finish
Whether to call hbitmap_deserialize_finish automatically.

Description

Fills the bitmap with zeroes.

If finish is false, caller must call hbitmap_serialize_finish before using the bitmap.

void hbitmap_deserialize_ones(HBitmap * hb, uint64_t start, uint64_t count, bool finish)

Parameters

HBitmap * hb
HBitmap to operate on.
uint64_t start
First bit to restore.
uint64_t count
Number of bits to restore.
bool finish
Whether to call hbitmap_deserialize_finish automatically.

Description

Fills the bitmap with ones.

If finish is false, caller must call hbitmap_serialize_finish before using the bitmap.

void hbitmap_deserialize_finish(HBitmap * hb)

Parameters

HBitmap * hb
HBitmap to operate on.

Description

Repair HBitmap after calling hbitmap_deserialize_data. Actually, all HBitmap layers are restored here.

char * hbitmap_sha256(const HBitmap * bitmap, Error ** errp)

Parameters

const HBitmap * bitmap
HBitmap to operate on.
Error ** errp
undescribed

Description

Returns SHA256 hash of the last level.

void hbitmap_free(HBitmap * hb)

Parameters

HBitmap * hb
HBitmap to operate on.

Description

Free an HBitmap and all of its associated memory.

void hbitmap_iter_init(HBitmapIter * hbi, const HBitmap * hb, uint64_t first)

Parameters

HBitmapIter * hbi
HBitmapIter to initialize.
const HBitmap * hb
HBitmap to iterate on.
uint64_t first
First bit to visit (0-based, must be strictly less than the size of the bitmap).

Description

Set up hbi to iterate on the HBitmap hb. hbitmap_iter_next will return the lowest-numbered bit that is set in hb, starting at first.

Concurrent setting of bits is acceptable, and will at worst cause the iteration to miss some of those bits.

The concurrent resetting of bits is OK.

int64_t hbitmap_iter_next(HBitmapIter * hbi)

Parameters

HBitmapIter * hbi
HBitmapIter to operate on.

Description

Return the next bit that is set in hbi‘s associated HBitmap, or -1 if all remaining bits are zero.

size_t hbitmap_iter_next_word(HBitmapIter * hbi, unsigned long * p_cur)

Parameters

HBitmapIter * hbi
HBitmapIter to operate on.
unsigned long * p_cur
Location where to store the next non-zero word.

Description

Return the index of the next nonzero word that is set in hbi‘s associated HBitmap, and set *p_cur to the content of that word (bits before the index that was passed to hbitmap_iter_init are trimmed on the first call). Return -1, and set *p_cur to zero, if all remaining words are zero.