OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 The Chromium OS Authors <chromium-os-dev@chromium.org> | 2 * Copyright (C) 2010 The Chromium OS Authors <chromium-os-dev@chromium.org> |
3 * | 3 * |
4 * Device-Mapper block hash tree interface. | 4 * Device-Mapper block hash tree interface. |
5 * See Documentation/device-mapper/dm-bht.txt for details. | 5 * See Documentation/device-mapper/dm-bht.txt for details. |
6 * | 6 * |
7 * This file is released under the GPLv2. | 7 * This file is released under the GPLv2. |
8 */ | 8 */ |
9 #ifndef __LINUX_DM_BHT_H | 9 #ifndef __LINUX_DM_BHT_H |
10 #define __LINUX_DM_BHT_H | 10 #define __LINUX_DM_BHT_H |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 * | 82 * |
83 * TODO(wad): All hash storage memory is pre-allocated and freed once an | 83 * TODO(wad): All hash storage memory is pre-allocated and freed once an |
84 * entire branch has been verified. | 84 * entire branch has been verified. |
85 */ | 85 */ |
86 struct dm_bht { | 86 struct dm_bht { |
87 /* Configured values */ | 87 /* Configured values */ |
88 /* ENFORCE: depth must be >= 2. */ | 88 /* ENFORCE: depth must be >= 2. */ |
89 unsigned int depth; /* Depth of the tree including the root */ | 89 unsigned int depth; /* Depth of the tree including the root */ |
90 unsigned int block_count; /* Number of blocks hashed */ | 90 unsigned int block_count; /* Number of blocks hashed */ |
91 char hash_alg[CRYPTO_MAX_ALG_NAME]; | 91 char hash_alg[CRYPTO_MAX_ALG_NAME]; |
92 unsigned int entry_readahead; /* number of entries to attempt to | |
93 * pre-read in a level. | |
94 */ | |
95 | 92 |
96 /* Computed values */ | 93 /* Computed values */ |
97 unsigned int node_count; /* Data size (in hashes) for each entry */ | 94 unsigned int node_count; /* Data size (in hashes) for each entry */ |
98 unsigned int node_count_shift; /* first bit set - 1 */ | 95 unsigned int node_count_shift; /* first bit set - 1 */ |
99 /* There is one per CPU so that verified can be simultaneous. */ | 96 /* There is one per CPU so that verified can be simultaneous. */ |
100 struct hash_desc *hash_desc; /* Container for the hash alg */ | 97 struct hash_desc *hash_desc; /* Container for the hash alg */ |
101 unsigned int digest_size; | 98 unsigned int digest_size; |
102 sector_t sectors; /* Number of disk sectors used */ | 99 sector_t sectors; /* Number of disk sectors used */ |
103 | 100 |
104 /* bool verified; Full tree is verified */ | 101 /* bool verified; Full tree is verified */ |
105 u8 *root_digest; /* hash_alg(levels[0].entries[*].nodes) */ | 102 u8 *root_digest; /* hash_alg(levels[0].entries[*].nodes) */ |
106 atomic_t root_state; /* Uses UNALLOCATED, REQUESTED, and VERIFIED */ | 103 atomic_t root_state; /* Uses UNALLOCATED, REQUESTED, and VERIFIED */ |
107 struct dm_bht_level *levels; /* in reverse order */ | 104 struct dm_bht_level *levels; /* in reverse order */ |
108 mempool_t *entry_pool; | 105 mempool_t *entry_pool; |
109 /* Callbacks for reading and/or writing to the hash device */ | 106 /* Callbacks for reading and/or writing to the hash device */ |
110 dm_bht_callback read_cb; | 107 dm_bht_callback read_cb; |
111 dm_bht_callback write_cb; | 108 dm_bht_callback write_cb; |
112 }; | 109 }; |
113 | 110 |
114 /* Constructor for struct dm_bht instances. */ | 111 /* Constructor for struct dm_bht instances. */ |
115 int dm_bht_create(struct dm_bht *bht, | 112 int dm_bht_create(struct dm_bht *bht, |
116 unsigned int depth, | 113 unsigned int depth, |
117 unsigned int block_count, | 114 unsigned int block_count, |
118 const char *alg_name); | 115 const char *alg_name); |
119 /* Destructor for struct dm_bht instances. Does not free @bht */ | 116 /* Destructor for struct dm_bht instances. Does not free @bht */ |
120 int dm_bht_destroy(struct dm_bht *bht); | 117 int dm_bht_destroy(struct dm_bht *bht); |
121 | 118 |
122 /* Basic accessors for struct dm_bht */ | 119 /* Basic accessors for struct dm_bht */ |
123 sector_t dm_bht_sectors(const struct dm_bht *bht); | 120 sector_t dm_bht_sectors(const struct dm_bht *bht); |
124 void dm_bht_set_entry_readahead(struct dm_bht *bht, | |
125 unsigned int readahead_count); | |
126 void dm_bht_set_read_cb(struct dm_bht *bht, dm_bht_callback read_cb); | 121 void dm_bht_set_read_cb(struct dm_bht *bht, dm_bht_callback read_cb); |
127 void dm_bht_set_write_cb(struct dm_bht *bht, dm_bht_callback write_cb); | 122 void dm_bht_set_write_cb(struct dm_bht *bht, dm_bht_callback write_cb); |
128 int dm_bht_set_root_hexdigest(struct dm_bht *bht, const u8 *hexdigest); | 123 int dm_bht_set_root_hexdigest(struct dm_bht *bht, const u8 *hexdigest); |
129 int dm_bht_root_hexdigest(struct dm_bht *bht, u8 *hexdigest, int available); | 124 int dm_bht_root_hexdigest(struct dm_bht *bht, u8 *hexdigest, int available); |
130 | 125 |
131 /* Functions for loading in data from disk for verification */ | 126 /* Functions for loading in data from disk for verification */ |
132 int dm_bht_populate(struct dm_bht *bht, void *read_cb_ctx, | 127 int dm_bht_populate(struct dm_bht *bht, void *read_cb_ctx, |
133 unsigned int block_index); | 128 unsigned int block_index); |
134 int dm_bht_verify_block(struct dm_bht *bht, unsigned int block_index, | 129 int dm_bht_verify_block(struct dm_bht *bht, unsigned int block_index, |
135 const void *block); | 130 const void *block); |
136 | 131 |
137 /* Functions for creating struct dm_bhts on disk. A newly created dm_bht | 132 /* Functions for creating struct dm_bhts on disk. A newly created dm_bht |
138 * should not be directly used for verification. (It should be repopulated.) | 133 * should not be directly used for verification. (It should be repopulated.) |
139 * In addition, these functions aren't meant to be called in parallel. | 134 * In addition, these functions aren't meant to be called in parallel. |
140 */ | 135 */ |
141 int dm_bht_compute(struct dm_bht *bht, void *read_cb_ctx); | 136 int dm_bht_compute(struct dm_bht *bht, void *read_cb_ctx); |
142 int dm_bht_sync(struct dm_bht *bht, void *write_cb_ctx); | 137 int dm_bht_sync(struct dm_bht *bht, void *write_cb_ctx); |
143 int dm_bht_store_block(struct dm_bht *bht, unsigned int block_index, | 138 int dm_bht_store_block(struct dm_bht *bht, unsigned int block_index, |
144 u8 *block_data); | 139 u8 *block_data); |
145 int dm_bht_zeroread_callback(void *ctx, sector_t start, u8 *dst, sector_t count, | 140 int dm_bht_zeroread_callback(void *ctx, sector_t start, u8 *dst, sector_t count, |
146 struct dm_bht_entry *entry); | 141 struct dm_bht_entry *entry); |
147 void dm_bht_read_completed(struct dm_bht_entry *entry, int status); | 142 void dm_bht_read_completed(struct dm_bht_entry *entry, int status); |
148 void dm_bht_write_completed(struct dm_bht_entry *entry, int status); | 143 void dm_bht_write_completed(struct dm_bht_entry *entry, int status); |
149 #endif /* __LINUX_DM_BHT_H */ | 144 #endif /* __LINUX_DM_BHT_H */ |
OLD | NEW |