From: Jens Axboe <[email protected]>
To: Xiaoguang Wang <[email protected]>,
[email protected]
Cc: [email protected]
Subject: Re: [PATCH v2] io_uring: reset -EBUSY error when io sq thread is waken up
Date: Wed, 20 May 2020 07:34:41 -0600 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 5/20/20 7:24 AM, Xiaoguang Wang wrote:
> In io_sq_thread(), currently if we get an -EBUSY error and go to sleep,
> we will won't clear it again, which will result in io_sq_thread() will
> never have a chance to submit sqes again. Below test program test.c
> can reveal this bug:
>
> int main(int argc, char *argv[])
> {
> struct io_uring ring;
> int i, fd, ret;
> struct io_uring_sqe *sqe;
> struct io_uring_cqe *cqe;
> struct iovec *iovecs;
> void *buf;
> struct io_uring_params p;
>
> if (argc < 2) {
> printf("%s: file\n", argv[0]);
> return 1;
> }
>
> memset(&p, 0, sizeof(p));
> p.flags = IORING_SETUP_SQPOLL;
> ret = io_uring_queue_init_params(4, &ring, &p);
> if (ret < 0) {
> fprintf(stderr, "queue_init: %s\n", strerror(-ret));
> return 1;
> }
>
> fd = open(argv[1], O_RDONLY | O_DIRECT);
> if (fd < 0) {
> perror("open");
> return 1;
> }
>
> iovecs = calloc(10, sizeof(struct iovec));
> for (i = 0; i < 10; i++) {
> if (posix_memalign(&buf, 4096, 4096))
> return 1;
> iovecs[i].iov_base = buf;
> iovecs[i].iov_len = 4096;
> }
>
> ret = io_uring_register_files(&ring, &fd, 1);
> if (ret < 0) {
> fprintf(stderr, "%s: register %d\n", __FUNCTION__, ret);
> return ret;
> }
>
> for (i = 0; i < 10; i++) {
> sqe = io_uring_get_sqe(&ring);
> if (!sqe)
> break;
>
> io_uring_prep_readv(sqe, 0, &iovecs[i], 1, 0);
> sqe->flags |= IOSQE_FIXED_FILE;
>
> ret = io_uring_submit(&ring);
> sleep(1);
> printf("submit %d\n", i);
> }
>
> for (i = 0; i < 10; i++) {
> io_uring_wait_cqe(&ring, &cqe);
> printf("receive: %d\n", i);
> if (cqe->res != 4096) {
> fprintf(stderr, "ret=%d, wanted 4096\n", cqe->res);
> ret = 1;
> }
> io_uring_cqe_seen(&ring, cqe);
> }
>
> close(fd);
> io_uring_queue_exit(&ring);
> return 0;
> }
> sudo ./test testfile
> above command will hang on the tenth request, to fix this bug, when io
> sq_thread is waken up, we reset the variable 'ret' to be zero.
Applied, thanks.
--
Jens Axboe
prev parent reply other threads:[~2020-05-20 13:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 13:24 [PATCH v2] io_uring: reset -EBUSY error when io sq thread is waken up Xiaoguang Wang
2020-05-20 13:34 ` Jens Axboe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox