[LTP] [PATCH] fanotify/fanotify04: Bugfix for running with option of "-i 500"
Zhao Gongyi
zhaogongyi@huawei.com
Wed Feb 9 08:39:43 CET 2022
When we running the testcase with option of "-i 500", the test
will fail:
...
fanotify04.c:163: TPASS: No event as expected
fanotify04.c:71: TPASS: fanotify_mark (3, FAN_MARK_ADD | 0, FAN_OPEN, AT_FDCWD, 'symlink_160172') succeeded
fanotify04.c:127: TPASS: event generated properly for type 100000
fanotify04.c:113: TBROK: read(3,0x55c783185280,0) failed, returned -1: EINVAL (22)
...
Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
.../kernel/syscalls/fanotify/fanotify04.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify04.c b/testcases/kernel/syscalls/fanotify/fanotify04.c
index b23d7a9a3..8dedcf34a 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify04.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify04.c
@@ -24,11 +24,8 @@
#ifdef HAVE_SYS_FANOTIFY_H
#include "fanotify.h"
-#define EVENT_MAX 1024
/* size of the event structure, not counting name */
#define EVENT_SIZE (sizeof (struct fanotify_event_metadata))
-/* reasonable guess as to size of 1024 events */
-#define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE)
#define BUF_SIZE 256
#define TST_TOTAL 9
@@ -39,7 +36,7 @@ static char dir[BUF_SIZE];
static int fd_notify;
static int len;
-static char event_buf[EVENT_BUF_LEN];
+static char event_buf[EVENT_SIZE];
static char *expect_str_fail(int expect)
{
@@ -109,11 +106,8 @@ static void verify_event(int mask)
struct stat st;
/* Read the event */
- ret = SAFE_READ(0, fd_notify, event_buf + len,
- EVENT_BUF_LEN - len);
- event = (struct fanotify_event_metadata *)&event_buf[len];
- len += ret;
-
+ ret = SAFE_READ(0, fd_notify, event_buf, EVENT_SIZE);
+ event = (struct fanotify_event_metadata *)&event_buf;
if (event->mask != FAN_OPEN) {
tst_res(TFAIL, "got unexpected event %llx",
(unsigned long long)event->mask);
@@ -146,11 +140,11 @@ static void verify_no_event(void)
{
int ret;
- ret = read(fd_notify, event_buf + len, EVENT_BUF_LEN - len);
+ ret = read(fd_notify, event_buf, EVENT_SIZE);
if (ret != -1) {
struct fanotify_event_metadata *event;
- event = (struct fanotify_event_metadata *)&event_buf[len];
+ event = (struct fanotify_event_metadata *)&event_buf;
tst_res(TFAIL, "seen unexpected event (mask %llx)",
(unsigned long long)event->mask);
/* Cleanup fd from the event */
@@ -158,7 +152,7 @@ static void verify_no_event(void)
SAFE_CLOSE(event->fd);
} else if (errno != EAGAIN) {
tst_res(TFAIL | TERRNO, "read(%d, buf, %zu) failed", fd_notify,
- EVENT_BUF_LEN);
+ EVENT_SIZE);
} else {
tst_res(TPASS, "No event as expected");
}
--
2.17.1
More information about the ltp
mailing list