Skip to content

Commit 705965b

Browse files
jankaratytso
authored andcommitted
ext4: rename and split get blocks functions
Rename ext4_get_blocks_write() to ext4_get_blocks_unwritten() to better describe what it does. Also split out get blocks functions for direct IO. Later we move functionality from _ext4_get_blocks() there. There's no functional change in this patch. Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent e142d05 commit 705965b

File tree

4 files changed

+74
-47
lines changed

4 files changed

+74
-47
lines changed

fs/ext4/ext4.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,12 +2506,14 @@ extern int ext4_trim_fs(struct super_block *, struct fstrim_range *);
25062506
int ext4_inode_is_fast_symlink(struct inode *inode);
25072507
struct buffer_head *ext4_getblk(handle_t *, struct inode *, ext4_lblk_t, int);
25082508
struct buffer_head *ext4_bread(handle_t *, struct inode *, ext4_lblk_t, int);
2509-
int ext4_get_block_write(struct inode *inode, sector_t iblock,
2510-
struct buffer_head *bh_result, int create);
2509+
int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
2510+
struct buffer_head *bh_result, int create);
25112511
int ext4_dax_mmap_get_block(struct inode *inode, sector_t iblock,
25122512
struct buffer_head *bh_result, int create);
25132513
int ext4_get_block(struct inode *inode, sector_t iblock,
2514-
struct buffer_head *bh_result, int create);
2514+
struct buffer_head *bh_result, int create);
2515+
int ext4_dio_get_block(struct inode *inode, sector_t iblock,
2516+
struct buffer_head *bh_result, int create);
25152517
int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
25162518
struct buffer_head *bh, int create);
25172519
int ext4_walk_page_buffers(handle_t *handle,

fs/ext4/indirect.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,21 +693,21 @@ ssize_t ext4_ind_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
693693
}
694694
if (IS_DAX(inode))
695695
ret = dax_do_io(iocb, inode, iter, offset,
696-
ext4_get_block, NULL, 0);
696+
ext4_dio_get_block, NULL, 0);
697697
else
698698
ret = __blockdev_direct_IO(iocb, inode,
699699
inode->i_sb->s_bdev, iter,
700-
offset, ext4_get_block, NULL,
701-
NULL, 0);
700+
offset, ext4_dio_get_block,
701+
NULL, NULL, 0);
702702
inode_dio_end(inode);
703703
} else {
704704
locked:
705705
if (IS_DAX(inode))
706706
ret = dax_do_io(iocb, inode, iter, offset,
707-
ext4_get_block, NULL, DIO_LOCKING);
707+
ext4_dio_get_block, NULL, DIO_LOCKING);
708708
else
709709
ret = blockdev_direct_IO(iocb, inode, iter, offset,
710-
ext4_get_block);
710+
ext4_dio_get_block);
711711

712712
if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
713713
loff_t isize = i_size_read(inode);

fs/ext4/inline.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,10 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
581581
if (ret)
582582
goto out;
583583

584-
if (ext4_should_dioread_nolock(inode))
585-
ret = __block_write_begin(page, from, to, ext4_get_block_write);
586-
else
584+
if (ext4_should_dioread_nolock(inode)) {
585+
ret = __block_write_begin(page, from, to,
586+
ext4_get_block_unwritten);
587+
} else
587588
ret = __block_write_begin(page, from, to, ext4_get_block);
588589

589590
if (!ret && ext4_should_journal_data(inode)) {

fs/ext4/inode.c

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,60 @@ int ext4_get_block(struct inode *inode, sector_t iblock,
768768
create ? EXT4_GET_BLOCKS_CREATE : 0);
769769
}
770770

