more extent mapping cleanups
Hi all,
This series contains another round of extent map related cleanups to prepare for the new incore extent list.
Because it is based on a huge number of outstanding (and reviewed) patches it might be a good idea to pull in the git tree for testing or detailed review:
git://git.infradead.org/users/hch/xfs.git xfs-bmbt-cleanup.2
Gitweb:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-bmbt-cleanup.2
PATCH 1/15 xfs: add a xfs_bmap_fork_to_state helper
This creates the right initial bmap state from the passed in inode fork enum.
--- fs/xfs/libxfs/xfs_bmap.c | 45 +++++++++------------------------------------ fs/xfs/libxfs/xfs_bmap.h | 12 ++++++++++++ 2 files changed, 21 insertions(+), 36 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +9 -36
@@ -499,12 +499,7 @@ xfs_bmap_trace_exlist( {xfs_extnum_t idx;/* extent record index */ xfs_ifork_t *ifp;/* inode fork pointer */ -int state =0 ; - -if (whichfork ==XFS_ATTR_FORK ) - state |=BMAP_ATTRFORK ; -else if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; +int state =xfs_bmap_fork_to_state (whichfork); ifp =XFS_IFORK_PTR (ip, whichfork);ASSERT (cnt ==xfs_iext_count (ifp));
@@ -925,8 +920,7 @@ xfs_bmap_local_to_extents( rec.br_state =XFS_EXT_NORM ;xfs_iext_insert (ip,0 ,1 , &rec,0 ); -trace_xfs_bmap_post_update (ip,0 , - whichfork ==XFS_ATTR_FORK ?BMAP_ATTRFORK :0 , +trace_xfs_bmap_post_update (ip,0 ,xfs_bmap_fork_to_state (whichfork), _THIS_IP_);XFS_IFORK_NEXT_SET (ip, whichfork,1 ); ip->i_d.di_nblocks =1 ;
@@ -1571,7 +1565,7 @@ xfs_bmap_add_extent_delay_real(xfs_bmbt_irec_t r[3 ];/* neighbor extent entries */ /* left is 0, right is 1, prev is 2 */ int rval=0 ;/* return value (logging flags) */ -int state =0 ;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);xfs_filblks_t da_new;/* new count del alloc blocks used */ xfs_filblks_t da_old;/* old count del alloc blocks used */ xfs_filblks_t temp=0 ;/* value for da_new calculations */
@@ -1598,9 +1592,6 @@ xfs_bmap_add_extent_delay_real(#define RIGHT r[1]#define PREV r[2] -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; -/* * Set up a bunch of variables to make the tests simpler. */
@@ -2108,7 +2099,7 @@ xfs_bmap_add_extent_unwritten_real(xfs_bmbt_irec_t r[3 ];/* neighbor extent entries */ /* left is 0, right is 1, prev is 2 */ int rval=0 ;/* return value (logging flags) */ -int state =0 ;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);struct xfs_mount *mp = ip->i_mount;struct xfs_bmbt_irec old;
@@ -2116,8 +2107,6 @@ xfs_bmap_add_extent_unwritten_real( cur = *curp; ifp =XFS_IFORK_PTR (ip, whichfork); -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ;ASSERT (*idx >=0 );ASSERT (*idx <=xfs_iext_count (ifp));
@@ -2601,13 +2590,10 @@ xfs_bmap_add_extent_hole_delay(xfs_filblks_t newlen=0 ;/* new indirect size */ xfs_filblks_t oldlen=0 ;/* old indirect size */ xfs_bmbt_irec_t right;/* right neighbor extent entry */ -int state;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);xfs_filblks_t temp;/* temp for indirect calculations */ ifp =XFS_IFORK_PTR (ip, whichfork); - state =0 ; -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ;ASSERT (isnullstartblock (new->br_startblock));/*
@@ -2760,7 +2746,7 @@ xfs_bmap_add_extent_hole_real(xfs_bmbt_irec_t left;/* left neighbor extent entry */ xfs_bmbt_irec_t right;/* right neighbor extent entry */ int rval=0 ;/* return value (logging flags) */ -int state;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);struct xfs_bmbt_irec old;ASSERT (*idx >=0 );
@@ -2770,12 +2756,6 @@ xfs_bmap_add_extent_hole_real(XFS_STATS_INC (mp, xs_add_exlist); - state =0 ; -if (whichfork ==XFS_ATTR_FORK ) - state |=BMAP_ATTRFORK ; -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; -/* * Check and set flags if this segment has a left neighbor. */
@@ -4737,7 +4717,8 @@ xfs_bmap_del_extent_delay(int64_t da_old, da_new, da_diff =0 ;xfs_fileoff_t del_endoff, got_endoff;xfs_filblks_t got_indlen, new_indlen, stolen; -int error =0 , state =0 ; +int state =xfs_bmap_fork_to_state (whichfork); +int error =0 ;bool isrt;XFS_STATS_INC (mp, xs_del_exlist);
@@ -4773,9 +4754,6 @@ xfs_bmap_del_extent_delay(return error; ip->i_delayed_blks -= del->br_blockcount; -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; -if (got->br_startoff == del->br_startoff) state |=BMAP_LEFT_FILLING ;if (got_endoff == del_endoff)
@@ -4969,17 +4947,12 @@ xfs_bmap_del_extent_real(xfs_bmbt_irec_t new;/* new record to be inserted */ /* REFERENCED */ uint qfield;/* quota field to update */ -int state =0 ; +int state =xfs_bmap_fork_to_state (whichfork);struct xfs_bmbt_irec old; mp = ip->i_mount;XFS_STATS_INC (mp, xs_del_exlist); -if (whichfork ==XFS_ATTR_FORK ) - state |=BMAP_ATTRFORK ; -else if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; - ifp =XFS_IFORK_PTR (ip, whichfork);ASSERT ((*idx >=0 ) && (*idx <xfs_iext_count (ifp)));ASSERT (del->br_blockcount >0 );
fs/xfs/libxfs/xfs_bmap.h +12 -0
@@ -277,4 +277,16 @@ int xfs_bmap_map_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,int xfs_bmap_unmap_extent (struct xfs_mount *mp,struct xfs_defer_ops *dfops,struct xfs_inode *ip,struct xfs_bmbt_irec *imap); +static inline int xfs_bmap_fork_to_state (int whichfork) +{ +switch (whichfork) { +case XFS_ATTR_FORK : +return BMAP_ATTRFORK ; +case XFS_COW_FORK : +return BMAP_COWFORK ; +default : +return 0 ; + } +} +#endif /* __XFS_BMAP_H__ */
Signature · 1 line
2.14.1
PATCH 2/15 xfs: make better use of the 'state' variable in xfs_bmap_del_extent_real
In reply to Christoph HellwigWe already have all the information about the fork aѕ well as additional tracing information, so pass that to xfs_iext_remove().
--- fs/xfs/libxfs/xfs_bmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +1 -2
@@ -5022,8 +5022,7 @@ xfs_bmap_del_extent_real(* Matches the whole extent. Delete the entry. */ trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_iext_remove (ip, *idx,1 , - whichfork ==XFS_ATTR_FORK ?BMAP_ATTRFORK :0 ); +xfs_iext_remove (ip, *idx,1 , state); --*idx; XFS_IFORK_NEXT_SET(ip, whichfork,
Signature · 1 line
2.14.1
PATCH 3/15 xfs: remove post-bmap tracing in xfs_bmap_local_to_extents
In reply to Christoph HellwigNow that we use xfs_iext_insert this is already covered by the tracing in that function.
--- fs/xfs/libxfs/xfs_bmap.c | 2 -- 1 file changed, 2 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +0 -2
@@ -920,8 +920,6 @@ xfs_bmap_local_to_extents( rec.br_state =XFS_EXT_NORM ;xfs_iext_insert (ip,0 ,1 , &rec,0 ); -trace_xfs_bmap_post_update (ip,0 ,xfs_bmap_fork_to_state (whichfork), - _THIS_IP_);XFS_IFORK_NEXT_SET (ip, whichfork,1 ); ip->i_d.di_nblocks =1 ; xfs_trans_mod_dquot_byino(tp, ip,
Signature · 1 line
2.14.1
PATCH 4/15 xfs: move pre/post-bmap tracing into xfs_iext_update_extent
In reply to Christoph Hellwigxfs_iext_update_extent already has basically all the information needed to centralize the bmap pre/post tracing. We just need to pass inode + bmap state instead of the inode fork pointer to get all trace annotations.
In addition to covering all the existing trace points this gives us tracing coverage for the extent shifting operations for free.
--- fs/xfs/libxfs/xfs_bmap.c | 167 ++++++++++++----------------------------- fs/xfs/libxfs/xfs_inode_fork.c | 7 +- fs/xfs/libxfs/xfs_inode_fork.h | 4 +- 3 files changed, 55 insertions(+), 123 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +47 -120
@@ -1669,10 +1669,8 @@ xfs_bmap_add_extent_delay_real(* The left and right neighbors are both contiguous with new. */ bma->idx--; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount +RIGHT .br_blockcount; -xfs_iext_update_extent (ifp, bma->idx, &LEFT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &LEFT );xfs_iext_remove (bma->ip, bma->idx +1 ,2 , state); (*nextents)--;
@@ -1706,10 +1704,8 @@ xfs_bmap_add_extent_delay_real( bma->idx--; old =LEFT ; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount; -xfs_iext_update_extent (ifp, bma->idx, &LEFT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &LEFT );xfs_iext_remove (bma->ip, bma->idx +1 ,1 , state);if (bma->cur ==NULL )
@@ -1731,11 +1727,9 @@ xfs_bmap_add_extent_delay_real(* Filling in all of a previously delayed allocation extent. * The right neighbor is contiguous, the left is not. */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_startblock = new->br_startblock;PREV .br_blockcount +=RIGHT .br_blockcount; -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV );xfs_iext_remove (bma->ip, bma->idx +1 ,1 , state);if (bma->cur ==NULL )
@@ -1758,11 +1752,9 @@ xfs_bmap_add_extent_delay_real(* Neither the left nor right neighbors are contiguous with * the new one. */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_startblock = new->br_startblock;PREV .br_state = new->br_state; -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV ); (*nextents)++;if (bma->cur ==NULL )
@@ -1790,17 +1782,13 @@ xfs_bmap_add_extent_delay_real( da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp),startblockval (PREV .br_startblock)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx -1 , state, _THIS_IP_);LEFT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, bma->idx -1 , &LEFT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx -1 , state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx -1 , &LEFT ); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_blockcount = temp =PREV .br_blockcount - new->br_blockcount;PREV .br_startoff += new->br_blockcount;PREV .br_startblock =nullstartblock (da_new); -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV );if (bma->cur ==NULL ) rval =XFS_ILOG_DEXT ;
@@ -1853,13 +1841,10 @@ xfs_bmap_add_extent_delay_real(startblockval (PREV .br_startblock) - (bma->cur ? bma->cur->bc_private.b.allocated : 0)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx +1 , state, _THIS_IP_);PREV .br_startoff = new_endoff;PREV .br_blockcount = temp;PREV .br_startblock =nullstartblock (da_new); -xfs_iext_update_extent (ifp, bma->idx +1 , &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx +1 , state, _THIS_IP_); - +xfs_iext_update_extent (bma->ip, state, bma->idx +1 , &PREV );break ;case BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG :
@@ -1868,12 +1853,10 @@ xfs_bmap_add_extent_delay_real(* The right neighbor is contiguous with the new allocation. */ old =RIGHT ; -trace_xfs_bmap_pre_update (bma->ip, bma->idx +1 , state, _THIS_IP_);RIGHT .br_startoff = new->br_startoff;RIGHT .br_startblock = new->br_startblock;RIGHT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, bma->idx +1 , &RIGHT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx +1 , state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx +1 , &RIGHT );if (bma->cur ==NULL ) rval =XFS_ILOG_DEXT ;
@@ -1892,11 +1875,9 @@ xfs_bmap_add_extent_delay_real( da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp),startblockval (PREV .br_startblock)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_blockcount = temp;PREV .br_startblock =nullstartblock (da_new); -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV ); bma->idx++;break ;
@@ -1936,11 +1917,9 @@ xfs_bmap_add_extent_delay_real(startblockval (PREV .br_startblock) - (bma->cur ? bma->cur->bc_private.b.allocated : 0)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_startblock =nullstartblock (da_new);PREV .br_blockcount = temp; -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV ); bma->idx++;break ;
@@ -1981,13 +1960,11 @@ xfs_bmap_add_extent_delay_real( RIGHT.br_blockcount));/* truncate PREV */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx,0 , _THIS_IP_);PREV .br_blockcount = new->br_startoff -PREV .br_startoff;PREV .br_startblock =nullstartblock (xfs_bmap_worst_indlen (bma->ip,PREV .br_blockcount)); -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV );/* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */ xfs_iext_insert (bma->ip, bma->idx +1 ,2 , &LEFT , state);
@@ -2192,10 +2169,8 @@ xfs_bmap_add_extent_unwritten_real(*/ --*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount +RIGHT .br_blockcount; -xfs_iext_update_extent (ifp, *idx, &LEFT ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &LEFT );xfs_iext_remove (ip, *idx +1 ,2 , state); XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -2233,10 +2208,8 @@ xfs_bmap_add_extent_unwritten_real(*/ --*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount; -xfs_iext_update_extent (ifp, *idx, &LEFT ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &LEFT );xfs_iext_remove (ip, *idx +1 ,1 , state); XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -2266,11 +2239,9 @@ xfs_bmap_add_extent_unwritten_real(* Setting all of a previous oldext extent to newext. * The right neighbor is contiguous, the left is not. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount +=RIGHT .br_blockcount;PREV .br_state = new->br_state; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV );xfs_iext_remove (ip, *idx +1 ,1 , state); XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -2301,10 +2272,8 @@ xfs_bmap_add_extent_unwritten_real(* Neither the left nor right neighbors are contiguous with * the new one. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_state = new->br_state; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV );if (cur ==NULL ) rval =XFS_ILOG_DEXT ;
@@ -2325,18 +2294,14 @@ xfs_bmap_add_extent_unwritten_real(* Setting the first part of a previous oldext extent to newext. * The left neighbor is contiguous. */ -trace_xfs_bmap_pre_update (ip, *idx -1 , state, _THIS_IP_);LEFT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx -1 , &LEFT ); -trace_xfs_bmap_post_update (ip, *idx -1 , state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx -1 , &LEFT ); old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_startoff += new->br_blockcount;PREV .br_startblock += new->br_blockcount;PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); --*idx;
@@ -2366,12 +2331,10 @@ xfs_bmap_add_extent_unwritten_real(* The left neighbor is not contiguous. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_startoff += new->br_blockcount;PREV .br_startblock += new->br_blockcount;PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV );xfs_iext_insert (ip, *idx,1 , new, state); XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -2400,19 +2363,15 @@ xfs_bmap_add_extent_unwritten_real(* The right neighbor is contiguous with the new allocation. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); ++*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);RIGHT .br_startoff = new->br_startoff;RIGHT .br_startblock = new->br_startblock;RIGHT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &RIGHT ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &RIGHT );if (cur ==NULL ) rval =XFS_ILOG_DEXT ;
@@ -2440,10 +2399,8 @@ xfs_bmap_add_extent_unwritten_real(* The right neighbor is not contiguous. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); ++*idx;xfs_iext_insert (ip, *idx,1 , new, state);
@@ -2478,10 +2435,8 @@ xfs_bmap_add_extent_unwritten_real(* One extent becomes three extents. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount = new->br_startoff -PREV .br_startoff; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); r[0 ] = *new; r[1 ].br_startoff = new_endoff;
@@ -2648,7 +2603,6 @@ xfs_bmap_add_extent_hole_delay( temp = left.br_blockcount + new->br_blockcount + right.br_blockcount; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); oldlen =startblockval (left.br_startblock) +startblockval (new->br_startblock) +startblockval (right.br_startblock);
@@ -2656,8 +2610,7 @@ xfs_bmap_add_extent_hole_delay( oldlen); left.br_startblock =nullstartblock (newlen); left.br_blockcount = temp; -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);xfs_iext_remove (ip, *idx +1 ,1 , state);break ;
@@ -2671,15 +2624,13 @@ xfs_bmap_add_extent_hole_delay( --*idx; temp = left.br_blockcount + new->br_blockcount; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); oldlen =startblockval (left.br_startblock) +startblockval (new->br_startblock); newlen =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (ip, temp), oldlen); left.br_blockcount = temp; left.br_startblock =nullstartblock (newlen); -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);break ;case BMAP_RIGHT_CONTIG :
@@ -2688,7 +2639,6 @@ xfs_bmap_add_extent_hole_delay(* on the right. * Merge the new allocation with the right neighbor. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); temp = new->br_blockcount + right.br_blockcount; oldlen =startblockval (new->br_startblock) +startblockval (right.br_startblock);
@@ -2697,8 +2647,7 @@ xfs_bmap_add_extent_hole_delay( right.br_startoff = new->br_startoff; right.br_startblock =nullstartblock (newlen); right.br_blockcount = temp; -xfs_iext_update_extent (ifp, *idx, &right); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &right);break ;case 0 :
@@ -2808,10 +2757,8 @@ xfs_bmap_add_extent_hole_real(* Merge all three into a single extent record. */ --*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); left.br_blockcount += new->br_blockcount + right.br_blockcount; -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);xfs_iext_remove (ip, *idx +1 ,1 , state);
@@ -2847,10 +2794,9 @@ xfs_bmap_add_extent_hole_real(*/ --*idx; old = left; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); + left.br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);if (cur ==NULL ) { rval =xfs_ilog_fext (whichfork);
@@ -2873,12 +2819,11 @@ xfs_bmap_add_extent_hole_real(* Merge the new allocation with the right neighbor. */ old = right; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); + right.br_startoff = new->br_startoff; right.br_startblock = new->br_startblock; right.br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &right); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &right);if (cur ==NULL ) { rval =xfs_ilog_fext (whichfork);
@@ -4769,26 +4714,22 @@ xfs_bmap_del_extent_delay(/* * Deleting the first part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_startoff = del_endoff; got->br_blockcount -= del->br_blockcount; da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (ip, got->br_blockcount), da_old); got->br_startblock =nullstartblock ((int )da_new); -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case BMAP_RIGHT_FILLING :/* * Deleting the last part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_blockcount = got->br_blockcount - del->br_blockcount; da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (ip, got->br_blockcount), da_old); got->br_startblock =nullstartblock ((int )da_new); -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case 0 :/*
@@ -4800,8 +4741,6 @@ xfs_bmap_del_extent_delay(* Warn if either of the new indlen reservations is zero as this * can lead to delalloc problems. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); - got->br_blockcount = del->br_startoff - got->br_startoff; got_indlen =xfs_bmap_worst_indlen (ip, got->br_blockcount);
@@ -4813,8 +4752,7 @@ xfs_bmap_del_extent_delay( del->br_blockcount); got->br_startblock =nullstartblock ((int )got_indlen); -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx,0 , _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got); new.br_startoff = del_endoff; new.br_state = got->br_state;
@@ -4879,30 +4817,24 @@ xfs_bmap_del_extent_cow(/* * Deleting the first part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_startoff = del_endoff; got->br_blockcount -= del->br_blockcount; got->br_startblock = del->br_startblock + del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case BMAP_RIGHT_FILLING :/* * Deleting the last part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_blockcount -= del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case 0 :/* * Deleting the middle of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_blockcount = del->br_startoff - got->br_startoff; -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got); new.br_startoff = del_endoff; new.br_blockcount = got_endoff - del_endoff;
@@ -5019,7 +4951,6 @@ xfs_bmap_del_extent_real(/* * Matches the whole extent. Delete the entry. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);xfs_iext_remove (ip, *idx,1 , state); --*idx;
@@ -5038,12 +4969,10 @@ xfs_bmap_del_extent_real(/* * Deleting the first part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got.br_startoff = del_endoff; got.br_startblock = del_endblock; got.br_blockcount -= del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &got);if (!cur) { flags |=xfs_ilog_fext (whichfork);break ;
@@ -5056,10 +4985,8 @@ xfs_bmap_del_extent_real(/* * Deleting the last part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got.br_blockcount -= del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &got);if (!cur) { flags |=xfs_ilog_fext (whichfork);break ;
@@ -5072,11 +4999,10 @@ xfs_bmap_del_extent_real(/* * Deleting the middle of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); - old = got; + got.br_blockcount = del->br_startoff - got.br_startoff; -xfs_iext_update_extent (ifp, *idx, &got); +xfs_iext_update_extent (ip, state, *idx, &got); new.br_startoff = del_endoff; new.br_blockcount = got_endoff - del_endoff;
@@ -5120,7 +5046,7 @@ xfs_bmap_del_extent_real(* Reset the extent record back * to the original value. */ -xfs_iext_update_extent (ifp, *idx, &old); +xfs_iext_update_extent (ip, state, *idx, &old); flags =0 ; error = -ENOSPC ; goto done;
@@ -5130,7 +5056,6 @@ xfs_bmap_del_extent_real( flags |=xfs_ilog_fext (whichfork);XFS_IFORK_NEXT_SET (ip, whichfork,XFS_IFORK_NEXTENTS (ip, whichfork) +1 ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_);xfs_iext_insert (ip, *idx +1 ,1 , &new, state); ++*idx;break ;
@@ -5605,7 +5530,6 @@ xfs_bmse_merge(int *logflags,/* output */ struct xfs_defer_ops *dfops) { - struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); struct xfs_bmbt_irec new;xfs_filblks_t blockcount;int error, i;
@@ -5654,7 +5578,8 @@ xfs_bmse_merge(return error; done: -xfs_iext_update_extent (ifp, current_ext -1 , &new); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), + current_ext -1 , &new);xfs_iext_remove (ip, current_ext,1 ,0 );/* update reverse mapping. rmap functions merge the rmaps for us */
@@ -5772,7 +5697,8 @@ xfs_bmse_shift_one( *logflags |=XFS_ILOG_DEXT ; } -xfs_iext_update_extent (ifp, *current_ext, &new); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), + *current_ext, &new);if (direction ==SHIFT_LEFT ) (*current_ext)++;
@@ -6019,7 +5945,8 @@ xfs_bmap_split_extent_at( } got.br_blockcount = gotblkcnt; -xfs_iext_update_extent (ifp, current_ext, &got); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), + current_ext, &got); logflags =XFS_ILOG_CORE ;if (cur) {
fs/xfs/libxfs/xfs_inode_fork.c +6 -1
@@ -2023,12 +2023,17 @@ xfs_iext_get_extent(void xfs_iext_update_extent ( -struct xfs_ifork *ifp, +struct xfs_inode *ip, +int state,xfs_extnum_t idx,struct xfs_bmbt_irec *gotp) { +struct xfs_ifork *ifp =xfs_iext_state_to_fork (ip, state); +ASSERT (idx >=0 );ASSERT (idx <xfs_iext_count (ifp)); +trace_xfs_bmap_pre_update (ip, idx, state, _RET_IP_);xfs_bmbt_set_all (xfs_iext_get_ext (ifp, idx), gotp); +trace_xfs_bmap_post_update (ip, idx, state, _RET_IP_); }
fs/xfs/libxfs/xfs_inode_fork.h +2 -2
@@ -187,8 +187,8 @@ bool xfs_iext_lookup_extent(struct xfs_inode *ip, xfs_extnum_t *idxp, struct xfs_bmbt_irec *gotp);bool xfs_iext_get_extent (struct xfs_ifork *ifp,xfs_extnum_t idx,struct xfs_bmbt_irec *gotp); -void xfs_iext_update_extent (struct xfs_ifork *ifp,xfs_extnum_t idx, -struct xfs_bmbt_irec *gotp); +void xfs_iext_update_extent (struct xfs_inode *ip,int state, +xfs_extnum_t idx,struct xfs_bmbt_irec *gotp);extern struct kmem_zone *xfs_ifork_zone;
Signature · 1 line
2.14.1
PATCH 5/15 xfs: remove XFS_BMAP_TRACE_EXLIST
In reply to Christoph HellwigInstead of looping over all extents in some debug-only helper just insert trace points into the loops that already exist in the calling functions.
Also split the xfs_extlist trace point into one each for reading and writing extents from disk.
--- fs/xfs/libxfs/xfs_bmap.c | 23 ++--------------------- fs/xfs/libxfs/xfs_bmap.h | 9 --------- fs/xfs/libxfs/xfs_inode_fork.c | 8 ++++++-- fs/xfs/xfs_trace.h | 3 ++- 4 files changed, 10 insertions(+), 33 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +2 -21
@@ -487,26 +487,6 @@ xfs_bmap_check_leaf_extents(return ; } -/* -* Add bmap trace insert entries for all the contents of the extent records. -*/ -void -xfs_bmap_trace_exlist ( -xfs_inode_t *ip,/* incore inode pointer */ -xfs_extnum_t cnt,/* count of entries in the list */ -int whichfork,/* data or attr or cow fork */ -unsigned long caller_ip) -{ -xfs_extnum_t idx;/* extent record index */ -xfs_ifork_t *ifp;/* inode fork pointer */ -int state =xfs_bmap_fork_to_state (whichfork); - - ifp =XFS_IFORK_PTR (ip, whichfork); -ASSERT (cnt ==xfs_iext_count (ifp)); -for (idx =0 ; idx < cnt; idx++) -trace_xfs_extlist (ip, idx, state, caller_ip); -} -/* * Validate that the bmbt_irecs being returned from bmapi are valid * given the caller's original parameters. Specifically check the
@@ -1210,6 +1190,7 @@ xfs_bmap_read_extents(__be64 *pp;/* pointer to block address */ /* REFERENCED */ xfs_extnum_t room;/* number of entries there's room for */ +int state =xfs_bmap_fork_to_state (whichfork); mp = ip->i_mount; ifp =XFS_IFORK_PTR (ip, whichfork);
@@ -1283,6 +1264,7 @@ xfs_bmap_read_extents( XFS_ERRLEVEL_LOW, mp); goto error0; } +trace_xfs_read_extent (ip, i, state, _THIS_IP_); }xfs_trans_brelse (tp, bp); bno = nextbno;
@@ -1300,7 +1282,6 @@ xfs_bmap_read_extents(if (i !=XFS_IFORK_NEXTENTS (ip, whichfork))return -EFSCORRUPTED ;ASSERT (i ==xfs_iext_count (ifp)); -XFS_BMAP_TRACE_EXLIST (ip, i, whichfork);return 0 ; error0:xfs_trans_brelse (tp, bp);
fs/xfs/libxfs/xfs_bmap.h +0 -9
@@ -197,15 +197,6 @@ enum shift_direction { SHIFT_RIGHT, }; -#ifdef DEBUG -void xfs_bmap_trace_exlist (struct xfs_inode *ip,xfs_extnum_t cnt, -int whichfork,unsigned long caller_ip); -#define XFS_BMAP_TRACE_EXLIST (ip,c,w) \ - xfs_bmap_trace_exlist(ip,c,w, _THIS_IP_) -#else -#define XFS_BMAP_TRACE_EXLIST (ip,c,w) -#endif -void xfs_trim_extent (struct xfs_bmbt_irec *irec,xfs_fileoff_t bno,xfs_filblks_t len);int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd);
fs/xfs/libxfs/xfs_inode_fork.c +6 -2
@@ -336,6 +336,7 @@ xfs_iformat_extents( {struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, 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_bmbt_rec *dp;
@@ -373,8 +374,8 @@ xfs_iformat_extents( XFS_ERRLEVEL_LOW, mp);return -EFSCORRUPTED ; } +trace_xfs_read_extent (ip, i, state, _THIS_IP_); } -XFS_BMAP_TRACE_EXLIST (ip, nex, whichfork); } ifp->if_flags |=XFS_IFEXTENTS ;return 0 ;
@@ -772,6 +773,7 @@ xfs_iextents_copy(xfs_bmbt_rec_t *dp, int whichfork) { + int state = xfs_bmap_fork_to_state(whichfork);int copied;int i;xfs_ifork_t *ifp;
@@ -783,7 +785,6 @@ xfs_iextents_copy(ASSERT (ifp->if_bytes >0 ); nrecs =xfs_iext_count (ifp); -XFS_BMAP_TRACE_EXLIST (ip, nrecs, whichfork);ASSERT (nrecs >0 );/*
@@ -806,9 +807,12 @@ xfs_iextents_copy(continue ; } +trace_xfs_write_extent (ip, i, state, _RET_IP_); +/* Translate to on disk format */ put_unaligned_be64 (ep->l0, &dp->l0);put_unaligned_be64 (ep->l1, &dp->l1); + dp++; copied++; }
fs/xfs/xfs_trace.h +2 -1
@@ -309,7 +309,8 @@ DEFINE_EVENT(xfs_bmap_class, name, \DEFINE_BMAP_EVENT (xfs_iext_remove);DEFINE_BMAP_EVENT (xfs_bmap_pre_update);DEFINE_BMAP_EVENT (xfs_bmap_post_update); -DEFINE_BMAP_EVENT (xfs_extlist); +DEFINE_BMAP_EVENT (xfs_read_extent); +DEFINE_BMAP_EVENT (xfs_write_extent); DECLARE_EVENT_CLASS(xfs_buf_class, TP_PROTO(struct xfs_buf *bp, unsigned long caller_ip),
Signature · 1 line
2.14.1
PATCH 6/15 xfs: remove the never fully implemented UUID fork format
In reply to Christoph HellwigRemove the dead code dealing with the UUID fork format that was never implemented in Linux (and neither in IRIX as far as I know).
--- fs/xfs/libxfs/xfs_attr_leaf.c | 6 +----- fs/xfs/libxfs/xfs_bmap.c | 4 ---- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/libxfs/xfs_inode_fork.c | 9 --------- fs/xfs/libxfs/xfs_inode_fork.h | 1 - fs/xfs/libxfs/xfs_log_format.h | 20 ++++++++++---------- fs/xfs/xfs_inode_item.c | 25 ++++++------------------- fs/xfs/xfs_itable.c | 1 - fs/xfs/xfs_log_recover.c | 10 +--------- 9 files changed, 19 insertions(+), 59 deletions(-)
fs/xfs/libxfs/xfs_attr_leaf.c +1 -5
@@ -397,13 +397,9 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)/* rounded down */ offset = (XFS_LITINO (mp, dp->i_d.di_version) - bytes) >>3 ; -switch (dp->i_d.di_format) { -case XFS_DINODE_FMT_DEV : +if (dp->i_d.di_format ==XFS_DINODE_FMT_DEV ) { minforkoff =roundup (sizeof (xfs_dev_t),8 ) >>3 ;return (offset >= minforkoff) ? minforkoff :0 ; -case XFS_DINODE_FMT_UUID : - minforkoff =roundup (sizeof (uuid_t),8 ) >>3 ; -return (offset >= minforkoff) ? minforkoff :0 ; }/*
fs/xfs/libxfs/xfs_bmap.c +0 -4
@@ -231,7 +231,6 @@ xfs_bmap_forkoff_reset( {if (whichfork ==XFS_ATTR_FORK && ip->i_d.di_format !=XFS_DINODE_FMT_DEV && - ip->i_d.di_format !=XFS_DINODE_FMT_UUID && ip->i_d.di_format !=XFS_DINODE_FMT_BTREE ) {uint dfl_forkoff =xfs_default_attroffset (ip) >>3 ;
@@ -1086,9 +1085,6 @@ xfs_bmap_add_attrfork(case XFS_DINODE_FMT_DEV : ip->i_d.di_forkoff =roundup (sizeof (xfs_dev_t),8 ) >>3 ;break ; -case XFS_DINODE_FMT_UUID : - ip->i_d.di_forkoff =roundup (sizeof (uuid_t),8 ) >>3 ; -break ;case XFS_DINODE_FMT_LOCAL :case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :
fs/xfs/libxfs/xfs_format.h +1 -1
@@ -941,7 +941,7 @@ typedef enum xfs_dinode_fmt {XFS_DINODE_FMT_LOCAL ,/* bulk data */ XFS_DINODE_FMT_EXTENTS ,/* struct xfs_bmbt_rec */ XFS_DINODE_FMT_BTREE ,/* struct xfs_bmdr_block */ - XFS_DINODE_FMT_UUID /* uuid_t */ + XFS_DINODE_FMT_UUID /* added long ago, but never used */ } xfs_dinode_fmt_t;/*
fs/xfs/libxfs/xfs_inode_fork.c +0 -9
@@ -902,15 +902,6 @@ xfs_iflush_fork( }break ; -case XFS_DINODE_FMT_UUID : -if (iip->ili_fields &XFS_ILOG_UUID ) { -ASSERT (whichfork ==XFS_DATA_FORK ); -memcpy (XFS_DFORK_DPTR (dip), - &ip->i_df.if_u2.if_uuid, -sizeof (uuid_t)); - } -break ; -default :ASSERT (0 );break ;
fs/xfs/libxfs/xfs_inode_fork.h +0 -1
@@ -70,7 +70,6 @@ typedef struct xfs_ifork {char if_inline_data[XFS_INLINE_DATA ];/* very small file data */ xfs_dev_t if_rdev;/* dev number if special */ -uuid_t if_uuid;/* mount point value */ } if_u2; } xfs_ifork_t;
fs/xfs/libxfs/xfs_log_format.h +10 -10
@@ -274,7 +274,7 @@ typedef struct xfs_inode_log_format {uint64_t ilf_ino;/* inode number */ union {uint32_t ilfu_rdev;/* rdev value for dev inode*/ -uuid_t ilfu_uuid;/* mount point value */ +u8 __pad[16 ];/* unused */ } ilf_u;int64_t ilf_blkno;/* blkno of inode buffer */ int32_t ilf_len;/* len of inode buffer */
@@ -295,7 +295,7 @@ struct xfs_inode_log_format_32 {uint64_t ilf_ino;/* inode number */ union {uint32_t ilfu_rdev;/* rdev value for dev inode*/ -uuid_t ilfu_uuid;/* mount point value */ +u8 __pad[16 ];/* unused */ } ilf_u;int64_t ilf_blkno;/* blkno of inode buffer */ int32_t ilf_len;/* len of inode buffer */
@@ -311,7 +311,7 @@ struct xfs_inode_log_format_32 {#define XFS_ILOG_DEXT 0x004/* log i_df.if_extents */ #define XFS_ILOG_DBROOT 0x008/* log i_df.i_broot */ #define XFS_ILOG_DEV 0x010/* log the dev field */ -#define XFS_ILOG_UUID 0x020/* log the uuid field */ +#define XFS_ILOG_UUID 0x020/* added long ago, but never used */ #define XFS_ILOG_ADATA 0x040/* log i_af.if_data */ #define XFS_ILOG_AEXT 0x080/* log i_af.if_extents */ #define XFS_ILOG_ABROOT 0x100/* log i_af.i_broot */
@@ -329,9 +329,9 @@ struct xfs_inode_log_format_32 {#define XFS_ILOG_NONCORE (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \ XFS_ILOG_DBROOT | XFS_ILOG_DEV | \ - XFS_ILOG_UUID | XFS_ILOG_ADATA | \ - XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \ - XFS_ILOG_DOWNER | XFS_ILOG_AOWNER) + XFS_ILOG_ADATA | XFS_ILOG_AEXT | \ + XFS_ILOG_ABROOT | XFS_ILOG_DOWNER | \ + XFS_ILOG_AOWNER)#define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \ XFS_ILOG_DBROOT)
@@ -341,10 +341,10 @@ struct xfs_inode_log_format_32 {#define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \ XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \ - XFS_ILOG_DEV | XFS_ILOG_UUID | \ - XFS_ILOG_ADATA | XFS_ILOG_AEXT | \ - XFS_ILOG_ABROOT | XFS_ILOG_TIMESTAMP | \ - XFS_ILOG_DOWNER | XFS_ILOG_AOWNER) + XFS_ILOG_DEV | XFS_ILOG_ADATA | \ + XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \ + XFS_ILOG_TIMESTAMP | XFS_ILOG_DOWNER | \ + XFS_ILOG_AOWNER)static inline int xfs_ilog_fbroot (int w) {
fs/xfs/xfs_inode_item.c +6 -19
@@ -72,7 +72,6 @@ xfs_inode_item_data_fork_size(break ;case XFS_DINODE_FMT_DEV : -case XFS_DINODE_FMT_UUID :break ;default :ASSERT (0 );
@@ -156,8 +155,7 @@ xfs_inode_item_format_data_fork(switch (ip->i_d.di_format) {case XFS_DINODE_FMT_EXTENTS : iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT | -XFS_ILOG_DEV |XFS_ILOG_UUID ); + ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT |XFS_ILOG_DEV ); if ((iip->ili_fields & XFS_ILOG_DEXT) && ip->i_d.di_nextents > 0 &&
@@ -181,8 +179,7 @@ xfs_inode_item_format_data_fork(break ;case XFS_DINODE_FMT_BTREE : iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DEXT | -XFS_ILOG_DEV |XFS_ILOG_UUID ); + ~(XFS_ILOG_DDATA |XFS_ILOG_DEXT |XFS_ILOG_DEV );if ((iip->ili_fields &XFS_ILOG_DBROOT ) && ip->i_df.if_broot_bytes >0 ) {
@@ -200,8 +197,7 @@ xfs_inode_item_format_data_fork(break ;case XFS_DINODE_FMT_LOCAL : iip->ili_fields &= - ~(XFS_ILOG_DEXT |XFS_ILOG_DBROOT | -XFS_ILOG_DEV |XFS_ILOG_UUID ); + ~(XFS_ILOG_DEXT |XFS_ILOG_DBROOT |XFS_ILOG_DEV );if ((iip->ili_fields &XFS_ILOG_DDATA ) && ip->i_df.if_bytes >0 ) {/*
@@ -224,18 +220,10 @@ xfs_inode_item_format_data_fork(break ;case XFS_DINODE_FMT_DEV : iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT | -XFS_ILOG_DEXT |XFS_ILOG_UUID ); + ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT |XFS_ILOG_DEXT );if (iip->ili_fields &XFS_ILOG_DEV ) ilf->ilf_u.ilfu_rdev = ip->i_df.if_u2.if_rdev;break ; -case XFS_DINODE_FMT_UUID : - iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT | -XFS_ILOG_DEXT |XFS_ILOG_DEV ); -if (iip->ili_fields &XFS_ILOG_UUID ) - ilf->ilf_u.ilfu_uuid = ip->i_df.if_u2.if_uuid; -break ;default :ASSERT (0 );break ;
@@ -441,7 +429,7 @@ xfs_inode_item_format( ilf->ilf_dsize =0 ; ilf->ilf_asize =0 ; ilf->ilf_pad =0 ; -uuid_copy (&ilf->ilf_u.ilfu_uuid, &uuid_null); +memset (&ilf->ilf_u,0 ,sizeof (ilf->ilf_u));xlog_finish_iovec (lv, vecp,sizeof (*ilf));
@@ -892,8 +880,7 @@ xfs_inode_item_format_convert( in_f->ilf_asize = in_f32->ilf_asize; in_f->ilf_dsize = in_f32->ilf_dsize; in_f->ilf_ino = in_f32->ilf_ino; -/* copy biggest field of ilf_u */ -uuid_copy (&in_f->ilf_u.ilfu_uuid, &in_f32->ilf_u.ilfu_uuid); +memcpy (&in_f->ilf_u, &in_f32->ilf_u,sizeof (in_f->ilf_u)); in_f->ilf_blkno = in_f32->ilf_blkno; in_f->ilf_len = in_f32->ilf_len; in_f->ilf_boffset = in_f32->ilf_boffset;
fs/xfs/xfs_itable.c +0 -1
@@ -124,7 +124,6 @@ xfs_bulkstat_one_int( buf->bs_blocks =0 ;break ;case XFS_DINODE_FMT_LOCAL : -case XFS_DINODE_FMT_UUID : buf->bs_rdev =0 ; buf->bs_blksize = mp->m_sb.sb_blocksize; buf->bs_blocks =0 ;
fs/xfs/xfs_log_recover.c +1 -9
@@ -3163,16 +3163,8 @@ xlog_recover_inode_pass2( } fields = in_f->ilf_fields; -switch (fields & (XFS_ILOG_DEV |XFS_ILOG_UUID )) { -case XFS_ILOG_DEV : +if (fields &XFS_ILOG_DEV )xfs_dinode_put_rdev (dip, in_f->ilf_u.ilfu_rdev); -break ; -case XFS_ILOG_UUID : -memcpy (XFS_DFORK_DPTR (dip), - &in_f->ilf_u.ilfu_uuid, -sizeof (uuid_t)); -break ; - }if (in_f->ilf_size ==2 ) goto out_owner_change;
Signature · 1 line
2.14.1
PATCH 7/15 xfs: remove if_rdev
In reply to Christoph HellwigWe can simply use the i_rdev field in the Linux inode and just convert to and from the XFS dev_t when reading or logging/writing the inode.
--- fs/xfs/libxfs/xfs_inode_fork.c | 38 +++++++++++++++++++++----------------- fs/xfs/libxfs/xfs_inode_fork.h | 1 - fs/xfs/xfs_inode.c | 9 ++++----- fs/xfs/xfs_inode.h | 4 ++-- fs/xfs/xfs_inode_item.c | 2 +- fs/xfs/xfs_iops.c | 16 +--------------- fs/xfs/xfs_itable.c | 2 +- 7 files changed, 30 insertions(+), 42 deletions(-)
fs/xfs/libxfs/xfs_inode_fork.c +21 -17
@@ -42,21 +42,27 @@ STATIC int xfs_iformat_local(xfs_inode_t *, xfs_dinode_t *, int, int); STATIC int xfs_iformat_extents(xfs_inode_t *, xfs_dinode_t *, int); STATIC int xfs_iformat_btree(xfs_inode_t *, xfs_dinode_t *, int); +static inline dev_t xfs_to_linux_dev_t (xfs_dev_t dev) +{ +return MKDEV (sysv_major (dev) &0x1ff ,sysv_minor (dev)); +} +/* -* Move inode type and inode format specific information from the -* on-disk inode to the in-core inode. For fifos, devs, and sockets -* this means set if_rdev to the proper value. For files, directories, -* and symlinks this means to bring in the in-line data or extent -* pointers. For a file in B-tree format, only the root is immediately -* brought in-core. The rest will be in-lined in if_extents when it -* is first referenced (see xfs_iread_extents()). +* Copy inode type and data and attr format specific information from the +* on-disk inode to the in-core inode and fork structures. For fifos, devices, +* and sockets this means set i_rdev to the proper value. For files, +* directories, and symlinks this means to bring in the in-line data or extent +* pointers as well as the attribute fork. For a fork in B-tree format, only +* the root is immediately brought in-core. The rest will be read in later when +* first referenced (see xfs_iread_extents()). */ int xfs_iformat_fork ( -xfs_inode_t *ip, -xfs_dinode_t *dip) +struct xfs_inode *ip, +struct xfs_dinode *dip) { -xfs_attr_shortform_t *atp; +struct inode *inode =VFS_I (ip); +struct xfs_attr_shortform *atp;int size;int error =0 ;xfs_fsize_t di_size;
@@ -95,8 +101,7 @@ xfs_iformat_fork(return -EFSCORRUPTED ; } -if (unlikely (xfs_is_reflink_inode (ip) && - (VFS_I (ip)->i_mode &S_IFMT ) !=S_IFREG )) { +if (unlikely (xfs_is_reflink_inode (ip) && !S_ISREG (inode->i_mode))) {xfs_warn (ip->i_mount,"corrupt dinode %llu, wrong file type for reflink." , ip->i_ino);
@@ -115,7 +120,7 @@ xfs_iformat_fork(return -EFSCORRUPTED ; } -switch (VFS_I (ip)->i_mode &S_IFMT ) { +switch (inode->i_mode &S_IFMT ) {case S_IFIFO :case S_IFCHR :case S_IFBLK :
@@ -126,7 +131,7 @@ xfs_iformat_fork(return -EFSCORRUPTED ; } ip->i_d.di_size =0 ; - ip->i_df.if_u2.if_rdev =xfs_dinode_get_rdev (dip); + inode->i_rdev =xfs_to_linux_dev_t (xfs_dinode_get_rdev (dip));break ;case S_IFREG :
@@ -184,8 +189,7 @@ xfs_iformat_fork(return error;/* Check inline dir contents. */ -if (S_ISDIR (VFS_I (ip)->i_mode) && - dip->di_format ==XFS_DINODE_FMT_LOCAL ) { +if (S_ISDIR (inode->i_mode) && dip->di_format ==XFS_DINODE_FMT_LOCAL ) { error =xfs_dir2_sf_verify (ip);if (error) {xfs_idestroy_fork (ip,XFS_DATA_FORK );
@@ -898,7 +902,7 @@ xfs_iflush_fork(case XFS_DINODE_FMT_DEV :if (iip->ili_fields &XFS_ILOG_DEV ) {ASSERT (whichfork ==XFS_DATA_FORK ); -xfs_dinode_put_rdev (dip, ip->i_df.if_u2.if_rdev); +xfs_dinode_put_rdev (dip,sysv_encode_dev (VFS_I (ip)->i_rdev)); }break ;
fs/xfs/libxfs/xfs_inode_fork.h +0 -1
@@ -69,7 +69,6 @@ typedef struct xfs_ifork {/* very small file extents */ char if_inline_data[XFS_INLINE_DATA ];/* very small file data */ -xfs_dev_t if_rdev;/* dev number if special */ } if_u2; } xfs_ifork_t;
fs/xfs/xfs_inode.c +4 -5
@@ -767,7 +767,7 @@ xfs_ialloc(xfs_inode_t *pip, umode_t mode, xfs_nlink_t nlink, - xfs_dev_t rdev, + dev_t rdev, prid_t prid, int okalloc, xfs_buf_t **ialloc_context,
@@ -819,6 +819,7 @@ xfs_ialloc(set_nlink (inode, nlink); ip->i_d.di_uid =xfs_kuid_to_uid (current_fsuid ()); ip->i_d.di_gid =xfs_kgid_to_gid (current_fsgid ()); + inode->i_rdev = rdev;xfs_set_projid (ip, prid);if (pip &&XFS_INHERIT_GID (pip)) {
@@ -867,7 +868,6 @@ xfs_ialloc(case S_IFBLK :case S_IFSOCK : ip->i_d.di_format =XFS_DINODE_FMT_DEV ; - ip->i_df.if_u2.if_rdev = rdev; ip->i_df.if_flags =0 ; flags |=XFS_ILOG_DEV ;break ;
@@ -975,7 +975,7 @@ xfs_dir_ialloc(the inode. */ umode_t mode, xfs_nlink_t nlink, - xfs_dev_t rdev, + dev_t rdev, prid_t prid, /* project id */ int okalloc, /* ok to allocate new space */ xfs_inode_t **ipp, /* pointer to inode; it will be
@@ -1147,7 +1147,7 @@ xfs_create(xfs_inode_t *dp, struct xfs_name *name, umode_t mode, - xfs_dev_t rdev, + dev_t rdev, xfs_inode_t **ipp) { int is_dir = S_ISDIR(mode);
@@ -1183,7 +1183,6 @@ xfs_create(return error;if (is_dir) { - rdev =0 ; resblks =XFS_MKDIR_SPACE_RES (mp, name->len); tres = &M_RES (mp)->tr_mkdir; }else {
fs/xfs/xfs_inode.h +2 -2
@@ -391,7 +391,7 @@ void xfs_inactive(struct xfs_inode *ip);int xfs_lookup (struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode **ipp,struct xfs_name *ci_name);int xfs_create (struct xfs_inode *dp,struct xfs_name *name, -umode_t mode,xfs_dev_t rdev,struct xfs_inode **ipp); +umode_t mode,dev_t rdev,struct xfs_inode **ipp);int xfs_create_tmpfile (struct xfs_inode *dp,struct dentry *dentry,umode_t mode,struct xfs_inode **ipp); int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
@@ -428,7 +428,7 @@ xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);xfs_extlen_t xfs_get_cowextsz_hint (struct xfs_inode *ip);int xfs_dir_ialloc (struct xfs_trans **,struct xfs_inode *,umode_t , -xfs_nlink_t ,xfs_dev_t ,prid_t ,int , +xfs_nlink_t ,dev_t ,prid_t ,int ,struct xfs_inode **,int *);/* from xfs_file.c */
fs/xfs/xfs_inode_item.c +1 -1
@@ -222,7 +222,7 @@ xfs_inode_item_format_data_fork( iip->ili_fields &= ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT |XFS_ILOG_DEXT );if (iip->ili_fields &XFS_ILOG_DEV ) - ilf->ilf_u.ilfu_rdev = ip->i_df.if_u2.if_rdev; + ilf->ilf_u.ilfu_rdev =sysv_encode_dev (VFS_I (ip)->i_rdev);break ;default :ASSERT (0 );
fs/xfs/xfs_iops.c +1 -15
@@ -160,7 +160,6 @@ xfs_generic_create(if (S_ISCHR (mode) ||S_ISBLK (mode)) {if (unlikely (!sysv_valid_dev (rdev) ||MAJOR (rdev) & ~0x1ff ))return -EINVAL ; - rdev =sysv_encode_dev (rdev); }else { rdev =0 ; }
@@ -535,8 +534,7 @@ xfs_vn_getattr(case S_IFBLK :case S_IFCHR : stat->blksize =BLKDEV_IOSIZE ; - stat->rdev =MKDEV (sysv_major (ip->i_df.if_u2.if_rdev) &0x1ff , -sysv_minor (ip->i_df.if_u2.if_rdev)); + stat->rdev = inode->i_rdev;break ;default :if (XFS_IS_REALTIME_INODE (ip)) {
@@ -1231,18 +1229,6 @@ xfs_setup_inode( inode->i_uid =xfs_uid_to_kuid (ip->i_d.di_uid); inode->i_gid =xfs_gid_to_kgid (ip->i_d.di_gid); -switch (inode->i_mode &S_IFMT ) { -case S_IFBLK : -case S_IFCHR : - inode->i_rdev = -MKDEV (sysv_major (ip->i_df.if_u2.if_rdev) &0x1ff , -sysv_minor (ip->i_df.if_u2.if_rdev)); -break ; -default : - inode->i_rdev =0 ; -break ; - } -i_size_write (inode, ip->i_d.di_size);xfs_diflags_to_iflags (inode, ip);
fs/xfs/xfs_itable.c +1 -1
@@ -119,7 +119,7 @@ xfs_bulkstat_one_int(switch (dic->di_format) {case XFS_DINODE_FMT_DEV : - buf->bs_rdev = ip->i_df.if_u2.if_rdev; + buf->bs_rdev =sysv_encode_dev (inode->i_rdev); buf->bs_blksize =BLKDEV_IOSIZE ; buf->bs_blocks =0 ;break ;
Signature · 1 line
2.14.1
PATCH 8/15 xfs: inline xfs_shift_file_space into callers
In reply to Christoph HellwigThe code is sufficiently different for the insert vs collapse cases both in xfs_shift_file_space itself and the callers that untangling them will make life a lot easier down the road.
We still keep a common helper for flushing all data and COW state to get the inode into the right shape for shifting the extents around.
--- fs/xfs/xfs_bmap_util.c | 192 ++++++++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 90 deletions(-)
fs/xfs/xfs_bmap_util.c +102 -90
@@ -1260,53 +1260,12 @@ xfs_zero_file_space( } -/* -* @next_fsb will keep track of the extent currently undergoing shift. -* @stop_fsb will keep track of the extent at which we have to stop. -* If we are shifting left, we will start with block (offset + len) and -* shift each extent till last extent. -* If we are shifting right, we will start with last extent inside file space -* and continue until we reach the block corresponding to offset. -*/ static int -xfs_shift_file_space ( -struct xfs_inode *ip, -xfs_off_t offset, -xfs_off_t len, -enum shift_direction direction) +xfs_prepare_shift ( +struct xfs_inode *ip, +loff_t offset) { -int done =0 ; -struct xfs_mount *mp = ip->i_mount; -struct xfs_trans *tp;int error; -struct xfs_defer_ops dfops; -xfs_fsblock_t first_block; -xfs_fileoff_t stop_fsb; -xfs_fileoff_t next_fsb; -xfs_fileoff_t shift_fsb; -uint resblks; - -ASSERT (direction ==SHIFT_LEFT || direction ==SHIFT_RIGHT ); - -if (direction ==SHIFT_LEFT ) { -/* -* Reserve blocks to cover potential extent merges after left -* shift operations. -*/ - resblks =XFS_DIOSTRAT_SPACE_RES (mp,0 ); - next_fsb =XFS_B_TO_FSB (mp, offset + len); - stop_fsb =XFS_B_TO_FSB (mp,VFS_I (ip)->i_size); - }else { -/* -* If right shift, delegate the work of initialization of -* next_fsb to xfs_bmap_shift_extent as it has ilock held. -*/ - resblks =0 ; - next_fsb =NULLFSBLOCK ; - stop_fsb =XFS_B_TO_FSB (mp, offset); - } - - shift_fsb =XFS_B_TO_FSB (mp, len);/* * Trim eofblocks to avoid shifting uninitialized post-eof preallocation
@@ -1322,8 +1281,7 @@ xfs_shift_file_space(* Writeback and invalidate cache for the remainder of the file as we're * about to shift down every extent from offset to EOF. */ - error =filemap_write_and_wait_range (VFS_I (ip)->i_mapping, - offset,-1 ); + error =filemap_write_and_wait_range (VFS_I (ip)->i_mapping, offset,-1 );if (error)return error; error = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping,
@@ -1343,16 +1301,48 @@ xfs_shift_file_space(return error; } -/* -* The extent shifting code works on extent granularity. So, if -* stop_fsb is not the starting block of extent, we need to split -* the extent at stop_fsb. -*/ -if (direction ==SHIFT_RIGHT ) { - error =xfs_bmap_split_extent (ip, stop_fsb); -if (error) -return error; - } +return 0 ; +} + +/* +* xfs_collapse_file_space() +* This routine frees disk space and shift extent for the given file. +* The first thing we do is to free data blocks in the specified range +* by calling xfs_free_file_space(). It would also sync dirty data +* and invalidate page cache over the region on which collapse range +* is working. And Shift extent records to the left to cover a hole. +* RETURNS: +* 0 on success +* errno on error +* +*/ +int +xfs_collapse_file_space ( +struct xfs_inode *ip, +xfs_off_t offset, +xfs_off_t len) +{ +int done =0 ; +struct xfs_mount *mp = ip->i_mount; +struct xfs_trans *tp; +int error; +struct xfs_defer_ops dfops; +xfs_fsblock_t first_block; +xfs_fileoff_t stop_fsb =XFS_B_TO_FSB (mp,VFS_I (ip)->i_size); +xfs_fileoff_t next_fsb =XFS_B_TO_FSB (mp, offset + len); +xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len); +uint resblks =XFS_DIOSTRAT_SPACE_RES (mp,0 ); + +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL )); +trace_xfs_collapse_file_space (ip); + + error =xfs_free_file_space (ip, offset, len); +if (error) +return error; + + error =xfs_prepare_shift (ip, offset); +if (error) +return error;while (!error && !done) { error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0,
@@ -1366,7 +1356,6 @@ xfs_shift_file_space( XFS_QMOPT_RES_REGBLKS);if (error) goto out_trans_cancel; -xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block);
@@ -1377,14 +1366,13 @@ xfs_shift_file_space(*/ error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, &done, stop_fsb, &first_block, &dfops, - direction,XFS_BMAP_MAX_SHIFT_EXTENTS ); +SHIFT_LEFT ,XFS_BMAP_MAX_SHIFT_EXTENTS );if (error) goto out_bmap_cancel; error =xfs_defer_finish (&tp, &dfops);if (error) goto out_bmap_cancel; - error =xfs_trans_commit (tp); }
@@ -1397,36 +1385,6 @@ xfs_shift_file_space(return error; } -/* -* xfs_collapse_file_space() -* This routine frees disk space and shift extent for the given file. -* The first thing we do is to free data blocks in the specified range -* by calling xfs_free_file_space(). It would also sync dirty data -* and invalidate page cache over the region on which collapse range -* is working. And Shift extent records to the left to cover a hole. -* RETURNS: -* 0 on success -* errno on error -* -*/ -int -xfs_collapse_file_space ( -struct xfs_inode *ip, -xfs_off_t offset, -xfs_off_t len) -{ -int error; - -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL )); -trace_xfs_collapse_file_space (ip); - - error =xfs_free_file_space (ip, offset, len); -if (error) -return error; - -return xfs_shift_file_space (ip, offset, len,SHIFT_LEFT ); -} -/* * xfs_insert_file_space() * This routine create hole space by shifting extents for the given file.
@@ -1445,10 +1403,64 @@ xfs_insert_file_space( loff_t offset, loff_t len) { +struct xfs_mount *mp = ip->i_mount; +struct xfs_trans *tp; +int error; +struct xfs_defer_ops dfops; +xfs_fsblock_t first_block; +xfs_fileoff_t stop_fsb =XFS_B_TO_FSB (mp, offset); +xfs_fileoff_t next_fsb =NULLFSBLOCK ; +xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len); +int done =0 ; +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));trace_xfs_insert_file_space (ip); -return xfs_shift_file_space (ip, offset, len,SHIFT_RIGHT ); + error =xfs_prepare_shift (ip, offset); +if (error) +return error; + +/* +* The extent shifting code works on extent granularity. So, if stop_fsb +* is not the starting block of extent, we need to split the extent at +* stop_fsb. +*/ + error =xfs_bmap_split_extent (ip, stop_fsb); +if (error) +return error; + +while (!error && !done) { + error =xfs_trans_alloc (mp, &M_RES (mp)->tr_write,0 ,0 ,0 , + &tp); +if (error) +break ; + +xfs_ilock (ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_defer_init (&dfops, &first_block); + +/* +* We are using the write transaction in which max 2 bmbt +* updates are allowed +*/ + error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, + &done, stop_fsb, &first_block, &dfops, +SHIFT_RIGHT ,XFS_BMAP_MAX_SHIFT_EXTENTS ); +if (error) + goto out_bmap_cancel; + + error =xfs_defer_finish (&tp, &dfops); +if (error) + goto out_bmap_cancel; + error =xfs_trans_commit (tp); + } + +return error; + +out_bmap_cancel: +xfs_defer_cancel (&dfops); +xfs_trans_cancel (tp); +return error; }/*
Signature · 1 line
2.14.1
PATCH 9/15 xfs: remove XFS_BMAP_MAX_SHIFT_EXTENTS
In reply to Christoph HellwigThe define was always set to 1, which means looping until we reach is was dead code from the start.
Also remove an initialization of next_fsb for the done case that doesn't fit the new code flow - it was never checked by the caller in the done case to start with.
--- fs/xfs/libxfs/xfs_bmap.c | 47 ++++++++++++++++++++--------------------------- fs/xfs/libxfs/xfs_bmap.h | 12 +----------- fs/xfs/xfs_bmap_util.c | 14 ++------------ 3 files changed, 23 insertions(+), 50 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +20 -27
@@ -5692,8 +5692,7 @@ xfs_bmse_shift_one(/* * Shift extent records to the left/right to cover/create a hole. * -* The maximum number of extents to be shifted in a single operation is -* @num_exts. @stop_fsb specifies the file offset at which to stop shift and the +* @stop_fsb specifies the file offset at which to stop shift and the * file offset where we've left off is returned in @next_fsb. @offset_shift_fsb * is the length by which each extent is shifted. If there is no hole to shift * the extents into, this will be considered invalid operation and we abort
@@ -5709,14 +5708,12 @@ xfs_bmap_shift_extents(xfs_fileoff_t stop_fsb, xfs_fsblock_t *firstblock, struct xfs_defer_ops *dfops, - enum shift_direction direction, - int num_exts) + enum shift_direction direction) { struct xfs_btree_cur *cur = NULL;struct xfs_bmbt_irec got;struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp; -xfs_extnum_t nexts =0 ;xfs_extnum_t current_ext;xfs_extnum_t total_extents;xfs_extnum_t stop_extent;
@@ -5814,31 +5811,27 @@ xfs_bmap_shift_extents( } } -while (nexts++ < num_exts) { - error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, - ¤t_ext, &got, cur, &logflags, - direction, dfops); -if (error) - goto del_cursor; -/* -* If there was an extent merge during the shift, the extent -* count can change. Update the total and grade the next record. -*/ -if (direction ==SHIFT_LEFT ) { - total_extents =xfs_iext_count (ifp); - stop_extent = total_extents; - } + error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, + ¤t_ext, &got, cur, &logflags, + direction, dfops); +if (error) + goto del_cursor; +/* +* If there was an extent merge during the shift, the extent +* count can change. Update the total and grade the next record. +*/ +if (direction ==SHIFT_LEFT ) { + total_extents =xfs_iext_count (ifp); + stop_extent = total_extents; + } -if (current_ext == stop_extent) { - *done =1 ; - *next_fsb =NULLFSBLOCK ; -break ; - } -xfs_iext_get_extent (ifp, current_ext, &got); +if (current_ext == stop_extent) { + *done =1 ; + goto del_cursor; } +xfs_iext_get_extent (ifp, current_ext, &got); -if (!*done) - *next_fsb = got.br_startoff; + *next_fsb = got.br_startoff; del_cursor:if (cur)
fs/xfs/libxfs/xfs_bmap.h +1 -11
@@ -183,15 +183,6 @@ static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec) !isnullstartblock (irec->br_startblock); } -/* -* This macro is used to determine how many extents will be shifted -* in one write transaction. We could require two splits, -* an extent move on the first and an extent merge on the second, -* So it is proper that one extent is shifted inside write transaction -* at a time. -*/ -#define XFS_BMAP_MAX_SHIFT_EXTENTS 1 -enum shift_direction {SHIFT_LEFT =0 ,SHIFT_RIGHT ,
@@ -239,8 +230,7 @@ uint xfs_default_attroffset(struct xfs_inode *ip);int xfs_bmap_shift_extents (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb,int *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, -struct xfs_defer_ops *dfops,enum shift_direction direction, -int num_exts); +struct xfs_defer_ops *dfops,enum shift_direction direction);int xfs_bmap_split_extent (struct xfs_inode *ip,xfs_fileoff_t split_offset); int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork, xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,
fs/xfs/xfs_bmap_util.c +2 -12
@@ -1359,14 +1359,9 @@ xfs_collapse_file_space(xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - -/* -* We are using the write transaction in which max 2 bmbt -* updates are allowed -*/ error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, &done, stop_fsb, &first_block, &dfops, -SHIFT_LEFT ,XFS_BMAP_MAX_SHIFT_EXTENTS ); +SHIFT_LEFT );if (error) goto out_bmap_cancel;
@@ -1438,14 +1433,9 @@ xfs_insert_file_space(xfs_ilock (ip,XFS_ILOCK_EXCL );xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - -/* -* We are using the write transaction in which max 2 bmbt -* updates are allowed -*/ error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, &done, stop_fsb, &first_block, &dfops, -SHIFT_RIGHT ,XFS_BMAP_MAX_SHIFT_EXTENTS ); +SHIFT_RIGHT );if (error) goto out_bmap_cancel;
Signature · 1 line
2.14.1
PATCH 10/15 xfs: split xfs_bmap_shift_extents
In reply to Christoph HellwigHave a separate helper for insert vs collapse, as this prepares us for simplifying the code in the next patches.
Also changed the done output argument to a bool intead of int for both new functions.
--- fs/xfs/libxfs/xfs_bmap.c | 197 ++++++++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_bmap.h | 10 ++- fs/xfs/xfs_bmap_util.c | 14 ++-- 3 files changed, 148 insertions(+), 73 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +135 -62
@@ -5689,57 +5689,151 @@ xfs_bmse_shift_one(return xfs_rmap_map_extent (mp, dfops, ip, whichfork, &new); } -/* -* Shift extent records to the left/right to cover/create a hole. -* -* @stop_fsb specifies the file offset at which to stop shift and the -* file offset where we've left off is returned in @next_fsb. @offset_shift_fsb -* is the length by which each extent is shifted. If there is no hole to shift -* the extents into, this will be considered invalid operation and we abort -* immediately. -*/ int -xfs_bmap_shift_extents ( +xfs_bmap_collapse_extents (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb, -int *done, +bool *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, -struct xfs_defer_ops *dfops, -enum shift_direction direction) +struct xfs_defer_ops *dfops) { -struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got; -struct xfs_mount *mp = ip->i_mount; -struct xfs_ifork *ifp; -xfs_extnum_t current_ext; -xfs_extnum_t total_extents; -xfs_extnum_t stop_extent; -int error =0 ; -int whichfork =XFS_DATA_FORK ; -int logflags =0 ; +int whichfork =XFS_DATA_FORK ; +struct xfs_mount *mp = ip->i_mount; +struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +struct xfs_btree_cur *cur =NULL ; +struct xfs_bmbt_irec got; +xfs_extnum_t current_ext; +xfs_extnum_t total_extents; +xfs_extnum_t stop_extent; +int error =0 ; +int logflags =0 ;if (unlikely (XFS_TEST_ERROR ( (XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_EXTENTS &&XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_BTREE ), mp,XFS_ERRTAG_BMAPIFORMAT ))) { -XFS_ERROR_REPORT ("xfs_bmap_shift_extents" , -XFS_ERRLEVEL_LOW , mp); +XFS_ERROR_REPORT (__func__,XFS_ERRLEVEL_LOW , mp);return -EFSCORRUPTED ; }if (XFS_FORCED_SHUTDOWN (mp))return -EIO ; -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL )); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); -ASSERT (direction ==SHIFT_LEFT || direction ==SHIFT_RIGHT ); +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL )); + +if (!(ifp->if_flags &XFS_IFEXTENTS )) { + error =xfs_iread_extents (tp, ip, whichfork); +if (error) +return error; + } + +if (ifp->if_flags &XFS_IFBROOT ) { + cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); + cur->bc_private.b.firstblock = *firstblock; + cur->bc_private.b.dfops = dfops; + cur->bc_private.b.flags =0 ; + } + +/* +* There may be delalloc extents in the data fork before the range we +* are collapsing out, so we cannot use the count of real extents here. +* Instead we have to calculate it from the incore fork. +*/ + total_extents =xfs_iext_count (ifp); +if (total_extents ==0 ) { + *done = true; + goto del_cursor; + } + +/* +* Look up the extent index for the fsb where we start shifting. We can +* henceforth iterate with current_ext as extent list changes are locked +* out via ilock. +* +* If next_fsb lies in a hole beyond which there are no extents we are +* done. +*/ +if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { + *done = true; + goto del_cursor; + } + + stop_extent = total_extents; +if (current_ext >= stop_extent) { + error = -EIO ; + goto del_cursor; + } + + error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, + ¤t_ext, &got, cur, &logflags, +SHIFT_LEFT , dfops); +if (error) + goto del_cursor; +/* +* If there was an extent merge during the shift, the extent +* count can change. Update the total and grade the next record. +*/ + total_extents =xfs_iext_count (ifp); + stop_extent = total_extents; +if (current_ext == stop_extent) { + *done = true; + goto del_cursor; + } +xfs_iext_get_extent (ifp, current_ext, &got); + +if (!*done) + *next_fsb = got.br_startoff; + +del_cursor: +if (cur) +xfs_btree_del_cursor (cur, + error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); + +if (logflags) +xfs_trans_log_inode (tp, ip, logflags); + +return error; +} + +int +xfs_bmap_insert_extents ( +struct xfs_trans *tp, +struct xfs_inode *ip, +xfs_fileoff_t *next_fsb, +xfs_fileoff_t offset_shift_fsb, +bool *done, +xfs_fileoff_t stop_fsb, +xfs_fsblock_t *firstblock, +struct xfs_defer_ops *dfops) +{ +int whichfork =XFS_DATA_FORK ; +struct xfs_mount *mp = ip->i_mount; +struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +struct xfs_btree_cur *cur =NULL ; +struct xfs_bmbt_irec got, s; +xfs_extnum_t current_ext; +xfs_extnum_t total_extents; +xfs_extnum_t stop_extent; +int error =0 ; +int logflags =0 ; + +if (unlikely (XFS_TEST_ERROR ( + (XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_EXTENTS && +XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_BTREE ), + mp,XFS_ERRTAG_BMAPIFORMAT ))) { +XFS_ERROR_REPORT (__func__,XFS_ERRLEVEL_LOW , mp); +return -EFSCORRUPTED ; + } + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL )); - ifp =XFS_IFORK_PTR (ip, whichfork);if (!(ifp->if_flags &XFS_IFEXTENTS )) { -/* Read in all the extents */ error =xfs_iread_extents (tp, ip, whichfork);if (error)return error;
@@ -5759,7 +5853,7 @@ xfs_bmap_shift_extents(*/ total_extents =xfs_iext_count (ifp);if (total_extents ==0 ) { - *done =1 ; + *done = true; goto del_cursor; }
@@ -5767,12 +5861,10 @@ xfs_bmap_shift_extents(* In case of first right shift, we need to initialize next_fsb */ if (*next_fsb ==NULLFSBLOCK ) { -ASSERT (direction ==SHIFT_RIGHT ); - current_ext = total_extents -1 ;xfs_iext_get_extent (ifp, current_ext, &got);if (stop_fsb > got.br_startoff) { - *done =1 ; + *done = true; goto del_cursor; } *next_fsb = got.br_startoff;
@@ -5787,46 +5879,27 @@ xfs_bmap_shift_extents(*/ if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { - *done =1 ; + *done = true; goto del_cursor; } }/* Lookup the extent index at which we have to stop */ -if (direction ==SHIFT_RIGHT ) { -struct xfs_bmbt_irec s; - -xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s); -/* Make stop_extent exclusive of shift range */ - stop_extent--; -if (current_ext <= stop_extent) { - error = -EIO ; - goto del_cursor; - } - }else { - stop_extent = total_extents; -if (current_ext >= stop_extent) { - error = -EIO ; - goto del_cursor; - } +xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s); +/* Make stop_extent exclusive of shift range */ + stop_extent--; +if (current_ext <= stop_extent) { + error = -EIO ; + goto del_cursor; } error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, ¤t_ext, &got, cur, &logflags, - direction, dfops); +SHIFT_RIGHT , dfops);if (error) goto del_cursor; -/* -* If there was an extent merge during the shift, the extent -* count can change. Update the total and grade the next record. -*/ -if (direction ==SHIFT_LEFT ) { - total_extents =xfs_iext_count (ifp); - stop_extent = total_extents; - } -if (current_ext == stop_extent) { - *done =1 ; + *done = true; goto del_cursor; }xfs_iext_get_extent (ifp, current_ext, &got);
fs/xfs/libxfs/xfs_bmap.h +7 -3
@@ -227,10 +227,14 @@ int xfs_bmap_del_extent_delay(struct xfs_inode *ip, int whichfork,void xfs_bmap_del_extent_cow (struct xfs_inode *ip,xfs_extnum_t *idx,struct xfs_bmbt_irec *got,struct xfs_bmbt_irec *del);uint xfs_default_attroffset (struct xfs_inode *ip); -int xfs_bmap_shift_extents (struct xfs_trans *tp,struct xfs_inode *ip, +int xfs_bmap_collapse_extents (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb, -int *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, -struct xfs_defer_ops *dfops,enum shift_direction direction); +bool *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, +struct xfs_defer_ops *dfops); +int xfs_bmap_insert_extents (struct xfs_trans *tp,struct xfs_inode *ip, +xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb, +bool *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, +struct xfs_defer_ops *dfops);int xfs_bmap_split_extent (struct xfs_inode *ip,xfs_fileoff_t split_offset); int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork, xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,
fs/xfs/xfs_bmap_util.c +6 -8
@@ -1322,7 +1322,6 @@ xfs_collapse_file_space( xfs_off_t offset, xfs_off_t len) { - int done = 0;struct xfs_mount *mp = ip->i_mount;struct xfs_trans *tp;int error;
@@ -1332,6 +1331,7 @@ xfs_collapse_file_space(xfs_fileoff_t next_fsb =XFS_B_TO_FSB (mp, offset + len);xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len);uint resblks =XFS_DIOSTRAT_SPACE_RES (mp,0 ); +bool done = false;ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));trace_xfs_collapse_file_space (ip);
@@ -1359,9 +1359,8 @@ xfs_collapse_file_space(xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, - &done, stop_fsb, &first_block, &dfops, -SHIFT_LEFT ); + error =xfs_bmap_collapse_extents (tp, ip, &next_fsb, shift_fsb, + &done, stop_fsb, &first_block, &dfops);if (error) goto out_bmap_cancel;
@@ -1406,7 +1405,7 @@ xfs_insert_file_space(xfs_fileoff_t stop_fsb =XFS_B_TO_FSB (mp, offset);xfs_fileoff_t next_fsb =NULLFSBLOCK ;xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len); -int done =0 ; +bool done = false;ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));trace_xfs_insert_file_space (ip);
@@ -1433,9 +1432,8 @@ xfs_insert_file_space(xfs_ilock (ip,XFS_ILOCK_EXCL );xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, - &done, stop_fsb, &first_block, &dfops, -SHIFT_RIGHT ); + error =xfs_bmap_insert_extents (tp, ip, &next_fsb, shift_fsb, + &done, stop_fsb, &first_block, &dfops);if (error) goto out_bmap_cancel;
Signature · 1 line
2.14.1
PATCH 11/15 xfs: remove xfs_bmse_shift_one
In reply to Christoph HellwigInstead do the actual left and right shift work in the callers, and just keep a helper to update the bmap and rmap btrees as well as the in-core extent list.
--- fs/xfs/libxfs/xfs_bmap.c | 181 +++++++++++++++++++---------------------------- fs/xfs/libxfs/xfs_bmap.h | 5 -- 2 files changed, 71 insertions(+), 115 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +71 -110
@@ -5568,94 +5568,21 @@ xfs_bmse_merge(return xfs_rmap_map_extent (mp, dfops, ip, whichfork, &new); } -/* -* Shift a single extent. -*/ -STATIC int -xfs_bmse_shift_one ( -struct xfs_inode *ip, -int whichfork, -xfs_fileoff_t offset_shift_fsb, -int *current_ext, -struct xfs_bmbt_irec *got, -struct xfs_btree_cur *cur, -int *logflags, -enum shift_direction direction, -struct xfs_defer_ops *dfops) +static int +xfs_bmap_shift_update_extent ( +struct xfs_inode *ip, +int whichfork, +xfs_extnum_t idx, +struct xfs_bmbt_irec *got, +struct xfs_btree_cur *cur, +int *logflags, +struct xfs_defer_ops *dfops, +xfs_fileoff_t startoff) { -struct xfs_ifork *ifp; -struct xfs_mount *mp; -xfs_fileoff_t startoff; -struct xfs_bmbt_irec adj_irec, new; -int error; -int i; -int total_extents; - - mp = ip->i_mount; - ifp =XFS_IFORK_PTR (ip, whichfork); - total_extents =xfs_iext_count (ifp); - -/* delalloc extents should be prevented by caller */ -XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got->br_startblock)); - -if (direction ==SHIFT_LEFT ) { - startoff = got->br_startoff - offset_shift_fsb; - -/* -* Check for merge if we've got an extent to the left, -* otherwise make sure there's enough room at the start -* of the file for the shift. -*/ -if (!*current_ext) { -if (got->br_startoff < offset_shift_fsb) -return -EINVAL ; - goto update_current_ext; - } - -/* -* grab the left extent and check for a large enough hole. -*/ -xfs_iext_get_extent (ifp, *current_ext -1 , &adj_irec); -if (startoff < adj_irec.br_startoff + adj_irec.br_blockcount) -return -EINVAL ; - -/* check whether to merge the extent or shift it down */ -if (xfs_bmse_can_merge (&adj_irec, got, offset_shift_fsb)) { -return xfs_bmse_merge (ip, whichfork, offset_shift_fsb, - *current_ext, got, &adj_irec, - cur, logflags, dfops); - } - }else { - startoff = got->br_startoff + offset_shift_fsb; -/* nothing to move if this is the last extent */ -if (*current_ext >= (total_extents -1 )) - goto update_current_ext; - -/* -* If this is not the last extent in the file, make sure there -* is enough room between current extent and next extent for -* accommodating the shift. -*/ -xfs_iext_get_extent (ifp, *current_ext +1 , &adj_irec); -if (startoff + got->br_blockcount > adj_irec.br_startoff) -return -EINVAL ; - -/* -* Unlike a left shift (which involves a hole punch), -* a right shift does not modify extent neighbors -* in any way. We should never find mergeable extents -* in this scenario. Check anyways and warn if we -* encounter two extents that could be one. -*/ -if (xfs_bmse_can_merge (got, &adj_irec, offset_shift_fsb)) -WARN_ON_ONCE (1 ); - } +struct xfs_mount *mp = ip->i_mount; +struct xfs_bmbt_irec new; +int error, i; -/* -* Increment the extent index for the next iteration, update the start -* offset of the in-core extent and update the btree if applicable. -*/ -update_current_ext: *logflags |=XFS_ILOG_CORE ; new = *got;
@@ -5674,13 +5601,8 @@ xfs_bmse_shift_one( *logflags |=XFS_ILOG_DEXT ; } -xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), - *current_ext, &new); - -if (direction ==SHIFT_LEFT ) - (*current_ext)++; -else - (*current_ext)--; +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), idx, + &new);/* update reverse mapping */ error =xfs_rmap_unmap_extent (mp, dfops, ip, whichfork, got);
@@ -5704,10 +5626,11 @@ xfs_bmap_collapse_extents(struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got; +struct xfs_bmbt_irec got, prev;xfs_extnum_t current_ext;xfs_extnum_t total_extents;xfs_extnum_t stop_extent; +xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;
@@ -5760,6 +5683,7 @@ xfs_bmap_collapse_extents( *done = true; goto del_cursor; } +XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock)); stop_extent = total_extents;if (current_ext >= stop_extent) {
@@ -5767,11 +5691,36 @@ xfs_bmap_collapse_extents( goto del_cursor; } - error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, - ¤t_ext, &got, cur, &logflags, -SHIFT_LEFT , dfops); + new_startoff = got.br_startoff - offset_shift_fsb; +if (current_ext) { +xfs_iext_get_extent (ifp, current_ext -1 , &prev); +if (new_startoff < prev.br_startoff + prev.br_blockcount) { + error = -EINVAL ; + goto del_cursor; + } + +/* check whether to merge the extent or shift it down */ +if (xfs_bmse_can_merge (&prev, &got, offset_shift_fsb)) { + error =xfs_bmse_merge (ip, whichfork, offset_shift_fsb, + current_ext, &got, &prev, cur, + &logflags, dfops); +if (error) + goto del_cursor; + goto done; + } + }else { +if (got.br_startoff < offset_shift_fsb) { + error = -EINVAL ; + goto del_cursor; + } + } + + error =xfs_bmap_shift_update_extent (ip, whichfork, current_ext, &got, + cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; + current_ext++; +done:/* * If there was an extent merge during the shift, the extent * count can change. Update the total and grade the next record.
@@ -5784,17 +5733,13 @@ xfs_bmap_collapse_extents( }xfs_iext_get_extent (ifp, current_ext, &got); -if (!*done) - *next_fsb = got.br_startoff; - + *next_fsb = got.br_startoff; del_cursor:if (cur)xfs_btree_del_cursor (cur, error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); -if (logflags)xfs_trans_log_inode (tp, ip, logflags); -return error; }
@@ -5813,10 +5758,11 @@ xfs_bmap_insert_extents(struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got, s; +struct xfs_bmbt_irec got, next, s;xfs_extnum_t current_ext;xfs_extnum_t total_extents;xfs_extnum_t stop_extent; +xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;
@@ -5883,6 +5829,7 @@ xfs_bmap_insert_extents( goto del_cursor; } } +XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock));/* Lookup the extent index at which we have to stop */ xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s);
@@ -5893,27 +5840,41 @@ xfs_bmap_insert_extents( goto del_cursor; } - error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, - ¤t_ext, &got, cur, &logflags, -SHIFT_RIGHT , dfops); + new_startoff = got.br_startoff + offset_shift_fsb; +if (current_ext < total_extents -1 ) { +xfs_iext_get_extent (ifp, current_ext +1 , &next); +if (new_startoff + got.br_blockcount > next.br_startoff) { + error = -EINVAL ; + goto del_cursor; + } + +/* +* Unlike a left shift (which involves a hole punch), a right +* shift does not modify extent neighbors in any way. We should +* never find mergeable extents in this scenario. Check anyways +* and warn if we encounter two extents that could be one. +*/ +if (xfs_bmse_can_merge (&got, &next, offset_shift_fsb)) +WARN_ON_ONCE (1 ); + } + + error =xfs_bmap_shift_update_extent (ip, whichfork, current_ext, &got, + cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; -if (current_ext == stop_extent) { +if (--current_ext == stop_extent) { *done = true; goto del_cursor; }xfs_iext_get_extent (ifp, current_ext, &got); *next_fsb = got.br_startoff; - del_cursor:if (cur)xfs_btree_del_cursor (cur, error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); -if (logflags)xfs_trans_log_inode (tp, ip, logflags); -return error; }
fs/xfs/libxfs/xfs_bmap.h +0 -5
@@ -183,11 +183,6 @@ static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec) !isnullstartblock (irec->br_startblock); } -enum shift_direction { -SHIFT_LEFT =0 , -SHIFT_RIGHT , -}; -void xfs_trim_extent (struct xfs_bmbt_irec *irec,xfs_fileoff_t bno,xfs_filblks_t len);int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd);
Signature · 1 line
2.14.1
PATCH 12/15 xfs: update got in xfs_bmap_shift_update_extent
In reply to Christoph HellwigThis way the caller gets the proper updated extent returned in got.
--- fs/xfs/libxfs/xfs_bmap.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +7 -9
@@ -5580,35 +5580,33 @@ xfs_bmap_shift_update_extent( xfs_fileoff_t startoff) {struct xfs_mount *mp = ip->i_mount; -struct xfs_bmbt_irec new; +struct xfs_bmbt_irec prev = *got;int error, i; *logflags |=XFS_ILOG_CORE ; - new = *got; - new.br_startoff = startoff; + got->br_startoff = startoff;if (cur) { - error =xfs_bmbt_lookup_eq (cur, got, &i); + error =xfs_bmbt_lookup_eq (cur, &prev, &i);if (error)return error;XFS_WANT_CORRUPTED_RETURN (mp, i ==1 ); - error =xfs_bmbt_update (cur, &new); + error =xfs_bmbt_update (cur, got);if (error)return error; }else { *logflags |=XFS_ILOG_DEXT ; } -xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), idx, - &new); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), idx, got);/* update reverse mapping */ - error =xfs_rmap_unmap_extent (mp, dfops, ip, whichfork, got); + error =xfs_rmap_unmap_extent (mp, dfops, ip, whichfork, &prev);if (error)return error; -return xfs_rmap_map_extent (mp, dfops, ip, whichfork, &new); +return xfs_rmap_map_extent (mp, dfops, ip, whichfork, got); }int
Signature · 1 line
2.14.1
PATCH 13/15 xfs: don't rely on extent indices in xfs_bmap_collapse_extents
In reply to Christoph HellwigRewrite xfs_bmap_collapse_extents so that we don't rely on extent indices except for iterating over them. Not being able to iterate to the next extent is a sufficient exit condition, and we don't need to do any extent count games given that:
a) we already flushed all delalloc extents past our start offset before doing the operation
b) xfs_iext_count() includes delalloc extents anyway
--- fs/xfs/libxfs/xfs_bmap.c | 54 +++++++++++------------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +12 -42
@@ -5626,8 +5626,6 @@ xfs_bmap_collapse_extents(struct xfs_btree_cur *cur =NULL ;struct xfs_bmbt_irec got, prev;xfs_extnum_t current_ext; -xfs_extnum_t total_extents; -xfs_extnum_t stop_extent;xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;
@@ -5658,52 +5656,31 @@ xfs_bmap_collapse_extents( cur->bc_private.b.flags =0 ; } -/* -* There may be delalloc extents in the data fork before the range we -* are collapsing out, so we cannot use the count of real extents here. -* Instead we have to calculate it from the incore fork. -*/ - total_extents =xfs_iext_count (ifp); -if (total_extents ==0 ) { - *done = true; - goto del_cursor; - } - -/* -* Look up the extent index for the fsb where we start shifting. We can -* henceforth iterate with current_ext as extent list changes are locked -* out via ilock. -* -* If next_fsb lies in a hole beyond which there are no extents we are -* done. -*/ if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { *done = true; goto del_cursor; }XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock)); - stop_extent = total_extents; -if (current_ext >= stop_extent) { - error = -EIO ; - goto del_cursor; - } - new_startoff = got.br_startoff - offset_shift_fsb; -if (current_ext) { -xfs_iext_get_extent (ifp, current_ext -1 , &prev); +if (xfs_iext_get_extent (ifp, current_ext -1 , &prev)) {if (new_startoff < prev.br_startoff + prev.br_blockcount) { error = -EINVAL ; goto del_cursor; } -/* check whether to merge the extent or shift it down */ if (xfs_bmse_can_merge (&prev, &got, offset_shift_fsb)) { error =xfs_bmse_merge (ip, whichfork, offset_shift_fsb, current_ext, &got, &prev, cur, &logflags, dfops);if (error) goto del_cursor; + +/* update got after merge */ +if (!xfs_iext_get_extent (ifp, current_ext, &got)) { + *done = true; + goto del_cursor; + } goto done; } }else {
@@ -5717,20 +5694,13 @@ xfs_bmap_collapse_extents( cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; - current_ext++; -done: -/* -* If there was an extent merge during the shift, the extent -* count can change. Update the total and grade the next record. -*/ - total_extents =xfs_iext_count (ifp); - stop_extent = total_extents; -if (current_ext == stop_extent) { - *done = true; - goto del_cursor; + +if (!xfs_iext_get_extent (ifp, ++current_ext, &got)) { + *done = true; + goto del_cursor; } -xfs_iext_get_extent (ifp, current_ext, &got); +done: *next_fsb = got.br_startoff; del_cursor:if (cur)
Signature · 1 line
2.14.1
PATCH 14/15 xfs: don't rely on extent indices in xfs_bmap_insert_extents
In reply to Christoph HellwigRewrite xfs_bmap_insert_extents so that we don't rely on extent indices except for iterating over them. Not being able to iterate to the previous extent or finding the extent that stop_fsb is in are sufficient exit conditions, and we don't need to do any extent count games given that:
a) we already flushed all delalloc extents past our start offset before doing the operation
b) xfs_iext_count() includes delalloc extents anyway
--- fs/xfs/libxfs/xfs_bmap.c | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +9 -38
@@ -5726,10 +5726,8 @@ xfs_bmap_insert_extents(struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got, next, s; +struct xfs_bmbt_irec got, next;xfs_extnum_t current_ext; -xfs_extnum_t total_extents; -xfs_extnum_t stop_extent;xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;
@@ -5760,37 +5758,14 @@ xfs_bmap_insert_extents( cur->bc_private.b.flags =0 ; } -/* -* There may be delalloc extents in the data fork before the range we -* are collapsing out, so we cannot use the count of real extents here. -* Instead we have to calculate it from the incore fork. -*/ - total_extents =xfs_iext_count (ifp); -if (total_extents ==0 ) { - *done = true; - goto del_cursor; - } - -/* -* In case of first right shift, we need to initialize next_fsb -*/ if (*next_fsb ==NULLFSBLOCK ) { - current_ext = total_extents -1 ; -xfs_iext_get_extent (ifp, current_ext, &got); -if (stop_fsb > got.br_startoff) { + current_ext =xfs_iext_count (ifp) -1 ; +if (!xfs_iext_get_extent (ifp, current_ext, &got) || + stop_fsb > got.br_startoff) { *done = true; goto del_cursor; } - *next_fsb = got.br_startoff; }else { -/* -* Look up the extent index for the fsb where we start shifting. We can -* henceforth iterate with current_ext as extent list changes are locked -* out via ilock. -* -* If next_fsb lies in a hole beyond which there are no extents we are -* done. -*/ if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { *done = true;
@@ -5799,18 +5774,13 @@ xfs_bmap_insert_extents( }XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock)); -/* Lookup the extent index at which we have to stop */ -xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s); -/* Make stop_extent exclusive of shift range */ - stop_extent--; -if (current_ext <= stop_extent) { +if (stop_fsb >= got.br_startoff + got.br_blockcount) { error = -EIO ; goto del_cursor; } new_startoff = got.br_startoff + offset_shift_fsb; -if (current_ext < total_extents -1 ) { -xfs_iext_get_extent (ifp, current_ext +1 , &next); +if (xfs_iext_get_extent (ifp, current_ext +1 , &next)) {if (new_startoff + got.br_blockcount > next.br_startoff) { error = -EINVAL ; goto del_cursor;
@@ -5830,11 +5800,12 @@ xfs_bmap_insert_extents( cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; -if (--current_ext == stop_extent) { + +if (!xfs_iext_get_extent (ifp, --current_ext, &got) || + stop_fsb >= got.br_startoff + got.br_blockcount) { *done = true; goto del_cursor; } -xfs_iext_get_extent (ifp, current_ext, &got); *next_fsb = got.br_startoff; del_cursor:
Signature · 1 line
2.14.1
PATCH 15/15 xfs: rewrite xfs_bmap_first_unused to make better use of xfs_iext_get_extent
In reply to Christoph HellwigLook at the return value of xfs_iext_get_extent instead of figuring out the extent count first and looping up to it.
--- fs/xfs/libxfs/xfs_bmap.c | 56 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 30 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +26 -30
@@ -1285,57 +1285,53 @@ xfs_bmap_read_extents( }/* -* Returns the file-relative block number of the first unused block(s) -* in the file with at least "len" logically contiguous blocks free. -* This is the lowest-address hole if the file has holes, else the first block -* past the end of file. -* Return 0 if the file is currently local (in-inode). +* Returns the relative block number of the first unused block(s) in the given +* fork with at least "len" logically contiguous blocks free. This is the +* lowest-address hole if the fork has holes, else the first block past the end +* of fork. Return 0 if the fork is currently local (in-inode). */ int /* error */ xfs_bmap_first_unused ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode */ -xfs_extlen_t len,/* size of hole to find */ -xfs_fileoff_t *first_unused,/* unused block */ -int whichfork)/* data or attr fork */ +struct xfs_trans *tp,/* transaction pointer */ +struct xfs_inode *ip,/* incore inode */ +xfs_extlen_t len,/* size of hole to find */ +xfs_fileoff_t *first_unused,/* unused block */ +int whichfork)/* data or attr fork */ { -int error;/* error return value */ -int idx;/* extent record index */ -xfs_ifork_t *ifp;/* inode fork pointer */ -xfs_fileoff_t lastaddr;/* last block number seen */ -xfs_fileoff_t lowest;/* lowest useful block */ -xfs_fileoff_t max;/* starting useful block */ -xfs_extnum_t nextents;/* number of extent entries */ +struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +struct xfs_bmbt_irec got; +xfs_extnum_t idx =0 ; +xfs_fileoff_t lastaddr =0 ; +xfs_fileoff_t lowest, max; +int error;ASSERT (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_BTREE ||XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_EXTENTS ||XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_LOCAL ); +if (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_LOCAL ) { *first_unused =0 ;return 0 ; } - ifp =XFS_IFORK_PTR (ip, whichfork); -if (!(ifp->if_flags &XFS_IFEXTENTS ) && - (error =xfs_iread_extents (tp, ip, whichfork))) -return error; - lowest = *first_unused; - nextents =xfs_iext_count (ifp); -for (idx =0 , lastaddr =0 , max = lowest; idx < nextents; idx++) { -struct xfs_bmbt_irec got; -xfs_iext_get_extent (ifp, idx, &got); +if (!(ifp->if_flags &XFS_IFEXTENTS )) { + error =xfs_iread_extents (tp, ip, whichfork); +if (error) +return error; + } + lowest = max = *first_unused; +while (xfs_iext_get_extent (ifp, idx++, &got)) {/* * See if the hole before this extent will work. */ if (got.br_startoff >= lowest + len && - got.br_startoff - max >= len) { - *first_unused = max; -return 0 ; - } + got.br_startoff - max >= len) +break ; lastaddr = got.br_startoff + got.br_blockcount; max =XFS_FILEOFF_MAX (lastaddr, lowest); } + *first_unused = max;return 0 ; }
Signature · 1 line
2.14.1
Quoted 8 lines · Christoph Hellwig
Hi all,
This series contains another round of extent map related cleanups to prepare for the new incore extent list.
Because it is based on a huge number of outstanding (and reviewed) patches it might be a good idea to pull in the git tree for testing or detailed review:
Looks ok on first glance, will feed it to the testing cloud while I take a closer look this afternoon.
--D
Quoted 10 lines
git://git.infradead.org/users/hch/xfs.gitxfs-bmbt-cleanup.2Gitweb:
http://git.infradead.org/users/hch/xfs.git/shortlog/refs/heads/xfs-bmbt-cleanup.2
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 06/15] xfs: remove the never fully implemented UUID fork format
In reply to Christoph HellwigQuoted 2 lines · Christoph Hellwig
Remove the dead code dealing with the UUID fork format that was never implemented in Linux (and neither in IRIX as far as I know).
I think I need a little more context on this -- for what purpose was the UUID format created, and has it ever been used anywhere? When I was working on the ifork verifiers/scrub I noticed that we'd never actually accept anything with that format.
(I'm ok with removing it, I just want to know what I'm killing before I commit to it.)
--D
Quoted 280 lines
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/libxfs/xfs_attr_leaf.c | 6 +----- fs/xfs/libxfs/xfs_bmap.c | 4 ---- fs/xfs/libxfs/xfs_format.h | 2 +- fs/xfs/libxfs/xfs_inode_fork.c | 9 --------- fs/xfs/libxfs/xfs_inode_fork.h | 1 - fs/xfs/libxfs/xfs_log_format.h | 20 ++++++++++---------- fs/xfs/xfs_inode_item.c | 25 ++++++------------------- fs/xfs/xfs_itable.c | 1 - fs/xfs/xfs_log_recover.c | 10 +--------- 9 files changed, 19 insertions(+), 59 deletions(-)fs/xfs/libxfs/xfs_attr_leaf.c +1
-5@@ -397,13 +397,9 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)/* rounded down */ offset = (XFS_LITINO (mp, dp->i_d.di_version) - bytes) >>3 ; -switch (dp->i_d.di_format) { -case XFS_DINODE_FMT_DEV : +if (dp->i_d.di_format ==XFS_DINODE_FMT_DEV ) { minforkoff =roundup (sizeof (xfs_dev_t),8 ) >>3 ;return (offset >= minforkoff) ? minforkoff :0 ; -case XFS_DINODE_FMT_UUID : - minforkoff =roundup (sizeof (uuid_t),8 ) >>3 ; -return (offset >= minforkoff) ? minforkoff :0 ; }/* fs/xfs/libxfs/xfs_bmap.c +0
-4@@ -231,7 +231,6 @@ xfs_bmap_forkoff_reset( {if (whichfork ==XFS_ATTR_FORK && ip->i_d.di_format !=XFS_DINODE_FMT_DEV && - ip->i_d.di_format !=XFS_DINODE_FMT_UUID && ip->i_d.di_format !=XFS_DINODE_FMT_BTREE ) {uint dfl_forkoff =xfs_default_attroffset (ip) >>3 ;@@ -1086,9 +1085,6 @@ xfs_bmap_add_attrfork(case XFS_DINODE_FMT_DEV : ip->i_d.di_forkoff =roundup (sizeof (xfs_dev_t),8 ) >>3 ;break ; -case XFS_DINODE_FMT_UUID : - ip->i_d.di_forkoff =roundup (sizeof (uuid_t),8 ) >>3 ; -break ;case XFS_DINODE_FMT_LOCAL :case XFS_DINODE_FMT_EXTENTS :case XFS_DINODE_FMT_BTREE :fs/xfs/libxfs/xfs_format.h +1
-1@@ -941,7 +941,7 @@ typedef enum xfs_dinode_fmt {XFS_DINODE_FMT_LOCAL ,/* bulk data */ XFS_DINODE_FMT_EXTENTS ,/* struct xfs_bmbt_rec */ XFS_DINODE_FMT_BTREE ,/* struct xfs_bmdr_block */ - XFS_DINODE_FMT_UUID /* uuid_t */ + XFS_DINODE_FMT_UUID /* added long ago, but never used */ } xfs_dinode_fmt_t;/* fs/xfs/libxfs/xfs_inode_fork.c +0
-9@@ -902,15 +902,6 @@ xfs_iflush_fork( }break ; -case XFS_DINODE_FMT_UUID : -if (iip->ili_fields &XFS_ILOG_UUID ) { -ASSERT (whichfork ==XFS_DATA_FORK ); -memcpy (XFS_DFORK_DPTR (dip), - &ip->i_df.if_u2.if_uuid, -sizeof (uuid_t)); - } -break ; -default :ASSERT (0 );break ;fs/xfs/libxfs/xfs_inode_fork.h +0
-1@@ -70,7 +70,6 @@ typedef struct xfs_ifork {char if_inline_data[XFS_INLINE_DATA ];/* very small file data */ xfs_dev_t if_rdev;/* dev number if special */ -uuid_t if_uuid;/* mount point value */ } if_u2; } xfs_ifork_t;fs/xfs/libxfs/xfs_log_format.h +10
-10@@ -274,7 +274,7 @@ typedef struct xfs_inode_log_format {uint64_t ilf_ino;/* inode number */ union {uint32_t ilfu_rdev;/* rdev value for dev inode*/ -uuid_t ilfu_uuid;/* mount point value */ +u8 __pad[16 ];/* unused */ } ilf_u;int64_t ilf_blkno;/* blkno of inode buffer */ int32_t ilf_len;/* len of inode buffer */ @@ -295,7 +295,7 @@ struct xfs_inode_log_format_32 {uint64_t ilf_ino;/* inode number */ union {uint32_t ilfu_rdev;/* rdev value for dev inode*/ -uuid_t ilfu_uuid;/* mount point value */ +u8 __pad[16 ];/* unused */ } ilf_u;int64_t ilf_blkno;/* blkno of inode buffer */ int32_t ilf_len;/* len of inode buffer */ @@ -311,7 +311,7 @@ struct xfs_inode_log_format_32 {#define XFS_ILOG_DEXT 0x004/* log i_df.if_extents */ #define XFS_ILOG_DBROOT 0x008/* log i_df.i_broot */ #define XFS_ILOG_DEV 0x010/* log the dev field */ -#define XFS_ILOG_UUID 0x020/* log the uuid field */ +#define XFS_ILOG_UUID 0x020/* added long ago, but never used */ #define XFS_ILOG_ADATA 0x040/* log i_af.if_data */ #define XFS_ILOG_AEXT 0x080/* log i_af.if_extents */ #define XFS_ILOG_ABROOT 0x100/* log i_af.i_broot */ @@ -329,9 +329,9 @@ struct xfs_inode_log_format_32 {#define XFS_ILOG_NONCORE (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \ XFS_ILOG_DBROOT | XFS_ILOG_DEV | \ - XFS_ILOG_UUID | XFS_ILOG_ADATA | \ - XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \ - XFS_ILOG_DOWNER | XFS_ILOG_AOWNER) + XFS_ILOG_ADATA | XFS_ILOG_AEXT | \ + XFS_ILOG_ABROOT | XFS_ILOG_DOWNER | \ + XFS_ILOG_AOWNER)#define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \ XFS_ILOG_DBROOT)@@ -341,10 +341,10 @@ struct xfs_inode_log_format_32 {#define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \ XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \ - XFS_ILOG_DEV | XFS_ILOG_UUID | \ - XFS_ILOG_ADATA | XFS_ILOG_AEXT | \ - XFS_ILOG_ABROOT | XFS_ILOG_TIMESTAMP | \ - XFS_ILOG_DOWNER | XFS_ILOG_AOWNER) + XFS_ILOG_DEV | XFS_ILOG_ADATA | \ + XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \ + XFS_ILOG_TIMESTAMP | XFS_ILOG_DOWNER | \ + XFS_ILOG_AOWNER)static inline int xfs_ilog_fbroot (int w) {fs/xfs/xfs_inode_item.c +6
-19@@ -72,7 +72,6 @@ xfs_inode_item_data_fork_size(break ;case XFS_DINODE_FMT_DEV : -case XFS_DINODE_FMT_UUID :break ;default :ASSERT (0 );@@ -156,8 +155,7 @@ xfs_inode_item_format_data_fork(switch (ip->i_d.di_format) {case XFS_DINODE_FMT_EXTENTS : iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT | -XFS_ILOG_DEV |XFS_ILOG_UUID ); + ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT |XFS_ILOG_DEV ); if ((iip->ili_fields & XFS_ILOG_DEXT) && ip->i_d.di_nextents > 0 &&@@ -181,8 +179,7 @@ xfs_inode_item_format_data_fork(break ;case XFS_DINODE_FMT_BTREE : iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DEXT | -XFS_ILOG_DEV |XFS_ILOG_UUID ); + ~(XFS_ILOG_DDATA |XFS_ILOG_DEXT |XFS_ILOG_DEV );if ((iip->ili_fields &XFS_ILOG_DBROOT ) && ip->i_df.if_broot_bytes >0 ) {@@ -200,8 +197,7 @@ xfs_inode_item_format_data_fork(break ;case XFS_DINODE_FMT_LOCAL : iip->ili_fields &= - ~(XFS_ILOG_DEXT |XFS_ILOG_DBROOT | -XFS_ILOG_DEV |XFS_ILOG_UUID ); + ~(XFS_ILOG_DEXT |XFS_ILOG_DBROOT |XFS_ILOG_DEV );if ((iip->ili_fields &XFS_ILOG_DDATA ) && ip->i_df.if_bytes >0 ) {/* @@ -224,18 +220,10 @@ xfs_inode_item_format_data_fork(break ;case XFS_DINODE_FMT_DEV : iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT | -XFS_ILOG_DEXT |XFS_ILOG_UUID ); + ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT |XFS_ILOG_DEXT );if (iip->ili_fields &XFS_ILOG_DEV ) ilf->ilf_u.ilfu_rdev = ip->i_df.if_u2.if_rdev;break ; -case XFS_DINODE_FMT_UUID : - iip->ili_fields &= - ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT | -XFS_ILOG_DEXT |XFS_ILOG_DEV ); -if (iip->ili_fields &XFS_ILOG_UUID ) - ilf->ilf_u.ilfu_uuid = ip->i_df.if_u2.if_uuid; -break ;default :ASSERT (0 );break ;@@ -441,7 +429,7 @@ xfs_inode_item_format( ilf->ilf_dsize =0 ; ilf->ilf_asize =0 ; ilf->ilf_pad =0 ; -uuid_copy (&ilf->ilf_u.ilfu_uuid, &uuid_null); +memset (&ilf->ilf_u,0 ,sizeof (ilf->ilf_u));xlog_finish_iovec (lv, vecp,sizeof (*ilf));@@ -892,8 +880,7 @@ xfs_inode_item_format_convert( in_f->ilf_asize = in_f32->ilf_asize; in_f->ilf_dsize = in_f32->ilf_dsize; in_f->ilf_ino = in_f32->ilf_ino; -/* copy biggest field of ilf_u */ -uuid_copy (&in_f->ilf_u.ilfu_uuid, &in_f32->ilf_u.ilfu_uuid); +memcpy (&in_f->ilf_u, &in_f32->ilf_u,sizeof (in_f->ilf_u)); in_f->ilf_blkno = in_f32->ilf_blkno; in_f->ilf_len = in_f32->ilf_len; in_f->ilf_boffset = in_f32->ilf_boffset;fs/xfs/xfs_itable.c +0
-1@@ -124,7 +124,6 @@ xfs_bulkstat_one_int( buf->bs_blocks =0 ;break ;case XFS_DINODE_FMT_LOCAL : -case XFS_DINODE_FMT_UUID : buf->bs_rdev =0 ; buf->bs_blksize = mp->m_sb.sb_blocksize; buf->bs_blocks =0 ;fs/xfs/xfs_log_recover.c +1
-9@@ -3163,16 +3163,8 @@ xlog_recover_inode_pass2( } fields = in_f->ilf_fields; -switch (fields & (XFS_ILOG_DEV |XFS_ILOG_UUID )) { -case XFS_ILOG_DEV : +if (fields &XFS_ILOG_DEV )xfs_dinode_put_rdev (dip, in_f->ilf_u.ilfu_rdev); -break ; -case XFS_ILOG_UUID : -memcpy (XFS_DFORK_DPTR (dip), - &in_f->ilf_u.ilfu_uuid, -sizeof (uuid_t)); -break ; - }if (in_f->ilf_size ==2 ) goto out_owner_change;Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 01/15] xfs: add a xfs_bmap_fork_to_state helper
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
This creates the right initial bmap state from the passed in inode fork enum.
Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 174 lines
--- fs/xfs/libxfs/xfs_bmap.c | 45 +++++++++------------------------------------ fs/xfs/libxfs/xfs_bmap.h | 12 ++++++++++++ 2 files changed, 21 insertions(+), 36 deletions(-)fs/xfs/libxfs/xfs_bmap.c +9
-36@@ -499,12 +499,7 @@ xfs_bmap_trace_exlist( {xfs_extnum_t idx;/* extent record index */ xfs_ifork_t *ifp;/* inode fork pointer */ -int state =0 ; - -if (whichfork ==XFS_ATTR_FORK ) - state |=BMAP_ATTRFORK ; -else if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; +int state =xfs_bmap_fork_to_state (whichfork); ifp =XFS_IFORK_PTR (ip, whichfork);ASSERT (cnt ==xfs_iext_count (ifp));@@ -925,8 +920,7 @@ xfs_bmap_local_to_extents( rec.br_state =XFS_EXT_NORM ;xfs_iext_insert (ip,0 ,1 , &rec,0 ); -trace_xfs_bmap_post_update (ip,0 , - whichfork ==XFS_ATTR_FORK ?BMAP_ATTRFORK :0 , +trace_xfs_bmap_post_update (ip,0 ,xfs_bmap_fork_to_state (whichfork), _THIS_IP_);XFS_IFORK_NEXT_SET (ip, whichfork,1 ); ip->i_d.di_nblocks =1 ;@@ -1571,7 +1565,7 @@ xfs_bmap_add_extent_delay_real(xfs_bmbt_irec_t r[3 ];/* neighbor extent entries */ /* left is 0, right is 1, prev is 2 */ int rval=0 ;/* return value (logging flags) */ -int state =0 ;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);xfs_filblks_t da_new;/* new count del alloc blocks used */ xfs_filblks_t da_old;/* old count del alloc blocks used */ xfs_filblks_t temp=0 ;/* value for da_new calculations */ @@ -1598,9 +1592,6 @@ xfs_bmap_add_extent_delay_real(#define RIGHT r[1]#define PREV r[2] -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; -/* * Set up a bunch of variables to make the tests simpler. */ @@ -2108,7 +2099,7 @@ xfs_bmap_add_extent_unwritten_real(xfs_bmbt_irec_t r[3 ];/* neighbor extent entries */ /* left is 0, right is 1, prev is 2 */ int rval=0 ;/* return value (logging flags) */ -int state =0 ;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);struct xfs_mount *mp = ip->i_mount;struct xfs_bmbt_irec old;@@ -2116,8 +2107,6 @@ xfs_bmap_add_extent_unwritten_real( cur = *curp; ifp =XFS_IFORK_PTR (ip, whichfork); -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ;ASSERT (*idx >=0 );ASSERT (*idx <=xfs_iext_count (ifp));@@ -2601,13 +2590,10 @@ xfs_bmap_add_extent_hole_delay(xfs_filblks_t newlen=0 ;/* new indirect size */ xfs_filblks_t oldlen=0 ;/* old indirect size */ xfs_bmbt_irec_t right;/* right neighbor extent entry */ -int state;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);xfs_filblks_t temp;/* temp for indirect calculations */ ifp =XFS_IFORK_PTR (ip, whichfork); - state =0 ; -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ;ASSERT (isnullstartblock (new->br_startblock));/* @@ -2760,7 +2746,7 @@ xfs_bmap_add_extent_hole_real(xfs_bmbt_irec_t left;/* left neighbor extent entry */ xfs_bmbt_irec_t right;/* right neighbor extent entry */ int rval=0 ;/* return value (logging flags) */ -int state;/* state bits, accessed thru macros */ +int state =xfs_bmap_fork_to_state (whichfork);struct xfs_bmbt_irec old;ASSERT (*idx >=0 );@@ -2770,12 +2756,6 @@ xfs_bmap_add_extent_hole_real(XFS_STATS_INC (mp, xs_add_exlist); - state =0 ; -if (whichfork ==XFS_ATTR_FORK ) - state |=BMAP_ATTRFORK ; -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; -/* * Check and set flags if this segment has a left neighbor. */ @@ -4737,7 +4717,8 @@ xfs_bmap_del_extent_delay(int64_t da_old, da_new, da_diff =0 ;xfs_fileoff_t del_endoff, got_endoff;xfs_filblks_t got_indlen, new_indlen, stolen; -int error =0 , state =0 ; +int state =xfs_bmap_fork_to_state (whichfork); +int error =0 ;bool isrt;XFS_STATS_INC (mp, xs_del_exlist);@@ -4773,9 +4754,6 @@ xfs_bmap_del_extent_delay(return error; ip->i_delayed_blks -= del->br_blockcount; -if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; -if (got->br_startoff == del->br_startoff) state |=BMAP_LEFT_FILLING ;if (got_endoff == del_endoff)@@ -4969,17 +4947,12 @@ xfs_bmap_del_extent_real(xfs_bmbt_irec_t new;/* new record to be inserted */ /* REFERENCED */ uint qfield;/* quota field to update */ -int state =0 ; +int state =xfs_bmap_fork_to_state (whichfork);struct xfs_bmbt_irec old; mp = ip->i_mount;XFS_STATS_INC (mp, xs_del_exlist); -if (whichfork ==XFS_ATTR_FORK ) - state |=BMAP_ATTRFORK ; -else if (whichfork ==XFS_COW_FORK ) - state |=BMAP_COWFORK ; - ifp =XFS_IFORK_PTR (ip, whichfork);ASSERT ((*idx >=0 ) && (*idx <xfs_iext_count (ifp)));ASSERT (del->br_blockcount >0 );fs/xfs/libxfs/xfs_bmap.h +12
-0@@ -277,4 +277,16 @@ int xfs_bmap_map_extent(struct xfs_mount *mp, struct xfs_defer_ops *dfops,int xfs_bmap_unmap_extent (struct xfs_mount *mp,struct xfs_defer_ops *dfops,struct xfs_inode *ip,struct xfs_bmbt_irec *imap); +static inline int xfs_bmap_fork_to_state (int whichfork) +{ +switch (whichfork) { +case XFS_ATTR_FORK : +return BMAP_ATTRFORK ; +case XFS_COW_FORK : +return BMAP_COWFORK ; +default : +return 0 ; + } +} +#endif /* __XFS_BMAP_H__ */ Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 02/15] xfs: make better use of the 'state' variable in xfs_bmap_del_extent_real
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
We already have all the information about the fork aѕ well as additional tracing information, so pass that to
xfs_iext_remove().Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 25 lines
--- fs/xfs/libxfs/xfs_bmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/xfs/libxfs/xfs_bmap.c +1
-2@@ -5022,8 +5022,7 @@ xfs_bmap_del_extent_real(* Matches the whole extent. Delete the entry. */ trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_iext_remove (ip, *idx,1 , - whichfork ==XFS_ATTR_FORK ?BMAP_ATTRFORK :0 ); +xfs_iext_remove (ip, *idx,1 , state); --*idx; XFS_IFORK_NEXT_SET(ip, whichfork,Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 03/15] xfs: remove post-bmap tracing in xfs_bmap_local_to_extents
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Now that we use
xfs_iext_insertthis is already covered by the tracing in that function.Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 24 lines
--- fs/xfs/libxfs/xfs_bmap.c | 2 -- 1 file changed, 2 deletions(-)fs/xfs/libxfs/xfs_bmap.c +0
-2@@ -920,8 +920,6 @@ xfs_bmap_local_to_extents( rec.br_state =XFS_EXT_NORM ;xfs_iext_insert (ip,0 ,1 , &rec,0 ); -trace_xfs_bmap_post_update (ip,0 ,xfs_bmap_fork_to_state (whichfork), - _THIS_IP_);XFS_IFORK_NEXT_SET (ip, whichfork,1 ); ip->i_d.di_nblocks =1 ; xfs_trans_mod_dquot_byino(tp, ip,Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 04/15] xfs: move pre/post-bmap tracing into xfs_iext_update_extent
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
xfs_iext_update_extentalready has basically all the information needed to centralize the bmap pre/post tracing. We just need to pass inode + bmap state instead of the inode fork pointer to get all trace annotations.In addition to covering all the existing trace points this gives us tracing coverage for the extent shifting operations for free.
Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 603 lines
--- fs/xfs/libxfs/xfs_bmap.c | 167 ++++++++++++----------------------------- fs/xfs/libxfs/xfs_inode_fork.c | 7 +- fs/xfs/libxfs/xfs_inode_fork.h | 4 +- 3 files changed, 55 insertions(+), 123 deletions(-)fs/xfs/libxfs/xfs_bmap.c +47
-120@@ -1669,10 +1669,8 @@ xfs_bmap_add_extent_delay_real(* The left and right neighbors are both contiguous with new. */ bma->idx--; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount +RIGHT .br_blockcount; -xfs_iext_update_extent (ifp, bma->idx, &LEFT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &LEFT );xfs_iext_remove (bma->ip, bma->idx +1 ,2 , state); (*nextents)--;@@ -1706,10 +1704,8 @@ xfs_bmap_add_extent_delay_real( bma->idx--; old =LEFT ; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount; -xfs_iext_update_extent (ifp, bma->idx, &LEFT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &LEFT );xfs_iext_remove (bma->ip, bma->idx +1 ,1 , state);if (bma->cur ==NULL )@@ -1731,11 +1727,9 @@ xfs_bmap_add_extent_delay_real(* Filling in all of a previously delayed allocation extent. * The right neighbor is contiguous, the left is not. */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_startblock = new->br_startblock;PREV .br_blockcount +=RIGHT .br_blockcount; -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV );xfs_iext_remove (bma->ip, bma->idx +1 ,1 , state);if (bma->cur ==NULL )@@ -1758,11 +1752,9 @@ xfs_bmap_add_extent_delay_real(* Neither the left nor right neighbors are contiguous with * the new one. */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_startblock = new->br_startblock;PREV .br_state = new->br_state; -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV ); (*nextents)++;if (bma->cur ==NULL )@@ -1790,17 +1782,13 @@ xfs_bmap_add_extent_delay_real( da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp),startblockval (PREV .br_startblock)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx -1 , state, _THIS_IP_);LEFT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, bma->idx -1 , &LEFT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx -1 , state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx -1 , &LEFT ); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_blockcount = temp =PREV .br_blockcount - new->br_blockcount;PREV .br_startoff += new->br_blockcount;PREV .br_startblock =nullstartblock (da_new); -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV );if (bma->cur ==NULL ) rval =XFS_ILOG_DEXT ;@@ -1853,13 +1841,10 @@ xfs_bmap_add_extent_delay_real(startblockval (PREV .br_startblock) - (bma->cur ? bma->cur->bc_private.b.allocated : 0)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx +1 , state, _THIS_IP_);PREV .br_startoff = new_endoff;PREV .br_blockcount = temp;PREV .br_startblock =nullstartblock (da_new); -xfs_iext_update_extent (ifp, bma->idx +1 , &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx +1 , state, _THIS_IP_); - +xfs_iext_update_extent (bma->ip, state, bma->idx +1 , &PREV );break ;case BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG :@@ -1868,12 +1853,10 @@ xfs_bmap_add_extent_delay_real(* The right neighbor is contiguous with the new allocation. */ old =RIGHT ; -trace_xfs_bmap_pre_update (bma->ip, bma->idx +1 , state, _THIS_IP_);RIGHT .br_startoff = new->br_startoff;RIGHT .br_startblock = new->br_startblock;RIGHT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, bma->idx +1 , &RIGHT ); -trace_xfs_bmap_post_update (bma->ip, bma->idx +1 , state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx +1 , &RIGHT );if (bma->cur ==NULL ) rval =XFS_ILOG_DEXT ;@@ -1892,11 +1875,9 @@ xfs_bmap_add_extent_delay_real( da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp),startblockval (PREV .br_startblock)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_blockcount = temp;PREV .br_startblock =nullstartblock (da_new); -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV ); bma->idx++;break ;@@ -1936,11 +1917,9 @@ xfs_bmap_add_extent_delay_real(startblockval (PREV .br_startblock) - (bma->cur ? bma->cur->bc_private.b.allocated : 0)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_);PREV .br_startblock =nullstartblock (da_new);PREV .br_blockcount = temp; -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV ); bma->idx++;break ;@@ -1981,13 +1960,11 @@ xfs_bmap_add_extent_delay_real( RIGHT.br_blockcount));/* truncate PREV */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx,0 , _THIS_IP_);PREV .br_blockcount = new->br_startoff -PREV .br_startoff;PREV .br_startblock =nullstartblock (xfs_bmap_worst_indlen (bma->ip,PREV .br_blockcount)); -xfs_iext_update_extent (ifp, bma->idx, &PREV ); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +xfs_iext_update_extent (bma->ip, state, bma->idx, &PREV );/* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */ xfs_iext_insert (bma->ip, bma->idx +1 ,2 , &LEFT , state);@@ -2192,10 +2169,8 @@ xfs_bmap_add_extent_unwritten_real(*/ --*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount +RIGHT .br_blockcount; -xfs_iext_update_extent (ifp, *idx, &LEFT ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &LEFT );xfs_iext_remove (ip, *idx +1 ,2 , state); XFS_IFORK_NEXT_SET(ip, whichfork,@@ -2233,10 +2208,8 @@ xfs_bmap_add_extent_unwritten_real(*/ --*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);LEFT .br_blockcount +=PREV .br_blockcount; -xfs_iext_update_extent (ifp, *idx, &LEFT ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &LEFT );xfs_iext_remove (ip, *idx +1 ,1 , state); XFS_IFORK_NEXT_SET(ip, whichfork,@@ -2266,11 +2239,9 @@ xfs_bmap_add_extent_unwritten_real(* Setting all of a previous oldext extent to newext. * The right neighbor is contiguous, the left is not. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount +=RIGHT .br_blockcount;PREV .br_state = new->br_state; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV );xfs_iext_remove (ip, *idx +1 ,1 , state); XFS_IFORK_NEXT_SET(ip, whichfork,@@ -2301,10 +2272,8 @@ xfs_bmap_add_extent_unwritten_real(* Neither the left nor right neighbors are contiguous with * the new one. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_state = new->br_state; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV );if (cur ==NULL ) rval =XFS_ILOG_DEXT ;@@ -2325,18 +2294,14 @@ xfs_bmap_add_extent_unwritten_real(* Setting the first part of a previous oldext extent to newext. * The left neighbor is contiguous. */ -trace_xfs_bmap_pre_update (ip, *idx -1 , state, _THIS_IP_);LEFT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx -1 , &LEFT ); -trace_xfs_bmap_post_update (ip, *idx -1 , state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx -1 , &LEFT ); old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_startoff += new->br_blockcount;PREV .br_startblock += new->br_blockcount;PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); --*idx;@@ -2366,12 +2331,10 @@ xfs_bmap_add_extent_unwritten_real(* The left neighbor is not contiguous. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_startoff += new->br_blockcount;PREV .br_startblock += new->br_blockcount;PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV );xfs_iext_insert (ip, *idx,1 , new, state); XFS_IFORK_NEXT_SET(ip, whichfork,@@ -2400,19 +2363,15 @@ xfs_bmap_add_extent_unwritten_real(* The right neighbor is contiguous with the new allocation. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); ++*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);RIGHT .br_startoff = new->br_startoff;RIGHT .br_startblock = new->br_startblock;RIGHT .br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &RIGHT ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &RIGHT );if (cur ==NULL ) rval =XFS_ILOG_DEXT ;@@ -2440,10 +2399,8 @@ xfs_bmap_add_extent_unwritten_real(* The right neighbor is not contiguous. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount -= new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); ++*idx;xfs_iext_insert (ip, *idx,1 , new, state);@@ -2478,10 +2435,8 @@ xfs_bmap_add_extent_unwritten_real(* One extent becomes three extents. */ old =PREV ; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);PREV .br_blockcount = new->br_startoff -PREV .br_startoff; -xfs_iext_update_extent (ifp, *idx, &PREV ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &PREV ); r[0 ] = *new; r[1 ].br_startoff = new_endoff;@@ -2648,7 +2603,6 @@ xfs_bmap_add_extent_hole_delay( temp = left.br_blockcount + new->br_blockcount + right.br_blockcount; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); oldlen =startblockval (left.br_startblock) +startblockval (new->br_startblock) +startblockval (right.br_startblock);@@ -2656,8 +2610,7 @@ xfs_bmap_add_extent_hole_delay( oldlen); left.br_startblock =nullstartblock (newlen); left.br_blockcount = temp; -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);xfs_iext_remove (ip, *idx +1 ,1 , state);break ;@@ -2671,15 +2624,13 @@ xfs_bmap_add_extent_hole_delay( --*idx; temp = left.br_blockcount + new->br_blockcount; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); oldlen =startblockval (left.br_startblock) +startblockval (new->br_startblock); newlen =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (ip, temp), oldlen); left.br_blockcount = temp; left.br_startblock =nullstartblock (newlen); -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);break ;case BMAP_RIGHT_CONTIG :@@ -2688,7 +2639,6 @@ xfs_bmap_add_extent_hole_delay(* on the right. * Merge the new allocation with the right neighbor. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); temp = new->br_blockcount + right.br_blockcount; oldlen =startblockval (new->br_startblock) +startblockval (right.br_startblock);@@ -2697,8 +2647,7 @@ xfs_bmap_add_extent_hole_delay( right.br_startoff = new->br_startoff; right.br_startblock =nullstartblock (newlen); right.br_blockcount = temp; -xfs_iext_update_extent (ifp, *idx, &right); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &right);break ;case 0 :@@ -2808,10 +2757,8 @@ xfs_bmap_add_extent_hole_real(* Merge all three into a single extent record. */ --*idx; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); left.br_blockcount += new->br_blockcount + right.br_blockcount; -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);xfs_iext_remove (ip, *idx +1 ,1 , state);@@ -2847,10 +2794,9 @@ xfs_bmap_add_extent_hole_real(*/ --*idx; old = left; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); + left.br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &left); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &left);if (cur ==NULL ) { rval =xfs_ilog_fext (whichfork);@@ -2873,12 +2819,11 @@ xfs_bmap_add_extent_hole_real(* Merge the new allocation with the right neighbor. */ old = right; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); + right.br_startoff = new->br_startoff; right.br_startblock = new->br_startblock; right.br_blockcount += new->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &right); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &right);if (cur ==NULL ) { rval =xfs_ilog_fext (whichfork);@@ -4769,26 +4714,22 @@ xfs_bmap_del_extent_delay(/* * Deleting the first part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_startoff = del_endoff; got->br_blockcount -= del->br_blockcount; da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (ip, got->br_blockcount), da_old); got->br_startblock =nullstartblock ((int )da_new); -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case BMAP_RIGHT_FILLING :/* * Deleting the last part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_blockcount = got->br_blockcount - del->br_blockcount; da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (ip, got->br_blockcount), da_old); got->br_startblock =nullstartblock ((int )da_new); -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case 0 :/* @@ -4800,8 +4741,6 @@ xfs_bmap_del_extent_delay(* Warn if either of the new indlen reservations is zero as this * can lead to delalloc problems. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); - got->br_blockcount = del->br_startoff - got->br_startoff; got_indlen =xfs_bmap_worst_indlen (ip, got->br_blockcount);@@ -4813,8 +4752,7 @@ xfs_bmap_del_extent_delay( del->br_blockcount); got->br_startblock =nullstartblock ((int )got_indlen); -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx,0 , _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got); new.br_startoff = del_endoff; new.br_state = got->br_state;@@ -4879,30 +4817,24 @@ xfs_bmap_del_extent_cow(/* * Deleting the first part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_startoff = del_endoff; got->br_blockcount -= del->br_blockcount; got->br_startblock = del->br_startblock + del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case BMAP_RIGHT_FILLING :/* * Deleting the last part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_blockcount -= del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got);break ;case 0 :/* * Deleting the middle of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got->br_blockcount = del->br_startoff - got->br_startoff; -xfs_iext_update_extent (ifp, *idx, got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, got); new.br_startoff = del_endoff; new.br_blockcount = got_endoff - del_endoff;@@ -5019,7 +4951,6 @@ xfs_bmap_del_extent_real(/* * Matches the whole extent. Delete the entry. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_);xfs_iext_remove (ip, *idx,1 , state); --*idx;@@ -5038,12 +4969,10 @@ xfs_bmap_del_extent_real(/* * Deleting the first part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got.br_startoff = del_endoff; got.br_startblock = del_endblock; got.br_blockcount -= del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &got);if (!cur) { flags |=xfs_ilog_fext (whichfork);break ;@@ -5056,10 +4985,8 @@ xfs_bmap_del_extent_real(/* * Deleting the last part of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); got.br_blockcount -= del->br_blockcount; -xfs_iext_update_extent (ifp, *idx, &got); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +xfs_iext_update_extent (ip, state, *idx, &got);if (!cur) { flags |=xfs_ilog_fext (whichfork);break ;@@ -5072,11 +4999,10 @@ xfs_bmap_del_extent_real(/* * Deleting the middle of the extent. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); - old = got; + got.br_blockcount = del->br_startoff - got.br_startoff; -xfs_iext_update_extent (ifp, *idx, &got); +xfs_iext_update_extent (ip, state, *idx, &got); new.br_startoff = del_endoff; new.br_blockcount = got_endoff - del_endoff;@@ -5120,7 +5046,7 @@ xfs_bmap_del_extent_real(* Reset the extent record back * to the original value. */ -xfs_iext_update_extent (ifp, *idx, &old); +xfs_iext_update_extent (ip, state, *idx, &old); flags =0 ; error = -ENOSPC ; goto done;@@ -5130,7 +5056,6 @@ xfs_bmap_del_extent_real( flags |=xfs_ilog_fext (whichfork);XFS_IFORK_NEXT_SET (ip, whichfork,XFS_IFORK_NEXTENTS (ip, whichfork) +1 ); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_);xfs_iext_insert (ip, *idx +1 ,1 , &new, state); ++*idx;break ;@@ -5605,7 +5530,6 @@ xfs_bmse_merge(int *logflags,/* output */ struct xfs_defer_ops *dfops) { - struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork); struct xfs_bmbt_irec new;xfs_filblks_t blockcount;int error, i;@@ -5654,7 +5578,8 @@ xfs_bmse_merge(return error; done: -xfs_iext_update_extent (ifp, current_ext -1 , &new); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), + current_ext -1 , &new);xfs_iext_remove (ip, current_ext,1 ,0 );/* update reverse mapping. rmap functions merge the rmaps for us */ @@ -5772,7 +5697,8 @@ xfs_bmse_shift_one( *logflags |=XFS_ILOG_DEXT ; } -xfs_iext_update_extent (ifp, *current_ext, &new); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), + *current_ext, &new);if (direction ==SHIFT_LEFT ) (*current_ext)++;@@ -6019,7 +5945,8 @@ xfs_bmap_split_extent_at( } got.br_blockcount = gotblkcnt; -xfs_iext_update_extent (ifp, current_ext, &got); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), + current_ext, &got); logflags =XFS_ILOG_CORE ;if (cur) {fs/xfs/libxfs/xfs_inode_fork.c +6
-1@@ -2023,12 +2023,17 @@ xfs_iext_get_extent(void xfs_iext_update_extent ( -struct xfs_ifork *ifp, +struct xfs_inode *ip, +int state,xfs_extnum_t idx,struct xfs_bmbt_irec *gotp) { +struct xfs_ifork *ifp =xfs_iext_state_to_fork (ip, state); +ASSERT (idx >=0 );ASSERT (idx <xfs_iext_count (ifp)); +trace_xfs_bmap_pre_update (ip, idx, state, _RET_IP_);xfs_bmbt_set_all (xfs_iext_get_ext (ifp, idx), gotp); +trace_xfs_bmap_post_update (ip, idx, state, _RET_IP_); }fs/xfs/libxfs/xfs_inode_fork.h +2
-2@@ -187,8 +187,8 @@ bool xfs_iext_lookup_extent(struct xfs_inode *ip, xfs_extnum_t *idxp, struct xfs_bmbt_irec *gotp);bool xfs_iext_get_extent (struct xfs_ifork *ifp,xfs_extnum_t idx,struct xfs_bmbt_irec *gotp); -void xfs_iext_update_extent (struct xfs_ifork *ifp,xfs_extnum_t idx, -struct xfs_bmbt_irec *gotp); +void xfs_iext_update_extent (struct xfs_inode *ip,int state, +xfs_extnum_t idx,struct xfs_bmbt_irec *gotp);extern struct kmem_zone *xfs_ifork_zone;Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 05/15] xfs: remove XFS_BMAP_TRACE_EXLIST
In reply to Christoph HellwigQuoted 8 lines · Christoph Hellwig
Instead of looping over all extents in some debug-only helper just insert trace points into the loops that already exist in the calling functions.
Also split the
xfs_extlisttrace point into one each for reading and writing extents from disk.Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 154 lines
--- fs/xfs/libxfs/xfs_bmap.c | 23 ++--------------------- fs/xfs/libxfs/xfs_bmap.h | 9 --------- fs/xfs/libxfs/xfs_inode_fork.c | 8 ++++++-- fs/xfs/xfs_trace.h | 3 ++- 4 files changed, 10 insertions(+), 33 deletions(-)fs/xfs/libxfs/xfs_bmap.c +2
-21@@ -487,26 +487,6 @@ xfs_bmap_check_leaf_extents(return ; } -/* -* Add bmap trace insert entries for all the contents of the extent records. -*/ -void -xfs_bmap_trace_exlist ( -xfs_inode_t *ip,/* incore inode pointer */ -xfs_extnum_t cnt,/* count of entries in the list */ -int whichfork,/* data or attr or cow fork */ -unsigned long caller_ip) -{ -xfs_extnum_t idx;/* extent record index */ -xfs_ifork_t *ifp;/* inode fork pointer */ -int state =xfs_bmap_fork_to_state (whichfork); - - ifp =XFS_IFORK_PTR (ip, whichfork); -ASSERT (cnt ==xfs_iext_count (ifp)); -for (idx =0 ; idx < cnt; idx++) -trace_xfs_extlist (ip, idx, state, caller_ip); -} -/* * Validate that the bmbt_irecs being returned from bmapi are valid * given the caller's original parameters. Specifically check the @@ -1210,6 +1190,7 @@ xfs_bmap_read_extents(__be64 *pp;/* pointer to block address */ /* REFERENCED */ xfs_extnum_t room;/* number of entries there's room for */ +int state =xfs_bmap_fork_to_state (whichfork); mp = ip->i_mount; ifp =XFS_IFORK_PTR (ip, whichfork);@@ -1283,6 +1264,7 @@ xfs_bmap_read_extents( XFS_ERRLEVEL_LOW, mp); goto error0; } +trace_xfs_read_extent (ip, i, state, _THIS_IP_); }xfs_trans_brelse (tp, bp); bno = nextbno;@@ -1300,7 +1282,6 @@ xfs_bmap_read_extents(if (i !=XFS_IFORK_NEXTENTS (ip, whichfork))return -EFSCORRUPTED ;ASSERT (i ==xfs_iext_count (ifp)); -XFS_BMAP_TRACE_EXLIST (ip, i, whichfork);return 0 ; error0:xfs_trans_brelse (tp, bp);fs/xfs/libxfs/xfs_bmap.h +0
-9@@ -197,15 +197,6 @@ enum shift_direction { SHIFT_RIGHT, }; -#ifdef DEBUG -void xfs_bmap_trace_exlist (struct xfs_inode *ip,xfs_extnum_t cnt, -int whichfork,unsigned long caller_ip); -#define XFS_BMAP_TRACE_EXLIST (ip,c,w) \ - xfs_bmap_trace_exlist(ip,c,w, _THIS_IP_) -#else -#define XFS_BMAP_TRACE_EXLIST (ip,c,w) -#endif -void xfs_trim_extent (struct xfs_bmbt_irec *irec,xfs_fileoff_t bno,xfs_filblks_t len);int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd);fs/xfs/libxfs/xfs_inode_fork.c +6
-2@@ -336,6 +336,7 @@ xfs_iformat_extents( {struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, 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_bmbt_rec *dp;@@ -373,8 +374,8 @@ xfs_iformat_extents( XFS_ERRLEVEL_LOW, mp);return -EFSCORRUPTED ; } +trace_xfs_read_extent (ip, i, state, _THIS_IP_); } -XFS_BMAP_TRACE_EXLIST (ip, nex, whichfork); } ifp->if_flags |=XFS_IFEXTENTS ;return 0 ;@@ -772,6 +773,7 @@ xfs_iextents_copy(xfs_bmbt_rec_t *dp, int whichfork) { + int state = xfs_bmap_fork_to_state(whichfork);int copied;int i;xfs_ifork_t *ifp;@@ -783,7 +785,6 @@ xfs_iextents_copy(ASSERT (ifp->if_bytes >0 ); nrecs =xfs_iext_count (ifp); -XFS_BMAP_TRACE_EXLIST (ip, nrecs, whichfork);ASSERT (nrecs >0 );/* @@ -806,9 +807,12 @@ xfs_iextents_copy(continue ; } +trace_xfs_write_extent (ip, i, state, _RET_IP_); +/* Translate to on disk format */ put_unaligned_be64 (ep->l0, &dp->l0);put_unaligned_be64 (ep->l1, &dp->l1); + dp++; copied++; }fs/xfs/xfs_trace.h +2
-1@@ -309,7 +309,8 @@ DEFINE_EVENT(xfs_bmap_class, name, \DEFINE_BMAP_EVENT (xfs_iext_remove);DEFINE_BMAP_EVENT (xfs_bmap_pre_update);DEFINE_BMAP_EVENT (xfs_bmap_post_update); -DEFINE_BMAP_EVENT (xfs_extlist); +DEFINE_BMAP_EVENT (xfs_read_extent); +DEFINE_BMAP_EVENT (xfs_write_extent); DECLARE_EVENT_CLASS(xfs_buf_class, TP_PROTO(struct xfs_buf *bp, unsigned long caller_ip),Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 07/15] xfs: remove if_rdev
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
We can simply use the
i_rdevfield in the Linux inode and just convert to and from the XFSdev_twhen reading or logging/writing the inode.Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 262 lines
--- fs/xfs/libxfs/xfs_inode_fork.c | 38 +++++++++++++++++++++----------------- fs/xfs/libxfs/xfs_inode_fork.h | 1 - fs/xfs/xfs_inode.c | 9 ++++----- fs/xfs/xfs_inode.h | 4 ++-- fs/xfs/xfs_inode_item.c | 2 +- fs/xfs/xfs_iops.c | 16 +--------------- fs/xfs/xfs_itable.c | 2 +- 7 files changed, 30 insertions(+), 42 deletions(-)fs/xfs/libxfs/xfs_inode_fork.c +21
-17@@ -42,21 +42,27 @@ STATIC int xfs_iformat_local(xfs_inode_t *, xfs_dinode_t *, int, int); STATIC int xfs_iformat_extents(xfs_inode_t *, xfs_dinode_t *, int); STATIC int xfs_iformat_btree(xfs_inode_t *, xfs_dinode_t *, int); +static inline dev_t xfs_to_linux_dev_t (xfs_dev_t dev) +{ +return MKDEV (sysv_major (dev) &0x1ff ,sysv_minor (dev)); +} +/* -* Move inode type and inode format specific information from the -* on-disk inode to the in-core inode. For fifos, devs, and sockets -* this means set if_rdev to the proper value. For files, directories, -* and symlinks this means to bring in the in-line data or extent -* pointers. For a file in B-tree format, only the root is immediately -* brought in-core. The rest will be in-lined in if_extents when it -* is first referenced (see xfs_iread_extents()). +* Copy inode type and data and attr format specific information from the +* on-disk inode to the in-core inode and fork structures. For fifos, devices, +* and sockets this means set i_rdev to the proper value. For files, +* directories, and symlinks this means to bring in the in-line data or extent +* pointers as well as the attribute fork. For a fork in B-tree format, only +* the root is immediately brought in-core. The rest will be read in later when +* first referenced (see xfs_iread_extents()). */ int xfs_iformat_fork ( -xfs_inode_t *ip, -xfs_dinode_t *dip) +struct xfs_inode *ip, +struct xfs_dinode *dip) { -xfs_attr_shortform_t *atp; +struct inode *inode =VFS_I (ip); +struct xfs_attr_shortform *atp;int size;int error =0 ;xfs_fsize_t di_size;@@ -95,8 +101,7 @@ xfs_iformat_fork(return -EFSCORRUPTED ; } -if (unlikely (xfs_is_reflink_inode (ip) && - (VFS_I (ip)->i_mode &S_IFMT ) !=S_IFREG )) { +if (unlikely (xfs_is_reflink_inode (ip) && !S_ISREG (inode->i_mode))) {xfs_warn (ip->i_mount,"corrupt dinode %llu, wrong file type for reflink." , ip->i_ino);@@ -115,7 +120,7 @@ xfs_iformat_fork(return -EFSCORRUPTED ; } -switch (VFS_I (ip)->i_mode &S_IFMT ) { +switch (inode->i_mode &S_IFMT ) {case S_IFIFO :case S_IFCHR :case S_IFBLK :@@ -126,7 +131,7 @@ xfs_iformat_fork(return -EFSCORRUPTED ; } ip->i_d.di_size =0 ; - ip->i_df.if_u2.if_rdev =xfs_dinode_get_rdev (dip); + inode->i_rdev =xfs_to_linux_dev_t (xfs_dinode_get_rdev (dip));break ;case S_IFREG :@@ -184,8 +189,7 @@ xfs_iformat_fork(return error;/* Check inline dir contents. */ -if (S_ISDIR (VFS_I (ip)->i_mode) && - dip->di_format ==XFS_DINODE_FMT_LOCAL ) { +if (S_ISDIR (inode->i_mode) && dip->di_format ==XFS_DINODE_FMT_LOCAL ) { error =xfs_dir2_sf_verify (ip);if (error) {xfs_idestroy_fork (ip,XFS_DATA_FORK );@@ -898,7 +902,7 @@ xfs_iflush_fork(case XFS_DINODE_FMT_DEV :if (iip->ili_fields &XFS_ILOG_DEV ) {ASSERT (whichfork ==XFS_DATA_FORK ); -xfs_dinode_put_rdev (dip, ip->i_df.if_u2.if_rdev); +xfs_dinode_put_rdev (dip,sysv_encode_dev (VFS_I (ip)->i_rdev)); }break ;fs/xfs/libxfs/xfs_inode_fork.h +0
-1@@ -69,7 +69,6 @@ typedef struct xfs_ifork {/* very small file extents */ char if_inline_data[XFS_INLINE_DATA ];/* very small file data */ -xfs_dev_t if_rdev;/* dev number if special */ } if_u2; } xfs_ifork_t;fs/xfs/xfs_inode.c +4
-5@@ -767,7 +767,7 @@ xfs_ialloc(xfs_inode_t *pip, umode_t mode, xfs_nlink_t nlink, - xfs_dev_t rdev, + dev_t rdev, prid_t prid, int okalloc, xfs_buf_t **ialloc_context,@@ -819,6 +819,7 @@ xfs_ialloc(set_nlink (inode, nlink); ip->i_d.di_uid =xfs_kuid_to_uid (current_fsuid ()); ip->i_d.di_gid =xfs_kgid_to_gid (current_fsgid ()); + inode->i_rdev = rdev;xfs_set_projid (ip, prid);if (pip &&XFS_INHERIT_GID (pip)) {@@ -867,7 +868,6 @@ xfs_ialloc(case S_IFBLK :case S_IFSOCK : ip->i_d.di_format =XFS_DINODE_FMT_DEV ; - ip->i_df.if_u2.if_rdev = rdev; ip->i_df.if_flags =0 ; flags |=XFS_ILOG_DEV ;break ;@@ -975,7 +975,7 @@ xfs_dir_ialloc(the inode. */ umode_t mode, xfs_nlink_t nlink, - xfs_dev_t rdev, + dev_t rdev, prid_t prid, /* project id */ int okalloc, /* ok to allocate new space */ xfs_inode_t **ipp, /* pointer to inode; it will be@@ -1147,7 +1147,7 @@ xfs_create(xfs_inode_t *dp, struct xfs_name *name, umode_t mode, - xfs_dev_t rdev, + dev_t rdev, xfs_inode_t **ipp) { int is_dir = S_ISDIR(mode);@@ -1183,7 +1183,6 @@ xfs_create(return error;if (is_dir) { - rdev =0 ; resblks =XFS_MKDIR_SPACE_RES (mp, name->len); tres = &M_RES (mp)->tr_mkdir; }else {fs/xfs/xfs_inode.h +2
-2@@ -391,7 +391,7 @@ void xfs_inactive(struct xfs_inode *ip);int xfs_lookup (struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode **ipp,struct xfs_name *ci_name);int xfs_create (struct xfs_inode *dp,struct xfs_name *name, -umode_t mode,xfs_dev_t rdev,struct xfs_inode **ipp); +umode_t mode,dev_t rdev,struct xfs_inode **ipp);int xfs_create_tmpfile (struct xfs_inode *dp,struct dentry *dentry,umode_t mode,struct xfs_inode **ipp); int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,@@ -428,7 +428,7 @@ xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);xfs_extlen_t xfs_get_cowextsz_hint (struct xfs_inode *ip);int xfs_dir_ialloc (struct xfs_trans **,struct xfs_inode *,umode_t , -xfs_nlink_t ,xfs_dev_t ,prid_t ,int , +xfs_nlink_t ,dev_t ,prid_t ,int ,struct xfs_inode **,int *);/* from xfs_file.c */ fs/xfs/xfs_inode_item.c +1
-1@@ -222,7 +222,7 @@ xfs_inode_item_format_data_fork( iip->ili_fields &= ~(XFS_ILOG_DDATA |XFS_ILOG_DBROOT |XFS_ILOG_DEXT );if (iip->ili_fields &XFS_ILOG_DEV ) - ilf->ilf_u.ilfu_rdev = ip->i_df.if_u2.if_rdev; + ilf->ilf_u.ilfu_rdev =sysv_encode_dev (VFS_I (ip)->i_rdev);break ;default :ASSERT (0 );fs/xfs/xfs_iops.c +1
-15@@ -160,7 +160,6 @@ xfs_generic_create(if (S_ISCHR (mode) ||S_ISBLK (mode)) {if (unlikely (!sysv_valid_dev (rdev) ||MAJOR (rdev) & ~0x1ff ))return -EINVAL ; - rdev =sysv_encode_dev (rdev); }else { rdev =0 ; }@@ -535,8 +534,7 @@ xfs_vn_getattr(case S_IFBLK :case S_IFCHR : stat->blksize =BLKDEV_IOSIZE ; - stat->rdev =MKDEV (sysv_major (ip->i_df.if_u2.if_rdev) &0x1ff , -sysv_minor (ip->i_df.if_u2.if_rdev)); + stat->rdev = inode->i_rdev;break ;default :if (XFS_IS_REALTIME_INODE (ip)) {@@ -1231,18 +1229,6 @@ xfs_setup_inode( inode->i_uid =xfs_uid_to_kuid (ip->i_d.di_uid); inode->i_gid =xfs_gid_to_kgid (ip->i_d.di_gid); -switch (inode->i_mode &S_IFMT ) { -case S_IFBLK : -case S_IFCHR : - inode->i_rdev = -MKDEV (sysv_major (ip->i_df.if_u2.if_rdev) &0x1ff , -sysv_minor (ip->i_df.if_u2.if_rdev)); -break ; -default : - inode->i_rdev =0 ; -break ; - } -i_size_write (inode, ip->i_d.di_size);xfs_diflags_to_iflags (inode, ip);fs/xfs/xfs_itable.c +1
-1@@ -119,7 +119,7 @@ xfs_bulkstat_one_int(switch (dic->di_format) {case XFS_DINODE_FMT_DEV : - buf->bs_rdev = ip->i_df.if_u2.if_rdev; + buf->bs_rdev =sysv_encode_dev (inode->i_rdev); buf->bs_blksize =BLKDEV_IOSIZE ; buf->bs_blocks =0 ;break ;Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 06/15] xfs: remove the never fully implemented UUID fork format
In reply to Darrick J. WongQuoted 11 lines · Darrick J. Wong
Quoted 2 lines · Christoph Hellwig
Remove the dead code dealing with the UUID fork format that was never implemented in Linux (and neither in IRIX as far as I know).
I think I need a little more context on this -- for what purpose was the UUID format created, and has it ever been used anywhere? When I was working on the ifork verifiers/scrub I noticed that we'd never actually accept anything with that format.
(I'm ok with removing it, I just want to know what I'm killing before I commit to it.)
For that you'd need to find people that were around at SGI in the 90s..
Note that we already removed it briefly in 2008, but unlike my patch that didn't keep the padding so broken log recovery.
relevant xfs-import commits:
Commit that adds the di_format values:c049a3e8d776a76a1ba3adaf168a406a8ee52172
then various commits in early development add UUID inode format bits, but none seems to actually ever generate it.
1st removal with minor comments on the history:415c805b441845dfc2be7d887f995ea8875358e9
Revert of the above:4ddd5953fad77a14f665fefa06899ef9f388b134
Darrick J. Wong
Reviewed-byRe: [PATCH 06/15] xfs: remove the never fully implemented UUID fork format
Quoted 20 lines · Christoph Hellwig
Quoted 11 lines · Darrick J. Wong
Quoted 2 lines · Christoph Hellwig
Remove the dead code dealing with the UUID fork format that was never implemented in Linux (and neither in IRIX as far as I know).
I think I need a little more context on this -- for what purpose was the UUID format created, and has it ever been used anywhere? When I was working on the ifork verifiers/scrub I noticed that we'd never actually accept anything with that format.
(I'm ok with removing it, I just want to know what I'm killing before I commit to it.)
For that you'd need to find people that were around at SGI in the 90s..
Note that we already removed it briefly in 2008, but unlike my patch that didn't keep the padding so broken log recovery.
relevant xfs-import commits:
Quoted 8 lines
Commit that adds the
di_formatvalues:c049a3e8d776a76a1ba3adaf168a406a8ee52172then various commits in early development add UUID inode format bits, but none seems to actually ever generate it.
1st removal with minor comments on the history:
415c805b441845dfc2be7d887f995ea8875358e9
Yummmmmmmmmy!
Looks ok,
--D
Quoted 7 lines
Revert of the above:
4ddd5953fad77a14f665fefa06899ef9f388b134
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 08/15] xfs: inline xfs_shift_file_space into callers
In reply to Christoph HellwigQuoted 120 lines · Christoph Hellwig
The code is sufficiently different for the insert vs collapse cases both in
xfs_shift_file_spaceitself and the callers that untangling them will make life a lot easier down the road.We still keep a common helper for flushing all data and COW state to get the inode into the right shape for shifting the extents around.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/xfs_bmap_util.c | 192 ++++++++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 90 deletions(-)fs/xfs/xfs_bmap_util.c +27
-56@@ -1260,53 +1260,12 @@ xfs_zero_file_space( } -/* -* @next_fsb will keep track of the extent currently undergoing shift. -* @stop_fsb will keep track of the extent at which we have to stop. -* If we are shifting left, we will start with block (offset + len) and -* shift each extent till last extent. -* If we are shifting right, we will start with last extent inside file space -* and continue until we reach the block corresponding to offset. -*/ static int -xfs_shift_file_space ( -struct xfs_inode *ip, -xfs_off_t offset, -xfs_off_t len, -enum shift_direction direction) +xfs_prepare_shift ( +struct xfs_inode *ip, +loff_t offset) { -int done =0 ; -struct xfs_mount *mp = ip->i_mount; -struct xfs_trans *tp;int error; -struct xfs_defer_ops dfops; -xfs_fsblock_t first_block; -xfs_fileoff_t stop_fsb; -xfs_fileoff_t next_fsb; -xfs_fileoff_t shift_fsb; -uint resblks; - -ASSERT (direction ==SHIFT_LEFT || direction ==SHIFT_RIGHT ); - -if (direction ==SHIFT_LEFT ) { -/* -* Reserve blocks to cover potential extent merges after left -* shift operations. -*/ - resblks =XFS_DIOSTRAT_SPACE_RES (mp,0 ); - next_fsb =XFS_B_TO_FSB (mp, offset + len); - stop_fsb =XFS_B_TO_FSB (mp,VFS_I (ip)->i_size); - }else { -/* -* If right shift, delegate the work of initialization of -* next_fsb to xfs_bmap_shift_extent as it has ilock held. -*/ - resblks =0 ; - next_fsb =NULLFSBLOCK ; - stop_fsb =XFS_B_TO_FSB (mp, offset); - } - - shift_fsb =XFS_B_TO_FSB (mp, len);/* * Trim eofblocks to avoid shifting uninitialized post-eof preallocation @@ -1322,8 +1281,7 @@ xfs_shift_file_space(* Writeback and invalidate cache for the remainder of the file as we're * about to shift down every extent from offset to EOF. */ - error =filemap_write_and_wait_range (VFS_I (ip)->i_mapping, - offset,-1 ); + error =filemap_write_and_wait_range (VFS_I (ip)->i_mapping, offset,-1 );if (error)return error; error = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping,@@ -1343,16 +1301,48 @@ xfs_shift_file_space(return error; } -/* -* The extent shifting code works on extent granularity. So, if -* stop_fsb is not the starting block of extent, we need to split -* the extent at stop_fsb. -*/ -if (direction ==SHIFT_RIGHT ) { - error =xfs_bmap_split_extent (ip, stop_fsb); -if (error) -return error; - } +return 0 ; +} + +/* +* xfs_collapse_file_space() +* This routine frees disk space and shift extent for the given file. +* The first thing we do is to free data blocks in the specified range +* by calling xfs_free_file_space(). It would also sync dirty data +* and invalidate page cache over the region on which collapse range +* is working. And Shift extent records to the left to cover a hole. +* RETURNS: +* 0 on success +* errno on error +* +*/ +int +xfs_collapse_file_space ( +struct xfs_inode *ip, +xfs_off_t offset, +xfs_off_t len) +{ +int done =0 ; +struct xfs_mount *mp = ip->i_mount;
fs/xfs/xfs_bmap_util.c xfs_shift_file_space( · line 1336
Quoted 10 lines
fs/xfs/xfs_bmap_util.c +10
-0+struct xfs_trans *tp; +int error; +struct xfs_defer_ops dfops; +xfs_fsblock_t first_block; +xfs_fileoff_t stop_fsb =XFS_B_TO_FSB (mp,VFS_I (ip)->i_size); +xfs_fileoff_t next_fsb =XFS_B_TO_FSB (mp, offset + len); +xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len); +uint resblks =XFS_DIOSTRAT_SPACE_RES (mp,0 ); + +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));
So it took me a while of wondering "don't we have to have the MMAPLOCK_EXCL too?" before realizing that yes, the caller actually does grab that too. I wonder if it's worth checking here, since you're asserting the lock status at all?
Aside from that,
Quoted 146 lines
fs/xfs/xfs_bmap_util.c +65
-34+trace_xfs_collapse_file_space (ip); + + error =xfs_free_file_space (ip, offset, len); +if (error) +return error; + + error =xfs_prepare_shift (ip, offset); +if (error) +return error;while (!error && !done) { error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0,@@ -1366,7 +1356,6 @@ xfs_shift_file_space( XFS_QMOPT_RES_REGBLKS);if (error) goto out_trans_cancel; -xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block);@@ -1377,14 +1366,13 @@ xfs_shift_file_space(*/ error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, &done, stop_fsb, &first_block, &dfops, - direction,XFS_BMAP_MAX_SHIFT_EXTENTS ); +SHIFT_LEFT ,XFS_BMAP_MAX_SHIFT_EXTENTS );if (error) goto out_bmap_cancel; error =xfs_defer_finish (&tp, &dfops);if (error) goto out_bmap_cancel; - error =xfs_trans_commit (tp); }@@ -1397,36 +1385,6 @@ xfs_shift_file_space(return error; } -/* -* xfs_collapse_file_space() -* This routine frees disk space and shift extent for the given file. -* The first thing we do is to free data blocks in the specified range -* by calling xfs_free_file_space(). It would also sync dirty data -* and invalidate page cache over the region on which collapse range -* is working. And Shift extent records to the left to cover a hole. -* RETURNS: -* 0 on success -* errno on error -* -*/ -int -xfs_collapse_file_space ( -struct xfs_inode *ip, -xfs_off_t offset, -xfs_off_t len) -{ -int error; - -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL )); -trace_xfs_collapse_file_space (ip); - - error =xfs_free_file_space (ip, offset, len); -if (error) -return error; - -return xfs_shift_file_space (ip, offset, len,SHIFT_LEFT ); -} -/* * xfs_insert_file_space() * This routine create hole space by shifting extents for the given file. @@ -1445,10 +1403,64 @@ xfs_insert_file_space( loff_t offset, loff_t len) { +struct xfs_mount *mp = ip->i_mount; +struct xfs_trans *tp; +int error; +struct xfs_defer_ops dfops; +xfs_fsblock_t first_block; +xfs_fileoff_t stop_fsb =XFS_B_TO_FSB (mp, offset); +xfs_fileoff_t next_fsb =NULLFSBLOCK ; +xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len); +int done =0 ; +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));trace_xfs_insert_file_space (ip); -return xfs_shift_file_space (ip, offset, len,SHIFT_RIGHT ); + error =xfs_prepare_shift (ip, offset); +if (error) +return error; + +/* +* The extent shifting code works on extent granularity. So, if stop_fsb +* is not the starting block of extent, we need to split the extent at +* stop_fsb. +*/ + error =xfs_bmap_split_extent (ip, stop_fsb); +if (error) +return error; + +while (!error && !done) { + error =xfs_trans_alloc (mp, &M_RES (mp)->tr_write,0 ,0 ,0 , + &tp); +if (error) +break ; + +xfs_ilock (ip,XFS_ILOCK_EXCL ); +xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_defer_init (&dfops, &first_block); + +/* +* We are using the write transaction in which max 2 bmbt +* updates are allowed +*/ + error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, + &done, stop_fsb, &first_block, &dfops, +SHIFT_RIGHT ,XFS_BMAP_MAX_SHIFT_EXTENTS ); +if (error) + goto out_bmap_cancel; + + error =xfs_defer_finish (&tp, &dfops); +if (error) + goto out_bmap_cancel; + error =xfs_trans_commit (tp); + } + +return error; + +out_bmap_cancel: +xfs_defer_cancel (&dfops); +xfs_trans_cancel (tp); +return error; }/* Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 09/15] xfs: remove XFS_BMAP_MAX_SHIFT_EXTENTS
In reply to Christoph HellwigQuoted 60 lines · Christoph Hellwig
The define was always set to 1, which means looping until we reach is was dead code from the start.
Also remove an initialization of
next_fsbfor the done case that doesn't fit the new code flow - it was never checked by the caller in the done case to start with.Signed-off-by Christoph Hellwig <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 47 ++++++++++++++++++++--------------------------- fs/xfs/libxfs/xfs_bmap.h | 12 +----------- fs/xfs/xfs_bmap_util.c | 14 ++------------ 3 files changed, 23 insertions(+), 50 deletions(-)fs/xfs/libxfs/xfs_bmap.c +2
-17@@ -5692,8 +5692,7 @@ xfs_bmse_shift_one(/* * Shift extent records to the left/right to cover/create a hole. * -* The maximum number of extents to be shifted in a single operation is -* @num_exts. @stop_fsb specifies the file offset at which to stop shift and the +* @stop_fsb specifies the file offset at which to stop shift and the * file offset where we've left off is returned in @next_fsb. @offset_shift_fsb * is the length by which each extent is shifted. If there is no hole to shift * the extents into, this will be considered invalid operation and we abort @@ -5709,14 +5708,12 @@ xfs_bmap_shift_extents(xfs_fileoff_t stop_fsb, xfs_fsblock_t *firstblock, struct xfs_defer_ops *dfops, - enum shift_direction direction, - int num_exts) + enum shift_direction direction) { struct xfs_btree_cur *cur = NULL;struct xfs_bmbt_irec got;struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp; -xfs_extnum_t nexts =0 ;xfs_extnum_t current_ext;xfs_extnum_t total_extents;xfs_extnum_t stop_extent;@@ -5814,31 +5811,27 @@ xfs_bmap_shift_extents( } } -while (nexts++ < num_exts) { - error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, - ¤t_ext, &got, cur, &logflags, - direction, dfops); -if (error) - goto del_cursor; -/* -* If there was an extent merge during the shift, the extent -* count can change. Update the total and grade the next record. -*/ -if (direction ==SHIFT_LEFT ) { - total_extents =xfs_iext_count (ifp);
fs/xfs/libxfs/xfs_bmap.c xfs_bmap_shift_extents( · line 5821
Quoted 10 lines
fs/xfs/libxfs/xfs_bmap.c +8
-2- stop_extent = total_extents; - } + error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, + ¤t_ext, &got, cur, &logflags, + direction, dfops); +if (error) + goto del_cursor; +/* +* If there was an extent merge during the shift, the extent +* count can change. Update the total and grade the next record.
/me wonders what "grade the next record" means, but afaict this comment disappears anyway...
--D
Quoted 97 lines
fs/xfs/libxfs/xfs_bmap.c +10
-8+*/ +if (direction ==SHIFT_LEFT ) { + total_extents =xfs_iext_count (ifp); + stop_extent = total_extents; + } -if (current_ext == stop_extent) { - *done =1 ; - *next_fsb =NULLFSBLOCK ; -break ; - } -xfs_iext_get_extent (ifp, current_ext, &got); +if (current_ext == stop_extent) { + *done =1 ; + goto del_cursor; } +xfs_iext_get_extent (ifp, current_ext, &got); -if (!*done) - *next_fsb = got.br_startoff; + *next_fsb = got.br_startoff; del_cursor:if (cur)fs/xfs/libxfs/xfs_bmap.h +1
-11@@ -183,15 +183,6 @@ static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec) !isnullstartblock (irec->br_startblock); } -/* -* This macro is used to determine how many extents will be shifted -* in one write transaction. We could require two splits, -* an extent move on the first and an extent merge on the second, -* So it is proper that one extent is shifted inside write transaction -* at a time. -*/ -#define XFS_BMAP_MAX_SHIFT_EXTENTS 1 -enum shift_direction {SHIFT_LEFT =0 ,SHIFT_RIGHT ,@@ -239,8 +230,7 @@ uint xfs_default_attroffset(struct xfs_inode *ip);int xfs_bmap_shift_extents (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb,int *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, -struct xfs_defer_ops *dfops,enum shift_direction direction, -int num_exts); +struct xfs_defer_ops *dfops,enum shift_direction direction);int xfs_bmap_split_extent (struct xfs_inode *ip,xfs_fileoff_t split_offset); int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork, xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,fs/xfs/xfs_bmap_util.c +2
-12@@ -1359,14 +1359,9 @@ xfs_collapse_file_space(xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - -/* -* We are using the write transaction in which max 2 bmbt -* updates are allowed -*/ error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, &done, stop_fsb, &first_block, &dfops, -SHIFT_LEFT ,XFS_BMAP_MAX_SHIFT_EXTENTS ); +SHIFT_LEFT );if (error) goto out_bmap_cancel;@@ -1438,14 +1433,9 @@ xfs_insert_file_space(xfs_ilock (ip,XFS_ILOCK_EXCL );xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - -/* -* We are using the write transaction in which max 2 bmbt -* updates are allowed -*/ error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, &done, stop_fsb, &first_block, &dfops, -SHIFT_RIGHT ,XFS_BMAP_MAX_SHIFT_EXTENTS ); +SHIFT_RIGHT );if (error) goto out_bmap_cancel;Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 10/15] xfs: split xfs_bmap_shift_extents
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Have a separate helper for insert vs collapse, as this prepares us for simplifying the code in the next patches.
Also changed the done output argument to a bool intead of int for both new functions.
Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 353 lines
--- fs/xfs/libxfs/xfs_bmap.c | 197 ++++++++++++++++++++++++++++++++--------------- fs/xfs/libxfs/xfs_bmap.h | 10 ++- fs/xfs/xfs_bmap_util.c | 14 ++-- 3 files changed, 148 insertions(+), 73 deletions(-)fs/xfs/libxfs/xfs_bmap.c +135
-62@@ -5689,57 +5689,151 @@ xfs_bmse_shift_one(return xfs_rmap_map_extent (mp, dfops, ip, whichfork, &new); } -/* -* Shift extent records to the left/right to cover/create a hole. -* -* @stop_fsb specifies the file offset at which to stop shift and the -* file offset where we've left off is returned in @next_fsb. @offset_shift_fsb -* is the length by which each extent is shifted. If there is no hole to shift -* the extents into, this will be considered invalid operation and we abort -* immediately. -*/ int -xfs_bmap_shift_extents ( +xfs_bmap_collapse_extents (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb, -int *done, +bool *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, -struct xfs_defer_ops *dfops, -enum shift_direction direction) +struct xfs_defer_ops *dfops) { -struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got; -struct xfs_mount *mp = ip->i_mount; -struct xfs_ifork *ifp; -xfs_extnum_t current_ext; -xfs_extnum_t total_extents; -xfs_extnum_t stop_extent; -int error =0 ; -int whichfork =XFS_DATA_FORK ; -int logflags =0 ; +int whichfork =XFS_DATA_FORK ; +struct xfs_mount *mp = ip->i_mount; +struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +struct xfs_btree_cur *cur =NULL ; +struct xfs_bmbt_irec got; +xfs_extnum_t current_ext; +xfs_extnum_t total_extents; +xfs_extnum_t stop_extent; +int error =0 ; +int logflags =0 ;if (unlikely (XFS_TEST_ERROR ( (XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_EXTENTS &&XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_BTREE ), mp,XFS_ERRTAG_BMAPIFORMAT ))) { -XFS_ERROR_REPORT ("xfs_bmap_shift_extents" , -XFS_ERRLEVEL_LOW , mp); +XFS_ERROR_REPORT (__func__,XFS_ERRLEVEL_LOW , mp);return -EFSCORRUPTED ; }if (XFS_FORCED_SHUTDOWN (mp))return -EIO ; -ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL )); -ASSERT (xfs_isilocked (ip,XFS_ILOCK_EXCL )); -ASSERT (direction ==SHIFT_LEFT || direction ==SHIFT_RIGHT ); +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL )); + +if (!(ifp->if_flags &XFS_IFEXTENTS )) { + error =xfs_iread_extents (tp, ip, whichfork); +if (error) +return error; + } + +if (ifp->if_flags &XFS_IFBROOT ) { + cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); + cur->bc_private.b.firstblock = *firstblock; + cur->bc_private.b.dfops = dfops; + cur->bc_private.b.flags =0 ; + } + +/* +* There may be delalloc extents in the data fork before the range we +* are collapsing out, so we cannot use the count of real extents here. +* Instead we have to calculate it from the incore fork. +*/ + total_extents =xfs_iext_count (ifp); +if (total_extents ==0 ) { + *done = true; + goto del_cursor; + } + +/* +* Look up the extent index for the fsb where we start shifting. We can +* henceforth iterate with current_ext as extent list changes are locked +* out via ilock. +* +* If next_fsb lies in a hole beyond which there are no extents we are +* done. +*/ +if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { + *done = true; + goto del_cursor; + } + + stop_extent = total_extents; +if (current_ext >= stop_extent) { + error = -EIO ; + goto del_cursor; + } + + error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, + ¤t_ext, &got, cur, &logflags, +SHIFT_LEFT , dfops); +if (error) + goto del_cursor; +/* +* If there was an extent merge during the shift, the extent +* count can change. Update the total and grade the next record. +*/ + total_extents =xfs_iext_count (ifp); + stop_extent = total_extents; +if (current_ext == stop_extent) { + *done = true; + goto del_cursor; + } +xfs_iext_get_extent (ifp, current_ext, &got); + +if (!*done) + *next_fsb = got.br_startoff; + +del_cursor: +if (cur) +xfs_btree_del_cursor (cur, + error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); + +if (logflags) +xfs_trans_log_inode (tp, ip, logflags); + +return error; +} + +int +xfs_bmap_insert_extents ( +struct xfs_trans *tp, +struct xfs_inode *ip, +xfs_fileoff_t *next_fsb, +xfs_fileoff_t offset_shift_fsb, +bool *done, +xfs_fileoff_t stop_fsb, +xfs_fsblock_t *firstblock, +struct xfs_defer_ops *dfops) +{ +int whichfork =XFS_DATA_FORK ; +struct xfs_mount *mp = ip->i_mount; +struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +struct xfs_btree_cur *cur =NULL ; +struct xfs_bmbt_irec got, s; +xfs_extnum_t current_ext; +xfs_extnum_t total_extents; +xfs_extnum_t stop_extent; +int error =0 ; +int logflags =0 ; + +if (unlikely (XFS_TEST_ERROR ( + (XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_EXTENTS && +XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_BTREE ), + mp,XFS_ERRTAG_BMAPIFORMAT ))) { +XFS_ERROR_REPORT (__func__,XFS_ERRLEVEL_LOW , mp); +return -EFSCORRUPTED ; + } + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + +ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL )); - ifp =XFS_IFORK_PTR (ip, whichfork);if (!(ifp->if_flags &XFS_IFEXTENTS )) { -/* Read in all the extents */ error =xfs_iread_extents (tp, ip, whichfork);if (error)return error;@@ -5759,7 +5853,7 @@ xfs_bmap_shift_extents(*/ total_extents =xfs_iext_count (ifp);if (total_extents ==0 ) { - *done =1 ; + *done = true; goto del_cursor; }@@ -5767,12 +5861,10 @@ xfs_bmap_shift_extents(* In case of first right shift, we need to initialize next_fsb */ if (*next_fsb ==NULLFSBLOCK ) { -ASSERT (direction ==SHIFT_RIGHT ); - current_ext = total_extents -1 ;xfs_iext_get_extent (ifp, current_ext, &got);if (stop_fsb > got.br_startoff) { - *done =1 ; + *done = true; goto del_cursor; } *next_fsb = got.br_startoff;@@ -5787,46 +5879,27 @@ xfs_bmap_shift_extents(*/ if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { - *done =1 ; + *done = true; goto del_cursor; } }/* Lookup the extent index at which we have to stop */ -if (direction ==SHIFT_RIGHT ) { -struct xfs_bmbt_irec s; - -xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s); -/* Make stop_extent exclusive of shift range */ - stop_extent--; -if (current_ext <= stop_extent) { - error = -EIO ; - goto del_cursor; - } - }else { - stop_extent = total_extents; -if (current_ext >= stop_extent) { - error = -EIO ; - goto del_cursor; - } +xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s); +/* Make stop_extent exclusive of shift range */ + stop_extent--; +if (current_ext <= stop_extent) { + error = -EIO ; + goto del_cursor; } error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, ¤t_ext, &got, cur, &logflags, - direction, dfops); +SHIFT_RIGHT , dfops);if (error) goto del_cursor; -/* -* If there was an extent merge during the shift, the extent -* count can change. Update the total and grade the next record. -*/ -if (direction ==SHIFT_LEFT ) { - total_extents =xfs_iext_count (ifp); - stop_extent = total_extents; - } -if (current_ext == stop_extent) { - *done =1 ; + *done = true; goto del_cursor; }xfs_iext_get_extent (ifp, current_ext, &got);fs/xfs/libxfs/xfs_bmap.h +7
-3@@ -227,10 +227,14 @@ int xfs_bmap_del_extent_delay(struct xfs_inode *ip, int whichfork,void xfs_bmap_del_extent_cow (struct xfs_inode *ip,xfs_extnum_t *idx,struct xfs_bmbt_irec *got,struct xfs_bmbt_irec *del);uint xfs_default_attroffset (struct xfs_inode *ip); -int xfs_bmap_shift_extents (struct xfs_trans *tp,struct xfs_inode *ip, +int xfs_bmap_collapse_extents (struct xfs_trans *tp,struct xfs_inode *ip,xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb, -int *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, -struct xfs_defer_ops *dfops,enum shift_direction direction); +bool *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, +struct xfs_defer_ops *dfops); +int xfs_bmap_insert_extents (struct xfs_trans *tp,struct xfs_inode *ip, +xfs_fileoff_t *next_fsb,xfs_fileoff_t offset_shift_fsb, +bool *done,xfs_fileoff_t stop_fsb,xfs_fsblock_t *firstblock, +struct xfs_defer_ops *dfops);int xfs_bmap_split_extent (struct xfs_inode *ip,xfs_fileoff_t split_offset); int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork, xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,fs/xfs/xfs_bmap_util.c +6
-8@@ -1322,7 +1322,6 @@ xfs_collapse_file_space( xfs_off_t offset, xfs_off_t len) { - int done = 0;struct xfs_mount *mp = ip->i_mount;struct xfs_trans *tp;int error;@@ -1332,6 +1331,7 @@ xfs_collapse_file_space(xfs_fileoff_t next_fsb =XFS_B_TO_FSB (mp, offset + len);xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len);uint resblks =XFS_DIOSTRAT_SPACE_RES (mp,0 ); +bool done = false;ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));trace_xfs_collapse_file_space (ip);@@ -1359,9 +1359,8 @@ xfs_collapse_file_space(xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, - &done, stop_fsb, &first_block, &dfops, -SHIFT_LEFT ); + error =xfs_bmap_collapse_extents (tp, ip, &next_fsb, shift_fsb, + &done, stop_fsb, &first_block, &dfops);if (error) goto out_bmap_cancel;@@ -1406,7 +1405,7 @@ xfs_insert_file_space(xfs_fileoff_t stop_fsb =XFS_B_TO_FSB (mp, offset);xfs_fileoff_t next_fsb =NULLFSBLOCK ;xfs_fileoff_t shift_fsb =XFS_B_TO_FSB (mp, len); -int done =0 ; +bool done = false;ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));trace_xfs_insert_file_space (ip);@@ -1433,9 +1432,8 @@ xfs_insert_file_space(xfs_ilock (ip,XFS_ILOCK_EXCL );xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL );xfs_defer_init (&dfops, &first_block); - error =xfs_bmap_shift_extents (tp, ip, &next_fsb, shift_fsb, - &done, stop_fsb, &first_block, &dfops, -SHIFT_RIGHT ); + error =xfs_bmap_insert_extents (tp, ip, &next_fsb, shift_fsb, + &done, stop_fsb, &first_block, &dfops);if (error) goto out_bmap_cancel;Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 11/15] xfs: remove xfs_bmse_shift_one
In reply to Christoph HellwigQuoted 5 lines · Christoph Hellwig
Instead do the actual left and right shift work in the callers, and just keep a helper to update the bmap and rmap btrees as well as the in-core extent list.
Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 306 lines
--- fs/xfs/libxfs/xfs_bmap.c | 181 +++++++++++++++++++---------------------------- fs/xfs/libxfs/xfs_bmap.h | 5 -- 2 files changed, 71 insertions(+), 115 deletions(-)fs/xfs/libxfs/xfs_bmap.c +71
-110@@ -5568,94 +5568,21 @@ xfs_bmse_merge(return xfs_rmap_map_extent (mp, dfops, ip, whichfork, &new); } -/* -* Shift a single extent. -*/ -STATIC int -xfs_bmse_shift_one ( -struct xfs_inode *ip, -int whichfork, -xfs_fileoff_t offset_shift_fsb, -int *current_ext, -struct xfs_bmbt_irec *got, -struct xfs_btree_cur *cur, -int *logflags, -enum shift_direction direction, -struct xfs_defer_ops *dfops) +static int +xfs_bmap_shift_update_extent ( +struct xfs_inode *ip, +int whichfork, +xfs_extnum_t idx, +struct xfs_bmbt_irec *got, +struct xfs_btree_cur *cur, +int *logflags, +struct xfs_defer_ops *dfops, +xfs_fileoff_t startoff) { -struct xfs_ifork *ifp; -struct xfs_mount *mp; -xfs_fileoff_t startoff; -struct xfs_bmbt_irec adj_irec, new; -int error; -int i; -int total_extents; - - mp = ip->i_mount; - ifp =XFS_IFORK_PTR (ip, whichfork); - total_extents =xfs_iext_count (ifp); - -/* delalloc extents should be prevented by caller */ -XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got->br_startblock)); - -if (direction ==SHIFT_LEFT ) { - startoff = got->br_startoff - offset_shift_fsb; - -/* -* Check for merge if we've got an extent to the left, -* otherwise make sure there's enough room at the start -* of the file for the shift. -*/ -if (!*current_ext) { -if (got->br_startoff < offset_shift_fsb) -return -EINVAL ; - goto update_current_ext; - } - -/* -* grab the left extent and check for a large enough hole. -*/ -xfs_iext_get_extent (ifp, *current_ext -1 , &adj_irec); -if (startoff < adj_irec.br_startoff + adj_irec.br_blockcount) -return -EINVAL ; - -/* check whether to merge the extent or shift it down */ -if (xfs_bmse_can_merge (&adj_irec, got, offset_shift_fsb)) { -return xfs_bmse_merge (ip, whichfork, offset_shift_fsb, - *current_ext, got, &adj_irec, - cur, logflags, dfops); - } - }else { - startoff = got->br_startoff + offset_shift_fsb; -/* nothing to move if this is the last extent */ -if (*current_ext >= (total_extents -1 )) - goto update_current_ext; - -/* -* If this is not the last extent in the file, make sure there -* is enough room between current extent and next extent for -* accommodating the shift. -*/ -xfs_iext_get_extent (ifp, *current_ext +1 , &adj_irec); -if (startoff + got->br_blockcount > adj_irec.br_startoff) -return -EINVAL ; - -/* -* Unlike a left shift (which involves a hole punch), -* a right shift does not modify extent neighbors -* in any way. We should never find mergeable extents -* in this scenario. Check anyways and warn if we -* encounter two extents that could be one. -*/ -if (xfs_bmse_can_merge (got, &adj_irec, offset_shift_fsb)) -WARN_ON_ONCE (1 ); - } +struct xfs_mount *mp = ip->i_mount; +struct xfs_bmbt_irec new; +int error, i; -/* -* Increment the extent index for the next iteration, update the start -* offset of the in-core extent and update the btree if applicable. -*/ -update_current_ext: *logflags |=XFS_ILOG_CORE ; new = *got;@@ -5674,13 +5601,8 @@ xfs_bmse_shift_one( *logflags |=XFS_ILOG_DEXT ; } -xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), - *current_ext, &new); - -if (direction ==SHIFT_LEFT ) - (*current_ext)++; -else - (*current_ext)--; +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), idx, + &new);/* update reverse mapping */ error =xfs_rmap_unmap_extent (mp, dfops, ip, whichfork, got);@@ -5704,10 +5626,11 @@ xfs_bmap_collapse_extents(struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got; +struct xfs_bmbt_irec got, prev;xfs_extnum_t current_ext;xfs_extnum_t total_extents;xfs_extnum_t stop_extent; +xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;@@ -5760,6 +5683,7 @@ xfs_bmap_collapse_extents( *done = true; goto del_cursor; } +XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock)); stop_extent = total_extents;if (current_ext >= stop_extent) {@@ -5767,11 +5691,36 @@ xfs_bmap_collapse_extents( goto del_cursor; } - error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, - ¤t_ext, &got, cur, &logflags, -SHIFT_LEFT , dfops); + new_startoff = got.br_startoff - offset_shift_fsb; +if (current_ext) { +xfs_iext_get_extent (ifp, current_ext -1 , &prev); +if (new_startoff < prev.br_startoff + prev.br_blockcount) { + error = -EINVAL ; + goto del_cursor; + } + +/* check whether to merge the extent or shift it down */ +if (xfs_bmse_can_merge (&prev, &got, offset_shift_fsb)) { + error =xfs_bmse_merge (ip, whichfork, offset_shift_fsb, + current_ext, &got, &prev, cur, + &logflags, dfops); +if (error) + goto del_cursor; + goto done; + } + }else { +if (got.br_startoff < offset_shift_fsb) { + error = -EINVAL ; + goto del_cursor; + } + } + + error =xfs_bmap_shift_update_extent (ip, whichfork, current_ext, &got, + cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; + current_ext++; +done:/* * If there was an extent merge during the shift, the extent * count can change. Update the total and grade the next record. @@ -5784,17 +5733,13 @@ xfs_bmap_collapse_extents( }xfs_iext_get_extent (ifp, current_ext, &got); -if (!*done) - *next_fsb = got.br_startoff; - + *next_fsb = got.br_startoff; del_cursor:if (cur)xfs_btree_del_cursor (cur, error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); -if (logflags)xfs_trans_log_inode (tp, ip, logflags); -return error; }@@ -5813,10 +5758,11 @@ xfs_bmap_insert_extents(struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got, s; +struct xfs_bmbt_irec got, next, s;xfs_extnum_t current_ext;xfs_extnum_t total_extents;xfs_extnum_t stop_extent; +xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;@@ -5883,6 +5829,7 @@ xfs_bmap_insert_extents( goto del_cursor; } } +XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock));/* Lookup the extent index at which we have to stop */ xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s);@@ -5893,27 +5840,41 @@ xfs_bmap_insert_extents( goto del_cursor; } - error =xfs_bmse_shift_one (ip, whichfork, offset_shift_fsb, - ¤t_ext, &got, cur, &logflags, -SHIFT_RIGHT , dfops); + new_startoff = got.br_startoff + offset_shift_fsb; +if (current_ext < total_extents -1 ) { +xfs_iext_get_extent (ifp, current_ext +1 , &next); +if (new_startoff + got.br_blockcount > next.br_startoff) { + error = -EINVAL ; + goto del_cursor; + } + +/* +* Unlike a left shift (which involves a hole punch), a right +* shift does not modify extent neighbors in any way. We should +* never find mergeable extents in this scenario. Check anyways +* and warn if we encounter two extents that could be one. +*/ +if (xfs_bmse_can_merge (&got, &next, offset_shift_fsb)) +WARN_ON_ONCE (1 ); + } + + error =xfs_bmap_shift_update_extent (ip, whichfork, current_ext, &got, + cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; -if (current_ext == stop_extent) { +if (--current_ext == stop_extent) { *done = true; goto del_cursor; }xfs_iext_get_extent (ifp, current_ext, &got); *next_fsb = got.br_startoff; - del_cursor:if (cur)xfs_btree_del_cursor (cur, error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); -if (logflags)xfs_trans_log_inode (tp, ip, logflags); -return error; }fs/xfs/libxfs/xfs_bmap.h +0
-5@@ -183,11 +183,6 @@ static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec) !isnullstartblock (irec->br_startblock); } -enum shift_direction { -SHIFT_LEFT =0 , -SHIFT_RIGHT , -}; -void xfs_trim_extent (struct xfs_bmbt_irec *irec,xfs_fileoff_t bno,xfs_filblks_t len);int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd);Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 12/15] xfs: update got in xfs_bmap_shift_update_extent
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
This way the caller gets the proper updated extent returned in got.
Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 58 lines
--- fs/xfs/libxfs/xfs_bmap.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)fs/xfs/libxfs/xfs_bmap.c +7
-9@@ -5580,35 +5580,33 @@ xfs_bmap_shift_update_extent( xfs_fileoff_t startoff) {struct xfs_mount *mp = ip->i_mount; -struct xfs_bmbt_irec new; +struct xfs_bmbt_irec prev = *got;int error, i; *logflags |=XFS_ILOG_CORE ; - new = *got; - new.br_startoff = startoff; + got->br_startoff = startoff;if (cur) { - error =xfs_bmbt_lookup_eq (cur, got, &i); + error =xfs_bmbt_lookup_eq (cur, &prev, &i);if (error)return error;XFS_WANT_CORRUPTED_RETURN (mp, i ==1 ); - error =xfs_bmbt_update (cur, &new); + error =xfs_bmbt_update (cur, got);if (error)return error; }else { *logflags |=XFS_ILOG_DEXT ; } -xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), idx, - &new); +xfs_iext_update_extent (ip,xfs_bmap_fork_to_state (whichfork), idx, got);/* update reverse mapping */ - error =xfs_rmap_unmap_extent (mp, dfops, ip, whichfork, got); + error =xfs_rmap_unmap_extent (mp, dfops, ip, whichfork, &prev);if (error)return error; -return xfs_rmap_map_extent (mp, dfops, ip, whichfork, &new); +return xfs_rmap_map_extent (mp, dfops, ip, whichfork, got); }int Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 13/15] xfs: don't rely on extent indices in xfs_bmap_collapse_extents
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Rewrite
xfs_bmap_collapse_extentsso that we don't rely on extent indices except for iterating over them. Not being able to iterate to the next extent is a sufficient exit condition, and we don't need to do any extent count games given that:a) we already flushed all delalloc extents past our start offset before doing the operation
b)xfs_iext_count()includes delalloc extents anywaySigned-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 110 lines
--- fs/xfs/libxfs/xfs_bmap.c | 54 +++++++++++------------------------------------- 1 file changed, 12 insertions(+), 42 deletions(-)fs/xfs/libxfs/xfs_bmap.c +12
-42@@ -5626,8 +5626,6 @@ xfs_bmap_collapse_extents(struct xfs_btree_cur *cur =NULL ;struct xfs_bmbt_irec got, prev;xfs_extnum_t current_ext; -xfs_extnum_t total_extents; -xfs_extnum_t stop_extent;xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;@@ -5658,52 +5656,31 @@ xfs_bmap_collapse_extents( cur->bc_private.b.flags =0 ; } -/* -* There may be delalloc extents in the data fork before the range we -* are collapsing out, so we cannot use the count of real extents here. -* Instead we have to calculate it from the incore fork. -*/ - total_extents =xfs_iext_count (ifp); -if (total_extents ==0 ) { - *done = true; - goto del_cursor; - } - -/* -* Look up the extent index for the fsb where we start shifting. We can -* henceforth iterate with current_ext as extent list changes are locked -* out via ilock. -* -* If next_fsb lies in a hole beyond which there are no extents we are -* done. -*/ if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { *done = true; goto del_cursor; }XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock)); - stop_extent = total_extents; -if (current_ext >= stop_extent) { - error = -EIO ; - goto del_cursor; - } - new_startoff = got.br_startoff - offset_shift_fsb; -if (current_ext) { -xfs_iext_get_extent (ifp, current_ext -1 , &prev); +if (xfs_iext_get_extent (ifp, current_ext -1 , &prev)) {if (new_startoff < prev.br_startoff + prev.br_blockcount) { error = -EINVAL ; goto del_cursor; } -/* check whether to merge the extent or shift it down */ if (xfs_bmse_can_merge (&prev, &got, offset_shift_fsb)) { error =xfs_bmse_merge (ip, whichfork, offset_shift_fsb, current_ext, &got, &prev, cur, &logflags, dfops);if (error) goto del_cursor; + +/* update got after merge */ +if (!xfs_iext_get_extent (ifp, current_ext, &got)) { + *done = true; + goto del_cursor; + } goto done; } }else {@@ -5717,20 +5694,13 @@ xfs_bmap_collapse_extents( cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; - current_ext++; -done: -/* -* If there was an extent merge during the shift, the extent -* count can change. Update the total and grade the next record. -*/ - total_extents =xfs_iext_count (ifp); - stop_extent = total_extents; -if (current_ext == stop_extent) { - *done = true; - goto del_cursor; + +if (!xfs_iext_get_extent (ifp, ++current_ext, &got)) { + *done = true; + goto del_cursor; } -xfs_iext_get_extent (ifp, current_ext, &got); +done: *next_fsb = got.br_startoff; del_cursor:if (cur)Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 14/15] xfs: don't rely on extent indices in xfs_bmap_insert_extents
In reply to Christoph HellwigQuoted 10 lines · Christoph Hellwig
Rewrite
xfs_bmap_insert_extentsso that we don't rely on extent indices except for iterating over them. Not being able to iterate to the previous extent or finding the extent thatstop_fsbis in are sufficient exit conditions, and we don't need to do any extent count games given that:a) we already flushed all delalloc extents past our start offset before doing the operation
b)xfs_iext_count()includes delalloc extents anywaySigned-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 104 lines
--- fs/xfs/libxfs/xfs_bmap.c | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-)fs/xfs/libxfs/xfs_bmap.c +9
-38@@ -5726,10 +5726,8 @@ xfs_bmap_insert_extents(struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_cur *cur =NULL ; -struct xfs_bmbt_irec got, next, s; +struct xfs_bmbt_irec got, next;xfs_extnum_t current_ext; -xfs_extnum_t total_extents; -xfs_extnum_t stop_extent;xfs_fileoff_t new_startoff;int error =0 ;int logflags =0 ;@@ -5760,37 +5758,14 @@ xfs_bmap_insert_extents( cur->bc_private.b.flags =0 ; } -/* -* There may be delalloc extents in the data fork before the range we -* are collapsing out, so we cannot use the count of real extents here. -* Instead we have to calculate it from the incore fork. -*/ - total_extents =xfs_iext_count (ifp); -if (total_extents ==0 ) { - *done = true; - goto del_cursor; - } - -/* -* In case of first right shift, we need to initialize next_fsb -*/ if (*next_fsb ==NULLFSBLOCK ) { - current_ext = total_extents -1 ; -xfs_iext_get_extent (ifp, current_ext, &got); -if (stop_fsb > got.br_startoff) { + current_ext =xfs_iext_count (ifp) -1 ; +if (!xfs_iext_get_extent (ifp, current_ext, &got) || + stop_fsb > got.br_startoff) { *done = true; goto del_cursor; } - *next_fsb = got.br_startoff; }else { -/* -* Look up the extent index for the fsb where we start shifting. We can -* henceforth iterate with current_ext as extent list changes are locked -* out via ilock. -* -* If next_fsb lies in a hole beyond which there are no extents we are -* done. -*/ if (!xfs_iext_lookup_extent (ip, ifp, *next_fsb, ¤t_ext, &got)) { *done = true;@@ -5799,18 +5774,13 @@ xfs_bmap_insert_extents( }XFS_WANT_CORRUPTED_RETURN (mp, !isnullstartblock (got.br_startblock)); -/* Lookup the extent index at which we have to stop */ -xfs_iext_lookup_extent (ip, ifp, stop_fsb, &stop_extent, &s); -/* Make stop_extent exclusive of shift range */ - stop_extent--; -if (current_ext <= stop_extent) { +if (stop_fsb >= got.br_startoff + got.br_blockcount) { error = -EIO ; goto del_cursor; } new_startoff = got.br_startoff + offset_shift_fsb; -if (current_ext < total_extents -1 ) { -xfs_iext_get_extent (ifp, current_ext +1 , &next); +if (xfs_iext_get_extent (ifp, current_ext +1 , &next)) {if (new_startoff + got.br_blockcount > next.br_startoff) { error = -EINVAL ; goto del_cursor;@@ -5830,11 +5800,12 @@ xfs_bmap_insert_extents( cur, &logflags, dfops, new_startoff);if (error) goto del_cursor; -if (--current_ext == stop_extent) { + +if (!xfs_iext_get_extent (ifp, --current_ext, &got) || + stop_fsb >= got.br_startoff + got.br_blockcount) { *done = true; goto del_cursor; } -xfs_iext_get_extent (ifp, current_ext, &got); *next_fsb = got.br_startoff; del_cursor:Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 15/15] xfs: rewrite xfs_bmap_first_unused to make better use of xfs_iext_get_extent
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
Look at the return value of
xfs_iext_get_extentinstead of figuring out the extent count first and looping up to it.Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
Quoted 99 lines
--- fs/xfs/libxfs/xfs_bmap.c | 56 ++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 30 deletions(-)fs/xfs/libxfs/xfs_bmap.c +26
-30@@ -1285,57 +1285,53 @@ xfs_bmap_read_extents( }/* -* Returns the file-relative block number of the first unused block(s) -* in the file with at least "len" logically contiguous blocks free. -* This is the lowest-address hole if the file has holes, else the first block -* past the end of file. -* Return 0 if the file is currently local (in-inode). +* Returns the relative block number of the first unused block(s) in the given +* fork with at least "len" logically contiguous blocks free. This is the +* lowest-address hole if the fork has holes, else the first block past the end +* of fork. Return 0 if the fork is currently local (in-inode). */ int /* error */ xfs_bmap_first_unused ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode */ -xfs_extlen_t len,/* size of hole to find */ -xfs_fileoff_t *first_unused,/* unused block */ -int whichfork)/* data or attr fork */ +struct xfs_trans *tp,/* transaction pointer */ +struct xfs_inode *ip,/* incore inode */ +xfs_extlen_t len,/* size of hole to find */ +xfs_fileoff_t *first_unused,/* unused block */ +int whichfork)/* data or attr fork */ { -int error;/* error return value */ -int idx;/* extent record index */ -xfs_ifork_t *ifp;/* inode fork pointer */ -xfs_fileoff_t lastaddr;/* last block number seen */ -xfs_fileoff_t lowest;/* lowest useful block */ -xfs_fileoff_t max;/* starting useful block */ -xfs_extnum_t nextents;/* number of extent entries */ +struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork); +struct xfs_bmbt_irec got; +xfs_extnum_t idx =0 ; +xfs_fileoff_t lastaddr =0 ; +xfs_fileoff_t lowest, max; +int error;ASSERT (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_BTREE ||XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_EXTENTS ||XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_LOCAL ); +if (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_LOCAL ) { *first_unused =0 ;return 0 ; } - ifp =XFS_IFORK_PTR (ip, whichfork); -if (!(ifp->if_flags &XFS_IFEXTENTS ) && - (error =xfs_iread_extents (tp, ip, whichfork))) -return error; - lowest = *first_unused; - nextents =xfs_iext_count (ifp); -for (idx =0 , lastaddr =0 , max = lowest; idx < nextents; idx++) { -struct xfs_bmbt_irec got; -xfs_iext_get_extent (ifp, idx, &got); +if (!(ifp->if_flags &XFS_IFEXTENTS )) { + error =xfs_iread_extents (tp, ip, whichfork); +if (error) +return error; + } + lowest = max = *first_unused; +while (xfs_iext_get_extent (ifp, idx++, &got)) {/* * See if the hole before this extent will work. */ if (got.br_startoff >= lowest + len && - got.br_startoff - max >= len) { - *first_unused = max; -return 0 ; - } + got.br_startoff - max >= len) +break ; lastaddr = got.br_startoff + got.br_blockcount; max =XFS_FILEOFF_MAX (lastaddr, lowest); } + *first_unused = max;return 0 ; }Signature · 6 lines
2.14.1 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 08/15] xfs: inline xfs_shift_file_space into callers
In reply to Darrick J. WongQuoted 6 lines
fs/xfs/xfs_bmap_util.c xfs_shift_file_space( · line 1336
Quoted 1 line
fs/xfs/xfs_bmap_util.c +1
-0+ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));So it took me a while of wondering "don't we have to have the
MMAPLOCK_EXCLtoo?" before realizing that yes, the caller actually does grab that too. I wonder if it's worth checking here, since you're asserting the lock status at all?
This just moves the previous code around.. I can send an incremental patch if you want, though.
Re: [PATCH 08/15] xfs: inline xfs_shift_file_space into callers
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines
fs/xfs/xfs_bmap_util.c xfs_shift_file_space( · line 1336
Quoted 1 line
fs/xfs/xfs_bmap_util.c +1
-0+ASSERT (xfs_isilocked (ip,XFS_IOLOCK_EXCL ));So it took me a while of wondering "don't we have to have the
MMAPLOCK_EXCLtoo?" before realizing that yes, the caller actually does grab that too. I wonder if it's worth checking here, since you're asserting the lock status at all?This just moves the previous code around.. I can send an incremental patch if you want, though.
Sure, either resending this patch or tacking a new one on the end is fine, I don't mind either way.
--D
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html