perf: Fix integer overflow

perf application can't generate IO for NVMe namespace with
 more than 4G size.

 Example of error:
 "Attached to NVMe over Fabrics controller at 1.1.75.1:1023:
 nqn.2016-06.io.spdk.r-dcs75:rd0
 WARNING: controller SPDK bdev Controller (SPDK000DEADBEAF00   ) ns 1 has
 invalid ns size 0 / block size 4096 for I/O size 4096
 WARNING: Some requested NVMe devices were skipped
 No valid NVMe controllers or AIO devices found"

 ns_size variable is uint32_t, spdk_nvme_ns_get_size function
 returns uint64_t. Result can exceed the maximum size of
 uint32_t and ns_size remains 0.

 The issue introduced by commit: f2462909

Change-Id: Idc6dd8688d5d6268bda1a1d6b06a611643af6155
Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Reviewed-on: https://review.gerrithub.io/c/443996
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Sasha Kotchubievsky 2019-02-07 12:46:03 +00:00 committed by Jim Harris
parent ceb32abbd8
commit bdc96b4dd6

View File

@ -4,6 +4,8 @@
* Copyright (c) Intel Corporation.
* All rights reserved.
*
* Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@ -588,7 +590,8 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
{
struct ns_entry *entry;
const struct spdk_nvme_ctrlr_data *cdata;
uint32_t max_xfer_size, entries, ns_size, sector_size;
uint32_t max_xfer_size, entries, sector_size;
uint64_t ns_size;
struct spdk_nvme_io_qpair_opts opts;
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
@ -606,7 +609,7 @@ register_ns(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns)
if (ns_size < g_io_size_bytes || sector_size > g_io_size_bytes) {
printf("WARNING: controller %-20.20s (%-20.20s) ns %u has invalid "
"ns size %u / block size %u for I/O size %u\n",
"ns size %" PRIu64 " / block size %u for I/O size %u\n",
cdata->mn, cdata->sn, spdk_nvme_ns_get_id(ns),
ns_size, spdk_nvme_ns_get_sector_size(ns), g_io_size_bytes);
g_warn = true;