nvme_perf: Relocate functions only for AIO to introduce abstraction

Subsequent patches will introduce function pointer table for
IO type depenedent operations.

This patch doesn't cause any functional change and just tries to
make them easier.

Change-Id: I664c9e39d101957c55cfcf9426f82feca348c328
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/440670
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-01-16 07:58:57 +09:00 committed by Jim Harris
parent 113798376d
commit 60bd1f32d5

View File

@ -377,6 +377,46 @@ register_ctrlr(struct spdk_nvme_ctrlr *ctrlr, struct trid_entry *trid_entry)
}
#if HAVE_LIBAIO
static int
aio_submit(io_context_t aio_ctx, struct iocb *iocb, int fd, enum io_iocb_cmd cmd, void *buf,
unsigned long nbytes, uint64_t offset, void *cb_ctx)
{
iocb->aio_fildes = fd;
iocb->aio_reqprio = 0;
iocb->aio_lio_opcode = cmd;
iocb->u.c.buf = buf;
iocb->u.c.nbytes = nbytes;
iocb->u.c.offset = offset;
iocb->data = cb_ctx;
if (io_submit(aio_ctx, 1, &iocb) < 0) {
printf("io_submit");
return -1;
}
return 0;
}
static void
aio_check_io(struct ns_worker_ctx *ns_ctx)
{
int count, i;
struct timespec timeout;
timeout.tv_sec = 0;
timeout.tv_nsec = 0;
count = io_getevents(ns_ctx->u.aio.ctx, 1, g_queue_depth, ns_ctx->u.aio.events, &timeout);
if (count < 0) {
fprintf(stderr, "io_getevents error\n");
exit(1);
}
for (i = 0; i < count; i++) {
task_complete(ns_ctx->u.aio.events[i].data);
}
}
static int
register_aio_file(const char *path)
{
@ -446,44 +486,19 @@ register_aio_file(const char *path)
}
static int
aio_submit(io_context_t aio_ctx, struct iocb *iocb, int fd, enum io_iocb_cmd cmd, void *buf,
unsigned long nbytes, uint64_t offset, void *cb_ctx)
register_aio_files(int argc, char **argv)
{
iocb->aio_fildes = fd;
iocb->aio_reqprio = 0;
iocb->aio_lio_opcode = cmd;
iocb->u.c.buf = buf;
iocb->u.c.nbytes = nbytes;
iocb->u.c.offset = offset;
iocb->data = cb_ctx;
int i;
if (io_submit(aio_ctx, 1, &iocb) < 0) {
printf("io_submit");
return -1;
/* Treat everything after the options as files for AIO */
for (i = g_aio_optind; i < argc; i++) {
if (register_aio_file(argv[i]) != 0) {
return 1;
}
}
return 0;
}
static void
aio_check_io(struct ns_worker_ctx *ns_ctx)
{
int count, i;
struct timespec timeout;
timeout.tv_sec = 0;
timeout.tv_nsec = 0;
count = io_getevents(ns_ctx->u.aio.ctx, 1, g_queue_depth, ns_ctx->u.aio.events, &timeout);
if (count < 0) {
fprintf(stderr, "io_getevents error\n");
exit(1);
}
for (i = 0; i < count; i++) {
task_complete(ns_ctx->u.aio.events[i].data);
}
}
#endif /* HAVE_LIBAIO */
static void
@ -1665,23 +1680,6 @@ unregister_controllers(void)
}
}
static int
register_aio_files(int argc, char **argv)
{
#if HAVE_LIBAIO
int i;
/* Treat everything after the options as files for AIO */
for (i = g_aio_optind; i < argc; i++) {
if (register_aio_file(argv[i]) != 0) {
return 1;
}
}
#endif /* HAVE_LIBAIO */
return 0;
}
static int
associate_workers_with_ns(void)
{
@ -1763,10 +1761,12 @@ int main(int argc, char **argv)
goto cleanup;
}
#if HAVE_LIBAIO
if (register_aio_files(argc, argv) != 0) {
rc = -1;
goto cleanup;
}
#endif
if (register_controllers() != 0) {
rc = -1;