From: Pavel Begunkov <[email protected]>
To: Jens Axboe <[email protected]>,
[email protected], [email protected]
Subject: [PATCH liburing] test/sfr: basic test for sync_file_range
Date: Fri, 1 May 2020 17:38:11 +0300 [thread overview]
Message-ID: <9a85a351b8a06108260fee1dfcbd901b8055b9a8.1588343872.git.asml.silence@gmail.com> (raw)
Just call it and check that it doesn't hang and returns success.
Signed-off-by: Pavel Begunkov <[email protected]>
---
test/fsync.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/test/fsync.c b/test/fsync.c
index 839716a..ee60e0f 100644
--- a/test/fsync.c
+++ b/test/fsync.c
@@ -135,6 +135,79 @@ err:
return 1;
}
+#define FILE_SIZE 1024
+
+static int create_file(const char *file)
+{
+ ssize_t ret;
+ char *buf;
+ int fd;
+
+ buf = malloc(FILE_SIZE);
+ memset(buf, 0xaa, FILE_SIZE);
+
+ fd = open(file, O_WRONLY | O_CREAT, 0644);
+ if (fd < 0) {
+ perror("open file");
+ return 1;
+ }
+ ret = write(fd, buf, FILE_SIZE);
+ close(fd);
+ return ret != FILE_SIZE;
+}
+
+static int test_sync_file_range(struct io_uring *ring)
+{
+ int ret, fd, save_errno;
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+
+ if (create_file(".sync_file_range")) {
+ fprintf(stderr, "file creation failed\n");
+ return 1;
+ }
+
+ fd = open(".sync_file_range", O_RDWR);
+ save_errno = errno;
+ unlink(".sync_file_range");
+ errno = save_errno;
+ if (fd < 0) {
+ perror("file open");
+ return 1;
+ }
+
+ sqe = io_uring_get_sqe(ring);
+ if (!sqe) {
+ fprintf(stderr, "sqe get failed\n");
+ return 1;
+ }
+ memset(sqe, 0, sizeof(*sqe));
+ sqe->opcode = IORING_OP_SYNC_FILE_RANGE;
+ sqe->off = 0;
+ sqe->len = 0;
+ sqe->sync_range_flags = 0;
+ sqe->user_data = 1;
+ sqe->fd = fd;
+
+ ret = io_uring_submit(ring);
+ if (ret != 1) {
+ fprintf(stderr, "submit failed: %d\n", ret);
+ return 1;
+ }
+ ret = io_uring_wait_cqe(ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "wait_cqe failed: %d\n", ret);
+ return 1;
+ }
+ if (cqe->res) {
+ fprintf(stderr, "sfr failed: %d\n", cqe->res);
+ return 1;
+ }
+
+ io_uring_cqe_seen(ring, cqe);
+ return 0;
+}
+
int main(int argc, char *argv[])
{
struct io_uring ring;
@@ -159,5 +232,11 @@ int main(int argc, char *argv[])
return ret;
}
+ ret = test_sync_file_range(&ring);
+ if (ret) {
+ fprintf(stderr, "test_sync_file_range failed\n");
+ return ret;
+ }
+
return 0;
}
--
2.24.0
next reply other threads:[~2020-05-01 14:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-01 14:38 Pavel Begunkov [this message]
2020-05-01 14:49 ` [PATCH liburing] test/sfr: basic test for sync_file_range 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=9a85a351b8a06108260fee1dfcbd901b8055b9a8.1588343872.git.asml.silence@gmail.com \
[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