Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1407218ybj; Fri, 8 May 2020 00:10:58 -0700 (PDT) X-Google-Smtp-Source: APiQypJHOjAcxGUgiF51Rseo1XMJo0s4lwAsTUetTE4cUJWx4wuipRNR/gPDqB0w60JoI6wrffPr X-Received: by 2002:a17:906:edc2:: with SMTP id sb2mr645247ejb.129.1588921858424; Fri, 08 May 2020 00:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588921858; cv=none; d=google.com; s=arc-20160816; b=L4Mnt/rP1qkhyNhu4jAEt6oouuxyCttE3mDObDp9JZx9F0PO9MOIJk4Y0F8Y3yYWrX gtrAVvOd85ez9fGShMTIqAEgDFqrqR/KCsqDWlTMw4onP0Q5hdPb2GKK+KxQIqwEL/0S c4z05LG1xg7BTl5Hs14ObGQYby47rFCdcE7Swt2ZNy4RWn2B4U+XvnxxHqY//J7ACc4w F49FudZWGT0IOecxCUOmpq05BKaih6+eTPPqLKcqOaZ0Y88fWaKkNxn2994iwUhmGgrf 9+MkM+Mep2vwKY7fbimR7fpPe+QskapiRfLRNPr6KMz3IvkvgQubq5t30I9xc+5K8xVm AclA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=RI0iMG93snjuwPqNGFCsa6QH1CXf/vdrL6kx128HalU=; b=mAjjahpQ6rJg9oWY2DSk8gSP1O4UGIVLsdiLzQe2iWPDOB7a1x7NCuOcS5Iogw1+5w EifiVe2euMMxRd+I3AqNUTEaxf0FSTSxDsT9Mq2LUFnovqcPtBel9SsZzVXcY0rAFQBP 3FqJNKLk3nPtlNEq2Nu5tb7WyFTHia9inhFq6SssZjG2Xjj7iUhAQSatLPvFkfhlOWaY x7Wvftm8V2C5z/2gXphVyRoKbxPMlW7AXUDgcVUbH+IVKDjVFEWs/lw+z0PWoHzItvW9 2DqUaqj669vAqY0iFJ3MSjAc6kWoEbDPUHmPeesvAyeelkN0fLu9Sd9uV0YjBLLtZVbJ TmXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si441512ejj.92.2020.05.08.00.10.35; Fri, 08 May 2020 00:10:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726797AbgEHHJP (ORCPT + 99 others); Fri, 8 May 2020 03:09:15 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4293 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725991AbgEHHJP (ORCPT ); Fri, 8 May 2020 03:09:15 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5FCB6F3B03B25BE65E27; Fri, 8 May 2020 15:09:10 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.206) with Microsoft SMTP Server (TLS) id 14.3.487.0; Fri, 8 May 2020 15:09:07 +0800 Subject: Re: [f2fs-dev] [PATCH] f2fs: remove race condition in releasing cblocks To: Daeho Jeong CC: , , , Daeho Jeong References: <20200508042506.143395-1-daeho43@gmail.com> <4dfb73d9-03a0-bb2f-a112-1dd42db4d7bb@huawei.com> From: Chao Yu Message-ID: Date: Fri, 8 May 2020 15:09:06 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/5/8 14:58, Daeho Jeong wrote: > I moved checking i_compr_blocks phrase after calling inode_lock() > already, because we should check this after writing pages. > > So, if it fails to check i_compr_blocks, we need to call inode_unlock(). > > Am I missing something? After applying this patch, I get this: ret = mnt_want_write_file(filp); if (ret) return ret; if (!F2FS_I(inode)->i_compr_blocks) goto out; f2fs_balance_fs(F2FS_I_SB(inode), true); inode_lock(inode); > > 2020년 5월 8일 (금) 오후 3:50, Chao Yu 님이 작성: >> >> On 2020/5/8 12:25, Daeho Jeong wrote: >>> From: Daeho Jeong >>> >>> Now, if writing pages and releasing compress blocks occur >>> simultaneously, and releasing cblocks is executed more than one time >>> to a file, then total block count of filesystem and block count of the >>> file could be incorrect and damaged. >>> >>> We have to execute releasing compress blocks only one time for a file >>> without being interfered by writepages path. >>> >>> Signed-off-by: Daeho Jeong >>> --- >>> fs/f2fs/file.c | 31 ++++++++++++++++++++++++------- >>> 1 file changed, 24 insertions(+), 7 deletions(-) >>> >>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >>> index 4aab4b42d8ba..a92bc51b9b28 100644 >>> --- a/fs/f2fs/file.c >>> +++ b/fs/f2fs/file.c >>> @@ -3488,6 +3488,7 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) >>> pgoff_t page_idx = 0, last_idx; >>> unsigned int released_blocks = 0; >>> int ret; >>> + int writecount; >>> >>> if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) >>> return -EOPNOTSUPP; >> >> Before inode_lock(), there is one case we may jump to out label, in >> this case, we may unlock inode incorrectly. >> >> if (!F2FS_I(inode)->i_compr_blocks) >> goto out; >> >>> - >>> - inode_unlock(inode); >>> out: >>> + inode_unlock(inode); >>> + >>> mnt_drop_write_file(filp); >> >> Thanks, > . >