| 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 /* Each dm_bht_entry->nodes is one page. The node code tracks | 281 /* Each dm_bht_entry->nodes is one page. The node code tracks |
| 282 * how many nodes fit into one entry where a node is a single | 282 * how many nodes fit into one entry where a node is a single |
| 283 * hash (message digest). | 283 * hash (message digest). |
| 284 */ | 284 */ |
| 285 bht->node_count_shift = fls(PAGE_SIZE / bht->digest_size) - 1; | 285 bht->node_count_shift = fls(PAGE_SIZE / bht->digest_size) - 1; |
| 286 /* Round down to the nearest power of two. This makes indexing | 286 /* Round down to the nearest power of two. This makes indexing |
| 287 * into the tree much less painful. | 287 * into the tree much less painful. |
| 288 */ | 288 */ |
| 289 bht->node_count = 1 << bht->node_count_shift; | 289 bht->node_count = 1 << bht->node_count_shift; |
| 290 | 290 |
| 291 /* TODO(wad) if node_count < DM_BHT_MAX_NODE_COUNT, then retry with | |
| 292 * node_count_shift-1. | |
| 293 */ | |
| 294 if (bht->node_count > DM_BHT_MAX_NODE_COUNT) { | |
| 295 DMERR("node_count maximum node bitmap size"); | |
| 296 status = -EINVAL; | |
| 297 goto bad_node_count; | |
| 298 } | |
| 299 | |
| 300 /* This is unlikely to happen, but with 64k pages, who knows. */ | 291 /* This is unlikely to happen, but with 64k pages, who knows. */ |
| 301 if (bht->node_count > UINT_MAX / bht->digest_size) { | 292 if (bht->node_count > UINT_MAX / bht->digest_size) { |
| 302 DMERR("node_count * hash_len exceeds UINT_MAX!"); | 293 DMERR("node_count * hash_len exceeds UINT_MAX!"); |
| 303 status = -EINVAL; | 294 status = -EINVAL; |
| 304 goto bad_node_count; | 295 goto bad_node_count; |
| 305 } | 296 } |
| 306 /* Ensure that we can safely shift by this value. */ | 297 /* Ensure that we can safely shift by this value. */ |
| 307 if (depth * bht->node_count_shift >= sizeof(unsigned int) * 8) { | 298 if (depth * bht->node_count_shift >= sizeof(unsigned int) * 8) { |
| 308 DMERR("specified depth and node_count_shift is too large"); | 299 DMERR("specified depth and node_count_shift is too large"); |
| 309 status = -EINVAL; | 300 status = -EINVAL; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 return 1; | 618 return 1; |
| 628 } | 619 } |
| 629 | 620 |
| 630 /* Index into the entry data */ | 621 /* Index into the entry data */ |
| 631 index = (block_index % bht->node_count) * bht->digest_size; | 622 index = (block_index % bht->node_count) * bht->digest_size; |
| 632 if (memcmp(&entry->nodes[index], digest, bht->digest_size)) { | 623 if (memcmp(&entry->nodes[index], digest, bht->digest_size)) { |
| 633 DMCRIT("digest mismatch for block %u", block_index); | 624 DMCRIT("digest mismatch for block %u", block_index); |
| 634 dm_bht_log_mismatch(bht, &entry->nodes[index], digest); | 625 dm_bht_log_mismatch(bht, &entry->nodes[index], digest); |
| 635 return DM_BHT_ENTRY_ERROR_MISMATCH; | 626 return DM_BHT_ENTRY_ERROR_MISMATCH; |
| 636 } | 627 } |
| 637 /* TODO(wad) update bht->block_bitmap here or in the caller */ | |
| 638 return 0; | 628 return 0; |
| 639 } | 629 } |
| 640 | 630 |
| 641 /* Walk all entries at level 0 to compute the root digest. | 631 /* Walk all entries at level 0 to compute the root digest. |
| 642 * 0 on success. | 632 * 0 on success. |
| 643 */ | 633 */ |
| 644 static int dm_bht_compute_root(struct dm_bht *bht, u8 *digest) | 634 static int dm_bht_compute_root(struct dm_bht *bht, u8 *digest) |
| 645 { | 635 { |
| 646 struct dm_bht_entry *entry; | 636 struct dm_bht_entry *entry; |
| 647 unsigned int count; | 637 unsigned int count; |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 DMERR("no root digest exists to export"); | 1278 DMERR("no root digest exists to export"); |
| 1289 if (available > 0) | 1279 if (available > 0) |
| 1290 *hexdigest = 0; | 1280 *hexdigest = 0; |
| 1291 return -1; | 1281 return -1; |
| 1292 } | 1282 } |
| 1293 dm_bht_bin_to_hex(bht->root_digest, hexdigest, bht->digest_size); | 1283 dm_bht_bin_to_hex(bht->root_digest, hexdigest, bht->digest_size); |
| 1294 return 0; | 1284 return 0; |
| 1295 } | 1285 } |
| 1296 EXPORT_SYMBOL(dm_bht_root_hexdigest); | 1286 EXPORT_SYMBOL(dm_bht_root_hexdigest); |
| 1297 | 1287 |
| OLD | NEW |