96 lines
2.1 KiB
C++
96 lines
2.1 KiB
C++
#include <sys/endian.h>
|
|
#include "storage/drivers/bdev.hh"
|
|
#include "ntr.h"
|
|
#include "spdk/bdev.h"
|
|
#include "spdk/thread.h"
|
|
|
|
size_t
|
|
birb_bdev_driver::get_capacity()
|
|
{
|
|
return block_num * block_sz;
|
|
}
|
|
|
|
birb_driver::birb_driver_status
|
|
birb_bdev_driver::get_status()
|
|
{
|
|
return this->status;
|
|
}
|
|
|
|
void
|
|
birb_bdev_driver::bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev * bdev UNUSED,
|
|
void * event_ctx UNUSED)
|
|
{
|
|
ntr(NTR_DEP_USER1, NTR_LEVEL_WARNING, "bdev_event_cb: unsupported bdev event: type %d\n", type);
|
|
}
|
|
|
|
void
|
|
birb_bdev_driver::print_all_bdev()
|
|
{
|
|
struct spdk_bdev * cur = spdk_bdev_first();
|
|
|
|
ntr(NTR_DEP_USER1, NTR_LEVEL_INFO, "birb_bdev_driver: all registered block devices: ");
|
|
|
|
while(cur != NULL) {
|
|
ntr(NTR_DEP_USER1, NTR_LEVEL_INFO, "%s, ", spdk_bdev_get_name(cur));
|
|
cur = spdk_bdev_next(cur);
|
|
}
|
|
}
|
|
|
|
birb_bdev_driver::birb_bdev_driver(const char * dev_name) : bdev_desc(nullptr),
|
|
bdev(nullptr),
|
|
block_sz(0),
|
|
block_num(0),
|
|
status(BIRB_FAIL)
|
|
{
|
|
int rc;
|
|
|
|
rc = spdk_bdev_open_ext(dev_name, true, birb_bdev_driver::bdev_event_cb, NULL, &this->bdev_desc);
|
|
|
|
if (rc != 0) {
|
|
ntr(NTR_DEP_USER1, NTR_LEVEL_ERROR, "birb_bdev_driver: failed to open bdev: %d\n", rc);
|
|
return;
|
|
}
|
|
|
|
/* A bdev pointer is valid while the bdev is opened. */
|
|
this->bdev = spdk_bdev_desc_get_bdev(this->bdev_desc);
|
|
this->block_sz = spdk_bdev_get_block_size(this->bdev);
|
|
this->block_num = spdk_bdev_get_num_blocks(this->bdev);
|
|
|
|
ntr(NTR_DEP_USER1, NTR_LEVEL_INFO, "birb_bdev_driver: bdev block size %zu bytes, blocks count %zu\n", this->block_sz, this->block_num);
|
|
|
|
this->status = BIRB_SUCCESS;
|
|
}
|
|
|
|
birb_bdev_driver::~birb_bdev_driver()
|
|
{
|
|
if (this->status == BIRB_SUCCESS) {
|
|
spdk_bdev_close(this->bdev_desc);
|
|
}
|
|
}
|
|
|
|
birb_driver::birb_driver_type
|
|
birb_bdev_driver::get_type()
|
|
{
|
|
return BIRB_DRV_BDEV;
|
|
}
|
|
|
|
size_t
|
|
birb_bdev_driver::get_align()
|
|
{
|
|
return spdk_bdev_get_buf_align(this->bdev);
|
|
}
|
|
|
|
|
|
struct spdk_bdev *
|
|
birb_bdev_driver::get_bdev()
|
|
{
|
|
return this->bdev;
|
|
}
|
|
|
|
|
|
struct spdk_bdev_desc *
|
|
birb_bdev_driver::get_bdev_desc()
|
|
{
|
|
return this->bdev_desc;
|
|
}
|