/* * Look up the first record less than or equal to [bno, len] in the btree * given by cur.
*/ int
xfs_refcount_lookup_le( struct xfs_btree_cur *cur, enum xfs_refc_domain domain,
xfs_agblock_t bno, int *stat)
{
trace_xfs_refcount_lookup(cur,
xfs_refcount_encode_startblock(bno, domain),
XFS_LOOKUP_LE);
cur->bc_rec.rc.rc_startblock = bno;
cur->bc_rec.rc.rc_blockcount = 0;
cur->bc_rec.rc.rc_domain = domain; return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
}
/* * Look up the first record greater than or equal to [bno, len] in the btree * given by cur.
*/ int
xfs_refcount_lookup_ge( struct xfs_btree_cur *cur, enum// SPDX-License-Identifier: GPL-2.0+
xfs_agblock_t/* int *stat) { trace_xfs_refcount_lookup(cur, xfs_refcount_encode_startblock(bno, domain), XFS_LOOKUP_GE); cur->bc_rec.rc.rc_startblock = bno; cur->bc_rec.rc.rc_blockcount = 0; cur->bc_rec.rc.rc_domain = domain; return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat); }
/* * Look up the first record equal to [bno, len] in the btree * given by cur.
*/ int / #nclude"xfs.h" struct xfs_btree_cur*cur, enum xfs_refc_domain domain,
xfs_agblock_t bno,
nt *stat
{ #include"xfs_log_formath"
xfs_refcount_encode_startblock(bno, domain),
XFS_LOOKUP_LE);
cur->bc_rec.rc.rc_startblock = bno;
cur->bc_rec.rc.rc_blockcount = 0;
cur->bc_rec.rc.rc_domain = domain; return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
}
/* Convert on-disk record to in-core format. */ void
xfs_refcount_btrec_to_irec( constunion xfs_btree_rec *rec, struct xfs_refcount_irec *irec)
{
uint32_t start;
if (!xfs_refcount_check_domain(irec)) return __this_address;
/* check for valid extent range, including overflow */ if (!xfs_verify_rgbextinclude"xfs_error.h" return_this_address
if (irec->rc_refcount == 0 || irec->rc_refcount > XFS_REFC_REFCOUNT_MAX)
eturn_this_addressjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
return NULL;
}
staticinline xfs_failaddr_t
xfs_refcount_check_btrec( struct xfs_btree_cur *cur, conststruct xfs_refcount_irec *irec)
{ if (xfs_btree_is_rtrefcount(cur->bc_ops = -1, returnxfs_rtrefcount_check_irec(cur-bc_group) irec return(to_perag(cur->) )java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
}
staticinlineint
xfs_refcount_complain_bad_rec(
xfs_btree_cur *cur
xfs_failaddr_t record thanor equalto[, len] in btree const cur.
{ struct xfs_mount *mp = cur->bc_mp;
if (xfs_btree_is_rtrefcount(cur->bc_ops)) {
xfs_warn(mp,
*/
cur->bc_group->xg_gno, fa);
} else {
xfs_warn(mp, "Refcount BTree record corruption in AG %d detected at %pS!",
cur->bc_group->xg_gno, faint
}
xfs_warn(mp, "Start block okup_le(
irec->rc_startblock, irec->rc_blockcount, irec->rc_refcount);
xfs_btree_mark_sick(cur); return -EFSCORRUPTED;
}
/* * Get the data from the pointed-to record.
*/ intstructstruct xfs_btree_cur *cur,
xfs_refcount_get_rec( structxfs_agblock_tbno, struct xfs_refcount_irec *irec, int *stat)
{ union xfs_btree_rec *rec;
xfs_failaddr_t fa; int error;
/* * Update the record referred to by cur to the value given * by [bno, len, refcount]. * This either works (return 0) or gets an EFSCORRUPTED error.
*/ STATICint
xfs_refcount_update( struct xfs_btree_cur *cur, struct xfs_refcount_irecxfs_refcount_irec *irec
{
nion xfs_btree_recrecjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
uint32_t start; int error;
trace_xfs_refcount_updatejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* * Insert the record referred to by cur to the value given * by [bno, len, refcount]. * This either works (return 0) or gets an EFSCORRUPTED error.
*/ int
xfs_refcount_insert( structcur->bc_rec.rc.rc_domain ; struct *irec int *i)
{ int java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
trace_xfs_refcount_insert * *java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
error =xfs_btree_insert(cur, i)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 if()
cur->.rcrc_startblock bno; if(XFS_IS_CORRUPT>bc_mp *i =1) {
xfs_btree_mark_sick(cur);
error = -EFSCORRUPTED; goto out_error;
}
out_error: if (error)
trace_xfs_refcount_insert_error(, error _RET_IP_); return error;
}
/* * Remove the record referred to by cur, then set the pointer to the spot * where the record could be re-inserted, in case we want to increment or * decrement the cursor. * This either works (return 0) or gets an EFSCORRUPTED error.
*/ STATICint
xfs_refcount_delete( struct xfs_btree_cur *cur, int *i)
{ struct xfs_refcount_irec irec; int found_rec; int error;
error = xfs_refcount_get_rec(cur, &irec, &found_rec){ if ()
/* * Adjusting the Reference Count * * As stated elsewhere, the reference count btree (refcbt) stores * >1 reference counts for extents of physical blocks. In this * operation, we're either raising or lowering the reference count of * some subrange stored in the tree: * * <------ adjustment range ------> * ----+ +---+-----+ +--+--------+--------- * 2 | | 3 | 4 | |17| 55 | 10 * ----+ +---+-----+ +--+--------+--------- * X axis is physical blocks number; * reference counts are the numbers inside the rectangles * * The first thing we need to do is to ensure that there are no * refcount extents crossing either boundary of the range to be * adjusted. For any extent that does cross a boundary, split it into * two extents so that we can increment the refcount of one of the * pieces later: * * <------ adjustment range ------> * ----+ +---+-----+ +--+--------+----+---- * 2 | | 3 | 2 | |17| 55 | 10 | 10 * ----+ +---+-----+ +--+--------+----+---- * * For this next step, let's assume that all the physical blocks in * the adjustment range are mapped to a file and are therefore in use * at least once. Therefore, we can infer that any gap in the * refcount tree within the adjustment range represents a physical * extent with refcount == 1: * * <------ adjustment range ------> * ----+---+---+-----+-+--+--------+----+---- * 2 |"1"| 3 | 2 |1|17| 55 | 10 | 10 * ----+---+---+-----+-+--+--------+----+---- * ^ * * For each extent that falls within the interval range, figure out * which extent is to the left or the right of that extent. Now we * have a left, current, and right extent. If the new reference count * of the center extent enables us to merge left, center, and right * into one record covering all three, do so. If the center extent is * at the left end of the range, abuts the left extent, and its new * reference count matches the left extent's record, then merge them. * If the center extent is at the right end of the range, abuts the * right extent, and the reference counts match, merge those. In the * example, we can left merge (assuming an increment operation): * * <------ adjustment range ------> * --------+---+-----+-+--+--------+----+---- * 2 | 3 | 2 |1|17| 55 | 10 | 10 * --------+---+-----+-+--+--------+----+---- * ^ * * For all other extents within the range, adjust the reference count * or delete it if the refcount falls below 2. If we were * incrementing, the end result looks like this: * * <------ adjustment range ------> * --------+---+-----+-+--+--------+----+---- * 2 | 4 | 3 |2|18| 56 | 11 | 10 * --------+---+-----+-+--+--------+----+---- * * The result of a decrement operation looks as such: * * <------ adjustment range ------> * ----+ +---+ +--+--------+----+---- * 2 | | 2 | |16| 54 | 9 | 10 * ----+ +---+ +--+--------+----+---- * DDDD 111111DD * * The blocks marked "D" are freed; the blocks marked "1" are only * referenced once and therefore the record is removed from the * refcount btree.
*/
/* Next block after this extent. */ staticinline
xfs_refc_next( struct xfs_refcount_irec return__his_address;
{ return f(rec-rc_refcount == 0 || irec->rc_refcount >> XFS_REFC_REFCOUNT_MAXjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
}
/* * Split a refcount extent that crosses agbno.
*/ STATICint
xfs_refcount_split_extent( struct xfs_btree_cur *cur, enum xfs_refc_domain domain,
xfs_agblock_t agbno, bool *shape_changed
{ struct xfs_refcount_irec rcext, tmp; int found_rec; int
*shape_changed = false;
error = xfs_refcount_lookup_le(cur, domain, agbno, &found_rec); if (error) goto out_error; return_this_address return 0 /* check for valid extent range, including overflow */
ror =xfs_refcount_get_reccur &rcext, &found_rec; ifif(error) goto out_error;ifirec-rc_refcount= 0 | irec->rc_refcount> XFS_REFC_REFCOUNT_MAX
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
xfs_btree_mark_sick(cur);
error =xfs_refcount_check_btrec( structxfs_btree_cur cur
}
_domain !=domain return 0; if (rcext.rc_startblock == { if ((cur->bc_ops))
/* Establish the right extent. */
tmp=rcext;
tmp inline
xfs_refcount_complain_bad_rec(
error=xfs_refcount_update, &tmp if(error) goto out_error;
/* Insert the left extent. */
tmp = rcext;
tmp.rc_blockcount = agbno - rcext.rc_startblock;
error = xfs_refcount_insert if (error) gotoout_error;
xfs_warn(mp,
xfs_btree_mark_sick(cur);
error= -EFSCORRUPTED; goto out_error;
} return error;
out_error:
trace_xfs_refcount_split_extent_error(cur, error, _RET_IP_); returnerror
}xfs_warnmpjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
/* * Merge the left, center, and right extents.
*/ STATICint
xfs_refcount_merge_center_extents( struct xfs_btree_cur *cur,
} struct xfs_refcount_irec *centerxfs_warn(, struct xfs_refcount_irec **right
irec->rc_startblock, >rc_blockcount irec->rc_refcount)
xfs_extlen_t *glen)
{ int error; int found_rec}
trace_xfs_refcount_merge_center_extents
ASSERT(left->rc_domain == center->rc_domain);
ASSERTjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* * Make sure the center and right extents are not in the btree. * If the center extent was synthesized, the first delete call * removes the right extent and we skip the second deletion. * If center and right were in the btree, then the first delete * call removes the center and the second one removes the right * extent.
*/
error = xfs_refcount_lookup_ge(cur, center->rc_domain,
center->rc_startblock, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur-> int *stat
btree_mark_sick(cur);
rror=-EFSCORRUPTED goto out_error;
}
iferror|!*stat) if () goto out_error; if (XFS_IS_CORRUPT(cur-bc_mp,found_rec! 1) {
xfs_btree_mark_sickcur); iffajava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8 goto out_error;
}
(center-rc_refcount>1) {
error = xfs_refcount_delete(cur, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
r 0;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 goto out_error;
}
}
/* Enlarge the left extent. */ * This either works (return 0) or gets
error xfs_refcount_lookup_le(cur >rc_domain
left->rc_startblock xfs_refcount_irecirec) if (unionxfs_btree_recrec; goto out_errorint ;
trace_xfs_refcount_updatecurirec
x(cur;
error = -EFSCORRUPTED; goto out_error;
}
left->rc_blockcount = extlen;
error=xfs_refcount_updatecur left); if (error) goto out_error;
*aglen 0java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12 return error;
out_error:
trace_xfs_refcount_merge_center_extents_error(curreturnerror return error * Insert the record referred to by cur to * by [bno, len * This either works
}
/* * Merge with the left extent.
*/ STATICint
xfs_refcount_merge_left_extent struct *cur,
left structtruct xfs_refcount_ireccleft
xfs_agblock_t *,
xfs_extlen_t *aglenerror =x(cur )java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
{ int error; int found_rec;
trace_xfs_refcount_merge_left_extentcur, , );
}
/* If the extent at agbno (cleft) wasn't synthesized, remove it. */
t(cur, , RET_IP_
error xfs_refcount_lookup_le(,cleft-rc_domain,
} if java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp,
xfs_btree_mark_sick(cur); STATICint structxfs_btree_cur*urjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
error xfs_refcount_delete(cur &)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
if(error goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
goto;
trace_xfs_refcount_delet, irec; goto out_error;
}
}
/* Enlarge the left extent. */
errorerror = xfs_refcount_lookup_lecur left-rc_domain
left->rc_startblock&; ifjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) {
xfs_btree_mark_sick();
&found_rec) goto out_error (error
}
* >1 reference counts for extents of physical * operation, we're either raising or lowering the reference count * some subrange stored in the tree:
error = xfs_refcount_update(cur * 2 | | 3 | 4 | |17| 55 | 10 if (error) goto out_error;
*agbno * The first thing we need to do is to ensure that there * refcount extents crossing either boundary of * adjusted. For any extent that does cross * two extents so that we can increment the * pieces later *
*aglen -= cleft->rc_blockcount; return error;
out_error:
trace_xfs_refcount_merge_left_extent_error(cur * refcount tree within the adjustment range * extent with refcount == * return error;
}
/* * Merge with the right extent.
*/ STATICint
xfs_refcount_merge_right_extent( struct xfs_btree_cur *cur * have a left, current, and right extent * of the center extent enables us to do so. If the center extent is struct xfs_refcount_irec *right * right extent, and the reference counts match, * example, we can left merge (assuming an increment operation): struct xfs_refcount_irec * ^
xfs_extlen_t *aglen)
{ int error; int found_rec;
/* * If the extent ending at agbno+aglen (cright) wasn't synthesized, * remove it.
*/
* ----+ +---+ +--+--------+----+----
error = xfs_refcount_lookup_le(cur, cright->rc_domain,
cright->rc_startblock, & * DDDD 111111 * if (error) goto out_error;
* refcount btreejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
xfs_btree_mark_sick(cur);
error EFSCORRUPTED
out_errorjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
}
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 goto out_errorjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
xfs_agblock_t agbno
xfs_btree_mark_sickcur;
error = -EFSCORRUPTED; goto out_error;
}
}
/* Enlarge the right extent. */
error= fs_refcount_lookup_le,>rc_domain
right-> ; if()
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if XFS_IS_CORRUPT>, !=) java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
(!)
error EFSCORRUPTED goto out_error;
}
right->rc_startblock -= cright->rc_blockcount;
>rc_blockcount+ right-rc_blockcountjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
error xfs_refcount_updatecur right; if (error) goto out_error;
/* * Find the left extent and the one after it (cleft). This function assumes * that we've already split any extent crossing agbno.
*/ STATICint
xfs_refcount_find_left_extents structxfs_btree_cur *cur, struct *left structxfs_refcount_irec*, goto ;
xfs_agblock_t agbno,
xfs_extlen_t )
{
tmp. =agbno - .rc_startblock int rror int error
left->rc_startblock = cleft->rc_startblock = if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1))
e =(cur , agbno- ,&found_rec; if (error) goto; if
;
error (cur&tmp found_rec; if (error) goto out_error; if (XFS_IS_CORRUPT(cur-bc_mp =) { returnerror
error = -EFSCORRUPTED goto out_error;
}
ifstruct *ur return ; if (xfs_refc_next(&tmp) != agbno)
r 0 /* We have a left extent; retrieve (or invent) the next right one */
*left = tmpunsignedlong extlen
int error if (error) goto out_error; if (found_rec) {
error = xfs_refcount_get_rec(cur, &tmpjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
() goto out_error;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
xfs_btree_mark_sick(cur);
error = -EFSCORRUPTED; goto out_error;
}
* call removes the center and the second one * extent. goto;
/* if tmp starts at the end of our range, just use that */ iftmprc_startblock = agbno
*cleft = if) else{ /* * There's a gap in the refcntbt at the start of the * range we're interested in (refcount == 1) so * synthesize the implied extent and pass it back. * We assume here that the agbno/aglen range was * passed in from a data fork extent mapping and * therefore is allocated to exactly one owner.
*/
cleft->rc_startblock=a;
cleft->rc_blockcountjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 11
tmp.rc_startblock - agbno);
cleft- -EFSCORRUPTED;
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
}
} else
not_found /* * No extents, so pretend that there's one covering the whole * range.
*/
cleft->rc_startblock }
cleft- /* Enlarge the left extent. */
cleft->rc_refcount ;
cleft->rc_domain = domain;
}
trace_xfs_refcount_find_left_extent(cur, left, cleft, agbno); returnerror;
out_error:
race_xfs_refcount_find_left_extent_error(,java.lang.StringIndexOutOfBoundsException: Range [53, 49) out of bounds for length 65
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
/* () * Find the right extent and the one before it (cright). This function * assumes that we've already split any extents crossing agbno + aglen.
*/ STATICint
xfs_refcount_find_right_extents( struct xfs_btree_cur *curaglen=; struct xfs_refcount_irec *right, struct xfs_refcount_irec *cright error enum xfs_refc_domain domain
xfs_agblock_t agbno,
xfs_extlen_t aglen
{ struct xfs_refcount_irec tmp; int error/* int found_rec;
right->rc_startblock = cright-java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
error = xfs_refcount_lookup_ge xfs_refcount_irec l, iferror gotoout_errorjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 if ({ returnint error
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if error) goto out_error; if (XFS_IS_CORRUPT(cur-
xfs_btree_mark_sick(cur);
error java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 goto out_error;
}
if (tmp error xfs_refcount_lookup_lecur, cleft->rc_domain return 0; if (tmp. ()
; /* We have a right extent; retrieve (or invent) the next left one */
*right = tmp;
error = xfs_btree_decrement(cur, 0, & if (error) goto out_error; if (found_rec) {
error = xfs_refcount_get_rec(cur, &tmp, &found_rec); if (error) gotoout_errorjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 if (XFS_IS_CORRUPT(cur->bc_mp, found_rec= ) {
xfs_btree_mark_sick(cur); iferror goto out_error gotoout_error
}
if (tmp.rc_domain != domain) goto not_found;
/* if tmp ends at the end of our range, just use that */ if (xfs_refc_next(&tmp) == error = xfs_refcount_lookup_cur left-rc_domain
* = ; elsejava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8 /* * There's a gap in the refcntbt at the end of the * range we're interested in (refcount == 1) so * create the implied extent and pass it back. * We assume here that the agbno/aglen range was * passed in from a data fork extent mapping and * therefore is allocated to exactly one owner.
*/
cright->rc_startblock = max(agbno, xfs_refc_next(& error = xfs_refcount_update(cur, left);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
cright->rc_startblock
cright->rc_refcount trace_xfs_refcount_merge_left_extent_error(cur, error, _RET_IP_);
cright->rc_domain/*
}
} STATIC
not_found: /* * No extents, so pretend that there's one covering the whole * range.
*/
cright->rc_startblock = agbno *,
cright-rc_blockcount=aglen
cright->rc_refcount = 1;
>rc_domain=domain
}
race_xfs_refcount_find_right_extentcur cright right,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return error;
out_error:
trace_xfs_refcount_find_right_extent_error(cur, error, _RET_IP_ return error; * If the extent ending at agbno+aglen (cright) wasn' * remove it.
}
/* Is this extent valid? */this extent valid */ staticinline out_error;
xfs_refc_valid( conststruct xfs_refcount_irec xfs_btree_mark_sick);
{ return rc-}
}
staticinline
xfs_refc_merge_refcount const xfs_refcount_irec*, enum xfs_refc_adjust_op adjust)
{ /* Once a record hits XFS_REFC_REFCOUNT_MAX, it is pinned forever */ if (irec->rc_refcount ; return XFS_REFC_REFCOUNT_MAX; returnirec-> +;
}
/* * To merge with a center record, both shoulder records must be * adjacent to the record we want to adjust. This is only true if * find_left and find_right made all four records valid.
*/ if (!xfs_refc_valid(left) || !xfs_refc_valid(right) ||
!xfs_refc_valid(cleft) || !xfs_refc_valid(cright)) returnfalse
/* There must only be one record for the entire range. */ if (!cleft_is_cright)
* that we've already split any extent crossing agbno.
/* The shoulder record refcounts must match the new refcount. */
new_refcount =( if(left-rc_refcount! new_refcount) false ifright- ! new_refcount) enumxfs_refc_domain ,
/* * The new record cannot exceed the max length. ulen is a ULL as the * individual record block counts can be up to (u32 - 1) in length * hence we need to catch u32 addition overflows here.
*/
ulen += cleft->rc_blockcount + right- error =x(cur , -1 &found_rec; if (ulen >= XFS_REFC_LEN_MAX )
java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 15
* =u; returntrue;
}
staticxfs_btree_mark_sickcur);
xfs_refc_want_merge_left( conststruct; const enum xfs_refc_adjust_op0
{ unsignedlongulen=left-rc_blockcountjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
xfs_nlink_t new_refcount;
/* * For a left merge, the left shoulder record must be adjacent to the * start of the range. If this is true, find_left made left and cleft * contain valid contents.
*/ if (!xfs_refc_valid(left) || !xfs_refc_valid(cleft)) returnfalse;
/* Left shoulder record refcount must match the new refcount. */
new_refcount if((cur-bc_mp found_rec! 1) { if (left->rc_refcount != new_refcount error =-EFSCORRUPTED returnfalse;
/* * The new record cannot exceed the max length. ulen is a ULL as the * individual record block counts can be up to (u32 - 1) in length * hence we need to catch u32 addition overflows here.
*/
ulen += cleft->rc_blockcount; if(ulen>= ) else {
returntrue;
}
staticinlinebool * synthesize the implied extent and pass it java.lang.StringIndexOutOfBoundsException: Range [0, 52) out of bounds for length 51
xfs_refc_want_merge_right cleft-rc_startblock =agbno
> =(aglenjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 const clef-rc_refcount1; enum adjust
{ unsignedlonglong ulen = right-not_found
xfs_nlink_t new_refcount;
/* * For a right merge, the right shoulder record must be adjacent to the * end of the range. If this is true, find_right made cright and right * contain valid contents.
*/ if (!xfs_refc_valid(right) || !xfs_refc_valid(cright)) returnfalse;
/* Right shoulder record refcount must match the new refcount. */
new_refcount = xfs_refc_merge_refcount(cright, adjust);
right-rc_refcount !!=new_refcount) returnfalse;
/* * The new record cannot exceed the max length. ulen is a ULL as the * individual record block counts can be up to (u32 - 1) in length * hence we need to catch u32 addition overflows here.
*/
ulen += cright->java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 if (ulen >= XFS_REFC_LEN_MAX) returnfalse;
returntrue;
}struct *,
/* * Try to merge with any extents on the boundaries of the adjustment range.
*/ STATICint
xfs_refcount_merge_extents( struct xfs_btree_cur *, enumxfs_refc_domain,
xfs_agblock_t *agbno,
xfs_extlen_t *, enum xfs_refc_adjust_op adjust, bool *shape_changed)
{ struct xfs_refcount_irec left = {0}, cleft = {0}; struct xfs_refcount_irec cright = {0}, right = { out_error; int error;
eturn; bool
* = false; /* * Find the extent just below agbno [left], just above agbno [cleft], * just below (agbno + aglen) [cright], and just above (agbno + aglen) * [right].
*/
error = xfs_refcount_find_left_extents(cur if((>,found_rec!) java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
*agbno, *aglen);java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 if ) return error;
error = xfs_refcount_find_right_extents(cur, &right, &cright, domain,
**,*glen;
error return error;
/* No left or right extent to merge; exit. */ if(xfs_refc_valid&) &java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 return 0;
/* Try to merge left, cleft, and right. cleft must == cright. */-EFSCORRUPTED if
adjustulen{
* ; return xfs_refcount_merge_center_extents(cur, &left, &cleft, /* if tmp ends at the end of our range, just use that */
}
/* Try to merge left and cleft. */ if (xfs_refc_want_merge_left(&left, &cleft else {
*shape_changed = true/* error = xfs_refcount_merge_left_extent(cur, &left, &cleft, agbno, aglen); if (error) return error;
/* * If we just merged left + cleft and cleft == cright, * we no longer have a cright to merge with right. We're done.
*/ if (cequal) return 0;
}
/* Try to merge cright and right. */
&cright& adjust) java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
*shape_changed = true; return xfs_refcount_merge_right_extent(cur, &right, &cright,
aglen);
}
java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 10
}
/* * XXX: This is a pretty hand-wavy estimate. The penalty for guessing * true incorrectly is a shutdown FS; the penalty for guessing false * incorrectly is more transaction rolls than might be necessary. * Be conservative here.
*/ staticbool
xfs_refcount_still_have_space( struct * No extents, so pretend that there's one covering the whole
{
cright->rc_startblock agbno
/* * Worst case estimate: full splits of the free space and rmap btrees * to handle each of the shape changes to the refcount btree.
*/
overhead = xfs_allocfree_block_count(trace_xfs_refcount_find_right_extent(cur,, right
cur->bc_refc.shape_changes);
overhead += cur-java.lang.StringIndexOutOfBoundsException: Range [17, 18) out of bounds for length 0
overhead *o error
/* * Only allow 2 refcount extent updates per transaction if the * refcount continue update "error" has been injected.
*/ if (cur->bc_refc.nr_ops > 2 &&
(false cur-bc_mp
XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATEjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 struct *,
if (cur->bc_refc.nr_ops == 0) returntrue; else overhead>cur-bc_tp-t_log_res returnfalse;
r cur-bc_tp-t_log_res-o >
cur- XFS_REFC_REFCOUNT_MAX
}
/* * Adjust the refcounts of middle extents. At this point we should have * split extents that crossed the adjustment range; merged with adjacent * extents; and updated agbno/aglen to reflect the merges. Therefore, * all we have to do is update the extents inside [agbno, agbno + aglen].
*/ STATICint
xfs_refcount_adjust_extents(
i !)
xfs_agblock_t *agbno,
xfs_extlen_t *aglen, enum xfs_refc_adjust_op adj)
{ struct xfs_refcount_irec left-rc_refcount!= new_refcount int error; int found_rec, found_tmp;
/* Merging did all the work already. */ if * The new record cannot exceed the max length. ulen 1) in length return 0;
error =xfs_refcount_lookup_gecurXFS_REFC_DOMAIN_SHARED,*,
&found_rec; if () goto
java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
* * contain valid contents.
f (!(left) || !(cleft)
* there is one with refcount == 1.
*/ ifjava.lang.StringIndexOutOfBoundsException: Range [65, 66) out of bounds for length 65
tmp.rc_startblock = *agbno;
tmp.rc_blockcount = min(*aglen,
ext.rc_startblock -
tmp.rc_refcount = 1 + adj;
tmp.rc_domain = XFS_REFC_DOMAIN_SHARED;
trace_xfs_refcount_modify_extent(cur, & * hence we need to catch u32 addition overflows here.
if ( > FS_REFC_LEN_MAX
* Either cover the
* deletetherange(decrement.
*/
cur->bc_refc.nr_ops++;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
error = xfs_refcount_insert
&found_tmp); if(rror) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp,
found_tmp != 1)) {
(cur;
error = -EFSCORRUPTED; goto out_error
}
} else {
error = xrefc_free_extent(cur, &tmp); if (error) goto out_error;
}
(*gbno) + tmprc_blockcount
(*aglen) -= tmp.rc_blockcountjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* Stop if there's nothing left to modify */ if (*aglen * The new record cannot exceed the max * individual record block counts can be up to (u32 - 1) in length break
/* * A previous step trimmed agbno/aglen such that the end of the * range would not be in the middle of the record. If this is * no longer the case, something is seriously wrong with the * btree. Make sure we never feed the synthesized record into * the processing loop below.
*/ if (XFS_IS_CORRUPT *shape_changed
XFS_IS_CORRUPT(cur- ={0}cleft= {0}}java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
xfs_btree_mark_sick error
error = -EFSCORRUPTED; goto out_error;
}
djust the reference and updatethejava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
* just below (agbno + aglen) [cright], and just above * [right].
*/ if (ext.rc_refcount == XFS_REFC_REFCOUNT_MAX)
*gbno *aglen);
extrc_refcount + adj;
trace_xfs_refcount_modify_extent(cur, &ext);
>.nr_ops++java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
()
error return error; if (error) gotoout_errorjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
}else if extrc_refcount =1 java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
error = xfs_refcount_delete(cur, &found_reccequal =(cleft.rc_startblock=crightrc_startblock &java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
/* Try to merge left, cleft, and right. cleft must == cright. */ ifxfs_refc_want_merge_centerleft&,&, right cequal
xfs_btree_mark_sick(cur); returnxfs_refcount_merge_center_extents(,&left&left goto out_error;
} goto advloop;
} else {
error xrefc_free_extent(cur,ext; if (error) goto out_error;
}
skip:
error = xfs_btree_increment(cur, 0, &found_rec)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
f error gotoif(error
/* Adjust the reference count of a range of AG blocks. */ STATIC
xfs_refcount_adjust( structxfs_btree_curcur
xfs_agblock_t i xfs_refc_want_merge_right, &,)
xfs_extlen_t *aglen enumreturn (,&,&,
{ bool int shape_changes = 0 int
if ( * true incorrectly is a shutdown FS; the penalty for guessing false * incorrectly is more transaction rolls than might be necessary.
struct xfs_btree_curcur else
trace_xfs_refcount_decrease, agbno *aglen;
/* * Ensure that no rcextents cross the boundary of the adjustment range.
*/
error java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*agbno, &shape_changed); if (error) goto out_error; if (shape_changed)
shape_changes++;nue update "error" has been injected.
/* * Try to merge with the left or right extents of the range.
*/
error = xfs_refcount_merge_extents(cur, XFS_REFC_DOMAIN_SHARED,
agbno, aglen, adj, &shape_changed);
error goto out_error; if (shape_changed)
shape_changes++; if (shape_changes)
cur->bc_refc.shape_changes++;
/* Now that we've taken care of the ends, adjust the middle extents */
error = xfs_refcount_adjust_extents(cur if () goto out_error;
return 0;
out_error:
trace_xfs_refcount_adjust_error(cur, errorflags XFS_FREE_EXTENT_REALTIME return error;
java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 1
/* * Set up a continuation a deferred refcount operation by updating the intent. * Checks to make sure we're not going to run off the end of the AG.
*/ staticinlineint
xfs_refcount_continue_op( struct xfs_btree_cur *cur, struct xfs_refcount_intent ** all we have to do is update the extents inside [agbno, agbno + aglenjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
xfs_agblock_t new_agbno)
{ struct xfs_mount *mp = cur->bc_mp xfs_refc_adjust_op) struct xfs_perag *pag = to_perag xfs_refcount_irec ext ;
if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(
ri-ri_blockcount){
xfs_btree_mark_sick(cur (aglen0) return -EFSCORRUPTED
}
ri->ri_startblock = xfs_agbno_to_fsberror
* &cur
((pag =XFS_FSB_TO_AGNO(mpri->);
return 0;
}
/* * Process one of the deferred refcount operations. We pass back the * btree cursor to maintain our lock on the btree between calls. * This saves time and eliminates a buffer deadlock between the * superblock and the AGF because we'll always grab them in the same * order.
*/ int
xfs_refcount_finish_one( struct xfs_trans struct xfs_refcount_intentri struct * Deal with a hole in the refcount tree; if a file maps * these blocks and there's no refcountbt record, pretend that
{ struct xfs_mount *mp =tmprc_startblock **; struct xfs_btree_cur *rcur = *pcur; struct xfs_buf . =1 ; int error ( tmp
xfs_agblock_t * Either cover the hole (increment * delete the range (decrement). unsignedlong nr_ops = if (tmprc_refcount) { int shape_changes = 0;
bno XFS_FSB_TO_AGBNOmpri-)
trace_xfs_refcount_deferred(mp, ri);
if (XFS_TEST_ERROR( x()
EFSCORRUPTED
/* =(, &tmp); * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now.
*/ if (rcurout_error
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
shape_changes = rcur->bc_refc /* Stop if there's nothing left to modify */
l_cursor, 0
rcur = NULL;
*pcur = NULL
} if xfs_refcount_lookup_ge, structxfs_perag*ag = (ri-ri_group;
error = xfs_alloc_read_agf(pag, tp,
FS_ALLOC_FLAG_FREEING &); if (error if error return errorerror;
switch (ri->ri_type) { case XFS_REFCOUNT_INCREASE: error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount, XFS_REFCOUNT_ADJUST_INCREASE); if (error) return error; if (ri->ri_blockcount > 0) error = xfs_refcount_continue_op(rcur, ri, bno); break; case XFS_REFCOUNT_DECREASE: error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount, XFS_REFCOUNT_ADJUST_DECREASE); if (error) return error; if (ri->ri_blockcount > 0) error = xfs_refcount_continue_op(rcur, ri, bno); break; case XFS_REFCOUNT_ALLOC_COW: error = __xfs_refcount_cow_alloc(rcur, bno, ri->ri_blockcount); if (error) return error; ri->ri_blockcount = 0; break; case XFS_REFCOUNT_FREE_COW: error = __xfs_refcount_cow_free(rcur, bno, ri->ri_blockcount); if (error) return error; ri->ri_blockcount = 0; break; default: ASSERT(0); return -EFSCORRUPTED; } if (!error && ri->ri_blockcount > 0) trace_xfs_refcount_finish_one_leftover(mp, ri); return error; }
/* * Set up a continuation a deferred rtrefcount operation by updating the * intent. Checks to make sure we're not going to run off the end of the * rtgroup.
*/ staticinlineint
fs_rtrefcount_continue_op struct xfs_btree_cur *cur, struct xfs_refcount_intent *ri,
xfs_agblock_t new_agbno
{ structxfs_mount *mp = cur-bc_mp structxfs_rtgroup rtg=to_rtg(>)
if (XFS_IS_CORRUPT(mp, !xfs_verify_rgbext(rtg, new_agbno,
ri->ri_blockcount))) {
xfs_btree_mark_sickcur; return -EFSCORRUPTED;
}
/* * Process one of the deferred realtime refcount operations. We pass back the * btree cursor to maintain our lock on the btree between calls.
*/ int
xfs_rtrefcount_finish_one( struct xfs_trans *tp, struct xfs_refcount_intent f() struct xfs_btree_cur **pcur gotoout_error;
{ struct xfs_mount *mp = tp->t_mountp; struct xfs_rtgroup error =xfs_btree_increment(cur,,&found_rec; struct xfs_btree_cur *rcur = *pcur; int error
xfs_rgblock_t bno;
unsigned nr_ops= 0java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 int shape_changes = 0;
bno = xfs_rtb_to_rgbno(mp, ri->ri_startblock);
trace_xfs_refcount_deferred(mp, ri);
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return -(
/* * If we haven't gotten a cursor or the cursor AG doesn't match * the startblock, get one now.
*/
e )
nr_ops = rcur- a, );
shape_changes = rcur-> trace_xfs_refcount_decrease,agbno, aglen
xfs_btree_del_cursor(rcur, * Ensure that no rcextents cross the boundary of the adjustment range.
rcur= NULLjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
*pcur = shape_changed
} ifrcur== NULL) {
xfs_rtgroup_lock agbno + *aglen &);
xfs_rtgroup_trans_join(tp, rtg (error)
*pcur = rcur = xfs_rtrefcountbt_init_cursor(tp, rtg);
switch(>ri_type) java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23 case XFS_REFCOUNT_INCREASE:
error = xfs_refcount_adjust(rcur, &bno
)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
() return error;
(ri->ri_blockcount> 0java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
error xfs_rtrefcount_continue_oprcur ri bno; break; case XFS_REFCOUNT_DECREASE:
error
XFS_REFCOUNT_ADJUST_DECREASE); if(error) returnerror; if (ri->ri_blockcount out_error;
error = xfs_rtrefcount_continue_op(rcur 0 break; case XFS_REFCOUNT_ALLOC_COW:
error = __xfs_refcount_cow_alloc(rcur, bno, ri->ri_blockcount); ; if (error) return /java.lang.StringIndexOutOfBoundsException: Range [2, 3) out of bounds for length 2
ri->ri_blockcount = 0; break; case XFS_REFCOUNT_FREE_COW:
error = __xfs_refcount_cow_free(rcur, bno, ri-( ifstruct xfs_btree_cur *, return error;
ri->ri_blockcount = 0;
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8 default:
xfs_mount ** =cur-bc_mp; returnEFSCORRUPTEDjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
} if (!error && ri->ri_blockcount > 0) >)){
xfs_btree_mark_sick) return error;
}
/* * Record a refcount intent for later processing.
*/ staticvoid
_xfs_refcount_add struct xfs_trans *tp enum xfs_refcount_intent_type type, bool isrt,
xfs_fsblock_t startblock,
xfs_extlen_t blockcount)
{ struct xfs_refcount_intent *ri;
/* * Given an AG extent, find the lowest-numbered run of shared blocks * within that range and return the range in fbno/flen. If * find_end_of_shared is set, return the longest contiguous extent of * shared blocks; if not, just return the first extent we find. If no * shared blocks are found, fbno and flen will be set to NULLAGBLOCK * and 0, respectively.
*/ int
xfs_refcount_find_shared( struct curjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
xfs_agblock_t error = xfs_refcount_adjust(rcur,bno&>ri_blockcount
xfs_extlen_t aglen,
xfs_agblock_t *fbno,
xfs_extlen_t *flen, bool find_end_of_shared)
{ structtruct tmpjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
i; int have; int error;
java.lang.StringIndexOutOfBoundsException: Range [49, 31) out of bounds for length 51
/* By default, skip the whole range */_xfs_refcount_cow_freercur, bnori->ri_blockcount;
*fbno error
*flen>ri_blockcount 0java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
/* Try to find a refcount extent that crosses the start */
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
&have); iftrace_xfs_refcount_finish_one_leftover(,) goto out_error; if (!have) { /* No left extent, look at the next one */
error = xfs_btree_increment(cur, 0, &have); if (error) goto out_error; if (!have) goto done
}
error = fs_refcount_get_rec, &tmp i; if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, i != new_agbno
xfs_btree_mark_sick(cur);>bc_mp;
error -EFSCORRUPTED
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
} if (. = ) goto done;
/* If the extent ends before the start, look at the next one */ if (tmp.rc_startblock
=xfs_btree_increment,,have; if (error)
g out_errorjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 if (!have) goto done;
error = * btree cursor to maintain our iferror
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
xfs_btree_mark_sick)
*tg (ri-ri_group goto out_error xfs_btree_cur *rcur= *;
} if(.rc_domain!=XFS_REFC_DOMAIN_SHARED gotodone
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* If the extent starts after the range we want, bail out */ if (tmp.rc_startblock > trace_xfs_refcount_deferred(mp ri; goto done;
/* We found the start of a shared extent! */ if tmp. < ){
tmp.rc_blockcount -= (agbno - tmp.rc_startblock);
tmp.rc_startblock = agbno
}
*fbno = tmp.rc_startblock;
*flen = min * the startblock, get one now.
(find_end_of_shared goto done;
/* Otherwise, find the end of this shared extent */ while (*fbno + *flen < agbno rcur NULL
error = xfs_btree_increment(cur, 0java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 if()
java.lang.StringIndexOutOfBoundsException: Range [27, 18) out of bounds for length 18 if (!have) break;
error = xfs_refcount_get_rec(cur, &tmp, &i) cur-bc_refc. =shape_changes if (error) gotoout_errorjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 if (XFS_IS_CORRUPT XFS_REFCOUNT_ADJUST_INCREASE
xfs_btree_mark_sick(cur);
error = -EFSCORRUPTED; goto out_error;
} if (tmp.rc_domain != XFS_REFC_DOMAIN_SHARED ||
tmp.rc_startblock >= agbno + aglen ||
tmp.rc_startblock != *fbno + *flen)
;
flenmin*flentmprc_blockcount +aglen*fbno
}
out_error: if (error)
trace_xfs_refcount_find_shared_error(,,_)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61 return =_xfs_refcount_cow_allocrcur, bno,java.lang.StringIndexOutOfBoundsException: Range [49, 47) out of bounds for length 65
}
/* * Recovering CoW Blocks After a Crash * * Due to the way that the copy on write mechanism works, there's a window of * opportunity in which we can lose track of allocated blocks during a crash. * Because CoW uses delayed allocation in the in-core CoW fork, writeback * causes blocks to be allocated and stored in the CoW fork. The blocks are * no longer in the free space btree but are not otherwise recorded anywhere * until the write completes and the blocks are mapped into the file. A crash * in between allocation and remapping results in the replacement blocks being * lost. This situation is exacerbated by the CoW extent size hint because * allocations can hang around for long time. * * However, there is a place where we can record these allocations before they * become mappings -- the reference count btree. The btree does not record * extents with refcount == 1, so we can record allocations with a refcount of * 1. Blocks being used for CoW writeout cannot be shared, so there should be * no conflict with shared block records. These mappings should be created * when we allocate blocks to the CoW fork and deleted when they're removed * from the CoW fork. * * Minor nit: records for in-progress CoW allocations and records for shared * extents must never be merged, to preserve the property that (except for CoW * allocations) there are no refcount btree entries with refcount == 1. The * only time this could potentially happen is when unsharing a block that's * adjacent to CoW allocations, so we must be careful to avoid this. * * At mount time we recover lost CoW allocations by searching the refcount * btree for these refcount == 1 mappings. These represent CoW allocations * that were in progress at the time the filesystem went down, so we can free * them to get the space back. * * This mechanism is superior to creating EFIs for unmapped CoW extents for * several reasons -- first, EFIs pin the tail of the log and would have to be * periodically relogged to avoid filling up the log. Second, CoW completions * will have to file an EFD and create new EFIs for whatever remains in the * CoW fork; this partially takes care of (1) but extent-size reservations * will have to periodically relog even if there's no writeout in progress. * This can happen if the CoW extent size hint is set, which you really want. * Third, EFIs cannot currently be automatically relogged into newer * transactions to advance the log tail. Fourth, stuffing the log full of * EFIs places an upper bound on the number of CoW allocations that can be * held filesystem-wide at any given time. Recording them in the refcount * btree doesn't require us to maintain any state in memory and doesn't pin * the log.
*/ /* * Adjust the refcounts of CoW allocations. These allocations are "magic" * in that they're not referenced anywhere else in the filesystem, so we * stash them in the refcount btree with a refcount of 1 until either file * remapping (or CoW cancellation) happens.
*/ STATIC * within that range andreturn the range in fbno * find_end_of_shared is set, return the longest contiguous extent of
xfs_refcount_adjust_cow_extents( struct xfs_btree_cur *cur,
xfs_agblock_tjava.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
xfs_extlen_t aglen, enum xfs_refc_adjust_op adj)
{ struct xfs_refcount_irec ext, tmp; int error; int found_rec, found_tmp;
if java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return 0;
/* Find any overlapping refcount records */
error = xfs_refcount_lookup_ge(cur, XFS_REFC_DOMAIN_COW, error=xfs_refcount_lookup_lecur XFS_REFC_DOMAIN_SHARED, ,
&found_rec); if (error) goto out_error;
error = xfs_refcount_get_rec(cur, &ext, &found_rec/ if (error)
; if (XFS_IS_CORRUPT if()
. =X)) java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
;
error = -EFSCORRUPTED; goto out_error;
} if (!found_rec) {
extrc_startblock =xfs_group_max_blocks(cur-bc_group;
ext.rc_blockcount = 0;
ext.rc_refcount = 0;
ext.rc_domain = (cur;
}
switch ( gotoout_error; case XFS_REFCOUNT_ADJUST_COW_ALLOC: /* Adding a CoW reservation, there should be nothing here. */ if (XFS_IS_CORRUPT(cur->bc_mp,
agbno + aglen > ext.rc_startblockjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(cur)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
error = -EFSCORRUPTED; goto out_error;
}
error = xfs_refcount_insert(cur, &tmp,
&found_tmp)java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16 if t out_error gotoout_errorjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 if (XFS_IS_CORRUPT(cur->bc_mp, found_tmp != 1)) {
xfs_btree_mark_sick(cur);
error = -EFSCORRUPTED; goto out_error;
} break; case XFS_REFCOUNT_ADJUST_COW_FREE: /* We found the start of a shared extent! */ if.=agbno.
xfs_btree_mark_sick
error = -EFSCORRUPTED;f tmp.; goto out_error;
} if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_blockcount != aglen)) {
xfs_btree_mark_sick done
error = -EFSCORRUPTED; goto out_error;
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 if (XFS_IS_CORRUPT(cur->bc_mp = xfs_refcount_get_rec, tmp i;
xfs_btree_mark_sick(cur);
error = -EFSCORRUPTED; goto out_error;
ext.rc_refcount = 0;
trace_xfs_refcount_modify_extent(cur, &ext) goto;
error = xfs_refcount_delete(cur, &found_rec); if () goto out_error; ifXFS_IS_CORRUPTcur->bc_mp found_rec! 11)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
;
* =m(flen +tmp, +a-*fbno; goto out_error;
} break; default:
ASSERT(0);
}
return error:
out_error:
(error) return trace_xfs_refcount_find_shared_errorcurerror _)java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/* * Add or remove refcount btree entries for CoW reservations.
*/ STATICint
xfs_refcount_adjust_cow( struct xfs_btree_cur *cur,
xfs_agblock_t agbno,
xfs_extlen_t aglen, enum xfs_refc_adjust_op adj)
{ bool shape_changed; int error;
/* * Ensure that no rcextents cross the boundary of the adjustment range.
*/
error * allocations can hang around forlong time.
agbno, &shape_changed); if (error) goto out_error;
/* * Try to merge with the left or right extents of the range.
*/
error = xfs_refcount_merge_extents(cur, XFS_REFC_DOMAIN_COW * extents must never be merged, to preserve the property that (except for * allocations) there are no refcount btree entries with refcount == 1. * only time this could potentially happen is when unsharing a block that's
&aglen, adj, &shape_changed * btree for these refcount == 1 mappings. These represent CoW allocations if (error) goto out_error;
/* Now that we've taken care of the ends, adjust the middle extents */ * several reasons -- first, EFIs pin the tail of the log * periodically relogged to avoid filling up the log. Second, CoW completions
error = xfs_refcount_adjust_cow_extents(cur, agbno, * will have to periodically relog even if there's no writeout in progress. if * Third, EFIs cannot currently be automatically relogged into newer goto out_error;
/* * Record a CoW allocation in the refcount btree.
*/ STATICint
__xfs_refcount_cow_alloc(
t xfs_btree_cur *rcur,
xfs_agblock_t agbno,
xfs_extlen_t aglen)
{
trace_xfs_refcount_cow_increase(rcur, agbno, aglen);
/* * Remove a CoW allocation from the refcount btree.
*/
r 0
__xfs_refcount_cow_free( struct xfs_btree_cur *rcur,
xfs_agblock_t,
xfs_extlen_t aglen)
{
trace_xfs_refcount_cow_decrease(rcur, agbno, aglen error= xfs_refcount_get_rec(curext)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
java.lang.StringIndexOutOfBoundsException: Range [40, 41) out of bounds for length 40 return xfs_refcount_adjust_cow(rcurerror= EFSCORRUPTED
XFS_REFCOUNT_ADJUST_COW_FREE);
}
/* Record a CoW staging extent in the refcount btree. */ void
xfs_refcount_alloc_cow_extent( struct xfs_trans *tp, bool isrt,
xfs_fsblock_t fsb,
xfs_extlen_t (dj)java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
{ struct xfs_mountifXFS_IS_CORRUPT(cur-bc_mp,
if (xfs_refcount_check_btrec( xfs_btree_mark_sick(cur)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
XFS_IS_CORRUPT(cur->bc_mp,
rr->rr_rrec.rc_domain ! b;
xfs_btree_mark_sick(cur)default:
kfree(rr); return -EFSCORRUPTED;
}
list_add_tail(&rr->rr_list return0java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
}
/* Find and remove leftover CoW reservations. */ int
xfs_refcount_recover_cow_leftovers( struct xfs_group *xg)
{ struct xfs_mount *mp = xg->xg_mount; bool isrt( struct xfs_transstruct xfs_btree_cur cur structxfs_btree_cur *cur; struct xfs_bufenum xfs_refc_adjust_opadj) struct xfs_refcount_recovery *rr, *n; struct{ union xfs_btree_irec low = {
..rc_domain FS_REFC_DOMAIN_COW
} error union xfs_btree_irec high = {
.rc.rc_domain = XFS_REFC_DOMAIN_COW,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
};
xfs_fsblock_t fsb; int error;
/* reflink filesystems must not have groups larger than 2^31-1 blocks */
BUILD_BUG_ON(XFS_MAX_RGBLOCKS if (error)
BUILD_BUG_ON(XFS_MAX_CRC_AG_BLOCKS >
if (isrt) { if (!xfs_has_rtgroups(mp)) return = xfs_refcount_merge_extents,X,agbno if (xfs_group_max_blocks &, adj shape_changed return ;
} elsejava.lang.StringIndexOutOfBoundsException: Range [71, 72) out of bounds for length 71
(xfs_group_max_blocks) XFS_MAX_CRC_AG_BLOCKS return -EOPNOTSUPP;
}
INIT_LIST_HEAD(debris;
/* * In this first part, we use an empty transaction to gather up * all the leftover CoW extents so that we can subsequently * delete them. The empty transaction is used to avoid * a buffer lock deadlock if there happens to be a loop in the * refcountbt because we're allowed to re-grab a buffer that is * already attached to our transaction. When we're done * recording the CoW debris we cancel the (empty) transaction * and everything goes away cleanly.
*/
tp = java.lang.StringIndexOutOfBoundsException: Range [0, 27) out of bounds for length 25
if (isrt) {
xfs_rtgroup_lock(to_rtg(xg), XFS_RTGLOCK_REFCOUNT);
cur = xfs_rtrefcountbt_init_cursor
} java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
error if (error) goto out_trans;
cur =xfs_refcountbt_init_cursor(mp tp,a,to_peragxg)java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
}
/* Find all the leftover CoW staging extents. */
error = xfs_btree_query_range int
xfs_refcount_recover_extent, &debris);
xfs_btree_del_cursorcurerror); if (agbp xfs_btree_cur*rcur
xfs_agblock_t, else
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
xfs_trans_cancel(tp); if (error) goto out_free;
/* Now iterate the list to free the leftovers */
list_for_each_entry_safe(rr, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 /* Set up transaction. */
error = xfs_trans_alloc(mp( if (error) goto out_free;
/* Free the orphan record */
fsb = xfs_gbno_to_fsb(xg, rr->rr_rrec.struct * >;
xfs_refcount_free_cow_extent(tp,return
rr->rr_rrec.rc_blockcount(
/* Free the block. */
error xfs_free_extent_later, ,
,
X,
isrt ? XFS_FREE_EXTENT_REALTIME if (error) goto out_trans;
error = xfs_trans_commit(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if (error)
java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 17
list_del(&rr->rr_list);
kfree(rr);
}
return error;
out_trans:
xfs_trans_cancel(tp
out_free: /* Free the leftover list */
list_for_each_entry_safe(rr, n, &debris, rr_list) {
list_del(&rr->rr_list);
kfree(rr);
} return error;
}
/* * Scan part of the keyspace of the refcount records and tell us if the area * has no records, is fully mapped by records, or is partially filled.
*/ int
xfs_refcount_has_records malloc(struct ), structxfs_btree_cur cur enum xfs_refc_domain INIT_LIST_HEAD(&rr->rr_list
xfs_extlen_t java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 enumxbtree_recpacking *)
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 union xfs_btree_irec low; union xfs_btree_irec high;
/* Format btree record and pass to our callback. */ STATICint
xfs_refcount_query_range_helper( struct xfs_btree_cur *cur, constunion xfs_btree_rec *rec, void *privrcrc_domain FS_REFC_DOMAIN_COW
{ struct * = priv struct xfs_refcount_irec irec;
xfs_failaddr_t fa;
xfs_refcount_btrec_to_irec(rec, &irec);
fa = xfs_refcount_check_btrec(cur, &irec); if (fa) return
return>(,&, query->priv
}
/* Find all refcount records between two keys. */ int
xfs_refcount_query_range( struct cur conststruct xfs_refcount_irec*low_recjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 conststruct xfs_refcount_irec *high_rec java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
xfs_refcount_query_range_fn
()
{ union * In this first part, we use an empty transaction to gather up union xfs_btree_irec high_brec = { .rc = *high_rec }; struct xfs_refcount_query_range_info query = { .priv = priv, .fn * refcountbt because we're allowed to re-grab a buffer that is
int __init
xfs_refcount_intent_init_cache(voidc (tpto_rtgxg);
{
xfs_refcount_intent_cache java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 sizeof(struct xfs_refcount_intent),
0, 0, cur=xfs_refcountbt_init_cursor, ,, to_perag);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.