|
6 | 6 | #ifndef __XFS_RTBITMAP_H__
|
7 | 7 | #define __XFS_RTBITMAP_H__
|
8 | 8 |
|
| 9 | +static inline xfs_rtblock_t |
| 10 | +xfs_rtx_to_rtb( |
| 11 | + struct xfs_mount *mp, |
| 12 | + xfs_rtxnum_t rtx) |
| 13 | +{ |
| 14 | + if (mp->m_rtxblklog >= 0) |
| 15 | + return rtx << mp->m_rtxblklog; |
| 16 | + |
| 17 | + return rtx * mp->m_sb.sb_rextsize; |
| 18 | +} |
| 19 | + |
| 20 | +static inline xfs_extlen_t |
| 21 | +xfs_rtxlen_to_extlen( |
| 22 | + struct xfs_mount *mp, |
| 23 | + xfs_rtxlen_t rtxlen) |
| 24 | +{ |
| 25 | + if (mp->m_rtxblklog >= 0) |
| 26 | + return rtxlen << mp->m_rtxblklog; |
| 27 | + |
| 28 | + return rtxlen * mp->m_sb.sb_rextsize; |
| 29 | +} |
| 30 | + |
| 31 | +/* Compute the misalignment between an extent length and a realtime extent .*/ |
| 32 | +static inline unsigned int |
| 33 | +xfs_extlen_to_rtxmod( |
| 34 | + struct xfs_mount *mp, |
| 35 | + xfs_extlen_t len) |
| 36 | +{ |
| 37 | + if (mp->m_rtxblklog >= 0) |
| 38 | + return len & mp->m_rtxblkmask; |
| 39 | + |
| 40 | + return len % mp->m_sb.sb_rextsize; |
| 41 | +} |
| 42 | + |
| 43 | +static inline xfs_rtxlen_t |
| 44 | +xfs_extlen_to_rtxlen( |
| 45 | + struct xfs_mount *mp, |
| 46 | + xfs_extlen_t len) |
| 47 | +{ |
| 48 | + if (mp->m_rtxblklog >= 0) |
| 49 | + return len >> mp->m_rtxblklog; |
| 50 | + |
| 51 | + return len / mp->m_sb.sb_rextsize; |
| 52 | +} |
| 53 | + |
| 54 | +/* Convert an rt block number into an rt extent number. */ |
| 55 | +static inline xfs_rtxnum_t |
| 56 | +xfs_rtb_to_rtx( |
| 57 | + struct xfs_mount *mp, |
| 58 | + xfs_rtblock_t rtbno) |
| 59 | +{ |
| 60 | + if (likely(mp->m_rtxblklog >= 0)) |
| 61 | + return rtbno >> mp->m_rtxblklog; |
| 62 | + |
| 63 | + return div_u64(rtbno, mp->m_sb.sb_rextsize); |
| 64 | +} |
| 65 | + |
| 66 | +/* Return the offset of an rt block number within an rt extent. */ |
| 67 | +static inline xfs_extlen_t |
| 68 | +xfs_rtb_to_rtxoff( |
| 69 | + struct xfs_mount *mp, |
| 70 | + xfs_rtblock_t rtbno) |
| 71 | +{ |
| 72 | + if (likely(mp->m_rtxblklog >= 0)) |
| 73 | + return rtbno & mp->m_rtxblkmask; |
| 74 | + |
| 75 | + return do_div(rtbno, mp->m_sb.sb_rextsize); |
| 76 | +} |
| 77 | + |
| 78 | +/* |
| 79 | + * Crack an rt block number into an rt extent number and an offset within that |
| 80 | + * rt extent. Returns the rt extent number directly and the offset in @off. |
| 81 | + */ |
| 82 | +static inline xfs_rtxnum_t |
| 83 | +xfs_rtb_to_rtxrem( |
| 84 | + struct xfs_mount *mp, |
| 85 | + xfs_rtblock_t rtbno, |
| 86 | + xfs_extlen_t *off) |
| 87 | +{ |
| 88 | + if (likely(mp->m_rtxblklog >= 0)) { |
| 89 | + *off = rtbno & mp->m_rtxblkmask; |
| 90 | + return rtbno >> mp->m_rtxblklog; |
| 91 | + } |
| 92 | + |
| 93 | + return div_u64_rem(rtbno, mp->m_sb.sb_rextsize, off); |
| 94 | +} |
| 95 | + |
| 96 | +/* |
| 97 | + * Convert an rt block number into an rt extent number, rounding up to the next |
| 98 | + * rt extent if the rt block is not aligned to an rt extent boundary. |
| 99 | + */ |
| 100 | +static inline xfs_rtxnum_t |
| 101 | +xfs_rtb_to_rtxup( |
| 102 | + struct xfs_mount *mp, |
| 103 | + xfs_rtblock_t rtbno) |
| 104 | +{ |
| 105 | + if (likely(mp->m_rtxblklog >= 0)) { |
| 106 | + if (rtbno & mp->m_rtxblkmask) |
| 107 | + return (rtbno >> mp->m_rtxblklog) + 1; |
| 108 | + return rtbno >> mp->m_rtxblklog; |
| 109 | + } |
| 110 | + |
| 111 | + if (do_div(rtbno, mp->m_sb.sb_rextsize)) |
| 112 | + rtbno++; |
| 113 | + return rtbno; |
| 114 | +} |
| 115 | + |
| 116 | +/* Round this rtblock up to the nearest rt extent size. */ |
| 117 | +static inline xfs_rtblock_t |
| 118 | +xfs_rtb_roundup_rtx( |
| 119 | + struct xfs_mount *mp, |
| 120 | + xfs_rtblock_t rtbno) |
| 121 | +{ |
| 122 | + return roundup_64(rtbno, mp->m_sb.sb_rextsize); |
| 123 | +} |
| 124 | + |
| 125 | +/* Round this rtblock down to the nearest rt extent size. */ |
| 126 | +static inline xfs_rtblock_t |
| 127 | +xfs_rtb_rounddown_rtx( |
| 128 | + struct xfs_mount *mp, |
| 129 | + xfs_rtblock_t rtbno) |
| 130 | +{ |
| 131 | + return rounddown_64(rtbno, mp->m_sb.sb_rextsize); |
| 132 | +} |
| 133 | + |
9 | 134 | /*
|
10 | 135 | * Functions for walking free space rtextents in the realtime bitmap.
|
11 | 136 | */
|
|
0 commit comments