From d7762cf829fd3e44e50e5e2e9889b6449772097c Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Fri, 23 Feb 2007 12:34:57 +0100 Subject: [PATCH 1/1] Move completion handler into the io_u This is needed for completions that happen outside of fio, or more specifically, for syslet to enable completions in a ->queue() hook combined with ->commit(). Signed-off-by: Jens Axboe --- fio.c | 18 ++++++++++-------- fio.h | 14 +++++++------- io_u.c | 21 ++++++++------------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/fio.c b/fio.c index dbea661d..74604929 100644 --- a/fio.c +++ b/fio.c @@ -159,7 +159,7 @@ static void cleanup_pending_aio(struct thread_data *td) /* * get immediately available events, if any */ - r = io_u_queued_complete(td, 0, NULL); + r = io_u_queued_complete(td, 0); if (r < 0) return; @@ -187,7 +187,7 @@ static void cleanup_pending_aio(struct thread_data *td) } if (td->cur_depth) - r = io_u_queued_complete(td, td->cur_depth, NULL); + r = io_u_queued_complete(td, td->cur_depth); } /* @@ -217,7 +217,7 @@ requeue: put_io_u(td, io_u); return 1; } else if (ret == FIO_Q_QUEUED) { - if (io_u_queued_complete(td, 1, NULL) < 0) + if (io_u_queued_complete(td, 1) < 0) return 1; } else if (ret == FIO_Q_COMPLETED) { if (io_u->error) { @@ -225,7 +225,7 @@ requeue: return 1; } - if (io_u_sync_complete(td, io_u, NULL) < 0) + if (io_u_sync_complete(td, io_u) < 0) return 1; } else if (ret == FIO_Q_BUSY) { if (td_io_commit(td)) @@ -282,6 +282,8 @@ static void do_verify(struct thread_data *td) put_io_u(td, io_u); break; } + + io_u->end_io = verify_io_u; requeue: ret = td_io_queue(td, io_u); @@ -296,7 +298,7 @@ requeue: io_u->xfer_buf += bytes; goto requeue; } - ret = io_u_sync_complete(td, io_u, verify_io_u); + ret = io_u_sync_complete(td, io_u); if (ret < 0) break; continue; @@ -331,7 +333,7 @@ requeue: * Reap required number of io units, if any, and do the * verification on them through the callback handler */ - if (io_u_queued_complete(td, min_events, verify_io_u) < 0) + if (io_u_queued_complete(td, min_events) < 0) break; } @@ -414,7 +416,7 @@ requeue: goto requeue; } fio_gettime(&comp_time, NULL); - bytes_done = io_u_sync_complete(td, io_u, NULL); + bytes_done = io_u_sync_complete(td, io_u); if (bytes_done < 0) ret = bytes_done; break; @@ -453,7 +455,7 @@ requeue: } fio_gettime(&comp_time, NULL); - bytes_done = io_u_queued_complete(td, min_evts, NULL); + bytes_done = io_u_queued_complete(td, min_evts); if (bytes_done < 0) break; } diff --git a/fio.h b/fio.h index 6abbd79e..f2366c4c 100644 --- a/fio.h +++ b/fio.h @@ -144,6 +144,11 @@ struct io_u { struct fio_file *file; struct list_head list; + + /* + * Callback for io completion + */ + int (*end_io)(struct io_u *); }; /* @@ -544,11 +549,6 @@ struct disk_util { struct timeval time; }; -/* - * Callback for io completion - */ -typedef int (endio_handler)(struct io_u *); - #define DISK_UTIL_MSEC (250) #ifndef min @@ -663,8 +663,8 @@ extern struct io_u *__get_io_u(struct thread_data *); extern struct io_u *get_io_u(struct thread_data *); extern void put_io_u(struct thread_data *, struct io_u *); extern void requeue_io_u(struct thread_data *, struct io_u **); -extern long __must_check io_u_sync_complete(struct thread_data *, struct io_u *, endio_handler *); -extern long __must_check io_u_queued_complete(struct thread_data *, int, endio_handler *); +extern long __must_check io_u_sync_complete(struct thread_data *, struct io_u *); +extern long __must_check io_u_queued_complete(struct thread_data *, int); extern void io_u_queued(struct thread_data *, struct io_u *); extern void io_u_init_timeout(void); extern void io_u_set_timeout(struct thread_data *); diff --git a/io_u.c b/io_u.c index 48d40760..53e57b4f 100644 --- a/io_u.c +++ b/io_u.c @@ -15,7 +15,6 @@ struct io_completion_data { int nr; /* input */ - endio_handler *handler; /* input */ int error; /* output */ unsigned long bytes_done[2]; /* output */ @@ -378,6 +377,7 @@ struct io_u *__get_io_u(struct thread_data *td) io_u->buflen = 0; io_u->resid = 0; io_u->file = NULL; + io_u->end_io = NULL; } if (io_u) { @@ -510,8 +510,8 @@ static void io_completed(struct thread_data *td, struct io_u *io_u, icd->bytes_done[idx] += bytes; - if (icd->handler) { - ret = icd->handler(io_u); + if (io_u->end_io) { + ret = io_u->end_io(io_u); if (ret && !icd->error) icd->error = ret; } @@ -519,12 +519,10 @@ static void io_completed(struct thread_data *td, struct io_u *io_u, icd->error = io_u->error; } -static void init_icd(struct io_completion_data *icd, endio_handler *handler, - int nr) +static void init_icd(struct io_completion_data *icd, int nr) { fio_gettime(&icd->time, NULL); - icd->handler = handler; icd->nr = nr; icd->error = 0; @@ -548,12 +546,11 @@ static void ios_completed(struct thread_data *td, /* * Complete a single io_u for the sync engines. */ -long io_u_sync_complete(struct thread_data *td, struct io_u *io_u, - endio_handler *handler) +long io_u_sync_complete(struct thread_data *td, struct io_u *io_u) { struct io_completion_data icd; - init_icd(&icd, handler, 1); + init_icd(&icd, 1); io_completed(td, io_u, &icd); put_io_u(td, io_u); @@ -566,9 +563,7 @@ long io_u_sync_complete(struct thread_data *td, struct io_u *io_u, /* * Called to complete min_events number of io for the async engines. */ -long io_u_queued_complete(struct thread_data *td, int min_events, - endio_handler *handler) - +long io_u_queued_complete(struct thread_data *td, int min_events) { struct io_completion_data icd; struct timespec *tvp = NULL; @@ -593,7 +588,7 @@ long io_u_queued_complete(struct thread_data *td, int min_events, } else if (!ret) return ret; - init_icd(&icd, handler, ret); + init_icd(&icd, ret); ios_completed(td, &icd); if (!icd.error) return icd.bytes_done[0] + icd.bytes_done[1]; -- 2.25.1