bdev: Vbdev Passthru Example
Example showing the basics of a vbdev via a module that implements the main functions, and a few extras, needed for a vbdev. The tests also demonstrate how to configure an application to use a vbdev and an underlying bdev Change-Id: I67bf542143eb6532465cdb6af63c0f2ab7084c0e Signed-off-by: paul luse <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/399768 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
a05f88ff34
commit
2191985125
@ -40,10 +40,9 @@ endif
|
||||
|
||||
C_SRCS = bdev.c part.c scsi_nvme.c
|
||||
C_SRCS-$(CONFIG_VTUNE) += vtune.c
|
||||
|
||||
LIBNAME = bdev
|
||||
|
||||
DIRS-y += error gpt lvol malloc null nvme rpc split
|
||||
DIRS-y += error gpt lvol malloc null nvme passthru rpc split
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
DIRS-y += aio
|
||||
|
42
lib/bdev/passthru/Makefile
Normal file
42
lib/bdev/passthru/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
#
|
||||
# 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 += -I$(SPDK_ROOT_DIR)/lib/bdev/
|
||||
|
||||
C_SRCS = vbdev_passthru.c
|
||||
LIBNAME = vbdev_passthru
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
515
lib/bdev/passthru/vbdev_passthru.c
Executable file
515
lib/bdev/passthru/vbdev_passthru.c
Executable file
@ -0,0 +1,515 @@
|
||||
/*-
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a simple example of a virtual block device module that passes IO
|
||||
* down to a bdev (or bdevs) that its configured to attach to.
|
||||
*/
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
|
||||
#include "spdk/rpc.h"
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/conf.h"
|
||||
#include "spdk/endian.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/io_channel.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
#include "spdk_internal/bdev.h"
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
|
||||
static int vbdev_passthru_init(void);
|
||||
static void vbdev_passthru_get_spdk_running_config(FILE *fp);
|
||||
static int vbdev_passthru_get_ctx_size(void);
|
||||
static void vbdev_passthru_examine(struct spdk_bdev *bdev);
|
||||
static void vbdev_passthru_finish(void);
|
||||
|
||||
static struct spdk_bdev_module passthru_if = {
|
||||
.name = "passthru",
|
||||
.module_init = vbdev_passthru_init,
|
||||
.config_text = vbdev_passthru_get_spdk_running_config,
|
||||
.get_ctx_size = vbdev_passthru_get_ctx_size,
|
||||
.examine = vbdev_passthru_examine,
|
||||
.module_fini = vbdev_passthru_finish
|
||||
};
|
||||
|
||||
SPDK_BDEV_MODULE_REGISTER(&passthru_if)
|
||||
|
||||
/* List of pt_bdev names and their base bdevs via configuration file.
|
||||
* Used so we can parse the conf once at init and use this list in examine().
|
||||
*/
|
||||
struct bdev_names {
|
||||
char *vbdev_name;
|
||||
char *bdev_name;
|
||||
TAILQ_ENTRY(bdev_names) link;
|
||||
};
|
||||
static TAILQ_HEAD(, bdev_names) g_bdev_names = TAILQ_HEAD_INITIALIZER(g_bdev_names);
|
||||
|
||||
/* List of virtual bdevs and associated info for each. */
|
||||
struct vbdev_passthru {
|
||||
struct spdk_bdev *base_bdev; /* the thing we're attaching to */
|
||||
struct spdk_bdev_desc *base_desc; /* its descriptor we get from open */
|
||||
struct spdk_bdev pt_bdev; /* the PT virtual bdev */
|
||||
TAILQ_ENTRY(vbdev_passthru) link;
|
||||
};
|
||||
static TAILQ_HEAD(, vbdev_passthru) g_pt_nodes = TAILQ_HEAD_INITIALIZER(g_pt_nodes);
|
||||
|
||||
/* The pt vbdev channel struct. It is allocated and freed on my behalf by the io channel code.
|
||||
* If this vbdev needed to implement a poller or a queue for IO, this is where those things
|
||||
* would be defined. This passthru bdev doesn't actually need to allocate a channel, it could
|
||||
* simply pass back the channel of the bdev underneath it but for example purposes we will
|
||||
* present its own to the upper layers.
|
||||
*/
|
||||
struct pt_io_channel {
|
||||
struct spdk_io_channel *base_ch; /* IO channel of base device */
|
||||
};
|
||||
|
||||
/* Just for fun, this pt_bdev module doesn't need it but this is essentially a per IO
|
||||
* context that we get handed by the bdev layer.
|
||||
*/
|
||||
struct passthru_bdev_io {
|
||||
uint8_t test;
|
||||
};
|
||||
|
||||
/* Called after we've unregistered following a hot remove callback.
|
||||
* Our finish entry point will be called next.
|
||||
*/
|
||||
static int
|
||||
vbdev_passthru_destruct(void *ctx)
|
||||
{
|
||||
struct vbdev_passthru *pt_node = (struct vbdev_passthru *)ctx;
|
||||
|
||||
/* Unclaim the underlying bdev. */
|
||||
spdk_bdev_module_release_bdev(pt_node->base_bdev);
|
||||
|
||||
/* Close the underlying bdev. */
|
||||
spdk_bdev_close(pt_node->base_desc);
|
||||
|
||||
/* Done with this pt_node. */
|
||||
TAILQ_REMOVE(&g_pt_nodes, pt_node, link);
|
||||
free(pt_node->pt_bdev.name);
|
||||
free(pt_node);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Completion callback for IO that were issued from this bdev. The original bdev_io
|
||||
* is passed in as an arg so we'll complete that one with the appropriate status
|
||||
* and then free the one that this module issued.
|
||||
*/
|
||||
static void
|
||||
_pt_complete_io(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
|
||||
{
|
||||
struct spdk_bdev_io *orig_io = cb_arg;
|
||||
int status = success ? SPDK_BDEV_IO_STATUS_SUCCESS : SPDK_BDEV_IO_STATUS_FAILED;
|
||||
struct passthru_bdev_io *io_ctx = (struct passthru_bdev_io *)orig_io->driver_ctx;
|
||||
|
||||
/* We setup this value in the submission routine, just showing here that it is
|
||||
* passed back to us.
|
||||
*/
|
||||
if (io_ctx->test != 0x5a) {
|
||||
SPDK_ERRLOG("Error, original IO device_ctx is wrong! 0x%x\n",
|
||||
io_ctx->test);
|
||||
}
|
||||
|
||||
/* Complete the original IO and then free the one that we created here
|
||||
* as a result of issuing an IO via submit_reqeust.
|
||||
*/
|
||||
spdk_bdev_io_complete(orig_io, status);
|
||||
spdk_bdev_free_io(bdev_io);
|
||||
}
|
||||
|
||||
|
||||
/* Called when someone above submits IO to this pt vbdev. We're simply passing it on here
|
||||
* via SPDK IO calls which in turn allocate another bdev IO and call our cpl callback provided
|
||||
* below along with the original bdiv_io so that we can complete it once this IO completes.
|
||||
*/
|
||||
static void
|
||||
vbdev_passthru_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
struct vbdev_passthru *pt_node = SPDK_CONTAINEROF(bdev_io->bdev, struct vbdev_passthru, pt_bdev);
|
||||
struct pt_io_channel *pt_ch = spdk_io_channel_get_ctx(ch);
|
||||
struct passthru_bdev_io *io_ctx = (struct passthru_bdev_io *)bdev_io->driver_ctx;
|
||||
int rc = 1;
|
||||
|
||||
/* Setup a per IO context value; we don't do anything with it in the vbdev other
|
||||
* than confirm we get the same thing back in the completion callback just to
|
||||
* demonstrate.
|
||||
*/
|
||||
io_ctx->test = 0x5a;
|
||||
|
||||
switch (bdev_io->type) {
|
||||
case SPDK_BDEV_IO_TYPE_READ:
|
||||
rc = spdk_bdev_readv_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs,
|
||||
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.offset_blocks,
|
||||
bdev_io->u.bdev.num_blocks, _pt_complete_io,
|
||||
bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_WRITE:
|
||||
rc = spdk_bdev_writev_blocks(pt_node->base_desc, pt_ch->base_ch, bdev_io->u.bdev.iovs,
|
||||
bdev_io->u.bdev.iovcnt, bdev_io->u.bdev.offset_blocks,
|
||||
bdev_io->u.bdev.num_blocks, _pt_complete_io,
|
||||
bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
||||
rc = spdk_bdev_write_zeroes_blocks(pt_node->base_desc, pt_ch->base_ch,
|
||||
bdev_io->u.bdev.offset_blocks,
|
||||
bdev_io->u.bdev.num_blocks,
|
||||
_pt_complete_io, bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_UNMAP:
|
||||
rc = spdk_bdev_unmap_blocks(pt_node->base_desc, pt_ch->base_ch,
|
||||
bdev_io->u.bdev.offset_blocks,
|
||||
bdev_io->u.bdev.num_blocks,
|
||||
_pt_complete_io, bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_FLUSH:
|
||||
rc = spdk_bdev_flush_blocks(pt_node->base_desc, pt_ch->base_ch,
|
||||
bdev_io->u.bdev.offset_blocks,
|
||||
bdev_io->u.bdev.num_blocks,
|
||||
_pt_complete_io, bdev_io);
|
||||
break;
|
||||
case SPDK_BDEV_IO_TYPE_RESET:
|
||||
rc = spdk_bdev_reset(pt_node->base_desc, pt_ch->base_ch,
|
||||
_pt_complete_io, bdev_io);
|
||||
break;
|
||||
default:
|
||||
SPDK_ERRLOG("passthru: unknown I/O type %d\n", bdev_io->type);
|
||||
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
||||
return;
|
||||
}
|
||||
if (rc != 0) {
|
||||
SPDK_ERRLOG("ERROR on bdev_io submission!\n");
|
||||
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
/* We'll just call the base bdev and let it answer however if we were more
|
||||
* restrictive for some reason (or less) we could get the repsonse back
|
||||
* and modify according to our purposes.
|
||||
*/
|
||||
static bool
|
||||
vbdev_passthru_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
|
||||
{
|
||||
struct vbdev_passthru *pt_node = (struct vbdev_passthru *)ctx;
|
||||
|
||||
return spdk_bdev_io_type_supported(pt_node->base_bdev, io_type);
|
||||
}
|
||||
|
||||
/* We supplied this as an entry point for upper layers who want to communicate to this
|
||||
* bdev. This is how they get a channel. We are passed the same context we provided when
|
||||
* we created our PT vbdev in examine() which, for this bdev, is the address of one of
|
||||
* our context nodes. From here we'll ask the SPDK channel code to fill out our channel
|
||||
* struct and we'll keep it in our PT node.
|
||||
*/
|
||||
static struct spdk_io_channel *
|
||||
vbdev_passthru_get_io_channel(void *ctx)
|
||||
{
|
||||
struct vbdev_passthru *pt_node = (struct vbdev_passthru *)ctx;
|
||||
struct spdk_io_channel *pt_ch = NULL;
|
||||
|
||||
/* The IO channel code will allocate a channel for us which consists of
|
||||
* the SPDK cahnnel structure plus the size of our pt_io_channel struct
|
||||
* that we passed in when we registered our IO device. It will then call
|
||||
* our channel create callback to populate any elements that we need to
|
||||
* update.
|
||||
*/
|
||||
pt_ch = spdk_get_io_channel(pt_node);
|
||||
|
||||
return pt_ch;
|
||||
}
|
||||
|
||||
static int
|
||||
vbdev_passthru_info_config_json(void *ctx, struct spdk_json_write_ctx *write_ctx)
|
||||
{
|
||||
struct vbdev_passthru *pt_node = (struct vbdev_passthru *)ctx;
|
||||
|
||||
/* This is the output for get_bdevs() for this vbdev */
|
||||
spdk_json_write_name(write_ctx, "passthru");
|
||||
spdk_json_write_object_begin(write_ctx);
|
||||
|
||||
spdk_json_write_name(write_ctx, "pt_bdev_name");
|
||||
spdk_json_write_string(write_ctx, spdk_bdev_get_name(&pt_node->pt_bdev));
|
||||
|
||||
spdk_json_write_name(write_ctx, "base_bdev_name");
|
||||
spdk_json_write_string(write_ctx, spdk_bdev_get_name(pt_node->base_bdev));
|
||||
|
||||
spdk_json_write_object_end(write_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We provide this callback for the SPDK channel code to create a channel using
|
||||
* the channel struct we provided in our module get_io_channel() entry point. Here
|
||||
* we get and save off an underlying base channel of the device below us so that
|
||||
* we can communicate with the base bdev on a per channel basis. If we needed
|
||||
* our own poller for this vbdev, we'd register it here.
|
||||
*/
|
||||
static int
|
||||
pt_bdev_ch_create_cb(void *io_device, void *ctx_buf)
|
||||
{
|
||||
struct pt_io_channel *pt_ch = ctx_buf;
|
||||
struct vbdev_passthru *pt_node = io_device;
|
||||
|
||||
pt_ch->base_ch = spdk_bdev_get_io_channel(pt_node->base_desc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We provide this callback for the SPDK channel code to destroy a channel
|
||||
* created with our create callback. We just need to undo anything we did
|
||||
* when we created. If this bdev used its own poller, we'd unregsiter it here.
|
||||
*/
|
||||
static void
|
||||
pt_bdev_ch_destroy_cb(void *io_device, void *ctx_buf)
|
||||
{
|
||||
struct pt_io_channel *pt_ch = ctx_buf;
|
||||
|
||||
spdk_put_io_channel(pt_ch->base_ch);
|
||||
}
|
||||
|
||||
/* On init, just parse config file and build list of pt vbdevs and bdev name pairs. */
|
||||
static int
|
||||
vbdev_passthru_init(void)
|
||||
{
|
||||
struct spdk_conf_section *sp = NULL;
|
||||
const char *conf_bdev_name = NULL;
|
||||
const char *conf_vbdev_name = NULL;
|
||||
struct bdev_names *name;
|
||||
int i;
|
||||
|
||||
sp = spdk_conf_find_section(NULL, "passthru");
|
||||
if (sp != NULL) {
|
||||
for (i = 0; ; i++) {
|
||||
if (!spdk_conf_section_get_nval(sp, "PT", i)) {
|
||||
break;
|
||||
}
|
||||
|
||||
conf_bdev_name = spdk_conf_section_get_nmval(sp, "PT", i, 0);
|
||||
if (!conf_bdev_name) {
|
||||
SPDK_ERRLOG("Passthru configuration missing bdev name\n");
|
||||
break;
|
||||
}
|
||||
|
||||
conf_vbdev_name = spdk_conf_section_get_nmval(sp, "PT", i, 1);
|
||||
if (!conf_vbdev_name) {
|
||||
SPDK_ERRLOG("Passthru configuration missing pt_bdev name\n");
|
||||
break;
|
||||
}
|
||||
|
||||
name = calloc(1, sizeof(struct bdev_names));
|
||||
if (!name) {
|
||||
SPDK_ERRLOG("could not allocate bdev_names\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
name->bdev_name = strdup(conf_bdev_name);
|
||||
if (!name->bdev_name) {
|
||||
SPDK_ERRLOG("could not allocate name->bdev_name\n");
|
||||
free(name);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
name->vbdev_name = strdup(conf_vbdev_name);
|
||||
if (!name->vbdev_name) {
|
||||
SPDK_ERRLOG("could not allocate name->vbdev_name\n");
|
||||
free(name->bdev_name);
|
||||
free(name);
|
||||
return -ENOMEM;
|
||||
}
|
||||
TAILQ_INSERT_TAIL(&g_bdev_names, name, link);
|
||||
}
|
||||
TAILQ_FOREACH(name, &g_bdev_names, link) {
|
||||
SPDK_NOTICELOG("conf parse matched: %s\n", name->bdev_name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Called when the entire module is being torn down. */
|
||||
static void
|
||||
vbdev_passthru_finish(void)
|
||||
{
|
||||
struct bdev_names *name;
|
||||
|
||||
while ((name = TAILQ_FIRST(&g_bdev_names))) {
|
||||
TAILQ_REMOVE(&g_bdev_names, name, link);
|
||||
free(name->bdev_name);
|
||||
free(name->vbdev_name);
|
||||
free(name);
|
||||
}
|
||||
}
|
||||
|
||||
/* During init we'll be asked how much memory we'd like passed to us
|
||||
* in bev_io structures as context. Here's where we specify how
|
||||
* much context we want per IO.
|
||||
*/
|
||||
static int
|
||||
vbdev_passthru_get_ctx_size(void)
|
||||
{
|
||||
return sizeof(struct passthru_bdev_io);
|
||||
}
|
||||
|
||||
/* Called when SPDK wants to save the current config of this vbdev module to
|
||||
* a file.
|
||||
*/
|
||||
static void
|
||||
vbdev_passthru_get_spdk_running_config(FILE *fp)
|
||||
{
|
||||
struct bdev_names *names = NULL;
|
||||
|
||||
fprintf(fp, "\n[passthru]\n");
|
||||
TAILQ_FOREACH(names, &g_bdev_names, link) {
|
||||
fprintf(fp, " PT %s %s ", names->bdev_name, names->vbdev_name);
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
/* When we regsiter our bdev this is how we specify our entry points. */
|
||||
static const struct spdk_bdev_fn_table vbdev_passthru_fn_table = {
|
||||
.destruct = vbdev_passthru_destruct,
|
||||
.submit_request = vbdev_passthru_submit_request,
|
||||
.io_type_supported = vbdev_passthru_io_type_supported,
|
||||
.get_io_channel = vbdev_passthru_get_io_channel,
|
||||
.dump_info_json = vbdev_passthru_info_config_json,
|
||||
};
|
||||
|
||||
/* Called when the underlying base bdev goes away. */
|
||||
static void
|
||||
vbdev_passthru_examine_hotremove_cb(void *ctx)
|
||||
{
|
||||
struct vbdev_passthru *pt_node, *tmp;
|
||||
struct spdk_bdev *bdev_find = ctx;
|
||||
|
||||
TAILQ_FOREACH_SAFE(pt_node, &g_pt_nodes, link, tmp) {
|
||||
if (bdev_find == pt_node->base_bdev) {
|
||||
spdk_bdev_unregister(&pt_node->pt_bdev, NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Because we specified this function in our pt bdev function table when we
|
||||
* registered our pt bdev, we'll get this call anytime a new bdev shows up.
|
||||
* Here we need to decide if we care about it and if so what to do. We
|
||||
* parsed the config file at init so we check the new bdev against the list
|
||||
* we built up at that time and if the user configured us to attach to this
|
||||
* bdev, here's where we do it.
|
||||
*/
|
||||
static void
|
||||
vbdev_passthru_examine(struct spdk_bdev *bdev)
|
||||
{
|
||||
struct bdev_names *name;
|
||||
struct vbdev_passthru *pt_node;
|
||||
int rc;
|
||||
|
||||
/* Check our list of names from config versus this bdev and if
|
||||
* there's a match, create the pt_node & bdev accordingly.
|
||||
*/
|
||||
TAILQ_FOREACH(name, &g_bdev_names, link) {
|
||||
if (strcmp(name->bdev_name, bdev->name) == 0) {
|
||||
SPDK_NOTICELOG("Match on %s\n", bdev->name);
|
||||
pt_node = calloc(1, sizeof(struct vbdev_passthru));
|
||||
if (!pt_node) {
|
||||
SPDK_ERRLOG("could not allocate pt_node\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* The base bdev that we're attaching to. */
|
||||
pt_node->base_bdev = bdev;
|
||||
pt_node->pt_bdev.name = strdup(name->vbdev_name);
|
||||
if (!pt_node->pt_bdev.name) {
|
||||
SPDK_ERRLOG("could not allocate pt_bdev name\n");
|
||||
free(pt_node);
|
||||
return;
|
||||
}
|
||||
pt_node->pt_bdev.product_name = "passthru";
|
||||
|
||||
/* Copy some properties from the underying base bdev. */
|
||||
pt_node->pt_bdev.write_cache = bdev->write_cache;
|
||||
pt_node->pt_bdev.need_aligned_buffer = bdev->need_aligned_buffer;
|
||||
pt_node->pt_bdev.optimal_io_boundary = bdev->optimal_io_boundary;
|
||||
pt_node->pt_bdev.blocklen = bdev->blocklen;
|
||||
pt_node->pt_bdev.blockcnt = bdev->blockcnt;
|
||||
|
||||
/* This is the context that is passed to us when the bdev
|
||||
* layer calls in so we'll save our pt_bdev node here.
|
||||
*/
|
||||
pt_node->pt_bdev.ctxt = pt_node;
|
||||
pt_node->pt_bdev.fn_table = &vbdev_passthru_fn_table;
|
||||
pt_node->pt_bdev.module = &passthru_if;
|
||||
TAILQ_INSERT_TAIL(&g_pt_nodes, pt_node, link);
|
||||
|
||||
spdk_io_device_register(pt_node, pt_bdev_ch_create_cb, pt_bdev_ch_destroy_cb,
|
||||
sizeof(struct pt_io_channel));
|
||||
SPDK_NOTICELOG("io_device created at: 0x%p\n", pt_node);
|
||||
|
||||
rc = spdk_bdev_open(bdev, false, vbdev_passthru_examine_hotremove_cb,
|
||||
bdev, &pt_node->base_desc);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("could not open bdev %s\n", spdk_bdev_get_name(bdev));
|
||||
TAILQ_REMOVE(&g_pt_nodes, pt_node, link);
|
||||
free(pt_node->pt_bdev.name);
|
||||
free(pt_node);
|
||||
return;
|
||||
}
|
||||
SPDK_NOTICELOG("bdev opened\n");
|
||||
|
||||
rc = spdk_bdev_module_claim_bdev(bdev, pt_node->base_desc, pt_node->pt_bdev.module);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("could not claim bdev %s\n", spdk_bdev_get_name(bdev));
|
||||
spdk_bdev_close(pt_node->base_desc);
|
||||
TAILQ_REMOVE(&g_pt_nodes, pt_node, link);
|
||||
free(pt_node->pt_bdev.name);
|
||||
free(pt_node);
|
||||
return;
|
||||
}
|
||||
SPDK_NOTICELOG("bdev claimed\n");
|
||||
|
||||
rc = spdk_vbdev_register(&pt_node->pt_bdev, &bdev, 1);
|
||||
if (rc) {
|
||||
SPDK_ERRLOG("could not register pt_bdev\n");
|
||||
spdk_bdev_close(pt_node->base_desc);
|
||||
TAILQ_REMOVE(&g_pt_nodes, pt_node, link);
|
||||
free(pt_node->pt_bdev.name);
|
||||
free(pt_node);
|
||||
return;
|
||||
}
|
||||
SPDK_NOTICELOG("pt_bdev registered\n");
|
||||
SPDK_NOTICELOG("created pt_bdev for: %s\n", name->vbdev_name);
|
||||
}
|
||||
}
|
||||
spdk_bdev_module_examine_done(&passthru_if);
|
||||
}
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT("vbdev_passthru", SPDK_LOG_VBDEV_PASSTHRU)
|
@ -31,7 +31,7 @@
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
BLOCKDEV_MODULES_LIST = bdev_malloc bdev_null bdev_nvme nvme vbdev_error vbdev_gpt vbdev_lvol vbdev_split
|
||||
BLOCKDEV_MODULES_LIST = bdev_malloc bdev_null bdev_nvme nvme vbdev_passthru vbdev_error vbdev_gpt vbdev_lvol vbdev_split
|
||||
|
||||
# Modules below are added as dependency for vbdev_lvol
|
||||
BLOCKDEV_MODULES_LIST += blob blob_bdev lvol
|
||||
|
@ -1,5 +1,9 @@
|
||||
[passthru]
|
||||
# PT <bdev name> <vbdev name>
|
||||
PT Malloc3 TestPT
|
||||
|
||||
[Malloc]
|
||||
NumberOfLuns 3
|
||||
NumberOfLuns 4
|
||||
LunSizeInMB 64
|
||||
|
||||
[Split]
|
||||
|
Loading…
x
Reference in New Issue
Block a user