From patchwork Tue Oct 13 15:42:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 7386321 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EED619F1B9 for ; Tue, 13 Oct 2015 15:43:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3EB3D20823 for ; Tue, 13 Oct 2015 15:43:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FEFC20827 for ; Tue, 13 Oct 2015 15:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932680AbbJMPnt (ORCPT ); Tue, 13 Oct 2015 11:43:49 -0400 Received: from mx2.suse.de ([195.135.220.15]:38575 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932677AbbJMPnr (ORCPT ); Tue, 13 Oct 2015 11:43:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 51D25ACA0 for ; Tue, 13 Oct 2015 15:43:45 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 5C53DDAB57; Tue, 13 Oct 2015 17:42:37 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 6/7] btrfs-progs: balance: enhance the limit fiter with range Date: Tue, 13 Oct 2015 17:42:37 +0200 Message-Id: <97da57b00a505d6501e2325fa3ab2802c7a461f4.1444750808.git.dsterba@suse.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: References: 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 We can do more with the balance filer. Enhance it so we can specify also the minimum number of block groups to process. The 'limit' filter now accepts a range (a..b, can be partial) and needs kernel support. The 'limit=value' filter is equivalent to 'limit=..value' but works on older kernels as well. The min/max values are 32bit, unlike the single-value limit which is 64bit. Signed-off-by: David Sterba --- cmds-balance.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cmds-balance.c b/cmds-balance.c index 1eadba417abc..7aaf33d03630 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -301,12 +301,24 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args) "the limit filter requires an argument\n"); return 1; } - if (parse_u64(value, &args->limit)) { - fprintf(stderr, "Invalid limit argument: %s\n", - value); - return 1; + /* + * Try to parse the range first. A single value is not + * a valid range + */ + if (parse_range_u32(value, &args->limit_min, + &args->limit_max) == 0) { + args->flags &= ~BTRFS_BALANCE_ARGS_LIMIT; + args->flags |= BTRFS_BALANCE_ARGS_LIMITS; + } else { + if (parse_u64(value, &args->limit)) { + fprintf(stderr, + "Invalid limit argument: %s\n", + value); + return 1; + } + args->flags &= ~BTRFS_BALANCE_ARGS_LIMITS; + args->flags |= BTRFS_BALANCE_ARGS_LIMIT; } - args->flags |= BTRFS_BALANCE_ARGS_LIMIT; } else { fprintf(stderr, "Unrecognized balance option '%s'\n", this_char);