target: move write_same to struct spc_ops
Add spc_ops->execute_write_same() caller for ->execute_cmd() setup, and update IBLOCK backends to use it. (nab: add export of spc_get_write_same_sectors symbol) (roland: Carry forward: Fix range calculation in WRITE SAME emulation when num blocks == 0) Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
This commit is contained in:
committed by
Nicholas Bellinger
parent
ad67f0d9e6
commit
6f974e8ce7
@@ -327,6 +327,23 @@ static int iblock_do_discard(struct se_device *dev, sector_t lba, u32 range)
|
|||||||
return blkdev_issue_discard(bd, lba, range, GFP_KERNEL, barrier);
|
return blkdev_issue_discard(bd, lba, range, GFP_KERNEL, barrier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int iblock_execute_write_same(struct se_cmd *cmd)
|
||||||
|
{
|
||||||
|
struct iblock_dev *ibd = cmd->se_dev->dev_ptr;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = blkdev_issue_discard(ibd->ibd_bd, cmd->t_task_lba,
|
||||||
|
spc_get_write_same_sectors(cmd), GFP_KERNEL,
|
||||||
|
0);
|
||||||
|
if (ret < 0) {
|
||||||
|
pr_debug("blkdev_issue_discard() failed for WRITE_SAME\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
target_complete_cmd(cmd, GOOD);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
Opt_udev_path, Opt_readonly, Opt_force, Opt_err
|
Opt_udev_path, Opt_readonly, Opt_force, Opt_err
|
||||||
};
|
};
|
||||||
@@ -669,6 +686,7 @@ static void iblock_bio_done(struct bio *bio, int err)
|
|||||||
static struct spc_ops iblock_spc_ops = {
|
static struct spc_ops iblock_spc_ops = {
|
||||||
.execute_rw = iblock_execute_rw,
|
.execute_rw = iblock_execute_rw,
|
||||||
.execute_sync_cache = iblock_execute_sync_cache,
|
.execute_sync_cache = iblock_execute_sync_cache,
|
||||||
|
.execute_write_same = iblock_execute_write_same,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int iblock_parse_cdb(struct se_cmd *cmd)
|
static int iblock_parse_cdb(struct se_cmd *cmd)
|
||||||
|
@@ -156,24 +156,9 @@ err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int spc_get_write_same_sectors(struct se_cmd *cmd)
|
||||||
* Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support.
|
|
||||||
* Note this is not used for TCM/pSCSI passthrough
|
|
||||||
*/
|
|
||||||
static int sbc_emulate_write_same(struct se_cmd *cmd)
|
|
||||||
{
|
{
|
||||||
struct se_device *dev = cmd->se_dev;
|
|
||||||
sector_t range;
|
|
||||||
sector_t lba = cmd->t_task_lba;
|
|
||||||
u32 num_blocks;
|
u32 num_blocks;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (!dev->transport->do_discard) {
|
|
||||||
pr_err("WRITE_SAME emulation not supported"
|
|
||||||
" for: %s\n", dev->transport->name);
|
|
||||||
cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
|
|
||||||
return -ENOSYS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd->t_task_cdb[0] == WRITE_SAME)
|
if (cmd->t_task_cdb[0] == WRITE_SAME)
|
||||||
num_blocks = get_unaligned_be16(&cmd->t_task_cdb[7]);
|
num_blocks = get_unaligned_be16(&cmd->t_task_cdb[7]);
|
||||||
@@ -186,23 +171,13 @@ static int sbc_emulate_write_same(struct se_cmd *cmd)
|
|||||||
* Use the explicit range when non zero is supplied, otherwise calculate
|
* Use the explicit range when non zero is supplied, otherwise calculate
|
||||||
* the remaining range based on ->get_blocks() - starting LBA.
|
* the remaining range based on ->get_blocks() - starting LBA.
|
||||||
*/
|
*/
|
||||||
if (num_blocks != 0)
|
if (num_blocks)
|
||||||
range = num_blocks;
|
return num_blocks;
|
||||||
else
|
|
||||||
range = (dev->transport->get_blocks(dev) - lba) + 1;
|
|
||||||
|
|
||||||
pr_debug("WRITE_SAME UNMAP: LBA: %llu Range: %llu\n",
|
return cmd->se_dev->transport->get_blocks(cmd->se_dev) -
|
||||||
(unsigned long long)lba, (unsigned long long)range);
|
cmd->t_task_lba + 1;
|
||||||
|
|
||||||
ret = dev->transport->do_discard(dev, lba, range);
|
|
||||||
if (ret < 0) {
|
|
||||||
pr_debug("blkdev_issue_discard() failed for WRITE_SAME\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
target_complete_cmd(cmd, GOOD);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(spc_get_write_same_sectors);
|
||||||
|
|
||||||
static int sbc_emulate_verify(struct se_cmd *cmd)
|
static int sbc_emulate_verify(struct se_cmd *cmd)
|
||||||
{
|
{
|
||||||
@@ -488,6 +463,9 @@ int sbc_parse_cdb(struct se_cmd *cmd, struct spc_ops *ops)
|
|||||||
cmd->se_cmd_flags |= SCF_FUA;
|
cmd->se_cmd_flags |= SCF_FUA;
|
||||||
break;
|
break;
|
||||||
case WRITE_SAME_32:
|
case WRITE_SAME_32:
|
||||||
|
if (!ops->execute_write_same)
|
||||||
|
goto out_unsupported_cdb;
|
||||||
|
|
||||||
sectors = transport_get_sectors_32(cdb);
|
sectors = transport_get_sectors_32(cdb);
|
||||||
if (!sectors) {
|
if (!sectors) {
|
||||||
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not"
|
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not"
|
||||||
@@ -500,7 +478,7 @@ int sbc_parse_cdb(struct se_cmd *cmd, struct spc_ops *ops)
|
|||||||
|
|
||||||
if (sbc_write_same_supported(dev, &cdb[10]) < 0)
|
if (sbc_write_same_supported(dev, &cdb[10]) < 0)
|
||||||
goto out_unsupported_cdb;
|
goto out_unsupported_cdb;
|
||||||
cmd->execute_cmd = sbc_emulate_write_same;
|
cmd->execute_cmd = ops->execute_write_same;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
pr_err("VARIABLE_LENGTH_CMD service action"
|
pr_err("VARIABLE_LENGTH_CMD service action"
|
||||||
@@ -559,6 +537,9 @@ int sbc_parse_cdb(struct se_cmd *cmd, struct spc_ops *ops)
|
|||||||
cmd->execute_cmd = sbc_emulate_unmap;
|
cmd->execute_cmd = sbc_emulate_unmap;
|
||||||
break;
|
break;
|
||||||
case WRITE_SAME_16:
|
case WRITE_SAME_16:
|
||||||
|
if (!ops->execute_write_same)
|
||||||
|
goto out_unsupported_cdb;
|
||||||
|
|
||||||
sectors = transport_get_sectors_16(cdb);
|
sectors = transport_get_sectors_16(cdb);
|
||||||
if (!sectors) {
|
if (!sectors) {
|
||||||
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
|
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
|
||||||
@@ -570,9 +551,12 @@ int sbc_parse_cdb(struct se_cmd *cmd, struct spc_ops *ops)
|
|||||||
|
|
||||||
if (sbc_write_same_supported(dev, &cdb[1]) < 0)
|
if (sbc_write_same_supported(dev, &cdb[1]) < 0)
|
||||||
goto out_unsupported_cdb;
|
goto out_unsupported_cdb;
|
||||||
cmd->execute_cmd = sbc_emulate_write_same;
|
cmd->execute_cmd = ops->execute_write_same;
|
||||||
break;
|
break;
|
||||||
case WRITE_SAME:
|
case WRITE_SAME:
|
||||||
|
if (!ops->execute_write_same)
|
||||||
|
goto out_unsupported_cdb;
|
||||||
|
|
||||||
sectors = transport_get_sectors_10(cdb);
|
sectors = transport_get_sectors_10(cdb);
|
||||||
if (!sectors) {
|
if (!sectors) {
|
||||||
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
|
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
|
||||||
@@ -588,7 +572,7 @@ int sbc_parse_cdb(struct se_cmd *cmd, struct spc_ops *ops)
|
|||||||
*/
|
*/
|
||||||
if (sbc_write_same_supported(dev, &cdb[1]) < 0)
|
if (sbc_write_same_supported(dev, &cdb[1]) < 0)
|
||||||
goto out_unsupported_cdb;
|
goto out_unsupported_cdb;
|
||||||
cmd->execute_cmd = sbc_emulate_write_same;
|
cmd->execute_cmd = ops->execute_write_same;
|
||||||
break;
|
break;
|
||||||
case VERIFY:
|
case VERIFY:
|
||||||
size = 0;
|
size = 0;
|
||||||
|
@@ -42,6 +42,7 @@ struct se_subsystem_api {
|
|||||||
struct spc_ops {
|
struct spc_ops {
|
||||||
int (*execute_rw)(struct se_cmd *cmd);
|
int (*execute_rw)(struct se_cmd *cmd);
|
||||||
int (*execute_sync_cache)(struct se_cmd *cmd);
|
int (*execute_sync_cache)(struct se_cmd *cmd);
|
||||||
|
int (*execute_write_same)(struct se_cmd *cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
int transport_subsystem_register(struct se_subsystem_api *);
|
int transport_subsystem_register(struct se_subsystem_api *);
|
||||||
@@ -55,6 +56,7 @@ void target_complete_cmd(struct se_cmd *, u8);
|
|||||||
|
|
||||||
int sbc_parse_cdb(struct se_cmd *cmd, struct spc_ops *ops);
|
int sbc_parse_cdb(struct se_cmd *cmd, struct spc_ops *ops);
|
||||||
int spc_parse_cdb(struct se_cmd *cmd, unsigned int *size);
|
int spc_parse_cdb(struct se_cmd *cmd, unsigned int *size);
|
||||||
|
int spc_get_write_same_sectors(struct se_cmd *cmd);
|
||||||
|
|
||||||
void transport_set_vpd_proto_id(struct t10_vpd *, unsigned char *);
|
void transport_set_vpd_proto_id(struct t10_vpd *, unsigned char *);
|
||||||
int transport_set_vpd_assoc(struct t10_vpd *, unsigned char *);
|
int transport_set_vpd_assoc(struct t10_vpd *, unsigned char *);
|
||||||
|
Reference in New Issue
Block a user