Merge branch 'akpm'
[linux-2.6/next.git] / drivers / md / persistent-data / dm-space-map-common.h
blob8c4aef87ab9d5d179f18f99e2e6071c83685a0bb
1 /*
2 * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
4 * This file is released under the GPL.
5 */
7 #ifndef DM_SPACE_MAP_COMMON_H
8 #define DM_SPACE_MAP_COMMON_H
10 #include "dm-btree.h"
13 *--------------------------------------------------------------------
14 * Low level disk format
16 * Bitmap btree
17 * ------------
19 * Each value stored in the btree is an index_entry. This points to a
20 * block that is used as a bitmap. Within the bitmap hold 2 bits per
21 * entry, which represent UNUSED = 0, REF_COUNT = 1, REF_COUNT = 2 and
22 * REF_COUNT = many.
24 * Refcount btree
25 * --------------
27 * Any entry that has a ref count higher than 2 gets entered in the ref
28 * count tree. The leaf values for this tree is the 32-bit ref count.
29 *---------------------------------------------------------------------
32 struct disk_index_entry {
33 __le64 blocknr;
34 __le32 nr_free;
35 __le32 none_free_before;
36 } __packed;
39 #define MAX_METADATA_BITMAPS 255
40 struct disk_metadata_index {
41 __le32 csum;
42 __le32 padding;
43 __le64 blocknr;
45 struct disk_index_entry index[MAX_METADATA_BITMAPS];
46 } __packed;
48 struct ll_disk {
49 struct dm_transaction_manager *tm;
50 struct dm_btree_info bitmap_info;
51 struct dm_btree_info ref_count_info;
53 uint32_t block_size;
54 uint32_t entries_per_block;
55 dm_block_t nr_blocks;
56 dm_block_t nr_allocated;
59 * bitmap_root may be a btree root or a simple index.
61 dm_block_t bitmap_root;
63 dm_block_t ref_count_root;
65 struct disk_metadata_index mi_le;
68 struct disk_sm_root {
69 __le64 nr_blocks;
70 __le64 nr_allocated;
71 __le64 bitmap_root;
72 __le64 ref_count_root;
73 } __packed;
75 #define ENTRIES_PER_BYTE 4
77 struct disk_bitmap_header {
78 __le32 csum;
79 __le32 not_used;
80 __le64 blocknr;
81 } __packed;
84 * These bitops work on a block's worth of bits.
86 unsigned sm_lookup_bitmap(void *addr, unsigned b);
87 void sm_set_bitmap(void *addr, unsigned b, unsigned val);
88 int sm_find_free(void *addr, unsigned begin, unsigned end, unsigned *result);
90 void *dm_bitmap_data(struct dm_block *b);
92 extern struct dm_block_validator dm_sm_bitmap_validator;
94 #endif /* DM_SPACE_MAP_COMMON_H */