Commit c0bf9314 authored by Changpeng Liu's avatar Changpeng Liu Committed by Jim Harris
Browse files

env/memory: return the memory virtual address's file descriptor and offset



For virtio-user library and coming vfio-user feature, the client needs
to send the memory file descriptors to target so that the two processes
can setup shared memory region to do data processing without memory copy.
Currently virtio-user will read /proc/self/maps to get memory file descriptor,
since DPDK already provides this such APIs, so here we can just use it,
for existing virtio-user library we may replace it with the new added
API.

Change-Id: Icfeae465d53826d0c8d1b335287634b03cd174aa
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4428


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 95b76c4d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1294,6 +1294,16 @@ int spdk_mem_unregister(void *vaddr, size_t len);
 */
int spdk_mem_reserve(void *vaddr, size_t len);

/**
 * Get the address's file descriptor and offset, it works with spdk memory allocation APIs
 *
 * \param vaddr Virtual address to get
 * \param offset Virtual address's map offset to the file descriptor
 *
 * \ return negative errno on failure, otherwise return the file descriptor
 */
int spdk_mem_get_fd_and_offset(void *vaddr, uint64_t *offset);

#ifdef __cplusplus
}
#endif
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 5
SO_MINOR := 0
SO_MINOR := 1

CFLAGS += $(ENV_CFLAGS)
C_SRCS = env.c memory.c pci.c init.c threads.c
+25 −0
Original line number Diff line number Diff line
@@ -1445,3 +1445,28 @@ spdk_vtophys(const void *buf, uint64_t *size)
		return paddr_2mb + (vaddr & MASK_2MB);
	}
}

int
spdk_mem_get_fd_and_offset(void *vaddr, uint64_t *offset)
{
	struct rte_memseg *seg;
	int ret, fd;

	seg = rte_mem_virt2memseg(vaddr, NULL);
	if (!seg) {
		SPDK_ERRLOG("memory %p doesn't exist\n", vaddr);
		return -ENOENT;
	}

	fd = rte_memseg_get_fd_thread_unsafe(seg);
	if (fd < 0) {
		return fd;
	}

	ret = rte_memseg_get_fd_offset_thread_unsafe(seg, offset);
	if (ret < 0) {
		return ret;
	}

	return fd;
}
+1 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@
	spdk_mem_map_translate;
	spdk_mem_register;
	spdk_mem_unregister;
	spdk_mem_get_fd_and_offset;

	# Public functions in env_dpdk.h
	spdk_env_dpdk_post_init;