···99 int wd;1010};11111212-struct inotify_inode_mark_entry {1313- /* fsnotify_mark MUST be the first thing */1414- struct fsnotify_mark fsn_entry;1212+struct inotify_inode_mark {1313+ struct fsnotify_mark fsn_mark;1514 int wd;1615};17161818-extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *entry,1717+extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,1918 struct fsnotify_group *group);2019extern void inotify_free_event_priv(struct fsnotify_event_private_data *event_priv);2120
+24-24
fs/notify/inotify/inotify_fsnotify.c
···88888989static int inotify_handle_event(struct fsnotify_group *group, struct fsnotify_event *event)9090{9191- struct fsnotify_mark *entry;9292- struct inotify_inode_mark_entry *ientry;9191+ struct fsnotify_mark *fsn_mark;9292+ struct inotify_inode_mark *i_mark;9393 struct inode *to_tell;9494 struct inotify_event_private_data *event_priv;9595 struct fsnotify_event_private_data *fsn_event_priv;···9898 to_tell = event->to_tell;9999100100 spin_lock(&to_tell->i_lock);101101- entry = fsnotify_find_mark(group, to_tell);101101+ fsn_mark = fsnotify_find_mark(group, to_tell);102102 spin_unlock(&to_tell->i_lock);103103 /* race with watch removal? We already passes should_send */104104- if (unlikely(!entry))104104+ if (unlikely(!fsn_mark))105105 return 0;106106- ientry = container_of(entry, struct inotify_inode_mark_entry,107107- fsn_entry);108108- wd = ientry->wd;106106+ i_mark = container_of(fsn_mark, struct inotify_inode_mark,107107+ fsn_mark);108108+ wd = i_mark->wd;109109110110 event_priv = kmem_cache_alloc(event_priv_cachep, GFP_KERNEL);111111 if (unlikely(!event_priv))···127127 }128128129129 /*130130- * If we hold the entry until after the event is on the queue130130+ * If we hold the fsn_mark until after the event is on the queue131131 * IN_IGNORED won't be able to pass this event in the queue132132 */133133- fsnotify_put_mark(entry);133133+ fsnotify_put_mark(fsn_mark);134134135135 return ret;136136}137137138138-static void inotify_freeing_mark(struct fsnotify_mark *entry, struct fsnotify_group *group)138138+static void inotify_freeing_mark(struct fsnotify_mark *fsn_mark, struct fsnotify_group *group)139139{140140- inotify_ignored_and_remove_idr(entry, group);140140+ inotify_ignored_and_remove_idr(fsn_mark, group);141141}142142143143static bool inotify_should_send_event(struct fsnotify_group *group, struct inode *inode,144144 struct vfsmount *mnt, __u32 mask, void *data,145145 int data_type)146146{147147- struct fsnotify_mark *entry;147147+ struct fsnotify_mark *fsn_mark;148148 bool send;149149150150 spin_lock(&inode->i_lock);151151- entry = fsnotify_find_mark(group, inode);151151+ fsn_mark = fsnotify_find_mark(group, inode);152152 spin_unlock(&inode->i_lock);153153- if (!entry)153153+ if (!fsn_mark)154154 return false;155155156156 mask = (mask & ~FS_EVENT_ON_CHILD);157157- send = (entry->mask & mask);157157+ send = (fsn_mark->mask & mask);158158159159 /* find took a reference */160160- fsnotify_put_mark(entry);160160+ fsnotify_put_mark(fsn_mark);161161162162 return send;163163}···171171 */172172static int idr_callback(int id, void *p, void *data)173173{174174- struct fsnotify_mark *entry;175175- struct inotify_inode_mark_entry *ientry;174174+ struct fsnotify_mark *fsn_mark;175175+ struct inotify_inode_mark *i_mark;176176 static bool warned = false;177177178178 if (warned)179179 return 0;180180181181 warned = true;182182- entry = p;183183- ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);182182+ fsn_mark = p;183183+ i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);184184185185- WARN(1, "inotify closing but id=%d for entry=%p in group=%p still in "185185+ WARN(1, "inotify closing but id=%d for fsn_mark=%p in group=%p still in "186186 "idr. Probably leaking memory\n", id, p, data);187187188188 /*···191191 * out why we got here and the panic is no worse than the original192192 * BUG() that was here.193193 */194194- if (entry)195195- printk(KERN_WARNING "entry->group=%p inode=%p wd=%d\n",196196- entry->group, entry->i.inode, ientry->wd);194194+ if (fsn_mark)195195+ printk(KERN_WARNING "fsn_mark->group=%p inode=%p wd=%d\n",196196+ fsn_mark->group, fsn_mark->i.inode, i_mark->wd);197197 return 0;198198}199199
+96-96
fs/notify/inotify/inotify_user.c
···353353354354static int inotify_add_to_idr(struct idr *idr, spinlock_t *idr_lock,355355 int *last_wd,356356- struct inotify_inode_mark_entry *ientry)356356+ struct inotify_inode_mark *i_mark)357357{358358 int ret;359359···362362 return -ENOMEM;363363364364 spin_lock(idr_lock);365365- ret = idr_get_new_above(idr, ientry, *last_wd + 1,366366- &ientry->wd);365365+ ret = idr_get_new_above(idr, i_mark, *last_wd + 1,366366+ &i_mark->wd);367367 /* we added the mark to the idr, take a reference */368368 if (!ret) {369369- fsnotify_get_mark(&ientry->fsn_entry);370370- *last_wd = ientry->wd;369369+ *last_wd = i_mark->wd;370370+ fsnotify_get_mark(&i_mark->fsn_mark);371371 }372372 spin_unlock(idr_lock);373373 } while (ret == -EAGAIN);···375375 return ret;376376}377377378378-static struct inotify_inode_mark_entry *inotify_idr_find_locked(struct fsnotify_group *group,378378+static struct inotify_inode_mark *inotify_idr_find_locked(struct fsnotify_group *group,379379 int wd)380380{381381 struct idr *idr = &group->inotify_data.idr;382382 spinlock_t *idr_lock = &group->inotify_data.idr_lock;383383- struct inotify_inode_mark_entry *ientry;383383+ struct inotify_inode_mark *i_mark;384384385385 assert_spin_locked(idr_lock);386386387387- ientry = idr_find(idr, wd);388388- if (ientry) {389389- struct fsnotify_mark *fsn_entry = &ientry->fsn_entry;387387+ i_mark = idr_find(idr, wd);388388+ if (i_mark) {389389+ struct fsnotify_mark *fsn_mark = &i_mark->fsn_mark;390390391391- fsnotify_get_mark(fsn_entry);391391+ fsnotify_get_mark(fsn_mark);392392 /* One ref for being in the idr, one ref we just took */393393- BUG_ON(atomic_read(&fsn_entry->refcnt) < 2);393393+ BUG_ON(atomic_read(&fsn_mark->refcnt) < 2);394394 }395395396396- return ientry;396396+ return i_mark;397397}398398399399-static struct inotify_inode_mark_entry *inotify_idr_find(struct fsnotify_group *group,399399+static struct inotify_inode_mark *inotify_idr_find(struct fsnotify_group *group,400400 int wd)401401{402402- struct inotify_inode_mark_entry *ientry;402402+ struct inotify_inode_mark *i_mark;403403 spinlock_t *idr_lock = &group->inotify_data.idr_lock;404404405405 spin_lock(idr_lock);406406- ientry = inotify_idr_find_locked(group, wd);406406+ i_mark = inotify_idr_find_locked(group, wd);407407 spin_unlock(idr_lock);408408409409- return ientry;409409+ return i_mark;410410}411411412412static void do_inotify_remove_from_idr(struct fsnotify_group *group,413413- struct inotify_inode_mark_entry *ientry)413413+ struct inotify_inode_mark *i_mark)414414{415415 struct idr *idr = &group->inotify_data.idr;416416 spinlock_t *idr_lock = &group->inotify_data.idr_lock;417417- int wd = ientry->wd;417417+ int wd = i_mark->wd;418418419419 assert_spin_locked(idr_lock);420420421421 idr_remove(idr, wd);422422423423 /* removed from the idr, drop that ref */424424- fsnotify_put_mark(&ientry->fsn_entry);424424+ fsnotify_put_mark(&i_mark->fsn_mark);425425}426426427427/*···429429 * on the mark because it was in the idr.430430 */431431static void inotify_remove_from_idr(struct fsnotify_group *group,432432- struct inotify_inode_mark_entry *ientry)432432+ struct inotify_inode_mark *i_mark)433433{434434 spinlock_t *idr_lock = &group->inotify_data.idr_lock;435435- struct inotify_inode_mark_entry *found_ientry = NULL;435435+ struct inotify_inode_mark *found_i_mark = NULL;436436 int wd;437437438438 spin_lock(idr_lock);439439- wd = ientry->wd;439439+ wd = i_mark->wd;440440441441 /*442442- * does this ientry think it is in the idr? we shouldn't get called442442+ * does this i_mark think it is in the idr? we shouldn't get called443443 * if it wasn't....444444 */445445 if (wd == -1) {446446- WARN_ONCE(1, "%s: ientry=%p ientry->wd=%d ientry->group=%p"447447- " ientry->inode=%p\n", __func__, ientry, ientry->wd,448448- ientry->fsn_entry.group, ientry->fsn_entry.i.inode);446446+ WARN_ONCE(1, "%s: i_mark=%p i_mark->wd=%d i_mark->group=%p"447447+ " i_mark->inode=%p\n", __func__, i_mark, i_mark->wd,448448+ i_mark->fsn_mark.group, i_mark->fsn_mark.i.inode);449449 goto out;450450 }451451452452 /* Lets look in the idr to see if we find it */453453- found_ientry = inotify_idr_find_locked(group, wd);454454- if (unlikely(!found_ientry)) {455455- WARN_ONCE(1, "%s: ientry=%p ientry->wd=%d ientry->group=%p"456456- " ientry->inode=%p\n", __func__, ientry, ientry->wd,457457- ientry->fsn_entry.group, ientry->fsn_entry.i.inode);453453+ found_i_mark = inotify_idr_find_locked(group, wd);454454+ if (unlikely(!found_i_mark)) {455455+ WARN_ONCE(1, "%s: i_mark=%p i_mark->wd=%d i_mark->group=%p"456456+ " i_mark->inode=%p\n", __func__, i_mark, i_mark->wd,457457+ i_mark->fsn_mark.group, i_mark->fsn_mark.i.inode);458458 goto out;459459 }460460461461 /*462462- * We found an entry in the idr at the right wd, but it's463463- * not the entry we were told to remove. eparis seriously462462+ * We found an mark in the idr at the right wd, but it's463463+ * not the mark we were told to remove. eparis seriously464464 * fucked up somewhere.465465 */466466- if (unlikely(found_ientry != ientry)) {467467- WARN_ONCE(1, "%s: ientry=%p ientry->wd=%d ientry->group=%p "468468- "entry->inode=%p found_ientry=%p found_ientry->wd=%d "469469- "found_ientry->group=%p found_ientry->inode=%p\n",470470- __func__, ientry, ientry->wd, ientry->fsn_entry.group,471471- ientry->fsn_entry.i.inode, found_ientry, found_ientry->wd,472472- found_ientry->fsn_entry.group,473473- found_ientry->fsn_entry.i.inode);466466+ if (unlikely(found_i_mark != i_mark)) {467467+ WARN_ONCE(1, "%s: i_mark=%p i_mark->wd=%d i_mark->group=%p "468468+ "mark->inode=%p found_i_mark=%p found_i_mark->wd=%d "469469+ "found_i_mark->group=%p found_i_mark->inode=%p\n",470470+ __func__, i_mark, i_mark->wd, i_mark->fsn_mark.group,471471+ i_mark->fsn_mark.i.inode, found_i_mark, found_i_mark->wd,472472+ found_i_mark->fsn_mark.group,473473+ found_i_mark->fsn_mark.i.inode);474474 goto out;475475 }476476···479479 * one ref held by the caller trying to kill us480480 * one ref grabbed by inotify_idr_find481481 */482482- if (unlikely(atomic_read(&ientry->fsn_entry.refcnt) < 3)) {483483- printk(KERN_ERR "%s: ientry=%p ientry->wd=%d ientry->group=%p"484484- " ientry->inode=%p\n", __func__, ientry, ientry->wd,485485- ientry->fsn_entry.group, ientry->fsn_entry.i.inode);482482+ if (unlikely(atomic_read(&i_mark->fsn_mark.refcnt) < 3)) {483483+ printk(KERN_ERR "%s: i_mark=%p i_mark->wd=%d i_mark->group=%p"484484+ " i_mark->inode=%p\n", __func__, i_mark, i_mark->wd,485485+ i_mark->fsn_mark.group, i_mark->fsn_mark.i.inode);486486 /* we can't really recover with bad ref cnting.. */487487 BUG();488488 }489489490490- do_inotify_remove_from_idr(group, ientry);490490+ do_inotify_remove_from_idr(group, i_mark);491491out:492492 /* match the ref taken by inotify_idr_find_locked() */493493- if (found_ientry)494494- fsnotify_put_mark(&found_ientry->fsn_entry);495495- ientry->wd = -1;493493+ if (found_i_mark)494494+ fsnotify_put_mark(&found_i_mark->fsn_mark);495495+ i_mark->wd = -1;496496 spin_unlock(idr_lock);497497}498498499499/*500500 * Send IN_IGNORED for this wd, remove this wd from the idr.501501 */502502-void inotify_ignored_and_remove_idr(struct fsnotify_mark *entry,502502+void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,503503 struct fsnotify_group *group)504504{505505- struct inotify_inode_mark_entry *ientry;505505+ struct inotify_inode_mark *i_mark;506506 struct fsnotify_event *ignored_event;507507 struct inotify_event_private_data *event_priv;508508 struct fsnotify_event_private_data *fsn_event_priv;···514514 if (!ignored_event)515515 return;516516517517- ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);517517+ i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);518518519519 event_priv = kmem_cache_alloc(event_priv_cachep, GFP_NOFS);520520 if (unlikely(!event_priv))···523523 fsn_event_priv = &event_priv->fsnotify_event_priv_data;524524525525 fsn_event_priv->group = group;526526- event_priv->wd = ientry->wd;526526+ event_priv->wd = i_mark->wd;527527528528 ret = fsnotify_add_notify_event(group, ignored_event, fsn_event_priv, NULL);529529 if (ret)···534534 /* matches the reference taken when the event was created */535535 fsnotify_put_event(ignored_event);536536537537- /* remove this entry from the idr */538538- inotify_remove_from_idr(group, ientry);537537+ /* remove this mark from the idr */538538+ inotify_remove_from_idr(group, i_mark);539539540540 atomic_dec(&group->inotify_data.user->inotify_watches);541541}542542543543/* ding dong the mark is dead */544544-static void inotify_free_mark(struct fsnotify_mark *entry)544544+static void inotify_free_mark(struct fsnotify_mark *fsn_mark)545545{546546- struct inotify_inode_mark_entry *ientry;546546+ struct inotify_inode_mark *i_mark;547547548548- ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);548548+ i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);549549550550- kmem_cache_free(inotify_inode_mark_cachep, ientry);550550+ kmem_cache_free(inotify_inode_mark_cachep, i_mark);551551}552552553553static int inotify_update_existing_watch(struct fsnotify_group *group,554554 struct inode *inode,555555 u32 arg)556556{557557- struct fsnotify_mark *entry;558558- struct inotify_inode_mark_entry *ientry;557557+ struct fsnotify_mark *fsn_mark;558558+ struct inotify_inode_mark *i_mark;559559 __u32 old_mask, new_mask;560560 __u32 mask;561561 int add = (arg & IN_MASK_ADD);···567567 return -EINVAL;568568569569 spin_lock(&inode->i_lock);570570- entry = fsnotify_find_mark(group, inode);570570+ fsn_mark = fsnotify_find_mark(group, inode);571571 spin_unlock(&inode->i_lock);572572- if (!entry)572572+ if (!fsn_mark)573573 return -ENOENT;574574575575- ientry = container_of(entry, struct inotify_inode_mark_entry, fsn_entry);575575+ i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);576576577577- spin_lock(&entry->lock);577577+ spin_lock(&fsn_mark->lock);578578579579- old_mask = entry->mask;579579+ old_mask = fsn_mark->mask;580580 if (add) {581581- entry->mask |= mask;582582- new_mask = entry->mask;581581+ fsn_mark->mask |= mask;582582+ new_mask = fsn_mark->mask;583583 } else {584584- entry->mask = mask;585585- new_mask = entry->mask;584584+ fsn_mark->mask = mask;585585+ new_mask = fsn_mark->mask;586586 }587587588588- spin_unlock(&entry->lock);588588+ spin_unlock(&fsn_mark->lock);589589590590 if (old_mask != new_mask) {591591 /* more bits in old than in new? */592592 int dropped = (old_mask & ~new_mask);593593- /* more bits in this entry than the inode's mask? */593593+ /* more bits in this fsn_mark than the inode's mask? */594594 int do_inode = (new_mask & ~inode->i_fsnotify_mask);595595- /* more bits in this entry than the group? */595595+ /* more bits in this fsn_mark than the group? */596596 int do_group = (new_mask & ~group->mask);597597598598- /* update the inode with this new entry */598598+ /* update the inode with this new fsn_mark */599599 if (dropped || do_inode)600600 fsnotify_recalc_inode_mask(inode);601601···605605 }606606607607 /* return the wd */608608- ret = ientry->wd;608608+ ret = i_mark->wd;609609610610 /* match the get from fsnotify_find_mark() */611611- fsnotify_put_mark(entry);611611+ fsnotify_put_mark(fsn_mark);612612613613 return ret;614614}···617617 struct inode *inode,618618 u32 arg)619619{620620- struct inotify_inode_mark_entry *tmp_ientry;620620+ struct inotify_inode_mark *tmp_i_mark;621621 __u32 mask;622622 int ret;623623 struct idr *idr = &group->inotify_data.idr;···628628 if (unlikely(!mask))629629 return -EINVAL;630630631631- tmp_ientry = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);632632- if (unlikely(!tmp_ientry))631631+ tmp_i_mark = kmem_cache_alloc(inotify_inode_mark_cachep, GFP_KERNEL);632632+ if (unlikely(!tmp_i_mark))633633 return -ENOMEM;634634635635- fsnotify_init_mark(&tmp_ientry->fsn_entry, inotify_free_mark);636636- tmp_ientry->fsn_entry.mask = mask;637637- tmp_ientry->wd = -1;635635+ fsnotify_init_mark(&tmp_i_mark->fsn_mark, inotify_free_mark);636636+ tmp_i_mark->fsn_mark.mask = mask;637637+ tmp_i_mark->wd = -1;638638639639 ret = -ENOSPC;640640 if (atomic_read(&group->inotify_data.user->inotify_watches) >= inotify_max_user_watches)641641 goto out_err;642642643643 ret = inotify_add_to_idr(idr, idr_lock, &group->inotify_data.last_wd,644644- tmp_ientry);644644+ tmp_i_mark);645645 if (ret)646646 goto out_err;647647648648 /* we are on the idr, now get on the inode */649649- ret = fsnotify_add_mark(&tmp_ientry->fsn_entry, group, inode, 0);649649+ ret = fsnotify_add_mark(&tmp_i_mark->fsn_mark, group, inode, 0);650650 if (ret) {651651 /* we failed to get on the inode, get off the idr */652652- inotify_remove_from_idr(group, tmp_ientry);652652+ inotify_remove_from_idr(group, tmp_i_mark);653653 goto out_err;654654 }655655656656 /* increment the number of watches the user has */657657 atomic_inc(&group->inotify_data.user->inotify_watches);658658659659- /* return the watch descriptor for this new entry */660660- ret = tmp_ientry->wd;659659+ /* return the watch descriptor for this new mark */660660+ ret = tmp_i_mark->wd;661661662662 /* if this mark added a new event update the group mask */663663 if (mask & ~group->mask)664664 fsnotify_recalc_group_mask(group);665665666666out_err:667667- /* match the ref from fsnotify_init_markentry() */668668- fsnotify_put_mark(&tmp_ientry->fsn_entry);667667+ /* match the ref from fsnotify_init_mark() */668668+ fsnotify_put_mark(&tmp_i_mark->fsn_mark);669669670670 return ret;671671}···801801SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)802802{803803 struct fsnotify_group *group;804804- struct inotify_inode_mark_entry *ientry;804804+ struct inotify_inode_mark *i_mark;805805 struct file *filp;806806 int ret = 0, fput_needed;807807···817817 group = filp->private_data;818818819819 ret = -EINVAL;820820- ientry = inotify_idr_find(group, wd);821821- if (unlikely(!ientry))820820+ i_mark = inotify_idr_find(group, wd);821821+ if (unlikely(!i_mark))822822 goto out;823823824824 ret = 0;825825826826- fsnotify_destroy_mark(&ientry->fsn_entry);826826+ fsnotify_destroy_mark(&i_mark->fsn_mark);827827828828 /* match ref taken by inotify_idr_find */829829- fsnotify_put_mark(&ientry->fsn_entry);829829+ fsnotify_put_mark(&i_mark->fsn_mark);830830831831out:832832 fput_light(filp, fput_needed);···840840 */841841static int __init inotify_user_setup(void)842842{843843- inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark_entry, SLAB_PANIC);843843+ inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC);844844 event_priv_cachep = KMEM_CACHE(inotify_event_private_data, SLAB_PANIC);845845846846 inotify_max_queued_events = 16384;