fsstress: add IO_URING read and write operations
authorZorro Lang <zlang@redhat.com>
Fri, 11 Sep 2020 07:15:51 +0000 (15:15 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 27 Sep 2020 09:31:10 +0000 (17:31 +0800)
IO_URING is a new feature of curent linux kernel, add basic IO_URING
read/write into fsstess to cover this kind of IO testing.

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
README
configure.ac
include/builddefs.in
ltp/Makefile
ltp/fsstress.c
m4/Makefile
m4/package_liburing.m4 [new file with mode: 0644]

diff --git a/README b/README
index 4af331b4fa06e9313e5607b202fd04dcd82d0199..43bb0cee3212370b0b7282af8cc909c383215a50 100644 (file)
--- a/README
+++ b/README
@@ -8,13 +8,13 @@ _______________________
        sudo apt-get install xfslibs-dev uuid-dev libtool-bin \
        e2fsprogs automake gcc libuuid1 quota attr libattr1-dev make \
        libacl1-dev libaio-dev xfsprogs libgdbm-dev gawk fio dbench \
        sudo apt-get install xfslibs-dev uuid-dev libtool-bin \
        e2fsprogs automake gcc libuuid1 quota attr libattr1-dev make \
        libacl1-dev libaio-dev xfsprogs libgdbm-dev gawk fio dbench \
-       uuid-runtime python sqlite3
+       uuid-runtime python sqlite3 liburing-dev
   For Fedora, RHEL, or CentOS:
        yum install acl attr automake bc dbench dump e2fsprogs fio \
        gawk gcc indent libtool lvm2 make psmisc quota sed \
        xfsdump xfsprogs \
        libacl-devel libattr-devel libaio-devel libuuid-devel \
   For Fedora, RHEL, or CentOS:
        yum install acl attr automake bc dbench dump e2fsprogs fio \
        gawk gcc indent libtool lvm2 make psmisc quota sed \
        xfsdump xfsprogs \
        libacl-devel libattr-devel libaio-devel libuuid-devel \
-       xfsprogs-devel btrfs-progs-devel python sqlite
+       xfsprogs-devel btrfs-progs-devel python sqlite liburing-devel
        (Older distributions may require xfsprogs-qa-devel as well.)
        (Note that for RHEL and CentOS, you may need the EPEL repo.)
 - run make
        (Older distributions may require xfsprogs-qa-devel as well.)
        (Note that for RHEL and CentOS, you may need the EPEL repo.)
 - run make
index 4bb50b32da33e9bb6506c50ae646ff93411841f2..8922c47e8aa6678e6d9c2f6a57b62a14b561a439 100644 (file)
@@ -61,6 +61,7 @@ AC_PACKAGE_NEED_ACLINIT_LIBACL
 
 AC_PACKAGE_WANT_GDBM
 AC_PACKAGE_WANT_AIO
 
 AC_PACKAGE_WANT_GDBM
 AC_PACKAGE_WANT_AIO
+AC_PACKAGE_WANT_URING
 AC_PACKAGE_WANT_DMAPI
 AC_PACKAGE_WANT_LINUX_FIEMAP_H
 AC_PACKAGE_WANT_FALLOCATE
 AC_PACKAGE_WANT_DMAPI
 AC_PACKAGE_WANT_LINUX_FIEMAP_H
 AC_PACKAGE_WANT_FALLOCATE
index e7894b1ab00978af1b9bf5be8c54f2b31c8f19d4..fded3230dbfc2e5324cf99f9c6a13841a6837662 100644 (file)
@@ -61,6 +61,7 @@ RPM_VERSION     = @rpm_version@
 ENABLE_SHARED = @enable_shared@
 HAVE_DB = @have_db@
 HAVE_AIO = @have_aio@
 ENABLE_SHARED = @enable_shared@
 HAVE_DB = @have_db@
 HAVE_AIO = @have_aio@
+HAVE_URING = @have_uring@
 HAVE_FALLOCATE = @have_fallocate@
 HAVE_OPEN_BY_HANDLE_AT = @have_open_by_handle_at@
 HAVE_DMAPI = @have_dmapi@
 HAVE_FALLOCATE = @have_fallocate@
 HAVE_OPEN_BY_HANDLE_AT = @have_open_by_handle_at@
 HAVE_DMAPI = @have_dmapi@
index ebf403364dbbf0e3dffa86e2067a74aedba6ef8e..198d930f3c30200caff501de9ab7f0ef49c2a1a6 100644 (file)
@@ -24,6 +24,11 @@ LCFLAGS += -DAIO
 LLDLIBS += -laio -lpthread
 endif
 
 LLDLIBS += -laio -lpthread
 endif
 
+ifeq ($(HAVE_URING), true)
+LCFLAGS += -DURING
+LLDLIBS += -luring
+endif
+
 ifeq ($(HAVE_LIBBTRFSUTIL), true)
 LLDLIBS += -lbtrfsutil
 endif
 ifeq ($(HAVE_LIBBTRFSUTIL), true)
 LLDLIBS += -lbtrfsutil
 endif
index 709fdeec7f0d19acbd6b863c8a04c0988afe593c..d28fcd756610f5a57f30fd8f2757a3dd1f574f64 100644 (file)
 #include <libaio.h>
 io_context_t   io_ctx;
 #endif
 #include <libaio.h>
 io_context_t   io_ctx;
 #endif
+#ifdef URING
+#include <liburing.h>
+#define URING_ENTRIES  1
+struct io_uring        ring;
+#endif
 #include <sys/syscall.h>
 #include <sys/xattr.h>
 
 #include <sys/syscall.h>
 #include <sys/xattr.h>
 
@@ -139,6 +144,8 @@ typedef enum {
        OP_TRUNCATE,
        OP_UNLINK,
        OP_UNRESVSP,
        OP_TRUNCATE,
        OP_UNLINK,
        OP_UNRESVSP,
+       OP_URING_READ,
+       OP_URING_WRITE,
        OP_WRITE,
        OP_WRITEV,
        OP_LAST
        OP_WRITE,
        OP_WRITEV,
        OP_LAST
@@ -267,6 +274,8 @@ void        sync_f(int, long);
 void   truncate_f(int, long);
 void   unlink_f(int, long);
 void   unresvsp_f(int, long);
 void   truncate_f(int, long);
 void   unlink_f(int, long);
 void   unresvsp_f(int, long);
+void   uring_read_f(int, long);
+void   uring_write_f(int, long);
 void   write_f(int, long);
 void   writev_f(int, long);
 char   *xattr_flag_to_string(int);
 void   write_f(int, long);
 void   writev_f(int, long);
 char   *xattr_flag_to_string(int);
@@ -335,6 +344,8 @@ opdesc_t    ops[] = {
        { OP_TRUNCATE, "truncate", truncate_f, 2, 1 },
        { OP_UNLINK, "unlink", unlink_f, 1, 1 },
        { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 },
        { OP_TRUNCATE, "truncate", truncate_f, 2, 1 },
        { OP_UNLINK, "unlink", unlink_f, 1, 1 },
        { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 },
+       { OP_URING_READ, "uring_read", uring_read_f, 1, 0 },
+       { OP_URING_WRITE, "uring_write", uring_write_f, 1, 1 },
        { OP_WRITE, "write", write_f, 4, 1 },
        { OP_WRITEV, "writev", writev_f, 4, 1 },
 }, *ops_end;
        { OP_WRITE, "write", write_f, 4, 1 },
        { OP_WRITEV, "writev", writev_f, 4, 1 },
 }, *ops_end;
@@ -692,6 +703,12 @@ int main(int argc, char **argv)
                                fprintf(stderr, "io_setup failed");
                                exit(1);
                        }
                                fprintf(stderr, "io_setup failed");
                                exit(1);
                        }
