Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1246800pxv; Fri, 16 Jul 2021 05:13:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkumFLwehnZPLXLyYzrSDhDMFnX036PDrnf4Y1vGdji1fr10v2kc5rlneRk8ScZffL4oNT X-Received: by 2002:a05:6402:5170:: with SMTP id d16mr14117689ede.300.1626437595878; Fri, 16 Jul 2021 05:13:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626437595; cv=none; d=google.com; s=arc-20160816; b=jVAP1xRod/lKrLNoUjDuhUqOjyec7tMLx88hWV7Tcn/UkZc5qiduFfzU6C3eGStwOj Raot0hUx4xneLb8i8Ur3hJ3P8y3UNjKQ+rt3lkDqGW7EJxGyF+H/vMAMuL65qnNRpEBU 6vv8qwoiiLQHnrYgP2BNe+q4JBvf9nsb1nq5CmK+AMdj1hcxvm5MAm0cIL5/2BrMWljt slokyk9wuWsxeg3uC8fB1mbW2vYYbCvatTpJKJ3OEFGZzNV9xVlXJr/1npKTouNzHarW MIzngHI9zRDhBMRED+CqgR8d2nJXErytnxA5E+VdzXhZYIrfAqv8DMemLQq3f6jovlq+ aJ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=u6QKX3NeVFuUvWiLzqAYme23Sb5WATIp8X4pkICPxWk=; b=rkVeecYr89C/vwRjyd0ssHMmebj/0ByRRgEQYqHJ3o/TfakOhk5RfDmQfstwCDTSzc Rb/V4jTwJgM2Ij8xU41aNmP8IfsDwYA9vBCOWRQQKn8Ykh2CYD7M2ChZ3Q5DNq31N5VP H+hSi96nfJo9mo4/cYLdiESE7klguhopJx1gHaNj1LTaRDQVopfwE3M3ETIHr+hp6+gv bP32wn6WOEVv7eZq+W8MGyMQ5OYBsugBSxRaySXvvosdsLhIpyqZ5J/pABEvSA64pveF cOoZnqp2w3dFW5i+7h8bVUCKUF6pnzesnkdv3uaGnyersSnsGAclM+gMsFHUPyICS+ae 4aAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d9si11169945edq.169.2021.07.16.05.12.51; Fri, 16 Jul 2021 05:13:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238373AbhGPMPS (ORCPT + 99 others); Fri, 16 Jul 2021 08:15:18 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:11435 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237493AbhGPMPP (ORCPT ); Fri, 16 Jul 2021 08:15:15 -0400 Received: from dggeme752-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GR9531KX2zcdx2; Fri, 16 Jul 2021 20:08:55 +0800 (CST) Received: from huawei.com (10.175.127.227) by dggeme752-chm.china.huawei.com (10.3.19.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 16 Jul 2021 20:12:13 +0800 From: Zhang Yi To: CC: , , , , Subject: [PATCH v3 2/4] ext4: correct the error path of ext4_write_inline_data_end() Date: Fri, 16 Jul 2021 20:20:22 +0800 Message-ID: <20210716122024.1105856-3-yi.zhang@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210716122024.1105856-1-yi.zhang@huawei.com> References: <20210716122024.1105856-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme752-chm.china.huawei.com (10.3.19.98) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Current error path of ext4_write_inline_data_end() is not correct. Firstly, it should pass out the error value if ext4_get_inode_loc() return fail, or else it could trigger infinite loop if we inject error here. And then it's better to add inode to orphan list if it return fail in ext4_journal_stop(), otherwise we could not restore inline xattr entry after power failure. Finally, we need to reset the 'ret' value if ext4_write_inline_data_end() return success in ext4_write_end() and ext4_journalled_write_end(), otherwise we could not get the error return value of ext4_journal_stop(). Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/inline.c | 15 +++++---------- fs/ext4/inode.c | 7 +++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 70cb64db33f7..28b666f25ac2 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -733,25 +733,20 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, void *kaddr; struct ext4_iloc iloc; - if (unlikely(copied < len)) { - if (!PageUptodate(page)) { - copied = 0; - goto out; - } - } + if (unlikely(copied < len) && !PageUptodate(page)) + return 0; ret = ext4_get_inode_loc(inode, &iloc); if (ret) { ext4_std_error(inode->i_sb, ret); - copied = 0; - goto out; + return ret; } ext4_write_lock_xattr(inode, &no_expand); BUG_ON(!ext4_has_inline_data(inode)); kaddr = kmap_atomic(page); - ext4_write_inline_data(inode, &iloc, kaddr, pos, len); + ext4_write_inline_data(inode, &iloc, kaddr, pos, copied); kunmap_atomic(kaddr); SetPageUptodate(page); /* clear page dirty so that writepages wouldn't work for us. */ @@ -760,7 +755,7 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, ext4_write_unlock_xattr(inode, &no_expand); brelse(iloc.bh); mark_inode_dirty(inode); -out: + return copied; } diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index dca8e3810443..5bbf9f3b8b6f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1295,6 +1295,7 @@ static int ext4_write_end(struct file *file, goto errout; } copied = ret; + ret = 0; } else copied = block_write_end(file, mapping, pos, len, copied, page, fsdata); @@ -1321,13 +1322,14 @@ static int ext4_write_end(struct file *file, if (i_size_changed || inline_data) ret = ext4_mark_inode_dirty(handle, inode); +errout: if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) /* if we have allocated more blocks and copied * less. We will have blocks allocated outside * inode->i_size. So truncate them */ ext4_orphan_add(handle, inode); -errout: + ret2 = ext4_journal_stop(handle); if (!ret) ret = ret2; @@ -1410,6 +1412,7 @@ static int ext4_journalled_write_end(struct file *file, goto errout; } copied = ret; + ret = 0; } else if (unlikely(copied < len) && !PageUptodate(page)) { copied = 0; ext4_journalled_zero_new_buffers(handle, page, from, to); @@ -1439,6 +1442,7 @@ static int ext4_journalled_write_end(struct file *file, ret = ret2; } +errout: if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) /* if we have allocated more blocks and copied * less. We will have blocks allocated outside @@ -1446,7 +1450,6 @@ static int ext4_journalled_write_end(struct file *file, */ ext4_orphan_add(handle, inode); -errout: ret2 = ext4_journal_stop(handle); if (!ret) ret = ret2; -- 2.31.1