aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/dm-thin.c
diff options
context:
space:
mode:
authorJoe Thornber <ejt@redhat.com>2013-12-04 15:05:36 -0500
committerMike Snitzer <snitzer@redhat.com>2013-12-10 16:35:12 -0500
commit020cc3b5e28c2e24f59f53a9154faf08564f308e (patch)
treed4bbed0ba0c780785187c9954658c723ed1973ac /drivers/md/dm-thin.c
parent4a02b34e0cf1d0d0dd3737702841da4bf615a50a (diff)
dm thin: always fallback the pool mode if commit fails
Rename commit_or_fallback() to commit(). Now all previous calls to commit() will trigger the pool mode to fallback if the commit fails. Also, check the error returned from commit() in alloc_data_block(). Signed-off-by: Joe Thornber <ejt@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers/md/dm-thin.c')
-rw-r--r--drivers/md/dm-thin.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 44ee489f4a6e..af79bae5ab74 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -883,32 +883,23 @@ static void schedule_zero(struct thin_c *tc, dm_block_t virt_block,
883 } 883 }
884} 884}
885 885
886static int commit(struct pool *pool)
887{
888 int r;
889
890 r = dm_pool_commit_metadata(pool->pmd);
891 if (r)
892 DMERR_LIMIT("%s: commit failed: error = %d",
893 dm_device_name(pool->pool_md), r);
894
895 return r;
896}
897
898/* 886/*
899 * A non-zero return indicates read_only or fail_io mode. 887 * A non-zero return indicates read_only or fail_io mode.
900 * Many callers don't care about the return value. 888 * Many callers don't care about the return value.
901 */ 889 */
902static int commit_or_fallback(struct pool *pool) 890static int commit(struct pool *pool)
903{ 891{
904 int r; 892 int r;
905 893
906 if (get_pool_mode(pool) != PM_WRITE) 894 if (get_pool_mode(pool) != PM_WRITE)
907 return -EINVAL; 895 return -EINVAL;
908 896
909 r = commit(pool); 897 r = dm_pool_commit_metadata(pool->pmd);
910 if (r) 898 if (r) {
899 DMERR_LIMIT("%s: dm_pool_commit_metadata failed: error = %d",
900 dm_device_name(pool->pool_md), r);
911 set_pool_mode(pool, PM_READ_ONLY); 901 set_pool_mode(pool, PM_READ_ONLY);
902 }
912 903
913 return r; 904 return r;
914} 905}
@@ -945,7 +936,9 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
945 * Try to commit to see if that will free up some 936 * Try to commit to see if that will free up some
946 * more space. 937 * more space.
947 */ 938 */
948 (void) commit_or_fallback(pool); 939 r = commit(pool);
940 if (r)
941 return r;
949 942
950 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks); 943 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
951 if (r) 944 if (r)
@@ -1359,7 +1352,7 @@ static void process_deferred_bios(struct pool *pool)
1359 if (bio_list_empty(&bios) && !need_commit_due_to_time(pool)) 1352 if (bio_list_empty(&bios) && !need_commit_due_to_time(pool))
1360 return; 1353 return;
1361 1354
1362 if (commit_or_fallback(pool)) { 1355 if (commit(pool)) {
1363 while ((bio = bio_list_pop(&bios))) 1356 while ((bio = bio_list_pop(&bios)))
1364 bio_io_error(bio); 1357 bio_io_error(bio);
1365 return; 1358 return;
@@ -2276,7 +2269,7 @@ static int pool_preresume(struct dm_target *ti)
2276 return r; 2269 return r;
2277 2270
2278 if (need_commit1 || need_commit2) 2271 if (need_commit1 || need_commit2)
2279 (void) commit_or_fallback(pool); 2272 (void) commit(pool);
2280 2273
2281 return 0; 2274 return 0;
2282} 2275}
@@ -2303,7 +2296,7 @@ static void pool_postsuspend(struct dm_target *ti)
2303 2296
2304 cancel_delayed_work(&pool->waker); 2297 cancel_delayed_work(&pool->waker);
2305 flush_workqueue(pool->wq); 2298 flush_workqueue(pool->wq);
2306 (void) commit_or_fallback(pool); 2299 (void) commit(pool);
2307} 2300}
2308 2301
2309static int check_arg_count(unsigned argc, unsigned args_required) 2302static int check_arg_count(unsigned argc, unsigned args_required)
@@ -2437,7 +2430,7 @@ static int process_reserve_metadata_snap_mesg(unsigned argc, char **argv, struct
2437 if (r) 2430 if (r)
2438 return r; 2431 return r;
2439 2432
2440 (void) commit_or_fallback(pool); 2433 (void) commit(pool);
2441 2434
2442 r = dm_pool_reserve_metadata_snap(pool->pmd); 2435 r = dm_pool_reserve_metadata_snap(pool->pmd);
2443 if (r) 2436 if (r)
@@ -2499,7 +2492,7 @@ static int pool_message(struct dm_target *ti, unsigned argc, char **argv)
2499 DMWARN("Unrecognised thin pool target message received: %s", argv[0]); 2492 DMWARN("Unrecognised thin pool target message received: %s", argv[0]);
2500 2493
2501 if (!r) 2494 if (!r)
2502 (void) commit_or_fallback(pool); 2495 (void) commit(pool);
2503 2496
2504 return r; 2497 return r;
2505} 2498}
@@ -2554,7 +2547,7 @@ static void pool_status(struct dm_target *ti, status_type_t type,
2554 2547
2555 /* Commit to ensure statistics aren't out-of-date */ 2548 /* Commit to ensure statistics aren't out-of-date */
2556 if (!(status_flags & DM_STATUS_NOFLUSH_FLAG) && !dm_suspended(ti)) 2549 if (!(status_flags & DM_STATUS_NOFLUSH_FLAG) && !dm_suspended(ti))
2557 (void) commit_or_fallback(pool); 2550 (void) commit(pool);
2558 2551
2559 r = dm_pool_get_metadata_transaction_id(pool->pmd, &transaction_id); 2552 r = dm_pool_get_metadata_transaction_id(pool->pmd, &transaction_id);
2560 if (r) { 2553 if (r) {