From patchwork Fri Feb 24 05:52:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9589415 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 A02FA60578 for ; Fri, 24 Feb 2017 05:55:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91017287A5 for ; Fri, 24 Feb 2017 05:55:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78C782879A; Fri, 24 Feb 2017 05:55:24 +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 E54A82879A for ; Fri, 24 Feb 2017 05:55:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751057AbdBXFwz (ORCPT ); Fri, 24 Feb 2017 00:52:55 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:60453 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750995AbdBXFwy (ORCPT ); Fri, 24 Feb 2017 00:52:54 -0500 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="15915857" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Feb 2017 13:52:51 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id DF98C47C4EB1; Fri, 24 Feb 2017 13:52:51 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 24 Feb 2017 13:52:51 +0800 From: Qu Wenruo To: , Subject: [PATCH v2 7/9] btrfs-progs: convert: Introduce function to read out btrfs reserved range Date: Fri, 24 Feb 2017 13:52:30 +0800 Message-ID: <20170224055232.4140-8-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170224055232.4140-1-quwenruo@cn.fujitsu.com> References: <20170224055232.4140-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: DF98C47C4EB1.A1606 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 Introduce a new function, read_reserved_ranges(), to allow later rollback to use these data to do rollback. Signed-off-by: Qu Wenruo --- convert/main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/convert/main.c b/convert/main.c index 08df0111..a58716b5 100644 --- a/convert/main.c +++ b/convert/main.c @@ -2749,6 +2749,37 @@ fail: return -1; } +/* + * Read out data of convert image which is in btrfs reserved range. + * + * So rollback can just use these data to overwrite these ranges of btrfs + */ +static int read_reserved_ranges(struct btrfs_root *root, u64 ino, + u64 total_bytes, char *reserved_ranges[]) +{ + int i; + int ret = 0; + + for (i = 0; i < ARRAY_SIZE(btrfs_reserved_ranges); i++) { + struct simple_range *range = &btrfs_reserved_ranges[i]; + + if (range->start + range->len >= total_bytes) + break; + ret = btrfs_read_file(root, ino, range->start, range->len, + reserved_ranges[i]); + if (ret < range->len) { + error( + "failed to read out data of convert image, offset=%llu len=%llu ret=%d", + range->start, range->len, ret); + if (ret >= 0) + ret = -EIO; + break; + } + ret = 0; + } + return ret; +} + static int do_rollback(const char *devname) { int fd = -1;