Skip to contentSkip to conversation

fs/notify/inotify: decrement user inotify count on close

PATCH In review Keith Packard 3 participants 4 messages Jul 2, 2009 – Jul 26, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/notify/inotify: decrement user inotify count on close

The per-user inotify_devs value is incremented each time a new file is allocated, but never decremented. This led to inotify_init failing after a limited number of calls.

---
 fs/notify/inotify/inotify_user.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
fs/notify/inotify/inotify_user.c +3 -0
index ff231ad..ff27a29 100644
@@ -296,12 +296,15 @@ static int inotify_fasync(int fd, struct file *file, int on)
 static int inotify_release(struct inode *ignored, struct file *file)
 {
 	struct fsnotify_group *group = file->private_data;
+	struct user_struct *user = group->inotify_data.user;
 
 	fsnotify_clear_marks_by_group(group);
 
 	/* free this group, matching get was inotify_init->fsnotify_obtain_group */
 	fsnotify_put_group(group);
 
+	atomic_dec(&user->inotify_devs);
+
 	return 0;
 }
 
Signature · 1 line
1.6.3.1
#1 lore raw
Quoted 5 lines · Keith Packard

The per-user inotify_devs value is incremented each time a new file is allocated, but never decremented. This led to inotify_init failing after a limited number of calls.

Thanks, I will push to Linus later today, sorry about the regression!

-Eric

#2 lore raw
Quoted 9 lines · Eric Paris
Quoted 5 lines · Keith Packard

The per-user inotify_devs value is incremented each time a new file is allocated, but never decremented. This led to inotify_init failing after a limited number of calls.

Thanks, I will push to Linus later today, sorry about the regression!

Hmm... Either the patch wasn't enough, or it was broken again. On v2.6.31-rc4, I get this:

  # echo 10 >/proc/sys/fs/inotify/max_user_watches
  # inotifywatch -r /usr/lib # generate watches up to the limit
  Establishing watches...
  Failed to watch /bin; upper limit on inotify watches reached!
  Please increase the amount of inotify watches allowed per user via
`/proc/sys/fs/inotify/max_user_watches'.
  # inotifywatch /bin/true # just one watch for just one file

AFAIU, the second inotifywatch should work, and the watches of the first, failed, run must be cleared.

#3 lore raw
Quoted 6 lines · Alex Riesen
Quoted 5 lines · Eric Paris
Quoted 4 lines · Keith Packard

The per-user inotify_devs value is incremented each time a new file is allocated, but never decremented. This led to inotify_init failing after a limited number of calls.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Thanks, I will push to Linus later today, sorry about the regression!

Hmm... Either the patch wasn't enough, or it was broken again.

The bug seem to be known since 2.6.28:

http://bugzilla.kernel.org/show_bug.cgi?id=12754