From patchwork Wed Jun 1 08:29:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9146363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AD4DA60761 for ; Wed, 1 Jun 2016 08:29:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CBA42040D for ; Wed, 1 Jun 2016 08:29:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9190625819; Wed, 1 Jun 2016 08:29:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BDFD2040D for ; Wed, 1 Jun 2016 08:29:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752489AbcFAI3v (ORCPT ); Wed, 1 Jun 2016 04:29:51 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:49294 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751488AbcFAI3u (ORCPT ); Wed, 1 Jun 2016 04:29:50 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="579670" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 01 Jun 2016 16:29:46 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 6E7AA4056404; Wed, 1 Jun 2016 16:29:43 +0800 (CST) From: Qu Wenruo To: dsterba@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs-progs: convert: Insert needed holes for superblock migration Date: Wed, 1 Jun 2016 16:29:43 +0800 Message-Id: <20160601082943.10364-1-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.8.3 MIME-Version: 1.0 X-yoursite-MailScanner-ID: 6E7AA4056404.AC706 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP New convert doesn't insert holes for superblock migration range. Unlike old design, which only relocate 4K(superblock size) to other places. In new design, to make sure convert can handle different page size and align chunk bytenr, we relocate the whole 64K range. And if there is only a 4K used block inside 64K superblock migration range, it will make converted fs has discontinuous file extents. This patch will fix it by inserting needed holes to avoid such discontinuous error. Reported-by: Tsutomu Itoh Signed-off-by: Qu Wenruo --- David, I'm very sorry, all these recently exposed bugs are related to superblock migration range, and will only be triggered by special build ext* images(Needs special space range be allocated in ext*) I'll try my best to create the minimal trigger e2image dump, our current image is too large for test cases. Thanks, Qu --- btrfs-convert.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/btrfs-convert.c b/btrfs-convert.c index 42d646c..25c0d17 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -1375,6 +1375,8 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, { u64 cur_off = start; u64 cur_len = len; + u64 hole_start = start; + u64 hole_len; struct cache_extent *cache; struct btrfs_key key; struct extent_buffer *eb; @@ -1426,9 +1428,23 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, ret = csum_disk_extent(trans, root, key.objectid, key.offset); + /* Don't forget to insert hole */ + hole_len = cur_off - hole_start; + if (hole_len) { + ret = btrfs_record_file_extent(trans, root, ino, inode, + hole_start, 0, hole_len); + if (ret < 0) + break; + } + cur_off += key.offset; + hole_start = cur_off; cur_len = start + len - cur_off; } + /* Last hole */ + if (start + len - hole_start > 0) + ret = btrfs_record_file_extent(trans, root, ino, inode, + hole_start, 0, start + len - hole_start); return ret; }