From: Joe Thornber <[email-masked]>

dm thin metadata: introduce dm_thin_changed_this_transaction

Publish a useful bit of information we're already tracking.  This will
help dm thin decide when to commit.

Signed-off-by: Joe Thornber <[email-masked]>
Signed-off-by: Mike Snitzer <[email-masked]>
---
 drivers/md/dm-thin-metadata.c |   16 +++++++++++++---
 drivers/md/dm-thin-metadata.h |    2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)

Index: linux/drivers/md/dm-thin-metadata.c
===================================================================
--- linux.orig/drivers/md/dm-thin-metadata.c
+++ linux/drivers/md/dm-thin-metadata.c
@@ -1378,10 +1378,9 @@ static int __insert(struct dm_thin_devic
 	if (r)
 		return r;
 
-	if (inserted) {
+	td->changed = 1;
+	if (inserted)
 		td->mapped_blocks++;
-		td->changed = 1;
-	}
 
 	return 0;
 }
@@ -1425,6 +1424,17 @@ int dm_thin_remove_block(struct dm_thin_
 	return r;
 }
 
+bool dm_thin_changed_this_transaction(struct dm_thin_device *td)
+{
+	int r;
+
+	down_read(&td->pmd->root_lock);
+	r = td->changed;
+	up_read(&td->pmd->root_lock);
+
+	return r;
+}
+
 int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result)
 {
 	int r;
Index: linux/drivers/md/dm-thin-metadata.h
===================================================================
--- linux.orig/drivers/md/dm-thin-metadata.h
+++ linux/drivers/md/dm-thin-metadata.h
@@ -153,6 +153,8 @@ int dm_thin_remove_block(struct dm_thin_
 /*
  * Queries.
  */
+bool dm_thin_changed_this_transaction(struct dm_thin_device *td);
+
 int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
 				     dm_block_t *highest_mapped);