From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B856C38A2A for ; Fri, 8 May 2020 13:47:49 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 529C3216FD; Fri, 8 May 2020 13:47:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="LSF1pzwF"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="JvbeE2AM"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="nWywNIbj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 529C3216FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jX3Lu-0003Pm-5A; Fri, 08 May 2020 13:47:46 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jX3Ls-0003PX-Dt for linux-f2fs-devel@lists.sourceforge.net; Fri, 08 May 2020 13:47:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=XgNLaYee7Zf/lAj40vwKqc9YGH7B6pbTm2i+PYDq7+Y=; b=LSF1pzwFkklGHRJTRpnBt7XYvT mSfSrTUA+ipzxL4gljkBExaZggTas3cpH9W+jcIIqSyikom5cvBd3zmjIZU4XJzYGJePanORBErS+ SiH9YCYXZs7aSE69kWLmEefdoQ/7qegvIZFQMJFyyqUzNLHP1nnq70LX0IqCO6nPMm6E=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=XgNLaYee7Zf/lAj40vwKqc9YGH7B6pbTm2i+PYDq7+Y=; b=JvbeE2AMH7Du3f3I6502DzdeqZ VqmxOiqb6EPtuw3niyjhvQHd7zmxE362HfMsQASLVPdNVP5401ZEw6eQjYKYZEckBlUIGq+iGKh5M p3hWTytPbzFteCXt79aVGh/+ap6UiukJkHOV9uP7ORIsx/AEMFzYJIXTJBf3Gl6rwAD0=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jX3Lp-001tUW-Jy for linux-f2fs-devel@lists.sourceforge.net; Fri, 08 May 2020 13:47:44 +0000 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8658B2070B; Fri, 8 May 2020 13:47:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588945652; bh=KyLkw4FIQ448eGd/+tb293VAzGUQcL3eG6cYNMKrqBc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nWywNIbjc5ts/cFIwMEi575SnVZ7yaork2GJhTjQUeWWLm0Z3A1nX5eYr/2P0Hqrr ybNJxdo/sNYCLcDvuZNOhYi84IlG5FhmWdhm3xWKEoDOPIhwLUsTcndqkWsd8vOhb6 apl2Bi1eTCu0d2tGp8ThYNf4gMbuYaa41yu+cYw0= Date: Fri, 8 May 2020 06:47:32 -0700 From: Jaegeuk Kim To: Daeho Jeong Message-ID: <20200508134732.GA88927@google.com> References: <20200508092921.208447-1-daeho43@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200508092921.208447-1-daeho43@gmail.com> X-Headers-End: 1jX3Lp-001tUW-Jy Subject: Re: [f2fs-dev] [PATCH] f2fs: remove race condition in releasing cblocks X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-team@android.com, kernel@vger.kernel.org, Daeho Jeong , linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Hi Daeho, Please let me integrate this patch into the original patch since it is still in the dev branch. Thanks, On 05/08, 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 | 34 ++++++++++++++++++++++++---------- > 1 file changed, 24 insertions(+), 10 deletions(-) > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 4aab4b42d8ba..f7de2a1da528 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; > @@ -3502,20 +3503,33 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) > if (ret) > return ret; > > - if (!F2FS_I(inode)->i_compr_blocks) > - goto out; > - > f2fs_balance_fs(F2FS_I_SB(inode), true); > > inode_lock(inode); > > - if (!IS_IMMUTABLE(inode)) { > - F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL; > - f2fs_set_inode_flags(inode); > - inode->i_ctime = current_time(inode); > - f2fs_mark_inode_dirty_sync(inode, true); > + writecount = atomic_read(&inode->i_writecount); > + if ((filp->f_mode & FMODE_WRITE && writecount != 1) || writecount) { > + ret = -EBUSY; > + goto out; > } > > + if (IS_IMMUTABLE(inode)) { > + ret = -EINVAL; > + goto out; > + } > + > + ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); > + if (ret) > + goto out; > + > + if (!F2FS_I(inode)->i_compr_blocks) > + goto out; > + > + F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL; > + f2fs_set_inode_flags(inode); > + inode->i_ctime = current_time(inode); > + f2fs_mark_inode_dirty_sync(inode, true); > + > down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > down_write(&F2FS_I(inode)->i_mmap_sem); > > @@ -3554,9 +3568,9 @@ static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) > > up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > up_write(&F2FS_I(inode)->i_mmap_sem); > - > - inode_unlock(inode); > out: > + inode_unlock(inode); > + > mnt_drop_write_file(filp); > > if (ret >= 0) { > -- > 2.26.2.645.ge9eca65c58-goog _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel