From patchwork Mon May 8 16:08:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234732 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 02A8EC77B7F for ; Mon, 8 May 2023 16:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232838AbjEHQIu (ORCPT ); Mon, 8 May 2023 12:08:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbjEHQIs (ORCPT ); Mon, 8 May 2023 12:08:48 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D5A5243 for ; Mon, 8 May 2023 09:08:46 -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=mk/eYF4kiK8qAMs5oBu1V5rGk5eSTdx1+ACao+nM2FQ=; b=qXWOxAkp3hh7ynVcVhAurMWqoc yIeJkZpE4YLerYuwXJjGv5r65FdsQ7COagcKKsH/D1IilABTl36Gytjd8hi0PhAOJaOFcgFAXLdF9 Bpu4/+0wAj5RaeQclPwvnp2HlhLaInWwY4TMJnzXlJ1KBccV1ngKQ18KNtSz1R32HJRFUkj8JdY8g ehPvWiiOhblxqOT84JQiInRh5vgCU4G6LdNWwtAmelrpSqrfMdifUNQPGzui0jsoV6xpHoOPiqwTY Rd8tsDEqeZueEdUILUyk9nb4QJh18gAyfckBLxEfZZHFMLN8Y7g7Xhc40b86NU7ZMsU13DEua8MPx vgK2KQeg==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Po-000vz3-1O; Mon, 08 May 2023 16:08:44 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn , syzbot+d8941552e21eac774778@syzkaller.appspotmail.com, Anand Jain Subject: [PATCH 01/21] btrfs: don't BUG_ON on allocation failure in btrfs_csum_one_bio Date: Mon, 8 May 2023 09:08:23 -0700 Message-Id: <20230508160843.133013-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 From: Johannes Thumshirn Since f8a53bb58ec7 ("btrfs: handle checksum generation in the storage layer") the failures of btrfs_csum_one_bio() are handled via bio_end_io(). This means, we can return BLK_STS_RESOURCE from btrfs_csum_one_bio() in case the allocation of the ordered sums fails. This also fixes a syzkaller report, where injecting a failure into the kvzalloc() call results in a BUG_ON(). Reported-by: syzbot+d8941552e21eac774778@syzkaller.appspotmail.com Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig Reviewed-by: Anand Jain --- fs/btrfs/file-item.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index bda1a41091601f..e74b9804bcdec8 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -792,7 +792,9 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) sums = kvzalloc(btrfs_ordered_sum_size(fs_info, bytes_left), GFP_KERNEL); memalloc_nofs_restore(nofs_flag); - BUG_ON(!sums); /* -ENOMEM */ + if (!sums) + return BLK_STS_RESOURCE; + sums->len = bytes_left; ordered = btrfs_lookup_ordered_extent(inode, offset); From patchwork Mon May 8 16:08:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234734 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 BAFA2C7EE24 for ; Mon, 8 May 2023 16:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233350AbjEHQIz (ORCPT ); Mon, 8 May 2023 12:08:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232528AbjEHQIt (ORCPT ); Mon, 8 May 2023 12:08:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF3AC65A0 for ; Mon, 8 May 2023 09:08:48 -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=/PLqqKbsgVYr1zZtKyLe+QrK8uW+x5+T+F3GbGbZQO8=; b=FO3DPsTz03XDaINCO5tImsVlU7 08l9clOtX+qEysLoPGuO+hongmqM6J0F4QBVe6/5DoD7hmRcCWH7bs4av2dm5aXmqj39/+ZhpLCK0 C4VeHBWQHUsSd/IZ4t3Y+OcKAmdcZtWyXMuQn7Sczsyi+CAe6kX61vJLdXHz6GtWVECdeP5mHbKIY ku1WWsnRR7gIekWoVIi/OpAz9HW51O7rIwCKVhpNAppQ7wZzMF3zR3IQS9IC06utz+ZNxN5OzPLnF R2PN0VrOG2esZVdWKk/wJeQHps7MbAg/1iP1sQfmv0qy5FhG66FsOpNFH2JKaPhpO10Wj1ZQaH54l zD5JT/pw==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pp-000vzB-0G; Mon, 08 May 2023 16:08:45 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 02/21] btrfs: fix file_offset for REQ_BTRFS_ONE_ORDERED bios that get split Date: Mon, 8 May 2023 09:08:24 -0700 Message-Id: <20230508160843.133013-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 If a bio gets split, it needs to have a proper file_offset for checksum validation and repair to work properly. Based on feedback from Josef, commit 852eee62d31a ("btrfs: allow btrfs_submit_bio to split bios") skipped this adjustment for ONE_ORDERED bios. But if we actually ever need to split a ONE_ORDERED read bio, this will lead to a wrong file offset in the repair code. Right now the only user of the file_offset is logging of an error message so this is mostly harmless, but the wrong offset might be more problematic for additional users in the future. Fixes: 852eee62d31a ("btrfs: allow btrfs_submit_bio to split bios") Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/bio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 1ea7f4eebf01e6..ae30ef638716b0 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -95,8 +95,7 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info, btrfs_bio_init(bbio, fs_info, NULL, orig_bbio); bbio->inode = orig_bbio->inode; bbio->file_offset = orig_bbio->file_offset; - if (!(orig_bbio->bio.bi_opf & REQ_BTRFS_ONE_ORDERED)) - orig_bbio->file_offset += map_length; + orig_bbio->file_offset += map_length; atomic_inc(&orig_bbio->pending_ios); return bbio; From patchwork Mon May 8 16:08:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234731 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 BD7CEC7EE22 for ; Mon, 8 May 2023 16:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232438AbjEHQIt (ORCPT ); Mon, 8 May 2023 12:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbjEHQIs (ORCPT ); Mon, 8 May 2023 12:08:48 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 537D36580 for ; Mon, 8 May 2023 09:08:47 -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=d6snkGl6NTgqQNVLnENkwoZL1bp302RcUwQDp7GRoDI=; b=WSSlqBtIWIJ3kxPfZH+nmFH7zw 6gKaB+OzresXFCyIHbz16EZVnQQNxUJQOBIcoys/FDKFYwytdeiu8PLciabsvN974asVjo1DNnDIp TjZ9XJJ6JGKKqQ9ipjun32MPemGo4/0+SkIcWSfEc5l5vBCOMBHCmRbnUKqIP1bjXm+XcEfbKOmTN Pm728Kr11Y3RCzjcH8A49slp/AL2PD6OHLgUAyoHUourAPMKW0n4qqttxpPro82yOBG4z5S6txc3T 8wufLET57m7lacgfylca1OKkpsjCHdPqLTenoK/yG6BxmMGAE2tXArpixrPbtOBmrj3MzNbdj5Pya U7Ghw1vA==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pp-000vzf-2M; Mon, 08 May 2023 16:08:45 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 03/21] btrfs: limit write bios to a single ordered extent Date: Mon, 8 May 2023 09:08:25 -0700 Message-Id: <20230508160843.133013-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Currently buffered writeback bios are allowed to span multiple ordered_extents, although that basically never actually happens since commit 4a445b7b6178 ("btrfs: don't merge pages into bio if their page offset is not contiguous"). Supporting bios than span ordered_extents complicates the file checksumming code, and prevents us from adding an ordered_extent pointer to the btrfs_bio structure. Use the existing code to limit a bio to single ordered_extent for zoned device writes for all writes. This allows to remove the REQ_BTRFS_ONE_ORDERED flags, and the handling of multiple ordered_extents in btrfs_csum_one_bio. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/bio.c | 3 --- fs/btrfs/bio.h | 3 --- fs/btrfs/compression.c | 2 -- fs/btrfs/extent_io.c | 9 ++------- fs/btrfs/file-item.c | 33 --------------------------------- 5 files changed, 2 insertions(+), 48 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index ae30ef638716b0..5f418eeaac070b 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -471,9 +471,6 @@ static void btrfs_submit_mirrored_bio(struct btrfs_io_context *bioc, int dev_nr) static void __btrfs_submit_bio(struct bio *bio, struct btrfs_io_context *bioc, struct btrfs_io_stripe *smap, int mirror_num) { - /* Do not leak our private flag into the block layer. */ - bio->bi_opf &= ~REQ_BTRFS_ONE_ORDERED; - if (!bioc) { /* Single mirror read/write fast path. */ btrfs_bio(bio)->mirror_num = mirror_num; diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index a8eca3a6567320..000e807f785395 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -91,9 +91,6 @@ static inline void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) bbio->end_io(bbio); } -/* Bio only refers to one ordered extent. */ -#define REQ_BTRFS_ONE_ORDERED REQ_DRV - /* Submit using blkcg_punt_bio_submit. */ #define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 14f5f25049a0d7..4f85113cbf9f0c 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -295,8 +295,6 @@ void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, ASSERT(IS_ALIGNED(start, fs_info->sectorsize) && IS_ALIGNED(len, fs_info->sectorsize)); - write_flags |= REQ_BTRFS_ONE_ORDERED; - cb = alloc_compressed_bio(inode, start, REQ_OP_WRITE | write_flags, end_compressed_bio_write); cb->start = start; diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index a1adadd5d25ddb..92e1edfcfb9cb4 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -907,12 +907,9 @@ static void alloc_new_bio(struct btrfs_inode *inode, bio_ctrl->len_to_oe_boundary = U32_MAX; /* - * Limit the extent to the ordered boundary for Zone Append. - * Compressed bios aren't submitted directly, so it doesn't apply to - * them. + * Limit data write bios to the ordered boundary. */ - if (bio_ctrl->compress_type == BTRFS_COMPRESS_NONE && - btrfs_use_zone_append(bbio)) { + if (bio_ctrl->wbc) { struct btrfs_ordered_extent *ordered; ordered = btrfs_lookup_ordered_extent(inode, file_offset); @@ -922,9 +919,7 @@ static void alloc_new_bio(struct btrfs_inode *inode, ordered->disk_num_bytes - file_offset); btrfs_put_ordered_extent(ordered); } - } - if (bio_ctrl->wbc) { /* * Pick the last added device to support cgroup writeback. For * multi-device file systems this means blk-cgroup policies have diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index e74b9804bcdec8..1c1cb6373f2c30 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -733,8 +733,6 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) struct bio_vec bvec; int index; unsigned int blockcount; - unsigned long total_bytes = 0; - unsigned long this_sum_bytes = 0; int i; unsigned nofs_flag; @@ -776,34 +774,6 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) - 1); for (i = 0; i < blockcount; i++) { - if (!(bio->bi_opf & REQ_BTRFS_ONE_ORDERED) && - !in_range(offset, ordered->file_offset, - ordered->num_bytes)) { - unsigned long bytes_left; - - sums->len = this_sum_bytes; - this_sum_bytes = 0; - btrfs_add_ordered_sum(ordered, sums); - btrfs_put_ordered_extent(ordered); - - bytes_left = bio->bi_iter.bi_size - total_bytes; - - nofs_flag = memalloc_nofs_save(); - sums = kvzalloc(btrfs_ordered_sum_size(fs_info, - bytes_left), GFP_KERNEL); - memalloc_nofs_restore(nofs_flag); - if (!sums) - return BLK_STS_RESOURCE; - - sums->len = bytes_left; - ordered = btrfs_lookup_ordered_extent(inode, - offset); - ASSERT(ordered); /* Logic error */ - sums->bytenr = (bio->bi_iter.bi_sector << SECTOR_SHIFT) - + total_bytes; - index = 0; - } - data = bvec_kmap_local(&bvec); crypto_shash_digest(shash, data + (i * fs_info->sectorsize), @@ -812,12 +782,9 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) kunmap_local(data); index += fs_info->csum_size; offset += fs_info->sectorsize; - this_sum_bytes += fs_info->sectorsize; - total_bytes += fs_info->sectorsize; } } - this_sum_bytes = 0; btrfs_add_ordered_sum(ordered, sums); btrfs_put_ordered_extent(ordered); return 0; From patchwork Mon May 8 16:08:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234733 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 E077BC7EE22 for ; Mon, 8 May 2023 16:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233098AbjEHQIx (ORCPT ); Mon, 8 May 2023 12:08:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230414AbjEHQIt (ORCPT ); Mon, 8 May 2023 12:08:49 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 721104EE5 for ; Mon, 8 May 2023 09:08:48 -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=4of+mpuzF0uqA1N81tVzZ0M4R7lBJ+9pGzXtukj9jgM=; b=soP2MZX9sYpv0qYEC5KZiV9BKg VhbYKtJVCh6eydRh+AJYbGJWlxfApFNN/7zwF2sPbKVtSWgJJkW5iHvJMgycZXGQTBPglnjPLKtry aaRI96EcDpVZbUhkNvO3sIufxqRN/N1qa+pX/dKKTbQUfI2DsN5lQG8dMzal2nzEdtSCj0ppTjES/ MgQ8Y6dA121mxaulwbDsDuXbYKlaL4rYqG7jgKz9FbMXk/hGgJCC6ZMgIt6HLUj4vaHL3ShdsOMGs tuvkK1ZmseoBS+7f4cO2vhiFM+Ug74qqYqyzchW3dtfXZ5GV165td4y2jw/OE4B4NLSCBmAMmsUMe 2L0tbruw==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pq-000w00-1F; Mon, 08 May 2023 16:08:46 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 04/21] btrfs: merge the two calls to btrfs_add_ordered_extent in run_delalloc_nocow Date: Mon, 8 May 2023 09:08:26 -0700 Message-Id: <20230508160843.133013-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Refactor run_delalloc_nocow a little bit so that there is only a single call to btrfs_add_ordered_extent instead of two. Signed-off-by: Christoph Hellwig --- fs/btrfs/inode.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 4f9ef5ca385650..f0372a01c12423 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2145,6 +2145,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, u64 ram_bytes; u64 nocow_end; int extent_type; + bool is_prealloc; nocow = false; @@ -2283,8 +2284,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, } nocow_end = cur_offset + nocow_args.num_bytes - 1; - - if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) { + is_prealloc = extent_type == BTRFS_FILE_EXTENT_PREALLOC; + if (is_prealloc) { u64 orig_start = found_key.offset - nocow_args.extent_offset; struct extent_map *em; @@ -2300,29 +2301,21 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, goto error; } free_extent_map(em); - ret = btrfs_add_ordered_extent(inode, - cur_offset, nocow_args.num_bytes, - nocow_args.num_bytes, - nocow_args.disk_bytenr, - nocow_args.num_bytes, 0, - 1 << BTRFS_ORDERED_PREALLOC, - BTRFS_COMPRESS_NONE); - if (ret) { + } + + ret = btrfs_add_ordered_extent(inode, cur_offset, + nocow_args.num_bytes, nocow_args.num_bytes, + nocow_args.disk_bytenr, nocow_args.num_bytes, 0, + is_prealloc ? + (1 << BTRFS_ORDERED_PREALLOC) : + (1 << BTRFS_ORDERED_NOCOW), + BTRFS_COMPRESS_NONE); + if (ret) { + if (is_prealloc) { btrfs_drop_extent_map_range(inode, cur_offset, nocow_end, false); - goto error; } - } else { - ret = btrfs_add_ordered_extent(inode, cur_offset, - nocow_args.num_bytes, - nocow_args.num_bytes, - nocow_args.disk_bytenr, - nocow_args.num_bytes, - 0, - 1 << BTRFS_ORDERED_NOCOW, - BTRFS_COMPRESS_NONE); - if (ret) - goto error; + goto error; } if (nocow) { From patchwork Mon May 8 16:08:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234736 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 3035BC7EE22 for ; Mon, 8 May 2023 16:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233451AbjEHQI7 (ORCPT ); Mon, 8 May 2023 12:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232753AbjEHQIu (ORCPT ); Mon, 8 May 2023 12:08:50 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10B914EF1 for ; Mon, 8 May 2023 09:08:49 -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=Q8sYcBbGjFRzEdG0MXeSCepX1viJjfoXeQdUDaw62+Y=; b=xsI9UM9O7sOsWqX7MI9pvJT8aN 99atDk88gApT+MPvFN008UTqBNEf5GAmyuTXZ6aExtGmkHaj8tuixk5szRfQEHu/08DMmouCJBtmd qjx9seZm6xQfKa9j1hkv625D5E2hHdD8OBphRwdbQF6SpGciZPwnxIP3nHqzN4UWHT28I+zInMJdy oeVWpUbVkhLCB1F4kfrgm1mROhRJ+WnG4vT16fN9L+1nN1Nvzh8jGGUZWf//kEOAqK/bC/iRkfP1I k56QYmqxO52z65UCfXLk3yrHL598/WUpcA0GZaXsk2WkgRgB27eyeTjbFuUgnATnG0PTkw4Z5IuKo KTsQnzrA==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pr-000w0B-07; Mon, 08 May 2023 16:08:47 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 05/21] btrfs: pass an ordered_extent to btrfs_reloc_clone_csums Date: Mon, 8 May 2023 09:08:27 -0700 Message-Id: <20230508160843.133013-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Both callers of btrfs_reloc_clone_csums allocate the ordered_extent that btrfs_reloc_clone_csums operates on. Switch them to use btrfs_alloc_ordered_extent instead of btrfs_add_ordered_extent and pass the ordered_extent to btrfs_reloc_clone_csums instead of doing an extra lookup. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 29 ++++++++++++++++++----------- fs/btrfs/relocation.c | 35 ++++++++++++++--------------------- fs/btrfs/relocation.h | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index f0372a01c12423..0bb47782267a2a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1478,6 +1478,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, min_alloc_size = fs_info->sectorsize; while (num_bytes > 0) { + struct btrfs_ordered_extent *ordered; + cur_alloc_size = num_bytes; ret = btrfs_reserve_extent(root, cur_alloc_size, cur_alloc_size, min_alloc_size, 0, alloc_hint, @@ -1502,16 +1504,18 @@ static noinline int cow_file_range(struct btrfs_inode *inode, } free_extent_map(em); - ret = btrfs_add_ordered_extent(inode, start, ram_size, ram_size, - ins.objectid, cur_alloc_size, 0, - 1 << BTRFS_ORDERED_REGULAR, - BTRFS_COMPRESS_NONE); - if (ret) + ordered = btrfs_alloc_ordered_extent(inode, start, ram_size, + ram_size, ins.objectid, cur_alloc_size, + 0, 1 << BTRFS_ORDERED_REGULAR, + BTRFS_COMPRESS_NONE); + if (IS_ERR(ordered)) { + ret = PTR_ERR(ordered); goto out_drop_extent_cache; + } if (btrfs_is_data_reloc_root(root)) { - ret = btrfs_reloc_clone_csums(inode, start, - cur_alloc_size); + ret = btrfs_reloc_clone_csums(ordered); + /* * Only drop cache here, and process as normal. * @@ -1528,6 +1532,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, start + ram_size - 1, false); } + btrfs_put_ordered_extent(ordered); btrfs_dec_block_group_reservations(fs_info, ins.objectid); @@ -2138,6 +2143,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, nocow_args.writeback_path = true; while (1) { + struct btrfs_ordered_extent *ordered; struct btrfs_key found_key; struct btrfs_file_extent_item *fi; struct extent_buffer *leaf; @@ -2303,18 +2309,19 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, free_extent_map(em); } - ret = btrfs_add_ordered_extent(inode, cur_offset, + ordered = btrfs_alloc_ordered_extent(inode, cur_offset, nocow_args.num_bytes, nocow_args.num_bytes, nocow_args.disk_bytenr, nocow_args.num_bytes, 0, is_prealloc ? (1 << BTRFS_ORDERED_PREALLOC) : (1 << BTRFS_ORDERED_NOCOW), BTRFS_COMPRESS_NONE); - if (ret) { + if (IS_ERR(ordered)) { if (is_prealloc) { btrfs_drop_extent_map_range(inode, cur_offset, nocow_end, false); } + ret = PTR_ERR(ordered); goto error; } @@ -2329,8 +2336,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, * extent_clear_unlock_delalloc() in error handler * from freeing metadata of created ordered extent. */ - ret = btrfs_reloc_clone_csums(inode, cur_offset, - nocow_args.num_bytes); + ret = btrfs_reloc_clone_csums(ordered); + btrfs_put_ordered_extent(ordered); extent_clear_unlock_delalloc(inode, cur_offset, nocow_end, locked_page, EXTENT_LOCKED | diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 1c74cbe2fc5787..d3db300978f8b8 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4342,29 +4342,25 @@ int btrfs_recover_relocation(struct btrfs_fs_info *fs_info) * cloning checksum properly handles the nodatasum extents. * it also saves CPU time to re-calculate the checksum. */ -int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len) +int btrfs_reloc_clone_csums(struct btrfs_ordered_extent *ordered) { + struct btrfs_inode *inode = BTRFS_I(ordered->inode); struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct btrfs_root *csum_root; - struct btrfs_ordered_sum *sums; - struct btrfs_ordered_extent *ordered; - int ret; - u64 disk_bytenr; - u64 new_bytenr; + u64 disk_bytenr = ordered->file_offset + inode->index_cnt; + struct btrfs_root *csum_root = btrfs_csum_root(fs_info, disk_bytenr); LIST_HEAD(list); + int ret; - ordered = btrfs_lookup_ordered_extent(inode, file_pos); - BUG_ON(ordered->file_offset != file_pos || ordered->num_bytes != len); - - disk_bytenr = file_pos + inode->index_cnt; - csum_root = btrfs_csum_root(fs_info, disk_bytenr); ret = btrfs_lookup_csums_list(csum_root, disk_bytenr, - disk_bytenr + len - 1, &list, 0, false); + disk_bytenr + ordered->num_bytes - 1, + &list, 0, false); if (ret) - goto out; + return ret; while (!list_empty(&list)) { - sums = list_entry(list.next, struct btrfs_ordered_sum, list); + struct btrfs_ordered_sum *sums = + list_entry(list.next, struct btrfs_ordered_sum, list); + list_del_init(&sums->list); /* @@ -4379,14 +4375,11 @@ int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len) * disk_len vs real len like with real inodes since it's all * disk length. */ - new_bytenr = ordered->disk_bytenr + sums->bytenr - disk_bytenr; - sums->bytenr = new_bytenr; - + sums->bytenr = ordered->disk_bytenr + sums->bytenr - disk_bytenr; btrfs_add_ordered_sum(ordered, sums); } -out: - btrfs_put_ordered_extent(ordered); - return ret; + + return 0; } int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, diff --git a/fs/btrfs/relocation.h b/fs/btrfs/relocation.h index 57cbac5c8ddd95..77d69f6ae967c2 100644 --- a/fs/btrfs/relocation.h +++ b/fs/btrfs/relocation.h @@ -8,7 +8,7 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans, struct btrfs_root *r int btrfs_update_reloc_root(struct btrfs_trans_handle *trans, struct btrfs_root *root); int btrfs_recover_relocation(struct btrfs_fs_info *fs_info); -int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len); +int btrfs_reloc_clone_csums(struct btrfs_ordered_extent *ordered); int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, struct extent_buffer *cow); From patchwork Mon May 8 16:08:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234735 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 01DE6C77B7F for ; Mon, 8 May 2023 16:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233552AbjEHQI6 (ORCPT ); Mon, 8 May 2023 12:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232674AbjEHQIu (ORCPT ); Mon, 8 May 2023 12:08:50 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD3F5658E for ; Mon, 8 May 2023 09:08:48 -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=3LltamFF6CYYgS49airF0OBv578DCg5OoWjSlYcrg+M=; b=tUaF/26fbL9wtTwVPA9nhlDBdy 4LF4WG3TjWjxfGiBau5Xcafc0eDSttFeEGoC2GvLMG7JYhjpvj/ZQC3JFlxkJeIdPXHwb3lxLoxyW B7BeVSdcCGbJq41y1RcRBIZ8NDSQ4otEzO/mIxrjC/7VYkgaahcl8CuwP+cN46DMsUGinPwd1XiL9 nSqMFcinZbP8InGEtG8Aik1ZG1DsKVeoVg7bCJ/dh7GmakgxrAdhVcjeXv0DAoGnYfqf7UwfdkGnB gvA3agzspabBB8IH4ihbANMe0YoCA8t9hunkEXoU5ksVTBxNeQc2Hws/CmmfYThN1oeVfcIIZhp/a +lLLnYfw==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pr-000w0W-2D; Mon, 08 May 2023 16:08:47 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 06/21] btrfs: pass an ordered_extent to btrfs_submit_compressed_write Date: Mon, 8 May 2023 09:08:28 -0700 Message-Id: <20230508160843.133013-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 btrfs_submit_compressed_write alwas operates on a single ordered_extent. Make that explicit by using btrfs_alloc_ordered_extent in the callers and passing the ordered_exten to btrfs_submit_compressed_write. This will help with storing and ordered_extent pointer in the btrfs_bio in subsequent patches. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/compression.c | 29 +++++++++++++++-------------- fs/btrfs/compression.h | 5 ++--- fs/btrfs/inode.c | 21 ++++++++++----------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 4f85113cbf9f0c..a8791781a5d7d2 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -281,33 +281,34 @@ static void btrfs_add_compressed_bio_pages(struct compressed_bio *cb) * This also checksums the file bytes and gets things ready for * the end io hooks. */ -void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, - unsigned int len, u64 disk_start, - unsigned int compressed_len, - struct page **compressed_pages, - unsigned int nr_pages, - blk_opf_t write_flags, - bool writeback) +void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered, + struct page **compressed_pages, + unsigned int nr_pages, + blk_opf_t write_flags, + bool writeback) { + struct btrfs_inode *inode = BTRFS_I(ordered->inode); struct btrfs_fs_info *fs_info = inode->root->fs_info; struct compressed_bio *cb; - ASSERT(IS_ALIGNED(start, fs_info->sectorsize) && - IS_ALIGNED(len, fs_info->sectorsize)); + ASSERT(IS_ALIGNED(ordered->file_offset, fs_info->sectorsize)); + ASSERT(IS_ALIGNED(ordered->num_bytes, fs_info->sectorsize)); - cb = alloc_compressed_bio(inode, start, REQ_OP_WRITE | write_flags, + cb = alloc_compressed_bio(inode, ordered->file_offset, + REQ_OP_WRITE | write_flags, end_compressed_bio_write); - cb->start = start; - cb->len = len; + cb->start = ordered->file_offset; + cb->len = ordered->num_bytes; cb->compressed_pages = compressed_pages; - cb->compressed_len = compressed_len; + cb->compressed_len = ordered->disk_num_bytes; cb->writeback = writeback; INIT_WORK(&cb->write_end_work, btrfs_finish_compressed_write_work); cb->nr_pages = nr_pages; - cb->bbio.bio.bi_iter.bi_sector = disk_start >> SECTOR_SHIFT; + cb->bbio.bio.bi_iter.bi_sector = ordered->disk_bytenr >> SECTOR_SHIFT; btrfs_add_compressed_bio_pages(cb); btrfs_submit_bio(&cb->bbio, 0); + btrfs_put_ordered_extent(ordered); } /* diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 19ab2abeddc088..733987339c03e8 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -10,6 +10,7 @@ #include "bio.h" struct btrfs_inode; +struct btrfs_ordered_extent; /* * We want to make sure that amount of RAM required to uncompress an extent is @@ -86,9 +87,7 @@ int btrfs_decompress(int type, const u8 *data_in, struct page *dest_page, int btrfs_decompress_buf2page(const char *buf, u32 buf_len, struct compressed_bio *cb, u32 decompressed); -void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, - unsigned int len, u64 disk_start, - unsigned int compressed_len, +void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered, struct page **compressed_pages, unsigned int nr_pages, blk_opf_t write_flags, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 0bb47782267a2a..8b6d824a46bc1f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1167,6 +1167,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, struct extent_io_tree *io_tree = &inode->io_tree; struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; + struct btrfs_ordered_extent *ordered; struct btrfs_key ins; struct page *locked_page = NULL; struct extent_map *em; @@ -1228,7 +1229,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, } free_extent_map(em); - ret = btrfs_add_ordered_extent(inode, start, /* file_offset */ + ordered = btrfs_alloc_ordered_extent(inode, start, /* file_offset */ async_extent->ram_size, /* num_bytes */ async_extent->ram_size, /* ram_bytes */ ins.objectid, /* disk_bytenr */ @@ -1236,8 +1237,9 @@ static int submit_one_async_extent(struct btrfs_inode *inode, 0, /* offset */ 1 << BTRFS_ORDERED_COMPRESSED, async_extent->compress_type); - if (ret) { + if (IS_ERR(ordered)) { btrfs_drop_extent_map_range(inode, start, end, false); + ret = PTR_ERR(ordered); goto out_free_reserve; } btrfs_dec_block_group_reservations(fs_info, ins.objectid); @@ -1246,11 +1248,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, extent_clear_unlock_delalloc(inode, start, end, NULL, EXTENT_LOCKED | EXTENT_DELALLOC, PAGE_UNLOCK | PAGE_START_WRITEBACK); - - btrfs_submit_compressed_write(inode, start, /* file_offset */ - async_extent->ram_size, /* num_bytes */ - ins.objectid, /* disk_bytenr */ - ins.offset, /* compressed_len */ + btrfs_submit_compressed_write(ordered, async_extent->pages, /* compressed_pages */ async_extent->nr_pages, async_chunk->write_flags, true); @@ -10351,6 +10349,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, struct extent_io_tree *io_tree = &inode->io_tree; struct extent_changeset *data_reserved = NULL; struct extent_state *cached_state = NULL; + struct btrfs_ordered_extent *ordered; int compression; size_t orig_count; u64 start, end; @@ -10527,14 +10526,15 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, } free_extent_map(em); - ret = btrfs_add_ordered_extent(inode, start, num_bytes, ram_bytes, + ordered = btrfs_alloc_ordered_extent(inode, start, num_bytes, ram_bytes, ins.objectid, ins.offset, encoded->unencoded_offset, (1 << BTRFS_ORDERED_ENCODED) | (1 << BTRFS_ORDERED_COMPRESSED), compression); - if (ret) { + if (IS_ERR(ordered)) { btrfs_drop_extent_map_range(inode, start, end, false); + ret = PTR_ERR(ordered); goto out_free_reserved; } btrfs_dec_block_group_reservations(fs_info, ins.objectid); @@ -10546,8 +10546,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, btrfs_delalloc_release_extents(inode, num_bytes); - btrfs_submit_compressed_write(inode, start, num_bytes, ins.objectid, - ins.offset, pages, nr_pages, 0, false); + btrfs_submit_compressed_write(ordered, pages, nr_pages, 0, false); ret = orig_count; goto out; From patchwork Mon May 8 16:08:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234737 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 9FEF5C7EE24 for ; Mon, 8 May 2023 16:09:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233480AbjEHQJA (ORCPT ); Mon, 8 May 2023 12:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232932AbjEHQIv (ORCPT ); Mon, 8 May 2023 12:08:51 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDBC94EE5 for ; Mon, 8 May 2023 09:08:50 -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=GSVLpPJ5lYgx7jX4qbDZPbu70qHcPEAVfOQxcSXD0Sw=; b=fEQkJh7xvaqfsbl7ltQnATNn1F OdS8My9jduHMOQ3Z2uHonc1IMeiC+r/1n+RosA1eUCkxN+US2hw+ZoWSyHkPAgtCTRJTlxG8Y9o01 9f083xtPa7IwPUdwicTAGFEQV6mowUFH9jMGh1h9E9veNLJRv2CkO2I+ds1otepBJX19rkZ4AS1hW uiyjb1avIV4aeXNdm22tSsdxZg9jRwloxOru9Vekn0ovK5BmvL4Ly6opxI4m0gpX6gigG4TgN3YM7 SWBwprsRHOvkriIVOYwO9NJQp3zNv5XSPlM6NCL8hlGNSEyb3LTpgxESpVzXlbERQV77P+J/dnQrq EbEXgPSA==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Ps-000w0j-17; Mon, 08 May 2023 16:08:48 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 07/21] btrfs: reorder btrfs_extract_ordered_extent Date: Mon, 8 May 2023 09:08:29 -0700 Message-Id: <20230508160843.133013-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 There is no good reason for doing one before the other in terms of failure implications, but doing the extent_map split first will simplify some upcoming refactoring. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- fs/btrfs/inode.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 8b6d824a46bc1f..711f0e2081148c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2799,9 +2799,7 @@ int btrfs_extract_ordered_extent(struct btrfs_bio *bbio, { u64 start = (u64)bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT; u64 len = bbio->bio.bi_iter.bi_size; - struct btrfs_inode *inode = bbio->inode; - u64 ordered_len = ordered->num_bytes; - int ret = 0; + int ret; /* Must always be called for the beginning of an ordered extent. */ if (WARN_ON_ONCE(start != ordered->disk_bytenr)) @@ -2811,18 +2809,18 @@ int btrfs_extract_ordered_extent(struct btrfs_bio *bbio, if (ordered->disk_num_bytes == len) return 0; - ret = btrfs_split_ordered_extent(ordered, len); - if (ret) - return ret; - /* * Don't split the extent_map for NOCOW extents, as we're writing into * a pre-existing one. */ - if (test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) - return 0; + if (!test_bit(BTRFS_ORDERED_NOCOW, &ordered->flags)) { + ret = split_extent_map(bbio->inode, bbio->file_offset, + ordered->num_bytes, len); + if (ret) + return ret; + } - return split_extent_map(inode, bbio->file_offset, ordered_len, len); + return btrfs_split_ordered_extent(ordered, len); } /* From patchwork Mon May 8 16:08:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234738 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 21523C7EE2A for ; Mon, 8 May 2023 16:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233529AbjEHQJB (ORCPT ); Mon, 8 May 2023 12:09:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232967AbjEHQIw (ORCPT ); Mon, 8 May 2023 12:08:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 661BC6A54 for ; Mon, 8 May 2023 09:08:51 -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=IPvLOJ5PkYIQ3jgxBfoG0nppgPBVT2Z24cX+tSCPQ+E=; b=M2kqYN1SDirnlt/AZJQ+s7w0Bl mr1btRCUGShaljPW9MROK/LqFADDROmzGaL8PyWTWK0Xi09+ZkjWpyPpiQqztob1EUTxdKzrJxSpc gVEhTnfPBPz32cu6aojWp981XY9u27Fw1r1hGlN3t/qBX3F7vVObBbpS4fRCIXrpkUDsbeCPj8fvZ uURKJTz6jVExRXBjkdqllg1vnMqlywp7kSsx/BEcv+ZopgBVXnQffBV19gMVJ1XYWPXze19vbAaS6 9RI8TVUbL72vIivx4qDcFBEKfgFAvAVbrqhdPyZ9xE/WuLvo5spfuHqLvKJ+c9l3XGZ4+BEtdazNL OKH4t8Dg==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Ps-000w0z-3D; Mon, 08 May 2023 16:08:49 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 08/21] btrfs: return the new ordered_extent from btrfs_split_ordered_extent Date: Mon, 8 May 2023 09:08:30 -0700 Message-Id: <20230508160843.133013-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Return the ordered_extent split from the passed in one. This will be needed to be able to store an ordered_extent in the btrfs_bio. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Reviewed-by: Naohiro Aota --- fs/btrfs/inode.c | 7 ++++++- fs/btrfs/ordered-data.c | 19 ++++++++++--------- fs/btrfs/ordered-data.h | 3 ++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 711f0e2081148c..3dceedf612d4ba 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2799,6 +2799,7 @@ int btrfs_extract_ordered_extent(struct btrfs_bio *bbio, { u64 start = (u64)bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT; u64 len = bbio->bio.bi_iter.bi_size; + struct btrfs_ordered_extent *new; int ret; /* Must always be called for the beginning of an ordered extent. */ @@ -2820,7 +2821,11 @@ int btrfs_extract_ordered_extent(struct btrfs_bio *bbio, return ret; } - return btrfs_split_ordered_extent(ordered, len); + new = btrfs_split_ordered_extent(ordered, len); + if (IS_ERR(new)) + return PTR_ERR(new); + btrfs_put_ordered_extent(new); + return 0; } /* diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index a9778a91511e19..f6855e37e7f94d 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -1117,7 +1117,8 @@ bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end, } /* Split out a new ordered extent for this first @len bytes of @ordered. */ -int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len) +struct btrfs_ordered_extent * +btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len) { struct inode *inode = ordered->inode; struct btrfs_ordered_inode_tree *tree = &BTRFS_I(inode)->ordered_tree; @@ -1136,16 +1137,16 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len) * reduce the original extent to a zero length either. */ if (WARN_ON_ONCE(len >= ordered->num_bytes)) - return -EINVAL; + return ERR_PTR(-EINVAL); /* We cannot split once ordered extent is past end_bio. */ if (WARN_ON_ONCE(ordered->bytes_left != ordered->disk_num_bytes)) - return -EINVAL; + return ERR_PTR(-EINVAL); /* We cannot split a compressed ordered extent. */ if (WARN_ON_ONCE(ordered->disk_num_bytes != ordered->num_bytes)) - return -EINVAL; + return ERR_PTR(-EINVAL); /* Checksum list should be empty. */ if (WARN_ON_ONCE(!list_empty(&ordered->list))) - return -EINVAL; + return ERR_PTR(-EINVAL); spin_lock_irq(&tree->lock); /* Remove from tree once */ @@ -1172,13 +1173,13 @@ int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len) /* * The splitting extent is already counted and will be added again in - * btrfs_add_ordered_extent(). Subtract len to avoid double counting. + * btrfs_alloc_ordered_extent(). Subtract len to avoid double counting. */ percpu_counter_add_batch(&fs_info->ordered_bytes, -len, fs_info->delalloc_batch); - return btrfs_add_ordered_extent(BTRFS_I(inode), file_offset, len, len, - disk_bytenr, len, 0, flags, - ordered->compress_type); + return btrfs_alloc_ordered_extent(BTRFS_I(inode), file_offset, len, len, + disk_bytenr, len, 0, flags, + ordered->compress_type); } int __init ordered_data_init(void) diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index f0f1138d23c331..150f75a155ca0c 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -212,7 +212,8 @@ void btrfs_lock_and_flush_ordered_range(struct btrfs_inode *inode, u64 start, struct extent_state **cached_state); bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end, struct extent_state **cached_state); -int btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len); +struct btrfs_ordered_extent * +btrfs_split_ordered_extent(struct btrfs_ordered_extent *ordered, u64 len); int __init ordered_data_init(void); void __cold ordered_data_exit(void); From patchwork Mon May 8 16:08:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234739 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 C432DC7EE2E for ; Mon, 8 May 2023 16:09:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233699AbjEHQJD (ORCPT ); Mon, 8 May 2023 12:09:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232935AbjEHQIw (ORCPT ); Mon, 8 May 2023 12:08:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02A0465A1 for ; Mon, 8 May 2023 09:08:50 -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=+bNBPEBDZq/ti6ccN9tX78n/lLCsqMuVy8+1rijmzWE=; b=3/qr9d7uP3CW8l73kL29dvI19P tTCODdRid7QL9k1ij8mEC9I5yETGWB597ZzEcCloiHf4nnMe28AzC/teJiVGsGFnwlBBdeaAWad1i w6A+LjUo0+23zGnkAYIRFn36FheL1DI9wLWpuKKNHsOBYQie56bW+BeTLdZ/caWMGW7W+/CzqfG8C 4N7bDwQIXYrAjcgRtORzPBFmQk3V6y4J3FUD3+12XkWu/ihJSASCb65AeXiVMwUT0oAKoLUBrPShB 7mAfYWpxBZmdaS/ehDmHYfSkf5XENxslzwD7maB8WJOS+q9dQOZ3uy30y9Fo0MlBAleO/fRhwXmSS vAF1VI4g==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pt-000w1I-28; Mon, 08 May 2023 16:08:49 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 09/21] btrfs: remove btrfs_add_ordered_extent Date: Mon, 8 May 2023 09:08:31 -0700 Message-Id: <20230508160843.133013-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 All callers are gone now. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/ordered-data.c | 25 +------------------------ fs/btrfs/ordered-data.h | 4 ---- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index f6855e37e7f94d..0ea4efc1264512 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -264,29 +264,6 @@ struct btrfs_ordered_extent *btrfs_alloc_ordered_extent( return entry; } -/* - * Add a new btrfs_ordered_extent for the range, but drop the reference instead - * of returning it to the caller. - */ -int btrfs_add_ordered_extent(struct btrfs_inode *inode, u64 file_offset, - u64 num_bytes, u64 ram_bytes, u64 disk_bytenr, - u64 disk_num_bytes, u64 offset, unsigned long flags, - int compress_type) -{ - struct btrfs_ordered_extent *ordered; - - ordered = btrfs_alloc_ordered_extent(inode, file_offset, num_bytes, - ram_bytes, disk_bytenr, - disk_num_bytes, offset, flags, - compress_type); - - if (IS_ERR(ordered)) - return PTR_ERR(ordered); - btrfs_put_ordered_extent(ordered); - - return 0; -} - /* * Add a struct btrfs_ordered_sum into the list of checksums to be inserted * when an ordered extent is finished. If the list covers more than one @@ -564,7 +541,7 @@ void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode, freespace_inode = btrfs_is_free_space_inode(btrfs_inode); btrfs_lockdep_acquire(fs_info, btrfs_trans_pending_ordered); - /* This is paired with btrfs_add_ordered_extent. */ + /* This is paired with btrfs_alloc_ordered_extent. */ spin_lock(&btrfs_inode->lock); btrfs_mod_outstanding_extents(btrfs_inode, -1); spin_unlock(&btrfs_inode->lock); diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 150f75a155ca0c..87a61a2bb722fd 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -183,10 +183,6 @@ struct btrfs_ordered_extent *btrfs_alloc_ordered_extent( u64 num_bytes, u64 ram_bytes, u64 disk_bytenr, u64 disk_num_bytes, u64 offset, unsigned long flags, int compress_type); -int btrfs_add_ordered_extent(struct btrfs_inode *inode, u64 file_offset, - u64 num_bytes, u64 ram_bytes, u64 disk_bytenr, - u64 disk_num_bytes, u64 offset, unsigned long flags, - int compress_type); void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, struct btrfs_ordered_sum *sum); struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct btrfs_inode *inode, From patchwork Mon May 8 16:08:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234741 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 6C033C7EE22 for ; Mon, 8 May 2023 16:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233759AbjEHQJG (ORCPT ); Mon, 8 May 2023 12:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233079AbjEHQIx (ORCPT ); Mon, 8 May 2023 12:08:53 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E786E9D for ; Mon, 8 May 2023 09:08:52 -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=E4XZJxbs8NNQ7u8yrXhZecRfgGQzix0EiSUGMJbQZEw=; b=UdmycDHLKaEmz+fxMf741cWLr9 NhX3XpOBEnKG207JeWR9Ld8GbwBXU4L/DU48FASTDJdzYLi0sqGzHFQCYNZMoKd0/NvsntDs64Hdm UqjqZXCO33akF9/TjZulA5rCF4BNb/naHUDp1XEkePpz2aUTyHz58a8vtLsOJMQKvla1KyvkMjjOg SaF85OE7Vm4FtjEJAhoWFZOxzlP+vzyouGBO5E26Ol1MqXuPnQVzndrkU5xhR34n37R7926bybDAF m2GWqYnwBxb0ozSdAC2MKXvoY8g7hcbU877YTd5CHlhFnZ2yFHeywDjXFyhqFQVFtYuPcrj+30aJs Dlg0AjWw==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pu-000w1m-0z; Mon, 08 May 2023 16:08:50 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 10/21] btrfs: add a is_data_bio helper Date: Mon, 8 May 2023 09:08:32 -0700 Message-Id: <20230508160843.133013-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Add a helper to check for that a btrfs_bio has a valid inde inode, and that it is a data inode to key off all the special handling for data path checksumming. Note that this uses is_data_inode instead of REQ_META as REQ_META is only set directly before submission in submit_one_bio and we'll also want to use this helper for error handling where REQ_META isn't set yet. Signed-off-by: Christoph Hellwig --- fs/btrfs/bio.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index 5f418eeaac070b..c38d3597169b5e 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -27,6 +27,12 @@ struct btrfs_failed_bio { atomic_t repair_count; }; +/* Is this a data path I/O that needs storage layer checksum and repair? */ +static inline bool is_data_bio(struct btrfs_bio *bbio) +{ + return bbio->inode && is_data_inode(&bbio->inode->vfs_inode); +} + /* * Initialize a btrfs_bio structure. This skips the embedded bio itself as it * is already initialized by the block layer. @@ -326,7 +332,7 @@ static void btrfs_end_bio_work(struct work_struct *work) struct btrfs_bio *bbio = container_of(work, struct btrfs_bio, end_io_work); /* Metadata reads are checked and repaired by the submitter. */ - if (bbio->inode && !(bbio->bio.bi_opf & REQ_META)) + if (is_data_bio(bbio)) btrfs_check_read_bio(bbio, bbio->bio.bi_private); else bbio->end_io(bbio); @@ -360,8 +366,7 @@ static void btrfs_raid56_end_io(struct bio *bio) btrfs_bio_counter_dec(bioc->fs_info); bbio->mirror_num = bioc->mirror_num; - if (bio_op(bio) == REQ_OP_READ && bbio->inode && - !(bbio->bio.bi_opf & REQ_META)) + if (bio_op(bio) == REQ_OP_READ && is_data_bio(bbio)) btrfs_check_read_bio(bbio, NULL); else btrfs_orig_bbio_end_io(bbio); @@ -651,7 +656,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) * Save the iter for the end_io handler and preload the checksums for * data reads. */ - if (bio_op(bio) == REQ_OP_READ && inode && !(bio->bi_opf & REQ_META)) { + if (bio_op(bio) == REQ_OP_READ && is_data_bio(bbio)) { bbio->saved_iter = bio->bi_iter; ret = btrfs_lookup_bio_sums(bbio); if (ret) From patchwork Mon May 8 16:08:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234740 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 D2A20C7EE24 for ; Mon, 8 May 2023 16:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233752AbjEHQJE (ORCPT ); Mon, 8 May 2023 12:09:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233057AbjEHQIx (ORCPT ); Mon, 8 May 2023 12:08:53 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26EF66EA2 for ; Mon, 8 May 2023 09:08:52 -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=YXE2wrNkKvYjH5/mlqKZrK9JlA/p2/0j+caHMvI421U=; b=ofxBMo2yeL2RqE0zoSZ0BFSxCE C2lx9wCmubMRUWUQGYGpWTyT0cRQSTrsnr3X66S8wNRYGeECnyadeHWfLmk6nLU4dbj05ZM9FEIrL NwtT4/YueYViICBrG0f8569kzCLz/X/nTg4eiCevimTk/LvXAYTjXulxoohRb553+t9txNZXhhHSt +fpYN0S9emY/XeSe37hADAMA+Q0NmtONG5LE3wz/Qb8TIQnwcR6CdXjDuqt8Bvyx70GtfRcJnMMtS 6DlANjFZ0QAorXSXPslk7uYnPNsV5zaMUJ7r1xkxyCuwt20B8okipN7urGtnZZnxuaKKtCFeaLn0G HBMtcBlQ==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pu-000w20-34; Mon, 08 May 2023 16:08:51 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 11/21] btrfs: open code btrfs_bio_end_io in btrfs_dio_submit_io Date: Mon, 8 May 2023 09:08:33 -0700 Message-Id: <20230508160843.133013-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 btrfs_dio_submit_io is the only place that uses btrfs_bio_end_io to end a bio that hasn't been submitted using btrfs_submit_bio yet, and this invariant will become a problem with upcoming changes to the btrfs bio layer. Just open code the assignment of bi_status and the call to btrfs_dio_end_io. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3dceedf612d4ba..a425658cfbae0c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7925,7 +7925,8 @@ static void btrfs_dio_submit_io(const struct iomap_iter *iter, struct bio *bio, ret = btrfs_extract_ordered_extent(bbio, dio_data->ordered); if (ret) { - btrfs_bio_end_io(bbio, errno_to_blk_status(ret)); + bbio->bio.bi_status = errno_to_blk_status(ret); + btrfs_dio_end_io(bbio); return; } } From patchwork Mon May 8 16:08:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234743 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 DB114C7EE2A for ; Mon, 8 May 2023 16:09:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233784AbjEHQJK (ORCPT ); Mon, 8 May 2023 12:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233237AbjEHQIz (ORCPT ); Mon, 8 May 2023 12:08:55 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FC7C65B5 for ; Mon, 8 May 2023 09:08:54 -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=qCg7c2Xb2HRfS3Nyx33QoFzN05w1CQttxiBpeNvx7DY=; b=AAOqk0DfsydAcgOozJ1bNDmIE9 GM7cIkMjp3Ku49+ScaBfFweVfxjyU9Se15DDSZX4RWkH7WwOwg+mlAmI+EGUSpgyNQlgAn3S5Zdvg IRji266iuttLNkrmZbrTiusPMOKDLDereUAAr936S/DNgwj2rPmjOayDXag0EyWDIeaTlk+gTDah9 OwmYSjbJaWZ+2D+mls7HdFzwbJATPTMqHdypg4is+c1GQwhCAn8TBfi28PTdkoh4KTeOJGBndbF68 1Pt0q2xWkeyRzjpkDCoM+rehVGOfRw+zY31L1Ibr3dqL+IyT+Y3MXj4Lct582DwcD2uyznLUt1nO2 delDTeUQ==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pv-000w2L-20; Mon, 08 May 2023 16:08:51 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 12/21] btrfs: add an ordered_extent pointer to struct btrfs_bio Date: Mon, 8 May 2023 09:08:34 -0700 Message-Id: <20230508160843.133013-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Add a pointer to the ordered_extent to the existing union in struct btrfs_bio, so all code dealing with data write bios can just use a pointer dereference to retrieve the ordered_extent instead of doing multiple rbtree lookups per I/O. The reference to this ordered_extent is dropped at end I/O time, which implies that an extra one must be acquired when the bio is split. This also requires moving the btrfs_extract_ordered_extent call into btrfs_split_bio so that the invariant of always having a valid ordered_extent reference for the btrfs_bio is kept. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/bio.c | 65 ++++++++++++++++++++++++++++-------------- fs/btrfs/bio.h | 16 +++++------ fs/btrfs/compression.c | 2 +- fs/btrfs/extent_io.c | 2 +- fs/btrfs/inode.c | 7 +++-- 5 files changed, 58 insertions(+), 34 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index c38d3597169b5e..a1ad9aba2f7fc2 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -67,26 +67,13 @@ struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, return bbio; } -static blk_status_t btrfs_bio_extract_ordered_extent(struct btrfs_bio *bbio) -{ - struct btrfs_ordered_extent *ordered; - int ret; - - ordered = btrfs_lookup_ordered_extent(bbio->inode, bbio->file_offset); - if (WARN_ON_ONCE(!ordered)) - return BLK_STS_IOERR; - ret = btrfs_extract_ordered_extent(bbio, ordered); - btrfs_put_ordered_extent(ordered); - - return errno_to_blk_status(ret); -} - static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info, struct btrfs_bio *orig_bbio, u64 map_length, bool use_append) { struct btrfs_bio *bbio; struct bio *bio; + int ret; if (use_append) { unsigned int nr_segs; @@ -101,12 +88,47 @@ static struct btrfs_bio *btrfs_split_bio(struct btrfs_fs_info *fs_info, btrfs_bio_init(bbio, fs_info, NULL, orig_bbio); bbio->inode = orig_bbio->inode; bbio->file_offset = orig_bbio->file_offset; + if (use_append) { + ret = btrfs_extract_ordered_extent(bbio, orig_bbio->ordered); + if (ret) { + bio_put(bio); + return ERR_PTR(ret); + } + } else if (is_data_bio(bbio) && btrfs_op(bio) == BTRFS_MAP_WRITE) { + refcount_inc(&orig_bbio->ordered->refs); + bbio->ordered = orig_bbio->ordered; + } orig_bbio->file_offset += map_length; - atomic_inc(&orig_bbio->pending_ios); return bbio; } +/* Free a bio that was never submitted to the underlying device */ +static void btrfs_cleanup_bio(struct btrfs_bio *bbio) +{ + if (is_data_bio(bbio) && btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE) + btrfs_put_ordered_extent(bbio->ordered); + bio_put(&bbio->bio); +} + +static void __btrfs_bio_end_io(struct btrfs_bio *bbio) +{ + if (is_data_bio(bbio) && btrfs_op(&bbio->bio) == BTRFS_MAP_WRITE) { + struct btrfs_ordered_extent *ordered = bbio->ordered; + + bbio->end_io(bbio); + btrfs_put_ordered_extent(ordered); + } else { + bbio->end_io(bbio); + } +} + +void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) +{ + bbio->bio.bi_status = status; + __btrfs_bio_end_io(bbio); +} + static void btrfs_orig_write_end_io(struct bio *bio); static void btrfs_bbio_propagate_error(struct btrfs_bio *bbio, @@ -135,12 +157,12 @@ static void btrfs_orig_bbio_end_io(struct btrfs_bio *bbio) if (bbio->bio.bi_status) btrfs_bbio_propagate_error(bbio, orig_bbio); - bio_put(&bbio->bio); + btrfs_cleanup_bio(bbio); bbio = orig_bbio; } if (atomic_dec_and_test(&bbio->pending_ios)) - bbio->end_io(bbio); + __btrfs_bio_end_io(bbio); } static int next_repair_mirror(struct btrfs_failed_bio *fbio, int cur_mirror) @@ -649,6 +671,10 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) if (map_length < length) { bbio = btrfs_split_bio(fs_info, bbio, map_length, use_append); + if (IS_ERR(bbio)) { + ret = errno_to_blk_status(PTR_ERR(bbio)); + goto fail; + } bio = &bbio->bio; } @@ -667,9 +693,6 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) if (use_append) { bio->bi_opf &= ~REQ_OP_WRITE; bio->bi_opf |= REQ_OP_ZONE_APPEND; - ret = btrfs_bio_extract_ordered_extent(bbio); - if (ret) - goto fail_put_bio; } /* @@ -695,7 +718,7 @@ static bool btrfs_submit_chunk(struct btrfs_bio *bbio, int mirror_num) fail_put_bio: if (map_length < length) - bio_put(bio); + btrfs_cleanup_bio(bbio); fail: btrfs_bio_counter_dec(fs_info); btrfs_bio_end_io(orig_bbio, ret); diff --git a/fs/btrfs/bio.h b/fs/btrfs/bio.h index 000e807f785395..8c3bfb7e04cb41 100644 --- a/fs/btrfs/bio.h +++ b/fs/btrfs/bio.h @@ -39,8 +39,8 @@ struct btrfs_bio { union { /* - * Data checksumming and original I/O information for internal - * use in the btrfs_submit_bio machinery. + * For data reads: checksumming and original I/O information. + * (for internal use in the btrfs_submit_bio machinery only) */ struct { u8 *csum; @@ -48,7 +48,10 @@ struct btrfs_bio { struct bvec_iter saved_iter; }; - /* For metadata parentness verification. */ + /* For data writes: ordered extent covering the bio */ + struct btrfs_ordered_extent *ordered; + + /* For metadata: parentness verification. */ struct btrfs_tree_parent_check parent_check; }; @@ -84,12 +87,7 @@ void btrfs_bio_init(struct btrfs_bio *bbio, struct btrfs_fs_info *fs_info, struct btrfs_bio *btrfs_bio_alloc(unsigned int nr_vecs, blk_opf_t opf, struct btrfs_fs_info *fs_info, btrfs_bio_end_io_t end_io, void *private); - -static inline void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status) -{ - bbio->bio.bi_status = status; - bbio->end_io(bbio); -} +void btrfs_bio_end_io(struct btrfs_bio *bbio, blk_status_t status); /* Submit using blkcg_punt_bio_submit. */ #define REQ_BTRFS_CGROUP_PUNT REQ_FS_PRIVATE diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index a8791781a5d7d2..a3f8416125a8c1 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -305,10 +305,10 @@ void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered, INIT_WORK(&cb->write_end_work, btrfs_finish_compressed_write_work); cb->nr_pages = nr_pages; cb->bbio.bio.bi_iter.bi_sector = ordered->disk_bytenr >> SECTOR_SHIFT; + cb->bbio.ordered = ordered; btrfs_add_compressed_bio_pages(cb); btrfs_submit_bio(&cb->bbio, 0); - btrfs_put_ordered_extent(ordered); } /* diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 92e1edfcfb9cb4..7417ce759f6f48 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -917,7 +917,7 @@ static void alloc_new_bio(struct btrfs_inode *inode, bio_ctrl->len_to_oe_boundary = min_t(u32, U32_MAX, ordered->file_offset + ordered->disk_num_bytes - file_offset); - btrfs_put_ordered_extent(ordered); + bbio->ordered = ordered; } /* diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a425658cfbae0c..ff1f5014156390 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2807,8 +2807,11 @@ int btrfs_extract_ordered_extent(struct btrfs_bio *bbio, return -EINVAL; /* No need to split if the ordered extent covers the entire bio. */ - if (ordered->disk_num_bytes == len) + if (ordered->disk_num_bytes == len) { + refcount_inc(&ordered->refs); + bbio->ordered = ordered; return 0; + } /* * Don't split the extent_map for NOCOW extents, as we're writing into @@ -2824,7 +2827,7 @@ int btrfs_extract_ordered_extent(struct btrfs_bio *bbio, new = btrfs_split_ordered_extent(ordered, len); if (IS_ERR(new)) return PTR_ERR(new); - btrfs_put_ordered_extent(new); + bbio->ordered = new; return 0; } From patchwork Mon May 8 16:08:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234742 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 7D9D0C7EE24 for ; Mon, 8 May 2023 16:09:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233762AbjEHQJI (ORCPT ); Mon, 8 May 2023 12:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbjEHQIy (ORCPT ); Mon, 8 May 2023 12:08:54 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C71896A68 for ; Mon, 8 May 2023 09:08:53 -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=oaeZPj/1qmhsBjaeSKdSnbSSioncgOKkmXVvgOzHqVs=; b=UMpYIXpZiO/xVyWQn+VZMWo0R8 e/fb95ivRnqOfxTsVTc065VJv6FdYJd1RTMLn0S5nYdYdMTXBQQs/6yZj30LTANRSuRGcWTUI3OP3 98e2eLnzMzfOSDebCmkw6i6q/98WGwqYZxVMsc/RiFemTGLYL8WvksEd51mtcZacLcuL6upx2Jl59 B6XlXrDPAB30Y17sULnEPKYTkbvGDSkx+dI3FrznNIg1/EDUUZLCKAR/E4BlkDB4RSvrGLbjV8YNN fs9h2wfQc3cp8ZTChhwfsZmHLiqfurebsWlEz3GiG+NFdAApZoMCMKqP1T2GV2Gsu+ILw+uE9N33c F7EtswOA==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pw-000w2n-10; Mon, 08 May 2023 16:08:52 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 13/21] btrfs: use bbio->ordered in btrfs_csum_one_bio Date: Mon, 8 May 2023 09:08:35 -0700 Message-Id: <20230508160843.133013-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Use the ordered_extent pointer in the btrfs_bio instead of looking it up manually. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/file-item.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 1c1cb6373f2c30..1832bf95d33e82 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -721,13 +721,12 @@ int btrfs_lookup_csums_bitmap(struct btrfs_root *root, u64 start, u64 end, */ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) { + struct btrfs_ordered_extent *ordered = bbio->ordered; struct btrfs_inode *inode = bbio->inode; struct btrfs_fs_info *fs_info = inode->root->fs_info; SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); struct bio *bio = &bbio->bio; - u64 offset = bbio->file_offset; struct btrfs_ordered_sum *sums; - struct btrfs_ordered_extent *ordered = NULL; char *data; struct bvec_iter iter; struct bio_vec bvec; @@ -753,22 +752,6 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) shash->tfm = fs_info->csum_shash; bio_for_each_segment(bvec, bio, iter) { - if (!ordered) { - ordered = btrfs_lookup_ordered_extent(inode, offset); - /* - * The bio range is not covered by any ordered extent, - * must be a code logic error. - */ - if (unlikely(!ordered)) { - WARN(1, KERN_WARNING - "no ordered extent for root %llu ino %llu offset %llu\n", - inode->root->root_key.objectid, - btrfs_ino(inode), offset); - kvfree(sums); - return BLK_STS_IOERR; - } - } - blockcount = BTRFS_BYTES_TO_BLKS(fs_info, bvec.bv_len + fs_info->sectorsize - 1); @@ -781,12 +764,10 @@ blk_status_t btrfs_csum_one_bio(struct btrfs_bio *bbio) sums->sums + index); kunmap_local(data); index += fs_info->csum_size; - offset += fs_info->sectorsize; } } btrfs_add_ordered_sum(ordered, sums); - btrfs_put_ordered_extent(ordered); return 0; } From patchwork Mon May 8 16:08:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234745 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 3C35CC7EE22 for ; Mon, 8 May 2023 16:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233775AbjEHQJM (ORCPT ); Mon, 8 May 2023 12:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233391AbjEHQI4 (ORCPT ); Mon, 8 May 2023 12:08:56 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D40B365AB for ; Mon, 8 May 2023 09:08:54 -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=AePrBrt5hj8Dih6JViE7MLHGtyPDkRI/jp1GQbGbY4w=; b=BvN6rvBFwtt8GIjK4NHIldfS// AuCkSi3gC5ajlc5iOUtV7wClEuHW3leBGfr2dk5+5DeZlEanNcI4EwT/8TtLVZ3f7ug+RhQ33wG56 uqoJNBseUB4W1Vh2RY2mD26RJfOKIYrtiF+7s+bi3SgxkmIDvox333Y9IqR/owhTcAOAQnksdu99i eKNqd0WAnixd23uH4uVCRD3o+thCleeVlVNBY6snJZ0d+FKxuiH70EQriff0zxgfpqYGvA6UtLjfM A+qh70kOu0g5CBa6nt2fZXo74tpMLRHBai9sxgZ10lC0BY0ASfqRELU59WU5uFf/rMnFtAKOJkXLY NLSOXl7Q==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pw-000w3B-36; Mon, 08 May 2023 16:08:53 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 14/21] btrfs: use bbio->ordered for zone append completions Date: Mon, 8 May 2023 09:08:36 -0700 Message-Id: <20230508160843.133013-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Use the ordered_extent pointer in the btrfs_bio instead of looking it up manually. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/bio.c | 3 ++- fs/btrfs/zoned.c | 13 ------------- fs/btrfs/zoned.h | 5 ----- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/bio.c b/fs/btrfs/bio.c index a1ad9aba2f7fc2..d697c4c9ef3c73 100644 --- a/fs/btrfs/bio.c +++ b/fs/btrfs/bio.c @@ -376,7 +376,8 @@ static void btrfs_simple_end_io(struct bio *bio) queue_work(btrfs_end_io_wq(fs_info, bio), &bbio->end_io_work); } else { if (bio_op(bio) == REQ_OP_ZONE_APPEND) - btrfs_record_physical_zoned(bbio); + bbio->ordered->physical = + bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT; btrfs_orig_bbio_end_io(bbio); } } diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c index e3fe02aae641f3..5882eca045a9d4 100644 --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -1675,19 +1675,6 @@ bool btrfs_use_zone_append(struct btrfs_bio *bbio) return ret; } -void btrfs_record_physical_zoned(struct btrfs_bio *bbio) -{ - const u64 physical = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT; - struct btrfs_ordered_extent *ordered; - - ordered = btrfs_lookup_ordered_extent(bbio->inode, bbio->file_offset); - if (WARN_ON(!ordered)) - return; - - ordered->physical = physical; - btrfs_put_ordered_extent(ordered); -} - void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered) { struct btrfs_inode *inode = BTRFS_I(ordered->inode); diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h index c0570d35fea291..f01d096f87d59b 100644 --- a/fs/btrfs/zoned.h +++ b/fs/btrfs/zoned.h @@ -56,7 +56,6 @@ void btrfs_redirty_list_add(struct btrfs_transaction *trans, struct extent_buffer *eb); void btrfs_free_redirty_list(struct btrfs_transaction *trans); bool btrfs_use_zone_append(struct btrfs_bio *bbio); -void btrfs_record_physical_zoned(struct btrfs_bio *bbio); void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered); bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info, struct extent_buffer *eb, @@ -186,10 +185,6 @@ static inline bool btrfs_use_zone_append(struct btrfs_bio *bbio) return false; } -static inline void btrfs_record_physical_zoned(struct btrfs_bio *bbio) -{ -} - static inline void btrfs_rewrite_logical_zoned( struct btrfs_ordered_extent *ordered) { } From patchwork Mon May 8 16:08:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234744 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 EE864C77B7F for ; Mon, 8 May 2023 16:09:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233789AbjEHQJL (ORCPT ); Mon, 8 May 2023 12:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233361AbjEHQI4 (ORCPT ); Mon, 8 May 2023 12:08:56 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D37145243 for ; Mon, 8 May 2023 09:08:54 -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=G6OSLjhAGHxVm5H0Yefaz+AZeSy5hynEjm7UlDC6rOg=; b=077Jsq9pw4bCJnLNeXeraZOT5v aLcDVszo6qERRqV01jAl0V7kqdXALzzVtihK/ZYHGJ7Dn79k07C6KnSAKh91NRtlQ0h5w4clwZcNj 0fqGQchRxu8peOPRP/E7h+oiCk/zGYi7UoVzaCOY7f9APFSRDHtMUV8oshSl01g5tjbsBgXKta+5p WbaloUOVmkOwc5zTtWf9LLS2c7/FbpeUjUuUwJeTqgrAFDCX5opTFb2Iv+wNm6bPD5h8hOswVv9V2 Vq265Le4h6w17NtnptBeEpxgCvYC0MktZfwqu6i7ysgk7EOUy3OrVDmY++5KZBcQ5nB/QOql5IDu3 3etkgmpw==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Px-000w3X-1x; Mon, 08 May 2023 16:08:53 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 15/21] btrfs: factor out a can_finish_ordered_extent helper Date: Mon, 8 May 2023 09:08:37 -0700 Message-Id: <20230508160843.133013-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Factor out a helper from btrfs_mark_ordered_io_finished that does the actual per-ordered_extent work to check if we want to schedule an I/O completion. This new helper will later be used complete an ordered_extent without first doing a lookup. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/ordered-data.c | 103 ++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 0ea4efc1264512..36e4d2517b28fd 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -288,6 +288,63 @@ static void finish_ordered_fn(struct btrfs_work *work) btrfs_finish_ordered_io(ordered_extent); } +static bool can_finish_ordered_extent(struct btrfs_ordered_extent *ordered, + struct page *page, u64 file_offset, + u64 len, bool uptodate) +{ + struct btrfs_inode *inode = BTRFS_I(ordered->inode); + struct btrfs_fs_info *fs_info = inode->root->fs_info; + + lockdep_assert_held(&inode->ordered_tree.lock); + + if (page) { + ASSERT(page->mapping); + ASSERT(page_offset(page) <= file_offset); + ASSERT(file_offset + len <= page_offset(page) + PAGE_SIZE); + + /* + * Ordered (Private2) bit indicates whether we still + * have pending io unfinished for the ordered extent. + * + * If there's no such bit, we need to skip to next range. + */ + if (!btrfs_page_test_ordered(fs_info, page, file_offset, len)) + return false; + btrfs_page_clear_ordered(fs_info, page, file_offset, len); + } + + /* Now we're fine to update the accounting */ + if (WARN_ON_ONCE(len > ordered->bytes_left)) { + btrfs_crit(fs_info, +"bad ordered extent accounting, root=%llu ino=%llu OE offset=%llu OE len=%llu to_dec=%llu left=%llu", + inode->root->root_key.objectid, + btrfs_ino(inode), + ordered->file_offset, + ordered->num_bytes, + len, + ordered->bytes_left); + ordered->bytes_left = 0; + } else { + ordered->bytes_left -= len; + } + + if (!uptodate) + set_bit(BTRFS_ORDERED_IOERR, &ordered->flags); + + if (ordered->bytes_left) + return false; + + /* + * All the IO of the ordered extent is finished, we need to queue + * the finish_func to be executed. + */ + set_bit(BTRFS_ORDERED_IO_DONE, &ordered->flags); + cond_wake_up(&ordered->wait); + refcount_inc(&ordered->refs); + trace_btrfs_ordered_extent_mark_finished(inode, ordered); + return true; +} + /* * Mark all ordered extents io inside the specified range finished. * @@ -318,10 +375,6 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, else wq = fs_info->endio_write_workers; - if (page) - ASSERT(page->mapping && page_offset(page) <= file_offset && - file_offset + num_bytes <= page_offset(page) + PAGE_SIZE); - spin_lock_irqsave(&tree->lock, flags); while (cur < file_offset + num_bytes) { u64 entry_end; @@ -374,47 +427,7 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, ASSERT(end + 1 - cur < U32_MAX); len = end + 1 - cur; - if (page) { - /* - * Ordered (Private2) bit indicates whether we still - * have pending io unfinished for the ordered extent. - * - * If there's no such bit, we need to skip to next range. - */ - if (!btrfs_page_test_ordered(fs_info, page, cur, len)) { - cur += len; - continue; - } - btrfs_page_clear_ordered(fs_info, page, cur, len); - } - - /* Now we're fine to update the accounting */ - if (unlikely(len > entry->bytes_left)) { - WARN_ON(1); - btrfs_crit(fs_info, -"bad ordered extent accounting, root=%llu ino=%llu OE offset=%llu OE len=%llu to_dec=%u left=%llu", - inode->root->root_key.objectid, - btrfs_ino(inode), - entry->file_offset, - entry->num_bytes, - len, entry->bytes_left); - entry->bytes_left = 0; - } else { - entry->bytes_left -= len; - } - - if (!uptodate) - set_bit(BTRFS_ORDERED_IOERR, &entry->flags); - - /* - * All the IO of the ordered extent is finished, we need to queue - * the finish_func to be executed. - */ - if (entry->bytes_left == 0) { - set_bit(BTRFS_ORDERED_IO_DONE, &entry->flags); - cond_wake_up(&entry->wait); - refcount_inc(&entry->refs); - trace_btrfs_ordered_extent_mark_finished(inode, entry); + if (can_finish_ordered_extent(entry, page, cur, len, uptodate)) { spin_unlock_irqrestore(&tree->lock, flags); btrfs_init_work(&entry->work, finish_ordered_fn, NULL, NULL); btrfs_queue_work(wq, &entry->work); From patchwork Mon May 8 16:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234746 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 97EF8C7EE24 for ; Mon, 8 May 2023 16:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233391AbjEHQJN (ORCPT ); Mon, 8 May 2023 12:09:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233424AbjEHQI5 (ORCPT ); Mon, 8 May 2023 12:08:57 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75B8C658E for ; Mon, 8 May 2023 09:08:55 -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=OqqypU+aKqc926oUL6ED0h5SbV6n+oqGaeXw5yBTkos=; b=bZA2V5n+ouPlg1EqRYhg+xKky2 8c+nFK9w37ZzZVMlI4w1jLh4sARN91RoXoSLsVuPy2Tp4I8mGfr8qUPKOS/f7ykf/rrE9UCzQk1Mw h2/Kng+Cc0BZbr66eiBE/oe1z3ZtK5mZcwn4KR66Kr1vwB+U2UjinN9N1RhW4o36AIjS1CRASwQcQ fn1eJ7LEV2ud6aBz/U0lEo2gQcmDlRwd2biNowfMf13VDndmvSHgbAJg9YGYjBkAb5h2NRajjwkdT JEoiLGACpxupSL8qAzpIC8oCEH1gsSIhvHtWcRd9VEaNxIOq7JltVvBqQx42unq+fl/o+Te2yO4kH XvNaW8Yw==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Py-000w3n-0u; Mon, 08 May 2023 16:08:54 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 16/21] btrfs: factor out a btrfs_queue_ordered_fn helper Date: Mon, 8 May 2023 09:08:38 -0700 Message-Id: <20230508160843.133013-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Factor out a helper to queue up an ordered_extent completion in a work queue. This new helper will later be used complete an ordered_extent without first doing a lookup. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/ordered-data.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 36e4d2517b28fd..f474585e6234fe 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -345,6 +345,17 @@ static bool can_finish_ordered_extent(struct btrfs_ordered_extent *ordered, return true; } +static void btrfs_queue_ordered_fn(struct btrfs_ordered_extent *ordered) +{ + struct btrfs_inode *inode = BTRFS_I(ordered->inode); + struct btrfs_fs_info *fs_info = inode->root->fs_info; + struct btrfs_workqueue *wq = btrfs_is_free_space_inode(inode) ? + fs_info->endio_freespace_worker : fs_info->endio_write_workers; + + btrfs_init_work(&ordered->work, finish_ordered_fn, NULL, NULL); + btrfs_queue_work(wq, &ordered->work); +} + /* * Mark all ordered extents io inside the specified range finished. * @@ -363,18 +374,11 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, u64 num_bytes, bool uptodate) { struct btrfs_ordered_inode_tree *tree = &inode->ordered_tree; - struct btrfs_fs_info *fs_info = inode->root->fs_info; - struct btrfs_workqueue *wq; struct rb_node *node; struct btrfs_ordered_extent *entry = NULL; unsigned long flags; u64 cur = file_offset; - if (btrfs_is_free_space_inode(inode)) - wq = fs_info->endio_freespace_worker; - else - wq = fs_info->endio_write_workers; - spin_lock_irqsave(&tree->lock, flags); while (cur < file_offset + num_bytes) { u64 entry_end; @@ -429,8 +433,7 @@ void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, if (can_finish_ordered_extent(entry, page, cur, len, uptodate)) { spin_unlock_irqrestore(&tree->lock, flags); - btrfs_init_work(&entry->work, finish_ordered_fn, NULL, NULL); - btrfs_queue_work(wq, &entry->work); + btrfs_queue_ordered_fn(entry); spin_lock_irqsave(&tree->lock, flags); } cur += len; From patchwork Mon May 8 16:08:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234748 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 AD632C77B7F for ; Mon, 8 May 2023 16:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233463AbjEHQJP (ORCPT ); Mon, 8 May 2023 12:09:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233551AbjEHQI6 (ORCPT ); Mon, 8 May 2023 12:08:58 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 981BE6EAE for ; Mon, 8 May 2023 09:08:57 -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=uie9UZUG8vdVd0Yi8qQ5As3KmYkbazcHCHvKuw7SOxs=; b=WGHP3JrBtCExeBP6wWu22Op1G8 kPlJhNU8+3Outo6GvwMThNyVxrIcschRKCffCyEuy+lCGdSDlmPBRUJ9Pj6Qs4uioWNc5KvJj4RLi p+Fh1vEEZmfe2Xk5tiGrPsPsB9Ccp/KbRsB6gRVD3D3DlZ6MlwCtLBn3qTsuiVAr7gKQjr3PV8Dcu haCovg67226ffZR7TMxxWxhLWXKnJz1ndOr6ZVSYsUbXyOXr+I9NfJ8LmhO5nkOSwDacdSHDAIgFN LcK9b7sjw3cz6cDMH2HlSkuSJNiB4t/MePIJXf7M5mYBiyLFOYpmmka2xDoKAt6+SGy0iwVg35SEz ZcyaF98A==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Py-000w3z-30; Mon, 08 May 2023 16:08:55 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 17/21] btrfs: add a btrfs_finish_ordered_extent helper Date: Mon, 8 May 2023 09:08:39 -0700 Message-Id: <20230508160843.133013-18-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Add a helper to complete an ordered_extent without first doing a lookup. Signed-off-by: Christoph Hellwig --- fs/btrfs/ordered-data.c | 20 ++++++++++++++++++++ fs/btrfs/ordered-data.h | 3 +++ include/trace/events/btrfs.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index f474585e6234fe..a54bf49bd5c849 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -356,6 +356,26 @@ static void btrfs_queue_ordered_fn(struct btrfs_ordered_extent *ordered) btrfs_queue_work(wq, &ordered->work); } +bool btrfs_finish_ordered_extent(struct btrfs_ordered_extent *ordered, + struct page *page, u64 file_offset, u64 len, + bool uptodate) +{ + struct btrfs_inode *inode = BTRFS_I(ordered->inode); + unsigned long flags; + bool ret; + + trace_btrfs_finish_ordered_extent(inode, file_offset, len, uptodate); + + spin_lock_irqsave(&inode->ordered_tree.lock, flags); + ret = can_finish_ordered_extent(ordered, page, file_offset, len, + uptodate); + spin_unlock_irqrestore(&inode->ordered_tree.lock, flags); + + if (ret) + btrfs_queue_ordered_fn(ordered); + return ret; +} + /* * Mark all ordered extents io inside the specified range finished. * diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 87a61a2bb722fd..16e2e7b91267cb 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -172,6 +172,9 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry); void btrfs_remove_ordered_extent(struct btrfs_inode *btrfs_inode, struct btrfs_ordered_extent *entry); +bool btrfs_finish_ordered_extent(struct btrfs_ordered_extent *ordered, + struct page *page, u64 file_offset, u64 len, + bool uptodate); void btrfs_mark_ordered_io_finished(struct btrfs_inode *inode, struct page *page, u64 file_offset, u64 num_bytes, bool uptodate); diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index 8ea9cea9bfeb4d..c0f308ef6f7699 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -661,6 +661,35 @@ DEFINE_EVENT(btrfs__ordered_extent, btrfs_ordered_extent_mark_finished, TP_ARGS(inode, ordered) ); +TRACE_EVENT(btrfs_finish_ordered_extent, + + TP_PROTO(const struct btrfs_inode *inode, u64 start, u64 len, + int uptodate), + + TP_ARGS(inode, start, len, uptodate), + + TP_STRUCT__entry_btrfs( + __field( u64, ino ) + __field( u64, start ) + __field( u64, len ) + __field( int, uptodate ) + __field( u64, root_objectid ) + ), + + TP_fast_assign_btrfs(inode->root->fs_info, + __entry->ino = btrfs_ino(inode); + __entry->start = start; + __entry->len = len; + __entry->uptodate = uptodate; + __entry->root_objectid = inode->root->root_key.objectid; + ), + + TP_printk_btrfs("root=%llu(%s) ino=%llu start=%llu len=%llu uptodate=%d", + show_root_type(__entry->root_objectid), + __entry->ino, __entry->start, + __entry->len, __entry->uptodate) +); + DECLARE_EVENT_CLASS(btrfs__writepage, TP_PROTO(const struct page *page, const struct inode *inode, From patchwork Mon May 8 16:08:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234747 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 8061AC7EE2A for ; Mon, 8 May 2023 16:09:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233778AbjEHQJO (ORCPT ); Mon, 8 May 2023 12:09:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233463AbjEHQI6 (ORCPT ); Mon, 8 May 2023 12:08:58 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C6865B5 for ; Mon, 8 May 2023 09:08:57 -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=e7/Uo8pet6CDs868vn74KDVtUPHYQqK7Fce+4jiBIj4=; b=bL1vYNdIstAVzx7aPbwxc8eFc0 LkPbmLqRLmTq7iqxq8SZzvUGzFDteJnKg8zplMRrPF6OrWW9nliG5EjP9uejaPMorSenqOZDjypH2 8lM6PFbSfHkEvea91y805ZN8GpuqZt49l71rV+fW6PQzEXivEzA32yEA1/wK2I1v1FdfWjCNo6W5o N88jX0EAjnXtzc+eY3bGrgWoeFWO37hULtP6QG6vdoq0AkuS+yAVu0/I1qb+4sGSjGWBmvGXK6ONE 5Rv/JRGQ6Clbn1yM0yD93k8tMbYazEqqnTf4Oo9nUtGPt8cSnma59LoItc7myPrx25QeNFnAh/asT 3YQajfJQ==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Pz-000w4G-1s; Mon, 08 May 2023 16:08:55 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 18/21] btrfs: use btrfs_finish_ordered_extent to complete compressed writes Date: Mon, 8 May 2023 09:08:40 -0700 Message-Id: <20230508160843.133013-19-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Use the btrfs_finish_ordered_extent helper to complete compressed writes using the bbio->ordered pointer instead of requiring an rbtree lookup in the otherwise equivalent btrfs_mark_ordered_io_finished called from btrfs_writepage_endio_finish_ordered. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/compression.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index a3f8416125a8c1..222cd998807838 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -226,13 +226,8 @@ static void btrfs_finish_compressed_write_work(struct work_struct *work) struct compressed_bio *cb = container_of(work, struct compressed_bio, write_end_work); - /* - * Ok, we're the last bio for this extent, step one is to call back - * into the FS and do all the end_io operations. - */ - btrfs_writepage_endio_finish_ordered(cb->bbio.inode, NULL, - cb->start, cb->start + cb->len - 1, - cb->bbio.bio.bi_status == BLK_STS_OK); + btrfs_finish_ordered_extent(cb->bbio.ordered, NULL, cb->start, cb->len, + cb->bbio.bio.bi_status == BLK_STS_OK); if (cb->writeback) end_compressed_writeback(cb); From patchwork Mon May 8 16:08:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234751 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 81F16C7EE22 for ; Mon, 8 May 2023 16:09:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233801AbjEHQJS (ORCPT ); Mon, 8 May 2023 12:09:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233557AbjEHQI6 (ORCPT ); Mon, 8 May 2023 12:08:58 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC8BD7285 for ; Mon, 8 May 2023 09:08:57 -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=FUmqKjQu4j2xpRHkwiDzI4uiKM0qMYUcWSvP6zY/Igc=; b=XX00TAQS3x81nnAAYKiIS5QPhZ CY6DsHQaMU+L2pUhRLSgVUYgQgvLyA8lzk0vRaCsqH9g0hafzfw/kn8aikJi0PpFzW8bfC0H0l3ww N84uZbnxwp0BW7Ujt+MA4fOwLncwkbTZMl/FBFhlxlF36XkCHvQADzzB5H0Z42vkMEQgbzO6kHdiH zAciBeWVM6ZZQOahR5o0u7xXXCY2ozlJ6Ikwf/nQ1FBDJvlZrWn/TWQp1alelhmqz7CrzcpXtdKqg Ma72cLcdMzGIMYhYNbXjMUHZebq4/8EgUeV9kHDh30RoNN4EBm+Pe3W7SEsNGRtsKyzhwzCpgtN8o ZIC3yC3g==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Q0-000w4S-0k; Mon, 08 May 2023 16:08:56 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 19/21] btrfs: use btrfs_finish_ordered_extent to complete direct writes Date: Mon, 8 May 2023 09:08:41 -0700 Message-Id: <20230508160843.133013-20-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Use the btrfs_finish_ordered_extent helper to complete compressed writes using the bbio->ordered pointer instead of requiring an rbtree lookup in the otherwise equivalent btrfs_mark_ordered_io_finished called from btrfs_writepage_endio_finish_ordered. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ff1f5014156390..3b55b7cd7ebf19 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7856,8 +7856,8 @@ static int btrfs_dio_iomap_end(struct inode *inode, loff_t pos, loff_t length, pos += submitted; length -= submitted; if (write) - btrfs_mark_ordered_io_finished(BTRFS_I(inode), NULL, - pos, length, false); + btrfs_finish_ordered_extent(dio_data->ordered, NULL, + pos, length, false); else unlock_extent(&BTRFS_I(inode)->io_tree, pos, pos + length - 1, NULL); @@ -7887,12 +7887,14 @@ static void btrfs_dio_end_io(struct btrfs_bio *bbio) dip->file_offset, dip->bytes, bio->bi_status); } - if (btrfs_op(bio) == BTRFS_MAP_WRITE) - btrfs_mark_ordered_io_finished(inode, NULL, dip->file_offset, - dip->bytes, !bio->bi_status); - else + if (btrfs_op(bio) == BTRFS_MAP_WRITE) { + btrfs_finish_ordered_extent(bbio->ordered, NULL, + dip->file_offset, dip->bytes, + !bio->bi_status); + } else { unlock_extent(&inode->io_tree, dip->file_offset, dip->file_offset + dip->bytes - 1, NULL); + } bbio->bio.bi_private = bbio->private; iomap_dio_bio_end_io(bio); From patchwork Mon May 8 16:08:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234750 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 C6507C7EE2A for ; Mon, 8 May 2023 16:09:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233625AbjEHQJR (ORCPT ); Mon, 8 May 2023 12:09:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233585AbjEHQJA (ORCPT ); Mon, 8 May 2023 12:09:00 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAFC27287 for ; Mon, 8 May 2023 09:08:58 -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=In6A8/bIfi/XcX1LUpSa5nRBoDlTnuaFGF7Tg/IbMTY=; b=VTw7Ddfbqt1LBl48RnZzGPYNJ4 q6ZO7qQt2/hsRLnmgwXFWkzZ0MiOfbHQUWH0/W76YAFPuXuokJQrgSdbP9yPxv7id945izLjiI7IB JUZ7yvn9CkL3Cuf+5qBJvEyYQgNnpKuvy5FZBUB/AVEFWOPJNu0UuryQ+HqCeyZRpH4W16Is5+5/V 3/EwKvNSD18GRLBprc0rUvTsb4swrqb76ns1WdjoSGKbUIsm8CpopcJvFxweXmvF8S0h0r7PU+GS4 nNCLQiBQutRK140JQ90j7ZqR7lMaKgQeOEwzGAxyir9Z+aPB9RkR7uZCY8nJz3vfoYjp349TZ+TqI PuGBpntA==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Q0-000w4d-2q; Mon, 08 May 2023 16:08:56 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 20/21] btrfs: open code end_extent_writepage in end_bio_extent_writepage Date: Mon, 8 May 2023 09:08:42 -0700 Message-Id: <20230508160843.133013-21-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 This prepares for switching to more efficient ordered_extent processing and already removes the forth and back conversion from len to end back to len. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 7417ce759f6f48..f02564ad194050 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -574,8 +574,6 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio) struct bio *bio = &bbio->bio; int error = blk_status_to_errno(bio->bi_status); struct bio_vec *bvec; - u64 start; - u64 end; struct bvec_iter_all iter_all; ASSERT(!bio_flagged(bio, BIO_CLONED)); @@ -584,6 +582,8 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio) struct inode *inode = page->mapping->host; struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); const u32 sectorsize = fs_info->sectorsize; + u64 start = page_offset(page) + bvec->bv_offset; + u32 len = bvec->bv_len; /* Our read/write should always be sector aligned. */ if (!IS_ALIGNED(bvec->bv_offset, sectorsize)) @@ -595,12 +595,14 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio) "incomplete page write with offset %u and length %u", bvec->bv_offset, bvec->bv_len); - start = page_offset(page) + bvec->bv_offset; - end = start + bvec->bv_len - 1; - - end_extent_writepage(page, error, start, end); - - btrfs_page_clear_writeback(fs_info, page, start, bvec->bv_len); + btrfs_writepage_endio_finish_ordered(BTRFS_I(inode), page, start, + start + len - 1, !error); + if (error) { + btrfs_page_clear_uptodate(fs_info, page, start, len); + btrfs_page_set_error(fs_info, page, start, len); + mapping_set_error(page->mapping, error); + } + btrfs_page_clear_writeback(fs_info, page, start, len); } bio_put(bio); From patchwork Mon May 8 16:08:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13234749 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 D4CADC7EE24 for ; Mon, 8 May 2023 16:09:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233790AbjEHQJQ (ORCPT ); Mon, 8 May 2023 12:09:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233442AbjEHQI7 (ORCPT ); Mon, 8 May 2023 12:08:59 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9BE46A63 for ; Mon, 8 May 2023 09:08:58 -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=xta5Lb2860oItYhGC8MyezxwVln/x6CpnyEoF4ifLro=; b=ma2Euz8K6djNCvwWyUUzBX3M7+ pAHcBd1/x9g9EdeeX9Xao0d0to/hsfZVmxOOuSkR0eSGZkAQh8++c2W83O0lGBKvrqGIfuPcihRdG WuNBm0HL7YcxSeT3wmQ4AAYotjEal3f1WhPlUJiqVLWNjzhexZYckRxSas1hJjhy06iGJNQBjnozF Krb+lgmbuasQ8YwTa3cs3Rbd9KPZx2egER7SUIx5exC8t7gNHzDlqFNKjjrPlPai2MY2mRZbLe0rE ezvUVsjSDsYhswc0F9j/lzeHJL8JTzVw8qmCdCxXMs46J5SR5FXSdYTvkMEhdMC4ZOe19bwhQerdN LrcsifeQ==; Received: from [208.98.210.70] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pw3Q1-000w52-1i; Mon, 08 May 2023 16:08:57 +0000 From: Christoph Hellwig To: Chris Mason , Josef Bacik , David Sterba Cc: linux-btrfs@vger.kernel.org Subject: [PATCH 21/21] btrfs: use btrfs_finish_ordered_extent to complete buffered writes Date: Mon, 8 May 2023 09:08:43 -0700 Message-Id: <20230508160843.133013-22-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230508160843.133013-1-hch@lst.de> References: <20230508160843.133013-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 Use the btrfs_finish_ordered_extent helper to complete compressed writes using the bbio->ordered pointer instead of requiring an rbtree lookup in the otherwise equivalent btrfs_mark_ordered_io_finished called from btrfs_writepage_endio_finish_ordered. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn --- fs/btrfs/extent_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index f02564ad194050..7a3a40c2eb7ff5 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -595,8 +595,8 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio) "incomplete page write with offset %u and length %u", bvec->bv_offset, bvec->bv_len); - btrfs_writepage_endio_finish_ordered(BTRFS_I(inode), page, start, - start + len - 1, !error); + btrfs_finish_ordered_extent(bbio->ordered, page, start, len, + !error); if (error) { btrfs_page_clear_uptodate(fs_info, page, start, len); btrfs_page_set_error(fs_info, page, start, len);