From patchwork Mon Sep 18 07:21:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9955605 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 96A3660385 for ; Mon, 18 Sep 2017 07:22:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8724528A50 for ; Mon, 18 Sep 2017 07:22:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BDD928ACD; Mon, 18 Sep 2017 07:22:19 +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.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM 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 1793628A50 for ; Mon, 18 Sep 2017 07:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752512AbdIRHWQ (ORCPT ); Mon, 18 Sep 2017 03:22:16 -0400 Received: from mout.gmx.net ([212.227.17.22]:57476 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752500AbdIRHWI (ORCPT ); Mon, 18 Sep 2017 03:22:08 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0LcEPJ-1dAZXk3h4P-00jdgx; Mon, 18 Sep 2017 09:22:06 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v3 14/14] btrfs-progs: tests/mkfs: Check error handler for rootdir parameter Date: Mon, 18 Sep 2017 16:21:39 +0900 Message-Id: <20170918072139.6300-15-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> References: <20170918072139.6300-1-quwenruo.btrfs@gmx.com> X-Provags-ID: V03:K0:Qa/UXNUJmXIyeJGXD3IjBODivAsE0g48fl4XwMqGXRCZgS+kyXf 6UGpJism9B+ZGB5vahahn5XLzRr+9DfJ4XbXnZzyMcihRXH4iA6ySusOOlFe1uEicEjhKjJ tzSj9amvoYhPmgWNjWX1Tuu6p26UzLDM/BS7c6UHEw0Ztkl8xwI00bBdG3i2bGdc/OREOAl JMcFaWm3xYTG6lPCnq8WQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Wdtq4kV2L5s=:Dfm3mF6IQc9RBTJoQYcG6Y Y6GTVvk/NJEQlkzZc1mqwSdk38J1lG3EU8FHz9dDKbaTCXHYTzbki4gDARcOMpTY3t75LjUPA NyiiOQwoORN4NCPNF5RrrpSxwE1GIJKdnYGDIvNLkbXb/5wB0Ybvq0n6yShzLCdPPWO4vGaPU 9p9m3JYIgDadMVUjkbQeSsv44mA53WQEtBQmrH9nWLxdOsCet+cASL1iCIhXcneQpVM/eZ9j8 kD0c7CBG0RyyzrEJd/RL5niqpcxPFUu7tMhG9glicvV08jlIqGwdUzjyG5slUjvFe5Ji5Fa4j M+9hheik7lLIDQEt73YJhziw2ffQpofaXHEsK1C5bOZmZQIgjdyhgPcX/LAv5luHVlHzdeET4 wqP3XqXP6C+ikt7mrRTZWo5l5KKeeuNyqDjfL6gWkF528g/9X0ldR3gKBO9iQoJ9gZAZJyk2i +TwYwY3J2jPyp9kELRXJiuzod8ToRidSNN8OSRsyjZ4Trb/UuqbzatmgI4hE9HA2xqyZ2H099 oH9qm4YjrdYEFtcI+uiRcS/OinpmTdSwPwJ5DTn0rmycA2B7/2qSBhekcw9d8+HGZk9kTlsRp 2Hil4kFk8zlWTqhJ8QjGHqdgdW3hni5pSiolzMELjOl9rFTFsx2sWPlmfCa4UnZY3gdqkJ2M6 V3/dWY2LjHkhyTVuvNumppTfuj3yDEjfgGXAPcwdoaD1AYTBmVsEKC9UEiDquec2BmF/9p9Uz YvbuXnX8bwIiuf0lKOte3pKCMaDBobpCfKrvm4mukZQYNdTGN6Jsr3m7OWWeKScbOkaz2mOzD 3YqNX+5RicUH4ILNujmt3p+Mf6pLQ== 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 Error handlers for the following case must fail gracefully: 1) No permission to read content of rootdir 2) Too small destination file 3) Non-existent destination file 4) Zero sized destination file Signed-off-by: Qu Wenruo --- .../mkfs-tests/011-rootdir-fail-condition/test.sh | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 tests/mkfs-tests/011-rootdir-fail-condition/test.sh diff --git a/tests/mkfs-tests/011-rootdir-fail-condition/test.sh b/tests/mkfs-tests/011-rootdir-fail-condition/test.sh new file mode 100755 index 00000000..efdb4e9f --- /dev/null +++ b/tests/mkfs-tests/011-rootdir-fail-condition/test.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# +# Check if "mkfs.btrfs --rootdir" exit gracefully for different error cases + +source "$TOP/tests/common" +source "$TOP/tests/common.convert" + +prepare_test_dev 128M +check_prereq mkfs.btrfs +check_global_prereq fallocate + +no_permission() { + local dir_path + local bad_file + + dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX) + bad_file="$dir_path/no_read_permission" + + echo " [TEST/mkfs_rootdir] error handler for -EPERM" + echo "creating test dir at $src_dir" >> "$RESULTS" + + run_check fallocate -l 4k "$bad_file" + run_check chmod 000 "$bad_file" + + run_mustfail "no permission to read" "$TOP/mkfs.btrfs" \ + --rootdir "$dir_path" "$TEST_DEV" + rm -rf -- "$dir_path" +} + +too_small_dest() { + local dir_path + local bad_file + + dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX) + bad_file="$dir_path/no_space" + + echo " [TEST/mkfs_rootdir] error handler for -ENOSPC" + echo "creating test dir at $src_dir" >> "$RESULTS" + + run_check fallocate -l 256M "$bad_file" + + run_mustfail "too small destination file" "$TOP/mkfs.btrfs" \ + --rootdir "$dir_path" "$TEST_DEV" + rm -rf -- "$dir_path" +} + +non_existent_dest() { + local dir_path + local dest_file + + dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX) + dest_file=$(mktemp --tmpdir btrfs-progs-mkfs-dest-file.XXXX) + run_check rm -- "$dest_file" + + echo " [TEST/mkfs_rootdir] error handler for non-existent destination file" + echo "creating test dir at $src_dir" >> "$RESULTS" + + run_mustfail "non-existent destination file" "$TOP/mkfs.btrfs" \ + --rootdir "$dir_path" "$dest_file" + rm -rf -- "$dir_path" +} + +zero_sized_dest() { + local dir_path + local dest_file + + dir_path=$(mktemp --tmpdir --directory btrfs-progs-mkfs-rootdir.XXXXXX) + dest_file=$(mktemp --tmpdir btrfs-progs-mkfs-dest-file.XXXX) + + echo " [TEST/mkfs_rootdir] error handler for zero-sized destination file" + echo "creating test dir at $src_dir" >> "$RESULTS" + + run_mustfail "zero-sized destination file" "$TOP/mkfs.btrfs" \ + --rootdir "$dir_path" "$dest_file" + rm -rf -- "$dir_path" + rm -- "$dest_file" +} + +no_permission +too_small_dest +non_existent_dest +zero_sized_dest