From patchwork Thu Jan 7 21:21:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 7984471 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 704A29F54F for ; Fri, 8 Jan 2016 11:04:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6D0722017E for ; Fri, 8 Jan 2016 11:04:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5D70E200D4 for ; Fri, 8 Jan 2016 11:04:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754627AbcAHLEw (ORCPT ); Fri, 8 Jan 2016 06:04:52 -0500 Received: from mail.kernel.org ([198.145.29.136]:33057 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753654AbcAHLEw (ORCPT ); Fri, 8 Jan 2016 06:04:52 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DAFDD2017E; Fri, 8 Jan 2016 11:04:50 +0000 (UTC) Received: from debian3.lan (bl8-199-62.dsl.telepac.pt [85.241.199.62]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4B04A200D4; Fri, 8 Jan 2016 11:04:49 +0000 (UTC) From: fdmanana@kernel.org To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org, Filipe Manana Subject: [PATCH] fstests: btrfs, verify fitrim does not discard reserved device area Date: Thu, 7 Jan 2016 21:21:46 +0000 Message-Id: <1452201706-29080-1-git-send-email-fdmanana@kernel.org> X-Mailer: git-send-email 2.1.3 X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00, DATE_IN_PAST_12_24, 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 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Filipe Manana Verify that when a fitrim operation is made against a btrfs filesystem, the ranges [0, 64Kb[ and [68Kb, 1Mb[ of the device are not discarded, they remain with the content they had before the fitrim operation. These regions of the device are reserved for a boot loader to use at its will. In the 4.3 linux kernel we got a regression that allowed a fitrim operation to discard these reserved ranges of the device, resulting in the filesystem becoming unbootable after a fitrim. The issue is fixed by the following patch (targeted for 4.5 and 4.3/4.4 stable releases): "Btrfs: fix fitrim discarding device area reserved for boot loader's use" Signed-off-by: Filipe Manana --- tests/btrfs/116 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/116.out | 12 +++++++++ tests/btrfs/group | 1 + 3 files changed, 89 insertions(+) create mode 100755 tests/btrfs/116 create mode 100644 tests/btrfs/116.out diff --git a/tests/btrfs/116 b/tests/btrfs/116 new file mode 100755 index 0000000..c51e135 --- /dev/null +++ b/tests/btrfs/116 @@ -0,0 +1,76 @@ +#! /bin/bash +# FSQA Test No. 116 +# +# Verify that when a fitrim operation is made against a btrfs filesystem, the +# ranges [0, 64Kb[ and [68Kb, 1Mb[ of the device are not discarded, they remain +# with the content they had before the fitrim operation. These regions of the +# device are reserved for a boot loader to use at its will. +# +#----------------------------------------------------------------------- +# +# Copyright (C) 2016 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" +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 +_need_to_be_root +_supported_fs btrfs +_supported_os Linux +_require_scratch + +rm -f $seqres.full + +_scratch_mkfs >>$seqres.full 2>&1 + +# Write to the [0, 64Kb[ and [68Kb, 1Mb[ ranges of the device. These ranges are +# reserved for a boot loader to use (GRUB for example) and btrfs should never +# use them - neither for allocating metadata/data nor should trim/discard them. +# The range [64Kb, 68Kb[ is used for the primary superblock of the filesystem. +$XFS_IO_PROG -c "pwrite -S 0xfd 0 64K" $SCRATCH_DEV | _filter_xfs_io +$XFS_IO_PROG -c "pwrite -S 0xfd 68K 956K" $SCRATCH_DEV | _filter_xfs_io + +# Now mount the filesystem and perform a fitrim against it. +_scratch_mount +_require_batched_discard $SCRATCH_MNT +$FSTRIM_PROG $SCRATCH_MNT + +# Now unmount the filesystem and verify the content of the ranges was not +# modified (no trim/discard happened on them). +_scratch_unmount +echo "Content of the ranges [0, 64Kb] and [68Kb, 1Mb[ after fitrim:" +od -t x1 -N $((64 * 1024)) $SCRATCH_DEV +od -t x1 -j $((68 * 1024)) -N $((956 * 1024)) $SCRATCH_DEV + +status=0 +exit diff --git a/tests/btrfs/116.out b/tests/btrfs/116.out new file mode 100644 index 0000000..9cec94d --- /dev/null +++ b/tests/btrfs/116.out @@ -0,0 +1,12 @@ +QA output created by 116 +wrote 65536/65536 bytes at offset 0 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 978944/978944 bytes at offset 69632 +XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Content of the ranges [0, 64Kb] and [68Kb, 1Mb[ after fitrim: +0000000 fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd +* +0200000 +0210000 fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd +* +4000000 diff --git a/tests/btrfs/group b/tests/btrfs/group index 3a99289..de628be 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -116,3 +116,4 @@ 113 auto quick compress clone 114 auto qgroup 115 auto qgroup +116 auto quick metadata