LCOV - code coverage report
Current view: top level - fs/xfs/libxfs - xfs_trans_inode.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc3-acha @ Mon Jul 31 20:08:06 PDT 2023 Lines: 44 45 97.8 %
Date: 2023-07-31 20:08:07 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
       4             :  * All Rights Reserved.
       5             :  */
       6             : #include "xfs.h"
       7             : #include "xfs_fs.h"
       8             : #include "xfs_shared.h"
       9             : #include "xfs_format.h"
      10             : #include "xfs_log_format.h"
      11             : #include "xfs_trans_resv.h"
      12             : #include "xfs_mount.h"
      13             : #include "xfs_inode.h"
      14             : #include "xfs_trans.h"
      15             : #include "xfs_trans_priv.h"
      16             : #include "xfs_inode_item.h"
      17             : 
      18             : #include <linux/iversion.h>
      19             : 
      20             : /*
      21             :  * Add a locked inode to the transaction.
      22             :  *
      23             :  * The inode must be locked, and it cannot be associated with any transaction.
      24             :  * If lock_flags is non-zero the inode will be unlocked on transaction commit.
      25             :  */
      26             : void
      27  2170637510 : xfs_trans_ijoin(
      28             :         struct xfs_trans        *tp,
      29             :         struct xfs_inode        *ip,
      30             :         uint                    lock_flags)
      31             : {
      32  2170637510 :         struct xfs_inode_log_item *iip;
      33             : 
      34  2170637510 :         ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
      35  2170706074 :         if (ip->i_itemp == NULL)
      36    47505962 :                 xfs_inode_item_init(ip, ip->i_mount);
      37  2170702133 :         iip = ip->i_itemp;
      38             : 
      39  2170702133 :         ASSERT(iip->ili_lock_flags == 0);
      40  2170702133 :         iip->ili_lock_flags = lock_flags;
      41  4341599165 :         ASSERT(!xfs_iflags_test(ip, XFS_ISTALE));
      42             : 
      43             :         /* Reset the per-tx dirty context and add the item to the tx. */
      44  2170897032 :         iip->ili_dirty_flags = 0;
      45  2170897032 :         xfs_trans_add_item(tp, &iip->ili_item);
      46  2170559986 : }
      47             : 
      48             : /*
      49             :  * Transactional inode timestamp update. Requires the inode to be locked and
      50             :  * joined to the transaction supplied. Relies on the transaction subsystem to
      51             :  * track dirty state and update/writeback the inode accordingly.
      52             :  */
      53             : void
      54   521556106 : xfs_trans_ichgtime(
      55             :         struct xfs_trans        *tp,
      56             :         struct xfs_inode        *ip,
      57             :         int                     flags)
      58             : {
      59   521556106 :         struct inode            *inode = VFS_I(ip);
      60   521556106 :         struct timespec64       tv;
      61             : 
      62   521556106 :         ASSERT(tp);
      63   521556106 :         ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
      64             : 
      65   521575685 :         tv = current_time(inode);
      66             : 
      67   521585538 :         if (flags & XFS_ICHGTIME_MOD)
      68   169380588 :                 inode->i_mtime = tv;
      69   521585538 :         if (flags & XFS_ICHGTIME_CHG)
      70   521595776 :                 inode->i_ctime = tv;
      71   521585538 :         if (flags & XFS_ICHGTIME_CREATE)
      72           0 :                 ip->i_crtime = tv;
      73   521585538 : }
      74             : 
      75             : /*
      76             :  * This is called to mark the fields indicated in fieldmask as needing to be
      77             :  * logged when the transaction is committed.  The inode must already be
      78             :  * associated with the given transaction. All we do here is record where the
      79             :  * inode was dirtied and mark the transaction and inode log item dirty;
      80             :  * everything else is done in the ->precommit log item operation after the
      81             :  * changes in the transaction have been completed.
      82             :  */
      83             : void
      84  2602837853 : xfs_trans_log_inode(
      85             :         struct xfs_trans        *tp,
      86             :         struct xfs_inode        *ip,
      87             :         uint                    flags)
      88             : {
      89  2602837853 :         struct xfs_inode_log_item *iip = ip->i_itemp;
      90  2602837853 :         struct inode            *inode = VFS_I(ip);
      91             : 
      92  2602837853 :         ASSERT(iip);
      93  2602837853 :         ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
      94  5206920075 :         ASSERT(!xfs_iflags_test(ip, XFS_ISTALE));
      95             : 
      96  2603860407 :         tp->t_flags |= XFS_TRANS_DIRTY;
      97             : 
      98             :         /*
      99             :          * First time we log the inode in a transaction, bump the inode change
     100             :          * counter if it is configured for this to occur. While we have the
     101             :          * inode locked exclusively for metadata modification, we can usually
     102             :          * avoid setting XFS_ILOG_CORE if no one has queried the value since
     103             :          * the last time it was incremented. If we have XFS_ILOG_CORE already
     104             :          * set however, then go ahead and bump the i_version counter
     105             :          * unconditionally.
     106             :          */
     107  5208421783 :         if (!test_and_set_bit(XFS_LI_DIRTY, &iip->ili_item.li_flags)) {
     108  2962021739 :                 if (IS_I_VERSION(inode) &&
     109  1480956301 :                     inode_maybe_inc_iversion(inode, flags & XFS_ILOG_CORE))
     110  1387288689 :                         flags |= XFS_ILOG_IVERSION;
     111             :         }
     112             : 
     113  2604689334 :         iip->ili_dirty_flags |= flags;
     114  2604689334 : }
     115             : 
     116             : int
     117     1297701 : xfs_trans_roll_inode(
     118             :         struct xfs_trans        **tpp,
     119             :         struct xfs_inode        *ip)
     120             : {
     121     1297701 :         int                     error;
     122             : 
     123     1297701 :         xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE);
     124     1298333 :         error = xfs_trans_roll(tpp);
     125     1298446 :         if (!error)
     126     1298450 :                 xfs_trans_ijoin(*tpp, ip, 0);
     127     1298313 :         return error;
     128             : }

Generated by: LCOV version 1.14