vitastor/fio_engine.cpp

258 lines
6.4 KiB
C++
Raw Normal View History

2019-11-25 02:31:48 +03:00
// FIO engine to test Blockstore
#include "blockstore.h"
2019-11-26 00:02:54 +03:00
extern "C" {
#define CONFIG_PWRITEV2
#include "fio/fio.h"
#include "fio/optgroup.h"
}
2019-11-25 02:31:48 +03:00
struct bs_data
{
blockstore *bs;
ring_loop_t *ringloop;
/* The list of completed io_u structs. */
2019-11-25 22:35:44 +03:00
std::vector<io_u*> completed;
2019-11-25 02:31:48 +03:00
};
struct bs_options
{
char *data_device, *meta_device, *journal_device;
};
static struct fio_option options[] = {
{
.name = "data_device",
.lname = "Data device",
2019-11-26 00:02:54 +03:00
.type = FIO_OPT_STR_STORE,
.off1 = offsetof(struct bs_options, data_device),
2019-11-25 02:31:48 +03:00
.help = "Name of the data device",
.category = FIO_OPT_C_ENGINE,
.group = FIO_OPT_G_FILENAME,
},
{
.name = NULL,
},
};
static int bs_setup(struct thread_data *td)
{
bs_data *bsd;
2019-11-26 00:02:54 +03:00
bs_options *o = (bs_options*)td->eo;
2019-11-25 02:31:48 +03:00
fio_file *f;
int r;
//int64_t size;
bsd = (bs_data*)calloc(1, sizeof(*bsd));
if (!bsd)
{
td_verror(td, errno, "calloc");
return 1;
}
td->io_ops_data = bsd;
if (!td->files_index)
{
add_file(td, "blockstore", 0, 0);
td->o.nr_files = td->o.nr_files ? : 1;
td->o.open_files++;
}
f = td->files[0];
//f->real_file_size = size;
return 0;
}
static void bs_cleanup(struct thread_data *td)
{
2019-11-26 00:02:54 +03:00
bs_data *bsd = (bs_data*)td->io_ops_data;
2019-11-25 02:31:48 +03:00
if (bsd)
{
2019-11-26 00:02:54 +03:00
free(bsd);
2019-11-25 02:31:48 +03:00
}
}
/* Connect to the server from each thread. */
static int bs_init(struct thread_data *td)
{
2019-11-26 00:02:54 +03:00
bs_options *o = (bs_options*)td->eo;
bs_data *bsd = (bs_data*)td->io_ops_data;
2019-11-25 02:31:48 +03:00
int r;
spp::sparse_hash_map<std::string, std::string> config;
config["meta_device"] = "./test_meta.bin";
config["journal_device"] = "./test_journal.bin";
config["data_device"] = "./test_data.bin";
bsd->ringloop = new ring_loop_t(512);
2019-11-26 00:02:54 +03:00
bsd->bs = new blockstore(config, bsd->ringloop);
2019-11-25 02:31:48 +03:00
while (!bsd->bs->is_started())
{
bsd->ringloop->loop();
}
log_info("fio: blockstore initialized\n");
return 0;
}
/* Begin read or write request. */
static enum fio_q_status bs_queue(struct thread_data *td, struct io_u *io_u)
{
2019-11-26 00:02:54 +03:00
bs_data *bsd = (bs_data*)td->io_ops_data;
2019-11-25 02:31:48 +03:00
fio_ro_check(td, io_u);
io_u->engine_data = bsd;
if (io_u->ddir == DDIR_WRITE || io_u->ddir == DDIR_READ)
2019-11-26 00:02:54 +03:00
assert(io_u->xfer_buflen <= bsd->bs->block_size);
2019-11-25 02:31:48 +03:00
2019-11-25 22:35:44 +03:00
blockstore_operation *op = new blockstore_operation;
switch (io_u->ddir)
{
2019-11-25 02:31:48 +03:00
case DDIR_READ:
2019-11-25 22:35:44 +03:00
op->flags = OP_READ;
op->buf = io_u->xfer_buf;
op->oid = {
.inode = 1,
2019-11-26 00:02:54 +03:00
.stripe = io_u->offset >> bsd->bs->block_order,
2019-11-25 22:35:44 +03:00
};
2019-11-26 00:02:54 +03:00
op->offset = io_u->offset % bsd->bs->block_size;
2019-11-25 22:35:44 +03:00
op->len = io_u->xfer_buflen;
op->callback = [&](blockstore_operation *op)
{
bsd->completed.push_back(io_u);
delete op;
};
2019-11-25 02:31:48 +03:00
break;
case DDIR_WRITE:
2019-11-25 22:35:44 +03:00
op->flags = OP_WRITE;
op->buf = io_u->xfer_buf;
op->oid = {
.inode = 1,
2019-11-26 00:02:54 +03:00
.stripe = io_u->offset >> bsd->bs->block_order,
2019-11-25 22:35:44 +03:00
};
2019-11-26 00:02:54 +03:00
op->offset = io_u->offset % bsd->bs->block_size;
2019-11-25 22:35:44 +03:00
op->len = io_u->xfer_buflen;
op->callback = [&](blockstore_operation *op)
{
bsd->completed.push_back(io_u);
delete op;
};
2019-11-25 02:31:48 +03:00
break;
case DDIR_SYNC:
2019-11-25 22:35:44 +03:00
op->flags = OP_SYNC;
op->callback = [&](blockstore_operation *op)
{
if (bsd->bs->unstable_writes.size() > 0)
{
op->flags = OP_STABLE;
op->len = bsd->bs->unstable_writes.size();
2019-11-26 00:02:54 +03:00
obj_ver_id *vers = new obj_ver_id[op->len];
op->buf = vers;
2019-11-25 22:35:44 +03:00
int i = 0;
for (auto it = bsd->bs->unstable_writes.begin(); it != bsd->bs->unstable_writes.end(); it++, i++)
{
2019-11-26 00:02:54 +03:00
vers[i] = {
2019-11-25 22:35:44 +03:00
.oid = it->first,
.version = it->second,
};
}
bsd->bs->enqueue_op(op);
op->callback = [&](blockstore_operation *op)
{
bsd->completed.push_back(io_u);
2019-11-26 00:02:54 +03:00
obj_ver_id *vers = (obj_ver_id*)op->buf;
delete[] vers;
2019-11-25 22:35:44 +03:00
delete op;
};
}
else
{
bsd->completed.push_back(io_u);
delete op;
}
};
2019-11-25 02:31:48 +03:00
break;
default:
io_u->error = EINVAL;
return FIO_Q_COMPLETED;
}
2019-11-25 22:35:44 +03:00
bsd->bs->enqueue_op(op);
2019-11-25 02:31:48 +03:00
io_u->error = 0;
return FIO_Q_QUEUED;
}
static int bs_getevents(struct thread_data *td, unsigned int min, unsigned int max, const struct timespec *t)
{
2019-11-26 00:02:54 +03:00
bs_data *bsd = (bs_data*)td->io_ops_data;
2019-11-25 22:35:44 +03:00
// FIXME timeout
while (bsd->completed.size() < min)
{
bsd->ringloop->loop();
2019-11-25 02:31:48 +03:00
}
2019-11-25 22:35:44 +03:00
return bsd->completed.size();
2019-11-25 02:31:48 +03:00
}
static struct io_u *bs_event(struct thread_data *td, int event)
{
2019-11-26 00:02:54 +03:00
bs_data *bsd = (bs_data*)td->io_ops_data;
2019-11-25 22:35:44 +03:00
if (bsd->completed.size() == 0)
2019-11-25 02:31:48 +03:00
return NULL;
2019-11-25 22:35:44 +03:00
/* FIXME We ignore the event number and assume fio calls us exactly once for [0..nr_events-1] */
struct io_u *ev = bsd->completed.back();
bsd->completed.pop_back();
return ev;
2019-11-25 02:31:48 +03:00
}
static int bs_io_u_init(struct thread_data *td, struct io_u *io_u)
{
io_u->engine_data = NULL;
return 0;
}
static void bs_io_u_free(struct thread_data *td, struct io_u *io_u)
{
}
static int bs_open_file(struct thread_data *td, struct fio_file *f)
{
return 0;
}
static int bs_invalidate(struct thread_data *td, struct fio_file *f)
{
return 0;
}
2019-11-26 00:02:54 +03:00
struct ioengine_ops ioengine = {
2019-11-25 02:31:48 +03:00
.name = "microceph_blockstore",
.version = FIO_IOOPS_VERSION,
.flags = FIO_MEMALIGN | FIO_DISKLESSIO | FIO_NOEXTEND,
.setup = bs_setup,
.init = bs_init,
.queue = bs_queue,
.getevents = bs_getevents,
.event = bs_event,
2019-11-26 00:02:54 +03:00
.cleanup = bs_cleanup,
2019-11-25 02:31:48 +03:00
.open_file = bs_open_file,
.invalidate = bs_invalidate,
2019-11-26 00:02:54 +03:00
.io_u_init = bs_io_u_init,
.io_u_free = bs_io_u_free,
2019-11-25 02:31:48 +03:00
};
static void fio_init fio_bs_register(void)
{
register_ioengine(&ioengine);
}
static void fio_exit fio_bs_unregister(void)
{
unregister_ioengine(&ioengine);
}