From 4582e9fb4a8d4c2307102f3e39bb88fa3452cbb8 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Tue, 23 Apr 2019 13:12:18 -0400 Subject: [PATCH] nvme: add additional check to avoid being divided by zero error When a Namespace was removed all the field will be zeroed, which may lead to being divied by zero error when IO is running, especially with perf tool. The perf tool doesn't add hogplug support, so we add the additional check here to avoid such issue. Fix issues #728 and #629. Change-Id: I0e387c8c1bd4f3d40130377e2e0f5143f43be6a3 Signed-off-by: Changpeng Liu Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/451762 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/nvme/nvme_ns_cmd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/nvme/nvme_ns_cmd.c b/lib/nvme/nvme_ns_cmd.c index da37552c5d..8d36dbab7b 100644 --- a/lib/nvme/nvme_ns_cmd.c +++ b/lib/nvme/nvme_ns_cmd.c @@ -44,11 +44,15 @@ static bool spdk_nvme_ns_check_request_length(uint32_t lba_count, uint32_t sectors_per_max_io, uint32_t sectors_per_stripe, uint32_t qdepth) { - uint32_t child_per_io; + uint32_t child_per_io = UINT32_MAX; + /* After a namespace is destroyed(e.g. hotplug), all the fields associated with the + * namespace will be cleared to zero, the function will return TRUE for this case, + * and -EINVAL will be returned to caller. + */ if (sectors_per_stripe > 0) { child_per_io = (lba_count + sectors_per_stripe - 1) / sectors_per_stripe; - } else { + } else if (sectors_per_max_io > 0) { child_per_io = (lba_count + sectors_per_max_io - 1) / sectors_per_max_io; }