]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
dm cache metadata: fix READ_LOCK macros and cleanup WRITE_LOCK macros
authorMike Snitzer <snitzer@redhat.com>
Tue, 12 Apr 2016 16:14:46 +0000 (12:14 -0400)
committerMike Snitzer <snitzer@redhat.com>
Thu, 14 Apr 2016 21:34:49 +0000 (17:34 -0400)
The READ_LOCK macro was incorrectly returning -EINVAL if
dm_bm_is_read_only() was true -- it will always be true once the cache
metadata transitions to read-only by dm_cache_metadata_set_read_only().

Wrap READ_LOCK and WRITE_LOCK multi-statement macros in do {} while(0).
Also, all accesses of the 'cmd' argument passed to these related macros
are now encapsulated in parenthesis.

A follow-up patch can be developed to eliminate the use of macros in
favor of pure C code.  Avoiding that now given that this needs to apply
to stable@.

Reported-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Fixes: d14fcf3dd79 ("dm cache: make sure every metadata function checks fail_io")
Cc: stable@vger.kernel.org
drivers/md/dm-cache-metadata.c

index 27f2ef300f8bb10bac594b094e3fafcc8db407d0..65ce6985f87a0a940aed6bf6bc9a70663a84c9fa 100644 (file)
@@ -867,39 +867,55 @@ static int blocks_are_unmapped_or_clean(struct dm_cache_metadata *cmd,
        return 0;
 }
 
-#define WRITE_LOCK(cmd)        \
-       down_write(&cmd->root_lock); \
-       if (cmd->fail_io || dm_bm_is_read_only(cmd->bm)) { \
-               up_write(&cmd->root_lock); \
-               return -EINVAL; \
+static bool cmd_write_lock(struct dm_cache_metadata *cmd)
+{
+       down_write(&cmd->root_lock);
+       if (cmd->fail_io || dm_bm_is_read_only(cmd->bm)) {
+               up_write(&cmd->root_lock);
+               return false;
        }
+       return true;
+}
 
-#define WRITE_LOCK_VOID(cmd) \
-       down_write(&cmd->root_lock); \
-       if (cmd->fail_io || dm_bm_is_read_only(cmd->bm)) { \
-               up_write(&cmd->root_lock); \
-               return; \
-       }
+#define WRITE_LOCK(cmd)                                \
+       do {                                    \
+               if (!cmd_write_lock((cmd)))     \
+                       return -EINVAL;         \
+       } while(0)
+
+#define WRITE_LOCK_VOID(cmd)                   \
+       do {                                    \
+               if (!cmd_write_lock((cmd)))     \
+                       return;                 \
+       } while(0)
 
 #define WRITE_UNLOCK(cmd) \
-       up_write(&cmd->root_lock)
+       up_write(&(cmd)->root_lock)
 
-#define READ_LOCK(cmd) \
-       down_read(&cmd->root_lock); \
-       if (cmd->fail_io || dm_bm_is_read_only(cmd->bm)) { \
-               up_read(&cmd->root_lock); \
-               return -EINVAL; \
+static bool cmd_read_lock(struct dm_cache_metadata *cmd)
+{
+       down_write(&cmd->root_lock);
+       if (cmd->fail_io) {
+               up_write(&cmd->root_lock);
+               return false;
        }
+       return true;
+}
 
-#define READ_LOCK_VOID(cmd)    \
-       down_read(&cmd->root_lock); \
-       if (cmd->fail_io || dm_bm_is_read_only(cmd->bm)) { \
-               up_read(&cmd->root_lock); \
-               return; \
-       }
+#define READ_LOCK(cmd)                         \
+       do {                                    \
+               if (!cmd_read_lock((cmd)))      \
+                       return -EINVAL;         \
+       } while(0)
+
+#define READ_LOCK_VOID(cmd)                    \
+       do {                                    \
+               if (!cmd_read_lock((cmd)))      \
+                       return;                 \
+       } while(0)
 
 #define READ_UNLOCK(cmd) \
-       up_read(&cmd->root_lock)
+       up_read(&(cmd)->root_lock)
 
 int dm_cache_resize(struct dm_cache_metadata *cmd, dm_cblock_t new_cache_size)
 {