bdev: add public function spdk_bdev_nvme_create().

Add public function which could be used by rpc method.

Change-Id: Id9d2938801e0acdf0f9827ef2990a54c75aec22a
Signed-off-by: Cunyin Chang <cunyin.chang@intel.com>
This commit is contained in:
Cunyin Chang 2016-10-10 11:54:38 +08:00
parent 0af0aa4b2e
commit 1fad9da400
2 changed files with 70 additions and 23 deletions

View File

@ -32,8 +32,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "blockdev_nvme.h"
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
@ -51,8 +52,6 @@
#include "bdev_module.h"
#define MAX_NVME_NAME_LENGTH 64
static void blockdev_nvme_get_spdk_running_config(FILE *fp);
struct nvme_device {
@ -93,16 +92,7 @@ enum data_direction {
BDEV_DISK_WRITE = 1
};
struct nvme_bdf_whitelist {
uint16_t domain;
uint8_t bus;
uint8_t dev;
uint8_t func;
char name[MAX_NVME_NAME_LENGTH];
};
#define NVME_MAX_BLOCKDEVS_PER_CONTROLLER 256
#define NVME_MAX_CONTROLLERS 16
#define NVME_MAX_BLOCKDEVS (NVME_MAX_BLOCKDEVS_PER_CONTROLLER * NVME_MAX_CONTROLLERS)
static struct nvme_blockdev g_blockdev[NVME_MAX_BLOCKDEVS];
static int blockdev_index_max = 0;
@ -340,12 +330,6 @@ static const struct spdk_bdev_fn_table nvmelib_fn_table = {
.get_io_channel = blockdev_nvme_get_io_channel,
};
struct nvme_probe_ctx {
int controllers_remaining;
int num_whitelist_controllers;
struct nvme_bdf_whitelist whitelist[NVME_MAX_CONTROLLERS];
};
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr_opts *opts)
{
@ -416,6 +400,14 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr
}
}
int
spdk_bdev_nvme_create(struct nvme_probe_ctx *ctx)
{
if (spdk_nvme_probe(ctx, probe_cb, attach_cb, NULL)) {
return -1;
}
return 0;
}
static int
nvme_library_init(void)
@ -498,11 +490,7 @@ nvme_library_init(void)
probe_ctx.controllers_remaining = num_controllers;
if (spdk_nvme_probe(&probe_ctx, probe_cb, attach_cb, NULL)) {
return -1;
}
return 0;
return spdk_bdev_nvme_create(&probe_ctx);
}
__attribute__((destructor)) void

View File

@ -0,0 +1,59 @@
/*-
* 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.
*/
#ifndef SPDK_BLOCKDEV_NVME_H
#define SPDK_BLOCKDEV_NVME_H
#include <stdint.h>
#define MAX_NVME_NAME_LENGTH 64
#define NVME_MAX_CONTROLLERS 16
struct nvme_bdf_whitelist {
uint16_t domain;
uint8_t bus;
uint8_t dev;
uint8_t func;
char name[MAX_NVME_NAME_LENGTH];
};
struct nvme_probe_ctx {
int controllers_remaining;
int num_whitelist_controllers;
struct nvme_bdf_whitelist whitelist[NVME_MAX_CONTROLLERS];
};
int
spdk_bdev_nvme_create(struct nvme_probe_ctx *ctx);
#endif // SPDK_BLOCKDEV_NVME_H