xfs: Check for m_errortag initialization in xfs_errortag_test
authorCarlos Maiolino <cmaiolino@redhat.com>
Fri, 30 Jun 2017 16:46:07 +0000 (09:46 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Sun, 2 Jul 2017 04:08:47 +0000 (21:08 -0700)
While adding error injection into IO completion, I notice the lack of
initialization check in xfs_errortag_test(), make the error injection
mechanism unable to be used there.

IO completion is executed a few times before the error injection
mechanism is initialized, so to be safer, make xfs_errortag_test() check
if the errortag is properly initialized.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/xfs_error.c

index 26c32bc5cd34f2ebb15fd06aeb730643ce579fc4..2f4feb959bfb46812678b65e262270b2fc55842a 100644 (file)
@@ -233,6 +233,17 @@ 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;
+
        ASSERT(error_tag < XFS_ERRTAG_MAX);
        randfactor = mp->m_errortag[error_tag];
        if (!randfactor || prandom_u32() % randfactor)