Commit e648950f authored by Ben Walker's avatar Ben Walker
Browse files

bdev: Delete bdev_db



Combine the necessary functionality with the main bdev file.

Change-Id: I96d796bc87ac2a8688cdf1fd3c16d2a7c8aef730
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
parent d054c97e
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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);

include/spdk/bdev_db.h

deleted100644 → 0
+0 −57
Original line number Diff line number Diff line
/*-
 *   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
+1 −1
Original line number Diff line number Diff line
@@ -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
+32 −3
Original line number Diff line number Diff line
@@ -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) {

lib/bdev/bdev_db.c

deleted100644 → 0
+0 −105
Original line number Diff line number Diff line
/*-
 *   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;
}
Loading