提交 62e46942 编写于 作者: C Christoph Hellwig 提交者: Nicholas Bellinger

target: simplify UNMAP handling

Move a little more processing into the core code, and lift the previous
do_unmap callback into the sbc_ops structure.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NAndy Grover <agrover@redhat.com>
Signed-off-by: NNicholas Bellinger <nab@linux-iscsi.org>
上级 7a971b1b
...@@ -475,9 +475,9 @@ fd_do_prot_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb) ...@@ -475,9 +475,9 @@ fd_do_prot_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
} }
static sense_reason_t static sense_reason_t
fd_do_unmap(struct se_cmd *cmd, void *priv, sector_t lba, sector_t nolb) fd_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
{ {
struct file *file = priv; struct file *file = FD_DEV(cmd->se_dev)->fd_file;
struct inode *inode = file->f_mapping->host; struct inode *inode = file->f_mapping->host;
int ret; int ret;
...@@ -521,9 +521,6 @@ fd_do_unmap(struct se_cmd *cmd, void *priv, sector_t lba, sector_t nolb) ...@@ -521,9 +521,6 @@ fd_do_unmap(struct se_cmd *cmd, void *priv, sector_t lba, sector_t nolb)
static sense_reason_t static sense_reason_t
fd_execute_write_same_unmap(struct se_cmd *cmd) fd_execute_write_same_unmap(struct se_cmd *cmd)
{ {
struct se_device *se_dev = cmd->se_dev;
struct fd_dev *fd_dev = FD_DEV(se_dev);
struct file *file = fd_dev->fd_file;
sector_t lba = cmd->t_task_lba; sector_t lba = cmd->t_task_lba;
sector_t nolb = sbc_get_write_same_sectors(cmd); sector_t nolb = sbc_get_write_same_sectors(cmd);
sense_reason_t ret; sense_reason_t ret;
...@@ -533,7 +530,7 @@ fd_execute_write_same_unmap(struct se_cmd *cmd) ...@@ -533,7 +530,7 @@ fd_execute_write_same_unmap(struct se_cmd *cmd)
return 0; return 0;
} }
ret = fd_do_unmap(cmd, file, lba, nolb); ret = fd_execute_unmap(cmd, lba, nolb);
if (ret) if (ret)
return ret; return ret;
...@@ -541,14 +538,6 @@ fd_execute_write_same_unmap(struct se_cmd *cmd) ...@@ -541,14 +538,6 @@ fd_execute_write_same_unmap(struct se_cmd *cmd)
return 0; return 0;
} }
static sense_reason_t
fd_execute_unmap(struct se_cmd *cmd)
{
struct file *file = FD_DEV(cmd->se_dev)->fd_file;
return sbc_execute_unmap(cmd, fd_do_unmap, file);
}
static sense_reason_t static sense_reason_t
fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
enum dma_data_direction data_direction) enum dma_data_direction data_direction)
......
...@@ -416,10 +416,9 @@ iblock_execute_sync_cache(struct se_cmd *cmd) ...@@ -416,10 +416,9 @@ iblock_execute_sync_cache(struct se_cmd *cmd)
} }
static sense_reason_t static sense_reason_t
iblock_do_unmap(struct se_cmd *cmd, void *priv, iblock_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)
sector_t lba, sector_t nolb)
{ {
struct block_device *bdev = priv; struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd;
int ret; int ret;
ret = blkdev_issue_discard(bdev, lba, nolb, GFP_KERNEL, 0); ret = blkdev_issue_discard(bdev, lba, nolb, GFP_KERNEL, 0);
...@@ -431,23 +430,14 @@ iblock_do_unmap(struct se_cmd *cmd, void *priv, ...@@ -431,23 +430,14 @@ iblock_do_unmap(struct se_cmd *cmd, void *priv,
return 0; return 0;
} }
static sense_reason_t
iblock_execute_unmap(struct se_cmd *cmd)
{
struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd;
return sbc_execute_unmap(cmd, iblock_do_unmap, bdev);
}
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 block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd;
sector_t lba = cmd->t_task_lba; sector_t lba = cmd->t_task_lba;
sector_t nolb = sbc_get_write_same_sectors(cmd); sector_t nolb = sbc_get_write_same_sectors(cmd);
sense_reason_t ret; sense_reason_t ret;
ret = iblock_do_unmap(cmd, bdev, lba, nolb); ret = iblock_execute_unmap(cmd, lba, nolb);
if (ret) if (ret)
return ret; return ret;
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
static sense_reason_t static sense_reason_t
sbc_check_prot(struct se_device *, struct se_cmd *, unsigned char *, u32, bool); sbc_check_prot(struct se_device *, struct se_cmd *, unsigned char *, u32, bool);
static sense_reason_t sbc_execute_unmap(struct se_cmd *cmd);
static sense_reason_t static sense_reason_t
sbc_emulate_readcapacity(struct se_cmd *cmd) sbc_emulate_readcapacity(struct se_cmd *cmd)
...@@ -999,7 +1000,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) ...@@ -999,7 +1000,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
return TCM_UNSUPPORTED_SCSI_OPCODE; return TCM_UNSUPPORTED_SCSI_OPCODE;
} }
size = get_unaligned_be16(&cdb[7]); size = get_unaligned_be16(&cdb[7]);
cmd->execute_cmd = ops->execute_unmap; cmd->execute_cmd = sbc_execute_unmap;
break; break;
case WRITE_SAME_16: case WRITE_SAME_16:
sectors = transport_get_sectors_16(cdb); sectors = transport_get_sectors_16(cdb);
...@@ -1087,12 +1088,10 @@ u32 sbc_get_device_type(struct se_device *dev) ...@@ -1087,12 +1088,10 @@ u32 sbc_get_device_type(struct se_device *dev)
} }
EXPORT_SYMBOL(sbc_get_device_type); EXPORT_SYMBOL(sbc_get_device_type);
sense_reason_t static sense_reason_t
sbc_execute_unmap(struct se_cmd *cmd, sbc_execute_unmap(struct se_cmd *cmd)
sense_reason_t (*do_unmap_fn)(struct se_cmd *, void *,
sector_t, sector_t),
void *priv)
{ {
struct sbc_ops *ops = cmd->protocol_data;
struct se_device *dev = cmd->se_dev; struct se_device *dev = cmd->se_dev;
unsigned char *buf, *ptr = NULL; unsigned char *buf, *ptr = NULL;
sector_t lba; sector_t lba;
...@@ -1156,7 +1155,7 @@ sbc_execute_unmap(struct se_cmd *cmd, ...@@ -1156,7 +1155,7 @@ sbc_execute_unmap(struct se_cmd *cmd,
goto err; goto err;
} }
ret = do_unmap_fn(cmd, priv, lba, range); ret = ops->execute_unmap(cmd, lba, range);
if (ret) if (ret)
goto err; goto err;
...@@ -1170,7 +1169,6 @@ sbc_execute_unmap(struct se_cmd *cmd, ...@@ -1170,7 +1169,6 @@ sbc_execute_unmap(struct se_cmd *cmd,
target_complete_cmd(cmd, GOOD); target_complete_cmd(cmd, GOOD);
return ret; return ret;
} }
EXPORT_SYMBOL(sbc_execute_unmap);
void void
sbc_dif_generate(struct se_cmd *cmd) sbc_dif_generate(struct se_cmd *cmd)
......
...@@ -50,7 +50,8 @@ struct sbc_ops { ...@@ -50,7 +50,8 @@ struct sbc_ops {
sense_reason_t (*execute_sync_cache)(struct se_cmd *cmd); sense_reason_t (*execute_sync_cache)(struct se_cmd *cmd);
sense_reason_t (*execute_write_same)(struct se_cmd *cmd); sense_reason_t (*execute_write_same)(struct se_cmd *cmd);
sense_reason_t (*execute_write_same_unmap)(struct se_cmd *cmd); sense_reason_t (*execute_write_same_unmap)(struct se_cmd *cmd);
sense_reason_t (*execute_unmap)(struct se_cmd *cmd); sense_reason_t (*execute_unmap)(struct se_cmd *cmd,
sector_t lba, sector_t nolb);
}; };
int transport_backend_register(const struct target_backend_ops *); int transport_backend_register(const struct target_backend_ops *);
...@@ -68,10 +69,6 @@ sense_reason_t sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops); ...@@ -68,10 +69,6 @@ sense_reason_t sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops);
u32 sbc_get_device_rev(struct se_device *dev); u32 sbc_get_device_rev(struct se_device *dev);
u32 sbc_get_device_type(struct se_device *dev); u32 sbc_get_device_type(struct se_device *dev);
sector_t sbc_get_write_same_sectors(struct se_cmd *cmd); sector_t sbc_get_write_same_sectors(struct se_cmd *cmd);
sense_reason_t sbc_execute_unmap(struct se_cmd *cmd,
sense_reason_t (*do_unmap_fn)(struct se_cmd *cmd, void *priv,
sector_t lba, sector_t nolb),
void *priv);
void sbc_dif_generate(struct se_cmd *); void sbc_dif_generate(struct se_cmd *);
sense_reason_t sbc_dif_verify(struct se_cmd *, sector_t, unsigned int, sense_reason_t sbc_dif_verify(struct se_cmd *, sector_t, unsigned int,
unsigned int, struct scatterlist *, int); unsigned int, struct scatterlist *, int);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册