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

Configure Feed

Select the types of activity you want to include in your feed.

dm cache: fix dirty mapping checking in passthrough mode switching

As mentioned in commit 9b1cc9f251af ("dm cache: share cache-metadata
object across inactive and active DM tables"), dm-cache assumed table
reload occurs after suspension, while LVM's table preload breaks this
assumption. The dirty mapping check for passthrough mode was designed
around this assumption and is performed during table creation, causing
the check to fail with preload while metadata updates are ongoing. This
risks loading dirty mappings into passthrough mode, resulting in data
loss.

Reproduce steps:

1. Create a writeback cache with zero migration_threshold to produce
dirty mappings

dmsetup create cmeta --table "0 8192 linear /dev/sdc 0"
dmsetup create cdata --table "0 131072 linear /dev/sdc 8192"
dmsetup create corig --table "0 262144 linear /dev/sdc 262144"
dd if=/dev/zero of=/dev/mapper/cmeta bs=4k count=1 oflag=direct
dmsetup create cache --table "0 262144 cache /dev/mapper/cmeta \
/dev/mapper/cdata /dev/mapper/corig 128 2 metadata2 writeback smq \
2 migration_threshold 0"

2. Preload a table in passthrough mode

dmsetup reload cache --table "0 262144 cache /dev/mapper/cmeta \
/dev/mapper/cdata /dev/mapper/corig 128 2 metadata2 passthrough smq 0"

3. Write to the first cache block to make it dirty

fio --filename=/dev/mapper/cache --name=populate --rw=write --bs=4k \
--direct=1 --size=64k

4. Resume the inactive table. Now it's possible to load the dirty block
into passthrough mode.

dmsetup resume cache

Fix by moving the checks to the preresume phase to support table
preloading. Also remove the unused function dm_cache_metadata_all_clean.

Fixes: 2ee57d587357 ("dm cache: add passthrough mode")
Signed-off-by: Ming-Hung Tsai <mtsai@redhat.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

authored by

Ming-Hung Tsai and committed by
Mikulas Patocka
32258674 e4f66341

+8 -33
-11
drivers/md/dm-cache-metadata.c
··· 1714 1714 return r; 1715 1715 } 1716 1716 1717 - int dm_cache_metadata_all_clean(struct dm_cache_metadata *cmd, bool *result) 1718 - { 1719 - int r; 1720 - 1721 - READ_LOCK(cmd); 1722 - r = blocks_are_unmapped_or_clean(cmd, 0, cmd->cache_blocks, result); 1723 - READ_UNLOCK(cmd); 1724 - 1725 - return r; 1726 - } 1727 - 1728 1717 void dm_cache_metadata_set_read_only(struct dm_cache_metadata *cmd) 1729 1718 { 1730 1719 WRITE_LOCK_VOID(cmd);
-5
drivers/md/dm-cache-metadata.h
··· 135 135 */ 136 136 int dm_cache_write_hints(struct dm_cache_metadata *cmd, struct dm_cache_policy *p); 137 137 138 - /* 139 - * Query method. Are all the blocks in the cache clean? 140 - */ 141 - int dm_cache_metadata_all_clean(struct dm_cache_metadata *cmd, bool *result); 142 - 143 138 int dm_cache_metadata_needs_check(struct dm_cache_metadata *cmd, bool *result); 144 139 int dm_cache_metadata_set_needs_check(struct dm_cache_metadata *cmd); 145 140 void dm_cache_metadata_set_read_only(struct dm_cache_metadata *cmd);
+8 -17
drivers/md/dm-cache-target.c
··· 2499 2499 goto bad; 2500 2500 } 2501 2501 2502 - if (passthrough_mode(cache)) { 2503 - bool all_clean; 2504 - 2505 - r = dm_cache_metadata_all_clean(cache->cmd, &all_clean); 2506 - if (r) { 2507 - *error = "dm_cache_metadata_all_clean() failed"; 2508 - goto bad; 2509 - } 2510 - 2511 - if (!all_clean) { 2512 - *error = "Cannot enter passthrough mode unless all blocks are clean"; 2513 - r = -EINVAL; 2514 - goto bad; 2515 - } 2516 - 2502 + if (passthrough_mode(cache)) 2517 2503 policy_allow_migrations(cache->policy, false); 2518 - } 2519 2504 2520 2505 spin_lock_init(&cache->lock); 2521 2506 bio_list_init(&cache->deferred_bios); ··· 2827 2842 struct cache *cache = context; 2828 2843 2829 2844 if (dirty) { 2845 + if (passthrough_mode(cache)) { 2846 + DMERR("%s: cannot enter passthrough mode unless all blocks are clean", 2847 + cache_device_name(cache)); 2848 + return -EBUSY; 2849 + } 2850 + 2830 2851 set_bit(from_cblock(cblock), cache->dirty_bitset); 2831 2852 atomic_inc(&cache->nr_dirty); 2832 2853 } else ··· 3066 3075 load_filtered_mapping, cache); 3067 3076 if (r) { 3068 3077 DMERR("%s: could not load cache mappings", cache_device_name(cache)); 3069 - if (r != -EFBIG) 3078 + if (r != -EFBIG && r != -EBUSY) 3070 3079 metadata_operation_failed(cache, "dm_cache_load_mappings", r); 3071 3080 return r; 3072 3081 }