Lines Matching +full:ip +full:- +full:blocks
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020-2023 Oracle. All Rights Reserved.
45 struct xfs_mount *mp = sc->mp; in xrep_setup_rtbitmap()
47 unsigned long long blocks = mp->m_sb.sb_rbmblocks; in xrep_setup_rtbitmap() local
56 error = xfile_create(descr, blocks * mp->m_sb.sb_blocksize, &sc->xfile); in xrep_setup_rtbitmap()
62 * Reserve enough blocks to write out a completely new bitmap file, in xrep_setup_rtbitmap()
63 * plus twice as many blocks as we would need if we can only allocate in xrep_setup_rtbitmap()
74 blocks += xfs_bmbt_calc_size(mp, blocks) * 2; in xrep_setup_rtbitmap()
75 if (blocks > UINT_MAX) in xrep_setup_rtbitmap()
76 return -EOPNOTSUPP; in xrep_setup_rtbitmap()
78 rtb->resblks += blocks; in xrep_setup_rtbitmap()
108 ASSERT(xfs_has_rtgroups(rtb->sc->mp)); in xfbmp_load()
110 error = xfile_load(rtb->sc->xfile, &urk, in xfbmp_load()
128 ASSERT(xfs_has_rtgroups(rtb->sc->mp)); in xfbmp_store()
131 return xfile_store(rtb->sc->xfile, &urk, in xfbmp_store()
143 return xfile_store(rtb->sc->xfile, word, nr_words << XFS_WORDLOG, in xfbmp_copyin()
154 return xfile_load(rtb->sc->xfile, word, nr_words << XFS_WORDLOG, in xfbmp_copyout()
172 trace_xrep_rtbitmap_or(rtb->sc->mp, wordoff, mask, word); in xrep_rtbitmap_or()
186 struct xfs_mount *mp = rtb->sc->mp; in xrep_rtbitmap_mark_free()
187 struct xchk_rt *sr = &rtb->sc->sr; in xrep_rtbitmap_mark_free()
188 struct xfs_rtgroup *rtg = sr->rtg; in xrep_rtbitmap_mark_free()
199 if (!xfs_verify_rgbext(rtg, rtb->next_rgbno, rgbno - rtb->next_rgbno)) in xrep_rtbitmap_mark_free()
200 return -EFSCORRUPTED; in xrep_rtbitmap_mark_free()
203 * Convert rt blocks to rt extents The block range we find must be in xrep_rtbitmap_mark_free()
206 startrtx = xfs_rgbno_to_rtx(mp, rtb->next_rgbno); in xrep_rtbitmap_mark_free()
207 mod = xfs_rgbno_to_rtxoff(mp, rtb->next_rgbno); in xrep_rtbitmap_mark_free()
209 return -EFSCORRUPTED; in xrep_rtbitmap_mark_free()
211 nextrtx = xfs_rgbno_to_rtx(mp, rgbno - 1) + 1; in xrep_rtbitmap_mark_free()
212 mod = xfs_rgbno_to_rtxoff(mp, rgbno - 1); in xrep_rtbitmap_mark_free()
213 if (mod != mp->m_sb.sb_rextsize - 1) in xrep_rtbitmap_mark_free()
214 return -EFSCORRUPTED; in xrep_rtbitmap_mark_free()
217 if (sr->refc_cur) { in xrep_rtbitmap_mark_free()
218 error = xfs_refcount_has_records(sr->refc_cur, in xrep_rtbitmap_mark_free()
219 XFS_REFC_DOMAIN_SHARED, rtb->next_rgbno, in xrep_rtbitmap_mark_free()
220 rgbno - rtb->next_rgbno, &outcome); in xrep_rtbitmap_mark_free()
224 return -EFSCORRUPTED; in xrep_rtbitmap_mark_free()
226 error = xfs_refcount_has_records(sr->refc_cur, in xrep_rtbitmap_mark_free()
227 XFS_REFC_DOMAIN_COW, rtb->next_rgbno, in xrep_rtbitmap_mark_free()
228 rgbno - rtb->next_rgbno, &outcome); in xrep_rtbitmap_mark_free()
232 return -EFSCORRUPTED; in xrep_rtbitmap_mark_free()
235 trace_xrep_rtbitmap_record_free(mp, startrtx, nextrtx - 1); in xrep_rtbitmap_mark_free()
240 xfs_rtblock_t len = nextrtx - startrtx; in xrep_rtbitmap_mark_free()
244 mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit; in xrep_rtbitmap_mark_free()
248 if (error || lastbit - bit == len) in xrep_rtbitmap_mark_free()
250 startrtx += XFS_NBWORD - bit; in xrep_rtbitmap_mark_free()
256 mask = ((xfs_rtword_t)1 << bit) - 1; in xrep_rtbitmap_mark_free()
262 nextrtx -= bit; in xrep_rtbitmap_mark_free()
265 trace_xrep_rtbitmap_record_free_bulk(mp, startrtx, nextrtx - 1); in xrep_rtbitmap_mark_free()
270 bufwsize = mp->m_sb.sb_blocksize >> XFS_WORDLOG; in xrep_rtbitmap_mark_free()
276 wordcnt = min_t(xrep_wordcnt_t, nextwordoff - wordoff, in xrep_rtbitmap_mark_free()
283 rem = wordoff & (bufwsize - 1); in xrep_rtbitmap_mark_free()
286 bufwsize - rem); in xrep_rtbitmap_mark_free()
288 error = xfbmp_copyin(rtb, wordoff, rtb->words, wordcnt); in xrep_rtbitmap_mark_free()
308 if (xchk_should_terminate(rtb->sc, &error)) in xrep_rtbitmap_walk_rtrmap()
311 if (rtb->next_rgbno < rec->rm_startblock) { in xrep_rtbitmap_walk_rtrmap()
312 error = xrep_rtbitmap_mark_free(rtb, rec->rm_startblock); in xrep_rtbitmap_walk_rtrmap()
317 rtb->next_rgbno = max(rtb->next_rgbno, in xrep_rtbitmap_walk_rtrmap()
318 rec->rm_startblock + rec->rm_blockcount); in xrep_rtbitmap_walk_rtrmap()
330 struct xfs_scrub *sc = rtb->sc; in xrep_rtbitmap_find_freespace()
331 struct xfs_mount *mp = sc->mp; in xrep_rtbitmap_find_freespace()
332 struct xfs_rtgroup *rtg = sc->sr.rtg; in xrep_rtbitmap_find_freespace()
337 memset(rtb->words, 0xFF, mp->m_sb.sb_blocksize); in xrep_rtbitmap_find_freespace()
339 xrep_rtgroup_btcur_init(sc, &sc->sr); in xrep_rtbitmap_find_freespace()
340 error = xfs_rmap_query_all(sc->sr.rmap_cur, xrep_rtbitmap_walk_rtrmap, in xrep_rtbitmap_find_freespace()
349 blockcount = rtg->rtg_extents * mp->m_sb.sb_rextsize; in xrep_rtbitmap_find_freespace()
350 if (rtb->next_rgbno < blockcount) { in xrep_rtbitmap_find_freespace()
357 xchk_rtgroup_btcur_free(&sc->sr); in xrep_rtbitmap_find_freespace()
368 struct xfs_mount *mp = sc->mp; in xrep_rtbitmap_prep_buf()
372 rtb->args.mp = sc->mp; in xrep_rtbitmap_prep_buf()
373 rtb->args.tp = sc->tp; in xrep_rtbitmap_prep_buf()
374 rtb->args.rbmbp = bp; in xrep_rtbitmap_prep_buf()
375 ondisk = xfs_rbmblock_wordptr(&rtb->args, 0); in xrep_rtbitmap_prep_buf()
376 rtb->args.rbmbp = NULL; in xrep_rtbitmap_prep_buf()
378 error = xfbmp_copyout(rtb, rtb->prep_wordoff, ondisk, in xrep_rtbitmap_prep_buf()
379 mp->m_blockwsize); in xrep_rtbitmap_prep_buf()
383 if (xfs_has_rtgroups(sc->mp)) { in xrep_rtbitmap_prep_buf()
384 struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; in xrep_rtbitmap_prep_buf()
386 hdr->rt_magic = cpu_to_be32(XFS_RTBITMAP_MAGIC); in xrep_rtbitmap_prep_buf()
387 hdr->rt_owner = cpu_to_be64(sc->ip->i_ino); in xrep_rtbitmap_prep_buf()
388 hdr->rt_blkno = cpu_to_be64(xfs_buf_daddr(bp)); in xrep_rtbitmap_prep_buf()
389 hdr->rt_lsn = 0; in xrep_rtbitmap_prep_buf()
390 uuid_copy(&hdr->rt_uuid, &sc->mp->m_sb.sb_meta_uuid); in xrep_rtbitmap_prep_buf()
391 bp->b_ops = &xfs_rtbitmap_buf_ops; in xrep_rtbitmap_prep_buf()
393 bp->b_ops = &xfs_rtbuf_ops; in xrep_rtbitmap_prep_buf()
396 rtb->prep_wordoff += mp->m_blockwsize; in xrep_rtbitmap_prep_buf()
397 xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_RTBITMAP_BUF); in xrep_rtbitmap_prep_buf()
403 * mapped to written blocks. The caller must ensure that the inode is joined
415 ASSERT(sc->ip != NULL); in xrep_rtbitmap_data_mappings()
424 error = xfs_bmapi_read(sc->ip, off, len - off, &map, &nmaps, in xrep_rtbitmap_data_mappings()
430 return -EFSCORRUPTED; in xrep_rtbitmap_data_mappings()
448 return -EFSCORRUPTED; in xrep_rtbitmap_data_mappings()
453 return -EFSCORRUPTED; in xrep_rtbitmap_data_mappings()
458 error = xfs_bmapi_write(sc->tp, sc->ip, map.br_startoff, in xrep_rtbitmap_data_mappings()
482 struct xfs_mount *mp = sc->mp; in xrep_rtbitmap_geometry()
483 struct xfs_trans *tp = sc->tp; in xrep_rtbitmap_geometry()
486 if (mp->m_sb.sb_rextents != rtb->rextents) in xrep_rtbitmap_geometry()
487 xfs_trans_mod_sb(sc->tp, XFS_TRANS_SB_REXTENTS, in xrep_rtbitmap_geometry()
488 rtb->rextents - mp->m_sb.sb_rextents); in xrep_rtbitmap_geometry()
490 if (mp->m_sb.sb_rbmblocks != rtb->rbmblocks) in xrep_rtbitmap_geometry()
492 rtb->rbmblocks - mp->m_sb.sb_rbmblocks); in xrep_rtbitmap_geometry()
494 if (mp->m_sb.sb_rextslog != rtb->rextslog) in xrep_rtbitmap_geometry()
496 rtb->rextslog - mp->m_sb.sb_rextslog); in xrep_rtbitmap_geometry()
499 sc->ip->i_disk_size = roundup_64(sc->ip->i_disk_size, in xrep_rtbitmap_geometry()
500 mp->m_sb.sb_blocksize); in xrep_rtbitmap_geometry()
502 if (sc->ip->i_disk_size < XFS_FSB_TO_B(mp, rtb->rbmblocks)) in xrep_rtbitmap_geometry()
503 sc->ip->i_disk_size = XFS_FSB_TO_B(mp, rtb->rbmblocks); in xrep_rtbitmap_geometry()
505 xfs_trans_log_inode(sc->tp, sc->ip, XFS_ILOG_CORE); in xrep_rtbitmap_geometry()
514 struct xchk_rtbitmap *rtb = sc->buf; in xrep_rtbitmap()
515 struct xfs_mount *mp = sc->mp; in xrep_rtbitmap()
516 struct xfs_group *xg = rtg_group(sc->sr.rtg); in xrep_rtbitmap()
517 unsigned long long blocks = 0; in xrep_rtbitmap() local
522 if (!xfs_has_rtrmapbt(sc->mp)) in xrep_rtbitmap()
523 return -EOPNOTSUPP; in xrep_rtbitmap()
525 if (!xfs_has_exchange_range(sc->mp)) in xrep_rtbitmap()
526 return -EOPNOTSUPP; in xrep_rtbitmap()
529 if (rtb->rbmblocks > U32_MAX) in xrep_rtbitmap()
537 blocks = xfs_bmbt_calc_size(mp, rtb->rbmblocks); in xrep_rtbitmap()
538 if (blocks > UINT_MAX) in xrep_rtbitmap()
539 return -EOPNOTSUPP; in xrep_rtbitmap()
540 if (blocks > rtb->resblks) { in xrep_rtbitmap()
541 error = xfs_trans_reserve_more(sc->tp, blocks, 0); in xrep_rtbitmap()
545 rtb->resblks += blocks; in xrep_rtbitmap()
553 xfs_trans_ijoin(sc->tp, sc->ip, 0); in xrep_rtbitmap()
556 error = xrep_rtbitmap_data_mappings(sc, rtb->rbmblocks); in xrep_rtbitmap()
573 error = xfs_extent_busy_flush(sc->tp, xg, busy_gen, 0); in xrep_rtbitmap()
599 * file that corresponds to this group. We already joined sc->ip. in xrep_rtbitmap()
601 xfs_trans_ijoin(sc->tp, sc->tempip, 0); in xrep_rtbitmap()
602 error = xrep_tempfile_prealloc(sc, 0, rtb->rbmblocks); in xrep_rtbitmap()
611 error = xrep_tempfile_copyin(sc, 0, rtb->rbmblocks, in xrep_rtbitmap()
616 XFS_FSB_TO_B(sc->mp, sc->mp->m_sb.sb_rbmblocks)); in xrep_rtbitmap()
625 rtb->rbmblocks, &rtb->tempexch); in xrep_rtbitmap()
629 error = xrep_tempexch_contents(sc, &rtb->tempexch); in xrep_rtbitmap()
633 /* Free the old rtbitmap blocks if they're not in use. */ in xrep_rtbitmap()
634 return xrep_reap_ifork(sc, sc->tempip, XFS_DATA_FORK); in xrep_rtbitmap()