-// https://github.com/axboe/fio/pull/762 sample pull req for new engine
#include <stdlib.h>
#include <poll.h>
#include <nfsc/libnfs.h>
struct fio_libnfs_options {
struct nfs_context *context;
char *nfs_url;
- // the following implements a circular queue of outstanding IOs
- int outstanding_events; // IOs issued to libnfs, that have not returned yet
- int prev_requested_event_index; // event last returned via fio_libnfs_event
- int next_buffered_event; // round robin-pointer within events[]
- int buffered_event_count; // IOs completed by libnfs faiting for FIO
- int free_event_buffer_index; // next empty buffer
- unsigned int queue_depth; // nfs_callback needs this info, but doesn't have fio td structure to pull it from
+ unsigned int queue_depth; /* nfs_callback needs this info, but doesn't have fio td structure to pull it from */
+ /* the following implement a circular queue of outstanding IOs */
+ int outstanding_events; /* IOs issued to libnfs, that have not returned yet */
+ int prev_requested_event_index; /* event last returned via fio_libnfs_event */
+ int next_buffered_event; /* round robin-pointer within events[] */
+ int buffered_event_count; /* IOs completed by libnfs, waiting for FIO */
+ int free_event_buffer_index; /* next free buffer */
struct io_u**events;
};
},
};
-/*
- * The ->event() hook is called to match an event number with an io_u.
- * After the core has called ->getevents() and it has returned eg 3,
- * the ->event() hook must return the 3 events that have completed for
- * subsequent calls to ->event() with [0-2]. Required.
- */
static struct io_u *fio_libnfs_event(struct thread_data *td, int event)
{
struct fio_libnfs_options *o = td->eo;
assert(o->events[o->next_buffered_event]);
o->events[o->next_buffered_event] = NULL;
o->next_buffered_event = (o->next_buffered_event + 1) % td->o.iodepth;
- // validate our state machine
+ /* validate our state machine */
assert(o->buffered_event_count);
o->buffered_event_count--;
assert(io_u);
- // assert that fio_libnfs_event is being called in sequential fashion
+ /* assert that fio_libnfs_event is being called in sequential fashion */
assert(event == 0 || o->prev_requested_event_index + 1 == event);
if (o->buffered_event_count == 0) {
o->prev_requested_event_index = -1;
static int nfs_event_loop(struct thread_data *td, bool flush) {
struct fio_libnfs_options *o = td->eo;
struct pollfd pfds[1]; /* nfs:0 */
- // we already have stuff queued for fio, no need to waste cpu on poll()
- if (o->buffered_event_count) {
+ /* we already have stuff queued for fio, no need to waste cpu on poll() */
+ if (o->buffered_event_count)
return o->buffered_event_count;
- }
- // fio core logic seems to stop calling this event-loop if we ever return with 0 events
+ /* fio core logic seems to stop calling this event-loop if we ever return with 0 events */
#define SHOULD_WAIT() (o->outstanding_events == td->o.iodepth || (flush && o->outstanding_events))
do {
}
} while (SHOULD_WAIT());
return o->buffered_event_count;
-}
#undef SHOULD_WAIT
+}
-/*
- * The ->getevents() hook is used to reap completion events from an async
- * io engine. It returns the number of completed events since the last call,
- * which may then be retrieved by calling the ->event() hook with the event
- * numbers. Required.
- */
static int fio_libnfs_getevents(struct thread_data *td, unsigned int min,
unsigned int max, const struct timespec *t)
{
if (res < 0) {
log_err("Failed NFS operation(code:%d): %s\n", res, nfs_get_error(o->context));
io_u->error = -res;
- // res is used for read math below, don't wanna pass negative there
+ /* res is used for read math below, don't wanna pass negative there */
res = 0;
} else if (io_u->ddir == DDIR_READ) {
memcpy(io_u->buf, data, res);
- if (res == 0) {
+ if (res == 0)
log_err("Got NFS EOF, this is probably not expected\n");
- }
}
- // fio uses resid to track remaining data
+ /* fio uses resid to track remaining data */
io_u->resid = io_u->xfer_buflen - res;
assert(!o->events[o->free_event_buffer_index]);
return nfs_pread_async(o->context, nfs_data->nfsfh, io_u->offset, io_u->buflen, nfs_callback, io_u);
}
-/*
- * The ->queue() hook is responsible for initiating io on the io_u
- * being passed in. If the io engine is a synchronous one, io may complete
- * before ->queue() returns. Required.
- *
- * The io engine must transfer in the direction noted by io_u->ddir
- * to the buffer pointed to by io_u->xfer_buf for as many bytes as
- * io_u->xfer_buflen. Residual data count may be set in io_u->resid
- * for a short read/write.
- */
static enum fio_q_status fio_libnfs_queue(struct thread_data *td,
struct io_u *io_u)
{
return ret;
}
-/** Do a mount if one has not been done before */
+/*
+ * Do a mount if one has not been done before
+ */
static int do_mount(struct thread_data *td, const char *url)
{
size_t event_size = sizeof(struct io_u **) * td->o.iodepth;
int path_len = 0;
char *mnt_dir = NULL;
- if (options->context) {
+ if (options->context)
return 0;
- }
options->context = nfs_init_context();
if (options->context == NULL) {
return ret;
}
-/*
- * The init function is called once per thread/process, and should set up
- * any structures that this io engine requires to keep track of io. Not
- * required.
- */
static int fio_libnfs_setup(struct thread_data *td)
{
- // flipping this makes using gdb easier, but tends to hang fio on exit
+ /* Using threads with libnfs causes fio to hang on exit, lower performance */
td->o.use_thread = 0;
return 0;
}
-/*
- * This is paired with the ->init() function and is called when a thread is
- * done doing io. Should tear down anything setup by the ->init() function.
- * Not required.
- */
static void fio_libnfs_cleanup(struct thread_data *td)
{
struct fio_libnfs_options *o = td->eo;
}
ret = nfs_open(options->context, f->file_name, flags, &nfs_data->nfsfh);
- if (ret != 0) {
+ if (ret != 0)
log_err("Failed to open %s: %s\n", f->file_name, nfs_get_error(options->context));
- }
f->engine_data = nfs_data;
return ret;
}
struct nfs_data *nfs_data = f->engine_data;
struct fio_libnfs_options *o = nfs_data->options;
int ret = 0;
- if (nfs_data->nfsfh) {
+ if (nfs_data->nfsfh)
ret = nfs_close(o->context, nfs_data->nfsfh);
- }
free(nfs_data);
f->engine_data = NULL;
return ret;
{
unregister_ioengine(&ioengine);
}
-