From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 2/4] syscalls/fanotify15: Minor corrections
Date: Tue, 21 Apr 2020 09:50:00 +0300 [thread overview]
Message-ID: <20200421065002.12417-3-amir73il@gmail.com> (raw)
In-Reply-To: <20200421065002.12417-1-amir73il@gmail.com>
- 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
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
.../kernel/syscalls/fanotify/fanotify15.c | 58 ++++++++++++++-----
1 file changed, 42 insertions(+), 16 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify15.c b/testcases/kernel/syscalls/fanotify/fanotify15.c
index e0d513025..454441bfe 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify15.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify15.c
@@ -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++)
--
2.17.1
next prev parent reply other threads:[~2020-04-21 6:50 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-21 6:49 [LTP] [PATCH 0/4] fanotify ltp tests for v5.7-rc1 Amir Goldstein
2020-04-21 6:49 ` [LTP] [PATCH 1/4] syscalls/fanotify09: Check merging of events on directories Amir Goldstein
2020-04-27 17:27 ` Petr Vorel
2020-05-01 7:17 ` Matthew Bobrowski
2020-05-01 9:05 ` Amir Goldstein
2020-05-01 9:46 ` Matthew Bobrowski
2020-04-21 6:50 ` Amir Goldstein [this message]
2020-04-27 19:30 ` [LTP] [PATCH 2/4] syscalls/fanotify15: Minor corrections Petr Vorel
2020-04-29 15:08 ` Cyril Hrubis
2020-05-01 8:09 ` Matthew Bobrowski
2020-04-21 6:50 ` [LTP] [PATCH 3/4] syscalls/fanotify15: Add a test case for inode marks Amir Goldstein
2020-04-27 19:43 ` Petr Vorel
2020-04-28 9:20 ` Petr Vorel
2020-04-29 15:28 ` Cyril Hrubis
2020-05-02 7:09 ` Matthew Bobrowski
2020-05-02 13:17 ` Amir Goldstein
2020-04-21 6:50 ` [LTP] [PATCH 4/4] syscalls/fanotify: New test for FAN_MODIFY_DIR Amir Goldstein
2020-04-27 16:49 ` Petr Vorel
2020-04-28 9:22 ` Petr Vorel
2020-04-28 9:51 ` Amir Goldstein
2020-04-29 16:02 ` Cyril Hrubis
2020-05-02 9:39 ` Matthew Bobrowski
2020-05-02 14:58 ` Amir Goldstein
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=20200421065002.12417-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox