From patchwork Tue Mar 7 22:34:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Borowski X-Patchwork-Id: 9609969 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 319B36016C for ; Tue, 7 Mar 2017 23:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B8A026E82 for ; Tue, 7 Mar 2017 23:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FB4F27CEA; Tue, 7 Mar 2017 23:24:23 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham 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 079CF26E82 for ; Tue, 7 Mar 2017 23:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756453AbdCGXYK (ORCPT ); Tue, 7 Mar 2017 18:24:10 -0500 Received: from tartarus.angband.pl ([89.206.35.136]:44974 "EHLO tartarus.angband.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751334AbdCGXYJ (ORCPT ); Tue, 7 Mar 2017 18:24:09 -0500 Received: from umbar.angband.pl ([2001:6a0:118::6]) by tartarus.angband.pl with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.88) (envelope-from ) id 1clNgz-0005kU-NH; Tue, 07 Mar 2017 23:34:56 +0100 Received: from kilobyte by umbar.angband.pl with local (Exim 4.89_RC7) (envelope-from ) id 1clNgz-0001yc-9M; Tue, 07 Mar 2017 23:34:53 +0100 From: Adam Borowski To: Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, Liu Bo Cc: Adam Borowski Date: Tue, 7 Mar 2017 23:34:44 +0100 Message-Id: <20170307223444.7526-1-kilobyte@angband.pl> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170307203406.GC12408@lim.localdomain> References: <20170307203406.GC12408@lim.localdomain> X-SA-Exim-Connect-IP: 2001:6a0:118::6 X-SA-Exim-Mail-From: kilobyte@angband.pl Subject: [PATCH v2] btrfs: fix a bogus warning when converting only data or metadata X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on tartarus.angband.pl) 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 If your filesystem has, eg, data:raid0 metadata:raid1, and you run "btrfs balance -dconvert=raid1", the meta.target field will be uninitialized. That's otherwise ok, as it's unused except for this warning. Thus, let's use the existing set of raid levels for the comparison. As a side effect, non-convert balances will now nag about data>metadata. Signed-off-by: Adam Borowski Reviewed-by: Liu Bo --- To reproduce: dd if=/dev/zero bs=1048576 count=1 seek=4095 of=ra dd if=/dev/zero bs=1048576 count=1 seek=4095 of=rb mkfs.btrfs ra rb # defaults to -draid0 -mraid1 losetup -f ra losetup -f rb mount /dev/loop0 /mnt/vol1 btrfs balance start -dconvert=raid1 /mnt/vol1 On Tue, Mar 07, 2017 at 12:34:07PM -0800, Liu Bo wrote: > This looks good, but this also brings another side effect, @bctl would > also be kept in balance_item which will be used to resume balance in > case of crash, so it may see a different bctl->meta.target. > > So would you please use local varibles for meta.target and data.target? Okay. I'm not sure why storing a bogus value that came from userspace and was uninitialized there (0 in normal use) would be better, but here we go: v2 doesn't overwrite what we got anymore. Unrelated: I wonder if the profiles in the warning message shouldn't be printk'ed as words (akin to ebce0e01), but we don't have a function to do that, have we? Meow! fs/btrfs/volumes.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3645af2749f8..987f395ddec5 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3750,6 +3750,7 @@ int btrfs_balance(struct btrfs_balance_control *bctl, struct btrfs_ioctl_balance_args *bargs) { struct btrfs_fs_info *fs_info = bctl->fs_info; + __u64 meta_target, data_target; u64 allowed; int mixed = 0; int ret; @@ -3846,11 +3847,16 @@ int btrfs_balance(struct btrfs_balance_control *bctl, } } while (read_seqretry(&fs_info->profiles_lock, seq)); - if (btrfs_get_num_tolerated_disk_barrier_failures(bctl->meta.target) < - btrfs_get_num_tolerated_disk_barrier_failures(bctl->data.target)) { + /* if we're not converting, the target field is uninitialized */ + meta_target = (bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) ? + bctl->meta.target : fs_info->avail_metadata_alloc_bits; + data_target = (bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) ? + bctl->data.target : fs_info->avail_data_alloc_bits; + if (btrfs_get_num_tolerated_disk_barrier_failures(meta_target) < + btrfs_get_num_tolerated_disk_barrier_failures(data_target)) { btrfs_warn(fs_info, "metadata profile 0x%llx has lower redundancy than data profile 0x%llx", - bctl->meta.target, bctl->data.target); + meta_target, data_target); } ret = insert_balance_item(fs_info, bctl);