diff --git a/include/spdk/bdev.h b/include/spdk/bdev.h index c4eac59c7..e819868e2 100644 --- a/include/spdk/bdev.h +++ b/include/spdk/bdev.h @@ -147,6 +147,8 @@ struct spdk_bdev { /** True if another blockdev or a LUN is using this device */ bool claimed; + + TAILQ_ENTRY(spdk_bdev) link; }; /** @@ -358,6 +360,12 @@ struct spdk_bdev_module_if { /* The following functions are intended to be called from the upper layer * that is using the blockdev layer. */ + +struct spdk_bdev *spdk_bdev_get_by_name(const char *bdev_name); + +struct spdk_bdev *spdk_bdev_first(void); +struct spdk_bdev *spdk_bdev_next(struct spdk_bdev *prev); + struct spdk_bdev_io *spdk_bdev_read(struct spdk_bdev *bdev, void *buf, uint64_t nbytes, uint64_t offset, spdk_bdev_io_completion_cb cb, void *cb_arg); diff --git a/include/spdk/bdev_db.h b/include/spdk/bdev_db.h deleted file mode 100644 index ffa9607dd..000000000 --- a/include/spdk/bdev_db.h +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright (C) 2008-2012 Daisuke Aoyama . - * 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 - * Block device database - */ - -#ifndef SPDK_BDEV_DB_H_ -#define SPDK_BDEV_DB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -struct spdk_bdev; - -int spdk_bdev_db_add(struct spdk_bdev *bdev); -int spdk_bdev_db_delete(struct spdk_bdev *bdev); - -struct spdk_bdev *spdk_bdev_db_get_by_name(const char *bdev_name); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/bdev/Makefile b/lib/bdev/Makefile index a34a566cd..024eb4be9 100644 --- a/lib/bdev/Makefile +++ b/lib/bdev/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk CFLAGS += $(DPDK_INC) -C_SRCS = bdev.c bdev_db.c +C_SRCS = bdev.c LIBNAME = bdev DIRS-y += malloc nvme diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index dfea0f6d5..3e667c214 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -45,7 +45,6 @@ #include #include -#include "spdk/bdev_db.h" #include "spdk/event.h" #include "spdk/log.h" #include "spdk/queue.h" @@ -67,6 +66,36 @@ static TAILQ_HEAD(, spdk_bdev_module_if) spdk_bdev_module_list = static TAILQ_HEAD(, spdk_bdev_module_if) spdk_vbdev_module_list = TAILQ_HEAD_INITIALIZER(spdk_vbdev_module_list); +static TAILQ_HEAD(, spdk_bdev) spdk_bdev_list = + TAILQ_HEAD_INITIALIZER(spdk_bdev_list); + +struct spdk_bdev *spdk_bdev_first(void) +{ + return TAILQ_FIRST(&spdk_bdev_list); +} + +struct spdk_bdev *spdk_bdev_next(struct spdk_bdev *prev) +{ + return TAILQ_NEXT(prev, link); +} + +struct spdk_bdev *spdk_bdev_get_by_name(const char *bdev_name) +{ + struct spdk_bdev *bdev = spdk_bdev_first(); + + while (bdev != NULL) { + if (strncmp(bdev_name, bdev->name, sizeof(bdev->name)) == 0) { + if (!bdev->claimed) { + bdev->claimed = true; + return bdev; + } + } + bdev = spdk_bdev_next(bdev); + } + + return NULL; +} + static void spdk_bdev_io_set_rbuf(struct spdk_bdev_io *bdev_io, void *buf) { @@ -760,7 +789,7 @@ spdk_bdev_register(struct spdk_bdev *bdev) bdev->poller.fn = spdk_bdev_do_work; bdev->poller.arg = bdev; - spdk_bdev_db_add(bdev); + TAILQ_INSERT_TAIL(&spdk_bdev_list, bdev, link); } void @@ -768,7 +797,7 @@ spdk_bdev_unregister(struct spdk_bdev *bdev) { int rc; - spdk_bdev_db_delete(bdev); + TAILQ_REMOVE(&spdk_bdev_list, bdev, link); rc = bdev->fn_table->destruct(bdev->ctxt); if (rc < 0) { diff --git a/lib/bdev/bdev_db.c b/lib/bdev/bdev_db.c deleted file mode 100644 index 294f44b68..000000000 --- a/lib/bdev/bdev_db.c +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * BSD LICENSE - * - * Copyright (C) 2008-2012 Daisuke Aoyama . - * 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/bdev_db.h" - -#include -#include -#include -#include "spdk/bdev.h" -#include "spdk/log.h" - -struct spdk_db_entry { - struct spdk_bdev *bdev; - int claimed; - struct spdk_db_entry *next; -}; - -static struct spdk_db_entry *bdev_list_head = NULL; - -int spdk_bdev_db_add(struct spdk_bdev *bdev) -{ - struct spdk_db_entry *new_entry = calloc(1, sizeof(struct spdk_db_entry)); - - if (!new_entry) { - SPDK_ERRLOG("Failed to allocate DB entry\n"); - return -ENOMEM; - } - - new_entry->bdev = bdev; - new_entry->next = bdev_list_head; - bdev_list_head = new_entry; - - return 0; -} - -int spdk_bdev_db_delete(struct spdk_bdev *bdev) -{ - struct spdk_db_entry *prev = NULL; - struct spdk_db_entry *node = bdev_list_head; - - while (node != NULL) { - if (node->bdev == bdev) { - if (prev != NULL) { - prev->next = node->next; - } else { - bdev_list_head = node->next; - } - free(node); - break; - } - prev = node; - node = node->next; - } - - return 0; -} - -struct spdk_bdev *spdk_bdev_db_get_by_name(const char *bdev_name) -{ - struct spdk_db_entry *current = bdev_list_head; - - while (current != NULL) { - struct spdk_bdev *bdev = current->bdev; - - if (strncmp(bdev_name, bdev->name, sizeof(bdev->name)) == 0) { - current->claimed++; - return bdev; - } - - current = current->next; - } - - return NULL; -} diff --git a/lib/scsi/dev.c b/lib/scsi/dev.c index a1c269b73..c5378bbf0 100644 --- a/lib/scsi/dev.c +++ b/lib/scsi/dev.c @@ -165,7 +165,7 @@ spdk_scsi_dev_construct(const char *name, char *lun_name_list[], int *lun_id_lis dev->maxlun = 0; for (i = 0; i < num_luns; i++) { - bdev = spdk_bdev_db_get_by_name(lun_name_list[i]); + bdev = spdk_bdev_get_by_name(lun_name_list[i]); if (bdev == NULL) { free_dev(dev); return NULL; diff --git a/lib/scsi/scsi_internal.h b/lib/scsi/scsi_internal.h index bc0ef8867..4d69cf7a4 100644 --- a/lib/scsi/scsi_internal.h +++ b/lib/scsi/scsi_internal.h @@ -50,7 +50,6 @@ #include #include "spdk/bdev.h" -#include "spdk/bdev_db.h" #include "spdk/log.h" #include "spdk/scsi.h" #include "spdk/scsi_spec.h" diff --git a/test/lib/bdev/bdevio/bdevio.c b/test/lib/bdev/bdevio/bdevio.c index 6af44a1be..27dfd8bac 100644 --- a/test/lib/bdev/bdevio/bdevio.c +++ b/test/lib/bdev/bdevio/bdevio.c @@ -43,7 +43,6 @@ #include #include "spdk/bdev.h" -#include "spdk/bdev_db.h" #include "spdk/copy_engine.h" #include "spdk/log.h" @@ -64,15 +63,14 @@ struct io_target *g_io_targets = NULL; static int bdevio_construct_targets(void) { - struct blockdev_entry *bdev_entry = g_bdevs; struct spdk_bdev *bdev; struct io_target *target; - while (bdev_entry != NULL) { - bdev = bdev_entry->bdev; + bdev = spdk_bdev_first(); + while (bdev != NULL) { if (bdev->claimed) { - bdev_entry = bdev_entry->next; + bdev = spdk_bdev_next(bdev); continue; } @@ -83,7 +81,8 @@ bdevio_construct_targets(void) target->bdev = bdev; target->next = g_io_targets; g_io_targets = target; - bdev_entry = bdev_entry->next; + + bdev = spdk_bdev_next(bdev); } return 0; @@ -114,14 +113,14 @@ static int check_io_completion(void) { int rc; - struct blockdev_entry *bdev_entry; + struct spdk_bdev *bdev; rc = 0; while (!complete) { - bdev_entry = g_bdevs; - while (bdev_entry != NULL) { - spdk_bdev_do_work(bdev_entry->bdev); - bdev_entry = bdev_entry->next; + bdev = spdk_bdev_first(); + while (bdev != NULL) { + spdk_bdev_do_work(bdev); + bdev = spdk_bdev_next(bdev); } spdk_event_queue_run_all(rte_lcore_id()); } diff --git a/test/lib/bdev/bdevperf/bdevperf.c b/test/lib/bdev/bdevperf/bdevperf.c index a9148f4da..6cc9da36a 100644 --- a/test/lib/bdev/bdevperf/bdevperf.c +++ b/test/lib/bdev/bdevperf/bdevperf.c @@ -48,7 +48,6 @@ #include #include "spdk/bdev.h" -#include "spdk/bdev_db.h" #include "spdk/copy_engine.h" #include "spdk/log.h" @@ -115,21 +114,20 @@ static void bdevperf_construct_targets(void) { int index = 0; - struct blockdev_entry *bdev_entry = g_bdevs; struct spdk_bdev *bdev; struct io_target *target; - while (bdev_entry != NULL) { - bdev = bdev_entry->bdev; + bdev = spdk_bdev_first(); + while (bdev != NULL) { if (bdev->claimed) { - bdev_entry = bdev_entry->next; + bdev = spdk_bdev_next(bdev); continue; } if (g_unmap && !bdev->thin_provisioning) { printf("Skipping %s because it does not support unmap\n", bdev->name); - bdev_entry = bdev_entry->next; + bdev = spdk_bdev_next(bdev); continue; } @@ -159,7 +157,8 @@ bdevperf_construct_targets(void) head[index] = target; g_target_count++; - bdev_entry = bdev_entry->next; + + bdev = spdk_bdev_next(bdev); } } @@ -665,11 +664,6 @@ main(int argc, char **argv) bdevperf_construct_targets(); - if (g_bdevs == NULL) { - printf("No blockdevs available.\n"); - return 1; - } - task_pool = rte_mempool_create("task_pool", 4096 * spdk_app_get_core_count(), sizeof(struct bdevperf_task), 64, 0, NULL, NULL, task_ctor, NULL, diff --git a/test/lib/bdev/common.c b/test/lib/bdev/common.c index c7b45285b..63453deb7 100644 --- a/test/lib/bdev/common.c +++ b/test/lib/bdev/common.c @@ -36,52 +36,6 @@ #include "spdk/event.h" -struct blockdev_entry { - struct spdk_bdev *bdev; - struct blockdev_entry *next; -}; - -struct blockdev_entry *g_bdevs = NULL; - -int -spdk_bdev_db_add(struct spdk_bdev *bdev) -{ - struct blockdev_entry *bdev_entry = calloc(1, sizeof(struct blockdev_entry)); - - if (bdev_entry == NULL) { - return -ENOMEM; - } - - bdev_entry->bdev = bdev; - - bdev_entry->next = g_bdevs; - g_bdevs = bdev_entry; - - return 0; -} - -int -spdk_bdev_db_delete(struct spdk_bdev *bdev) -{ - /* Deleting is not important */ - return 0; -} - -struct spdk_bdev * -spdk_bdev_db_get_by_name(const char *bdev_name) -{ - struct blockdev_entry *bdev_entry = g_bdevs; - - while (bdev_entry != NULL) { - if (strcmp(bdev_name, bdev_entry->bdev->name) == 0) { - return bdev_entry->bdev; - } - bdev_entry = bdev_entry->next; - } - - return NULL; -} - static void bdevtest_init(const char *config_file, const char *cpumask) { diff --git a/test/lib/scsi/dev/dev_ut.c b/test/lib/scsi/dev/dev_ut.c index cca8f75cf..ad5cca8df 100644 --- a/test/lib/scsi/dev/dev_ut.c +++ b/test/lib/scsi/dev/dev_ut.c @@ -83,7 +83,7 @@ spdk_scsi_lun_construct(const char *name, struct spdk_bdev *bdev) } struct spdk_bdev * -spdk_bdev_db_get_by_name(const char *bdev_name) +spdk_bdev_get_by_name(const char *bdev_name) { snprintf(g_bdev.name, sizeof(g_bdev.name), "%s", bdev_name); return &g_bdev;