Skip to content

Commit 8f40d03

Browse files
committed
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: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 43597aa commit 8f40d03

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

tools/io_uring/io_uring-cp.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ static int copy_file(struct io_uring *ring, off_t insize)
131131
writes = reads = offset = 0;
132132

133133
while (insize || write_left) {
134-
unsigned long had_reads;
135-
int got_comp;
134+
int had_reads, got_comp;
136135

137136
/*
138137
* Queue up as many reads as we can
@@ -174,8 +173,13 @@ static int copy_file(struct io_uring *ring, off_t insize)
174173
if (!got_comp) {
175174
ret = io_uring_wait_cqe(ring, &cqe);
176175
got_comp = 1;
177-
} else
176+
} else {
178177
ret = io_uring_peek_cqe(ring, &cqe);
178+
if (ret == -EAGAIN) {
179+
cqe = NULL;
180+
ret = 0;
181+
}
182+
}
179183
if (ret < 0) {
180184
fprintf(stderr, "io_uring_peek_cqe: %s\n",
181185
strerror(-ret));
@@ -194,7 +198,7 @@ static int copy_file(struct io_uring *ring, off_t insize)
194198
fprintf(stderr, "cqe failed: %s\n",
195199
strerror(-cqe->res));
196200
return 1;
197-
} else if ((size_t) cqe->res != data->iov.iov_len) {
201+
} else if (cqe->res != data->iov.iov_len) {
198202
/* Short read/write, adjust and requeue */
199203
data->iov.iov_base += cqe->res;
200204
data->iov.iov_len -= cqe->res;
@@ -221,6 +225,25 @@ static int copy_file(struct io_uring *ring, off_t insize)
221225
}
222226
}
223227

228+
/* wait out pending writes */
229+
while (writes) {
230+
struct io_data *data;
231+
232+
ret = io_uring_wait_cqe(ring, &cqe);
233+
if (ret) {
234+
fprintf(stderr, "wait_cqe=%d\n", ret);
235+
return 1;
236+
}
237+
if (cqe->res < 0) {
238+
fprintf(stderr, "write res=%d\n", cqe->res);
239+
return 1;
240+
}
241+
data = io_uring_cqe_get_data(cqe);
242+
free(data);
243+
writes--;
244+
io_uring_cqe_seen(ring, cqe);
245+
}
246+
224247
return 0;
225248
}
226249

0 commit comments

Comments
 (0)