mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
xfs: refactor inode forkoff to byte conversions
A reviewer suggested that I formalize the conversion between the inode forkoff field and actual byte count, so let's add a few conversion macros and a helper function to compute the default forkoff; and then adjust the codebase to use them. No functional changes intended. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
parent
02c8e8d787
commit
ce58cff107
|
|
@ -733,10 +733,10 @@ xfs_attr_shortform_bytesfit(
|
|||
return 0;
|
||||
|
||||
/* rounded down */
|
||||
offset = (XFS_LITINO(mp) - bytes) >> 3;
|
||||
offset = XFS_B_TO_FORKOFFT(XFS_LITINO(mp) - bytes);
|
||||
|
||||
if (dp->i_df.if_format == XFS_DINODE_FMT_DEV) {
|
||||
minforkoff = roundup(sizeof(xfs_dev_t), 8) >> 3;
|
||||
minforkoff = XFS_B_TO_FORKOFF(sizeof(xfs_dev_t));
|
||||
return (offset >= minforkoff) ? minforkoff : 0;
|
||||
}
|
||||
|
||||
|
|
@ -792,12 +792,12 @@ xfs_attr_shortform_bytesfit(
|
|||
* A data fork btree root must have space for at least
|
||||
* MINDBTPTRS key/ptr pairs if the data fork is small or empty.
|
||||
*/
|
||||
minforkoff = max_t(int64_t, dsize, xfs_bmdr_space_calc(MINDBTPTRS));
|
||||
minforkoff = roundup(minforkoff, 8) >> 3;
|
||||
minforkoff = XFS_B_TO_FORKOFF(
|
||||
max_t(int64_t, dsize, xfs_bmdr_space_calc(MINDBTPTRS)));
|
||||
|
||||
/* attr fork btree root can have at least this many key/ptr pairs */
|
||||
maxforkoff = XFS_LITINO(mp) - xfs_bmdr_space_calc(MINABTPTRS);
|
||||
maxforkoff = maxforkoff >> 3; /* rounded down */
|
||||
maxforkoff = XFS_B_TO_FORKOFFT(
|
||||
XFS_LITINO(mp) - xfs_bmdr_space_calc(MINABTPTRS));
|
||||
|
||||
if (offset >= maxforkoff)
|
||||
return maxforkoff;
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ xfs_bmap_forkoff_reset(
|
|||
if (whichfork == XFS_ATTR_FORK &&
|
||||
ip->i_df.if_format != XFS_DINODE_FMT_DEV &&
|
||||
ip->i_df.if_format != XFS_DINODE_FMT_BTREE) {
|
||||
uint dfl_forkoff = xfs_default_attroffset(ip) >> 3;
|
||||
uint dfl_forkoff = xfs_inode_default_forkoff(ip);
|
||||
|
||||
if (dfl_forkoff > ip->i_forkoff)
|
||||
ip->i_forkoff = dfl_forkoff;
|
||||
|
|
@ -997,7 +997,7 @@ xfs_bmap_set_attrforkoff(
|
|||
struct xfs_inode *ip,
|
||||
int size)
|
||||
{
|
||||
int default_size = xfs_default_attroffset(ip) >> 3;
|
||||
int default_size = xfs_inode_default_forkoff(ip);
|
||||
|
||||
switch (ip->i_df.if_format) {
|
||||
case XFS_DINODE_FMT_DEV:
|
||||
|
|
|
|||
|
|
@ -213,6 +213,12 @@ void xfs_bmap_del_extent_cow(struct xfs_inode *ip,
|
|||
struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *got,
|
||||
struct xfs_bmbt_irec *del);
|
||||
uint xfs_default_attroffset(struct xfs_inode *ip);
|
||||
|
||||
static inline uint xfs_inode_default_forkoff(struct xfs_inode *ip)
|
||||
{
|
||||
return XFS_B_TO_FORKOFFT(xfs_default_attroffset(ip));
|
||||
}
|
||||
|
||||
int xfs_bmap_collapse_extents(struct xfs_trans *tp, struct xfs_inode *ip,
|
||||
xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb,
|
||||
bool *done);
|
||||
|
|
|
|||
|
|
@ -1096,7 +1096,11 @@ enum xfs_dinode_fmt {
|
|||
/*
|
||||
* Inode data & attribute fork sizes, per inode.
|
||||
*/
|
||||
#define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3))
|
||||
#define XFS_B_TO_FORKOFFT(b) ((b) >> 3)
|
||||
#define XFS_B_TO_FORKOFF(b) XFS_B_TO_FORKOFFT((b) + 7)
|
||||
#define XFS_FORKOFF_TO_B(f) ((int)(f) << 3)
|
||||
|
||||
#define XFS_DFORK_BOFF(dip) XFS_FORKOFF_TO_B((dip)->di_forkoff)
|
||||
|
||||
#define XFS_DFORK_DSIZE(dip,mp) \
|
||||
((dip)->di_forkoff ? XFS_DFORK_BOFF(dip) : XFS_LITINO(mp))
|
||||
|
|
|
|||
|
|
@ -487,7 +487,7 @@ xfs_dinode_verify_forkoff(
|
|||
|
||||
switch (dip->di_format) {
|
||||
case XFS_DINODE_FMT_DEV:
|
||||
if (dip->di_forkoff != (roundup(sizeof(xfs_dev_t), 8) >> 3))
|
||||
if (dip->di_forkoff != XFS_B_TO_FORKOFF(sizeof(xfs_dev_t)))
|
||||
return __this_address;
|
||||
break;
|
||||
case XFS_DINODE_FMT_META_BTREE:
|
||||
|
|
@ -497,7 +497,7 @@ xfs_dinode_verify_forkoff(
|
|||
case XFS_DINODE_FMT_LOCAL: /* fall through ... */
|
||||
case XFS_DINODE_FMT_EXTENTS: /* fall through ... */
|
||||
case XFS_DINODE_FMT_BTREE:
|
||||
if (dip->di_forkoff >= (XFS_LITINO(mp) >> 3))
|
||||
if (dip->di_forkoff >= XFS_B_TO_FORKOFFT(XFS_LITINO(mp)))
|
||||
return __this_address;
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -345,7 +345,7 @@ xfs_inode_init(
|
|||
}
|
||||
|
||||
if (xfs_icreate_want_attrfork(mp, args)) {
|
||||
ip->i_forkoff = xfs_default_attroffset(ip) >> 3;
|
||||
ip->i_forkoff = xfs_inode_default_forkoff(ip);
|
||||
xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0);
|
||||
|
||||
if (!xfs_has_attr(mp)) {
|
||||
|
|
|
|||
|
|
@ -607,7 +607,7 @@ xchk_dinode(
|
|||
}
|
||||
|
||||
/* di_forkoff */
|
||||
if (dip->di_forkoff >= (XFS_LITINO(mp) >> 3))
|
||||
if (dip->di_forkoff >= XFS_B_TO_FORKOFFT(XFS_LITINO(mp)))
|
||||
xchk_ino_set_corrupt(sc, ino);
|
||||
if (naextents != 0 && dip->di_forkoff == 0)
|
||||
xchk_ino_set_corrupt(sc, ino);
|
||||
|
|
|
|||
|
|
@ -1490,7 +1490,7 @@ xrep_dinode_ensure_forkoff(
|
|||
|
||||
/* Otherwise, just slide the attr fork up. */
|
||||
before = XFS_DFORK_APTR(dip);
|
||||
dip->di_forkoff = bmdr_minsz >> 3;
|
||||
dip->di_forkoff = XFS_B_TO_FORKOFFT(bmdr_minsz);
|
||||
after = XFS_DFORK_APTR(dip);
|
||||
memmove(after, before, XFS_DFORK_ASIZE(dip, sc->mp));
|
||||
}
|
||||
|
|
@ -1522,7 +1522,7 @@ xrep_dinode_ensure_forkoff(
|
|||
* fork is empty, so we don't have any old contents to
|
||||
* move here.
|
||||
*/
|
||||
dip->di_forkoff = (lit_sz - bmdr_minsz) >> 3;
|
||||
dip->di_forkoff = XFS_B_TO_FORKOFFT(lit_sz - bmdr_minsz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ xfs_ifork_ptr(
|
|||
|
||||
static inline unsigned int xfs_inode_fork_boff(struct xfs_inode *ip)
|
||||
{
|
||||
return ip->i_forkoff << 3;
|
||||
return XFS_FORKOFF_TO_B(ip->i_forkoff);
|
||||
}
|
||||
|
||||
static inline unsigned int xfs_inode_data_fork_size(struct xfs_inode *ip)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user