From patchwork Tue May 8 16:54:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10386563 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 36FF16037F for ; Tue, 8 May 2018 16:54:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25B9828EA8 for ; Tue, 8 May 2018 16:54:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A8C428ED0; Tue, 8 May 2018 16:54:13 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY 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 7A70528EA8 for ; Tue, 8 May 2018 16:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933094AbeEHQyM (ORCPT ); Tue, 8 May 2018 12:54:12 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:53936 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932606AbeEHQyL (ORCPT ); Tue, 8 May 2018 12:54:11 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w48GpO8N041628; Tue, 8 May 2018 16:54:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=eq0d/Whb1BOeFXM+eziSs0lBn3R7O0ADYv5QOopaPrE=; b=lu0l25HXLnhQQqtq/YMGosiUiQNM4CFGweLuY/ygogtY4O1E6vYl2XQ0QDS2A6LES0NB h1gakEdiuesOlzlBcSBt0+nUKp5qr/bh3UsaGEEu0dM45K0ufua0dvrnWZiuQ3hoSCDT VFB4P30a4a1dJ7RHrpbTzmGnac57lNgGQRXNAvgfxkUQH1Q/tVr6hKJ3d811f7IMEF/O jdrj9p5QE6U66gafIDcHNbsty1h8j8fh5CnXgkxSYKoO4+iIKkoznkyEl1QsmyR1suI3 cPbwzoAYFIAEcXW1UGMAdY0pS9CNQiLGrIBIeiq5eV/74fnKLY22di3NA9EXI56ykNyL Iw== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2hs5939h8r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 08 May 2018 16:54:09 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w48Gs8Xj016300 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 8 May 2018 16:54:08 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w48Gs78k027328; Tue, 8 May 2018 16:54:07 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 08 May 2018 09:54:07 -0700 Subject: [PATCH 2/2] generic: test swapfile creation, activation, and deactivation From: "Darrick J. Wong" To: guaneryu@gmail.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org Date: Tue, 08 May 2018 09:54:06 -0700 Message-ID: <152579844608.18959.5745995713836937294.stgit@magnolia> In-Reply-To: <152579843989.18959.14108003206856326245.stgit@magnolia> References: <152579843989.18959.14108003206856326245.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8887 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805080162 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Test swapfile activation and deactivation. Signed-off-by: Darrick J. Wong --- tests/generic/708 | 152 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/708.out | 10 +++ tests/generic/group | 1 3 files changed, 163 insertions(+) create mode 100755 tests/generic/708 create mode 100644 tests/generic/708.out -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tests/generic/708 b/tests/generic/708 new file mode 100755 index 00000000..48feeb25 --- /dev/null +++ b/tests/generic/708 @@ -0,0 +1,152 @@ +#! /bin/bash +# FS QA Test No. 708 +# +# Test various swapfile activation oddities. +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +#----------------------------------------------------------------------- + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $testfile +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch_swapfile + +rm -f $seqres.full +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount >>$seqres.full 2>&1 + +swapfile=$SCRATCH_MNT/swap +len=$((2 * 1048576)) + +swapfile_cycle() { + local swapfile="$1" + + mkswap $swapfile >> $seqres.full + filefrag -v $swapfile >> $seqres.full + swapon $swapfile 2>&1 | _filter_scratch + swapon -v --bytes >> $seqres.full + swapoff $swapfile 2>> $seeqres.full + rm -f $swapfile +} + +test_can_falloc_swap() { + local test_swapfile=$TEST_DIR/swapfile + + echo "can we fallocate swap?" + $XFS_IO_PROG -f -c "falloc 0 64k" $test_swapfile + test -f $test_swapfile || return 1 + mkswap $test_swapfile + swapon $test_swapfile + res=$? + swapoff $test_swapfile + rm -f $test_swapfile + return $res +} + +unset can_falloc_swap +test_can_falloc_swap >> $seqres.full 2>&1 && can_falloc_swap=yes +page_size=$(get_page_size) + +# Create a sparse swap file +echo "sparse swap" | tee -a $seqres.full +$XFS_IO_PROG -f -c "truncate $len" $swapfile >> $seqres.full +swapfile_cycle $swapfile + +# Create a regular swap file +echo "regular swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $len $swapfile >> $seqres.full +swapfile_cycle $swapfile + +# Create a fallocated swap file +echo "fallocate swap" | tee -a $seqres.full +if [ "$can_falloc_swap" = "yes" ]; then + $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full + swapfile_cycle $swapfile +fi + +# Create a swap file with a little too much junk on the end +echo "too long swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $((len + 3)) $swapfile >> $seqres.full +swapfile_cycle $swapfile + +# Create a swap file with a large discontiguous range(?) +echo "large discontig swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $((len * 2)) $swapfile >> $seqres.full +old_sz="$(stat -c '%s' $swapfile)" +$XFS_IO_PROG -c "fcollapse $((len / 2)) $len" $swapfile >> $seqres.full 2>&1 +new_sz="$(stat -c '%s' $swapfile)" +if [ $old_sz -gt $new_sz ]; then + swapfile_cycle $swapfile +fi +rm -f $swapfile + +# Create a swap file with a small discontiguous range(?) +echo "small discontig swap" | tee -a $seqres.full +_pwrite_byte 0x58 0 $((len + 1024)) $swapfile >> $seqres.full +old_sz="$(stat -c '%s' $swapfile)" +$XFS_IO_PROG -c "fcollapse 66560 1024" $swapfile >> $seqres.full 2>&1 +new_sz="$(stat -c '%s' $swapfile)" +if [ $old_sz -gt $new_sz ]; then + swapfile_cycle $swapfile +fi +rm -f $swapfile + +# Create a fallocated swap file and touch every other $PAGE_SIZE to create +# a mess of written/unwritten extent records +echo "mixed swap" | tee -a $seqres.full +if [ "$can_falloc_swap" = "yes" ]; then + $XFS_IO_PROG -f -c "falloc 0 $len" $swapfile >> $seqres.full + seq $page_size $((page_size * 2)) $len | while read offset; do + _pwrite_byte 0x58 $offset 1 $swapfile >> $seqres.full + done + swapfile_cycle $swapfile +fi + +# Create a ridiculously small swap file; mkswap says the minimum is 40k. +# However, each swap file must be at least two pages long. +echo "tiny swap" | tee -a $seqres.full +tiny_len=40960 +min_swap_size=$((page_size * 2)) +if [ "$min_swap_size" -gt "$tiny_len" ]; then + tiny_len=$min_swap_size +fi +_pwrite_byte 0x58 0 $tiny_len $swapfile >> $seqres.full +swapfile_cycle $swapfile + +status=0 +exit diff --git a/tests/generic/708.out b/tests/generic/708.out new file mode 100644 index 00000000..d6199b99 --- /dev/null +++ b/tests/generic/708.out @@ -0,0 +1,10 @@ +QA output created by 708 +sparse swap +swapon: SCRATCH_MNT/swap: skipping - it appears to have holes. +regular swap +fallocate swap +too long swap +large discontig swap +small discontig swap +mixed swap +tiny swap diff --git a/tests/generic/group b/tests/generic/group index 505383f7..9f3a933e 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -489,3 +489,4 @@ 484 auto quick 485 auto quick insert 486 auto quick attr +708 auto quick swapfile