Skip to contentSkip to conversation

fsnotify: Independent inode tracking

PATCH New Jan Kara 2 participants 8 messages Jan 21 – Jan 22

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author maintainer
#0 lore raw

v3 cover fsnotify: Independent inode tracking

Hello!

Here is another revision of the patch set implementing independent tracking of inodes that have any notification marks attached through a linked list of mark connectors used for inodes. We then use this list to destroy all inode marks for a superblock during unmount instead of iterating all inodes on a superblock. With this more efficient way of destroying all inode marks we can move this destruction earlier in generic_shutdown_super() before dcache (and sb->s_root in particular) is pruned which fixes races between fsnotify events encoding handles and accessing sb->s_root after generic_shutdown_super() has freed them.

Changes since v2:
* Fix fsnotify_unmount_inodes() to safely deal with connectors not holding inode reference
* Add Amir's Reviewed-by tag

Changes since v1:
* Remove pointless srcu protection when tearing down inode connectors
* Remove FSNOTIFY_CONN_FLAG_TRACKED as it isn't needed
* Use ihold() instead of __iget() as we don't hold inode->i_lock but the connector holds inode ref
* Add Amir's Reviewed-by tags

Honza

Previous versions:

author maintainer
#1 lore raw

PATCH v3 1/3 fsnotify: Track inode connectors for a superblock

Introduce a linked list tracking all inode connectors for a superblock. We will use this list when the superblock is getting shutdown to properly clean up all the inode marks instead of relying on scanning all inodes in the superblock which can get rather slow.

---
 fs/notify/fsnotify.c             |  8 +--
 fs/notify/fsnotify.h             |  2 +-
 fs/notify/mark.c                 | 89 ++++++++++++++++++++++++++++----
 include/linux/fsnotify_backend.h |  5 +-
 4 files changed, 89 insertions(+), 15 deletions(-)
fs/notify/fsnotify.c +5 -3
index 71bd44e5ab6d..706484fb3bf3 100644
@@ -112,7 +112,10 @@ void fsnotify_sb_delete(struct super_block *sb)
 
 void fsnotify_sb_free(struct super_block *sb)
 {
-	kfree(sb->s_fsnotify_info);
+	if (sb->s_fsnotify_info) {
+		WARN_ON_ONCE(!list_empty(&sb->s_fsnotify_info->inode_conn_list));
+		kfree(sb->s_fsnotify_info);
+	}
 }
 
 /*
@@ -777,8 +780,7 @@ static __init int fsnotify_init(void)
 	if (ret)
 		panic("initializing fsnotify_mark_srcu");
 
-	fsnotify_mark_connector_cachep = KMEM_CACHE(fsnotify_mark_connector,
-						    SLAB_PANIC);
+	fsnotify_init_connector_caches();
 
 	return 0;
 }
fs/notify/fsnotify.h +1 -1
index 5950c7a67f41..6b58d733ceb6 100644
@@ -106,6 +106,6 @@ static inline void fsnotify_clear_marks_by_mntns(struct mnt_namespace *mntns)
  */
 extern void fsnotify_set_children_dentry_flags(struct inode *inode);
 
-extern struct kmem_cache *fsnotify_mark_connector_cachep;
+void fsnotify_init_connector_caches(void);
 
 #endif	/* __FS_NOTIFY_FSNOTIFY_H_ */
fs/notify/mark.c +79 -10

138 lines not on this page · raw message

include/linux/fsnotify_backend.h +4 -1
index 0d954ea7b179..95985400d3d8 100644
@@ -553,7 +553,7 @@ struct fsnotify_mark_connector {
 		/* Used listing heads to free after srcu period expires */
 		struct fsnotify_mark_connector *destroy_next;
 	};
