bdev: Delete bdev_db

Combine the necessary functionality with the main bdev file.

Change-Id: I96d796bc87ac2a8688cdf1fd3c16d2a7c8aef730
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2016-08-01 14:31:02 -07:00
parent d054c97e65
commit e648950f89
11 changed files with 59 additions and 238 deletions

View File

@ -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);

View File

@ -1,57 +0,0 @@
/*-
* BSD LICENSE
*
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
* 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

View File

@ -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

View File

@ -45,7 +45,6 @@
#include <rte_mempool.h>
#include <rte_version.h>
#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) {

View File

@ -1,105 +0,0 @@
/*-
* BSD LICENSE
*
* Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
* 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 <stdio.h>
#include <stdlib.h>
#include <errno.h>
#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;
}

View File

@ -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;

View File

@ -50,7 +50,6 @@
#include <sys/uio.h>
#include "spdk/bdev.h"
#include "spdk/bdev_db.h"
#include "spdk/log.h"
#include "spdk/scsi.h"
#include "spdk/scsi_spec.h"

View File

@ -43,7 +43,6 @@
#include <rte_ring.h>
#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());
}

View File

@ -48,7 +48,6 @@
#include <rte_timer.h>
#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,

View File

@ -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)
{

View File

@ -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;