From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 05/10] syscalls/fanotify16: Verify child fid info
Date: Wed, 9 Sep 2020 20:57:02 +0300 [thread overview]
Message-ID: <20200909175707.10670-6-amir73il@gmail.com> (raw)
In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com>
If event reports both dir and child fid, also verify the expected
child fid in the second info record.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify16.c | 73 ++++++++++++++++---
1 file changed, 61 insertions(+), 12 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c
index c8c7a9ee8..7995a1688 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify16.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify16.c
@@ -44,6 +44,7 @@
struct event_t {
unsigned long long mask;
struct fanotify_fid_t *fid;
+ struct fanotify_fid_t *child_fid;
char name[BUF_SIZE];
};
@@ -205,6 +206,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;
strcpy(event_set[tst_count].name, DIR_NAME1);
tst_count++;
@@ -230,6 +232,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;
strcpy(event_set[tst_count].name, FILE_NAME1);
tst_count++;
/*
@@ -242,12 +245,14 @@ static void do_test(unsigned int number)
if (group->flag & FAN_REPORT_NAME) {
event_set[tst_count].mask = FAN_OPEN;
event_set[tst_count].fid = &dir_fid;
+ event_set[tst_count].child_fid = &file_fid;
strcpy(event_set[tst_count].name, FILE_NAME1);
tst_count++;
}
event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO;
event_set[tst_count].fid = &dir_fid;
+ event_set[tst_count].child_fid = NULL;
strcpy(event_set[tst_count].name, FILE_NAME2);
tst_count++;
/*
@@ -257,6 +262,7 @@ static void do_test(unsigned int number)
if (!(group->flag & FAN_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;
strcpy(event_set[tst_count].name, "");
tst_count++;
}
@@ -268,6 +274,7 @@ static void do_test(unsigned int number)
if (mark->flag == FAN_MARK_FILESYSTEM && (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;
strcpy(event_set[tst_count].name, "");
tst_count++;
}
@@ -279,6 +286,7 @@ static void do_test(unsigned int number)
if (group->flag & FAN_REPORT_NAME) {
event_set[tst_count].mask = FAN_CLOSE_WRITE;
event_set[tst_count].fid = &dir_fid;
+ event_set[tst_count].child_fid = &file_fid;
strcpy(event_set[tst_count].name, FILE_NAME2);
tst_count++;
}
@@ -294,6 +302,7 @@ static void do_test(unsigned int number)
*/
event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_NOWRITE | FAN_ONDIR;
event_set[tst_count].fid = &dir_fid;
+ event_set[tst_count].child_fid = NULL;
strcpy(event_set[tst_count].name, ".");
tst_count++;
/*
@@ -302,6 +311,7 @@ static void do_test(unsigned int number)
*/
event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR;
event_set[tst_count].fid = &dir_fid;
+ event_set[tst_count].child_fid = NULL;
strcpy(event_set[tst_count].name, ".");
tst_count++;
@@ -313,10 +323,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;
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;
strcpy(event_set[tst_count].name, DIR_NAME2);
tst_count++;
/* Expect no more events */
@@ -332,17 +344,21 @@ static void do_test(unsigned int number)
struct event_t *expected = &event_set[test_num];
struct fanotify_event_metadata *event;
struct fanotify_event_info_fid *event_fid;
+ struct fanotify_event_info_fid *child_fid;
+ struct fanotify_fid_t *expected_fid = expected->fid;
+ struct fanotify_fid_t *expected_child_fid = expected->child_fid;
struct file_handle *file_handle;
unsigned int fhlen;
const char *filename;
- int namelen, info_type, mask_match;
+ int namelen, info_type, mask_match, info_id = 0;
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_fid + event_fid->hdr.len) - filename;
+ child_fid = (void *)((char *)event_fid + event_fid->hdr.len);
+ namelen = (char *)child_fid - (char *)filename;
/* End of event_fid could have name, zero padding, both or none */
if (namelen > 0) {
namelen = strlen(filename);
@@ -350,6 +366,12 @@ static void do_test(unsigned int number)
filename = "";
namelen = 0;
}
+ /* Is there a child fid after first fid record? */
+ if (((char *)child_fid - (char *)event) >= event->event_len)
+ child_fid = NULL;
+
+ if (!(group->flag & FAN_REPORT_FID))
+ expected_child_fid = NULL;
if (!(group->flag & FAN_REPORT_NAME))
expected->name[0] = 0;
@@ -375,6 +397,7 @@ static void do_test(unsigned int number)
!(expected->mask & ~event->mask) &&
!((event->mask ^ expected->mask) & FAN_ONDIR));
+check_match:
if (test_num >= tst_count) {
tst_res(TFAIL,
"got unnecessary event: mask=%llx "
@@ -409,7 +432,7 @@ static void do_test(unsigned int number)
(unsigned)event->pid, event->fd,
event->event_len, event_fid->hdr.info_type,
info_type, event_fid->hdr.len, fhlen);
- } else if (fhlen != expected->fid->handle.handle_bytes) {
+ } else if (fhlen != expected_fid->handle.handle_bytes) {
tst_res(TFAIL,
"got event: mask=%llx pid=%u fd=%d name='%s' "
"len=%d info_type=%d info_len=%d fh_len=%d expected(%d)"
@@ -418,10 +441,10 @@ static void do_test(unsigned int number)
(unsigned)event->pid, event->fd, filename,
event->event_len, info_type,
event_fid->hdr.len, fhlen,
- expected->fid->handle.handle_bytes,
+ expected_fid->handle.handle_bytes,
file_handle->handle_type);
} else if (file_handle->handle_type !=
- expected->fid->handle.handle_type) {
+ expected_fid->handle.handle_type) {
tst_res(TFAIL,
"got event: mask=%llx pid=%u fd=%d name='%s' "
"len=%d info_type=%d info_len=%d fh_len=%d "
@@ -431,9 +454,9 @@ static void do_test(unsigned int number)
event->event_len, info_type,
event_fid->hdr.len, fhlen,
file_handle->handle_type,
- expected->fid->handle.handle_type);
+ expected_fid->handle.handle_type);
} else if (memcmp(file_handle->f_handle,
- expected->fid->handle.f_handle, fhlen)) {
+ expected_fid->handle.f_handle, fhlen)) {
tst_res(TFAIL,
"got event: mask=%llx pid=%u fd=%d name='%s' "
"len=%d info_type=%d info_len=%d fh_len=%d "
@@ -444,7 +467,7 @@ static void do_test(unsigned int number)
event_fid->hdr.len, fhlen,
file_handle->handle_type,
*(int *)(file_handle->f_handle));
- } else if (memcmp(&event_fid->fsid, &expected->fid->fsid,
+ } 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' "
@@ -456,8 +479,8 @@ static void do_test(unsigned int number)
event_fid->hdr.len, fhlen,
FSID_VAL_MEMBER(event_fid->fsid, 0),
FSID_VAL_MEMBER(event_fid->fsid, 1),
- expected->fid->fsid.val[0],
- expected->fid->fsid.val[1]);
+ expected_fid->fsid.val[0],
+ expected_fid->fsid.val[1]);
} else if (strcmp(expected->name, filename)) {
tst_res(TFAIL,
"got event: mask=%llx "
@@ -479,13 +502,39 @@ static void do_test(unsigned int number)
event->fd, filename,
event->event_len, event_fid->hdr.info_type,
event_fid->hdr.len, fhlen);
+ } else if (!!child_fid != !!expected_child_fid) {
+ tst_res(TFAIL,
+ "got event: mask=%llx "
+ "pid=%u fd=%d name='%s' num_info=%d (expected %d) "
+ "len=%d info_type=%d info_len=%d fh_len=%d",
+ (unsigned long long)event->mask,
+ (unsigned)event->pid, event->fd,
+ filename, 1 + !!child_fid, 1 + !!expected_child_fid,
+ event->event_len, event_fid->hdr.info_type,
+ event_fid->hdr.len, fhlen);
+ } else if (child_fid) {
+ tst_res(TINFO,
+ "got event #%d: info #%d: info_type=%d info_len=%d fh_len=%d",
+ test_num, info_id, event_fid->hdr.info_type,
+ event_fid->hdr.len, fhlen);
+
+ /* Recheck event_fid match with child_fid */
+ event_fid = child_fid;
+ expected_fid = expected->child_fid;
+ info_id = 1;
+ info_type = FAN_EVENT_INFO_TYPE_FID;
+ file_handle = (struct file_handle *)event_fid->handle;
+ fhlen = file_handle->handle_bytes;
+ child_fid = NULL;
+ expected_child_fid = NULL;
+ goto check_match;
} else {
tst_res(TPASS,
"got event #%d: mask=%llx pid=%u fd=%d name='%s' "
- "len=%d info_type=%d info_len=%d fh_len=%d",
+ "len=%d; info #%d: info_type=%d info_len=%d fh_len=%d",
test_num, (unsigned long long)event->mask,
(unsigned)event->pid, event->fd, filename,
- event->event_len, event_fid->hdr.info_type,
+ event->event_len, info_id, event_fid->hdr.info_type,
event_fid->hdr.len, fhlen);
}
--
2.17.1
next prev parent reply other threads:[~2020-09-09 17:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 17:56 [LTP] [PATCH 00/10] Fanotify tests for v5.9 Amir Goldstein
2020-09-09 17:56 ` [LTP] [PATCH 01/10] syscalls/fanotify14: Test cases for FAN_REPORT_DFID_NAME Amir Goldstein
2020-09-09 17:56 ` [LTP] [PATCH 02/10] syscalls/fanotify16: Adjust test to use FAN_REPORT_DFID_NAME Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 03/10] syscalls/fanotify16: Test more event types with name Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 04/10] syscalls/fanotify16: Add test cases more init flag combinations Amir Goldstein
2020-09-09 17:57 ` Amir Goldstein [this message]
2020-09-09 17:57 ` [LTP] [PATCH 06/10] syscalls/fcntl: New test for F_NOTIFY (dnotify) Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 07/10] syscalls/inotify: New test for watches on both parent and child Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 08/10] syscalls/fanotify09: Add test case with parent and subdir marks Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 09/10] syscalls/fanotify10: Test with group flag FAN_REPORT_NAME Amir Goldstein
2020-09-09 17:57 ` [LTP] [PATCH 10/10] syscalls/fanotify10: Add test cases for merge with ignored mask on directory Amir Goldstein
2020-09-10 8:16 ` [LTP] [PATCH 00/10] Fanotify tests for v5.9 Petr Vorel
2020-09-10 8:34 ` Petr Vorel
2020-09-10 11:27 ` Petr Vorel
2020-09-10 13:36 ` Amir Goldstein
2020-09-10 13:50 ` Amir Goldstein
2020-09-10 14:43 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200909175707.10670-6-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.