Commit 020cc3b5 authored by Joe Thornber's avatar Joe Thornber Committed by Mike Snitzer
Browse files

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: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org
parent 4a02b34e
Loading
Loading
Loading
Loading
+15 −22
Original line number Original line Diff line number Diff line
@@ -883,32 +883,23 @@ static void schedule_zero(struct thin_c *tc, dm_block_t virt_block,
	}
	}
}
}


static int commit(struct pool *pool)
{
	int r;

	r = dm_pool_commit_metadata(pool->pmd);
	if (r)
		DMERR_LIMIT("%s: commit failed: error = %d",
			    dm_device_name(pool->pool_md), r);

	return r;
}

/*
/*
 * A non-zero return indicates read_only or fail_io mode.
 * A non-zero return indicates read_only or fail_io mode.
 * Many callers don't care about the return value.
 * Many callers don't care about the return value.
 */
 */
static int commit_or_fallback(struct pool *pool)
static int commit(struct pool *pool)
{
{
	int r;
	int r;


	if (get_pool_mode(pool) != PM_WRITE)
	if (get_pool_mode(pool) != PM_WRITE)
		return -EINVAL;
		return -EINVAL;


	r = commit(pool);
	r = dm_pool_commit_metadata(pool->pmd);
	if (r)
	if (r) {
		DMERR_LIMIT("%s: dm_pool_commit_metadata failed: error = %d",
			    dm_device_name(pool->pool_md), r);
		set_pool_mode(pool, PM_READ_ONLY);
		set_pool_mode(pool, PM_READ_ONLY);
	}


	return r;
	return r;
}
}
@@ -945,7 +936,9 @@ static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
		 * Try to commit to see if that will free up some
		 * Try to commit to see if that will free up some
		 * more space.
		 * more space.
		 */
		 */
		(void) commit_or_fallback(pool);
		r = commit(pool);
		if (r)
			return r;


		r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
		r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
		if (r)
		if (r)
@@ -1359,7 +1352,7 @@ static void process_deferred_bios(struct pool *pool)
	if (bio_list_empty(&bios) && !need_commit_due_to_time(pool))
	if (bio_list_empty(&bios) && !need_commit_due_to_time(pool))
		return;
		return;


	if (commit_or_fallback(pool)) {
	if (commit(pool)) {
		while ((bio = bio_list_pop(&bios)))
		while ((bio = bio_list_pop(&bios)))
			bio_io_error(bio);
			bio_io_error(bio);
		return;
		return;
@@ -2276,7 +2269,7 @@ static int pool_preresume(struct dm_target *ti)
		return r;
		return r;


	if (need_commit1 || need_commit2)
	if (need_commit1 || need_commit2)
		(void) commit_or_fallback(pool);
		(void) commit(pool);


	return 0;
	return 0;
}
}
@@ -2303,7 +2296,7 @@ static void pool_postsuspend(struct dm_target *ti)


	cancel_delayed_work(&pool->waker);
	cancel_delayed_work(&pool->waker);
	flush_workqueue(pool->wq);
	flush_workqueue(pool->wq);
	(void) commit_or_fallback(pool);
	(void) commit(pool);
}
}


static int check_arg_count(unsigned argc, unsigned args_required)
static 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
	if (r)
	if (r)
		return r;
		return r;


	(void) commit_or_fallback(pool);
	(void) commit(pool);


	r = dm_pool_reserve_metadata_snap(pool->pmd);
	r = dm_pool_reserve_metadata_snap(pool->pmd);
	if (r)
	if (r)
@@ -2499,7 +2492,7 @@ static int pool_message(struct dm_target *ti, unsigned argc, char **argv)
		DMWARN("Unrecognised thin pool target message received: %s", argv[0]);
		DMWARN("Unrecognised thin pool target message received: %s", argv[0]);


	if (!r)
	if (!r)
		(void) commit_or_fallback(pool);
		(void) commit(pool);


	return r;
	return r;
}
}
@@ -2554,7 +2547,7 @@ static void pool_status(struct dm_target *ti, status_type_t type,


		/* Commit to ensure statistics aren't out-of-date */
		/* Commit to ensure statistics aren't out-of-date */
		if (!(status_flags & DM_STATUS_NOFLUSH_FLAG) && !dm_suspended(ti))
		if (!(status_flags & DM_STATUS_NOFLUSH_FLAG) && !dm_suspended(ti))
			(void) commit_or_fallback(pool);
			(void) commit(pool);


		r = dm_pool_get_metadata_transaction_id(pool->pmd, &transaction_id);
		r = dm_pool_get_metadata_transaction_id(pool->pmd, &transaction_id);
		if (r) {
		if (r) {