Skip to content

Commit

Permalink
dm writecache: do direct write if the cache is full
Browse files Browse the repository at this point in the history
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: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
  • Loading branch information
Mikulas Patocka authored and Mike Snitzer committed Mar 24, 2020
1 parent eaab4bd commit d53f1fa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions drivers/md/dm-writecache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@ static int writecache_map(struct dm_target *ti, struct bio *bio)
}
} else {
do {
bool found_entry = false;
if (writecache_has_error(wc))
goto unlock_error;
e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0);
Expand All @@ -1204,9 +1205,21 @@ static int writecache_map(struct dm_target *ti, struct bio *bio)
wc->overwrote_committed = true;
goto bio_copy;
}
found_entry = true;
}
e = writecache_pop_from_freelist(wc, (sector_t)-1);
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);
continue;
}
Expand Down

0 comments on commit d53f1fa

Please sign in to comment.