Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

inotify: do not reuse watch descriptors

Prior to 2.6.31 inotify would not reuse watch descriptors until all of
them had been used at least once. After the rewrite inotify would reuse
watch descriptors. The selinux utility 'restorecond' was found to have
problems when watch descriptors were reused. This patch reverts to the
pre inotify rewrite behavior to not reuse watch descriptors.

Signed-off-by: Eric Paris <eparis@redhat.com>

+6 -7
+6 -7
fs/notify/inotify/inotify_user.c
··· 358 358 } 359 359 360 360 static int inotify_add_to_idr(struct idr *idr, spinlock_t *idr_lock, 361 - int last_wd, 361 + int *last_wd, 362 362 struct inotify_inode_mark_entry *ientry) 363 363 { 364 364 int ret; ··· 368 368 return -ENOMEM; 369 369 370 370 spin_lock(idr_lock); 371 - ret = idr_get_new_above(idr, ientry, last_wd + 1, 371 + ret = idr_get_new_above(idr, ientry, *last_wd + 1, 372 372 &ientry->wd); 373 373 /* we added the mark to the idr, take a reference */ 374 - if (!ret) 374 + if (!ret) { 375 375 fsnotify_get_mark(&ientry->fsn_entry); 376 + *last_wd = ientry->wd; 377 + } 376 378 spin_unlock(idr_lock); 377 379 } while (ret == -EAGAIN); 378 380 ··· 649 647 if (atomic_read(&group->inotify_data.user->inotify_watches) >= inotify_max_user_watches) 650 648 goto out_err; 651 649 652 - ret = inotify_add_to_idr(idr, idr_lock, group->inotify_data.last_wd, 650 + ret = inotify_add_to_idr(idr, idr_lock, &group->inotify_data.last_wd, 653 651 tmp_ientry); 654 652 if (ret) 655 653 goto out_err; ··· 661 659 inotify_remove_from_idr(group, tmp_ientry); 662 660 goto out_err; 663 661 } 664 - 665 - /* update the idr hint, who cares about races, it's just a hint */ 666 - group->inotify_data.last_wd = tmp_ientry->wd; 667 662 668 663 /* increment the number of watches the user has */ 669 664 atomic_inc(&group->inotify_data.user->inotify_watches);