From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Subject: [PATCH liburing] tests: test fixed file removal order
Date: Thu, 7 Jan 2021 02:46:58 +0000 [thread overview]
Message-ID: <31d6fcb0f328966c5f68c7629d123a5b0f783331.1609966277.git.asml.silence@gmail.com> (raw)
Do two file removals on a fixed file that used by an inflight request
and make sure it goes well.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/file-register.c | 89 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+)
diff --git a/test/file-register.c b/test/file-register.c
index 55af9dc..fc8b887 100644
--- a/test/file-register.c
+++ b/test/file-register.c
@@ -604,6 +604,89 @@ static int test_sparse_updates(void)
return 0;
}
+static int test_fixed_removal_ordering(void)
+{
+ char buffer[128];
+ struct io_uring ring;
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ struct __kernel_timespec ts;
+ int ret, fd, i, fds[2];
+
+ ret = io_uring_queue_init(8, &ring, 0);
+ if (ret < 0) {
+ fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
+ return ret;
+ }
+ if (pipe(fds)) {
+ perror("pipe");
+ return -1;
+ }
+ ret = io_uring_register_files(&ring, fds, 2);
+ if (ret) {
+ fprintf(stderr, "file_register: %d\n", ret);
+ return ret;
+ }
+ /* ring should have fds referenced, can close them */
+ close(fds[0]);
+ close(fds[1]);
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ fprintf(stderr, "%s: get sqe failed\n", __FUNCTION__);
+ return 1;
+ }
+ /* outwait file recycling delay */
+ ts.tv_sec = 3;
+ ts.tv_nsec = 0;
+ io_uring_prep_timeout(sqe, &ts, 0, 0);
+ sqe->flags |= IOSQE_IO_LINK | IOSQE_IO_HARDLINK;
+ sqe->user_data = 1;
+
+ sqe = io_uring_get_sqe(&ring);
+ if (!sqe) {
+ printf("get sqe failed\n");
+ return -1;
+ }
+ io_uring_prep_write(sqe, 1, buffer, sizeof(buffer), 0);
+ sqe->flags |= IOSQE_FIXED_FILE;
+ sqe->user_data = 2;
+
+ ret = io_uring_submit(&ring);
+ if (ret != 2) {
+ fprintf(stderr, "%s: got %d, wanted 2\n", __FUNCTION__, ret);
+ return -1;
+ }
+
+ /* remove unused pipe end */
+ fd = -1;
+ ret = io_uring_register_files_update(&ring, 0, &fd, 1);
+ if (ret != 1) {
+ fprintf(stderr, "update off=0 failed\n");
+ return -1;
+ }
+
+ /* remove used pipe end */
+ fd = -1;
+ ret = io_uring_register_files_update(&ring, 1, &fd, 1);
+ if (ret != 1) {
+ fprintf(stderr, "update off=1 failed\n");
+ return -1;
+ }
+
+ for (i = 0; i < 2; ++i) {
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret < 0) {
+ fprintf(stderr, "%s: io_uring_wait_cqe=%d\n", __FUNCTION__, ret);
+ return 1;
+ }
+ io_uring_cqe_seen(&ring, cqe);
+ }
+
+ io_uring_queue_exit(&ring);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
struct io_uring ring;
@@ -699,5 +782,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_fixed_removal_ordering();
+ if (ret) {
+ printf("test_fixed_removal_ordering failed\n");
+ return 1;
+ }
+
return 0;
}
--
2.24.0
next reply other threads:[~2021-01-07 2:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-07 2:46 Pavel Begunkov [this message]
2021-01-07 14:46 ` [PATCH liburing] tests: test fixed file removal order Jens Axboe
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 \
--in-reply-to=31d6fcb0f328966c5f68c7629d123a5b0f783331.1609966277.git.asml.silence@gmail.com \
[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