From patchwork Thu Apr 7 17:06:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 693051 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p37H6Kju027176 for ; Thu, 7 Apr 2011 17:06:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756322Ab1DGRGV (ORCPT ); Thu, 7 Apr 2011 13:06:21 -0400 Received: from frost.carfax.org.uk ([212.13.194.111]:2828 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756310Ab1DGRGS (ORCPT ); Thu, 7 Apr 2011 13:06:18 -0400 Received: from ruthven.carfax.org.uk ([10.0.0.10]) by frost.carfax.org.uk with esmtp (Exim 4.69) (envelope-from ) id 1Q7sev-00087R-H1; Thu, 07 Apr 2011 17:06:17 +0000 Received: from [10.0.0.10] (helo=ruthven.carfax.org.uk) by ruthven.carfax.org.uk with esmtp (Exim 4.72) (envelope-from ) id 1Q7sev-0000oT-6I; Thu, 07 Apr 2011 18:06:17 +0100 From: Hugo Mills To: linux-btrfs@vger.kernel.org, chris.mason@oracle.com Subject: [PATCH v4 8/8] btrfs: Balance filter for physical device address Date: Thu, 7 Apr 2011 18:06:15 +0100 Message-Id: <1302195975-3088-9-git-send-email-hugo@carfax.org.uk> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1302195975-3088-1-git-send-email-hugo@carfax.org.uk> References: <1302195975-3088-1-git-send-email-hugo@carfax.org.uk> X-frost.carfax.org.uk-Spam-Score: -0.0 (/) X-frost.carfax.org.uk-Spam-Report: Spam detection software, running on the system "spamd2.lon.bitfolk.com", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add a filter for balancing which allows the selection of chunks with data in the given byte range on any block device in the filesystem. On its own, this filter is of little use, but when used with the devid filter, it can be used to rebalance all chunks which lie on a part of a specific device. [...] Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 07 Apr 2011 17:06:40 +0000 (UTC) Add a filter for balancing which allows the selection of chunks with data in the given byte range on any block device in the filesystem. On its own, this filter is of little use, but when used with the devid filter, it can be used to rebalance all chunks which lie on a part of a specific device. Signed-off-by: Hugo Mills --- fs/btrfs/ioctl.h | 9 +++++++-- fs/btrfs/volumes.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 5177229..b13f14d 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -168,7 +168,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2 #define BTRFS_BALANCE_FILTER_DEVID 0x4 #define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE 0x8 -#define BTRFS_BALANCE_FILTER_MASK 0xf /* Logical or of all filter +#define BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE 0x10 +#define BTRFS_BALANCE_FILTER_MASK 0x1f /* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */ @@ -192,7 +193,11 @@ struct btrfs_ioctl_balance_start { __u64 vrange_start; __u64 vrange_end; - __u64 spare[503]; /* Make up the size of the structure to 4088 + /* For FILTER_DEVICE_ADDRESS_RANGE */ + __u64 drange_start; + __u64 drange_end; + + __u64 spare[501]; /* Make up the size of the structure to 4088 * bytes for future expansion */ }; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 83f13b6..f97f19f 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2123,6 +2123,25 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, if (filter->vrange_start >= end || start >= filter->vrange_end) return 0; } + if (filter->flags & BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE) { + int num_stripes = btrfs_chunk_num_stripes(eb, chunk); + int stripe_length = btrfs_chunk_length(eb, chunk) + * num_stripes / replinfo.num_copies; + int res = 0; + + for (i = 0; i < num_stripes; i++) { + struct btrfs_stripe *stripe = btrfs_stripe_nr(chunk, i); + u64 start = btrfs_stripe_offset(eb, stripe); + u64 end = start + stripe_length; + if (filter->drange_start < end + && start < filter->drange_end) { + res = 1; + break; + } + } + if (!res) + return 0; + } return 1; }