Commit 5e8858d7 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

nvmf/rdma: Simplify nvmf_rdma_fill_wr_sge() by using cached pointers



Cache pointers to iovec and ibv_sge at the head of the function
and use them throughout.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I493759bf3989ced4390d077280cd44c122847d08
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469348


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarAlexey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 89a28bfd
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -1623,25 +1623,27 @@ nvmf_rdma_fill_wr_sge(struct spdk_nvmf_rdma_device *device,
		      struct spdk_nvmf_request *req, struct ibv_send_wr *wr)
{
	uint64_t	translation_len;
	struct iovec	*iov = &req->iov[req->iovcnt];
	struct ibv_sge	*sg_ele = &wr->sg_list[wr->num_sge];

	translation_len = req->iov[req->iovcnt].iov_len;
	translation_len = iov->iov_len;

	if (!g_nvmf_hooks.get_rkey) {
		wr->sg_list[wr->num_sge].lkey = ((struct ibv_mr *)spdk_mem_map_translate(device->map,
						 (uint64_t)req->iov[req->iovcnt].iov_base, &translation_len))->lkey;
		sg_ele->lkey = ((struct ibv_mr *)spdk_mem_map_translate(device->map,
				(uint64_t)iov->iov_base, &translation_len))->lkey;
	} else {
		wr->sg_list[wr->num_sge].lkey = spdk_mem_map_translate(device->map,
						(uint64_t)req->iov[req->iovcnt].iov_base, &translation_len);
		sg_ele->lkey = spdk_mem_map_translate(device->map,
						      (uint64_t)iov->iov_base, &translation_len);
	}

	if (spdk_unlikely(translation_len < req->iov[req->iovcnt].iov_len)) {
	if (spdk_unlikely(translation_len < iov->iov_len)) {
		/* This is a very rare case that can occur when using DPDK version < 19.05 */
		SPDK_ERRLOG("Data buffer split over multiple RDMA Memory Regions. Removing it from circulation.\n");
		return false;
	}

	wr->sg_list[wr->num_sge].addr = (uintptr_t)(req->iov[req->iovcnt].iov_base);
	wr->sg_list[wr->num_sge].length = req->iov[req->iovcnt].iov_len;
	sg_ele->addr = (uintptr_t)(iov->iov_base);
	sg_ele->length = iov->iov_len;
	wr->num_sge++;

	return true;