Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1400329ybj; Fri, 8 May 2020 00:00:43 -0700 (PDT) X-Google-Smtp-Source: APiQypK6tJTflDq+Cq3gBRUBgquDt8E15yDtwNX+7jZpLse7EjAgY05YfyivLyjK2V+AB4T4WsjG X-Received: by 2002:a17:906:3e44:: with SMTP id t4mr673629eji.337.1588921243086; Fri, 08 May 2020 00:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588921243; cv=none; d=google.com; s=arc-20160816; b=NvuCSXl5w+naMWKktX1w2ABKryImTm9JdAxkkBdL/wYHKmqZ7N3S3s5F9vnVZOKLpe hvOINAd2vL8KJH1TYj5yJliz07mNT31YlkXAt8FR91Q7WCPbjGQBqI0Ku6zYgtqaq7wP qd5RT6mlDo8n1OLhcOBFR0ycefvDjua/aGVCzhHEsuB76jIrDDU+b3FpTt26wxe1Z+fA zAaLr2JnYK+fQssO+Mg9ARlokKhv2bNv6RwfbbjYOGDvS7mHOecHZOvoR1C5IDx/NxBA GlRNsWcblqtO/3nS/5lyFrMhS4NQWOEOu6Xz6jTvSiKU/K+nx6ho9chNM7Vh/1n3QOe4 I2Og== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pUqYbbEhhoBOpMJg82tH9U5Nj13y9+Ar796jHBZ0iuk=; b=v3YOVudTxm4H8VaofiTR48xc8YYAXNO96RNaaqmCNH2p6s59+sWQ7wBgumRKZIv76V wKU4gpWoisvhcoPsqfRk3dDiRY20JFVwZ36Ng9JCar1eQg1cNLWNBwIzv4m2eRDO855D irmW5L9neMeCM/J6CCPVtpsqd1jlH/dDEFoqUwXFMSLtJNeXe3k9iSs75k5ejjTpKFIk 4IHczUAAaik3nNMdwzNukHY1wlJPTjG7+O54JwgMCcQzVuZqS4Fxw5NJAt34lKxeUkzm XG8cZ5y80BoZxDY+/APSpIwJhAvc2cfwI/nxbkj4R/1AL1xikh2TBT1fEUSYMKCfXAgF Hc6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="G7/6rRT9"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si418931edv.243.2020.05.08.00.00.18; Fri, 08 May 2020 00:00:43 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="G7/6rRT9"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726099AbgEHG65 (ORCPT + 99 others); Fri, 8 May 2020 02:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725971AbgEHG65 (ORCPT ); Fri, 8 May 2020 02:58:57 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD932C05BD43 for ; Thu, 7 May 2020 23:58:56 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id f18so512481lja.13 for ; Thu, 07 May 2020 23:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=pUqYbbEhhoBOpMJg82tH9U5Nj13y9+Ar796jHBZ0iuk=; b=G7/6rRT9CAiKUhr1x2HJR1bBbUhx1FptG/OWbT6gPV4TchFejkTo8f/6hlCk2kNdGE NmNuSEztMvkKfI3NVQtmFm9WJID7r8OpPqDf2/mV0/YFYY6H+RDGU55qfEU1L47jhIZp qHkHz5jggUJmn0Tddvy/C21A/otqQ9CLoZFG6NiphUkV4tfAwr3G4tnN6Ph0bvw0o0Kn 6NBNrfLsGfVexLXDWyKyVG2L5RzaYMC4gH4g/cg8ruCX5rcJ1H0JuVb+5nAt8Q67WCSF miMHIMejlC7lFiV8E++ShTzwcy7qjRMba2rw5JhQliDfIal61viSDQBgiF52TusRnKmf b6vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=pUqYbbEhhoBOpMJg82tH9U5Nj13y9+Ar796jHBZ0iuk=; b=G7gwU78i74BIZgYd1v2gylSC+ntUsX9fLNVXfO0Elae5aZ43nsFOUM7j6Cf19cdaT1 yniUUvPaSMq8slSfpuEkfIOqWdJjaiItd236cskJTone+PvmR/qFMpSIbTfVvSfdPPdE zEHtRbrE6K3q1TUZFzOMPxyigEjdgYDgrq5p9/HYYnlbeDEC17IHaAtg8l139f21ZjlS zH4WCywQJ/FKWGurVyoUA/7usqfcte+FoPMgv0QdjoBBVR7b6s5fWegnc/GoZWuSZQJa P60/qp8AiS0+GsuNA91F1FCb64naIYf+vS/iridfKRxyghCWa9J5pu8Mj16t6kz0qOKD BieQ== X-Gm-Message-State: AOAM531p/YtMFS1qFhy9DxHrVAvjrjUcdE6D1WaZkuXjfYrnpBJWRiAd uTsSVTiqLja3rxm87jTLVddbN5Avcjis2wVPSIj9isGyI8M= X-Received: by 2002:a2e:97d3:: with SMTP id m19mr681437ljj.136.1588921135090; Thu, 07 May 2020 23:58:55 -0700 (PDT) MIME-Version: 1.0 References: <20200508042506.143395-1-daeho43@gmail.com> <4dfb73d9-03a0-bb2f-a112-1dd42db4d7bb@huawei.com> In-Reply-To: <4dfb73d9-03a0-bb2f-a112-1dd42db4d7bb@huawei.com> From: Daeho Jeong Date: Fri, 8 May 2020 15:58:44 +0900 Message-ID: Subject: Re: [f2fs-dev] [PATCH] f2fs: remove race condition in releasing cblocks To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Daeho Jeong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 2020=EB=85=84 5=EC=9B=94 8=EC=9D=BC (=EA=B8=88) =EC=98=A4=ED=9B=84 3:50, Ch= ao Yu =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > > 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 fi= le *filp, unsigned long arg) > > pgoff_t page_idx =3D 0, last_idx; > > unsigned int released_blocks =3D 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,