From patchwork Mon May 23 01:48:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 12858396 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 C1B91C433EF for ; Mon, 23 May 2022 01:48:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351914AbiEWBs4 (ORCPT ); Sun, 22 May 2022 21:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351911AbiEWBsz (ORCPT ); Sun, 22 May 2022 21:48:55 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50C2613FB9 for ; Sun, 22 May 2022 18:48:54 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 01EEA1F385; Mon, 23 May 2022 01:48:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1653270533; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lm7PihVKbV+9QZsORzpyjvpOtsEvQ3YmWkfAcpKY6cU=; b=gs5uYY1RCWmUdMMVZ67YBG2CUgijg7hlDv805RIfEfi3BdCuJ2sT6KgiWulhNI0glMHLa8 OArlmMP7X/3YS4+vLZ/AZ+H+b+XRBWmZes57M0xFhwzRViQJquSrGxgB6xpvCbs3RdNLR9 oyPNq6qQZVJ5hvqLdc5D23kYkbj4/lA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1B00113ADF; Mon, 23 May 2022 01:48:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6N8+NQPoimLzOQAAMHmgww (envelope-from ); Mon, 23 May 2022 01:48:51 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: Christoph Hellwig Subject: [PATCH 1/7] btrfs: save the original bi_iter into btrfs_bio for buffered read Date: Mon, 23 May 2022 09:48:25 +0800 Message-Id: X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Although we have btrfs_bio::iter, it currently have very limited usage: - RAID56 Which is not needed at all - btrfs_bio_clone() This is used mostly for direct IO. For the incoming read repair patches, we want to grab the original logical bytenr, and be able to iterate the range of the bio (no matter if it's cloned). So this patch will also save btrfs_bio::iter for buffered read bios at submit_one_bio(). And for the sake of consistency, also save the btrfs_bio::iter for direct IO at btrfs_submit_dio_bio(). The reason that we didn't save the iter in btrfs_map_bio() is, btrfs_map_bio() is going to handle various bios, with or without btrfs_bio bioset. And we want to keep btrfs_map_bio() to handle and only handle plain bios without bother the bioset. Signed-off-by: Qu Wenruo Signed-off-by: Christoph Hellwig --- fs/btrfs/extent_io.c | 7 +++++++ fs/btrfs/inode.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 1d144f655f65..1bd1b1253f9d 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -188,6 +188,13 @@ static void submit_one_bio(struct bio *bio, int mirror_num, /* Caller should ensure the bio has at least some range added */ ASSERT(bio->bi_iter.bi_size); + /* + * Save the original bi_iter for read bios, as read repair wants the + * orignial logical bytenr. + */ + if (bio_op(bio) == REQ_OP_READ) + btrfs_bio(bio)->iter = bio->bi_iter; + if (is_data_inode(tree->private_data)) btrfs_submit_data_bio(tree->private_data, bio, mirror_num, compress_type); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 34466b543ed9..dd0882e1b982 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7974,6 +7974,8 @@ static inline blk_status_t btrfs_submit_dio_bio(struct bio *bio, ret = btrfs_bio_wq_end_io(fs_info, bio, BTRFS_WQ_ENDIO_DATA); if (ret) goto err; + /* Check submit_one_bio() for the reason. */ + btrfs_bio(bio)->iter = bio->bi_iter; } if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)