From patchwork Fri Jan 29 05:03:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 8158991 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 466D69F9A0 for ; Fri, 29 Jan 2016 05:17:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6450B20361 for ; Fri, 29 Jan 2016 05:17:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E47B20351 for ; Fri, 29 Jan 2016 05:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752324AbcA2FR2 (ORCPT ); Fri, 29 Jan 2016 00:17:28 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:7336 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752282AbcA2FR1 (ORCPT ); Fri, 29 Jan 2016 00:17:27 -0500 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="304664" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 29 Jan 2016 13:05:46 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id E9B084056416; Fri, 29 Jan 2016 13:05:34 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, David Sterba Subject: [PATCH v3 20/22] btrfs-progs: Convert: Add support for rollback new convert behavior Date: Fri, 29 Jan 2016 13:03:30 +0800 Message-Id: <1454043812-7893-21-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454043812-7893-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1454043812-7893-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: E9B084056416.AB720 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support to rollback new btrfs-convert. The support is quite easy unlike the new convert behavior, which in fact makes the rollback less restricted. The core is, rollback must support both old and new convert result. For old convert, all fs image extents can be covered by any chunk type. But any extents inside reserved range must be covered by chunk. For new convert, all fs image extents are covered by data chunk. Allowing any condition will just make another fail to pass. So make the convert condition a little less restricted to allow both can be converted. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- btrfs-convert.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/btrfs-convert.c b/btrfs-convert.c index 17ce8ac..efa3b02 100644 --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -3801,11 +3801,19 @@ static int do_rollback(const char *devname) num_bytes = btrfs_file_extent_num_bytes(leaf, fi); cache1 = btrfs_lookup_block_group(root->fs_info, offset); - cache2 = btrfs_lookup_block_group(root->fs_info, - offset + num_bytes - 1); - if (!cache1 || cache1 != cache2 || - (!(cache1->flags & BTRFS_BLOCK_GROUP_SYSTEM) && - !intersect_with_sb(offset, num_bytes))) + cache2 = btrfs_lookup_block_group(root->fs_info, + offset + num_bytes - 1); + /* + * Here we must take consideration of old and new convert + * behavior. + * For old convert case, sign, there is no consist chunk type + * that will cover the extent. META/DATA/SYS are all possible. + * Just ensure relocate one is in SYS chunk. + * For new convert case, they are all covered by DATA chunk. + * + * So, there is not valid chunk type check for it now. + */ + if (cache1 != cache2) break; set_extent_bits(&io_tree, offset, offset + num_bytes - 1, @@ -3819,6 +3827,7 @@ next_extent: if (offset < total_bytes) { fprintf(stderr, "unable to build extent mapping\n"); + fprintf(stderr, "converted filesystem after balance is unable to rollback\n"); goto fail; }