771+
/*
772+
* Get block function used when preparing for buffered write if we require
773+
* creating an unwritten extent if blocks haven't been allocated. The extent
774+
* will be converted to written after the IO is complete.
775+
*/
776+
int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
777+
struct buffer_head *bh_result, int create)
778+
{
779+
ext4_debug("ext4_get_block_unwritten: inode %lu, create flag %d\n",
780+
inode->i_ino, create);
781+
return _ext4_get_block(inode, iblock, bh_result,
782+
EXT4_GET_BLOCKS_IO_CREATE_EXT);
783+
}
784+
785+
/* Get block function for DIO reads and writes to inodes without extents */
786+
int ext4_dio_get_block(struct inode *inode, sector_t iblock,
787+
struct buffer_head *bh, int create)
788+
{
789+
return _ext4_get_block(inode, iblock, bh,
790+
create ? EXT4_GET_BLOCKS_CREATE : 0);
791+
}
792+
793+
/*
794+
* Get block function for DIO writes when we create unwritten extent if
795+
* blocks are not allocated yet. The extent will be converted to written
796+
* after IO is complete.
797+
*/
798+
static int ext4_dio_get_block_unwritten(struct inode *inode, sector_t iblock,
799+
struct buffer_head *bh_result, int create)
800+
{
801+
ext4_debug("ext4_dio_get_block_unwritten: inode %lu, create flag %d\n",
802+
inode->i_ino, create);
803+
return _ext4_get_block(inode, iblock, bh_result,
804+
EXT4_GET_BLOCKS_IO_CREATE_EXT);
805+
}
806+
807+
static int ext4_dio_get_block_overwrite(struct inode *inode, sector_t iblock,
808+
struct buffer_head *bh_result, int create)
809+
{
810+
int ret;
811+
812+
ext4_debug("ext4_dio_get_block_overwrite: inode %lu, create flag %d\n",
813+
inode->i_ino, create);
814+
ret = _ext4_get_block(inode, iblock, bh_result, 0);
815+
/*
816+
* Blocks should have been preallocated! ext4_file_write_iter() checks
817+
* that.
818+
*/
819+
WARN_ON_ONCE(!buffer_mapped(bh_result));
820+
821+
return ret;
822+
}
823+
824+
771825
/*
772826
* `handle' can be NULL if create is zero
773827
*/
@@ -1079,13 +1133,14 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
10791133
#ifdef CONFIG_EXT4_FS_ENCRYPTION
10801134
if (ext4_should_dioread_nolock(inode))
10811135
ret = ext4_block_write_begin(page, pos, len,
1082-
ext4_get_block_write);
1136+
ext4_get_block_unwritten);
10831137
else
10841138
ret = ext4_block_write_begin(page, pos, len,
10851139
ext4_get_block);
10861140
#else
10871141
if (ext4_should_dioread_nolock(inode))
1088-
ret = __block_write_begin(page, pos, len, ext4_get_block_write);
1142+
ret = __block_write_begin(page, pos, len,
1143+
ext4_get_block_unwritten);
10891144
else
10901145
ret = __block_write_begin(page, pos, len, ext4_get_block);
10911146
#endif
@@ -3084,37 +3139,6 @@ static int ext4_releasepage(struct page *page, gfp_t wait)
30843139
return try_to_free_buffers(page);
30853140
}
30863141

3087-
/*
3088-
* ext4_get_block used when preparing for a DIO write or buffer write.
3089-
* We allocate an uinitialized extent if blocks haven't been allocated.
3090-
* The extent will be converted to initialized after the IO is complete.
3091-
*/
3092-
int ext4_get_block_write(struct inode *inode, sector_t iblock,
3093-
struct buffer_head *bh_result, int create)
3094-
{
3095-
ext4_debug("ext4_get_block_write: inode %lu, create flag %d\n",
3096-
inode->i_ino, create);
3097-
return _ext4_get_block(inode, iblock, bh_result,
3098-
EXT4_GET_BLOCKS_IO_CREATE_EXT);
3099-
}
3100-
3101-
static int ext4_get_block_overwrite(struct inode *inode, sector_t iblock,
3102-
struct buffer_head *bh_result, int create)
3103-
{
3104-
int ret;
3105-
3106-
ext4_debug("ext4_get_block_overwrite: inode %lu, create flag %d\n",
3107-
inode->i_ino, create);
3108-
ret = _ext4_get_block(inode, iblock, bh_result, 0);
3109-
/*
3110-
* Blocks should have been preallocated! ext4_file_write_iter() checks
3111-
* that.
3112-
*/
3113-
WARN_ON_ONCE(!buffer_mapped(bh_result));
3114-
3115-
return ret;
3116-
}
3117-
31183142
#ifdef CONFIG_FS_DAX
31193143
int ext4_dax_mmap_get_block(struct inode *inode, sector_t iblock,
31203144
struct buffer_head *bh_result, int create)
@@ -3282,7 +3306,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
32823306
*/
32833307
iocb->private = NULL;
32843308
if (overwrite) {
3285-
get_block_func = ext4_get_block_overwrite;
3309+
get_block_func = ext4_dio_get_block_overwrite;
32863310
} else {
32873311
ext4_inode_aio_set(inode, NULL);
32883312
if (!is_sync_kiocb(iocb)) {
@@ -3304,7 +3328,7 @@ static ssize_t ext4_ext_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
33043328
*/
33053329
ext4_inode_aio_set(inode, io_end);
33063330
}
3307-
get_block_func = ext4_get_block_write;
3331+
get_block_func = ext4_dio_get_block_unwritten;
33083332
dio_flags = DIO_LOCKING;
33093333
}
33103334
#ifdef CONFIG_EXT4_FS_ENCRYPTION
@@ -5498,7 +5522,7 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
54985522
unlock_page(page);
54995523
/* OK, we need to fill the hole... */
55005524
if (ext4_should_dioread_nolock(inode))
5501-
get_block = ext4_get_block_write;
5525+
get_block = ext4_get_block_unwritten;
55025526
else
55035527
get_block = ext4_get_block;
55045528
retry_alloc:

0 commit comments

Comments
 (0)