All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] fanotify06: add a test case for overlayfs
@ 2019-06-04 15:10 ` Amir Goldstein
  0 siblings, 0 replies; 6+ messages in thread
From: Amir Goldstein @ 2019-06-04 15:10 UTC (permalink / raw)
  To: Petr Vorel
  Cc: Cyril Hrubis, Murphy Zhou, Jan Kara, Miklos Szeredi, linux-unionfs, ltp

This test fails on overlayfs since kernel v4.19.
Added a test case for overlayfs mount.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Changes since v1:
- Use new overlayfs mount helpers
- Add patch to fix EBUSY error on overlayfs umount

 .../kernel/syscalls/fanotify/fanotify06.c     | 61 +++++++++++++------
 1 file changed, 43 insertions(+), 18 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify06.c b/testcases/kernel/syscalls/fanotify/fanotify06.c
index 6a2e2494f..e053da0e5 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify06.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify06.c
@@ -15,6 +15,14 @@
  *  Date:   Thu Nov 13 15:19:33 2014 -0800
  *
  *      fanotify: fix notification of groups with inode & mount marks
+ *
+ * The overlayfs test case is a regression test for:
+ *
+ *  commit d989903058a83e8536cc7aadf9256a47d5c173fe
+ *  Author: Amir Goldstein <amir73il@gmail.com>
+ *  Date:   Wed Apr 24 19:39:50 2019 +0300
+ *
+ *      ovl: do not generate duplicate fsnotify events for "fake" path
  */
 #define _GNU_SOURCE
 #include "config.h"
@@ -54,8 +62,18 @@ static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO];
 
 static char event_buf[EVENT_BUF_LEN];
 
-#define MOUNT_NAME "mntpoint"
-static int mount_created;
+static const char mntpoint[] = OVL_BASE_MNTPOINT;
+
+static int ovl_mounted;
+
+static struct tcase {
+	const char *tname;
+	const char *mnt;
+	int use_overlay;
+} tcases[] = {
+	{ "Fanotify merge mount mark", mntpoint, 0 },
+	{ "Fanotify merge overlayfs mount mark", OVL_MNT, 1 },
+};
 
 static void create_fanotify_groups(void)
 {
@@ -72,12 +90,12 @@ static void create_fanotify_groups(void)
 			ret = fanotify_mark(fd_notify[p][i],
 					    FAN_MARK_ADD | FAN_MARK_MOUNT,
 					    FAN_MODIFY,
-					    AT_FDCWD, ".");
+					    AT_FDCWD, fname);
 			if (ret < 0) {
 				tst_brk(TBROK | TERRNO,
 					"fanotify_mark(%d, FAN_MARK_ADD | "
 					"FAN_MARK_MOUNT, FAN_MODIFY, AT_FDCWD,"
-					" '.') failed", fd_notify[p][i]);
+					" %s) failed", fd_notify[p][i], fname);
 			}
 			/* Add ignore mark for groups with higher priority */
 			if (p == 0)
@@ -130,11 +148,23 @@ static void verify_event(int group, struct fanotify_event_metadata *event)
 	}
 }
 
-void test01(void)
+void test_fanotify(unsigned int n)
 {
 	int ret;
 	unsigned int p, i;
 	struct fanotify_event_metadata *event;
+	struct tcase *tc = &tcases[n];
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+
+	if (tc->use_overlay && !ovl_mounted) {
+		tst_res(TCONF,
+		        "overlayfs is not configured in this kernel.");
+		return;
+	}
+
+	sprintf(fname, "%s/tfile_%d", tc->mnt, getpid());
+	SAFE_TOUCH(fname, 0644, NULL);
 
 	create_fanotify_groups();
 
@@ -196,31 +226,26 @@ void test01(void)
 
 static void setup(void)
 {
-	SAFE_MKDIR(MOUNT_NAME, 0755);
-	SAFE_MOUNT(MOUNT_NAME, MOUNT_NAME, "none", MS_BIND, NULL);
-	mount_created = 1;
-	SAFE_CHDIR(MOUNT_NAME);
-
-	sprintf(fname, "tfile_%d", getpid());
-	SAFE_FILE_PRINTF(fname, "1");
+	ovl_mounted = TST_MOUNT_OVERLAY();
 }
 
 static void cleanup(void)
 {
 	cleanup_fanotify_groups();
 
-	SAFE_CHDIR("../");
-
-	if (mount_created && tst_umount(MOUNT_NAME) < 0)
-		tst_brk(TBROK | TERRNO, "umount failed");
+	if (ovl_mounted)
+		SAFE_UMOUNT(OVL_MNT);
 }
 
 static struct tst_test test = {
-	.test_all = test01,
+	.test = test_fanotify,
+	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
-	.needs_root = 1
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = mntpoint,
 };
 
 #else
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH v2 1/2] fanotify06: add a test case for overlayfs
@ 2019-06-04 15:10 ` Amir Goldstein
  0 siblings, 0 replies; 6+ messages in thread
