public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: inotify regression, missing events
  2009-07-11 16:02 inotify regression, missing events Scott James Remnant
@ 2009-07-11 11:50 ` Eric Paris
  2009-07-13 12:21   ` Scott James Remnant
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Paris @ 2009-07-11 11:50 UTC (permalink / raw)
  To: Scott James Remnant; +Cc: linux-kernel

On Sat, 2009-07-11 at 17:02 +0100, Scott James Remnant wrote:
> Hey folks,
> 
> Looks like there's a regression with inotify since the rewrite to use
> fanotify.  Events are simply missing and not being delivered to
> userspace.
> 
> Here's a simple test case, just compile and run it:

I bet I know exactly what it is (notification.c tail merge code isn't
comparing filename only inode+mask) but I'm walking out of the house.
I'll try my theory later tonight and post a patch.

Stupid Eric, Stupid.

-Eric


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

* inotify regression, missing events
@ 2009-07-11 16:02 Scott James Remnant
  2009-07-11 11:50 ` Eric Paris
  0 siblings, 1 reply; 6+ messages in thread
From: Scott James Remnant @ 2009-07-11 16:02 UTC (permalink / raw)
  To: Eric Paris; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 6067 bytes --]

Hey folks,

Looks like there's a regression with inotify since the rewrite to use
fanotify.  Events are simply missing and not being delivered to
userspace.

Here's a simple test case, just compile and run it:

----8<--------8<--------8<--------8<--------8<--------8<--------8<----
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/inotify.h>

#include <stdio.h>
#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>


enum {
	WD		= 0x01,
	FOO		= 0x02,
	BAR		= 0x04,
	SUBDIR_WD	= 0x08,
	SUBDIR		= 0x10,
	SUBDIR_FOO	= 0x20,
	ALL		= 0x3f
};

int
main (int   argc,
      char *argv[])
{
	int     fd;
	char    dirname[PATH_MAX];
	char    filename[PATH_MAX];
	int     ret;
	FILE *  fp;
	int     wd;
	int     subdir_wd;
	char    buf[4096];
	int     expected;
	ssize_t len;
	size_t  sz;
	
	fd = inotify_init ();
	assert (fd >= 0);
	
	/* Create a temporary directory with two files and a sub-directory
	 * containing just one file.
	 */
	strcpy (dirname, "/tmp/inotify_test_XXXXXX");
	assert (mkdtemp (dirname));
	

	strcpy (filename, dirname);
	strcat (filename, "/subdir");
	
	ret = mkdir (filename, 0755);
	assert (ret == 0);
	

	strcpy (filename, dirname);
	strcat (filename, "/subdir/foo");
	
	fp = fopen (filename, "w");
	assert (fp);
	
	fprintf (fp, "file in a sub-directory\n");
	
	ret = fclose (fp);
	assert (ret == 0);


	strcpy (filename, dirname);
	strcat (filename, "/foo");
	
	fp = fopen (filename, "w");
	assert (fp);
	
	fprintf (fp, "this is a test\n");
	
	ret = fclose (fp);
	assert (ret == 0);
	

	strcpy (filename, dirname);
	strcat (filename, "/bar");
	
	fp = fopen (filename, "w");
	assert (fp);
	
	fprintf (fp, "this is another test\n");
	
	ret = fclose (fp);
	assert (ret == 0);

	
	/* Watch those directories for deletions */
	wd = inotify_add_watch (fd, dirname, IN_DELETE);
	assert (wd >= 0);

	strcpy (filename, dirname);
	strcat (filename, "/subdir");

	subdir_wd = inotify_add_watch (fd, filename, IN_DELETE);
	assert (wd >= 0);
	

	/* Clean up the directory */
	strcpy (filename, dirname);
	strcat (filename, "/subdir/foo");

	ret = unlink (filename);
	assert (ret == 0);

	strcpy (filename, dirname);
	strcat (filename, "/subdir");

	ret = rmdir (filename);
	assert (ret == 0);
	
	strcpy (filename, dirname);
	strcat (filename, "/bar");

	ret = unlink (filename);
	assert (ret == 0);

	strcpy (filename, dirname);
	strcat (filename, "/foo");

	ret = unlink (filename);
	assert (ret == 0);

	ret = rmdir (dirname);
	assert (ret == 0);
	
	
	/* Read the inotify events */
	expected = ALL;
	while (expected) {
		struct inotify_event *ev;
		ssize_t off;
		
		printf ("Waiting for:");
		if (expected & WD)
			printf (" wd");
		if (expected & FOO)
			printf (" foo");
		if (expected & BAR)
			printf (" bar");
		if (expected & SUBDIR_WD)
			printf (" subdir_wd");
		if (expected & SUBDIR)
			printf (" subdir");
		if (expected & SUBDIR_FOO)
			printf (" subdir/foo");
		printf ("\n");

		len = read (fd, buf, sizeof buf);
		assert (len > 0);
		
		off = 0;
		while (off < len) {
			ev = (struct inotify_event *)(buf + off);
			sz = sizeof (struct inotify_event) + ev->len;
			off += sz;

			/* Eliminate the silly */
			assert (! (ev->mask & IN_Q_OVERFLOW));
			assert (! (ev->mask & IN_UNMOUNT));
			
			/* Print the event for debugging */
			printf ("Got ");
			if (ev->mask & IN_DELETE)
				printf ("DELETE ");
			if (ev->mask & IN_IGNORED)
				printf ("IGNORED ");
			if (ev->mask & IN_ISDIR)
				printf ("ISDIR ");
			if (ev->len)
				printf ("\"%.*s\" ", ev->len, ev->name);
			printf ("(%d)\n", ev->wd);

			/* Expect the file in the sub-directory to go */			
			if ((ev->wd == subdir_wd)
			    && (ev->mask & IN_DELETE)
			    && (! (ev->mask & IN_ISDIR))
			    && (strncmp (ev->name, "foo", ev->len) == 0))
				expected &= ~SUBDIR_FOO;
			
			/* Expect the sub-directory to go */
			if ((ev->wd == wd)
			    && (ev->mask & IN_DELETE)
			    && (ev->mask & IN_ISDIR)
			    && (strncmp (ev->name, "subdir", ev->len) == 0))
				expected &= ~SUBDIR;
				
			/* Expect an IS_IGNORED for the sub-directory watch */
			if ((ev->wd == subdir_wd)
			    && (ev->mask & IN_IGNORED))
				expected &= ~SUBDIR_WD;
				
			/* Expect the first file in the directory to go */			
			if ((ev->wd == wd)
			    && (ev->mask & IN_DELETE)
			    && (! (ev->mask & IN_ISDIR))
			    && (strncmp (ev->name, "foo", ev->len) == 0))
				expected &= ~FOO;
			
			/* Expect the second file in the directory to go */			
			if ((ev->wd == wd)
			    && (ev->mask & IN_DELETE)
			    && (! (ev->mask & IN_ISDIR))
			    && (strncmp (ev->name, "bar", ev->len) == 0))
				expected &= ~BAR;

			/* And finally expect an IS_IGNORED for the directory */
			if ((ev->wd == wd)
			    && (ev->mask & IN_IGNORED))
				expected &= ~WD;
		}
	}	

	ret = close (fd);
	assert (ret == 0);
	
	printf ("\n");
	printf ("All good!\n");

	return 0;
}
---->8-------->8-------->8-------->8-------->8-------->8-------->8----

With 2.6.30, you see (as you'd expect) an inotify delete event for each
of the files and the sub-directory along with the IN_IGNORED for the
sub-directory and directory as the watch gets cleaned up by the kernel:


Waiting for: wd foo bar subdir_wd subdir subdir/foo
Got DELETE "foo" (2)
Got DELETE ISDIR "subdir" (1)
Got IGNORED (2)
Got DELETE "bar" (1)
Got DELETE "foo" (1)
Got IGNORED (1)

All good!


But with 2.6.31-rc2, the event for the "foo" file isn't delivered:

Waiting for: wd foo bar subdir_wd subdir subdir/foo
Got DELETE "foo" (2)
Got DELETE ISDIR "subdir" (1)
Got IGNORED (2)
Got DELETE "bar" (1)
Got IGNORED (1)
Waiting for: foo


This doesn't seem to be related to the removal of the parent directory,
without removing that we still hang waiting for the event for that file.

Scott
-- 
Scott James Remnant
scott@ubuntu.com

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: inotify regression, missing events
  2009-07-11 11:50 ` Eric Paris
@ 2009-07-13 12:21   ` Scott James Remnant
  2009-07-13 13:43     ` Eric Paris
  0 siblings, 1 reply; 6+ messages in thread
From: Scott James Remnant @ 2009-07-13 12:21 UTC (permalink / raw)
  To: Eric Paris; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 815 bytes --]

On Sat, 2009-07-11 at 07:50 -0400, Eric Paris wrote:

> On Sat, 2009-07-11 at 17:02 +0100, Scott James Remnant wrote:
> > Looks like there's a regression with inotify since the rewrite to use
> > fanotify.  Events are simply missing and not being delivered to
> > userspace.
> > 
> > Here's a simple test case, just compile and run it:
> 
> I bet I know exactly what it is (notification.c tail merge code isn't
> comparing filename only inode+mask) but I'm walking out of the house.
> I'll try my theory later tonight and post a patch.
> 
> Stupid Eric, Stupid.
> 
In other words, when the second deleted-file-in-a-directory event comes
through, it gets ignored because there's already a
"deleted-file-in-a-directory" event for that directory?

Scott
-- 
Scott James Remnant
scott@ubuntu.com

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: inotify regression, missing events
  2009-07-13 12:21   ` Scott James Remnant
@ 2009-07-13 13:43     ` Eric Paris
  2009-07-25 22:23       ` Rafael J. Wysocki
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Paris @ 2009-07-13 13:43 UTC (permalink / raw)
  To: Scott James Remnant; +Cc: linux-kernel

On Mon, 2009-07-13 at 13:21 +0100, Scott James Remnant wrote:
> On Sat, 2009-07-11 at 07:50 -0400, Eric Paris wrote:
> 
> > On Sat, 2009-07-11 at 17:02 +0100, Scott James Remnant wrote:
> > > Looks like there's a regression with inotify since the rewrite to use
> > > fanotify.  Events are simply missing and not being delivered to
> > > userspace.
> > > 
> > > Here's a simple test case, just compile and run it:
> > 
> > I bet I know exactly what it is (notification.c tail merge code isn't
> > comparing filename only inode+mask) but I'm walking out of the house.
> > I'll try my theory later tonight and post a patch.
> > 
> > Stupid Eric, Stupid.
> > 
> In other words, when the second deleted-file-in-a-directory event comes
> through, it gets ignored because there's already a
> "deleted-file-in-a-directory" event for that directory?

Yes, and I sent a patch but apparent screwed up the --smtp-server option
so it never got out.  Resending.  Sorry.....

-Eric


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

* Re: inotify regression, missing events
  2009-07-13 13:43     ` Eric Paris
@ 2009-07-25 22:23       ` Rafael J. Wysocki
  2009-07-25 22:27         ` Eric Paris
  0 siblings, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki @ 2009-07-25 22:23 UTC (permalink / raw)
  To: Eric Paris; +Cc: Scott James Remnant, linux-kernel

On Monday 13 July 2009, Eric Paris wrote:
> On Mon, 2009-07-13 at 13:21 +0100, Scott James Remnant wrote:
> > On Sat, 2009-07-11 at 07:50 -0400, Eric Paris wrote:
> > 
> > > On Sat, 2009-07-11 at 17:02 +0100, Scott James Remnant wrote:
> > > > Looks like there's a regression with inotify since the rewrite to use
> > > > fanotify.  Events are simply missing and not being delivered to
> > > > userspace.
> > > > 
> > > > Here's a simple test case, just compile and run it:
> > > 
> > > I bet I know exactly what it is (notification.c tail merge code isn't
> > > comparing filename only inode+mask) but I'm walking out of the house.
> > > I'll try my theory later tonight and post a patch.
> > > 
> > > Stupid Eric, Stupid.
> > > 
> > In other words, when the second deleted-file-in-a-directory event comes
> > through, it gets ignored because there's already a
> > "deleted-file-in-a-directory" event for that directory?
> 
> Yes, and I sent a patch but apparent screwed up the --smtp-server option
> so it never got out.  Resending.  Sorry.....

Did the patch reach Linus eventually?

Rafael

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

* Re: inotify regression, missing events
  2009-07-25 22:23       ` Rafael J. Wysocki
@ 2009-07-25 22:27         ` Eric Paris
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Paris @ 2009-07-25 22:27 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Scott James Remnant, linux-kernel

On Sun, 2009-07-26 at 00:23 +0200, Rafael J. Wysocki wrote:
> On Monday 13 July 2009, Eric Paris wrote:
> > On Mon, 2009-07-13 at 13:21 +0100, Scott James Remnant wrote:
> > > On Sat, 2009-07-11 at 07:50 -0400, Eric Paris wrote:
> > > 
> > > > On Sat, 2009-07-11 at 17:02 +0100, Scott James Remnant wrote:
> > > > > Looks like there's a regression with inotify since the rewrite to use
> > > > > fanotify.  Events are simply missing and not being delivered to
> > > > > userspace.
> > > > > 
> > > > > Here's a simple test case, just compile and run it:
> > > > 
> > > > I bet I know exactly what it is (notification.c tail merge code isn't
> > > > comparing filename only inode+mask) but I'm walking out of the house.
> > > > I'll try my theory later tonight and post a patch.
> > > > 
> > > > Stupid Eric, Stupid.
> > > > 
> > > In other words, when the second deleted-file-in-a-directory event comes
> > > through, it gets ignored because there's already a
> > > "deleted-file-in-a-directory" event for that directory?
> > 
> > Yes, and I sent a patch but apparent screwed up the --smtp-server option
> > so it never got out.  Resending.  Sorry.....
> 
> Did the patch reach Linus eventually?

No, I sent a git-pull but Linus did not pull from my tree before -rc4.
If he doesn't do it in his openning -rc5 salvo I'll send the request
again.

-Eric


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

end of thread, other threads:[~2009-07-25 22:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-11 16:02 inotify regression, missing events Scott James Remnant
2009-07-11 11:50 ` Eric Paris
2009-07-13 12:21   ` Scott James Remnant
2009-07-13 13:43     ` Eric Paris
2009-07-25 22:23       ` Rafael J. Wysocki
2009-07-25 22:27         ` Eric Paris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox