Add three event counters to each mount object:

 (1) mnt_topology_changes.

     Counts the number of changes to the mount tree topology, including
     addition of new mount objects, removal of mount objects and mount
     objects being moved about.

 (2) mnt_attr_changes.

     Counts the number of changes to a mount object's attributes, such as
     whether or not the device files it contains are interpretable as such.

 (3) mnt_subtree_notifications.

     Counts the number of events within the mount subtree at this point.

Signed-off-by: David Howells <[email protected]>
---

 fs/mount.h        |    3 +++
 fs/mount_notify.c |    4 ++++
 2 files changed, 7 insertions(+)

diff --git a/fs/mount.h b/fs/mount.h
index 1037781be055..9758a9fa8f69 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -83,6 +83,9 @@ struct mount {
        u64     mnt_unique_id;          /* ID unique over lifetime of kernel */
 #endif
 #ifdef CONFIG_MOUNT_NOTIFICATIONS
+       atomic_long_t mnt_topology_changes;     /* Number of topology changes 
applied */
+       atomic_long_t mnt_attr_changes;         /* Number of attribute changes 
applied */
+       atomic_long_t mnt_subtree_notifications; /* Number of notifications in 
subtree */
        struct watch_list *mnt_watchers; /* Watches on dentries within this 
mount */
 #endif
 } __randomize_layout;
diff --git a/fs/mount_notify.c b/fs/mount_notify.c
index d8ba66ed5f77..57eebae51cb1 100644
--- a/fs/mount_notify.c
+++ b/fs/mount_notify.c
@@ -61,6 +61,7 @@ static void post_mount_notification(struct mount *changed,
                        cursor.dentry = READ_ONCE(mnt->mnt_mountpoint);
                        mnt = parent;
                        cursor.mnt = &mnt->mnt;
+                       atomic_long_inc(&mnt->mnt_subtree_notifications);
                } else {
                        cursor.dentry = cursor.dentry->d_parent;
                }
@@ -96,6 +97,7 @@ void notify_mount(struct mount *trigger,
        case NOTIFY_MOUNT_EXPIRY:
        case NOTIFY_MOUNT_READONLY:
        case NOTIFY_MOUNT_SETATTR:
+               atomic_long_inc(&trigger->mnt_attr_changes);
                break;
 
        case NOTIFY_MOUNT_NEW_MOUNT:
@@ -103,6 +105,8 @@ void notify_mount(struct mount *trigger,
        case NOTIFY_MOUNT_MOVE_FROM:
        case NOTIFY_MOUNT_MOVE_TO:
                n.auxiliary_mount = aux->mnt_unique_id;
+               atomic_long_inc(&trigger->mnt_topology_changes);
+               atomic_long_inc(&aux->mnt_topology_changes);
                break;
 
        default:


Reply via email to