From patchwork Tue Jun 25 03:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13710566 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id BB3D2C2BBCA for ; Tue, 25 Jun 2024 03:14:16 +0000 (UTC) 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.95) (envelope-from ) id 1sLwdJ-0002Iw-8q; Tue, 25 Jun 2024 03:14:13 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLwdH-0002Io-QJ for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=S3SEIrRgLkDTi9iwxnp9i8R8Cp9PuLar69WrF7Vxfqc=; b=VjbP1gR6GxP026Hvcrp2eO9jQb sxkm46BCRFz2aXGQrMSvC0E932dWKGIQsZqHiytU3LW13lDWGFzDoXuokAs6eQkoiETCkuO8a8Z1T hGcNcKHCWuOskRo1Mpp43JNLl08ay0NQsdvnVljBRIXA93gnoKlAM2jDUxuBNzFEZ+ew=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=S3SEIrRgLkDTi9iwxnp9i8R8Cp9PuLar69WrF7Vxfqc=; b=V VaS2o9By0jbi48KNN5U3JkP4G9pRVxJmUyfCNegC0p0cYErpZQk6aKATuFo87jxVaWbQeAhaiGhTt FJdvT3xoSUjsA3x+eiDcxdJBCb/AZY3MF9ZT6lI3QafQI6BCeRimx9/OeauXc4TgHoiQanzIuvuBP qn5L/5nePX3IFljQ=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLwdI-0001Uw-3y for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:12 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id F3C71611CA; Tue, 25 Jun 2024 03:14:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC10DC32782; Tue, 25 Jun 2024 03:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719285240; bh=wxT7s6VN+/GloyB+qWgTcBkk6+rCXosFyOxrCWFGLqE=; h=From:To:Cc:Subject:Date:From; b=JLcrhK/NZP0TSviBtUvn/pqtj0qNrgHRPVTfJ0xlkU/9RLka7tuoH7s7BBdGPqp7S hEiSMx7h8/u5Ym8VFSfqzxxBtFHT6xSD6rnzWMvr//X+S1poxSBiVGqYHXeChjCmab axAxe2pXw6gtE2MWC6Z87/5u7BqgkJXCqxUF+sjHHl2sR4D37ekCtk2DCHQRb3O5f9 EKapz6lWE58bLkdWlX+bewronwIWIlZvRPyz9OXarj+nR2vKa9Z28ZB5gbiXLqGBPX KNqpLxCIrkUa8TaohxTs9Vo/ENLf5coXFMQMymdt7vIMGJdU/Q5WaQobvonwVCqElQ Nquq0HDRwBU/g== From: Chao Yu To: jaegeuk@kernel.org Date: Tue, 25 Jun 2024 11:13:48 +0800 Message-Id: <20240625031351.3586955-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1sLwdI-0001Uw-3y Subject: [f2fs-dev] [PATCH 1/4] f2fs: atomic: fix to avoid racing w/ GC 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: Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Case #1: SQLite App GC Thread Kworker Shrinker - f2fs_ioc_start_atomic_write - f2fs_ioc_commit_atomic_write - f2fs_commit_atomic_write - filemap_write_and_wait_range : write atomic_file's data to cow_inode echo 3 > drop_caches to drop atomic_file's cache. - f2fs_gc - gc_data_segment - move_data_page - set_page_dirty - writepages - f2fs_do_write_data_page : overwrite atomic_file's data to cow_inode - f2fs_down_write(&fi->i_gc_rwsem[WRITE]) - __f2fs_commit_atomic_write - f2fs_up_write(&fi->i_gc_rwsem[WRITE]) Case #2: SQLite App GC Thread Kworker - f2fs_ioc_start_atomic_write - __writeback_single_inode - do_writepages - f2fs_write_cache_pages - f2fs_write_single_data_page - f2fs_do_write_data_page : write atomic_file's data to cow_inode - f2fs_gc - gc_data_segment - move_data_page - set_page_dirty - writepages - f2fs_do_write_data_page : overwrite atomic_file's data to cow_inode - f2fs_ioc_commit_atomic_write In above cases racing in between atomic_write and GC, previous data in atomic_file may be overwrited to cow_file, result in data corruption. This patch introduces PAGE_PRIVATE_ATOMIC_WRITE bit flag in page.private, and use it to indicate that there is last dirty data in atomic file, and the data should be writebacked into cow_file, if the flag is not tagged in page, we should never write data across files. Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Cc: Daeho Jeong Signed-off-by: Chao Yu --- v1: - this patch can fix on-disk data consistency issue caused by f2fs/003 fs/f2fs/data.c | 10 +++++++++- fs/f2fs/f2fs.h | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 0b4f563f2361..22031b9b507c 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2647,10 +2647,13 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) struct dnode_of_data dn; struct node_info ni; bool ipu_force = false; + bool atomic_commit; int err = 0; /* Use COW inode to make dnode_of_data for atomic write */ - if (f2fs_is_atomic_file(inode)) + atomic_commit = f2fs_is_atomic_file(inode) && + page_private_atomic(fio->page); + if (atomic_commit) set_new_dnode(&dn, F2FS_I(inode)->cow_inode, NULL, NULL, 0); else set_new_dnode(&dn, inode, NULL, NULL, 0); @@ -2749,6 +2752,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) f2fs_outplace_write_data(&dn, fio); trace_f2fs_do_write_data_page(page_folio(page), OPU); set_inode_flag(inode, FI_APPEND_WRITE); + if (atomic_commit) + clear_page_private_atomic(page); out_writepage: f2fs_put_dnode(&dn); out: @@ -3718,6 +3723,9 @@ static int f2fs_write_end(struct file *file, set_page_dirty(page); + if (f2fs_is_atomic_file(inode)) + set_page_private_atomic(page); + if (pos + copied > i_size_read(inode) && !f2fs_verity_in_progress(inode)) { f2fs_i_size_write(inode, pos + copied); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index eacf0b0e6b2e..f1d65ee3addf 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1413,7 +1413,8 @@ static inline void f2fs_clear_bit(unsigned int nr, char *addr); * bit 1 PAGE_PRIVATE_ONGOING_MIGRATION * bit 2 PAGE_PRIVATE_INLINE_INODE * bit 3 PAGE_PRIVATE_REF_RESOURCE - * bit 4- f2fs private data + * bit 4 PAGE_PRIVATE_ATOMIC_WRITE + * bit 5- f2fs private data * * Layout B: lowest bit should be 0 * page.private is a wrapped pointer. @@ -1423,6 +1424,7 @@ enum { PAGE_PRIVATE_ONGOING_MIGRATION, /* data page which is on-going migrating */ PAGE_PRIVATE_INLINE_INODE, /* inode page contains inline data */ PAGE_PRIVATE_REF_RESOURCE, /* dirty page has referenced resources */ + PAGE_PRIVATE_ATOMIC_WRITE, /* data page from atomic write path */ PAGE_PRIVATE_MAX }; @@ -2401,14 +2403,17 @@ static inline void clear_page_private_##name(struct page *page) \ PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER); PAGE_PRIVATE_GET_FUNC(inline, INLINE_INODE); PAGE_PRIVATE_GET_FUNC(gcing, ONGOING_MIGRATION); +PAGE_PRIVATE_GET_FUNC(atomic, ATOMIC_WRITE); PAGE_PRIVATE_SET_FUNC(reference, REF_RESOURCE); PAGE_PRIVATE_SET_FUNC(inline, INLINE_INODE); PAGE_PRIVATE_SET_FUNC(gcing, ONGOING_MIGRATION); +PAGE_PRIVATE_SET_FUNC(atomic, ATOMIC_WRITE); PAGE_PRIVATE_CLEAR_FUNC(reference, REF_RESOURCE); PAGE_PRIVATE_CLEAR_FUNC(inline, INLINE_INODE); PAGE_PRIVATE_CLEAR_FUNC(gcing, ONGOING_MIGRATION); +PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE); static inline unsigned long get_page_private_data(struct page *page) { @@ -2440,6 +2445,7 @@ static inline void clear_page_private_all(struct page *page) clear_page_private_reference(page); clear_page_private_gcing(page); clear_page_private_inline(page); + clear_page_private_atomic(page); f2fs_bug_on(F2FS_P_SB(page), page_private(page)); } From patchwork Tue Jun 25 03:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13710567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C6CACC41513 for ; Tue, 25 Jun 2024 03:14:16 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLwdK-0001Fc-6G; Tue, 25 Jun 2024 03:14:15 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLwdJ-0001FW-7E for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=SMIzjambBpVjpM5+hgPKK8w+gOiakAacXZNeJc+H6r4=; b=TzyjRSX7nUf2O6nnUb9fjfGvT/ phDyBZ8mH7UWYqE8C0UFkgpf3jg3yziPiOoEF4wqaIl0JN9/X0IR9DvHQg/82QL4ycq/l0sWHDPWX njJADZ+V2bZDb0azL5y/Q7v9Ur+QsHWl5iRRkgV4mm7QOb7ghMt7vOBP1IoK/ZbZFoRs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=SMIzjambBpVjpM5+hgPKK8w+gOiakAacXZNeJc+H6r4=; b=hDSk9qZviSgExsLPKfXOU7FTvT jBOQUeuWXPAUDuNGfTbJwMD9PoVTtaSwZQFLArS0DYK3zj5GMdXlWZjCVHo6I7FUueEdDIwS4WCvv +hw/P80gCaH16mEZxZOj8GnIETxSjaQ/S+pB5xed283VPQpfZrEy9DpxbGaQWuJoXL6E=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLwdK-0001V8-CH for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:14 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 41442611D4 for ; Tue, 25 Jun 2024 03:14:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E693C32782; Tue, 25 Jun 2024 03:14:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719285242; bh=0eAJUXNK7k0eoACdFcWnWupZI7JhpdKON3unr3Ao0hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lf7SrOlMH/1fEKjba/eCJe0GgTpp/YFjevK0bmG7R/INKvyLnfOh5bydYmK0UhmoM tRv/KFUhVuxJyyeQoRaN4haiaFbF2l5UDtHwdadhr36XAgXdi42ABihvOfjsGIOyW1 2oMOEz87gwmnR6X65K97gDnoWMhzYn4cq2sO0SWGC279axHqGU6pN7+11QwCcNSe1Z JIUei08+j9earKDKpzvr9DkYsQvJ/0iImPzhWd2lu1SWeJSx5WDRcRI4Jh/Mx1kVK8 bPMhnTvGzNWSKZULg/EYKgXaIk+HwDZrzm7z3n08ItJQ7K8m+uS/O6oEqayP9SAMqJ oTFfMN7RBp+ag== From: Chao Yu To: jaegeuk@kernel.org Date: Tue, 25 Jun 2024 11:13:49 +0800 Message-Id: <20240625031351.3586955-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240625031351.3586955-1-chao@kernel.org> References: <20240625031351.3586955-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1sLwdK-0001V8-CH Subject: [f2fs-dev] [PATCH 2/4] f2fs: atomic: fix to not allow GC to pollute atomic_file 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: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net SQLite App GC Thread Shrinker - f2fs_ioc_start_atomic_write - f2fs_ioc_commit_atomic_write - f2fs_commit_atomic_write - filemap_write_and_wait_range : write atomic_file's data to cow_inode echo 3 > drop_caches - f2fs_gc - gc_data_segment - move_data_page - set_page_dirty : it may load data of previous transaction into pagecache. - f2fs_down_write(&fi->i_gc_rwsem[WRITE]) - __f2fs_commit_atomic_write - f2fs_up_write(&fi->i_gc_rwsem[WRITE]) During committing atomic_file, GC may be triggered to migrate atomic_file's block, so it may contain data of previous transaction in page cache, we should drop atomic_file's cache once it was migrated by GC. And also, we should writeback atomic_file and cow_file's data w/ i_gc_rwsem lock held, in order to avoid block address change during __f2fs_commit_atomic_write(). Meahwhile, this patch adds f2fs_wait_on_block_writeback_range() to wait completion of block migration. Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Chao Yu --- v1: - this patch can fix in-memory data consistency issue caused by f2fs/003 fs/f2fs/segment.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 4db1add43e36..914a13bfc2ab 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -236,6 +236,9 @@ static int __replace_atomic_write_block(struct inode *inode, pgoff_t index, return err; } + if (__is_valid_data_blkaddr(dn.data_blkaddr)) + f2fs_wait_on_block_writeback_range(inode, dn.data_blkaddr, 1); + if (recover) { /* dn.data_blkaddr is always valid */ if (!__is_valid_data_blkaddr(new_addr)) { @@ -339,6 +342,9 @@ static int __f2fs_commit_atomic_write(struct inode *inode) goto out; } + f2fs_wait_on_block_writeback_range(cow_inode, + blkaddr, 1); + new = f2fs_kmem_cache_alloc(revoke_entry_slab, GFP_NOFS, true, NULL); @@ -379,16 +385,28 @@ int f2fs_commit_atomic_write(struct inode *inode) struct f2fs_inode_info *fi = F2FS_I(inode); int err; + f2fs_down_write(&fi->i_gc_rwsem[WRITE]); + err = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); if (err) return err; - f2fs_down_write(&fi->i_gc_rwsem[WRITE]); - f2fs_lock_op(sbi); + /* writeback GCing page of cow_inode */ + err = filemap_write_and_wait_range(fi->cow_inode->i_mapping, + 0, LLONG_MAX); + if (err) + return err; - err = __f2fs_commit_atomic_write(inode); + filemap_invalidate_lock(inode->i_mapping); + + /* don't allow clean page loaded by GC to pollute atomic_file */ + truncate_pagecache(inode, 0); + f2fs_lock_op(sbi); + err = __f2fs_commit_atomic_write(inode); f2fs_unlock_op(sbi); + + filemap_invalidate_unlock(inode->i_mapping); f2fs_up_write(&fi->i_gc_rwsem[WRITE]); return err; From patchwork Tue Jun 25 03:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13710568 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DE456C3064D for ; Tue, 25 Jun 2024 03:14:18 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLwdN-0008MS-Po; Tue, 25 Jun 2024 03:14:18 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLwdM-0008MF-L7 for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=NmHJXYGisQ1RRwa4ETkJsHZbDJngqxhu7cjxBCLxnGU=; b=bHOCYpcAe3OUmfLIRSaoxDDC6R llUCG/cW4XuBGD7jZKwR8kfHjVCcgH2kdCcd/aCE7t8sLr9g5P6hcIeaScKy34dV2qyEC1khZCTsn 6xp9G8o2Ajb4vfUIcMhICfEaGTpQqzMWZNH3ZfASMOqY7jcGEeBJAYQArL0vtibsqpKE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=NmHJXYGisQ1RRwa4ETkJsHZbDJngqxhu7cjxBCLxnGU=; b=S3L617wsPK7AbVhdrb4A+xuBCN DqN95UX7NLc9YvLiMRWlyA1xMCXQuM/edkWE3sgdtPRO75UR9RS5Flxf6QCK0lEtnNPYkfsPAja5D mvsPw7RKfystaKynYn9L5rqorPotmwQE6EpmL+M0x74VBcTkdlejihl63GM4GrqhhGws=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLwdN-0001VR-0s for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:16 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id DCC96611CC for ; Tue, 25 Jun 2024 03:14:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 912ECC4AF07; Tue, 25 Jun 2024 03:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719285245; bh=7i9ANIkcb5e+IjTGnXP1+fnS3hh1UJ930GMPGvqfu9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oMOyQR//ysFjBcydfxv3gFlf1Xl1zVfYea9wWSmsmP7PuAKdH2XRqxpQeBvN5fA6q YzzQsRaPy8yrJSo+a0BFSoZGbpseVHwr5mlpjK3l9xj8fbRlmzVxaKpQuT9Sslchtt hubqkx+BApzr9szwqKRcMXJAav2kTc4TCbD94LiG3lJP1DpEOgF8/fYdDPLEelq6qU l33HIsHL2lIdUZTr79zgDPr0cqe/s1YY+YXQIkwkSiFbG+Lwpb//PWreEFEAxlV7Ba +WM6BMUOWrzs+tu2YA+IzWwLaN7KZmimrX/Z3MnOcbxCRJASdsij4aDkXp/XOiKIiB SOpaIjO7/PJmA== From: Chao Yu To: jaegeuk@kernel.org Date: Tue, 25 Jun 2024 11:13:50 +0800 Message-Id: <20240625031351.3586955-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240625031351.3586955-1-chao@kernel.org> References: <20240625031351.3586955-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1sLwdN-0001VR-0s Subject: [f2fs-dev] [PATCH 3/4] f2fs: atomic: fix to truncate pagecache before on-disk metadata truncation 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: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net We should always truncate pagecache while truncating on-disk data. Fixes: a46bebd502fe ("f2fs: synchronize atomic write aborts") Signed-off-by: Chao Yu --- fs/f2fs/file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 2203904383a6..0355cb054521 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2185,6 +2185,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) clear_inode_flag(fi->cow_inode, FI_INLINE_DATA); } else { /* Reuse the already created COW inode */ + truncate_setsize(inode, 0); ret = f2fs_do_truncate_blocks(fi->cow_inode, 0, true); if (ret) { f2fs_up_write(&fi->i_gc_rwsem[WRITE]); From patchwork Tue Jun 25 03:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13710569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C73CDC2BBCA for ; Tue, 25 Jun 2024 03:14:20 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sLwdR-000895-1X; Tue, 25 Jun 2024 03:14:20 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sLwdP-00088y-B7 for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=zFoPWh3n1vldeyDoiiwfNDaGFyKz3NB2faLdmiv25Cs=; b=LoaY7wRFJeu3UZ6AMpvs9w7Daz KKNLXjQ2jlD41Z5NNQFaYpTTwQLRZHZJWuW1f2gIfpF6MlYCJlijyNxxCoRbXFtwtxhyBVxYnrhkY lVvHwwDmtIKg/7AcqjhCQ04mlIRuWhPHSQdK+bP+wMSbyWY9EJ/37PqJ9irxDiykZzSw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=zFoPWh3n1vldeyDoiiwfNDaGFyKz3NB2faLdmiv25Cs=; b=AnpHDp5uMXeGNaO7UWsdIyvC0+ 84P/SIt2Y8600Eyn9Lv1NysRRLek/wosuNF0vdx8R0Ks6We4lhNNIJbZSwJhzsTwpWOcvCwec9wmx 6L59GnnqwP6rvEPmC7y7A+zcParV59BQ4cVgU35WRepaxn7krxmNplwyWcBVnlDR2zvE=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sLwdO-0001Vd-QS for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Jun 2024 03:14:18 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A85A6611DE for ; Tue, 25 Jun 2024 03:14:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2CF7C4AF09; Tue, 25 Jun 2024 03:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1719285247; bh=xmtO96A+N055YtD+3waXk7KlXygllEUWidyxOMqx4xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=As17zSnO0H4YoH+VEVrP911ZuxvwpgRbdBTze0ZpkNW/ELFc5oFf3HykaV5PANk7V 2ab/7PRTOjsr6r8s93ABFdevstCei9Equ9lwnzbWYj1q5ETshXq2OnFghqFDsYetV1 Cde/ANAIZobA0uB4A09LUfECsCiwkmMdt3OW8WYqBlPQyRuSoNfvV/HYYSNknt6EPn P+LmSyn3ekDO+OGnl3c9P0GY+b3aoDdWe5ijfWLYOGBwW2xUP+oEaIkr0p5a5e6iD4 akbjT990sIF+LS/A7BewqCDY92BD8N15JmuelcQLhk3z1FnqQL/qKl/J329434dGdF yGpMuq1R6GzIA== From: Chao Yu To: jaegeuk@kernel.org Date: Tue, 25 Jun 2024 11:13:51 +0800 Message-Id: <20240625031351.3586955-4-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240625031351.3586955-1-chao@kernel.org> References: <20240625031351.3586955-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1sLwdO-0001Vd-QS Subject: [f2fs-dev] [PATCH 4/4] f2fs: atomic: fix to forbid dio in atomic_file 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: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net atomic write can only be used via buffered IO, let's fail direct IO on atomic_file and return -EOPNOTSUPP. Signed-off-by: Chao Yu --- fs/f2fs/file.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 0355cb054521..a527de1e7a2f 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2150,6 +2150,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) goto out; f2fs_down_write(&fi->i_gc_rwsem[WRITE]); + f2fs_down_write(&fi->i_gc_rwsem[READ]); /* * Should wait end_io to count F2FS_WB_CP_DATA correctly by @@ -2209,6 +2210,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp, bool truncate) } f2fs_i_size_write(fi->cow_inode, isize); + f2fs_up_write(&fi->i_gc_rwsem[READ]); f2fs_up_write(&fi->i_gc_rwsem[WRITE]); f2fs_update_time(sbi, REQ_TIME); @@ -4537,6 +4539,13 @@ static ssize_t f2fs_dio_read_iter(struct kiocb *iocb, struct iov_iter *to) f2fs_down_read(&fi->i_gc_rwsem[READ]); } + /* dio is not compatible w/ atomic file */ + if (f2fs_is_atomic_file(inode)) { + f2fs_up_read(&fi->i_gc_rwsem[READ]); + ret = -EOPNOTSUPP; + goto out; + } + /* * We have to use __iomap_dio_rw() and iomap_dio_complete() instead of * the higher-level function iomap_dio_rw() in order to ensure that the @@ -4948,6 +4957,12 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) /* Determine whether we will do a direct write or a buffered write. */ dio = f2fs_should_use_dio(inode, iocb, from); + /* dio is not compatible w/ atomic write */ + if (dio && f2fs_is_atomic_file(inode)) { + ret = -EOPNOTSUPP; + goto out_unlock; + } + /* Possibly preallocate the blocks for the write. */ target_size = iocb->ki_pos + iov_iter_count(from); preallocated = f2fs_preallocate_blocks(iocb, from, dio);