xfs: Extend per-inode extent counters
cover xfs: Extend per-inode extent counters
The commit xfs: fix inode fork extent count overflow (3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this patchset extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.
Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.
Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this patchset extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.
I did try in vain to get this done in a seamless way (i.e. setting an ro-compat flag just in time when extent counter is about to overflow). The maximum height of data and attr BMBT trees are a function of maximum number of per-inode data and attr extents respectively. Due to increase in the maximum value of data/attr extents, the maximum height of the data/attr BMBT tree increased causing the dependent log reservation values to increase as well.
Increased log reservation values caused "minimum log reservation size" check to fail in some scenarios and hence mount syscall would return with an error. Reducing log reservation values by making the corresponding calculations more precise is not an option since these code changes, once percolated to mkfs.xfs, could create filesystems that won't mount on older kernels (Please refer to the discussion at
https://www.spinics.net/lists/linux-xfs/msg42061.html).
The patchset has been tested by executing xfstests with the following mkfs.xfs options,
1. -m crc=0 -b size=1k
2. -m crc=0 -b size=4k
3. -m crc=0 -b size=512
4. -m rmapbt=1,reflink=1 -b size=1k
5. -m rmapbt=1,reflink=1 -b size=4k
Each of the above test scenarios were executed on the following combinations (For V4 FS test scenario, the last combination i.e. "Patched (enable widextcnt)", was omitted).
|-----------------------------+-----------| | Xfsprogs | Kernel | |-----------------------------+-----------| | Unpatched | Patched | | Patched (disable widextcnt) | Unpatched | | Patched (disable widextcnt) | Patched | | Patched (enable widextcnt) | Patched | |-----------------------------+-----------|
This patchset is built on top of V3 of "Bail out if transaction can cause extent count to overflow" patchset. It can also be obtained from https://github.com/chandanr/linux.git at branch xfs-incompat-extend-extcnt-v1.
I will be posting the changes associated with xfsprogs separately.
Chandan Babu R (3):
xfs: Introduce xfs_iext_max() helper
xfs: Introduce xfs_dfork_nextents() helper
xfs: Extend data/attr fork extent counter width
fs/xfs/libxfs/xfs_bmap.c | 17 ++++---- fs/xfs/libxfs/xfs_format.h | 24 +++++++----- fs/xfs/libxfs/xfs_inode_buf.c | 69 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 6 ++- fs/xfs/libxfs/xfs_inode_fork.c | 10 +++-- fs/xfs/libxfs/xfs_inode_fork.h | 19 ++++++++- fs/xfs/libxfs/xfs_log_format.h | 8 ++-- fs/xfs/libxfs/xfs_types.h | 10 +++-- fs/xfs/scrub/inode.c | 14 ++++--- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 +++++- fs/xfs/xfs_inode_item_recover.c | 20 +++++++--- 12 files changed, 153 insertions(+), 58 deletions(-)
Signature · 1 line
2.28.0
PATCH 1/3 xfs: Introduce xfs_iext_max() helper
xfs_iext_max() returns the maximum number of extents possible for either data fork or attribute fork. This helper will be extended further in a future commit when maximum extent counts associated with data/attribute forks are increased.
No functional changes have been made.
--- fs/xfs/libxfs/xfs_bmap.c | 9 ++++----- fs/xfs/libxfs/xfs_inode_buf.c | 8 +++----- fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +4 -5
@@ -74,13 +74,12 @@ xfs_bmap_compute_maxlevels(* for both ATTR1 and ATTR2 we have to assume the worst case scenario * of a minimum size available. */ -if (whichfork ==XFS_DATA_FORK ) { - maxleafents =MAXEXTNUM ; + maxleafents =xfs_iext_max (&mp->m_sb, whichfork); +if (whichfork ==XFS_DATA_FORK ) sz =XFS_BMDR_SPACE_CALC (MINDBTPTRS ); - }else { - maxleafents =MAXAEXTNUM ; +else sz =XFS_BMDR_SPACE_CALC (MINABTPTRS ); - } + maxrootrecs =xfs_bmdr_maxrecs (sz,0 ); minleafrecs = mp->m_bmap_dmnr[0 ]; minnoderecs = mp->m_bmap_dmnr[1 ];
fs/xfs/libxfs/xfs_inode_buf.c +3 -5
@@ -369,6 +369,7 @@ xfs_dinode_verify_fork( int whichfork) {uint32_t di_nextents =XFS_DFORK_NEXTENTS (dip, whichfork); +xfs_extnum_t max_extents;switch (XFS_DFORK_FORMAT (dip, whichfork)) {case XFS_DINODE_FMT_LOCAL :
@@ -390,12 +391,9 @@ xfs_dinode_verify_fork(return __this_address;break ;case XFS_DINODE_FMT_BTREE : -if (whichfork ==XFS_ATTR_FORK ) { -if (di_nextents >MAXAEXTNUM ) -return __this_address; - }else if (di_nextents >MAXEXTNUM ) { + max_extents =xfs_iext_max (&mp->m_sb, whichfork); +if (di_nextents > max_extents)return __this_address; - }break ;default :return __this_address;
fs/xfs/libxfs/xfs_inode_fork.h +10 -0
@@ -153,6 +153,16 @@ static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp)return ifp->if_format; } +static inline xfs_extnum_t xfs_iext_max (struct xfs_sb *sbp,int whichfork) +{ +ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); + +if (whichfork ==XFS_DATA_FORK ) +return MAXEXTNUM ; +else +return MAXAEXTNUM ; +} +struct xfs_ifork *xfs_iext_state_to_fork (struct xfs_inode *ip,int state);int xfs_iformat_data_fork (struct xfs_inode *,struct xfs_dinode *);
Signature · 1 line
2.28.0
Re: [PATCH 1/3] xfs: Introduce xfs_iext_max() helper
Quoted 6 lines · Chandan Babu R
xfs_iext_max()returns the maximum number of extents possible for either data fork or attribute fork. This helper will be extended further in a future commit when maximum extent counts associated with data/attribute forks are increased.No functional changes have been made.
Hmm....
Quoted 62 lines
Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 9 ++++----- fs/xfs/libxfs/xfs_inode_buf.c | 8 +++----- fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-)fs/xfs/libxfs/xfs_bmap.c +4
-5@@ -74,13 +74,12 @@ xfs_bmap_compute_maxlevels(* for both ATTR1 and ATTR2 we have to assume the worst case scenario * of a minimum size available. */ -if (whichfork ==XFS_DATA_FORK ) { - maxleafents =MAXEXTNUM ; + maxleafents =xfs_iext_max (&mp->m_sb, whichfork); +if (whichfork ==XFS_DATA_FORK ) sz =XFS_BMDR_SPACE_CALC (MINDBTPTRS ); - }else { - maxleafents =MAXAEXTNUM ; +else sz =XFS_BMDR_SPACE_CALC (MINABTPTRS ); - } + maxrootrecs =xfs_bmdr_maxrecs (sz,0 ); minleafrecs = mp->m_bmap_dmnr[0 ]; minnoderecs = mp->m_bmap_dmnr[1 ];fs/xfs/libxfs/xfs_inode_buf.c +3
-5@@ -369,6 +369,7 @@ xfs_dinode_verify_fork( int whichfork) {uint32_t di_nextents =XFS_DFORK_NEXTENTS (dip, whichfork); +xfs_extnum_t max_extents;switch (XFS_DFORK_FORMAT (dip, whichfork)) {case XFS_DINODE_FMT_LOCAL :@@ -390,12 +391,9 @@ xfs_dinode_verify_fork(return __this_address;break ;case XFS_DINODE_FMT_BTREE : -if (whichfork ==XFS_ATTR_FORK ) { -if (di_nextents >MAXAEXTNUM ) -return __this_address; - }else if (di_nextents >MAXEXTNUM ) { + max_extents =xfs_iext_max (&mp->m_sb, whichfork); +if (di_nextents > max_extents)return __this_address; - }break ;default :return __this_address;fs/xfs/libxfs/xfs_inode_fork.h +0
-0@@ -153,6 +153,16 @@ static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp)return ifp->if_format;
fs/xfs/libxfs/xfs_inode_fork.h static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp) · line 163
Quoted 10 lines
fs/xfs/libxfs/xfs_inode_fork.h +8
-0} +static inline xfs_extnum_t xfs_iext_max (struct xfs_sb *sbp,int whichfork) +{ +ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); + +if (whichfork ==XFS_DATA_FORK ) +return MAXEXTNUM ; +else +return MAXAEXTNUM ;
...I kinda wish you /had/ made the functional change to make this return MAXEXTNUM for cow forks, even if none of the callers actually care. :)
--D
Quoted 8 lines
fs/xfs/libxfs/xfs_inode_fork.h +2
-0+} +struct xfs_ifork *xfs_iext_state_to_fork (struct xfs_inode *ip,int state);int xfs_iformat_data_fork (struct xfs_inode *,struct xfs_dinode *);Signature · 1 line
2.28.0
Re: [PATCH 1/3] xfs: Introduce xfs_iext_max() helper
Quoted 74 lines · IST Darrick J. Wong
Quoted 6 lines · Chandan Babu R
xfs_iext_max()returns the maximum number of extents possible for either data fork or attribute fork. This helper will be extended further in a future commit when maximum extent counts associated with data/attribute forks are increased.No functional changes have been made.
Hmm....
Quoted 64 lines
Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 9 ++++----- fs/xfs/libxfs/xfs_inode_buf.c | 8 +++----- fs/xfs/libxfs/xfs_inode_fork.h | 10 ++++++++++ 3 files changed, 17 insertions(+), 10 deletions(-)fs/xfs/libxfs/xfs_bmap.c +4
-5@@ -74,13 +74,12 @@ xfs_bmap_compute_maxlevels(* for both ATTR1 and ATTR2 we have to assume the worst case scenario * of a minimum size available. */ -if (whichfork ==XFS_DATA_FORK ) { - maxleafents =MAXEXTNUM ; + maxleafents =xfs_iext_max (&mp->m_sb, whichfork); +if (whichfork ==XFS_DATA_FORK ) sz =XFS_BMDR_SPACE_CALC (MINDBTPTRS ); - }else { - maxleafents =MAXAEXTNUM ; +else sz =XFS_BMDR_SPACE_CALC (MINABTPTRS ); - } + maxrootrecs =xfs_bmdr_maxrecs (sz,0 ); minleafrecs = mp->m_bmap_dmnr[0 ]; minnoderecs = mp->m_bmap_dmnr[1 ];fs/xfs/libxfs/xfs_inode_buf.c +3
-5@@ -369,6 +369,7 @@ xfs_dinode_verify_fork( int whichfork) {uint32_t di_nextents =XFS_DFORK_NEXTENTS (dip, whichfork); +xfs_extnum_t max_extents;switch (XFS_DFORK_FORMAT (dip, whichfork)) {case XFS_DINODE_FMT_LOCAL :@@ -390,12 +391,9 @@ xfs_dinode_verify_fork(return __this_address;break ;case XFS_DINODE_FMT_BTREE : -if (whichfork ==XFS_ATTR_FORK ) { -if (di_nextents >MAXAEXTNUM ) -return __this_address; - }else if (di_nextents >MAXEXTNUM ) { + max_extents =xfs_iext_max (&mp->m_sb, whichfork); +if (di_nextents > max_extents)return __this_address; - }break ;default :return __this_address;fs/xfs/libxfs/xfs_inode_fork.h +0
-0@@ -153,6 +153,16 @@ static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp)return ifp->if_format; }
Quoted 11 lines
fs/xfs/libxfs/xfs_inode_fork.h static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp) · line 163
Quoted 8 lines
fs/xfs/libxfs/xfs_inode_fork.h +8
-0+static inline xfs_extnum_t xfs_iext_max (struct xfs_sb *sbp,int whichfork) +{ +ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); + +if (whichfork ==XFS_DATA_FORK ) +return MAXEXTNUM ; +else +return MAXAEXTNUM ;...I kinda wish you /had/ made the functional change to make this return MAXEXTNUM for cow forks, even if none of the callers actually care. :)
Ok. I will include that change in the next version.
Quoted 9 lines
--D
Quoted 5 lines
fs/xfs/libxfs/xfs_inode_fork.h +2
-0+} +struct xfs_ifork *xfs_iext_state_to_fork (struct xfs_inode *ip,int state);int xfs_iformat_data_fork (struct xfs_inode *,struct xfs_dinode *);
Signature · 1 line
chandan
PATCH 2/3 xfs: Introduce xfs_dfork_nextents() helper
In reply to Chandan Babu RThis commit replaces the macro XFS_DFORK_NEXTENTS() with the helper function xfs_dfork_nextents(). As of this commit, xfs_dfork_nextents() returns the same value as XFS_DFORK_NEXTENTS(). A future commit which extends inode's extent counter fields will add more logic to this helper.
This commit also replaces direct accesses to xfs_dinode->di_[a]nextents with calls to xfs_dfork_nextents().
No functional changes have been made.
--- fs/xfs/libxfs/xfs_format.h | 4 ---- fs/xfs/libxfs/xfs_inode_buf.c | 29 ++++++++++++++++++++++++----- fs/xfs/libxfs/xfs_inode_buf.h | 2 ++ fs/xfs/libxfs/xfs_inode_fork.c | 10 +++++++--- fs/xfs/scrub/inode.c | 12 +++++++----- 5 files changed, 40 insertions(+), 17 deletions(-)
fs/xfs/libxfs/xfs_format.h +0 -4
@@ -992,10 +992,6 @@ enum xfs_dinode_fmt { ((w) ==XFS_DATA_FORK ? \ (dip)->di_format : \ (dip)->di_aformat) -#define XFS_DFORK_NEXTENTS (dip,w) \ - ((w) == XFS_DATA_FORK ? \ - be32_to_cpu((dip)->di_nextents) : \ - be16_to_cpu((dip)->di_anextents))/* * For block and character special files the 32bit dev_t is stored at the
fs/xfs/libxfs/xfs_inode_buf.c +24 -5
@@ -368,9 +368,11 @@ xfs_dinode_verify_fork(struct xfs_mount *mp, int whichfork) { - uint32_t di_nextents = XFS_DFORK_NEXTENTS(dip, whichfork); + uint32_t di_nextents;xfs_extnum_t max_extents; + di_nextents =xfs_dfork_nextents (&mp->m_sb, dip, whichfork); +switch (XFS_DFORK_FORMAT (dip, whichfork)) {case XFS_DINODE_FMT_LOCAL :/*
@@ -401,6 +403,19 @@ xfs_dinode_verify_fork(return NULL ; } +xfs_extnum_t +xfs_dfork_nextents (struct xfs_sb *sbp,struct xfs_dinode *dip,int whichfork) +{ +xfs_extnum_t nextents; + +if (whichfork ==XFS_DATA_FORK ) + nextents =be32_to_cpu (dip->di_nextents); +else + nextents =be16_to_cpu (dip->di_anextents); + +return nextents; +} + static xfs_failaddr_t xfs_dinode_verify_forkoff( struct xfs_dinode *dip,
@@ -437,6 +452,8 @@ xfs_dinode_verify(uint16_t flags;uint64_t flags2;uint64_t di_size; +xfs_extnum_t nextents; +int64_t nblocks;if (dip->di_magic !=cpu_to_be16 (XFS_DINODE_MAGIC ))return __this_address;
@@ -467,10 +484,12 @@ xfs_dinode_verify(if ((S_ISLNK (mode) ||S_ISDIR (mode)) && di_size ==0 )return __this_address; + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ); + nextents +=xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ); + nblocks =be64_to_cpu (dip->di_nblocks); +/* Fork checks carried over from xfs_iformat_fork */ -if (mode && -be32_to_cpu (dip->di_nextents) +be16_to_cpu (dip->di_anextents) > -be64_to_cpu (dip->di_nblocks)) +if (mode && nextents > nblocks)return __this_address;if (mode &&XFS_DFORK_BOFF (dip) > mp->m_sb.sb_inodesize)
@@ -527,7 +546,7 @@ xfs_dinode_verify(default :return __this_address; } -if (dip->di_anextents) +if (xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ))return __this_address; }
fs/xfs/libxfs/xfs_inode_buf.h +2 -0
@@ -59,5 +59,7 @@ xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp,xfs_failaddr_t xfs_inode_validate_cowextsize (struct xfs_mount *mp,uint32_t cowextsize,uint16_t mode,uint16_t flags,uint64_t flags2); +xfs_extnum_t xfs_dfork_nextents (struct xfs_sb *sbp,struct xfs_dinode *dip, +int whichfork);#endif /* __XFS_INODE_BUF_H__ */
fs/xfs/libxfs/xfs_inode_fork.c +7 -3
@@ -10,6 +10,7 @@#include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h" +#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_trans.h"
@@ -104,9 +105,10 @@ xfs_iformat_extents( int whichfork) {struct xfs_mount *mp = ip->i_mount; +struct xfs_sb *sbp = &mp->m_sb;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +int nex =xfs_dfork_nextents (sbp, dip, whichfork);int state =xfs_bmap_fork_to_state (whichfork); -int nex =XFS_DFORK_NEXTENTS (dip, whichfork);int size = nex *sizeof (xfs_bmbt_rec_t);struct xfs_iext_cursor icur;struct xfs_bmbt_rec *dp;
@@ -226,6 +228,7 @@ xfs_iformat_data_fork(struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_sb *sbp = &ip->i_mount->m_sb;struct inode *inode =VFS_I (ip);int error;
@@ -234,7 +237,7 @@ xfs_iformat_data_fork(* depend on it. */ ip->i_df.if_format = dip->di_format; - ip->i_df.if_nextents =be32_to_cpu (dip->di_nextents); + ip->i_df.if_nextents =xfs_dfork_nextents (sbp, dip,XFS_DATA_FORK );switch (inode->i_mode &S_IFMT ) {case S_IFIFO :
@@ -286,6 +289,7 @@ xfs_iformat_attr_fork(struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_sb *sbp = &ip->i_mount->m_sb;int error =0 ;/*
@@ -296,7 +300,7 @@ xfs_iformat_attr_fork( ip->i_afp->if_format = dip->di_aformat;if (unlikely (ip->i_afp->if_format ==0 ))/* pre IRIX 6.2 file system */ ip->i_afp->if_format =XFS_DINODE_FMT_EXTENTS ; - ip->i_afp->if_nextents =be16_to_cpu (dip->di_anextents); + ip->i_afp->if_nextents =xfs_dfork_nextents (sbp, dip,XFS_ATTR_FORK );switch (ip->i_afp->if_format) {case XFS_DINODE_FMT_LOCAL :
fs/xfs/scrub/inode.c +7 -5
@@ -354,7 +354,7 @@ xchk_dinode(xchk_inode_extsize (sc, dip, ino, mode, flags);/* di_nextents */ - nextents =be32_to_cpu (dip->di_nextents); + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ); fork_recs =XFS_DFORK_DSIZE (dip, mp) /sizeof (struct xfs_bmbt_rec );switch (dip->di_format) {case XFS_DINODE_FMT_EXTENTS :
@@ -371,10 +371,12 @@ xchk_dinode(break ; } + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ); +/* di_forkoff */ if (XFS_DFORK_APTR (dip) >= (char *)dip + mp->m_sb.sb_inodesize)xchk_ino_set_corrupt (sc, ino); -if (dip->di_anextents !=0 && dip->di_forkoff ==0 ) +if (nextents !=0 && dip->di_forkoff ==0 )xchk_ino_set_corrupt (sc, ino);if (dip->di_forkoff ==0 && dip->di_aformat !=XFS_DINODE_FMT_EXTENTS )xchk_ino_set_corrupt (sc, ino);
@@ -386,7 +388,6 @@ xchk_dinode(xchk_ino_set_corrupt (sc, ino);/* di_anextents */ - nextents =be16_to_cpu (dip->di_anextents); fork_recs =XFS_DFORK_ASIZE (dip, mp) /sizeof (struct xfs_bmbt_rec );switch (dip->di_aformat) {case XFS_DINODE_FMT_EXTENTS :
@@ -464,6 +465,7 @@ xchk_inode_xref_bmap(struct xfs_scrub *sc, struct xfs_dinode *dip) { + xfs_mount_t *mp = sc->mp;xfs_extnum_t nextents;xfs_filblks_t count;xfs_filblks_t acount;
@@ -477,14 +479,14 @@ xchk_inode_xref_bmap( &nextents, &count);if (!xchk_should_check_xref (sc, &error,NULL ))return ; -if (nextents <be32_to_cpu (dip->di_nextents)) +if (nextents <xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ))xchk_ino_xref_set_corrupt (sc, sc->ip->i_ino); error =xfs_bmap_count_blocks (sc->tp, sc->ip,XFS_ATTR_FORK , &nextents, &acount);if (!xchk_should_check_xref (sc, &error,NULL ))return ; -if (nextents !=be16_to_cpu (dip->di_anextents)) +if (nextents !=xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ))xchk_ino_xref_set_corrupt (sc, sc->ip->i_ino);/* Check nblocks against the inode. */
Signature · 1 line
2.28.0
Re: [PATCH 2/3] xfs: Introduce xfs_dfork_nextents() helper
Quoted 53 lines · Chandan Babu R
This commit replaces the macro
XFS_DFORK_NEXTENTS()with the helper functionxfs_dfork_nextents(). As of this commit,xfs_dfork_nextents()returns the same value asXFS_DFORK_NEXTENTS(). A future commit which extends inode's extent counter fields will add more logic to this helper.This commit also replaces direct accesses to xfs_dinode->di_[a]nextents with calls to
xfs_dfork_nextents().No functional changes have been made.
Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_format.h | 4 ---- fs/xfs/libxfs/xfs_inode_buf.c | 29 ++++++++++++++++++++++++----- fs/xfs/libxfs/xfs_inode_buf.h | 2 ++ fs/xfs/libxfs/xfs_inode_fork.c | 10 +++++++--- fs/xfs/scrub/inode.c | 12 +++++++----- 5 files changed, 40 insertions(+), 17 deletions(-)fs/xfs/libxfs/xfs_format.h +0
-4@@ -992,10 +992,6 @@ enum xfs_dinode_fmt { ((w) ==XFS_DATA_FORK ? \ (dip)->di_format : \ (dip)->di_aformat) -#define XFS_DFORK_NEXTENTS (dip,w) \ - ((w) == XFS_DATA_FORK ? \ - be32_to_cpu((dip)->di_nextents) : \ - be16_to_cpu((dip)->di_anextents))/* * For block and character special files the 32bit dev_t is stored at the fs/xfs/libxfs/xfs_inode_buf.c +3
-1@@ -368,9 +368,11 @@ xfs_dinode_verify_fork(struct xfs_mount *mp, int whichfork) { - uint32_t di_nextents = XFS_DFORK_NEXTENTS(dip, whichfork); + uint32_t di_nextents;xfs_extnum_t max_extents; + di_nextents =xfs_dfork_nextents (&mp->m_sb, dip, whichfork); +switch (XFS_DFORK_FORMAT (dip, whichfork)) {case XFS_DINODE_FMT_LOCAL :/*
fs/xfs/libxfs/xfs_inode_buf.c xfs_dinode_verify_fork( · line 407
Quoted 5 lines
fs/xfs/libxfs/xfs_inode_buf.c +2
-0@@ -401,6 +403,19 @@ xfs_dinode_verify_fork(return NULL ; } +xfs_extnum_t +xfs_dfork_nextents (struct xfs_sb *sbp,struct xfs_dinode *dip,int whichfork)
The first arg probaly should be a (struct xfs_mount *) to save the callers some typing.
fs/xfs/libxfs/xfs_inode_buf.c xfs_dinode_verify_fork( · line 416
Quoted 9 lines
fs/xfs/libxfs/xfs_inode_buf.c +9
-0+{ +xfs_extnum_t nextents; + +if (whichfork ==XFS_DATA_FORK ) + nextents =be32_to_cpu (dip->di_nextents); +else + nextents =be16_to_cpu (dip->di_anextents); + +return nextents;
Would this be cleaner (as well as barf loudly on invalid args)?
switch (whichfork) {
case XFS_DATA_FORK:
return be32_to_cpu(...);
case XFS_ATTR_FORK:
return be16_to_cpu(...);
default:
ASSERT(0);
return 0;
}Quoted 44 lines
fs/xfs/libxfs/xfs_inode_buf.c +10
-4+} + static xfs_failaddr_t xfs_dinode_verify_forkoff( struct xfs_dinode *dip,@@ -437,6 +452,8 @@ xfs_dinode_verify(uint16_t flags;uint64_t flags2;uint64_t di_size; +xfs_extnum_t nextents; +int64_t nblocks;if (dip->di_magic !=cpu_to_be16 (XFS_DINODE_MAGIC ))return __this_address;@@ -467,10 +484,12 @@ xfs_dinode_verify(if ((S_ISLNK (mode) ||S_ISDIR (mode)) && di_size ==0 )return __this_address; + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ); + nextents +=xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ); + nblocks =be64_to_cpu (dip->di_nblocks); +/* Fork checks carried over from xfs_iformat_fork */ -if (mode && -be32_to_cpu (dip->di_nextents) +be16_to_cpu (dip->di_anextents) > -be64_to_cpu (dip->di_nblocks)) +if (mode && nextents > nblocks)return __this_address;if (mode &&XFS_DFORK_BOFF (dip) > mp->m_sb.sb_inodesize)@@ -527,7 +546,7 @@ xfs_dinode_verify(default :return __this_address; } -if (dip->di_anextents) +if (xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ))return __this_address; }fs/xfs/libxfs/xfs_inode_buf.h +0
-0
fs/xfs/libxfs/xfs_inode_buf.h xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp, · line 63
Quoted 5 lines
fs/xfs/libxfs/xfs_inode_buf.h +2
-0@@ -59,5 +59,7 @@ xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp,xfs_failaddr_t xfs_inode_validate_cowextsize (struct xfs_mount *mp,uint32_t cowextsize,uint16_t mode,uint16_t flags,uint64_t flags2); +xfs_extnum_t xfs_dfork_nextents (struct xfs_sb *sbp,struct xfs_dinode *dip, +int whichfork);
Please try to match the second-line indentation of the declaration above it. Or: two tabs is enough.
Quoted 74 lines
fs/xfs/libxfs/xfs_inode_buf.h +0
-0#endif /* __XFS_INODE_BUF_H__ */ fs/xfs/libxfs/xfs_inode_fork.c +7
-3@@ -10,6 +10,7 @@#include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h" +#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_trans.h" @@ -104,9 +105,10 @@ xfs_iformat_extents( int whichfork) {struct xfs_mount *mp = ip->i_mount; +struct xfs_sb *sbp = &mp->m_sb;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +int nex =xfs_dfork_nextents (sbp, dip, whichfork);int state =xfs_bmap_fork_to_state (whichfork); -int nex =XFS_DFORK_NEXTENTS (dip, whichfork);int size = nex *sizeof (xfs_bmbt_rec_t);struct xfs_iext_cursor icur;struct xfs_bmbt_rec *dp;@@ -226,6 +228,7 @@ xfs_iformat_data_fork(struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_sb *sbp = &ip->i_mount->m_sb;struct inode *inode =VFS_I (ip);int error;@@ -234,7 +237,7 @@ xfs_iformat_data_fork(* depend on it. */ ip->i_df.if_format = dip->di_format; - ip->i_df.if_nextents =be32_to_cpu (dip->di_nextents); + ip->i_df.if_nextents =xfs_dfork_nextents (sbp, dip,XFS_DATA_FORK );switch (inode->i_mode &S_IFMT ) {case S_IFIFO :@@ -286,6 +289,7 @@ xfs_iformat_attr_fork(struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_sb *sbp = &ip->i_mount->m_sb;int error =0 ;/* @@ -296,7 +300,7 @@ xfs_iformat_attr_fork( ip->i_afp->if_format = dip->di_aformat;if (unlikely (ip->i_afp->if_format ==0 ))/* pre IRIX 6.2 file system */ ip->i_afp->if_format =XFS_DINODE_FMT_EXTENTS ; - ip->i_afp->if_nextents =be16_to_cpu (dip->di_anextents); + ip->i_afp->if_nextents =xfs_dfork_nextents (sbp, dip,XFS_ATTR_FORK );switch (ip->i_afp->if_format) {case XFS_DINODE_FMT_LOCAL :fs/xfs/scrub/inode.c +1
-1@@ -354,7 +354,7 @@ xchk_dinode(xchk_inode_extsize (sc, dip, ino, mode, flags);/* di_nextents */ - nextents =be32_to_cpu (dip->di_nextents); + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ); fork_recs =XFS_DFORK_DSIZE (dip, mp) /sizeof (struct xfs_bmbt_rec );switch (dip->di_format) {case XFS_DINODE_FMT_EXTENTS :
fs/xfs/scrub/inode.c xchk_dinode( · line 374
Quoted 4 lines
fs/xfs/scrub/inode.c +1
-0@@ -371,10 +371,12 @@ xchk_dinode(break ; } + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK );
Might be a good time to change these all to "naextents"?
Quoted 18 lines
fs/xfs/scrub/inode.c +2
-2+/* di_forkoff */ if (XFS_DFORK_APTR (dip) >= (char *)dip + mp->m_sb.sb_inodesize)xchk_ino_set_corrupt (sc, ino); -if (dip->di_anextents !=0 && dip->di_forkoff ==0 ) +if (nextents !=0 && dip->di_forkoff ==0 )xchk_ino_set_corrupt (sc, ino);if (dip->di_forkoff ==0 && dip->di_aformat !=XFS_DINODE_FMT_EXTENTS )xchk_ino_set_corrupt (sc, ino);@@ -386,7 +388,6 @@ xchk_dinode(xchk_ino_set_corrupt (sc, ino);/* di_anextents */ - nextents =be16_to_cpu (dip->di_anextents); fork_recs =XFS_DFORK_ASIZE (dip, mp) /sizeof (struct xfs_bmbt_rec );switch (dip->di_aformat) {case XFS_DINODE_FMT_EXTENTS :
fs/xfs/scrub/inode.c xchk_inode_xref_bmap( · line 468
Quoted 4 lines
fs/xfs/scrub/inode.c +1
-0@@ -464,6 +465,7 @@ xchk_inode_xref_bmap(struct xfs_scrub *sc, struct xfs_dinode *dip) { + xfs_mount_t *mp = sc->mp;
Don't increase the usage of structure typedefs, please.
--D
Quoted 23 lines
fs/xfs/scrub/inode.c +2
-2xfs_extnum_t nextents;xfs_filblks_t count;xfs_filblks_t acount;@@ -477,14 +479,14 @@ xchk_inode_xref_bmap( &nextents, &count);if (!xchk_should_check_xref (sc, &error,NULL ))return ; -if (nextents <be32_to_cpu (dip->di_nextents)) +if (nextents <xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ))xchk_ino_xref_set_corrupt (sc, sc->ip->i_ino); error =xfs_bmap_count_blocks (sc->tp, sc->ip,XFS_ATTR_FORK , &nextents, &acount);if (!xchk_should_check_xref (sc, &error,NULL ))return ; -if (nextents !=be16_to_cpu (dip->di_anextents)) +if (nextents !=xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ))xchk_ino_xref_set_corrupt (sc, sc->ip->i_ino);/* Check nblocks against the inode. */ Signature · 1 line
2.28.0
Re: [PATCH 2/3] xfs: Introduce xfs_dfork_nextents() helper
Quoted 57 lines · IST Darrick J. Wong
Quoted 56 lines · Chandan Babu R
This commit replaces the macro
XFS_DFORK_NEXTENTS()with the helper functionxfs_dfork_nextents(). As of this commit,xfs_dfork_nextents()returns the same value asXFS_DFORK_NEXTENTS(). A future commit which extends inode's extent counter fields will add more logic to this helper.This commit also replaces direct accesses to xfs_dinode->di_[a]nextents with calls to
xfs_dfork_nextents().No functional changes have been made.
Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_format.h | 4 ---- fs/xfs/libxfs/xfs_inode_buf.c | 29 ++++++++++++++++++++++++----- fs/xfs/libxfs/xfs_inode_buf.h | 2 ++ fs/xfs/libxfs/xfs_inode_fork.c | 10 +++++++--- fs/xfs/scrub/inode.c | 12 +++++++----- 5 files changed, 40 insertions(+), 17 deletions(-)fs/xfs/libxfs/xfs_format.h +0
-4@@ -992,10 +992,6 @@ enum xfs_dinode_fmt { ((w) ==XFS_DATA_FORK ? \ (dip)->di_format : \ (dip)->di_aformat) -#define XFS_DFORK_NEXTENTS (dip,w) \ - ((w) == XFS_DATA_FORK ? \ - be32_to_cpu((dip)->di_nextents) : \ - be16_to_cpu((dip)->di_anextents))/* * For block and character special files the 32bit dev_t is stored at the fs/xfs/libxfs/xfs_inode_buf.c +3
-1@@ -368,9 +368,11 @@ xfs_dinode_verify_fork(struct xfs_mount *mp, int whichfork) { - uint32_t di_nextents = XFS_DFORK_NEXTENTS(dip, whichfork); + uint32_t di_nextents;xfs_extnum_t max_extents; + di_nextents =xfs_dfork_nextents (&mp->m_sb, dip, whichfork); +switch (XFS_DFORK_FORMAT (dip, whichfork)) {case XFS_DINODE_FMT_LOCAL :/* @@ -401,6 +403,19 @@ xfs_dinode_verify_fork(return NULL ; }
Quoted 5 lines
fs/xfs/libxfs/xfs_inode_buf.c xfs_dinode_verify_fork( · line 407
Quoted 2 lines
fs/xfs/libxfs/xfs_inode_buf.c +2
-0+xfs_extnum_t +xfs_dfork_nextents (struct xfs_sb *sbp,struct xfs_dinode *dip,int whichfork)The first arg probaly should be a (struct
xfs_mount*) to save the callers some typing.
Hmm. I actually did try that ... but ended up failing. I don't recall the reason now. I will implement this suggestion.
Quoted 13 lines
fs/xfs/libxfs/xfs_inode_buf.c xfs_dinode_verify_fork( · line 416
Quoted 10 lines
fs/xfs/libxfs/xfs_inode_buf.c +9
-0+{ +xfs_extnum_t nextents; + +if (whichfork ==XFS_DATA_FORK ) + nextents =be32_to_cpu (dip->di_nextents); +else + nextents =be16_to_cpu (dip->di_anextents); + +return nextents;Would this be cleaner (as well as barf loudly on invalid args)?
Quoted 9 lines
switch (whichfork) {
case XFS_DATA_FORK:
return be32_to_cpu(...);
case XFS_ATTR_FORK:
return be16_to_cpu(...);
default:
ASSERT(0);
return 0;
}Yes, This is much better. I will include this in the next version of the patchset.
Quoted 41 lines
Quoted 41 lines
fs/xfs/libxfs/xfs_inode_buf.c +10
-4+} + static xfs_failaddr_t xfs_dinode_verify_forkoff( struct xfs_dinode *dip,@@ -437,6 +452,8 @@ xfs_dinode_verify(uint16_t flags;uint64_t flags2;uint64_t di_size; +xfs_extnum_t nextents; +int64_t nblocks;if (dip->di_magic !=cpu_to_be16 (XFS_DINODE_MAGIC ))return __this_address;@@ -467,10 +484,12 @@ xfs_dinode_verify(if ((S_ISLNK (mode) ||S_ISDIR (mode)) && di_size ==0 )return __this_address; + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ); + nextents +=xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ); + nblocks =be64_to_cpu (dip->di_nblocks); +/* Fork checks carried over from xfs_iformat_fork */ -if (mode && -be32_to_cpu (dip->di_nextents) +be16_to_cpu (dip->di_anextents) > -be64_to_cpu (dip->di_nblocks)) +if (mode && nextents > nblocks)return __this_address;if (mode &&XFS_DFORK_BOFF (dip) > mp->m_sb.sb_inodesize)@@ -527,7 +546,7 @@ xfs_dinode_verify(default :return __this_address; } -if (dip->di_anextents) +if (xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ))return __this_address; }
Quoted 13 lines
fs/xfs/libxfs/xfs_inode_buf.h xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp, · line 63
Quoted 10 lines
fs/xfs/libxfs/xfs_inode_buf.h +2
-0@@ -59,5 +59,7 @@ xfs_failaddr_t xfs_inode_validate_extsize(struct xfs_mount *mp,xfs_failaddr_t xfs_inode_validate_cowextsize (struct xfs_mount *mp,uint32_t cowextsize,uint16_t mode,uint16_t flags,uint64_t flags2); +xfs_extnum_t xfs_dfork_nextents (struct xfs_sb *sbp,struct xfs_dinode *dip, +int whichfork);Please try to match the second-line indentation of the declaration above it. Or: two tabs is enough.
Sorry, I missed out on this one. I will fix this up.
Quoted 78 lines
Quoted 78 lines
fs/xfs/libxfs/xfs_inode_buf.h +0
-0#endif /* __XFS_INODE_BUF_H__ */ fs/xfs/libxfs/xfs_inode_fork.c +7
-3@@ -10,6 +10,7 @@#include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h" +#include "xfs_sb.h" #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_trans.h" @@ -104,9 +105,10 @@ xfs_iformat_extents( int whichfork) {struct xfs_mount *mp = ip->i_mount; +struct xfs_sb *sbp = &mp->m_sb;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +int nex =xfs_dfork_nextents (sbp, dip, whichfork);int state =xfs_bmap_fork_to_state (whichfork); -int nex =XFS_DFORK_NEXTENTS (dip, whichfork);int size = nex *sizeof (xfs_bmbt_rec_t);struct xfs_iext_cursor icur;struct xfs_bmbt_rec *dp;@@ -226,6 +228,7 @@ xfs_iformat_data_fork(struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_sb *sbp = &ip->i_mount->m_sb;struct inode *inode =VFS_I (ip);int error;@@ -234,7 +237,7 @@ xfs_iformat_data_fork(* depend on it. */ ip->i_df.if_format = dip->di_format; - ip->i_df.if_nextents =be32_to_cpu (dip->di_nextents); + ip->i_df.if_nextents =xfs_dfork_nextents (sbp, dip,XFS_DATA_FORK );switch (inode->i_mode &S_IFMT ) {case S_IFIFO :@@ -286,6 +289,7 @@ xfs_iformat_attr_fork(struct xfs_inode *ip, struct xfs_dinode *dip) { + struct xfs_sb *sbp = &ip->i_mount->m_sb;int error =0 ;/* @@ -296,7 +300,7 @@ xfs_iformat_attr_fork( ip->i_afp->if_format = dip->di_aformat;if (unlikely (ip->i_afp->if_format ==0 ))/* pre IRIX 6.2 file system */ ip->i_afp->if_format =XFS_DINODE_FMT_EXTENTS ; - ip->i_afp->if_nextents =be16_to_cpu (dip->di_anextents); + ip->i_afp->if_nextents =xfs_dfork_nextents (sbp, dip,XFS_ATTR_FORK );switch (ip->i_afp->if_format) {case XFS_DINODE_FMT_LOCAL :fs/xfs/scrub/inode.c +1
-1@@ -354,7 +354,7 @@ xchk_dinode(xchk_inode_extsize (sc, dip, ino, mode, flags);/* di_nextents */ - nextents =be32_to_cpu (dip->di_nextents); + nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ); fork_recs =XFS_DFORK_DSIZE (dip, mp) /sizeof (struct xfs_bmbt_rec );switch (dip->di_format) {case XFS_DINODE_FMT_EXTENTS :@@ -371,10 +371,12 @@ xchk_dinode(break ; }
Quoted 3 lines
fs/xfs/scrub/inode.c xchk_dinode( · line 374
Quoted 1 line
fs/xfs/scrub/inode.c +1
-0+ nextents =xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK );Might be a good time to change these all to "naextents"?
Sure, I will make the change.
Quoted 13 lines
Quoted 13 lines
fs/xfs/scrub/inode.c +2
-1+/* di_forkoff */ if (XFS_DFORK_APTR (dip) >= (char *)dip + mp->m_sb.sb_inodesize)xchk_ino_set_corrupt (sc, ino); -if (dip->di_anextents !=0 && dip->di_forkoff ==0 ) +if (nextents !=0 && dip->di_forkoff ==0 )xchk_ino_set_corrupt (sc, ino);if (dip->di_forkoff ==0 && dip->di_aformat !=XFS_DINODE_FMT_EXTENTS )xchk_ino_set_corrupt (sc, ino);@@ -386,7 +388,6 @@ xchk_dinode(xchk_ino_set_corrupt (sc, ino);
Quoted 12 lines
fs/xfs/scrub/inode.c xchk_inode_xref_bmap( · line 468
Quoted 10 lines
fs/xfs/scrub/inode.c +1
-1/* di_anextents */ - nextents =be16_to_cpu (dip->di_anextents); fork_recs =XFS_DFORK_ASIZE (dip, mp) /sizeof (struct xfs_bmbt_rec );switch (dip->di_aformat) {case XFS_DINODE_FMT_EXTENTS :@@ -464,6 +465,7 @@ xchk_inode_xref_bmap(struct xfs_scrub *sc, struct xfs_dinode *dip) { + xfs_mount_t *mp = sc->mp;Don't increase the usage of structure typedefs, please.
Sorry, I will replace it with 'struct xfs_mount'.
Quoted 24 lines
--D
Quoted 20 lines
fs/xfs/scrub/inode.c +2
-2xfs_extnum_t nextents;xfs_filblks_t count;xfs_filblks_t acount;@@ -477,14 +479,14 @@ xchk_inode_xref_bmap( &nextents, &count);if (!xchk_should_check_xref (sc, &error,NULL ))return ; -if (nextents <be32_to_cpu (dip->di_nextents)) +if (nextents <xfs_dfork_nextents (&mp->m_sb, dip,XFS_DATA_FORK ))xchk_ino_xref_set_corrupt (sc, sc->ip->i_ino); error =xfs_bmap_count_blocks (sc->tp, sc->ip,XFS_ATTR_FORK , &nextents, &acount);if (!xchk_should_check_xref (sc, &error,NULL ))return ; -if (nextents !=be16_to_cpu (dip->di_anextents)) +if (nextents !=xfs_dfork_nextents (&mp->m_sb, dip,XFS_ATTR_FORK ))xchk_ino_xref_set_corrupt (sc, sc->ip->i_ino);/* Check nblocks against the inode. */
Signature · 1 line
chandan
PATCH 3/3 xfs: Extend data/attr fork extent counter width
In reply to Chandan Babu RThe commit xfs: fix inode fork extent count overflow (3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this commit extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.
Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.
Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this commit extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.
--- fs/xfs/libxfs/xfs_bmap.c | 8 ++++--- fs/xfs/libxfs/xfs_format.h | 20 ++++++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 42 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.h | 17 +++++++++---- fs/xfs/libxfs/xfs_log_format.h | 8 ++++--- fs/xfs/libxfs/xfs_types.h | 10 ++++---- fs/xfs/scrub/inode.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 ++++++++-- fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++---- 11 files changed, 105 insertions(+), 40 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +5 -3
@@ -52,9 +52,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { +xfs_extnum_t maxleafents;/* max leaf entries possible */ int level;/* btree level */ uint maxblocks;/* max blocks at this level */ -uint maxleafents;/* max leaf entries possible */ int maxrootrecs;/* max records in root block */ int minleafrecs;/* min records in leaf block */ int minnoderecs;/* min records in node block */
@@ -64,7 +64,9 @@ xfs_bmap_compute_maxlevels(* The maximum number of extents in a file, hence the maximum number of * leaf entries, is controlled by the size of the on-disk extent count, * either a signed 32-bit number for the data fork, or a signed 16-bit -* number for the attr fork. +* number for the attr fork. With mkfs.xfs' wide-extcount option +* enabled, the data fork extent count is unsigned 47-bits wide, while +* the corresponding attr fork extent count is unsigned 32-bits wide. * * Note that we can no longer assume that if we are in ATTR1 that * the fork offset of all the inodes will be
@@ -464,7 +466,7 @@ xfs_bmap_check_leaf_extents(if (bp_release)xfs_trans_brelse (NULL , bp); error_norelse: -xfs_warn (mp,"%s: BAD after btree leaves for %d extents" , +xfs_warn (mp,"%s: BAD after btree leaves for %llu extents" , __func__, i);xfs_err (mp,"%s: CORRUPTED BTREE OR SOMETHING" , __func__);xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE );
fs/xfs/libxfs/xfs_format.h +15 -5
@@ -465,10 +465,12 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT (1 << 3)/* Wider data/attr fork extent counters */ +#define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \ - XFS_SB_FEAT_INCOMPAT_META_UUID) + XFS_SB_FEAT_INCOMPAT_META_UUID| \ + XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool
@@ -551,6 +553,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_haswideextcnt (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT ); +} +static inline bool xfs_sb_version_hasrmapbt (struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&
@@ -873,8 +881,8 @@ typedef struct xfs_dinode {__be64 di_size;/* number of bytes in file */ __be64 di_nblocks;/* # of direct & btree blocks used */ __be32 di_extsize;/* basic/minimum extent size for file */ -__be32 di_nextents;/* number of extents in data fork */ -__be16 di_anextents;/* number of extents in attribute fork*/ +__be32 di_nextents_lo;/* lower part of data fork extent count */ +__be16 di_anextents_lo;/* lower part of attr fork extent count */ __u8 di_forkoff;/* attr fork offs, <<3 for 64b align */ __s8 di_aformat;/* format of attr fork's data */ __be32 di_dmevmask;/* DMIG event mask */
@@ -891,7 +899,9 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ -__u8 di_pad2[12 ];/* more padding for future expansion */ +__be32 di_nextents_hi;/* higher part of data fork extent count */ +__be16 di_anextents_hi;/* higher part of attr fork extent count */ +__u8 di_pad2[6 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_timestamp_t di_crtime;/* time created */
fs/xfs/libxfs/xfs_inode_buf.c +33 -9
93 lines not on this page · raw message
fs/xfs/libxfs/xfs_inode_buf.h +2 -2
@@ -49,8 +49,8 @@ void xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);void xfs_inode_to_disk (struct xfs_inode *ip,struct xfs_dinode *to,xfs_lsn_t lsn);int xfs_inode_from_disk (struct xfs_inode *ip,struct xfs_dinode *from); -void xfs_log_dinode_to_disk (struct xfs_log_dinode *from, -struct xfs_dinode *to); +void xfs_log_dinode_to_disk (struct xfs_mount *mp, +struct xfs_log_dinode *from,struct xfs_dinode *to);xfs_failaddr_t xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino,struct xfs_dinode *dip);
fs/xfs/libxfs/xfs_inode_fork.h +12 -5
@@ -21,10 +21,10 @@ struct xfs_ifork {void *if_root;/* extent tree root */ char *if_data;/* inline file data */ } if_u1; +xfs_extnum_t if_nextents;/* # of extents in this fork */ short if_broot_bytes;/* bytes allocated for root */ unsigned char if_flags;/* per-fork flags */ int8_t if_format;/* format of this fork */ -xfs_extnum_t if_nextents;/* # of extents in this fork */ };/*
@@ -157,10 +157,17 @@ static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) {ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); -if (whichfork ==XFS_DATA_FORK ) -return MAXEXTNUM ; -else -return MAXAEXTNUM ; +if (whichfork ==XFS_DATA_FORK ) { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXEXTNUM_HI ; +else +return MAXEXTNUM ; + }else { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXAEXTNUM_HI ; +else +return MAXAEXTNUM ; + } }struct xfs_ifork *xfs_iext_state_to_fork (struct xfs_inode *ip,int state);
fs/xfs/libxfs/xfs_log_format.h +5 -3
@@ -396,8 +396,8 @@ struct xfs_log_dinode {xfs_fsize_t di_size;/* number of bytes in file */ xfs_rfsblock_t di_nblocks;/* # of direct & btree blocks used */ xfs_extlen_t di_extsize;/* basic/minimum extent size for file */ -xfs_extnum_t di_nextents;/* number of extents in data fork */ -xfs_aextnum_t di_anextents;/* number of extents in attribute fork*/ +uint32_t di_nextents_lo;/* lower part of data fork extent count */ +uint16_t di_anextents_lo;/* lower part of attr fork extent count */ uint8_t di_forkoff;/* attr fork offs, <<3 for 64b align */ int8_t di_aformat;/* format of attr fork's data */ uint32_t di_dmevmask;/* DMIG event mask */
@@ -414,7 +414,9 @@ struct xfs_log_dinode {xfs_lsn_t di_lsn;/* flush sequence */ uint64_t di_flags2;/* more random flags */ uint32_t di_cowextsize;/* basic cow extent size for file */ -uint8_t di_pad2[12 ];/* more padding for future expansion */ +uint32_t di_nextents_hi;/* higher part of data fork extent count */ +uint16_t di_anextents_hi;/* higher part of attr fork extent count */ +uint8_t di_pad2[6 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_ictimestamp_t di_crtime;/* time created */
fs/xfs/libxfs/xfs_types.h +6 -4
@@ -12,8 +12,8 @@ typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ -typedef int32_t xfs_extnum_t ;/* # of extents in a file */ -typedef int16_t xfs_aextnum_t ;/* # extents in an attribute fork */ +typedef uint64_t xfs_extnum_t ;/* # of extents in a file */ +typedef uint32_t xfs_aextnum_t ;/* # extents in an attribute fork */ typedef int64_t xfs_fsize_t ;/* bytes in a file */ typedef uint64_t xfs_ufsize_t ;/* unsigned bytes in a file */
@@ -59,8 +59,10 @@ typedef void * xfs_failaddr_t;* Max values for extlen, extnum, aextnum. */ #define MAXEXTLEN ((xfs_extlen_t)0x001fffff)/* 21 bits */ -#define MAXEXTNUM ((xfs_extnum_t)0x7fffffff)/* signed int */ -#define MAXAEXTNUM ((xfs_aextnum_t)0x7fff)/* signed short */ +#define MAXEXTNUM ((int32_t)0x7fffffff)/* signed int */ +#define MAXAEXTNUM ((int16_t)0x7fff)/* signed short */ +#define MAXEXTNUM_HI ((xfs_extnum_t)0x7fffffffffff)/* unsigned 47 bits */ +#define MAXAEXTNUM_HI ((xfs_aextnum_t)0xffffffff)/* unsigned 32 bits */ /* * Minimum and maximum blocksize and sectorsize.
fs/xfs/scrub/inode.c +1 -1
@@ -206,7 +206,7 @@ xchk_dinode(size_t fork_recs;unsigned long long isize;uint64_t flags2; -uint32_t nextents; +xfs_extnum_t nextents;uint16_t flags;uint16_t mode;
fs/xfs/xfs_inode.c +1 -1
@@ -3517,7 +3517,7 @@ xfs_iflush( ip->i_d.di_nblocks, mp, XFS_ERRTAG_IFLUSH_5)) {xfs_alert_tag (mp,XFS_PTAG_IFLUSH ,"%s: detected corrupt incore inode %Lu, " -"total extents = %d, nblocks = %Ld, ptr " PTR_FMT , +"total extents = %llu, nblocks = %Ld, ptr " PTR_FMT , __func__, ip->i_ino, ip->i_df.if_nextents +xfs_ifork_nextents (ip->i_afp), ip->i_d.di_nblocks, ip);
fs/xfs/xfs_inode_item.c +10 -2
@@ -301,6 +301,7 @@ xfs_inode_to_log_dinode( struct xfs_log_dinode *to, xfs_lsn_t lsn) { +struct xfs_sb *sbp = &ip->i_mount->m_sb;struct xfs_icdinode *from = &ip->i_d;struct inode *inode =VFS_I (ip);
@@ -326,8 +327,8 @@ xfs_inode_to_log_dinode( to->di_size = from->di_size; to->di_nblocks = from->di_nblocks; to->di_extsize = from->di_extsize; - to->di_nextents =xfs_ifork_nextents (&ip->i_df); - to->di_anextents =xfs_ifork_nextents (ip->i_afp); + to->di_nextents_lo =xfs_ifork_nextents (&ip->i_df); + to->di_anextents_lo =xfs_ifork_nextents (ip->i_afp); to->di_forkoff = from->di_forkoff; to->di_aformat =xfs_ifork_format (ip->i_afp); to->di_dmevmask = from->di_dmevmask;
@@ -344,6 +345,13 @@ xfs_inode_to_log_dinode( to->di_crtime.t_nsec = from->di_crtime.tv_nsec; to->di_flags2 = from->di_flags2; to->di_cowextsize = from->di_cowextsize; +if (xfs_sb_version_haswideextcnt (sbp)) { + to->di_nextents_hi + =xfs_ifork_nextents (&ip->i_df) >>32 ; + to->di_anextents_hi + =xfs_ifork_nextents (ip->i_afp) >>16 ; + } + to->di_ino = ip->i_ino; to->di_lsn = lsn;memset (to->di_pad2,0 ,sizeof (to->di_pad2));
fs/xfs/xfs_inode_item_recover.c +15 -5
@@ -126,6 +126,8 @@ xlog_recover_inode_commit_pass2(struct xfs_mount *mp = log->l_mp;struct xfs_buf *bp;struct xfs_dinode *dip; +xfs_extnum_t nextents; +xfs_aextnum_t anextents;int len;char *src;char *dest;
@@ -256,16 +258,24 @@ xlog_recover_inode_commit_pass2( goto out_release; } } -if (unlikely (ldip->di_nextents + ldip->di_anextents > ldip->di_nblocks)){ + + nextents = ldip->di_nextents_lo; +if (xfs_sb_version_haswideextcnt (&mp->m_sb)) + nextents |= ((xfs_extnum_t)(ldip->di_nextents_hi) <<32 ); + + anextents = ldip->di_anextents_lo; +if (xfs_sb_version_haswideextcnt (&mp->m_sb)) + anextents |= ((xfs_aextnum_t)(ldip->di_anextents_hi) <<16 ); + +if (unlikely (nextents + anextents > ldip->di_nblocks)) {XFS_CORRUPTION_ERROR ("xlog_recover_inode_pass2(5)" ,XFS_ERRLEVEL_LOW , mp, ldip,sizeof (*ldip));xfs_alert (mp,"%s: Bad inode log record, rec ptr " PTR_FMT ", dino ptr " PTR_FMT ", " -"dino bp " PTR_FMT ", ino %Ld, total extents = %d, nblocks = %Ld" , +"dino bp " PTR_FMT ", ino %Ld, total extents = %llu, nblocks = %Ld" , __func__, item, dip, bp, in_f->ilf_ino, - ldip->di_nextents + ldip->di_anextents, - ldip->di_nblocks); + nextents + anextents, ldip->di_nblocks); error = -EFSCORRUPTED ; goto out_release; }
@@ -293,7 +303,7 @@ xlog_recover_inode_commit_pass2( }/* recover the log dinode inode into the on disk inode */ -xfs_log_dinode_to_disk (ldip, dip); +xfs_log_dinode_to_disk (mp, ldip, dip); fields = in_f->ilf_fields;if (fields &XFS_ILOG_DEV )
Signature · 1 line
2.28.0
Re: [PATCH 3/3] xfs: Extend data/attr fork extent counter width
Quoted 8 lines · Chandan Babu R
The commit xfs: fix inode fork extent count overflow (
3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this commit extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.
Sorry I forgot to reply to your follow up to this question the last time you sent this series. I still don't understand why you're consuming 32 more bits of xfs_dinode for the data fork extent count but only using 15 bits of that space.
On a 1k block filesystem, we can have 2^(63-10) = 2^53 extents. Block sizes this small are still supported by the V5 format.
On a 4k block filesystem, we can have 2^(63-12) = 2^51 extents. This blocksize is the default on x86.
Granted, that would be aw{ful,esome}, but I do not see why it's necessary to have this limitation.
Quoted 150 lines
Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this commit extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 8 ++++--- fs/xfs/libxfs/xfs_format.h | 20 ++++++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 42 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.h | 17 +++++++++---- fs/xfs/libxfs/xfs_log_format.h | 8 ++++--- fs/xfs/libxfs/xfs_types.h | 10 ++++---- fs/xfs/scrub/inode.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 ++++++++-- fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++---- 11 files changed, 105 insertions(+), 40 deletions(-)fs/xfs/libxfs/xfs_bmap.c +5
-3@@ -52,9 +52,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { +xfs_extnum_t maxleafents;/* max leaf entries possible */ int level;/* btree level */ uint maxblocks;/* max blocks at this level */ -uint maxleafents;/* max leaf entries possible */ int maxrootrecs;/* max records in root block */ int minleafrecs;/* min records in leaf block */ int minnoderecs;/* min records in node block */ @@ -64,7 +64,9 @@ xfs_bmap_compute_maxlevels(* The maximum number of extents in a file, hence the maximum number of * leaf entries, is controlled by the size of the on-disk extent count, * either a signed 32-bit number for the data fork, or a signed 16-bit -* number for the attr fork. +* number for the attr fork. With mkfs.xfs' wide-extcount option +* enabled, the data fork extent count is unsigned 47-bits wide, while +* the corresponding attr fork extent count is unsigned 32-bits wide. * * Note that we can no longer assume that if we are in ATTR1 that * the fork offset of all the inodes will be @@ -464,7 +466,7 @@ xfs_bmap_check_leaf_extents(if (bp_release)xfs_trans_brelse (NULL , bp); error_norelse: -xfs_warn (mp,"%s: BAD after btree leaves for %d extents" , +xfs_warn (mp,"%s: BAD after btree leaves for %llu extents" , __func__, i);xfs_err (mp,"%s: CORRUPTED BTREE OR SOMETHING" , __func__);xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE );fs/xfs/libxfs/xfs_format.h +15
-5@@ -465,10 +465,12 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT (1 << 3)/* Wider data/attr fork extent counters */ +#define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \ - XFS_SB_FEAT_INCOMPAT_META_UUID) + XFS_SB_FEAT_INCOMPAT_META_UUID| \ + XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool@@ -551,6 +553,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_haswideextcnt (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT ); +} +static inline bool xfs_sb_version_hasrmapbt (struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&@@ -873,8 +881,8 @@ typedef struct xfs_dinode {__be64 di_size;/* number of bytes in file */ __be64 di_nblocks;/* # of direct & btree blocks used */ __be32 di_extsize;/* basic/minimum extent size for file */ -__be32 di_nextents;/* number of extents in data fork */ -__be16 di_anextents;/* number of extents in attribute fork*/ +__be32 di_nextents_lo;/* lower part of data fork extent count */ +__be16 di_anextents_lo;/* lower part of attr fork extent count */ __u8 di_forkoff;/* attr fork offs, <<3 for 64b align */ __s8 di_aformat;/* format of attr fork's data */ __be32 di_dmevmask;/* DMIG event mask */ @@ -891,7 +899,9 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ -__u8 di_pad2[12 ];/* more padding for future expansion */ +__be32 di_nextents_hi;/* higher part of data fork extent count */ +__be16 di_anextents_hi;/* higher part of attr fork extent count */ +__u8 di_pad2[6 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_timestamp_t di_crtime;/* time created */ fs/xfs/libxfs/xfs_inode_buf.c +3
-2@@ -258,6 +258,7 @@ xfs_inode_to_disk( struct xfs_dinode *to, xfs_lsn_t lsn) { +struct xfs_sb *sbp = &ip->i_mount->m_sb;struct xfs_icdinode *from = &ip->i_d;struct inode *inode =VFS_I (ip);@@ -284,8 +285,8 @@ xfs_inode_to_disk( to->di_size =cpu_to_be64 (from->di_size); to->di_nblocks =cpu_to_be64 (from->di_nblocks); to->di_extsize =cpu_to_be32 (from->di_extsize); - to->di_nextents =cpu_to_be32 (xfs_ifork_nextents (&ip->i_df)); - to->di_anextents =cpu_to_be16 (xfs_ifork_nextents (ip->i_afp)); + to->di_nextents_lo =cpu_to_be32 (xfs_ifork_nextents (&ip->i_df)); + to->di_anextents_lo =cpu_to_be16 (xfs_ifork_nextents (ip->i_afp)); to->di_forkoff = from->di_forkoff; to->di_aformat =xfs_ifork_format (ip->i_afp); to->di_dmevmask =cpu_to_be32 (from->di_dmevmask);
fs/xfs/libxfs/xfs_inode_buf.c xfs_inode_to_disk( · line 306
Quoted 7 lines
fs/xfs/libxfs/xfs_inode_buf.c +4
-0@@ -299,6 +300,15 @@ xfs_inode_to_disk( to->di_crtime.t_nsec =cpu_to_be32 (from->di_crtime.tv_nsec); to->di_flags2 =cpu_to_be64 (from->di_flags2); to->di_cowextsize =cpu_to_be32 (from->di_cowextsize); +if (xfs_sb_version_haswideextcnt (sbp)) { + to->di_nextents_hi + =cpu_to_be32 (xfs_ifork_nextents (&ip->i_df) + >>32 );
I thought you were only using this u32 field for the lower 15 bits? If that's really true ("47-bit field") then there ought to be some masking.
(Or you could just support BMBT_STARTOFF_MASK extents...)
Also, this might be a good time to add a helper to decode the extent counts from the dinode/log dinode.
Quoted 199 lines
fs/xfs/libxfs/xfs_inode_buf.c +26
-7+ to->di_anextents_hi + =cpu_to_be16 (xfs_ifork_nextents (ip->i_afp) + >>16 ); + } + to->di_ino =cpu_to_be64 (ip->i_ino); to->di_lsn =cpu_to_be64 (lsn);memset (to->di_pad2,0 ,sizeof (to->di_pad2));@@ -312,9 +322,12 @@ xfs_inode_to_disk(void xfs_log_dinode_to_disk ( +struct xfs_mount *mp,struct xfs_log_dinode *from,struct xfs_dinode *to) { +struct xfs_sb *sbp = &mp->m_sb; + to->di_magic =cpu_to_be16 (from->di_magic); to->di_mode =cpu_to_be16 (from->di_mode); to->di_version = from->di_version;@@ -337,8 +350,8 @@ xfs_log_dinode_to_disk( to->di_size =cpu_to_be64 (from->di_size); to->di_nblocks =cpu_to_be64 (from->di_nblocks); to->di_extsize =cpu_to_be32 (from->di_extsize); - to->di_nextents =cpu_to_be32 (from->di_nextents); - to->di_anextents =cpu_to_be16 (from->di_anextents); + to->di_nextents_lo =cpu_to_be32 (from->di_nextents_lo); + to->di_anextents_lo =cpu_to_be16 (from->di_anextents_lo); to->di_forkoff = from->di_forkoff; to->di_aformat = from->di_aformat; to->di_dmevmask =cpu_to_be32 (from->di_dmevmask);@@ -352,6 +365,10 @@ xfs_log_dinode_to_disk( to->di_crtime.t_nsec =cpu_to_be32 (from->di_crtime.t_nsec); to->di_flags2 =cpu_to_be64 (from->di_flags2); to->di_cowextsize =cpu_to_be32 (from->di_cowextsize); +if (xfs_sb_version_haswideextcnt (sbp)) { + to->di_nextents_hi =cpu_to_be32 (from->di_nextents_hi); + to->di_anextents_hi =cpu_to_be16 (from->di_anextents_hi); + } to->di_ino =cpu_to_be64 (from->di_ino); to->di_lsn =cpu_to_be64 (from->di_lsn);memcpy (to->di_pad2, from->di_pad2,sizeof (to->di_pad2));@@ -368,7 +385,7 @@ xfs_dinode_verify_fork( struct xfs_mount *mp, int whichfork) { - uint32_t di_nextents; +xfs_extnum_t di_nextents;xfs_extnum_t max_extents; di_nextents =xfs_dfork_nextents (&mp->m_sb, dip, whichfork);@@ -408,10 +425,17 @@ xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) {xfs_extnum_t nextents; -if (whichfork ==XFS_DATA_FORK ) - nextents =be32_to_cpu (dip->di_nextents); -else - nextents =be16_to_cpu (dip->di_anextents); +if (whichfork ==XFS_DATA_FORK ) { + nextents =be32_to_cpu (dip->di_nextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_extnum_t )be32_to_cpu (dip->di_nextents_hi) <<32 ); + }else { + nextents =be16_to_cpu (dip->di_anextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_aextnum_t )be16_to_cpu (dip->di_anextents_hi) <<16 ); + }return nextents; }fs/xfs/libxfs/xfs_inode_buf.h +2
-2@@ -49,8 +49,8 @@ void xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);void xfs_inode_to_disk (struct xfs_inode *ip,struct xfs_dinode *to,xfs_lsn_t lsn);int xfs_inode_from_disk (struct xfs_inode *ip,struct xfs_dinode *from); -void xfs_log_dinode_to_disk (struct xfs_log_dinode *from, -struct xfs_dinode *to); +void xfs_log_dinode_to_disk (struct xfs_mount *mp, +struct xfs_log_dinode *from,struct xfs_dinode *to);xfs_failaddr_t xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino,struct xfs_dinode *dip);fs/xfs/libxfs/xfs_inode_fork.h +12
-5@@ -21,10 +21,10 @@ struct xfs_ifork {void *if_root;/* extent tree root */ char *if_data;/* inline file data */ } if_u1; +xfs_extnum_t if_nextents;/* # of extents in this fork */ short if_broot_bytes;/* bytes allocated for root */ unsigned char if_flags;/* per-fork flags */ int8_t if_format;/* format of this fork */ -xfs_extnum_t if_nextents;/* # of extents in this fork */ };/* @@ -157,10 +157,17 @@ static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) {ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); -if (whichfork ==XFS_DATA_FORK ) -return MAXEXTNUM ; -else -return MAXAEXTNUM ; +if (whichfork ==XFS_DATA_FORK ) { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXEXTNUM_HI ; +else +return MAXEXTNUM ; + }else { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXAEXTNUM_HI ; +else +return MAXAEXTNUM ; + } }struct xfs_ifork *xfs_iext_state_to_fork (struct xfs_inode *ip,int state);fs/xfs/libxfs/xfs_log_format.h +5
-3@@ -396,8 +396,8 @@ struct xfs_log_dinode {xfs_fsize_t di_size;/* number of bytes in file */ xfs_rfsblock_t di_nblocks;/* # of direct & btree blocks used */ xfs_extlen_t di_extsize;/* basic/minimum extent size for file */ -xfs_extnum_t di_nextents;/* number of extents in data fork */ -xfs_aextnum_t di_anextents;/* number of extents in attribute fork*/ +uint32_t di_nextents_lo;/* lower part of data fork extent count */ +uint16_t di_anextents_lo;/* lower part of attr fork extent count */ uint8_t di_forkoff;/* attr fork offs, <<3 for 64b align */ int8_t di_aformat;/* format of attr fork's data */ uint32_t di_dmevmask;/* DMIG event mask */ @@ -414,7 +414,9 @@ struct xfs_log_dinode {xfs_lsn_t di_lsn;/* flush sequence */ uint64_t di_flags2;/* more random flags */ uint32_t di_cowextsize;/* basic cow extent size for file */ -uint8_t di_pad2[12 ];/* more padding for future expansion */ +uint32_t di_nextents_hi;/* higher part of data fork extent count */ +uint16_t di_anextents_hi;/* higher part of attr fork extent count */ +uint8_t di_pad2[6 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_ictimestamp_t di_crtime;/* time created */ fs/xfs/libxfs/xfs_types.h +6
-4@@ -12,8 +12,8 @@ typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ -typedef int32_t xfs_extnum_t ;/* # of extents in a file */ -typedef int16_t xfs_aextnum_t ;/* # extents in an attribute fork */ +typedef uint64_t xfs_extnum_t ;/* # of extents in a file */ +typedef uint32_t xfs_aextnum_t ;/* # extents in an attribute fork */ typedef int64_t xfs_fsize_t ;/* bytes in a file */ typedef uint64_t xfs_ufsize_t ;/* unsigned bytes in a file */ @@ -59,8 +59,10 @@ typedef void * xfs_failaddr_t;* Max values for extlen, extnum, aextnum. */ #define MAXEXTLEN ((xfs_extlen_t)0x001fffff)/* 21 bits */ -#define MAXEXTNUM ((xfs_extnum_t)0x7fffffff)/* signed int */ -#define MAXAEXTNUM ((xfs_aextnum_t)0x7fff)/* signed short */ +#define MAXEXTNUM ((int32_t)0x7fffffff)/* signed int */ +#define MAXAEXTNUM ((int16_t)0x7fff)/* signed short */ +#define MAXEXTNUM_HI ((xfs_extnum_t)0x7fffffffffff)/* unsigned 47 bits */ +#define MAXAEXTNUM_HI ((xfs_aextnum_t)0xffffffff)/* unsigned 32 bits */ /* * Minimum and maximum blocksize and sectorsize. fs/xfs/scrub/inode.c +1
-1@@ -206,7 +206,7 @@ xchk_dinode(size_t fork_recs;unsigned long long isize;uint64_t flags2; -uint32_t nextents; +xfs_extnum_t nextents;uint16_t flags;uint16_t mode;fs/xfs/xfs_inode.c +0
-0
fs/xfs/xfs_inode.c xfs_iflush( · line 3520
Quoted 5 lines
fs/xfs/xfs_inode.c +1
-1@@ -3517,7 +3517,7 @@ xfs_iflush( ip->i_d.di_nblocks, mp, XFS_ERRTAG_IFLUSH_5)) { xfs_alert_tag(mp, XFS_PTAG_IFLUSH, "%s: detected corrupt incore inode %Lu, " - "total extents = %d, nblocks = %Ld, ptr "PTR_FMT, + "total extents = %llu, nblocks = %Ld, ptr "PTR_FMT,
Might be a good time to get rid of these nonstandard "%Ld" format specifiers too...
Quoted 94 lines
fs/xfs/xfs_inode.c +0
-0__func__, ip->i_ino, ip->i_df.if_nextents +xfs_ifork_nextents (ip->i_afp), ip->i_d.di_nblocks, ip);fs/xfs/xfs_inode_item.c +10
-2@@ -301,6 +301,7 @@ xfs_inode_to_log_dinode( struct xfs_log_dinode *to, xfs_lsn_t lsn) { +struct xfs_sb *sbp = &ip->i_mount->m_sb;struct xfs_icdinode *from = &ip->i_d;struct inode *inode =VFS_I (ip);@@ -326,8 +327,8 @@ xfs_inode_to_log_dinode( to->di_size = from->di_size; to->di_nblocks = from->di_nblocks; to->di_extsize = from->di_extsize; - to->di_nextents =xfs_ifork_nextents (&ip->i_df); - to->di_anextents =xfs_ifork_nextents (ip->i_afp); + to->di_nextents_lo =xfs_ifork_nextents (&ip->i_df); + to->di_anextents_lo =xfs_ifork_nextents (ip->i_afp); to->di_forkoff = from->di_forkoff; to->di_aformat =xfs_ifork_format (ip->i_afp); to->di_dmevmask = from->di_dmevmask;@@ -344,6 +345,13 @@ xfs_inode_to_log_dinode( to->di_crtime.t_nsec = from->di_crtime.tv_nsec; to->di_flags2 = from->di_flags2; to->di_cowextsize = from->di_cowextsize; +if (xfs_sb_version_haswideextcnt (sbp)) { + to->di_nextents_hi + =xfs_ifork_nextents (&ip->i_df) >>32 ; + to->di_anextents_hi + =xfs_ifork_nextents (ip->i_afp) >>16 ; + } + to->di_ino = ip->i_ino; to->di_lsn = lsn;memset (to->di_pad2,0 ,sizeof (to->di_pad2));fs/xfs/xfs_inode_item_recover.c +15
-5@@ -126,6 +126,8 @@ xlog_recover_inode_commit_pass2(struct xfs_mount *mp = log->l_mp;struct xfs_buf *bp;struct xfs_dinode *dip; +xfs_extnum_t nextents; +xfs_aextnum_t anextents;int len;char *src;char *dest;@@ -256,16 +258,24 @@ xlog_recover_inode_commit_pass2( goto out_release; } } -if (unlikely (ldip->di_nextents + ldip->di_anextents > ldip->di_nblocks)){ + + nextents = ldip->di_nextents_lo; +if (xfs_sb_version_haswideextcnt (&mp->m_sb)) + nextents |= ((xfs_extnum_t)(ldip->di_nextents_hi) <<32 ); + + anextents = ldip->di_anextents_lo; +if (xfs_sb_version_haswideextcnt (&mp->m_sb)) + anextents |= ((xfs_aextnum_t)(ldip->di_anextents_hi) <<16 ); + +if (unlikely (nextents + anextents > ldip->di_nblocks)) {XFS_CORRUPTION_ERROR ("xlog_recover_inode_pass2(5)" ,XFS_ERRLEVEL_LOW , mp, ldip,sizeof (*ldip));xfs_alert (mp,"%s: Bad inode log record, rec ptr " PTR_FMT ", dino ptr " PTR_FMT ", " -"dino bp " PTR_FMT ", ino %Ld, total extents = %d, nblocks = %Ld" , +"dino bp " PTR_FMT ", ino %Ld, total extents = %llu, nblocks = %Ld" , __func__, item, dip, bp, in_f->ilf_ino, - ldip->di_nextents + ldip->di_anextents, - ldip->di_nblocks); + nextents + anextents, ldip->di_nblocks); error = -EFSCORRUPTED ; goto out_release; }@@ -293,7 +303,7 @@ xlog_recover_inode_commit_pass2( }/* recover the log dinode inode into the on disk inode */ -xfs_log_dinode_to_disk (ldip, dip); +xfs_log_dinode_to_disk (mp, ldip, dip); fields = in_f->ilf_fields;if (fields &XFS_ILOG_DEV )Signature · 1 line
2.28.0
Re: [PATCH 3/3] xfs: Extend data/attr fork extent counter width
Quoted 15 lines · IST Darrick J. Wong
Quoted 8 lines · Chandan Babu R
The commit xfs: fix inode fork extent count overflow (
3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this commit extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.Sorry I forgot to reply to your follow up to this question the last time you sent this series. I still don't understand why you're consuming 32 more bits of
xfs_dinodefor the data fork extent count but only using 15 bits of that space.
Quoted 8 lines
On a 1k block filesystem, we can have 2^(63-10) = 2^53 extents. Block sizes this small are still supported by the V5 format.
On a 4k block filesystem, we can have 2^(63-12) = 2^51 extents. This blocksize is the default on x86.
Granted, that would be aw{ful,esome}, but I do not see why it's necessary to have this limitation.
The thought process was that the maximum data fork extent count based on the value derived from 1k block size (i.e. 2^53) would be an invalid upper bound for the largest blocksized filesystem instance (i.e. 64k block size). Extent count overflow checks would succeed (they should actually be failing) when using 2^53 as the upper limit for extent count.
Hence I chose 2^47 as the limit for maximum data fork extent count. In hindsight, I could have carved out a 16-bit field from di_pad2[] instead of a 32-bit field.
I browsed some VFS source code today and I see that the file size limit check is performed in VFS layer. For example,
# truncate -s 9223372036854775800 /mnt/file-1.bin # xfs_io -f -a -c 'pwrite 9223372036854775800 10' /mnt/file-1.bin pwrite: Invalid argument
9223372036854775800 is 8 bytes less than 2^63. In this case, -EINVAL is being returned by rw_verify_area(). But the check inside rw_verify_area() is based on overflow of a loff_t typed value i.e. it is not based on the value held by sb->s_maxbytes. In case of XFS, this works well since the value assigned to sb->s_maxbytes and the maximum value held by a loff_t typed variable is 2^63.
Quoted 153 lines
Quoted 153 lines
Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this commit extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 8 ++++--- fs/xfs/libxfs/xfs_format.h | 20 ++++++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 42 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.h | 17 +++++++++---- fs/xfs/libxfs/xfs_log_format.h | 8 ++++--- fs/xfs/libxfs/xfs_types.h | 10 ++++---- fs/xfs/scrub/inode.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 ++++++++-- fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++---- 11 files changed, 105 insertions(+), 40 deletions(-)fs/xfs/libxfs/xfs_bmap.c +5
-3@@ -52,9 +52,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { +xfs_extnum_t maxleafents;/* max leaf entries possible */ int level;/* btree level */ uint maxblocks;/* max blocks at this level */ -uint maxleafents;/* max leaf entries possible */ int maxrootrecs;/* max records in root block */ int minleafrecs;/* min records in leaf block */ int minnoderecs;/* min records in node block */ @@ -64,7 +64,9 @@ xfs_bmap_compute_maxlevels(* The maximum number of extents in a file, hence the maximum number of * leaf entries, is controlled by the size of the on-disk extent count, * either a signed 32-bit number for the data fork, or a signed 16-bit -* number for the attr fork. +* number for the attr fork. With mkfs.xfs' wide-extcount option +* enabled, the data fork extent count is unsigned 47-bits wide, while +* the corresponding attr fork extent count is unsigned 32-bits wide. * * Note that we can no longer assume that if we are in ATTR1 that * the fork offset of all the inodes will be @@ -464,7 +466,7 @@ xfs_bmap_check_leaf_extents(if (bp_release)xfs_trans_brelse (NULL , bp); error_norelse: -xfs_warn (mp,"%s: BAD after btree leaves for %d extents" , +xfs_warn (mp,"%s: BAD after btree leaves for %llu extents" , __func__, i);xfs_err (mp,"%s: CORRUPTED BTREE OR SOMETHING" , __func__);xfs_force_shutdown (mp,SHUTDOWN_CORRUPT_INCORE );fs/xfs/libxfs/xfs_format.h +15
-5@@ -465,10 +465,12 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT (1 << 3)/* Wider data/attr fork extent counters */ +#define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \ - XFS_SB_FEAT_INCOMPAT_META_UUID) + XFS_SB_FEAT_INCOMPAT_META_UUID| \ + XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool@@ -551,6 +553,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_haswideextcnt (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT ); +} +static inline bool xfs_sb_version_hasrmapbt (struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&@@ -873,8 +881,8 @@ typedef struct xfs_dinode {__be64 di_size;/* number of bytes in file */ __be64 di_nblocks;/* # of direct & btree blocks used */ __be32 di_extsize;/* basic/minimum extent size for file */ -__be32 di_nextents;/* number of extents in data fork */ -__be16 di_anextents;/* number of extents in attribute fork*/ +__be32 di_nextents_lo;/* lower part of data fork extent count */ +__be16 di_anextents_lo;/* lower part of attr fork extent count */ __u8 di_forkoff;/* attr fork offs, <<3 for 64b align */ __s8 di_aformat;/* format of attr fork's data */ __be32 di_dmevmask;/* DMIG event mask */ @@ -891,7 +899,9 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ -__u8 di_pad2[12 ];/* more padding for future expansion */ +__be32 di_nextents_hi;/* higher part of data fork extent count */ +__be16 di_anextents_hi;/* higher part of attr fork extent count */ +__u8 di_pad2[6 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_timestamp_t di_crtime;/* time created */ fs/xfs/libxfs/xfs_inode_buf.c +3
-2@@ -258,6 +258,7 @@ xfs_inode_to_disk( struct xfs_dinode *to, xfs_lsn_t lsn) { +struct xfs_sb *sbp = &ip->i_mount->m_sb;struct xfs_icdinode *from = &ip->i_d;struct inode *inode =VFS_I (ip);@@ -284,8 +285,8 @@ xfs_inode_to_disk( to->di_size =cpu_to_be64 (from->di_size); to->di_nblocks =cpu_to_be64 (from->di_nblocks); to->di_extsize =cpu_to_be32 (from->di_extsize); - to->di_nextents =cpu_to_be32 (xfs_ifork_nextents (&ip->i_df)); - to->di_anextents =cpu_to_be16 (xfs_ifork_nextents (ip->i_afp)); + to->di_nextents_lo =cpu_to_be32 (xfs_ifork_nextents (&ip->i_df)); + to->di_anextents_lo =cpu_to_be16 (xfs_ifork_nextents (ip->i_afp)); to->di_forkoff = from->di_forkoff; to->di_aformat =xfs_ifork_format (ip->i_afp); to->di_dmevmask =cpu_to_be32 (from->di_dmevmask);@@ -299,6 +300,15 @@ xfs_inode_to_disk( to->di_crtime.t_nsec =cpu_to_be32 (from->di_crtime.tv_nsec); to->di_flags2 =cpu_to_be64 (from->di_flags2);
Quoted 8 lines
fs/xfs/libxfs/xfs_inode_buf.c xfs_inode_to_disk( · line 306
Quoted 5 lines
fs/xfs/libxfs/xfs_inode_buf.c +4
-0to->di_cowextsize =cpu_to_be32 (from->di_cowextsize); +if (xfs_sb_version_haswideextcnt (sbp)) { + to->di_nextents_hi + =cpu_to_be32 (xfs_ifork_nextents (&ip->i_df) + >>32 );I thought you were only using this u32 field for the lower 15 bits? If that's really true ("47-bit field") then there ought to be some masking.
Thanks for pointing it out. I will fix this in the next version.
Quoted 5 lines
(Or you could just support
BMBT_STARTOFF_MASKextents...)Also, this might be a good time to add a helper to decode the extent counts from the dinode/log dinode.
I agree. I will add those in the next version of the patchset.
Quoted 195 lines
Quoted 195 lines
fs/xfs/libxfs/xfs_inode_buf.c +26
-7+ to->di_anextents_hi + =cpu_to_be16 (xfs_ifork_nextents (ip->i_afp) + >>16 ); + } + to->di_ino =cpu_to_be64 (ip->i_ino); to->di_lsn =cpu_to_be64 (lsn);memset (to->di_pad2,0 ,sizeof (to->di_pad2));@@ -312,9 +322,12 @@ xfs_inode_to_disk(void xfs_log_dinode_to_disk ( +struct xfs_mount *mp,struct xfs_log_dinode *from,struct xfs_dinode *to) { +struct xfs_sb *sbp = &mp->m_sb; + to->di_magic =cpu_to_be16 (from->di_magic); to->di_mode =cpu_to_be16 (from->di_mode); to->di_version = from->di_version;@@ -337,8 +350,8 @@ xfs_log_dinode_to_disk( to->di_size =cpu_to_be64 (from->di_size); to->di_nblocks =cpu_to_be64 (from->di_nblocks); to->di_extsize =cpu_to_be32 (from->di_extsize); - to->di_nextents =cpu_to_be32 (from->di_nextents); - to->di_anextents =cpu_to_be16 (from->di_anextents); + to->di_nextents_lo =cpu_to_be32 (from->di_nextents_lo); + to->di_anextents_lo =cpu_to_be16 (from->di_anextents_lo); to->di_forkoff = from->di_forkoff; to->di_aformat = from->di_aformat; to->di_dmevmask =cpu_to_be32 (from->di_dmevmask);@@ -352,6 +365,10 @@ xfs_log_dinode_to_disk( to->di_crtime.t_nsec =cpu_to_be32 (from->di_crtime.t_nsec); to->di_flags2 =cpu_to_be64 (from->di_flags2); to->di_cowextsize =cpu_to_be32 (from->di_cowextsize); +if (xfs_sb_version_haswideextcnt (sbp)) { + to->di_nextents_hi =cpu_to_be32 (from->di_nextents_hi); + to->di_anextents_hi =cpu_to_be16 (from->di_anextents_hi); + } to->di_ino =cpu_to_be64 (from->di_ino); to->di_lsn =cpu_to_be64 (from->di_lsn);memcpy (to->di_pad2, from->di_pad2,sizeof (to->di_pad2));@@ -368,7 +385,7 @@ xfs_dinode_verify_fork( struct xfs_mount *mp, int whichfork) { - uint32_t di_nextents; +xfs_extnum_t di_nextents;xfs_extnum_t max_extents; di_nextents =xfs_dfork_nextents (&mp->m_sb, dip, whichfork);@@ -408,10 +425,17 @@ xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) {xfs_extnum_t nextents; -if (whichfork ==XFS_DATA_FORK ) - nextents =be32_to_cpu (dip->di_nextents); -else - nextents =be16_to_cpu (dip->di_anextents); +if (whichfork ==XFS_DATA_FORK ) { + nextents =be32_to_cpu (dip->di_nextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_extnum_t )be32_to_cpu (dip->di_nextents_hi) <<32 ); + }else { + nextents =be16_to_cpu (dip->di_anextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_aextnum_t )be16_to_cpu (dip->di_anextents_hi) <<16 ); + }return nextents; }fs/xfs/libxfs/xfs_inode_buf.h +2
-2@@ -49,8 +49,8 @@ void xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);void xfs_inode_to_disk (struct xfs_inode *ip,struct xfs_dinode *to,xfs_lsn_t lsn);int xfs_inode_from_disk (struct xfs_inode *ip,struct xfs_dinode *from); -void xfs_log_dinode_to_disk (struct xfs_log_dinode *from, -struct xfs_dinode *to); +void xfs_log_dinode_to_disk (struct xfs_mount *mp, +struct xfs_log_dinode *from,struct xfs_dinode *to);xfs_failaddr_t xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino,struct xfs_dinode *dip);fs/xfs/libxfs/xfs_inode_fork.h +12
-5@@ -21,10 +21,10 @@ struct xfs_ifork {void *if_root;/* extent tree root */ char *if_data;/* inline file data */ } if_u1; +xfs_extnum_t if_nextents;/* # of extents in this fork */ short if_broot_bytes;/* bytes allocated for root */ unsigned char if_flags;/* per-fork flags */ int8_t if_format;/* format of this fork */ -xfs_extnum_t if_nextents;/* # of extents in this fork */ };/* @@ -157,10 +157,17 @@ static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) {ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); -if (whichfork ==XFS_DATA_FORK ) -return MAXEXTNUM ; -else -return MAXAEXTNUM ; +if (whichfork ==XFS_DATA_FORK ) { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXEXTNUM_HI ; +else +return MAXEXTNUM ; + }else { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXAEXTNUM_HI ; +else +return MAXAEXTNUM ; + } }struct xfs_ifork *xfs_iext_state_to_fork (struct xfs_inode *ip,int state);fs/xfs/libxfs/xfs_log_format.h +5
-3@@ -396,8 +396,8 @@ struct xfs_log_dinode {xfs_fsize_t di_size;/* number of bytes in file */ xfs_rfsblock_t di_nblocks;/* # of direct & btree blocks used */ xfs_extlen_t di_extsize;/* basic/minimum extent size for file */ -xfs_extnum_t di_nextents;/* number of extents in data fork */ -xfs_aextnum_t di_anextents;/* number of extents in attribute fork*/ +uint32_t di_nextents_lo;/* lower part of data fork extent count */ +uint16_t di_anextents_lo;/* lower part of attr fork extent count */ uint8_t di_forkoff;/* attr fork offs, <<3 for 64b align */ int8_t di_aformat;/* format of attr fork's data */ uint32_t di_dmevmask;/* DMIG event mask */ @@ -414,7 +414,9 @@ struct xfs_log_dinode {xfs_lsn_t di_lsn;/* flush sequence */ uint64_t di_flags2;/* more random flags */ uint32_t di_cowextsize;/* basic cow extent size for file */ -uint8_t di_pad2[12 ];/* more padding for future expansion */ +uint32_t di_nextents_hi;/* higher part of data fork extent count */ +uint16_t di_anextents_hi;/* higher part of attr fork extent count */ +uint8_t di_pad2[6 ];/* more padding for future expansion */ /* fields only written to during inode creation */ xfs_ictimestamp_t di_crtime;/* time created */ fs/xfs/libxfs/xfs_types.h +6
-4@@ -12,8 +12,8 @@ typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ -typedef int32_t xfs_extnum_t ;/* # of extents in a file */ -typedef int16_t xfs_aextnum_t ;/* # extents in an attribute fork */ +typedef uint64_t xfs_extnum_t ;/* # of extents in a file */ +typedef uint32_t xfs_aextnum_t ;/* # extents in an attribute fork */ typedef int64_t xfs_fsize_t ;/* bytes in a file */ typedef uint64_t xfs_ufsize_t ;/* unsigned bytes in a file */ @@ -59,8 +59,10 @@ typedef void * xfs_failaddr_t;* Max values for extlen, extnum, aextnum. */ #define MAXEXTLEN ((xfs_extlen_t)0x001fffff)/* 21 bits */ -#define MAXEXTNUM ((xfs_extnum_t)0x7fffffff)/* signed int */ -#define MAXAEXTNUM ((xfs_aextnum_t)0x7fff)/* signed short */ +#define MAXEXTNUM ((int32_t)0x7fffffff)/* signed int */ +#define MAXAEXTNUM ((int16_t)0x7fff)/* signed short */ +#define MAXEXTNUM_HI ((xfs_extnum_t)0x7fffffffffff)/* unsigned 47 bits */ +#define MAXAEXTNUM_HI ((xfs_aextnum_t)0xffffffff)/* unsigned 32 bits */ /* * Minimum and maximum blocksize and sectorsize. fs/xfs/scrub/inode.c +1
-1@@ -206,7 +206,7 @@ xchk_dinode(size_t fork_recs;unsigned long long isize;uint64_t flags2; -uint32_t nextents; +xfs_extnum_t nextents;uint16_t flags;uint16_t mode;
Quoted 13 lines
fs/xfs/xfs_inode.c xfs_iflush( · line 3520
Quoted 10 lines
fs/xfs/xfs_inode.c +1
-1@@ -3517,7 +3517,7 @@ xfs_iflush( ip->i_d.di_nblocks, mp, XFS_ERRTAG_IFLUSH_5)) { xfs_alert_tag(mp, XFS_PTAG_IFLUSH, "%s: detected corrupt incore inode %Lu, " - "total extents = %d, nblocks = %Ld, ptr "PTR_FMT, + "total extents = %llu, nblocks = %Ld, ptr "PTR_FMT,Might be a good time to get rid of these nonstandard "%Ld" format specifiers too...
Ok. I will fix these up.
Quoted 93 lines
Quoted 92 lines
fs/xfs/xfs_inode.c +0
-0__func__, ip->i_ino, ip->i_df.if_nextents +xfs_ifork_nextents (ip->i_afp), ip->i_d.di_nblocks, ip);fs/xfs/xfs_inode_item.c +10
-2@@ -301,6 +301,7 @@ xfs_inode_to_log_dinode( struct xfs_log_dinode *to, xfs_lsn_t lsn) { +struct xfs_sb *sbp = &ip->i_mount->m_sb;struct xfs_icdinode *from = &ip->i_d;struct inode *inode =VFS_I (ip);@@ -326,8 +327,8 @@ xfs_inode_to_log_dinode( to->di_size = from->di_size; to->di_nblocks = from->di_nblocks; to->di_extsize = from->di_extsize; - to->di_nextents =xfs_ifork_nextents (&ip->i_df); - to->di_anextents =xfs_ifork_nextents (ip->i_afp); + to->di_nextents_lo =xfs_ifork_nextents (&ip->i_df); + to->di_anextents_lo =xfs_ifork_nextents (ip->i_afp); to->di_forkoff = from->di_forkoff; to->di_aformat =xfs_ifork_format (ip->i_afp); to->di_dmevmask = from->di_dmevmask;@@ -344,6 +345,13 @@ xfs_inode_to_log_dinode( to->di_crtime.t_nsec = from->di_crtime.tv_nsec; to->di_flags2 = from->di_flags2; to->di_cowextsize = from->di_cowextsize; +if (xfs_sb_version_haswideextcnt (sbp)) { + to->di_nextents_hi + =xfs_ifork_nextents (&ip->i_df) >>32 ; + to->di_anextents_hi + =xfs_ifork_nextents (ip->i_afp) >>16 ; + } + to->di_ino = ip->i_ino; to->di_lsn = lsn;memset (to->di_pad2,0 ,sizeof (to->di_pad2));fs/xfs/xfs_inode_item_recover.c +15
-5@@ -126,6 +126,8 @@ xlog_recover_inode_commit_pass2(struct xfs_mount *mp = log->l_mp;struct xfs_buf *bp;struct xfs_dinode *dip; +xfs_extnum_t nextents; +xfs_aextnum_t anextents;int len;char *src;char *dest;@@ -256,16 +258,24 @@ xlog_recover_inode_commit_pass2( goto out_release; } } -if (unlikely (ldip->di_nextents + ldip->di_anextents > ldip->di_nblocks)){ + + nextents = ldip->di_nextents_lo; +if (xfs_sb_version_haswideextcnt (&mp->m_sb)) + nextents |= ((xfs_extnum_t)(ldip->di_nextents_hi) <<32 ); + + anextents = ldip->di_anextents_lo; +if (xfs_sb_version_haswideextcnt (&mp->m_sb)) + anextents |= ((xfs_aextnum_t)(ldip->di_anextents_hi) <<16 ); + +if (unlikely (nextents + anextents > ldip->di_nblocks)) {XFS_CORRUPTION_ERROR ("xlog_recover_inode_pass2(5)" ,XFS_ERRLEVEL_LOW , mp, ldip,sizeof (*ldip));xfs_alert (mp,"%s: Bad inode log record, rec ptr " PTR_FMT ", dino ptr " PTR_FMT ", " -"dino bp " PTR_FMT ", ino %Ld, total extents = %d, nblocks = %Ld" , +"dino bp " PTR_FMT ", ino %Ld, total extents = %llu, nblocks = %Ld" , __func__, item, dip, bp, in_f->ilf_ino, - ldip->di_nextents + ldip->di_anextents, - ldip->di_nblocks); + nextents + anextents, ldip->di_nblocks); error = -EFSCORRUPTED ; goto out_release; }@@ -293,7 +303,7 @@ xlog_recover_inode_commit_pass2( }/* recover the log dinode inode into the on disk inode */ -xfs_log_dinode_to_disk (ldip, dip); +xfs_log_dinode_to_disk (mp, ldip, dip); fields = in_f->ilf_fields;if (fields &XFS_ILOG_DEV )
Signature · 1 line
chandan
Re: [PATCH 3/3] xfs: Extend data/attr fork extent counter width
In reply to Chandan Babu RQuoted 62 lines · Chandan Babu R
The commit xfs: fix inode fork extent count overflow (
3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this commit extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this commit extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 8 ++++--- fs/xfs/libxfs/xfs_format.h | 20 ++++++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 42 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.h | 17 +++++++++---- fs/xfs/libxfs/xfs_log_format.h | 8 ++++--- fs/xfs/libxfs/xfs_types.h | 10 ++++---- fs/xfs/scrub/inode.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 ++++++++-- fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++---- 11 files changed, 105 insertions(+), 40 deletions(-)fs/xfs/libxfs/xfs_bmap.c +1
-1@@ -52,9 +52,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { +xfs_extnum_t maxleafents;/* max leaf entries possible */ int level;/* btree level */ uint maxblocks;/* max blocks at this level */ -uint maxleafents;/* max leaf entries possible */ int maxrootrecs;/* max records in root block */ int minleafrecs;/* min records in leaf block */ int minnoderecs;/* min records in node block */
fs/xfs/libxfs/xfs_bmap.c xfs_bmap_compute_maxlevels( · line 69
Quoted 7 lines
fs/xfs/libxfs/xfs_bmap.c +3
-1@@ -64,7 +64,9 @@ xfs_bmap_compute_maxlevels(* The maximum number of extents in a file, hence the maximum number of * leaf entries, is controlled by the size of the on-disk extent count, * either a signed 32-bit number for the data fork, or a signed 16-bit -* number for the attr fork. +* number for the attr fork. With mkfs.xfs' wide-extcount option +* enabled, the data fork extent count is unsigned 47-bits wide, while +* the corresponding attr fork extent count is unsigned 32-bits wide.
This doesn't really need to state what the sizes of the on disk fields are. If anything should state that, it's a description of the helper function that returns the maximum supported extent count. Also, it's the maximum extents in a the fork, not the _file_.
i.e. this should probably just read
* The maximum number of extents in a fork, hence the maximum number of
* leaf entries, is controlled by the size of the on-disk extent count.
Quoted 6 lines
fs/xfs/libxfs/xfs_format.h +0
-0@@ -465,10 +465,12 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 473
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +4
-2#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT (1 << 3)/* Wider data/attr fork extent counters */ +#define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \ - XFS_SB_FEAT_INCOMPAT_META_UUID) + XFS_SB_FEAT_INCOMPAT_META_UUID| \ + XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT)
Don't we normally add the feature bit in a standalone patch once all the infrastructure has already been put in place?
fs/xfs/libxfs/xfs_format.h static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) · line 560
Quoted 11 lines
fs/xfs/libxfs/xfs_format.h +5
-0#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool@@ -551,6 +553,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_haswideextcnt (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT ); +}
I don't really like the name of the feature :/
Precendence in naming feature additions like this is "32 bit project IDs" - when we extended them from 16 to 32 bits, we didn't call them "wide project IDs" as "wide" could mean anything. What do we do if we later need to increase the size of the attribute fork extent count? :/
xfs_sb_version_hasextcount_64bit() would match the xfs_sb_version_hasprojid_32bit() naming internally....
Quoted 15 lines
fs/xfs/libxfs/xfs_format.h +2
-2static inline bool xfs_sb_version_hasrmapbt (struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&@@ -873,8 +881,8 @@ typedef struct xfs_dinode {__be64 di_size;/* number of bytes in file */ __be64 di_nblocks;/* # of direct & btree blocks used */ __be32 di_extsize;/* basic/minimum extent size for file */ -__be32 di_nextents;/* number of extents in data fork */ -__be16 di_anextents;/* number of extents in attribute fork*/ +__be32 di_nextents_lo;/* lower part of data fork extent count */ +__be16 di_anextents_lo;/* lower part of attr fork extent count */ __u8 di_forkoff;/* attr fork offs, <<3 for 64b align */ __s8 di_aformat;/* format of attr fork's data */ __be32 di_dmevmask;/* DMIG event mask */
fs/xfs/libxfs/xfs_format.h typedef struct xfs_dinode { · line 904
Quoted 7 lines
fs/xfs/libxfs/xfs_format.h +3
-1@@ -891,7 +899,9 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ -__u8 di_pad2[12 ];/* more padding for future expansion */ +__be32 di_nextents_hi;/* higher part of data fork extent count */ +__be16 di_anextents_hi;/* higher part of attr fork extent count */ +__u8 di_pad2[6 ];/* more padding for future expansion */
I think I've mentioned this before - I don't really like extending inode variables this way. We did it for projid32 because we did not have any spare space in the v4 inode to do anything else.
I would kinda prefer to do something like this:
- __be32 di_nextents; /* number of extents in data fork */
- __be16 di_anextents; /* number of extents in attribute fork*/
+ __be32 di_nextents32; /* 32 bit fork extent count */
+ __be16 di_nextents16; /* 16 bit fork extent count */
....
- __u8 di_pad2[12]; /* more padding for future expansion */
+ __u8 di_pad2[4]; /* more padding for future expansion */
+ __be64 di_nextents64; /* 64 bit fork extent count */
And then depending on the hasextcount_64bit bit is set, we read from disk like this:
if (hasextcount_64bit) {
to->di_nextents = be64_to_cpu(dip->di_nextents64);
to->di_naextents = be32_to_cpu(dip->di_nextents32);
if (dip->di_nextents16 != 0)
return -EFSCORRUPTED;
} else {
to->di_nextents = be32_to_cpu(dip->di_nextents32);
to->di_naextents = be16_to_cpu(dip->di_nextents16);
if (dip->di_nextents64 != 0)
return -EFSCORRUPTED;
}and the writing to disk is equally simple. There's no bit shifting or masking, and we still end up with the same amount of unused space in the inode when hasextcount_64bit is set because di_nextents16 can be reused by another new feature....
Quoted 9 lines
fs/xfs/libxfs/xfs_format.h +1
-4@@ -408,10 +425,17 @@ xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) {xfs_extnum_t nextents; -if (whichfork ==XFS_DATA_FORK ) - nextents =be32_to_cpu (dip->di_nextents); -else - nextents =be16_to_cpu (dip->di_anextents); +if (whichfork ==XFS_DATA_FORK ) {
fs/xfs/libxfs/xfs_format.h xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) · line 438
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +10
-0+ nextents =be32_to_cpu (dip->di_nextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_extnum_t )be32_to_cpu (dip->di_nextents_hi) <<32 ); + }else { + nextents =be16_to_cpu (dip->di_anextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_aextnum_t )be16_to_cpu (dip->di_anextents_hi) <<16 ); + }
... and we get rid of this bit of messy code :)
Quoted 9 lines
fs/xfs/libxfs/xfs_format.h +1
-4@@ -157,10 +157,17 @@ static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) {ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); -if (whichfork ==XFS_DATA_FORK ) -return MAXEXTNUM ; -else -return MAXAEXTNUM ; +if (whichfork ==XFS_DATA_FORK ) {
fs/xfs/libxfs/xfs_format.h static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) · line 170
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +10
-0+if (xfs_sb_version_haswideextcnt (sbp)) +return MAXEXTNUM_HI ; +else +return MAXEXTNUM ; + }else { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXAEXTNUM_HI ; +else +return MAXAEXTNUM ; + }
I think we should actually rework MAXEXTNUM/MAXAEXTNUM before doing this. They are defined in xfs_types.h as in-memory limits, while these are actually returning on-disk format limits which should be defined in xfs_format.h
e.g:
#define XFS_IFORK_EXTCNT_MAX64 ....
#define XFS_IFORK_EXTCNT_MAX32 ....
#define XFS_IFORK_EXTCNT_MAX16 ....
And in xfs_iext_max() we do:
bool has64 = xfs_sb_version_haswideextcnt()
switch (whichfork) {
case XFS_DATA_FORK:
return has64 ? XFS_IFORK_EXTCNT_MAX64 : XFS_IFORK_EXTCNT_MAX32;
case XFS_ATTR_FORK:
return has64 ? XFS_IFORK_EXTCNT_MAX32 : XFS_IFORK_EXTCNT_MAX16;
case XFS_COW_FORK:
return XFS_IFORK_EXTCNT_MAX32;
default:
ASSERT(0);
break;
}
return -EFSCORRUPTED;fs/xfs/libxfs/xfs_format.h typedef void * xfs_failaddr_t; · line 65
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +4
-2@@ -59,8 +59,10 @@ typedef void * xfs_failaddr_t;* Max values for extlen, extnum, aextnum. */ #define MAXEXTLEN ((xfs_extlen_t)0x001fffff)/* 21 bits */ -#define MAXEXTNUM ((xfs_extnum_t)0x7fffffff)/* signed int */ -#define MAXAEXTNUM ((xfs_aextnum_t)0x7fff)/* signed short */ +#define MAXEXTNUM ((int32_t)0x7fffffff)/* signed int */ +#define MAXAEXTNUM ((int16_t)0x7fff)/* signed short */ +#define MAXEXTNUM_HI ((xfs_extnum_t)0x7fffffffffff)/* unsigned 47 bits */ +#define MAXAEXTNUM_HI ((xfs_aextnum_t)0xffffffff)/* unsigned 32 bits */
Yeah, these on-disk limits need to go into xfs_format.h and not used directly anymore...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 3/3] xfs: Extend data/attr fork extent counter width
Quoted 76 lines · IST Dave Chinner
Quoted 62 lines · Chandan Babu R
The commit xfs: fix inode fork extent count overflow (
3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this commit extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this commit extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 8 ++++--- fs/xfs/libxfs/xfs_format.h | 20 ++++++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 42 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.h | 17 +++++++++---- fs/xfs/libxfs/xfs_log_format.h | 8 ++++--- fs/xfs/libxfs/xfs_types.h | 10 ++++---- fs/xfs/scrub/inode.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 ++++++++-- fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++---- 11 files changed, 105 insertions(+), 40 deletions(-)fs/xfs/libxfs/xfs_bmap.c +1
-1@@ -52,9 +52,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { +xfs_extnum_t maxleafents;/* max leaf entries possible */ int level;/* btree level */ uint maxblocks;/* max blocks at this level */ -uint maxleafents;/* max leaf entries possible */ int maxrootrecs;/* max records in root block */ int minleafrecs;/* min records in leaf block */ int minnoderecs;/* min records in node block */ fs/xfs/libxfs/xfs_bmap.c xfs_bmap_compute_maxlevels( · line 69
Quoted 7 lines
fs/xfs/libxfs/xfs_bmap.c +3
-1@@ -64,7 +64,9 @@ xfs_bmap_compute_maxlevels(* The maximum number of extents in a file, hence the maximum number of * leaf entries, is controlled by the size of the on-disk extent count, * either a signed 32-bit number for the data fork, or a signed 16-bit -* number for the attr fork. +* number for the attr fork. With mkfs.xfs' wide-extcount option +* enabled, the data fork extent count is unsigned 47-bits wide, while +* the corresponding attr fork extent count is unsigned 32-bits wide. This doesn't really need to state what the sizes of the on disk fields are. If anything should state that, it's a description of the helper function that returns the maximum supported extent count. Also, it's the maximum extents in a the fork, not the _file_.
Quoted 4 lines
i.e. this should probably just read
* The maximum number of extents in a fork, hence the maximum number of
* leaf entries, is controlled by the size of the on-disk extent count.
I agree. I will fix this up.
Quoted 12 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +2
-1@@ -465,10 +465,12 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT (1 << 3)/* Wider data/attr fork extent counters */ +#define XFS_SB_FEAT_INCOMPAT_ALL \
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 473
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +2
-1(XFS_SB_FEAT_INCOMPAT_FTYPE | \XFS_SB_FEAT_INCOMPAT_SPINODES | \ -XFS_SB_FEAT_INCOMPAT_META_UUID ) +XFS_SB_FEAT_INCOMPAT_META_UUID | \ +XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT )Don't we normally add the feature bit in a standalone patch once all the infrastructure has already been put in place?
Yes, I now realize that code changes like "defining new fields in on-disk inode structure" and "promoting xfs_extnum_t to uint64_t" can be moved to a separate patch. I will split this patch into as many required parts before posting the next version.
Quoted 15 lines
fs/xfs/libxfs/xfs_format.h static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) · line 560
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +5
-0#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool@@ -551,6 +553,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_haswideextcnt (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT ); +}I don't really like the name of the feature :/
Quoted 8 lines
Precendence in naming feature additions like this is "32 bit project IDs" - when we extended them from 16 to 32 bits, we didn't call them "wide project IDs" as "wide" could mean anything. What do we do if we later need to increase the size of the attribute fork extent count? :/
xfs_sb_version_hasextcount_64bit()would match thexfs_sb_version_hasprojid_32bit()naming internally....
I agree. I will fix the name here and in xfsprogs.
Quoted 19 lines
Quoted 19 lines
fs/xfs/libxfs/xfs_format.h +2
-2static inline bool xfs_sb_version_hasrmapbt (struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&@@ -873,8 +881,8 @@ typedef struct xfs_dinode {__be64 di_size;/* number of bytes in file */ __be64 di_nblocks;/* # of direct & btree blocks used */ __be32 di_extsize;/* basic/minimum extent size for file */ -__be32 di_nextents;/* number of extents in data fork */ -__be16 di_anextents;/* number of extents in attribute fork*/ +__be32 di_nextents_lo;/* lower part of data fork extent count */ +__be16 di_anextents_lo;/* lower part of attr fork extent count */ __u8 di_forkoff;/* attr fork offs, <<3 for 64b align */ __s8 di_aformat;/* format of attr fork's data */ __be32 di_dmevmask;/* DMIG event mask */ @@ -891,7 +899,9 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h typedef struct xfs_dinode { · line 904
Quoted 4 lines
fs/xfs/libxfs/xfs_format.h +3
-1-__u8 di_pad2[12 ];/* more padding for future expansion */ +__be32 di_nextents_hi;/* higher part of data fork extent count */ +__be16 di_anextents_hi;/* higher part of attr fork extent count */ +__u8 di_pad2[6 ];/* more padding for future expansion */ I think I've mentioned this before - I don't really like extending inode variables this way. We did it for projid32 because we did not have any spare space in the v4 inode to do anything else.
Yes, You had suggested the "add new inode member" approach in one of the older versions of the patchset. But Christoph had objected to this approach
(https://www.spinics.net/lists/linux-xfs/msg40112.html). Hence I had dropped the idea. Sorry, I should have consulted with you before taking that decision.
Quoted 46 lines
I would kinda prefer to do something like this:
(quoted diff) +4
-3- __be32 di_nextents; /* number of extents in data fork */ - __be16 di_anextents; /* number of extents in attribute fork*/ + __be32 di_nextents32; /* 32 bit fork extent count */ + __be16 di_nextents16; /* 16 bit fork extent count */ - __u8 di_pad2[12]; /* more padding for future expansion */ + __u8 di_pad2[4]; /* more padding for future expansion */ + __be64 di_nextents64; /* 64 bit fork extent count */And then depending on the
hasextcount_64bitbit is set, we read from disk like this:if (hasextcount_64bit) { to->di_nextents = be64_to_cpu(dip->di_nextents64); to->di_naextents = be32_to_cpu(dip->di_nextents32); if (dip->di_nextents16 != 0) return -EFSCORRUPTED; } else { to->di_nextents = be32_to_cpu(dip->di_nextents32); to->di_naextents = be16_to_cpu(dip->di_nextents16); if (dip->di_nextents64 != 0) return -EFSCORRUPTED; }and the writing to disk is equally simple. There's no bit shifting or masking, and we still end up with the same amount of unused space in the inode when
hasextcount_64bitis set becausedi_nextents16can be reused by another new feature....Quoted 13 lines
fs/xfs/libxfs/xfs_format.h +5
-4@@ -408,10 +425,17 @@ xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) {xfs_extnum_t nextents; -if (whichfork ==XFS_DATA_FORK ) - nextents =be32_to_cpu (dip->di_nextents); -else - nextents =be16_to_cpu (dip->di_anextents); +if (whichfork ==XFS_DATA_FORK ) { + nextents =be32_to_cpu (dip->di_nextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_extnum_t )be32_to_cpu (dip->di_nextents_hi) <<32 );
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) · line 438
Quoted 6 lines
fs/xfs/libxfs/xfs_format.h +6
-0+ }else { + nextents =be16_to_cpu (dip->di_anextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_aextnum_t )be16_to_cpu (dip->di_anextents_hi) <<16 ); + }... and we get rid of this bit of messy code :)
I agree. I am pretty sure that this will also make it easy to code up the corresponding changes in xfs_db.
Quoted 49 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +1
-4@@ -157,10 +157,17 @@ static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) {ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); -if (whichfork ==XFS_DATA_FORK ) -return MAXEXTNUM ; -else -return MAXAEXTNUM ; +if (whichfork ==XFS_DATA_FORK ) {fs/xfs/libxfs/xfs_format.h static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) · line 170
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +10
-0+if (xfs_sb_version_haswideextcnt (sbp)) +return MAXEXTNUM_HI ; +else +return MAXEXTNUM ; + }else { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXAEXTNUM_HI ; +else +return MAXAEXTNUM ; + }I think we should actually rework MAXEXTNUM/MAXAEXTNUM before doing this. They are defined in
xfs_types.has in-memory limits, while these are actually returning on-disk format limits which should be defined inxfs_format.he.g:
#define
XFS_IFORK_EXTCNT_MAX64....
#defineXFS_IFORK_EXTCNT_MAX32....
#defineXFS_IFORK_EXTCNT_MAX16....And in
xfs_iext_max()we do:bool has64 = xfs_sb_version_haswideextcnt() switch (whichfork) { case XFS_DATA_FORK: return has64 ? XFS_IFORK_EXTCNT_MAX64 : XFS_IFORK_EXTCNT_MAX32; case XFS_ATTR_FORK: return has64 ? XFS_IFORK_EXTCNT_MAX32 : XFS_IFORK_EXTCNT_MAX16; case XFS_COW_FORK: return XFS_IFORK_EXTCNT_MAX32; default: ASSERT(0); break; } return -EFSCORRUPTED;
Quoted 14 lines
fs/xfs/libxfs/xfs_format.h typedef void * xfs_failaddr_t; · line 65
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +4
-2@@ -59,8 +59,10 @@ typedef void * xfs_failaddr_t;* Max values for extlen, extnum, aextnum. */ #define MAXEXTLEN ((xfs_extlen_t)0x001fffff)/* 21 bits */ -#define MAXEXTNUM ((xfs_extnum_t)0x7fffffff)/* signed int */ -#define MAXAEXTNUM ((xfs_aextnum_t)0x7fff)/* signed short */ +#define MAXEXTNUM ((int32_t)0x7fffffff)/* signed int */ +#define MAXAEXTNUM ((int16_t)0x7fff)/* signed short */ +#define MAXEXTNUM_HI ((xfs_extnum_t)0x7fffffffffff)/* unsigned 47 bits */ +#define MAXAEXTNUM_HI ((xfs_aextnum_t)0xffffffff)/* unsigned 32 bits */ Yeah, these on-disk limits need to go into
xfs_format.hand not used directly anymore...
Sure. I will apply the above comments in the next version of this patchset.
Thanks a lot for your time!
Signature · 1 line
chandan
Re: [PATCH 3/3] xfs: Extend data/attr fork extent counter width
Quoted 105 lines · Chandan Babu R
Quoted 76 lines · IST Dave Chinner
Quoted 62 lines · Chandan Babu R
The commit xfs: fix inode fork extent count overflow (
3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this commit extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this commit extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 8 ++++--- fs/xfs/libxfs/xfs_format.h | 20 ++++++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 42 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.h | 17 +++++++++---- fs/xfs/libxfs/xfs_log_format.h | 8 ++++--- fs/xfs/libxfs/xfs_types.h | 10 ++++---- fs/xfs/scrub/inode.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 ++++++++-- fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++---- 11 files changed, 105 insertions(+), 40 deletions(-)fs/xfs/libxfs/xfs_bmap.c +1
-1@@ -52,9 +52,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { +xfs_extnum_t maxleafents;/* max leaf entries possible */ int level;/* btree level */ uint maxblocks;/* max blocks at this level */ -uint maxleafents;/* max leaf entries possible */ int maxrootrecs;/* max records in root block */ int minleafrecs;/* min records in leaf block */ int minnoderecs;/* min records in node block */ fs/xfs/libxfs/xfs_bmap.c xfs_bmap_compute_maxlevels( · line 69
Quoted 7 lines
fs/xfs/libxfs/xfs_bmap.c +3
-1@@ -64,7 +64,9 @@ xfs_bmap_compute_maxlevels(* The maximum number of extents in a file, hence the maximum number of * leaf entries, is controlled by the size of the on-disk extent count, * either a signed 32-bit number for the data fork, or a signed 16-bit -* number for the attr fork. +* number for the attr fork. With mkfs.xfs' wide-extcount option +* enabled, the data fork extent count is unsigned 47-bits wide, while +* the corresponding attr fork extent count is unsigned 32-bits wide. This doesn't really need to state what the sizes of the on disk fields are. If anything should state that, it's a description of the helper function that returns the maximum supported extent count. Also, it's the maximum extents in a the fork, not the _file_.
Quoted 4 lines
i.e. this should probably just read
* The maximum number of extents in a fork, hence the maximum number of
* leaf entries, is controlled by the size of the on-disk extent count.I agree. I will fix this up.
Quoted 12 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +2
-1@@ -465,10 +465,12 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT (1 << 3)/* Wider data/attr fork extent counters */ +#define XFS_SB_FEAT_INCOMPAT_ALL \Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 473
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +2
-1(XFS_SB_FEAT_INCOMPAT_FTYPE | \XFS_SB_FEAT_INCOMPAT_SPINODES | \ -XFS_SB_FEAT_INCOMPAT_META_UUID ) +XFS_SB_FEAT_INCOMPAT_META_UUID | \ +XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT )Don't we normally add the feature bit in a standalone patch once all the infrastructure has already been put in place?
Quoted 28 lines
Yes, I now realize that code changes like "defining new fields in on-disk inode structure" and "promoting
xfs_extnum_ttouint64_t" can be moved to a separate patch. I will split this patch into as many required parts before posting the next version.Quoted 23 lines
fs/xfs/libxfs/xfs_format.h static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) · line 560
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +5
-0#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool@@ -551,6 +553,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_haswideextcnt (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT ); +}I don't really like the name of the feature :/
Precendence in naming feature additions like this is "32 bit project IDs" - when we extended them from 16 to 32 bits, we didn't call them "wide project IDs" as "wide" could mean anything. What do we do if we later need to increase the size of the attribute fork extent count? :/
xfs_sb_version_hasextcount_64bit()would match thexfs_sb_version_hasprojid_32bit()naming internally....
I was about to suggest "nexts64" but my brain typo'd that into "next4" and no don't go there. ;)
Quoted 39 lines
I agree. I will fix the name here and in xfsprogs.
Quoted 19 lines
Quoted 19 lines
fs/xfs/libxfs/xfs_format.h +2
-2static inline bool xfs_sb_version_hasrmapbt (struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&@@ -873,8 +881,8 @@ typedef struct xfs_dinode {__be64 di_size;/* number of bytes in file */ __be64 di_nblocks;/* # of direct & btree blocks used */ __be32 di_extsize;/* basic/minimum extent size for file */ -__be32 di_nextents;/* number of extents in data fork */ -__be16 di_anextents;/* number of extents in attribute fork*/ +__be32 di_nextents_lo;/* lower part of data fork extent count */ +__be16 di_anextents_lo;/* lower part of attr fork extent count */ __u8 di_forkoff;/* attr fork offs, <<3 for 64b align */ __s8 di_aformat;/* format of attr fork's data */ __be32 di_dmevmask;/* DMIG event mask */ @@ -891,7 +899,9 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ Quoted 8 lines
fs/xfs/libxfs/xfs_format.h typedef struct xfs_dinode { · line 904
Quoted 4 lines
fs/xfs/libxfs/xfs_format.h +3
-1-__u8 di_pad2[12 ];/* more padding for future expansion */ +__be32 di_nextents_hi;/* higher part of data fork extent count */ +__be16 di_anextents_hi;/* higher part of attr fork extent count */ +__u8 di_pad2[6 ];/* more padding for future expansion */ I think I've mentioned this before - I don't really like extending inode variables this way. We did it for projid32 because we did not have any spare space in the v4 inode to do anything else.
Yes, You had suggested the "add new inode member" approach in one of the older versions of the patchset. But Christoph had objected to this approach
(https://www.spinics.net/lists/linux-xfs/msg40112.html). Hence I had dropped the idea. Sorry, I should have consulted with you before taking that decision.Quoted 3 lines
I would kinda prefer to do something like this:
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +4
-3- __be32 di_nextents; /* number of extents in data fork */ - __be16 di_anextents; /* number of extents in attribute fork*/ + __be32 di_nextents32; /* 32 bit fork extent count */ + __be16 di_nextents16; /* 16 bit fork extent count */ - __u8 di_pad2[12]; /* more padding for future expansion */ + __u8 di_pad2[4]; /* more padding for future expansion */ + __be64 di_nextents64; /* 64 bit fork extent count */
The comments for these fields had better document the fact that we have this shifty encoding scheme. Something like:
/* * On a extcount64 filesystem, di_nextents64 holds the data fork * extent count, di_nextents32 holds the attr fork extent count, * and di_nextents16 must be zero. * * Without that feature, di_nextents32 holds the data fork * extent count, di_nextents16 holds the attr fork extent count, * and di_nextents64 must be zero. */ __be32 di_nextents32; __be16 di_nextents16; .... __be64 di_nextents64;
I more or less agree with the rest of Dave's reply.
--D
Quoted 120 lines
Quoted 35 lines
And then depending on the
hasextcount_64bitbit is set, we read from disk like this:if (hasextcount_64bit) { to->di_nextents = be64_to_cpu(dip->di_nextents64); to->di_naextents = be32_to_cpu(dip->di_nextents32); if (dip->di_nextents16 != 0) return -EFSCORRUPTED; } else { to->di_nextents = be32_to_cpu(dip->di_nextents32); to->di_naextents = be16_to_cpu(dip->di_nextents16); if (dip->di_nextents64 != 0) return -EFSCORRUPTED; }and the writing to disk is equally simple. There's no bit shifting or masking, and we still end up with the same amount of unused space in the inode when
hasextcount_64bitis set becausedi_nextents16can be reused by another new feature....Quoted 13 lines
fs/xfs/libxfs/xfs_format.h +5
-4@@ -408,10 +425,17 @@ xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) {xfs_extnum_t nextents; -if (whichfork ==XFS_DATA_FORK ) - nextents =be32_to_cpu (dip->di_nextents); -else - nextents =be16_to_cpu (dip->di_anextents); +if (whichfork ==XFS_DATA_FORK ) { + nextents =be32_to_cpu (dip->di_nextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_extnum_t )be32_to_cpu (dip->di_nextents_hi) <<32 );Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_dfork_nextents(struct xfs_sb *sbp, struct xfs_dinode *dip, int whichfork) · line 438
Quoted 6 lines
fs/xfs/libxfs/xfs_format.h +6
-0+ }else { + nextents =be16_to_cpu (dip->di_anextents_lo); +if (xfs_sb_version_haswideextcnt (sbp)) + nextents |= + ((xfs_aextnum_t )be16_to_cpu (dip->di_anextents_hi) <<16 ); + }... and we get rid of this bit of messy code :)
I agree. I am pretty sure that this will also make it easy to code up the corresponding changes in
xfs_db.Quoted 49 lines
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +1
-4@@ -157,10 +157,17 @@ static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) {ASSERT (whichfork ==XFS_DATA_FORK || whichfork ==XFS_ATTR_FORK ); -if (whichfork ==XFS_DATA_FORK ) -return MAXEXTNUM ; -else -return MAXAEXTNUM ; +if (whichfork ==XFS_DATA_FORK ) {fs/xfs/libxfs/xfs_format.h static inline xfs_extnum_t xfs_iext_max(struct xfs_sb *sbp, int whichfork) · line 170
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +10
-0+if (xfs_sb_version_haswideextcnt (sbp)) +return MAXEXTNUM_HI ; +else +return MAXEXTNUM ; + }else { +if (xfs_sb_version_haswideextcnt (sbp)) +return MAXAEXTNUM_HI ; +else +return MAXAEXTNUM ; + }I think we should actually rework MAXEXTNUM/MAXAEXTNUM before doing this. They are defined in
xfs_types.has in-memory limits, while these are actually returning on-disk format limits which should be defined inxfs_format.he.g:
#define
XFS_IFORK_EXTCNT_MAX64....
#defineXFS_IFORK_EXTCNT_MAX32....
#defineXFS_IFORK_EXTCNT_MAX16....And in
xfs_iext_max()we do:bool has64 = xfs_sb_version_haswideextcnt() switch (whichfork) { case XFS_DATA_FORK: return has64 ? XFS_IFORK_EXTCNT_MAX64 : XFS_IFORK_EXTCNT_MAX32; case XFS_ATTR_FORK: return has64 ? XFS_IFORK_EXTCNT_MAX32 : XFS_IFORK_EXTCNT_MAX16; case XFS_COW_FORK: return XFS_IFORK_EXTCNT_MAX32; default: ASSERT(0); break; } return -EFSCORRUPTED;Quoted 14 lines
fs/xfs/libxfs/xfs_format.h typedef void * xfs_failaddr_t; · line 65
Quoted 10 lines
fs/xfs/libxfs/xfs_format.h +4
-2@@ -59,8 +59,10 @@ typedef void * xfs_failaddr_t;* Max values for extlen, extnum, aextnum. */ #define MAXEXTLEN ((xfs_extlen_t)0x001fffff)/* 21 bits */ -#define MAXEXTNUM ((xfs_extnum_t)0x7fffffff)/* signed int */ -#define MAXAEXTNUM ((xfs_aextnum_t)0x7fff)/* signed short */ +#define MAXEXTNUM ((int32_t)0x7fffffff)/* signed int */ +#define MAXAEXTNUM ((int16_t)0x7fff)/* signed short */ +#define MAXEXTNUM_HI ((xfs_extnum_t)0x7fffffffffff)/* unsigned 47 bits */ +#define MAXAEXTNUM_HI ((xfs_aextnum_t)0xffffffff)/* unsigned 32 bits */ Yeah, these on-disk limits need to go into
xfs_format.hand not used directly anymore...Sure. I will apply the above comments in the next version of this patchset.
Thanks a lot for your time!
Signature · 1 line
chandan
Re: [PATCH 3/3] xfs: Extend data/attr fork extent counter width
Quoted 189 lines · IST Darrick J. Wong
Quoted 105 lines · Chandan Babu R
Quoted 76 lines · IST Dave Chinner
Quoted 62 lines · Chandan Babu R
The commit xfs: fix inode fork extent count overflow (
3f8a4f1d876d3e3e49e50b0396eaffcc4ba71b08) mentions that 10 billion data fork extents should be possible to create. However the corresponding on-disk field has a signed 32-bit type. Hence this commit extends the per-inode data extent counter to 47 bits. The length of 47-bits was chosen because,
Maximum file size = 2^63.
Maximum extent count when using 64k block size = 2^63 / 2^16 = 2^47.Also, XFS has a per-inode xattr extent counter which is 16 bits wide. A workload which
1. Creates 1 million 255-byte sized xattrs,
2. Deletes 50% of these xattrs in an alternating manner,
3. Tries to insert 400,000 new 255-byte sized xattrs causes the xattr extent counter to overflow.Dave tells me that there are instances where a single file has more than 100 million hardlinks. With parent pointers being stored in xattrs, we will overflow the signed 16-bits wide xattr extent counter when large number of hardlinks are created. Hence this commit extends the on-disk field to 32-bits.
The following changes are made to accomplish this,
1. A new incompat superblock flag to prevent older kernels from mounting the filesystem. This flag has to be set during mkfs time.
2. Carve out a new 32-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 15 bits of the data extent counter.
3. Carve out a new 16-bit field from xfs_dinode->di_pad2[]. This field holds the most significant 16 bits of the attr extent counter.Signed-off-by Chandan Babu R <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 8 ++++--- fs/xfs/libxfs/xfs_format.h | 20 ++++++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 42 ++++++++++++++++++++++++++------- fs/xfs/libxfs/xfs_inode_buf.h | 4 ++-- fs/xfs/libxfs/xfs_inode_fork.h | 17 +++++++++---- fs/xfs/libxfs/xfs_log_format.h | 8 ++++--- fs/xfs/libxfs/xfs_types.h | 10 ++++---- fs/xfs/scrub/inode.c | 2 +- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode_item.c | 12 ++++++++-- fs/xfs/xfs_inode_item_recover.c | 20 ++++++++++++---- 11 files changed, 105 insertions(+), 40 deletions(-)fs/xfs/libxfs/xfs_bmap.c +1
-1@@ -52,9 +52,9 @@ xfs_bmap_compute_maxlevels( xfs_mount_t *mp, /* file system mount structure */ int whichfork) /* data or attr fork */ { +xfs_extnum_t maxleafents;/* max leaf entries possible */ int level;/* btree level */ uint maxblocks;/* max blocks at this level */ -uint maxleafents;/* max leaf entries possible */ int maxrootrecs;/* max records in root block */ int minleafrecs;/* min records in leaf block */ int minnoderecs;/* min records in node block */ fs/xfs/libxfs/xfs_bmap.c xfs_bmap_compute_maxlevels( · line 69
Quoted 7 lines
fs/xfs/libxfs/xfs_bmap.c +3
-1@@ -64,7 +64,9 @@ xfs_bmap_compute_maxlevels(* The maximum number of extents in a file, hence the maximum number of * leaf entries, is controlled by the size of the on-disk extent count, * either a signed 32-bit number for the data fork, or a signed 16-bit -* number for the attr fork. +* number for the attr fork. With mkfs.xfs' wide-extcount option +* enabled, the data fork extent count is unsigned 47-bits wide, while +* the corresponding attr fork extent count is unsigned 32-bits wide. This doesn't really need to state what the sizes of the on disk fields are. If anything should state that, it's a description of the helper function that returns the maximum supported extent count. Also, it's the maximum extents in a the fork, not the _file_.
Quoted 4 lines
i.e. this should probably just read
* The maximum number of extents in a fork, hence the maximum number of
* leaf entries, is controlled by the size of the on-disk extent count.I agree. I will fix this up.
Quoted 12 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +2
-1@@ -465,10 +465,12 @@ xfs_sb_has_ro_compat_feature(#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0)/* filetype in dirent */ #define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1)/* sparse inode chunks */ #define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2)/* metadata UUID */ -#define XFS_SB_FEAT_INCOMPAT_ALL \ +#define XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT (1 << 3)/* Wider data/attr fork extent counters */ +#define XFS_SB_FEAT_INCOMPAT_ALL \Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_ro_compat_feature( · line 473
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +2
-1(XFS_SB_FEAT_INCOMPAT_FTYPE | \XFS_SB_FEAT_INCOMPAT_SPINODES | \ -XFS_SB_FEAT_INCOMPAT_META_UUID ) +XFS_SB_FEAT_INCOMPAT_META_UUID | \ +XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT )Don't we normally add the feature bit in a standalone patch once all the infrastructure has already been put in place?
Quoted 28 lines
Yes, I now realize that code changes like "defining new fields in on-disk inode structure" and "promoting
xfs_extnum_ttouint64_t" can be moved to a separate patch. I will split this patch into as many required parts before posting the next version.Quoted 23 lines
fs/xfs/libxfs/xfs_format.h static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) · line 560
Quoted 12 lines
fs/xfs/libxfs/xfs_format.h +5
-0#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool@@ -551,6 +553,12 @@ static inline bool xfs_sb_version_hasmetauuid(struct xfs_sb *sbp) (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_META_UUID ); } +static inline bool xfs_sb_version_haswideextcnt (struct xfs_sb *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_WIDEEXTCNT ); +}I don't really like the name of the feature :/
Precendence in naming feature additions like this is "32 bit project IDs" - when we extended them from 16 to 32 bits, we didn't call them "wide project IDs" as "wide" could mean anything. What do we do if we later need to increase the size of the attribute fork extent count? :/
xfs_sb_version_hasextcount_64bit()would match thexfs_sb_version_hasprojid_32bit()naming internally....I was about to suggest "nexts64" but my brain typo'd that into "next4" and no don't go there. ;)
Quoted 39 lines
I agree. I will fix the name here and in xfsprogs.
Quoted 19 lines
Quoted 19 lines
fs/xfs/libxfs/xfs_format.h +2
-2static inline bool xfs_sb_version_hasrmapbt (struct xfs_sb *sbp) { return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&@@ -873,8 +881,8 @@ typedef struct xfs_dinode {__be64 di_size;/* number of bytes in file */ __be64 di_nblocks;/* # of direct & btree blocks used */ __be32 di_extsize;/* basic/minimum extent size for file */ -__be32 di_nextents;/* number of extents in data fork */ -__be16 di_anextents;/* number of extents in attribute fork*/ +__be32 di_nextents_lo;/* lower part of data fork extent count */ +__be16 di_anextents_lo;/* lower part of attr fork extent count */ __u8 di_forkoff;/* attr fork offs, <<3 for 64b align */ __s8 di_aformat;/* format of attr fork's data */ __be32 di_dmevmask;/* DMIG event mask */ @@ -891,7 +899,9 @@ typedef struct xfs_dinode {__be64 di_lsn;/* flush sequence */ __be64 di_flags2;/* more random flags */ __be32 di_cowextsize;/* basic cow extent size for file */ Quoted 8 lines
fs/xfs/libxfs/xfs_format.h typedef struct xfs_dinode { · line 904
Quoted 4 lines
fs/xfs/libxfs/xfs_format.h +3
-1-__u8 di_pad2[12 ];/* more padding for future expansion */ +__be32 di_nextents_hi;/* higher part of data fork extent count */ +__be16 di_anextents_hi;/* higher part of attr fork extent count */ +__u8 di_pad2[6 ];/* more padding for future expansion */ I think I've mentioned this before - I don't really like extending inode variables this way. We did it for projid32 because we did not have any spare space in the v4 inode to do anything else.
Yes, You had suggested the "add new inode member" approach in one of the older versions of the patchset. But Christoph had objected to this approach
(https://www.spinics.net/lists/linux-xfs/msg40112.html). Hence I had dropped the idea. Sorry, I should have consulted with you before taking that decision.Quoted 3 lines
I would kinda prefer to do something like this:
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +4
-3- __be32 di_nextents; /* number of extents in data fork */ - __be16 di_anextents; /* number of extents in attribute fork*/ + __be32 di_nextents32; /* 32 bit fork extent count */ + __be16 di_nextents16; /* 16 bit fork extent count */ - __u8 di_pad2[12]; /* more padding for future expansion */ + __u8 di_pad2[4]; /* more padding for future expansion */ + __be64 di_nextents64; /* 64 bit fork extent count */The comments for these fields had better document the fact that we have this shifty encoding scheme. Something like:
Quoted 14 lines
/* * On a extcount64 filesystem, di_nextents64 holds the data fork * extent count, di_nextents32 holds the attr fork extent count, * and di_nextents16 must be zero. * * Without that feature, di_nextents32 holds the data fork * extent count, di_nextents16 holds the attr fork extent count, * and di_nextents64 must be zero. */ __be32 di_nextents32; __be16 di_nextents16; .... __be64 di_nextents64;
Ok. I will add the relevant descriptions.
Signature · 1 line
chandan