Line data Source code
1 : // SPDX-License-Identifier: GPL-2.0
2 : /*
3 : * Copyright (c) 2000-2002,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_inode_item.h"
16 : #include "xfs_trace.h"
17 : #include "xfs_trans_priv.h"
18 : #include "xfs_buf_item.h"
19 : #include "xfs_log.h"
20 : #include "xfs_log_priv.h"
21 : #include "xfs_error.h"
22 :
23 : #include <linux/iversion.h>
24 :
25 : struct kmem_cache *xfs_ili_cache; /* inode log item */
26 :
27 : static inline struct xfs_inode_log_item *INODE_ITEM(struct xfs_log_item *lip)
28 : {
29 : return container_of(lip, struct xfs_inode_log_item, ili_item);
30 : }
31 :
32 : static uint64_t
33 1741641546 : xfs_inode_item_sort(
34 : struct xfs_log_item *lip)
35 : {
36 1741641546 : return INODE_ITEM(lip)->ili_inode->i_ino;
37 : }
38 :
39 : /*
40 : * Prior to finally logging the inode, we have to ensure that all the
41 : * per-modification inode state changes are applied. This includes VFS inode
42 : * state updates, format conversions, verifier state synchronisation and
43 : * ensuring the inode buffer remains in memory whilst the inode is dirty.
44 : *
45 : * We have to be careful when we grab the inode cluster buffer due to lock
46 : * ordering constraints. The unlinked inode modifications (xfs_iunlink_item)
47 : * require AGI -> inode cluster buffer lock order. The inode cluster buffer is
48 : * not locked until ->precommit, so it happens after everything else has been
49 : * modified.
50 : *
51 : * Further, we have AGI -> AGF lock ordering, and with O_TMPFILE handling we
52 : * have AGI -> AGF -> iunlink item -> inode cluster buffer lock order. Hence we
53 : * cannot safely lock the inode cluster buffer in xfs_trans_log_inode() because
54 : * it can be called on a inode (e.g. via bumplink/droplink) before we take the
55 : * AGF lock modifying directory blocks.
56 : *
57 : * Rather than force a complete rework of all the transactions to call
58 : * xfs_trans_log_inode() once and once only at the end of every transaction, we
59 : * move the pinning of the inode cluster buffer to a ->precommit operation. This
60 : * matches how the xfs_iunlink_item locks the inode cluster buffer, and it
61 : * ensures that the inode cluster buffer locking is always done last in a
62 : * transaction. i.e. we ensure the lock order is always AGI -> AGF -> inode
63 : * cluster buffer.
64 : *
65 : * If we return the inode number as the precommit sort key then we'll also
66 : * guarantee that the order all inode cluster buffer locking is the same all the
67 : * inodes and unlink items in the transaction.
68 : */
69 : static int
70 2164230469 : xfs_inode_item_precommit(
71 : struct xfs_trans *tp,
72 : struct xfs_log_item *lip)
73 : {
74 2164230469 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
75 2164230469 : struct xfs_inode *ip = iip->ili_inode;
76 2164230469 : struct inode *inode = VFS_I(ip);
77 2164230469 : unsigned int flags = iip->ili_dirty_flags;
78 :
79 : /*
80 : * Don't bother with i_lock for the I_DIRTY_TIME check here, as races
81 : * don't matter - we either will need an extra transaction in 24 hours
82 : * to log the timestamps, or will clear already cleared fields in the
83 : * worst case.
84 : */
85 2164230469 : if (inode->i_state & I_DIRTY_TIME) {
86 4 : spin_lock(&inode->i_lock);
87 4 : inode->i_state &= ~I_DIRTY_TIME;
88 4 : spin_unlock(&inode->i_lock);
89 : }
90 :
91 : /*
92 : * If we're updating the inode core or the timestamps and it's possible
93 : * to upgrade this inode to bigtime format, do so now.
94 : */
95 2164230469 : if ((flags & (XFS_ILOG_CORE | XFS_ILOG_TIMESTAMP)) &&
96 1956610487 : xfs_has_bigtime(ip->i_mount) &&
97 : !xfs_inode_has_bigtime(ip)) {
98 24 : ip->i_diflags2 |= XFS_DIFLAG2_BIGTIME;
99 24 : flags |= XFS_ILOG_CORE;
100 : }
101 :
102 : /*
103 : * Inode verifiers do not check that the extent size hint is an integer
104 : * multiple of the rt extent size on a directory with both rtinherit
105 : * and extszinherit flags set. If we're logging a directory that is
106 : * misconfigured in this way, clear the hint.
107 : */
108 2164230469 : if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
109 0 : (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) &&
110 0 : (ip->i_extsize % ip->i_mount->m_sb.sb_rextsize) > 0) {
111 0 : ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE |
112 : XFS_DIFLAG_EXTSZINHERIT);
113 0 : ip->i_extsize = 0;
114 0 : flags |= XFS_ILOG_CORE;
115 : }
116 :
117 : /*
118 : * Record the specific change for fdatasync optimisation. This allows
119 : * fdatasync to skip log forces for inodes that are only timestamp
120 : * dirty. Once we've processed the XFS_ILOG_IVERSION flag, convert it
121 : * to XFS_ILOG_CORE so that the actual on-disk dirty tracking
122 : * (ili_fields) correctly tracks that the version has changed.
123 : */
124 2164230469 : spin_lock(&iip->ili_lock);
125 2164514565 : iip->ili_fsync_fields |= (flags & ~XFS_ILOG_IVERSION);
126 2164514565 : if (flags & XFS_ILOG_IVERSION)
127 1387039909 : flags = ((flags & ~XFS_ILOG_IVERSION) | XFS_ILOG_CORE);
128 :
129 2164514565 : if (!iip->ili_item.li_buf) {
130 186952378 : struct xfs_buf *bp;
131 186952378 : int error;
132 :
133 : /*
134 : * We hold the ILOCK here, so this inode is not going to be
135 : * flushed while we are here. Further, because there is no
136 : * buffer attached to the item, we know that there is no IO in
137 : * progress, so nothing will clear the ili_fields while we read
138 : * in the buffer. Hence we can safely drop the spin lock and
139 : * read the buffer knowing that the state will not change from
140 : * here.
141 : */
142 186952378 : spin_unlock(&iip->ili_lock);
143 186947644 : error = xfs_imap_to_bp(ip->i_mount, tp, &ip->i_imap, &bp);
144 186959431 : if (error)
145 196 : return error;
146 :
147 : /*
148 : * We need an explicit buffer reference for the log item but
149 : * don't want the buffer to remain attached to the transaction.
150 : * Hold the buffer but release the transaction reference once
151 : * we've attached the inode log item to the buffer log item
152 : * list.
153 : */
154 186959235 : xfs_buf_hold(bp);
155 186960805 : spin_lock(&iip->ili_lock);
156 186959345 : iip->ili_item.li_buf = bp;
157 186959345 : bp->b_flags |= _XBF_INODES;
158 186959345 : list_add_tail(&iip->ili_item.li_bio_list, &bp->b_li_list);
159 186944779 : xfs_trans_brelse(tp, bp);
160 : }
161 :
162 : /*
163 : * Always OR in the bits from the ili_last_fields field. This is to
164 : * coordinate with the xfs_iflush() and xfs_buf_inode_iodone() routines
165 : * in the eventual clearing of the ili_fields bits. See the big comment
166 : * in xfs_iflush() for an explanation of this coordination mechanism.
167 : */
168 2164531187 : iip->ili_fields |= (flags | iip->ili_last_fields);
169 2164531187 : spin_unlock(&iip->ili_lock);
170 :
171 : /*
172 : * We are done with the log item transaction dirty state, so clear it so
173 : * that it doesn't pollute future transactions.
174 : */
175 2163830123 : iip->ili_dirty_flags = 0;
176 2163830123 : return 0;
177 : }
178 :
179 : /*
180 : * The logged size of an inode fork is always the current size of the inode
181 : * fork. This means that when an inode fork is relogged, the size of the logged
182 : * region is determined by the current state, not the combination of the
183 : * previously logged state + the current state. This is different relogging
184 : * behaviour to most other log items which will retain the size of the
185 : * previously logged changes when smaller regions are relogged.
186 : *
187 : * Hence operations that remove data from the inode fork (e.g. shortform
188 : * dir/attr remove, extent form extent removal, etc), the size of the relogged
189 : * inode gets -smaller- rather than stays the same size as the previously logged
190 : * size and this can result in the committing transaction reducing the amount of
191 : * space being consumed by the CIL.
192 : */
193 : STATIC void
194 1481171612 : xfs_inode_item_data_fork_size(
195 : struct xfs_inode_log_item *iip,
196 : int *nvecs,
197 : int *nbytes)
198 : {
199 1481171612 : struct xfs_inode *ip = iip->ili_inode;
200 :
201 1481171612 : switch (ip->i_df.if_format) {
202 744346395 : case XFS_DINODE_FMT_EXTENTS:
203 744346395 : if ((iip->ili_fields & XFS_ILOG_DEXT) &&
204 293860698 : ip->i_df.if_nextents > 0 &&
205 266797534 : ip->i_df.if_bytes > 0) {
206 : /* worst case, doesn't subtract delalloc extents */
207 266797534 : *nbytes += xfs_inode_data_fork_size(ip);
208 266797534 : *nvecs += 1;
209 : }
210 : break;
211 399939863 : case XFS_DINODE_FMT_BTREE:
212 399939863 : if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
213 291414751 : ip->i_df.if_broot_bytes > 0) {
214 291414751 : *nbytes += ip->i_df.if_broot_bytes;
215 291414751 : *nvecs += 1;
216 : }
217 : break;
218 279967894 : case XFS_DINODE_FMT_LOCAL:
219 279967894 : if ((iip->ili_fields & XFS_ILOG_DDATA) &&
220 270879555 : ip->i_df.if_bytes > 0) {
221 270879555 : *nbytes += xlog_calc_iovec_len(ip->i_df.if_bytes);
222 270879555 : *nvecs += 1;
223 : }
224 : break;
225 :
226 : case XFS_DINODE_FMT_DEV:
227 : break;
228 0 : default:
229 0 : ASSERT(0);
230 0 : break;
231 : }
232 1481171612 : }
233 :
234 : STATIC void
235 1382215073 : xfs_inode_item_attr_fork_size(
236 : struct xfs_inode_log_item *iip,
237 : int *nvecs,
238 : int *nbytes)
239 : {
240 1382215073 : struct xfs_inode *ip = iip->ili_inode;
241 :
242 1382215073 : switch (ip->i_af.if_format) {
243 211253302 : case XFS_DINODE_FMT_EXTENTS:
244 211253302 : if ((iip->ili_fields & XFS_ILOG_AEXT) &&
245 23066481 : ip->i_af.if_nextents > 0 &&
246 21965113 : ip->i_af.if_bytes > 0) {
247 : /* worst case, doesn't subtract unused space */
248 21965113 : *nbytes += xfs_inode_attr_fork_size(ip);
249 21965113 : *nvecs += 1;
250 : }
251 : break;
252 100198 : case XFS_DINODE_FMT_BTREE:
253 100198 : if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
254 84270 : ip->i_af.if_broot_bytes > 0) {
255 84270 : *nbytes += ip->i_af.if_broot_bytes;
256 84270 : *nvecs += 1;
257 : }
258 : break;
259 1170861573 : case XFS_DINODE_FMT_LOCAL:
260 1170861573 : if ((iip->ili_fields & XFS_ILOG_ADATA) &&
261 768367715 : ip->i_af.if_bytes > 0) {
262 768367715 : *nbytes += xlog_calc_iovec_len(ip->i_af.if_bytes);
263 768367715 : *nvecs += 1;
264 : }
265 : break;
266 0 : default:
267 0 : ASSERT(0);
268 0 : break;
269 : }
270 1382215073 : }
271 :
272 : /*
273 : * This returns the number of iovecs needed to log the given inode item.
274 : *
275 : * We need one iovec for the inode log format structure, one for the
276 : * inode core, and possibly one for the inode data/extents/b-tree root
277 : * and one for the inode attribute data/extents/b-tree root.
278 : */
279 : STATIC void
280 1481069359 : xfs_inode_item_size(
281 : struct xfs_log_item *lip,
282 : int *nvecs,
283 : int *nbytes)
284 : {
285 1481069359 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
286 1481069359 : struct xfs_inode *ip = iip->ili_inode;
287 :
288 1481069359 : *nvecs += 2;
289 2962138718 : *nbytes += sizeof(struct xfs_inode_log_format) +
290 1481069359 : xfs_log_dinode_size(ip->i_mount);
291 :
292 1481069359 : xfs_inode_item_data_fork_size(iip, nvecs, nbytes);
293 1481085773 : if (xfs_inode_has_attr_fork(ip))
294 1382180972 : xfs_inode_item_attr_fork_size(iip, nvecs, nbytes);
295 1481111183 : }
296 :
297 : STATIC void
298 1481261676 : xfs_inode_item_format_data_fork(
299 : struct xfs_inode_log_item *iip,
300 : struct xfs_inode_log_format *ilf,
301 : struct xfs_log_vec *lv,
302 : struct xfs_log_iovec **vecp)
303 : {
304 1481261676 : struct xfs_inode *ip = iip->ili_inode;
305 1481261676 : size_t data_bytes;
306 :
307 1481261676 : switch (ip->i_df.if_format) {
308 744434831 : case XFS_DINODE_FMT_EXTENTS:
309 744434831 : iip->ili_fields &=
310 : ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
311 :
312 744434831 : if ((iip->ili_fields & XFS_ILOG_DEXT) &&
313 293860623 : ip->i_df.if_nextents > 0 &&
314 266807833 : ip->i_df.if_bytes > 0) {
315 266805761 : struct xfs_bmbt_rec *p;
316 :
317 266805761 : ASSERT(xfs_iext_count(&ip->i_df) > 0);
318 :
319 266806091 : p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IEXT);
320 266813738 : data_bytes = xfs_iextents_copy(ip, p, XFS_DATA_FORK);
321 266806530 : xlog_finish_iovec(lv, *vecp, data_bytes);
322 :
323 266801271 : ASSERT(data_bytes <= ip->i_df.if_bytes);
324 :
325 266801271 : ilf->ilf_dsize = data_bytes;
326 266801271 : ilf->ilf_size++;
327 : } else {
328 477629070 : iip->ili_fields &= ~XFS_ILOG_DEXT;
329 : }
330 : break;
331 399937576 : case XFS_DINODE_FMT_BTREE:
332 399937576 : iip->ili_fields &=
333 : ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | XFS_ILOG_DEV);
334 :
335 399937576 : if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
336 291414300 : ip->i_df.if_broot_bytes > 0) {
337 291414300 : ASSERT(ip->i_df.if_broot != NULL);
338 291414300 : xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IBROOT,
339 291414300 : ip->i_df.if_broot,
340 291414300 : ip->i_df.if_broot_bytes);
341 291414128 : ilf->ilf_dsize = ip->i_df.if_broot_bytes;
342 291414128 : ilf->ilf_size++;
343 : } else {
344 108523276 : ASSERT(!(iip->ili_fields &
345 : XFS_ILOG_DBROOT));
346 108523276 : iip->ili_fields &= ~XFS_ILOG_DBROOT;
347 : }
348 : break;
349 279971119 : case XFS_DINODE_FMT_LOCAL:
350 279971119 : iip->ili_fields &=
351 : ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
352 279971119 : if ((iip->ili_fields & XFS_ILOG_DDATA) &&
353 270881035 : ip->i_df.if_bytes > 0) {
354 270881035 : ASSERT(ip->i_df.if_u1.if_data != NULL);
355 270881035 : ASSERT(ip->i_disk_size > 0);
356 270881035 : xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_ILOCAL,
357 270881035 : ip->i_df.if_u1.if_data,
358 270881035 : ip->i_df.if_bytes);
359 270882736 : ilf->ilf_dsize = (unsigned)ip->i_df.if_bytes;
360 270882736 : ilf->ilf_size++;
361 : } else {
362 9090084 : iip->ili_fields &= ~XFS_ILOG_DDATA;
363 : }
364 : break;
365 56918150 : case XFS_DINODE_FMT_DEV:
366 56918150 : iip->ili_fields &=
367 : ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEXT);
368 56918150 : if (iip->ili_fields & XFS_ILOG_DEV)
369 24704170 : ilf->ilf_u.ilfu_rdev = sysv_encode_dev(VFS_I(ip)->i_rdev);
370 : break;
371 0 : default:
372 0 : ASSERT(0);
373 0 : break;
374 : }
375 1481258715 : }
376 :
377 : STATIC void
378 1382275805 : xfs_inode_item_format_attr_fork(
379 : struct xfs_inode_log_item *iip,
380 : struct xfs_inode_log_format *ilf,
381 : struct xfs_log_vec *lv,
382 : struct xfs_log_iovec **vecp)
383 : {
384 1382275805 : struct xfs_inode *ip = iip->ili_inode;
385 1382275805 : size_t data_bytes;
386 :
387 1382275805 : switch (ip->i_af.if_format) {
388 211262616 : case XFS_DINODE_FMT_EXTENTS:
389 211262616 : iip->ili_fields &=
390 : ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
391 :
392 211262616 : if ((iip->ili_fields & XFS_ILOG_AEXT) &&
393 23066346 : ip->i_af.if_nextents > 0 &&
394 21965154 : ip->i_af.if_bytes > 0) {
395 21965312 : struct xfs_bmbt_rec *p;
396 :
397 21965312 : ASSERT(xfs_iext_count(&ip->i_af) ==
398 : ip->i_af.if_nextents);
399 :
400 21965098 : p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_EXT);
401 21965091 : data_bytes = xfs_iextents_copy(ip, p, XFS_ATTR_FORK);
402 21964698 : xlog_finish_iovec(lv, *vecp, data_bytes);
403 :
404 21964739 : ilf->ilf_asize = data_bytes;
405 21964739 : ilf->ilf_size++;
406 : } else {
407 189297304 : iip->ili_fields &= ~XFS_ILOG_AEXT;
408 : }
409 : break;
410 100198 : case XFS_DINODE_FMT_BTREE:
411 100198 : iip->ili_fields &=
412 : ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
413 :
414 100198 : if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
415 84270 : ip->i_af.if_broot_bytes > 0) {
416 84270 : ASSERT(ip->i_af.if_broot != NULL);
417 :
418 84270 : xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_BROOT,
419 84270 : ip->i_af.if_broot,
420 84270 : ip->i_af.if_broot_bytes);
421 84270 : ilf->ilf_asize = ip->i_af.if_broot_bytes;
422 84270 : ilf->ilf_size++;
423 : } else {
424 15928 : iip->ili_fields &= ~XFS_ILOG_ABROOT;
425 : }
426 : break;
427 1170912991 : case XFS_DINODE_FMT_LOCAL:
428 1170912991 : iip->ili_fields &=
429 : ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
430 :
431 1170912991 : if ((iip->ili_fields & XFS_ILOG_ADATA) &&
432 768369991 : ip->i_af.if_bytes > 0) {
433 768369991 : ASSERT(ip->i_af.if_u1.if_data != NULL);
434 768369991 : xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_LOCAL,
435 768369991 : ip->i_af.if_u1.if_data,
436 768369991 : ip->i_af.if_bytes);
437 768372666 : ilf->ilf_asize = (unsigned)ip->i_af.if_bytes;
438 768372666 : ilf->ilf_size++;
439 : } else {
440 402543000 : iip->ili_fields &= ~XFS_ILOG_ADATA;
441 : }
442 : break;
443 0 : default:
444 0 : ASSERT(0);
445 0 : break;
446 : }
447 1382277907 : }
448 :
449 : /*
450 : * Convert an incore timestamp to a log timestamp. Note that the log format
451 : * specifies host endian format!
452 : */
453 : static inline xfs_log_timestamp_t
454 : xfs_inode_to_log_dinode_ts(
455 : struct xfs_inode *ip,
456 : const struct timespec64 tv)
457 : {
458 5924610254 : struct xfs_log_legacy_timestamp *lits;
459 5924610254 : xfs_log_timestamp_t its;
460 :
461 5924610254 : if (xfs_inode_has_bigtime(ip))
462 5923930993 : return xfs_inode_encode_bigtime(tv);
463 :
464 680754 : lits = (struct xfs_log_legacy_timestamp *)&its;
465 680754 : lits->t_sec = tv.tv_sec;
466 680754 : lits->t_nsec = tv.tv_nsec;
467 :
468 680754 : return its;
469 : }
470 :
471 : /*
472 : * The legacy DMAPI fields are only present in the on-disk and in-log inodes,
473 : * but not in the in-memory one. But we are guaranteed to have an inode buffer
474 : * in memory when logging an inode, so we can just copy it from the on-disk
475 : * inode to the in-log inode here so that recovery of file system with these
476 : * fields set to non-zero values doesn't lose them. For all other cases we zero
477 : * the fields.
478 : */
479 : static void
480 1481057075 : xfs_copy_dm_fields_to_log_dinode(
481 : struct xfs_inode *ip,
482 : struct xfs_log_dinode *to)
483 : {
484 1481057075 : struct xfs_dinode *dip;
485 :
486 1481057075 : dip = xfs_buf_offset(ip->i_itemp->ili_item.li_buf,
487 1481057075 : ip->i_imap.im_boffset);
488 :
489 2962173669 : if (xfs_iflags_test(ip, XFS_IPRESERVE_DM_FIELDS)) {
490 0 : to->di_dmevmask = be32_to_cpu(dip->di_dmevmask);
491 0 : to->di_dmstate = be16_to_cpu(dip->di_dmstate);
492 : } else {
493 1481133987 : to->di_dmevmask = 0;
494 1481133987 : to->di_dmstate = 0;
495 : }
496 1481133987 : }
497 :
498 : static inline void
499 1481152573 : xfs_inode_to_log_dinode_iext_counters(
500 : struct xfs_inode *ip,
501 : struct xfs_log_dinode *to)
502 : {
503 1481152573 : if (xfs_inode_has_large_extent_counts(ip)) {
504 1480990717 : to->di_big_nextents = xfs_ifork_nextents(&ip->i_df);
505 1480990717 : to->di_big_anextents = xfs_ifork_nextents(&ip->i_af);
506 1480990717 : to->di_nrext64_pad = 0;
507 : } else {
508 161856 : to->di_nextents = xfs_ifork_nextents(&ip->i_df);
509 323712 : to->di_anextents = xfs_ifork_nextents(&ip->i_af);
510 : }
511 1481152573 : }
512 :
513 : static void
514 1481071111 : xfs_inode_to_log_dinode(
515 : struct xfs_inode *ip,
516 : struct xfs_log_dinode *to,
517 : xfs_lsn_t lsn)
518 : {
519 1481071111 : struct inode *inode = VFS_I(ip);
520 :
521 1481071111 : to->di_magic = XFS_DINODE_MAGIC;
522 1481071111 : to->di_format = xfs_ifork_format(&ip->i_df);
523 1481071111 : to->di_uid = i_uid_read(inode);
524 1481203027 : to->di_gid = i_gid_read(inode);
525 1481163953 : to->di_projid_lo = ip->i_projid & 0xffff;
526 1481163953 : to->di_projid_hi = ip->i_projid >> 16;
527 :
528 1481163953 : memset(to->di_pad3, 0, sizeof(to->di_pad3));
529 1481163953 : to->di_atime = xfs_inode_to_log_dinode_ts(ip, inode->i_atime);
530 1481163953 : to->di_mtime = xfs_inode_to_log_dinode_ts(ip, inode->i_mtime);
531 1481163953 : to->di_ctime = xfs_inode_to_log_dinode_ts(ip, inode->i_ctime);
532 1481163953 : to->di_nlink = inode->i_nlink;
533 1481163953 : to->di_gen = inode->i_generation;
534 1481163953 : to->di_mode = inode->i_mode;
535 :
536 1481163953 : to->di_size = ip->i_disk_size;
537 1481163953 : to->di_nblocks = ip->i_nblocks;
538 1481163953 : to->di_extsize = ip->i_extsize;
539 1481163953 : to->di_forkoff = ip->i_forkoff;
540 1481163953 : to->di_aformat = xfs_ifork_format(&ip->i_af);
541 1481163953 : to->di_flags = ip->i_diflags;
542 :
543 1481163953 : xfs_copy_dm_fields_to_log_dinode(ip, to);
544 :
545 : /* log a dummy value to ensure log structure is fully initialised */
546 1481119246 : to->di_next_unlinked = NULLAGINO;
547 :
548 1481119246 : if (xfs_has_v3inodes(ip->i_mount)) {
549 1481118395 : to->di_version = 3;
550 1481118395 : to->di_changecount = inode_peek_iversion(inode);
551 1481118395 : to->di_crtime = xfs_inode_to_log_dinode_ts(ip, ip->i_crtime);
552 1481118395 : to->di_flags2 = ip->i_diflags2;
553 1481118395 : to->di_cowextsize = ip->i_cowextsize;
554 1481118395 : to->di_ino = ip->i_ino;
555 1481118395 : to->di_lsn = lsn;
556 1481118395 : memset(to->di_pad2, 0, sizeof(to->di_pad2));
557 1481118395 : uuid_copy(&to->di_uuid, &ip->i_mount->m_sb.sb_meta_uuid);
558 1481177531 : to->di_v3_pad = 0;
559 : } else {
560 851 : to->di_version = 2;
561 851 : to->di_flushiter = ip->i_flushiter;
562 1702 : memset(to->di_v2_pad, 0, sizeof(to->di_v2_pad));
563 : }
564 :
565 1481178382 : xfs_inode_to_log_dinode_iext_counters(ip, to);
566 1481050596 : }
567 :
568 : /*
569 : * Format the inode core. Current timestamp data is only in the VFS inode
570 : * fields, so we need to grab them from there. Hence rather than just copying
571 : * the XFS inode core structure, format the fields directly into the iovec.
572 : */
573 : static void
574 1481028269 : xfs_inode_item_format_core(
575 : struct xfs_inode *ip,
576 : struct xfs_log_vec *lv,
577 : struct xfs_log_iovec **vecp)
578 : {
579 1481028269 : struct xfs_log_dinode *dic;
580 :
581 1481028269 : dic = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_ICORE);
582 1481089249 : xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);
583 1481089921 : xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_mount));
584 1481183513 : }
585 :
586 : /*
587 : * This is called to fill in the vector of log iovecs for the given inode
588 : * log item. It fills the first item with an inode log format structure,
589 : * the second with the on-disk inode structure, and a possible third and/or
590 : * fourth with the inode data/extents/b-tree root and inode attributes
591 : * data/extents/b-tree root.
592 : *
593 : * Note: Always use the 64 bit inode log format structure so we don't
594 : * leave an uninitialised hole in the format item on 64 bit systems. Log
595 : * recovery on 32 bit systems handles this just fine, so there's no reason
596 : * for not using an initialising the properly padded structure all the time.
597 : */
598 : STATIC void
599 1480940241 : xfs_inode_item_format(
600 : struct xfs_log_item *lip,
601 : struct xfs_log_vec *lv)
602 : {
603 1480940241 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
604 1480940241 : struct xfs_inode *ip = iip->ili_inode;
605 1480940241 : struct xfs_log_iovec *vecp = NULL;
606 1480940241 : struct xfs_inode_log_format *ilf;
607 :
608 1480940241 : ilf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_IFORMAT);
609 1480957891 : ilf->ilf_type = XFS_LI_INODE;
610 1480957891 : ilf->ilf_ino = ip->i_ino;
611 1480957891 : ilf->ilf_blkno = ip->i_imap.im_blkno;
612 1480957891 : ilf->ilf_len = ip->i_imap.im_len;
613 1480957891 : ilf->ilf_boffset = ip->i_imap.im_boffset;
614 1480957891 : ilf->ilf_fields = XFS_ILOG_CORE;
615 1480957891 : ilf->ilf_size = 2; /* format + core */
616 :
617 : /*
618 : * make sure we don't leak uninitialised data into the log in the case
619 : * when we don't log every field in the inode.
620 : */
621 1480957891 : ilf->ilf_dsize = 0;
622 1480957891 : ilf->ilf_asize = 0;
623 1480957891 : ilf->ilf_pad = 0;
624 1480957891 : memset(&ilf->ilf_u, 0, sizeof(ilf->ilf_u));
625 :
626 1480957891 : xlog_finish_iovec(lv, vecp, sizeof(*ilf));
627 :
628 1481034974 : xfs_inode_item_format_core(ip, lv, &vecp);
629 1481159945 : xfs_inode_item_format_data_fork(iip, ilf, lv, &vecp);
630 1481184796 : if (xfs_inode_has_attr_fork(ip)) {
631 1382209006 : xfs_inode_item_format_attr_fork(iip, ilf, lv, &vecp);
632 : } else {
633 98975790 : iip->ili_fields &=
634 : ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
635 : }
636 :
637 : /* update the format with the exact fields we actually logged */
638 1481166187 : ilf->ilf_fields |= (iip->ili_fields & ~XFS_ILOG_TIMESTAMP);
639 1481166187 : }
640 :
641 : /*
642 : * This is called to pin the inode associated with the inode log
643 : * item in memory so it cannot be written out.
644 : */
645 : STATIC void
646 336803221 : xfs_inode_item_pin(
647 : struct xfs_log_item *lip)
648 : {
649 336803221 : struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
650 :
651 336803221 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
652 336804753 : ASSERT(lip->li_buf);
653 :
654 336804753 : trace_xfs_inode_pin(ip, _RET_IP_);
655 336809405 : atomic_inc(&ip->i_pincount);
656 336810024 : }
657 :
658 :
659 : /*
660 : * This is called to unpin the inode associated with the inode log
661 : * item which was previously pinned with a call to xfs_inode_item_pin().
662 : *
663 : * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
664 : *
665 : * Note that unpin can race with inode cluster buffer freeing marking the buffer
666 : * stale. In that case, flush completions are run from the buffer unpin call,
667 : * which may happen before the inode is unpinned. If we lose the race, there
668 : * will be no buffer attached to the log item, but the inode will be marked
669 : * XFS_ISTALE.
670 : */
671 : STATIC void
672 336826329 : xfs_inode_item_unpin(
673 : struct xfs_log_item *lip,
674 : int remove)
675 : {
676 336826329 : struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
677 :
678 336826329 : trace_xfs_inode_unpin(ip, _RET_IP_);
679 336829717 : ASSERT(lip->li_buf || xfs_iflags_test(ip, XFS_ISTALE));
680 336826329 : ASSERT(atomic_read(&ip->i_pincount) > 0);
681 673652658 : if (atomic_dec_and_test(&ip->i_pincount))
682 323827538 : wake_up_bit(&ip->i_flags, __XFS_IPINNED_BIT);
683 336826329 : }
684 :
685 : STATIC uint
686 114957828 : xfs_inode_item_push(
687 : struct xfs_log_item *lip,
688 : struct list_head *buffer_list)
689 : __releases(&lip->li_ailp->ail_lock)
690 : __acquires(&lip->li_ailp->ail_lock)
691 : {
692 114957828 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
693 114957828 : struct xfs_inode *ip = iip->ili_inode;
694 114957828 : struct xfs_buf *bp = lip->li_buf;
695 114957828 : uint rval = XFS_ITEM_SUCCESS;
696 114957828 : int error;
697 :
698 114957828 : if (!bp || (ip->i_flags & XFS_ISTALE)) {
699 : /*
700 : * Inode item/buffer is being aborted due to cluster
701 : * buffer deletion. Trigger a log force to have that operation
702 : * completed and items removed from the AIL before the next push
703 : * attempt.
704 : */
705 : return XFS_ITEM_PINNED;
706 : }
707 :
708 114930994 : if (xfs_ipincount(ip) > 0 || xfs_buf_ispinned(bp))
709 : return XFS_ITEM_PINNED;
710 :
711 225671884 : if (xfs_iflags_test(ip, XFS_IFLUSHING))
712 : return XFS_ITEM_FLUSHING;
713 :
714 31269625 : if (!xfs_buf_trylock(bp))
715 : return XFS_ITEM_LOCKED;
716 :
717 31230729 : spin_unlock(&lip->li_ailp->ail_lock);
718 :
719 : /*
720 : * We need to hold a reference for flushing the cluster buffer as it may
721 : * fail the buffer without IO submission. In which case, we better get a
722 : * reference for that completion because otherwise we don't get a
723 : * reference for IO until we queue the buffer for delwri submission.
724 : */
725 31230729 : xfs_buf_hold(bp);
726 31230729 : error = xfs_iflush_cluster(bp);
727 31230729 : if (!error) {
728 30879392 : if (!xfs_buf_delwri_queue(bp, buffer_list))
729 762488 : rval = XFS_ITEM_FLUSHING;
730 30879392 : xfs_buf_relse(bp);
731 : } else {
732 : /*
733 : * Release the buffer if we were unable to flush anything. On
734 : * any other error, the buffer has already been released.
735 : */
736 351337 : if (error == -EAGAIN)
737 75870 : xfs_buf_relse(bp);
738 : rval = XFS_ITEM_LOCKED;
739 : }
740 :
741 31230729 : spin_lock(&lip->li_ailp->ail_lock);
742 31230729 : return rval;
743 : }
744 :
745 : /*
746 : * Unlock the inode associated with the inode log item.
747 : */
748 : STATIC void
749 2171392151 : xfs_inode_item_release(
750 : struct xfs_log_item *lip)
751 : {
752 2171392151 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
753 2171392151 : struct xfs_inode *ip = iip->ili_inode;
754 2171392151 : unsigned short lock_flags;
755 :
756 2171392151 : ASSERT(ip->i_itemp != NULL);
757 2171392151 : ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
758 :
759 2171452046 : lock_flags = iip->ili_lock_flags;
760 2171452046 : iip->ili_lock_flags = 0;
761 2171452046 : if (lock_flags)
762 161518034 : xfs_iunlock(ip, lock_flags);
763 2171450507 : }
764 :
765 : /*
766 : * This is called to find out where the oldest active copy of the inode log
767 : * item in the on disk log resides now that the last log write of it completed
768 : * at the given lsn. Since we always re-log all dirty data in an inode, the
769 : * latest copy in the on disk log is the only one that matters. Therefore,
770 : * simply return the given lsn.
771 : *
772 : * If the inode has been marked stale because the cluster is being freed, we
773 : * don't want to (re-)insert this inode into the AIL. There is a race condition
774 : * where the cluster buffer may be unpinned before the inode is inserted into
775 : * the AIL during transaction committed processing. If the buffer is unpinned
776 : * before the inode item has been committed and inserted, then it is possible
777 : * for the buffer to be written and IO completes before the inode is inserted
778 : * into the AIL. In that case, we'd be inserting a clean, stale inode into the
779 : * AIL which will never get removed. It will, however, get reclaimed which
780 : * triggers an assert in xfs_inode_free() complaining about freein an inode
781 : * still in the AIL.
782 : *
783 : * To avoid this, just unpin the inode directly and return a LSN of -1 so the
784 : * transaction committed code knows that it does not need to do any further
785 : * processing on the item.
786 : */
787 : STATIC xfs_lsn_t
788 336826329 : xfs_inode_item_committed(
789 : struct xfs_log_item *lip,
790 : xfs_lsn_t lsn)
791 : {
792 336826329 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
793 336826329 : struct xfs_inode *ip = iip->ili_inode;
794 :
795 673652658 : if (xfs_iflags_test(ip, XFS_ISTALE)) {
796 2767742 : xfs_inode_item_unpin(lip, 0);
797 2767742 : return -1;
798 : }
799 : return lsn;
800 : }
801 :
802 : STATIC void
803 1831272241 : xfs_inode_item_committing(
804 : struct xfs_log_item *lip,
805 : xfs_csn_t seq)
806 : {
807 1831272241 : INODE_ITEM(lip)->ili_commit_seq = seq;
808 1831272241 : return xfs_inode_item_release(lip);
809 : }
810 :
811 : static const struct xfs_item_ops xfs_inode_item_ops = {
812 : .iop_sort = xfs_inode_item_sort,
813 : .iop_precommit = xfs_inode_item_precommit,
814 : .iop_size = xfs_inode_item_size,
815 : .iop_format = xfs_inode_item_format,
816 : .iop_pin = xfs_inode_item_pin,
817 : .iop_unpin = xfs_inode_item_unpin,
818 : .iop_release = xfs_inode_item_release,
819 : .iop_committed = xfs_inode_item_committed,
820 : .iop_push = xfs_inode_item_push,
821 : .iop_committing = xfs_inode_item_committing,
822 : };
823 :
824 :
825 : /*
826 : * Initialize the inode log item for a newly allocated (in-core) inode.
827 : */
828 : void
829 47506876 : xfs_inode_item_init(
830 : struct xfs_inode *ip,
831 : struct xfs_mount *mp)
832 : {
833 47506876 : struct xfs_inode_log_item *iip;
834 :
835 47506876 : ASSERT(ip->i_itemp == NULL);
836 47506876 : iip = ip->i_itemp = kmem_cache_zalloc(xfs_ili_cache,
837 : GFP_KERNEL | __GFP_NOFAIL);
838 :
839 47501965 : iip->ili_inode = ip;
840 47501965 : spin_lock_init(&iip->ili_lock);
841 47503863 : xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE,
842 : &xfs_inode_item_ops);
843 47502766 : }
844 :
845 : /*
846 : * Free the inode log item and any memory hanging off of it.
847 : */
848 : void
849 47207391 : xfs_inode_item_destroy(
850 : struct xfs_inode *ip)
851 : {
852 47207391 : struct xfs_inode_log_item *iip = ip->i_itemp;
853 :
854 47207391 : ASSERT(iip->ili_item.li_buf == NULL);
855 :
856 47207391 : ip->i_itemp = NULL;
857 47207391 : kmem_free(iip->ili_item.li_lv_shadow);
858 47375288 : kmem_cache_free(xfs_ili_cache, iip);
859 47430004 : }
860 :
861 :
862 : /*
863 : * We only want to pull the item from the AIL if it is actually there
864 : * and its location in the log has not changed since we started the
865 : * flush. Thus, we only bother if the inode's lsn has not changed.
866 : */
867 : static void
868 30870756 : xfs_iflush_ail_updates(
869 : struct xfs_ail *ailp,
870 : struct list_head *list)
871 : {
872 30870756 : struct xfs_log_item *lip;
873 30870756 : xfs_lsn_t tail_lsn = 0;
874 :
875 : /* this is an opencoded batch version of xfs_trans_ail_delete */
876 30870756 : spin_lock(&ailp->ail_lock);
877 215750511 : list_for_each_entry(lip, list, li_bio_list) {
878 184879754 : xfs_lsn_t lsn;
879 :
880 184879754 : clear_bit(XFS_LI_FAILED, &lip->li_flags);
881 184879754 : if (INODE_ITEM(lip)->ili_flush_lsn != lip->li_lsn)
882 12 : continue;
883 :
884 : /*
885 : * dgc: Not sure how this happens, but it happens very
886 : * occassionaly via generic/388. xfs_iflush_abort() also
887 : * silently handles this same "under writeback but not in AIL at
888 : * shutdown" condition via xfs_trans_ail_delete().
889 : */
890 184879742 : if (!test_bit(XFS_LI_IN_AIL, &lip->li_flags)) {
891 0 : ASSERT(xlog_is_shutdown(lip->li_log));
892 0 : continue;
893 : }
894 :
895 184879742 : lsn = xfs_ail_delete_one(ailp, lip);
896 184879742 : if (!tail_lsn && lsn)
897 347209 : tail_lsn = lsn;
898 : }
899 30870757 : xfs_ail_update_finish(ailp, tail_lsn);
900 30870757 : }
901 :
902 : /*
903 : * Walk the list of inodes that have completed their IOs. If they are clean
904 : * remove them from the list and dissociate them from the buffer. Buffers that
905 : * are still dirty remain linked to the buffer and on the list. Caller must
906 : * handle them appropriately.
907 : */
908 : static void
909 31388340 : xfs_iflush_finish(
910 : struct xfs_buf *bp,
911 : struct list_head *list)
912 : {
913 31388340 : struct xfs_log_item *lip, *n;
914 :
915 216823010 : list_for_each_entry_safe(lip, n, list, li_bio_list) {
916 185434670 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
917 185434670 : bool drop_buffer = false;
918 :
919 185434670 : spin_lock(&iip->ili_lock);
920 :
921 : /*
922 : * Remove the reference to the cluster buffer if the inode is
923 : * clean in memory and drop the buffer reference once we've
924 : * dropped the locks we hold.
925 : */
926 185434670 : ASSERT(iip->ili_item.li_buf == bp);
927 185434670 : if (!iip->ili_fields) {
928 182785879 : iip->ili_item.li_buf = NULL;
929 182785879 : list_del_init(&lip->li_bio_list);
930 182785879 : drop_buffer = true;
931 : }
932 185434670 : iip->ili_last_fields = 0;
933 185434670 : iip->ili_flush_lsn = 0;
934 185434670 : spin_unlock(&iip->ili_lock);
935 185434668 : xfs_iflags_clear(iip->ili_inode, XFS_IFLUSHING);
936 185434668 : if (drop_buffer)
937 182785877 : xfs_buf_rele(bp);
938 : }
939 31388340 : }
940 :
941 : /*
942 : * Inode buffer IO completion routine. It is responsible for removing inodes
943 : * attached to the buffer from the AIL if they have not been re-logged and
944 : * completing the inode flush.
945 : */
946 : void
947 31388340 : xfs_buf_inode_iodone(
948 : struct xfs_buf *bp)
949 : {
950 31388340 : struct xfs_log_item *lip, *n;
951 31388340 : LIST_HEAD(flushed_inodes);
952 31388340 : LIST_HEAD(ail_updates);
953 :
954 : /*
955 : * Pull the attached inodes from the buffer one at a time and take the
956 : * appropriate action on them.
957 : */
958 228085388 : list_for_each_entry_safe(lip, n, &bp->b_li_list, li_bio_list) {
959 196697049 : struct xfs_inode_log_item *iip = INODE_ITEM(lip);
960 :
961 393394113 : if (xfs_iflags_test(iip->ili_inode, XFS_ISTALE)) {
962 3143910 : xfs_iflush_abort(iip->ili_inode);
963 3143910 : continue;
964 : }
965 193553154 : if (!iip->ili_last_fields)
966 8118501 : continue;
967 :
968 : /* Do an unlocked check for needing the AIL lock. */
969 185989569 : if (iip->ili_flush_lsn == lip->li_lsn ||
970 554916 : test_bit(XFS_LI_FAILED, &lip->li_flags))
971 184879737 : list_move_tail(&lip->li_bio_list, &ail_updates);
972 : else
973 554916 : list_move_tail(&lip->li_bio_list, &flushed_inodes);
974 : }
975 :
976 31388339 : if (!list_empty(&ail_updates)) {
977 30870756 : xfs_iflush_ail_updates(bp->b_mount->m_ail, &ail_updates);
978 30870757 : list_splice_tail(&ail_updates, &flushed_inodes);
979 : }
980 :
981 31388340 : xfs_iflush_finish(bp, &flushed_inodes);
982 31388340 : if (!list_empty(&flushed_inodes))
983 1582927 : list_splice_tail(&flushed_inodes, &bp->b_li_list);
984 31388340 : }
985 :
986 : void
987 0 : xfs_buf_inode_io_fail(
988 : struct xfs_buf *bp)
989 : {
990 0 : struct xfs_log_item *lip;
991 :
992 0 : list_for_each_entry(lip, &bp->b_li_list, li_bio_list)
993 0 : set_bit(XFS_LI_FAILED, &lip->li_flags);
994 0 : }
995 :
996 : /*
997 : * Clear the inode logging fields so no more flushes are attempted. If we are
998 : * on a buffer list, it is now safe to remove it because the buffer is
999 : * guaranteed to be locked. The caller will drop the reference to the buffer
1000 : * the log item held.
1001 : */
1002 : static void
1003 5274747 : xfs_iflush_abort_clean(
1004 : struct xfs_inode_log_item *iip)
1005 : {
1006 5274747 : iip->ili_last_fields = 0;
1007 5274747 : iip->ili_fields = 0;
1008 5274747 : iip->ili_fsync_fields = 0;
1009 5274747 : iip->ili_flush_lsn = 0;
1010 5274747 : iip->ili_item.li_buf = NULL;
1011 5274747 : list_del_init(&iip->ili_item.li_bio_list);
1012 5274747 : }
1013 :
1014 : /*
1015 : * Abort flushing the inode from a context holding the cluster buffer locked.
1016 : *
1017 : * This is the normal runtime method of aborting writeback of an inode that is
1018 : * attached to a cluster buffer. It occurs when the inode and the backing
1019 : * cluster buffer have been freed (i.e. inode is XFS_ISTALE), or when cluster
1020 : * flushing or buffer IO completion encounters a log shutdown situation.
1021 : *
1022 : * If we need to abort inode writeback and we don't already hold the buffer
1023 : * locked, call xfs_iflush_shutdown_abort() instead as this should only ever be
1024 : * necessary in a shutdown situation.
1025 : */
1026 : void
1027 5274747 : xfs_iflush_abort(
1028 : struct xfs_inode *ip)
1029 : {
1030 5274747 : struct xfs_inode_log_item *iip = ip->i_itemp;
1031 5274747 : struct xfs_buf *bp;
1032 :
1033 5274747 : if (!iip) {
1034 : /* clean inode, nothing to do */
1035 0 : xfs_iflags_clear(ip, XFS_IFLUSHING);
1036 0 : return;
1037 : }
1038 :
1039 : /*
1040 : * Remove the inode item from the AIL before we clear its internal
1041 : * state. Whilst the inode is in the AIL, it should have a valid buffer
1042 : * pointer for push operations to access - it is only safe to remove the
1043 : * inode from the buffer once it has been removed from the AIL.
1044 : *
1045 : * We also clear the failed bit before removing the item from the AIL
1046 : * as xfs_trans_ail_delete()->xfs_clear_li_failed() will release buffer
1047 : * references the inode item owns and needs to hold until we've fully
1048 : * aborted the inode log item and detached it from the buffer.
1049 : */
1050 5274747 : clear_bit(XFS_LI_FAILED, &iip->ili_item.li_flags);
1051 5274747 : xfs_trans_ail_delete(&iip->ili_item, 0);
1052 :
1053 : /*
1054 : * Grab the inode buffer so can we release the reference the inode log
1055 : * item holds on it.
1056 : */
1057 5274747 : spin_lock(&iip->ili_lock);
1058 5274747 : bp = iip->ili_item.li_buf;
1059 5274747 : xfs_iflush_abort_clean(iip);
1060 5274747 : spin_unlock(&iip->ili_lock);
1061 :
1062 5274747 : xfs_iflags_clear(ip, XFS_IFLUSHING);
1063 5274747 : if (bp)
1064 4184819 : xfs_buf_rele(bp);
1065 : }
1066 :
1067 : /*
1068 : * Abort an inode flush in the case of a shutdown filesystem. This can be called
1069 : * from anywhere with just an inode reference and does not require holding the
1070 : * inode cluster buffer locked. If the inode is attached to a cluster buffer,
1071 : * it will grab and lock it safely, then abort the inode flush.
1072 : */
1073 : void
1074 293787254 : xfs_iflush_shutdown_abort(
1075 : struct xfs_inode *ip)
1076 : {
1077 293787254 : struct xfs_inode_log_item *iip = ip->i_itemp;
1078 293787254 : struct xfs_buf *bp;
1079 :
1080 293787254 : if (!iip) {
1081 : /* clean inode, nothing to do */
1082 292657099 : xfs_iflags_clear(ip, XFS_IFLUSHING);
1083 292657099 : return;
1084 : }
1085 :
1086 1130155 : spin_lock(&iip->ili_lock);
1087 1130155 : bp = iip->ili_item.li_buf;
1088 1130155 : if (!bp) {
1089 1089928 : spin_unlock(&iip->ili_lock);
1090 1089928 : xfs_iflush_abort(ip);
1091 1089928 : return;
1092 : }
1093 :
1094 : /*
1095 : * We have to take a reference to the buffer so that it doesn't get
1096 : * freed when we drop the ili_lock and then wait to lock the buffer.
1097 : * We'll clean up the extra reference after we pick up the ili_lock
1098 : * again.
1099 : */
1100 40227 : xfs_buf_hold(bp);
1101 40227 : spin_unlock(&iip->ili_lock);
1102 40227 : xfs_buf_lock(bp);
1103 :
1104 40227 : spin_lock(&iip->ili_lock);
1105 40227 : if (!iip->ili_item.li_buf) {
1106 : /*
1107 : * Raced with another removal, hold the only reference
1108 : * to bp now. Inode should not be in the AIL now, so just clean
1109 : * up and return;
1110 : */
1111 0 : ASSERT(list_empty(&iip->ili_item.li_bio_list));
1112 0 : ASSERT(!test_bit(XFS_LI_IN_AIL, &iip->ili_item.li_flags));
1113 0 : xfs_iflush_abort_clean(iip);
1114 0 : spin_unlock(&iip->ili_lock);
1115 0 : xfs_iflags_clear(ip, XFS_IFLUSHING);
1116 0 : xfs_buf_relse(bp);
1117 0 : return;
1118 : }
1119 :
1120 : /*
1121 : * Got two references to bp. The first will get dropped by
1122 : * xfs_iflush_abort() when the item is removed from the buffer list, but
1123 : * we can't drop our reference until _abort() returns because we have to
1124 : * unlock the buffer as well. Hence we abort and then unlock and release
1125 : * our reference to the buffer.
1126 : */
1127 40227 : ASSERT(iip->ili_item.li_buf == bp);
1128 40227 : spin_unlock(&iip->ili_lock);
1129 40227 : xfs_iflush_abort(ip);
1130 40227 : xfs_buf_relse(bp);
1131 : }
1132 :
1133 :
1134 : /*
1135 : * convert an xfs_inode_log_format struct from the old 32 bit version
1136 : * (which can have different field alignments) to the native 64 bit version
1137 : */
1138 : int
1139 0 : xfs_inode_item_format_convert(
1140 : struct xfs_log_iovec *buf,
1141 : struct xfs_inode_log_format *in_f)
1142 : {
1143 0 : struct xfs_inode_log_format_32 *in_f32 = buf->i_addr;
1144 :
1145 0 : if (buf->i_len != sizeof(*in_f32)) {
1146 0 : XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
1147 0 : return -EFSCORRUPTED;
1148 : }
1149 :
1150 0 : in_f->ilf_type = in_f32->ilf_type;
1151 0 : in_f->ilf_size = in_f32->ilf_size;
1152 0 : in_f->ilf_fields = in_f32->ilf_fields;
1153 0 : in_f->ilf_asize = in_f32->ilf_asize;
1154 0 : in_f->ilf_dsize = in_f32->ilf_dsize;
1155 0 : in_f->ilf_ino = in_f32->ilf_ino;
1156 0 : memcpy(&in_f->ilf_u, &in_f32->ilf_u, sizeof(in_f->ilf_u));
1157 0 : in_f->ilf_blkno = in_f32->ilf_blkno;
1158 0 : in_f->ilf_len = in_f32->ilf_len;
1159 0 : in_f->ilf_boffset = in_f32->ilf_boffset;
1160 0 : return 0;
1161 : }
|