verity: use block instead of block_index everywhere

This makes our use block consistent. block is also easier to type than
block_index.

BUG=chromium-os:9752
TEST=Ran dm-verity.git unit tests. Ran platform_DMVerityCorruption on H/W.

Signed-off-by: Mandeep Singh Baines <msb@chromium.org>
kernel.git Reviewed-on: http://gerrit.chromium.org/gerrit/4453

Code has already been reviewed and committed to kernel.git.

Change-Id: Ia24f93cf9d7b318dbbe71732116088f012fafee6
Signed-off-by: Mandeep Singh Baines <msb@chromium.org>
Reviewed-on: http://gerrit.chromium.org/gerrit/6775
diff --git a/dm-bht.c b/dm-bht.c
index 9df856e..a602929 100644
--- a/dm-bht.c
+++ b/dm-bht.c
@@ -149,9 +149,9 @@
 
 static inline struct dm_bht_entry *dm_bht_get_entry(struct dm_bht *bht,
 						    unsigned int depth,
-						    unsigned int block_index)
+						    unsigned int block)
 {
-	unsigned int index = dm_bht_index_at_level(bht, depth, block_index);
+	unsigned int index = dm_bht_index_at_level(bht, depth, block);
 	struct dm_bht_level *level = dm_bht_get_level(bht, depth);
 
 	BUG_ON(index >= level->count);
@@ -162,9 +162,9 @@
 static inline u8 *dm_bht_get_node(struct dm_bht *bht,
 				  struct dm_bht_entry *entry,
 				  unsigned int depth,
-				  unsigned int block_index)
+				  unsigned int block)
 {
-	unsigned int index = dm_bht_index_at_level(bht, depth, block_index);
+	unsigned int index = dm_bht_index_at_level(bht, depth, block);
 
 	return dm_bht_node(bht, entry, index % bht->node_count);
 }
@@ -462,7 +462,7 @@
 /* dm_bht_verify_path
  * Verifies the path. Returns 0 on ok.
  */
-static int dm_bht_verify_path(struct dm_bht *bht, unsigned int block_index,
+static int dm_bht_verify_path(struct dm_bht *bht, unsigned int block,
 			      struct page *pg, unsigned int offset)
 {
 	unsigned int depth = bht->depth;
@@ -475,13 +475,13 @@
 		/* Need to check that the hash of the current block is accurate
 		 * in its parent.
 		 */
-		entry = dm_bht_get_entry(bht, depth - 1, block_index);
+		entry = dm_bht_get_entry(bht, depth - 1, block);
 		state = atomic_read(&entry->state);
 		/* This call is only safe if all nodes along the path
 		 * are already populated (i.e. READY) via dm_bht_populate.
 		 */
 		BUG_ON(state < DM_BHT_ENTRY_READY);
-		node = dm_bht_get_node(bht, entry, depth, block_index);
+		node = dm_bht_get_node(bht, entry, depth, block);
 
 		if (dm_bht_compute_hash(bht, pg, offset, digest) ||
 		    memcmp(digest, node, bht->digest_size))
@@ -503,19 +503,19 @@
 
 	/* Mark path to leaf as verified. */
 	for (depth++; depth < bht->depth; depth++) {
-		entry = dm_bht_get_entry(bht, depth, block_index);
+		entry = dm_bht_get_entry(bht, depth, block);
 		/* At this point, entry can only be in VERIFIED or READY state.
 		 * So it is safe to use atomic_set instead of atomic_cmpxchg.
 		 */
 		atomic_set(&entry->state, DM_BHT_ENTRY_VERIFIED);
 	}
 
-	DMDEBUG("verify_path: node %u is verified to root", block_index);
+	DMDEBUG("verify_path: node %u is verified to root", block);
 	return 0;
 
 mismatch:
 	DMERR_LIMIT("verify_path: failed to verify hash (d=%u,bi=%u)",
-		    depth, block_index);
+		    depth, block);
 	dm_bht_log_mismatch(bht, node, digest);
 	return DM_BHT_ENTRY_ERROR_MISMATCH;
 }