From: Amir Goldstein @ 2019-06-04 15:10 UTC (permalink / raw)
  To: ltp

This test fails on overlayfs since kernel v4.19.
Added a test case for overlayfs mount.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Changes since v1:
- Use new overlayfs mount helpers
- Add patch to fix EBUSY error on overlayfs umount

 .../kernel/syscalls/fanotify/fanotify06.c     | 61 +++++++++++++------
 1 file changed, 43 insertions(+), 18 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify06.c b/testcases/kernel/syscalls/fanotify/fanotify06.c
index 6a2e2494f..e053da0e5 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify06.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify06.c
@@ -15,6 +15,14 @@
  *  Date:   Thu Nov 13 15:19:33 2014 -0800
  *
  *      fanotify: fix notification of groups with inode & mount marks
+ *
+ * The overlayfs test case is a regression test for:
+ *
+ *  commit d989903058a83e8536cc7aadf9256a47d5c173fe
+ *  Author: Amir Goldstein <amir73il@gmail.com>
+ *  Date:   Wed Apr 24 19:39:50 2019 +0300
+ *
+ *      ovl: do not generate duplicate fsnotify events for "fake" path
  */
 #define _GNU_SOURCE
 #include "config.h"
@@ -54,8 +62,18 @@ static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO];
 
 static char event_buf[EVENT_BUF_LEN];
 
-#define MOUNT_NAME "mntpoint"
-static int mount_created;
+static const char mntpoint[] = OVL_BASE_MNTPOINT;
+
+static int ovl_mounted;
+
+static struct tcase {
+	const char *tname;
+	const char *mnt;
+	int use_overlay;
+} tcases[] = {
+	{ "Fanotify merge mount mark", mntpoint, 0 },
+	{ "Fanotify merge overlayfs mount mark", OVL_MNT, 1 },
+};
 
 static void create_fanotify_groups(void)
 {
@@ -72,12 +90,12 @@ static void create_fanotify_groups(void)
 			ret = fanotify_mark(fd_notify[p][i],
 					    FAN_MARK_ADD | FAN_MARK_MOUNT,
 					    FAN_MODIFY,
-					    AT_FDCWD, ".");
+					    AT_FDCWD, fname);
 			if (ret < 0) {
 				tst_brk(TBROK | TERRNO,
 					"fanotify_mark(%d, FAN_MARK_ADD | "
 					"FAN_MARK_MOUNT, FAN_MODIFY, AT_FDCWD,"
-					" '.') failed", fd_notify[p][i]);
+					" %s) failed", fd_notify[p][i], fname);
 			}
 			/* Add ignore mark for groups with higher priority */
 			if (p == 0)
@@ -130,11 +148,23 @@ static void verify_event(int group, struct fanotify_event_metadata *event)
 	}
 }
 
-void test01(void)
+void test_fanotify(unsigned int n)
 {
 	int ret;
 	unsigned int p, i;
 	struct fanotify_event_metadata *event;
+	struct tcase *tc = &tcases[n];
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+
+	if (tc->use_overlay && !ovl_mounted) {
+		tst_res(TCONF,
+		        "overlayfs is not configured in this kernel.");
+		return;
+	}
+
+	sprintf(fname, "%s/tfile_%d", tc->mnt, getpid());
+	SAFE_TOUCH(fname, 0644, NULL);
 
 	create_fanotify_groups();
 
@@ -196,31 +226,26 @@ void test01(void)
 
 static void setup(void)
 {
-	SAFE_MKDIR(MOUNT_NAME, 0755);
-	SAFE_MOUNT(MOUNT_NAME, MOUNT_NAME, "none", MS_BIND, NULL);
-	mount_created = 1;
-	SAFE_CHDIR(MOUNT_NAME);
-
-	sprintf(fname, "tfile_%d", getpid());
-	SAFE_FILE_PRINTF(fname, "1");
+	ovl_mounted = TST_MOUNT_OVERLAY();
 }
 
 static void cleanup(void)
 {
 	cleanup_fanotify_groups();
 
-	SAFE_CHDIR("../");
-
-	if (mount_created && tst_umount(MOUNT_NAME) < 0)
-		tst_brk(TBROK | TERRNO, "umount failed");
+	if (ovl_mounted)
+		SAFE_UMOUNT(OVL_MNT);
 }
 
 static struct tst_test test = {
-	.test_all = test01,
+	.test = test_fanotify,
+	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_tmpdir = 1,
-	.needs_root = 1
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = mntpoint,
 };
 
 #else
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] fanotify06: Close all file descriptors of read events
  2019-06-04 15:10 ` [LTP] " Amir Goldstein
@ 2019-06-04 15:10   ` Amir Goldstein
  -1 siblings, 0 replies; 6+ messages in thread
From: Amir Goldstein @ 2019-06-04 15:10 UTC (permalink / raw)
  To: Petr Vorel
  Cc: Cyril Hrubis, Murphy Zhou, Jan Kara, Miklos Szeredi, linux-unionfs, ltp

