xfs: allocate m_errortag early

Ensure the mount structure always has a valid m_errortag for debug
builds.  This removes the NULL checking from the runtime code, and
prepares for allowing to set errortags from mount.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
Christoph Hellwig 2026-01-30 06:19:17 +01:00 committed by Carlos Maiolino
parent 9a228d1415
commit 394969e2f9
2 changed files with 13 additions and 25 deletions

View File

@ -114,18 +114,8 @@ int
xfs_errortag_init(
struct xfs_mount *mp)
{
int ret;
mp->m_errortag = kzalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX,
GFP_KERNEL | __GFP_RETRY_MAYFAIL);
if (!mp->m_errortag)
return -ENOMEM;
ret = xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
&mp->m_kobj, "errortag");
if (ret)
kfree(mp->m_errortag);
return ret;
}
void
@ -133,7 +123,6 @@ xfs_errortag_del(
struct xfs_mount *mp)
{
xfs_sysfs_del(&mp->m_errortag_kobj);
kfree(mp->m_errortag);
}
static bool
@ -154,8 +143,6 @@ xfs_errortag_enabled(
struct xfs_mount *mp,
unsigned int tag)
{
if (!mp->m_errortag)
return false;
if (!xfs_errortag_valid(tag))
return false;
@ -171,17 +158,6 @@ xfs_errortag_test(
{
unsigned int randfactor;
/*
* To be able to use error injection anywhere, we need to ensure error
* injection mechanism is already initialized.
*
* Code paths like I/O completion can be called before the
* initialization is complete, but be able to inject errors in such
* places is still useful.
*/
if (!mp->m_errortag)
return false;
if (!xfs_errortag_valid(error_tag))
return false;

View File

@ -40,6 +40,7 @@
#include "xfs_defer.h"
#include "xfs_attr_item.h"
#include "xfs_xattr.h"
#include "xfs_errortag.h"
#include "xfs_iunlink_item.h"
#include "xfs_dahash_test.h"
#include "xfs_rtbitmap.h"
@ -824,6 +825,9 @@ xfs_mount_free(
debugfs_remove(mp->m_debugfs);
kfree(mp->m_rtname);
kfree(mp->m_logname);
#ifdef DEBUG
kfree(mp->m_errortag);
#endif
kfree(mp);
}
@ -2266,6 +2270,14 @@ xfs_init_fs_context(
mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
if (!mp)
return -ENOMEM;
#ifdef DEBUG
mp->m_errortag = kcalloc(XFS_ERRTAG_MAX, sizeof(*mp->m_errortag),
GFP_KERNEL);
if (!mp->m_errortag) {
kfree(mp);
return -ENOMEM;
}
#endif
spin_lock_init(&mp->m_sb_lock);
for (i = 0; i < XG_TYPE_MAX; i++)