@@ -523,7 +523,7 @@
 /**
  * dm_bht_store_block - sets a given block's hash in the tree
  * @bht:	pointer to a dm_bht_create()d bht
- * @block_index:numeric index of the block in the tree
+ * @block:	numeric index of the block in the tree
  * @digest:	array of u8s containing the digest of length @bht->digest_size
  *
  * Returns 0 on success, >0 when data is pending, and <0 when a IO or other
@@ -537,7 +537,7 @@
  *
  * It is expected that virt_to_page will work on |block_data|.
  */
-int dm_bht_store_block(struct dm_bht *bht, unsigned int block_index,
+int dm_bht_store_block(struct dm_bht *bht, unsigned int block,
 		       u8 *block_data)
 {
 	int depth;
@@ -553,16 +553,16 @@
 
 	/* Index into the level */
 	level = dm_bht_get_level(bht, depth);
-	index = dm_bht_index_at_level(bht, depth, block_index);
+	index = dm_bht_index_at_level(bht, depth, block);
 	/* Grab the node index into the current entry by getting the
 	 * index at the leaf-level.
 	 */
-	node_index = dm_bht_index_at_level(bht, depth + 1, block_index) %
+	node_index = dm_bht_index_at_level(bht, depth + 1, block) %
 		     bht->node_count;
 	entry = &level->entries[index];
 
 	DMDEBUG("Storing block %u in d=%d,ei=%u,ni=%u,s=%d",
-		block_index, depth, index, node_index,
+		block, depth, index, node_index,
 		atomic_read(&entry->state));
 
 	state = atomic_cmpxchg(&entry->state,
@@ -587,10 +587,10 @@
 		atomic_set(&entry->state, DM_BHT_ENTRY_READY);
 	} else if (state <= DM_BHT_ENTRY_ERROR) {
 		DMCRIT("leaf entry for block %u is invalid",
-		      block_index);
+		      block);
 		return state;
 	} else if (state == DM_BHT_ENTRY_PENDING) {
-		DMERR("leaf data is pending for block %u", block_index);
+		DMERR("leaf data is pending for block %u", block);
 		return 1;
 	}
 
@@ -745,19 +745,19 @@
  * dm_bht_is_populated - check that entries from disk needed to verify a given
  *                       block are all ready
  * @bht:	pointer to a dm_bht_create()d bht
- * @block_index:specific block data is expected from
+ * @block:	specific block data is expected from
  *
  * Callers may wish to call dm_bht_is_populated() when checking an io
  * for which entries were already pending.
  */
-bool dm_bht_is_populated(struct dm_bht *bht, unsigned int block_index)
+bool dm_bht_is_populated(struct dm_bht *bht, unsigned int block)
 {
 	unsigned int depth;
 
 	/* TODO(msb) convert depth to int and avoid ugly cast */
 	for (depth = bht->depth - 1; (int)depth >= 0; depth--) {
 		struct dm_bht_entry *entry = dm_bht_get_entry(bht, depth,
-							      block_index);
+							      block);
 		if (atomic_read(&entry->state) < DM_BHT_ENTRY_READY)
 			return false;
 	}
@@ -770,19 +770,19 @@
  * dm_bht_populate - reads entries from disk needed to verify a given block
  * @bht:	pointer to a dm_bht_create()d bht
  * @ctx:        context used for all read_cb calls on this request
- * @block_index:specific block data is expected from
+ * @block:	specific block data is expected from
  *
  * Returns negative value on error. Returns 0 on success.
  */
 int dm_bht_populate(struct dm_bht *bht, void *ctx,
-		    unsigned int block_index)
+		    unsigned int block)
 {
 	unsigned int depth;
 	int state = 0;
 
-	BUG_ON(block_index >= bht->block_count);
+	BUG_ON(block >= bht->block_count);
 
-	DMDEBUG("dm_bht_populate(%u)", block_index);
+	DMDEBUG("dm_bht_populate(%u)", block);
 
 	for (depth = bht->depth - 1; (int)depth >= 0; --depth) {
 		struct dm_bht_level *level;
@@ -790,7 +790,7 @@
 		unsigned int index;
 		struct page *pg;
 
-		entry = dm_bht_get_entry(bht, depth, block_index);
+		entry = dm_bht_get_entry(bht, depth, block);
 		state = atomic_cmpxchg(&entry->state,
 				       DM_BHT_ENTRY_UNALLOCATED,
 				       DM_BHT_ENTRY_PENDING);
@@ -813,7 +813,7 @@
 		/* TODO(wad) error check callback here too */
 
 		level = &bht->levels[depth];
-		index = dm_bht_index_at_level(bht, depth, block_index);
+		index = dm_bht_index_at_level(bht, depth, block);
 		bht->read_cb(ctx, level->sector + to_sector(index * PAGE_SIZE),
 			     entry->nodes, to_sector(PAGE_SIZE), entry);
 	}
@@ -821,7 +821,7 @@
 	return 0;
 
 error_state:
-	DMCRIT("block %u at depth %u is in an error state", block_index, depth);
+	DMCRIT("block %u at depth %u is in an error state", block, depth);
 	return state;
 
 nomem:
@@ -834,20 +834,20 @@
 /**
  * dm_bht_verify_block - checks that all nodes in the path for @block are valid
  * @bht:	pointer to a dm_bht_create()d bht
- * @block_index:specific block data is expected from
- * @block:	virtual address of the block data in memory
- *              (must be aligned to block size)
+ * @block:	specific block data is expected from
+ * @pg:		page holding the block data
+ * @offset:	offset into the page
  *
  * Returns 0 on success, 1 on missing data, and a negative error
  * code on verification failure. All supporting functions called
  * should return similarly.
  */
-int dm_bht_verify_block(struct dm_bht *bht, unsigned int block_index,
+int dm_bht_verify_block(struct dm_bht *bht, unsigned int block,
 			struct page *pg, unsigned int offset)
 {
 	BUG_ON(offset != 0);
 
-	return  dm_bht_verify_path(bht, block_index, pg, offset);
+	return  dm_bht_verify_path(bht, block, pg, offset);
 }
 EXPORT_SYMBOL(dm_bht_verify_block);
 
diff --git a/dm-bht.h b/dm-bht.h
index 44a1c02..bbdca0e 100644
--- a/dm-bht.h
+++ b/dm-bht.h
@@ -119,10 +119,10 @@
 int dm_bht_root_hexdigest(struct dm_bht *bht, u8 *hexdigest, int available);
 
 /* Functions for loading in data from disk for verification */
-bool dm_bht_is_populated(struct dm_bht *bht, unsigned int block_index);
+bool dm_bht_is_populated(struct dm_bht *bht, unsigned int block);
 int dm_bht_populate(struct dm_bht *bht, void *read_cb_ctx,
-		    unsigned int block_index);
-int dm_bht_verify_block(struct dm_bht *bht, unsigned int block_index,
+		    unsigned int block);
+int dm_bht_verify_block(struct dm_bht *bht, unsigned int block,
 			struct page *pg, unsigned int offset);
 
 /* Functions for creating struct dm_bhts on disk.  A newly created dm_bht
@@ -131,7 +131,7 @@
  */
 int dm_bht_compute(struct dm_bht *bht, void *read_cb_ctx);
 int dm_bht_sync(struct dm_bht *bht, void *write_cb_ctx);
-int dm_bht_store_block(struct dm_bht *bht, unsigned int block_index,
+int dm_bht_store_block(struct dm_bht *bht, unsigned int block,
 		       u8 *block_data);
 int dm_bht_zeroread_callback(void *ctx, sector_t start, u8 *dst, sector_t count,
 			     struct dm_bht_entry *entry);