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 2971565817 : xfs_trans_ijoin( 29 : struct xfs_trans *tp, 30 : struct xfs_inode *ip, 31 : uint lock_flags) 32 : { 33 2971565817 : struct xfs_inode_log_item *iip; 34 : 35 2971565817 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); 36 2971663700 : if (ip->i_itemp == NULL) 37 55161232 : xfs_inode_item_init(ip, ip->i_mount); 38 2971663108 : iip = ip->i_itemp; 39 : 40 2971663108 : ASSERT(iip->ili_lock_flags == 0); 41 2971663108 : iip->ili_lock_flags = lock_flags; 42 5943562872 : ASSERT(!xfs_iflags_test(ip, XFS_ISTALE)); 43 : 44 : /* Reset the per-tx dirty context and add the item to the tx. */ 45 2971899764 : iip->ili_dirty_flags = 0; 46 2971899764 : xfs_trans_add_item(tp, &iip->ili_item); 47 2971487052 : } 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 760869916 : xfs_trans_ichgtime( 56 : struct xfs_trans *tp, 57 : struct xfs_inode *ip, 58 : int flags) 59 : { 60 760869916 : struct inode *inode = VFS_I(ip); 61 760869916 : struct timespec64 tv; 62 : 63 760869916 : ASSERT(tp); 64 760869916 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); 65 : 66 760858752 : tv = current_time(inode); 67 : 68 760991331 : if (flags & XFS_ICHGTIME_MOD) 69 237883511 : inode->i_mtime = tv; 70 760991331 : if (flags & XFS_ICHGTIME_CHG) 71 760975174 : inode->i_ctime = tv; 72 760991331 : if (flags & XFS_ICHGTIME_ACCESS) 73 64360282 : inode->i_atime = tv; 74 760991331 : if (flags & XFS_ICHGTIME_CREATE) 75 64361848 : ip->i_crtime = tv; 76 760991331 : } 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 3198052110 : xfs_trans_log_inode( 88 : struct xfs_trans *tp, 89 : struct xfs_inode *ip, 90 : uint flags) 91 : { 92 3198052110 : struct xfs_inode_log_item *iip = ip->i_itemp; 93 3198052110 : struct inode *inode = VFS_I(ip); 94 : 95 3198052110 : ASSERT(iip); 96 3198052110 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); 97 6398289640 : ASSERT(!xfs_iflags_test(ip, XFS_ISTALE)); 98 : 99 3199822455 : 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 6400431844 : if (!test_and_set_bit(XFS_LI_DIRTY, &iip->ili_item.li_flags)) { 111 3725870591 : if (IS_I_VERSION(inode) && 112 1862912641 : inode_maybe_inc_iversion(inode, flags & XFS_ILOG_CORE)) 113 1754880926 : flags |= XFS_ILOG_IVERSION; 114 : } 115 : 116 3200720584 : iip->ili_dirty_flags |= flags; 117 3200720584 : } 118 : 119 : int 120 2705161 : xfs_trans_roll_inode( 121 : struct xfs_trans **tpp, 122 : struct xfs_inode *ip) 123 : { 124 2705161 : int error; 125 : 126 2705161 : xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE); 127 2705396 : error = xfs_trans_roll(tpp); 128 2705434 : if (!error) 129 2705440 : xfs_trans_ijoin(*tpp, ip, 0); 130 2705387 : return error; 131 : }