1
2
3
4
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
22
23
24
25
26void
27xfs_trans_ijoin(
28 struct xfs_trans *tp,
29 struct xfs_inode *ip,
30 uint lock_flags)
31{
32 struct xfs_inode_log_item *iip;
33
34 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
35 if (ip->i_itemp == NULL)
36 xfs_inode_item_init(ip, ip->i_mount);
37 iip = ip->i_itemp;
38
39 ASSERT(iip->ili_lock_flags == 0);
40 iip->ili_lock_flags = lock_flags;
41 ASSERT(!xfs_iflags_test(ip, XFS_ISTALE));
42
43
44
45
46 xfs_trans_add_item(tp, &iip->ili_item);
47}
48
49
50
51
52
53
54void
55xfs_trans_ichgtime(
56 struct xfs_trans *tp,
57 struct xfs_inode *ip,
58 int flags)
59{
60 struct inode *inode = VFS_I(ip);
61 struct timespec64 tv;
62
63 ASSERT(tp);
64 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
65
66 tv = current_time(inode);
67
68 if (flags & XFS_ICHGTIME_MOD)
69 inode->i_mtime = tv;
70 if (flags & XFS_ICHGTIME_CHG)
71 inode->i_ctime = tv;
72 if (flags & XFS_ICHGTIME_CREATE)
73 ip->i_d.di_crtime = tv;
74}
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91void
92xfs_trans_log_inode(
93 struct xfs_trans *tp,
94 struct xfs_inode *ip,
95 uint flags)
96{
97 struct xfs_inode_log_item *iip = ip->i_itemp;
98 struct inode *inode = VFS_I(ip);
99 uint iversion_flags = 0;
100
101 ASSERT(iip);
102 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
103 ASSERT(!xfs_iflags_test(ip, XFS_ISTALE));
104
105 tp->t_flags |= XFS_TRANS_DIRTY;
106
107
108
109
110
111
112
113 if (inode->i_state & I_DIRTY_TIME) {
114 spin_lock(&inode->i_lock);
115 inode->i_state &= ~I_DIRTY_TIME;
116 spin_unlock(&inode->i_lock);
117 }
118
119
120
121
122
123
124
125
126
127
128 if (!test_and_set_bit(XFS_LI_DIRTY, &iip->ili_item.li_flags)) {
129 if (IS_I_VERSION(inode) &&
130 inode_maybe_inc_iversion(inode, flags & XFS_ILOG_CORE))
131 iversion_flags = XFS_ILOG_CORE;
132 }
133
134
135
136
137
138 if ((flags & (XFS_ILOG_CORE | XFS_ILOG_TIMESTAMP)) &&
139 xfs_sb_version_hasbigtime(&ip->i_mount->m_sb) &&
140 !xfs_inode_has_bigtime(ip)) {
141 ip->i_d.di_flags2 |= XFS_DIFLAG2_BIGTIME;
142 flags |= XFS_ILOG_CORE;
143 }
144
145
146
147
148
149
150 spin_lock(&iip->ili_lock);
151 iip->ili_fsync_fields |= flags;
152
153 if (!iip->ili_item.li_buf) {
154 struct xfs_buf *bp;
155 int error;
156
157
158
159
160
161
162
163
164
165
166 spin_unlock(&iip->ili_lock);
167 error = xfs_imap_to_bp(ip->i_mount, tp, &ip->i_imap, NULL,
168 &bp, 0);
169 if (error) {
170 xfs_force_shutdown(ip->i_mount, SHUTDOWN_META_IO_ERROR);
171 return;
172 }
173
174
175
176
177
178
179
180
181 xfs_buf_hold(bp);
182 spin_lock(&iip->ili_lock);
183 iip->ili_item.li_buf = bp;
184 bp->b_flags |= _XBF_INODES;
185 list_add_tail(&iip->ili_item.li_bio_list, &bp->b_li_list);
186 xfs_trans_brelse(tp, bp);
187 }
188
189
190
191
192
193
194
195 iip->ili_fields |= (flags | iip->ili_last_fields | iversion_flags);
196 spin_unlock(&iip->ili_lock);
197}
198
199int
200xfs_trans_roll_inode(
201 struct xfs_trans **tpp,
202 struct xfs_inode *ip)
203{
204 int error;
205
206 xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE);
207 error = xfs_trans_roll(tpp);
208 if (!error)
209 xfs_trans_ijoin(*tpp, ip, 0);
210 return error;
211}
212