From 065b1ff1f27fffd1e2fa0614a57e6ed697ece679 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 1 Oct 2024 16:33:53 -0600 Subject: [PATCH] examples/kdigest: remove "error" handling There's on way the request will return -ECANCELED without being explicitly canceled, which the example doesn't do, or the ring being torn down. Just remove the attempted error handling here, as it's incomplete/broken and it's better to have none (and just abort) than broken error handling in what serves as an example. Signed-off-by: Jens Axboe --- examples/kdigest.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/examples/kdigest.c b/examples/kdigest.c index fe95ccfeb..45ff966df 100644 --- a/examples/kdigest.c +++ b/examples/kdigest.c @@ -75,7 +75,7 @@ static int reap_completions(struct io_uring *ring, int *inflight, { struct io_uring_cqe *cqe; unsigned head; - int ret, nr; + int ret = 0, nr; nr = 0; io_uring_for_each_cqe(ring, head, cqe) { @@ -83,37 +83,24 @@ static int reap_completions(struct io_uring *ring, int *inflight, req = io_uring_cqe_get_data(cqe); assert(req->state == IO_READ || req->state == IO_WRITE); - ret = cqe->res; - if (ret < 0) { - if (ret == -ECANCELED && req->state == IO_READ) { - struct io_uring_sqe *sqe; - - fprintf(stderr, "canceled read@%lld\n", - (long long)req->offset); - sqe = io_uring_get_sqe(ring); - io_uring_prep_read(sqe, infd, - req->iov.iov_base, - req->iov.iov_len, req->offset); - io_uring_sqe_set_data(sqe, req); - if (io_uring_submit(ring) < 0) - return 1; - continue; - } else { - fprintf(stderr, "cqe error: %s\n", - strerror(-ret)); - return 1; - } + if (cqe->res < 0) { + fprintf(stderr, "%s: cqe error %d\n", + req->state == IO_WRITE ? "send" : "read", + cqe->res); + *outsize = 0; + ret = 1; + break; } (*inflight)--; req->state++; if (req->state == IO_WRITE_COMPLETE) - *outsize -= ret; + *outsize -= cqe->res; nr++; } io_uring_cq_advance(ring, nr); - return 0; + return ret; } static void submit_sends_br(struct kdigest *kdigest, int *write_idx,