Skip to content

Commit 272348e

Browse files
author
Bryant G. Ly
committed
Revert "target/iblock: Convert WRITE_SAME to blkdev_issue_zeroout"
This reverts commit 2237498.
1 parent 268c785 commit 272348e

File tree

2 files changed

+18
-28
lines changed

2 files changed

+18
-28
lines changed

drivers/target/target_core_device.c

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

drivers/target/target_core_iblock.c

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ 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;
9089
int ret = -ENOMEM;
9190

9291
if (!(ib_dev->ibd_flags & IBDF_HAS_UDEV_PATH)) {
@@ -130,11 +129,7 @@ static int iblock_configure_device(struct se_device *dev)
130129
* Enable write same emulation for IBLOCK and use 0xFFFF as
131130
* the smaller WRITE_SAME(10) only has a two-byte block count.
132131
*/
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;
132+
dev->dev_attrib.max_write_same_len = 0xFFFF;
138133

139134
if (blk_queue_nonrot(q))
140135
dev->dev_attrib.is_nonrot = 1;
@@ -423,31 +418,28 @@ iblock_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
423418
}
424419

425420
static sense_reason_t
426-
iblock_execute_zero_out(struct block_device *bdev, struct se_cmd *cmd)
421+
iblock_execute_write_same_direct(struct block_device *bdev, struct se_cmd *cmd)
427422
{
428423
struct se_device *dev = cmd->se_dev;
429424
struct scatterlist *sg = &cmd->t_data_sg[0];
430-
unsigned char *buf, zero = 0x00, *p = &zero;
431-
int rc, ret;
432-
433-
buf = kmap(sg_page(sg)) + sg->offset;
434-
if (!buf)
435-
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
436-
/*
437-
* Fall back to block_execute_write_same() slow-path if
438-
* incoming WRITE_SAME payload does not contain zeros.
439-
*/
440-
rc = memcmp(buf, p, cmd->data_length);
441-
kunmap(sg_page(sg));
425+
struct page *page = NULL;
426+
int ret;
442427

443-
if (rc)
444-
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
428+
if (sg->offset) {
429+
page = alloc_page(GFP_KERNEL);
430+
if (!page)
431+
return TCM_OUT_OF_RESOURCES;
432+
sg_copy_to_buffer(sg, cmd->t_data_nents, page_address(page),
433+
dev->dev_attrib.block_size);
434+
}
445435

446-
ret = blkdev_issue_zeroout(bdev,
436+
ret = blkdev_issue_write_same(bdev,
447437
target_to_linux_sector(dev, cmd->t_task_lba),
448438
target_to_linux_sector(dev,
449439
sbc_get_write_same_sectors(cmd)),
450-
GFP_KERNEL, false);
440+
GFP_KERNEL, page ? page : sg_page(sg));
441+
if (page)
442+
__free_page(page);
451443
if (ret)
452444
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
453445

@@ -483,10 +475,8 @@ iblock_execute_write_same(struct se_cmd *cmd)
483475
return TCM_INVALID_CDB_FIELD;
484476
}
485477

486-
if (bdev_write_zeroes_sectors(bdev)) {
487-
if (!iblock_execute_zero_out(bdev, cmd))
488-
return 0;
489-
}
478+
if (bdev_write_same(bdev))
479+
return iblock_execute_write_same_direct(bdev, cmd);
490480

491481
ibr = kzalloc(sizeof(struct iblock_req), GFP_KERNEL);
492482
if (!ibr)

0 commit comments

Comments
 (0)