1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2006 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_error.h"
21 #include "xfs_log_priv.h"
22 #include "xfs_log_recover.h"
23 #include "xfs_icache.h"
24 #include "xfs_bmap_btree.h"
25 #include "xfs_rtrmap_btree.h"
26 #include "xfs_rtrefcount_btree.h"
27
28 STATIC void
xlog_recover_inode_ra_pass2(struct xlog * log,struct xlog_recover_item * item)29 xlog_recover_inode_ra_pass2(
30 struct xlog *log,
31 struct xlog_recover_item *item)
32 {
33 if (item->ri_buf[0].i_len == sizeof(struct xfs_inode_log_format)) {
34 struct xfs_inode_log_format *ilfp = item->ri_buf[0].i_addr;
35
36 xlog_buf_readahead(log, ilfp->ilf_blkno, ilfp->ilf_len,
37 &xfs_inode_buf_ra_ops);
38 } else {
39 struct xfs_inode_log_format_32 *ilfp = item->ri_buf[0].i_addr;
40
41 xlog_buf_readahead(log, ilfp->ilf_blkno, ilfp->ilf_len,
42 &xfs_inode_buf_ra_ops);
43 }
44 }
45
46 /*
47 * Inode fork owner changes
48 *
49 * If we have been told that we have to reparent the inode fork, it's because an
50 * extent swap operation on a CRC enabled filesystem has been done and we are
51 * replaying it. We need to walk the BMBT of the appropriate fork and change the
52 * owners of it.
53 *
54 * The complexity here is that we don't have an inode context to work with, so
55 * after we've replayed the inode we need to instantiate one. This is where the
56 * fun begins.
57 *
58 * We are in the middle of log recovery, so we can't run transactions. That
59 * means we cannot use cache coherent inode instantiation via xfs_iget(), as
60 * that will result in the corresponding iput() running the inode through
61 * xfs_inactive(). If we've just replayed an inode core that changes the link
62 * count to zero (i.e. it's been unlinked), then xfs_inactive() will run
63 * transactions (bad!).
64 *
65 * So, to avoid this, we instantiate an inode directly from the inode core we've
66 * just recovered. We have the buffer still locked, and all we really need to
67 * instantiate is the inode core and the forks being modified. We can do this
68 * manually, then run the inode btree owner change, and then tear down the
69 * xfs_inode without having to run any transactions at all.
70 *
71 * Also, because we don't have a transaction context available here but need to
72 * gather all the buffers we modify for writeback so we pass the buffer_list
73 * instead for the operation to use.
74 */
75
76 STATIC int
xfs_recover_inode_owner_change(struct xfs_mount * mp,struct xfs_dinode * dip,struct xfs_inode_log_format * in_f,struct list_head * buffer_list)77 xfs_recover_inode_owner_change(
78 struct xfs_mount *mp,
79 struct xfs_dinode *dip,
80 struct xfs_inode_log_format *in_f,
81 struct list_head *buffer_list)
82 {
83 struct xfs_inode *ip;
84 int error;
85
86 ASSERT(in_f->ilf_fields & (XFS_ILOG_DOWNER|XFS_ILOG_AOWNER));
87
88 ip = xfs_inode_alloc(mp, in_f->ilf_ino);
89 if (!ip)
90 return -ENOMEM;
91
92 /* instantiate the inode */
93 ASSERT(dip->di_version >= 3);
94
95 error = xfs_inode_from_disk(ip, dip);
96 if (error)
97 goto out_free_ip;
98
99 if (in_f->ilf_fields & XFS_ILOG_DOWNER) {
100 ASSERT(in_f->ilf_fields & XFS_ILOG_DBROOT);
101 error = xfs_bmbt_change_owner(NULL, ip, XFS_DATA_FORK,
102 ip->i_ino, buffer_list);
103 if (error)
104 goto out_free_ip;
105 }
106
107 if (in_f->ilf_fields & XFS_ILOG_AOWNER) {
108 ASSERT(in_f->ilf_fields & XFS_ILOG_ABROOT);
109 error = xfs_bmbt_change_owner(NULL, ip, XFS_ATTR_FORK,
110 ip->i_ino, buffer_list);
111 if (error)
112 goto out_free_ip;
113 }
114
115 out_free_ip:
116 xfs_inode_free(ip);
117 return error;
118 }
119
xfs_log_dinode_has_bigtime(const struct xfs_log_dinode * ld)120 static inline bool xfs_log_dinode_has_bigtime(const struct xfs_log_dinode *ld)
121 {
122 return ld->di_version >= 3 &&
123 (ld->di_flags2 & XFS_DIFLAG2_BIGTIME);
124 }
125
126 /* Convert a log timestamp to an ondisk timestamp. */
127 static inline xfs_timestamp_t
xfs_log_dinode_to_disk_ts(struct xfs_log_dinode * from,const xfs_log_timestamp_t its)128 xfs_log_dinode_to_disk_ts(
129 struct xfs_log_dinode *from,
130 const xfs_log_timestamp_t its)
131 {
132 struct xfs_legacy_timestamp *lts;
133 struct xfs_log_legacy_timestamp *lits;
134 xfs_timestamp_t ts;
135
136 if (xfs_log_dinode_has_bigtime(from))
137 return cpu_to_be64(its);
138
139 lts = (struct xfs_legacy_timestamp *)&ts;
140 lits = (struct xfs_log_legacy_timestamp *)&its;
141 lts->t_sec = cpu_to_be32(lits->t_sec);
142 lts->t_nsec = cpu_to_be32(lits->t_nsec);
143
144 return ts;
145 }
146
xfs_log_dinode_has_large_extent_counts(const struct xfs_log_dinode * ld)147 static inline bool xfs_log_dinode_has_large_extent_counts(
148 const struct xfs_log_dinode *ld)
149 {
150 return ld->di_version >= 3 &&
151 (ld->di_flags2 & XFS_DIFLAG2_NREXT64);
152 }
153
154 static inline void
xfs_log_dinode_to_disk_iext_counters(struct xfs_log_dinode * from,struct xfs_dinode * to)155 xfs_log_dinode_to_disk_iext_counters(
156 struct xfs_log_dinode *from,
157 struct xfs_dinode *to)
158 {
159 if (xfs_log_dinode_has_large_extent_counts(from)) {
160 to->di_big_nextents = cpu_to_be64(from->di_big_nextents);
161 to->di_big_anextents = cpu_to_be32(from->di_big_anextents);
162 to->di_nrext64_pad = cpu_to_be16(from->di_nrext64_pad);
163 } else {
164 to->di_nextents = cpu_to_be32(from->di_nextents);
165 to->di_anextents = cpu_to_be16(from->di_anextents);
166 }
167
168 }
169
170 STATIC void
xfs_log_dinode_to_disk(struct xfs_log_dinode * from,struct xfs_dinode * to,xfs_lsn_t lsn)171 xfs_log_dinode_to_disk(
172 struct xfs_log_dinode *from,
173 struct xfs_dinode *to,
174 xfs_lsn_t lsn)
175 {
176 to->di_magic = cpu_to_be16(from->di_magic);
177 to->di_mode = cpu_to_be16(from->di_mode);
178 to->di_version = from->di_version;
179 to->di_format = from->di_format;
180 to->di_metatype = cpu_to_be16(from->di_metatype);
181 to->di_uid = cpu_to_be32(from->di_uid);
182 to->di_gid = cpu_to_be32(from->di_gid);
183 to->di_nlink = cpu_to_be32(from->di_nlink);
184 to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
185 to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
186
187 to->di_atime = xfs_log_dinode_to_disk_ts(from, from->di_atime);
188 to->di_mtime = xfs_log_dinode_to_disk_ts(from, from->di_mtime);
189 to->di_ctime = xfs_log_dinode_to_disk_ts(from, from->di_ctime);
190
191 to->di_size = cpu_to_be64(from->di_size);
192 to->di_nblocks = cpu_to_be64(from->di_nblocks);
193 to->di_extsize = cpu_to_be32(from->di_extsize);
194 to->di_forkoff = from->di_forkoff;
195 to->di_aformat = from->di_aformat;
196 to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
197 to->di_dmstate = cpu_to_be16(from->di_dmstate);
198 to->di_flags = cpu_to_be16(from->di_flags);
199 to->di_gen = cpu_to_be32(from->di_gen);
200
201 if (from->di_version == 3) {
202 to->di_changecount = cpu_to_be64(from->di_changecount);
203 to->di_crtime = xfs_log_dinode_to_disk_ts(from,
204 from->di_crtime);
205 to->di_flags2 = cpu_to_be64(from->di_flags2);
206 /* also covers the di_used_blocks union arm: */
207 to->di_cowextsize = cpu_to_be32(from->di_cowextsize);
208 to->di_ino = cpu_to_be64(from->di_ino);
209 to->di_lsn = cpu_to_be64(lsn);
210 memset(to->di_pad2, 0, sizeof(to->di_pad2));
211 uuid_copy(&to->di_uuid, &from->di_uuid);
212 to->di_v3_pad = 0;
213 } else {
214 to->di_flushiter = cpu_to_be16(from->di_flushiter);
215 memset(to->di_v2_pad, 0, sizeof(to->di_v2_pad));
216 }
217
218 xfs_log_dinode_to_disk_iext_counters(from, to);
219 }
220
221 STATIC int
xlog_dinode_verify_extent_counts(struct xfs_mount * mp,struct xfs_log_dinode * ldip)222 xlog_dinode_verify_extent_counts(
223 struct xfs_mount *mp,
224 struct xfs_log_dinode *ldip)
225 {
226 xfs_extnum_t nextents;
227 xfs_aextnum_t anextents;
228
229 if (xfs_log_dinode_has_large_extent_counts(ldip)) {
230 if (!xfs_has_large_extent_counts(mp) ||
231 (ldip->di_nrext64_pad != 0)) {
232 XFS_CORRUPTION_ERROR(
233 "Bad log dinode large extent count format",
234 XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip));
235 xfs_alert(mp,
236 "Bad inode 0x%llx, large extent counts %d, padding 0x%x",
237 ldip->di_ino, xfs_has_large_extent_counts(mp),
238 ldip->di_nrext64_pad);
239 return -EFSCORRUPTED;
240 }
241
242 nextents = ldip->di_big_nextents;
243 anextents = ldip->di_big_anextents;
244 } else {
245 if (ldip->di_version == 3 && ldip->di_v3_pad != 0) {
246 XFS_CORRUPTION_ERROR(
247 "Bad log dinode di_v3_pad",
248 XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip));
249 xfs_alert(mp,
250 "Bad inode 0x%llx, di_v3_pad 0x%llx",
251 ldip->di_ino, ldip->di_v3_pad);
252 return -EFSCORRUPTED;
253 }
254
255 nextents = ldip->di_nextents;
256 anextents = ldip->di_anextents;
257 }
258
259 if (unlikely(nextents + anextents > ldip->di_nblocks)) {
260 XFS_CORRUPTION_ERROR("Bad log dinode extent counts",
261 XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip));
262 xfs_alert(mp,
263 "Bad inode 0x%llx, large extent counts %d, nextents 0x%llx, anextents 0x%x, nblocks 0x%llx",
264 ldip->di_ino, xfs_has_large_extent_counts(mp), nextents,
265 anextents, ldip->di_nblocks);
266 return -EFSCORRUPTED;
267 }
268
269 return 0;
270 }
271
272 static inline int
xlog_recover_inode_dbroot(struct xfs_mount * mp,void * src,unsigned int len,struct xfs_dinode * dip)273 xlog_recover_inode_dbroot(
274 struct xfs_mount *mp,
275 void *src,
276 unsigned int len,
277 struct xfs_dinode *dip)
278 {
279 void *dfork = XFS_DFORK_DPTR(dip);
280 unsigned int dsize = XFS_DFORK_DSIZE(dip, mp);
281
282 switch (dip->di_format) {
283 case XFS_DINODE_FMT_BTREE:
284 xfs_bmbt_to_bmdr(mp, src, len, dfork, dsize);
285 break;
286 case XFS_DINODE_FMT_META_BTREE:
287 switch (be16_to_cpu(dip->di_metatype)) {
288 case XFS_METAFILE_RTRMAP:
289 xfs_rtrmapbt_to_disk(mp, src, len, dfork, dsize);
290 return 0;
291 case XFS_METAFILE_RTREFCOUNT:
292 xfs_rtrefcountbt_to_disk(mp, src, len, dfork, dsize);
293 return 0;
294 default:
295 ASSERT(0);
296 return -EFSCORRUPTED;
297 }
298 break;
299 default:
300 ASSERT(0);
301 return -EFSCORRUPTED;
302 }
303
304 return 0;
305 }
306
307 STATIC int
xlog_recover_inode_commit_pass2(struct xlog * log,struct list_head * buffer_list,struct xlog_recover_item * item,xfs_lsn_t current_lsn)308 xlog_recover_inode_commit_pass2(
309 struct xlog *log,
310 struct list_head *buffer_list,
311 struct xlog_recover_item *item,
312 xfs_lsn_t current_lsn)
313 {
314 struct xfs_inode_log_format *in_f;
315 struct xfs_mount *mp = log->l_mp;
316 struct xfs_buf *bp;
317 struct xfs_dinode *dip;
318 int len;
319 char *src;
320 char *dest;
321 int error;
322 int attr_index;
323 uint fields;
324 struct xfs_log_dinode *ldip;
325 uint isize;
326 int need_free = 0;
327 xfs_failaddr_t fa;
328
329 if (item->ri_buf[0].i_len == sizeof(struct xfs_inode_log_format)) {
330 in_f = item->ri_buf[0].i_addr;
331 } else {
332 in_f = kmalloc(sizeof(struct xfs_inode_log_format),
333 GFP_KERNEL | __GFP_NOFAIL);
334 need_free = 1;
335 error = xfs_inode_item_format_convert(&item->ri_buf[0], in_f);
336 if (error)
337 goto error;
338 }
339
340 /*
341 * Inode buffers can be freed, look out for it,
342 * and do not replay the inode.
343 */
344 if (xlog_is_buffer_cancelled(log, in_f->ilf_blkno, in_f->ilf_len)) {
345 error = 0;
346 trace_xfs_log_recover_inode_cancel(log, in_f);
347 goto error;
348 }
349 trace_xfs_log_recover_inode_recover(log, in_f);
350
351 error = xfs_buf_read(mp->m_ddev_targp, in_f->ilf_blkno, in_f->ilf_len,
352 0, &bp, &xfs_inode_buf_ops);
353 if (error)
354 goto error;
355 ASSERT(in_f->ilf_fields & XFS_ILOG_CORE);
356 dip = xfs_buf_offset(bp, in_f->ilf_boffset);
357
358 /*
359 * Make sure the place we're flushing out to really looks
360 * like an inode!
361 */
362 if (XFS_IS_CORRUPT(mp, !xfs_verify_magic16(bp, dip->di_magic))) {
363 xfs_alert(mp,
364 "%s: Bad inode magic number, dip = "PTR_FMT", dino bp = "PTR_FMT", ino = %lld",
365 __func__, dip, bp, in_f->ilf_ino);
366 error = -EFSCORRUPTED;
367 goto out_release;
368 }
369 ldip = item->ri_buf[1].i_addr;
370 if (XFS_IS_CORRUPT(mp, ldip->di_magic != XFS_DINODE_MAGIC)) {
371 xfs_alert(mp,
372 "%s: Bad inode log record, rec ptr "PTR_FMT", ino %lld",
373 __func__, item, in_f->ilf_ino);
374 error = -EFSCORRUPTED;
375 goto out_release;
376 }
377
378 /*
379 * If the inode has an LSN in it, recover the inode only if the on-disk
380 * inode's LSN is older than the lsn of the transaction we are
381 * replaying. We can have multiple checkpoints with the same start LSN,
382 * so the current LSN being equal to the on-disk LSN doesn't necessarily
383 * mean that the on-disk inode is more recent than the change being
384 * replayed.
385 *
386 * We must check the current_lsn against the on-disk inode
387 * here because the we can't trust the log dinode to contain a valid LSN
388 * (see comment below before replaying the log dinode for details).
389 *
390 * Note: we still need to replay an owner change even though the inode
391 * is more recent than the transaction as there is no guarantee that all
392 * the btree blocks are more recent than this transaction, too.
393 */
394 if (dip->di_version >= 3) {
395 xfs_lsn_t lsn = be64_to_cpu(dip->di_lsn);
396
397 if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) > 0) {
398 trace_xfs_log_recover_inode_skip(log, in_f);
399 error = 0;
400 goto out_owner_change;
401 }
402 }
403
404 /*
405 * di_flushiter is only valid for v1/2 inodes. All changes for v3 inodes
406 * are transactional and if ordering is necessary we can determine that
407 * more accurately by the LSN field in the V3 inode core. Don't trust
408 * the inode versions we might be changing them here - use the
409 * superblock flag to determine whether we need to look at di_flushiter
410 * to skip replay when the on disk inode is newer than the log one
411 */
412 if (!xfs_has_v3inodes(mp)) {
413 if (ldip->di_flushiter < be16_to_cpu(dip->di_flushiter)) {
414 /*
415 * Deal with the wrap case, DI_MAX_FLUSH is less
416 * than smaller numbers
417 */
418 if (be16_to_cpu(dip->di_flushiter) == DI_MAX_FLUSH &&
419 ldip->di_flushiter < (DI_MAX_FLUSH >> 1)) {
420 /* do nothing */
421 } else {
422 trace_xfs_log_recover_inode_skip(log, in_f);
423 error = 0;
424 goto out_release;
425 }
426 }
427
428 /* Take the opportunity to reset the flush iteration count */
429 ldip->di_flushiter = 0;
430 }
431
432
433 if (unlikely(S_ISREG(ldip->di_mode))) {
434 if (ldip->di_format != XFS_DINODE_FMT_EXTENTS &&
435 ldip->di_format != XFS_DINODE_FMT_BTREE &&
436 ldip->di_format != XFS_DINODE_FMT_META_BTREE) {
437 XFS_CORRUPTION_ERROR(
438 "Bad log dinode data fork format for regular file",
439 XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip));
440 xfs_alert(mp,
441 "Bad inode 0x%llx, data fork format 0x%x",
442 in_f->ilf_ino, ldip->di_format);
443 error = -EFSCORRUPTED;
444 goto out_release;
445 }
446 } else if (unlikely(S_ISDIR(ldip->di_mode))) {
447 if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) &&
448 (ldip->di_format != XFS_DINODE_FMT_BTREE) &&
449 (ldip->di_format != XFS_DINODE_FMT_LOCAL)) {
450 XFS_CORRUPTION_ERROR(
451 "Bad log dinode data fork format for directory",
452 XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip));
453 xfs_alert(mp,
454 "Bad inode 0x%llx, data fork format 0x%x",
455 in_f->ilf_ino, ldip->di_format);
456 error = -EFSCORRUPTED;
457 goto out_release;
458 }
459 }
460
461 error = xlog_dinode_verify_extent_counts(mp, ldip);
462 if (error)
463 goto out_release;
464
465 if (unlikely(ldip->di_forkoff > mp->m_sb.sb_inodesize)) {
466 XFS_CORRUPTION_ERROR("Bad log dinode fork offset",
467 XFS_ERRLEVEL_LOW, mp, ldip, sizeof(*ldip));
468 xfs_alert(mp,
469 "Bad inode 0x%llx, di_forkoff 0x%x",
470 in_f->ilf_ino, ldip->di_forkoff);
471 error = -EFSCORRUPTED;
472 goto out_release;
473 }
474 isize = xfs_log_dinode_size(mp);
475 if (unlikely(item->ri_buf[1].i_len > isize)) {
476 XFS_CORRUPTION_ERROR("Bad log dinode size", XFS_ERRLEVEL_LOW,
477 mp, ldip, sizeof(*ldip));
478 xfs_alert(mp,
479 "Bad inode 0x%llx log dinode size 0x%x",
480 in_f->ilf_ino, item->ri_buf[1].i_len);
481 error = -EFSCORRUPTED;
482 goto out_release;
483 }
484
485 /*
486 * Recover the log dinode inode into the on disk inode.
487 *
488 * The LSN in the log dinode is garbage - it can be zero or reflect
489 * stale in-memory runtime state that isn't coherent with the changes
490 * logged in this transaction or the changes written to the on-disk
491 * inode. Hence we write the current lSN into the inode because that
492 * matches what xfs_iflush() would write inode the inode when flushing
493 * the changes in this transaction.
494 */
495 xfs_log_dinode_to_disk(ldip, dip, current_lsn);
496
497 fields = in_f->ilf_fields;
498 if (fields & XFS_ILOG_DEV)
499 xfs_dinode_put_rdev(dip, in_f->ilf_u.ilfu_rdev);
500
501 if (in_f->ilf_size == 2)
502 goto out_owner_change;
503 len = item->ri_buf[2].i_len;
504 src = item->ri_buf[2].i_addr;
505 ASSERT(in_f->ilf_size <= 4);
506 ASSERT((in_f->ilf_size == 3) || (fields & XFS_ILOG_AFORK));
507 ASSERT(!(fields & XFS_ILOG_DFORK) ||
508 (len == xlog_calc_iovec_len(in_f->ilf_dsize)));
509
510 switch (fields & XFS_ILOG_DFORK) {
511 case XFS_ILOG_DDATA:
512 case XFS_ILOG_DEXT:
513 memcpy(XFS_DFORK_DPTR(dip), src, len);
514 break;
515
516 case XFS_ILOG_DBROOT:
517 error = xlog_recover_inode_dbroot(mp, src, len, dip);
518 if (error)
519 goto out_release;
520 break;
521
522 default:
523 /*
524 * There are no data fork flags set.
525 */
526 ASSERT((fields & XFS_ILOG_DFORK) == 0);
527 break;
528 }
529
530 /*
531 * If we logged any attribute data, recover it. There may or
532 * may not have been any other non-core data logged in this
533 * transaction.
534 */
535 if (in_f->ilf_fields & XFS_ILOG_AFORK) {
536 if (in_f->ilf_fields & XFS_ILOG_DFORK) {
537 attr_index = 3;
538 } else {
539 attr_index = 2;
540 }
541 len = item->ri_buf[attr_index].i_len;
542 src = item->ri_buf[attr_index].i_addr;
543 ASSERT(len == xlog_calc_iovec_len(in_f->ilf_asize));
544
545 switch (in_f->ilf_fields & XFS_ILOG_AFORK) {
546 case XFS_ILOG_ADATA:
547 case XFS_ILOG_AEXT:
548 dest = XFS_DFORK_APTR(dip);
549 ASSERT(len <= XFS_DFORK_ASIZE(dip, mp));
550 memcpy(dest, src, len);
551 break;
552
553 case XFS_ILOG_ABROOT:
554 dest = XFS_DFORK_APTR(dip);
555 xfs_bmbt_to_bmdr(mp, (struct xfs_btree_block *)src,
556 len, (struct xfs_bmdr_block *)dest,
557 XFS_DFORK_ASIZE(dip, mp));
558 break;
559
560 default:
561 xfs_warn(log->l_mp, "%s: Invalid flag", __func__);
562 ASSERT(0);
563 error = -EFSCORRUPTED;
564 goto out_release;
565 }
566 }
567
568 out_owner_change:
569 /* Recover the swapext owner change unless inode has been deleted */
570 if ((in_f->ilf_fields & (XFS_ILOG_DOWNER|XFS_ILOG_AOWNER)) &&
571 (dip->di_mode != 0))
572 error = xfs_recover_inode_owner_change(mp, dip, in_f,
573 buffer_list);
574 /* re-generate the checksum and validate the recovered inode. */
575 xfs_dinode_calc_crc(log->l_mp, dip);
576 fa = xfs_dinode_verify(log->l_mp, in_f->ilf_ino, dip);
577 if (fa) {
578 XFS_CORRUPTION_ERROR(
579 "Bad dinode after recovery",
580 XFS_ERRLEVEL_LOW, mp, dip, sizeof(*dip));
581 xfs_alert(mp,
582 "Metadata corruption detected at %pS, inode 0x%llx",
583 fa, in_f->ilf_ino);
584 error = -EFSCORRUPTED;
585 goto out_release;
586 }
587
588 ASSERT(bp->b_mount == mp);
589 bp->b_flags |= _XBF_LOGRECOVERY;
590 xfs_buf_delwri_queue(bp, buffer_list);
591
592 out_release:
593 xfs_buf_relse(bp);
594 error:
595 if (need_free)
596 kfree(in_f);
597 return error;
598 }
599
600 const struct xlog_recover_item_ops xlog_inode_item_ops = {
601 .item_type = XFS_LI_INODE,
602 .ra_pass2 = xlog_recover_inode_ra_pass2,
603 .commit_pass2 = xlog_recover_inode_commit_pass2,
604 };
605