Commit 2e80638c authored by Mike Snitzer's avatar Mike Snitzer Committed by Greg Kroah-Hartman

dm cache metadata: fail operations if fail_io mode has been established

commit 10add84e upstream.

Otherwise it is possible to trigger crashes due to the metadata being
inaccessible yet these methods don't safely account for that possibility
without these checks.
Reported-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a5b9afd6
...@@ -1627,17 +1627,19 @@ void dm_cache_metadata_set_stats(struct dm_cache_metadata *cmd, ...@@ -1627,17 +1627,19 @@ void dm_cache_metadata_set_stats(struct dm_cache_metadata *cmd,
int dm_cache_commit(struct dm_cache_metadata *cmd, bool clean_shutdown) int dm_cache_commit(struct dm_cache_metadata *cmd, bool clean_shutdown)
{ {
int r; int r = -EINVAL;
flags_mutator mutator = (clean_shutdown ? set_clean_shutdown : flags_mutator mutator = (clean_shutdown ? set_clean_shutdown :
clear_clean_shutdown); clear_clean_shutdown);
WRITE_LOCK(cmd); WRITE_LOCK(cmd);
if (cmd->fail_io)
goto out;
r = __commit_transaction(cmd, mutator); r = __commit_transaction(cmd, mutator);
if (r) if (r)
goto out; goto out;
r = __begin_transaction(cmd); r = __begin_transaction(cmd);
out: out:
WRITE_UNLOCK(cmd); WRITE_UNLOCK(cmd);
return r; return r;
...@@ -1649,7 +1651,8 @@ int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata *cmd, ...@@ -1649,7 +1651,8 @@ int dm_cache_get_free_metadata_block_count(struct dm_cache_metadata *cmd,
int r = -EINVAL; int r = -EINVAL;
READ_LOCK(cmd); READ_LOCK(cmd);
r = dm_sm_get_nr_free(cmd->metadata_sm, result); if (!cmd->fail_io)
r = dm_sm_get_nr_free(cmd->metadata_sm, result);
READ_UNLOCK(cmd); READ_UNLOCK(cmd);
return r; return r;
...@@ -1661,7 +1664,8 @@ int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd, ...@@ -1661,7 +1664,8 @@ int dm_cache_get_metadata_dev_size(struct dm_cache_metadata *cmd,
int r = -EINVAL; int r = -EINVAL;
READ_LOCK(cmd); READ_LOCK(cmd);
r = dm_sm_get_nr_blocks(cmd->metadata_sm, result); if (!cmd->fail_io)
r = dm_sm_get_nr_blocks(cmd->metadata_sm, result);
READ_UNLOCK(cmd); READ_UNLOCK(cmd);
return r; return r;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment