From patchwork Tue Nov 15 18:00:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goldwyn Rodrigues X-Patchwork-Id: 13044057 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B8C6C46467 for ; Tue, 15 Nov 2022 18:02:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231698AbiKOSCE (ORCPT ); Tue, 15 Nov 2022 13:02:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231475AbiKOSBO (ORCPT ); Tue, 15 Nov 2022 13:01:14 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C7AC62C7 for ; Tue, 15 Nov 2022 10:01:13 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1CE291F8E0; Tue, 15 Nov 2022 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1668535272; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wqci/3B1Q9K7U2AZI/lsbKOytc6jr8mWCM1rkUcjzog=; b=pn1Uugat2MHvpf88oPhgR1/gkLBRO+QvRnz3K68jlLlbAIxE4NnlDNjs1N/9F7C836X0hV 877G01mVVlgouj0Jvb1QCQjf1Df/SOWw6U8pbl04ilzIcmdQeisWjJj0mt47luztmxcDeA fGmeeHmnVcXiuPUJ7yQ6CFpddwh8hqs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1668535272; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wqci/3B1Q9K7U2AZI/lsbKOytc6jr8mWCM1rkUcjzog=; b=DcYhfbhBDo9Vghc+FjBAoZJ0tAYYezxdIGi/CXSVoxACSXQuIPc7iSdu/wRs7QLamJHxca GTfD/L2XoQPsUBCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C4CFE13A91; Tue, 15 Nov 2022 18:01:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id p8kTKOfTc2PVZAAAMHmgww (envelope-from ); Tue, 15 Nov 2022 18:01:11 +0000 From: Goldwyn Rodrigues To: linux-btrfs@vger.kernel.org Cc: Goldwyn Rodrigues , Goldwyn Rodrigues Subject: [PATCH 16/16] btrfs: btree_writepages lock extents before pages Date: Tue, 15 Nov 2022 12:00:34 -0600 Message-Id: <994c7a74720e3c8589263095704dc7f87cfdb3e7.1668530684.git.rgoldwyn@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Lock extents before pages while performing btree_writepages(). Signed-off-by: Goldwyn Rodrigues --- fs/btrfs/disk-io.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8ac9612f8f27..b7e7c4c9d404 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -858,8 +858,25 @@ static int btree_migrate_folio(struct address_space *mapping, static int btree_writepages(struct address_space *mapping, struct writeback_control *wbc) { + u64 start, end; + struct btrfs_inode *inode = BTRFS_I(mapping->host); + struct extent_state *cached = NULL; struct btrfs_fs_info *fs_info; int ret; + u64 isize = round_up(i_size_read(&inode->vfs_inode), PAGE_SIZE) - 1; + + if (wbc->range_cyclic) { + start = mapping->writeback_index << PAGE_SHIFT; + end = isize; + } else { + start = round_down(wbc->range_start, PAGE_SIZE); + end = round_up(wbc->range_end, PAGE_SIZE) - 1; + end = min(isize, end); + } + + if (start >= end) + return 0; + if (wbc->sync_mode == WB_SYNC_NONE) { @@ -874,7 +891,12 @@ static int btree_writepages(struct address_space *mapping, if (ret < 0) return 0; } - return btree_write_cache_pages(mapping, wbc); + + lock_extent(&inode->io_tree, start, end, &cached); + ret = btree_write_cache_pages(mapping, wbc); + unlock_extent(&inode->io_tree, start, end, &cached); + + return ret; } static bool btree_release_folio(struct folio *folio, gfp_t gfp_flags)