From patchwork Tue Aug 23 20:01:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 1089622 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7NK2Jp7006828 for ; Tue, 23 Aug 2011 20:02:19 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756055Ab1HWUCQ (ORCPT ); Tue, 23 Aug 2011 16:02:16 -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 S1756054Ab1HWUCO (ORCPT ); Tue, 23 Aug 2011 16:02:14 -0400 Received: by mail-bw0-f46.google.com with SMTP id 11so372435bke.19 for ; Tue, 23 Aug 2011 13:02:13 -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=vZsHPf8sga3iJdsiULwPkYsomZTN2bAMnuV1sPR/xts=; b=vxBS32pRtRxWyZIWGhq3ozPiw0XJMchmaulorKDtQouMlxGseLjgOQrX5esZckHjjO c/tZCRn7NrGrpKiMDbpRk4lXIg99EnJ0RXL8BNpyv2PNOt0DXLSXlogAj+BFIio44DZ1 y647JB0Dd3TCiU2LXHRyPuTpMe9iKdkbhyGY8= Received: by 10.204.144.137 with SMTP id z9mr1649166bku.245.1314129733847; Tue, 23 Aug 2011 13:02:13 -0700 (PDT) Received: from localhost ([31.28.235.172]) by mx.google.com with ESMTPS id l12sm79691bkk.63.2011.08.23.13.02.12 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Aug 2011 13:02:13 -0700 (PDT) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , Hugo Mills , idryomov@gmail.com Subject: [PATCH 06/21] Btrfs: implement online profile changing Date: Tue, 23 Aug 2011 23:01:47 +0300 Message-Id: <1314129722-31601-7-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 (demeter1.kernel.org [140.211.167.41]); Tue, 23 Aug 2011 20:02:19 +0000 (UTC) Profile changing is done by initializing target field in respective btrfs_restripe_args structs and launching a balance. Reducing code in this mode will pick restriper's target profile if it's available instead of doing a blind reduce. If target profile is not yet available go back to plain reducing. Signed-off-by: Ilya Dryomov --- fs/btrfs/extent-tree.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 53 insertions(+), 1 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index a04f99b..05e55d1 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2968,6 +2968,34 @@ u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) u64 num_devices = root->fs_info->fs_devices->rw_devices + root->fs_info->fs_devices->missing_devices; + /* pick restriper's target profile if it's available */ + spin_lock(&root->fs_info->restripe_lock); + if (root->fs_info->restripe_ctl) { + struct restripe_control *rctl = root->fs_info->restripe_ctl; + u64 t = 0; + + if ((flags & BTRFS_BLOCK_GROUP_DATA) && + (rctl->data.flags & BTRFS_RESTRIPE_ARGS_CONVERT) && + (flags & rctl->data.target)) { + t = BTRFS_BLOCK_GROUP_DATA | rctl->data.target; + } else if ((flags & BTRFS_BLOCK_GROUP_SYSTEM) && + (rctl->sys.flags & BTRFS_RESTRIPE_ARGS_CONVERT) && + (flags & rctl->sys.target)) { + t = BTRFS_BLOCK_GROUP_SYSTEM | rctl->sys.target; + } else if ((flags & BTRFS_BLOCK_GROUP_METADATA) && + (rctl->meta.flags & BTRFS_RESTRIPE_ARGS_CONVERT) && + (flags & rctl->meta.target)) { + t = BTRFS_BLOCK_GROUP_METADATA | rctl->meta.target; + } + + if (t) { + spin_unlock(&root->fs_info->restripe_lock); + t &= ~BTRFS_AVAIL_ALLOC_BIT_SINGLE; + return t; + } + } + spin_unlock(&root->fs_info->restripe_lock); + if (num_devices == 1) flags &= ~(BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID0); if (num_devices < 4) @@ -2987,8 +3015,9 @@ u64 btrfs_reduce_alloc_profile(struct btrfs_root *root, u64 flags) if ((flags & BTRFS_BLOCK_GROUP_RAID0) && ((flags & BTRFS_BLOCK_GROUP_RAID1) | (flags & BTRFS_BLOCK_GROUP_RAID10) | - (flags & BTRFS_BLOCK_GROUP_DUP))) + (flags & BTRFS_BLOCK_GROUP_DUP))) { flags &= ~BTRFS_BLOCK_GROUP_RAID0; + } /* in-memory -> on-disk */ flags &= ~BTRFS_AVAIL_ALLOC_BIT_SINGLE; @@ -6519,6 +6548,29 @@ static u64 update_block_group_flags(struct btrfs_root *root, u64 flags) u64 stripped = BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10; + if (root->fs_info->restripe_ctl) { + struct restripe_control *rctl = root->fs_info->restripe_ctl; + u64 t = 0; + + /* pick restriper's target profile and return */ + if (flags & BTRFS_BLOCK_GROUP_DATA && + rctl->data.flags & BTRFS_RESTRIPE_ARGS_CONVERT) { + t = BTRFS_BLOCK_GROUP_DATA | rctl->data.target; + } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM && + rctl->sys.flags & BTRFS_RESTRIPE_ARGS_CONVERT) { + t = BTRFS_BLOCK_GROUP_SYSTEM | rctl->sys.target; + } else if (flags & BTRFS_BLOCK_GROUP_METADATA && + rctl->meta.flags & BTRFS_RESTRIPE_ARGS_CONVERT) { + t = BTRFS_BLOCK_GROUP_METADATA | rctl->meta.target; + } + + if (t) { + /* in-memory -> on-disk */ + t &= ~BTRFS_AVAIL_ALLOC_BIT_SINGLE; + return t; + } + } + /* * we add in the count of missing devices because we want * to make sure that any RAID levels on a degraded FS