mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-04 16:15:11 +00:00
inotify: convert to idr_alloc()
Convert to the much saner new idr interface. Note that the adhoc cyclic id allocation is buggy. If wraparound happens, the previous code with idr_get_new_above() may segfault and the converted code will trigger WARN and return -EINVAL. Even if it's fixed to wrap to zero, the code will be prone to unnecessary -ENOSPC failures after the first wraparound. We probably need to implement proper cyclic support in idr. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: John McCutchan <john@johnmccutchan.com> Cc: Robert Love <rlove@rlove.org> Cc: Eric Paris <eparis@parisplace.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
2a86b3e74f
commit
4542da631a
1 changed files with 11 additions and 13 deletions
|
@ -364,22 +364,20 @@ static int inotify_add_to_idr(struct idr *idr, spinlock_t *idr_lock,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
do {
|
idr_preload(GFP_KERNEL);
|
||||||
if (unlikely(!idr_pre_get(idr, GFP_KERNEL)))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
spin_lock(idr_lock);
|
spin_lock(idr_lock);
|
||||||
ret = idr_get_new_above(idr, i_mark, *last_wd + 1,
|
|
||||||
&i_mark->wd);
|
ret = idr_alloc(idr, i_mark, *last_wd + 1, 0, GFP_NOWAIT);
|
||||||
|
if (ret >= 0) {
|
||||||
/* we added the mark to the idr, take a reference */
|
/* we added the mark to the idr, take a reference */
|
||||||
if (!ret) {
|
i_mark->wd = ret;
|
||||||
*last_wd = i_mark->wd;
|
*last_wd = i_mark->wd;
|
||||||
fsnotify_get_mark(&i_mark->fsn_mark);
|
fsnotify_get_mark(&i_mark->fsn_mark);
|
||||||
}
|
}
|
||||||
spin_unlock(idr_lock);
|
|
||||||
} while (ret == -EAGAIN);
|
|
||||||
|
|
||||||
return ret;
|
spin_unlock(idr_lock);
|
||||||
|
idr_preload_end();
|
||||||
|
return ret < 0 ? ret : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct inotify_inode_mark *inotify_idr_find_locked(struct fsnotify_group *group,
|
static struct inotify_inode_mark *inotify_idr_find_locked(struct fsnotify_group *group,
|
||||||
|
|
Loading…
Reference in a new issue