From patchwork Thu Jul 4 10:37:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 2822841 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F3C5FBF4A1 for ; Thu, 4 Jul 2013 11:13:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1816F2014C for ; Thu, 4 Jul 2013 11:13:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 446282014B for ; Thu, 4 Jul 2013 11:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756499Ab3GDLNK (ORCPT ); Thu, 4 Jul 2013 07:13:10 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:11079 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752984Ab3GDLNJ (ORCPT ); Thu, 4 Jul 2013 07:13:09 -0400 X-IronPort-AV: E=Sophos;i="4.87,994,1363104000"; d="scan'208";a="7782807" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 04 Jul 2013 19:10:10 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r64AbksR019758 for ; Thu, 4 Jul 2013 18:37:47 +0800 Received: from btrfs.fnst.cn.fujitsu.com ([10.167.234.170]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013070418361715-2713041 ; Thu, 4 Jul 2013 18:36:17 +0800 From: Miao Xie To: linux-btrfs@vger.kernel.org Subject: [PATCH] Btrfs: fix wrong write offset when replacing a device Date: Thu, 4 Jul 2013 18:37:21 +0800 Message-Id: <1372934241-421-1-git-send-email-miaox@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/04 18:36:17, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/04 18:36:18, Serialize complete at 2013/07/04 18:36:18 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The filesystem was corrupted after we did a device replace. Steps to reproduce: # mkfs.btrfs -f -m single -d raid10 .. # mount # btrfs replace start -rfB 1 # umount # btrfsck The reason is that we changed the write offset by mistake. When we replace the a device, we read the data from the source device at first, and then write the data into the corresponding place of the new device. But when we read the data, we will try to spread the read request among the mirrors. It is a good idea that can speed up the read request, but should not change the write offset because it is corresponding to the source device, not the mirror device, if we change it by the offset of the mirror device, we would get the wrong offset. Fix it. Signed-off-by: Miao Xie --- fs/btrfs/scrub.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 929093d..092bec4 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -228,7 +228,6 @@ static void scrub_bio_end_io_worker(struct btrfs_work *work); static void scrub_block_complete(struct scrub_block *sblock); static void scrub_remap_extent(struct btrfs_fs_info *fs_info, u64 extent_logical, u64 extent_len, - u64 *extent_physical, struct btrfs_device **extent_dev, int *extent_mirror_num); static int scrub_setup_wr_ctx(struct scrub_ctx *sctx, @@ -2482,8 +2481,7 @@ again: extent_mirror_num = mirror_num; if (is_dev_replace) scrub_remap_extent(fs_info, extent_logical, - extent_len, &extent_physical, - &extent_dev, + extent_len, &extent_dev, &extent_mirror_num); ret = btrfs_lookup_csums_range(csum_root, logical, @@ -3057,7 +3055,6 @@ int btrfs_scrub_progress(struct btrfs_root *root, u64 devid, static void scrub_remap_extent(struct btrfs_fs_info *fs_info, u64 extent_logical, u64 extent_len, - u64 *extent_physical, struct btrfs_device **extent_dev, int *extent_mirror_num) { @@ -3074,7 +3071,6 @@ static void scrub_remap_extent(struct btrfs_fs_info *fs_info, return; } - *extent_physical = bbio->stripes[0].physical; *extent_mirror_num = bbio->mirror_num; *extent_dev = bbio->stripes[0].dev; kfree(bbio);