From patchwork Sun Apr 10 21:06:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 697031 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 p3AL6RwT018769 for ; Sun, 10 Apr 2011 21:06:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758004Ab1DJVGc (ORCPT ); Sun, 10 Apr 2011 17:06:32 -0400 Received: from frost.carfax.org.uk ([212.13.194.111]:2246 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757956Ab1DJVGY (ORCPT ); Sun, 10 Apr 2011 17:06:24 -0400 Received: from ruthven.carfax.org.uk ([10.0.0.10]) by frost.carfax.org.uk with esmtp (Exim 4.69) (envelope-from ) id 1Q91pk-00058C-NT; Sun, 10 Apr 2011 21:06:13 +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 1Q91pk-0003Hx-Eq; Sun, 10 Apr 2011 22:06:12 +0100 From: Hugo Mills To: chris.mason@oracle.com, dave@jikos.cz, lizf@cn.fujitsu.com Cc: linux-btrfs@vger.kernel.org Subject: [PATCH v5 5/8] btrfs: Balance filter for device ID Date: Sun, 10 Apr 2011 22:06:08 +0100 Message-Id: <1302469571-12605-6-git-send-email-hugo@carfax.org.uk> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1302469571-12605-1-git-send-email-hugo@carfax.org.uk> References: <1302469571-12605-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 "admin.kwak.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: Balance filter to take only chunks which have (or had) a stripe on the given device. Useful if a device has been forcibly removed from the filesystem, and the data from that device needs rebuilding. Signed-off-by: Hugo Mills --- fs/btrfs/ioctl.h | 8 ++++++-- fs/btrfs/volumes.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) [...] 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]); Sun, 10 Apr 2011 21:06:50 +0000 (UTC) Balance filter to take only chunks which have (or had) a stripe on the given device. Useful if a device has been forcibly removed from the filesystem, and the data from that device needs rebuilding. Signed-off-by: Hugo Mills --- fs/btrfs/ioctl.h | 8 ++++++-- fs/btrfs/volumes.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index eb91d20..54523c0 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -166,7 +166,8 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_BALANCE_FILTER_COUNT_ONLY (1 << 0) #define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 << 1) -#define BTRFS_BALANCE_FILTER_MASK ((1 << 2) - 1) /* Logical or of all filter +#define BTRFS_BALANCE_FILTER_DEVID (1 << 2) +#define BTRFS_BALANCE_FILTER_MASK ((1 << 3) - 1) /* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */ @@ -183,7 +184,10 @@ struct btrfs_ioctl_balance_start { __u64 chunk_type; /* Flag bits required */ __u64 chunk_type_mask; /* Mask of bits to examine */ - __u64 spare[506]; /* Make up the size of the structure to 4088 + /* For FILTER_DEVID */ + __u64 devid; + + __u64 spare[505]; /* 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 95c603a..e7fa2ab 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -2036,6 +2036,7 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, { struct extent_buffer *eb; struct btrfs_chunk *chunk; + int i; /* No filter defined, everything matches */ if (!filter) @@ -2056,8 +2057,21 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, return 0; } } + if (filter->flags & BTRFS_BALANCE_FILTER_DEVID) { + int num_stripes = btrfs_chunk_num_stripes(eb, chunk); + int res = 0; + for (i = 0; i < num_stripes; i++) { + struct btrfs_stripe *stripe = btrfs_stripe_nr(chunk, i); + if (btrfs_stripe_devid(eb, stripe) == filter->devid) { + res = 1; + break; + } + } + if (!res) + return 0; + } - return ret; + return 1; } /* Define a type, and two functions which can be used for the two