diff options
author | Jens Axboe <axboe@kernel.dk> | 2019-05-14 20:46:12 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-05-14 20:46:12 -0600 |
commit | 7e8902e14c1e684c03d44a7357928246b96b55bb (patch) | |
tree | 967d984203a79b7e1b1bfe8f846f1748436666d9 | |
parent | bb2c80ff0f7834691c892b6ea38114603b20abbe (diff) |
examples/link-cp: fix a few issues
Still need to handle broken chains, must resubmit those.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | examples/link-cp.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/examples/link-cp.c b/examples/link-cp.c index 993d3a6..9ac4658 100644 --- a/examples/link-cp.c +++ b/examples/link-cp.c @@ -78,7 +78,7 @@ static int queue_rw_pair(struct io_uring *ring, off_t size, off_t offset) return 0; } -static void handle_cqe(struct io_uring_cqe *cqe) +static void handle_cqe(struct io_uring *ring, struct io_uring_cqe *cqe) { struct io_data *data; @@ -86,10 +86,9 @@ static void handle_cqe(struct io_uring_cqe *cqe) printf("cqe error: %s\n", strerror(cqe->res)); data = io_uring_cqe_get_data(cqe); - if (!data) - return; - - free(data); + if (data) + free(data); + io_uring_cqe_seen(ring, cqe); } static int copy_file(struct io_uring *ring, off_t insize) @@ -103,8 +102,9 @@ static int copy_file(struct io_uring *ring, off_t insize) inflight = 0; while (insize) { int has_inflight = inflight; + int depth; - while (inflight < QD) { + while (insize && inflight < QD) { this_size = BS; if (this_size > insize) this_size = insize; @@ -117,12 +117,16 @@ static int copy_file(struct io_uring *ring, off_t insize) if (has_inflight != inflight) io_uring_submit(ring); - while (inflight >= QD) { + if (insize) + depth = QD; + else + depth = 1; + while (inflight >= depth) { int ret; ret = io_uring_wait_cqe(ring, &cqe); assert(ret >= 0); - handle_cqe(cqe); + handle_cqe(ring, cqe); inflight--; } } |