Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp50634pxv; Wed, 14 Jul 2021 18:59:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsPq6RGPUGP7qaPBmr3nAquP2Q+izAp1Wqu5PaojQ4RIqTHtOMe0Ymynb32S+gJC3mJEtQ X-Received: by 2002:a05:6402:17d3:: with SMTP id s19mr2208638edy.49.1626314361036; Wed, 14 Jul 2021 18:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626314361; cv=none; d=google.com; s=arc-20160816; b=l+aRLsG64Vuqqs9FMLMxxihGK+uyLo4UJN0hX0YAPKIyME01Ur/w+vSyOQQ5E9Xn2z 8V9fLxeVFugLf7ymilvbKQiOP6aWI82eTP70BnuhqRf5lU7w4wwxAa8I/c95uJK1dFnJ 3VhBdlHN7kOR8qVPIDDSH/Q/FYZlGqpEINJmnsHtoIyIbM/NXZQiJsbbL5nZ1KmJuCiI UZza4TJ4FjsOYmtNcogeigU0TIwaXs/kcnimYMbG4vCrjuU4HMdjk0zOB7JKWK+Jdeyc +PD0are4l2gkx6flGjvrCKsSPOyBD3HL3mqIGR/K8sYSYet48NPYqlV2cKNFhWf611H7 A72Q== 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=pLsN8XvNDx5wG7R0AYhV9KQCIxJ6gn50bxwxwiO80fYY1VBU8AsCdwiz/rWka7DAm6 +kY+hxVALPDQZIOg7TmdKW98Dd5PhaIss6+wL+NIL4J+FTuT1halAMYgeBuMXadoyc2r wB2Zgy16+6NiHIx2JPUHTUs5VntyUipRiY0ymB+yQ31i/FOvyzL40aWMONuNleNVWdXl Z9cY3mjyz67lbqxofFRX6wKaWJTyh2MBcqOpo+02LJ0Dnsp5IxSpwU47FOSLMxotsVch GgXQX9ZMZkmuqGcHZWxa+/8pVEdemnqC4oNQOD4uloFslOxK+rLlQGAGUeNBYR9DA/+w nxHw== 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 hr18si5010005ejc.140.2021.07.14.18.58.54; Wed, 14 Jul 2021 18:59:21 -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 S231742AbhGOBtg (ORCPT + 99 others); Wed, 14 Jul 2021 21:49:36 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:15013 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbhGOBtf (ORCPT ); Wed, 14 Jul 2021 21:49:35 -0400 Received: from dggeme752-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GQHFg1Dz1zbcfh; Thu, 15 Jul 2021 09:43:19 +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; Thu, 15 Jul 2021 09:46:36 +0800 From: Zhang Yi To: CC: , , , , Subject: [PATCH v2 2/4] ext4: correct the error path of ext4_write_inline_data_end() Date: Thu, 15 Jul 2021 09:54:50 +0800 Message-ID: <20210715015452.2542505-3-yi.zhang@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715015452.2542505-1-yi.zhang@huawei.com> References: <20210715015452.2542505-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