Message ID | 20240724-ioctl_ficlone-v3-1-bdf7551380ee@suse.com |
---|---|
State | Accepted |
Headers | show |
Series | [v3] Add ioctl_ficlone04 test | expand |
On Wed 24-07-24 22:02:11, Andrea Cervesato wrote: > From: Andrea Cervesato <andrea.cervesato@suse.com> > > This test verifies that ioctl() FICLONE/FICLONERANGE feature raises > the right error according with bad file descriptors. > > Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com> ... > +static void test_bad_fd(struct tst_fd *fd_src, struct tst_fd *fd_dst) > +{ > + if (fd_src->type == TST_FD_FILE && fd_src->type == fd_dst->type) { > + tst_res(TCONF, "Skipping file: SUCCESS"); > + return; > + } > + > + if (fd_src->type == TST_FD_MEMFD && fd_src->type == fd_dst->type) { > + tst_res(TCONF, "Skipping memory: EOPNOTSUPP"); > + return; > + } > + > + int exp_errnos[] = { > + EISDIR, > + EBADF, > + EINVAL, > + EXDEV, > + }; Two comments here: Sometimes security modules forbid operations on unexpected file types and you get EPERM in that case so I'd add it to the list of allowed error codes. Also the test for EOPNOTSUPP looks a bit fragile to me. Currently TST_FD_MEMFD is the only fd type where we'd get as far as checking whether the fs actually supports reflink but that could change in the future. So I'd not special-case MEMFD and instead add EOPNOTSUPP as another allowed error code. Otherwise the test looks good to me. Honza
diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore index 9f995b1ad..1f099ff95 100644 --- a/testcases/kernel/syscalls/ioctl/.gitignore +++ b/testcases/kernel/syscalls/ioctl/.gitignore @@ -25,5 +25,6 @@ /ioctl_ficlone01 /ioctl_ficlone02 /ioctl_ficlone03 +/ioctl_ficlone04 /ioctl_ficlonerange01 /ioctl_ficlonerange02 diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c b/testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c new file mode 100644 index 000000000..8420c269c --- /dev/null +++ b/testcases/kernel/syscalls/ioctl/ioctl_ficlone04.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2024 Andrea Cervesato andrea.cervesato@suse.com + */ + +/*\ + * [Description] + * + * This test verifies that ioctl() FICLONE/FICLONERANGE feature raises the right + * error according with bad file descriptors. + */ + +#include "tst_test.h" +#include "lapi/fs.h" + +static void test_bad_fd(struct tst_fd *fd_src, struct tst_fd *fd_dst) +{ + if (fd_src->type == TST_FD_FILE && fd_src->type == fd_dst->type) { + tst_res(TCONF, "Skipping file: SUCCESS"); + return; + } + + if (fd_src->type == TST_FD_MEMFD && fd_src->type == fd_dst->type) { + tst_res(TCONF, "Skipping memory: EOPNOTSUPP"); + return; + } + + int exp_errnos[] = { + EISDIR, + EBADF, + EINVAL, + EXDEV, + }; + + TST_EXP_FAIL2_ARR(ioctl(fd_dst->fd, FICLONE, fd_src->fd), + exp_errnos, ARRAY_SIZE(exp_errnos), + "ioctl(%s, FICLONE, %s)", + tst_fd_desc(fd_src), + tst_fd_desc(fd_dst)); +} + +static void run(void) +{ + TST_FD_FOREACH(fd_src) { + TST_FD_FOREACH(fd_dst) + test_bad_fd(&fd_src, &fd_dst); + } +} + +static struct tst_test test = { + .test_all = run, + .min_kver = "4.5", + .needs_root = 1, + .needs_tmpdir = 1, +};