/* * Extract the blockcount field from an on disk bmap extent record.
*/
xfs_filblks_t
xfs_bmbt_disk_get_blockcount( conststruct xfs_bmbt_rec *r)
{ return (xfs_filblks_t)(be64_to_cpu(r->l1) & xfs_mask64lo(21));
}
/* * Extract the startoff field from a disk format bmap extent record.
*/
xfs_fileoff_t
xfs_bmbt_disk_get_startoff( conststruct xfs_bmbt_rec *r)
{ return ((xfs_fileoff_t)be64_to_cpu(r->l0) &
xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
}
/* * Set all the fields in a bmap extent record from the uncompressed form.
*/ void
xfs_bmbt_disk_set_all( struct xfs_bmbt_rec *r, struct xfs_bmbt_irec *s)
{ int extent_flag = (s->br_state != XFS_EXT_NORM);
/* * If we are coming here from something like unwritten extent * conversion, there has been no data extent allocation already done, so * we have to ensure that we attempt to locate the entire set of bmbt * allocations in the same AG, as xfs_bmapi_write() would have reserved.
*/ if (cur->bc_tp->t_highest_agno == NULLAGNUMBER)
args.minleft = xfs_bmapi_minleft(cur->bc_tp, cur->bc_ino.ip,
cur->bc_ino.whichfork);
error = xfs_alloc_vextent_start_ag(&args, be64_to_cpu(start->l)); if (error) return error;
if (args.fsbno == NULLFSBLOCK && args.minleft) { /* * Could not find an AG with enough free space to satisfy * a full btree split. Try again and if * successful activate the lowspace algorithm.
*/
args.minleft = 0;
error = xfs_alloc_vextent_start_ag(&args, 0); if (error) return error;
cur->bc_tp->t_flags |= XFS_TRANS_LOWMODE;
} if (WARN_ON_ONCE(args.fsbno == NULLFSBLOCK)) {
*stat = 0; return 0;
}
/* * Get the maximum records we could store in the on-disk format. * * For non-root nodes this is equivalent to xfs_bmbt_get_maxrecs, but * for the root node this checks the available space in the dinode fork * so that we can resize the in-memory buffer to match it. After a * resize to the maximum size this function returns the same value * as xfs_bmbt_get_maxrecs for the root node, too.
*/ STATICint
xfs_bmbt_get_dmaxrecs( struct xfs_btree_cur *cur, int level)
{ if (level != cur->bc_nlevels - 1) return cur->bc_mp->m_bmap_dmxr[level != 0]; return xfs_bmdr_maxrecs(cur->bc_ino.forksize, level == 0);
}
if (!xfs_verify_magic(bp, block->bb_magic)) return __this_address;
if (xfs_has_crc(mp)) { /* * XXX: need a better way of verifying the owner here. Right now * just make sure there has been one set.
*/
fa = xfs_btree_fsblock_v5hdr_verify(bp, XFS_RMAP_OWN_UNKNOWN); if (fa) return fa;
}
/* * numrecs and level verification. * * We don't know what fork we belong to, so just verify that the level * is less than the maximum of the two. Later checks will be more * precise.
*/
level = be16_to_cpu(block->bb_level); if (level > max(mp->m_bm_maxlevels[0], mp->m_bm_maxlevels[1])) return __this_address;
/* * Reallocate the space for if_broot based on the number of records. Move the * records and pointers in if_broot to fit the new size. When shrinking this * will eliminate holes between the records and pointers created by the caller. * When growing this will create holes to be filled in by the caller. * * The caller must not request to add more records than would fit in the * on-disk inode root. If the if_broot is currently NULL, then if we are * adding records, one will be allocated. The caller must also not request * that the number of records go below zero, although it can go to zero. * * ip -- the inode whose if_broot area is changing * whichfork -- which inode fork to change * new_numrecs -- the new number of records requested for the if_broot array * * Returns the incore btree root block.
*/ struct xfs_btree_block *
xfs_bmap_broot_realloc( struct xfs_inode *ip, int whichfork, unsignedint new_numrecs)
{ struct xfs_mount *mp = ip->i_mount; struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); struct xfs_btree_block *broot; unsignedint new_size; unsignedint old_size = ifp->if_broot_bytes;
/* * Block mapping btrees do not support storing zero records; if this * happens, the fork is being changed to FMT_EXTENTS. Free the broot * and get out.
*/ if (new_numrecs == 0) return xfs_broot_realloc(ifp, 0);
/* Handle the nop case quietly. */ if (new_size == old_size) return ifp->if_broot;
if (new_size > old_size) { unsignedint old_numrecs;
/* * If there wasn't any memory allocated before, just * allocate it now and get out.
*/ if (old_size == 0) return xfs_broot_realloc(ifp, new_size);
/* * If there is already an existing if_broot, then we need * to realloc() it and shift the pointers to their new * location. The records don't change location because * they are kept butted up against the btree block header.
*/
old_numrecs = xfs_bmbt_maxrecs(mp, old_size, false);
broot = xfs_broot_realloc(ifp, new_size);
ASSERT(xfs_bmap_bmdr_space(broot) <=
xfs_inode_fork_size(ip, whichfork));
xfs_bmbt_move_ptrs(mp, broot, old_size, new_size, old_numrecs); return broot;
}
/* * We're reducing, but not totally eliminating, numrecs. In this case, * we are shrinking the if_broot buffer, so it must already exist.
*/
ASSERT(ifp->if_broot != NULL && old_size > 0 && new_size > 0);
/* * Shrink the btree root by moving the bmbt pointers, since they are * not butted up against the btree block header, then reallocating * broot.
*/
xfs_bmbt_move_ptrs(mp, ifp->if_broot, old_size, new_size, new_numrecs);
broot = xfs_broot_realloc(ifp, new_size);
ASSERT(xfs_bmap_bmdr_space(broot) <=
xfs_inode_fork_size(ip, whichfork)); return broot;
}
/* Calculate number of records in a block mapping btree block. */ staticinlineunsignedint
xfs_bmbt_block_maxrecs( unsignedint blocklen, bool leaf)
{ if (leaf) return blocklen / sizeof(xfs_bmbt_rec_t); return blocklen / (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t));
}
/* * Swap in the new inode fork root. Once we pass this point the newly rebuilt * mappings are in place and we have to kill off any old btree blocks.
*/ void
xfs_bmbt_commit_staged_btree( struct xfs_btree_cur *cur, struct xfs_trans *tp, int whichfork)
{ struct xbtree_ifakeroot *ifake = cur->bc_ino.ifake; struct xfs_ifork *ifp; staticconstshort brootflag[2] = {XFS_ILOG_DBROOT, XFS_ILOG_ABROOT}; staticconstshort extflag[2] = {XFS_ILOG_DEXT, XFS_ILOG_AEXT}; int flags = XFS_ILOG_CORE;
/* * Free any resources hanging off the real fork, then shallow-copy the * staging fork's contents into the real fork to transfer everything * we just built.
*/
ifp = xfs_ifork_ptr(cur->bc_ino.ip, whichfork);
xfs_idestroy_fork(ifp);
memcpy(ifp, ifake->if_fork, sizeof(struct xfs_ifork));
/* * Calculate number of records in a bmap btree block.
*/ unsignedint
xfs_bmbt_maxrecs( struct xfs_mount *mp, unsignedint blocklen, bool leaf)
{
blocklen -= xfs_bmbt_block_len(mp); return xfs_bmbt_block_maxrecs(blocklen, leaf);
}
/* * Calculate the maximum possible height of the btree that the on-disk format * supports. This is used for sizing structures large enough to support every * possible configuration of a filesystem that might get mounted.
*/ unsignedint
xfs_bmbt_maxlevels_ondisk(void)
{ unsignedint minrecs[2]; unsignedint blocklen;
/* * Change the owner of a btree format fork fo the inode passed in. Change it to * the owner of that is passed in so that we can change owners before or after * we switch forks between inodes. The operation that the caller is doing will * determine whether is needs to change owner before or after the switch. * * For demand paged transactional modification, the fork switch should be done * after reading in all the blocks, modifying them and pinning them in the * transaction. For modification when the buffers are already pinned in memory, * the fork switch can be done before changing the owner as we won't need to * validate the owner until the btree buffers are unpinned and writes can occur * again. * * For recovery based ownership change, there is no transactional context and * so a buffer list must be supplied so that we can record the buffers that we * modified for the caller to issue IO on.
*/ int
xfs_bmbt_change_owner( struct xfs_trans *tp, struct xfs_inode *ip, int whichfork,
xfs_ino_t new_owner, struct list_head *buffer_list)
{ struct xfs_btree_cur *cur; int error;
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.