LCOV - code coverage report
Current view: top level - fs/xfs - xfs_inode_item_recover.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc4-xfsa @ Mon Jul 31 20:08:27 PDT 2023 Lines: 168 266 63.2 %
Date: 2023-07-31 20:08:27 Functions: 7 8 87.5 %

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

Generated by: LCOV version 1.14