I recently started using liburing and tried to write some demos. I met trouble when tried to write something into the disk.
Here is my code, the error check has been removed.
#include "liburing.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>
#include <unistd.h>
int main() {
struct io_uring ring;
struct iovec *iovecs;
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int fd;
void *buf;
int ret = io_uring_queue_init(4, &ring, 0);
fd = open("./tmp_file", O_WRONLY | O_TRUNC | O_CREAT, 0644);
ret = ftruncate(fd, 4096);
sqe = io_uring_get_sqe(&ring);
posix_memalign(&buf, 4096, 4096);
memset(buf, 0x2, 4096);
sqe = io_uring_get_sqe(&ring);
io_uring_prep_write(sqe, fd, buf, 4096, 0);
ret = io_uring_submit(&ring);
ret = io_uring_wait_cqe(&ring, &cqe);
printf("cqe->res: %d\n", cqe->res);
io_uring_cqe_seen(&ring, cqe);
io_uring_queue_exit(&ring);
close(fd);
return 0;
}
cqe->res
always return 0. I have no clues to continue the search.
My kernel version is linux 5.4.56
, and the liburing version is liburing-2.1
. I compiled my demo with GCC 830.
I also tried other existing examples, compiled them from the source, they work just fine.
Any help is appreciated, thank you very much.