Fanotify tests for v5.17 features
cover Fanotify tests for v5.17 features
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.
Thanks,
Amir.
Amir Goldstein (6):
syscalls/fcntl: New test for DN_RENAME (dnotify) syscalls/fanotify14: Add tests for FAN_REPORT_TARGET_FID and
FAN_RENAME
syscalls/fanotify16: Add test cases for FAN_REPORT_TARGET_FID syscalls/fanotify16: Add test cases for FAN_RENAME syscalls/fanotify16: Test FAN_RENAME with one watching directory syscalls/fanotify16: Test FAN_RENAME with ignored mask
runtest/syscalls | 2 + testcases/kernel/syscalls/fanotify/fanotify.h | 15 + .../kernel/syscalls/fanotify/fanotify14.c | 12 + .../kernel/syscalls/fanotify/fanotify16.c | 256 ++++++++++++++++-- testcases/kernel/syscalls/fcntl/.gitignore | 2 + testcases/kernel/syscalls/fcntl/fcntl39.c | 114 ++++++++ 6 files changed, 385 insertions(+), 16 deletions(-) create mode 100644 testcases/kernel/syscalls/fcntl/fcntl39.c
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/6 syscalls/fcntl: New test for DN_RENAME (dnotify)
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.
--- 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
runtest/syscalls +2 -0
@@ -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
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
@@ -74,3 +74,5 @@ /fcntl37_64 /fcntl38 /fcntl38_64 +/fcntl39 +/fcntl39_64
testcases/kernel/syscalls/fcntl/fcntl39.c new file +114 -0
114 lines not on this page · raw message
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify)
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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify)
Quoted 16 lines · Petr Vorel
Hi Amir,
could you please fix
fcntl39.cto 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 noDN_RENAMEon 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: TestingDN_RENAMEon 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)
Quoted 2 lines
Kind regards,
Petr
Sorry forgot to run it with -i
Here is the fix if you want to apply it yourself:
testcases/kernel/syscalls/fcntl/fcntl39.c +6 -0
@@ -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.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] syscalls/fcntl: New test for DN_RENAME (dnotify)
Hi Amir,
Quoted 7 lines
Sorry forgot to run it with -i
Here is the fix if you want to apply it yourself:
testcases/kernel/syscalls/fcntl/fcntl39.c static void verify_dnotify(void) · line 98
Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl39.c +6
-0@@ -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
Quoted 2 lines
testcases/kernel/syscalls/fcntl/fcntl39.c +0
-0Thanks,Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/6 syscalls/fanotify14: Add tests for FAN_REPORT_TARGET_FID and FAN_RENAME
In reply to Amir GoldsteinValidate flag combinations:
1) FAN_REPORT_TARGET_FID requires FAN_REPORT_NAME and FAN_REPORT_FID
2) FAN_RENAME requires FAN_REPORT_NAME
--- testcases/kernel/syscalls/fanotify/fanotify.h | 15 +++++++++++++++ testcases/kernel/syscalls/fanotify/fanotify14.c | 12 ++++++++++++ 2 files changed, 27 insertions(+)
testcases/kernel/syscalls/fanotify/fanotify.h +15 -0
@@ -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;
testcases/kernel/syscalls/fanotify/fanotify14.c +12 -0
@@ -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)
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/6 syscalls/fanotify16: Add test cases for FAN_REPORT_TARGET_FID
In reply to Amir GoldsteinVerify 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).
--- .../kernel/syscalls/fanotify/fanotify16.c | 69 +++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify16.c +57 -12
@@ -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 );
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/6 syscalls/fanotify16: Add test cases for FAN_RENAME
In reply to Amir GoldsteinIn 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
--- .../kernel/syscalls/fanotify/fanotify16.c | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/fanotify/fanotify16.c +87 -1
@@ -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 );
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/6 syscalls/fanotify16: Test FAN_RENAME with one watching directory
In reply to Amir GoldsteinWhen 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.
--- .../kernel/syscalls/fanotify/fanotify16.c | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify16.c +46 -7
@@ -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 ); }
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 6/6 syscalls/fanotify16: Test FAN_RENAME with ignored mask
In reply to Amir GoldsteinWhen 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.
--- .../kernel/syscalls/fanotify/fanotify16.c | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify16.c +57 -3
@@ -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;
Signature · 5 lines
2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Amir,
Quoted 5 lines
Hi Pert,
Following test for new features
FAN_REPORT_TARGET_FIDandFAN_RENAMEincluded 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
Quoted 2 lines
Thanks,
Amir.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp