Re: [PATCH 3/3] fanotify: fix inconsistent behaviour regarding flag FAN_ONDIR

From: Lino Sanfilippo
Date: Mon Dec 01 2014 - 21:03:54 EST


On 01.12.2014 11:05, Jan Kara wrote:
> On Sun 30-11-14 00:37:38, Lino Sanfilippo wrote:
>> Before flag FAN_ONDIR was implicitly set in a marks ignored mask. This led to
>> some inconsistent behaviour:
>> 1. It was not possible to remove the flag from the ignored mask, once it was set
>> (implicitly) with a call like
>> fanotify_mark(fd, FAN_MARK_ADD, FAN_OPEN, AT_FDCWD, "dir");
>> This was since the needed flag FAN_MARK_ONDIR was only honored when setting a
>> marks mask, but not when removing it. Now FAN_ONDIR is only set when explicitly
>> passed in the masks parameter. It now is also possible to remove it again:
>> fanotify_mark(fd, FAN_MARK_ADD, FAN_OPEN | FAN_ONDIR , AT_FDCWD, "dir");
>> fanotify_mark(fd, FAN_MARK_REMOVE, FAN_ONDIR , AT_FDCWD, "dir");
>> 2. Subsequent calls to fanotify_mark for a mark that had FAN_ONDIR already set
>> in its mask removed the flag, if it was not specified in the mask parameter
>> again. Thus
>> fanotify_mark(fd, FAN_MARK_ADD, FAN_OPEN | FAN_ONDIR , AT_FDCWD, "dir");
>> fanotify_mark(fd, FAN_MARK_ADD, FAN_CLOSE, AT_FDCWD, "dir");
>> set FAN_ONDIR in the first call on the marks mask but also on the ignored
>> mask in the second call. So the first request for DIR events was overwritten.
>> Since the flag is now not set implicitly any longer this cant happen any more.
> Ugh, I have to say I don't understand the changelog. From the code I
> think I understood that instead of always adding FAN_ONDIR to ignore mask
> you require FAN_ONDIR to be set in the normal mask. That makes sense to me
> but please make the changelog more comprehensible.

Hm. My intention was to describe at least two cases of strange behaviour
when setting the FAN_ONDIR flag. But maybe the description has indeed
become a little bit too complicated. I will adjust that and resend the

Also please add a
> testcase to LTP fanotify() coverage for FAN_ONDIR behavior so that we can
> easily see how userspace visible behavior changed / didn't change. Thanks!

Ok, i can do that (it may take a few days until i find the time for it
though). Thank you for review!

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at