-	struct hlist_head list;
+	struct hlist_head list;	/* List of marks */
 };
 
 /*
@@ -562,6 +562,9 @@ struct fsnotify_mark_connector {
  */
 struct fsnotify_sb_info {
 	struct fsnotify_mark_connector __rcu *sb_marks;
+	/* List of connectors for inode marks */
+	struct list_head inode_conn_list;
+	spinlock_t list_lock;	/* Lock protecting inode_conn_list */
 	/*
 	 * Number of inode/mount/sb objects that are being watched in this sb.
 	 * Note that inodes objects are currently double-accounted.
Signature · 1 line
2.51.0
author maintainer
#2 lore raw

PATCH v3 2/3 fsnotify: Use connector list for destroying inode marks

In reply to Jan Kara

Instead of iterating all inodes belonging to a superblock to find inode marks and remove them on umount, iterate all inode connectors for the superblock. This may be substantially faster since there are generally much less inodes with fsnotify marks than all inodes. It also removes one use of sb->s_inodes list which we strive to ultimately remove.

---
 fs/notify/fsnotify.c | 61 +-------------------------------------------
 fs/notify/fsnotify.h |  3 +++
 fs/notify/mark.c     | 41 +++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 60 deletions(-)
fs/notify/fsnotify.c +1 -60
index 706484fb3bf3..9995de1710e5 100644
@@ -33,65 +33,6 @@ void __fsnotify_mntns_delete(struct mnt_namespace *mntns)
 	fsnotify_clear_marks_by_mntns(mntns);
 }
 
-/**
- * fsnotify_unmount_inodes - an sb is unmounting.  handle any watched inodes.
- * @sb: superblock being unmounted.
- *
- * Called during unmount with no locks held, so needs to be safe against
- * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block.
- */
-static void fsnotify_unmount_inodes(struct super_block *sb)
-{
-	struct inode *inode, *iput_inode = NULL;
-
-	spin_lock(&sb->s_inode_list_lock);
-	list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
-		/*
-		 * We cannot __iget() an inode in state I_FREEING,
-		 * I_WILL_FREE, or I_NEW which is fine because by that point
-		 * the inode cannot have any associated watches.
-		 */
-		spin_lock(&inode->i_lock);
-		if (inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) {
-			spin_unlock(&inode->i_lock);
-			continue;
-		}
-
-		/*
-		 * If i_count is zero, the inode cannot have any watches and
-		 * doing an __iget/iput with SB_ACTIVE clear would actually
-		 * evict all inodes with zero i_count from icache which is
-		 * unnecessarily violent and may in fact be illegal to do.
-		 * However, we should have been called /after/ evict_inodes
-		 * removed all zero refcount inodes, in any case.  Test to
-		 * be sure.
-		 */
-		if (!icount_read(inode)) {
-			spin_unlock(&inode->i_lock);
-			continue;
-		}
-
-		__iget(inode);
-		spin_unlock(&inode->i_lock);
-		spin_unlock(&sb->s_inode_list_lock);
-
-		iput(iput_inode);
-
-		/* for each watch, send FS_UNMOUNT and then remove it */
-		fsnotify_inode(inode, FS_UNMOUNT);
-
-		fsnotify_inode_delete(inode);
-
-		iput_inode = inode;
-
-		cond_resched();
-		spin_lock(&sb->s_inode_list_lock);
-	}
-	spin_unlock(&sb->s_inode_list_lock);
-
-	iput(iput_inode);
-}
-
 void fsnotify_sb_delete(struct super_block *sb)
 {
 	struct fsnotify_sb_info *sbinfo = fsnotify_sb_info(sb);
@@ -100,7 +41,7 @@ void fsnotify_sb_delete(struct super_block *sb)
 	if (!sbinfo)
 		return;
 
-	fsnotify_unmount_inodes(sb);
+	fsnotify_unmount_inodes(sbinfo);
 	fsnotify_clear_marks_by_sb(sb);
 	/* Wait for outstanding object references from connectors */
 	wait_var_event(fsnotify_sb_watched_objects(sb),
fs/notify/fsnotify.h +3 -0
index 6b58d733ceb6..58c7bb25e571 100644
@@ -77,6 +77,9 @@ extern struct srcu_struct fsnotify_mark_srcu;
 extern int fsnotify_compare_groups(struct fsnotify_group *a,
 				   struct fsnotify_group *b);
 
+/* Destroy all inode marks for given superblock */
+void fsnotify_unmount_inodes(struct fsnotify_sb_info *sbinfo);
+
 /* Destroy all marks attached to an object via connector */
 extern void fsnotify_destroy_marks(fsnotify_connp_t *connp);
 /* run the list of all marks associated with inode and destroy them */
fs/notify/mark.c +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.51.0
reviewer Reviewed-by on v3 2/3
#3 lore raw

Re: [PATCH v3 2/3] fsnotify: Use connector list for destroying inode marks

Quoted 128 lines · Jan Kara

Instead of iterating all inodes belonging to a superblock to find inode marks and remove them on umount, iterate all inode connectors for the superblock. This may be substantially faster since there are generally much less inodes with fsnotify marks than all inodes. It also removes one use of sb->s_inodes list which we strive to ultimately remove.

---
 fs/notify/fsnotify.c | 61 +-------------------------------------------
 fs/notify/fsnotify.h |  3 +++
 fs/notify/mark.c     | 41 +++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 60 deletions(-)
fs/notify/fsnotify.c +1 -60
index 706484fb3bf3..9995de1710e5 100644
@@ -33,65 +33,6 @@ void __fsnotify_mntns_delete(struct mnt_namespace *mntns)
        fsnotify_clear_marks_by_mntns(mntns);
 }
 
-/**
- * fsnotify_unmount_inodes - an sb is unmounting.  handle any watched inodes.
- * @sb: superblock being unmounted.
- *
- * Called during unmount with no locks held, so needs to be safe against
- * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block.
- */
-static void fsnotify_unmount_inodes(struct super_block *sb)
-{
-       struct inode *inode, *iput_inode = NULL;
-
-       spin_lock(&sb->s_inode_list_lock);
-       list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
-               /*
-                * We cannot __iget() an inode in state I_FREEING,
-                * I_WILL_FREE, or I_NEW which is fine because by that point
-                * the inode cannot have any associated watches.
-                */
-               spin_lock(&inode->i_lock);
-               if (inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) {
-                       spin_unlock(&inode->i_lock);
-                       continue;
-               }
-
-               /*
-                * If i_count is zero, the inode cannot have any watches and
-                * doing an __iget/iput with SB_ACTIVE clear would actually
-                * evict all inodes with zero i_count from icache which is
-                * unnecessarily violent and may in fact be illegal to do.
-                * However, we should have been called /after/ evict_inodes
-                * removed all zero refcount inodes, in any case.  Test to
-                * be sure.
-                */
-               if (!icount_read(inode)) {
-                       spin_unlock(&inode->i_lock);
-                       continue;
-               }
-
-               __iget(inode);
-               spin_unlock(&inode->i_lock);
-               spin_unlock(&sb->s_inode_list_lock);
-
-               iput(iput_inode);
-
-               /* for each watch, send FS_UNMOUNT and then remove it */
-               fsnotify_inode(inode, FS_UNMOUNT);
-
-               fsnotify_inode_delete(inode);
-
-               iput_inode = inode;
-
-               cond_resched();
-               spin_lock(&sb->s_inode_list_lock);
-       }
-       spin_unlock(&sb->s_inode_list_lock);
-
-       iput(iput_inode);
-}
-
 void fsnotify_sb_delete(struct super_block *sb)
 {
        struct fsnotify_sb_info *sbinfo = fsnotify_sb_info(sb);
@@ -100,7 +41,7 @@ void fsnotify_sb_delete(struct super_block *sb)
        if (!sbinfo)
                return;
 
-       fsnotify_unmount_inodes(sb);
+       fsnotify_unmount_inodes(sbinfo);
        fsnotify_clear_marks_by_sb(sb);
        /* Wait for outstanding object references from connectors */
        wait_var_event(fsnotify_sb_watched_objects(sb),
fs/notify/fsnotify.h +3 -0
index 6b58d733ceb6..58c7bb25e571 100644
@@ -77,6 +77,9 @@ extern struct srcu_struct fsnotify_mark_srcu;
 extern int fsnotify_compare_groups(struct fsnotify_group *a,
                                   struct fsnotify_group *b);
 
+/* Destroy all inode marks for given superblock */
+void fsnotify_unmount_inodes(struct fsnotify_sb_info *sbinfo);
+
 /* Destroy all marks attached to an object via connector */
 extern void fsnotify_destroy_marks(fsnotify_connp_t *connp);
 /* run the list of all marks associated with inode and destroy them */
fs/notify/mark.c +13 -0
index 4a525791a2f3..1b955000ad5b 100644
@@ -666,6 +666,47 @@ struct fsnotify_inode_mark_connector {
        struct list_head conns_list;
 };
 
+/**
+ * fsnotify_unmount_inodes - an sb is unmounting. Handle any watched inodes.
+ * @sbinfo: fsnotify info for superblock being unmounted.
+ *
+ * Walk all inode connectors for the superblock and free all associated marks.
+ */
+void fsnotify_unmount_inodes(struct fsnotify_sb_info *sbinfo)
+{
+       struct fsnotify_inode_mark_connector *iconn;
+       struct inode *inode;
+
+restart:
+       spin_lock(&sbinfo->list_lock);

fs/notify/mark.c struct fsnotify_inode_mark_connector { · line 691

Quoted 10 lines
fs/notify/mark.c +10 -0
+       list_for_each_entry(iconn, &sbinfo->inode_conn_list, conns_list) {
+               /* All connectors on the list are still attached to an inode */
+               inode = iconn->common.obj;
+               /*
+                * For connectors without FSNOTIFY_CONN_FLAG_HAS_IREF
+                * (evictable marks) corresponding inode may well have 0
+                * refcount and can be undergoing eviction. OTOH list_lock
+                * protects us from the connector getting detached and inode
+                * freed. So we can poke around the inode safely.
+                */

OK. You convinced me that this is safe.

Quoted 5 lines
fs/notify/mark.c +5 -0
+               spin_lock(&inode->i_lock);
+               if (unlikely(
+                   inode_state_read(inode) & (I_FREEING | I_WILL_FREE))) {
+                       spin_unlock(&inode->i_lock);
+                       continue;

fs/notify/mark.c struct fsnotify_inode_mark_connector { · line 706

Quoted 10 lines
fs/notify/mark.c +10 -0
+               }
+               __iget(inode);
+               spin_unlock(&inode->i_lock);
+               spin_unlock(&sbinfo->list_lock);
+               fsnotify_inode(inode, FS_UNMOUNT);
+               fsnotify_clear_marks_by_inode(inode);
+               iput(inode);
+               cond_resched();
+               goto restart;
+       }

This loop looks odd being a while loop that is always restarted for the likely branch.

Maybe would be more clear to add some comment like:

find_next_inode:

       /* Find the first non-evicting inodes and free connector and marks */
       spin_lock(&sbinfo->list_lock);
       list_for_each_entry(iconn, &sbinfo->inode_conn_list, conns_list) {

Just a thought.

Anyway, with or without it, feel free to add:

Thanks,
Amir.

author maintainer
#4 lore raw

Re: [PATCH v3 2/3] fsnotify: Use connector list for destroying inode marks

Quoted 20 lines · Amir Goldstein
Quoted 5 lines · Jan Kara
(quoted diff) +5 -0
+               spin_lock(&inode->i_lock);
+               if (unlikely(
+                   inode_state_read(inode) & (I_FREEING | I_WILL_FREE))) {
+                       spin_unlock(&inode->i_lock);
+                       continue;

Review

Quoted 10 lines
(quoted diff) +10 -0
+               }
+               __iget(inode);
+               spin_unlock(&inode->i_lock);
+               spin_unlock(&sbinfo->list_lock);
+               fsnotify_inode(inode, FS_UNMOUNT);
+               fsnotify_clear_marks_by_inode(inode);
+               iput(inode);
+               cond_resched();
+               goto restart;
+       }

This loop looks odd being a while loop that is always restarted for the likely branch.

Quoted 8 lines

Maybe would be more clear to add some comment like:

find_next_inode:

       /* Find the first non-evicting inodes and free connector and marks */
       spin_lock(&sbinfo->list_lock);
       list_for_each_entry(iconn, &sbinfo->inode_conn_list, conns_list) {

Just a thought.

I agree the loop is perverse and I'm not happy about it either (but at least it works :)). With a fresh mind: What about the attached variant?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR

From e2e6bc81f309f26812455a84f42dddbb6a194847 Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 15 Oct 2025 16:02:47 +0200
Subject: [PATCH 2/3] fsnotify: Use connector list for destroying inode marks

Instead of iterating all inodes belonging to a superblock to find inode marks and remove them on umount, iterate all inode connectors for the superblock. This may be substantially faster since there are generally much less inodes with fsnotify marks than all inodes. It also removes one use of sb->s_inodes list which we strive to ultimately remove.

---
 fs/notify/fsnotify.c | 61 +-------------------------------------------
 fs/notify/fsnotify.h |  3 +++
 fs/notify/mark.c     | 50 ++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 60 deletions(-)
fs/notify/fsnotify.c +1 -60
index 706484fb3bf3..9995de1710e5 100644
@@ -33,65 +33,6 @@ void __fsnotify_mntns_delete(struct mnt_namespace *mntns)
 	fsnotify_clear_marks_by_mntns(mntns);
 }
 
-/**
- * fsnotify_unmount_inodes - an sb is unmounting.  handle any watched inodes.
- * @sb: superblock being unmounted.
- *
- * Called during unmount with no locks held, so needs to be safe against
- * concurrent modifiers. We temporarily drop sb->s_inode_list_lock and CAN block.
- */
-static void fsnotify_unmount_inodes(struct super_block *sb)
-{
-	struct inode *inode, *iput_inode = NULL;
-
-	spin_lock(&sb->s_inode_list_lock);
-	list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
-		/*
-		 * We cannot __iget() an inode in state I_FREEING,
-		 * I_WILL_FREE, or I_NEW which is fine because by that point
-		 * the inode cannot have any associated watches.
-		 */
-		spin_lock(&inode->i_lock);
-		if (inode_state_read(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) {
-			spin_unlock(&inode->i_lock);
-			continue;
-		}
-
-		/*
-		 * If i_count is zero, the inode cannot have any watches and
-		 * doing an __iget/iput with SB_ACTIVE clear would actually
-		 * evict all inodes with zero i_count from icache which is
-		 * unnecessarily violent and may in fact be illegal to do.
-		 * However, we should have been called /after/ evict_inodes
-		 * removed all zero refcount inodes, in any case.  Test to
-		 * be sure.
-		 */
-		if (!icount_read(inode)) {
-			spin_unlock(&inode->i_lock);
-			continue;
-		}
-
-		__iget(inode);
-		spin_unlock(&inode->i_lock);
-		spin_unlock(&sb->s_inode_list_lock);
-
-		iput(iput_inode);
-
-		/* for each watch, send FS_UNMOUNT and then remove it */
-		fsnotify_inode(inode, FS_UNMOUNT);
-
-		fsnotify_inode_delete(inode);
-
-		iput_inode = inode;
-
-		cond_resched();
-		spin_lock(&sb->s_inode_list_lock);
-	}
-	spin_unlock(&sb->s_inode_list_lock);
-
-	iput(iput_inode);
-}
-
 void fsnotify_sb_delete(struct super_block *sb)
 {
 	struct fsnotify_sb_info *sbinfo = fsnotify_sb_info(sb);
@@ -100,7 +41,7 @@ void fsnotify_sb_delete(struct super_block *sb)
 	if (!sbinfo)
 		return;
 
-	fsnotify_unmount_inodes(sb);
+	fsnotify_unmount_inodes(sbinfo);
 	fsnotify_clear_marks_by_sb(sb);
 	/* Wait for outstanding object references from connectors */
 	wait_var_event(fsnotify_sb_watched_objects(sb),
fs/notify/fsnotify.h +3 -0
index 6b58d733ceb6..58c7bb25e571 100644
@@ -77,6 +77,9 @@ extern struct srcu_struct fsnotify_mark_srcu;
 extern int fsnotify_compare_groups(struct fsnotify_group *a,
 				   struct fsnotify_group *b);
 
+/* Destroy all inode marks for given superblock */
+void fsnotify_unmount_inodes(struct fsnotify_sb_info *sbinfo);
+
 /* Destroy all marks attached to an object via connector */
 extern void fsnotify_destroy_marks(fsnotify_connp_t *connp);
 /* run the list of all marks associated with inode and destroy them */
fs/notify/mark.c +50 -0

56 lines not on this page · raw message

Signature · 1 line
2.51.0
reviewer Reviewed-by
#5 lore raw

Re: [PATCH v3 2/3] fsnotify: Use connector list for destroying inode marks

Quoted 29 lines · Jan Kara
Quoted 27 lines · Amir Goldstein
Quoted 5 lines · Jan Kara
fs/notify/mark.c +5 -0
+               spin_lock(&inode->i_lock);
+               if (unlikely(
+                   inode_state_read(inode) & (I_FREEING | I_WILL_FREE))) {
+                       spin_unlock(&inode->i_lock);
+                       continue;

fs/notify/mark.c struct fsnotify_inode_mark_connector { · line 716

Quoted 10 lines
fs/notify/mark.c +10 -0
+               }
+               __iget(inode);
+               spin_unlock(&inode->i_lock);
+               spin_unlock(&sbinfo->list_lock);
+               fsnotify_inode(inode, FS_UNMOUNT);
+               fsnotify_clear_marks_by_inode(inode);
+               iput(inode);
+               cond_resched();
+               goto restart;
+       }

This loop looks odd being a while loop that is always restarted for the likely branch.

Maybe would be more clear to add some comment like:

find_next_inode:

       /* Find the first non-evicting inodes and free connector and marks */
       spin_lock(&sbinfo->list_lock);
       list_for_each_entry(iconn, &sbinfo->inode_conn_list, conns_list) {
Quoted 4 lines
Quoted 1 line

Just a thought.

I agree the loop is perverse and I'm not happy about it either (but at least it works :)). With a fresh mind: What about the attached variant?

This is waaay nicer :)

I think that we don't need to worry about a hung task warning in fsnotify_get_living_inode(), because a long list of evicting inodes would be unexpected. Right?

Feel free to add:

Thanks,
Amir.

author maintainer
#6 lore raw

Re: [PATCH v3 2/3] fsnotify: Use connector list for destroying inode marks

Quoted 32 lines · Amir Goldstein
Quoted 31 lines · Jan Kara
Quoted 28 lines · Amir Goldstein
Quoted 5 lines · Jan Kara
fs/notify/mark.c +5 -0
+               spin_lock(&inode->i_lock);
+               if (unlikely(
+                   inode_state_read(inode) & (I_FREEING | I_WILL_FREE))) {
+                       spin_unlock(&inode->i_lock);
+                       continue;

fs/notify/mark.c struct fsnotify_inode_mark_connector { · line 716

Quoted 10 lines
fs/notify/mark.c +10 -0
+               }
+               __iget(inode);
+               spin_unlock(&inode->i_lock);
+               spin_unlock(&sbinfo->list_lock);
+               fsnotify_inode(inode, FS_UNMOUNT);
+               fsnotify_clear_marks_by_inode(inode);
+               iput(inode);
+               cond_resched();
+               goto restart;
+       }

This loop looks odd being a while loop that is always restarted for the likely branch.

Maybe would be more clear to add some comment like:

find_next_inode:

       /* Find the first non-evicting inodes and free connector and marks */
       spin_lock(&sbinfo->list_lock);
       list_for_each_entry(iconn, &sbinfo->inode_conn_list, conns_list) {

Just a thought.

Quoted 8 lines
Quoted 2 lines

I agree the loop is perverse and I'm not happy about it either (but at least it works :)). With a fresh mind: What about the attached variant?

This is waaay nicer :)

I think that we don't need to worry about a hung task warning in fsnotify_get_living_inode(), because a long list of evicting inodes would be unexpected. Right?

Yes, very much unexpected. If something like that happens, we'll be probably better off to export the __wait_for_freeing_inode() logic from core VFS and use it here instead of skipping over freeing inodes. At this point I find that unnecessary...

Quoted 2 lines

Feel free to add:

Thanks! So I'll push the changes to my tree.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author maintainer
#7 lore raw

PATCH v3 3/3 fsnotify: Shutdown fsnotify before destroying sb's dcache

In reply to Jan Kara

Currently fsnotify_sb_delete() was called after we have evicted superblock's dcache and inode cache. This was done mainly so that we iterate as few inodes as possible when removing inode marks. However, as Jakub reported, this is problematic because for some filesystems encoding of file handles uses sb->s_root which gets cleared as part of dcache eviction. And either delayed fsnotify events or reading fdinfo for fsnotify group with marks on fs being unmounted may trigger encoding of file handles during unmount. So move shutdown of fsnotify subsystem before shrinking of dcache.

---
 fs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/super.c +2 -2
index 3d85265d1400..9c13e68277dd 100644
@@ -618,6 +618,7 @@ void generic_shutdown_super(struct super_block *sb)
 	const struct super_operations *sop = sb->s_op;
 
 	if (sb->s_root) {
+		fsnotify_sb_delete(sb);
 		shrink_dcache_for_umount(sb);
 		sync_filesystem(sb);
 		sb->s_flags &= ~SB_ACTIVE;
@@ -629,9 +630,8 @@ void generic_shutdown_super(struct super_block *sb)
 
 		/*
 		 * Clean up and evict any inodes that still have references due
-		 * to fsnotify or the security policy.
+		 * to the security policy.
 		 */
-		fsnotify_sb_delete(sb);
 		security_sb_delete(sb);
 
 		if (sb->s_dio_done_wq) {
Signature · 1 line
2.51.0