env: pass an spdk_mem_map_ops structure to mem_map_alloc

This series of changes is aimed at enabling spdk_mem_map_translate to
report back to the user the length of the valid mem_map up to the
function that requested the translation.
This will be useful when retrieving memory regions associated with I/O
buffers in NVMe-oF. For large I/O it will be possible that the buffer is
split over multiple MRs and the I/O will have to be split into multiple
SGLs.

Change-Id: I90da6d4d31c669a3bf046f7721923dd743c5ef21
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/425328
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Seth Howell 2018-09-11 15:03:31 -07:00 committed by Jim Harris
parent 55bc3a7255
commit 4e06bb5e6d
8 changed files with 37 additions and 13 deletions

View File

@ -37,6 +37,10 @@ The size parameter of spdk_mem_map_translate is now a pointer. This allows the
function to report back the actual size of the translation relative to the original
request made by the user.
A new structure spdk_mem_map_ops has been introduced to hold memory map related
callbacks. This structure is now passed as the second argument of spdk_mem_map_alloc
in lieu of the notify callback.
### iscsi
Parameter names of `set_iscsi_options` and `get_iscsi_global_params` RPC

View File

@ -990,13 +990,13 @@ struct spdk_mem_map_ops {
* Allocate a virtual memory address translation map.
*
* \param default_translation Default translation for the map.
* \param notify_cb Callback function to notify the mapping.
* \param ops Table of callback functions for map operations.
* \param cb_ctx Argument passed to the callback function.
*
* \return a pointer to the allocated virtual memory address translation map.
*/
struct spdk_mem_map *spdk_mem_map_alloc(uint64_t default_translation,
spdk_mem_map_notify_cb notify_cb, void *cb_ctx);
const struct spdk_mem_map_ops *ops, void *cb_ctx);
/**
* Free a memory map previously allocated by spdk_mem_map_alloc().

View File

@ -151,7 +151,7 @@ spdk_mem_map_notify_walk(struct spdk_mem_map *map, enum spdk_mem_map_notify_acti
}
struct spdk_mem_map *
spdk_mem_map_alloc(uint64_t default_translation, spdk_mem_map_notify_cb notify_cb, void *cb_ctx)
spdk_mem_map_alloc(uint64_t default_translation, const struct spdk_mem_map_ops *ops, void *cb_ctx)
{
struct spdk_mem_map *map;
@ -166,12 +166,14 @@ spdk_mem_map_alloc(uint64_t default_translation, spdk_mem_map_notify_cb notify_c
}
map->default_translation = default_translation;
map->ops.notify_cb = notify_cb;
map->cb_ctx = cb_ctx;
if (ops) {
map->ops = *ops;
}
pthread_mutex_lock(&g_spdk_mem_map_mutex);
if (notify_cb) {
if (ops && ops->notify_cb) {
spdk_mem_map_notify_walk(map, SPDK_MEM_MAP_NOTIFY_REGISTER);
TAILQ_INSERT_TAIL(&g_spdk_mem_maps, map, tailq);
}

View File

@ -604,11 +604,15 @@ spdk_vtophys_pci_device_removed(struct rte_pci_device *pci_device)
int
spdk_vtophys_init(void)
{
const struct spdk_mem_map_ops vtophys_map_ops = {
.notify_cb = spdk_vtophys_notify
};
#if SPDK_VFIO_ENABLED
spdk_vtophys_iommu_init();
#endif
g_vtophys_map = spdk_mem_map_alloc(SPDK_VTOPHYS_ERROR, spdk_vtophys_notify, NULL);
g_vtophys_map = spdk_mem_map_alloc(SPDK_VTOPHYS_ERROR, &vtophys_map_ops, NULL);
if (g_vtophys_map == NULL) {
DEBUG_PRINT("vtophys map allocation failed\n");
return -1;

View File

@ -631,12 +631,14 @@ nvme_rdma_mr_map_notify(void *cb_ctx, struct spdk_mem_map *map,
return rc;
}
static int
nvme_rdma_register_mem(struct nvme_rdma_qpair *rqpair)
{
struct ibv_pd *pd = rqpair->cm_id->qp->pd;
struct spdk_nvme_rdma_mr_map *mr_map;
const struct spdk_mem_map_ops nvme_rdma_map_ops = {
.notify_cb = nvme_rdma_mr_map_notify
};
pthread_mutex_lock(&g_rdma_mr_maps_mutex);
@ -659,7 +661,7 @@ nvme_rdma_register_mem(struct nvme_rdma_qpair *rqpair)
mr_map->ref = 1;
mr_map->pd = pd;
mr_map->map = spdk_mem_map_alloc((uint64_t)NULL, nvme_rdma_mr_map_notify, pd);
mr_map->map = spdk_mem_map_alloc((uint64_t)NULL, &nvme_rdma_map_ops, pd);
if (mr_map->map == NULL) {
SPDK_ERRLOG("spdk_mem_map_alloc() failed\n");
free(mr_map);

View File

@ -1634,6 +1634,10 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_transport_opts *opts)
int flag;
uint32_t sge_count;
const struct spdk_mem_map_ops nvmf_rdma_map_ops = {
.notify_cb = spdk_nvmf_rdma_mem_notify
};
rtransport = calloc(1, sizeof(*rtransport));
if (!rtransport) {
return NULL;
@ -1766,7 +1770,7 @@ spdk_nvmf_rdma_create(struct spdk_nvmf_transport_opts *opts)
break;
}
device->map = spdk_mem_map_alloc(0, spdk_nvmf_rdma_mem_notify, device);
device->map = spdk_mem_map_alloc(0, &nvmf_rdma_map_ops, device);
if (!device->map) {
SPDK_ERRLOG("Unable to allocate memory map for new poll group\n");
ibv_dealloc_pd(device->pd);

View File

@ -96,13 +96,17 @@ test_mem_map_notify(void *cb_ctx, struct spdk_mem_map *map,
return 0;
}
const struct spdk_mem_map_ops test_mem_map_ops = {
.notify_cb = test_mem_map_notify
};
static void
test_mem_map_alloc_free(void)
{
struct spdk_mem_map *map;
uint64_t default_translation = 0xDEADBEEF0BADF00D;
map = spdk_mem_map_alloc(default_translation, test_mem_map_notify, NULL);
map = spdk_mem_map_alloc(default_translation, &test_mem_map_ops, NULL);
SPDK_CU_ASSERT_FATAL(map != NULL);
spdk_mem_map_free(&map);
@ -117,7 +121,7 @@ test_mem_map_translation(void)
uint64_t addr;
int rc;
map = spdk_mem_map_alloc(default_translation, test_mem_map_notify, NULL);
map = spdk_mem_map_alloc(default_translation, &test_mem_map_ops, NULL);
SPDK_CU_ASSERT_FATAL(map != NULL);
/* Try to get translation for address with no translation */
@ -204,7 +208,7 @@ test_mem_map_registration(void)
struct spdk_mem_map *map;
uint64_t default_translation = 0xDEADBEEF0BADF00D;
map = spdk_mem_map_alloc(default_translation, test_mem_map_notify, NULL);
map = spdk_mem_map_alloc(default_translation, &test_mem_map_ops, NULL);
SPDK_CU_ASSERT_FATAL(map != NULL);
/* Unregister memory region that wasn't previously registered */

View File

@ -135,8 +135,12 @@ mem_map_test(void)
{
struct spdk_mem_map *map;
uint64_t default_translation = 0xDEADBEEF0BADF00D;
const struct spdk_mem_map_ops test_map_ops = {
.notify_cb = test_map_notify
};
map = spdk_mem_map_alloc(default_translation, test_map_notify, NULL);
map = spdk_mem_map_alloc(default_translation, &test_map_ops, NULL);
if (map == NULL) {
return 1;
}