From patchwork Wed Sep 23 07:19:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7248011 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 5AA529F30C for ; Wed, 23 Sep 2015 07:20:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 68AD42034B for ; Wed, 23 Sep 2015 07:20:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70BF92035D for ; Wed, 23 Sep 2015 07:20:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752629AbbIWHUr (ORCPT ); Wed, 23 Sep 2015 03:20:47 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:27885 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752456AbbIWHUq (ORCPT ); Wed, 23 Sep 2015 03:20:46 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="101010640" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 23 Sep 2015 15:23:29 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8N7KQK1027982 for ; Wed, 23 Sep 2015 15:20:26 +0800 Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Wed, 23 Sep 2015 15:20:44 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH v2 1/3] btrfs-progs: tests: Move extract_image out of check_all_images for common use Date: Wed, 23 Sep 2015 15:19:04 +0800 Message-ID: <79b70366a2679adbc039ba11b92d874460fb6d0c.1442992715.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move code for extract image file to a function from check_all_images() for common use, so caller can use this function to extrace single image file. Signed-off-by: Zhao Lei --- tests/common | 76 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/tests/common b/tests/common index 63b0d9f..320c4dd 100644 --- a/tests/common +++ b/tests/common @@ -62,6 +62,44 @@ check_image() run_check $TOP/btrfs check $image } +extract_image() +{ + local image="$1" + + local cleanme= + case "$image" in + *.img) + rm -f $image.restored + : ;; + *.img.xz) + xz --decompress --keep "$image" || \ + _fail "failed to decompress image $image" >&2 + image=${image%%.xz} + rm -f $image.restored + cleanme=$image + ;; + *.raw) + cp --sparse=auto $image $image.restored + ;; + *.raw.xz) + xz --decompress --keep "$image" || \ + _fail "failed to decompress image $image" >&2 + image=${image%%.xz} + mv "$image" "$image".restored + ;; + esac + + if ! [ -f $image.restored ]; then + echo "restoring image $(basename $image)" >> $RESULTS + $TOP/btrfs-image -r $image $image.restored || \ + _fail "failed to restore image $image" >&2 + fi + + [[ "$cleanme" ]] && rm -f "$cleanme" + + echo "$image.restored" +} + # Process all image dumps in a given directory, # - raw btrfs filesystem images, suffix .raw # - dtto compressed by XZ, suffix .raw.xz @@ -69,44 +107,16 @@ check_image() # - dtto compressed by XZ, suffix .img.xz check_all_images() { - dir=$1 + local dir=$1 for image in $(find $dir \( -iname '*.img' -o \ -iname '*.img.xz' -o \ -iname '*.raw' -o \ -iname '*.raw.xz' \) | sort) do - cleanme= - case "$image" in - *.img) - rm -f $image.restored - : ;; - *.img.xz) - xz --decompress --keep "$image" || \ - _fail "failed to decompress image $image" - image=${image%%.xz} - rm -f $image.restored - cleanme=$image - ;; - *.raw) - cp --sparse=auto $image $image.restored - ;; - *.raw.xz) - xz --decompress --keep "$image" || \ - _fail "failed to decompress image $image" - image=${image%%.xz} - mv "$image" "$image".restored - ;; - esac - - if ! [ -f $image.restored ]; then - echo "restoring image $(basename $image)" >> $RESULTS - $TOP/btrfs-image -r $image $image.restored || \ - _fail "failed to restore image $image" - fi - - check_image $image.restored - - rm -f $image.restored $cleanme + local extracted + extracted=$(extract_image "$image") + check_image "$extracted" + rm -f "$extracted" done }