From patchwork Tue Oct 13 15:42:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 7386331 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 6FC579F1B9 for ; Tue, 13 Oct 2015 15:43:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8BF0220822 for ; Tue, 13 Oct 2015 15:43:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A0E52073B for ; Tue, 13 Oct 2015 15:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932684AbbJMPnw (ORCPT ); Tue, 13 Oct 2015 11:43:52 -0400 Received: from mx2.suse.de ([195.135.220.15]:38583 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932677AbbJMPnv (ORCPT ); Tue, 13 Oct 2015 11:43:51 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E665CABCC; Tue, 13 Oct 2015 15:43:48 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id B77C5DAB57; Tue, 13 Oct 2015 17:42:40 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: =?UTF-8?q?Gabr=C3=ADel=20Arth=C3=BAr=20P=C3=A9tursson?= , David Sterba Subject: [PATCH 7/7] btrfs-progs: balance: add stripes filter Date: Tue, 13 Oct 2015 17:42:40 +0200 Message-Id: <0d304408d62f90be68b319ee1d3799f8c283503b.1444750808.git.dsterba@suse.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: References: MIME-Version: 1.0 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 From: Gabríel Arthúr Pétursson Add new balance filter 'stripes=' to process only chunks that are spread accross given number of chunks. The range must be specified with both values, but they can be the same to denote exact number of stripes. Signed-off-by: Gabríel Arthúr Pétursson [ reworked a bit to use the range helpers, dropped the single value for stripes ] Signed-off-by: David Sterba --- Documentation/btrfs-balance.asciidoc | 4 ++++ cmds-balance.c | 17 +++++++++++++++++ ioctl.h | 4 +++- volumes.h | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/btrfs-balance.asciidoc b/Documentation/btrfs-balance.asciidoc index 61517461ca90..6bb9fffdf188 100644 --- a/Documentation/btrfs-balance.asciidoc +++ b/Documentation/btrfs-balance.asciidoc @@ -114,6 +114,10 @@ The argument may be a single value or a range. The single value *N* means *at most N chunks*, equivalent to *..N* range syntax. Kernels prior to 4.4 accept only the single value format. +*stripes*:: +Balances only block groups which have the given number of stripes. The +parameter is a range specified as . + *soft*:: Takes no parameters. Only has meaning when converting between profiles. When doing convert from one profile to another and soft mode is on, diff --git a/cmds-balance.c b/cmds-balance.c index 7aaf33d03630..a958e584eeb5 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -319,6 +319,19 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args) args->flags &= ~BTRFS_BALANCE_ARGS_LIMITS; args->flags |= BTRFS_BALANCE_ARGS_LIMIT; } + args->flags |= BTRFS_BALANCE_ARGS_LIMIT; + } else if (!strcmp(this_char, "stripes")) { + if (!value || !*value) { + fprintf(stderr, + "the stripes filter requires an argument\n"); + return 1; + } + if (parse_range_u32(value, &args->stripes_min, + &args->stripes_max)) { + fprintf(stderr, "Invalid stripes argument\n"); + return 1; + } + args->flags |= BTRFS_BALANCE_ARGS_STRIPES; } else { fprintf(stderr, "Unrecognized balance option '%s'\n", this_char); @@ -359,6 +372,10 @@ static void dump_balance_args(struct btrfs_balance_args *args) printf(", limit="); print_range_u32(args->limit_min, args->limit_max); } + if (args->flags & BTRFS_BALANCE_ARGS_STRIPES) { + printf(", stripes="); + print_range_u32(args->stripes_min, args->stripes_max); + } printf("\n"); } diff --git a/ioctl.h b/ioctl.h index ff7a1a0610a1..50f9e1485a30 100644 --- a/ioctl.h +++ b/ioctl.h @@ -239,7 +239,9 @@ struct btrfs_balance_args { __u32 limit_max; }; }; - __u64 unused[7]; + __u32 stripes_min; + __u32 stripes_max; + __u64 unused[6]; } __attribute__ ((__packed__)); /* report balance progress to userspace */ diff --git a/volumes.h b/volumes.h index cb6f5752cdda..150ea7f31659 100644 --- a/volumes.h +++ b/volumes.h @@ -137,6 +137,7 @@ struct map_lookup { #define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4) #define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5) #define BTRFS_BALANCE_ARGS_LIMITS (1ULL << 6) +#define BTRFS_BALANCE_ARGS_STRIPES (1ULL << 7) /* * Profile changing flags. When SOFT is set we won't relocate chunk if