From patchwork Thu Jun 14 06:30:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10463417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 15F7160348 for ; Thu, 14 Jun 2018 06:31:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06F2828A57 for ; Thu, 14 Jun 2018 06:31:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFCB128AD7; Thu, 14 Jun 2018 06:31:00 +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.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 9788728A57 for ; Thu, 14 Jun 2018 06:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752719AbeFNGa6 (ORCPT ); Thu, 14 Jun 2018 02:30:58 -0400 Received: from mx2.suse.de ([195.135.220.15]:39208 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752551AbeFNGa5 (ORCPT ); Thu, 14 Jun 2018 02:30:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F3852ACBF; Thu, 14 Jun 2018 06:30:55 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v3] fstests: btrfs: Test if btrfs will corrupt nodatasum compressed extent when replacing device Date: Thu, 14 Jun 2018 14:30:53 +0800 Message-Id: <20180614063053.8780-1-wqu@suse.com> X-Mailer: git-send-email 2.17.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a long existing bug (from 2012) but exposed by a reporter recently, that when compressed extent without data csum get written to device-replace target device, the written data is in fact uncompressed data other than the original compressed data. And since btrfs still consider the data is compressed and will try to read it as compressed, it can cause read error. The root cause is located, and fix already sent. "btrfs: scrub: Don't use inode pages for device replace". Reported-by: James Harvey Signed-off-by: Qu Wenruo ---- changelog: v2: Now the fix patch is no longer RFC. Remove _require_test as we don't really touch it. Add comment on the mount cycle. Add the test to group 'volume'. v3: Use latest template. Rebased to latest upstream base. Reviewed-by: Nikolay Borisov --- tests/btrfs/165 | 76 +++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/165.out | 2 ++ tests/btrfs/group | 1 + 3 files changed, 79 insertions(+) create mode 100755 tests/btrfs/165 create mode 100644 tests/btrfs/165.out diff --git a/tests/btrfs/165 b/tests/btrfs/165 new file mode 100755 index 000000000000..eb9bb61c9ea3 --- /dev/null +++ b/tests/btrfs/165 @@ -0,0 +1,76 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved. +# +# FS QA Test 165 +# +# Test if btrfs will corrupt compressed data extent without data csum +# by replacing it with uncompressed data, when doing device replace. +# +# This could be fixed by the following patch: +# "btrfs: scrub: Don't use inode pages for device replace" +# +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 + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch_dev_pool 2 +_require_scratch_dev_pool_equal_size + +_scratch_dev_pool_get 1 +_spare_dev_get +_scratch_pool_mkfs >> $seqres.full 2>&1 + +# Create nodatasum inode +_scratch_mount "-o nodatasum" +touch $SCRATCH_MNT/nodatasum_file +_scratch_remount "datasum,compress" +_pwrite_byte 0xcd 0 128K $SCRATCH_MNT/nodatasum_file > /dev/null + +# Write the compressed data back to disk +sync + +# Replace the device +_run_btrfs_util_prog replace start -Bf 1 $SPARE_DEV $SCRATCH_MNT + +# Unmount to drop all cache so next read will read from disk +_scratch_unmount +_mount $SPARE_DEV $SCRATCH_MNT + +# Now the EXTENT_DATA item still marks the extent as compressed, +# but the on-disk data is uncompressed, thus reading it as compressed +# will definitely cause EIO. +cat $SCRATCH_MNT/nodatasum_file > /dev/null + +_scratch_unmount +_spare_dev_put +_scratch_dev_pool_put + +echo "Silence is golden" + +# success, all done +status=0 +exit diff --git a/tests/btrfs/165.out b/tests/btrfs/165.out new file mode 100644 index 000000000000..94ec17dc1075 --- /dev/null +++ b/tests/btrfs/165.out @@ -0,0 +1,2 @@ +QA output created by 165 +Silence is golden diff --git a/tests/btrfs/group b/tests/btrfs/group index 35354de2ea6f..91a1ebadae7c 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -167,3 +167,4 @@ 162 auto quick volume 163 auto quick volume 164 auto quick volume +165 auto quick replace volume