Skip to content

Commit 0b9f230

Browse files
matthewbobrowskitytso
authored andcommitted
ext4: move inode extension check out from ext4_iomap_alloc()
Lift the inode extension/orphan list handling code out from ext4_iomap_alloc() and apply it within the ext4_dax_write_iter(). Signed-off-by: Matthew Bobrowski <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/fd5c84db25d5d0da87d97ed4c36fd844f57da759.1572949325.git.mbobrowski@mbobrowski.org Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 569342d commit 0b9f230

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

fs/ext4/file.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
323323
ssize_t ret;
324324
size_t count;
325325
loff_t offset;
326+
handle_t *handle;
327+
bool extend = false;
326328
struct inode *inode = file_inode(iocb->ki_filp);
327329

328330
if (!inode_trylock(inode)) {
@@ -342,8 +344,28 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
342344

343345
offset = iocb->ki_pos;
344346
count = iov_iter_count(from);
347+
348+
if (offset + count > EXT4_I(inode)->i_disksize) {
349+
handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
350+
if (IS_ERR(handle)) {
351+
ret = PTR_ERR(handle);
352+
goto out;
353+
}
354+
355+
ret = ext4_orphan_add(handle, inode);
356+
if (ret) {
357+
ext4_journal_stop(handle);
358+
goto out;
359+
}
360+
361+
extend = true;
362+
ext4_journal_stop(handle);
363+
}
364+
345365
ret = dax_iomap_rw(iocb, from, &ext4_iomap_ops);
346-
ret = ext4_handle_inode_extension(inode, offset, ret, count);
366+
367+
if (extend)
368+
ret = ext4_handle_inode_extension(inode, offset, ret, count);
347369
out:
348370
inode_unlock(inode);
349371
if (ret > 0)

fs/ext4/inode.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,6 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map,
34943494
unsigned int flags)
34953495
{
34963496
handle_t *handle;
3497-
u8 blkbits = inode->i_blkbits;
34983497
int ret, dio_credits, retries = 0;
34993498

35003499
/*
@@ -3517,28 +3516,7 @@ static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map,
35173516
return PTR_ERR(handle);
35183517

35193518
ret = ext4_map_blocks(handle, inode, map, EXT4_GET_BLOCKS_CREATE_ZERO);
3520-
if (ret < 0)
3521-
goto journal_stop;
3522-
3523-
/*
3524-
* If we've allocated blocks beyond EOF, we need to ensure that they're
3525-
* truncated if we crash before updating the inode size metadata within
3526-
* ext4_iomap_end(). For faults, we don't need to do that (and cannot
3527-
* due to orphan list operations needing an inode_lock()). If we happen
3528-
* to instantiate blocks beyond EOF, it is because we race with a
3529-
* truncate operation, which already has added the inode onto the
3530-
* orphan list.
3531-
*/
3532-
if (!(flags & IOMAP_FAULT) && map->m_lblk + map->m_len >
3533-
(i_size_read(inode) + (1 << blkbits) - 1) >> blkbits) {
3534-
int err;
3535-
3536-
err = ext4_orphan_add(handle, inode);
3537-
if (err < 0)
3538-
ret = err;
3539-
}
35403519

3541-
journal_stop:
35423520
ext4_journal_stop(handle);
35433521
if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
35443522
goto retry;

0 commit comments

Comments
 (0)