numam/storage/drivers/bdev_thread.cc

72 lines
1.8 KiB
C++
Raw Normal View History

2022-03-21 11:43:49 +00:00
#include <sys/endian.h>
2022-03-28 16:47:46 +00:00
#include "storage/drivers/bdev.hh"
2022-03-21 11:43:49 +00:00
#include "ntr.h"
#include "spdk/bdev.h"
#include "spdk/thread.h"
birb_bdev_thread_context::birb_bdev_thread_context(birb_bdev_driver * driver) : io_channel(nullptr),
status(birb_driver::BIRB_FAIL),
driver(driver)
{
struct spdk_bdev_desc * desc = driver->get_bdev_desc();
// obtain io channel
this->io_channel = spdk_bdev_get_io_channel(desc);
if (io_channel == nullptr) {
ntr(NTR_DEP_USER1, NTR_LEVEL_ERROR, "birb_bdev_thread_context: could not create bdev I/O channel!\n");
}
this->status = birb_driver::BIRB_SUCCESS;
}
birb_driver::birb_driver_status
birb_bdev_thread_context::get_status()
{
return this->status;
}
birb_bdev_thread_context::~birb_bdev_thread_context()
{
if (this->io_channel != nullptr) {
spdk_put_io_channel(this->io_channel);
}
}
/*
* Callback function for io completion.
*/
void
birb_bdev_thread_context::io_callback(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
{
spdk_bdev_free_io(bdev_io);
auto ctx = reinterpret_cast<struct cb_context *>(cb_arg);
ctx->cb(success, ctx->ctx);
delete ctx;
}
int
birb_bdev_thread_context::read(size_t offset, size_t size, char * buffer, callback callback, void * context)
{
auto ctx = new struct cb_context;
ctx->cb = callback;
ctx->ctx = context;
return spdk_bdev_read(driver->get_bdev_desc(), this->io_channel, buffer, offset, size, io_callback, reinterpret_cast<void*>(ctx));
}
int
birb_bdev_thread_context::write(size_t offset, size_t size, char * buffer, callback callback, void * context)
{
auto ctx = new struct cb_context;
ctx->cb = callback;
ctx->ctx = context;
return spdk_bdev_write(driver->get_bdev_desc(), this->io_channel, buffer, offset, size, io_callback, reinterpret_cast<void*>(ctx));
2022-03-21 15:01:24 +00:00
}
void
birb_bdev_thread_context::poll()
{
return;
2022-03-21 11:43:49 +00:00
}