commit 
10add84e276432d9dd8044679a1028dd4084117e 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: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
 
 
 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 :
                                 clear_clean_shutdown);
 
        WRITE_LOCK(cmd);
+       if (cmd->fail_io)
+               goto out;
+
        r = __commit_transaction(cmd, mutator);
        if (r)
                goto out;
 
        r = __begin_transaction(cmd);
-
 out:
        WRITE_UNLOCK(cmd);
        return r;
        int r = -EINVAL;
 
        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);
 
        return r;
        int r = -EINVAL;
 
        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);
 
        return r;