| 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 bool dm_bht_is_populated(struct dm_bht *bht, unsigned int block_index); | 127 bool dm_bht_is_populated(struct dm_bht *bht, unsigned int block_index); |
| 133 int dm_bht_populate(struct dm_bht *bht, void *read_cb_ctx, | 128 int dm_bht_populate(struct dm_bht *bht, void *read_cb_ctx, |
| 134 unsigned int block_index); | 129 unsigned int block_index); |
| 135 int dm_bht_verify_block(struct dm_bht *bht, unsigned int block_index, | 130 int dm_bht_verify_block(struct dm_bht *bht, unsigned int block_index, |
| 136 const void *buf); | 131 const void *buf); |
| 137 | 132 |
| 138 /* Functions for creating struct dm_bhts on disk. A newly created dm_bht | 133 /* Functions for creating struct dm_bhts on disk. A newly created dm_bht |
| 139 * should not be directly used for verification. (It should be repopulated.) | 134 * should not be directly used for verification. (It should be repopulated.) |
| 140 * In addition, these functions aren't meant to be called in parallel. | 135 * In addition, these functions aren't meant to be called in parallel. |
| 141 */ | 136 */ |
| 142 int dm_bht_compute(struct dm_bht *bht, void *read_cb_ctx); | 137 int dm_bht_compute(struct dm_bht *bht, void *read_cb_ctx); |
| 143 int dm_bht_sync(struct dm_bht *bht, void *write_cb_ctx); | 138 int dm_bht_sync(struct dm_bht *bht, void *write_cb_ctx); |
| 144 int dm_bht_store_block(struct dm_bht *bht, unsigned int block_index, | 139 int dm_bht_store_block(struct dm_bht *bht, unsigned int block_index, |
| 145 u8 *block_data); | 140 u8 *block_data); |
| 146 int dm_bht_zeroread_callback(void *ctx, sector_t start, u8 *dst, sector_t count, | 141 int dm_bht_zeroread_callback(void *ctx, sector_t start, u8 *dst, sector_t count, |
| 147 struct dm_bht_entry *entry); | 142 struct dm_bht_entry *entry); |
| 148 void dm_bht_read_completed(struct dm_bht_entry *entry, int status); | 143 void dm_bht_read_completed(struct dm_bht_entry *entry, int status); |
| 149 void dm_bht_write_completed(struct dm_bht_entry *entry, int status); | 144 void dm_bht_write_completed(struct dm_bht_entry *entry, int status); |
| 150 #endif /* __LINUX_DM_BHT_H */ | 145 #endif /* __LINUX_DM_BHT_H */ |
| OLD | NEW |