@@ -863,91 +863,76 @@ xfs_free_eofblocks(
863
863
bool need_iolock )
864
864
{
865
865
xfs_trans_t * tp ;
866
+ bool has ;
866
867
int error ;
867
- xfs_fileoff_t end_fsb ;
868
- xfs_fileoff_t last_fsb ;
869
- xfs_filblks_t map_len ;
870
- int nimaps ;
871
- xfs_bmbt_irec_t imap ;
872
868
873
869
/*
874
- * Figure out if there are any blocks beyond the end
875
- * of the file. If not, then there is nothing to do .
870
+ * If there are blocks after the end of file, truncate the file to its
871
+ * current size to free them up .
876
872
*/
877
- end_fsb = XFS_B_TO_FSB (mp , (xfs_ufsize_t )XFS_ISIZE (ip ));
878
- last_fsb = XFS_B_TO_FSB (mp , mp -> m_super -> s_maxbytes );
879
- if (last_fsb <= end_fsb )
880
- return 0 ;
881
- map_len = last_fsb - end_fsb ;
882
-
883
- nimaps = 1 ;
884
- xfs_ilock (ip , XFS_ILOCK_SHARED );
885
- error = xfs_bmapi_read (ip , end_fsb , map_len , & imap , & nimaps , 0 );
886
- xfs_iunlock (ip , XFS_ILOCK_SHARED );
887
-
888
- if (!error && (nimaps != 0 ) &&
889
- (imap .br_startblock != HOLESTARTBLOCK ||
890
- ip -> i_delayed_blks )) {
891
- /*
892
- * Attach the dquots to the inode up front.
893
- */
894
- error = xfs_qm_dqattach (ip , 0 );
895
- if (error )
896
- return error ;
873
+ error = xfs_has_eofblocks (ip , & has );
874
+ if (error || !has )
875
+ return error ;
897
876
898
- /* wait on dio to ensure i_size has settled */
899
- inode_dio_wait (VFS_I (ip ));
877
+ /*
878
+ * Attach the dquots to the inode up front.
879
+ */
880
+ error = xfs_qm_dqattach (ip , 0 );
881
+ if (error )
882
+ return error ;
900
883
901
- /*
902
- * There are blocks after the end of file.
903
- * Free them up now by truncating the file to
904
- * its current size.
905
- */
906
- tp = xfs_trans_alloc (mp , XFS_TRANS_INACTIVE );
884
+ /* wait on dio to ensure i_size has settled */
885
+ inode_dio_wait (VFS_I (ip ));
907
886
908
- if ( need_iolock ) {
909
- if (! xfs_ilock_nowait ( ip , XFS_IOLOCK_EXCL )) {
910
- xfs_trans_cancel ( tp );
911
- return - EAGAIN ;
912
- }
913
- }
887
+ /*
888
+ * There are blocks after the end of file.
889
+ * Free them up now by truncating the file to
890
+ * its current size.
891
+ */
892
+ tp = xfs_trans_alloc ( mp , XFS_TRANS_INACTIVE );
914
893
915
- error = xfs_trans_reserve (tp , & M_RES (mp )-> tr_itruncate , 0 , 0 );
916
- if (error ) {
917
- ASSERT (XFS_FORCED_SHUTDOWN (mp ));
894
+ if (need_iolock ) {
895
+ if (!xfs_ilock_nowait (ip , XFS_IOLOCK_EXCL )) {
918
896
xfs_trans_cancel (tp );
919
- if (need_iolock )
920
- xfs_iunlock (ip , XFS_IOLOCK_EXCL );
921
- return error ;
897
+ return - EAGAIN ;
922
898
}
899
+ }
923
900
924
- xfs_ilock (ip , XFS_ILOCK_EXCL );
925
- xfs_trans_ijoin (tp , ip , 0 );
901
+ error = xfs_trans_reserve (tp , & M_RES (mp )-> tr_itruncate , 0 , 0 );
902
+ if (error ) {
903
+ ASSERT (XFS_FORCED_SHUTDOWN (mp ));
904
+ xfs_trans_cancel (tp );
905
+ if (need_iolock )
906
+ xfs_iunlock (ip , XFS_IOLOCK_EXCL );
907
+ return error ;
908
+ }
909
+
910
+ xfs_ilock (ip , XFS_ILOCK_EXCL );
911
+ xfs_trans_ijoin (tp , ip , 0 );
926
912
913
+ /*
914
+ * Do not update the on-disk file size. If we update the
915
+ * on-disk file size and then the system crashes before the
916
+ * contents of the file are flushed to disk then the files
917
+ * may be full of holes (ie NULL files bug).
918
+ */
919
+ error = xfs_itruncate_extents (& tp , ip , XFS_DATA_FORK ,
920
+ XFS_ISIZE (ip ));
921
+ if (error ) {
927
922
/*
928
- * Do not update the on-disk file size. If we update the
929
- * on-disk file size and then the system crashes before the
930
- * contents of the file are flushed to disk then the files
931
- * may be full of holes (ie NULL files bug).
923
+ * If we get an error at this point we simply don't
924
+ * bother truncating the file.
932
925
*/
933
- error = xfs_itruncate_extents (& tp , ip , XFS_DATA_FORK ,
934
- XFS_ISIZE (ip ));
935
- if (error ) {
936
- /*
937
- * If we get an error at this point we simply don't
938
- * bother truncating the file.
939
- */
940
- xfs_trans_cancel (tp );
941
- } else {
942
- error = xfs_trans_commit (tp );
943
- if (!error )
944
- xfs_inode_clear_eofblocks_tag (ip );
945
- }
946
-
947
- xfs_iunlock (ip , XFS_ILOCK_EXCL );
948
- if (need_iolock )
949
- xfs_iunlock (ip , XFS_IOLOCK_EXCL );
926
+ xfs_trans_cancel (tp );
927
+ } else {
928
+ error = xfs_trans_commit (tp );
929
+ if (!error )
930
+ xfs_inode_clear_eofblocks_tag (ip );
950
931
}
932
+
933
+ xfs_iunlock (ip , XFS_ILOCK_EXCL );
934
+ if (need_iolock )
935
+ xfs_iunlock (ip , XFS_IOLOCK_EXCL );
951
936
return error ;
952
937
}
953
938
0 commit comments