From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 1/2] Fix unlink09 test
Date: Tue, 02 Jul 2024 09:38:17 +0200 [thread overview]
Message-ID: <20240702-unlink09-v4-1-d8df24772a76@suse.com> (raw)
In-Reply-To: <20240702-unlink09-v4-0-d8df24772a76@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
This patch will fix unlink09 test by checking for filesystems which
are not supporting inode attributes. At the same time, it removes the
read-only filesystem unlink() check in order to add .all_filesystems
support.
Fixes: 2cf78f47a6 (unlink: Add error tests for EPERM and EROFS)
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/unlink/unlink09.c | 108 ++++++++++++++++------------
1 file changed, 64 insertions(+), 44 deletions(-)
diff --git a/testcases/kernel/syscalls/unlink/unlink09.c b/testcases/kernel/syscalls/unlink/unlink09.c
index cc4b4a07e..5e438569f 100644
--- a/testcases/kernel/syscalls/unlink/unlink09.c
+++ b/testcases/kernel/syscalls/unlink/unlink09.c
@@ -2,92 +2,103 @@
/*
* Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
* Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
*/
/*\
* [Description]
*
- * Verify that unlink(2) fails with
- *
- * - EPERM when target file is marked as immutable or append-only
- * - EROFS when target file is on a read-only filesystem.
+ * Verify that unlink(2) fails with EPERM when target file is marked as
+ * immutable or append-only.
*/
#include <sys/ioctl.h>
#include "tst_test.h"
#include "lapi/fs.h"
-#define TEST_EPERM_IMMUTABLE "test_eperm_immutable"
-#define TEST_EPERM_APPEND_ONLY "test_eperm_append_only"
-#define DIR_EROFS "erofs"
-#define TEST_EROFS "erofs/test_erofs"
+#define MNTPOINT "mnt"
+#define TEST_EPERM_IMMUTABLE MNTPOINT"/test_eperm_immutable"
+#define TEST_EPERM_APPEND_ONLY MNTPOINT"/test_eperm_append_only"
-static int fd_immutable;
-static int fd_append_only;
+static int fd_immutable = -1;
+static int fd_append_only = -1;
static struct test_case_t {
char *filename;
int *fd;
int flag;
- int expected_errno;
char *desc;
} tcases[] = {
- {TEST_EPERM_IMMUTABLE, &fd_immutable, FS_IMMUTABLE_FL, EPERM,
+ {TEST_EPERM_IMMUTABLE, &fd_immutable, FS_IMMUTABLE_FL,
"target file is immutable"},
- {TEST_EPERM_APPEND_ONLY, &fd_append_only, FS_APPEND_FL, EPERM,
+ {TEST_EPERM_APPEND_ONLY, &fd_append_only, FS_APPEND_FL,
"target file is append-only"},
- {TEST_EROFS, NULL, 0, EROFS, "target file in read-only filesystem"},
};
+static void setup_inode_flag(const int fd, const int flag, const int reset)
+{
+ int attr;
+
+ SAFE_IOCTL(fd, FS_IOC_GETFLAGS, &attr);
+
+ if (reset)
+ attr &= ~flag;
+ else
+ attr |= flag;
+
+ SAFE_IOCTL(fd, FS_IOC_SETFLAGS, &attr);
+}
+
static void setup(void)
{
int attr;
- fd_immutable = SAFE_OPEN(TEST_EPERM_IMMUTABLE, O_CREAT, 0600);
- SAFE_IOCTL(fd_immutable, FS_IOC_GETFLAGS, &attr);
+ /* inode attributes in tmpfs are supported from kernel 6.0
+ * https://lore.kernel.org/all/20220715015912.2560575-1-tytso@mit.edu/
+ */
+ if (!strcmp(tst_device->fs_type, "tmpfs") && tst_kvercmp(6, 0, 0) < 0)
+ tst_brk(TCONF, "FS_IOC_GETFLAGS on tmpfs not supported for kernel<6.0");
+
+ fd_immutable = SAFE_CREAT(TEST_EPERM_IMMUTABLE, 0600);
+ TEST(ioctl(fd_immutable, FS_IOC_GETFLAGS, &attr));
+
+ if (TST_RET == -1 && TST_ERR == ENOTTY) {
+ SAFE_CLOSE(fd_immutable);
+
+ tst_brk(TBROK, "Inode attributes not supported by '%s'",
+ tst_device->fs_type);
+ }
+
attr |= FS_IMMUTABLE_FL;
SAFE_IOCTL(fd_immutable, FS_IOC_SETFLAGS, &attr);
- fd_append_only = SAFE_OPEN(TEST_EPERM_APPEND_ONLY, O_CREAT, 0600);
- SAFE_IOCTL(fd_append_only, FS_IOC_GETFLAGS, &attr);
- attr |= FS_APPEND_FL;
- SAFE_IOCTL(fd_append_only, FS_IOC_SETFLAGS, &attr);
+ fd_append_only = SAFE_CREAT(TEST_EPERM_APPEND_ONLY, 0600);
+ setup_inode_flag(fd_append_only, FS_APPEND_FL, 0);
}
static void cleanup(void)
{
- int attr;
-
- SAFE_IOCTL(fd_immutable, FS_IOC_GETFLAGS, &attr);
- attr &= ~FS_IMMUTABLE_FL;
- SAFE_IOCTL(fd_immutable, FS_IOC_SETFLAGS, &attr);
- SAFE_CLOSE(fd_immutable);
+ if (fd_immutable != -1) {
+ setup_inode_flag(fd_immutable, FS_IMMUTABLE_FL, 1);
+ SAFE_CLOSE(fd_immutable);
+ }
- SAFE_IOCTL(fd_append_only, FS_IOC_GETFLAGS, &attr);
- attr &= ~FS_APPEND_FL;
- SAFE_IOCTL(fd_append_only, FS_IOC_SETFLAGS, &attr);
- SAFE_CLOSE(fd_append_only);
+ if (fd_append_only != -1) {
+ setup_inode_flag(fd_append_only, FS_APPEND_FL, 1);
+ SAFE_CLOSE(fd_append_only);
+ }
}
static void verify_unlink(unsigned int i)
{
struct test_case_t *tc = &tcases[i];
- int attr;
- TST_EXP_FAIL(unlink(tc->filename), tc->expected_errno, "%s", tc->desc);
+ TST_EXP_FAIL(unlink(tc->filename), EPERM, "%s", tc->desc);
/* If unlink() succeeded unexpectedly, test file should be restored. */
if (!TST_RET) {
- if (tc->fd) {
- *(tc->fd) = SAFE_OPEN(tc->filename, O_CREAT, 0600);
- if (tc->flag) {
- SAFE_IOCTL(*(tc->fd), FS_IOC_GETFLAGS, &attr);
- attr |= tc->flag;
- SAFE_IOCTL(*(tc->fd), FS_IOC_SETFLAGS, &attr);
- }
- } else {
- SAFE_TOUCH(tc->filename, 0600, 0);
- }
+ *(tc->fd) = SAFE_CREAT(tc->filename, 0600);
+ setup_inode_flag(*(tc->fd), tc->flag, 0);
}
}
@@ -96,7 +107,16 @@ static struct tst_test test = {
.tcnt = ARRAY_SIZE(tcases),
.cleanup = cleanup,
.test = verify_unlink,
- .needs_rofs = 1,
- .mntpoint = DIR_EROFS,
+ .mntpoint = MNTPOINT,
.needs_root = 1,
+ .format_device = 1,
+ .mount_device = 1,
+ .all_filesystems = 1,
+ .skip_filesystems = (const char *const[]) {
+ "fuse",
+ "exfat",
+ "vfat",
+ "ntfs",
+ NULL
+ },
};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-07-02 7:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 7:38 [LTP] [PATCH v4 0/2] Fix unlink09 test Andrea Cervesato
2024-07-02 7:38 ` Andrea Cervesato [this message]
2024-07-02 13:57 ` [LTP] [PATCH v4 1/2] " Cyril Hrubis
2024-07-02 14:02 ` Andrea Cervesato via ltp
2024-07-02 14:18 ` Cyril Hrubis
2024-07-02 7:38 ` [LTP] [PATCH v4 2/2] Add unlink10 test Andrea Cervesato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240702-unlink09-v4-1-d8df24772a76@suse.com \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.