With overlayfs test case on kernel v4.19, we get extra events.
If we do not close the event->fd file descriptros of all the events
that we read, overlayfs will fail to unmount at the end of the test
and test will retry un-mounting for a while.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify06.c      | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify06.c b/testcases/kernel/syscalls/fanotify/fanotify06.c
index e053da0e5..273c1f0c4 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify06.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify06.c
@@ -148,6 +148,17 @@ static void verify_event(int group, struct fanotify_event_metadata *event)
 	}
 }
 
+/* Close all file descriptors of read events */
+static void close_events_fd(struct fanotify_event_metadata *event, int buflen)
+{
+	while (buflen >= (int)FAN_EVENT_METADATA_LEN) {
+		if (event->fd != FAN_NOFD)
+			SAFE_CLOSE(event->fd);
+		buflen -= (int)FAN_EVENT_METADATA_LEN;
+		event++;
+	}
+}
+
 void test_fanotify(unsigned int n)
 {
 	int ret;
@@ -198,17 +209,16 @@ void test_fanotify(unsigned int n)
 		} else {
 			verify_event(i, event);
 		}
-		if (event->fd != FAN_NOFD)
-			SAFE_CLOSE(event->fd);
+		close_events_fd(event, ret);
 	}
+
 	for (p = 1; p < FANOTIFY_PRIORITIES; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN);
 			if (ret > 0) {
 				tst_res(TFAIL, "group %d got event",
 					p*GROUPS_PER_PRIO + i);
-				if (event->fd != FAN_NOFD)
-					SAFE_CLOSE(event->fd);
+				close_events_fd((void *)event_buf, ret);
 			} else if (ret == 0) {
 				tst_brk(TBROK, "zero length "
 					"read from fanotify fd");
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH v2 2/2] fanotify06: Close all file descriptors of read events
@ 2019-06-04 15:10   ` Amir Goldstein
  0 siblings, 0 replies; 6+ messages in thread
From: Amir Goldstein @ 2019-06-04 15:10 UTC (permalink / raw)
  To: ltp

With overlayfs test case on kernel v4.19, we get extra events.
If we do not close the event->fd file descriptros of all the events
that we read, overlayfs will fail to unmount at the end of the test
and test will retry un-mounting for a while.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify06.c      | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify06.c b/testcases/kernel/syscalls/fanotify/fanotify06.c
index e053da0e5..273c1f0c4 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify06.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify06.c
@@ -148,6 +148,17 @@ static void verify_event(int group, struct fanotify_event_metadata *event)
 	}
 }
 
+/* Close all file descriptors of read events */
+static void close_events_fd(struct fanotify_event_metadata *event, int buflen)
+{
+	while (buflen >= (int)FAN_EVENT_METADATA_LEN) {
+		if (event->fd != FAN_NOFD)
+			SAFE_CLOSE(event->fd);
+		buflen -= (int)FAN_EVENT_METADATA_LEN;
+		event++;
+	}
+}
+
 void test_fanotify(unsigned int n)
 {
 	int ret;
@@ -198,17 +209,16 @@ void test_fanotify(unsigned int n)
 		} else {
 			verify_event(i, event);
 		}
-		if (event->fd != FAN_NOFD)
-			SAFE_CLOSE(event->fd);
+		close_events_fd(event, ret);
 	}
+
 	for (p = 1; p < FANOTIFY_PRIORITIES; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN);
 			if (ret > 0) {
 				tst_res(TFAIL, "group %d got event",
 					p*GROUPS_PER_PRIO + i);
-				if (event->fd != FAN_NOFD)
-					SAFE_CLOSE(event->fd);
+				close_events_fd((void *)event_buf, ret);
 			} else if (ret == 0) {
 				tst_brk(TBROK, "zero length "
 					"read from fanotify fd");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] fanotify06: Close all file descriptors of read events
  2019-06-04 15:10   ` [LTP] " Amir Goldstein
@ 2019-06-05  5:31     ` Petr Vorel
  -1 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2019-06-05  5:31 UTC (permalink / raw)
  To: Amir Goldstein
  Cc: Cyril Hrubis, Murphy Zhou, Jan Kara, Miklos Szeredi, linux-unionfs, ltp

Hi Amir,

thanks for your patchset, merged.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [LTP] [PATCH v2 2/2] fanotify06: Close all file descriptors of read events
@ 2019-06-05  5:31     ` Petr Vorel
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2019-06-05  5:31 UTC (permalink / raw)
  To: ltp

Hi Amir,

thanks for your patchset, merged.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-06-05  5:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-04 15:10 [PATCH v2 1/2] fanotify06: add a test case for overlayfs Amir Goldstein
2019-06-04 15:10 ` [LTP] " Amir Goldstein
2019-06-04 15:10 ` [PATCH v2 2/2] fanotify06: Close all file descriptors of read events Amir Goldstein
2019-06-04 15:10   ` [LTP] " Amir Goldstein
2019-06-05  5:31   ` Petr Vorel
2019-06-05  5:31     ` [LTP] " Petr Vorel

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.