Skip to content

Commit 59efe53

Browse files
yangerkuntytso
authored andcommitted
ext4: dax: keep orphan list before truncate overflow allocated blocks
Any extending write for ext4 requires the inode to be placed on the orphan list before the actual write. In addition, the inode can be actually removed from the orphan list only after all writes are completed. Otherwise we'd leave allocated blocks beyond i_disksize if we could not copy all the data into allocated block and e2fsck would complain. Currently, direct IO and buffered IO comply with this logic(buffered IO will truncate all overflow allocated blocks that has not been written successfully, and direct IO will truncate all allocated blocks when error occurs). However, dax write break this since dax write will remove the inode from the orphan list by calling ext4_handle_inode_extension unconditionally during extending write. We add a argument to help determine does we do a fully write, and for the case not fully write, we leave the inode on the orphan list, and the latter ext4_inode_extension_cleanup will help us truncate the overflow allocated blocks, and then remove the inode from the orphan list. Signed-off-by: yangerkun <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent a218743 commit 59efe53

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/ext4/file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,
306306
}
307307

308308
static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset,
309-
ssize_t count)
309+
ssize_t written, ssize_t count)
310310
{
311311
handle_t *handle;
312312

@@ -315,19 +315,19 @@ static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset,
315315
if (IS_ERR(handle))
316316
return PTR_ERR(handle);
317317

318-
if (ext4_update_inode_size(inode, offset + count)) {
318+
if (ext4_update_inode_size(inode, offset + written)) {
319319
int ret = ext4_mark_inode_dirty(handle, inode);
320320
if (unlikely(ret)) {
321321
ext4_journal_stop(handle);
322322
return ret;
323323
}
324324
}
325325

326-
if (inode->i_nlink)
326+
if ((written == count) && inode->i_nlink)
327327
ext4_orphan_del(handle, inode);
328328
ext4_journal_stop(handle);
329329

330-
return count;
330+
return written;
331331
}
332332

333333
/*
@@ -393,7 +393,7 @@ static int ext4_dio_write_end_io(struct kiocb *iocb, ssize_t size,
393393
if (pos + size <= READ_ONCE(EXT4_I(inode)->i_disksize) &&
394394
pos + size <= i_size_read(inode))
395395
return size;
396-
return ext4_handle_inode_extension(inode, pos, size);
396+
return ext4_handle_inode_extension(inode, pos, size, size);
397397
}
398398

399399
static const struct iomap_dio_ops ext4_dio_write_ops = {
@@ -669,7 +669,7 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
669669
ret = dax_iomap_rw(iocb, from, &ext4_iomap_ops);
670670

671671
if (extend) {
672-
ret = ext4_handle_inode_extension(inode, offset, ret);
672+
ret = ext4_handle_inode_extension(inode, offset, ret, count);
673673
ext4_inode_extension_cleanup(inode, ret < (ssize_t)count);
674674
}
675675
out:

0 commit comments

Comments
 (0)