Skip to content

Commit 394969e

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
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>
1 parent 9a228d1 commit 394969e

2 files changed

Lines changed: 13 additions & 25 deletions

File tree

fs/xfs/xfs_error.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,15 @@ int
114114
xfs_errortag_init(
115115
struct xfs_mount *mp)
116116
{
117-
int ret;
118-
119-
mp->m_errortag = kzalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX,
120-
GFP_KERNEL | __GFP_RETRY_MAYFAIL);
121-
if (!mp->m_errortag)
122-
return -ENOMEM;
123-
124-
ret = xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
117+
return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
125118
&mp->m_kobj, "errortag");
126-
if (ret)
127-
kfree(mp->m_errortag);
128-
return ret;
129119
}
130120

131121
void
132122
xfs_errortag_del(
133123
struct xfs_mount *mp)
134124
{
135125
xfs_sysfs_del(&mp->m_errortag_kobj);
136-
kfree(mp->m_errortag);
137126
}
138127

139128
static bool
@@ -154,8 +143,6 @@ xfs_errortag_enabled(
154143
struct xfs_mount *mp,
155144
unsigned int tag)
156145
{
157-
if (!mp->m_errortag)
158-
return false;
159146
if (!xfs_errortag_valid(tag))
160147
return false;
161148

@@ -171,17 +158,6 @@ xfs_errortag_test(
171158
{
172159
unsigned int randfactor;
173160

174-
/*
175-
* To be able to use error injection anywhere, we need to ensure error
176-
* injection mechanism is already initialized.
177-
*
178-
* Code paths like I/O completion can be called before the
179-
* initialization is complete, but be able to inject errors in such
180-
* places is still useful.
181-
*/
182-
if (!mp->m_errortag)
183-
return false;
184-
185161
if (!xfs_errortag_valid(error_tag))
186162
return false;
187163

fs/xfs/xfs_super.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "xfs_defer.h"
4141
#include "xfs_attr_item.h"
4242
#include "xfs_xattr.h"
43+
#include "xfs_errortag.h"
4344
#include "xfs_iunlink_item.h"
4445
#include "xfs_dahash_test.h"
4546
#include "xfs_rtbitmap.h"
@@ -824,6 +825,9 @@ xfs_mount_free(
824825
debugfs_remove(mp->m_debugfs);
825826
kfree(mp->m_rtname);
826827
kfree(mp->m_logname);
828+
#ifdef DEBUG
829+
kfree(mp->m_errortag);
830+
#endif
827831
kfree(mp);
828832
}
829833

@@ -2266,6 +2270,14 @@ xfs_init_fs_context(
22662270
mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
22672271
if (!mp)
22682272
return -ENOMEM;
2273+
#ifdef DEBUG
2274+
mp->m_errortag = kcalloc(XFS_ERRTAG_MAX, sizeof(*mp->m_errortag),
2275+
GFP_KERNEL);
2276+
if (!mp->m_errortag) {
2277+
kfree(mp);
2278+
return -ENOMEM;
2279+
}
2280+
#endif
22692281

22702282
spin_lock_init(&mp->m_sb_lock);
22712283
for (i = 0; i < XG_TYPE_MAX; i++)

0 commit comments

Comments
 (0)