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 : #include "xfs_rtbitmap.h" 18 : 19 : #include <linux/iversion.h> 20 : 21 : /* 22 : * Add a locked inode to the transaction. 23 : * 24 : * The inode must be locked, and it cannot be associated with any transaction. 25 : * If lock_flags is non-zero the inode will be unlocked on transaction commit. 26 : */ 27 : void 28 5559744600 : xfs_trans_ijoin( 29 : struct xfs_trans *tp, 30 : struct xfs_inode *ip, 31 : uint lock_flags) 32 : { 33 5559744600 : struct xfs_inode_log_item *iip; 34 : 35 5559744600 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); 36 5558067404 : if (ip->i_itemp == NULL) 37 83097837 : xfs_inode_item_init(ip, ip->i_mount); 38 5558522854 : iip = ip->i_itemp; 39 : 40 5558522854 : ASSERT(iip->ili_lock_flags == 0); 41 5558522854 : iip->ili_lock_flags = lock_flags; 42 11120769513 : ASSERT(!xfs_iflags_test(ip, XFS_ISTALE)); 43 : 44 : /* Reset the per-tx dirty context and add the item to the tx. */ 45 5562246659 : iip->ili_dirty_flags = 0; 46 5562246659 : xfs_trans_add_item(tp, &iip->ili_item); 47 5559753918 : } 48 : 49 : /* 50 : * Transactional inode timestamp update. Requires the inode to be locked and 51 : * joined to the transaction supplied. Relies on the transaction subsystem to 52 : * track dirty state and update/writeback the inode accordingly. 53 : */ 54 : void 55 1070468855 : xfs_trans_ichgtime( 56 : struct xfs_trans *tp, 57 : struct xfs_inode *ip, 58 : int flags) 59 : { 60 1070468855 : struct inode *inode = VFS_I(ip); 61 1070468855 : struct timespec64 tv; 62 : 63 1070468855 : ASSERT(tp); 64 1070468855 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); 65 : 66 1070108895 : tv = current_time(inode); 67 : 68 1069636343 : if (flags & XFS_ICHGTIME_MOD) 69 421206460 : inode->i_mtime = tv; 70 1069636343 : if (flags & XFS_ICHGTIME_CHG) 71 1069618029 : inode->i_ctime = tv; 72 1069636343 : if (flags & XFS_ICHGTIME_ACCESS) 73 123159304 : inode->i_atime = tv; 74 1069636343 : if (flags & XFS_ICHGTIME_CREATE) 75 123146919 : ip->i_crtime = tv; 76 1069636343 : } 77 : 78 : /* 79 : * This is called to mark the fields indicated in fieldmask as needing to be 80 : * logged when the transaction is committed. The inode must already be 81 : * associated with the given transaction. All we do here is record where the 82 : * inode was dirtied and mark the transaction and inode log item dirty; 83 : * everything else is done in the ->precommit log item operation after the 84 : * changes in the transaction have been completed. 85 : */ 86 : void 87 5886200149 : xfs_trans_log_inode( 88 : struct xfs_trans *tp, 89 : struct xfs_inode *ip, 90 : uint flags) 91 : { 92 5886200149 : struct xfs_inode_log_item *iip = ip->i_itemp; 93 5886200149 : struct inode *inode = VFS_I(ip); 94 : 95 5886200149 : ASSERT(iip); 96 5886200149 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); 97 11774987955 : ASSERT(!xfs_iflags_test(ip, XFS_ISTALE)); 98 : 99 5890351316 : tp->t_flags |= XFS_TRANS_DIRTY; 100 : 101 : /* 102 : * First time we log the inode in a transaction, bump the inode change 103 : * counter if it is configured for this to occur. While we have the 104 : * inode locked exclusively for metadata modification, we can usually 105 : * avoid setting XFS_ILOG_CORE if no one has queried the value since 106 : * the last time it was incremented. If we have XFS_ILOG_CORE already 107 : * set however, then go ahead and bump the i_version counter 108 : * unconditionally. 109 : */ 110 5890351316 : if (!test_and_set_bit(XFS_LI_DIRTY, &iip->ili_item.li_flags)) { 111 6909654582 : if (IS_I_VERSION(inode) && 112 3455004482 : inode_maybe_inc_iversion(inode, flags & XFS_ILOG_CORE)) 113 3219205126 : flags |= XFS_ILOG_IVERSION; 114 : } 115 : 116 5889743927 : iip->ili_dirty_flags |= flags; 117 5889743927 : } 118 : 119 : int 120 10304364 : xfs_trans_roll_inode( 121 : struct xfs_trans **tpp, 122 : struct xfs_inode *ip) 123 : { 124 10304364 : int error; 125 : 126 10304364 : xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE); 127 10322841 : error = xfs_trans_roll(tpp); 128 10316062 : if (!error) 129 10314317 : xfs_trans_ijoin(*tpp, ip, 0); 130 10323972 : return error; 131 : }