summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-04-08 09:55:52 -0600
committerJens Axboe <axboe@kernel.dk>2020-04-08 09:55:52 -0600
commit8040ba7d9e0d0d7fba7aa557fd59aa1610fe835c (patch)
tree019d89716e1420cd1c0c094c69a8dddac4985205 /test
parent884f44fd30026d55012a975c6f86c75b98a4c217 (diff)
downloadliburing-8040ba7d9e0d0d7fba7aa557fd59aa1610fe835c.tar.gz
liburing-8040ba7d9e0d0d7fba7aa557fd59aa1610fe835c.tar.bz2
Coding style cleanups
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'test')
-rw-r--r--test/lfs-openat-write.c31
-rw-r--r--test/lfs-openat.c35
2 files changed, 37 insertions, 29 deletions
diff --git a/test/lfs-openat-write.c b/test/lfs-openat-write.c
index b36a288..8c46032 100644
--- a/test/lfs-openat-write.c
+++ b/test/lfs-openat-write.c
@@ -21,8 +21,9 @@ static const mode_t OPEN_MODE = S_IRUSR | S_IWUSR;
static int do_write(struct io_uring *ring, int fd, off_t offset)
{
char buf[] = "some test write buf";
- int res;
struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ int res, ret;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
@@ -30,14 +31,13 @@ static int do_write(struct io_uring *ring, int fd, off_t offset)
return 1;
}
io_uring_prep_write(sqe, fd, buf, sizeof(buf), offset);
- int ret = io_uring_submit(ring);
+
+ ret = io_uring_submit(ring);
if (ret < 0) {
fprintf(stderr, "failed to submit write: %s\n", strerror(-ret));
return 1;
}
- struct io_uring_cqe *cqe;
-
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
fprintf(stderr, "wait_cqe failed: %s\n", strerror(-ret));
@@ -57,22 +57,22 @@ static int do_write(struct io_uring *ring, int fd, off_t offset)
static int test_open_write(struct io_uring *ring, int dfd, const char *fn)
{
struct io_uring_sqe *sqe;
- int fd = -1;
+ struct io_uring_cqe *cqe;
+ int ret, fd = -1;
sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "failed to get sqe\n");
return 1;
}
-
io_uring_prep_openat(sqe, dfd, fn, OPEN_FLAGS, OPEN_MODE);
- int ret = io_uring_submit(ring);
+
+ ret = io_uring_submit(ring);
if (ret < 0) {
fprintf(stderr, "failed to submit openat: %s\n", strerror(-ret));
return 1;
}
- struct io_uring_cqe *cqe;
ret = io_uring_wait_cqe(ring, &cqe);
if (ret < 0) {
fprintf(stderr, "wait_cqe failed: %s\n", strerror(-ret));
@@ -91,15 +91,16 @@ static int test_open_write(struct io_uring *ring, int dfd, const char *fn)
int main(int argc, char *argv[])
{
- int dfd = open("/tmp", O_RDONLY | O_DIRECTORY);
- if (dfd < 0) {
- DIE("open /tmp: %s\n", strerror(errno));
- }
struct io_uring ring;
- int ret = io_uring_queue_init(RSIZE, &ring, 0);
- if (ret < 0) {
+ int dfd, ret;
+
+ dfd = open("/tmp", O_RDONLY | O_DIRECTORY);
+ if (dfd < 0)
+ DIE("open /tmp: %s\n", strerror(errno));
+
+ ret = io_uring_queue_init(RSIZE, &ring, 0);
+ if (ret < 0)
DIE("failed to init io_uring: %s\n", strerror(-ret));
- }
ret = test_open_write(&ring, dfd, "io_uring_openat_write_test1");
diff --git a/test/lfs-openat.c b/test/lfs-openat.c
index 1765fb5..d26111a 100644
--- a/test/lfs-openat.c
+++ b/test/lfs-openat.c
@@ -22,21 +22,24 @@ static const mode_t OPEN_MODE = S_IRUSR | S_IWUSR;
static int open_io_uring(struct io_uring *ring, int dfd, const char *fn)
{
struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe;
+ int ret, fd;
+
sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "failed to get sqe\n");
return 1;
}
io_uring_prep_openat(sqe, dfd, fn, OPEN_FLAGS, OPEN_MODE);
- int ret = io_uring_submit(ring);
+
+ ret = io_uring_submit(ring);
if (ret < 0) {
fprintf(stderr, "failed to submit openat: %s\n", strerror(-ret));
return 1;
}
- struct io_uring_cqe *cqe;
ret = io_uring_wait_cqe(ring, &cqe);
- int fd = cqe->res;
+ fd = cqe->res;
io_uring_cqe_seen(ring, cqe);
if (ret < 0) {
fprintf(stderr, "wait_cqe failed: %s\n", strerror(-ret));
@@ -50,18 +53,21 @@ static int open_io_uring(struct io_uring *ring, int dfd, const char *fn)
return 0;
}
-int prepare_file(int dfd, const char* fn)
+static int prepare_file(int dfd, const char* fn)
{
const char buf[] = "foo";
- int fd = openat(dfd, fn, OPEN_FLAGS, OPEN_MODE);
+ int fd, res;
+
+ fd = openat(dfd, fn, OPEN_FLAGS, OPEN_MODE);
if (fd < 0) {
fprintf(stderr, "prepare/open: %s\n", strerror(errno));
return -1;
}
- int res = pwrite(fd, buf, sizeof(buf), 1ull << 32);
- if (res < 0) {
+
+ res = pwrite(fd, buf, sizeof(buf), 1ull << 32);
+ if (res < 0)
fprintf(stderr, "prepare/pwrite: %s\n", strerror(errno));
- }
+
close(fd);
return res < 0 ? res : 0;
}
@@ -70,14 +76,15 @@ int main(int argc, char *argv[])
{
const char *fn = "io_uring_openat_test";
int dfd = open("/tmp", O_RDONLY | O_DIRECTORY);
- if (dfd < 0) {
- DIE("open /tmp: %s\n", strerror(errno));
- }
struct io_uring ring;
- int ret = io_uring_queue_init(RSIZE, &ring, 0);
- if (ret < 0) {
+ int ret;
+
+ if (dfd < 0)
+ DIE("open /tmp: %s\n", strerror(errno));
+
+ ret = io_uring_queue_init(RSIZE, &ring, 0);
+ if (ret < 0)
DIE("failed to init io_uring: %s\n", strerror(-ret));
- }
if (prepare_file(dfd, fn))
return 1;