+#endif
+#ifdef URING
+                       if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
+                               fprintf(stderr, "io_uring_queue_init failed\n");
+                               exit(1);
+                       }
 #endif
                        for (i = 0; !loops || (i < loops); i++)
                                doproc();
 #endif
                        for (i = 0; !loops || (i < loops); i++)
                                doproc();
@@ -701,7 +718,9 @@ int main(int argc, char **argv)
                                return 1;
                        }
 #endif
                                return 1;
                        }
 #endif
-
+#ifdef URING
+                       io_uring_queue_exit(&ring);
+#endif
                        cleanup_flist();
                        free(freq_table);
                        return 0;
                        cleanup_flist();
                        free(freq_table);
                        return 0;
@@ -2170,6 +2189,108 @@ do_aio_rw(int opno, long r, int flags)
 }
 #endif
 
 }
 #endif
 
+#ifdef URING
+void
+do_uring_rw(int opno, long r, int flags)
+{
+       char            *buf = NULL;
+       int             e;
+       pathname_t      f;
+       int             fd = -1;
+       size_t          len;
+       int64_t         lr;
+       off64_t         off;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+       struct io_uring_sqe     *sqe;
+       struct io_uring_cqe     *cqe;
+       struct iovec    iovec;
+       int             iswrite = (flags & (O_WRONLY | O_RDWR)) ? 1 : 0;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - no filename\n", procid, opno);
+               goto uring_out;
+       }
+       fd = open_path(&f, flags);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - open %s failed %d\n",
+                              procid, opno, f.path, e);
+               goto uring_out;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - fstat64 %s failed %d\n",
+                              procid, opno, f.path, errno);
+               goto uring_out;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       if (!iswrite && stb.st_size == 0) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - %s%s zero size\n", procid, opno,
+                              f.path, st);
+               goto uring_out;
+       }
+       sqe = io_uring_get_sqe(&ring);
+       if (!sqe) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - io_uring_get_sqe failed\n",
+                              procid, opno);
+               goto uring_out;
+       }
+       lr = ((int64_t)random() << 32) + random();
+       len = (random() % FILELEN_MAX) + 1;
+       buf = malloc(len);
+       if (!buf) {
+               if (v)
+                       printf("%d/%d: do_uring_rw - malloc failed\n",
+                              procid, opno);
+               goto uring_out;
+       }
+       iovec.iov_base = buf;
+       iovec.iov_len = len;
+       if (iswrite) {
+               off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+               off %= maxfsize;
+               memset(buf, nameseq & 0xff, len);
+               io_uring_prep_writev(sqe, fd, &iovec, 1, off);
+       } else {
+               off = (off64_t)(lr % stb.st_size);
+               io_uring_prep_readv(sqe, fd, &iovec, 1, off);
+       }
+
+       if ((e = io_uring_submit_and_wait(&ring, 1)) != 1) {
+               if (v)
+                       printf("%d/%d: %s - io_uring_submit failed %d\n", procid, opno,
+                              iswrite ? "uring_write" : "uring_read", e);
+               goto uring_out;
+       }
+       if ((e = io_uring_wait_cqe(&ring, &cqe)) < 0) {
+               if (v)
+                       printf("%d/%d: %s - io_uring_wait_cqe failed %d\n", procid, opno,
+                              iswrite ? "uring_write" : "uring_read", e);
+               goto uring_out;
+       }
+       if (v)
+               printf("%d/%d: %s %s%s [%lld, %d(res=%d)] %d\n",
+                      procid, opno, iswrite ? "uring_write" : "uring_read",
+                      f.path, st, (long long)off, (int)len, cqe->res, e);
+       io_uring_cqe_seen(&ring, cqe);
+
+ uring_out:
+       if (buf)
+               free(buf);
+       if (fd != -1)
+               close(fd);
+       free_pathname(&f);
+}
+#endif
+
 void
 aread_f(int opno, long r)
 {
 void
 aread_f(int opno, long r)
 {
@@ -5044,6 +5165,22 @@ unresvsp_f(int opno, long r)
        close(fd);
 }
 
        close(fd);
 }
 
