OSDN Git Service

dm switch: factor out switch_region_table_read
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 28 Jul 2014 21:49:41 +0000 (17:49 -0400)
committerMike Snitzer <snitzer@redhat.com>
Fri, 1 Aug 2014 16:30:36 +0000 (12:30 -0400)
Move code that reads the table to a switch_region_table_read.
It will be needed for the next commit.  No functional change.

Tested-by: Jay Wang <jwang@nimblestorage.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-switch.c

index 09a688b..c40e095 100644 (file)
@@ -137,13 +137,23 @@ static void switch_get_position(struct switch_ctx *sctx, unsigned long region_nr
        *bit *= sctx->region_table_entry_bits;
 }
 
+static unsigned switch_region_table_read(struct switch_ctx *sctx, unsigned long region_nr)
+{
+       unsigned long region_index;
+       unsigned bit;
+
+       switch_get_position(sctx, region_nr, &region_index, &bit);
+
+       return (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
+               ((1 << sctx->region_table_entry_bits) - 1);
+}
+
 /*
  * Find which path to use at given offset.
  */
 static unsigned switch_get_path_nr(struct switch_ctx *sctx, sector_t offset)
 {
-       unsigned long region_index;
-       unsigned bit, path_nr;
+       unsigned path_nr;
        sector_t p;
 
        p = offset;
@@ -152,9 +162,7 @@ static unsigned switch_get_path_nr(struct switch_ctx *sctx, sector_t offset)
        else
                sector_div(p, sctx->region_size);
 
-       switch_get_position(sctx, p, &region_index, &bit);
-       path_nr = (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) &
-              ((1 << sctx->region_table_entry_bits) - 1);
+       path_nr = switch_region_table_read(sctx, p);
 
        /* This can only happen if the processor uses non-atomic stores. */
        if (unlikely(path_nr >= sctx->nr_paths))