Commit d53f1faf authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mike Snitzer

dm writecache: do direct write if the cache is full

If the cache device is full, we do a direct write to the origin device.
Note that we must not do it if the written block is already in the cache.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent eaab4bde
...@@ -1194,6 +1194,7 @@ static int writecache_map(struct dm_target *ti, struct bio *bio) ...@@ -1194,6 +1194,7 @@ static int writecache_map(struct dm_target *ti, struct bio *bio)
} }
} else { } else {
do { do {
bool found_entry = false;
if (writecache_has_error(wc)) if (writecache_has_error(wc))
goto unlock_error; goto unlock_error;
e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0); e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0);
...@@ -1204,9 +1205,21 @@ static int writecache_map(struct dm_target *ti, struct bio *bio) ...@@ -1204,9 +1205,21 @@ static int writecache_map(struct dm_target *ti, struct bio *bio)
wc->overwrote_committed = true; wc->overwrote_committed = true;
goto bio_copy; goto bio_copy;
} }
found_entry = true;
} }
e = writecache_pop_from_freelist(wc, (sector_t)-1); e = writecache_pop_from_freelist(wc, (sector_t)-1);
if (unlikely(!e)) { if (unlikely(!e)) {
if (!found_entry) {
e = writecache_find_entry(wc, bio->bi_iter.bi_sector, WFE_RETURN_FOLLOWING);
if (e) {
sector_t next_boundary = read_original_sector(wc, e) - bio->bi_iter.bi_sector;
BUG_ON(!next_boundary);
if (next_boundary < bio->bi_iter.bi_size >> SECTOR_SHIFT) {
dm_accept_partial_bio(bio, next_boundary);
}
}
goto unlock_remap_origin;
}
writecache_wait_on_freelist(wc); writecache_wait_on_freelist(wc);
continue; continue;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment