diff --git a/include/spdk/nbd.h b/include/spdk/nbd.h index 9df8b4d60..d823e559b 100644 --- a/include/spdk/nbd.h +++ b/include/spdk/nbd.h @@ -37,6 +37,10 @@ struct spdk_bdev; struct spdk_nbd_disk; +int spdk_nbd_init(void); + +void spdk_nbd_fini(void); + struct spdk_nbd_disk *spdk_nbd_start(const char *bdev_name, const char *nbd_path); void spdk_nbd_stop(struct spdk_nbd_disk *nbd); diff --git a/lib/event/subsystems/Makefile b/lib/event/subsystems/Makefile index d47b2c31d..4e1f55000 100644 --- a/lib/event/subsystems/Makefile +++ b/lib/event/subsystems/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -DIRS-y += bdev copy iscsi net scsi vhost +DIRS-y += bdev copy iscsi nbd net scsi vhost .PHONY: all clean $(DIRS-y) diff --git a/lib/event/subsystems/nbd/Makefile b/lib/event/subsystems/nbd/Makefile new file mode 100644 index 000000000..0c678e77c --- /dev/null +++ b/lib/event/subsystems/nbd/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. +C_SRCS = nbd.c +LIBNAME = event_nbd + +include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk diff --git a/lib/event/subsystems/nbd/nbd.c b/lib/event/subsystems/nbd/nbd.c new file mode 100644 index 000000000..d7820550f --- /dev/null +++ b/lib/event/subsystems/nbd/nbd.c @@ -0,0 +1,58 @@ +/*- + * 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 "spdk/nbd.h" + +#include "spdk_internal/event.h" + +static void +spdk_nbd_subsystem_init(void) +{ + int rc; + + rc = spdk_nbd_init(); + + spdk_subsystem_init_next(rc); +} + +static void +spdk_nbd_subsystem_fini(void) +{ + spdk_nbd_fini(); + spdk_subsystem_fini_next(); +} + +SPDK_SUBSYSTEM_REGISTER(nbd, spdk_nbd_subsystem_init, spdk_nbd_subsystem_fini, NULL) +SPDK_SUBSYSTEM_DEPEND(nbd, bdev) diff --git a/lib/nbd/nbd.c b/lib/nbd/nbd.c index a25658076..5768c8ffd 100644 --- a/lib/nbd/nbd.c +++ b/lib/nbd/nbd.c @@ -79,6 +79,25 @@ struct spdk_nbd_disk { uint32_t buf_align; }; +struct spdk_nbd_disk_globals { + TAILQ_HEAD(, spdk_nbd_disk) disk_head; +}; + +static struct spdk_nbd_disk_globals g_spdk_nbd; + +int +spdk_nbd_init(void) +{ + TAILQ_INIT(&g_spdk_nbd.disk_head); + + return 0; +} + +void +spdk_nbd_fini(void) +{ +} + static bool is_read(enum spdk_bdev_io_type io_type) { diff --git a/test/lib/bdev/nbd/Makefile b/test/lib/bdev/nbd/Makefile index dff27aeb3..6e7a0722e 100644 --- a/test/lib/bdev/nbd/Makefile +++ b/test/lib/bdev/nbd/Makefile @@ -42,8 +42,8 @@ C_SRCS := nbd.c CFLAGS += -I. $(ENV_CFLAGS) -SPDK_LIB_LIST = event_bdev event_copy nbd -SPDK_LIB_LIST += bdev bdev_rpc copy event trace log log_rpc conf util rpc jsonrpc json +SPDK_LIB_LIST = event_bdev event_copy event_nbd +SPDK_LIB_LIST += bdev bdev_rpc copy event trace log log_rpc conf util rpc jsonrpc json nbd LIBS += $(BLOCKDEV_MODULES_LINKER_ARGS) \ $(COPY_MODULES_LINKER_ARGS)