Just call it and check that it doesn't hang and returns success. Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx> --- 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