From patchwork Tue Aug 23 20:01:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 1089602 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7NK2CTQ028723 for ; Tue, 23 Aug 2011 20:02:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756029Ab1HWUCJ (ORCPT ); Tue, 23 Aug 2011 16:02:09 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:56659 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755878Ab1HWUCH (ORCPT ); Tue, 23 Aug 2011 16:02:07 -0400 Received: by mail-bw0-f46.google.com with SMTP id 11so372435bke.19 for ; Tue, 23 Aug 2011 13:02:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=80kKQq5KRZ03XeXUCbxrMpd+b95NJgDPnCEi4mUD6Sk=; b=c59e+TmT3WELmBTeGKLqiKim+kbzVEUqMUAebsR/x2aAHgH/spZ5t7WvUZ4d5rDsV7 990Hxt6g41tlVntP+Rq9P+SOWGM64Z9hwkpafK8gXcvsWqPF4hOSos9wPuUtcimqJNlH 7I5s9wvXQ40j65tqlVwJsi+ZMkkLatizYO12k= Received: by 10.204.148.67 with SMTP id o3mr1720573bkv.258.1314129727091; Tue, 23 Aug 2011 13:02:07 -0700 (PDT) Received: from localhost ([31.28.235.172]) by mx.google.com with ESMTPS id l12sm82631bkk.30.2011.08.23.13.02.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Aug 2011 13:02:06 -0700 (PDT) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , Hugo Mills , idryomov@gmail.com Subject: [PATCH 04/21] Btrfs: make avail_*_alloc_bits fields dynamic Date: Tue, 23 Aug 2011 23:01:45 +0300 Message-Id: <1314129722-31601-5-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1314129722-31601-1-git-send-email-idryomov@gmail.com> References: <1314129722-31601-1-git-send-email-idryomov@gmail.com> 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 (demeter2.kernel.org [140.211.167.43]); Tue, 23 Aug 2011 20:02:12 +0000 (UTC) Currently when new chunks are created respective avail_alloc_bits field is updated to reflect profiles of all chunks present in the system. However when chunks are removed, corresponding profile bits are never cleared. This patch clears corresponding bit of avail_alloc_bits field when the last chunk of that type goes away. Restriper needs this to properly operate when "downgrading". Signed-off-by: Ilya Dryomov --- fs/btrfs/extent-tree.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index ed35eb5..a04f99b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -7197,6 +7197,22 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans, return 0; } +static void clear_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags) +{ + u64 extra_flags = flags & BTRFS_BLOCK_GROUP_PROFILE_MASK; + + /* on-disk -> in-memory */ + if (extra_flags == 0) + extra_flags = BTRFS_AVAIL_ALLOC_BIT_SINGLE; + + if (flags & BTRFS_BLOCK_GROUP_DATA) + fs_info->avail_data_alloc_bits &= ~extra_flags; + if (flags & BTRFS_BLOCK_GROUP_METADATA) + fs_info->avail_metadata_alloc_bits &= ~extra_flags; + if (flags & BTRFS_BLOCK_GROUP_SYSTEM) + fs_info->avail_system_alloc_bits &= ~extra_flags; +} + int btrfs_remove_block_group(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 group_start) { @@ -7207,6 +7223,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, struct btrfs_key key; struct inode *inode; int ret; + int index; int factor; root = root->fs_info->extent_root; @@ -7222,6 +7239,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, free_excluded_extents(root, block_group); memcpy(&key, &block_group->key, sizeof(key)); + index = get_block_group_index(block_group); if (block_group->flags & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10)) @@ -7296,6 +7314,8 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, * are still on the list after taking the semaphore */ list_del_init(&block_group->list); + if (list_empty(&block_group->space_info->block_groups[index])) + clear_avail_alloc_bits(root->fs_info, block_group->flags); up_write(&block_group->space_info->groups_sem); if (block_group->cached == BTRFS_CACHE_STARTED)