From 8f33ac020dfd582154016e38bfb78a298be06def Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 3 Sep 2019 16:06:46 +0900 Subject: [PATCH] scsi: Fix seg.fault due to the gap between IO channel put and LUN removal The reported github issue #938 has been reported intermettently. The issue is that the bdev descriptor passed to spdk_bdev_reset() is not valid and causes seg. fault. Current implementation of LUN hot plug is that putting IO channel and removing LUN are done by different poller. Hence if any task management command is issued between the gap, the reported issue is likely to occur. The flag removing is set at the start of LUN hot plug and so spdk_scsi_dev_get_lun() can return NULL even before completing removal by referring the flag removing. Fixes #938. Signed-off-by: Shuhei Matsumoto Change-Id: I1a51d90cc700134e8c0ec399a3ce62620c84ef73 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/467212 Reviewed-by: Changpeng Liu Reviewed-by: Broadcom SPDK FC-NVMe CI Reviewed-by: Ben Walker Reviewed-by: Paul Luse Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/scsi/dev.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/scsi/dev.c b/lib/scsi/dev.c index e567b4033..6171c849e 100644 --- a/lib/scsi/dev.c +++ b/lib/scsi/dev.c @@ -411,11 +411,19 @@ spdk_scsi_dev_get_id(const struct spdk_scsi_dev *dev) struct spdk_scsi_lun * spdk_scsi_dev_get_lun(struct spdk_scsi_dev *dev, int lun_id) { + struct spdk_scsi_lun *lun; + if (lun_id < 0 || lun_id >= SPDK_SCSI_DEV_MAX_LUN) { return NULL; } - return dev->lun[lun_id]; + lun = dev->lun[lun_id]; + + if (lun != NULL && !spdk_scsi_lun_is_removing(lun)) { + return lun; + } else { + return NULL; + } } bool