diff --git a/test/common/skipped_build_files.txt b/test/common/skipped_build_files.txt index 13443f244..05168c590 100644 --- a/test/common/skipped_build_files.txt +++ b/test/common/skipped_build_files.txt @@ -32,3 +32,5 @@ test/unit/lib/sock/uring.c/uring_ut test/external_code/hello_world/hello_bdev test/external_code/passthru/vbdev_passthru test/external_code/passthru/vbdev_passthru_rpc +test/external_code/nvme/nvme +test/external_code/nvme/identify diff --git a/test/external_code/Makefile b/test/external_code/Makefile index 6da3f62fc..23b705cd2 100644 --- a/test/external_code/Makefile +++ b/test/external_code/Makefile @@ -31,7 +31,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -ALL_DEPDIRS+= hello_world passthru +ALL_DEPDIRS+= hello_world passthru nvme ifneq ($(SPDK_HEADER_DIR),) COMMON_CFLAGS+=-I$(SPDK_HEADER_DIR) @@ -51,9 +51,9 @@ endif export .PHONY: all -all: hello_world_bdev_shared_combo +all: hello_world_bdev_shared_combo nvme_shared -static: hello_world_bdev_static +static: hello_world_bdev_static nvme_static hello_world_bdev_shared_combo: passthru_shared $(MAKE) --directory=hello_world bdev_shared_combo @@ -79,6 +79,13 @@ passthru_shared: passthru_static: $(MAKE) --directory=passthru static +nvme_shared: + $(MAKE) --directory=nvme shared + +nvme_static: + $(MAKE) --directory=nvme static + clean: rm -f ./hello_world/hello_bdev rm -f ./passthru/libpassthru_external.* + rm -f ./nvme/*.{so,o} ./nvme/identify diff --git a/test/external_code/nvme/.gitignore b/test/external_code/nvme/.gitignore new file mode 100644 index 000000000..5c5444c1e --- /dev/null +++ b/test/external_code/nvme/.gitignore @@ -0,0 +1 @@ +identify diff --git a/test/external_code/nvme/Makefile b/test/external_code/nvme/Makefile new file mode 100644 index 000000000..bf1763cc1 --- /dev/null +++ b/test/external_code/nvme/Makefile @@ -0,0 +1,46 @@ +# +# 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. +# + +PKG_CONFIG_PATH = $(SPDK_LIB_DIR)/pkgconfig + +DEPLIBS := $(shell PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --libs spdk_log) + +shared: + $(CC) $(COMMON_CFLAGS) -c -fPIC nvme.c -o nvme.o + $(CC) $(COMMON_CFLAGS) -shared nvme.o -o libnvme_external.so + $(CC) $(COMMON_CFLAGS) identify.c -o identify -L. -lnvme_external \ + -Wl,-rpath=$(SPDK_LIB_DIR) $(DEPLIBS) + +static: + $(CC) $(COMMON_CFLAGS) nvme.c identify.c -o identify -Wl,--whole-archive \ + $(DEPLIBS) -Wl,--no-whole-archive diff --git a/test/external_code/nvme/identify.c b/test/external_code/nvme/identify.c new file mode 100644 index 000000000..0d9272cc2 --- /dev/null +++ b/test/external_code/nvme/identify.c @@ -0,0 +1,51 @@ +/*- + * 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/stdinc.h" +#include "nvme.h" + +int +main(int argc, const char **argv) +{ + int rc; + + (void)argc; + + rc = nvme_probe(NULL, NULL); + if (rc != 0) { + fprintf(stderr, "%s: nvme probe failed\n", argv[0]); + return 1; + } + + return 0; +} diff --git a/test/external_code/nvme/nvme.c b/test/external_code/nvme/nvme.c new file mode 100644 index 000000000..15ec88566 --- /dev/null +++ b/test/external_code/nvme/nvme.c @@ -0,0 +1,53 @@ +/*- + * 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/log.h" +#include "spdk/stdinc.h" +#include "nvme.h" + +int +nvme_probe(nvme_attach_cb attach_cb, void *cb_ctx) +{ + (void)attach_cb; + (void)cb_ctx; + + return -ENOTSUP; +} + +void +nvme_detach(struct nvme_ctrlr *ctrlr) +{ + (void) ctrlr; +} + +SPDK_LOG_REGISTER_COMPONENT(nvme_external) diff --git a/test/external_code/nvme/nvme.h b/test/external_code/nvme/nvme.h new file mode 100644 index 000000000..e3bfff7dc --- /dev/null +++ b/test/external_code/nvme/nvme.h @@ -0,0 +1,71 @@ +/*- + * 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 EXTERNAL_NVME_H +#define EXTERNAL_NVME_H + +#include "spdk/env.h" + +struct nvme_ctrlr; + +/** + * Callback for nvme_probe() to report a device that has been attached to + * the userspace NVMe driver. + * + * \param cb_ctx Opaque value passed to spdk_nvme_attach_cb(). + * \param addr NVMe PCI address. + * \param ctrlr Opaque handle to NVMe controller. + */ +typedef void (*nvme_attach_cb)(void *cb_ctx, const struct spdk_pci_addr *addr, + struct nvme_ctrlr *ctrlr); + +/** + * Enumerate PCIe bus and attach all NVMe devices found to the driver. + * + * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of + * the callbacks. + * \param attach_cb will be called for each NVMe device found + * + * \return 0 on success, negative errno on failure. + */ +int nvme_probe(nvme_attach_cb attach_cb, void *ctx); + +/** + * Detach specified device returned by nvme_probe()'s attach_cb. After returning + * the nvme_ctrlr handle is no longer valid. + * + * \param ctrlr Opaque handle to NVMe controller. + */ +void nvme_detach(struct nvme_ctrlr *ctrlr); + +#endif /* EXTERNAL_NVME_H */