LCOV - code coverage report
Current view: top level - fs/xfs - xfs_fsmap.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc3-djwx @ Mon Jul 31 20:08:22 PDT 2023 Lines: 437 458 95.4 %
Date: 2023-07-31 20:08:22 Functions: 23 23 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0+
       2             : /*
       3             :  * Copyright (C) 2017 Oracle.  All Rights Reserved.
       4             :  * Author: Darrick J. Wong <darrick.wong@oracle.com>
       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_btree.h"
      16             : #include "xfs_rmap_btree.h"
      17             : #include "xfs_trace.h"
      18             : #include "xfs_rmap.h"
      19             : #include "xfs_alloc.h"
      20             : #include "xfs_bit.h"
      21             : #include <linux/fsmap.h>
      22             : #include "xfs_fsmap.h"
      23             : #include "xfs_refcount.h"
      24             : #include "xfs_refcount_btree.h"
      25             : #include "xfs_alloc_btree.h"
      26             : #include "xfs_rtalloc.h"
      27             : #include "xfs_ag.h"
      28             : 
      29             : /* Convert an xfs_fsmap to an fsmap. */
      30             : static void
      31   248608565 : xfs_fsmap_from_internal(
      32             :         struct fsmap            *dest,
      33             :         struct xfs_fsmap        *src)
      34             : {
      35   248608565 :         dest->fmr_device = src->fmr_device;
      36   248608565 :         dest->fmr_flags = src->fmr_flags;
      37   248608565 :         dest->fmr_physical = BBTOB(src->fmr_physical);
      38   248608565 :         dest->fmr_owner = src->fmr_owner;
      39   248608565 :         dest->fmr_offset = BBTOB(src->fmr_offset);
      40   248608565 :         dest->fmr_length = BBTOB(src->fmr_length);
      41   248608565 :         dest->fmr_reserved[0] = 0;
      42   248608565 :         dest->fmr_reserved[1] = 0;
      43   248608565 :         dest->fmr_reserved[2] = 0;
      44   248608565 : }
      45             : 
      46             : /* Convert an fsmap to an xfs_fsmap. */
      47             : void
      48     2266561 : xfs_fsmap_to_internal(
      49             :         struct xfs_fsmap        *dest,
      50             :         struct fsmap            *src)
      51             : {
      52     2266561 :         dest->fmr_device = src->fmr_device;
      53     2266561 :         dest->fmr_flags = src->fmr_flags;
      54     2266561 :         dest->fmr_physical = BTOBBT(src->fmr_physical);
      55     2266561 :         dest->fmr_owner = src->fmr_owner;
      56     2266561 :         dest->fmr_offset = BTOBBT(src->fmr_offset);
      57     2266561 :         dest->fmr_length = BTOBBT(src->fmr_length);
      58     2266561 : }
      59             : 
      60             : /* Convert an fsmap owner into an rmapbt owner. */
      61             : static int
      62     1421068 : xfs_fsmap_owner_to_rmap(
      63             :         struct xfs_rmap_irec    *dest,
      64             :         const struct xfs_fsmap  *src)
      65             : {
      66     1421068 :         if (!(src->fmr_flags & FMR_OF_SPECIAL_OWNER)) {
      67      692964 :                 dest->rm_owner = src->fmr_owner;
      68      692964 :                 return 0;
      69             :         }
      70             : 
      71      728104 :         switch (src->fmr_owner) {
      72      696093 :         case 0:                 /* "lowest owner id possible" */
      73             :         case -1ULL:             /* "highest owner id possible" */
      74      696093 :                 dest->rm_owner = 0;
      75      696093 :                 break;
      76       24965 :         case XFS_FMR_OWN_FREE:
      77       24965 :                 dest->rm_owner = XFS_RMAP_OWN_NULL;
      78       24965 :                 break;
      79        3927 :         case XFS_FMR_OWN_UNKNOWN:
      80        3927 :                 dest->rm_owner = XFS_RMAP_OWN_UNKNOWN;
      81        3927 :                 break;
      82          39 :         case XFS_FMR_OWN_FS:
      83          39 :                 dest->rm_owner = XFS_RMAP_OWN_FS;
      84          39 :                 break;
      85           4 :         case XFS_FMR_OWN_LOG:
      86           4 :                 dest->rm_owner = XFS_RMAP_OWN_LOG;
      87           4 :                 break;
      88         650 :         case XFS_FMR_OWN_AG:
      89         650 :                 dest->rm_owner = XFS_RMAP_OWN_AG;
      90         650 :                 break;
      91          62 :         case XFS_FMR_OWN_INOBT:
      92          62 :                 dest->rm_owner = XFS_RMAP_OWN_INOBT;
      93          62 :                 break;
      94         827 :         case XFS_FMR_OWN_INODES:
      95         827 :                 dest->rm_owner = XFS_RMAP_OWN_INODES;
      96         827 :                 break;
      97          62 :         case XFS_FMR_OWN_REFC:
      98          62 :                 dest->rm_owner = XFS_RMAP_OWN_REFC;
      99          62 :                 break;
     100        1475 :         case XFS_FMR_OWN_COW:
     101        1475 :                 dest->rm_owner = XFS_RMAP_OWN_COW;
     102        1475 :                 break;
     103             :         case XFS_FMR_OWN_DEFECTIVE:     /* not implemented */
     104             :                 /* fall through */
     105             :         default:
     106             :                 return -EINVAL;
     107             :         }
     108             :         return 0;
     109             : }
     110             : 
     111             : /* Convert an rmapbt owner into an fsmap owner. */
     112             : static int
     113   195531860 : xfs_fsmap_owner_from_rmap(
     114             :         struct xfs_fsmap                *dest,
     115             :         const struct xfs_rmap_irec      *src)
     116             : {
     117   195531860 :         dest->fmr_flags = 0;
     118   195531860 :         if (!XFS_RMAP_NON_INODE_OWNER(src->rm_owner)) {
     119   176753133 :                 dest->fmr_owner = src->rm_owner;
     120   176753133 :                 return 0;
     121             :         }
     122    18778727 :         dest->fmr_flags |= FMR_OF_SPECIAL_OWNER;
     123             : 
     124    18778727 :         switch (src->rm_owner) {
     125      431216 :         case XFS_RMAP_OWN_FS:
     126      431216 :                 dest->fmr_owner = XFS_FMR_OWN_FS;
     127      431216 :                 break;
     128      104854 :         case XFS_RMAP_OWN_LOG:
     129      104854 :                 dest->fmr_owner = XFS_FMR_OWN_LOG;
     130      104854 :                 break;
     131     2692306 :         case XFS_RMAP_OWN_AG:
     132     2692306 :                 dest->fmr_owner = XFS_FMR_OWN_AG;
     133     2692306 :                 break;
     134      457420 :         case XFS_RMAP_OWN_INOBT:
     135      457420 :                 dest->fmr_owner = XFS_FMR_OWN_INOBT;
     136      457420 :                 break;
     137     1435763 :         case XFS_RMAP_OWN_INODES:
     138     1435763 :                 dest->fmr_owner = XFS_FMR_OWN_INODES;
     139     1435763 :                 break;
     140      477503 :         case XFS_RMAP_OWN_REFC:
     141      477503 :                 dest->fmr_owner = XFS_FMR_OWN_REFC;
     142      477503 :                 break;
     143     3653982 :         case XFS_RMAP_OWN_COW:
     144     3653982 :                 dest->fmr_owner = XFS_FMR_OWN_COW;
     145     3653982 :                 break;
     146     9525683 :         case XFS_RMAP_OWN_NULL: /* "free" */
     147     9525683 :                 dest->fmr_owner = XFS_FMR_OWN_FREE;
     148     9525683 :                 break;
     149           0 :         default:
     150           0 :                 ASSERT(0);
     151           0 :                 return -EFSCORRUPTED;
     152             :         }
     153             :         return 0;
     154             : }
     155             : 
     156             : /* getfsmap query state */
     157             : struct xfs_getfsmap_info {
     158             :         struct xfs_fsmap_head   *head;
     159             :         struct fsmap            *fsmap_recs;    /* mapping records */
     160             :         struct xfs_buf          *agf_bp;        /* AGF, for refcount queries */
     161             :         struct xfs_perag        *pag;           /* AG info, if applicable */
     162             :         xfs_daddr_t             next_daddr;     /* next daddr we expect */
     163             :         /* daddr of low fsmap key when we're using the rtbitmap */
     164             :         xfs_daddr_t             low_daddr;
     165             :         u64                     missing_owner;  /* owner of holes */
     166             :         u32                     dev;            /* device id */
     167             :         /*
     168             :          * Low rmap key for the query.  If low.rm_blockcount is nonzero, this
     169             :          * is the second (or later) call to retrieve the recordset in pieces.
     170             :          * xfs_getfsmap_rec_before_start will compare all records retrieved
     171             :          * by the rmapbt query to filter out any records that start before
     172             :          * the last record.
     173             :          */
     174             :         struct xfs_rmap_irec    low;
     175             :         struct xfs_rmap_irec    high;           /* high rmap key */
     176             :         bool                    last;           /* last extent? */
     177             : };
     178             : 
     179             : /* Associate a device with a getfsmap handler. */
     180             : struct xfs_getfsmap_dev {
     181             :         u32                     dev;
     182             :         int                     (*fn)(struct xfs_trans *tp,
     183             :                                       const struct xfs_fsmap *keys,
     184             :                                       struct xfs_getfsmap_info *info);
     185             : };
     186             : 
     187             : /* Compare two getfsmap device handlers. */
     188             : static int
     189     2394886 : xfs_getfsmap_dev_compare(
     190             :         const void                      *p1,
     191             :         const void                      *p2)
     192             : {
     193     2394886 :         const struct xfs_getfsmap_dev   *d1 = p1;
     194     2394886 :         const struct xfs_getfsmap_dev   *d2 = p2;
     195             : 
     196     2394886 :         return d1->dev - d2->dev;
     197             : }
     198             : 
     199             : /* Decide if this mapping is shared. */
     200             : STATIC int
     201   151311907 : xfs_getfsmap_is_shared(
     202             :         struct xfs_trans                *tp,
     203             :         struct xfs_getfsmap_info        *info,
     204             :         const struct xfs_rmap_irec      *rec,
     205             :         bool                            *stat)
     206             : {
     207   151311907 :         struct xfs_mount                *mp = tp->t_mountp;
     208   151311907 :         struct xfs_btree_cur            *cur;
     209   151311907 :         xfs_agblock_t                   fbno;
     210   151311907 :         xfs_extlen_t                    flen;
     211   151311907 :         int                             error;
     212             : 
     213   151311907 :         *stat = false;
     214   151311907 :         if (!xfs_has_reflink(mp))
     215             :                 return 0;
     216             :         /* rt files will have no perag structure */
     217   151311907 :         if (!info->pag)
     218             :                 return 0;
     219             : 
     220             :         /* Are there any shared blocks here? */
     221   151311907 :         flen = 0;
     222   151311907 :         cur = xfs_refcountbt_init_cursor(mp, tp, info->agf_bp, info->pag);
     223             : 
     224   152848266 :         error = xfs_refcount_find_shared(cur, rec->rm_startblock,
     225   152848266 :                         rec->rm_blockcount, &fbno, &flen, false);
     226             : 
     227   151499609 :         xfs_btree_del_cursor(cur, error);
     228   152613384 :         if (error)
     229             :                 return error;
     230             : 
     231   152613384 :         *stat = flen > 0;
     232   152613384 :         return 0;
     233             : }
     234             : 
     235             : static inline void
     236   248405959 : xfs_getfsmap_format(
     237             :         struct xfs_mount                *mp,
     238             :         struct xfs_fsmap                *xfm,
     239             :         struct xfs_getfsmap_info        *info)
     240             : {
     241   248405959 :         struct fsmap                    *rec;
     242             : 
     243   248405959 :         trace_xfs_getfsmap_mapping(mp, xfm);
     244             : 
     245   248467091 :         rec = &info->fsmap_recs[info->head->fmh_entries++];
     246   248467091 :         xfs_fsmap_from_internal(rec, xfm);
     247   248298257 : }
     248             : 
     249             : static inline bool
     250   195400684 : xfs_getfsmap_rec_before_start(
     251             :         struct xfs_getfsmap_info        *info,
     252             :         const struct xfs_rmap_irec      *rec,
     253             :         xfs_daddr_t                     rec_daddr)
     254             : {
     255   195400684 :         if (info->low_daddr != -1ULL)
     256     3636888 :                 return rec_daddr < info->low_daddr;
     257   191763796 :         if (info->low.rm_blockcount)
     258   121964331 :                 return xfs_rmap_compare(rec, &info->low) < 0;
     259             :         return false;
     260             : }
     261             : 
     262             : /*
     263             :  * Format a reverse mapping for getfsmap, having translated rm_startblock
     264             :  * into the appropriate daddr units.  Pass in a nonzero @len_daddr if the
     265             :  * length could be larger than rm_blockcount in struct xfs_rmap_irec.
     266             :  */
     267             : STATIC int
     268   197132082 : xfs_getfsmap_helper(
     269             :         struct xfs_trans                *tp,
     270             :         struct xfs_getfsmap_info        *info,
     271             :         const struct xfs_rmap_irec      *rec,
     272             :         xfs_daddr_t                     rec_daddr,
     273             :         xfs_daddr_t                     len_daddr)
     274             : {
     275   197132082 :         struct xfs_fsmap                fmr;
     276   197132082 :         struct xfs_mount                *mp = tp->t_mountp;
     277   197132082 :         bool                            shared;
     278   197132082 :         int                             error;
     279             : 
     280   197132082 :         if (fatal_signal_pending(current))
     281             :                 return -EINTR;
     282             : 
     283   195075374 :         if (len_daddr == 0)
     284   189456642 :                 len_daddr = XFS_FSB_TO_BB(mp, rec->rm_blockcount);
     285             : 
     286             :         /*
     287             :          * Filter out records that start before our startpoint, if the
     288             :          * caller requested that.
     289             :          */
     290   195075374 :         if (xfs_getfsmap_rec_before_start(info, rec, rec_daddr)) {
     291      778393 :                 rec_daddr += len_daddr;
     292      778393 :                 if (info->next_daddr < rec_daddr)
     293        3673 :                         info->next_daddr = rec_daddr;
     294      778393 :                 return 0;
     295             :         }
     296             : 
     297             :         /* Are we just counting mappings? */
     298   196696990 :         if (info->head->fmh_count == 0) {
     299           0 :                 if (info->head->fmh_entries == UINT_MAX)
     300             :                         return -ECANCELED;
     301             : 
     302           0 :                 if (rec_daddr > info->next_daddr)
     303           0 :                         info->head->fmh_entries++;
     304             : 
     305           0 :                 if (info->last)
     306             :                         return 0;
     307             : 
     308           0 :                 info->head->fmh_entries++;
     309             : 
     310           0 :                 rec_daddr += len_daddr;
     311           0 :                 if (info->next_daddr < rec_daddr)
     312           0 :                         info->next_daddr = rec_daddr;
     313           0 :                 return 0;
     314             :         }
     315             : 
     316             :         /*
     317             :          * If the record starts past the last physical block we saw,
     318             :          * then we've found a gap.  Report the gap as being owned by
     319             :          * whatever the caller specified is the missing owner.
     320             :          */
     321   196696990 :         if (rec_daddr > info->next_daddr) {
     322    52682052 :                 if (info->head->fmh_entries >= info->head->fmh_count)
     323             :                         return -ECANCELED;
     324             : 
     325    52649773 :                 fmr.fmr_device = info->dev;
     326    52649773 :                 fmr.fmr_physical = info->next_daddr;
     327    52649773 :                 fmr.fmr_owner = info->missing_owner;
     328    52649773 :                 fmr.fmr_offset = 0;
     329    52649773 :                 fmr.fmr_length = rec_daddr - info->next_daddr;
     330    52649773 :                 fmr.fmr_flags = FMR_OF_SPECIAL_OWNER;
     331    52649773 :                 xfs_getfsmap_format(mp, &fmr, info);
     332             :         }
     333             : 
     334   196594433 :         if (info->last)
     335      675912 :                 goto out;
     336             : 
     337             :         /* Fill out the extent we found */
     338   195918521 :         if (info->head->fmh_entries >= info->head->fmh_count)
     339             :                 return -ECANCELED;
     340             : 
     341   195833442 :         trace_xfs_fsmap_mapping(mp, info->dev,
     342   195833442 :                         info->pag ? info->pag->pag_agno : NULLAGNUMBER, rec);
     343             : 
     344   195489895 :         fmr.fmr_device = info->dev;
     345   195489895 :         fmr.fmr_physical = rec_daddr;
     346   195489895 :         error = xfs_fsmap_owner_from_rmap(&fmr, rec);
     347   194851715 :         if (error)
     348             :                 return error;
     349   194851715 :         fmr.fmr_offset = XFS_FSB_TO_BB(mp, rec->rm_offset);
     350   194851715 :         fmr.fmr_length = len_daddr;
     351   194851715 :         if (rec->rm_flags & XFS_RMAP_UNWRITTEN)
     352    25710824 :                 fmr.fmr_flags |= FMR_OF_PREALLOC;
     353   194851715 :         if (rec->rm_flags & XFS_RMAP_ATTR_FORK)
     354      491715 :                 fmr.fmr_flags |= FMR_OF_ATTR_FORK;
     355   194851715 :         if (rec->rm_flags & XFS_RMAP_BMBT_BLOCK)
     356     1219964 :                 fmr.fmr_flags |= FMR_OF_EXTENT_MAP;
     357   194851715 :         if (fmr.fmr_flags == 0) {
     358   150133381 :                 error = xfs_getfsmap_is_shared(tp, info, rec, &shared);
     359   152000658 :                 if (error)
     360             :                         return error;
     361   152000658 :                 if (shared)
     362    58205226 :                         fmr.fmr_flags |= FMR_OF_SHARED;
     363             :         }
     364             : 
     365   196718992 :         xfs_getfsmap_format(mp, &fmr, info);
     366   197646020 : out:
     367   197646020 :         rec_daddr += len_daddr;
     368   197646020 :         if (info->next_daddr < rec_daddr)
     369   149053813 :                 info->next_daddr = rec_daddr;
     370             :         return 0;
     371             : }
     372             : 
     373             : /* Transform a rmapbt irec into a fsmap */
     374             : STATIC int
     375   186054713 : xfs_getfsmap_datadev_helper(
     376             :         struct xfs_btree_cur            *cur,
     377             :         const struct xfs_rmap_irec      *rec,
     378             :         void                            *priv)
     379             : {
     380   186054713 :         struct xfs_mount                *mp = cur->bc_mp;
     381   186054713 :         struct xfs_getfsmap_info        *info = priv;
     382   186054713 :         xfs_fsblock_t                   fsb;
     383   186054713 :         xfs_daddr_t                     rec_daddr;
     384             : 
     385   186054713 :         fsb = XFS_AGB_TO_FSB(mp, cur->bc_ag.pag->pag_agno, rec->rm_startblock);
     386   186054713 :         rec_daddr = XFS_FSB_TO_DADDR(mp, fsb);
     387             : 
     388   186602094 :         return xfs_getfsmap_helper(cur->bc_tp, info, rec, rec_daddr, 0);
     389             : }
     390             : 
     391             : /* Transform a bnobt irec into a fsmap */
     392             : STATIC int
     393     3963493 : xfs_getfsmap_datadev_bnobt_helper(
     394             :         struct xfs_btree_cur            *cur,
     395             :         const struct xfs_alloc_rec_incore *rec,
     396             :         void                            *priv)
     397             : {
     398     3963493 :         struct xfs_mount                *mp = cur->bc_mp;
     399     3963493 :         struct xfs_getfsmap_info        *info = priv;
     400     3963493 :         struct xfs_rmap_irec            irec;
     401     3963493 :         xfs_daddr_t                     rec_daddr;
     402             : 
     403     3963493 :         rec_daddr = XFS_AGB_TO_DADDR(mp, cur->bc_ag.pag->pag_agno,
     404             :                         rec->ar_startblock);
     405             : 
     406     3963493 :         irec.rm_startblock = rec->ar_startblock;
     407     3963493 :         irec.rm_blockcount = rec->ar_blockcount;
     408     3963493 :         irec.rm_owner = XFS_RMAP_OWN_NULL;      /* "free" */
     409     3963493 :         irec.rm_offset = 0;
     410     3963493 :         irec.rm_flags = 0;
     411             : 
     412     3963493 :         return xfs_getfsmap_helper(cur->bc_tp, info, &irec, rec_daddr, 0);
     413             : }
     414             : 
     415             : /* Set rmap flags based on the getfsmap flags */
     416             : static void
     417     1417427 : xfs_getfsmap_set_irec_flags(
     418             :         struct xfs_rmap_irec    *irec,
     419             :         const struct xfs_fsmap  *fmr)
     420             : {
     421     1417427 :         irec->rm_flags = 0;
     422     1417427 :         if (fmr->fmr_flags & FMR_OF_ATTR_FORK)
     423      694385 :                 irec->rm_flags |= XFS_RMAP_ATTR_FORK;
     424     1417427 :         if (fmr->fmr_flags & FMR_OF_EXTENT_MAP)
     425      694696 :                 irec->rm_flags |= XFS_RMAP_BMBT_BLOCK;
     426     1417427 :         if (fmr->fmr_flags & FMR_OF_PREALLOC)
     427      704743 :                 irec->rm_flags |= XFS_RMAP_UNWRITTEN;
     428     1417427 : }
     429             : 
     430             : /* Execute a getfsmap query against the log device. */
     431             : STATIC int
     432       17634 : xfs_getfsmap_logdev(
     433             :         struct xfs_trans                *tp,
     434             :         const struct xfs_fsmap          *keys,
     435             :         struct xfs_getfsmap_info        *info)
     436             : {
     437       17634 :         struct xfs_mount                *mp = tp->t_mountp;
     438       17634 :         struct xfs_rmap_irec            rmap;
     439       17634 :         xfs_daddr_t                     rec_daddr, len_daddr;
     440       17634 :         xfs_fsblock_t                   start_fsb, end_fsb;
     441       17634 :         uint64_t                        eofs;
     442             : 
     443       17634 :         eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
     444       17634 :         if (keys[0].fmr_physical >= eofs)
     445             :                 return 0;
     446       17634 :         start_fsb = XFS_BB_TO_FSBT(mp,
     447             :                                 keys[0].fmr_physical + keys[0].fmr_length);
     448       17634 :         end_fsb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical));
     449             : 
     450             :         /* Adjust the low key if we are continuing from where we left off. */
     451       17634 :         if (keys[0].fmr_length > 0)
     452           4 :                 info->low_daddr = XFS_FSB_TO_BB(mp, start_fsb);
     453             : 
     454       17634 :         trace_xfs_fsmap_low_key_linear(mp, info->dev, start_fsb);
     455       17634 :         trace_xfs_fsmap_high_key_linear(mp, info->dev, end_fsb);
     456             : 
     457       17634 :         if (start_fsb > 0)
     458             :                 return 0;
     459             : 
     460             :         /* Fabricate an rmap entry for the external log device. */
     461       17630 :         rmap.rm_startblock = 0;
     462       17630 :         rmap.rm_blockcount = mp->m_sb.sb_logblocks;
     463       17630 :         rmap.rm_owner = XFS_RMAP_OWN_LOG;
     464       17630 :         rmap.rm_offset = 0;
     465       17630 :         rmap.rm_flags = 0;
     466             : 
     467       17630 :         rec_daddr = XFS_FSB_TO_BB(mp, rmap.rm_startblock);
     468       17630 :         len_daddr = XFS_FSB_TO_BB(mp, rmap.rm_blockcount);
     469       17630 :         return xfs_getfsmap_helper(tp, info, &rmap, rec_daddr, len_daddr);
     470             : }
     471             : 
     472             : #ifdef CONFIG_XFS_RT
     473             : /* Transform a rtbitmap "record" into a fsmap */
     474             : STATIC int
     475     5894037 : xfs_getfsmap_rtdev_rtbitmap_helper(
     476             :         struct xfs_mount                *mp,
     477             :         struct xfs_trans                *tp,
     478             :         const struct xfs_rtalloc_rec    *rec,
     479             :         void                            *priv)
     480             : {
     481     5894037 :         struct xfs_getfsmap_info        *info = priv;
     482     5894037 :         struct xfs_rmap_irec            irec;
     483     5894037 :         xfs_rtblock_t                   rtbno;
     484     5894037 :         xfs_daddr_t                     rec_daddr, len_daddr;
     485             : 
     486     5894037 :         rtbno = rec->ar_startext * mp->m_sb.sb_rextsize;
     487     5894037 :         rec_daddr = XFS_FSB_TO_BB(mp, rtbno);
     488     5894037 :         irec.rm_startblock = rtbno;
     489             : 
     490     5894037 :         rtbno = rec->ar_extcount * mp->m_sb.sb_rextsize;
     491     5894037 :         len_daddr = XFS_FSB_TO_BB(mp, rtbno);
     492     5894037 :         irec.rm_blockcount = rtbno;
     493             : 
     494     5894037 :         irec.rm_owner = XFS_RMAP_OWN_NULL;      /* "free" */
     495     5894037 :         irec.rm_offset = 0;
     496     5894037 :         irec.rm_flags = 0;
     497             : 
     498     5894037 :         return xfs_getfsmap_helper(tp, info, &irec, rec_daddr, len_daddr);
     499             : }
     500             : 
     501             : /* Execute a getfsmap query against the realtime device rtbitmap. */
     502             : STATIC int
     503       57736 : xfs_getfsmap_rtdev_rtbitmap(
     504             :         struct xfs_trans                *tp,
     505             :         const struct xfs_fsmap          *keys,
     506             :         struct xfs_getfsmap_info        *info)
     507             : {
     508             : 
     509       57736 :         struct xfs_rtalloc_rec          alow = { 0 };
     510       57736 :         struct xfs_rtalloc_rec          ahigh = { 0 };
     511       57736 :         struct xfs_mount                *mp = tp->t_mountp;
     512       57736 :         xfs_rtblock_t                   start_rtb;
     513       57736 :         xfs_rtblock_t                   end_rtb;
     514       57736 :         uint64_t                        eofs;
     515       57736 :         int                             error;
     516             : 
     517       57736 :         eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_rextents * mp->m_sb.sb_rextsize);
     518       57736 :         if (keys[0].fmr_physical >= eofs)
     519             :                 return 0;
     520       57734 :         start_rtb = XFS_BB_TO_FSBT(mp,
     521             :                                 keys[0].fmr_physical + keys[0].fmr_length);
     522       57734 :         end_rtb = XFS_BB_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical));
     523             : 
     524       57734 :         info->missing_owner = XFS_FMR_OWN_UNKNOWN;
     525             : 
     526             :         /* Adjust the low key if we are continuing from where we left off. */
     527       57734 :         if (keys[0].fmr_length > 0) {
     528        4134 :                 info->low_daddr = XFS_FSB_TO_BB(mp, start_rtb);
     529        4134 :                 if (info->low_daddr >= eofs)
     530             :                         return 0;
     531             :         }
     532             : 
     533       57734 :         trace_xfs_fsmap_low_key_linear(mp, info->dev, start_rtb);
     534       57734 :         trace_xfs_fsmap_high_key_linear(mp, info->dev, end_rtb);
     535             : 
     536       57734 :         xfs_ilock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
     537             : 
     538             :         /*
     539             :          * Set up query parameters to return free rtextents covering the range
     540             :          * we want.
     541             :          */
     542       57734 :         alow.ar_startext = start_rtb;
     543       57734 :         ahigh.ar_startext = end_rtb;
     544       57734 :         do_div(alow.ar_startext, mp->m_sb.sb_rextsize);
     545       57734 :         if (do_div(ahigh.ar_startext, mp->m_sb.sb_rextsize))
     546           6 :                 ahigh.ar_startext++;
     547       57734 :         error = xfs_rtalloc_query_range(mp, tp, &alow, &ahigh,
     548             :                         xfs_getfsmap_rtdev_rtbitmap_helper, info);
     549       57734 :         if (error)
     550        4139 :                 goto err;
     551             : 
     552             :         /*
     553             :          * Report any gaps at the end of the rtbitmap by simulating a null
     554             :          * rmap starting at the block after the end of the query range.
     555             :          */
     556       53595 :         info->last = true;
     557       53595 :         ahigh.ar_startext = min(mp->m_sb.sb_rextents, ahigh.ar_startext);
     558             : 
     559       53595 :         error = xfs_getfsmap_rtdev_rtbitmap_helper(mp, tp, &ahigh, info);
     560       53595 :         if (error)
     561           0 :                 goto err;
     562       53595 : err:
     563       57734 :         xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP);
     564       57734 :         return error;
     565             : }
     566             : #endif /* CONFIG_XFS_RT */
     567             : 
     568             : /* Execute a getfsmap query against the regular data device. */
     569             : STATIC int
     570      729767 : __xfs_getfsmap_datadev(
     571             :         struct xfs_trans                *tp,
     572             :         const struct xfs_fsmap          *keys,
     573             :         struct xfs_getfsmap_info        *info,
     574             :         int                             (*query_fn)(struct xfs_trans *,
     575             :                                                     struct xfs_getfsmap_info *,
     576             :                                                     struct xfs_btree_cur **,
     577             :                                                     void *),
     578             :         void                            *priv)
     579             : {
     580      729767 :         struct xfs_mount                *mp = tp->t_mountp;
     581      729767 :         struct xfs_perag                *pag;
     582      729767 :         struct xfs_btree_cur            *bt_cur = NULL;
     583      729767 :         xfs_fsblock_t                   start_fsb;
     584      729767 :         xfs_fsblock_t                   end_fsb;
     585      729767 :         xfs_agnumber_t                  start_ag;
     586      729767 :         xfs_agnumber_t                  end_ag;
     587      729767 :         uint64_t                        eofs;
     588      729767 :         int                             error = 0;
     589             : 
     590      729767 :         eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks);
     591      729767 :         if (keys[0].fmr_physical >= eofs)
     592             :                 return 0;
     593      727163 :         start_fsb = XFS_DADDR_TO_FSB(mp, keys[0].fmr_physical);
     594      724591 :         end_fsb = XFS_DADDR_TO_FSB(mp, min(eofs - 1, keys[1].fmr_physical));
     595             : 
     596             :         /*
     597             :          * Convert the fsmap low/high keys to AG based keys.  Initialize
     598             :          * low to the fsmap low key and max out the high key to the end
     599             :          * of the AG.
     600             :          */
     601      726751 :         info->low.rm_startblock = XFS_FSB_TO_AGBNO(mp, start_fsb);
     602      724933 :         info->low.rm_offset = XFS_BB_TO_FSBT(mp, keys[0].fmr_offset);
     603      724933 :         error = xfs_fsmap_owner_to_rmap(&info->low, &keys[0]);
     604      726397 :         if (error)
     605             :                 return error;
     606      726397 :         info->low.rm_blockcount = XFS_BB_TO_FSBT(mp, keys[0].fmr_length);
     607      726397 :         xfs_getfsmap_set_irec_flags(&info->low, &keys[0]);
     608             : 
     609             :         /* Adjust the low key if we are continuing from where we left off. */
     610      722433 :         if (info->low.rm_blockcount == 0) {
     611             :                 /* empty */
     612      113212 :         } else if (XFS_RMAP_NON_INODE_OWNER(info->low.rm_owner) ||
     613       81200 :                    (info->low.rm_flags & (XFS_RMAP_ATTR_FORK |
     614             :                                           XFS_RMAP_BMBT_BLOCK |
     615             :                                           XFS_RMAP_UNWRITTEN))) {
     616       43806 :                 info->low.rm_startblock += info->low.rm_blockcount;
     617       43806 :                 info->low.rm_owner = 0;
     618       43806 :                 info->low.rm_offset = 0;
     619             : 
     620       43806 :                 start_fsb += info->low.rm_blockcount;
     621       43806 :                 if (XFS_FSB_TO_DADDR(mp, start_fsb) >= eofs)
     622             :                         return 0;
     623             :         } else {
     624       69406 :                 info->low.rm_offset += info->low.rm_blockcount;
     625             :         }
     626             : 
     627      722429 :         info->high.rm_startblock = -1U;
     628      722429 :         info->high.rm_owner = ULLONG_MAX;
     629      722429 :         info->high.rm_offset = ULLONG_MAX;
     630      722429 :         info->high.rm_blockcount = 0;
     631      722429 :         info->high.rm_flags = XFS_RMAP_KEY_FLAGS | XFS_RMAP_REC_FLAGS;
     632             : 
     633      722429 :         start_ag = XFS_FSB_TO_AGNO(mp, start_fsb);
     634      722429 :         end_ag = XFS_FSB_TO_AGNO(mp, end_fsb);
     635             : 
     636     1384046 :         for_each_perag_range(mp, start_ag, end_ag, pag) {
     637             :                 /*
     638             :                  * Set the AG high key from the fsmap high key if this
     639             :                  * is the last AG that we're querying.
     640             :                  */
     641      776126 :                 info->pag = pag;
     642      776126 :                 if (pag->pag_agno == end_ag) {
     643      699056 :                         info->high.rm_startblock = XFS_FSB_TO_AGBNO(mp,
     644             :                                         end_fsb);
     645      697619 :                         info->high.rm_offset = XFS_BB_TO_FSBT(mp,
     646             :                                         keys[1].fmr_offset);
     647      697619 :                         error = xfs_fsmap_owner_to_rmap(&info->high, &keys[1]);
     648      694975 :                         if (error)
     649             :                                 break;
     650      694975 :                         xfs_getfsmap_set_irec_flags(&info->high, &keys[1]);
     651             :                 }
     652             : 
     653      769583 :                 if (bt_cur) {
     654       40140 :                         xfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
     655       40140 :                         bt_cur = NULL;
     656       40140 :                         xfs_trans_brelse(tp, info->agf_bp);
     657       40140 :                         info->agf_bp = NULL;
     658             :                 }
     659             : 
     660      769583 :                 error = xfs_alloc_read_agf(pag, tp, 0, &info->agf_bp);
     661      774246 :                 if (error)
     662             :                         break;
     663             : 
     664      774246 :                 trace_xfs_fsmap_low_key(mp, info->dev, pag->pag_agno,
     665             :                                 &info->low);
     666      773351 :                 trace_xfs_fsmap_high_key(mp, info->dev, pag->pag_agno,
     667      773351 :                                 &info->high);
     668             : 
     669      771485 :                 error = query_fn(tp, info, &bt_cur, priv);
     670      773271 :                 if (error)
     671             :                         break;
     672             : 
     673             :                 /*
     674             :                  * Set the AG low key to the start of the AG prior to
     675             :                  * moving on to the next AG.
     676             :                  */
     677      660080 :                 if (pag->pag_agno == start_ag)
     678     1322416 :                         memset(&info->low, 0, sizeof(info->low));
     679             : 
     680             :                 /*
     681             :                  * If this is the last AG, report any gap at the end of it
     682             :                  * before we drop the reference to the perag when the loop
     683             :                  * terminates.
     684             :                  */
     685      660080 :                 if (pag->pag_agno == end_ag) {
     686      619940 :                         info->last = true;
     687      619940 :                         error = query_fn(tp, info, &bt_cur, priv);
     688      621572 :                         if (error)
     689             :                                 break;
     690             :                 }
     691      661697 :                 info->pag = NULL;
     692             :         }
     693             : 
     694      735042 :         if (bt_cur)
     695      735118 :                 xfs_btree_del_cursor(bt_cur, error < 0 ? XFS_BTREE_ERROR :
     696             :                                                          XFS_BTREE_NOERROR);
     697      734717 :         if (info->agf_bp) {
     698      736545 :                 xfs_trans_brelse(tp, info->agf_bp);
     699      738326 :                 info->agf_bp = NULL;
     700             :         }
     701      736498 :         if (info->pag) {
     702      113213 :                 xfs_perag_rele(info->pag);
     703      113214 :                 info->pag = NULL;
     704      623285 :         } else if (pag) {
     705             :                 /* loop termination case */
     706           0 :                 xfs_perag_rele(pag);
     707             :         }
     708             : 
     709             :         return error;
     710             : }
     711             : 
     712             : /* Actually query the rmap btree. */
     713             : STATIC int
     714      951478 : xfs_getfsmap_datadev_rmapbt_query(
     715             :         struct xfs_trans                *tp,
     716             :         struct xfs_getfsmap_info        *info,
     717             :         struct xfs_btree_cur            **curpp,
     718             :         void                            *priv)
     719             : {
     720             :         /* Report any gap at the end of the last AG. */
     721      951478 :         if (info->last)
     722      404336 :                 return xfs_getfsmap_datadev_helper(*curpp, &info->high, info);
     723             : 
     724             :         /* Allocate cursor for this AG and query_range it. */
     725      547142 :         *curpp = xfs_rmapbt_init_cursor(tp->t_mountp, tp, info->agf_bp,
     726             :                         info->pag);
     727      550868 :         return xfs_rmap_query_range(*curpp, &info->low, &info->high,
     728             :                         xfs_getfsmap_datadev_helper, info);
     729             : }
     730             : 
     731             : /* Execute a getfsmap query against the regular data device rmapbt. */
     732             : STATIC int
     733      505154 : xfs_getfsmap_datadev_rmapbt(
     734             :         struct xfs_trans                *tp,
     735             :         const struct xfs_fsmap          *keys,
     736             :         struct xfs_getfsmap_info        *info)
     737             : {
     738      505154 :         info->missing_owner = XFS_FMR_OWN_FREE;
     739      505154 :         return __xfs_getfsmap_datadev(tp, keys, info,
     740             :                         xfs_getfsmap_datadev_rmapbt_query, NULL);
     741             : }
     742             : 
     743             : /* Actually query the bno btree. */
     744             : STATIC int
     745      440429 : xfs_getfsmap_datadev_bnobt_query(
     746             :         struct xfs_trans                *tp,
     747             :         struct xfs_getfsmap_info        *info,
     748             :         struct xfs_btree_cur            **curpp,
     749             :         void                            *priv)
     750             : {
     751      440429 :         struct xfs_alloc_rec_incore     *key = priv;
     752             : 
     753             :         /* Report any gap at the end of the last AG. */
     754      440429 :         if (info->last)
     755      215780 :                 return xfs_getfsmap_datadev_bnobt_helper(*curpp, &key[1], info);
     756             : 
     757             :         /* Allocate cursor for this AG and query_range it. */
     758      224649 :         *curpp = xfs_allocbt_init_cursor(tp->t_mountp, tp, info->agf_bp,
     759             :                         info->pag, XFS_BTNUM_BNO);
     760      224960 :         key->ar_startblock = info->low.rm_startblock;
     761      224960 :         key[1].ar_startblock = info->high.rm_startblock;
     762      224960 :         return xfs_alloc_query_range(*curpp, key, &key[1],
     763             :                         xfs_getfsmap_datadev_bnobt_helper, info);
     764             : }
     765             : 
     766             : /* Execute a getfsmap query against the regular data device's bnobt. */
     767             : STATIC int
     768      224430 : xfs_getfsmap_datadev_bnobt(
     769             :         struct xfs_trans                *tp,
     770             :         const struct xfs_fsmap          *keys,
     771             :         struct xfs_getfsmap_info        *info)
     772             : {
     773      224430 :         struct xfs_alloc_rec_incore     akeys[2];
     774             : 
     775      224430 :         memset(akeys, 0, sizeof(akeys));
     776      224430 :         info->missing_owner = XFS_FMR_OWN_UNKNOWN;
     777      224430 :         return __xfs_getfsmap_datadev(tp, keys, info,
     778             :                         xfs_getfsmap_datadev_bnobt_query, &akeys[0]);
     779             : }
     780             : 
     781             : /* Do we recognize the device? */
     782             : STATIC bool
     783     1609707 : xfs_getfsmap_is_valid_device(
     784             :         struct xfs_mount        *mp,
     785             :         struct xfs_fsmap        *fm)
     786             : {
     787     1609707 :         if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX ||
     788     1550655 :             fm->fmr_device == new_encode_dev(mp->m_ddev_targp->bt_dev))
     789             :                 return true;
     790      147634 :         if (mp->m_logdev_targp &&
     791      147634 :             fm->fmr_device == new_encode_dev(mp->m_logdev_targp->bt_dev))
     792             :                 return true;
     793      115312 :         if (mp->m_rtdev_targp &&
     794      115312 :             fm->fmr_device == new_encode_dev(mp->m_rtdev_targp->bt_dev))
     795      115312 :                 return true;
     796             :         return false;
     797             : }
     798             : 
     799             : /* Ensure that the low key is less than the high key. */
     800             : STATIC bool
     801      802670 : xfs_getfsmap_check_keys(
     802             :         struct xfs_fsmap                *low_key,
     803             :         struct xfs_fsmap                *high_key)
     804             : {
     805      802670 :         if (low_key->fmr_flags & (FMR_OF_SPECIAL_OWNER | FMR_OF_EXTENT_MAP)) {
     806       36572 :                 if (low_key->fmr_offset)
     807             :                         return false;
     808             :         }
     809      802670 :         if (high_key->fmr_flags != -1U &&
     810           0 :             (high_key->fmr_flags & (FMR_OF_SPECIAL_OWNER |
     811             :                                     FMR_OF_EXTENT_MAP))) {
     812           0 :                 if (high_key->fmr_offset && high_key->fmr_offset != -1ULL)
     813             :                         return false;
     814             :         }
     815      802670 :         if (high_key->fmr_length && high_key->fmr_length != -1ULL)
     816             :                 return false;
     817             : 
     818      802670 :         if (low_key->fmr_device > high_key->fmr_device)
     819             :                 return false;
     820      802670 :         if (low_key->fmr_device < high_key->fmr_device)
     821             :                 return true;
     822             : 
     823      751984 :         if (low_key->fmr_physical > high_key->fmr_physical)
     824             :                 return false;
     825      751984 :         if (low_key->fmr_physical < high_key->fmr_physical)
     826             :                 return true;
     827             : 
     828           0 :         if (low_key->fmr_owner > high_key->fmr_owner)
     829             :                 return false;
     830           0 :         if (low_key->fmr_owner < high_key->fmr_owner)
     831             :                 return true;
     832             : 
     833           0 :         if (low_key->fmr_offset > high_key->fmr_offset)
     834             :                 return false;
     835           0 :         if (low_key->fmr_offset < high_key->fmr_offset)
     836           0 :                 return true;
     837             : 
     838             :         return false;
     839             : }
     840             : 
     841             : /*
     842             :  * There are only two devices if we didn't configure RT devices at build time.
     843             :  */
     844             : #ifdef CONFIG_XFS_RT
     845             : #define XFS_GETFSMAP_DEVS       3
     846             : #else
     847             : #define XFS_GETFSMAP_DEVS       2
     848             : #endif /* CONFIG_XFS_RT */
     849             : 
     850             : /*
     851             :  * Get filesystem's extents as described in head, and format for output. Fills
     852             :  * in the supplied records array until there are no more reverse mappings to
     853             :  * return or head.fmh_entries == head.fmh_count.  In the second case, this
     854             :  * function returns -ECANCELED to indicate that more records would have been
     855             :  * returned.
     856             :  *
     857             :  * Key to Confusion
     858             :  * ----------------
     859             :  * There are multiple levels of keys and counters at work here:
     860             :  * xfs_fsmap_head.fmh_keys      -- low and high fsmap keys passed in;
     861             :  *                                 these reflect fs-wide sector addrs.
     862             :  * dkeys                        -- fmh_keys used to query each device;
     863             :  *                                 these are fmh_keys but w/ the low key
     864             :  *                                 bumped up by fmr_length.
     865             :  * xfs_getfsmap_info.next_daddr -- next disk addr we expect to see; this
     866             :  *                                 is how we detect gaps in the fsmap
     867             :                                    records and report them.
     868             :  * xfs_getfsmap_info.low/high   -- per-AG low/high keys computed from
     869             :  *                                 dkeys; used to query the metadata.
     870             :  */
     871             : int
     872      796687 : xfs_getfsmap(
     873             :         struct xfs_mount                *mp,
     874             :         struct xfs_fsmap_head           *head,
     875             :         struct fsmap                    *fsmap_recs)
     876             : {
     877      796687 :         struct xfs_trans                *tp = NULL;
     878      796687 :         struct xfs_fsmap                dkeys[2];       /* per-dev keys */
     879      796687 :         struct xfs_getfsmap_dev         handlers[XFS_GETFSMAP_DEVS];
     880      796687 :         struct xfs_getfsmap_info        info = { NULL };
     881      796687 :         bool                            use_rmap;
     882      796687 :         int                             i;
     883      796687 :         int                             error = 0;
     884             : 
     885      796687 :         if (head->fmh_iflags & ~FMH_IF_VALID)
     886             :                 return -EINVAL;
     887      796687 :         if (!xfs_getfsmap_is_valid_device(mp, &head->fmh_keys[0]) ||
     888      796687 :             !xfs_getfsmap_is_valid_device(mp, &head->fmh_keys[1]))
     889             :                 return -EINVAL;
     890      796687 :         if (!xfs_getfsmap_check_keys(&head->fmh_keys[0], &head->fmh_keys[1]))
     891             :                 return -EINVAL;
     892             : 
     893     1305813 :         use_rmap = xfs_has_rmapbt(mp) &&
     894      506429 :                    has_capability_noaudit(current, CAP_SYS_ADMIN);
     895      799384 :         head->fmh_entries = 0;
     896             : 
     897             :         /* Set up our device handlers. */
     898      799384 :         memset(handlers, 0, sizeof(handlers));
     899      799384 :         handlers[0].dev = new_encode_dev(mp->m_ddev_targp->bt_dev);
     900      799384 :         if (use_rmap)
     901      506933 :                 handlers[0].fn = xfs_getfsmap_datadev_rmapbt;
     902             :         else
     903      292451 :                 handlers[0].fn = xfs_getfsmap_datadev_bnobt;
     904      799384 :         if (mp->m_logdev_targp != mp->m_ddev_targp) {
     905      124469 :                 handlers[1].dev = new_encode_dev(mp->m_logdev_targp->bt_dev);
     906      124469 :                 handlers[1].fn = xfs_getfsmap_logdev;
     907             :         }
     908             : #ifdef CONFIG_XFS_RT
     909      799384 :         if (mp->m_rtdev_targp) {
     910      292858 :                 handlers[2].dev = new_encode_dev(mp->m_rtdev_targp->bt_dev);
     911      292858 :                 handlers[2].fn = xfs_getfsmap_rtdev_rtbitmap;
     912             :         }
     913             : #endif /* CONFIG_XFS_RT */
     914             : 
     915      799384 :         xfs_sort(handlers, XFS_GETFSMAP_DEVS, sizeof(struct xfs_getfsmap_dev),
     916             :                         xfs_getfsmap_dev_compare);
     917             : 
     918             :         /*
     919             :          * To continue where we left off, we allow userspace to use the
     920             :          * last mapping from a previous call as the low key of the next.
     921             :          * This is identified by a non-zero length in the low key. We
     922             :          * have to increment the low key in this scenario to ensure we
     923             :          * don't return the same mapping again, and instead return the
     924             :          * very next mapping.
     925             :          *
     926             :          * If the low key mapping refers to file data, the same physical
     927             :          * blocks could be mapped to several other files/offsets.
     928             :          * According to rmapbt record ordering, the minimal next
     929             :          * possible record for the block range is the next starting
     930             :          * offset in the same inode. Therefore, each fsmap backend bumps
     931             :          * the file offset to continue the search appropriately.  For
     932             :          * all other low key mapping types (attr blocks, metadata), each
     933             :          * fsmap backend bumps the physical offset as there can be no
     934             :          * other mapping for the same physical block range.
     935             :          */
     936      799776 :         dkeys[0] = head->fmh_keys[0];
     937      799776 :         memset(&dkeys[1], 0xFF, sizeof(struct xfs_fsmap));
     938             : 
     939      799776 :         info.next_daddr = head->fmh_keys[0].fmr_physical +
     940      799776 :                           head->fmh_keys[0].fmr_length;
     941      799776 :         info.fsmap_recs = fsmap_recs;
     942      799776 :         info.head = head;
     943             : 
     944             :         /* For each device we support... */
     945     2753224 :         for (i = 0; i < XFS_GETFSMAP_DEVS; i++) {
     946             :                 /* Is this device within the range the user asked for? */
     947     2311562 :                 if (!handlers[i].fn)
     948     1176601 :                         continue;
     949     1125942 :                 if (head->fmh_keys[0].fmr_device > handlers[i].dev)
     950       89354 :                         continue;
     951     1042091 :                 if (head->fmh_keys[1].fmr_device < handlers[i].dev)
     952             :                         break;
     953             : 
     954             :                 /*
     955             :                  * If this device number matches the high key, we have
     956             :                  * to pass the high key to the handler to limit the
     957             :                  * query results.  If the device number exceeds the
     958             :                  * low key, zero out the low key so that we get
     959             :                  * everything from the beginning.
     960             :                  */
     961      799122 :                 if (handlers[i].dev == head->fmh_keys[1].fmr_device)
     962      747656 :                         dkeys[1] = head->fmh_keys[1];
     963      800046 :                 if (handlers[i].dev > head->fmh_keys[0].fmr_device)
     964        9904 :                         memset(&dkeys[0], 0, sizeof(struct xfs_fsmap));
     965             : 
     966             :                 /*
     967             :                  * Grab an empty transaction so that we can use its recursive
     968             :                  * buffer locking abilities to detect cycles in the rmapbt
     969             :                  * without deadlocking.
     970             :                  */
     971      798822 :                 error = xfs_trans_alloc_empty(mp, &tp);
     972      799328 :                 if (error)
     973             :                         break;
     974             : 
     975      799328 :                 info.dev = handlers[i].dev;
     976      799365 :                 info.last = false;
     977      799365 :                 info.pag = NULL;
     978      799365 :                 info.low_daddr = -1ULL;
     979      799365 :                 info.low.rm_blockcount = 0;
     980      799365 :                 error = handlers[i].fn(tp, dkeys, &info);
     981      811583 :                 if (error)
     982             :                         break;
     983      694224 :                 xfs_trans_cancel(tp);
     984      687493 :                 tp = NULL;
     985      687493 :                 info.next_daddr = 0;
     986             :         }
     987             : 
     988      802145 :         if (tp)
     989      117357 :                 xfs_trans_cancel(tp);
     990      801413 :         head->fmh_oflags = FMH_OF_DEV_T;
     991      801413 :         return error;
     992             : }

Generated by: LCOV version 1.14