From 37bdd0e87fce534e65ddb751dff557b40f1ca411 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 7 Jun 2019 10:01:27 +0900 Subject: [PATCH] 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 Change-Id: I54bf1168ec5959432aa15dae0360c0640138b033 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/457541 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker --- include/spdk/scsi.h | 6 +++--- lib/iscsi/iscsi.c | 10 ++++----- lib/scsi/lun.c | 4 ++-- lib/scsi/scsi_bdev.c | 8 +++---- lib/scsi/scsi_internal.h | 2 +- test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c | 21 ++++++++++--------- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/include/spdk/scsi.h b/include/spdk/scsi.h index e9b5d4ff7..e3f9a0d20 100644 --- a/include/spdk/scsi.h +++ b/include/spdk/scsi.h @@ -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 diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index f1421d543..5a0e8a174 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -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) diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index cb3c2d2c7..c84fdb63b 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -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); } diff --git a/lib/scsi/scsi_bdev.c b/lib/scsi/scsi_bdev.c index 535a759e4..7e72fac6e 100644 --- a/lib/scsi/scsi_bdev.c +++ b/lib/scsi/scsi_bdev.c @@ -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; } diff --git a/lib/scsi/scsi_internal.h b/lib/scsi/scsi_internal.h index 7ad1caa31..8ad47f62e 100644 --- a/lib/scsi/scsi_internal.h +++ b/lib/scsi/scsi_internal.h @@ -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); diff --git a/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c b/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c index 347905470..9d9206ff9 100644 --- a/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c +++ b/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c @@ -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