summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2021-03-26 07:18:45 -0600
committerJens Axboe <axboe@kernel.dk>2021-03-26 07:18:45 -0600
commit941a5c7cdf35fd562553491a539e81005fbcebd6 (patch)
tree4fea314b1ea7ca2a2529ec5cbc2013b3aa739c27
parent2b89fce100ee1e6859fedc0768029dc9019faef1 (diff)
downloadliburing-941a5c7cdf35fd562553491a539e81005fbcebd6.tar.gz
liburing-941a5c7cdf35fd562553491a539e81005fbcebd6.tar.bz2
examples/io_uring-cp: wait for pending writes before exit copy loop
We could be ending the loop with all reads done, but with pending writes that we haven't waited for yet. Ensure that we do so. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--examples/io_uring-cp.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/io_uring-cp.c b/examples/io_uring-cp.c
index cc7a227..2a44c30 100644
--- a/examples/io_uring-cp.c
+++ b/examples/io_uring-cp.c
@@ -221,6 +221,25 @@ static int copy_file(struct io_uring *ring, off_t insize)
}
}
+ /* wait out pending writes */
+ while (writes) {
+ struct io_data *data;
+
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "wait_cqe=%d\n", ret);
+ return 1;
+ }
+ if (cqe->res < 0) {
+ fprintf(stderr, "write res=%d\n", cqe->res);
+ return 1;
+ }
+ data = io_uring_cqe_get_data(cqe);
+ free(data);
+ writes--;
+ io_uring_cqe_seen(ring, cqe);
+ }
+
return 0;
}