Commit 8f40d037 authored by Jens Axboe's avatar Jens Axboe

tools/io_uring/io_uring-cp: sync with liburing example

This example is missing a few fixes that are in the liburing version,
synchronize with the upstream version.
Reported-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 43597aac
...@@ -131,8 +131,7 @@ static int copy_file(struct io_uring *ring, off_t insize) ...@@ -131,8 +131,7 @@ static int copy_file(struct io_uring *ring, off_t insize)
writes = reads = offset = 0; writes = reads = offset = 0;
while (insize || write_left) { while (insize || write_left) {
unsigned long had_reads; int had_reads, got_comp;
int got_comp;
/* /*
* Queue up as many reads as we can * Queue up as many reads as we can
...@@ -174,8 +173,13 @@ static int copy_file(struct io_uring *ring, off_t insize) ...@@ -174,8 +173,13 @@ static int copy_file(struct io_uring *ring, off_t insize)
if (!got_comp) { if (!got_comp) {
ret = io_uring_wait_cqe(ring, &cqe); ret = io_uring_wait_cqe(ring, &cqe);
got_comp = 1; got_comp = 1;
} else } else {
ret = io_uring_peek_cqe(ring, &cqe); ret = io_uring_peek_cqe(ring, &cqe);
if (ret == -EAGAIN) {
cqe = NULL;
ret = 0;
}
}
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "io_uring_peek_cqe: %s\n", fprintf(stderr, "io_uring_peek_cqe: %s\n",
strerror(-ret)); strerror(-ret));
...@@ -194,7 +198,7 @@ static int copy_file(struct io_uring *ring, off_t insize) ...@@ -194,7 +198,7 @@ static int copy_file(struct io_uring *ring, off_t insize)
fprintf(stderr, "cqe failed: %s\n", fprintf(stderr, "cqe failed: %s\n",
strerror(-cqe->res)); strerror(-cqe->res));
return 1; return 1;
} else if ((size_t) cqe->res != data->iov.iov_len) { } else if (cqe->res != data->iov.iov_len) {
/* Short read/write, adjust and requeue */ /* Short read/write, adjust and requeue */
data->iov.iov_base += cqe->res; data->iov.iov_base += cqe->res;
data->iov.iov_len -= cqe->res; data->iov.iov_len -= cqe->res;
...@@ -221,6 +225,25 @@ static int copy_file(struct io_uring *ring, off_t insize) ...@@ -221,6 +225,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; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment