Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1101141pxa; Thu, 20 Aug 2020 02:28:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr3H2ReNmq4PGZ5hRFw7CEk++J2RRJGO66JhoH3BOADTVyFObEIiHip97P1cMO7evkiBMA X-Received: by 2002:a17:906:248b:: with SMTP id e11mr2306250ejb.280.1597915708309; Thu, 20 Aug 2020 02:28:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597915708; cv=none; d=google.com; s=arc-20160816; b=GcRslnNDtL38RnMGHLgo1VjrFR51EUgViCT5sVCi9DIpBMcgqX98cQHTyI5F5OXW8Z XgLxFDteO6sVKL4L6+rwZoIlaieXpOofEGHDJZi04I43w0cT/fZRKKrcNIAGtp+LsLVH V3HSCPZZ2HNyFAJM+0HA1IRvdRE1HD+aTXCHQ3YpHmMuPz8GqwwdHJD7gadKVrYVrYG1 r3NKsW4c2WTIyoUiSC6En1CNxZz+FfurAig423yYXaFA9GpQwQ6oBypbqrgYfEKRoxMO AmP7xvkygI+mkiRpE1xb2TNtilCshvYg4X+ZH1uWTBCLxIRSZiS8nft1D0Rt6s2xuODQ 5ZCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=n/A0dpv7OAuc7QtwxbV9tYhz2Ea13HCE5PxgTCG+GJw=; b=RyhpIVC8GgIJwKcgE3mxrBInYEBeOjaTG8eBoJz28pQEexu9rFIWP7HVBrMZjP3PCt rlC6+94cwCBo5cnOasMGlEr2OZA5QvZThWaB9B83uKPP6585fXAfrTBUdCLk+LjtRbSh bjzx0CYeO9tXM7c2vqKAiIniGXYmb98JMmZbXYws7d5swtLHl3w9SFiUiEqQ04J1Opr/ oCff7mSydxgbPnwhHCaXV1KC4PNh0zW5pQnVIy+0FFKk+Dv1V2f5LaqXzvW7x1FYxfz2 If44YkTF6FgYkRQZ97DztO1X2O+k8DfKAUFX24QFg4acSuYgpGIbfujJ8NdJerj11oxu 1WLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wzxwoVbd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si975504ede.495.2020.08.20.02.28.04; Thu, 20 Aug 2020 02:28:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wzxwoVbd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbgHTJZs (ORCPT + 99 others); Thu, 20 Aug 2020 05:25:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:60858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbgHTJYg (ORCPT ); Thu, 20 Aug 2020 05:24:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 889C822CB2; Thu, 20 Aug 2020 09:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915476; bh=OztBmgibWac0/yJ+f4OlaPKdZfBiGL7/ahnGw2aTiHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wzxwoVbdhZTpv3bxLwbo7gkolheU6t1Cohvhp7Z61QLbDGK3aJ/RO6aFnEQ9MV2kL mJMp85sidBsujP3Rlty4t2rbYokuYnVwkGG3EARCmYsVrkAmK1cjfr3rY69c+dUsKf SHs9D8Astc2T2JlVZlmcONTnqfs95k0CPXQq2zTQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba Subject: [PATCH 5.8 026/232] btrfs: relocation: review the call sites which can be interrupted by signal Date: Thu, 20 Aug 2020 11:17:57 +0200 Message-Id: <20200820091614.014697416@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Qu Wenruo commit 44d354abf33e92a5e73b965c84caf5a5d5e58a0b upstream. Since most metadata reservation calls can return -EINTR when get interrupted by fatal signal, we need to review the all the metadata reservation call sites. In relocation code, the metadata reservation happens in the following sites: - btrfs_block_rsv_refill() in merge_reloc_root() merge_reloc_root() is a pretty critical section, we don't want to be interrupted by signal, so change the flush status to BTRFS_RESERVE_FLUSH_LIMIT, so it won't get interrupted by signal. Since such change can be ENPSPC-prone, also shrink the amount of metadata to reserve least amount avoid deadly ENOSPC there. - btrfs_block_rsv_refill() in reserve_metadata_space() It calls with BTRFS_RESERVE_FLUSH_LIMIT, which won't get interrupted by signal. - btrfs_block_rsv_refill() in prepare_to_relocate() - btrfs_block_rsv_add() in prepare_to_relocate() - btrfs_block_rsv_refill() in relocate_block_group() - btrfs_delalloc_reserve_metadata() in relocate_file_extent_cluster() - btrfs_start_transaction() in relocate_block_group() - btrfs_start_transaction() in create_reloc_inode() Can be interrupted by fatal signal and we can handle it easily. For these call sites, just catch the -EINTR value in btrfs_balance() and count them as canceled. CC: stable@vger.kernel.org # 5.4+ Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/relocation.c | 12 ++++++++++-- fs/btrfs/volumes.c | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -1686,12 +1686,20 @@ static noinline_for_stack int merge_relo btrfs_unlock_up_safe(path, 0); } - min_reserved = fs_info->nodesize * (BTRFS_MAX_LEVEL - 1) * 2; + /* + * In merge_reloc_root(), we modify the upper level pointer to swap the + * tree blocks between reloc tree and subvolume tree. Thus for tree + * block COW, we COW at most from level 1 to root level for each tree. + * + * Thus the needed metadata size is at most root_level * nodesize, + * and * 2 since we have two trees to COW. + */ + min_reserved = fs_info->nodesize * btrfs_root_level(root_item) * 2; memset(&next_key, 0, sizeof(next_key)); while (1) { ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved, - BTRFS_RESERVE_FLUSH_ALL); + BTRFS_RESERVE_FLUSH_LIMIT); if (ret) { err = ret; goto out; --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -4150,7 +4150,22 @@ int btrfs_balance(struct btrfs_fs_info * mutex_lock(&fs_info->balance_mutex); if (ret == -ECANCELED && atomic_read(&fs_info->balance_pause_req)) btrfs_info(fs_info, "balance: paused"); - else if (ret == -ECANCELED && atomic_read(&fs_info->balance_cancel_req)) + /* + * Balance can be canceled by: + * + * - Regular cancel request + * Then ret == -ECANCELED and balance_cancel_req > 0 + * + * - Fatal signal to "btrfs" process + * Either the signal caught by wait_reserve_ticket() and callers + * got -EINTR, or caught by btrfs_should_cancel_balance() and + * got -ECANCELED. + * Either way, in this case balance_cancel_req = 0, and + * ret == -EINTR or ret == -ECANCELED. + * + * So here we only check the return value to catch canceled balance. + */ + else if (ret == -ECANCELED || ret == -EINTR) btrfs_info(fs_info, "balance: canceled"); else btrfs_info(fs_info, "balance: ended with status: %d", ret);