From patchwork Tue Sep 22 20:02:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Moise <00moses.alexander00@gmail.com> X-Patchwork-Id: 7241511 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 70BFCBEEC1 for ; Tue, 22 Sep 2015 17:04:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9C207208FF for ; Tue, 22 Sep 2015 17:04:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1D8E2082B for ; Tue, 22 Sep 2015 17:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758129AbbIVRCu (ORCPT ); Tue, 22 Sep 2015 13:02:50 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:32994 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752862AbbIVRCs (ORCPT ); Tue, 22 Sep 2015 13:02:48 -0400 Received: by wiclk2 with SMTP id lk2so203114381wic.0; Tue, 22 Sep 2015 10:02:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=0WO7n5QsKt+hK2Zhd6J+oTZFLdvQum4rIaJyxsHmSSQ=; b=jfKAwS8FIhGA6NH9XCnA/NL9hwmw4KW9ThnDT2ZB9GmYVzO8V2GmCPZDepOHKG5vPx QGUhdgySAlYGzN3FWHOMniP7d0ho3cFVJQUlCYTR0n7RE9Dsc0QyWQfAJRwisAT8XnqE eXSgq2ztXTR35Fao+KZlgmg+lg8pPp9H1kUHpkqe7QjOAoIQU5vHGflmMQdF2u6JoVwh yQkpMfUT/EC2lFw9HCJjDVGCYu4gjKkAUUY5OIgxjJtHbtKZKXQ7yw097gnfSf6Xb3TU MDck+G2oFzO3bcFUvTS4K3mC8j7mSsFYrnw/5PJ1EmCSg6Wmpl5UrvQ9sCFMnIGXBo3N C3/Q== X-Received: by 10.180.39.193 with SMTP id r1mr4105364wik.57.1442941367246; Tue, 22 Sep 2015 10:02:47 -0700 (PDT) Received: from gmail.com ([188.24.228.168]) by smtp.gmail.com with ESMTPSA id go2sm4091914wib.20.2015.09.22.10.02.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Sep 2015 10:02:46 -0700 (PDT) Date: Tue, 22 Sep 2015 20:02:25 +0000 From: Alexandru Moise <00moses.alexander00@gmail.com> To: clm@fb.com, jbacik@fb.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, 00moses.alexander00@gmail.com Subject: [PATCH v2] btrfs: cleanup btrfs_balance profile validity checks Message-ID: <20150922200225.GA4138@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 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=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 Improve readability by generalizing the profile validity checks. Signed-off-by: Alexandru Moise <00moses.alexander00@gmail.com> Reviewed-by: David Sterba --- v2: Followed Dave's suggestion and renamed function to validate_convert_profile instead of balance_relocate_invalid fs/btrfs/volumes.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 6fc73586..d2b8f08 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3466,6 +3466,15 @@ static void __cancel_balance(struct btrfs_fs_info *fs_info) atomic_set(&fs_info->mutually_exclusive_operation_running, 0); } +/* Non-zero return value signifies invalidity */ +static inline int validate_convert_profile(struct btrfs_balance_args *bctl_arg, + u64 allowed) +{ + return ((bctl_arg->flags & BTRFS_BALANCE_ARGS_CONVERT) && + (!alloc_profile_is_valid(bctl_arg->target, 1) || + (bctl_arg->target & ~allowed))); +} + /* * Should be called with both balance and volume mutexes held */ @@ -3523,27 +3532,21 @@ int btrfs_balance(struct btrfs_balance_control *bctl, if (num_devices > 3) allowed |= (BTRFS_BLOCK_GROUP_RAID10 | BTRFS_BLOCK_GROUP_RAID6); - if ((bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) && - (!alloc_profile_is_valid(bctl->data.target, 1) || - (bctl->data.target & ~allowed))) { + if (validate_convert_profile(&bctl->data, allowed)) { btrfs_err(fs_info, "unable to start balance with target " "data profile %llu", bctl->data.target); ret = -EINVAL; goto out; } - if ((bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) && - (!alloc_profile_is_valid(bctl->meta.target, 1) || - (bctl->meta.target & ~allowed))) { + if (validate_convert_profile(&bctl->meta, allowed)) { btrfs_err(fs_info, "unable to start balance with target metadata profile %llu", bctl->meta.target); ret = -EINVAL; goto out; } - if ((bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) && - (!alloc_profile_is_valid(bctl->sys.target, 1) || - (bctl->sys.target & ~allowed))) { + if (validate_convert_profile(&bctl->sys, allowed)) { btrfs_err(fs_info, "unable to start balance with target system profile %llu", bctl->sys.target);