From patchwork Tue Apr 18 17:52:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daeho Jeong X-Patchwork-Id: 13216017 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 7CC07C6FD18 for ; Tue, 18 Apr 2023 17:52:21 +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 1popV5-0008Fr-Qr; Tue, 18 Apr 2023 17:52:18 +0000 Received: from [172.30.20.202] (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 1popV5-0008Fl-2J for linux-f2fs-devel@lists.sourceforge.net; Tue, 18 Apr 2023 17:52: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: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=ecJfBqabO7lqZzAX7J4vFKzXJzBbVDV46eKIKNvjRGA=; b=g505lIfTGTFXl+st3ddigC1vqM sdjwMNA9djsChxNu4EXJfqtnUz5/QeOTUkMMH5SlK1BOX5L0QJmRUkZ+8/x4D7fFgyqRjNl8Oe7Pv HhugJEnUEqFqtuot0TAnNscSQB/UgL9BZULe1IWMVRj0KEC27bUyz7HJ751OL86/fWBM=; 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=ecJfBqabO7lqZzAX7J4vFKzXJzBbVDV46eKIKNvjRGA=; b=d 8o9OhL8x4iHonzqFEE5SFMIcxldieauzTimZSvK4/vY3sWmHEKoGnTzCbOz6MysUxUir54/6qE9zk I//bhXBD0EI4X6dB5MHN7jmOOl6E8HNixdeQh4tlCbd43g5LTUKJ5SMmlaahGHi+HBAhK2z1OJ+gg 6UyosuFVgY8PlCu8=; Received: from mail-pj1-f48.google.com ([209.85.216.48]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1popV2-00012k-Ct for linux-f2fs-devel@lists.sourceforge.net; Tue, 18 Apr 2023 17:52:16 +0000 Received: by mail-pj1-f48.google.com with SMTP id pc15so156333pjb.3 for ; Tue, 18 Apr 2023 10:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681840330; x=1684432330; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ecJfBqabO7lqZzAX7J4vFKzXJzBbVDV46eKIKNvjRGA=; b=UuRVKbYHNO2+ypBmSsydrxG8hH0RsWKq/LU/ZHKXV3YRapO0ysKFvJSkROA9g7vm9B kLFt2FJPSyJKCbQOci0pY9obi5lV3WhsPGxGZCQOvGTRpPXXNfeJ+YiKMsoWUFYfYVVC brzT+MNq4jqVKJ0DhI5dCPneI/MVeL9HK+9+VVuccBxTEIyGtwUDbxfQFDizQEXMSGHS CC3WtzHnHWxWEoebWLZ+Squf20SfvvP28iI3yEsj8IvyblGco7JE/OvflzMQMJddtIWS VK92b2mxVVLsDvnzBJjk+35Ap9aTyT4X8bk/cmStc14JO8egcGxG0gNu7bYh+C/DLGPx LLrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681840330; x=1684432330; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ecJfBqabO7lqZzAX7J4vFKzXJzBbVDV46eKIKNvjRGA=; b=WHf8sgCvD12PjzF+NmUW5q1jKoW+ui6mUrz894ClbhEekKY8DAZTZ0U9iMHkwYgvfQ tUrLGY0VvmzFES258rFHaO05T1D8FEAxkAHKrCiYoDfkt7ZsdGX9YA/3IY6i7qMYa+wo WwvCipYqI6maORH0sMPo6MFeI01Rk/ElGl6mxFNw3HF+Um5XLEbaWMKcqUbIxw1C0PFk VD8cLYadw4bzR9rEmanruLBeWLFiKc3PtiRH8HiUqP6oOKGAvcy2NytkvwG4JSikyK0K FcnFZ4zvi/I5IgFUVdP+/PntlWheAiBf/blMVNBXhf6VrezxDIjc5ImzaNUzs7usT6pp Vwlw== X-Gm-Message-State: AAQBX9fpm+JpA/ytQxv3cynlEQTPM0JduytCZHbSvASu8ou6ITBLdqHo d5T7j9CUxyZY1tnjmuhUyY1zSLeHhnY= X-Google-Smtp-Source: AKy350bRDp0Yo5TSKicloGZlgruDCfWjNghh4tbzOOhERT6f6BCtJkiJzdsOxSs6PKdY33rl8XzJIQ== X-Received: by 2002:a05:6a20:a110:b0:ef:8b50:56b7 with SMTP id q16-20020a056a20a11000b000ef8b5056b7mr470860pzk.60.1681840330484; Tue, 18 Apr 2023 10:52:10 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2620:15c:211:201:e22b:bd7c:4df6:1ae0]) by smtp.gmail.com with ESMTPSA id w3-20020a17090ac98300b00227223c58ecsm8881772pjt.42.2023.04.18.10.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 10:52:10 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Date: Tue, 18 Apr 2023 10:52:06 -0700 Message-ID: <20230418175206.3282328-1-daeho43@gmail.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog MIME-Version: 1.0 X-Headers-End: 1popV2-00012k-Ct Subject: [f2fs-dev] [PATCH] f2fs: use cow inode data when updating atomic write 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 Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Daeho Jeong Need to use cow inode data content instead of the one in the original inode, when we try to write the already updated atomic write files. Signed-off-by: Daeho Jeong --- fs/f2fs/data.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 8df225014304..7165b1202f53 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3491,7 +3491,7 @@ static int __reserve_data_block(struct inode *inode, pgoff_t index, static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi, struct page *page, loff_t pos, unsigned int len, - block_t *blk_addr, bool *node_changed) + block_t *blk_addr, bool *node_changed, bool *use_cow) { struct inode *inode = page->mapping->host; struct inode *cow_inode = F2FS_I(inode)->cow_inode; @@ -3505,10 +3505,12 @@ static int prepare_atomic_write_begin(struct f2fs_sb_info *sbi, /* Look for the block in COW inode first */ err = __find_data_block(cow_inode, index, blk_addr); - if (err) + if (err) { return err; - else if (*blk_addr != NULL_ADDR) + } else if (*blk_addr != NULL_ADDR) { + *use_cow = true; return 0; + } if (is_inode_flag_set(inode, FI_ATOMIC_REPLACE)) goto reserve_block; @@ -3538,6 +3540,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, struct page *page = NULL; pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT; bool need_balance = false; + bool use_cow = false; block_t blkaddr = NULL_ADDR; int err = 0; @@ -3597,7 +3600,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, if (f2fs_is_atomic_file(inode)) err = prepare_atomic_write_begin(sbi, page, pos, len, - &blkaddr, &need_balance); + &blkaddr, &need_balance, &use_cow); else err = prepare_write_begin(sbi, page, pos, len, &blkaddr, &need_balance); @@ -3637,7 +3640,9 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); goto fail; } - err = f2fs_submit_page_read(inode, page, blkaddr, 0, true); + err = f2fs_submit_page_read(use_cow ? + F2FS_I(inode)->cow_inode : inode, page, + blkaddr, 0, true); if (err) goto fail;