+void
+uring_read_f(int opno, long r)
+{
+#ifdef URING
+       do_uring_rw(opno, r, O_RDONLY);
+#endif
+}
+
+void
+uring_write_f(int opno, long r)
+{
+#ifdef URING
+       do_uring_rw(opno, r, O_WRONLY);
+#endif
+}
+
 void
 write_f(int opno, long r)
 {
 void
 write_f(int opno, long r)
 {
index 7fbff822bfd9ebd7e75ed02133fc47fbd8ca24d7..0352534d94377af15f0180251f6be13e7c56cb86 100644 (file)
@@ -14,6 +14,7 @@ LSRCFILES = \
        package_dmapidev.m4 \
        package_globals.m4 \
        package_libcdev.m4 \
        package_dmapidev.m4 \
        package_globals.m4 \
        package_libcdev.m4 \
+       package_liburing.m4 \
        package_ncurses.m4 \
        package_pthread.m4 \
        package_ssldev.m4 \
        package_ncurses.m4 \
        package_pthread.m4 \
        package_ssldev.m4 \
diff --git a/m4/package_liburing.m4 b/m4/package_liburing.m4
new file mode 100644 (file)
index 0000000..c92cc02
--- /dev/null
@@ -0,0 +1,4 @@
+AC_DEFUN([AC_PACKAGE_WANT_URING],
+  [ AC_CHECK_HEADERS(liburing.h, [ have_uring=true ], [ have_uring=false ])
+    AC_SUBST(have_uring)
+  ])