diff --git a/CONFIG b/CONFIG index 22d1553b1..d49b69780 100644 --- a/CONFIG +++ b/CONFIG @@ -80,3 +80,6 @@ CONFIG_RBD?=n # Build vhost library. CONFIG_VHOST?=y + +# Build with NVML backends +CONFIG_NVML?=n diff --git a/configure b/configure index d015e252c..4d96ccc1c 100755 --- a/configure +++ b/configure @@ -31,6 +31,8 @@ function usage() echo " example: /usr/share/dpdk/x86_64-default-linuxapp-gcc" echo " fio Required to build fio_plugin." echo " example: /usr/src/fio" + echo " nvml Required to build persistent memory bdev." + echo " example: /usr/share/nvml" echo " rbd [disabled]" echo " No path required." echo " rdma [disabled]" @@ -109,6 +111,16 @@ for i in "$@"; do --without-dpdk) CONFIG_DPDK_DIR= ;; + --with-nvml) + CONFIG_NVML=y + ;; + --with-nvml=*) + CONFIG_NVML=y + CONFIG_NVML_DIR=$(readlink -f ${i#*=}) + ;; + --without-nvml) + CONFIG_NVML=n + ;; --with-fio=*) FIO_SOURCE_DIR="${i#*=}" CONFIG_FIO_PLUGIN=y @@ -206,6 +218,12 @@ fi if [ -n "$CONFIG_DPDK_DIR" ]; then echo "CONFIG_DPDK_DIR?=$CONFIG_DPDK_DIR" >> CONFIG.local fi +if [ -n "$CONFIG_NVML" ]; then + echo "CONFIG_NVML?=$CONFIG_NVML" >> CONFIG.local +fi +if [ -n "$CONFIG_NVML_DIR" ]; then + echo "CONFIG_NVML_DIR?=$CONFIG_NVML_DIR" >> CONFIG.local +fi if [ -n "$CONFIG_FIO_PLUGIN" ]; then echo "CONFIG_FIO_PLUGIN?=$CONFIG_FIO_PLUGIN" >> CONFIG.local fi diff --git a/lib/bdev/Makefile b/lib/bdev/Makefile index 5f0f7ac0b..4464f45f1 100644 --- a/lib/bdev/Makefile +++ b/lib/bdev/Makefile @@ -48,6 +48,7 @@ DIRS-y += error gpt lvol malloc null nvme rpc split ifeq ($(OS),Linux) DIRS-y += aio virtio +DIRS-$(CONFIG_NVML) += pmem endif DIRS-$(CONFIG_RBD) += rbd diff --git a/lib/bdev/pmem/Makefile b/lib/bdev/pmem/Makefile new file mode 100644 index 000000000..6a6da5ecc --- /dev/null +++ b/lib/bdev/pmem/Makefile @@ -0,0 +1,41 @@ +# +# 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. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +CFLAGS += $(ENV_CFLAGS) -I$(SPDK_ROOT_DIR)/lib/bdev/ +C_SRCS = bdev_pmem.c bdev_pmem_rpc.c +LIBNAME = bdev_pmem + +include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/bdev/pmem/bdev_pmem.c b/lib/bdev/pmem/bdev_pmem.c new file mode 100644 index 000000000..94e1e246a --- /dev/null +++ b/lib/bdev/pmem/bdev_pmem.c @@ -0,0 +1,391 @@ +/*- + * 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. + */ + +#include "spdk/conf.h" +#include "spdk/string.h" +#include "spdk/likely.h" +#include "spdk/util.h" +#include "spdk/rpc.h" +#include "spdk_internal/bdev.h" +#include "spdk_internal/log.h" + +#include "bdev_pmem.h" +#include "libpmemblk.h" + +struct pmem_disk { + struct spdk_bdev disk; + PMEMblkpool *pool; + char pmem_file[NAME_MAX]; + TAILQ_ENTRY(pmem_disk) tailq; +}; + +static TAILQ_HEAD(, pmem_disk) g_pmem_disks = TAILQ_HEAD_INITIALIZER(g_pmem_disks); + +static int pmem_disk_count = 0; + +static int bdev_pmem_initialize(void); +static void bdev_pmem_finish(void); + +static int +bdev_pmem_get_ctx_size(void) +{ + return 0; +} + +SPDK_BDEV_MODULE_REGISTER(pmem, bdev_pmem_initialize, bdev_pmem_finish, + NULL, bdev_pmem_get_ctx_size, NULL) + + +typedef int(*spdk_bdev_pmem_io_request)(PMEMblkpool *pbp, void *buf, long long blockno); + +static int +_bdev_pmem_submit_io_read(PMEMblkpool *pbp, void *buf, long long blockno) +{ + return pmemblk_read(pbp, buf, blockno); +} + +static int +_bdev_pmem_submit_io_write(PMEMblkpool *pbp, void *buf, long long blockno) +{ + return pmemblk_write(pbp, buf, blockno); +} + +static int +bdev_pmem_destruct(void *ctx) +{ + struct pmem_disk *pdisk = ctx; + + TAILQ_REMOVE(&g_pmem_disks, pdisk, tailq); + free(pdisk->disk.name); + pmemblk_close(pdisk->pool); + free(pdisk); + + return 0; +} + +static int +bdev_pmem_check_iov_len(struct iovec *iovs, int iovcnt, size_t num_blocks, uint32_t block_size) +{ + size_t nbytes = num_blocks * block_size; + int i; + + for (i = 0; i < iovcnt; i++) { + if (spdk_unlikely(iovs[i].iov_base == NULL && iovs[i].iov_len != 0)) { + return -1; + } + + if (nbytes <= iovs[i].iov_len) { + return 0; + } + + if (spdk_unlikely(iovs[i].iov_len % block_size != 0)) { + return -1; + } + + nbytes -= iovs[i].iov_len; + } + + return -1; +} + +static void +bdev_pmem_submit_io(struct spdk_bdev_io *bdev_io, struct pmem_disk *pdisk, + struct spdk_io_channel *ch, + struct iovec *iov, int iovcnt, + uint64_t offset_blocks, size_t num_blocks, uint32_t block_size, + spdk_bdev_pmem_io_request fn) +{ + int rc; + size_t nbytes, offset, len; + enum spdk_bdev_io_status status; + + rc = bdev_pmem_check_iov_len(iov, iovcnt, num_blocks, block_size); + if (rc) { + status = SPDK_BDEV_IO_STATUS_FAILED; + goto end; + } + + SPDK_DEBUGLOG(SPDK_TRACE_BDEV_PMEM, "io %lu bytes from offset %#lx\n", + num_blocks, offset_blocks); + + for (nbytes = num_blocks * block_size; nbytes > 0; iov++) { + len = spdk_min(iov->iov_len, nbytes); + nbytes -= len; + + offset = 0; + while (offset != len) { + rc = fn(pdisk->pool, iov->iov_base + offset, offset_blocks); + if (rc != 0) { + SPDK_ERRLOG("pmemblk io failed: %d (%s)\n", errno, pmemblk_errormsg()); + status = SPDK_BDEV_IO_STATUS_FAILED; + goto end; + } + + offset += block_size; + offset_blocks++; + } + } + + assert(num_blocks == offset_blocks - bdev_io->u.bdev.offset_blocks); + status = SPDK_BDEV_IO_STATUS_SUCCESS; +end: + + spdk_bdev_io_complete(bdev_io, status); +} + +static void +bdev_pmem_write_zeros(struct spdk_bdev_io *bdev_io, struct pmem_disk *pdisk, + struct spdk_io_channel *ch, uint64_t offset_blocks, + uint64_t num_blocks, uint32_t block_size) +{ + int rc; + enum spdk_bdev_io_status status = SPDK_BDEV_IO_STATUS_SUCCESS; + + while (num_blocks > 0) { + rc = pmemblk_set_zero(pdisk->pool, offset_blocks); + if (rc != 0) { + SPDK_ERRLOG("pmemblk_set_zero failed: %d (%s)\n", errno, pmemblk_errormsg()); + status = SPDK_BDEV_IO_STATUS_FAILED; + break; + } + offset_blocks++; + num_blocks--; + } + spdk_bdev_io_complete(bdev_io, status); +} + +static void +bdev_pmem_io_get_buf_cb(struct spdk_io_channel *channel, struct spdk_bdev_io *bdev_io) +{ + bdev_pmem_submit_io(bdev_io, + bdev_io->bdev->ctxt, + channel, + bdev_io->u.bdev.iovs, + bdev_io->u.bdev.iovcnt, + bdev_io->u.bdev.offset_blocks, + bdev_io->u.bdev.num_blocks, + bdev_io->bdev->blocklen, + _bdev_pmem_submit_io_read); +} + +static void +bdev_pmem_submit_request(struct spdk_io_channel *channel, struct spdk_bdev_io *bdev_io) +{ + switch (bdev_io->type) { + case SPDK_BDEV_IO_TYPE_READ: + spdk_bdev_io_get_buf(bdev_io, bdev_pmem_io_get_buf_cb, + bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen); + break; + case SPDK_BDEV_IO_TYPE_WRITE: + bdev_pmem_submit_io(bdev_io, + bdev_io->bdev->ctxt, + channel, + bdev_io->u.bdev.iovs, + bdev_io->u.bdev.iovcnt, + bdev_io->u.bdev.offset_blocks, + bdev_io->u.bdev.num_blocks, + bdev_io->bdev->blocklen, + _bdev_pmem_submit_io_write); + break; + case SPDK_BDEV_IO_TYPE_UNMAP: + case SPDK_BDEV_IO_TYPE_WRITE_ZEROES: + bdev_pmem_write_zeros(bdev_io, + bdev_io->bdev->ctxt, + channel, + bdev_io->u.bdev.offset_blocks, + bdev_io->u.bdev.num_blocks, + bdev_io->bdev->blocklen); + break; + case SPDK_BDEV_IO_TYPE_RESET: + spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_SUCCESS); + break; + default: + spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED); + } +} + +static bool +bdev_pmem_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type) +{ + switch (io_type) { + case SPDK_BDEV_IO_TYPE_READ: + case SPDK_BDEV_IO_TYPE_WRITE: + case SPDK_BDEV_IO_TYPE_RESET: + case SPDK_BDEV_IO_TYPE_UNMAP: + case SPDK_BDEV_IO_TYPE_WRITE_ZEROES: + return true; + default: + return false; + } +} + +static struct spdk_io_channel * +bdev_pmem_get_io_channel(void *ctx) +{ + return spdk_get_io_channel(&g_pmem_disks); +} + +static int +bdev_pmem_dump_config_json(void *ctx, struct spdk_json_write_ctx *w) +{ + struct pmem_disk *pdisk = ctx; + + spdk_json_write_name(w, "pmem"); + spdk_json_write_object_begin(w); + spdk_json_write_name(w, "pmem_file"); + spdk_json_write_string(w, pdisk->pmem_file); + spdk_json_write_object_end(w); + + return 0; +} + +static int +bdev_pmem_create_cb(void *io_device, void *ctx_buf) +{ + return 0; +} + +static void +bdev_pmem_destroy_cb(void *io_device, void *ctx_buf) +{ +} + +static const struct spdk_bdev_fn_table pmem_fn_table = { + .destruct = bdev_pmem_destruct, + .submit_request = bdev_pmem_submit_request, + .io_type_supported = bdev_pmem_io_type_supported, + .get_io_channel = bdev_pmem_get_io_channel, + .dump_config_json = bdev_pmem_dump_config_json, +}; + +int +spdk_create_pmem_disk(const char *pmem_file, struct spdk_bdev **bdev) +{ + uint64_t num_blocks; + uint32_t block_size; + struct pmem_disk *pdisk; + + if (pmemblk_check(pmem_file, 0) != 1) { + SPDK_ERRLOG("Pool '%s' check failed: %s\n", pmem_file, pmemblk_errormsg()); + return EIO; + } + + pdisk = calloc(1, sizeof(*pdisk)); + if (!pdisk) { + return ENOMEM; + } + + snprintf(pdisk->pmem_file, sizeof(pdisk->pmem_file), "%s", pmem_file); + pdisk->pool = pmemblk_open(pmem_file, 0); + if (!pdisk->pool) { + SPDK_ERRLOG("Opening pmem pool '%s' failed: %d\n", pmem_file, errno); + free(pdisk); + return errno; + } + + block_size = pmemblk_bsize(pdisk->pool); + num_blocks = pmemblk_nblock(pdisk->pool); + + if (block_size == 0) { + SPDK_ERRLOG("Block size must be more than 0 bytes\n"); + pmemblk_close(pdisk->pool); + free(pdisk); + return EINVAL; + } + + if (num_blocks == 0) { + SPDK_ERRLOG("Disk must be more than 0 blocks\n"); + pmemblk_close(pdisk->pool); + free(pdisk); + return EINVAL; + } + + + pdisk->disk.name = spdk_sprintf_alloc("pmem%d", pmem_disk_count); + + if (!pdisk->disk.name) { + pmemblk_close(pdisk->pool); + free(pdisk); + return ENOMEM; + } + + pdisk->disk.product_name = "pmemblk disk"; + pmem_disk_count++; + + pdisk->disk.write_cache = 0; + pdisk->disk.blocklen = block_size; + pdisk->disk.blockcnt = num_blocks; + + pdisk->disk.ctxt = pdisk; + pdisk->disk.fn_table = &pmem_fn_table; + pdisk->disk.module = SPDK_GET_BDEV_MODULE(pmem); + + spdk_bdev_register(&pdisk->disk); + + TAILQ_INSERT_TAIL(&g_pmem_disks, pdisk, tailq); + + *bdev = &pdisk->disk; + + return 0; +} + +static int +bdev_pmem_initialize(void) +{ + const char *err = pmemblk_check_version(PMEMBLK_MAJOR_VERSION, PMEMBLK_MINOR_VERSION); + + if (err != NULL) { + SPDK_ERRLOG("Invalid libpmemblk version (expected %d.%d): %s\n", PMEMBLK_MAJOR_VERSION, + PMEMBLK_MINOR_VERSION, err); + return -1; + } + + spdk_io_device_register(&g_pmem_disks, bdev_pmem_create_cb, bdev_pmem_destroy_cb, 0); + + return 0; + +} + +static void +bdev_pmem_finish(void) +{ + struct pmem_disk *pdisk, *tmp; + + TAILQ_FOREACH_SAFE(pdisk, &g_pmem_disks, tailq, tmp) { + bdev_pmem_destruct(pdisk); + } + + spdk_io_device_unregister(&g_pmem_disks, NULL); +} + +SPDK_LOG_REGISTER_TRACE_FLAG("bdev_pmem", SPDK_TRACE_BDEV_PMEM) diff --git a/lib/bdev/pmem/bdev_pmem.h b/lib/bdev/pmem/bdev_pmem.h new file mode 100644 index 000000000..79742ad63 --- /dev/null +++ b/lib/bdev/pmem/bdev_pmem.h @@ -0,0 +1,41 @@ +/*- + * 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. + */ + +#ifndef SPDK_BDEV_PMEM_H +#define SPDK_BDEV_PMEM_H + +#include "spdk/bdev.h" + +int spdk_create_pmem_disk(const char *pmem_file, struct spdk_bdev **bdev); + +#endif /* SPDK_BDEV_PMEM_H */ diff --git a/lib/bdev/pmem/bdev_pmem_rpc.c b/lib/bdev/pmem/bdev_pmem_rpc.c new file mode 100644 index 000000000..8e2a00c32 --- /dev/null +++ b/lib/bdev/pmem/bdev_pmem_rpc.c @@ -0,0 +1,101 @@ +/*- + * 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. + */ + +#include "bdev_pmem.h" +#include "spdk/rpc.h" +#include "spdk/util.h" +#include "spdk/string.h" +#include "libpmemblk.h" + +#include "spdk_internal/log.h" + +struct rpc_construct_pmem { + char *pmem_file; +}; + +static void +free_rpc_construct_pmem_bdev(struct rpc_construct_pmem *req) +{ + free(req->pmem_file); +} + +static const struct spdk_json_object_decoder rpc_construct_pmem_decoders[] = { + {"pmem_file", offsetof(struct rpc_construct_pmem, pmem_file), spdk_json_decode_string}, +}; + +static void +spdk_rpc_construct_pmem_bdev(struct spdk_jsonrpc_request *request, + const struct spdk_json_val *params) +{ + struct rpc_construct_pmem req = {}; + struct spdk_json_write_ctx *w; + struct spdk_bdev *bdev; + char buf[64]; + int rc; + + if (spdk_json_decode_object(params, rpc_construct_pmem_decoders, + SPDK_COUNTOF(rpc_construct_pmem_decoders), + &req)) { + SPDK_DEBUGLOG(SPDK_TRACE_BDEV_PMEM, "spdk_json_decode_object failed\n"); + rc = EINVAL; + goto invalid; + } + rc = spdk_create_pmem_disk(req.pmem_file, &bdev); + if (rc != 0) { + goto invalid; + } + if (bdev == NULL) { + goto invalid; + } + + w = spdk_jsonrpc_begin_result(request); + if (w == NULL) { + free_rpc_construct_pmem_bdev(&req); + return; + } + + spdk_json_write_array_begin(w); + spdk_json_write_string(w, spdk_bdev_get_name(bdev)); + spdk_json_write_array_end(w); + spdk_jsonrpc_end_result(request, w); + + free_rpc_construct_pmem_bdev(&req); + + return; + +invalid: + spdk_strerror_r(rc, buf, sizeof(buf)); + spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, buf); + free_rpc_construct_pmem_bdev(&req); +} +SPDK_RPC_REGISTER("construct_pmem_bdev", spdk_rpc_construct_pmem_bdev) diff --git a/mk/spdk.common.mk b/mk/spdk.common.mk index 6ba889228..35423aaac 100644 --- a/mk/spdk.common.mk +++ b/mk/spdk.common.mk @@ -87,6 +87,12 @@ LIBS += -L/usr/local/lib COMMON_CFLAGS += -I/usr/local/include endif +# Attach only if NVML lib specified with configure +ifneq ($(CONFIG_NVML_DIR),) +LIBS += -L$(CONFIG_NVML_DIR)/src/nondebug +COMMON_CFLAGS += -I$(CONFIG_NVML_DIR)/src/include +endif + ifeq ($(CONFIG_DEBUG), y) COMMON_CFLAGS += -DDEBUG -O0 else diff --git a/mk/spdk.modules.mk b/mk/spdk.modules.mk index bc1e8c062..85185a798 100644 --- a/mk/spdk.modules.mk +++ b/mk/spdk.modules.mk @@ -50,6 +50,11 @@ BLOCKDEV_MODULES_LIST += bdev_rbd BLOCKDEV_MODULES_DEPS += -lrados -lrbd endif +ifeq ($(CONFIG_NVML),y) +BLOCKDEV_MODULES_LIST += bdev_pmem +BLOCKDEV_MODULES_DEPS += -lpmemblk +endif + COPY_MODULES_LIST = copy_ioat ioat BLOCKDEV_MODULES_LINKER_ARGS = -Wl,--whole-archive \ diff --git a/scripts/autotest_common.sh b/scripts/autotest_common.sh index dfd285781..934b3939d 100755 --- a/scripts/autotest_common.sh +++ b/scripts/autotest_common.sh @@ -26,6 +26,7 @@ fi : ${SPDK_TEST_IOAT=1}; export SPDK_TEST_IOAT : ${SPDK_TEST_EVENT=1}; export SPDK_TEST_EVENT : ${SPDK_TEST_BLOBFS=1}; export SPDK_TEST_BLOBFS +: ${SPDK_TEST_NVML=1}; export SPDK_TEST_NVML : ${SPDK_RUN_ASAN=1}; export SPDK_RUN_ASAN : ${SPDK_RUN_UBSAN=1}; export SPDK_RUN_UBSAN @@ -90,6 +91,10 @@ if [ -f /usr/include/infiniband/verbs.h ]; then config_params+=' --with-rdma' fi +if [ -f /usr/include/libpmemblk.h ]; then + config_params+=' --with-nvml' +fi + if [ -d /usr/src/fio ]; then config_params+=' --with-fio=/usr/src/fio' fi diff --git a/scripts/pkgdep.sh b/scripts/pkgdep.sh index 3062d960a..53b73e63a 100755 --- a/scripts/pkgdep.sh +++ b/scripts/pkgdep.sh @@ -17,6 +17,8 @@ if [ -s /etc/redhat-release ]; then yum install -y numactl-devel # Additional dependencies for building docs yum install -y doxygen mscgen + # Additional dependencies for building nvml based backends + yum install -y libpmemblk-devel || true elif [ -f /etc/debian_version ]; then # Includes Ubuntu, Debian apt-get install -y gcc g++ make libcunit1-dev libaio-dev libssl-dev \ diff --git a/scripts/rpc.py b/scripts/rpc.py index bdbb65b33..9979ae583 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -174,6 +174,14 @@ p.add_argument('block_size', help='Block size for this bdev', type=int) p.set_defaults(func=construct_malloc_bdev) +def construct_pmem_bdev(args): + params = {'pmem_file': args.pmem_file} + print_array(jsonrpc_call('construct_pmem_bdev', params)) + +p = subparsers.add_parser('construct_pmem_bdev', help='Add a bdev with pmem backend') +p.add_argument('pmem_file', help='Path to pmemblk pool file') +p.set_defaults(func=construct_pmem_bdev) + def construct_null_bdev(args): num_blocks = (args.total_size * 1024 * 1024) / args.block_size params = {'name': args.name, 'num_blocks': num_blocks, 'block_size': args.block_size}