scsi: Add data offset to DIF context separately from start block address

This patch uses the change by the last patch to initialize DIF
context in SCSI layer. Besides this patch changes the name of a
parameter from offset to data_offset to clarify the meaning.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I54bf1168ec5959432aa15dae0360c0640138b033
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457541
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-06-07 10:01:27 +09:00 committed by Ben Walker
parent 73204fe2e5
commit 37bdd0e87f
6 changed files with 25 additions and 26 deletions

View File

@ -527,13 +527,13 @@ void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun_desc *desc);
*
* \param lun Logical unit.
* \param cdb SCSI CDB.
* \param offset Byte offset in the payload.
* \param data_offset Byte offset in the payload.
* \param dif_ctx Output parameter which will contain initialized DIF context.
*
* \return true on success or false otherwise.
*/
bool spdk_scsi_lun_get_dif_ctx(struct spdk_scsi_lun *lun, uint8_t *cdb, uint32_t offset,
struct spdk_dif_ctx *dif_ctx);
bool spdk_scsi_lun_get_dif_ctx(struct spdk_scsi_lun *lun, uint8_t *cdb,
uint32_t data_offset, struct spdk_dif_ctx *dif_ctx);
/**
* Set iSCSI Initiator port TransportID

View File

@ -4620,7 +4620,7 @@ spdk_iscsi_get_dif_ctx(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
struct spdk_dif_ctx *dif_ctx)
{
struct iscsi_bhs *bhs;
uint32_t offset = 0;
uint32_t data_offset = 0;
uint8_t *cdb = NULL;
uint64_t lun;
int lun_id = 0;
@ -4647,7 +4647,7 @@ spdk_iscsi_get_dif_ctx(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
struct iscsi_bhs_scsi_req *sbhs;
sbhs = (struct iscsi_bhs_scsi_req *)bhs;
offset = 0;
data_offset = 0;
cdb = sbhs->cdb;
lun = from_be64(&sbhs->lun);
lun_id = spdk_scsi_lun_id_fmt_to_int(lun);
@ -4659,7 +4659,7 @@ spdk_iscsi_get_dif_ctx(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
int transfer_tag;
dbhs = (struct iscsi_bhs_data_out *)bhs;
offset = from_be32(&dbhs->buffer_offset);
data_offset = from_be32(&dbhs->buffer_offset);
transfer_tag = from_be32(&dbhs->ttt);
task = get_transfer_task(conn, transfer_tag);
if (task == NULL) {
@ -4674,7 +4674,7 @@ spdk_iscsi_get_dif_ctx(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
struct spdk_iscsi_task *task;
dbhs = (struct iscsi_bhs_data_in *)bhs;
offset = from_be32(&dbhs->buffer_offset);
data_offset = from_be32(&dbhs->buffer_offset);
task = pdu->task;
assert(task != NULL);
cdb = task->scsi.cdb;
@ -4690,7 +4690,7 @@ spdk_iscsi_get_dif_ctx(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu,
return false;
}
return spdk_scsi_lun_get_dif_ctx(lun_dev, cdb, offset, dif_ctx);
return spdk_scsi_lun_get_dif_ctx(lun_dev, cdb, data_offset, dif_ctx);
}
void spdk_free_sess(struct spdk_iscsi_sess *sess)

View File

@ -511,7 +511,7 @@ spdk_scsi_lun_is_removing(const struct spdk_scsi_lun *lun)
bool
spdk_scsi_lun_get_dif_ctx(struct spdk_scsi_lun *lun, uint8_t *cdb,
uint32_t offset, struct spdk_dif_ctx *dif_ctx)
uint32_t data_offset, struct spdk_dif_ctx *dif_ctx)
{
return spdk_scsi_bdev_get_dif_ctx(lun->bdev, cdb, offset, dif_ctx);
return spdk_scsi_bdev_get_dif_ctx(lun->bdev, cdb, data_offset, dif_ctx);
}

View File

@ -2115,8 +2115,8 @@ spdk_bdev_scsi_reset(struct spdk_scsi_task *task)
}
bool
spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb, uint32_t offset,
struct spdk_dif_ctx *dif_ctx)
spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb,
uint32_t data_offset, struct spdk_dif_ctx *dif_ctx)
{
uint32_t ref_tag = 0, dif_check_flags = 0;
int rc;
@ -2147,8 +2147,6 @@ spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb, uint32_t offset
return false;
}
ref_tag += offset / spdk_bdev_get_data_block_size(bdev);
if (spdk_bdev_is_dif_check_enabled(bdev, SPDK_DIF_CHECK_TYPE_REFTAG)) {
dif_check_flags |= SPDK_DIF_FLAGS_REFTAG_CHECK;
}
@ -2164,7 +2162,7 @@ spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb, uint32_t offset
spdk_bdev_is_dif_head_of_md(bdev),
spdk_bdev_get_dif_type(bdev),
dif_check_flags,
ref_tag, 0, 0, 0, 0);
ref_tag, 0, 0, data_offset, 0);
return (rc == 0) ? true : false;
}

View File

@ -198,7 +198,7 @@ void spdk_scsi_port_destruct(struct spdk_scsi_port *port);
int spdk_bdev_scsi_execute(struct spdk_scsi_task *task);
void spdk_bdev_scsi_reset(struct spdk_scsi_task *task);
bool spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb, uint32_t offset,
bool spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb, uint32_t data_offset,
struct spdk_dif_ctx *dif_ctx);
int spdk_scsi_pr_out(struct spdk_scsi_task *task, uint8_t *cdb, uint8_t *data, uint16_t data_len);

View File

@ -275,6 +275,7 @@ spdk_dif_ctx_init(struct spdk_dif_ctx *ctx, uint32_t block_size, uint32_t md_siz
uint32_t data_offset, uint16_t guard_seed)
{
ctx->init_ref_tag = init_ref_tag;
ctx->ref_tag_offset = data_offset / 512;
return 0;
}
@ -968,34 +969,34 @@ get_dif_ctx_test(void)
struct spdk_bdev bdev = {};
struct spdk_dif_ctx dif_ctx = {};
uint8_t cdb[16];
uint32_t offset;
uint32_t data_offset;
bool ret;
cdb[0] = SPDK_SBC_READ_6;
cdb[1] = 0x12;
cdb[2] = 0x34;
cdb[3] = 0x50;
offset = 0x6 * 512;
data_offset = 0x6 * 512;
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, offset, &dif_ctx);
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, data_offset, &dif_ctx);
CU_ASSERT(ret == true);
CU_ASSERT(dif_ctx.init_ref_tag == 0x123456);
CU_ASSERT(dif_ctx.init_ref_tag + dif_ctx.ref_tag_offset == 0x123456);
cdb[0] = SPDK_SBC_WRITE_12;
to_be32(&cdb[2], 0x12345670);
offset = 0x8 * 512;
data_offset = 0x8 * 512;
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, offset, &dif_ctx);
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, data_offset, &dif_ctx);
CU_ASSERT(ret == true);
CU_ASSERT(dif_ctx.init_ref_tag == 0x12345678);
CU_ASSERT(dif_ctx.init_ref_tag + dif_ctx.ref_tag_offset == 0x12345678);
cdb[0] = SPDK_SBC_WRITE_16;
to_be64(&cdb[2], 0x0000000012345670);
offset = 0x8 * 512;
data_offset = 0x8 * 512;
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, offset, &dif_ctx);
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, data_offset, &dif_ctx);
CU_ASSERT(ret == true);
CU_ASSERT(dif_ctx.init_ref_tag == 0x12345678);
CU_ASSERT(dif_ctx.init_ref_tag + dif_ctx.ref_tag_offset == 0x12345678);
}
int