Skip to content

Commit

Permalink
tools/io_uring/io_uring-cp: sync with liburing example
Browse files Browse the repository at this point in the history
This example is missing a few fixes that are in the liburing version,
synchronize with the upstream version.

Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Jens Axboe committed Aug 13, 2021
1 parent 43597aa commit 8f40d03
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions tools/io_uring/io_uring-cp.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ static int copy_file(struct io_uring *ring, off_t insize)
writes = reads = offset = 0;

while (insize || write_left) {
unsigned long had_reads;
int got_comp;
int had_reads, got_comp;

/*
* Queue up as many reads as we can
Expand Down Expand Up @@ -174,8 +173,13 @@ static int copy_file(struct io_uring *ring, off_t insize)
if (!got_comp) {
ret = io_uring_wait_cqe(ring, &cqe);
got_comp = 1;
} else
} else {
ret = io_uring_peek_cqe(ring, &cqe);
if (ret == -EAGAIN) {
cqe = NULL;
ret = 0;
}
}
if (ret < 0) {
fprintf(stderr, "io_uring_peek_cqe: %s\n",
strerror(-ret));
Expand All @@ -194,7 +198,7 @@ static int copy_file(struct io_uring *ring, off_t insize)
fprintf(stderr, "cqe failed: %s\n",
strerror(-cqe->res));
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 */
data->iov.iov_base += cqe->res;
data->iov.iov_len -= cqe->res;
Expand All @@ -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;
}

Expand Down

0 comments on commit 8f40d03

Please sign in to comment.