From patchwork Wed Feb 19 16:10:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Austin S. Hemmelgarn" X-Patchwork-Id: 3682331 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B21D99F1EE for ; Wed, 19 Feb 2014 16:10:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D2634200DB for ; Wed, 19 Feb 2014 16:10:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE027200C6 for ; Wed, 19 Feb 2014 16:10:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753933AbaBSQKp (ORCPT ); Wed, 19 Feb 2014 11:10:45 -0500 Received: from mail-ie0-f175.google.com ([209.85.223.175]:56526 "EHLO mail-ie0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753801AbaBSQKo (ORCPT ); Wed, 19 Feb 2014 11:10:44 -0500 Received: by mail-ie0-f175.google.com with SMTP id at1so373691iec.34 for ; Wed, 19 Feb 2014 08:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:openpgp :content-type:content-transfer-encoding; bh=mKRYbtOsnkUL2MbTk/h4jPWUtQnFF5tA8a6ZzXkQ8v4=; b=cRZ4ID/1MZfNmSn2itVzgO2JQIdW9tTUTzehlW+WXddgJbY8czonYrX1xid/8tb9/O KYhtk7Kl7hpy58m+LJ1M7jwSrxJnVLmoeEIEPx/zBvY9eMmIp5TnwtXZitfSAljRTctK CdVUVI98BlOW5rgOxG9yWKJyd8ZVXQc1zJN5SCy6d4kBtHW3zF1gYYw18KWaisPJA605 8iA/wQSZi1idw4b2rrlMWH6lSaxu7L9aLZwcAIq4J82DLKZDI4bia9UnbGu3yKxYerXk NnKteqU8eDUBYYKl+tnLtCSzVmd21MYGpxPqsGdKN1sIMzu3tfUY/OsonwK2tOh81+Yv 73bg== X-Received: by 10.50.66.205 with SMTP id h13mr1977505igt.19.1392826244377; Wed, 19 Feb 2014 08:10:44 -0800 (PST) Received: from [10.0.1.18] (user-0cdvcvs.cable.mindspring.com. [24.223.179.252]) by mx.google.com with ESMTPSA id y9sm28916634igl.7.2014.02.19.08.10.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Feb 2014 08:10:42 -0800 (PST) Message-ID: <5304D781.6020309@gmail.com> Date: Wed, 19 Feb 2014 11:10:41 -0500 From: Austin S Hemmelgarn User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs: Allow forced conversion of metadata to dup profile on multiple devices X-Enigmail-Version: 1.6 OpenPGP: id=85D2EC0F Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Currently, btrfs balance start fails when trying to convert metadata or system chunks to dup profile on filesystems with multiple devices. This requires that a conversion from a multi-device filesystem to a single device filesystem use the following methodology: 1. btrfs balance start -dconvert=single -mconvert=single \ -sconvert=single -f / 2. btrfs device delete / /dev/sdx 3. btrfs balance start -mconvert=dup -sconvert=dup / This results in a period of time (possibly very long if the devices are big) where you don't have the protection guarantees of multiple copies of metadata chunks. After applying this patch, one can instead use the following methodology for conversion from a multi-device filesystem to a single device filesystem: 1. btrfs balance start -dconvert=single -mconvert=dup \ -sconvert=dup -f / 2. btrfs device delete / /dev/sdx This greatly reduces the chances of the operation causing data loss due to a read error during the device delete. Signed-off-by: Austin S. Hemmelgarn Reviewed-by: David Sterba --- fs/btrfs/volumes.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) allowed |= BTRFS_BLOCK_GROUP_RAID5; @@ -3221,6 +3219,21 @@ int btrfs_balance(struct btrfs_balance_control *bctl, goto out; } } + if (((bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) && + (bctl->sys.target & ~BTRFS_BLOCK_GROUP_DUP) || + (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) && + (bctl->meta.target & ~BTRFS_BLOCK_GROUP_DUP)) && + (num_devs > 1)) { + if (bctl->flags & BTRFS_BALANCE_FORCE) { + btrfs_info(fs_info, "force conversion of metadata " + "to dup profile on multiple devices"); + } else { + btrfs_err(fs_info, "balance will reduce metadata " + "integrity, use force if you want this"); + ret = -EINVAL; + goto out; + } + } } while (read_seqretry(&fs_info->profiles_lock, seq)); if (bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) { diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 07629e9..38a9522 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3152,10 +3152,8 @@ int btrfs_balance(struct btrfs_balance_control *bctl, num_devices--; } btrfs_dev_replace_unlock(&fs_info->dev_replace); - allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE; - if (num_devices == 1) - allowed |= BTRFS_BLOCK_GROUP_DUP; - else if (num_devices > 1) + allowed = BTRFS_AVAIL_ALLOC_BIT_SINGLE | BTRFS_BLOCK_GROUP_DUP; + if (num_devices > 1) allowed |= (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1); if (num_devices > 2)