From patchwork Thu Sep 26 16:51:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 11163015 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D0FBF13B1 for ; Thu, 26 Sep 2019 16:51:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B9094222C9 for ; Thu, 26 Sep 2019 16:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727573AbfIZQvs (ORCPT ); Thu, 26 Sep 2019 12:51:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41718 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727512AbfIZQvs (ORCPT ); Thu, 26 Sep 2019 12:51:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20E4E10DCC9D for ; Thu, 26 Sep 2019 16:51:48 +0000 (UTC) Received: from localhost (unknown [10.40.205.151]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B203A60923; Thu, 26 Sep 2019 16:51:47 +0000 (UTC) From: Max Reitz To: fstests@vger.kernel.org Cc: Max Reitz Subject: [PATCH v2] generic: fallocate two bytes at block boundary Date: Thu, 26 Sep 2019 18:51:45 +0200 Message-Id: <20190926165145.9161-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Thu, 26 Sep 2019 16:51:48 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org Allocating two bytes at a block boundary with fallocate should allocate both blocks involved. Test this by writing data to both bytes afterwards and see whether the on-disk size increases (it should not). Signed-off-by: Max Reitz --- v2: - Use _get_file_block_size instead of manual stat -fc '%S' - Use xfs_io instead of fallocate/dd (and require falloc support) - Add the ' B' that was missing as allocated_size_after's unit in the error message --- tests/generic/568 | 63 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/568.out | 4 +++ tests/generic/group | 1 + 3 files changed, 68 insertions(+) create mode 100755 tests/generic/568 create mode 100644 tests/generic/568.out diff --git a/tests/generic/568 b/tests/generic/568 new file mode 100755 index 00000000..df67daf4 --- /dev/null +++ b/tests/generic/568 @@ -0,0 +1,63 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2019 Red Hat, Inc. All Rights Reserved. +# +# FS QA Test No. generic/568 +# +# Test that fallocating an unaligned range allocates all blocks +# touched by that range +# +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 15 + +_cleanup() +{ + cd / + rm -f "$tmp".* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_scratch +_require_xfs_io_command "falloc" + +testfile="$SCRATCH_MNT/testfile" + +_scratch_mkfs > /dev/null 2>&1 +_scratch_mount + +# Fallocate 2 bytes across a block boundary +block_size=$(_get_file_block_size "$SCRATCH_MNT") +$XFS_IO_PROG -f -c "falloc $((block_size - 1)) 2" "$testfile" + +# Both the first blocks should be allocated now. Check that by +# inquiring whether the file grows when we write to the two bytes we +# have just fallocated. + +allocated_size_before=$(($(stat -c '%b * %B' "$testfile"))) + +$XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \ + | _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/" + +allocated_size_after=$(($(stat -c '%b * %B' "$testfile"))) + +if [ $allocated_size_after -gt $allocated_size_before ]; then + echo "ERROR: File grew from ${allocated_size_before} B to" \ + "${allocated_size_after} B when writing to the fallocated range." +else + echo "OK: File did not grow." +fi + +status=0 +exit diff --git a/tests/generic/568.out b/tests/generic/568.out new file mode 100644 index 00000000..435a9630 --- /dev/null +++ b/tests/generic/568.out @@ -0,0 +1,4 @@ +QA output created by 568 +wrote 2/2 bytes at offset block_size - 1 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +OK: File did not grow. diff --git a/tests/generic/group b/tests/generic/group index 7cf4f6c4..24ab29bc 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -570,3 +570,4 @@ 565 auto quick copy_range 566 auto quick quota metadata 567 auto quick rw punch +568 auto quick rw