aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2016-04-01 02:07:22 -0400
committerTheodore Ts'o <tytso@mit.edu>2016-04-01 02:07:22 -0400
commite84dfbe2bf170c626778079e5b94435b05b8d572 (patch)
treed00b3abe754efacc314909b85ceede6d922c533c
parentdaf647d2dd58cec59570d7698a45b98e580f2076 (diff)
ext4: retry block allocation for failed DIO and DAX writes
Currently if block allocation for DIO or DAX write fails due to ENOSPC, we just returned it to userspace. However these ENOSPC errors can be transient because the transaction freeing blocks has not yet committed. This demonstrates as failures of generic/102 test when the filesystem is mounted with 'dax' mount option. Fix the problem by properly retrying the allocation in case of ENOSPC error in get blocks functions used for direct IO. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Tested-by: Ross Zwisler <ross.zwisler@linux.intel.com>
-rw-r--r--fs/ext4/inode.c58
1 files changed, 28 insertions, 30 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index dab84a2530ff..8710174090f5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -763,39 +763,47 @@ int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
763/* Maximum number of blocks we map for direct IO at once. */ 763/* Maximum number of blocks we map for direct IO at once. */
764#define DIO_MAX_BLOCKS 4096 764#define DIO_MAX_BLOCKS 4096
765 765
766static handle_t *start_dio_trans(struct inode *inode, 766/*
767 struct buffer_head *bh_result) 767 * Get blocks function for the cases that need to start a transaction -
768 * generally difference cases of direct IO and DAX IO. It also handles retries
769 * in case of ENOSPC.
770 */
771static int ext4_get_block_trans(struct inode *inode, sector_t iblock,
772 struct buffer_head *bh_result, int flags)
768{ 773{
769 int dio_credits; 774 int dio_credits;
775 handle_t *handle;
776 int retries = 0;
777 int ret;
770 778
771 /* Trim mapping request to maximum we can map at once for DIO */ 779 /* Trim mapping request to maximum we can map at once for DIO */
772 if (bh_result->b_size >> inode->i_blkbits > DIO_MAX_BLOCKS) 780 if (bh_result->b_size >> inode->i_blkbits > DIO_MAX_BLOCKS)
773 bh_result->b_size = DIO_MAX_BLOCKS << inode->i_blkbits; 781 bh_result->b_size = DIO_MAX_BLOCKS << inode->i_blkbits;
774 dio_credits = ext4_chunk_trans_blocks(inode, 782 dio_credits = ext4_chunk_trans_blocks(inode,
775 bh_result->b_size >> inode->i_blkbits); 783 bh_result->b_size >> inode->i_blkbits);
776 return ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits); 784retry:
785 handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits);
786 if (IS_ERR(handle))
787 return PTR_ERR(handle);
788
789 ret = _ext4_get_block(inode, iblock, bh_result, flags);
790 ext4_journal_stop(handle);
791
792 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
793 goto retry;
794 return ret;
777} 795}
778 796
779/* Get block function for DIO reads and writes to inodes without extents */ 797/* Get block function for DIO reads and writes to inodes without extents */
780int ext4_dio_get_block(struct inode *inode, sector_t iblock, 798int ext4_dio_get_block(struct inode *inode, sector_t iblock,
781 struct buffer_head *bh, int create) 799 struct buffer_head *bh, int create)
782{ 800{
783 handle_t *handle;
784 int ret;
785
786 /* We don't expect handle for direct IO */ 801 /* We don't expect handle for direct IO */
787 WARN_ON_ONCE(ext4_journal_current_handle()); 802 WARN_ON_ONCE(ext4_journal_current_handle());
788 803
789 if (create) { 804 if (!create)
790 handle = start_dio_trans(inode, bh); 805 return _ext4_get_block(inode, iblock, bh, 0);
791 if (IS_ERR(handle)) 806 return ext4_get_block_trans(inode, iblock, bh, EXT4_GET_BLOCKS_CREATE);
792 return PTR_ERR(handle);
793 }
794 ret = _ext4_get_block(inode, iblock, bh,
795 create ? EXT4_GET_BLOCKS_CREATE : 0);
796 if (create)
797 ext4_journal_stop(handle);
798 return ret;
799} 807}
800 808
801/* 809/*
@@ -806,18 +814,13 @@ int ext4_dio_get_block(struct inode *inode, sector_t iblock,
806static int ext4_dio_get_block_unwritten_async(struct inode *inode, 814static int ext4_dio_get_block_unwritten_async(struct inode *inode,
807 sector_t iblock, struct buffer_head *bh_result, int create) 815 sector_t iblock, struct buffer_head *bh_result, int create)
808{ 816{
809 handle_t *handle;
810 int ret; 817 int ret;
811 818
812 /* We don't expect handle for direct IO */ 819 /* We don't expect handle for direct IO */
813 WARN_ON_ONCE(ext4_journal_current_handle()); 820 WARN_ON_ONCE(ext4_journal_current_handle());
814 821
815 handle = start_dio_trans(inode, bh_result); 822 ret = ext4_get_block_trans(inode, iblock, bh_result,
816 if (IS_ERR(handle)) 823 EXT4_GET_BLOCKS_IO_CREATE_EXT);
817 return PTR_ERR(handle);
818 ret = _ext4_get_block(inode, iblock, bh_result,
819 EXT4_GET_BLOCKS_IO_CREATE_EXT);
820 ext4_journal_stop(handle);
821 824
822 /* 825 /*
823 * When doing DIO using unwritten extents, we need io_end to convert 826 * When doing DIO using unwritten extents, we need io_end to convert
@@ -850,18 +853,13 @@ static int ext4_dio_get_block_unwritten_async(struct inode *inode,
850static int ext4_dio_get_block_unwritten_sync(struct inode *inode, 853static int ext4_dio_get_block_unwritten_sync(struct inode *inode,
851 sector_t iblock, struct buffer_head *bh_result, int create) 854 sector_t iblock, struct buffer_head *bh_result, int create)
852{ 855{
853 handle_t *handle;
854 int ret; 856 int ret;
855 857
856 /* We don't expect handle for direct IO */ 858 /* We don't expect handle for direct IO */
857 WARN_ON_ONCE(ext4_journal_current_handle()); 859 WARN_ON_ONCE(ext4_journal_current_handle());
858 860
859 handle = start_dio_trans(inode, bh_result); 861 ret = ext4_get_block_trans(inode, iblock, bh_result,
860 if (IS_ERR(handle)) 862 EXT4_GET_BLOCKS_IO_CREATE_EXT);
861 return PTR_ERR(handle);
862 ret = _ext4_get_block(inode, iblock, bh_result,
863 EXT4_GET_BLOCKS_IO_CREATE_EXT);
864 ext4_journal_stop(handle);
865 863
866 /* 864 /*
867 * Mark inode as having pending DIO writes to unwritten extents. 865 * Mark inode as having pending DIO writes to unwritten extents.