Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dm switch: factor out switch_region_table_read

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>

authored by

Mikulas Patocka and committed by
Mike Snitzer
99eb1908 b0246530

+13 -5
+13 -5
drivers/md/dm-switch.c
··· 137 137 *bit *= sctx->region_table_entry_bits; 138 138 } 139 139 140 + static unsigned switch_region_table_read(struct switch_ctx *sctx, unsigned long region_nr) 141 + { 142 + unsigned long region_index; 143 + unsigned bit; 144 + 145 + switch_get_position(sctx, region_nr, &region_index, &bit); 146 + 147 + return (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) & 148 + ((1 << sctx->region_table_entry_bits) - 1); 149 + } 150 + 140 151 /* 141 152 * Find which path to use at given offset. 142 153 */ 143 154 static unsigned switch_get_path_nr(struct switch_ctx *sctx, sector_t offset) 144 155 { 145 - unsigned long region_index; 146 - unsigned bit, path_nr; 156 + unsigned path_nr; 147 157 sector_t p; 148 158 149 159 p = offset; ··· 162 152 else 163 153 sector_div(p, sctx->region_size); 164 154 165 - switch_get_position(sctx, p, &region_index, &bit); 166 - path_nr = (ACCESS_ONCE(sctx->region_table[region_index]) >> bit) & 167 - ((1 << sctx->region_table_entry_bits) - 1); 155 + path_nr = switch_region_table_read(sctx, p); 168 156 169 157 /* This can only happen if the processor uses non-atomic stores. */ 170 158 if (unlikely(path_nr >= sctx->nr_paths))