]>
Commit | Line | Data |
---|---|---|
0b61f8a4 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* |
7b718769 NS |
3 | * Copyright (c) 2000,2005 Silicon Graphics, Inc. |
4 | * All Rights Reserved. | |
1da177e4 | 5 | */ |
1da177e4 | 6 | #include "xfs.h" |
a844f451 | 7 | #include "xfs_fs.h" |
70a9883c | 8 | #include "xfs_shared.h" |
a4fbe6ab | 9 | #include "xfs_format.h" |
239880ef | 10 | #include "xfs_log_format.h" |
298f7bec DC |
11 | #include "xfs_trans_resv.h" |
12 | #include "xfs_mount.h" | |
1da177e4 | 13 | #include "xfs_inode.h" |
239880ef | 14 | #include "xfs_trans.h" |
a844f451 NS |
15 | #include "xfs_trans_priv.h" |
16 | #include "xfs_inode_item.h" | |
1da177e4 | 17 | |
f0e28280 JL |
18 | #include <linux/iversion.h> |
19 | ||
1da177e4 | 20 | /* |
898621d5 CH |
21 | * Add a locked inode to the transaction. |
22 | * | |
23 | * The inode must be locked, and it cannot be associated with any transaction. | |
ddc3415a | 24 | * If lock_flags is non-zero the inode will be unlocked on transaction commit. |
1da177e4 LT |
25 | */ |
26 | void | |
27 | xfs_trans_ijoin( | |
898621d5 | 28 | struct xfs_trans *tp, |
ddc3415a CH |
29 | struct xfs_inode *ip, |
30 | uint lock_flags) | |
1da177e4 | 31 | { |
fd9cbe51 | 32 | struct xfs_inode_log_item *iip; |
1da177e4 | 33 | |
579aa9ca | 34 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
1da177e4 LT |
35 | if (ip->i_itemp == NULL) |
36 | xfs_inode_item_init(ip, ip->i_mount); | |
37 | iip = ip->i_itemp; | |
ddc3415a | 38 | |
898621d5 | 39 | ASSERT(iip->ili_lock_flags == 0); |
ddc3415a | 40 | iip->ili_lock_flags = lock_flags; |
96355d5a | 41 | ASSERT(!xfs_iflags_test(ip, XFS_ISTALE)); |
1da177e4 | 42 | |
82842fee DC |
43 | /* Reset the per-tx dirty context and add the item to the tx. */ |
44 | iip->ili_dirty_flags = 0; | |
e98c414f | 45 | xfs_trans_add_item(tp, &iip->ili_item); |
1da177e4 LT |
46 | } |
47 | ||
dcd79a14 DC |
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 | xfs_trans_ichgtime( | |
55 | struct xfs_trans *tp, | |
56 | struct xfs_inode *ip, | |
57 | int flags) | |
58 | { | |
59 | struct inode *inode = VFS_I(ip); | |
8d2d878d | 60 | struct timespec64 tv; |
dcd79a14 DC |
61 | |
62 | ASSERT(tp); | |
63 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); | |
dcd79a14 | 64 | |
f798accd | 65 | tv = current_time(inode); |
dcd79a14 | 66 | |
3987848c | 67 | if (flags & XFS_ICHGTIME_MOD) |
dcd79a14 | 68 | inode->i_mtime = tv; |
f798accd CB |
69 | if (flags & XFS_ICHGTIME_CHG) |
70 | inode_set_ctime_to_ts(inode, tv); | |
8d2d878d | 71 | if (flags & XFS_ICHGTIME_CREATE) |
e98d5e88 | 72 | ip->i_crtime = tv; |
dcd79a14 DC |
73 | } |
74 | ||
1da177e4 | 75 | /* |
298f7bec DC |
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 | |
82842fee DC |
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. | |
1da177e4 LT |
82 | */ |
83 | void | |
84 | xfs_trans_log_inode( | |
1319ebef DC |
85 | struct xfs_trans *tp, |
86 | struct xfs_inode *ip, | |
87 | uint flags) | |
1da177e4 | 88 | { |
1319ebef DC |
89 | struct xfs_inode_log_item *iip = ip->i_itemp; |
90 | struct inode *inode = VFS_I(ip); | |
c3b1b131 | 91 | |
1319ebef | 92 | ASSERT(iip); |
579aa9ca | 93 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); |
96355d5a | 94 | ASSERT(!xfs_iflags_test(ip, XFS_ISTALE)); |
1da177e4 | 95 | |
1319ebef DC |
96 | tp->t_flags |= XFS_TRANS_DIRTY; |
97 | ||
dc037ad7 DC |
98 | /* |
99 | * First time we log the inode in a transaction, bump the inode change | |
d17260fd JL |
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. | |
dc037ad7 | 106 | */ |
1319ebef DC |
107 | if (!test_and_set_bit(XFS_LI_DIRTY, &iip->ili_item.li_flags)) { |
108 | if (IS_I_VERSION(inode) && | |
109 | inode_maybe_inc_iversion(inode, flags & XFS_ILOG_CORE)) | |
82842fee | 110 | flags |= XFS_ILOG_IVERSION; |
603f000b DW |
111 | } |
112 | ||
82842fee | 113 | iip->ili_dirty_flags |= flags; |
1da177e4 | 114 | } |
411350df CH |
115 | |
116 | int | |
117 | xfs_trans_roll_inode( | |
118 | struct xfs_trans **tpp, | |
119 | struct xfs_inode *ip) | |
120 | { | |
121 | int error; | |
122 | ||
123 | xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE); | |
124 | error = xfs_trans_roll(tpp); | |
125 | if (!error) | |
126 | xfs_trans_ijoin(*tpp, ip, 0); | |
127 | return error; | |
128 | } |