ext4: do not delete unlinked inode from orphan list on failed truncate [Linux 5.2]

ext4: do not delete unlinked inode from orphan list on failed truncate [Linux 5.2]

This Linux kernel change "ext4: do not delete unlinked inode from orphan list on failed truncate" is included in the Linux 5.2 release. This change is authored by Jan Kara <jack [at] suse.cz> on Thu May 23 23:35:28 2019 -0400. The commit for this change in Linux stable tree is ee0ed02 (patch).

ext4: do not delete unlinked inode from orphan list on failed truncate

It is possible that unlinked inode enters ext4_setattr() (e.g. if
somebody calls ftruncate(2) on unlinked but still open file). In such
case we should not delete the inode from the orphan list if truncate
fails. Note that this is mostly a theoretical concern as filesystem is
corrupted if we reach this path anyway but let's be consistent in our
orphan handling.

Reviewed-by: Ira Weiny <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>
Cc: [email protected]

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 fs/ext4/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 9bcb7f2..c7f77c6 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -5625,7 +5625,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
            up_write(&EXT4_I(inode)->i_data_sem);
            ext4_journal_stop(handle);
            if (error) {
-               if (orphan)
+               if (orphan && inode->i_nlink)
                    ext4_orphan_del(NULL, inode);
                goto err_out;
            }

Leave a Reply

Your email address will not be published. Required fields are marked *