From patchwork Tue Jan 6 20:21:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 5576901 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 D3EC59F507 for ; Tue, 6 Jan 2015 20:21:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E4EEC20221 for ; Tue, 6 Jan 2015 20:21:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BD2CB20263 for ; Tue, 6 Jan 2015 20:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756552AbbAFUVg (ORCPT ); Tue, 6 Jan 2015 15:21:36 -0500 Received: from victor.provo.novell.com ([137.65.250.26]:37905 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756548AbbAFUVe (ORCPT ); Tue, 6 Jan 2015 15:21:34 -0500 Received: from debian3.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Tue, 06 Jan 2015 13:21:30 -0700 From: Filipe Manana To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH] fstests: add generic test for fsync after unlink Date: Tue, 6 Jan 2015 20:21:20 +0000 Message-Id: <1420575680-9809-1-git-send-email-fdmanana@suse.com> X-Mailer: git-send-email 2.1.3 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 This test is motivated by an fsync issue discovered in btrfs. The issue was that after fsyncing an inode that got its link count decremented, and the new link count is greater than zero, after the fsync log replay the inode's parent directory metadata became inconsistent - it had a wrong i_size which prevented the directory from ever being removed (rmdir always failed with -ENOTEMPTY, even if the directory had no more child inodes). The btrfs issue was fixed by the following linux kernel patch: Btrfs: fix directory inconsistency after fsync log replay Signed-off-by: Filipe Manana --- tests/generic/039 | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/039.out | 2 + tests/generic/group | 1 + 3 files changed, 105 insertions(+) create mode 100755 tests/generic/039 create mode 100644 tests/generic/039.out diff --git a/tests/generic/039 b/tests/generic/039 new file mode 100755 index 0000000..85646f9 --- /dev/null +++ b/tests/generic/039 @@ -0,0 +1,102 @@ +#! /bin/bash +# FS QA Test No. 039 +# +# This test is motivated by an fsync issue discovered in btrfs. +# The issue was that after fsyncing an inode that got its link count +# decremented, and the new link count is greater than zero, after the +# fsync log replay the inode's parent directory metadata became +# inconsistent - it had a wrong i_size which prevented the directory +# from ever being removed (rmdir always failed with -ENOTEMPTY, even +# if the directory had no more child inodes). +# +# The btrfs issue was fixed by the following linux kernel patch: +# +# Btrfs: fix directory inconsistency after fsync log replay +# +#----------------------------------------------------------------------- +# Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved. +# Author: Filipe Manana +# +# 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` +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_flakey +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/dmflakey + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_need_to_be_root +_require_scratch +_require_dm_flakey + +rm -f $seqres.full + +_scratch_mkfs >> $seqres.full 2>&1 + +_init_flakey +_mount_flakey + +# Create a test file with 2 hard links. +mkdir -p $SCRATCH_MNT/a/b +echo "hello world" > $SCRATCH_MNT/a/b/foo +ln $SCRATCH_MNT/a/b/foo $SCRATCH_MNT/a/b/bar + +# Make sure all metadata and data are durably persisted. +sync + +# Now remove one of the hard links and fsync the inode. +rm -f $SCRATCH_MNT/a/b/bar +$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/b/foo + +# Simulate a crash/power loss. This makes sure the next mount +# will see an fsync log and will replay that log. + +_load_flakey_table $FLAKEY_DROP_WRITES +_unmount_flakey + +_load_flakey_table $FLAKEY_ALLOW_WRITES +_mount_flakey + +# Remove the last hard link of the file and attempt to remove its parent +# directory - this failed in btrfs because the fsync log and replay code +# didn't decrement the parent directory's i_size - this made the btrfs +# rmdir implementation always fail with -ENOTEMPTY. +# +# The parent directory's metadata inconsistency was also detected by btrfs' +# fsck tool, which is run automatically by the fstests framework when the +# test finishes. +rm -f $SCRATCH_MNT/a/b/foo +rmdir $SCRATCH_MNT/a/b +rmdir $SCRATCH_MNT/a + +echo "Silence is golden" +status=0 +exit diff --git a/tests/generic/039.out b/tests/generic/039.out new file mode 100644 index 0000000..d4e7ef6 --- /dev/null +++ b/tests/generic/039.out @@ -0,0 +1,2 @@ +QA output created by 039 +Silence is golden diff --git a/tests/generic/group b/tests/generic/group index 1e89848..6af5a1a 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -41,6 +41,7 @@ 036 auto aio rw stress 037 metadata auto quick 038 auto stress +039 metadata auto quick 053 acl repair auto quick 062 attr udf auto quick 068 other auto freeze dangerous stress