From patchwork Fri Sep 4 13:23:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 7122701 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9D76DBEEC1 for ; Fri, 4 Sep 2015 13:27:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 90BBD20841 for ; Fri, 4 Sep 2015 13:26:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A57F520840 for ; Fri, 4 Sep 2015 13:26:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933144AbbIDNZh (ORCPT ); Fri, 4 Sep 2015 09:25:37 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:7682 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S933115AbbIDNZe (ORCPT ); Fri, 4 Sep 2015 09:25:34 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100347636" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Sep 2015 21:28: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 t84DPHId029996 for ; Fri, 4 Sep 2015 21:25:17 +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; Fri, 4 Sep 2015 21:25:27 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH 1/3] btrfs-progs: tests: Move extract_image out of check_all_images for common use Date: Fri, 4 Sep 2015 21:23:49 +0800 Message-ID: <154afcdd14c259551d843a157814fd0ff3589e8f.1441373012.git.zhaolei@cn.fujitsu.com> X-Mailer: git-send-email 1.8.5.1 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 | 73 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/tests/common b/tests/common index 63b0d9f..0c0efef 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" + 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 + + [[ "$cleanme" ]] && rm -f "$cleanme" + + EXTRACT_IMAGE_OUTPUT="$image.restored" +} + # Process all image dumps in a given directory, # - raw btrfs filesystem images, suffix .raw # - dtto compressed by XZ, suffix .raw.xz @@ -75,38 +113,9 @@ check_all_images() -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 + extract_image "$image" + check_image "$EXTRACT_IMAGE_OUTPUT" + rm -f "$EXTRACT_IMAGE_OUTPUT" done }