Skip to content

Commit

Permalink
test/hardlink: code cleanup and fail on -EINVAL for flags
Browse files Browse the repository at this point in the history
Just some random cleanups to make it fit better with liburing, and then
a tweak so that if we do fail LINKAT with flags, then it should be a
hard failure. The latter is fixed by commit a52d4f657568 in Linus's
kernel tree.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed Sep 29, 2023
1 parent 0624120 commit f0e60d0
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions test/hardlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,34 @@
#include "liburing.h"
#include "helpers.h"


static int do_linkat(struct io_uring *ring, const char *oldname, const char *newname, int flags)
static int do_linkat(struct io_uring *ring, const char *oldname,
const char *newname, int flags)
{
int ret;
struct io_uring_sqe *sqe;
struct io_uring_cqe *cqe;
int ret;

sqe = io_uring_get_sqe(ring);
if (!sqe) {
fprintf(stderr, "sqe get failed\n");
goto err;
return 1;
}
io_uring_prep_linkat(sqe, AT_FDCWD, oldname, AT_FDCWD, newname, flags);

ret = io_uring_submit(ring);
if (ret != 1) {
fprintf(stderr, "submit failed: %d\n", ret);
goto err;
return 1;
}

ret = io_uring_wait_cqes(ring, &cqe, 1, 0, 0);
if (ret) {
fprintf(stderr, "wait_cqe failed: %d\n", ret);
goto err;
return 1;
}
ret = cqe->res;
io_uring_cqe_seen(ring, cqe);
return ret;
err:
return 1;
}

static int files_linked_ok(const char* fn1, const char *fn2)
Expand Down Expand Up @@ -72,8 +70,8 @@ int main(int argc, char *argv[])
static const char target[] = "io_uring-linkat-test-target";
static const char linkname[] = "io_uring-linkat-test-link";
static const char symlinkname[] = "io_uring-linkat-test-symlink";
int ret;
struct io_uring ring;
int ret;

if (argc > 1)
return T_EXIT_SKIP;
Expand Down Expand Up @@ -120,10 +118,6 @@ int main(int argc, char *argv[])

ret = do_linkat(&ring, symlinkname, linkname, AT_SYMLINK_FOLLOW);
if (ret < 0) {
if (ret == -EBADF || ret == -EINVAL) {
fprintf(stdout, "linkat with flags not supported, skipping\n");
goto skip;
}
fprintf(stderr, "linkat: %s\n", strerror(-ret));
goto err2;
} else if (ret) {
Expand Down

0 comments on commit f0e60d0

Please sign in to comment.