From patchwork Mon Jun 5 08:45:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13267088 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 DDBA1C7EE23 for ; Mon, 5 Jun 2023 08:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbjFEIpd (ORCPT ); Mon, 5 Jun 2023 04:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbjFEIp3 (ORCPT ); Mon, 5 Jun 2023 04:45:29 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D15A100 for ; Mon, 5 Jun 2023 01:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=3+bItWR1gepd8DnNnjGK8NxI5XtSJB11Dh+SzqbGHDw=; b=AeCKBFaDqFr/HGdmAZzjpe/6V0 oH2u0WiELpg/6+4q/G/NpgPWL9zisGbC9rMkVZKUKb6btx5dKUlHbe7REVgJhKW13LITOkQf8iZqs m3bh1u73h8vTyeD7e3pv8V/tAkYpl1It4UXXSraOE+AFZeUn46YDaJ/9KrXOBnsuJ8XrVvCDE9b2M tZzvAqoKqmfL5smtSq40N46OVohbGrqZE7pLuuXZoIP2hEqtJvwJ+Rp5dp6rG5mVqLeppuI8sy4EI DR3MRLeh5M6rlbw933QAgwFQmicqtPUSTdofeeFrngwkD8/t9GisjchGVRiTw74ZPzPFKUZyuoIOs YzIQq3lg==; Received: from [2001:4bb8:191:e9d5:e931:d7f5:9239:69f3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q65q8-00Eka0-2Q; Mon, 05 Jun 2023 08:45:25 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] btrfs: factor out a btrfs_inode_is_nodatasum helper Date: Mon, 5 Jun 2023 10:45:18 +0200 Message-Id: <20230605084519.580346-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230605084519.580346-1-hch@lst.de> References: <20230605084519.580346-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Split out a helper to check if an inode needs nodatasum treatment. Signed-off-by: Christoph Hellwig --- fs/btrfs/bio.c | 3 +-- fs/btrfs/btrfs_inode.h | 7 +++++++ fs/btrfs/file-item.c | 3 +-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index c9b4aa339b4b07..627d06fbb4c425 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -659,8 +659,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) * Csum items for reloc roots have already been cloned at this * point, so they are handled as part of the no-checksum case. */ - if (inode && !(inode->flags & BTRFS_INODE_NODATASUM) && - !test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state) && + if (inode && !btrfs_inode_is_nodatasum(inode) && !btrfs_is_data_reloc_root(inode->root)) { if (should_async_write(bbio) && btrfs_wq_submit_bio(bbio, bioc, &smap, mirror_num)) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 8abf96cfea8fae..713439d62adda3 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -535,4 +535,11 @@ void btrfs_update_inode_bytes(struct btrfs_inode *inode, const u64 add_bytes, const u64 del_bytes); void btrfs_assert_inode_range_clean(struct btrfs_inode *inode, u64 start, u64 end); +static inline bool btrfs_inode_is_nodatasum(struct btrfs_inode *inode) +{ + return (inode->flags & BTRFS_INODE_NODATASUM) || + test_bit(BTRFS_FS_STATE_NO_CSUMS, + &inode->root->fs_info->fs_state); +} + #endif diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 2e7d5ec6c9a68c..5e6603e76e5ac0 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -355,8 +355,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) blk_status_t ret = BLK_STS_OK; u32 bio_offset = 0; - if ((inode->flags & BTRFS_INODE_NODATASUM) || - test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)) + if (btrfs_inode_is_nodatasum(inode)) return BLK_STS_OK; /* From patchwork Mon Jun 5 08:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13267089 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 1E080C7EE23 for ; Mon, 5 Jun 2023 08:45:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230265AbjFEIpg (ORCPT ); Mon, 5 Jun 2023 04:45:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbjFEIpg (ORCPT ); Mon, 5 Jun 2023 04:45:36 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C534EB0 for ; Mon, 5 Jun 2023 01:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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; bh=WkmW6FngTZpGZpAU0L5bukZ1tI7TJIwU/Hp0ccDcxXo=; b=cw7OlYs4NeJOyFMATY5xeqyLeU EaRXxkaBwUqst6UImuKYnHV8BkRaY9trY2j8jCw0wRd3ft/73NlmyQKf6dZo8QBsYPe9YRy1lML1L JgXju79619K3cQnXJEXU99gfph9HOU+VR14KqAp9UhcAjti4GPgiOs6euT1gmhudeSZFKriU/UmUK dTYjK5/sXQvU8/B0+SHC2nyO2OnJWNdTqtnCXzmiOx6EazgKHyiTqKWIcOglmSaNDESr7dR2aa4zV KdVUD561HR6BFd5EPitvenmhnaOG9Ekh+zupZE6ZEtZ6AO0wmGQQXIeBjnvw2rlEgty/6hU7Gz1NB JDhvj7Rw==; Received: from [2001:4bb8:191:e9d5:e931:d7f5:9239:69f3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q65qC-00Ekan-05; Mon, 05 Jun 2023 08:45:28 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs: allocate dummy ordereded_sums objects for nocsum I/O on zoned file systems Date: Mon, 5 Jun 2023 10:45:19 +0200 Message-Id: <20230605084519.580346-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230605084519.580346-1-hch@lst.de> References: <20230605084519.580346-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Zoned file systems now need the ordereded_sums structure to record the actual write location returned by zone append, so allocate dummy structures without the csum array for them when the I/O doesn't use checksums, and free them when completing the ordered_extent. Fixes: 5a1b7f2b6306 ("btrfs: optimize the logical to physical mapping for zoned writes") Signed-off-by: Christoph Hellwig --- fs/btrfs/bio.c | 4 ++++ fs/btrfs/file-item.c | 12 ++++++++++-- fs/btrfs/zoned.c | 11 ++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 627d06fbb4c425..2482739be49163 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -668,6 +668,10 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) ret = btrfs_bio_csum(bbio); if (ret) goto fail_put_bio; + } else if (use_append) { + ret = btrfs_csum_one_bio(bbio); + if (ret) + goto fail_put_bio; } } diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 5e6603e76e5ac0..1308c369b1ebd8 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -751,8 +751,16 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) sums->logical = bio->bi_iter.bi_sector << SECTOR_SHIFT; index = 0; - shash->tfm = fs_info->csum_shash; + /* + * If we are called for a nodatasum inode, this means we are on a zoned + * file system. In this case a ordered_csum structure needs to be + * allocated to track the logical address actually written, but it does + * notactually carry any checksums. + */ + if (btrfs_inode_is_nodatasum(inode)) + goto done; + shash->tfm = fs_info->csum_shash; bio_for_each_segment(bvec, bio, iter) { if (!ordered) { ordered = btrfs_lookup_ordered_extent(inode, offset); @@ -817,7 +825,7 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) } this_sum_bytes = 0; - +done: /* * The ->sums assignment is for zoned writes, where a bio never spans * ordered extents and is only done unconditionally because that's cheaper diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index bbde4ddd475492..1f5497b9b2695c 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1717,7 +1717,7 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered) if (!btrfs_zoned_split_ordered(ordered, logical, len)) { set_bit(BTRFS_ORDERED_IOERR, &ordered->flags); btrfs_err(fs_info, "failed to split ordered extent\n"); - return; + goto out; } logical = sum->logical; len = sum->len; @@ -1725,6 +1725,15 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered) if (ordered->disk_bytenr != logical) btrfs_rewrite_logical_zoned(ordered, logical); + +out: + if (btrfs_inode_is_nodatasum(BTRFS_I(ordered->inode))) { + while ((sum = list_first_entry_or_null(&ordered->list, + typeof(*sum), list))) { + list_del(&sum->list); + kfree(sum); + } + } } bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info,