Commit e9e2eae8 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: only check the superblock version for dinode size calculation

The size of the dinode structure is only dependent on the file system
version, so instead of checking the individual inode version just use
the newly added xfs_sb_version_has_large_dinode helper, and simplify
various calling conventions.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarChandan Rajendra <chandanrlinux@gmail.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent b81b79f4
...@@ -537,7 +537,7 @@ xfs_attr_shortform_bytesfit( ...@@ -537,7 +537,7 @@ xfs_attr_shortform_bytesfit(
int offset; int offset;
/* rounded down */ /* rounded down */
offset = (XFS_LITINO(mp, dp->i_d.di_version) - bytes) >> 3; offset = (XFS_LITINO(mp) - bytes) >> 3;
if (dp->i_d.di_format == XFS_DINODE_FMT_DEV) { if (dp->i_d.di_format == XFS_DINODE_FMT_DEV) {
minforkoff = roundup(sizeof(xfs_dev_t), 8) >> 3; minforkoff = roundup(sizeof(xfs_dev_t), 8) >> 3;
...@@ -604,8 +604,7 @@ xfs_attr_shortform_bytesfit( ...@@ -604,8 +604,7 @@ xfs_attr_shortform_bytesfit(
minforkoff = roundup(minforkoff, 8) >> 3; minforkoff = roundup(minforkoff, 8) >> 3;
/* attr fork btree root can have at least this many key/ptr pairs */ /* attr fork btree root can have at least this many key/ptr pairs */
maxforkoff = XFS_LITINO(mp, dp->i_d.di_version) - maxforkoff = XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(MINABTPTRS);
XFS_BMDR_SPACE_CALC(MINABTPTRS);
maxforkoff = maxforkoff >> 3; /* rounded down */ maxforkoff = maxforkoff >> 3; /* rounded down */
if (offset >= maxforkoff) if (offset >= maxforkoff)
......
...@@ -193,14 +193,12 @@ xfs_default_attroffset( ...@@ -193,14 +193,12 @@ xfs_default_attroffset(
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
uint offset; uint offset;
if (mp->m_sb.sb_inodesize == 256) { if (mp->m_sb.sb_inodesize == 256)
offset = XFS_LITINO(mp, ip->i_d.di_version) - offset = XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(MINABTPTRS);
XFS_BMDR_SPACE_CALC(MINABTPTRS); else
} else {
offset = XFS_BMDR_SPACE_CALC(6 * MINABTPTRS); offset = XFS_BMDR_SPACE_CALC(6 * MINABTPTRS);
}
ASSERT(offset < XFS_LITINO(mp, ip->i_d.di_version)); ASSERT(offset < XFS_LITINO(mp));
return offset; return offset;
} }
......
...@@ -954,8 +954,12 @@ enum xfs_dinode_fmt { ...@@ -954,8 +954,12 @@ enum xfs_dinode_fmt {
/* /*
* Inode size for given fs. * Inode size for given fs.
*/ */
#define XFS_LITINO(mp, version) \ #define XFS_DINODE_SIZE(sbp) \
((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version))) (xfs_sb_version_has_v3inode(sbp) ? \
sizeof(struct xfs_dinode) : \
offsetof(struct xfs_dinode, di_crc))
#define XFS_LITINO(mp) \
((mp)->m_sb.sb_inodesize - XFS_DINODE_SIZE(&(mp)->m_sb))
/* /*
* Inode data & attribute fork sizes, per inode. * Inode data & attribute fork sizes, per inode.
...@@ -964,13 +968,9 @@ enum xfs_dinode_fmt { ...@@ -964,13 +968,9 @@ enum xfs_dinode_fmt {
#define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3)) #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3))
#define XFS_DFORK_DSIZE(dip,mp) \ #define XFS_DFORK_DSIZE(dip,mp) \
(XFS_DFORK_Q(dip) ? \ (XFS_DFORK_Q(dip) ? XFS_DFORK_BOFF(dip) : XFS_LITINO(mp))
XFS_DFORK_BOFF(dip) : \
XFS_LITINO(mp, (dip)->di_version))
#define XFS_DFORK_ASIZE(dip,mp) \ #define XFS_DFORK_ASIZE(dip,mp) \
(XFS_DFORK_Q(dip) ? \ (XFS_DFORK_Q(dip) ? XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : 0)
XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \
0)
#define XFS_DFORK_SIZE(dip,mp,w) \ #define XFS_DFORK_SIZE(dip,mp,w) \
((w) == XFS_DATA_FORK ? \ ((w) == XFS_DATA_FORK ? \
XFS_DFORK_DSIZE(dip, mp) : \ XFS_DFORK_DSIZE(dip, mp) : \
......
...@@ -339,7 +339,7 @@ xfs_ialloc_inode_init( ...@@ -339,7 +339,7 @@ xfs_ialloc_inode_init(
xfs_buf_zero(fbuf, 0, BBTOB(fbuf->b_length)); xfs_buf_zero(fbuf, 0, BBTOB(fbuf->b_length));
for (i = 0; i < M_IGEO(mp)->inodes_per_cluster; i++) { for (i = 0; i < M_IGEO(mp)->inodes_per_cluster; i++) {
int ioffset = i << mp->m_sb.sb_inodelog; int ioffset = i << mp->m_sb.sb_inodelog;
uint isize = xfs_dinode_size(version); uint isize = XFS_DINODE_SIZE(&mp->m_sb);
free = xfs_make_iptr(mp, fbuf, i); free = xfs_make_iptr(mp, fbuf, i);
free->di_magic = cpu_to_be16(XFS_DINODE_MAGIC); free->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
......
...@@ -417,7 +417,7 @@ xfs_dinode_verify_forkoff( ...@@ -417,7 +417,7 @@ xfs_dinode_verify_forkoff(
case XFS_DINODE_FMT_LOCAL: /* fall through ... */ case XFS_DINODE_FMT_LOCAL: /* fall through ... */
case XFS_DINODE_FMT_EXTENTS: /* fall through ... */ case XFS_DINODE_FMT_EXTENTS: /* fall through ... */
case XFS_DINODE_FMT_BTREE: case XFS_DINODE_FMT_BTREE:
if (dip->di_forkoff >= (XFS_LITINO(mp, dip->di_version) >> 3)) if (dip->di_forkoff >= (XFS_LITINO(mp) >> 3))
return __this_address; return __this_address;
break; break;
default: default:
......
...@@ -183,7 +183,7 @@ xfs_iformat_local( ...@@ -183,7 +183,7 @@ xfs_iformat_local(
*/ */
if (unlikely(size > XFS_DFORK_SIZE(dip, ip->i_mount, whichfork))) { if (unlikely(size > XFS_DFORK_SIZE(dip, ip->i_mount, whichfork))) {
xfs_warn(ip->i_mount, xfs_warn(ip->i_mount,
"corrupt inode %Lu (bad size %d for local fork, size = %d).", "corrupt inode %Lu (bad size %d for local fork, size = %zd).",
(unsigned long long) ip->i_ino, size, (unsigned long long) ip->i_ino, size,
XFS_DFORK_SIZE(dip, ip->i_mount, whichfork)); XFS_DFORK_SIZE(dip, ip->i_mount, whichfork));
xfs_inode_verifier_error(ip, -EFSCORRUPTED, xfs_inode_verifier_error(ip, -EFSCORRUPTED,
......
...@@ -46,14 +46,9 @@ struct xfs_ifork { ...@@ -46,14 +46,9 @@ struct xfs_ifork {
(ip)->i_afp : \ (ip)->i_afp : \
(ip)->i_cowfp)) (ip)->i_cowfp))
#define XFS_IFORK_DSIZE(ip) \ #define XFS_IFORK_DSIZE(ip) \
(XFS_IFORK_Q(ip) ? \ (XFS_IFORK_Q(ip) ? XFS_IFORK_BOFF(ip) : XFS_LITINO((ip)->i_mount))
XFS_IFORK_BOFF(ip) : \
XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
#define XFS_IFORK_ASIZE(ip) \ #define XFS_IFORK_ASIZE(ip) \
(XFS_IFORK_Q(ip) ? \ (XFS_IFORK_Q(ip) ? XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : 0)
XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
XFS_IFORK_BOFF(ip) : \
0)
#define XFS_IFORK_SIZE(ip,w) \ #define XFS_IFORK_SIZE(ip,w) \
((w) == XFS_DATA_FORK ? \ ((w) == XFS_DATA_FORK ? \
XFS_IFORK_DSIZE(ip) : \ XFS_IFORK_DSIZE(ip) : \
......
...@@ -424,12 +424,10 @@ struct xfs_log_dinode { ...@@ -424,12 +424,10 @@ struct xfs_log_dinode {
/* structure must be padded to 64 bit alignment */ /* structure must be padded to 64 bit alignment */
}; };
static inline uint xfs_log_dinode_size(int version) #define xfs_log_dinode_size(mp) \
{ (xfs_sb_version_has_v3inode(&(mp)->m_sb) ? \
if (version == 3) sizeof(struct xfs_log_dinode) : \
return sizeof(struct xfs_log_dinode); offsetof(struct xfs_log_dinode, di_next_unlinked))
return offsetof(struct xfs_log_dinode, di_next_unlinked);
}
/* /*
* Buffer Log Format definitions * Buffer Log Format definitions
......
...@@ -125,7 +125,7 @@ xfs_inode_item_size( ...@@ -125,7 +125,7 @@ xfs_inode_item_size(
*nvecs += 2; *nvecs += 2;
*nbytes += sizeof(struct xfs_inode_log_format) + *nbytes += sizeof(struct xfs_inode_log_format) +
xfs_log_dinode_size(ip->i_d.di_version); xfs_log_dinode_size(ip->i_mount);
xfs_inode_item_data_fork_size(iip, nvecs, nbytes); xfs_inode_item_data_fork_size(iip, nvecs, nbytes);
if (XFS_IFORK_Q(ip)) if (XFS_IFORK_Q(ip))
...@@ -370,7 +370,7 @@ xfs_inode_item_format_core( ...@@ -370,7 +370,7 @@ xfs_inode_item_format_core(
dic = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_ICORE); dic = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_ICORE);
xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn); xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);
xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_d.di_version)); xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_mount));
} }
/* /*
......
...@@ -3068,7 +3068,7 @@ xlog_recover_inode_pass2( ...@@ -3068,7 +3068,7 @@ xlog_recover_inode_pass2(
error = -EFSCORRUPTED; error = -EFSCORRUPTED;
goto out_release; goto out_release;
} }
isize = xfs_log_dinode_size(ldip->di_version); isize = xfs_log_dinode_size(mp);
if (unlikely(item->ri_buf[1].i_len > isize)) { if (unlikely(item->ri_buf[1].i_len > isize)) {
XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(7)", XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(7)",
XFS_ERRLEVEL_LOW, mp, ldip, XFS_ERRLEVEL_LOW, mp, ldip,
......
...@@ -192,7 +192,7 @@ xfs_symlink( ...@@ -192,7 +192,7 @@ xfs_symlink(
* The symlink will fit into the inode data fork? * The symlink will fit into the inode data fork?
* There can't be any attributes so we get the whole variable part. * There can't be any attributes so we get the whole variable part.
*/ */
if (pathlen <= XFS_LITINO(mp, dp->i_d.di_version)) if (pathlen <= XFS_LITINO(mp))
fs_blocks = 0; fs_blocks = 0;
else else
fs_blocks = xfs_symlink_blocks(mp, pathlen); fs_blocks = xfs_symlink_blocks(mp, pathlen);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment