fanotify ltp tests for v5.7-rc1
cover fanotify ltp tests for v5.7-rc1
Hi Cyril,
Following patches test kernel code merged to v5.7-rc1.
Patch 1,3 test fanotify minor bug fixes, which could be backported to stable kernels.
Patch 2 makes test fanotify15 more robust, by making less assumptions, in preparation for adding a test case.
Patch 4 adds a new test for the new event type FAN_MODIFY_DIR, which carries a new event format (parent fid + name).
Thanks,
Amir.
Amir Goldstein (4):
syscalls/fanotify09: Check merging of events on directories syscalls/fanotify15: Minor corrections syscalls/fanotify15: Add a test case for inode marks syscalls/fanotify: New test for FAN_MODIFY_DIR
runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/fanotify.h | 15 +- .../kernel/syscalls/fanotify/fanotify09.c | 46 +- .../kernel/syscalls/fanotify/fanotify15.c | 128 ++++- .../kernel/syscalls/fanotify/fanotify16.c | 441 ++++++++++++++++++ 6 files changed, 595 insertions(+), 37 deletions(-) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify16.c
Signature · 1 line
2.17.1
PATCH 1/4 syscalls/fanotify09: Check merging of events on directories
In a setup of mount mark and directory inode mark the FAN_ONDIR flag set on one mark should not imply that all events in the other mark mask are expected on directories as well.
Add a regression test case for commit 55bf882c7f13:
fanotify: fix merging marks masks with FAN_ONDIR
--- .../kernel/syscalls/fanotify/fanotify09.c | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify09.c +32 -14
@@ -15,6 +15,10 @@* Test case #2 is a regression test for commit b469e7e47c8a: * * fanotify: fix handling of events on child sub-directory +* +* Test case #3 is a regression test for commit 55bf882c7f13: +* +* fanotify: fix merging marks masks with FAN_ONDIR */ #define _GNU_SOURCE#include "config.h"
@@ -57,16 +61,25 @@ static int mount_created;static struct tcase {const char *tname;unsigned int ondir; +const char *testdir;int nevents; } tcases[] = { {"Events on children with both inode and mount marks" ,0 , +DIR_NAME ,1 , }, {"Events on children and subdirs with both inode and mount marks" ,FAN_ONDIR , +DIR_NAME , +2 , + }, + { +"Events on files and dirs with both inode and mount marks" , +FAN_ONDIR , +"." ,2 , }, };
@@ -125,6 +138,20 @@ static void cleanup_fanotify_groups(void) } } +static void event_res (int ttype,int group, +struct fanotify_event_metadata *event) +{ +int len; +sprintf (symlnk,"/proc/self/fd/%d" , event->fd); + len =readlink (symlnk, fdpath,sizeof (fdpath)); +if (len <0 ) + len =0 ; + fdpath[len] =0 ; +tst_res (ttype,"group %d got event: mask %llx pid=%u fd=%d path=%s" , + group, (unsigned long long )event->mask, + (unsigned )event->pid, event->fd, fdpath); +} +static void verify_event (int group,struct fanotify_event_metadata *event,uint32_t expect) {
@@ -139,15 +166,7 @@ static void verify_event(int group, struct fanotify_event_metadata *event, (unsigned long long )event->mask, (unsigned )event->pid, (unsigned)getpid(), event->fd); }else { -int len; -sprintf (symlnk,"/proc/self/fd/%d" , event->fd); - len =readlink (symlnk, fdpath,sizeof (fdpath)); -if (len <0 ) - len =0 ; - fdpath[len] =0 ; -tst_res (TPASS ,"group %d got event: mask %llx pid=%u fd=%d path=%s" , - group, (unsigned long long )event->mask, - (unsigned )event->pid, event->fd, fdpath); +event_res (TPASS , group, event); } }
@@ -167,9 +186,9 @@ static void test_fanotify(unsigned int n)*/ SAFE_FILE_PRINTF (fname,"1" );/* -* generate FAN_CLOSE_NOWRITE event on a child subdir. +* generate FAN_CLOSE_NOWRITE event on a testdir (subdir or ".") */ - dirfd =SAFE_OPEN (DIR_NAME ,O_RDONLY ); + dirfd =SAFE_OPEN (tc->testdir,O_RDONLY );if (dirfd >=0 )SAFE_CLOSE (dirfd);
@@ -210,13 +229,12 @@ static void test_fanotify(unsigned int n)/* * Then verify the rest of the groups did not get the MODIFY event and -* did not get the FAN_CLOSE_NOWRITE event on subdir. +* did not get the FAN_CLOSE_NOWRITE event on testdir. */ for (i =1 ; i <NUM_GROUPS ; i++) { ret =read (fd_notify[i], event_buf,FAN_EVENT_METADATA_LEN );if (ret >0 ) { -tst_res (TFAIL ,"group %d got event" , i); -verify_event (i, event,FAN_CLOSE_NOWRITE ); +event_res (TFAIL , i, event);if (event->fd !=FAN_NOFD )SAFE_CLOSE (event->fd);continue ;
Signature · 1 line
2.17.1
PATCH 1/4 syscalls/fanotify09: Check merging of events on directories
Hi Amir,
Quoted 6 lines
In a setup of mount mark and directory inode mark the
FAN_ONDIRflag set on one mark should not imply that all events in the other mark mask are expected on directories as well.Add a regression test case for commit
55bf882c7f13:
fanotify: fix merging marks masks withFAN_ONDIR
Merged this one (with simple change: added {"linux-git", "55bf882c7f13"},). Thanks for your work!
Kind regards,
Petr
PATCH 1/4 syscalls/fanotify09: Check merging of events on directories
In reply to Amir Goldsteintestcases/kernel/syscalls/fanotify/fanotify09.c static void cleanup_fanotify_groups(void) · line 153
Quoted 13 lines · Amir Goldstein
testcases/kernel/syscalls/fanotify/fanotify09.c +13
-0+static void event_res (int ttype,int group, +struct fanotify_event_metadata *event) +{ +int len; +sprintf (symlnk,"/proc/self/fd/%d" , event->fd); + len =readlink (symlnk, fdpath,sizeof (fdpath)); +if (len <0 ) + len =0 ; + fdpath[len] =0 ; +tst_res (ttype,"group %d got event: mask %llx pid=%u fd=%d path=%s" , + group, (unsigned long long )event->mask, + (unsigned )event->pid, event->fd, fdpath); +}
Nice helper, although it would be nice not to see all these statements clunked together like this.
testcases/kernel/syscalls/fanotify/fanotify09.c static void test_fanotify(unsigned int n) · line 189
Quoted 2 lines
testcases/kernel/syscalls/fanotify/fanotify09.c +1
-1-* generate FAN_CLOSE_NOWRITE event on a child subdir. +* generate FAN_CLOSE_NOWRITE event on a testdir (subdir or ".")
^ s/g/G :P
/M
PATCH 1/4 syscalls/fanotify09: Check merging of events on directories
Quoted 19 lines · Matthew Bobrowski
testcases/kernel/syscalls/fanotify/fanotify09.c static void cleanup_fanotify_groups(void) · line 153
Quoted 13 lines · Amir Goldstein
testcases/kernel/syscalls/fanotify/fanotify09.c +13
-0+static void event_res (int ttype,int group, +struct fanotify_event_metadata *event) +{ +int len; +sprintf (symlnk,"/proc/self/fd/%d" , event->fd); + len =readlink (symlnk, fdpath,sizeof (fdpath)); +if (len <0 ) + len =0 ; + fdpath[len] =0 ; +tst_res (ttype,"group %d got event: mask %llx pid=%u fd=%d path=%s" , + group, (unsigned long long )event->mask, + (unsigned )event->pid, event->fd, fdpath); +}Nice helper, although it would be nice not to see all these statements clunked together like this.
Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify09.c static void test_fanotify(unsigned int n) · line 189
Quoted 2 lines
testcases/kernel/syscalls/fanotify/fanotify09.c +1
-1-* generate FAN_CLOSE_NOWRITE event on a child subdir. +* generate FAN_CLOSE_NOWRITE event on a testdir (subdir or ".") ^ s/g/G :PReviewed-by Matthew Bobrowski <[email protected]>
Thanks for the review Matthew, but this patch has already been merged, so those cleanups could be done at a later time.
I will address you comments to fanotify15 and fanotify16, which are still not merged, when you are done with review.
Thanks,
Amir.
PATCH 1/4 syscalls/fanotify09: Check merging of events on directories
Ah, right.
I'll finish off the review tomorrow when I have some more time.
Chat then!
/M
Quoted 29 lines · Amir Goldstein,
Quoted 12 lines · Matthew Bobrowski
testcases/kernel/syscalls/fanotify/fanotify09.c static void cleanup_fanotify_groups(void)
Quoted 10 lines · Amir Goldstein
testcases/kernel/syscalls/fanotify/fanotify09.c +10
-0+static void event_res (int ttype,int group, +struct fanotify_event_metadata *event) +{ +int len; +sprintf (symlnk,"/proc/self/fd/%d" , event->fd); + len =readlink (symlnk, fdpath,sizeof (fdpath)); +if (len <0 ) + len =0 ; + fdpath[len] =0 ; + tst_res(ttype, "group %d got event: mask %llx pid=%u fd=%dpath=%s",
Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify09.c static void cleanup_fanotify_groups(void) · line 153
Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify09.c +3
-0+ group, (unsigned long long )event->mask, + (unsigned)event->pid, event->fd, fdpath); +}Quoted 9 lines
Nice helper, although it would be nice not to see all these statements clunked together like this.
testcases/kernel/syscalls/fanotify/fanotify09.c static void test_fanotify(unsigned int n) · line 189
Quoted 2 lines
testcases/kernel/syscalls/fanotify/fanotify09.c +1
-1-* generate FAN_CLOSE_NOWRITE event on a child subdir. +* generate FAN_CLOSE_NOWRITE event on a testdir (subdir or ".") ^ s/g/G :PReviewed-by Matthew Bobrowski <[email protected]>
Quoted 8 lines
Thanks for the review Matthew, but this patch has already been merged, so those cleanups could be done at a later time.
I will address you comments to fanotify15 and fanotify16, which are still not merged, when you are done with review.Thanks,
Amir.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20200501/9b454f70/attachment-0001.htm>
PATCH 2/4 syscalls/fanotify15: Minor corrections
In reply to Amir Goldstein- Fix calculation of events buffer size
- Read file events and dir events in two batches
- Generate FAN_MODIFY event explicitly with truncate() operation instead of FAN_ATTRIB event implicitly with create() operation
- FAN_MODIFY and FAN_DELETE_SELF may or may not be merged
--- .../kernel/syscalls/fanotify/fanotify15.c | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify15.c +42 -16
@@ -25,8 +25,14 @@#if defined(HAVE_SYS_FANOTIFY_H )#include <sys/fanotify.h> -#define BUF_SIZE 256 -#define EVENT_MAX 256 +#define EVENT_MAX 10 + +/* Size of the event structure, not including file handle */ +#define EVENT_SIZE (sizeof(struct fanotify_event_metadata) + \ + sizeof(struct fanotify_event_info_fid)) +/* Double events buffer size to account for file handles */ +#define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE * 2) +#define MOUNT_POINT "mntpoint"#define TEST_DIR MOUNT_POINT"/test_dir"
@@ -44,7 +50,7 @@ struct event_t { };static int fanotify_fd; -static char events_buf[BUF_SIZE ]; +static char events_buf[EVENT_BUF_LEN ];static struct event_t event_set[EVENT_MAX ];static void do_test (void )
@@ -55,23 +61,24 @@ static void do_test(void)struct fanotify_event_metadata *metadata;struct fanotify_event_info_fid *event_fid; +if (fanotify_mark (fanotify_fd,FAN_MARK_ADD |FAN_MARK_FILESYSTEM , -FAN_CREATE |FAN_DELETE |FAN_ATTRIB | -FAN_MOVED_FROM |FAN_MOVED_TO | -FAN_DELETE_SELF |FAN_ONDIR , +FAN_CREATE |FAN_DELETE |FAN_MOVE | +FAN_MODIFY |FAN_DELETE_SELF |FAN_ONDIR ,AT_FDCWD ,TEST_DIR ) ==-1 ) {if (errno ==ENODEV )tst_brk (TCONF ,"FAN_REPORT_FID not supported on %s " "filesystem" , tst_device->fs_type);tst_brk (TBROK |TERRNO , -"fanotify_mark(%d, FAN_MARK_ADD, FAN_CREATE | " -"FAN_DELETE | FAN_MOVED_FROM | FAN_MOVED_TO | " -"FAN_DELETE_SELF | FAN_ONDIR, AT_FDCWD, %s) failed" , +"fanotify_mark(%d, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, " +"FAN_CREATE | FAN_DELETE | FAN_MOVE | " +"FAN_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, " +"AT_FDCWD, %s) failed" , fanotify_fd,TEST_DIR ); } -/* Generate a sequence of events */ +/* All dirent events on testdir are merged */ event_set[count].mask =FAN_CREATE |FAN_MOVED_FROM |FAN_MOVED_TO | \FAN_DELETE ; event_set[count].handle.handle_bytes =MAX_HANDLE_SZ ;
@@ -82,9 +89,22 @@ static void do_test(void) fd =SAFE_CREAT (FILE1 ,0644 );SAFE_CLOSE (fd); +/* +* Event on child file is not merged with dirent events. +*/ + event_set[count].mask =FAN_MODIFY ; + event_set[count].handle.handle_bytes =MAX_HANDLE_SZ ; +fanotify_get_fid (FILE1 , &event_set[count].fsid, + &event_set[count].handle); + count++; + +SAFE_TRUNCATE (FILE1 ,1 );SAFE_RENAME (FILE1 ,FILE2 ); - event_set[count].mask =FAN_ATTRIB |FAN_DELETE_SELF ; +/* +* FAN_DELETE_SELF may be merged with FAN_MODIFY event above. +*/ + event_set[count].mask =FAN_DELETE_SELF ; event_set[count].handle.handle_bytes =MAX_HANDLE_SZ ;fanotify_get_fid (FILE2 , &event_set[count].fsid, &event_set[count].handle);
@@ -92,6 +112,9 @@ static void do_test(void)SAFE_UNLINK (FILE2 ); +/* Read file events from the event queue */ + len =SAFE_READ (0 , fanotify_fd, events_buf,EVENT_BUF_LEN ); +/* * Generate a sequence of events on a directory. Subsequent events * are merged, so it's required that we set FAN_ONDIR once in
@@ -118,13 +141,12 @@ static void do_test(void)SAFE_RMDIR (DIR2 ); -/* Read events from the event queue */ - len =SAFE_READ (0 , fanotify_fd, events_buf,BUF_SIZE ); +/* Read dir events from the event queue */ + len +=SAFE_READ (0 , fanotify_fd, events_buf + len,EVENT_BUF_LEN - len);/* Process each event in buffer */ for (i =0 , metadata = (struct fanotify_event_metadata *) events_buf; -FAN_EVENT_OK (metadata, len); - metadata =FAN_EVENT_NEXT (metadata,len), i++) { +FAN_EVENT_OK (metadata, len); i++) { event_fid = (struct fanotify_event_info_fid *) (metadata +1 ); event_file_handle = (struct file_handle *) event_fid->handle;
@@ -141,7 +163,7 @@ static void do_test(void)"Received unexpected file descriptor %d in " "event. Expected to get FAN_NOFD(%d)" , metadata->fd, FAN_NOFD); - }else if (metadata->mask != event_set[i].mask) { + }else if (!(metadata->mask & event_set[i].mask)) { tst_res(TFAIL, "Got event: mask=%llx (expected %llx) " "pid=%u fd=%d",
@@ -197,6 +219,10 @@ static void do_test(void) *(unsigned long *) event_file_handle->f_handle); } + metadata->mask &= ~event_set[i].mask; +/* No events left in current mask? Go for next event */ +if (metadata->mask ==0 ) + metadata =FAN_EVENT_NEXT (metadata, len); }for (; i < count; i++)
Signature · 1 line
2.17.1
PATCH 2/4 syscalls/fanotify15: Minor corrections
Hi Amir,
Quoted 5 lines
- Fix calculation of events buffer size
- Read file events and dir events in two batches
- GenerateFAN_MODIFYevent explicitly withtruncate()operation instead ofFAN_ATTRIBevent implicitly withcreate()operation
-FAN_MODIFYandFAN_DELETE_SELFmay or may not be merged
Whole patchset LGTM, but I'd prefer Jan or somebody else reviewed it.
Kind regards,
Petr
PATCH 2/4 syscalls/fanotify15: Minor corrections
In reply to Amir GoldsteinHi!
Looks good to me as well.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/4 syscalls/fanotify15: Minor corrections
In reply to Amir Goldsteintestcases/kernel/syscalls/fanotify/fanotify15.c static void do_test(void) · line 64
Quoted 6 lines · Amir Goldstein
static void
do_test(void)testcases/kernel/syscalls/fanotify/fanotify15.c +1
-0@@ -55,23 +61,24 @@ static void do_test(void)struct fanotify_event_metadata *metadata;struct fanotify_event_info_fid *event_fid; +
^ Unnecessary white line entered here?
Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify15.c +2
-3if (fanotify_mark (fanotify_fd,FAN_MARK_ADD |FAN_MARK_FILESYSTEM , -FAN_CREATE |FAN_DELETE |FAN_ATTRIB | -FAN_MOVED_FROM |FAN_MOVED_TO | -FAN_DELETE_SELF |FAN_ONDIR , +FAN_CREATE |FAN_DELETE |FAN_MOVE | +FAN_MODIFY |FAN_DELETE_SELF |FAN_ONDIR ,AT_FDCWD ,TEST_DIR ) ==-1 ) {
...
testcases/kernel/syscalls/fanotify/fanotify15.c static void do_test(void) · line 83
Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify15.c +1
-1-/* Generate a sequence of events */ +/* All dirent events on testdir are merged */ event_set[count].mask =FAN_CREATE |FAN_MOVED_FROM |FAN_MOVED_TO | \FAN_DELETE ;
Just a suggestion, perhaps we can modify the above line to the following:
event_set[count].mask = FAN_CREATE | FAN_MOVE | FAN_DELETE;
Also, I believe that we can generally replace all instances of FAN_MOVED_FROM | FAN_MOVED_TO with FAN_MOVE within this file.
The rest looks good to me.
/M
PATCH 3/4 syscalls/fanotify15: Add a test case for inode marks
In reply to Amir GoldsteinTest reporting events with fid also with recusrive inode marks:
- Test events "on self" (FAN_DELETE_SELF) on file and dir
- Test events "on child" (FAN_MODIFY) on file
With recursive inode marks, verify that the FAN_MODIFY event reported to parent "on child" is merged with the FAN_MODIFY event reported to child.
The new test case is a regression test for commit f367a62a7cad:
fanotify: merge duplicate events on parent and child
--- .../kernel/syscalls/fanotify/fanotify15.c | 76 +++++++++++++++++-- 1 file changed, 69 insertions(+), 7 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify15.c +69 -7
@@ -9,6 +9,10 @@* Test file that has been purposely designed to verify * FAN_REPORT_FID functionality while using newly defined dirent * events. +* +* Test case #1 is a regression test for commit f367a62a7cad: +* +* fanotify: merge duplicate events on parent and child */ #define _GNU_SOURCE#include "config.h"
@@ -53,29 +57,51 @@ static int fanotify_fd;static char events_buf[EVENT_BUF_LEN ];static struct event_t event_set[EVENT_MAX ]; -static void do_test (void ) +static struct test_case_t { +struct fanotify_mark_type mark; +unsigned long mask; +} test_cases[] = { + { +/* Watch filesystem including events "on self" */ +INIT_FANOTIFY_MARK_TYPE (FILESYSTEM ), +FAN_DELETE_SELF , + }, + { +/* Watch directory including events "on children" */ +INIT_FANOTIFY_MARK_TYPE (INODE ), +FAN_EVENT_ON_CHILD , + }, +}; + +static void do_test (unsigned int number) {int i, fd, len, count =0 ;struct file_handle *event_file_handle;struct fanotify_event_metadata *metadata;struct fanotify_event_info_fid *event_fid; +struct test_case_t *tc = &test_cases[number]; +struct fanotify_mark_type *mark = &tc->mark; +tst_res (TINFO , +"Test #%d: FAN_REPORT_FID with mark type: %s" , + number, mark->name); -if (fanotify_mark (fanotify_fd,FAN_MARK_ADD |FAN_MARK_FILESYSTEM , + +if (fanotify_mark (fanotify_fd,FAN_MARK_ADD | mark->flag, tc->mask |FAN_CREATE |FAN_DELETE |FAN_MOVE | -FAN_MODIFY |FAN_DELETE_SELF |FAN_ONDIR , +FAN_MODIFY |FAN_ONDIR ,AT_FDCWD ,TEST_DIR ) ==-1 ) {if (errno ==ENODEV )tst_brk (TCONF ,"FAN_REPORT_FID not supported on %s " "filesystem" , tst_device->fs_type);tst_brk (TBROK |TERRNO , -"fanotify_mark(%d, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, " +"fanotify_mark(%d, FAN_MARK_ADD | %s, " "FAN_CREATE | FAN_DELETE | FAN_MOVE | " -"FAN_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, " +"FAN_MODIFY | FAN_ONDIR, " "AT_FDCWD, %s) failed" , - fanotify_fd,TEST_DIR ); + fanotify_fd, mark->name,TEST_DIR ); }/* All dirent events on testdir are merged */
@@ -89,8 +115,21 @@ static void do_test(void) fd =SAFE_CREAT (FILE1 ,0644 );SAFE_CLOSE (fd); +/* Recursive watch file for events "on self" */ +if (mark->flag ==FAN_MARK_INODE && +fanotify_mark (fanotify_fd,FAN_MARK_ADD | mark->flag, +FAN_MODIFY |FAN_DELETE_SELF , +AT_FDCWD ,FILE1 ) ==-1 ) { +tst_brk (TBROK |TERRNO , +"fanotify_mark(%d, FAN_MARK_ADD | %s, " +"FAN_DELETE_SELF, AT_FDCWD, %s) failed" , + fanotify_fd, mark->name,FILE1 ); + } +/* * Event on child file is not merged with dirent events. +* FAN_MODIFY event reported on file mark should be merged with the +* FAN_MODIFY event reported on parent directory watch. */ event_set[count].mask =FAN_MODIFY ; event_set[count].handle.handle_bytes =MAX_HANDLE_SZ ;
@@ -131,6 +170,17 @@ static void do_test(void)SAFE_MKDIR (DIR1 ,0755 ); +/* Recursive watch subdir for events "on self" */ +if (mark->flag ==FAN_MARK_INODE && +fanotify_mark (fanotify_fd,FAN_MARK_ADD | mark->flag, +FAN_DELETE_SELF |FAN_ONDIR , +AT_FDCWD ,DIR1 ) ==-1 ) { +tst_brk (TBROK |TERRNO , +"fanotify_mark(%d, FAN_MARK_ADD | %s," +"FAN_DELETE_SELF | FAN_ONDIR, AT_FDCWD, %s) failed" , + fanotify_fd, mark->name,DIR1 ); + } +SAFE_RENAME (DIR1 ,DIR2 ); event_set[count].mask =FAN_ONDIR |FAN_DELETE_SELF ;
@@ -144,6 +194,17 @@ static void do_test(void)/* Read dir events from the event queue */ len +=SAFE_READ (0 , fanotify_fd, events_buf + len,EVENT_BUF_LEN - len); +/* +* Cleanup the mark +*/ +if (fanotify_mark (fanotify_fd,FAN_MARK_FLUSH | mark->flag,0 , +AT_FDCWD ,TEST_DIR ) <0 ) { +tst_brk (TBROK |TERRNO , +"fanotify_mark (%d, FAN_MARK_FLUSH | %s, 0," +"AT_FDCWD, '" TEST_DIR "') failed" , + fanotify_fd, mark->name); + } +/* Process each event in buffer */ for (i =0 , metadata = (struct fanotify_event_metadata *) events_buf;FAN_EVENT_OK (metadata, len); i++) {
@@ -262,7 +323,8 @@ static struct tst_test test = { .mount_device = 1, .mntpoint = MOUNT_POINT, .all_filesystems = 1, - .test_all = do_test, + .test = do_test, + .tcnt = ARRAY_SIZE(test_cases), .setup = do_setup, .cleanup = do_cleanup };
Signature · 1 line
2.17.1
PATCH 3/4 syscalls/fanotify15: Add a test case for inode marks
Hi Amir,
testcases/kernel/syscalls/fanotify/fanotify15.c static struct tst_test test = { · line 329
Quoted 11 lines
testcases/kernel/syscalls/fanotify/fanotify15.c +2
-1for (i =0 , metadata = (struct fanotify_event_metadata *) events_buf;FAN_EVENT_OK (metadata, len); i++) {@@ -262,7 +323,8 @@ static struct tst_test test = { .mount_device = 1, .mntpoint = MOUNT_POINT, .all_filesystems = 1, - .test_all = do_test, + .test = do_test, + .tcnt = ARRAY_SIZE(test_cases), .setup = do_setup, .cleanup = do_cleanup
Again, missing (can be added during merge):
- .cleanup = do_cleanup
+ .cleanup = do_cleanup,
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "f367a62a7cad"},
+ {}
Review static struct tst_test test = { · line 330
Quoted 1 line
(quoted diff) +0
-0};
Apart from already mentioned FSID_VAL_MEMBER() LGTM, but again, somebody more experienced in fanotify and/or filesystems should look into it.
Kind regards,
Petr
PATCH 3/4 syscalls/fanotify15: Add a test case for inode marks
Hi Amir,
Quoted 1 line
Apart from already mentioned
FSID_VAL_MEMBER()LGTM, but again, somebody more
I'm sorry, FSID_VAL_MEMBER() was meant to be for fanotify16.c.
Quoted 1 line
experienced in fanotify and/or filesystems should look into it.
Kind regards,
Petr
PATCH 3/4 syscalls/fanotify15: Add a test case for inode marks
In reply to Amir GoldsteinHi!
Looks good to me, minus the things pointed out by Peter.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/4 syscalls/fanotify15: Add a test case for inode marks
In reply to Amir Goldsteintestcases/kernel/syscalls/fanotify/fanotify15.c static int fanotify_fd; · line 90
Quoted 6 lines · Amir Goldstein
testcases/kernel/syscalls/fanotify/fanotify15.c +4
-1+tst_res (TINFO , +"Test #%d: FAN_REPORT_FID with mark type: %s" , + number, mark->name); - if (fanotify_mark(fanotify_fd, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, +
A nit, but there's an unnecessary extra whiteline here.
Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify15.c +2
-1+if (fanotify_mark (fanotify_fd,FAN_MARK_ADD | mark->flag, tc->mask |FAN_CREATE |FAN_DELETE |FAN_MOVE | - FAN_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, +FAN_MODIFY |FAN_ONDIR ,AT_FDCWD ,TEST_DIR ) ==-1 ) {if (errno ==ENODEV )tst_brk (TCONF , "FAN_REPORT_FID not supported on %s "
testcases/kernel/syscalls/fanotify/fanotify15.c static int fanotify_fd; · line 104
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify15.c +3
-3"filesystem", tst_device->fs_type);tst_brk (TBROK |TERRNO , -"fanotify_mark(%d, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, " +"fanotify_mark(%d, FAN_MARK_ADD | %s, " "FAN_CREATE | FAN_DELETE | FAN_MOVE | " -"FAN_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, " +"FAN_MODIFY | FAN_ONDIR, " "AT_FDCWD, %s) failed" , - fanotify_fd,TEST_DIR ); + fanotify_fd, mark->name,TEST_DIR );
I see that you've removed the FAN_DELETE_SELF mask here, although should we consider adding tc->mask here too for the sake of correctness?
The rest looks fine to me.
/M
PATCH 3/4 syscalls/fanotify15: Add a test case for inode marks
Quoted 30 lines · Matthew Bobrowski
testcases/kernel/syscalls/fanotify/fanotify15.c static int fanotify_fd; · line 90
Quoted 6 lines · Amir Goldstein
testcases/kernel/syscalls/fanotify/fanotify15.c +4
-1+tst_res (TINFO , +"Test #%d: FAN_REPORT_FID with mark type: %s" , + number, mark->name); - if (fanotify_mark(fanotify_fd, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, +A nit, but there's an unnecessary extra whiteline here.
Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify15.c +2
-1+if (fanotify_mark (fanotify_fd,FAN_MARK_ADD | mark->flag, tc->mask |FAN_CREATE |FAN_DELETE |FAN_MOVE | - FAN_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, +FAN_MODIFY |FAN_ONDIR ,AT_FDCWD ,TEST_DIR ) ==-1 ) {if (errno ==ENODEV )tst_brk (TCONF , "FAN_REPORT_FID not supported on %s "testcases/kernel/syscalls/fanotify/fanotify15.c static int fanotify_fd; · line 104
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify15.c +3
-3"filesystem", tst_device->fs_type);tst_brk (TBROK |TERRNO , -"fanotify_mark(%d, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, " +"fanotify_mark(%d, FAN_MARK_ADD | %s, " "FAN_CREATE | FAN_DELETE | FAN_MOVE | " -"FAN_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, " +"FAN_MODIFY | FAN_ONDIR, " "AT_FDCWD, %s) failed" , - fanotify_fd,TEST_DIR ); + fanotify_fd, mark->name,TEST_DIR );
Quoted 3 lines
I see that you've removed the
FAN_DELETE_SELFmask here, although should we consider addingtc->maskhere too for the sake of correctness?
Sure, I added " | 0x%x" for the extra tc->mask and also enhanced the TINFO in the beginning of the test case to disaply more explicit text like this:
"FAN_REPORT_FID on filesystem including FAN_DELETE_SELF", "FAN_REPORT_FID on directory with FAN_EVENT_ON_CHILD",
Thanks,
Amir.
PATCH 4/4 syscalls/fanotify: New test for FAN_MODIFY_DIR
In reply to Amir Goldstein- Watch dir modify events with name info
- Watch self delete events w/o name info
- Test inode and filesystem marks
- Check getting events for all file and dir names
--- runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/fanotify.h | 15 +- .../kernel/syscalls/fanotify/fanotify16.c | 441 ++++++++++++++++++ 4 files changed, 455 insertions(+), 3 deletions(-) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify16.c
runtest/syscalls +1 -0
@@ -571,6 +571,7 @@ fanotify12 fanotify12 fanotify13 fanotify13 fanotify14 fanotify14 fanotify15 fanotify15 +fanotify16 fanotify16 ioperm01 ioperm01 ioperm02 ioperm02
testcases/kernel/syscalls/fanotify/.gitignore +1 -0
@@ -13,4 +13,5 @@ /fanotify13 /fanotify14 /fanotify15 +/fanotify16 /fanotify_child
testcases/kernel/syscalls/fanotify/fanotify.h +12 -3
@@ -41,6 +41,9 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,#ifndef FAN_REPORT_TID #define FAN_REPORT_TID 0x00000100#endif +#ifndef FAN_REPORT_FID +#define FAN_REPORT_FID 0x00000200 +#endif #ifndef FAN_MARK_INODE #define FAN_MARK_INODE 0
@@ -79,9 +82,8 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask,#ifndef FAN_OPEN_EXEC_PERM #define FAN_OPEN_EXEC_PERM 0x00040000#endif - -#ifndef FAN_REPORT_FID -#define FAN_REPORT_FID 0x00000200 +#ifndef FAN_DIR_MODIFY +#define FAN_DIR_MODIFY 0x00080000#endif /*
@@ -106,6 +108,13 @@ typedef struct {#define __kernel_fsid_t lapi_fsid_t#endif /* __kernel_fsid_t */ +#ifndef FAN_EVENT_INFO_TYPE_FID +#define FAN_EVENT_INFO_TYPE_FID 1 +#endif +#ifndef FAN_EVENT_INFO_TYPE_DFID_NAME +#define FAN_EVENT_INFO_TYPE_DFID_NAME 2 +#endif + #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER struct fanotify_event_info_header { uint8_t info_type;
testcases/kernel/syscalls/fanotify/fanotify16.c new file +441 -0
441 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 4/4 syscalls/fanotify: New test for FAN_MODIFY_DIR
Hi Amir,
thank you for this patchset!
...
Quoted 1 line
testcases/kernel/syscalls/fanotify/fanotify16.c +0
-0
...
testcases/kernel/syscalls/fanotify/fanotify16.c line 368
Quoted 11 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +11
-0+ }else if (memcmp (&event_fid->fsid, &expected->fid->fsid, +sizeof (event_fid->fsid)) !=0 ) { + tst_res(TFAIL, + "got event: mask=%llx pid=%u fd=%d name='%s' " + "len=%d info_type=%d info_len=%d fh_len=%d " + "fsid=%x.%x (expected %x.%x)", + (unsigned long long)event->mask, + (unsigned)event->pid, event->fd, filename, + event->event_len, info_type, + event_fid->hdr.len, fhlen, + event_fid->fsid.val[0], event_fid->fsid.val[1],
This needs to be:
+ FSID_VAL_MEMBER(event_fid->fsid, 0),
+ FSID_VAL_MEMBER(event_fid->fsid, 1),
FSID_VAL_MEMBER() is a wrapper struct fanotify_event_info_fid, needed to fix build on musl (and it shouldn't be used for struct event_t).
https://travis-ci.org/github/pevik/ltp/jobs/680149701
Also I got problems on FUSE:
safe_macros.c:754: INFO: Trying FUSE...
tst_test.c:1244: INFO: Timeout per run is 0h 05m 00s
fanotify16.c:112: INFO: Test #0: FAN_REPORT_FID with mark type: FAN_MARK_FILESYSTEM
fanotify16.c:138: BROK: fanotify_mark (3, FAN_MARK_ADD | FAN_MARK_FILESYSTEM, FAN_DIR_MODIFY, AT_FDCWD, 'fs_mnt') failed: ENODEV (19) tst_device.c:373: INFO: umount('fs_mnt') failed with EBUSY, try 1...
tst_device.c:377: INFO: Likely gvfsd-trash is probing newly mounted fs, kill it to speed up tests.
Skipping FUSE fixes it:
.dev_fs_flags = TST_FS_SKIP_FUSE,
Kind regards,
Petr
PATCH 4/4 syscalls/fanotify: New test for FAN_MODIFY_DIR
In reply to Amir GoldsteinHi Amir,
...
Quoted 1 line
testcases/kernel/syscalls/fanotify/fanotify16.c +0
-0
...
testcases/kernel/syscalls/fanotify/fanotify16.c
Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +6
-0+ fd_notify =fanotify_init (FAN_REPORT_FID ,0 ); +if (fd_notify ==-1 ) { +if (errno ==EINVAL ) { +tst_brk (TCONF , +"FAN_REPORT_FID not supported by kernel" ); +return ;
tst_brk() exits the test, so return is not needed.
Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +4
-0+ } +tst_brk (TBROK |TERRNO , +"fanotify_init(FAN_REPORT_FID, 0) failed" ); + }
testcases/kernel/syscalls/fanotify/fanotify16.c
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +10
-0+ +/* +* Watch dir modify events with name in filesystem/dir +*/ +if (fanotify_mark (fd_notify,FAN_MARK_ADD | mark->flag, tc->mask, +AT_FDCWD ,MOUNT_PATH ) <0 ) { +if (errno ==EINVAL ) { +tst_brk (TCONF , +"FAN_DIR_MODIFY not supported by kernel" ); +return ;
Also here.
testcases/kernel/syscalls/fanotify/fanotify16.c
Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +6
-0+ } +tst_brk (TBROK |TERRNO , +"fanotify_mark (%d, FAN_MARK_ADD | %s, " +"FAN_DIR_MODIFY, AT_FDCWD, '" MOUNT_PATH "') " +"failed" , fd_notify, mark->name); + }
Suggesting these changes:
Kind regards,
Petr
kernel/syscalls/fanotify/fanotify16.c +7 -7
@@ -116,11 +116,10 @@ static void do_test(unsigned int number) fd_notify =fanotify_init (FAN_REPORT_FID ,0 );if (fd_notify ==-1 ) { -if (errno ==EINVAL ) { +if (errno ==EINVAL )tst_brk (TCONF ,"FAN_REPORT_FID not supported by kernel" ); -return ; - } +tst_brk (TBROK |TERRNO ,"fanotify_init(FAN_REPORT_FID, 0) failed" ); }
@@ -130,11 +129,10 @@ static void do_test(unsigned int number)*/ if (fanotify_mark (fd_notify,FAN_MARK_ADD | mark->flag, tc->mask,AT_FDCWD ,MOUNT_PATH ) <0 ) { -if (errno ==EINVAL ) { +if (errno ==EINVAL )tst_brk (TCONF ,"FAN_DIR_MODIFY not supported by kernel" ); -return ; - } +tst_brk (TBROK |TERRNO ,"fanotify_mark (%d, FAN_MARK_ADD | %s, " "FAN_DIR_MODIFY, AT_FDCWD, '"MOUNT_PATH"') "
@@ -365,7 +363,8 @@ static void do_test(unsigned int number) (unsigned )event->pid, event->fd, filename, event->event_len, info_type, event_fid->hdr.len, fhlen, - event_fid->fsid.val[0 ], event_fid->fsid.val[1 ], +FSID_VAL_MEMBER (event_fid->fsid,0 ), +FSID_VAL_MEMBER (event_fid->fsid,1 ), expected->fid->fsid.val[0 ], expected->fid->fsid.val[1]); }else if (strcmp (expected->name, filename)) {
@@ -427,6 +426,7 @@ static void cleanup(void)static struct tst_test test = { .test = do_test, .tcnt =ARRAY_SIZE (test_cases), + .dev_fs_flags =TST_FS_SKIP_FUSE , .setup = setup, .cleanup = cleanup, .mount_device =1 ,
PATCH 4/4 syscalls/fanotify: New test for FAN_MODIFY_DIR
Quoted 35 lines · Petr Vorel
Hi Amir,
...
Quoted 1 line
testcases/kernel/syscalls/fanotify/fanotify16.c +0
-0...
testcases/kernel/syscalls/fanotify/fanotify16.c
Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +6
-0+ fd_notify =fanotify_init (FAN_REPORT_FID ,0 ); +if (fd_notify ==-1 ) { +if (errno ==EINVAL ) { +tst_brk (TCONF , +"FAN_REPORT_FID not supported by kernel" ); +return ;
tst_brk()exits the test, so return is not needed.Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +4
-0+ } +tst_brk (TBROK |TERRNO , +"fanotify_init(FAN_REPORT_FID, 0) failed" ); + }testcases/kernel/syscalls/fanotify/fanotify16.c
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +10
-0+ +/* +* Watch dir modify events with name in filesystem/dir +*/ +if (fanotify_mark (fd_notify,FAN_MARK_ADD | mark->flag, tc->mask, +AT_FDCWD ,MOUNT_PATH ) <0 ) { +if (errno ==EINVAL ) { +tst_brk (TCONF , +"FAN_DIR_MODIFY not supported by kernel" ); +return ;Also here.
testcases/kernel/syscalls/fanotify/fanotify16.c
Quoted 6 lines
testcases/kernel/syscalls/fanotify/fanotify16.c +6
-0+ } +tst_brk (TBROK |TERRNO , +"fanotify_mark (%d, FAN_MARK_ADD | %s, " +"FAN_DIR_MODIFY, AT_FDCWD, '" MOUNT_PATH "') " +"failed" , fd_notify, mark->name); + }
Quoted 3 lines
Reviewed-by Petr Vorel <[email protected]>Suggesting these changes:
Hi Petr,
Those changes are fine by me.
Thanks,
Amir.
PATCH 4/4 syscalls/fanotify: New test for FAN_MODIFY_DIR
In reply to Amir GoldsteinHi!
testcases/kernel/syscalls/fanotify/fanotify16.c line 153
Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +7
-0+/* +* Create subdir and watch open events "on children" with name. +*/ +if (mkdir (dname1,0755 ) <0 ) { +tst_brk (TBROK |TERRNO , +"mkdir('" DIR_NAME1 "', 0755) failed" ); + }
The rest of the tests are using SAFE_ macros to generate events, which is basically the same these snippets do, but the code is a bit shorter.
Is there a reason not to use them in this test?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 4/4 syscalls/fanotify: New test for FAN_MODIFY_DIR
In reply to Amir Goldsteintestcases/kernel/syscalls/fanotify/fanotify16.c line 100
Quoted 13 lines · Amir Goldstein
testcases/kernel/syscalls/fanotify/fanotify16.c new file +13
-0+void save_fid (const char *path,struct fid_t *fid) +{ +int *fh = (int *)(fid->handle.f_handle); +int *fsid = fid->fsid.val; + + fh[0 ] = fh[1 ] = fh[2 ] =0 ; + fid->handle.handle_bytes =MAX_HANDLE_SZ ; +fanotify_get_fid (path, &fid->fsid, &fid->handle); + +tst_res (TINFO , +"fid(%s) = %x.%x.%x.%x.%x..." , + path, fsid[0 ], fsid[1 ], fh[0 ], fh[1 ], fh[2 ]); +}
What do you think about pulling this out and shoving it in fanotify.h as another helper? Perhaps future tests would/could also make use of this routine.
testcases/kernel/syscalls/fanotify/fanotify16.c line 106
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +5
-0+static void do_test (unsigned int number) +{ +int len =0 , i =0 , test_num =0 ; +int tst_count =0 ; +int fd;
Just shove all these on one line?
testcases/kernel/syscalls/fanotify/fanotify16.c line 141
Quoted 11 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +11
-0+if (fanotify_mark (fd_notify,FAN_MARK_ADD | mark->flag, tc->mask, +AT_FDCWD ,MOUNT_PATH ) <0 ) { +if (errno ==EINVAL ) { +tst_brk (TCONF , +"FAN_DIR_MODIFY not supported by kernel" ); +return ; + } +tst_brk (TBROK |TERRNO , +"fanotify_mark (%d, FAN_MARK_ADD | %s, " +"FAN_DIR_MODIFY, AT_FDCWD, '" MOUNT_PATH "') " +"failed" , fd_notify, mark->name);
Should we be adding tc->mask here to the format string output?
testcases/kernel/syscalls/fanotify/fanotify16.c line 153
Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +7
-0+/* +* Create subdir and watch open events "on children" with name. +*/ +if (mkdir (dname1,0755 ) <0 ) { +tst_brk (TBROK |TERRNO , +"mkdir('" DIR_NAME1 "', 0755) failed" ); + }
Perhaps we should be making use of the SAFE_MACROS() so that we're adhering to the test writing guidelines?
testcases/kernel/syscalls/fanotify/fanotify16.c line 166
Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +9
-0+if (tc->sub_mask && +fanotify_mark (fd_notify,FAN_MARK_ADD | sub_mark->flag, tc->sub_mask, +AT_FDCWD , dname1) <0 ) { +tst_brk (TBROK |TERRNO , +"fanotify_mark (%d, FAN_MARK_ADD | %s, " +"FAN_DIR_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, " +"AT_FDCWD, '%s') " +"failed" , fd_notify, sub_mark->name, dname1); + }
Maybe just replace the statically typed mask here with tc->sub_mask? That way, if test cases are added or modified in the future, you don't have to update it?
Quoted 11 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +11
-0+if ((fd =creat (fname1,0755 )) ==-1 ) { +tst_brk (TBROK |TERRNO , +"creat(\"%s\", 755) failed" ,FILE_NAME1 ); + } + +if (rename (fname1, fname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"rename(%s, %s) failed" , +FILE_NAME1 ,FILE_NAME2 ); + } +
testcases/kernel/syscalls/fanotify/fanotify16.c line 199
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +10
-0+if (close (fd) ==-1 ) { +tst_brk (TBROK |TERRNO , +"close(%s) failed" ,FILE_NAME2 ); + } + +/* Generate delete events with fname2 */ +if (unlink (fname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"unlink(%s) failed" ,FILE_NAME2 ); + }
The same applies with the above set of system calls?
...
testcases/kernel/syscalls/fanotify/fanotify16.c line 235
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +10
-0+if (rename (dname1, dname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"rename(%s, %s) failed" , +DIR_NAME1 ,DIR_NAME2 ); + } + +if (rmdir (dname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"rmdir(%s) failed" ,DIR_NAME2 ); + }
And here...
Quoted 17 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +17
-0+while (i < len) { +struct event_t *expected = &event_set[test_num]; +struct fanotify_event_metadata *event; +struct fanotify_event_info_fid *event_fid; +struct file_handle *file_handle; +unsigned int fhlen; +const char *filename; +int namelen, info_type; + + event = (struct fanotify_event_metadata *)&event_buf[i]; + event_fid = (struct fanotify_event_info_fid *)(event +1 ); + file_handle = (struct file_handle *)event_fid->handle; + fhlen = file_handle->handle_bytes; + filename = (char *)file_handle->f_handle + fhlen; + namelen = ((char *)event + event->event_len) - filename; +/* End of event could have name, zero padding, both or none */ +if (namelen >0 ) {
testcases/kernel/syscalls/fanotify/fanotify16.c line 288
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +10
-0+ namelen =strlen (filename); + }else { + filename ="" ; + namelen =0 ; + } +if (expected->name[0 ]) { + info_type =FAN_EVENT_INFO_TYPE_DFID_NAME ; + }else { + info_type =FAN_EVENT_INFO_TYPE_FID ; + }
Can we line break these conditional statements?
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static void setup(void) +{
int fd; fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, 0_RDONLY); SAFE_CLOSE(fd);
Above snippet missing from test bootstrap? I remember we had to add this in the past, but I can't remember the _why_?
Anyway, the functionality testing looks fine to me.
/M
PATCH 4/4 syscalls/fanotify: New test for FAN_MODIFY_DIR
Quoted 11 lines · Matthew Bobrowski
Quoted 9 lines · Amir Goldstein
testcases/kernel/syscalls/fanotify/fanotify16.c new file +9
-0+void save_fid (const char *path,struct fid_t *fid) +{ +int *fh = (int *)(fid->handle.f_handle); +int *fsid = fid->fsid.val; + + fh[0 ] = fh[1 ] = fh[2 ] =0 ; + fid->handle.handle_bytes =MAX_HANDLE_SZ ; +fanotify_get_fid (path, &fid->fsid, &fid->handle); +
Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify16.c line 100
Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +4
-0+tst_res (TINFO , +"fid(%s) = %x.%x.%x.%x.%x..." , + path, fsid[0 ], fsid[1 ], fh[0 ], fh[1 ], fh[2 ]); +}What do you think about pulling this out and shoving it in
fanotify.has another helper? Perhaps future tests would/could also make use of this routine.
Ok. And I'll convert fanotify15/fanotify13 to use this helper in another patch.
Quoted 7 lines
testcases/kernel/syscalls/fanotify/fanotify16.c line 106
Quoted 5 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +5
-0+static void do_test (unsigned int number) +{ +int len =0 , i =0 , test_num =0 ; +int tst_count =0 ; +int fd;Just shove all these on one line?
ok.
Quoted 13 lines
testcases/kernel/syscalls/fanotify/fanotify16.c line 141
Quoted 12 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +11
-0+if (fanotify_mark (fd_notify,FAN_MARK_ADD | mark->flag, tc->mask, +AT_FDCWD ,MOUNT_PATH ) <0 ) { +if (errno ==EINVAL ) { +tst_brk (TCONF , +"FAN_DIR_MODIFY not supported by kernel" ); +return ; + } +tst_brk (TBROK |TERRNO , +"fanotify_mark (%d, FAN_MARK_ADD | %s, " +"FAN_DIR_MODIFY, AT_FDCWD, '" MOUNT_PATH "') " +"failed" , fd_notify, mark->name);
Quoted 1 line
Should we be adding
tc->maskhere to the format string output?
Ok.
Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify16.c line 153
Quoted 8 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +7
-0+/* +* Create subdir and watch open events "on children" with name. +*/ +if (mkdir (dname1,0755 ) <0 ) { +tst_brk (TBROK |TERRNO , +"mkdir('" DIR_NAME1 "', 0755) failed" ); + }
Quoted 3 lines
Perhaps we should be making use of the
SAFE_MACROS()so that we're adhering to the test writing guidelines?
Of course.
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c line 166
Quoted 9 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +9
-0+if (tc->sub_mask && +fanotify_mark (fd_notify,FAN_MARK_ADD | sub_mark->flag, tc->sub_mask, +AT_FDCWD , dname1) <0 ) { +tst_brk (TBROK |TERRNO , +"fanotify_mark (%d, FAN_MARK_ADD | %s, " +"FAN_DIR_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, " +"AT_FDCWD, '%s') " +"failed" , fd_notify, sub_mark->name, dname1); + }
Quoted 4 lines
Maybe just replace the statically typed mask here with
tc->sub_mask? That way, if test cases are added or modified in the future, you don't have to update it?
Sure.
Quoted 68 lines
Quoted 11 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +11
-0+if ((fd =creat (fname1,0755 )) ==-1 ) { +tst_brk (TBROK |TERRNO , +"creat(\"%s\", 755) failed" ,FILE_NAME1 ); + } + +if (rename (fname1, fname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"rename(%s, %s) failed" , +FILE_NAME1 ,FILE_NAME2 ); + } +testcases/kernel/syscalls/fanotify/fanotify16.c line 199
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +10
-0+if (close (fd) ==-1 ) { +tst_brk (TBROK |TERRNO , +"close(%s) failed" ,FILE_NAME2 ); + } + +/* Generate delete events with fname2 */ +if (unlink (fname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"unlink(%s) failed" ,FILE_NAME2 ); + }The same applies with the above set of system calls?
...
testcases/kernel/syscalls/fanotify/fanotify16.c line 235
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +10
-0+if (rename (dname1, dname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"rename(%s, %s) failed" , +DIR_NAME1 ,DIR_NAME2 ); + } + +if (rmdir (dname2) ==-1 ) { +tst_brk (TBROK |TERRNO , +"rmdir(%s) failed" ,DIR_NAME2 ); + }And here...
Quoted 17 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +17
-0+while (i < len) { +struct event_t *expected = &event_set[test_num]; +struct fanotify_event_metadata *event; +struct fanotify_event_info_fid *event_fid; +struct file_handle *file_handle; +unsigned int fhlen; +const char *filename; +int namelen, info_type; + + event = (struct fanotify_event_metadata *)&event_buf[i]; + event_fid = (struct fanotify_event_info_fid *)(event +1 ); + file_handle = (struct file_handle *)event_fid->handle; + fhlen = file_handle->handle_bytes; + filename = (char *)file_handle->f_handle + fhlen; + namelen = ((char *)event + event->event_len) - filename; +/* End of event could have name, zero padding, both or none */ +if (namelen >0 ) {testcases/kernel/syscalls/fanotify/fanotify16.c line 288
Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify16.c new file +10
-0+ namelen =strlen (filename); + }else { + filename ="" ; + namelen =0 ; + } +if (expected->name[0 ]) { + info_type =FAN_EVENT_INFO_TYPE_DFID_NAME ; + }else { + info_type =FAN_EVENT_INFO_TYPE_FID ; + }
Quoted 2 lines
Can we line break these conditional statements?
ok.
Quoted 10 lines
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static void setup(void) +{int fd; fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, 0_RDONLY); SAFE_CLOSE(fd);
Quoted 3 lines
Above snippet missing from test bootstrap? I remember we had to add this in the past, but I can't remember the _why_?
Because, if kernel does not support fanotify, we want the test to fail on setup with "fanotify is not configured in this kernel." instead of inaccurately reporting later:
"FAN_REPORT_FID not supported by kernel".
Thanks a lot for the review,
Amir.