Skip to content

Commit c6ef4d2

Browse files
committed
CA-403297: when storing read-through do not mirror
When the lcache driver has read from the remote storage and returned the data to the caller it then stores the data into the local vhdcache by forwarding a write to the vhdcache file. As the vhdcache file is opened in TD_VBD_SECONDARY_MIRROR mode this also results in the data being unnecessarily written back to the remote where it has just been read from. Signed-off-by: Mark Syms <[email protected]>
1 parent 522971d commit c6ef4d2

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

drivers/block-lcache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ lcache_store_read(td_lcache_t *cache, td_lcache_req_t *req)
284284
vreq->iovcnt = 1;
285285
vreq->cb = __lcache_write_cb;
286286
vreq->token = cache;
287+
vreq->skip_mirror = true;
287288

288289
vbd = req->treq.vreq->vbd;
289290

drivers/tapdisk-vbd.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,26 +1552,33 @@ tapdisk_vbd_issue_request(td_vbd_t *vbd, td_vbd_request_t *vreq)
15521552
vreq->secs_pending += iov->secs;
15531553
vbd->secs_pending += iov->secs;
15541554
if (vbd->secondary_mode == TD_VBD_SECONDARY_MIRROR &&
1555-
vreq->op == TD_OP_WRITE) {
1555+
vreq->op == TD_OP_WRITE &&
1556+
likely(vreq->skip_mirror == false))
1557+
{
15561558
vreq->secs_pending += iov->secs;
15571559
vbd->secs_pending += iov->secs;
15581560
}
15591561

15601562
switch (vreq->op) {
15611563
case TD_OP_WRITE:
15621564
treq.op = TD_OP_WRITE;
1563-
vbd->vdi_stats.stats->write_reqs_submitted++;
1565+
vbd->vdi_stats.stats->write_reqs_submitted++;
15641566
/*
1565-
* it's important to queue the mirror request before
1566-
* queuing the main one. If the main image runs into
1567-
* ENOSPC, the mirroring could be disabled before
1568-
* td_queue_write returns, so if the mirror request was
1569-
* queued after (which would then not happen), we'd
1570-
* lose that write and cause the process to hang with
1571-
* unacknowledged writes
1567+
* it's important to queue the mirror request before
1568+
* queuing the main one. If the main image runs into
1569+
* ENOSPC, the mirroring could be disabled before
1570+
* td_queue_write returns, so if the mirror request was
1571+
* queued after (which would then not happen), we'd
1572+
* lose that write and cause the process to hang with
1573+
* unacknowledged writes.
1574+
*
1575+
* Skip when lcache is storing a read-through.
15721576
*/
1573-
if (vbd->secondary_mode == TD_VBD_SECONDARY_MIRROR)
1574-
queue_mirror_req(vbd, treq);
1577+
if (vbd->secondary_mode == TD_VBD_SECONDARY_MIRROR &&
1578+
likely(vreq->skip_mirror == false)) {
1579+
queue_mirror_req(vbd, treq);
1580+
}
1581+
15751582
td_queue_write(treq.image, treq);
15761583
break;
15771584

drivers/tapdisk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ struct td_vbd_request {
177177
int num_retries;
178178
struct timeval ts;
179179
struct timeval last_try;
180+
/* When "reading-through" the local cache, don't write back to the source */
181+
bool skip_mirror;
180182

181183
td_vbd_t *vbd;
182184
struct list_head next;

0 commit comments

Comments
 (0)