From patchwork Sat Jul 4 16:08:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 6717641 Return-Path: X-Original-To: patchwork-fstests@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DA8E59F319 for ; Sun, 5 Jul 2015 08:41:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E355D205C7 for ; Sun, 5 Jul 2015 08:41:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE8D5205AA for ; Sun, 5 Jul 2015 08:41:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750971AbbGEIly (ORCPT ); Sun, 5 Jul 2015 04:41:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57133 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751074AbbGEIlx (ORCPT ); Sun, 5 Jul 2015 04:41:53 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 7A691A2C36; Sat, 4 Jul 2015 16:12:16 +0000 (UTC) Received: from localhost (vpn1-7-157.pek2.redhat.com [10.72.7.157]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t64GCFuf014082; Sat, 4 Jul 2015 12:12:15 -0400 From: Eryu Guan To: fstests@vger.kernel.org Cc: linux-ext4@vger.kernel.org, Eryu Guan Subject: [PATCH] ext4: test migration to non-extent based file format Date: Sun, 5 Jul 2015 00:08:58 +0800 Message-Id: <1436026138-4278-1-git-send-email-eguan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On unpatched kernel, converting file with a hole at the beginning to non-extent based format results in ext4 i_blocks corruption. Add a new regression test case for it. These two commits fixed the corruption: ext4: be more strict when migrating to non-extent based file ext4: correctly migrate a file with a hole at the beginning Signed-off-by: Eryu Guan --- Note that this patch applies cleanly only after my patch: generic/081: wait for lv to be settled before creating fs on it common/config | 1 + tests/ext4/005 | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ext4/group | 1 + 3 files changed, 85 insertions(+) create mode 100755 tests/ext4/005 diff --git a/common/config b/common/config index 73da60a..dca7aad 100644 --- a/common/config +++ b/common/config @@ -191,6 +191,7 @@ export WIPEFS_PROG="`set_prog_path wipefs`" export DUMP_PROG="`set_prog_path dump`" export RESTORE_PROG="`set_prog_path restore`" export LVM_PROG="`set_prog_path lvm`" +export CHATTR_PROG="`set_prog_path chattr`" # use 'udevadm settle' or 'udevsettle' to wait for lv to be settled. # newer systems have udevadm command but older systems like RHEL5 don't. diff --git a/tests/ext4/005 b/tests/ext4/005 new file mode 100755 index 0000000..1028bf3 --- /dev/null +++ b/tests/ext4/005 @@ -0,0 +1,83 @@ +#! /bin/bash +# FS QA Test 005 +# +# Test corruption issue in converting file with a hole at the beginning to +# non-extent based format +# +# These two commits fixed the corruption: +# ext4: be more strict when migrating to non-extent based file +# ext4: correctly migrate a file with a hole at the beginning +# +#----------------------------------------------------------------------- +# Copyright (c) 2015 Red Hat Inc. 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" + +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 ext4 +_supported_os Linux +_require_scratch +_require_command "$CHATTR_PROG" chattr + +rm -f $seqres.full + +echo "Silence is golden" + +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount + +testfile=$SCRATCH_MNT/$seq.attrtest +touch $testfile +$CHATTR_PROG -e $testfile >>$seqres.full 2>&1 +if [ $? -ne 0 ]; then + _notrun "Clearing extent flag not supported, old chattr and/or kernel?" +fi + +rm -f $testfile +# skip the first 4k and write to the second 4k, leave the first 4k as a hole +$XFS_IO_PROG -fc "pwrite 4k 4k" -c "fsync" $testfile >>$seqres.full 2>&1 + +# convert to non-extent based file format, buggy ext4 moves the data blocks to +# the beginning of the file, but extent status cache still marks that region as +# a hole +$CHATTR_PROG -e $testfile >>$seqres.full 2>&1 + +# delayed allocation writes to the "hole", reclaim the same data block again, +# results in i_blocks corruption +$XFS_IO_PROG -c "pwrite 0 4k" $testfile >>$seqres.full 2>&1 + +# success, all done +status=0 +exit diff --git a/tests/ext4/group b/tests/ext4/group index e7f1f2a..96218b7 100644 --- a/tests/ext4/group +++ b/tests/ext4/group @@ -7,6 +7,7 @@ 002 auto quick prealloc 003 auto quick 004 auto dump +005 auto quick metadata ioctl rw 271 auto rw quick 301 aio dangerous ioctl rw stress 302 aio dangerous ioctl rw stress