Skip to content

Commit e9e2eae

Browse files
Christoph Hellwigdjwong
authored andcommitted
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: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Chandan Rajendra <chandanrlinux@gmail.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent b81b79f commit e9e2eae

11 files changed

Lines changed: 27 additions & 37 deletions

‎fs/xfs/libxfs/xfs_attr_leaf.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ xfs_attr_shortform_bytesfit(
537537
int offset;
538538

539539
/* rounded down */
540-
offset = (XFS_LITINO(mp, dp->i_d.di_version) - bytes) >> 3;
540+
offset = (XFS_LITINO(mp) - bytes) >> 3;
541541

542542
if (dp->i_d.di_format == XFS_DINODE_FMT_DEV) {
543543
minforkoff = roundup(sizeof(xfs_dev_t), 8) >> 3;
@@ -604,8 +604,7 @@ xfs_attr_shortform_bytesfit(
604604
minforkoff = roundup(minforkoff, 8) >> 3;
605605

606606
/* attr fork btree root can have at least this many key/ptr pairs */
607-
maxforkoff = XFS_LITINO(mp, dp->i_d.di_version) -
608-
XFS_BMDR_SPACE_CALC(MINABTPTRS);
607+
maxforkoff = XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(MINABTPTRS);
609608
maxforkoff = maxforkoff >> 3; /* rounded down */
610609

611610
if (offset >= maxforkoff)

‎fs/xfs/libxfs/xfs_bmap.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,12 @@ xfs_default_attroffset(
193193
struct xfs_mount *mp = ip->i_mount;
194194
uint offset;
195195

196-
if (mp->m_sb.sb_inodesize == 256) {
197-
offset = XFS_LITINO(mp, ip->i_d.di_version) -
198-
XFS_BMDR_SPACE_CALC(MINABTPTRS);
199-
} else {
196+
if (mp->m_sb.sb_inodesize == 256)
197+
offset = XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(MINABTPTRS);
198+
else
200199
offset = XFS_BMDR_SPACE_CALC(6 * MINABTPTRS);
201-
}
202200

203-
ASSERT(offset < XFS_LITINO(mp, ip->i_d.di_version));
201+
ASSERT(offset < XFS_LITINO(mp));
204202
return offset;
205203
}
206204

‎fs/xfs/libxfs/xfs_format.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -954,8 +954,12 @@ enum xfs_dinode_fmt {
954954
/*
955955
* Inode size for given fs.
956956
*/
957-
#define XFS_LITINO(mp, version) \
958-
((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version)))
957+
#define XFS_DINODE_SIZE(sbp) \
958+
(xfs_sb_version_has_v3inode(sbp) ? \
959+
sizeof(struct xfs_dinode) : \
960+
offsetof(struct xfs_dinode, di_crc))
961+
#define XFS_LITINO(mp) \
962+
((mp)->m_sb.sb_inodesize - XFS_DINODE_SIZE(&(mp)->m_sb))
959963

960964
/*
961965
* Inode data & attribute fork sizes, per inode.
@@ -964,13 +968,9 @@ enum xfs_dinode_fmt {
964968
#define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3))
965969

966970
#define XFS_DFORK_DSIZE(dip,mp) \
967-
(XFS_DFORK_Q(dip) ? \
968-
XFS_DFORK_BOFF(dip) : \
969-
XFS_LITINO(mp, (dip)->di_version))
971+
(XFS_DFORK_Q(dip) ? XFS_DFORK_BOFF(dip) : XFS_LITINO(mp))
970972
#define XFS_DFORK_ASIZE(dip,mp) \
971-
(XFS_DFORK_Q(dip) ? \
972-
XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \
973-
0)
973+
(XFS_DFORK_Q(dip) ? XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : 0)
974974
#define XFS_DFORK_SIZE(dip,mp,w) \
975975
((w) == XFS_DATA_FORK ? \
976976
XFS_DFORK_DSIZE(dip, mp) : \

‎fs/xfs/libxfs/xfs_ialloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ xfs_ialloc_inode_init(
339339
xfs_buf_zero(fbuf, 0, BBTOB(fbuf->b_length));
340340
for (i = 0; i < M_IGEO(mp)->inodes_per_cluster; i++) {
341341
int ioffset = i << mp->m_sb.sb_inodelog;
342-
uint isize = xfs_dinode_size(version);
342+
uint isize = XFS_DINODE_SIZE(&mp->m_sb);
343343

344344
free = xfs_make_iptr(mp, fbuf, i);
345345
free->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);

‎fs/xfs/libxfs/xfs_inode_buf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ xfs_dinode_verify_forkoff(
417417
case XFS_DINODE_FMT_LOCAL: /* fall through ... */
418418
case XFS_DINODE_FMT_EXTENTS: /* fall through ... */
419419
case XFS_DINODE_FMT_BTREE:
420-
if (dip->di_forkoff >= (XFS_LITINO(mp, dip->di_version) >> 3))
420+
if (dip->di_forkoff >= (XFS_LITINO(mp) >> 3))
421421
return __this_address;
422422
break;
423423
default:

‎fs/xfs/libxfs/xfs_inode_fork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ xfs_iformat_local(
183183
*/
184184
if (unlikely(size > XFS_DFORK_SIZE(dip, ip->i_mount, whichfork))) {
185185
xfs_warn(ip->i_mount,
186-
"corrupt inode %Lu (bad size %d for local fork, size = %d).",
186+
"corrupt inode %Lu (bad size %d for local fork, size = %zd).",
187187
(unsigned long long) ip->i_ino, size,
188188
XFS_DFORK_SIZE(dip, ip->i_mount, whichfork));
189189
xfs_inode_verifier_error(ip, -EFSCORRUPTED,

‎fs/xfs/libxfs/xfs_inode_fork.h‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ struct xfs_ifork {
4646
(ip)->i_afp : \
4747
(ip)->i_cowfp))
4848
#define XFS_IFORK_DSIZE(ip) \
49-
(XFS_IFORK_Q(ip) ? \
50-
XFS_IFORK_BOFF(ip) : \
51-
XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
49+
(XFS_IFORK_Q(ip) ? XFS_IFORK_BOFF(ip) : XFS_LITINO((ip)->i_mount))
5250
#define XFS_IFORK_ASIZE(ip) \
53-
(XFS_IFORK_Q(ip) ? \
54-
XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
55-
XFS_IFORK_BOFF(ip) : \
56-
0)
51+
(XFS_IFORK_Q(ip) ? XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : 0)
5752
#define XFS_IFORK_SIZE(ip,w) \
5853
((w) == XFS_DATA_FORK ? \
5954
XFS_IFORK_DSIZE(ip) : \

‎fs/xfs/libxfs/xfs_log_format.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,10 @@ struct xfs_log_dinode {
424424
/* structure must be padded to 64 bit alignment */
425425
};
426426

427-
static inline uint xfs_log_dinode_size(int version)
428-
{
429-
if (version == 3)
430-
return sizeof(struct xfs_log_dinode);
431-
return offsetof(struct xfs_log_dinode, di_next_unlinked);
432-
}
427+
#define xfs_log_dinode_size(mp) \
428+
(xfs_sb_version_has_v3inode(&(mp)->m_sb) ? \
429+
sizeof(struct xfs_log_dinode) : \
430+
offsetof(struct xfs_log_dinode, di_next_unlinked))
433431

434432
/*
435433
* Buffer Log Format definitions

‎fs/xfs/xfs_inode_item.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ xfs_inode_item_size(
125125

126126
*nvecs += 2;
127127
*nbytes += sizeof(struct xfs_inode_log_format) +
128-
xfs_log_dinode_size(ip->i_d.di_version);
128+
xfs_log_dinode_size(ip->i_mount);
129129

130130
xfs_inode_item_data_fork_size(iip, nvecs, nbytes);
131131
if (XFS_IFORK_Q(ip))
@@ -370,7 +370,7 @@ xfs_inode_item_format_core(
370370

371371
dic = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_ICORE);
372372
xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);
373-
xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_d.di_version));
373+
xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_mount));
374374
}
375375

376376
/*

‎fs/xfs/xfs_log_recover.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ xlog_recover_inode_pass2(
30683068
error = -EFSCORRUPTED;
30693069
goto out_release;
30703070
}
3071-
isize = xfs_log_dinode_size(ldip->di_version);
3071+
isize = xfs_log_dinode_size(mp);
30723072
if (unlikely(item->ri_buf[1].i_len > isize)) {
30733073
XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(7)",
30743074
XFS_ERRLEVEL_LOW, mp, ldip,

0 commit comments

Comments
 (0)