xfs: properly order xfsstats proc/sysfs init and teardown
PATCH 1/1 xfs: properly order xfsstats proc/sysfs init and teardown
The xfs statistics are accessible both through procfs and through sysctls, so they need to be fully set up before exposure via those interfaces, and those interfaces both need to be torn down before the underlying percpu structures are freed. Today we get that wrong on both ends - we expose them through xfs_init_procfs before allocating the percpu structures, and we free those percpu structures before tearing down sysctls and procfs.
Fix init_xfs_fs by calling alloc_percpu(xfsstats) prior to xfs_init_procfs(), and fix the error unwind path to reflect this, then also move free_percpu() to after tearing down both procfs and sysctls in exit_xfs_fs.
--- fs/xfs/xfs_super.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
fs/xfs/xfs_super.c +11 -11
@@ -2668,9 +2668,15 @@ init_xfs_fs(void)if (error) goto out_destroy_wq; + xfsstats.xs_stats = alloc_percpu(struct xfsstats); +if (!xfsstats.xs_stats) { + error = -ENOMEM ; + goto out_mru_cache_uninit; + } + error =xfs_init_procfs ();if (error) - goto out_mru_cache_uninit; + goto out_free_stats; error =xfs_sysctl_register ();if (error)
@@ -2686,16 +2692,10 @@ init_xfs_fs(void) xfsstats.xs_kobj.kobject.kset = xfs_kset; - xfsstats.xs_stats = alloc_percpu(struct xfsstats); -if (!xfsstats.xs_stats) { - error = -ENOMEM ; - goto out_kset_unregister; - } - error =xfs_sysfs_init (&xfsstats.xs_kobj, &xfs_stats_ktype,NULL ,"stats" );if (error) - goto out_free_stats; + goto out_kset_unregister; error =xchk_global_stats_setup (xfs_debugfs);if (error)
@@ -2727,8 +2727,6 @@ init_xfs_fs(void)xchk_global_stats_teardown (); out_remove_stats_kobj:xfs_sysfs_del (&xfsstats.xs_kobj); - out_free_stats: -free_percpu (xfsstats.xs_stats); out_kset_unregister:kset_unregister (xfs_kset); out_debugfs_unregister:
@@ -2736,6 +2734,8 @@ init_xfs_fs(void)xfs_sysctl_unregister (); out_cleanup_procfs:xfs_cleanup_procfs (); + out_free_stats: +free_percpu (xfsstats.xs_stats); out_mru_cache_uninit:xfs_mru_cache_uninit (); out_destroy_wq:
@@ -2756,11 +2756,11 @@ exit_xfs_fs(void)#endif xchk_global_stats_teardown ();xfs_sysfs_del (&xfsstats.xs_kobj); -free_percpu (xfsstats.xs_stats);kset_unregister (xfs_kset);debugfs_remove (xfs_debugfs);xfs_sysctl_unregister ();xfs_cleanup_procfs (); +free_percpu (xfsstats.xs_stats);xfs_mru_cache_uninit ();xfs_destroy_workqueues ();xfs_destroy_caches ();
Signature · 1 line
2.56.0
Looks good:
Quoted 9 lines · Eric Sandeen
The xfs statistics are accessible both through procfs and through sysctls, so they need to be fully set up before exposure via those interfaces, and those interfaces both need to be torn down before the underlying percpu structures are freed. Today we get that wrong on both ends - we expose them through
xfs_init_procfsbefore allocating the percpu structures, and we free those percpu structures before tearing down sysctls and procfs.[...]
Applied to for-next, thanks!
[1/1] xfs: properly order xfsstats proc/sysfs init and teardown
commit: 765db499ad5837365b445b26b6fc81f30f134758
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>