vhost: simplify memory registration functions

Make them accept a struct rte_vhost_memory * param
instead of a full spdk session object.

Change-Id: Ibe12f29146d2e971ef58fd5f7366cb059123224d
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/470457
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: John Kariuki <John.K.Kariuki@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-08-06 09:14:48 +02:00 committed by Tomasz Zawadzki
parent 30998f9b1f
commit 6231a197f5

View File

@ -530,15 +530,15 @@ vhost_session_find_by_vid(int vid)
#define CEIL_2MB(x) ((((uintptr_t)x) + SIZE_2MB - 1) / SIZE_2MB) << SHIFT_2MB #define CEIL_2MB(x) ((((uintptr_t)x) + SIZE_2MB - 1) / SIZE_2MB) << SHIFT_2MB
static void static void
vhost_session_mem_register(struct spdk_vhost_session *vsession) vhost_session_mem_register(struct rte_vhost_memory *mem)
{ {
struct rte_vhost_mem_region *region; struct rte_vhost_mem_region *region;
uint32_t i; uint32_t i;
uint64_t previous_start = UINT64_MAX; uint64_t previous_start = UINT64_MAX;
for (i = 0; i < vsession->mem->nregions; i++) { for (i = 0; i < mem->nregions; i++) {
uint64_t start, end, len; uint64_t start, end, len;
region = &vsession->mem->regions[i]; region = &mem->regions[i];
start = FLOOR_2MB(region->mmap_addr); start = FLOOR_2MB(region->mmap_addr);
end = CEIL_2MB(region->mmap_addr + region->mmap_size); end = CEIL_2MB(region->mmap_addr + region->mmap_size);
if (start == previous_start) { if (start == previous_start) {
@ -558,15 +558,15 @@ vhost_session_mem_register(struct spdk_vhost_session *vsession)
} }
static void static void
vhost_session_mem_unregister(struct spdk_vhost_session *vsession) vhost_session_mem_unregister(struct rte_vhost_memory *mem)
{ {
struct rte_vhost_mem_region *region; struct rte_vhost_mem_region *region;
uint32_t i; uint32_t i;
uint64_t previous_start = UINT64_MAX; uint64_t previous_start = UINT64_MAX;
for (i = 0; i < vsession->mem->nregions; i++) { for (i = 0; i < mem->nregions; i++) {
uint64_t start, end, len; uint64_t start, end, len;
region = &vsession->mem->regions[i]; region = &mem->regions[i];
start = FLOOR_2MB(region->mmap_addr); start = FLOOR_2MB(region->mmap_addr);
end = CEIL_2MB(region->mmap_addr + region->mmap_size); end = CEIL_2MB(region->mmap_addr + region->mmap_size);
if (start == previous_start) { if (start == previous_start) {
@ -1055,7 +1055,7 @@ _stop_session(struct spdk_vhost_session *vsession)
rte_vhost_set_vring_base(vsession->vid, i, q->last_avail_idx, q->last_used_idx); rte_vhost_set_vring_base(vsession->vid, i, q->last_avail_idx, q->last_used_idx);
} }
vhost_session_mem_unregister(vsession); vhost_session_mem_unregister(vsession->mem);
free(vsession->mem); free(vsession->mem);
return 0; return 0;
@ -1163,11 +1163,11 @@ vhost_start_device_cb(int vid)
} }
vhost_session_set_coalescing(vdev, vsession, NULL); vhost_session_set_coalescing(vdev, vsession, NULL);
vhost_session_mem_register(vsession); vhost_session_mem_register(vsession->mem);
vsession->initialized = true; vsession->initialized = true;
rc = vdev->backend->start_session(vsession); rc = vdev->backend->start_session(vsession);
if (rc != 0) { if (rc != 0) {
vhost_session_mem_unregister(vsession); vhost_session_mem_unregister(vsession->mem);
free(vsession->mem); free(vsession->mem);
goto out; goto out;
} }