lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri,  1 May 2020 17:38:11 +0300
From:   Pavel Begunkov <asml.silence@...il.com>
To:     Jens Axboe <axboe@...nel.dk>, io-uring@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH liburing] test/sfr: basic test for sync_file_range

Just call it and check that it doesn't hang and returns success.

Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
---
 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

Powered by blists - more mailing lists