From 816c34cbce2622cdfb1a3d1fde67682108f313fd Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Wed, 20 Jun 2018 16:38:35 -0700 Subject: [PATCH] bdev: move error union to internal spdk_bdev_io struct Change-Id: Iab755bb1473c404693f84f97c07bbb5c5fefbb49 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/416266 Tested-by: SPDK Automated Test System Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Daniel Verkamp --- include/spdk/bdev_module.h | 44 +++++++++---------- lib/bdev/bdev.c | 24 +++++----- lib/bdev/scsi_nvme.c | 4 +- test/unit/lib/bdev/scsi_nvme.c/scsi_nvme_ut.c | 22 +++++----- test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c | 16 +++---- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/include/spdk/bdev_module.h b/include/spdk/bdev_module.h index e8d686748e..0b34d62f58 100644 --- a/include/spdk/bdev_module.h +++ b/include/spdk/bdev_module.h @@ -299,28 +299,6 @@ struct spdk_bdev_io { /** The block device that this I/O belongs to. */ struct spdk_bdev *bdev; - /** Error information from a device */ - union { - /** Only valid when status is SPDK_BDEV_IO_STATUS_NVME_ERROR */ - struct { - /** NVMe status code type */ - uint8_t sct; - /** NVMe status code */ - uint8_t sc; - } nvme; - /** Only valid when status is SPDK_BDEV_IO_STATUS_SCSI_ERROR */ - struct { - /** SCSI status code */ - uint8_t sc; - /** SCSI sense key */ - uint8_t sk; - /** SCSI additional sense code */ - uint8_t asc; - /** SCSI additional sense code qualifier */ - uint8_t ascq; - } scsi; - } error; - /** Enumerated value representing the I/O type. */ uint8_t type; @@ -379,6 +357,28 @@ struct spdk_bdev_io { * must not read or write to these fields. */ struct __bdev_io_internal_fields { + /** Error information from a device */ + union { + /** Only valid when status is SPDK_BDEV_IO_STATUS_NVME_ERROR */ + struct { + /** NVMe status code type */ + uint8_t sct; + /** NVMe status code */ + uint8_t sc; + } nvme; + /** Only valid when status is SPDK_BDEV_IO_STATUS_SCSI_ERROR */ + struct { + /** SCSI status code */ + uint8_t sc; + /** SCSI sense key */ + uint8_t sk; + /** SCSI additional sense code */ + uint8_t asc; + /** SCSI additional sense code qualifier */ + uint8_t ascq; + } scsi; + } error; + /** The bdev I/O channel that this was handled on. */ struct spdk_bdev_channel *ch; diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 6fd976143e..e3cdc33499 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -2492,10 +2492,10 @@ spdk_bdev_io_complete_scsi_status(struct spdk_bdev_io *bdev_io, enum spdk_scsi_s bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS; } else { bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SCSI_ERROR; - bdev_io->error.scsi.sc = sc; - bdev_io->error.scsi.sk = sk; - bdev_io->error.scsi.asc = asc; - bdev_io->error.scsi.ascq = ascq; + bdev_io->internal.error.scsi.sc = sc; + bdev_io->internal.error.scsi.sk = sk; + bdev_io->internal.error.scsi.asc = asc; + bdev_io->internal.error.scsi.ascq = ascq; } spdk_bdev_io_complete(bdev_io, bdev_io->internal.status); @@ -2521,10 +2521,10 @@ spdk_bdev_io_get_scsi_status(const struct spdk_bdev_io *bdev_io, spdk_scsi_nvme_translate(bdev_io, sc, sk, asc, ascq); break; case SPDK_BDEV_IO_STATUS_SCSI_ERROR: - *sc = bdev_io->error.scsi.sc; - *sk = bdev_io->error.scsi.sk; - *asc = bdev_io->error.scsi.asc; - *ascq = bdev_io->error.scsi.ascq; + *sc = bdev_io->internal.error.scsi.sc; + *sk = bdev_io->internal.error.scsi.sk; + *asc = bdev_io->internal.error.scsi.asc; + *ascq = bdev_io->internal.error.scsi.ascq; break; default: *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; @@ -2541,8 +2541,8 @@ spdk_bdev_io_complete_nvme_status(struct spdk_bdev_io *bdev_io, int sct, int sc) if (sct == SPDK_NVME_SCT_GENERIC && sc == SPDK_NVME_SC_SUCCESS) { bdev_io->internal.status = SPDK_BDEV_IO_STATUS_SUCCESS; } else { - bdev_io->error.nvme.sct = sct; - bdev_io->error.nvme.sc = sc; + bdev_io->internal.error.nvme.sct = sct; + bdev_io->internal.error.nvme.sc = sc; bdev_io->internal.status = SPDK_BDEV_IO_STATUS_NVME_ERROR; } @@ -2556,8 +2556,8 @@ spdk_bdev_io_get_nvme_status(const struct spdk_bdev_io *bdev_io, int *sct, int * assert(sc != NULL); if (bdev_io->internal.status == SPDK_BDEV_IO_STATUS_NVME_ERROR) { - *sct = bdev_io->error.nvme.sct; - *sc = bdev_io->error.nvme.sc; + *sct = bdev_io->internal.error.nvme.sct; + *sc = bdev_io->internal.error.nvme.sc; } else if (bdev_io->internal.status == SPDK_BDEV_IO_STATUS_SUCCESS) { *sct = SPDK_NVME_SCT_GENERIC; *sc = SPDK_NVME_SC_SUCCESS; diff --git a/lib/bdev/scsi_nvme.c b/lib/bdev/scsi_nvme.c index 7f2b8cdebf..385b9036fe 100644 --- a/lib/bdev/scsi_nvme.c +++ b/lib/bdev/scsi_nvme.c @@ -38,8 +38,8 @@ void spdk_scsi_nvme_translate(const struct spdk_bdev_io *bdev_io, int *sc, int *sk, int *asc, int *ascq) { - int nvme_sct = bdev_io->error.nvme.sct; - int nvme_sc = bdev_io->error.nvme.sc; + int nvme_sct = bdev_io->internal.error.nvme.sct; + int nvme_sc = bdev_io->internal.error.nvme.sc; switch (nvme_sct) { case SPDK_NVME_SCT_GENERIC: diff --git a/test/unit/lib/bdev/scsi_nvme.c/scsi_nvme_ut.c b/test/unit/lib/bdev/scsi_nvme.c/scsi_nvme_ut.c index 59f30d45cd..9b2eff358d 100644 --- a/test/unit/lib/bdev/scsi_nvme.c/scsi_nvme_ut.c +++ b/test/unit/lib/bdev/scsi_nvme.c/scsi_nvme_ut.c @@ -53,15 +53,15 @@ scsi_nvme_translate_test(void) int sc, sk, asc, ascq; /* SPDK_NVME_SCT_GENERIC */ - bdev_io.error.nvme.sct = SPDK_NVME_SCT_GENERIC; - bdev_io.error.nvme.sc = SPDK_NVME_SC_ABORTED_POWER_LOSS; + bdev_io.internal.error.nvme.sct = SPDK_NVME_SCT_GENERIC; + bdev_io.internal.error.nvme.sc = SPDK_NVME_SC_ABORTED_POWER_LOSS; spdk_scsi_nvme_translate(&bdev_io, &sc, &sk, &asc, &ascq); CU_ASSERT_EQUAL(sc, SPDK_SCSI_STATUS_TASK_ABORTED); CU_ASSERT_EQUAL(sk, SPDK_SCSI_SENSE_ABORTED_COMMAND); CU_ASSERT_EQUAL(asc, SPDK_SCSI_ASC_WARNING); CU_ASSERT_EQUAL(ascq, SPDK_SCSI_ASCQ_POWER_LOSS_EXPECTED); - bdev_io.error.nvme.sc = SPDK_NVME_SC_INVALID_NUM_SGL_DESCIRPTORS; + bdev_io.internal.error.nvme.sc = SPDK_NVME_SC_INVALID_NUM_SGL_DESCIRPTORS; spdk_scsi_nvme_translate(&bdev_io, &sc, &sk, &asc, &ascq); CU_ASSERT_EQUAL(sc, SPDK_SCSI_STATUS_CHECK_CONDITION); CU_ASSERT_EQUAL(sk, SPDK_SCSI_SENSE_ILLEGAL_REQUEST); @@ -69,15 +69,15 @@ scsi_nvme_translate_test(void) CU_ASSERT_EQUAL(ascq, SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE); /* SPDK_NVME_SCT_COMMAND_SPECIFIC */ - bdev_io.error.nvme.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC; - bdev_io.error.nvme.sc = SPDK_NVME_SC_INVALID_FORMAT; + bdev_io.internal.error.nvme.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC; + bdev_io.internal.error.nvme.sc = SPDK_NVME_SC_INVALID_FORMAT; spdk_scsi_nvme_translate(&bdev_io, &sc, &sk, &asc, &ascq); CU_ASSERT_EQUAL(sc, SPDK_SCSI_STATUS_CHECK_CONDITION); CU_ASSERT_EQUAL(sk, SPDK_SCSI_SENSE_ILLEGAL_REQUEST); CU_ASSERT_EQUAL(asc, SPDK_SCSI_ASC_FORMAT_COMMAND_FAILED); CU_ASSERT_EQUAL(ascq, SPDK_SCSI_ASCQ_FORMAT_COMMAND_FAILED); - bdev_io.error.nvme.sc = SPDK_NVME_SC_OVERLAPPING_RANGE; + bdev_io.internal.error.nvme.sc = SPDK_NVME_SC_OVERLAPPING_RANGE; spdk_scsi_nvme_translate(&bdev_io, &sc, &sk, &asc, &ascq); CU_ASSERT_EQUAL(sc, SPDK_SCSI_STATUS_CHECK_CONDITION); CU_ASSERT_EQUAL(sk, SPDK_SCSI_SENSE_ILLEGAL_REQUEST); @@ -85,15 +85,15 @@ scsi_nvme_translate_test(void) CU_ASSERT_EQUAL(ascq, SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE); /* SPDK_NVME_SCT_MEDIA_ERROR */ - bdev_io.error.nvme.sct = SPDK_NVME_SCT_MEDIA_ERROR; - bdev_io.error.nvme.sc = SPDK_NVME_SC_GUARD_CHECK_ERROR; + bdev_io.internal.error.nvme.sct = SPDK_NVME_SCT_MEDIA_ERROR; + bdev_io.internal.error.nvme.sc = SPDK_NVME_SC_GUARD_CHECK_ERROR; spdk_scsi_nvme_translate(&bdev_io, &sc, &sk, &asc, &ascq); CU_ASSERT_EQUAL(sc, SPDK_SCSI_STATUS_CHECK_CONDITION); CU_ASSERT_EQUAL(sk, SPDK_SCSI_SENSE_MEDIUM_ERROR); CU_ASSERT_EQUAL(asc, SPDK_SCSI_ASC_LOGICAL_BLOCK_GUARD_CHECK_FAILED); CU_ASSERT_EQUAL(ascq, SPDK_SCSI_ASCQ_LOGICAL_BLOCK_GUARD_CHECK_FAILED); - bdev_io.error.nvme.sc = SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK; + bdev_io.internal.error.nvme.sc = SPDK_NVME_SC_DEALLOCATED_OR_UNWRITTEN_BLOCK; spdk_scsi_nvme_translate(&bdev_io, &sc, &sk, &asc, &ascq); CU_ASSERT_EQUAL(sc, SPDK_SCSI_STATUS_CHECK_CONDITION); CU_ASSERT_EQUAL(sk, SPDK_SCSI_SENSE_ILLEGAL_REQUEST); @@ -101,8 +101,8 @@ scsi_nvme_translate_test(void) CU_ASSERT_EQUAL(ascq, SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE); /* SPDK_NVME_SCT_VENDOR_SPECIFIC */ - bdev_io.error.nvme.sct = SPDK_NVME_SCT_VENDOR_SPECIFIC; - bdev_io.error.nvme.sc = 0xff; + bdev_io.internal.error.nvme.sct = SPDK_NVME_SCT_VENDOR_SPECIFIC; + bdev_io.internal.error.nvme.sc = 0xff; spdk_scsi_nvme_translate(&bdev_io, &sc, &sk, &asc, &ascq); CU_ASSERT_EQUAL(sc, SPDK_SCSI_STATUS_CHECK_CONDITION); CU_ASSERT_EQUAL(sk, SPDK_SCSI_SENSE_ILLEGAL_REQUEST); 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 65272d35ea..7582db3717 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 @@ -158,10 +158,10 @@ spdk_bdev_io_get_scsi_status(const struct spdk_bdev_io *bdev_io, *ascq = SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE; break; case SPDK_BDEV_IO_STATUS_SCSI_ERROR: - *sc = bdev_io->error.scsi.sc; - *sk = bdev_io->error.scsi.sk; - *asc = bdev_io->error.scsi.asc; - *ascq = bdev_io->error.scsi.ascq; + *sc = bdev_io->internal.error.scsi.sc; + *sk = bdev_io->internal.error.scsi.sk; + *asc = bdev_io->internal.error.scsi.asc; + *ascq = bdev_io->internal.error.scsi.ascq; break; default: *sc = SPDK_SCSI_STATUS_CHECK_CONDITION; @@ -596,10 +596,10 @@ task_complete_test(void) CU_ASSERT_EQUAL(task.status, SPDK_SCSI_STATUS_GOOD); bdev_io.internal.status = SPDK_BDEV_IO_STATUS_SCSI_ERROR; - bdev_io.error.scsi.sc = SPDK_SCSI_STATUS_CHECK_CONDITION; - bdev_io.error.scsi.sk = SPDK_SCSI_SENSE_HARDWARE_ERROR; - bdev_io.error.scsi.asc = SPDK_SCSI_ASC_WARNING; - bdev_io.error.scsi.ascq = SPDK_SCSI_ASCQ_POWER_LOSS_EXPECTED; + bdev_io.internal.error.scsi.sc = SPDK_SCSI_STATUS_CHECK_CONDITION; + bdev_io.internal.error.scsi.sk = SPDK_SCSI_SENSE_HARDWARE_ERROR; + bdev_io.internal.error.scsi.asc = SPDK_SCSI_ASC_WARNING; + bdev_io.internal.error.scsi.ascq = SPDK_SCSI_ASCQ_POWER_LOSS_EXPECTED; spdk_bdev_scsi_task_complete_cmd(&bdev_io, bdev_io.internal.status, &task); CU_ASSERT_EQUAL(task.status, SPDK_SCSI_STATUS_CHECK_CONDITION); CU_ASSERT_EQUAL(task.sense_data[2] & 0xf, SPDK_SCSI_SENSE_HARDWARE_ERROR);