Skip to content

Commit 2237498

Browse files
author
Nicholas Bellinger
committed
target/iblock: Convert WRITE_SAME to blkdev_issue_zeroout
The people who are actively using iblock_execute_write_same_direct() are doing so in the context of ESX VAAI BlockZero, together with EXTENDED_COPY and COMPARE_AND_WRITE primitives. In practice though I've not seen any users of IBLOCK WRITE_SAME for anything other than VAAI BlockZero, so just using blkdev_issue_zeroout() when available, and falling back to iblock_execute_write_same() if the WRITE_SAME buffer contains anything other than zeros should be OK. (Hook up max_write_zeroes_sectors to signal LBPRZ feature bit in target_configure_unmap_from_queue - nab) Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Mike Christie <mchristi@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Jens Axboe <axboe@fb.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent 464fd64 commit 2237498

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

drivers/target/target_core_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
851851
attrib->unmap_granularity = q->limits.discard_granularity / block_size;
852852
attrib->unmap_granularity_alignment = q->limits.discard_alignment /
853853
block_size;
854-
attrib->unmap_zeroes_data = 0;
854+
attrib->unmap_zeroes_data = (q->limits.max_write_zeroes_sectors);
855855
return true;
856856
}
857857
EXPORT_SYMBOL(target_configure_unmap_from_queue);

drivers/target/target_core_iblock.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static int iblock_configure_device(struct se_device *dev)
8686
struct block_device *bd = NULL;
8787
struct blk_integrity *bi;
8888
fmode_t mode;
89+
unsigned int max_write_zeroes_sectors;
8990
int ret = -ENOMEM;
9091

9192
if (!(ib_dev->ibd_flags & IBDF_HAS_UDEV_PATH)) {
@@ -129,7 +130,11 @@ static int iblock_configure_device(struct se_device *dev)
129130
* Enable write same emulation for IBLOCK and use 0xFFFF as
130131
* the smaller WRITE_SAME(10) only has a two-byte block count.
131132
*/
132-
dev->dev_attrib.max_write_same_len = 0xFFFF;
133+
max_write_zeroes_sectors = bdev_write_zeroes_sectors(bd);
134+
if (max_write_zeroes_sectors)
135+
dev->dev_attrib.max_write_same_len = max_write_zeroes_sectors;
136+
else
137+
dev->dev_attrib.max_write_same_len = 0xFFFF;
133138

134139
if (blk_queue_nonrot(q))
135140
dev->dev_attrib.is_nonrot = 1;
@@ -415,28 +420,31 @@ iblock_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
415420
}
416421

417422
static sense_reason_t
418-
iblock_execute_write_same_direct(struct block_device *bdev, struct se_cmd *cmd)
423+
iblock_execute_zero_out(struct block_device *bdev, struct se_cmd *cmd)
419424
{
420425
struct se_device *dev = cmd->se_dev;
421426
struct scatterlist *sg = &cmd->t_data_sg[0];
422-
struct page *page = NULL;
423-
int ret;
427+
unsigned char *buf, zero = 0x00, *p = &zero;
428+
int rc, ret;
424429

425-
if (sg->offset) {
426-
page = alloc_page(GFP_KERNEL);
427-
if (!page)
428-
return TCM_OUT_OF_RESOURCES;
429-
sg_copy_to_buffer(sg, cmd->t_data_nents, page_address(page),
430-
dev->dev_attrib.block_size);
431-
}
430+
buf = kmap(sg_page(sg)) + sg->offset;
431+
if (!buf)
432+
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
433+
/*
434+
* Fall back to block_execute_write_same() slow-path if
435+
* incoming WRITE_SAME payload does not contain zeros.
436+
*/
437+
rc = memcmp(buf, p, cmd->data_length);
438+
kunmap(sg_page(sg));
439+
440+
if (rc)
441+
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
432442

433-
ret = blkdev_issue_write_same(bdev,
443+
ret = blkdev_issue_zeroout(bdev,
434444
target_to_linux_sector(dev, cmd->t_task_lba),
435445
target_to_linux_sector(dev,
436446
sbc_get_write_same_sectors(cmd)),
437-
GFP_KERNEL, page ? page : sg_page(sg));
438-
if (page)
439-
__free_page(page);
447+
GFP_KERNEL, false);
440448
if (ret)
441449
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
442450

@@ -472,8 +480,10 @@ iblock_execute_write_same(struct se_cmd *cmd)
472480
return TCM_INVALID_CDB_FIELD;
473481
}
474482

475-
if (bdev_write_same(bdev))
476-
return iblock_execute_write_same_direct(bdev, cmd);
483+
if (bdev_write_zeroes_sectors(bdev)) {
484+
if (!iblock_execute_zero_out(bdev, cmd))
485+
return 0;
486+
}
477487

478488
ibr = kzalloc(sizeof(struct iblock_req), GFP_KERNEL);
479489
if (!ibr)

0 commit comments

Comments
 (0)