Skip to content

Commit df5fa69

Browse files
Christoph HellwigNicholas Bellinger
authored andcommitted
target: make iblock_emulate_sync_cache asynchronous
Do not block the submitting thread when handling a SYNCHRONIZE CACHE command, but implement it asynchronously by sending the FLUSH command ourself and calling transport_complete_sync_cache from the completion handler. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 6b20fa9 commit df5fa69

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

‎drivers/target/target_core_iblock.c‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -313,37 +313,42 @@ static unsigned long long iblock_emulate_read_cap_with_block_size(
313313
return blocks_long;
314314
}
315315

316+
static void iblock_end_io_flush(struct bio *bio, int err)
317+
{
318+
struct se_cmd *cmd = bio->bi_private;
319+
320+
if (err)
321+
pr_err("IBLOCK: cache flush failed: %d\n", err);
322+
323+
if (cmd)
324+
transport_complete_sync_cache(cmd, err == 0);
325+
bio_put(bio);
326+
}
327+
316328
/*
317-
* Emulate SYCHRONIZE_CACHE_*
329+
* Implement SYCHRONIZE CACHE. Note that we can't handle lba ranges and must
330+
* always flush the whole cache.
318331
*/
319332
static void iblock_emulate_sync_cache(struct se_task *task)
320333
{
321334
struct se_cmd *cmd = task->task_se_cmd;
322335
struct iblock_dev *ib_dev = cmd->se_dev->dev_ptr;
323336
int immed = (cmd->t_task_cdb[1] & 0x2);
324-
sector_t error_sector;
325-
int ret;
337+
struct bio *bio;
326338

327339
/*
328340
* If the Immediate bit is set, queue up the GOOD response
329-
* for this SYNCHRONIZE_CACHE op
341+
* for this SYNCHRONIZE_CACHE op.
330342
*/
331343
if (immed)
332344
transport_complete_sync_cache(cmd, 1);
333345

334-
/*
335-
* blkdev_issue_flush() does not support a specifying a range, so
336-
* we have to flush the entire cache.
337-
*/
338-
ret = blkdev_issue_flush(ib_dev->ibd_bd, GFP_KERNEL, &error_sector);
339-
if (ret != 0) {
340-
pr_err("IBLOCK: block_issue_flush() failed: %d "
341-
" error_sector: %llu\n", ret,
342-
(unsigned long long)error_sector);
343-
}
344-
346+
bio = bio_alloc(GFP_KERNEL, 0);
347+
bio->bi_end_io = iblock_end_io_flush;
348+
bio->bi_bdev = ib_dev->ibd_bd;
345349
if (!immed)
346-
transport_complete_sync_cache(cmd, ret == 0);
350+
bio->bi_private = cmd;
351+
submit_bio(WRITE_FLUSH, bio);
347352
}
348353

349354
/*

0 commit comments

Comments
 (0)