LCOV - code coverage report
Current view: top level - fs/xfs/scrub - fscounters_repair.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc4-xfsa @ Mon Jul 31 20:08:27 PDT 2023 Lines: 11 13 84.6 %
Date: 2023-07-31 20:08:27 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0-or-later
       2             : /*
       3             :  * Copyright (C) 2018-2023 Oracle.  All Rights Reserved.
       4             :  * Author: Darrick J. Wong <djwong@kernel.org>
       5             :  */
       6             : #include "xfs.h"
       7             : #include "xfs_fs.h"
       8             : #include "xfs_shared.h"
       9             : #include "xfs_format.h"
      10             : #include "xfs_trans_resv.h"
      11             : #include "xfs_mount.h"
      12             : #include "xfs_defer.h"
      13             : #include "xfs_btree.h"
      14             : #include "xfs_bit.h"
      15             : #include "xfs_log_format.h"
      16             : #include "xfs_trans.h"
      17             : #include "xfs_sb.h"
      18             : #include "xfs_inode.h"
      19             : #include "xfs_alloc.h"
      20             : #include "xfs_ialloc.h"
      21             : #include "xfs_rmap.h"
      22             : #include "xfs_health.h"
      23             : #include "scrub/xfs_scrub.h"
      24             : #include "scrub/scrub.h"
      25             : #include "scrub/common.h"
      26             : #include "scrub/trace.h"
      27             : #include "scrub/repair.h"
      28             : #include "scrub/fscounters.h"
      29             : 
      30             : /*
      31             :  * FS Summary Counters
      32             :  * ===================
      33             :  *
      34             :  * We correct errors in the filesystem summary counters by setting them to the
      35             :  * values computed during the obligatory scrub phase.  However, we must be
      36             :  * careful not to allow any other thread to change the counters while we're
      37             :  * computing and setting new values.  To achieve this, we freeze the
      38             :  * filesystem for the whole operation if the REPAIR flag is set.  The checking
      39             :  * function is stricter when we've frozen the fs.
      40             :  */
      41             : 
      42             : /*
      43             :  * Reset the superblock counters.  Caller is responsible for freezing the
      44             :  * filesystem during the calculation and reset phases.
      45             :  */
      46             : int
      47       15578 : xrep_fscounters(
      48             :         struct xfs_scrub        *sc)
      49             : {
      50       15578 :         struct xfs_mount        *mp = sc->mp;
      51       15578 :         struct xchk_fscounters  *fsc = sc->buf;
      52             : 
      53             :         /*
      54             :          * Reinitialize the in-core counters from what we computed.  We froze
      55             :          * the filesystem, so there shouldn't be anyone else trying to modify
      56             :          * these counters.
      57             :          */
      58       15578 :         if (!fsc->frozen) {
      59           0 :                 ASSERT(fsc->frozen);
      60           0 :                 return -EFSCORRUPTED;
      61             :         }
      62             : 
      63       15578 :         trace_xrep_reset_counters(mp, fsc);
      64             : 
      65       15578 :         percpu_counter_set(&mp->m_icount, fsc->icount);
      66       15578 :         percpu_counter_set(&mp->m_ifree, fsc->ifree);
      67       15578 :         percpu_counter_set(&mp->m_fdblocks, fsc->fdblocks);
      68       15578 :         percpu_counter_set(&mp->m_frextents, fsc->frextents);
      69       15578 :         mp->m_sb.sb_frextents = fsc->frextents;
      70             : 
      71       15578 :         return 0;
      72             : }

Generated by: LCOV version 1.14