hbitmap: Rename serialization_granularity to serialization_align
The only client of hbitmap_serialization_granularity() is dirty-bitmap's bdrv_dirty_bitmap_serialization_align(). Keeping the two names consistent is worthwhile, and the shorter name is more representative of what the function returns (the required alignment to be used for start/count of other serialization functions, where violating the alignment causes assertion failures). Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
		
							parent
							
								
									a8b42a1c09
								
							
						
					
					
						commit
						ecbfa2817d
					
				@ -617,7 +617,7 @@ uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitmap,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap)
 | 
					uint64_t bdrv_dirty_bitmap_serialization_align(const BdrvDirtyBitmap *bitmap)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return hbitmap_serialization_granularity(bitmap->bitmap);
 | 
					    return hbitmap_serialization_align(bitmap->bitmap);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
 | 
					void bdrv_dirty_bitmap_serialize_part(const BdrvDirtyBitmap *bitmap,
 | 
				
			||||||
 | 
				
			|||||||
@ -159,16 +159,16 @@ bool hbitmap_get(const HBitmap *hb, uint64_t item);
 | 
				
			|||||||
bool hbitmap_is_serializable(const HBitmap *hb);
 | 
					bool hbitmap_is_serializable(const HBitmap *hb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * hbitmap_serialization_granularity:
 | 
					 * hbitmap_serialization_align:
 | 
				
			||||||
 * @hb: HBitmap to operate on.
 | 
					 * @hb: HBitmap to operate on.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Granularity of serialization chunks, used by other serialization functions.
 | 
					 * Required alignment of serialization chunks, used by other serialization
 | 
				
			||||||
 * For every chunk:
 | 
					 * functions. For every chunk:
 | 
				
			||||||
 * 1. Chunk start should be aligned to this granularity.
 | 
					 * 1. Chunk start should be aligned to this granularity.
 | 
				
			||||||
 * 2. Chunk size should be aligned too, except for last chunk (for which
 | 
					 * 2. Chunk size should be aligned too, except for last chunk (for which
 | 
				
			||||||
 *      start + count == hb->size)
 | 
					 *      start + count == hb->size)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
uint64_t hbitmap_serialization_granularity(const HBitmap *hb);
 | 
					uint64_t hbitmap_serialization_align(const HBitmap *hb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * hbitmap_serialization_size:
 | 
					 * hbitmap_serialization_size:
 | 
				
			||||||
 | 
				
			|||||||
@ -738,7 +738,7 @@ static void test_hbitmap_meta_one(TestHBitmapData *data, const void *unused)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void test_hbitmap_serialize_granularity(TestHBitmapData *data,
 | 
					static void test_hbitmap_serialize_align(TestHBitmapData *data,
 | 
				
			||||||
                                         const void *unused)
 | 
					                                         const void *unused)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int r;
 | 
					    int r;
 | 
				
			||||||
@ -746,7 +746,7 @@ static void test_hbitmap_serialize_granularity(TestHBitmapData *data,
 | 
				
			|||||||
    hbitmap_test_init(data, L3 * 2, 3);
 | 
					    hbitmap_test_init(data, L3 * 2, 3);
 | 
				
			||||||
    g_assert(hbitmap_is_serializable(data->hb));
 | 
					    g_assert(hbitmap_is_serializable(data->hb));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    r = hbitmap_serialization_granularity(data->hb);
 | 
					    r = hbitmap_serialization_align(data->hb);
 | 
				
			||||||
    g_assert_cmpint(r, ==, 64 << 3);
 | 
					    g_assert_cmpint(r, ==, 64 << 3);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -974,8 +974,8 @@ int main(int argc, char **argv)
 | 
				
			|||||||
    hbitmap_test_add("/hbitmap/meta/word", test_hbitmap_meta_word);
 | 
					    hbitmap_test_add("/hbitmap/meta/word", test_hbitmap_meta_word);
 | 
				
			||||||
    hbitmap_test_add("/hbitmap/meta/sector", test_hbitmap_meta_sector);
 | 
					    hbitmap_test_add("/hbitmap/meta/sector", test_hbitmap_meta_sector);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hbitmap_test_add("/hbitmap/serialize/granularity",
 | 
					    hbitmap_test_add("/hbitmap/serialize/align",
 | 
				
			||||||
                     test_hbitmap_serialize_granularity);
 | 
					                     test_hbitmap_serialize_align);
 | 
				
			||||||
    hbitmap_test_add("/hbitmap/serialize/basic",
 | 
					    hbitmap_test_add("/hbitmap/serialize/basic",
 | 
				
			||||||
                     test_hbitmap_serialize_basic);
 | 
					                     test_hbitmap_serialize_basic);
 | 
				
			||||||
    hbitmap_test_add("/hbitmap/serialize/part",
 | 
					    hbitmap_test_add("/hbitmap/serialize/part",
 | 
				
			||||||
 | 
				
			|||||||
@ -413,14 +413,14 @@ bool hbitmap_is_serializable(const HBitmap *hb)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    /* Every serialized chunk must be aligned to 64 bits so that endianness
 | 
					    /* Every serialized chunk must be aligned to 64 bits so that endianness
 | 
				
			||||||
     * requirements can be fulfilled on both 64 bit and 32 bit hosts.
 | 
					     * requirements can be fulfilled on both 64 bit and 32 bit hosts.
 | 
				
			||||||
     * We have hbitmap_serialization_granularity() which converts this
 | 
					     * We have hbitmap_serialization_align() which converts this
 | 
				
			||||||
     * alignment requirement from bitmap bits to items covered (e.g. sectors).
 | 
					     * alignment requirement from bitmap bits to items covered (e.g. sectors).
 | 
				
			||||||
     * That value is:
 | 
					     * That value is:
 | 
				
			||||||
     *    64 << hb->granularity
 | 
					     *    64 << hb->granularity
 | 
				
			||||||
     * Since this value must not exceed UINT64_MAX, hb->granularity must be
 | 
					     * Since this value must not exceed UINT64_MAX, hb->granularity must be
 | 
				
			||||||
     * less than 58 (== 64 - 6, where 6 is ld(64), i.e. 1 << 6 == 64).
 | 
					     * less than 58 (== 64 - 6, where 6 is ld(64), i.e. 1 << 6 == 64).
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * In order for hbitmap_serialization_granularity() to always return a
 | 
					     * In order for hbitmap_serialization_align() to always return a
 | 
				
			||||||
     * meaningful value, bitmaps that are to be serialized must have a
 | 
					     * meaningful value, bitmaps that are to be serialized must have a
 | 
				
			||||||
     * granularity of less than 58. */
 | 
					     * granularity of less than 58. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -437,7 +437,7 @@ bool hbitmap_get(const HBitmap *hb, uint64_t item)
 | 
				
			|||||||
    return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0;
 | 
					    return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint64_t hbitmap_serialization_granularity(const HBitmap *hb)
 | 
					uint64_t hbitmap_serialization_align(const HBitmap *hb)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    assert(hbitmap_is_serializable(hb));
 | 
					    assert(hbitmap_is_serializable(hb));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -454,7 +454,7 @@ static void serialization_chunk(const HBitmap *hb,
 | 
				
			|||||||
                                unsigned long **first_el, uint64_t *el_count)
 | 
					                                unsigned long **first_el, uint64_t *el_count)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint64_t last = start + count - 1;
 | 
					    uint64_t last = start + count - 1;
 | 
				
			||||||
    uint64_t gran = hbitmap_serialization_granularity(hb);
 | 
					    uint64_t gran = hbitmap_serialization_align(hb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert((start & (gran - 1)) == 0);
 | 
					    assert((start & (gran - 1)) == 0);
 | 
				
			||||||
    assert((last >> hb->granularity) < hb->size);
 | 
					    assert((last >> hb->granularity) < hb->size);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user