Commit 4582e9fb authored by Changpeng Liu's avatar Changpeng Liu
Browse files

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: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/451762


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent f74643ef
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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;
	}