* [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify)
2022-04-14 14:53 [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Amir Goldstein
@ 2022-04-14 14:53 ` Amir Goldstein
2022-04-14 15:12 ` Petr Vorel
2022-04-14 14:53 ` [LTP] [PATCH 2/6] syscalls/fanotify14: Add tests for FAN_REPORT_TARGET_FID and FAN_RENAME Amir Goldstein
` (5 subsequent siblings)
6 siblings, 1 reply; 11+ messages in thread
From: Amir Goldstein @ 2022-04-14 14:53 UTC (permalink / raw)
To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp
Check that signal is delivered for directory watching for DN_RENAME
only when rename is within the same directory.
Even if both old and new directories are watches, DN_RENAME is not
generated on cross parent rename.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
runtest/syscalls | 2 +
testcases/kernel/syscalls/fcntl/.gitignore | 2 +
testcases/kernel/syscalls/fcntl/fcntl39.c | 114 +++++++++++++++++++++
3 files changed, 118 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl39.c
diff --git a/runtest/syscalls b/runtest/syscalls
index c30383ee5..d43d6983b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -334,6 +334,8 @@ fcntl37 fcntl37
fcntl37_64 fcntl37_64
fcntl38 fcntl38
fcntl38_64 fcntl38_64
+fcntl39 fcntl39
+fcntl39_64 fcntl39_64
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore
index ede0c97b8..48b36ec34 100644
--- a/testcases/kernel/syscalls/fcntl/.gitignore
+++ b/testcases/kernel/syscalls/fcntl/.gitignore
@@ -74,3 +74,5 @@
/fcntl37_64
/fcntl38
/fcntl38_64
+/fcntl39
+/fcntl39_64
diff --git a/testcases/kernel/syscalls/fcntl/fcntl39.c b/testcases/kernel/syscalls/fcntl/fcntl39.c
new file mode 100644
index 000000000..0fef20764
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl39.c
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021 CTERA Networks. All Rights Reserved.
+ *
+ * Started by Amir Goldstein <amir73il@gmail.com>
+ *
+ * DESCRIPTION
+ * Check that dnotify DN_RENAME event is reported only on rename
+ * inside same parent
+ */
+
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "lapi/fcntl.h"
+
+#define TEST_DIR "test_dir"
+#define TEST_DIR2 "test_dir2"
+#define TEST_FILE "test_file"
+
+#define TEST_SIG SIGRTMIN+1
+
+static int parent_fd, subdir_fd;
+static int got_parent_event, got_subdir_event;
+
+static void dnotify_handler(int sig, siginfo_t *si, void *data __attribute__((unused)))
+{
+ if (si->si_fd == parent_fd)
+ got_parent_event = 1;
+ else if (si->si_fd == subdir_fd)
+ got_subdir_event = 1;
+ else
+ tst_brk(TBROK, "Got unexpected signal %d with si_fd %d", sig, si->si_fd);
+}
+
+static void setup_dnotify(int fd)
+{
+ struct sigaction act;
+
+ act.sa_sigaction = dnotify_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = SA_SIGINFO;
+ sigaction(TEST_SIG, &act, NULL);
+
+ TEST(fcntl(fd, F_SETSIG, TEST_SIG));
+ if (TST_RET != 0) {
+ tst_brk(TBROK, "F_SETSIG failed errno = %d : %s",
+ TST_ERR, strerror(TST_ERR));
+ }
+ TEST(fcntl(fd, F_NOTIFY, DN_RENAME|DN_MULTISHOT));
+ if (TST_RET != 0) {
+ tst_brk(TBROK, "F_NOTIFY failed errno = %d : %s",
+ TST_ERR, strerror(TST_ERR));
+ }
+}
+
+static void verify_dnotify(void)
+{
+ parent_fd = SAFE_OPEN(".", O_RDONLY);
+ subdir_fd = SAFE_OPEN(TEST_DIR, O_RDONLY);
+ /* Watch renames inside ".", but not in and out of "." */
+ setup_dnotify(parent_fd);
+ /* Also watch for renames inside subdir, but not in and out of subdir */
+ setup_dnotify(subdir_fd);
+ /* Rename file from "." to subdir should not generate DN_RENAME on either */
+ tst_res(TINFO, "Testing no DN_RENAME on rename from parent to subdir");
+ SAFE_RENAME(TEST_FILE, TEST_DIR "/" TEST_FILE);
+ if (got_parent_event)
+ tst_res(TFAIL, "Got unexpected event on parent");
+ else
+ tst_res(TPASS, "No event on parent as expected");
+ if (got_subdir_event)
+ tst_res(TFAIL, "Got unexpected event on subdir");
+ else
+ tst_res(TPASS, "No event on subdir as expected");
+ /* Rename subdir itself should generate DN_RENAME on ".", but not on itself */
+ tst_res(TINFO, "Testing DN_RENAME on rename of subdir itself");
+ SAFE_RENAME(TEST_DIR, TEST_DIR2);
+ if (got_parent_event)
+ tst_res(TPASS, "Got event on parent as expected");
+ else
+ tst_res(TFAIL, "Missing event on parent");
+ if (got_subdir_event)
+ tst_res(TFAIL, "Got unexpected event on subdir");
+ else
+ tst_res(TPASS, "No event on subdir as expected");
+
+ SAFE_CLOSE(parent_fd);
+ SAFE_CLOSE(subdir_fd);
+}
+
+static void setup(void)
+{
+ SAFE_MKDIR(TEST_DIR, 00700);
+ SAFE_TOUCH(TEST_FILE, 0666, NULL);
+}
+
+static void cleanup(void)
+{
+ if (parent_fd > 0)
+ SAFE_CLOSE(parent_fd);
+ if (subdir_fd > 0)
+ SAFE_CLOSE(subdir_fd);
+}
+
+static struct tst_test test = {
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_dnotify,
+ .needs_kconfigs = (const char *[]) { "CONFIG_DNOTIFY=y", NULL },
+};
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify)
2022-04-14 14:53 ` [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify) Amir Goldstein
@ 2022-04-14 15:12 ` Petr Vorel
2022-04-14 15:31 ` Amir Goldstein
0 siblings, 1 reply; 11+ messages in thread
From: Petr Vorel @ 2022-04-14 15:12 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp
Hi Amir,
could you please fix fcntl39.c to be running for more iterations?
./fcntl39_64 -i2
tst_kconfig.c:82: TINFO: Parsing kernel config '/proc/config.gz'
tst_test.c:1459: TINFO: Timeout per run is 0h 05m 00s
fcntl39.c:68: TINFO: Testing no DN_RENAME on rename from parent to subdir
fcntl39.c:73: TPASS: No event on parent as expected
fcntl39.c:77: TPASS: No event on subdir as expected
fcntl39.c:79: TINFO: Testing DN_RENAME on rename of subdir itself
fcntl39.c:82: TPASS: Got event on parent as expected
fcntl39.c:88: TPASS: No event on subdir as expected
fcntl39.c:62: TBROK: open(test_dir,0,20254540) failed: ENOENT (2)
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify)
2022-04-14 15:12 ` Petr Vorel
@ 2022-04-14 15:31 ` Amir Goldstein
2022-04-14 19:03 ` Petr Vorel
0 siblings, 1 reply; 11+ messages in thread
From: Amir Goldstein @ 2022-04-14 15:31 UTC (permalink / raw)
To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, LTP List
On Thu, Apr 14, 2022 at 6:12 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Amir,
>
> could you please fix fcntl39.c to be running for more iterations?
>
> ./fcntl39_64 -i2
> tst_kconfig.c:82: TINFO: Parsing kernel config '/proc/config.gz'
> tst_test.c:1459: TINFO: Timeout per run is 0h 05m 00s
> fcntl39.c:68: TINFO: Testing no DN_RENAME on rename from parent to subdir
> fcntl39.c:73: TPASS: No event on parent as expected
> fcntl39.c:77: TPASS: No event on subdir as expected
> fcntl39.c:79: TINFO: Testing DN_RENAME on rename of subdir itself
> fcntl39.c:82: TPASS: Got event on parent as expected
> fcntl39.c:88: TPASS: No event on subdir as expected
> fcntl39.c:62: TBROK: open(test_dir,0,20254540) failed: ENOENT (2)
>
> Kind regards,
> Petr
Sorry forgot to run it with -i
Here is the fix if you want to apply it yourself:
--- a/testcases/kernel/syscalls/fcntl/fcntl39.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl39.c
@@ -89,6 +89,12 @@ static void verify_dnotify(void)
SAFE_CLOSE(parent_fd);
SAFE_CLOSE(subdir_fd);
+
+ /* Cleanup before rerun */
+ SAFE_RENAME(TEST_DIR2 "/" TEST_FILE, TEST_FILE);
+ SAFE_RENAME(TEST_DIR2, TEST_DIR);
+ got_parent_event = 0;
+ got_subdir_event = 0;
}
Thanks,
Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify)
2022-04-14 15:31 ` Amir Goldstein
@ 2022-04-14 19:03 ` Petr Vorel
0 siblings, 0 replies; 11+ messages in thread
From: Petr Vorel @ 2022-04-14 19:03 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, LTP List
Hi Amir,
> Sorry forgot to run it with -i
> Here is the fix if you want to apply it yourself:
> --- a/testcases/kernel/syscalls/fcntl/fcntl39.c
> +++ b/testcases/kernel/syscalls/fcntl/fcntl39.c
> @@ -89,6 +89,12 @@ static void verify_dnotify(void)
> SAFE_CLOSE(parent_fd);
> SAFE_CLOSE(subdir_fd);
> +
> + /* Cleanup before rerun */
> + SAFE_RENAME(TEST_DIR2 "/" TEST_FILE, TEST_FILE);
> + SAFE_RENAME(TEST_DIR2, TEST_DIR);
> + got_parent_event = 0;
> + got_subdir_event = 0;
> }
Thanks for a quick fix, patch merged (with minor changes to keep checkpatch happy).
Kind regards,
Petr
> Thanks,
> Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 11+ messages in thread
* [LTP] [PATCH 2/6] syscalls/fanotify14: Add tests for FAN_REPORT_TARGET_FID and FAN_RENAME
2022-04-14 14:53 [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Amir Goldstein
2022-04-14 14:53 ` [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify) Amir Goldstein
@ 2022-04-14 14:53 ` Amir Goldstein
2022-04-14 14:53 ` [LTP] [PATCH 3/6] syscalls/fanotify16: Add test cases for FAN_REPORT_TARGET_FID Amir Goldstein
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2022-04-14 14:53 UTC (permalink / raw)
To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp
Validate flag combinations:
1) FAN_REPORT_TARGET_FID requires FAN_REPORT_NAME and FAN_REPORT_FID
2) FAN_RENAME requires FAN_REPORT_NAME
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
testcases/kernel/syscalls/fanotify/fanotify.h | 15 +++++++++++++++
testcases/kernel/syscalls/fanotify/fanotify14.c | 12 ++++++++++++
2 files changed, 27 insertions(+)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index b2855d292..eb690e332 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -81,6 +81,11 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
#ifndef FAN_REPORT_PIDFD
#define FAN_REPORT_PIDFD 0x00000080
#endif
+#ifndef FAN_REPORT_TARGET_FID
+#define FAN_REPORT_TARGET_FID 0x00001000
+#define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \
+ FAN_REPORT_FID | FAN_REPORT_TARGET_FID)
+#endif
/* Non-uapi convenience macros */
#ifndef FAN_REPORT_DFID_NAME_FID
@@ -130,6 +135,9 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
#ifndef FAN_FS_ERROR
#define FAN_FS_ERROR 0x00008000
#endif
+#ifndef FAN_RENAME
+#define FAN_RENAME 0x10000000
+#endif
/* Additional error status codes that can be returned to userspace */
#ifndef FAN_NOPIDFD
@@ -185,6 +193,13 @@ typedef struct {
#define FAN_EVENT_INFO_TYPE_ERROR 5
#endif
+#ifndef FAN_EVENT_INFO_TYPE_OLD_DFID_NAME
+#define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME 10
+#endif
+#ifndef FAN_EVENT_INFO_TYPE_NEW_DFID_NAME
+#define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME 12
+#endif
+
#ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER
struct fanotify_event_info_header {
uint8_t info_type;
diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c
index 1944bcbb4..5d74b9b91 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify14.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify14.c
@@ -62,6 +62,18 @@ static struct test_case_t {
/* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */
FAN_CLASS_NOTIF | FAN_REPORT_FID | FAN_REPORT_NAME, 0, 0
},
+ {
+ /* FAN_REPORT_TARGET_FID without FAN_REPORT_FID is not valid */
+ FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_NAME, 0, 0
+ },
+ {
+ /* FAN_REPORT_TARGET_FID without FAN_REPORT_NAME is not valid */
+ FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_FID, 0, 0
+ },
+ {
+ /* FAN_RENAME without FAN_REPORT_NAME is not valid */
+ FAN_CLASS_NOTIF | FAN_REPORT_DFID_FID, 0, FAN_RENAME
+ },
};
static void do_test(unsigned int number)
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH 3/6] syscalls/fanotify16: Add test cases for FAN_REPORT_TARGET_FID
2022-04-14 14:53 [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Amir Goldstein
2022-04-14 14:53 ` [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify) Amir Goldstein
2022-04-14 14:53 ` [LTP] [PATCH 2/6] syscalls/fanotify14: Add tests for FAN_REPORT_TARGET_FID and FAN_RENAME Amir Goldstein
@ 2022-04-14 14:53 ` Amir Goldstein
2022-04-14 14:53 ` [LTP] [PATCH 4/6] syscalls/fanotify16: Add test cases for FAN_RENAME Amir Goldstein
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2022-04-14 14:53 UTC (permalink / raw)
To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp
Verify both parent and child fids are reported for dirent events
with FAN_REPORT_TARGET_FID.
When child fid is reported for dirent events, they can be merged
with events "on child" (e.g. open/close).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify16.c | 69 +++++++++++++++----
1 file changed, 57 insertions(+), 12 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c
index 40bcdd581..529d18ee2 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify16.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify16.c
@@ -14,6 +14,7 @@
* - FAN_REPORT_DIR_FID (dir fid)
* - FAN_REPORT_DIR_FID | FAN_REPORT_FID (dir fid + child fid)
* - FAN_REPORT_DFID_NAME | FAN_REPORT_FID (dir fid + name + child fid)
+ * - FAN_REPORT_DFID_NAME_TARGET (dir fid + name + created/deleted file fid)
*/
#define _GNU_SOURCE
@@ -64,6 +65,8 @@ static char event_buf[EVENT_BUF_LEN];
#define FILE_NAME2 "test_file2"
#define MOUNT_PATH "fs_mnt"
+static int fan_report_target_fid_unsupported;
+
static struct test_case_t {
const char *tname;
struct fanotify_group_type group;
@@ -148,6 +151,25 @@ static struct test_case_t {
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
},
+ {
+ "FAN_REPORT_DFID_NAME_TARGET monitor filesystem for create/delete/move/open/close",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+ INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+ /* Mount watch for events possible on children */
+ INIT_FANOTIFY_MARK_TYPE(MOUNT),
+ FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ },
+ {
+ "FAN_REPORT_DFID_NAME_TARGET monitor directories for create/delete/move/open/close",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR,
+ /* Watches for self events on subdir and events on subdir's children */
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+ FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ },
};
static void do_test(unsigned int number)
@@ -158,9 +180,18 @@ static void do_test(unsigned int number)
struct fanotify_mark_type *mark = &tc->mark;
struct fanotify_mark_type *sub_mark = &tc->sub_mark;
struct fanotify_fid_t root_fid, dir_fid, file_fid;
+ struct fanotify_fid_t *child_fid = NULL, *subdir_fid = NULL;
+ int report_name = (group->flag & FAN_REPORT_NAME);
+ int report_target_fid = (group->flag & FAN_REPORT_TARGET_FID);
tst_res(TINFO, "Test #%d: %s", number, tc->tname);
+ if (fan_report_target_fid_unsupported && report_target_fid) {
+ FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_TARGET_FID,
+ fan_report_target_fid_unsupported);
+ return;
+ }
+
fd_notify = SAFE_FANOTIFY_INIT(group->flag, 0);
/*
@@ -181,6 +212,9 @@ static void do_test(unsigned int number)
/* Save the subdir fid */
fanotify_save_fid(dname1, &dir_fid);
+ /* With FAN_REPORT_TARGET_FID, report subdir fid also for dirent events */
+ if (report_target_fid)
+ subdir_fid = &dir_fid;
if (tc->sub_mask)
SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | sub_mark->flag,
@@ -188,7 +222,7 @@ static void do_test(unsigned int number)
event_set[tst_count].mask = FAN_CREATE | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
- event_set[tst_count].child_fid = NULL;
+ event_set[tst_count].child_fid = subdir_fid;
strcpy(event_set[tst_count].name, DIR_NAME1);
tst_count++;
@@ -197,6 +231,9 @@ static void do_test(unsigned int number)
/* Save the file fid */
fanotify_save_fid(fname1, &file_fid);
+ /* With FAN_REPORT_TARGET_FID, report child fid also for dirent events */
+ if (report_target_fid)
+ child_fid = &file_fid;
SAFE_WRITE(1, fd, "1", 1);
SAFE_RENAME(fname1, fname2);
@@ -214,7 +251,7 @@ static void do_test(unsigned int number)
*/
event_set[tst_count].mask = FAN_CREATE | FAN_MOVED_FROM;
event_set[tst_count].fid = &dir_fid;
- event_set[tst_count].child_fid = NULL;
+ event_set[tst_count].child_fid = child_fid;
strcpy(event_set[tst_count].name, FILE_NAME1);
tst_count++;
/*
@@ -224,7 +261,7 @@ static void do_test(unsigned int number)
* FAN_REPORT_NAME is not set, then FAN_CREATE above is merged with
* FAN_DELETE below and FAN_OPEN will be merged with FAN_CLOSE.
*/
- if (group->flag & FAN_REPORT_NAME) {
+ if (report_name) {
event_set[tst_count].mask = FAN_OPEN;
event_set[tst_count].fid = &dir_fid;
event_set[tst_count].child_fid = &file_fid;
@@ -233,15 +270,22 @@ static void do_test(unsigned int number)
}
event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO;
+ /*
+ * With FAN_REPORT_TARGET_FID, close of FILE_NAME2 is merged with
+ * moved_to and delete events, because they all have parent and
+ * child fid records.
+ */
+ if (report_target_fid)
+ event_set[tst_count].mask |= FAN_CLOSE_WRITE;
event_set[tst_count].fid = &dir_fid;
- event_set[tst_count].child_fid = NULL;
+ event_set[tst_count].child_fid = child_fid;
strcpy(event_set[tst_count].name, FILE_NAME2);
tst_count++;
/*
* When not reporting name, open of FILE_NAME1 is merged
* with close of FILE_NAME2.
*/
- if (!(group->flag & FAN_REPORT_NAME)) {
+ if (!report_name) {
event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_WRITE;
event_set[tst_count].fid = &dir_fid;
event_set[tst_count].child_fid = &file_fid;
@@ -261,11 +305,10 @@ static void do_test(unsigned int number)
tst_count++;
}
/*
- * When reporting name, close of FILE_NAME2 is not merged with
- * open of FILE_NAME1 and it is received after the merged self
- * events.
+ * Without FAN_REPORT_TARGET_FID, close of FILE_NAME2 is not merged with
+ * open of FILE_NAME1 and it is received after the merged self events.
*/
- if (group->flag & FAN_REPORT_NAME) {
+ if (report_name && !report_target_fid) {
event_set[tst_count].mask = FAN_CLOSE_WRITE;
event_set[tst_count].fid = &dir_fid;
event_set[tst_count].child_fid = &file_fid;
@@ -305,12 +348,12 @@ static void do_test(unsigned int number)
event_set[tst_count].mask = FAN_MOVED_FROM | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
- event_set[tst_count].child_fid = NULL;
+ event_set[tst_count].child_fid = subdir_fid;
strcpy(event_set[tst_count].name, DIR_NAME1);
tst_count++;
event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
- event_set[tst_count].child_fid = NULL;
+ event_set[tst_count].child_fid = subdir_fid;
strcpy(event_set[tst_count].name, DIR_NAME2);
tst_count++;
/* Expect no more events */
@@ -355,7 +398,7 @@ static void do_test(unsigned int number)
if (!(group->flag & FAN_REPORT_FID))
expected_child_fid = NULL;
- if (!(group->flag & FAN_REPORT_NAME))
+ if (!report_name)
expected->name[0] = 0;
if (expected->name[0]) {
@@ -545,6 +588,8 @@ check_match:
static void setup(void)
{
REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_DIR_FID, MOUNT_PATH);
+ fan_report_target_fid_unsupported =
+ fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME_TARGET, MOUNT_PATH);
sprintf(dname1, "%s/%s", MOUNT_PATH, DIR_NAME1);
sprintf(dname2, "%s/%s", MOUNT_PATH, DIR_NAME2);
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH 4/6] syscalls/fanotify16: Add test cases for FAN_RENAME
2022-04-14 14:53 [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Amir Goldstein
` (2 preceding siblings ...)
2022-04-14 14:53 ` [LTP] [PATCH 3/6] syscalls/fanotify16: Add test cases for FAN_REPORT_TARGET_FID Amir Goldstein
@ 2022-04-14 14:53 ` Amir Goldstein
2022-04-14 14:53 ` [LTP] [PATCH 5/6] syscalls/fanotify16: Test FAN_RENAME with one watching directory Amir Goldstein
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2022-04-14 14:53 UTC (permalink / raw)
To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp
In the special case of FAN_RENAME event, the second record contains the
the new parent + name, which also prevent merge of FAN_RENAME event
with any other event.
TODO: check 2nd name and child fid
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify16.c | 88 ++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c
index 529d18ee2..b5b53e7d8 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify16.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify16.c
@@ -49,6 +49,7 @@ struct event_t {
struct fanotify_fid_t *fid;
struct fanotify_fid_t *child_fid;
char name[BUF_SIZE];
+ char name2[BUF_SIZE];
};
static char fname1[BUF_SIZE + 11], fname2[BUF_SIZE + 11];
@@ -66,6 +67,7 @@ static char event_buf[EVENT_BUF_LEN];
#define MOUNT_PATH "fs_mnt"
static int fan_report_target_fid_unsupported;
+static int rename_events_unsupported;
static struct test_case_t {
const char *tname;
@@ -170,6 +172,44 @@ static struct test_case_t {
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
},
+ {
+ "FAN_REPORT_DFID_NAME_FID monitor filesystem for create/delete/move/rename/open/close",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+ INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+ /* Mount watch for events possible on children */
+ INIT_FANOTIFY_MARK_TYPE(MOUNT),
+ FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ },
+ {
+ "FAN_REPORT_DFID_NAME_FID monitor directories for create/delete/move/rename/open/close",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_ONDIR,
+ /* Watches for self events on subdir and events on subdir's children */
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+ FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ },
+ {
+ "FAN_REPORT_DFID_NAME_TARGET monitor filesystem for create/delete/move/rename/open/close",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+ INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+ /* Mount watch for events possible on children */
+ INIT_FANOTIFY_MARK_TYPE(MOUNT),
+ FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ },
+ {
+ "FAN_REPORT_DFID_NAME_TARGET monitor directories for create/delete/move/rename/open/close",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_ONDIR,
+ /* Watches for self events on subdir and events on subdir's children */
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+ FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ },
};
static void do_test(unsigned int number)
@@ -183,9 +223,15 @@ static void do_test(unsigned int number)
struct fanotify_fid_t *child_fid = NULL, *subdir_fid = NULL;
int report_name = (group->flag & FAN_REPORT_NAME);
int report_target_fid = (group->flag & FAN_REPORT_TARGET_FID);
+ int report_rename = (tc->mask & FAN_RENAME);
tst_res(TINFO, "Test #%d: %s", number, tc->tname);
+ if (report_rename && rename_events_unsupported) {
+ tst_res(TCONF, "FAN_RENAME not supported in kernel?");
+ return;
+ }
+
if (fan_report_target_fid_unsupported && report_target_fid) {
FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_TARGET_FID,
fan_report_target_fid_unsupported);
@@ -268,6 +314,18 @@ static void do_test(unsigned int number)
strcpy(event_set[tst_count].name, FILE_NAME1);
tst_count++;
}
+ /*
+ * FAN_RENAME event is independent of MOVED_FROM/MOVED_TO and not merged
+ * with any other event because it has different info records.
+ */
+ if (report_rename) {
+ event_set[tst_count].mask = FAN_RENAME;
+ event_set[tst_count].fid = &dir_fid;
+ event_set[tst_count].child_fid = child_fid;
+ strcpy(event_set[tst_count].name, FILE_NAME1);
+ strcpy(event_set[tst_count].name2, FILE_NAME2);
+ tst_count++;
+ }
event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO;
/*
@@ -346,6 +404,18 @@ static void do_test(unsigned int number)
/* Read more events on dirs */
len += SAFE_READ(0, fd_notify, event_buf + len, EVENT_BUF_LEN - len);
+ /*
+ * FAN_RENAME event is independent of MOVED_FROM/MOVED_TO and not merged
+ * with any other event because it has different info records.
+ */
+ if (report_rename) {
+ event_set[tst_count].mask = FAN_RENAME | FAN_ONDIR;
+ event_set[tst_count].fid = &root_fid;
+ event_set[tst_count].child_fid = subdir_fid;
+ strcpy(event_set[tst_count].name, DIR_NAME1);
+ strcpy(event_set[tst_count].name2, DIR_NAME2);
+ tst_count++;
+ }
event_set[tst_count].mask = FAN_MOVED_FROM | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
event_set[tst_count].child_fid = subdir_fid;
@@ -401,7 +471,11 @@ static void do_test(unsigned int number)
if (!report_name)
expected->name[0] = 0;
- if (expected->name[0]) {
+ if (expected->mask & FAN_RENAME) {
+ info_type = FAN_EVENT_INFO_TYPE_OLD_DFID_NAME;
+ /* The 2nd fid is same as 1st becaue we rename in same parent */
+ expected_child_fid = expected_fid;
+ } else if (expected->name[0]) {
info_type = FAN_EVENT_INFO_TYPE_DFID_NAME;
} else if (expected->mask & FAN_ONDIR) {
info_type = FAN_EVENT_INFO_TYPE_DFID;
@@ -548,6 +622,16 @@ check_match:
expected_fid = expected->child_fid;
info_id = 1;
info_type = FAN_EVENT_INFO_TYPE_FID;
+ /*
+ * With FAN_RENAME event, expect a second record of
+ * type NEW_DFID_NAME, which in our case
+ * has the same fid as the source dir in 1st record.
+ * TODO: check the 2nd name and the 3rd child fid record.
+ */
+ if (event->mask & FAN_RENAME) {
+ info_type = FAN_EVENT_INFO_TYPE_NEW_DFID_NAME;
+ expected_fid = expected->fid;
+ }
file_handle = (struct file_handle *)event_fid->handle;
fhlen = file_handle->handle_bytes;
child_fid = NULL;
@@ -590,6 +674,8 @@ static void setup(void)
REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_DIR_FID, MOUNT_PATH);
fan_report_target_fid_unsupported =
fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME_TARGET, MOUNT_PATH);
+ rename_events_unsupported =
+ fanotify_events_supported_by_kernel(FAN_RENAME, FAN_REPORT_DFID_NAME, 0);
sprintf(dname1, "%s/%s", MOUNT_PATH, DIR_NAME1);
sprintf(dname2, "%s/%s", MOUNT_PATH, DIR_NAME2);
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH 5/6] syscalls/fanotify16: Test FAN_RENAME with one watching directory
2022-04-14 14:53 [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Amir Goldstein
` (3 preceding siblings ...)
2022-04-14 14:53 ` [LTP] [PATCH 4/6] syscalls/fanotify16: Add test cases for FAN_RENAME Amir Goldstein
@ 2022-04-14 14:53 ` Amir Goldstein
2022-04-14 14:53 ` [LTP] [PATCH 6/6] syscalls/fanotify16: Test FAN_RENAME with ignored mask Amir Goldstein
2022-04-19 5:39 ` [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Petr Vorel
6 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2022-04-14 14:53 UTC (permalink / raw)
To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp
When root/dir1 is renamed to root/dir2 via an intermediate unwatched
tmpdir, two FAN_RENAME events are reported:
The 1st FAN_RENAME event has the info record of root_fid+dir1 and
the 2nd FAN_RENAME event has the info record of root_fid+dir2.
MOVED_FROM/MOVED_TO events in this scenario look the same as a direct
rename from root/dir1 to root/dir2.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify16.c | 53 ++++++++++++++++---
1 file changed, 46 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c
index b5b53e7d8..ee77e2285 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify16.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify16.c
@@ -50,10 +50,12 @@ struct event_t {
struct fanotify_fid_t *child_fid;
char name[BUF_SIZE];
char name2[BUF_SIZE];
+ char *old_name;
+ char *new_name;
};
static char fname1[BUF_SIZE + 11], fname2[BUF_SIZE + 11];
-static char dname1[BUF_SIZE], dname2[BUF_SIZE];
+static char dname1[BUF_SIZE], dname2[BUF_SIZE], tmpdir[BUF_SIZE];
static int fd_notify;
static struct event_t event_set[EVENT_MAX];
@@ -65,6 +67,7 @@ static char event_buf[EVENT_BUF_LEN];
#define FILE_NAME1 "test_file1"
#define FILE_NAME2 "test_file2"
#define MOUNT_PATH "fs_mnt"
+#define TEMP_DIR MOUNT_PATH "/temp_dir"
static int fan_report_target_fid_unsupported;
static int rename_events_unsupported;
@@ -224,6 +227,7 @@ static void do_test(unsigned int number)
int report_name = (group->flag & FAN_REPORT_NAME);
int report_target_fid = (group->flag & FAN_REPORT_TARGET_FID);
int report_rename = (tc->mask & FAN_RENAME);
+ int fs_mark = (mark->flag == FAN_MARK_FILESYSTEM);
tst_res(TINFO, "Test #%d: %s", number, tc->tname);
@@ -266,6 +270,7 @@ static void do_test(unsigned int number)
SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | sub_mark->flag,
tc->sub_mask, AT_FDCWD, dname1);
+ memset(event_set, 0, sizeof(event_set));
event_set[tst_count].mask = FAN_CREATE | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
event_set[tst_count].child_fid = subdir_fid;
@@ -324,6 +329,8 @@ static void do_test(unsigned int number)
event_set[tst_count].child_fid = child_fid;
strcpy(event_set[tst_count].name, FILE_NAME1);
strcpy(event_set[tst_count].name2, FILE_NAME2);
+ event_set[tst_count].old_name = event_set[tst_count].name;
+ event_set[tst_count].new_name = event_set[tst_count].name2;
tst_count++;
}
@@ -355,7 +362,7 @@ static void do_test(unsigned int number)
* Filesystem watch gets self event w/o name info if FAN_REPORT_FID
* is set.
*/
- if (mark->flag == FAN_MARK_FILESYSTEM && (group->flag & FAN_REPORT_FID)) {
+ if (fs_mark && (group->flag & FAN_REPORT_FID)) {
event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF;
event_set[tst_count].fid = &file_fid;
event_set[tst_count].child_fid = NULL;
@@ -398,7 +405,18 @@ static void do_test(unsigned int number)
strcpy(event_set[tst_count].name, ".");
tst_count++;
- SAFE_RENAME(dname1, dname2);
+ /*
+ * If only root dir and subdir are watched, a rename via an unwatched tmpdir
+ * will observe the same MOVED_FROM/MOVED_TO events as a direct rename,
+ * but will observe 2 FAN_RENAME events with 1 info dir+name record each
+ * instead of 1 FAN_RENAME event with 2 dir+name info records.
+ */
+ if (!fs_mark) {
+ SAFE_RENAME(dname1, tmpdir);
+ SAFE_RENAME(tmpdir, dname2);
+ } else {
+ SAFE_RENAME(dname1, dname2);
+ }
SAFE_RMDIR(dname2);
/* Read more events on dirs */
@@ -407,13 +425,20 @@ static void do_test(unsigned int number)
/*
* FAN_RENAME event is independent of MOVED_FROM/MOVED_TO and not merged
* with any other event because it has different info records.
+ * When renamed via an unwatched tmpdir, the 1st FAN_RENAME event has the
+ * info record of root_fid+DIR_NAME1 and the 2nd FAN_RENAME event has the
+ * info record of root_fid+DIR_NAME2.
*/
if (report_rename) {
event_set[tst_count].mask = FAN_RENAME | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
event_set[tst_count].child_fid = subdir_fid;
strcpy(event_set[tst_count].name, DIR_NAME1);
- strcpy(event_set[tst_count].name2, DIR_NAME2);
+ event_set[tst_count].old_name = event_set[tst_count].name;
+ if (fs_mark) {
+ strcpy(event_set[tst_count].name2, DIR_NAME2);
+ event_set[tst_count].new_name = event_set[tst_count].name2;
+ }
tst_count++;
}
event_set[tst_count].mask = FAN_MOVED_FROM | FAN_ONDIR;
@@ -421,6 +446,14 @@ static void do_test(unsigned int number)
event_set[tst_count].child_fid = subdir_fid;
strcpy(event_set[tst_count].name, DIR_NAME1);
tst_count++;
+ if (report_rename && !fs_mark) {
+ event_set[tst_count].mask = FAN_RENAME | FAN_ONDIR;
+ event_set[tst_count].fid = &root_fid;
+ event_set[tst_count].child_fid = subdir_fid;
+ strcpy(event_set[tst_count].name, DIR_NAME2);
+ event_set[tst_count].new_name = event_set[tst_count].name;
+ tst_count++;
+ }
event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
event_set[tst_count].child_fid = subdir_fid;
@@ -472,9 +505,13 @@ static void do_test(unsigned int number)
expected->name[0] = 0;
if (expected->mask & FAN_RENAME) {
- info_type = FAN_EVENT_INFO_TYPE_OLD_DFID_NAME;
+ /* If old name is not reported, first record is new name */
+ info_type = expected->old_name ?
+ FAN_EVENT_INFO_TYPE_OLD_DFID_NAME :
+ FAN_EVENT_INFO_TYPE_NEW_DFID_NAME;
/* The 2nd fid is same as 1st becaue we rename in same parent */
- expected_child_fid = expected_fid;
+ if (expected->name2[0])
+ expected_child_fid = expected_fid;
} else if (expected->name[0]) {
info_type = FAN_EVENT_INFO_TYPE_DFID_NAME;
} else if (expected->mask & FAN_ONDIR) {
@@ -628,7 +665,7 @@ check_match:
* has the same fid as the source dir in 1st record.
* TODO: check the 2nd name and the 3rd child fid record.
*/
- if (event->mask & FAN_RENAME) {
+ if (event->mask & FAN_RENAME && expected->name2[0]) {
info_type = FAN_EVENT_INFO_TYPE_NEW_DFID_NAME;
expected_fid = expected->fid;
}
@@ -677,8 +714,10 @@ static void setup(void)
rename_events_unsupported =
fanotify_events_supported_by_kernel(FAN_RENAME, FAN_REPORT_DFID_NAME, 0);
+ SAFE_MKDIR(TEMP_DIR, 0755);
sprintf(dname1, "%s/%s", MOUNT_PATH, DIR_NAME1);
sprintf(dname2, "%s/%s", MOUNT_PATH, DIR_NAME2);
+ sprintf(tmpdir, "%s/%s", TEMP_DIR, DIR_NAME2);
sprintf(fname1, "%s/%s", dname1, FILE_NAME1);
sprintf(fname2, "%s/%s", dname1, FILE_NAME2);
}
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [LTP] [PATCH 6/6] syscalls/fanotify16: Test FAN_RENAME with ignored mask
2022-04-14 14:53 [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Amir Goldstein
` (4 preceding siblings ...)
2022-04-14 14:53 ` [LTP] [PATCH 5/6] syscalls/fanotify16: Test FAN_RENAME with one watching directory Amir Goldstein
@ 2022-04-14 14:53 ` Amir Goldstein
2022-04-19 5:39 ` [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Petr Vorel
6 siblings, 0 replies; 11+ messages in thread
From: Amir Goldstein @ 2022-04-14 14:53 UTC (permalink / raw)
To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp
When a file is moved between two directories and only one of them is
watching for FAN_RENAME events, the FAN_RENAME event will include only
the information about the entry in the watched directory.
When one of the directories or filesystem is watching FAN_RENAME, but
the other is ignoring FAN_RENAME events, the FAN_RENAME event will not
be reported at all.
This is not the same behavior as MOVED_FROM/TO events. User cannot
request to ignore MOVED_FROM events according to destination directory
nor MOVED_TO events according to source directory.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify16.c | 60 ++++++++++++++++++-
1 file changed, 57 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c
index ee77e2285..d33e945ad 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify16.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify16.c
@@ -79,6 +79,7 @@ static struct test_case_t {
unsigned long mask;
struct fanotify_mark_type sub_mark;
unsigned long sub_mask;
+ unsigned long tmpdir_ignored_mask;
} test_cases[] = {
{
"FAN_REPORT_DFID_NAME monitor filesystem for create/delete/move/open/close",
@@ -88,6 +89,7 @@ static struct test_case_t {
/* Mount watch for events possible on children */
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ 0,
},
{
"FAN_REPORT_DFID_NAME monitor directories for create/delete/move/open/close",
@@ -98,6 +100,7 @@ static struct test_case_t {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ 0,
},
{
"FAN_REPORT_DIR_FID monitor filesystem for create/delete/move/open/close",
@@ -107,6 +110,7 @@ static struct test_case_t {
/* Mount watch for events possible on children */
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ 0,
},
{
"FAN_REPORT_DIR_FID monitor directories for create/delete/move/open/close",
@@ -117,6 +121,7 @@ static struct test_case_t {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ 0,
},
{
"FAN_REPORT_DFID_FID monitor filesystem for create/delete/move/open/close",
@@ -126,6 +131,7 @@ static struct test_case_t {
/* Mount watch for events possible on children */
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ 0,
},
{
"FAN_REPORT_DFID_FID monitor directories for create/delete/move/open/close",
@@ -136,6 +142,7 @@ static struct test_case_t {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_FID monitor filesystem for create/delete/move/open/close",
@@ -145,6 +152,7 @@ static struct test_case_t {
/* Mount watch for events possible on children */
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_FID monitor directories for create/delete/move/open/close",
@@ -155,6 +163,7 @@ static struct test_case_t {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_TARGET monitor filesystem for create/delete/move/open/close",
@@ -164,6 +173,7 @@ static struct test_case_t {
/* Mount watch for events possible on children */
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_TARGET monitor directories for create/delete/move/open/close",
@@ -174,6 +184,7 @@ static struct test_case_t {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_FID monitor filesystem for create/delete/move/rename/open/close",
@@ -183,6 +194,7 @@ static struct test_case_t {
/* Mount watch for events possible on children */
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_FID monitor directories for create/delete/move/rename/open/close",
@@ -193,6 +205,7 @@ static struct test_case_t {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_TARGET monitor filesystem for create/delete/move/rename/open/close",
@@ -202,6 +215,7 @@ static struct test_case_t {
/* Mount watch for events possible on children */
INIT_FANOTIFY_MARK_TYPE(MOUNT),
FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ 0,
},
{
"FAN_REPORT_DFID_NAME_TARGET monitor directories for create/delete/move/rename/open/close",
@@ -212,6 +226,30 @@ static struct test_case_t {
INIT_FANOTIFY_MARK_TYPE(INODE),
FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ 0,
+ },
+ {
+ "FAN_REPORT_DFID_NAME_FID monitor directories and ignore FAN_RENAME events to/from temp directory",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_ONDIR,
+ /* Watches for self events on subdir and events on subdir's children */
+ INIT_FANOTIFY_MARK_TYPE(INODE),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+ FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+ /* Ignore FAN_RENAME to/from tmpdir */
+ FAN_MOVE | FAN_RENAME,
+ },
+ {
+ "FAN_REPORT_DFID_NAME_FID monitor filesystem and ignore FAN_RENAME events to/from temp directory",
+ INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+ INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+ FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+ /* Mount watch for events possible on children */
+ INIT_FANOTIFY_MARK_TYPE(MOUNT),
+ FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+ /* Ignore FAN_RENAME to/from tmpdir */
+ FAN_MOVE | FAN_RENAME,
},
};
@@ -228,6 +266,7 @@ static void do_test(unsigned int number)
int report_target_fid = (group->flag & FAN_REPORT_TARGET_FID);
int report_rename = (tc->mask & FAN_RENAME);
int fs_mark = (mark->flag == FAN_MARK_FILESYSTEM);
+ int rename_ignored = (tc->tmpdir_ignored_mask & FAN_RENAME);
tst_res(TINFO, "Test #%d: %s", number, tc->tname);
@@ -269,6 +308,17 @@ static void do_test(unsigned int number)
if (tc->sub_mask)
SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | sub_mark->flag,
tc->sub_mask, AT_FDCWD, dname1);
+ /*
+ * ignore FAN_RENAME to/from tmpdir, so we won't get the FAN_RENAME events
+ * when subdir is moved via tmpdir.
+ * FAN_MOVE is also set in ignored mark of tmpdir, but it will have no effect
+ * and the MOVED_FROM/TO events will still be reported.
+ */
+ if (tc->tmpdir_ignored_mask)
+ SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD |
+ FAN_MARK_IGNORED_MASK |
+ FAN_MARK_IGNORED_SURV_MODIFY,
+ tc->tmpdir_ignored_mask, AT_FDCWD, TEMP_DIR);
memset(event_set, 0, sizeof(event_set));
event_set[tst_count].mask = FAN_CREATE | FAN_ONDIR;
@@ -410,8 +460,11 @@ static void do_test(unsigned int number)
* will observe the same MOVED_FROM/MOVED_TO events as a direct rename,
* but will observe 2 FAN_RENAME events with 1 info dir+name record each
* instead of 1 FAN_RENAME event with 2 dir+name info records.
+ *
+ * If tmpdir is ignoring FAN_RENAME, we will get the MOVED_FROM/MOVED_TO
+ * events and will not get the FAN_RENAME event for rename via tmpdir.
*/
- if (!fs_mark) {
+ if (!fs_mark || rename_ignored) {
SAFE_RENAME(dname1, tmpdir);
SAFE_RENAME(tmpdir, dname2);
} else {
@@ -428,8 +481,9 @@ static void do_test(unsigned int number)
* When renamed via an unwatched tmpdir, the 1st FAN_RENAME event has the
* info record of root_fid+DIR_NAME1 and the 2nd FAN_RENAME event has the
* info record of root_fid+DIR_NAME2.
+ * If tmpdir is ignoring FAN_RENAME, we get no FAN_RENAME events at all.
*/
- if (report_rename) {
+ if (report_rename && !rename_ignored) {
event_set[tst_count].mask = FAN_RENAME | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
event_set[tst_count].child_fid = subdir_fid;
@@ -446,7 +500,7 @@ static void do_test(unsigned int number)
event_set[tst_count].child_fid = subdir_fid;
strcpy(event_set[tst_count].name, DIR_NAME1);
tst_count++;
- if (report_rename && !fs_mark) {
+ if (report_rename && !fs_mark && !rename_ignored) {
event_set[tst_count].mask = FAN_RENAME | FAN_ONDIR;
event_set[tst_count].fid = &root_fid;
event_set[tst_count].child_fid = subdir_fid;
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [LTP] [PATCH 0/6] Fanotify tests for v5.17 features
2022-04-14 14:53 [LTP] [PATCH 0/6] Fanotify tests for v5.17 features Amir Goldstein
` (5 preceding siblings ...)
2022-04-14 14:53 ` [LTP] [PATCH 6/6] syscalls/fanotify16: Test FAN_RENAME with ignored mask Amir Goldstein
@ 2022-04-19 5:39 ` Petr Vorel
6 siblings, 0 replies; 11+ messages in thread
From: Petr Vorel @ 2022-04-19 5:39 UTC (permalink / raw)
To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp
Hi Amir,
> Hi Pert,
> Following test for new features FAN_REPORT_TARGET_FID and
> FAN_RENAME included in v5.17 release.
> The new test cases do not run on < v5.17 kernel.
FYI the rest of the patchset merged.
I tested it on various old and new kernels.
Kind regards,
Petr
> Thanks,
> Amir.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 11+ messages in thread