Lines Matching +full:ip +full:- +full:block
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
58 if (args->rbmbp) { in xfs_rtbuf_cache_relse()
59 xfs_trans_brelse(args->tp, args->rbmbp); in xfs_rtbuf_cache_relse()
60 args->rbmbp = NULL; in xfs_rtbuf_cache_relse()
61 args->rbmoff = NULLFILEOFF; in xfs_rtbuf_cache_relse()
63 if (args->sumbp) { in xfs_rtbuf_cache_relse()
64 xfs_trans_brelse(args->tp, args->sumbp); in xfs_rtbuf_cache_relse()
65 args->sumbp = NULL; in xfs_rtbuf_cache_relse()
66 args->sumoff = NULLFILEOFF; in xfs_rtbuf_cache_relse()
71 * Get a buffer for the bitmap or summary file block specified.
77 xfs_fileoff_t block, /* block number in bitmap or summary */ in xfs_rtbuf_get() argument
80 struct xfs_mount *mp = args->mp; in xfs_rtbuf_get()
81 struct xfs_buf **cbpp; /* cached block buffer */ in xfs_rtbuf_get()
82 xfs_fileoff_t *coffp; /* cached block number */ in xfs_rtbuf_get()
83 struct xfs_buf *bp; /* block buffer, result */ in xfs_rtbuf_get()
84 struct xfs_inode *ip; /* bitmap or summary inode */ in xfs_rtbuf_get() local
91 cbpp = &args->sumbp; in xfs_rtbuf_get()
92 coffp = &args->sumoff; in xfs_rtbuf_get()
93 ip = mp->m_rsumip; in xfs_rtbuf_get()
96 cbpp = &args->rbmbp; in xfs_rtbuf_get()
97 coffp = &args->rbmoff; in xfs_rtbuf_get()
98 ip = mp->m_rbmip; in xfs_rtbuf_get()
103 * If we have a cached buffer, and the block number matches, use that. in xfs_rtbuf_get()
105 if (*cbpp && *coffp == block) in xfs_rtbuf_get()
113 xfs_trans_brelse(args->tp, *cbpp); in xfs_rtbuf_get()
117 error = xfs_bmapi_read(ip, block, 1, &map, &nmap, 0); in xfs_rtbuf_get()
124 return -EFSCORRUPTED; in xfs_rtbuf_get()
128 error = xfs_trans_read_buf(mp, args->tp, mp->m_ddev_targp, in xfs_rtbuf_get()
130 mp->m_bsize, 0, &bp, &xfs_rtbuf_ops); in xfs_rtbuf_get()
137 xfs_trans_buf_set_type(args->tp, bp, type); in xfs_rtbuf_get()
139 *coffp = block; in xfs_rtbuf_get()
146 xfs_fileoff_t block) in xfs_rtbitmap_read_buf() argument
148 struct xfs_mount *mp = args->mp; in xfs_rtbitmap_read_buf()
150 if (XFS_IS_CORRUPT(mp, block >= mp->m_sb.sb_rbmblocks)) { in xfs_rtbitmap_read_buf()
152 return -EFSCORRUPTED; in xfs_rtbitmap_read_buf()
155 return xfs_rtbuf_get(args, block, 0); in xfs_rtbitmap_read_buf()
161 xfs_fileoff_t block) in xfs_rtsummary_read_buf() argument
163 struct xfs_mount *mp = args->mp; in xfs_rtsummary_read_buf()
165 if (XFS_IS_CORRUPT(mp, block >= mp->m_rsumblocks)) { in xfs_rtsummary_read_buf()
166 xfs_rt_mark_sick(args->mp, XFS_SICK_RT_SUMMARY); in xfs_rtsummary_read_buf()
167 return -EFSCORRUPTED; in xfs_rtsummary_read_buf()
169 return xfs_rtbuf_get(args, block, 1); in xfs_rtsummary_read_buf()
173 * Searching backward from start find the first block whose allocated/free state
182 struct xfs_mount *mp = args->mp; in xfs_rtfind_back()
184 xfs_fileoff_t block; /* bitmap block number */ in xfs_rtfind_back() local
196 * Compute and read in starting bitmap block for starting block. in xfs_rtfind_back()
198 block = xfs_rtx_to_rbmblock(mp, start); in xfs_rtfind_back()
199 error = xfs_rtbitmap_read_buf(args, block); in xfs_rtfind_back()
207 bit = (int)(start & (XFS_NBWORD - 1)); in xfs_rtfind_back()
211 * then all-ones, else all-zeroes. in xfs_rtfind_back()
214 want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0; in xfs_rtfind_back()
216 * If the starting position is not word-aligned, deal with the in xfs_rtfind_back()
219 if (bit < XFS_NBWORD - 1) { in xfs_rtfind_back()
224 firstbit = max_t(xfs_srtblock_t, bit - len + 1, 0); in xfs_rtfind_back()
225 mask = (((xfs_rtword_t)1 << (bit - firstbit + 1)) - 1) << in xfs_rtfind_back()
235 i = bit - xfs_highbit32(wdiff); in xfs_rtfind_back()
236 *rtx = start - i + 1; in xfs_rtfind_back()
239 i = bit - firstbit + 1; in xfs_rtfind_back()
241 * Go on to previous block if that's where the previous word is in xfs_rtfind_back()
244 if (--word == -1 && i < len) { in xfs_rtfind_back()
246 * If done with this block, get the previous one. in xfs_rtfind_back()
248 error = xfs_rtbitmap_read_buf(args, --block); in xfs_rtfind_back()
252 word = mp->m_blockwsize - 1; in xfs_rtfind_back()
264 while (len - i >= XFS_NBWORD) { in xfs_rtfind_back()
273 i += XFS_NBWORD - 1 - xfs_highbit32(wdiff); in xfs_rtfind_back()
274 *rtx = start - i + 1; in xfs_rtfind_back()
279 * Go on to previous block if that's where the previous word is in xfs_rtfind_back()
282 if (--word == -1 && i < len) { in xfs_rtfind_back()
284 * If done with this block, get the previous one. in xfs_rtfind_back()
286 error = xfs_rtbitmap_read_buf(args, --block); in xfs_rtfind_back()
290 word = mp->m_blockwsize - 1; in xfs_rtfind_back()
297 if (len - i) { in xfs_rtfind_back()
302 firstbit = XFS_NBWORD - (len - i); in xfs_rtfind_back()
303 mask = (((xfs_rtword_t)1 << (len - i)) - 1) << firstbit; in xfs_rtfind_back()
312 i += XFS_NBWORD - 1 - xfs_highbit32(wdiff); in xfs_rtfind_back()
313 *rtx = start - i + 1; in xfs_rtfind_back()
321 *rtx = start - i + 1; in xfs_rtfind_back()
326 * Searching forward from start to limit, find the first block whose
336 struct xfs_mount *mp = args->mp; in xfs_rtfind_forw()
338 xfs_fileoff_t block; /* bitmap block number */ in xfs_rtfind_forw() local
352 * Compute and read in starting bitmap block for starting block. in xfs_rtfind_forw()
354 block = xfs_rtx_to_rbmblock(mp, start); in xfs_rtfind_forw()
355 error = xfs_rtbitmap_read_buf(args, block); in xfs_rtfind_forw()
363 bit = (int)(start & (XFS_NBWORD - 1)); in xfs_rtfind_forw()
364 len = limit - start + 1; in xfs_rtfind_forw()
367 * then all-ones, else all-zeroes. in xfs_rtfind_forw()
370 want = (incore & ((xfs_rtword_t)1 << bit)) ? -1 : 0; in xfs_rtfind_forw()
372 * If the starting position is not word-aligned, deal with the in xfs_rtfind_forw()
381 mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit; in xfs_rtfind_forw()
390 i = xfs_lowbit32(wdiff) - bit; in xfs_rtfind_forw()
391 *rtx = start + i - 1; in xfs_rtfind_forw()
394 i = lastbit - bit; in xfs_rtfind_forw()
396 * Go on to next block if that's where the next word is in xfs_rtfind_forw()
399 if (++word == mp->m_blockwsize && i < len) { in xfs_rtfind_forw()
401 * If done with this block, get the previous one. in xfs_rtfind_forw()
403 error = xfs_rtbitmap_read_buf(args, ++block); in xfs_rtfind_forw()
419 while (len - i >= XFS_NBWORD) { in xfs_rtfind_forw()
429 *rtx = start + i - 1; in xfs_rtfind_forw()
434 * Go on to next block if that's where the next word is in xfs_rtfind_forw()
437 if (++word == mp->m_blockwsize && i < len) { in xfs_rtfind_forw()
439 * If done with this block, get the next one. in xfs_rtfind_forw()
441 error = xfs_rtbitmap_read_buf(args, ++block); in xfs_rtfind_forw()
452 if ((lastbit = len - i)) { in xfs_rtfind_forw()
456 mask = ((xfs_rtword_t)1 << lastbit) - 1; in xfs_rtfind_forw()
466 *rtx = start + i - 1; in xfs_rtfind_forw()
474 *rtx = start + i - 1; in xfs_rtfind_forw()
484 struct xfs_buf *bp = args->sumbp; in xfs_trans_log_rtsummary()
487 first = (void *)xfs_rsumblock_infoptr(args, infoword) - bp->b_addr; in xfs_trans_log_rtsummary()
488 last = first + sizeof(xfs_suminfo_t) - 1; in xfs_trans_log_rtsummary()
490 xfs_trans_log_buf(args->tp, bp, first, last); in xfs_trans_log_rtsummary()
494 * Modify the summary information for a given extent size, bitmap block
501 xfs_fileoff_t bbno, /* bitmap block number */ in xfs_rtmodify_summary()
502 int delta) /* in/out: summary block number */ in xfs_rtmodify_summary()
504 struct xfs_mount *mp = args->mp; in xfs_rtmodify_summary()
517 if (mp->m_rsum_cache) { in xfs_rtmodify_summary()
518 if (val == 0 && log + 1 == mp->m_rsum_cache[bbno]) in xfs_rtmodify_summary()
519 mp->m_rsum_cache[bbno] = log; in xfs_rtmodify_summary()
520 if (val != 0 && log >= mp->m_rsum_cache[bbno]) in xfs_rtmodify_summary()
521 mp->m_rsum_cache[bbno] = log + 1; in xfs_rtmodify_summary()
529 * Read and return the summary information for a given extent size, bitmap block
536 xfs_fileoff_t bbno, /* bitmap block number */ in xfs_rtget_summary()
537 xfs_suminfo_t *sum) /* out: summary info for this block */ in xfs_rtget_summary()
539 struct xfs_mount *mp = args->mp; in xfs_rtget_summary()
549 /* Log rtbitmap block from the word @from to the byte before @next. */
556 struct xfs_buf *bp = args->rbmbp; in xfs_trans_log_rtbitmap()
559 first = (void *)xfs_rbmblock_wordptr(args, from) - bp->b_addr; in xfs_trans_log_rtbitmap()
560 last = ((void *)xfs_rbmblock_wordptr(args, next) - 1) - bp->b_addr; in xfs_trans_log_rtbitmap()
562 xfs_trans_log_buf(args->tp, bp, first, last); in xfs_trans_log_rtbitmap()
576 struct xfs_mount *mp = args->mp; in xfs_rtmodify_range()
578 xfs_fileoff_t block; /* bitmap block number */ in xfs_rtmodify_range() local
588 * Compute starting bitmap block number. in xfs_rtmodify_range()
590 block = xfs_rtx_to_rbmblock(mp, start); in xfs_rtmodify_range()
592 * Read the bitmap block, and point to its data. in xfs_rtmodify_range()
594 error = xfs_rtbitmap_read_buf(args, block); in xfs_rtmodify_range()
602 bit = (int)(start & (XFS_NBWORD - 1)); in xfs_rtmodify_range()
606 val = -val; in xfs_rtmodify_range()
616 mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit; in xfs_rtmodify_range()
626 i = lastbit - bit; in xfs_rtmodify_range()
628 * Go on to the next block if that's where the next word is in xfs_rtmodify_range()
631 if (++word == mp->m_blockwsize && i < len) { in xfs_rtmodify_range()
633 * Log the changed part of this block. in xfs_rtmodify_range()
637 error = xfs_rtbitmap_read_buf(args, ++block); in xfs_rtmodify_range()
653 while (len - i >= XFS_NBWORD) { in xfs_rtmodify_range()
660 * Go on to the next block if that's where the next word is in xfs_rtmodify_range()
663 if (++word == mp->m_blockwsize && i < len) { in xfs_rtmodify_range()
665 * Log the changed part of this block. in xfs_rtmodify_range()
669 error = xfs_rtbitmap_read_buf(args, ++block); in xfs_rtmodify_range()
680 if ((lastbit = len - i)) { in xfs_rtmodify_range()
684 mask = ((xfs_rtword_t)1 << lastbit) - 1; in xfs_rtmodify_range()
712 xfs_rtxlen_t len) /* in/out: summary block number */ in xfs_rtfree_range()
714 struct xfs_mount *mp = args->mp; in xfs_rtfree_range()
720 end = start + len - 1; in xfs_rtfree_range()
738 * Find the next allocated block (end of allocated extent). in xfs_rtfree_range()
740 error = xfs_rtfind_forw(args, end, mp->m_sb.sb_rextents - 1, in xfs_rtfree_range()
750 xfs_highbit64(start - preblock), in xfs_rtfree_range()
751 xfs_rtx_to_rbmblock(mp, preblock), -1); in xfs_rtfree_range()
762 xfs_highbit64(postblock - end), in xfs_rtfree_range()
763 xfs_rtx_to_rbmblock(mp, end + 1), -1); in xfs_rtfree_range()
773 xfs_highbit64(postblock + 1 - preblock), in xfs_rtfree_range()
790 struct xfs_mount *mp = args->mp; in xfs_rtcheck_range()
792 xfs_fileoff_t block; /* bitmap block number */ in xfs_rtcheck_range() local
802 * Compute starting bitmap block number in xfs_rtcheck_range()
804 block = xfs_rtx_to_rbmblock(mp, start); in xfs_rtcheck_range()
806 * Read the bitmap block. in xfs_rtcheck_range()
808 error = xfs_rtbitmap_read_buf(args, block); in xfs_rtcheck_range()
816 bit = (int)(start & (XFS_NBWORD - 1)); in xfs_rtcheck_range()
820 val = -val; in xfs_rtcheck_range()
833 mask = (((xfs_rtword_t)1 << (lastbit - bit)) - 1) << bit; in xfs_rtcheck_range()
842 i = xfs_lowbit32(wdiff) - bit; in xfs_rtcheck_range()
847 i = lastbit - bit; in xfs_rtcheck_range()
849 * Go on to next block if that's where the next word is in xfs_rtcheck_range()
852 if (++word == mp->m_blockwsize && i < len) { in xfs_rtcheck_range()
854 * If done with this block, get the next one. in xfs_rtcheck_range()
856 error = xfs_rtbitmap_read_buf(args, ++block); in xfs_rtcheck_range()
872 while (len - i >= XFS_NBWORD) { in xfs_rtcheck_range()
888 * Go on to next block if that's where the next word is in xfs_rtcheck_range()
891 if (++word == mp->m_blockwsize && i < len) { in xfs_rtcheck_range()
893 * If done with this block, get the next one. in xfs_rtcheck_range()
895 error = xfs_rtbitmap_read_buf(args, ++block); in xfs_rtcheck_range()
906 if ((lastbit = len - i)) { in xfs_rtcheck_range()
910 mask = ((xfs_rtword_t)1 << lastbit) - 1; in xfs_rtcheck_range()
936 * Check that the given extent (block range) is allocated already.
959 * realtime extents, as is the block number.
967 struct xfs_mount *mp = tp->t_mountp; in xfs_rtfree_extent()
975 ASSERT(mp->m_rbmip->i_itemp != NULL); in xfs_rtfree_extent()
976 xfs_assert_ilocked(mp->m_rbmip, XFS_ILOCK_EXCL); in xfs_rtfree_extent()
997 if (tp->t_frextents_delta + mp->m_sb.sb_frextents == in xfs_rtfree_extent()
998 mp->m_sb.sb_rextents) { in xfs_rtfree_extent()
999 if (!(mp->m_rbmip->i_diflags & XFS_DIFLAG_NEWRTBM)) in xfs_rtfree_extent()
1000 mp->m_rbmip->i_diflags |= XFS_DIFLAG_NEWRTBM; in xfs_rtfree_extent()
1002 atime = inode_get_atime(VFS_I(mp->m_rbmip)); in xfs_rtfree_extent()
1004 inode_set_atime_to_ts(VFS_I(mp->m_rbmip), atime); in xfs_rtfree_extent()
1005 xfs_trans_log_inode(tp, mp->m_rbmip, XFS_ILOG_CORE); in xfs_rtfree_extent()
1024 struct xfs_mount *mp = tp->t_mountp; in xfs_rtfree_blocks()
1032 return -EIO; in xfs_rtfree_blocks()
1038 return -EIO; in xfs_rtfree_blocks()
1062 return -EINVAL; in xfs_rtalloc_query_range()
1063 if (start == end || start >= mp->m_sb.sb_rextents) in xfs_rtalloc_query_range()
1066 end = min(end, mp->m_sb.sb_rextents - 1); in xfs_rtalloc_query_range()
1074 /* Is the first block free? */ in xfs_rtalloc_query_range()
1087 rec.ar_extcount = rtend - start + 1; in xfs_rtalloc_query_range()
1109 return xfs_rtalloc_query_range(mp, tp, 0, mp->m_sb.sb_rextents - 1, fn, in xfs_rtalloc_query_all()
1148 return howmany_64(rtextents, NBBY * mp->m_sb.sb_blocksize); in xfs_rtbitmap_blockcount()
1169 xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP); in xfs_rtbitmap_lock()
1170 xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM); in xfs_rtbitmap_lock()
1181 xfs_trans_ijoin(tp, tp->t_mountp->m_rbmip, XFS_ILOCK_EXCL); in xfs_rtbitmap_trans_join()
1182 xfs_trans_ijoin(tp, tp->t_mountp->m_rsumip, XFS_ILOCK_EXCL); in xfs_rtbitmap_trans_join()
1190 xfs_iunlock(mp->m_rsumip, XFS_ILOCK_EXCL | XFS_ILOCK_RTSUM); in xfs_rtbitmap_unlock()
1191 xfs_iunlock(mp->m_rbmip, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP); in xfs_rtbitmap_unlock()
1204 xfs_ilock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP); in xfs_rtbitmap_lock_shared()
1207 xfs_ilock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM); in xfs_rtbitmap_lock_shared()
1217 xfs_iunlock(mp->m_rsumip, XFS_ILOCK_SHARED | XFS_ILOCK_RTSUM); in xfs_rtbitmap_unlock_shared()
1220 xfs_iunlock(mp->m_rbmip, XFS_ILOCK_SHARED | XFS_ILOCK_RTBITMAP); in xfs_rtbitmap_unlock_shared()
1225 struct xfs_inode *ip, in xfs_rtfile_alloc_blocks() argument
1230 struct xfs_mount *mp = ip->i_mount; in xfs_rtfile_alloc_blocks()
1235 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtalloc, in xfs_rtfile_alloc_blocks()
1240 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_rtfile_alloc_blocks()
1241 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); in xfs_rtfile_alloc_blocks()
1243 error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, in xfs_rtfile_alloc_blocks()
1248 error = xfs_bmapi_write(tp, ip, offset_fsb, count_fsb, in xfs_rtfile_alloc_blocks()
1260 /* Get a buffer for the block. */
1263 struct xfs_inode *ip, in xfs_rtfile_initialize_block() argument
1267 struct xfs_mount *mp = ip->i_mount; in xfs_rtfile_initialize_block()
1270 const size_t copylen = mp->m_blockwsize << XFS_WORDLOG; in xfs_rtfile_initialize_block()
1274 if (ip == mp->m_rsumip) in xfs_rtfile_initialize_block()
1279 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growrtzero, 0, 0, 0, &tp); in xfs_rtfile_initialize_block()
1282 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_rtfile_initialize_block()
1283 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); in xfs_rtfile_initialize_block()
1285 error = xfs_trans_get_buf(tp, mp->m_ddev_targp, in xfs_rtfile_initialize_block()
1286 XFS_FSB_TO_DADDR(mp, fsbno), mp->m_bsize, 0, &bp); in xfs_rtfile_initialize_block()
1293 bp->b_ops = &xfs_rtbuf_ops; in xfs_rtfile_initialize_block()
1295 memcpy(bp->b_addr, data, copylen); in xfs_rtfile_initialize_block()
1297 memset(bp->b_addr, 0, copylen); in xfs_rtfile_initialize_block()
1298 xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1); in xfs_rtfile_initialize_block()
1309 struct xfs_inode *ip, /* inode (bitmap/summary) */ in xfs_rtfile_initialize_blocks() argument
1314 struct xfs_mount *mp = ip->i_mount; in xfs_rtfile_initialize_blocks()
1315 const size_t copylen = mp->m_blockwsize << XFS_WORDLOG; in xfs_rtfile_initialize_blocks()
1322 error = xfs_rtfile_alloc_blocks(ip, offset_fsb, in xfs_rtfile_initialize_blocks()
1323 end_fsb - offset_fsb, &map); in xfs_rtfile_initialize_blocks()
1330 * Do this one block per transaction, to keep it simple. in xfs_rtfile_initialize_blocks()
1333 error = xfs_rtfile_initialize_block(ip, in xfs_rtfile_initialize_blocks()