From patchwork Thu Oct 13 09:22:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9374591 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 4A9CF607FD for ; Thu, 13 Oct 2016 09:23:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BE7229EB0 for ; Thu, 13 Oct 2016 09:23:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FD0529EB3; Thu, 13 Oct 2016 09:23:04 +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,LOTS_OF_MONEY, 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 6484829EB0 for ; Thu, 13 Oct 2016 09:23:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752861AbcJMJWw (ORCPT ); Thu, 13 Oct 2016 05:22:52 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:16152 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752746AbcJMJWs (ORCPT ); Thu, 13 Oct 2016 05:22:48 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="895723" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 13 Oct 2016 17:22:36 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 42F7A41B4BC9; Thu, 13 Oct 2016 17:22:34 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH 2/2] btrfs-progs: fsck-tests: Check if clear space cache works Date: Thu, 13 Oct 2016 17:22:27 +0800 Message-Id: <20161013092227.19761-2-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161013092227.19761-1-quwenruo@cn.fujitsu.com> References: <20161013092227.19761-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 42F7A41B4BC9.AE391 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 Add test case to check the basic function of --clear-space-cache. Signed-off-by: Qu Wenruo --- tests/fsck-tests/024-clear-space-cache/test.sh | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 tests/fsck-tests/024-clear-space-cache/test.sh diff --git a/tests/fsck-tests/024-clear-space-cache/test.sh b/tests/fsck-tests/024-clear-space-cache/test.sh new file mode 100755 index 0000000..ce4fbae --- /dev/null +++ b/tests/fsck-tests/024-clear-space-cache/test.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# confirm fsck clear space cache works fine. + +source $TOP/tests/common + +check_prereq btrfs +check_prereq mkfs.btrfs + +setup_root_helper +prepare_test_dev 1G + +tmp=$(mktemp) +run_check $SUDO_HELPER $TOP/mkfs.btrfs -f $TEST_DEV +run_check_mount_test_dev + +# Create files that takes at least 3 data chunks, while +# can still be removed to create free space inside one chunk. + +for i in $(seq 0 6); do + run_check $SUDO_HELPER dd if=/dev/zero of=$TEST_MNT/file_${i} bs=1M \ + count=64 > /dev/null 2>&1 +done +sync + +# Remove file 1 3 5 to create holes +for i in $(seq 1 2 6); do + run_check $SUDO_HELPER rm $TEST_MNT/file_${i} +done + +sync + +run_check_umount_test_dev + +# Clear space cache and re-check fs +run_check $TOP/btrfs check --clear-space-cache v1 $TEST_DEV +run_check $TOP/btrfs check $TEST_DEV + +# Manually recheck space cache and super space cache generation +run_check_stdout $TOP/btrfs inspect-internal dump-tree -t root $TEST_DEV \ + > $tmp +grep -q FREE_SPACE $tmp +if [ $? -eq 0 ]; then + rm $tmp + _fail "clear space cache doesn't clear all space cache" +fi + +run_check_stdout $TOP/btrfs inspect-internal dump-super $TEST_DEV |\ + grep cache_generation > $tmp + +grep -q 18446744073709551615 $tmp +if [ $? -ne 0 ]; then + rm $tmp + _fail "clear space cache doesn't set cache_generation correctly" +fi +rm $tmp