From patchwork Wed Mar 18 20:21:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5220117E6 for ; Wed, 18 Mar 2020 20:18:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 31F8320752 for ; Wed, 18 Mar 2020 20:18:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="juMXASig" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726781AbgCRUSs (ORCPT ); Wed, 18 Mar 2020 16:18:48 -0400 Received: from gateway31.websitewelcome.com ([192.185.143.46]:33925 "EHLO gateway31.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726733AbgCRUSr (ORCPT ); Wed, 18 Mar 2020 16:18:47 -0400 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway31.websitewelcome.com (Postfix) with ESMTP id A94D2190F05 for ; Wed, 18 Mar 2020 15:18:47 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9LjBMssLnBiEf9Ljh8N7; Wed, 18 Mar 2020 15:18:47 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7TJZ+sCVjJrSn+DU1CLSw/cotnXtVMUu6fJsYQSLKkM=; b=juMXASig38DQGMBdzjH+xzf32v KNlHqRldIlfxgS0gxH37t0QiUThIa1czT9j8olkTt3VBctWL99aIN+vcPzw8pukwUyUAQrBhueh6R Zz9zqtx6dDY2Lify9gMkagmRU9EP9wArD2alh0YErE3DvmcO7PWnL5Yzkws0Dm/KbLZpf3SIinHry IjzOmmHi+57YGu5vVqgh89RWnf846CEfmiLJ5DNOomRNvQL2WeyvpULDL9j2OlY1pkPxzT9duwiYO 3/7TImJtxG1Wi84g5CHD9SX74vxgEX9XG1omy1DEAVq3RTcsxGem3Edc/feVUxkJvjDwqqDm4HunJ j38lIw7A==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9L-000yAj-3g; Wed, 18 Mar 2020 17:18:47 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 01/11] btrfs-progs: qgroup-verify: Avoid NULL pointer dereference for later silent qgroup repair Date: Wed, 18 Mar 2020 17:21:38 -0300 Message-Id: <20200318202148.14828-2-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9L-000yAj-3g X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 5 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Commit 078e9a1cc973 ("btrfs-progs: check: enhanced progress indicator") introduced @qgroup_item_count for progress indicator. However since we will later introduce silent qgroup rescan functionality, the @qgroup_item_count pointer can be NULL. So check if @qgroup_item_count is NULL before accessing it. Signed-off-by: Qu Wenruo --- check/qgroup-verify.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/check/qgroup-verify.c b/check/qgroup-verify.c index afe15acf..17c266d4 100644 --- a/check/qgroup-verify.c +++ b/check/qgroup-verify.c @@ -743,7 +743,8 @@ static int travel_tree(struct btrfs_fs_info *info, struct btrfs_root *root, */ nr = btrfs_header_nritems(eb); for (i = 0; i < nr; i++) { - (*qgroup_item_count)++; + if (qgroup_item_count) + (*qgroup_item_count)++; new_bytenr = btrfs_node_blockptr(eb, i); new_num_bytes = info->nodesize; From patchwork Wed Mar 18 20:21:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445961 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F087A6CA for ; Wed, 18 Mar 2020 20:40:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF06C2076F for ; Wed, 18 Mar 2020 20:40:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="AksshsdK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726836AbgCRUk1 (ORCPT ); Wed, 18 Mar 2020 16:40:27 -0400 Received: from gateway24.websitewelcome.com ([192.185.51.196]:27537 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbgCRUk1 (ORCPT ); Wed, 18 Mar 2020 16:40:27 -0400 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 14CFC2BAA8 for ; Wed, 18 Mar 2020 15:18:49 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9NjlN4TSl8qEf9NjKGQC; Wed, 18 Mar 2020 15:18:49 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=TN77EJkOHwY+b8YCeSFh11cEXDqEu09+dDtG+P2xcrQ=; b=AksshsdKbgiVw8qdwZ/Hrw+dOO UT7WSDeV7SCPuzy0BU38AWeGQB9Hb0YZ88FPKR3EXMqkfyS6cZR0a1TUgdR7hMdQicNVOO0u2po1T 0aV6zpQaLQku1lwF9b9UeQGZJnC+6u57/42nMq7eLykUrLdbjVTFuf36Rc4DVmXgoP/KRh+iDj7MF 7sbE9CyPsPO0aZhrTJ6M6eTFh/Y9Ijtik8bOLJq9dYrj+LHePPHKWW6kdvyIXVwL2TrF0pHINtn5d oNMDPvTDrRnt0eeNQDukp79dRk3xoX85GVjW6pAESWQgdQQ+M4u0vQ5BWoZ8V+SlVGzpPCfwTaExs RmD0XRlA==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9M-000yAj-Gq; Wed, 18 Mar 2020 17:18:48 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 02/11] btrfs-progs: qgroup-verify: Also repair qgroup status version Date: Wed, 18 Mar 2020 17:21:39 -0300 Message-Id: <20200318202148.14828-3-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9M-000yAj-Gq X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 8 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Current kernel only supports qgroup version 1. Make qgroup-verify to follow this standard. Signed-off-by: Qu Wenruo --- check/qgroup-verify.c | 2 ++ ctree.h | 1 + 2 files changed, 3 insertions(+) diff --git a/check/qgroup-verify.c b/check/qgroup-verify.c index 17c266d4..0509ecec 100644 --- a/check/qgroup-verify.c +++ b/check/qgroup-verify.c @@ -1598,6 +1598,8 @@ static int repair_qgroup_status(struct btrfs_fs_info *info) btrfs_set_qgroup_status_rescan(path.nodes[0], status_item, 0); btrfs_set_qgroup_status_generation(path.nodes[0], status_item, trans->transid); + btrfs_set_qgroup_status_version(path.nodes[0], status_item, + BTRFS_QGROUP_STATUS_VERSION); btrfs_mark_buffer_dirty(path.nodes[0]); diff --git a/ctree.h b/ctree.h index 36f62732..083bde3c 100644 --- a/ctree.h +++ b/ctree.h @@ -1034,6 +1034,7 @@ struct btrfs_qgroup_status_item { __le64 rescan; /* progress during scanning */ } __attribute__ ((__packed__)); +#define BTRFS_QGROUP_STATUS_VERSION 1 struct btrfs_block_group_item { __le64 used; __le64 chunk_objectid; From patchwork Wed Mar 18 20:21:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445967 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69D2A14B4 for ; Wed, 18 Mar 2020 20:43:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48CB2208CA for ; Wed, 18 Mar 2020 20:43:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="KNcxkZ9a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727030AbgCRUnd (ORCPT ); Wed, 18 Mar 2020 16:43:33 -0400 Received: from gateway36.websitewelcome.com ([192.185.197.22]:37247 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbgCRUnd (ORCPT ); Wed, 18 Mar 2020 16:43:33 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 12DD44068AA84 for ; Wed, 18 Mar 2020 14:34:51 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9OjFOVHAGTXEf9OjfWje; Wed, 18 Mar 2020 15:18:50 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=sWC+8lph8mgYGTKQDTByg5CI4SVPQNA4LoSAKIu6yiI=; b=KNcxkZ9aps6TSuTk8oDfsQO4gm aCKLDgbxBwVReXsG+GQRxneRxNCHsMEWYyPzGANjeHKB+B8wpHeXzlmYKv+c0zPAn6blKhxXfpFNR ofCr01nwMJ9vxnM6qgXNdjgu/rQ27JmCdl/ezyl15qcmf0eTx3+sdxACVW3UAU6EBRg8NqkEzBUo2 7Md6XIWHwVifaCxH1Zcp90BQ5pwgmUf/UjjnPCxXVpt1tRbHEfHriOuXXG2IcHPjW5kIMRAQTu97d FcbimFTbmcV1iHwvCf57w9OIjZfhSpmp+PC1Ob7RRConMyofL4wnTHE3tmyLBhx2vf+4Sq1S4XRIS gT1wmpKg==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9O-000yAj-0S; Wed, 18 Mar 2020 17:18:50 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 03/11] btrfs-progs: qgroup-verify: Use fs_info->readonly to check if we should repair qgroups Date: Wed, 18 Mar 2020 17:21:40 -0300 Message-Id: <20200318202148.14828-4-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9O-000yAj-0S X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 11 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo In fact qgroup-verify is just kind of offline qgroup rescan, and later mkfs qgroup support will reuse it. So qgroup-verify doesn't really need to rely the global variable @repair to check if it should repair qgroups. Instead check fs_info->readonly to do the repair. Signed-off-by: Qu Wenruo --- check/qgroup-verify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/qgroup-verify.c b/check/qgroup-verify.c index 0509ecec..b7b63095 100644 --- a/check/qgroup-verify.c +++ b/check/qgroup-verify.c @@ -1617,7 +1617,7 @@ int repair_qgroups(struct btrfs_fs_info *info, int *repaired) *repaired = 0; - if (!repair) + if (info->readonly) return 0; list_for_each_entry_safe(count, tmpcount, &bad_qgroups, bad_list) { From patchwork Wed Mar 18 20:21:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1237017E6 for ; Wed, 18 Mar 2020 20:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC36620777 for ; Wed, 18 Mar 2020 20:18:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="pXfBN3As" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726797AbgCRUSy (ORCPT ); Wed, 18 Mar 2020 16:18:54 -0400 Received: from gateway21.websitewelcome.com ([192.185.46.113]:44592 "EHLO gateway21.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbgCRUSy (ORCPT ); Wed, 18 Mar 2020 16:18:54 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 820994011AE7D for ; Wed, 18 Mar 2020 15:18:52 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9QjFOXMAGTXEf9QjfWlj; Wed, 18 Mar 2020 15:18:52 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=QmMwKn25xxXIipr6CHwpL0xXXilvyoO+iJoU/DLMhfg=; b=pXfBN3AspyF+c/dxmMCrViHqkC j2sXJ5qtvuew3daJ0nHlxJ++Guc8JDlWxlG33IHg+ioIeW3NtXsPfxitpDGByiLS/W+7wkP4VIpOr BEnOyJJZ/xerUNhBeqkAUeQwbMpYgHcq7j7q+8VegNN9+005QQDyCnBhSN5bJ7TQmIeupFzvI+nZy zz4h9yky/VnvPwINpx+HX6LCTv3uIPcMhHeuVrudYFQaXNdyb3+HL+JZQgp1tDcay5AvgbpLuYSon lEJFe6AvxDEsZnBdC2FRct+U87Y42P7NMXaeZvLB2YrQMygbgrZcIWBd5VLdHwdx1nFLr51l8OEtf ulSenoDQ==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9P-000yAj-K2; Wed, 18 Mar 2020 17:18:52 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Cc: Marcos Paulo de Souza Subject: [PATCH v4 04/11] btrfs-progs: qgroup-verify: Move qgroup classification out of report_qgroups Date: Wed, 18 Mar 2020 17:21:41 -0300 Message-Id: <20200318202148.14828-5-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9P-000yAj-K2 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 15 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo The original qgroup-verify integrates qgroup classification into report_qgroups(). This behavior makes silent qgroup repair (or offline rescan) impossible. To repair qgroup, we must call report_qgroups() to trigger bad qgroup classification, which will output error message. This patch moves bad qgroup classification from report_qgroups() to qgroup_verify_all(). Now report_qgroups() is pretty lightweight, only doing basic qgroup difference report thus change it type to void. And since the functionality of qgroup_verify_all() changes, change callers to handle the new return value correctly. Signed-off-by: Qu Wenruo [ removed some comments ] Signed-off-by: Marcos Paulo de Souza --- check/main.c | 18 ++++++------ check/qgroup-verify.c | 67 +++++++++++++++++++++++++++++++------------ check/qgroup-verify.h | 2 +- 3 files changed, 59 insertions(+), 28 deletions(-) diff --git a/check/main.c b/check/main.c index 49bdbfec..7632b60a 100644 --- a/check/main.c +++ b/check/main.c @@ -9941,7 +9941,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) int clear_space_cache = 0; int qgroup_report = 0; int qgroups_repaired = 0; - int qgroup_report_ret; + int qgroup_verify_ret; unsigned ctree_flags = OPEN_CTREE_EXCLUSIVE; int force = 0; @@ -10198,8 +10198,8 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) uuidbuf); ret = qgroup_verify_all(info); err |= !!ret; - if (ret == 0) - err |= !!report_qgroups(1); + if (ret >= 0) + report_qgroups(1); goto close_out; } if (subvolid) { @@ -10433,21 +10433,21 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) ctx.tp = TASK_QGROUPS; task_start(ctx.info, &ctx.start_time, &ctx.item_count); } - ret = qgroup_verify_all(info); + qgroup_verify_ret = qgroup_verify_all(info); task_stop(ctx.info); - err |= !!ret; - if (ret) { + if (qgroup_verify_ret < 0) { error("failed to check quota groups"); + err |= !!qgroup_verify_ret; goto out; } - qgroup_report_ret = report_qgroups(0); + report_qgroups(0); ret = repair_qgroups(info, &qgroups_repaired); if (ret) { error("failed to repair quota groups"); goto out; } - if (qgroup_report_ret && (!qgroups_repaired || ret)) - err |= qgroup_report_ret; + if (qgroup_verify_ret && (!qgroups_repaired || ret)) + err |= !!qgroup_verify_ret; ret = 0; } else { fprintf(stderr, diff --git a/check/qgroup-verify.c b/check/qgroup-verify.c index b7b63095..b1e6b26c 100644 --- a/check/qgroup-verify.c +++ b/check/qgroup-verify.c @@ -1311,18 +1311,13 @@ static int report_qgroup_difference(struct qgroup_count *count, int verbose) /* * Report qgroups errors - * Return 0 if nothing wrong. - * Return <0 if any qgroup is inconsistent. - * * @all: if set, all qgroup will be checked and reported even already * inconsistent or under rescan. */ -int report_qgroups(int all) +void report_qgroups(int all) { struct rb_node *node; struct qgroup_count *c; - bool found_err = false; - bool skip_err = false; if (!repair && counts.rescan_running) { if (all) { @@ -1331,34 +1326,26 @@ int report_qgroups(int all) } else { printf( "Qgroup rescan is running, qgroups will not be printed.\n"); - return 0; + return; } } /* * It's possible that rescan hasn't been initialized yet. */ if (counts.qgroup_inconsist && !counts.rescan_running && - counts.rescan_running == 0) { + counts.rescan_running == 0) printf( -"Rescan hasn't been initialized, a difference in qgroup accounting is expected\n"); - skip_err = true; - } +"Rescan hasn't been initialzied, a difference in qgroup accounting is expected\n"); if (counts.qgroup_inconsist && !counts.rescan_running) fprintf(stderr, "Qgroup are marked as inconsistent.\n"); node = rb_first(&counts.root); while (node) { c = rb_entry(node, struct qgroup_count, rb_node); - if (report_qgroup_difference(c, all)) { - list_add_tail(&c->bad_list, &bad_qgroups); - found_err = true; - } + report_qgroup_difference(c, all); node = rb_next(node); } - if (found_err && !skip_err) - return -EUCLEAN; - return 0; } void free_qgroup_counts(void) @@ -1393,9 +1380,29 @@ void free_qgroup_counts(void) } } +static bool is_bad_qgroup(struct qgroup_count *count) +{ + struct qgroup_info *info = &count->info; + struct qgroup_info *disk = &count->diskinfo; + s64 excl_diff = info->exclusive - disk->exclusive; + s64 ref_diff = info->referenced - disk->referenced; + + return (excl_diff || ref_diff); +} + +/* + * Verify all qgroup numbers. + * + * Return <0 for fatal errors (e.g. ENOMEM or failed to read quota tree) + * Return 0 if all qgroup numbers are correct or no need to check (under rescan) + * Return >0 if qgroup numbers are inconsistent. + */ int qgroup_verify_all(struct btrfs_fs_info *info) { int ret; + bool found_err = false; + bool skip_err = false; + struct rb_node *node; if (!info->quota_enabled) return 0; @@ -1413,6 +1420,12 @@ int qgroup_verify_all(struct btrfs_fs_info *info) goto out; } + if (counts.rescan_running) + skip_err = true; + if (counts.qgroup_inconsist && !counts.rescan_running && + counts.rescan_running == 0) + skip_err = true; + /* * Put all extent refs into our rbtree */ @@ -1430,6 +1443,22 @@ int qgroup_verify_all(struct btrfs_fs_info *info) ret = account_all_refs(1, 0); + /* + * Do the correctness check here, so for callers who don't want + * verbose report can skip calling report_qgroups() + */ + node = rb_first(&counts.root); + while (node) { + struct qgroup_count *c; + + c = rb_entry(node, struct qgroup_count, rb_node); + if (is_bad_qgroup(c)) { + list_add_tail(&c->bad_list, &bad_qgroups); + found_err = true; + } + node = rb_next(node); + } + out: /* * Don't free the qgroup count records as they will be walked @@ -1437,6 +1466,8 @@ out: */ free_tree_blocks(); free_ref_tree(&by_bytenr); + if (!ret && !skip_err && found_err) + ret = 1; return ret; } diff --git a/check/qgroup-verify.h b/check/qgroup-verify.h index 20e93708..6495dd18 100644 --- a/check/qgroup-verify.h +++ b/check/qgroup-verify.h @@ -23,7 +23,7 @@ #include "ctree.h" int qgroup_verify_all(struct btrfs_fs_info *info); -int report_qgroups(int all); +void report_qgroups(int all); int repair_qgroups(struct btrfs_fs_info *info, int *repaired); int print_extent_state(struct btrfs_fs_info *info, u64 subvol); From patchwork Wed Mar 18 20:21:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445965 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC084139A for ; Wed, 18 Mar 2020 20:43:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9264A208CA for ; Wed, 18 Mar 2020 20:43:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="Vd6ncQw0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727024AbgCRUnc (ORCPT ); Wed, 18 Mar 2020 16:43:32 -0400 Received: from gateway36.websitewelcome.com ([192.185.197.22]:40768 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbgCRUnc (ORCPT ); Wed, 18 Mar 2020 16:43:32 -0400 X-Greylist: delayed 1481 seconds by postgrey-1.27 at vger.kernel.org; Wed, 18 Mar 2020 16:43:32 EDT Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway36.websitewelcome.com (Postfix) with ESMTP id CD8D04068FDBB for ; Wed, 18 Mar 2020 14:34:53 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9RjlNAQSl8qEf9RjKGW5; Wed, 18 Mar 2020 15:18:53 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=9Q1GO3N7UMmC9HV+qkUFefBdvFCgEOXvkIfH4IiZllk=; b=Vd6ncQw09vM8SwJkBNpQodVXR9 CwfqSldjPD/iJw17wUaaNUdYYXXptG3EfvNS51fDLd4JmwOtyDfqJd0xYfdmNVe6rRSX4J5bq1MPF fvAVa890k6EsOVDUOrxUDYMvxTc/NrSfYFPYU35galmUpvgTA6gRN5duQsmKOuUWccUAxZ1MWlff+ o0Rrcdiv9OoM667QbcbiDjPwPDpDJ1KsOmhRJGOq35QufGpoa2uLqNhQ9VqSIj2bPMQPFVUaIZVEH dbShr6XZQcT5x91p4ie5B85ZlJDLTB++MJBgI73cj7Gc2wD4jcAua44EqqQ5Hv4FhYJDtoDqxcQzt anRVKbWA==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9Q-000yAj-Uc; Wed, 18 Mar 2020 17:18:53 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 05/11] btrfs-progs: qgroup-verify: Allow repair_qgroups function to do silent repair Date: Wed, 18 Mar 2020 17:21:42 -0300 Message-Id: <20200318202148.14828-6-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9Q-000yAj-Uc X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 18 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Allow repair_qgroups() to do silent repair, so it can acts as offline qgroup rescan. This provides the basis for later mkfs quota support. Signed-off-by: Qu Wenruo --- check/main.c | 2 +- check/qgroup-verify.c | 19 +++++++++++-------- check/qgroup-verify.h | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/check/main.c b/check/main.c index 7632b60a..375aef8f 100644 --- a/check/main.c +++ b/check/main.c @@ -10441,7 +10441,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) goto out; } report_qgroups(0); - ret = repair_qgroups(info, &qgroups_repaired); + ret = repair_qgroups(info, &qgroups_repaired, false); if (ret) { error("failed to repair quota groups"); goto out; diff --git a/check/qgroup-verify.c b/check/qgroup-verify.c index b1e6b26c..b1736aab 100644 --- a/check/qgroup-verify.c +++ b/check/qgroup-verify.c @@ -1540,7 +1540,7 @@ out: } static int repair_qgroup_info(struct btrfs_fs_info *info, - struct qgroup_count *count) + struct qgroup_count *count, bool silent) { int ret; struct btrfs_root *root = info->quota_root; @@ -1549,8 +1549,10 @@ static int repair_qgroup_info(struct btrfs_fs_info *info, struct btrfs_qgroup_info_item *info_item; struct btrfs_key key; - printf("Repair qgroup %llu/%llu\n", btrfs_qgroup_level(count->qgroupid), - btrfs_qgroup_subvid(count->qgroupid)); + if (!silent) + printf("Repair qgroup %llu/%llu\n", + btrfs_qgroup_level(count->qgroupid), + btrfs_qgroup_subvid(count->qgroupid)); trans = btrfs_start_transaction(root, 1); if (IS_ERR(trans)) @@ -1595,7 +1597,7 @@ out: return ret; } -static int repair_qgroup_status(struct btrfs_fs_info *info) +static int repair_qgroup_status(struct btrfs_fs_info *info, bool silent) { int ret; struct btrfs_root *root = info->quota_root; @@ -1604,7 +1606,8 @@ static int repair_qgroup_status(struct btrfs_fs_info *info) struct btrfs_key key; struct btrfs_qgroup_status_item *status_item; - printf("Repair qgroup status item\n"); + if (!silent) + printf("Repair qgroup status item\n"); trans = btrfs_start_transaction(root, 1); if (IS_ERR(trans)) @@ -1641,7 +1644,7 @@ out: return ret; } -int repair_qgroups(struct btrfs_fs_info *info, int *repaired) +int repair_qgroups(struct btrfs_fs_info *info, int *repaired, bool silent) { int ret = 0; struct qgroup_count *count, *tmpcount; @@ -1652,7 +1655,7 @@ int repair_qgroups(struct btrfs_fs_info *info, int *repaired) return 0; list_for_each_entry_safe(count, tmpcount, &bad_qgroups, bad_list) { - ret = repair_qgroup_info(info, count); + ret = repair_qgroup_info(info, count, silent); if (ret) { goto out; } @@ -1668,7 +1671,7 @@ int repair_qgroups(struct btrfs_fs_info *info, int *repaired) * mount. */ if (*repaired || counts.qgroup_inconsist || counts.rescan_running) { - ret = repair_qgroup_status(info); + ret = repair_qgroup_status(info, silent); if (ret) goto out; diff --git a/check/qgroup-verify.h b/check/qgroup-verify.h index 6495dd18..8a8694b6 100644 --- a/check/qgroup-verify.h +++ b/check/qgroup-verify.h @@ -24,7 +24,7 @@ int qgroup_verify_all(struct btrfs_fs_info *info); void report_qgroups(int all); -int repair_qgroups(struct btrfs_fs_info *info, int *repaired); +int repair_qgroups(struct btrfs_fs_info *info, int *repaired, bool silent); int print_extent_state(struct btrfs_fs_info *info, u64 subvol); From patchwork Wed Mar 18 20:21:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445957 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF3356CA for ; Wed, 18 Mar 2020 20:40:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 857C22076F for ; Wed, 18 Mar 2020 20:40:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="umhzgqdC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726741AbgCRUkY (ORCPT ); Wed, 18 Mar 2020 16:40:24 -0400 Received: from gateway24.websitewelcome.com ([192.185.51.196]:31316 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbgCRUkX (ORCPT ); Wed, 18 Mar 2020 16:40:23 -0400 X-Greylist: delayed 1294 seconds by postgrey-1.27 at vger.kernel.org; Wed, 18 Mar 2020 16:40:23 EDT Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 6DEA02CE60 for ; Wed, 18 Mar 2020 15:18:55 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9Tj3vXJ8vkBEf9Tjv9Ga; Wed, 18 Mar 2020 15:18:55 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2kZwrVJXQnHBOYUdClAiEtoWTFk30qt64/jtbofxREU=; b=umhzgqdC63rW4H7NgnlUaU8HKS HgPJyAtfqIeCUe90FppEbT6daFJW8oERD612T7F+F1Rvu7Bb1OEZBofWJvhZEuAe1yk4N1MImPux9 7R1V7DUCGuRgu/rz+BJ79aVgrsIdx9pv7hZ7QNyp0TftJcyA2sjzQJQY9hsKDSNcy2baq1XDiaD0d nAtC9mreZ+dH6w6VqWsasgsFcHckftjL0zcF92pCyFiM1a7lRdl9ZOlUzqAgcB5LrsJ4R4HQnvDxE nKUXJ7ziHByf9bzilhxlZbJT7WPI6Ylc4WApzkKpskVpvAbJR0xiVDn5M4OwhLBL/i0zqGMUxFsyJ MFcxthbw==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9S-000yAj-FG; Wed, 18 Mar 2020 17:18:54 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Cc: Marcos Paulo de Souza Subject: [PATCH v4 06/11] btrfs-progs: ctree: Introduce function to create an empty tree Date: Wed, 18 Mar 2020 17:21:43 -0300 Message-Id: <20200318202148.14828-7-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9S-000yAj-FG X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 22 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Introduce a new function, btrfs_create_tree(), to create an empty tree. Currently, there is only one caller to create new tree, namely data reloc tree in mkfs. However it's copying fs tree to create a new root. This copy fs tree method is not a good idea if we only need an empty tree. So here introduce a new function, btrfs_create_tree() to create new tree. Which will handle the following things: 1) New tree root leaf Using generic tree allocation 2) New root item in tree root 3) Modify special tree root pointers in fs_info Only quota_root is supported yet, but can be expended easily This patch provides the basis to implement quota support in mkfs. Signed-off-by: Qu Wenruo [ solved minor conflicts ] Signed-off-by: Marcos Paulo de Souza --- ctree.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- ctree.h | 2 ++ 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/ctree.c b/ctree.c index 97b44d48..49598a45 100644 --- a/ctree.c +++ b/ctree.c @@ -21,8 +21,9 @@ #include "print-tree.h" #include "repair.h" #include "common/internal.h" -#include "kernel-lib/sizes.h" #include "common/messages.h" +#include "common/utils.h" +#include "kernel-lib/sizes.h" #include "volumes.h" static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root @@ -182,6 +183,112 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, return 0; } +/* + * Create a new tree root, with root objectid set to @objectid. + * + * NOTE: Doesn't support tree with non-zero offset, like data reloc tree. + */ +int btrfs_create_root(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *fs_info, u64 objectid) +{ + struct extent_buffer *node; + struct btrfs_root *new_root; + struct btrfs_disk_key disk_key; + struct btrfs_key location; + struct btrfs_root_item root_item = { 0 }; + int ret; + + new_root = malloc(sizeof(*new_root)); + if (!new_root) + return -ENOMEM; + + btrfs_setup_root(new_root, fs_info, objectid); + if (!is_fstree(objectid)) + new_root->track_dirty = 1; + add_root_to_dirty_list(new_root); + + new_root->objectid = objectid; + new_root->root_key.objectid = objectid; + new_root->root_key.type = BTRFS_ROOT_ITEM_KEY; + new_root->root_key.offset = 0; + + node = btrfs_alloc_free_block(trans, new_root, fs_info->nodesize, + objectid, &disk_key, 0, 0, 0); + if (IS_ERR(node)) { + ret = PTR_ERR(node); + error("failed to create root node for tree %llu: %d (%s)", + objectid, ret, strerror(-ret)); + return ret; + } + new_root->node = node; + + btrfs_set_header_generation(node, trans->transid); + btrfs_set_header_backref_rev(node, BTRFS_MIXED_BACKREF_REV); + btrfs_clear_header_flag(node, BTRFS_HEADER_FLAG_RELOC | + BTRFS_HEADER_FLAG_WRITTEN); + btrfs_set_header_owner(node, objectid); + btrfs_set_header_nritems(node, 0); + btrfs_set_header_level(node, 0); + ret = btrfs_inc_ref(trans, new_root, node, 0); + if (ret < 0) + goto free; + + /* + * Special tree roots may need to modify pointers in @fs_info + * Only quota is supported yet. + */ + switch (objectid) { + case BTRFS_QUOTA_TREE_OBJECTID: + if (fs_info->quota_root) { + error("quota root already exists"); + ret = -EEXIST; + goto free; + } + fs_info->quota_root = new_root; + fs_info->quota_enabled = 1; + break; + /* + * Essential trees can't be created by this function, yet. + * As we expect such skeleton exists, or a lot of functions like + * btrfs_alloc_free_block() doesn't work at all + */ + case BTRFS_ROOT_TREE_OBJECTID: + case BTRFS_EXTENT_TREE_OBJECTID: + case BTRFS_CHUNK_TREE_OBJECTID: + case BTRFS_FS_TREE_OBJECTID: + ret = -EEXIST; + goto free; + default: + /* Subvolume trees don't need special handles */ + if (is_fstree(objectid)) + break; + /* Other special trees are not supported yet */ + ret = -ENOTTY; + goto free; + } + btrfs_mark_buffer_dirty(node); + btrfs_set_root_bytenr(&root_item, btrfs_header_bytenr(node)); + btrfs_set_root_level(&root_item, 0); + btrfs_set_root_generation(&root_item, trans->transid); + btrfs_set_root_dirid(&root_item, 0); + btrfs_set_root_refs(&root_item, 1); + btrfs_set_root_used(&root_item, fs_info->nodesize); + location.objectid = objectid; + location.type = BTRFS_ROOT_ITEM_KEY; + location.offset = 0; + + ret = btrfs_insert_root(trans, fs_info->tree_root, &location, + &root_item); + if (ret < 0) + goto free; + return ret; + +free: + free_extent_buffer(node); + free(new_root); + return ret; +} + /* * check if the tree block can be shared by multiple trees */ diff --git a/ctree.h b/ctree.h index 083bde3c..41565b52 100644 --- a/ctree.h +++ b/ctree.h @@ -2641,6 +2641,8 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, struct extent_buffer **cow_ret, u64 new_root_objectid); +int btrfs_create_root(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *fs_info, u64 objectid); int btrfs_extend_item(struct btrfs_root *root, struct btrfs_path *path, u32 data_size); int btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path, From patchwork Wed Mar 18 20:21:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AFFF159A for ; Wed, 18 Mar 2020 20:18:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A82A20752 for ; Wed, 18 Mar 2020 20:18:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="IGFC7e+L" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726822AbgCRUS5 (ORCPT ); Wed, 18 Mar 2020 16:18:57 -0400 Received: from gateway34.websitewelcome.com ([192.185.149.62]:41092 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbgCRUS5 (ORCPT ); Wed, 18 Mar 2020 16:18:57 -0400 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 8444810C3BC9 for ; Wed, 18 Mar 2020 15:18:56 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9UjBN2gLnBiEf9Ujh8Wy; Wed, 18 Mar 2020 15:18:56 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=wX42d+FnfgrXr8XCTpCE5OubZ7NxM0U2yhf7d175Yzo=; b=IGFC7e+LGWnQ0eYjJ8N8F1B0gl /LS+eu9Hy36XQSOG+/4+uyfltBE2uHAV5warOPh3wmXMmUkPGOj5DywO6enh0eHYXUCmQawiqO+bn r4RCCtMerAakcTp8muPqEX5DU4QZGm8qMvQsUieDL3pdlcs9u7ycCIP76pvlbTEKtS7aJNPFO1WFi WPiNs74MO273fsRt/UJpWl+6JdsWcaxSCRf23S+LFOjiW3nTF3R7lVApY3jtuKDeq1sZ3oISS73Pd dVr0h9cX7KMPPebe2JQAtQKrrsJg0kjfdtnvB5C4cdRqnPcwbc7kF/1pXJN3i3HNjsyvQal4va7Gd YIHx0/OA==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9T-000yAj-RS; Wed, 18 Mar 2020 17:18:56 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 07/11] btrfs-progs: mkfs: Introduce function to insert qgroup info and limit items Date: Wed, 18 Mar 2020 17:21:44 -0300 Message-Id: <20200318202148.14828-8-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9T-000yAj-RS X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 25 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Introduce a new function, insert_qgroup_items(), to insert qgroup info item and qgroup limit item for later mkfs qgroup support. Signed-off-by: Qu Wenruo --- mkfs/main.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/mkfs/main.c b/mkfs/main.c index 316ea82e..6d9b3265 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -798,6 +798,40 @@ out: return ret; } +static int insert_qgroup_items(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *fs_info, + u64 qgroupid) +{ + struct btrfs_path path; + struct btrfs_root *quota_root = fs_info->quota_root; + struct btrfs_key key; + int ret; + + if (qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT) { + error("qgroup level other than 0 is not supported yet"); + return -ENOTTY; + } + + key.objectid = 0; + key.type = BTRFS_QGROUP_INFO_KEY; + key.offset = qgroupid; + + btrfs_init_path(&path); + ret = btrfs_insert_empty_item(trans, quota_root, &path, &key, + sizeof(struct btrfs_qgroup_info_item)); + btrfs_release_path(&path); + if (ret < 0) + return ret; + + key.objectid = 0; + key.type = BTRFS_QGROUP_LIMIT_KEY; + key.offset = qgroupid; + ret = btrfs_insert_empty_item(trans, quota_root, &path, &key, + sizeof(struct btrfs_qgroup_limit_item)); + btrfs_release_path(&path); + return ret; +} + int BOX_MAIN(mkfs)(int argc, char **argv) { char *file; From patchwork Wed Mar 18 20:21:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445917 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 054796CA for ; Wed, 18 Mar 2020 20:19:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D99C220777 for ; Wed, 18 Mar 2020 20:19:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="CWXtIUuM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726857AbgCRUTA (ORCPT ); Wed, 18 Mar 2020 16:19:00 -0400 Received: from gateway22.websitewelcome.com ([192.185.47.144]:14114 "EHLO gateway22.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726663AbgCRUS7 (ORCPT ); Wed, 18 Mar 2020 16:18:59 -0400 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 1DD6F16B56 for ; Wed, 18 Mar 2020 15:18:58 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9WjBN4ULnBiEf9Wjh8Yi; Wed, 18 Mar 2020 15:18:58 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+7MMq0skBd4GN0Wsv2CMytC6ZYdlLaM8PZ6eB8b5ojg=; b=CWXtIUuM7ivs4Lj1hmGmUWsJye EH889LR3hjsS+jvWN6CCGNlt4NAIxza/YoG95xHJIcFp6RUYtfO7nAx/mv9Omd31Kk7ljApjzyQZE /VLwsi9fA0qFnuWwnBZ8gRruHZm1rQNQV58bKtRBGSck/SQtnbXCmNCIzTCY57LEecqmMvnprXPlh NBgG7BIzDSOUVNoIUqdk/RaeHNwQBZ7QZa5BJP+aSnyqe/26UaG/kmimxKQh5G62gMWINAj9o1eKG 4zLHCnVZi01IMMyC5GZv0Wqlsa1+ePfWsbMB7SqklO5e/BT/SS/45kRcs3QP5aLGYSfRli+tFrwg7 qZh+c5QQ==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9V-000yAj-DC; Wed, 18 Mar 2020 17:18:57 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Cc: Marcos Paulo de Souza Subject: [PATCH v4 08/11] btrfs-progs: mkfs: Introduce function to setup quota root and rescan Date: Wed, 18 Mar 2020 17:21:45 -0300 Message-Id: <20200318202148.14828-9-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9V-000yAj-DC X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 29 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Introduce a new function, setup_quota_root(), which will create quota root, and do an offline rescan to ensure all quota accounting numbers are correct. Signed-off-by: Qu Wenruo [ minor improvement in the fail path ] Signed-off-by: Marcos Paulo de Souza --- mkfs/main.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/mkfs/main.c b/mkfs/main.c index 6d9b3265..1fb25a9d 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -48,6 +48,7 @@ #include "crypto/crc32c.h" #include "common/fsfeatures.h" #include "common/box.h" +#include "check/qgroup-verify.h" static int verbose = 1; @@ -832,6 +833,91 @@ static int insert_qgroup_items(struct btrfs_trans_handle *trans, return ret; } +static int setup_quota_root(struct btrfs_fs_info *fs_info) +{ + struct btrfs_trans_handle *trans; + struct btrfs_qgroup_status_item *qsi; + struct btrfs_root *quota_root; + struct btrfs_path path; + struct btrfs_key key; + int qgroup_repaired = 0; + int ret; + + /* One to modify tree root, one for quota root */ + trans = btrfs_start_transaction(fs_info->tree_root, 2); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + error("failed to start transaction: %d (%s)", + ret, strerror(-ret)); + return ret; + } + ret = btrfs_create_root(trans, fs_info, BTRFS_QUOTA_TREE_OBJECTID); + if (ret < 0) { + error("failed to create quota root: %d (%s)", + ret, strerror(-ret)); + goto fail; + } + quota_root = fs_info->quota_root; + + key.objectid = 0; + key.type = BTRFS_QGROUP_STATUS_KEY; + key.offset = 0; + + btrfs_init_path(&path); + ret = btrfs_insert_empty_item(trans, quota_root, &path, &key, + sizeof(*qsi)); + if (ret < 0) { + error("failed to insert qgroup status item: %d (%s)", + ret, strerror(-ret)); + goto fail; + } + + qsi = btrfs_item_ptr(path.nodes[0], path.slots[0], + struct btrfs_qgroup_status_item); + btrfs_set_qgroup_status_generation(path.nodes[0], qsi, 0); + btrfs_set_qgroup_status_rescan(path.nodes[0], qsi, 0); + + /* Mark current status info inconsistent, and fix it later */ + btrfs_set_qgroup_status_flags(path.nodes[0], qsi, + BTRFS_QGROUP_STATUS_FLAG_ON | + BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT); + btrfs_release_path(&path); + + /* Currently mkfs will only create one subvolume */ + ret = insert_qgroup_items(trans, fs_info, BTRFS_FS_TREE_OBJECTID); + if (ret < 0) { + error("failed to insert qgroup items: %d (%s)", + ret, strerror(-ret)); + goto fail; + } + + ret = btrfs_commit_transaction(trans, fs_info->tree_root); + if (ret < 0) { + error("failed to commit current transaction: %d (%s)", + ret, strerror(-ret)); + return ret; + } + + /* + * Qgroup is setup but with wrong info, use qgroup-verify + * infrastructure to repair them. + * (Just acts as offline rescan) + */ + ret = qgroup_verify_all(fs_info); + if (ret < 0) { + error("qgroup rescan failed: %d (%s)", ret, strerror(-ret)); + return ret; + } + ret = repair_qgroups(fs_info, &qgroup_repaired, true); + if (ret < 0) + error("failed to fill qgroup info: %d (%s)", ret, + strerror(-ret)); + return ret; +fail: + btrfs_abort_transaction(trans, ret); + return ret; +} + int BOX_MAIN(mkfs)(int argc, char **argv) { char *file; From patchwork Wed Mar 18 20:21:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445919 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9173159A for ; Wed, 18 Mar 2020 20:19:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9882220752 for ; Wed, 18 Mar 2020 20:19:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="rVK55Vo5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726872AbgCRUTB (ORCPT ); Wed, 18 Mar 2020 16:19:01 -0400 Received: from gateway23.websitewelcome.com ([192.185.49.124]:20623 "EHLO gateway23.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726836AbgCRUTA (ORCPT ); Wed, 18 Mar 2020 16:19:00 -0400 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 67FF6CC0F for ; Wed, 18 Mar 2020 15:18:59 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9XjUuwT1s2xEf9XjDUHt; Wed, 18 Mar 2020 15:18:59 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=qd2sBufH3yYuOMkDsTyAwBL8CIUkfdqCnMCx10pwlnY=; b=rVK55Vo5Yd6KP2trOs0N7nxIa/ 9tkTJHIdxLb5dbIW/RCZSA/0DerSMmfsqdYbgz2p/pR65aHV3PuJj2DDexPQhd4SW2JXoaidc7dA4 zOsZfvSxV/eV8YBXvGFZ7+qVRC540ZPPDRpL8U6qjkF+PcSnI1v/xAs3wjr5c3fGMQDNd/lUq/fZf I1wCoM3FCPvTCkFPmx1NnyZDOPOLa4K/LxUZmscvM43F8BDBsVaviGslJJbUMEzS1MWp0TJ/a6A6P NcUyEGAK5lFNkuBmLcIoow6w7fpmvDalQpr7YA/EHMVh0bBFmRDloxusFa5Kho48iyLnii5kbxxIp II9TYNDg==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9W-000yAj-RF; Wed, 18 Mar 2020 17:18:59 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 09/11] btrfs-progs: mkfs: Introduce mkfs time quota support Date: Wed, 18 Mar 2020 17:21:46 -0300 Message-Id: <20200318202148.14828-10-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9W-000yAj-RF X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 32 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo The result fs will has quota enabled, with consistent qgroup accounting. This is quite handy to test quota with fstests, which doesn't support to call ioctl for btrfs at mount time. Signed-off-by: Qu Wenruo --- Documentation/mkfs.btrfs.asciidoc | 5 +++++ mkfs/main.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Documentation/mkfs.btrfs.asciidoc b/Documentation/mkfs.btrfs.asciidoc index 0502d1d8..611ea9c2 100644 --- a/Documentation/mkfs.btrfs.asciidoc +++ b/Documentation/mkfs.btrfs.asciidoc @@ -87,6 +87,11 @@ updating the metadata blocks. + NOTE: versions up to 3.11 set the nodesize to 4k. +*-Q|--quota*:: +Enable btrfs quota support. Result filesystem will have quota enabled and all +qgroup accounting correct. +See also `btrfs-quota`(8). + *-s|--sectorsize *:: Specify the sectorsize, the minimum data block allocation unit. + diff --git a/mkfs/main.c b/mkfs/main.c index 1fb25a9d..70a66cef 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -949,6 +949,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv) char *source_dir = NULL; bool source_dir_set = false; bool shrink_rootdir = false; + bool enable_quota = false; u64 source_dir_size = 0; u64 min_dev_size; u64 shrink_size; @@ -985,13 +986,14 @@ int BOX_MAIN(mkfs)(int argc, char **argv) { "nodiscard", no_argument, NULL, 'K' }, { "features", required_argument, NULL, 'O' }, { "uuid", required_argument, NULL, 'U' }, + { "quota", required_argument, NULL, 'Q' }, { "quiet", 0, NULL, 'q' }, { "shrink", no_argument, NULL, GETOPT_VAL_SHRINK }, { "help", no_argument, NULL, GETOPT_VAL_HELP }, { NULL, 0, NULL, 0} }; - c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:O:r:U:VMKq", + c = getopt_long(argc, argv, "A:b:fl:n:s:m:d:L:O:r:U:VMKqQ", long_options, NULL); if (c < 0) break; @@ -1066,6 +1068,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv) case 'q': verbose = 0; break; + case 'Q': + enable_quota = true; + break; case GETOPT_VAL_SHRINK: shrink_rootdir = true; break; @@ -1470,6 +1475,15 @@ raid_groups: } } + if (enable_quota) { + ret = setup_quota_root(fs_info); + if (ret < 0) { + error("failed to initialize quota: %d (%s)", ret, + strerror(-ret)); + goto out; + } + } + if (verbose) { char features_buf[64]; From patchwork Wed Mar 18 20:21:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445959 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D84DA1392 for ; Wed, 18 Mar 2020 20:40:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B81B32076F for ; Wed, 18 Mar 2020 20:40:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="t+TwnLtl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726810AbgCRUkY (ORCPT ); Wed, 18 Mar 2020 16:40:24 -0400 Received: from gateway24.websitewelcome.com ([192.185.51.196]:47027 "EHLO gateway24.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726647AbgCRUkY (ORCPT ); Wed, 18 Mar 2020 16:40:24 -0400 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway24.websitewelcome.com (Postfix) with ESMTP id CA4B12E5C6 for ; Wed, 18 Mar 2020 15:19:00 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9YjFOhpAGTXEf9YjfWvx; Wed, 18 Mar 2020 15:19:00 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZaxzvBDJkfibJLdkSzcz8GDD/BiBpFGh8TbALYTtL00=; b=t+TwnLtl5PfHCA/yV2DCewK9Lj WSFfvv5sr6PF9/OwR31+4G3PUzaqyGl2ItDsJEKB3abSXpqwt2voy8dbvR4xPICmeGxKrdNZdiKrE fo5ps/B+KKRD3UO+wbQKZbT/AbAAYgKbYCswiN32Jgs/8Pd14GN5dnRt1gsGL+vETDwxVaSMTdBcy sRaFeRR/t/HhY/Tf8OqucDYtSN4OVeO2d9HE0UHKPyl2bUBUvdmhZDwG3HJ4YQAGxR+MITM0d1MKU i8wzoQdnNivSSJOYE9A7W0Wv6pyqXguUKoNa28xcLBY2ATtqxRJEY6cYkaEBteUVuj98kByTqlyWO UgFfigDg==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9Y-000yAj-6S; Wed, 18 Mar 2020 17:19:00 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 10/11] btrfs-progs: test/mkfs: Add test case for -Q|--quota option Date: Wed, 18 Mar 2020 17:21:47 -0300 Message-Id: <20200318202148.14828-11-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9Y-000yAj-6S X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 35 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Only test if btrfs check (which will check qgroup by default) and kernel mount success. Comprehensive qgroup test cases still belongs to fstests. Signed-off-by: Qu Wenruo --- tests/mkfs-tests/001-basic-profiles/test.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/mkfs-tests/001-basic-profiles/test.sh b/tests/mkfs-tests/001-basic-profiles/test.sh index 4b6c2f42..c273f1df 100755 --- a/tests/mkfs-tests/001-basic-profiles/test.sh +++ b/tests/mkfs-tests/001-basic-profiles/test.sh @@ -47,6 +47,16 @@ test_mkfs_single -d dup -m single test_mkfs_single -d dup -m dup test_mkfs_single -d dup -m dup --mixed +test_mkfs_single -Q +test_mkfs_single -Q -d single -m single +test_mkfs_single -Q -d single -m single --mixed +test_mkfs_single -Q -d single -m dup +test_mkfs_single -Q -d dup -m single +test_mkfs_single -Q -d dup -m dup +test_mkfs_single -Q -d dup -m dup --mixed + +# Profile doesn't really affect quota, skip them to save some time + test_mkfs_multi test_mkfs_multi -d single -m single test_mkfs_multi -d single -m single --mixed From patchwork Wed Mar 18 20:21:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11445921 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33C856CA for ; Wed, 18 Mar 2020 20:19:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1313920752 for ; Wed, 18 Mar 2020 20:19:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=mpdesouza.com header.i=@mpdesouza.com header.b="fGbrZpDH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726875AbgCRUTE (ORCPT ); Wed, 18 Mar 2020 16:19:04 -0400 Received: from gateway34.websitewelcome.com ([192.185.149.62]:38613 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbgCRUTE (ORCPT ); Wed, 18 Mar 2020 16:19:04 -0400 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 75F4B20CADE5 for ; Wed, 18 Mar 2020 15:19:03 -0500 (CDT) Received: from br540.hostgator.com.br ([108.179.252.180]) by cmsmtp with SMTP id Ef9bjBN9pLnBiEf9bjh8dr; Wed, 18 Mar 2020 15:19:03 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mpdesouza.com; s=default; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Vv3LeU+z2MSvX2S/QqZoBMJsm3X8KHrh1/MRgo119ew=; b=fGbrZpDHivtBA+iUGu1tSkrJNt jDdpWv2rXHpnT++f/NTM9wUaGn7dMYFl+Cumm1i5boFh8khdp+9neo3wW+K4OaN5YDO6VZr87CJXI qQAA+t2R/CtuMUks65yENqPJUBQNqNIz6f+ykR8j6+Kavfxdi/wcFf5UrtKuNEoNpW5ilFCoxXTIz Din1kqiDC+91KjcEvpIKv3aOB4rDBVLLD65vmzFNtHdjuvxIrhmV7L2iLFpv428P28KQPZrk/yePs 588p7PlxbW/4iqrK/hRVQcrgE4ptQJEAdZtJqiWIMNb1ZD6I321X97kW0uYuGdB1RO6uvmOTluhxV OkcaFLfg==; Received: from [191.249.66.103] (port=50308 helo=hephaestus.prv.suse.net) by br540.hostgator.com.br with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1jEf9Z-000yAj-ME; Wed, 18 Mar 2020 17:19:02 -0300 From: Marcos Paulo de Souza To: dsterba@suse.com, wqu@suse.com, linux-btrfs@vger.kernel.org Subject: [PATCH v4 11/11] btrfs-progs: test/mkfs: Add test case for --rootdir and --quota Date: Wed, 18 Mar 2020 17:21:48 -0300 Message-Id: <20200318202148.14828-12-marcos@mpdesouza.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318202148.14828-1-marcos@mpdesouza.com> References: <20200318202148.14828-1-marcos@mpdesouza.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - br540.hostgator.com.br X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mpdesouza.com X-BWhitelist: no X-Source-IP: 191.249.66.103 X-Source-L: No X-Exim-ID: 1jEf9Z-000yAj-ME X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (hephaestus.prv.suse.net) [191.249.66.103]:50308 X-Source-Auth: marcos@mpdesouza.com X-Email-Count: 38 X-Source-Cap: bXBkZXNvNTM7bXBkZXNvNTM7YnI1NDAuaG9zdGdhdG9yLmNvbS5icg== X-Local-Domain: yes Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Qu Wenruo Nothing interesting, since such combination can be handled easily by qgroup-verify. Signed-off-by: Qu Wenruo --- .../mkfs-tests/018-rootdir-with-quota/test.sh | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 tests/mkfs-tests/018-rootdir-with-quota/test.sh diff --git a/tests/mkfs-tests/018-rootdir-with-quota/test.sh b/tests/mkfs-tests/018-rootdir-with-quota/test.sh new file mode 100755 index 00000000..97e5f592 --- /dev/null +++ b/tests/mkfs-tests/018-rootdir-with-quota/test.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# Check if runtime feature quota can handle rootdir +# + +source "$TOP/tests/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper # For mknod +prepare_test_dev 1G # make it large since we will fill the fs + +# mknod can create FIFO/CHAR/BLOCK file but not SOCK. +# No neat tool to create socket file, unless using python or similar. +# So no SOCK is tested here +check_global_prereq mknod +check_global_prereq dd + +tmp=$(mktemp -d --tmpdir btrfs-progs-mkfs.rootdirXXXXXXX) + +run_check mkdir "$tmp/dir" +run_check mkdir -p "$tmp/dir/in/dir" + +# More dir, there is no good way to pump metadata since we have no trigger +# to enable/disable inline extent data, so here create enough dirs to bump +# metadata +run_check mkdir "$tmp/a_lot_of_dirs" +for i in $(seq -w 0 8192); do + run_check mkdir "$tmp/a_lot_of_dirs/dir_$i" +done + +# Then some data +run_check dd if=/dev/zero bs=1M count=1 of="$tmp/1M" +run_check dd if=/dev/zero bs=2M count=1 of="$tmp/2M" +run_check dd if=/dev/zero bs=4M count=1 of="$tmp/4M" +run_check dd if=/dev/zero bs=8M count=1 of="$tmp/8M" + +run_check dd if=/dev/zero bs=1K count=1 of="$tmp/1K" +run_check dd if=/dev/zero bs=2K count=1 of="$tmp/2K" +run_check dd if=/dev/zero bs=4K count=1 of="$tmp/4K" +run_check dd if=/dev/zero bs=8K count=1 of="$tmp/8K" + +run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f -r "$tmp" -Q "$TEST_DEV" + +rm -rf -- "$tmp" + +# Normal check already includes quota check +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" + +# Just in case +run_check $SUDO_HELPER "$TOP/btrfs" check --qgroup-report "$TEST_DEV"