From d3828a23ec54a5caef5a40c169e1d4b0b5398add Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 29 Aug 2017 16:42:37 -0700 Subject: [PATCH] scsi: remove LUN I/O channel ref counting spdk_bdev_get_io_channel() already handles this. Change-Id: I6b28fe10b86b00762ff15324fcd0a32aae94e012 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/376267 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu --- lib/scsi/lun.c | 17 ++++------------- lib/scsi/scsi_internal.h | 8 -------- test/unit/lib/scsi/lun.c/lun_ut.c | 5 +++++ 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index c7d3c8b22..c263aae8d 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -373,12 +373,8 @@ spdk_scsi_lun_delete(const char *lun_name) int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) { if (lun->io_channel != NULL) { - if (pthread_self() == lun->thread_id) { - lun->ref++; - return 0; - } - SPDK_ERRLOG("io_channel already allocated for lun %s\n", lun->name); - return -1; + assert(spdk_io_channel_get_thread(lun->io_channel) == spdk_get_thread()); + return 0; } lun->lcore = spdk_env_get_current_core(); @@ -387,19 +383,14 @@ int spdk_scsi_lun_allocate_io_channel(struct spdk_scsi_lun *lun) if (lun->io_channel == NULL) { return -1; } - lun->thread_id = pthread_self(); - lun->ref = 1; return 0; } void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun *lun) { if (lun->io_channel != NULL) { - lun->ref--; - if (lun->ref == 0) { - spdk_put_io_channel(lun->io_channel); - lun->io_channel = NULL; - } + spdk_put_io_channel(lun->io_channel); + lun->io_channel = NULL; } } diff --git a/lib/scsi/scsi_internal.h b/lib/scsi/scsi_internal.h index 2da98dac3..49bd1af4a 100644 --- a/lib/scsi/scsi_internal.h +++ b/lib/scsi/scsi_internal.h @@ -87,14 +87,6 @@ struct spdk_scsi_lun { /** I/O channel for the bdev associated with this LUN. */ struct spdk_io_channel *io_channel; - /** Thread ID for the thread that allocated the I/O channel for this - * LUN. All I/O to this LUN must be performed from this thread. - */ - pthread_t thread_id; - - /** The reference number for this LUN, thus we can correctly free the io_channel */ - uint32_t ref; - /** Name for this LUN. */ char name[SPDK_SCSI_LUN_MAX_NAME_LENGTH]; diff --git a/test/unit/lib/scsi/lun.c/lun_ut.c b/test/unit/lib/scsi/lun.c/lun_ut.c index 653f62459..bd6ccb45d 100644 --- a/test/unit/lib/scsi/lun.c/lun_ut.c +++ b/test/unit/lib/scsi/lun.c/lun_ut.c @@ -39,6 +39,8 @@ #include "lun.c" #include "lun_db.c" +#include "spdk_internal/mock.h" + /* Unit test bdev mockup */ struct spdk_bdev { int x; @@ -194,6 +196,9 @@ spdk_put_io_channel(struct spdk_io_channel *ch) { } +DEFINE_STUB(spdk_io_channel_get_thread, struct spdk_thread *, (struct spdk_io_channel *ch), NULL) +DEFINE_STUB(spdk_get_thread, struct spdk_thread *, (void), NULL) + static _spdk_scsi_lun * lun_construct(void) {