Commit dbc21c5a authored by Asias He's avatar Asias He Committed by Nicholas Bellinger

target/iblock: Add iblock_do_unmap() helper

Add helper iblock_do_unmap() to remove duplicated code in
iblock_execute_write_same_unmap() and iblock_execute_unmap().

Cc: Christoph Hellwig <hch@lst.de>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: default avatarAsias He <asias@redhat.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 43f55bbb
...@@ -379,6 +379,21 @@ iblock_execute_sync_cache(struct se_cmd *cmd) ...@@ -379,6 +379,21 @@ iblock_execute_sync_cache(struct se_cmd *cmd)
return 0; return 0;
} }
static sense_reason_t
iblock_do_unmap(struct se_cmd *cmd, struct block_device *bdev,
sector_t lba, sector_t nolb)
{
int ret;
ret = blkdev_issue_discard(bdev, lba, nolb, GFP_KERNEL, 0);
if (ret < 0) {
pr_err("blkdev_issue_discard() failed: %d\n", ret);
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
}
return 0;
}
static sense_reason_t static sense_reason_t
iblock_execute_unmap(struct se_cmd *cmd) iblock_execute_unmap(struct se_cmd *cmd)
{ {
...@@ -389,7 +404,7 @@ iblock_execute_unmap(struct se_cmd *cmd) ...@@ -389,7 +404,7 @@ iblock_execute_unmap(struct se_cmd *cmd)
int size; int size;
u32 range; u32 range;
sense_reason_t ret = 0; sense_reason_t ret = 0;
int dl, bd_dl, err; int dl, bd_dl;
/* We never set ANC_SUP */ /* We never set ANC_SUP */
if (cmd->t_task_cdb[1]) if (cmd->t_task_cdb[1])
...@@ -446,14 +461,9 @@ iblock_execute_unmap(struct se_cmd *cmd) ...@@ -446,14 +461,9 @@ iblock_execute_unmap(struct se_cmd *cmd)
goto err; goto err;
} }
err = blkdev_issue_discard(ib_dev->ibd_bd, lba, range, ret = iblock_do_unmap(cmd, ib_dev->ibd_bd, lba, range);
GFP_KERNEL, 0); if (ret)
if (err < 0) {
pr_err("blkdev_issue_discard() failed: %d\n",
err);
ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
goto err; goto err;
}
ptr += 16; ptr += 16;
size -= 16; size -= 16;
...@@ -469,15 +479,14 @@ iblock_execute_unmap(struct se_cmd *cmd) ...@@ -469,15 +479,14 @@ iblock_execute_unmap(struct se_cmd *cmd)
static sense_reason_t static sense_reason_t
iblock_execute_write_same_unmap(struct se_cmd *cmd) iblock_execute_write_same_unmap(struct se_cmd *cmd)
{ {
struct iblock_dev *ib_dev = IBLOCK_DEV(cmd->se_dev); struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd;
int rc; sector_t lba = cmd->t_task_lba;
sector_t nolb = sbc_get_write_same_sectors(cmd);
rc = blkdev_issue_discard(ib_dev->ibd_bd, cmd->t_task_lba, int ret;
sbc_get_write_same_sectors(cmd), GFP_KERNEL, 0);
if (rc < 0) { ret = iblock_do_unmap(cmd, bdev, lba, nolb);
pr_warn("blkdev_issue_discard() failed: %d\n", rc); if (ret)
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; return ret;
}
target_complete_cmd(cmd, GOOD); target_complete_cmd(cmd, GOOD);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment