| 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 GPL. | 7 * This file is released under the GPL. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 #include <asm/atomic.h> | 10 #include <asm/atomic.h> |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 } | 306 } |
| 307 | 307 |
| 308 /* Setup callback stubs */ | 308 /* Setup callback stubs */ |
| 309 bht->read_cb = &dm_bht_read_callback_stub; | 309 bht->read_cb = &dm_bht_read_callback_stub; |
| 310 bht->write_cb = &dm_bht_write_callback_stub; | 310 bht->write_cb = &dm_bht_write_callback_stub; |
| 311 | 311 |
| 312 status = dm_bht_initialize_entries(bht); | 312 status = dm_bht_initialize_entries(bht); |
| 313 if (status) | 313 if (status) |
| 314 goto bad_entries_alloc; | 314 goto bad_entries_alloc; |
| 315 | 315 |
| 316 bht->entry_readahead = 0; | |
| 317 return 0; | 316 return 0; |
| 318 | 317 |
| 319 bad_entries_alloc: | 318 bad_entries_alloc: |
| 320 while (bht->depth-- > 0) | 319 while (bht->depth-- > 0) |
| 321 kfree(bht->levels[bht->depth].entries); | 320 kfree(bht->levels[bht->depth].entries); |
| 322 bad_node_count: | 321 bad_node_count: |
| 323 kfree(bht->levels); | 322 kfree(bht->levels); |
| 324 bad_level_alloc: | 323 bad_level_alloc: |
| 325 bad_block_count: | 324 bad_block_count: |
| 326 bad_depth: | 325 bad_depth: |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 read_status = dm_bht_maybe_read_entries(bht, read_cb_ctx, | 967 read_status = dm_bht_maybe_read_entries(bht, read_cb_ctx, |
| 969 depth, entry_index, | 968 depth, entry_index, |
| 970 1, false); | 969 1, false); |
| 971 if (unlikely(read_status < 0)) { | 970 if (unlikely(read_status < 0)) { |
| 972 DMCRIT("failure occurred reading entry %u depth %u", | 971 DMCRIT("failure occurred reading entry %u depth %u", |
| 973 entry_index, depth); | 972 entry_index, depth); |
| 974 return read_status; | 973 return read_status; |
| 975 } | 974 } |
| 976 /* Accrue return code flags */ | 975 /* Accrue return code flags */ |
| 977 populated |= read_status; | 976 populated |= read_status; |
| 978 | |
| 979 /* Attempt to pull in up to entry_readahead extra entries on | |
| 980 * this I/O call iff we're doing the read right now. This | |
| 981 * helps optimize sequential access to the mapped drive. | |
| 982 */ | |
| 983 if (bht->entry_readahead && | |
| 984 (read_status & DM_BHT_ENTRY_REQUESTED)) { | |
| 985 unsigned int readahead_count; | |
| 986 entry_index++; | |
| 987 readahead_count = min(bht->entry_readahead, | |
| 988 level->count - entry_index); | |
| 989 /* The result is completely ignored since this call is | |
| 990 * critical for the current request. | |
| 991 */ | |
| 992 if (readahead_count) | |
| 993 dm_bht_maybe_read_entries(bht, read_cb_ctx, | |
| 994 depth, entry_index, | |
| 995 readahead_count, | |
| 996 true); | |
| 997 } | |
| 998 } | 977 } |
| 999 | 978 |
| 1000 /* All nodes are ready. The hash for the block_index can be verified */ | 979 /* All nodes are ready. The hash for the block_index can be verified */ |
| 1001 return populated; | 980 return populated; |
| 1002 } | 981 } |
| 1003 EXPORT_SYMBOL(dm_bht_populate); | 982 EXPORT_SYMBOL(dm_bht_populate); |
| 1004 | 983 |
| 1005 | 984 |
| 1006 /** | 985 /** |
| 1007 * dm_bht_verify_block - checks that all nodes in the path for @block are valid | 986 * dm_bht_verify_block - checks that all nodes in the path for @block are valid |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 * @bht: pointer to a dm_bht_create()d bht | 1096 * @bht: pointer to a dm_bht_create()d bht |
| 1118 * @write_cb: callback function used for all write requests by @bht | 1097 * @write_cb: callback function used for all write requests by @bht |
| 1119 */ | 1098 */ |
| 1120 void dm_bht_set_write_cb(struct dm_bht *bht, dm_bht_callback write_cb) | 1099 void dm_bht_set_write_cb(struct dm_bht *bht, dm_bht_callback write_cb) |
| 1121 { | 1100 { |
| 1122 bht->write_cb = write_cb; | 1101 bht->write_cb = write_cb; |
| 1123 } | 1102 } |
| 1124 EXPORT_SYMBOL(dm_bht_set_write_cb); | 1103 EXPORT_SYMBOL(dm_bht_set_write_cb); |
| 1125 | 1104 |
| 1126 /** | 1105 /** |
| 1127 * dm_bht_set_entry_readahead - set verify mode | |
| 1128 * @bht: pointer to a dm_bht_create()d bht | |
| 1129 * @readahead_count: number of entries to readahead from a given level | |
| 1130 */ | |
| 1131 void dm_bht_set_entry_readahead(struct dm_bht *bht, | |
| 1132 unsigned int readahead_count) | |
| 1133 { | |
| 1134 bht->entry_readahead = readahead_count; | |
| 1135 } | |
| 1136 EXPORT_SYMBOL(dm_bht_set_entry_readahead); | |
| 1137 | |
| 1138 /** | |
| 1139 * dm_bht_set_root_hexdigest - sets an unverified root digest hash from hex | 1106 * dm_bht_set_root_hexdigest - sets an unverified root digest hash from hex |
| 1140 * @bht: pointer to a dm_bht_create()d bht | 1107 * @bht: pointer to a dm_bht_create()d bht |
| 1141 * @hexdigest: array of u8s containing the new digest in binary | 1108 * @hexdigest: array of u8s containing the new digest in binary |
| 1142 * Returns non-zero on error. hexdigest should be NUL terminated. | 1109 * Returns non-zero on error. hexdigest should be NUL terminated. |
| 1143 */ | 1110 */ |
| 1144 int dm_bht_set_root_hexdigest(struct dm_bht *bht, const u8 *hexdigest) | 1111 int dm_bht_set_root_hexdigest(struct dm_bht *bht, const u8 *hexdigest) |
| 1145 { | 1112 { |
| 1146 if (!bht->root_digest) { | 1113 if (!bht->root_digest) { |
| 1147 DMCRIT("No allocation for root digest. Call dm_bht_create"); | 1114 DMCRIT("No allocation for root digest. Call dm_bht_create"); |
| 1148 return -1; | 1115 return -1; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 if (!bht->root_digest) { | 1149 if (!bht->root_digest) { |
| 1183 DMERR("no root digest exists to export"); | 1150 DMERR("no root digest exists to export"); |
| 1184 if (available > 0) | 1151 if (available > 0) |
| 1185 *hexdigest = 0; | 1152 *hexdigest = 0; |
| 1186 return -1; | 1153 return -1; |
| 1187 } | 1154 } |
| 1188 dm_bht_bin_to_hex(bht->root_digest, hexdigest, bht->digest_size); | 1155 dm_bht_bin_to_hex(bht->root_digest, hexdigest, bht->digest_size); |
| 1189 return 0; | 1156 return 0; |
| 1190 } | 1157 } |
| 1191 EXPORT_SYMBOL(dm_bht_root_hexdigest); | 1158 EXPORT_SYMBOL(dm_bht_root_hexdigest); |
| 1192 | |
| OLD | NEW |