diff options
author | Asias He <asias@redhat.com> | 2013-02-25 14:03:45 +0800 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2013-04-25 01:05:24 -0700 |
commit | dbc21c5abbeb4419da5a54157c4b7a0ec0dee185 (patch) | |
tree | 916011a08bf1d2ac9b09fcecdf8aee1b5c69d984 /drivers/target | |
parent | 43f55bbb144acca55cea50326388d1b648b6fd0f (diff) | |
download | linux-dbc21c5abbeb4419da5a54157c4b7a0ec0dee185.tar.bz2 |
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: Asias He <asias@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r-- | drivers/target/target_core_iblock.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index 8bcc514ec8b6..96a9b620e89a 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -380,6 +380,21 @@ iblock_execute_sync_cache(struct se_cmd *cmd) } 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 iblock_execute_unmap(struct se_cmd *cmd) { struct se_device *dev = cmd->se_dev; @@ -389,7 +404,7 @@ iblock_execute_unmap(struct se_cmd *cmd) int size; u32 range; sense_reason_t ret = 0; - int dl, bd_dl, err; + int dl, bd_dl; /* We never set ANC_SUP */ if (cmd->t_task_cdb[1]) @@ -446,14 +461,9 @@ iblock_execute_unmap(struct se_cmd *cmd) goto err; } - err = blkdev_issue_discard(ib_dev->ibd_bd, lba, range, - GFP_KERNEL, 0); - if (err < 0) { - pr_err("blkdev_issue_discard() failed: %d\n", - err); - ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + ret = iblock_do_unmap(cmd, ib_dev->ibd_bd, lba, range); + if (ret) goto err; - } ptr += 16; size -= 16; @@ -469,15 +479,14 @@ err: static sense_reason_t iblock_execute_write_same_unmap(struct se_cmd *cmd) { - struct iblock_dev *ib_dev = IBLOCK_DEV(cmd->se_dev); - int rc; - - rc = blkdev_issue_discard(ib_dev->ibd_bd, cmd->t_task_lba, - sbc_get_write_same_sectors(cmd), GFP_KERNEL, 0); - if (rc < 0) { - pr_warn("blkdev_issue_discard() failed: %d\n", rc); - return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; - } + struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd; + sector_t lba = cmd->t_task_lba; + sector_t nolb = sbc_get_write_same_sectors(cmd); + int ret; + + ret = iblock_do_unmap(cmd, bdev, lba, nolb); + if (ret) + return ret; target_complete_cmd(cmd, GOOD); return 0; |