Skip to content

Commit

Permalink
xfs: create scaffolding for creating debugfs entries
Browse files Browse the repository at this point in the history
Set up debugfs directories for xfs as a whole, and a subdirectory for
each mounted filesystem.  This will enable the creation of debugfs files
in the next patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
  • Loading branch information
Darrick J. Wong committed Aug 10, 2023
1 parent 764018c commit a76dba3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions fs/xfs/xfs_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ typedef __u32 xfs_nlink_t;
#include <linux/rhashtable.h>
#include <linux/xattr.h>
#include <linux/mnt_idmapping.h>
#include <linux/debugfs.h>

#include <asm/page.h>
#include <asm/div64.h>
Expand Down
1 change: 1 addition & 0 deletions fs/xfs/xfs_mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ typedef struct xfs_mount {
uint64_t m_resblks_avail;/* available reserved blocks */
uint64_t m_resblks_save; /* reserved blks @ remount,ro */
struct delayed_work m_reclaim_work; /* background inode reclaim */
struct dentry *m_debugfs; /* debugfs parent */
struct xfs_kobj m_kobj;
struct xfs_kobj m_error_kobj;
struct xfs_kobj m_error_meta_kobj;
Expand Down
32 changes: 30 additions & 2 deletions fs/xfs/xfs_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

static const struct super_operations xfs_super_operations;

static struct dentry *xfs_debugfs; /* top-level xfs debugfs dir */
static struct kset *xfs_kset; /* top-level xfs sysfs dir */
#ifdef DEBUG
static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
Expand Down Expand Up @@ -758,6 +759,7 @@ static void
xfs_mount_free(
struct xfs_mount *mp)
{
debugfs_remove(mp->m_debugfs);
kfree(mp->m_rtname);
kfree(mp->m_logname);
kmem_free(mp);
Expand Down Expand Up @@ -1479,6 +1481,21 @@ xfs_fs_validate_params(
return 0;
}

struct dentry *
xfs_debugfs_mkdir(
const char *name,
struct dentry *parent)
{
struct dentry *child;

/* Apparently we're expected to ignore error returns?? */
child = debugfs_create_dir(name, parent);
if (IS_ERR(child))
return NULL;

return child;
}

static int
xfs_fs_fill_super(
struct super_block *sb,
Expand Down Expand Up @@ -1521,6 +1538,13 @@ xfs_fs_fill_super(
if (error)
goto out_free_names;

if (xfs_debugfs) {
mp->m_debugfs = xfs_debugfs_mkdir(mp->m_super->s_id,
xfs_debugfs);
} else {
mp->m_debugfs = NULL;
}

error = xfs_init_mount_workqueues(mp);
if (error)
goto out_close_devices;
Expand Down Expand Up @@ -2353,10 +2377,12 @@ init_xfs_fs(void)
if (error)
goto out_cleanup_procfs;

xfs_debugfs = xfs_debugfs_mkdir("xfs", NULL);

xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
if (!xfs_kset) {
error = -ENOMEM;
goto out_sysctl_unregister;
goto out_debugfs_unregister;
}

xfsstats.xs_kobj.kobject.kset = xfs_kset;
Expand Down Expand Up @@ -2400,7 +2426,8 @@ init_xfs_fs(void)
free_percpu(xfsstats.xs_stats);
out_kset_unregister:
kset_unregister(xfs_kset);
out_sysctl_unregister:
out_debugfs_unregister:
debugfs_remove(xfs_debugfs);
xfs_sysctl_unregister();
out_cleanup_procfs:
xfs_cleanup_procfs();
Expand All @@ -2427,6 +2454,7 @@ exit_xfs_fs(void)
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();
xfs_mru_cache_uninit();
Expand Down
2 changes: 2 additions & 0 deletions fs/xfs/xfs_super.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,6 @@ extern struct workqueue_struct *xfs_discard_wq;

#define XFS_M(sb) ((struct xfs_mount *)((sb)->s_fs_info))

struct dentry *xfs_debugfs_mkdir(const char *name, struct dentry *parent);

#endif /* __XFS_SUPER_H__ */

0 comments on commit a76dba3

Please sign in to comment.