From bfdc02ab486b00fcabc636e60e0e6b00311945ee Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Fri, 12 Aug 2016 10:24:34 -0700 Subject: [PATCH] nvme: Eliminate nvme_impl.h and use the swappable env lib. Change-Id: Ibbc557b732d5b0858a2922a7a442c4b17a0d579a Signed-off-by: Ben Walker --- CONFIG | 4 - doc/Doxyfile | 3 +- include/spdk/env.h | 2 +- lib/nvme/Makefile | 2 +- lib/nvme/nvme.c | 22 +-- lib/nvme/nvme_ctrlr.c | 30 ++-- lib/nvme/nvme_impl.h | 140 ------------------ lib/nvme/nvme_internal.h | 2 +- lib/nvme/nvme_qpair.c | 34 ++--- mk/nvme.unittest.mk | 2 +- test/lib/nvme/unit/nvme_c/nvme_ut.c | 7 +- .../nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c | 6 +- .../nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c | 19 +-- .../nvme/unit/nvme_qpair_c/nvme_qpair_ut.c | 23 +-- .../lib/nvme/unit/{nvme_impl.h => test_env.c} | 98 ++++++------ 15 files changed, 122 insertions(+), 272 deletions(-) delete mode 100644 lib/nvme/nvme_impl.h rename test/lib/nvme/unit/{nvme_impl.h => test_env.c} (64%) diff --git a/CONFIG b/CONFIG index 5e54681ce..1d147e1cc 100644 --- a/CONFIG +++ b/CONFIG @@ -53,10 +53,6 @@ CONFIG_ENV?=$(SPDK_ROOT_DIR)/lib/env # when using the default SPDK environment library. CONFIG_DPDK_DIR?=/path/to/dpdk -# Header file to use for NVMe implementation specific functions. -# Defaults to depending on DPDK. -CONFIG_NVME_IMPL?=nvme_impl.h - # Build SPDK FIO plugin. Requires FIO_SOURCE_DIR set to a valid # fio source code directory. CONFIG_FIO_PLUGIN?=n diff --git a/doc/Doxyfile b/doc/Doxyfile index 80775178b..9a8e4ab28 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -758,8 +758,7 @@ WARN_LOGFILE = # spaces. # Note: If this tag is empty the current directory is searched. -INPUT = ../lib/nvme/nvme_impl.h \ - ../include/spdk \ +INPUT = ../include/spdk \ mainpage.txt \ ioat/index.txt \ nvme/index.txt \ diff --git a/include/spdk/env.h b/include/spdk/env.h index dd2c97d07..ce7c85dd5 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -56,7 +56,7 @@ void * spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr); /** - * Free a memory buffer previously allocated with spdk_malloc. + * Free a memory buffer previously allocated with spdk_zmalloc. * This call is never made from the performance path. */ void diff --git a/lib/nvme/Makefile b/lib/nvme/Makefile index c88fa5636..6def9d2bf 100644 --- a/lib/nvme/Makefile +++ b/lib/nvme/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -CFLAGS += $(ENV_CFLAGS) -include $(CONFIG_NVME_IMPL) +CFLAGS += $(ENV_CFLAGS) C_SRCS = nvme_ctrlr_cmd.c nvme_ctrlr.c nvme_ns_cmd.c nvme_ns.c nvme_qpair.c nvme.c nvme_intel.c LIBNAME = nvme diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 238b99083..eea09e959 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -51,8 +51,8 @@ nvme_attach(void *devhandle) int status; uint64_t phys_addr = 0; - ctrlr = nvme_malloc(sizeof(struct spdk_nvme_ctrlr), - 64, &phys_addr); + ctrlr = spdk_zmalloc(sizeof(struct spdk_nvme_ctrlr), + 64, &phys_addr); if (ctrlr == NULL) { SPDK_ERRLOG("could not allocate ctrlr\n"); return NULL; @@ -60,7 +60,7 @@ nvme_attach(void *devhandle) status = nvme_ctrlr_construct(ctrlr, devhandle); if (status != 0) { - nvme_free(ctrlr); + spdk_free(ctrlr); return NULL; } @@ -74,7 +74,7 @@ spdk_nvme_detach(struct spdk_nvme_ctrlr *ctrlr) nvme_ctrlr_destruct(ctrlr); TAILQ_REMOVE(&g_spdk_nvme_driver->attached_ctrlrs, ctrlr, tailq); - nvme_free(ctrlr); + spdk_free(ctrlr); pthread_mutex_unlock(&g_spdk_nvme_driver->lock); return 0; @@ -100,7 +100,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size, { struct nvme_request *req = NULL; - req = nvme_mempool_get(g_spdk_nvme_driver->request_mempool); + req = spdk_mempool_get(g_spdk_nvme_driver->request_mempool); if (req == NULL) { return req; } @@ -156,7 +156,7 @@ nvme_user_copy_cmd_complete(void *arg, const struct spdk_nvme_cpl *cpl) memcpy(req->user_buffer, req->payload.u.contig, req->payload_size); } - nvme_free(req->payload.u.contig); + spdk_free(req->payload.u.contig); } /* Call the user's original callback now that the buffer has been copied */ @@ -178,7 +178,7 @@ nvme_allocate_request_user_copy(void *buffer, uint32_t payload_size, spdk_nvme_c uint64_t phys_addr; if (buffer && payload_size) { - contig_buffer = nvme_malloc(payload_size, 4096, &phys_addr); + contig_buffer = spdk_zmalloc(payload_size, 4096, &phys_addr); if (!contig_buffer) { return NULL; } @@ -190,7 +190,7 @@ nvme_allocate_request_user_copy(void *buffer, uint32_t payload_size, spdk_nvme_c req = nvme_allocate_request_contig(contig_buffer, payload_size, nvme_user_copy_cmd_complete, NULL); if (!req) { - nvme_free(buffer); + spdk_free(buffer); return NULL; } @@ -208,7 +208,7 @@ nvme_free_request(struct nvme_request *req) assert(req != NULL); assert(req->num_children == 0); - nvme_mempool_put(g_spdk_nvme_driver->request_mempool, req); + spdk_mempool_put(g_spdk_nvme_driver->request_mempool, req); } int @@ -279,7 +279,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a pthread_mutex_lock(&g_spdk_nvme_driver->lock); if (g_spdk_nvme_driver->request_mempool == NULL) { - g_spdk_nvme_driver->request_mempool = nvme_mempool_create("nvme_request", 8192, + g_spdk_nvme_driver->request_mempool = spdk_mempool_create("nvme_request", 8192, sizeof(struct nvme_request), -1); if (g_spdk_nvme_driver->request_mempool == NULL) { SPDK_ERRLOG("Unable to allocate pool of requests\n"); @@ -316,7 +316,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a /* Controller failed to initialize. */ TAILQ_REMOVE(&g_spdk_nvme_driver->init_ctrlrs, ctrlr, tailq); nvme_ctrlr_destruct(ctrlr); - nvme_free(ctrlr); + spdk_free(ctrlr); rc = -1; break; } diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index 7844935d8..e1b6f4d0d 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -247,8 +247,8 @@ static int nvme_ctrlr_set_intel_support_log_pages(struct spdk_nvme_ctrlr *ctrlr) struct nvme_completion_poll_status status; struct spdk_nvme_intel_log_page_directory *log_page_directory; - log_page_directory = nvme_malloc(sizeof(struct spdk_nvme_intel_log_page_directory), - 64, &phys_addr); + log_page_directory = spdk_zmalloc(sizeof(struct spdk_nvme_intel_log_page_directory), + 64, &phys_addr); if (log_page_directory == NULL) { SPDK_ERRLOG("could not allocate log_page_directory\n"); return -ENXIO; @@ -263,13 +263,13 @@ static int nvme_ctrlr_set_intel_support_log_pages(struct spdk_nvme_ctrlr *ctrlr) spdk_nvme_qpair_process_completions(&ctrlr->adminq, 0); } if (spdk_nvme_cpl_is_error(&status.cpl)) { - nvme_free(log_page_directory); + spdk_free(log_page_directory); SPDK_ERRLOG("nvme_ctrlr_cmd_get_log_page failed!\n"); return -ENXIO; } nvme_ctrlr_construct_intel_support_log_page_list(ctrlr, log_page_directory); - nvme_free(log_page_directory); + spdk_free(log_page_directory); return 0; } @@ -374,8 +374,8 @@ nvme_ctrlr_construct_io_qpairs(struct spdk_nvme_ctrlr *ctrlr) */ num_trackers = nvme_min(NVME_IO_TRACKERS, (num_entries - 1)); - ctrlr->ioq = nvme_malloc(ctrlr->opts.num_io_queues * sizeof(struct spdk_nvme_qpair), - 64, &phys_addr); + ctrlr->ioq = spdk_zmalloc(ctrlr->opts.num_io_queues * sizeof(struct spdk_nvme_qpair), + 64, &phys_addr); if (ctrlr->ioq == NULL) return -1; @@ -509,7 +509,7 @@ nvme_ctrlr_set_state(struct spdk_nvme_ctrlr *ctrlr, enum nvme_ctrlr_state state, if (timeout_in_ms == NVME_TIMEOUT_INFINITE) { ctrlr->state_timeout_tsc = NVME_TIMEOUT_INFINITE; } else { - ctrlr->state_timeout_tsc = nvme_get_tsc() + (timeout_in_ms * nvme_get_tsc_hz()) / 1000; + ctrlr->state_timeout_tsc = spdk_get_ticks() + (timeout_in_ms * spdk_get_ticks_hz()) / 1000; } } @@ -660,13 +660,13 @@ nvme_ctrlr_destruct_namespaces(struct spdk_nvme_ctrlr *ctrlr) nvme_ns_destruct(&ctrlr->ns[i]); } - nvme_free(ctrlr->ns); + spdk_free(ctrlr->ns); ctrlr->ns = NULL; ctrlr->num_ns = 0; } if (ctrlr->nsdata) { - nvme_free(ctrlr->nsdata); + spdk_free(ctrlr->nsdata); ctrlr->nsdata = NULL; } } @@ -688,14 +688,14 @@ nvme_ctrlr_construct_namespaces(struct spdk_nvme_ctrlr *ctrlr) if (nn != ctrlr->num_ns) { nvme_ctrlr_destruct_namespaces(ctrlr); - ctrlr->ns = nvme_malloc(nn * sizeof(struct spdk_nvme_ns), 64, - &phys_addr); + ctrlr->ns = spdk_zmalloc(nn * sizeof(struct spdk_nvme_ns), 64, + &phys_addr); if (ctrlr->ns == NULL) { goto fail; } - ctrlr->nsdata = nvme_malloc(nn * sizeof(struct spdk_nvme_ns_data), 64, - &phys_addr); + ctrlr->nsdata = spdk_zmalloc(nn * sizeof(struct spdk_nvme_ns_data), 64, + &phys_addr); if (ctrlr->nsdata == NULL) { goto fail; } @@ -907,7 +907,7 @@ nvme_ctrlr_process_init(struct spdk_nvme_ctrlr *ctrlr) } if (ctrlr->state_timeout_tsc != NVME_TIMEOUT_INFINITE && - nvme_get_tsc() > ctrlr->state_timeout_tsc) { + spdk_get_ticks() > ctrlr->state_timeout_tsc) { SPDK_ERRLOG("Initialization timed out in state %d\n", ctrlr->state); nvme_ctrlr_fail(ctrlr); return -1; @@ -1163,7 +1163,7 @@ nvme_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr) } } - nvme_free(ctrlr->ioq); + spdk_free(ctrlr->ioq); nvme_qpair_destroy(&ctrlr->adminq); diff --git a/lib/nvme/nvme_impl.h b/lib/nvme/nvme_impl.h deleted file mode 100644 index 79b10454e..000000000 --- a/lib/nvme/nvme_impl.h +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright (c) Intel Corporation. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * \file - * NVMe driver integration callbacks - * - * This file describes the callback functions required to integrate - * the userspace NVMe driver for a specific implementation. This - * implementation is specific for DPDK. Users would - * revise it as necessary for their own particular environment if not - * using it within the DPDK framework. - */ - -#ifndef __NVME_IMPL_H__ -#define __NVME_IMPL_H__ - -#include "spdk/env.h" -#include "spdk/env.h" -#include "spdk/nvme_spec.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "spdk/pci_ids.h" - -/** - * \page nvme_driver_integration NVMe Driver Integration - * - * Users can integrate the userspace NVMe driver into their environment - * by implementing the callbacks in nvme_impl.h. These callbacks - * enable users to specify how to allocate pinned and physically - * contiguous memory, performance virtual to physical address - * translations, log messages, PCI configuration and register mapping, - * and a number of other facilities that may differ depending on the - * environment. - */ - -/** - * Allocate a pinned, physically contiguous memory buffer with the - * given size and alignment. - * Note: these calls are only made during driver initialization. - */ -#define nvme_malloc spdk_zmalloc - -/** - * Free a memory buffer previously allocated with nvme_malloc. - */ -#define nvme_free spdk_free - -/** - * Reserve a named, process shared memory zone with the given size, - * socket_id and flags. - * Return a pointer to the allocated memory address. If the allocation - * cannot be done, return NULL. - */ -#define nvme_memzone_reserve spdk_memzone_reserve - -/** - * Lookup the memory zone identified by the given name. - * Return a pointer to the reserved memory address. If the reservation - * cannot be found, return NULL. - */ -#define nvme_memzone_lookup spdk_memzone_lookup - -/** - * Free the memory zone identified by the given name. - */ -#define nvme_memzone_free spdk_memzone_free - -/** - * Return true if the calling process is primary process - */ -#define nvme_process_is_primary spdk_process_is_primary - -/** - * Return the physical address for the specified virtual address. - */ -#define nvme_vtophys(buf) spdk_vtophys(buf) -#define NVME_VTOPHYS_ERROR SPDK_VTOPHYS_ERROR - -typedef struct spdk_mempool nvme_mempool_t; - -/** - * Create a mempool with the given configuration. - * Return a pointer to the allocated memory address. If the allocation - * cannot be done, return NULL. - */ -#define nvme_mempool_create spdk_mempool_create -#define nvme_mempool_free spdk_mempool_free -#define nvme_mempool_get spdk_mempool_get -#define nvme_mempool_put spdk_mempool_put - -/** - * Get a monotonic timestamp counter (used for measuring timeouts during initialization). - */ -#define nvme_get_tsc() spdk_get_ticks() - -/** - * Get the tick rate of nvme_get_tsc() per second. - */ -#define nvme_get_tsc_hz() spdk_get_ticks_hz() - -#endif /* __NVME_IMPL_H__ */ diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index 158e28171..4484abc77 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -465,7 +465,7 @@ struct nvme_driver { pthread_mutex_t lock; TAILQ_HEAD(, spdk_nvme_ctrlr) init_ctrlrs; TAILQ_HEAD(, spdk_nvme_ctrlr) attached_ctrlrs; - nvme_mempool_t *request_mempool; + struct spdk_mempool *request_mempool; }; struct pci_id { diff --git a/lib/nvme/nvme_qpair.c b/lib/nvme/nvme_qpair.c index cd7135e74..039681262 100644 --- a/lib/nvme/nvme_qpair.c +++ b/lib/nvme/nvme_qpair.c @@ -556,18 +556,18 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id, } } if (qpair->sq_in_cmb == false) { - qpair->cmd = nvme_malloc(qpair->num_entries * sizeof(struct spdk_nvme_cmd), - 0x1000, - &qpair->cmd_bus_addr); + qpair->cmd = spdk_zmalloc(qpair->num_entries * sizeof(struct spdk_nvme_cmd), + 0x1000, + &qpair->cmd_bus_addr); if (qpair->cmd == NULL) { SPDK_ERRLOG("alloc qpair_cmd failed\n"); goto fail; } } - qpair->cpl = nvme_malloc(qpair->num_entries * sizeof(struct spdk_nvme_cpl), - 0x1000, - &qpair->cpl_bus_addr); + qpair->cpl = spdk_zmalloc(qpair->num_entries * sizeof(struct spdk_nvme_cpl), + 0x1000, + &qpair->cpl_bus_addr); if (qpair->cpl == NULL) { SPDK_ERRLOG("alloc qpair_cpl failed\n"); goto fail; @@ -587,7 +587,7 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id, * This ensures the PRP list embedded in the nvme_tracker object will not span a * 4KB boundary, while allowing access to trackers in tr[] via normal array indexing. */ - qpair->tr = nvme_malloc(num_trackers * sizeof(*tr), sizeof(*tr), &phys_addr); + qpair->tr = spdk_zmalloc(num_trackers * sizeof(*tr), sizeof(*tr), &phys_addr); if (qpair->tr == NULL) { SPDK_ERRLOG("nvme_tr failed\n"); goto fail; @@ -640,15 +640,15 @@ nvme_qpair_destroy(struct spdk_nvme_qpair *qpair) _nvme_admin_qpair_destroy(qpair); } if (qpair->cmd && !qpair->sq_in_cmb) { - nvme_free(qpair->cmd); + spdk_free(qpair->cmd); qpair->cmd = NULL; } if (qpair->cpl) { - nvme_free(qpair->cpl); + spdk_free(qpair->cpl); qpair->cpl = NULL; } if (qpair->tr) { - nvme_free(qpair->tr); + spdk_free(qpair->tr); qpair->tr = NULL; } } @@ -678,8 +678,8 @@ _nvme_qpair_build_contig_request(struct spdk_nvme_qpair *qpair, struct nvme_requ void *md_payload; void *payload = req->payload.u.contig + req->payload_offset; - phys_addr = nvme_vtophys(payload); - if (phys_addr == NVME_VTOPHYS_ERROR) { + phys_addr = spdk_vtophys(payload); + if (phys_addr == SPDK_VTOPHYS_ERROR) { _nvme_fail_request_bad_vtophys(qpair, tr); return -1; } @@ -692,8 +692,8 @@ _nvme_qpair_build_contig_request(struct spdk_nvme_qpair *qpair, struct nvme_requ if (req->payload.md) { md_payload = req->payload.md + req->md_offset; - tr->req->cmd.mptr = nvme_vtophys(md_payload); - if (tr->req->cmd.mptr == NVME_VTOPHYS_ERROR) { + tr->req->cmd.mptr = spdk_vtophys(md_payload); + if (tr->req->cmd.mptr == SPDK_VTOPHYS_ERROR) { _nvme_fail_request_bad_vtophys(qpair, tr); return -1; } @@ -703,14 +703,14 @@ _nvme_qpair_build_contig_request(struct spdk_nvme_qpair *qpair, struct nvme_requ tr->req->cmd.dptr.prp.prp1 = phys_addr; if (nseg == 2) { seg_addr = payload + PAGE_SIZE - unaligned; - tr->req->cmd.dptr.prp.prp2 = nvme_vtophys(seg_addr); + tr->req->cmd.dptr.prp.prp2 = spdk_vtophys(seg_addr); } else if (nseg > 2) { cur_nseg = 1; tr->req->cmd.dptr.prp.prp2 = (uint64_t)tr->prp_sgl_bus_addr; while (cur_nseg < nseg) { seg_addr = payload + cur_nseg * PAGE_SIZE - unaligned; - phys_addr = nvme_vtophys(seg_addr); - if (phys_addr == NVME_VTOPHYS_ERROR) { + phys_addr = spdk_vtophys(seg_addr); + if (phys_addr == SPDK_VTOPHYS_ERROR) { _nvme_fail_request_bad_vtophys(qpair, tr); return -1; } diff --git a/mk/nvme.unittest.mk b/mk/nvme.unittest.mk index 9e69ae9ab..28f0ba378 100644 --- a/mk/nvme.unittest.mk +++ b/mk/nvme.unittest.mk @@ -37,7 +37,7 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk C_SRCS = $(TEST_FILE) $(OTHER_FILES) -CFLAGS += -I$(SPDK_ROOT_DIR)/lib -include $(SPDK_ROOT_DIR)/test/lib/nvme/unit/nvme_impl.h +CFLAGS += -I$(SPDK_ROOT_DIR)/lib CFLAGS += -I$(SPDK_ROOT_DIR)/test SPDK_LIBS += $(SPDK_ROOT_DIR)/lib/log/libspdk_log.a diff --git a/test/lib/nvme/unit/nvme_c/nvme_ut.c b/test/lib/nvme/unit/nvme_c/nvme_ut.c index c3ad5a96d..1f8d3022c 100644 --- a/test/lib/nvme/unit/nvme_c/nvme_ut.c +++ b/test/lib/nvme/unit/nvme_c/nvme_ut.c @@ -37,6 +37,8 @@ #include "nvme/nvme.c" +#include "lib/nvme/unit/test_env.c" + int spdk_pci_enumerate(enum spdk_pci_device_type type, spdk_pci_enum_cb enum_cb, @@ -45,11 +47,6 @@ spdk_pci_enumerate(enum spdk_pci_device_type type, return -1; } -uint64_t nvme_vtophys(void *buf) -{ - return (uintptr_t)buf; -} - int nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr, void *devhandle) { diff --git a/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c b/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c index e503bde74..f3b4b6907 100644 --- a/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c +++ b/test/lib/nvme/unit/nvme_ctrlr_c/nvme_ctrlr_ut.c @@ -35,6 +35,8 @@ #include +#include "lib/nvme/unit/test_env.c" + bool trace_flag = false; #define SPDK_TRACE_NVME trace_flag @@ -154,7 +156,7 @@ nvme_qpair_submit_request(struct spdk_nvme_qpair *qpair, struct nvme_request *re * Free the request here so it does not leak. * For the purposes of this unit test, we don't need to bother emulating request submission. */ - nvme_mempool_put(_g_nvme_driver.request_mempool, req); + spdk_mempool_put(_g_nvme_driver.request_mempool, req); return 0; } @@ -321,7 +323,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size, void *cb_arg) { struct nvme_request *req = NULL; - req = nvme_mempool_get(_g_nvme_driver.request_mempool); + req = spdk_mempool_get(_g_nvme_driver.request_mempool); if (req != NULL) { memset(req, 0, offsetof(struct nvme_request, children)); diff --git a/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c b/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c index a65308128..3f3e313b6 100644 --- a/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c +++ b/test/lib/nvme/unit/nvme_ns_cmd_c/nvme_ns_cmd_ut.c @@ -35,6 +35,8 @@ #include "nvme/nvme_ns_cmd.c" +#include "lib/nvme/unit/test_env.c" + struct nvme_request *g_request = NULL; @@ -55,11 +57,6 @@ static int nvme_request_next_sge(void *cb_arg, uint64_t *address, uint32_t *leng return 0; } -uint64_t nvme_vtophys(void *buf) -{ - return (uintptr_t)buf; -} - int nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr, void *devhandle) { @@ -484,7 +481,7 @@ test_nvme_ns_cmd_dataset_management(void) CU_ASSERT(g_request->cmd.nsid == ns.id); CU_ASSERT(g_request->cmd.cdw10 == 0); CU_ASSERT(g_request->cmd.cdw11 == SPDK_NVME_DSM_ATTR_DEALLOCATE); - nvme_free(g_request->payload.u.contig); + spdk_free(g_request->payload.u.contig); nvme_free_request(g_request); /* TRIM 256 LBAs */ @@ -496,7 +493,7 @@ test_nvme_ns_cmd_dataset_management(void) CU_ASSERT(g_request->cmd.nsid == ns.id); CU_ASSERT(g_request->cmd.cdw10 == 255u); CU_ASSERT(g_request->cmd.cdw11 == SPDK_NVME_DSM_ATTR_DEALLOCATE); - nvme_free(g_request->payload.u.contig); + spdk_free(g_request->payload.u.contig); nvme_free_request(g_request); rc = spdk_nvme_ns_cmd_dataset_management(&ns, &qpair, SPDK_NVME_DSM_ATTR_DEALLOCATE, @@ -635,7 +632,7 @@ test_nvme_ns_cmd_reservation_register(void) CU_ASSERT(g_request->cmd.cdw10 == tmp_cdw10); - nvme_free(g_request->payload.u.contig); + spdk_free(g_request->payload.u.contig); nvme_free_request(g_request); free(payload); } @@ -672,7 +669,7 @@ test_nvme_ns_cmd_reservation_release(void) CU_ASSERT(g_request->cmd.cdw10 == tmp_cdw10); - nvme_free(g_request->payload.u.contig); + spdk_free(g_request->payload.u.contig); nvme_free_request(g_request); free(payload); } @@ -709,7 +706,7 @@ test_nvme_ns_cmd_reservation_acquire(void) CU_ASSERT(g_request->cmd.cdw10 == tmp_cdw10); - nvme_free(g_request->payload.u.contig); + spdk_free(g_request->payload.u.contig); nvme_free_request(g_request); free(payload); } @@ -738,7 +735,7 @@ test_nvme_ns_cmd_reservation_report(void) CU_ASSERT(g_request->cmd.cdw10 == (0x1000 / 4)); - nvme_free(g_request->payload.u.contig); + spdk_free(g_request->payload.u.contig); nvme_free_request(g_request); free(payload); } diff --git a/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c b/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c index 16f0647d6..5fd662259 100644 --- a/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c +++ b/test/lib/nvme/unit/nvme_qpair_c/nvme_qpair_ut.c @@ -37,6 +37,8 @@ #include "spdk_cunit.h" +#include "lib/nvme/unit/test_env.c" + bool trace_flag = false; #define SPDK_TRACE_NVME trace_flag @@ -51,19 +53,10 @@ int32_t spdk_nvme_retry_count = 1; struct nvme_request *g_request = NULL; -bool fail_vtophys = false; +extern bool ut_fail_vtophys; bool fail_next_sge = false; -uint64_t nvme_vtophys(void *buf) -{ - if (fail_vtophys) { - return (uint64_t) - 1; - } else { - return (uintptr_t)buf; - } -} - struct io_request { uint64_t address_offset; bool invalid_addr; @@ -132,7 +125,7 @@ nvme_allocate_request(const struct nvme_payload *payload, uint32_t payload_size, { struct nvme_request *req = NULL; - req = nvme_mempool_get(_g_nvme_driver.request_mempool); + req = spdk_mempool_get(_g_nvme_driver.request_mempool); if (req == NULL) { return req; @@ -176,7 +169,7 @@ nvme_allocate_request_null(spdk_nvme_cmd_cb cb_fn, void *cb_arg) void nvme_free_request(struct nvme_request *req) { - nvme_mempool_put(_g_nvme_driver.request_mempool, req); + spdk_mempool_put(_g_nvme_driver.request_mempool, req); } void @@ -208,7 +201,7 @@ prepare_submit_request_test(struct spdk_nvme_qpair *qpair, CU_ASSERT(qpair->sq_tail == 0); CU_ASSERT(qpair->cq_head == 0); - fail_vtophys = false; + ut_fail_vtophys = false; } static void @@ -224,7 +217,7 @@ ut_insert_cq_entry(struct spdk_nvme_qpair *qpair, uint32_t slot) struct nvme_tracker *tr; struct spdk_nvme_cpl *cpl; - req = nvme_mempool_get(_g_nvme_driver.request_mempool); + req = spdk_mempool_get(_g_nvme_driver.request_mempool); SPDK_CU_ASSERT_FATAL(req != NULL); memset(req, 0, sizeof(*req)); @@ -310,7 +303,7 @@ test4(void) * the request with error status to signify * a bad payload buffer. */ - fail_vtophys = true; + ut_fail_vtophys = true; CU_ASSERT(qpair.sq_tail == 0); diff --git a/test/lib/nvme/unit/nvme_impl.h b/test/lib/nvme/unit/test_env.c similarity index 64% rename from test/lib/nvme/unit/nvme_impl.h rename to test/lib/nvme/unit/test_env.c index 0d3331d2f..3a10c71fd 100644 --- a/test/lib/nvme/unit/nvme_impl.h +++ b/test/lib/nvme/unit/test_env.c @@ -31,22 +31,15 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __NVME_IMPL_H__ -#define __NVME_IMPL_H__ - -#include +#include #include #include #include -#include -#include -#include "spdk/nvme_spec.h" +#include "spdk/env.h" -struct spdk_pci_device; - -static inline void * -nvme_malloc(size_t size, unsigned align, uint64_t *phys_addr) +void * +spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) { void *buf = NULL; if (posix_memalign(&buf, align, size)) { @@ -56,58 +49,56 @@ nvme_malloc(size_t size, unsigned align, uint64_t *phys_addr) return buf; } -#define nvme_free(buf) free(buf) -#define nvme_get_num_ioq() 8 -#define nvme_get_ioq_idx() 0 +void spdk_free(void *buf) +{ + free(buf); +} -uint64_t nvme_vtophys(void *buf); -#define NVME_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL) +bool ut_fail_vtophys = false; +uint64_t spdk_vtophys(void *buf) +{ + if (ut_fail_vtophys) { + return (uint64_t) - 1; + } else { + return (uintptr_t)buf; + } +} -extern uint64_t g_ut_tsc; -#define nvme_get_tsc() (g_ut_tsc) -#define nvme_get_tsc_hz() (1000000) - -static inline void * -nvme_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags) +void * +spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags) { return malloc(len); } -static inline void * -nvme_memzone_lookup(const char *name) +void * +spdk_memzone_lookup(const char *name) { - assert(0); return NULL; } -static inline int -nvme_memzone_free(const char *name) +int +spdk_memzone_free(const char *name) { - assert(0); return 0; } -static inline bool -nvme_process_is_primary(void) +struct spdk_mempool * +spdk_mempool_create(const char *name, size_t count, + size_t ele_size, size_t cache_size) { - return true; + static int mp = 0; + + return (struct spdk_mempool *)∓ } -#define NVME_SOCKET_ID_ANY -1 - -typedef unsigned nvme_mempool_t; - -static inline nvme_mempool_t * -nvme_mempool_create(const char *name, size_t n, - size_t elt_size, size_t cache_size) +void +spdk_mempool_free(struct spdk_mempool *mp) { - static int mp; - return ∓ } -static inline void * -nvme_mempool_get(nvme_mempool_t *mp) +void * +spdk_mempool_get(struct spdk_mempool *mp) { void *buf; @@ -118,10 +109,25 @@ nvme_mempool_get(nvme_mempool_t *mp) return buf; } -static inline void -nvme_mempool_put(nvme_mempool_t *mp, void *buf) +void +spdk_mempool_put(struct spdk_mempool *mp, void *ele) { - free(buf); + free(ele); } -#endif /* __NVME_IMPL_H__ */ +bool +spdk_process_is_primary(void) +{ + return true; +} + +uint64_t ut_tsc = 0; +uint64_t spdk_get_ticks(void) +{ + return ut_tsc; +} + +uint64_t spdk_get_ticks_hz(void) +{ + return 1000000; +}