From patchwork Thu Aug 2 18:03:35 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: 10554031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9D7A15E9 for ; Thu, 2 Aug 2018 18:03:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96DC32C0E3 for ; Thu, 2 Aug 2018 18:03:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A5A22C45F; Thu, 2 Aug 2018 18:03:46 +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=unavailable 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 17F662C3BC for ; Thu, 2 Aug 2018 18:03:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732364AbeHBTz5 (ORCPT ); Thu, 2 Aug 2018 15:55:57 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:54460 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727152AbeHBTz4 (ORCPT ); Thu, 2 Aug 2018 15:55:56 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w72HsbW9079840; Thu, 2 Aug 2018 18:03:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type; s=corp-2018-07-02; bh=m7P1TnQL0Jbw1oziFCZrMc6OkUgpGSMicS7sjqrFMq8=; b=ZpMdDhsIXH7VQ4nSwsE/KWQTrUlaTIYJpD5B1ykg2Ik8ONgfjF8S3lrtg4wwE+wKs+uu I9rrs+LkL4jPPW2PA7kMOYhzp30x807CedjgNFfQbSr8EIZkZkx8b43RDQnesjmsk/Ex G4hvTfYp0NVo9gaNyegJ2Hlj01zyUP6Xa5Y5fz3YHpTotE/xIr2jQdBP/oIyrcI+FhkG yxpzYIRa2vd7vAQHukWgBW9rDXjg1KSaolTgQJLmMjqnCeLJjaP0gv3mJaZElTt56O6Y ACnVjP/dBfjLjhHXSiC+vpxM6v46z40EGBhPzhtNlYjzhf54Y11vcST0YzADX6xC3o2g nQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2km6j3r2kr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Aug 2018 18:03:42 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w72I3g8B017941 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Aug 2018 18:03:42 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w72I3fZR028693; Thu, 2 Aug 2018 18:03:41 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Aug 2018 11:03:41 -0700 Date: Thu, 2 Aug 2018 11:03:35 -0700 From: "Darrick J. Wong" To: Eryu Guan Cc: xfs , fstests Subject: [PATCH] xfs: check for COW overflows in i_delayed_blks Message-ID: <20180802180335.GS30972@magnolia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8973 signatures=668707 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-1807170000 definitions=main-1808020176 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong With the new copy on write functionality it's possible to reserve so much COW space for a file that we end up overflowing i_delayed_blks. The only user-visible effect of this is to cause totally wrong i_blocks output in stat, so check for that. Signed-off-by: Darrick J. Wong --- tests/xfs/907 | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/907.out | 7 +++ tests/xfs/group | 1 3 files changed, 133 insertions(+) create mode 100755 tests/xfs/907 create mode 100644 tests/xfs/907.out -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" 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/xfs/907 b/tests/xfs/907 new file mode 100755 index 00000000..86c3448d --- /dev/null +++ b/tests/xfs/907 @@ -0,0 +1,125 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018 Oracle, Inc. All Rights Reserved. +# +# FS QA Test No. 907 +# +# Try to overflow i_delayed_blks by setting the largest cowextsize hint +# possible, creating a sparse file with a single byte every cowextsize bytes, +# reflinking it, and retouching every written byte to see if we can create +# enough speculative COW reservations to overflow i_delayed_blks. +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 7 15 + +_cleanup() +{ + cd / + umount $loop_mount > /dev/null 2>&1 + rm -rf $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/reflink + +# real QA test starts here +_supported_os Linux +_supported_fs xfs +_require_scratch_reflink +_require_loop +_require_xfs_debug + +echo "Format and mount" +_scratch_mkfs > "$seqres.full" 2>&1 +_scratch_mount +_require_fs_space $SCRATCH_MNT 2400000 # 100T fs requires ~2.4GB of space + +loop_file=$SCRATCH_MNT/a.img +loop_mount=$SCRATCH_MNT/a +truncate -s 100T $loop_file +$MKFS_XFS_PROG $MKFS_OPTIONS -f $loop_file >> $seqres.full +mkdir $loop_mount +mount -o loop -t xfs $loop_file $loop_mount + +echo "Create crazy huge file" +touch "${loop_mount}/a" +blksz="$(stat -f -c '%S' "${loop_mount}")" +MAXEXTLEN=2097151 # cowextsize can't be more than MAXEXTLEN +extsize="$(( ((2 ** 32) - 1) / blksz ))" +test "${extsize}" -gt "${MAXEXTLEN}" && extsize="${MAXEXTLEN}" +extsize_bytes="$(( extsize * blksz ))" + +# Set the largest cowextsize we can +$XFS_IO_PROG -c "cowextsize ${extsize_bytes}" "${loop_mount}/a" +set_cowextsize="$($XFS_IO_PROG -c 'cowextsize' "${loop_mount}/a" | sed -e 's/^.\([0-9]*\).*$/\1/g')" +test "${set_cowextsize}" -eq 0 && _fail "could not set cowextsize?" + +statB="$(stat -c '%B' "${loop_mount}/a")" + +# Write a single byte every cowextsize bytes so that we minimize the space +# required to create maximally sized cow reservations +nr="$(( ((2 ** 32) / extsize) + 100 ))" +seq 0 "${nr}" | tac | while read n; do + off="$((n * extsize * blksz))" + $XFS_IO_PROG -c "pwrite ${off} 1" "${loop_mount}/a" > /dev/null +done + +echo "Reflink crazy huge file" +cp --reflink=always "${loop_mount}/a" "${loop_mount}/b" + +echo "COW crazy huge file" +# Try to create enough maximally sized cow reservations to overflow +# i_delayed_blks +seq 0 "${nr}" | tac | while read n; do + off="$((n * extsize * blksz))" + $XFS_IO_PROG -c "pwrite ${off} 1" "${loop_mount}/a" > /dev/null +done + +echo "Check crazy huge file" +blocks="$(stat -c '%b' "${loop_mount}/a")" +fsblocks="$((blocks * statB / blksz))" + +# Make sure we got enough COW reservations to overflow a 32-bit counter. +$XFS_IO_PROG -c 'bmap -clpv' "${loop_mount}/a" > $tmp.extents +echo "COW EXTENT STATE" >> $seqres.full +cat $tmp.extents >> $seqres.full +cat > $tmp.awk << ENDL +{ + if (\$3 == "delalloc") { + x += \$4; + } else if (\$3 == "hole") { + ; + } else { + x += \$6; + } +} +END { + printf("%d\\n", x / ($blksz / 512)); +} +ENDL +cat $tmp.awk >> $seqres.full +cowblocks="$(awk -f $tmp.awk $tmp.extents)" +echo "cowblocks is ${cowblocks}" >> $seqres.full +if [ "${cowblocks}" -lt "$((2 ** 32))" ]; then + echo "cowblocks (${cowblocks}) should be more than 2^32!" +fi + +# And finally, see if i_delayed_blks overflowed. +echo "stat blocks is ${fsblocks}" >> $seqres.full +if [ "${fsblocks}" -lt "$((2 ** 32))" ]; then + echo "stat blocks (${fsblocks}) should be more than 2^32!" +fi + +echo "Test done" +umount $loop_mount + +# success, all done +status=0 +exit diff --git a/tests/xfs/907.out b/tests/xfs/907.out new file mode 100644 index 00000000..9778d5ed --- /dev/null +++ b/tests/xfs/907.out @@ -0,0 +1,7 @@ +QA output created by 907 +Format and mount +Create crazy huge file +Reflink crazy huge file +COW crazy huge file +Check crazy huge file +Test done diff --git a/tests/xfs/group b/tests/xfs/group index 280b1ba1..1142a45e 100644 --- a/tests/xfs/group +++ b/tests/xfs/group @@ -501,3 +501,4 @@ 723 auto quick fuzz 724 auto quick fuzz 903 mount auto quick stress +907 clone