Skip to content

Commit 2823e04

Browse files
committed
fsnotify: put inode specific fields in an fsnotify_mark in a union
The addition of marks on vfs mounts will be simplified if the inode specific parts of a mark and the vfsmnt specific parts of a mark are actually in a union so naming can be easy. This patch just implements the inode struct and the union. Signed-off-by: Eric Paris <eparis@redhat.com>
1 parent 3a9fb89 commit 2823e04

6 files changed

Lines changed: 43 additions & 34 deletions

File tree

‎fs/notify/dnotify/dnotify.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ static void dnotify_recalc_inode_mask(struct fsnotify_mark_entry *entry)
7070
if (old_mask == new_mask)
7171
return;
7272

73-
if (entry->inode)
74-
fsnotify_recalc_inode_mask(entry->inode);
73+
if (entry->i.inode)
74+
fsnotify_recalc_inode_mask(entry->i.inode);
7575
}
7676

7777
/*

‎fs/notify/inode_mark.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static void fsnotify_recalc_inode_mask_locked(struct inode *inode)
117117

118118
assert_spin_locked(&inode->i_lock);
119119

120-
hlist_for_each_entry(entry, pos, &inode->i_fsnotify_mark_entries, i_list)
120+
hlist_for_each_entry(entry, pos, &inode->i_fsnotify_mark_entries, i.i_list)
121121
new_mask |= entry->mask;
122122
inode->i_fsnotify_mask = new_mask;
123123
}
@@ -148,7 +148,7 @@ void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry)
148148
spin_lock(&entry->lock);
149149

150150
group = entry->group;
151-
inode = entry->inode;
151+
inode = entry->i.inode;
152152

153153
BUG_ON(group && !inode);
154154
BUG_ON(!group && inode);
@@ -165,8 +165,8 @@ void fsnotify_destroy_mark_by_entry(struct fsnotify_mark_entry *entry)
165165
spin_lock(&group->mark_lock);
166166
spin_lock(&inode->i_lock);
167167

168-
hlist_del_init(&entry->i_list);
169-
entry->inode = NULL;
168+
hlist_del_init(&entry->i.i_list);
169+
entry->i.inode = NULL;
170170

171171
list_del_init(&entry->g_list);
172172
entry->group = NULL;
@@ -248,14 +248,14 @@ void fsnotify_clear_marks_by_inode(struct inode *inode)
248248
LIST_HEAD(free_list);
249249

250250
spin_lock(&inode->i_lock);
251-
hlist_for_each_entry_safe(entry, pos, n, &inode->i_fsnotify_mark_entries, i_list) {
252-
list_add(&entry->free_i_list, &free_list);
253-
hlist_del_init(&entry->i_list);
251+
hlist_for_each_entry_safe(entry, pos, n, &inode->i_fsnotify_mark_entries, i.i_list) {
252+
list_add(&entry->i.free_i_list, &free_list);
253+
hlist_del_init(&entry->i.i_list);
254254
fsnotify_get_mark(entry);
255255
}
256256
spin_unlock(&inode->i_lock);
257257

258-
list_for_each_entry_safe(entry, lentry, &free_list, free_i_list) {
258+
list_for_each_entry_safe(entry, lentry, &free_list, i.free_i_list) {
259259
fsnotify_destroy_mark_by_entry(entry);
260260
fsnotify_put_mark(entry);
261261
}
@@ -273,7 +273,7 @@ struct fsnotify_mark_entry *fsnotify_find_mark_entry(struct fsnotify_group *grou
273273

274274
assert_spin_locked(&inode->i_lock);
275275

276-
hlist_for_each_entry(entry, pos, &inode->i_fsnotify_mark_entries, i_list) {
276+
hlist_for_each_entry(entry, pos, &inode->i_fsnotify_mark_entries, i.i_list) {
277277
if (entry->group == group) {
278278
fsnotify_get_mark(entry);
279279
return entry;
@@ -285,7 +285,7 @@ struct fsnotify_mark_entry *fsnotify_find_mark_entry(struct fsnotify_group *grou
285285
void fsnotify_duplicate_mark(struct fsnotify_mark_entry *new, struct fsnotify_mark_entry *old)
286286
{
287287
assert_spin_locked(&old->lock);
288-
new->inode = old->inode;
288+
new->i.inode = old->i.inode;
289289
new->group = old->group;
290290
new->mask = old->mask;
291291
new->free_mark = old->free_mark;
@@ -299,10 +299,10 @@ void fsnotify_init_mark(struct fsnotify_mark_entry *entry,
299299
{
300300
spin_lock_init(&entry->lock);
301301
atomic_set(&entry->refcnt, 1);
302-
INIT_HLIST_NODE(&entry->i_list);
302+
INIT_HLIST_NODE(&entry->i.i_list);
303303
entry->group = NULL;
304304
entry->mask = 0;
305-
entry->inode = NULL;
305+
entry->i.inode = NULL;
306306
entry->free_mark = free_mark;
307307
}
308308

@@ -350,9 +350,9 @@ int fsnotify_add_mark(struct fsnotify_mark_entry *entry,
350350
lentry = fsnotify_find_mark_entry(group, inode);
351351
if (!lentry) {
352352
entry->group = group;
353-
entry->inode = inode;
353+
entry->i.inode = inode;
354354

355-
hlist_add_head(&entry->i_list, &inode->i_fsnotify_mark_entries);
355+
hlist_add_head(&entry->i.i_list, &inode->i_fsnotify_mark_entries);
356356
list_add(&entry->g_list, &group->mark_entries);
357357

358358
fsnotify_get_mark(entry); /* for i_list and g_list */

‎fs/notify/inotify/inotify_fsnotify.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int idr_callback(int id, void *p, void *data)
193193
*/
194194
if (entry)
195195
printk(KERN_WARNING "entry->group=%p inode=%p wd=%d\n",
196-
entry->group, entry->inode, ientry->wd);
196+
entry->group, entry->i.inode, ientry->wd);
197197
return 0;
198198
}
199199

‎fs/notify/inotify/inotify_user.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static void inotify_remove_from_idr(struct fsnotify_group *group,
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,
448-
ientry->fsn_entry.group, ientry->fsn_entry.inode);
448+
ientry->fsn_entry.group, ientry->fsn_entry.i.inode);
449449
goto out;
450450
}
451451

@@ -454,7 +454,7 @@ static void inotify_remove_from_idr(struct fsnotify_group *group,
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,
457-
ientry->fsn_entry.group, ientry->fsn_entry.inode);
457+
ientry->fsn_entry.group, ientry->fsn_entry.i.inode);
458458
goto out;
459459
}
460460

@@ -468,9 +468,9 @@ static void inotify_remove_from_idr(struct fsnotify_group *group,
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,
471-
ientry->fsn_entry.inode, found_ientry, found_ientry->wd,
471+
ientry->fsn_entry.i.inode, found_ientry, found_ientry->wd,
472472
found_ientry->fsn_entry.group,
473-
found_ientry->fsn_entry.inode);
473+
found_ientry->fsn_entry.i.inode);
474474
goto out;
475475
}
476476

@@ -482,7 +482,7 @@ static void inotify_remove_from_idr(struct fsnotify_group *group,
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,
485-
ientry->fsn_entry.group, ientry->fsn_entry.inode);
485+
ientry->fsn_entry.group, ientry->fsn_entry.i.inode);
486486
/* we can't really recover with bad ref cnting.. */
487487
BUG();
488488
}

‎include/linux/fsnotify_backend.h‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ struct fsnotify_event {
226226
struct list_head private_data_list; /* groups can store private data here */
227227
};
228228

229+
/*
230+
* Inode specific fields in an fsnotify_mark_entry
231+
*/
232+
struct fsnotify_inode_mark {
233+
struct inode *inode; /* inode this entry is associated with */
234+
struct hlist_node i_list; /* list of mark_entries by inode->i_fsnotify_mark_entries */
235+
struct list_head free_i_list; /* tmp list used when freeing this mark */
236+
};
237+
229238
/*
230239
* a mark is simply an entry attached to an in core inode which allows an
231240
* fsnotify listener to indicate they are either no longer interested in events
@@ -241,12 +250,12 @@ struct fsnotify_mark_entry {
241250
/* we hold ref for each i_list and g_list. also one ref for each 'thing'
242251
* in kernel that found and may be using this mark. */
243252
atomic_t refcnt; /* active things looking at this mark */
244-
struct inode *inode; /* inode this entry is associated with */
245253
struct fsnotify_group *group; /* group this mark entry is for */
246-
struct hlist_node i_list; /* list of mark_entries by inode->i_fsnotify_mark_entries */
247254
struct list_head g_list; /* list of mark_entries by group->i_fsnotify_mark_entries */
248-
spinlock_t lock; /* protect group, inode, and killme */
249-
struct list_head free_i_list; /* tmp list used when freeing this mark */
255+
spinlock_t lock; /* protect group and inode */
256+
union {
257+
struct fsnotify_inode_mark i;
258+
};
250259
struct list_head free_g_list; /* tmp list used when freeing this mark */
251260
void (*free_mark)(struct fsnotify_mark_entry *entry); /* called on final put+free */
252261
};

‎kernel/audit_tree.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ static void insert_hash(struct audit_chunk *chunk)
179179
struct fsnotify_mark_entry *entry = &chunk->mark;
180180
struct list_head *list;
181181

182-
if (!entry->inode)
182+
if (!entry->i.inode)
183183
return;
184-
list = chunk_hash(entry->inode);
184+
list = chunk_hash(entry->i.inode);
185185
list_add_rcu(&chunk->hash, list);
186186
}
187187

@@ -193,7 +193,7 @@ struct audit_chunk *audit_tree_lookup(const struct inode *inode)
193193

194194
list_for_each_entry_rcu(p, list, hash) {
195195
/* mark.inode may have gone NULL, but who cares? */
196-
if (p->mark.inode == inode) {
196+
if (p->mark.i.inode == inode) {
197197
atomic_long_inc(&p->refs);
198198
return p;
199199
}
@@ -233,7 +233,7 @@ static void untag_chunk(struct node *p)
233233
spin_unlock(&hash_lock);
234234

235235
spin_lock(&entry->lock);
236-
if (chunk->dead || !entry->inode) {
236+
if (chunk->dead || !entry->i.inode) {
237237
spin_unlock(&entry->lock);
238238
goto out;
239239
}
@@ -259,7 +259,7 @@ static void untag_chunk(struct node *p)
259259
if (!new)
260260
goto Fallback;
261261
fsnotify_duplicate_mark(&new->mark, entry);
262-
if (fsnotify_add_mark(&new->mark, new->mark.group, new->mark.inode, 1)) {
262+
if (fsnotify_add_mark(&new->mark, new->mark.group, new->mark.i.inode, 1)) {
263263
free_chunk(new);
264264
goto Fallback;
265265
}
@@ -388,7 +388,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
388388
chunk_entry = &chunk->mark;
389389

390390
spin_lock(&old_entry->lock);
391-
if (!old_entry->inode) {
391+
if (!old_entry->i.inode) {
392392
/* old_entry is being shot, lets just lie */
393393
spin_unlock(&old_entry->lock);
394394
fsnotify_put_mark(old_entry);
@@ -397,7 +397,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
397397
}
398398

399399
fsnotify_duplicate_mark(chunk_entry, old_entry);
400-
if (fsnotify_add_mark(chunk_entry, chunk_entry->group, chunk_entry->inode, 1)) {
400+
if (fsnotify_add_mark(chunk_entry, chunk_entry->group, chunk_entry->i.inode, 1)) {
401401
spin_unlock(&old_entry->lock);
402402
free_chunk(chunk);
403403
fsnotify_put_mark(old_entry);
@@ -605,7 +605,7 @@ void audit_trim_trees(void)
605605
list_for_each_entry(node, &tree->chunks, list) {
606606
struct audit_chunk *chunk = find_chunk(node);
607607
/* this could be NULL if the watch is dieing else where... */
608-
struct inode *inode = chunk->mark.inode;
608+
struct inode *inode = chunk->mark.i.inode;
609609
node->index |= 1U<<31;
610610
if (iterate_mounts(compare_root, inode, root_mnt))
611611
node->index &= ~(1U<<31);

0 commit comments

Comments
 (0)