From patchwork Tue Mar 2 02:48:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12111129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97CE9C28E85 for ; Tue, 2 Mar 2021 08:12:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7299864D9E for ; Tue, 2 Mar 2021 08:12:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245590AbhCBGjA (ORCPT ); Tue, 2 Mar 2021 01:39:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26023 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242529AbhCBCyV (ORCPT ); Mon, 1 Mar 2021 21:54:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614653575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dZFfZ874yaa8YKtxQkyzrYvtn9qlPDx16b5j7MmxPC0=; b=WQimdoK0agPTKrjFNZk05fZvKpEOYvoY5+8z5jLvC7upSFd5rJFsqQ/687CK+POa+a7NAD ddKB7j//H2OHOqvPojOfWLfMim78s4WWaDYBfYfYHvANppl1/kWLiYUjamyitVoC4mTV6y f6MTa22+jPMBJZ5tz58xvlUEkQk+w0o= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-425-ozQUfZzHOdmd0rmP27WI8g-1; Mon, 01 Mar 2021 21:49:14 -0500 X-MC-Unique: ozQUfZzHOdmd0rmP27WI8g-1 Received: by mail-pl1-f199.google.com with SMTP id t14so10356659plr.15 for ; Mon, 01 Mar 2021 18:49:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dZFfZ874yaa8YKtxQkyzrYvtn9qlPDx16b5j7MmxPC0=; b=b3Ea2ex89dxnk/8/8zlR6AMLd7XLiJyGUQNm01NvhlAKet9wHUTrM/Kz0Se/xKMViR jWJlWt36ym+1kJvNF9pD1YZjqVuHI6MEgFycoO5i3BTSeafe2pa//dS3bB6jAtFQavqT OfZ+vPx1RnFCmrQYhLMc9diW5BCtwB0cITQQqCBsISoMM17AD6cV5Er3nWpipxCp0SD+ jyUfTvYpIN/oSysfejRpYlAdkwqZjG6/UGI2ew+T5UKP1FGfUwVoNwtXt6nFVUgAD9xh NEGHgnz2/2sRIyKQJle6aJHCQqxjYdgwuifNkRt2UWy2+TW1gDlku1IbbN9/7ijJixpV o27g== X-Gm-Message-State: AOAM531c7KCy6S/5CgDhvyXSA2pfV32s3OssJv+vGaNIr0OXesxHldSp KTHEgEaLaDNMlNMBJQoFSw5vwjRbz+QJdS0drcSJROin6jkRD6OgasPsIMkOo8bjWaIpca4/8Ks BhXIdHZ4fGM2RCF6SINrEU0+noLTJplD4wKSl6wqxbxkWjSJFK3cVmgNmcZECGrr5YKnQGWfaIQ == X-Received: by 2002:a17:903:22cf:b029:e5:b66c:5903 with SMTP id y15-20020a17090322cfb02900e5b66c5903mr655830plg.68.1614653353174; Mon, 01 Mar 2021 18:49:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyvfcrEJ8soQpoNHGgHOdDTbbLfaI/tJ56A41gYLWVAV+2h0P68B8s2/yHeMRDzqXYnqJ6HA== X-Received: by 2002:a17:903:22cf:b029:e5:b66c:5903 with SMTP id y15-20020a17090322cfb02900e5b66c5903mr655800plg.68.1614653352904; Mon, 01 Mar 2021 18:49:12 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d24sm18451031pfr.139.2021.03.01.18.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 18:49:12 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang Subject: [PATCH v7 1/5] xfs: update lazy sb counters immediately for resizefs Date: Tue, 2 Mar 2021 10:48:12 +0800 Message-Id: <20210302024816.2525095-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210302024816.2525095-1-hsiangkao@redhat.com> References: <20210302024816.2525095-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org sb_fdblocks will be updated lazily if lazysbcount is enabled, therefore when shrinking the filesystem sb_fdblocks could be larger than sb_dblocks and xfs_validate_sb_write() would fail. Even for growfs case, it'd be better to update lazy sb counters immediately to reflect the real sb counters. Signed-off-by: Gao Xiang Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_fsops.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index a2a407039227..9f9ba8bd0213 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -128,6 +128,15 @@ xfs_growfs_data_private( nb - mp->m_sb.sb_dblocks); if (id.nfree) xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree); + + /* + * Sync sb counters now to reflect the updated values. This is + * particularly important for shrink because the write verifier + * will fail if sb_fdblocks is ever larger than sb_dblocks. + */ + if (xfs_sb_version_haslazysbcount(&mp->m_sb)) + xfs_log_sb(tp); + xfs_trans_set_sync(tp); error = xfs_trans_commit(tp); if (error) From patchwork Tue Mar 2 02:48:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12111137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ECF6C433DB for ; Tue, 2 Mar 2021 08:20:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 597196148E for ; Tue, 2 Mar 2021 08:20:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245165AbhCBGjr (ORCPT ); Tue, 2 Mar 2021 01:39:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32503 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242583AbhCBCy1 (ORCPT ); Mon, 1 Mar 2021 21:54:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614653581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=syJAbd8h09jBQ8/g4k3fRAl3Qr7NcBT800qyHfUnx/s=; b=FXmXoYFzXkzRZe1rDQAfUlNLGGxiWc6um/l24dO2Bm9ULGwMAiGrqRcntlNi34RWhF9uPG oj7ttz7+SAVfwqEtaGZGzJOxMLkieWbaz1qDsx7cAByYDSNJy4qNv0WcOapRaQRcLylwak V6z/GvRQQf/8LoTltdRlktUX+NUcWco= Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-506-C0GTx5jhM0aDA9Jem0L4KQ-1; Mon, 01 Mar 2021 21:49:19 -0500 X-MC-Unique: C0GTx5jhM0aDA9Jem0L4KQ-1 Received: by mail-pg1-f200.google.com with SMTP id i10so10978383pgm.7 for ; Mon, 01 Mar 2021 18:49:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=syJAbd8h09jBQ8/g4k3fRAl3Qr7NcBT800qyHfUnx/s=; b=iAH8vomwxHBiTZ89JhkqP7nO1bbWRFSPWdIg6fjc+nJwp5usnbPf2+wvE27drl4fbO 2OEQTGBWUyqTsQZnh7ZOVLvB+l3ZD4xQVduQRDM+HYbxA4PwqAShY85d1DGGvicTJ1C2 cPkH3MKwJNZvN5VU6fq+7VjjA/9EzaZtc/6ecYcjtQQVgVpSfvJ9JDmRXzD34ZVrykw+ C2g16qPcb8VNR3ddJmoZilgQi3azs5LyE7KdOZeSvaPoQjPeHkDgGhUbqvF5WJj2iG6Q RWPEuJ0jZFUjd5DVA45d9rFtc2bHnvoUj0jAXyDoxJEHIbY198LX9/i1e9S/4sM13uLv 535Q== X-Gm-Message-State: AOAM530M9Ar7G/tPPrlEQ1XjCRIsC5Z1Fb+MoYDGFC4/+KbBcm0J3VeV Lfvm8GP/BWrybHd90Dz6MIfETtyKFC5iPQoKH7WC1mV+ceeYeigCBxONvCmHZZsnffm1XNCJpFk ByJOjVEv6ewpGE0CEKBTpqKXF59SbHM/F7QbKD5Lm9E8TzlYmKF9maszgU7YHs86H389g2ORi0A == X-Received: by 2002:a17:90b:798:: with SMTP id l24mr1919479pjz.63.1614653357717; Mon, 01 Mar 2021 18:49:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5TrdJ6Q0OTedyknySG1s0tBzVm6GtzqOIZ5HfOGFYq8y7c5G857hERZc/pVgYF8DaMWRD1w== X-Received: by 2002:a17:90b:798:: with SMTP id l24mr1919450pjz.63.1614653357407; Mon, 01 Mar 2021 18:49:17 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d24sm18451031pfr.139.2021.03.01.18.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 18:49:17 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang , "Darrick J . Wong" Subject: [PATCH v7 2/5] xfs: hoist out xfs_resizefs_init_new_ags() Date: Tue, 2 Mar 2021 10:48:13 +0800 Message-Id: <20210302024816.2525095-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210302024816.2525095-1-hsiangkao@redhat.com> References: <20210302024816.2525095-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Move out related logic for initializing new added AGs to a new helper in preparation for shrinking. No logic changes. Reviewed-by: Darrick J. Wong Signed-off-by: Gao Xiang --- fs/xfs/xfs_fsops.c | 110 ++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 9f9ba8bd0213..494f9354e3fb 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -20,6 +20,64 @@ #include "xfs_ag.h" #include "xfs_ag_resv.h" +/* + * Write new AG headers to disk. Non-transactional, but need to be + * written and completed prior to the growfs transaction being logged. + * To do this, we use a delayed write buffer list and wait for + * submission and IO completion of the list as a whole. This allows the + * IO subsystem to merge all the AG headers in a single AG into a single + * IO and hide most of the latency of the IO from us. + * + * This also means that if we get an error whilst building the buffer + * list to write, we can cancel the entire list without having written + * anything. + */ +static int +xfs_resizefs_init_new_ags( + struct xfs_trans *tp, + struct aghdr_init_data *id, + xfs_agnumber_t oagcount, + xfs_agnumber_t nagcount, + xfs_rfsblock_t delta, + bool *lastag_resetagres) +{ + struct xfs_mount *mp = tp->t_mountp; + xfs_rfsblock_t nb = mp->m_sb.sb_dblocks + delta; + int error; + + *lastag_resetagres = false; + + INIT_LIST_HEAD(&id->buffer_list); + for (id->agno = nagcount - 1; + id->agno >= oagcount; + id->agno--, delta -= id->agsize) { + + if (id->agno == nagcount - 1) + id->agsize = nb - (id->agno * + (xfs_rfsblock_t)mp->m_sb.sb_agblocks); + else + id->agsize = mp->m_sb.sb_agblocks; + + error = xfs_ag_init_headers(mp, id); + if (error) { + xfs_buf_delwri_cancel(&id->buffer_list); + return error; + } + } + + error = xfs_buf_delwri_submit(&id->buffer_list); + if (error) + return error; + + xfs_trans_agblocks_delta(tp, id->nfree); + + if (delta) { + *lastag_resetagres = true; + error = xfs_ag_extend_space(mp, tp, id, delta); + } + return error; +} + /* * growfs operations */ @@ -32,8 +90,8 @@ xfs_growfs_data_private( int error; xfs_agnumber_t nagcount; xfs_agnumber_t nagimax = 0; - xfs_rfsblock_t nb, nb_div, nb_mod; - xfs_rfsblock_t delta; + xfs_rfsblock_t nb, nb_div, nb_mod, delta; + bool lastag_resetagres; xfs_agnumber_t oagcount; struct xfs_trans *tp; struct aghdr_init_data id = {}; @@ -74,48 +132,11 @@ xfs_growfs_data_private( if (error) return error; - /* - * Write new AG headers to disk. Non-transactional, but need to be - * written and completed prior to the growfs transaction being logged. - * To do this, we use a delayed write buffer list and wait for - * submission and IO completion of the list as a whole. This allows the - * IO subsystem to merge all the AG headers in a single AG into a single - * IO and hide most of the latency of the IO from us. - * - * This also means that if we get an error whilst building the buffer - * list to write, we can cancel the entire list without having written - * anything. - */ - INIT_LIST_HEAD(&id.buffer_list); - for (id.agno = nagcount - 1; - id.agno >= oagcount; - id.agno--, delta -= id.agsize) { - - if (id.agno == nagcount - 1) - id.agsize = nb - - (id.agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks); - else - id.agsize = mp->m_sb.sb_agblocks; - - error = xfs_ag_init_headers(mp, &id); - if (error) { - xfs_buf_delwri_cancel(&id.buffer_list); - goto out_trans_cancel; - } - } - error = xfs_buf_delwri_submit(&id.buffer_list); + error = xfs_resizefs_init_new_ags(tp, &id, oagcount, nagcount, + delta, &lastag_resetagres); if (error) goto out_trans_cancel; - xfs_trans_agblocks_delta(tp, id.nfree); - - /* If there are new blocks in the old last AG, extend it. */ - if (delta) { - error = xfs_ag_extend_space(mp, tp, &id, delta); - if (error) - goto out_trans_cancel; - } - /* * Update changed superblock fields transactionally. These are not * seen by the rest of the world until the transaction commit applies @@ -123,9 +144,8 @@ xfs_growfs_data_private( */ if (nagcount > oagcount) xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount); - if (nb > mp->m_sb.sb_dblocks) - xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS, - nb - mp->m_sb.sb_dblocks); + if (delta > 0) + xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS, delta); if (id.nfree) xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree); @@ -152,7 +172,7 @@ xfs_growfs_data_private( * If we expanded the last AG, free the per-AG reservation * so we can reinitialize it with the new size. */ - if (delta) { + if (lastag_resetagres) { struct xfs_perag *pag; pag = xfs_perag_get(mp, id.agno); From patchwork Tue Mar 2 02:48:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12111139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FA85C433E0 for ; Tue, 2 Mar 2021 08:20:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE59D6148E for ; Tue, 2 Mar 2021 08:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344127AbhCBGkP (ORCPT ); Tue, 2 Mar 2021 01:40:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55742 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242611AbhCBCy2 (ORCPT ); Mon, 1 Mar 2021 21:54:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614653581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yGQqUecRx+rvMXapMkIjCEn36fraMZi5aWsBCX03ces=; b=CP1yHEEYhq9hg839aOSjvBhnO6XUaLx3VaPb2ghAPMMboFfafsQYHmRq3PZCAYAKGtXW2Y erLDPU49ADBmDM66PUE1IJli1f0SqrXdJTrWWemsauo0Ca61rE3JuUmBamian9wc+MVWPL KAisOEsQjgv7EtGBZ638kgtw9fYnYxk= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-579-_-JlCS1SM0CyYI9wQ8SPfg-1; Mon, 01 Mar 2021 21:49:24 -0500 X-MC-Unique: _-JlCS1SM0CyYI9wQ8SPfg-1 Received: by mail-pl1-f199.google.com with SMTP id o8so10438416pls.7 for ; Mon, 01 Mar 2021 18:49:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yGQqUecRx+rvMXapMkIjCEn36fraMZi5aWsBCX03ces=; b=Sjgel5fc9KUkXdfmohiWS8+L9OeK3F/JP8SabPC91YuB8I4EzAdIg86zD9Jq0bMFSN 2ZUkS3IM4FQwGy7U6DWKgS2MEn7t9NOS1rWlKI+SUEQkkgT1vef/rt88t+Wwwyv4wnM2 klWwkyEPuRj8FR0MmuzTcZvbigp8hXMznMql+re0NtYdT1RmzTtU6lDlCFAzCZtYmvrY DhQMsTW35HgPorm0cCZftQopxcgUXPyfG08mOZk43i4ZJ9nyy9id4rtRHlaCJjbvnmJc rUerd8I5dRTvVs+7sKxlGTJ6pSUz25iEtbMP2p8u2taWgHHktPATXINhp/CytzSb3zKj E1mw== X-Gm-Message-State: AOAM5308UlE3eb1/3BLC0060PRqDiQnkbTj3/HnUUUXOKMFsaW3m/m88 T5716DWbQIuAxP5SUwScLMi9RRMy8AYxmeTxl36BvSUllM/NC8YBSOgV9SgZlCSFW6RncMGGezN auCZwqlUJ6NJ0kQFrjnFfA5BJTKFeNPbetjSB+jaRZ6E+EYQP+hFtBcXPRAOh8nzUp67lQJkGEg == X-Received: by 2002:a17:902:c317:b029:e4:aecd:8539 with SMTP id k23-20020a170902c317b02900e4aecd8539mr1486067plx.61.1614653362551; Mon, 01 Mar 2021 18:49:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpJRu1OMsVY2p7zMtFaEiCXjjP//hYY0Cx3+FggfBPcIk8f/qKvl0DJXVmN8d5PJrB4UouLg== X-Received: by 2002:a17:902:c317:b029:e4:aecd:8539 with SMTP id k23-20020a170902c317b02900e4aecd8539mr1486051plx.61.1614653362186; Mon, 01 Mar 2021 18:49:22 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d24sm18451031pfr.139.2021.03.01.18.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 18:49:21 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang Subject: [PATCH v7 3/5] xfs: introduce xfs_ag_shrink_space() Date: Tue, 2 Mar 2021 10:48:14 +0800 Message-Id: <20210302024816.2525095-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210302024816.2525095-1-hsiangkao@redhat.com> References: <20210302024816.2525095-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org This patch introduces a helper to shrink unused space in the last AG by fixing up the freespace btree. Also make sure that the per-AG reservation works under the new AG size. If such per-AG reservation or extent allocation fails, roll the transaction so the new transaction could cancel without any side effects. Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ag.c | 108 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_ag.h | 2 + 2 files changed, 110 insertions(+) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index 9331f3516afa..a1128814630a 100644 --- a/fs/xfs/libxfs/xfs_ag.c +++ b/fs/xfs/libxfs/xfs_ag.c @@ -22,6 +22,11 @@ #include "xfs_ag.h" #include "xfs_ag_resv.h" #include "xfs_health.h" +#include "xfs_error.h" +#include "xfs_bmap.h" +#include "xfs_defer.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" static int xfs_get_aghdr_buf( @@ -485,6 +490,109 @@ xfs_ag_init_headers( return error; } +int +xfs_ag_shrink_space( + struct xfs_mount *mp, + struct xfs_trans **tpp, + xfs_agnumber_t agno, + xfs_extlen_t len) +{ + struct xfs_alloc_arg args = { + .tp = *tpp, + .mp = mp, + .type = XFS_ALLOCTYPE_THIS_BNO, + .minlen = len, + .maxlen = len, + .oinfo = XFS_RMAP_OINFO_SKIP_UPDATE, + .resv = XFS_AG_RESV_NONE, + .prod = 1 + }; + struct xfs_buf *agibp, *agfbp; + struct xfs_agi *agi; + struct xfs_agf *agf; + int error, err2; + + ASSERT(agno == mp->m_sb.sb_agcount - 1); + error = xfs_ialloc_read_agi(mp, *tpp, agno, &agibp); + if (error) + return error; + + agi = agibp->b_addr; + + error = xfs_alloc_read_agf(mp, *tpp, agno, 0, &agfbp); + if (error) + return error; + + agf = agfbp->b_addr; + if (XFS_IS_CORRUPT(mp, agf->agf_length != agi->agi_length)) + return -EFSCORRUPTED; + + args.fsbno = XFS_AGB_TO_FSB(mp, agno, + be32_to_cpu(agi->agi_length) - len); + + /* remove the preallocations before allocation and re-establish then */ + error = xfs_ag_resv_free(agibp->b_pag); + if (error) + return error; + + /* internal log shouldn't also show up in the free space btrees */ + error = xfs_alloc_vextent(&args); + if (!error && args.agbno == NULLAGBLOCK) + error = -ENOSPC; + + if (error) { + /* + * if extent allocation fails, need to roll the transaction to + * ensure that the AGFL fixup has been committed anyway. + */ + err2 = xfs_trans_roll(tpp); + if (err2) + return err2; + goto resv_init_out; + } + + /* + * if successfully deleted from freespace btrees, need to confirm + * per-AG reservation works as expected. + */ + be32_add_cpu(&agi->agi_length, -len); + be32_add_cpu(&agf->agf_length, -len); + + err2 = xfs_ag_resv_init(agibp->b_pag, *tpp); + if (err2) { + be32_add_cpu(&agi->agi_length, len); + be32_add_cpu(&agf->agf_length, len); + if (err2 != -ENOSPC) + goto resv_err; + + __xfs_bmap_add_free(*tpp, args.fsbno, len, NULL, true); + + /* + * Roll the transaction before trying to re-init the per-ag + * reservation. The new transaction is clean so it will cancel + * without any side effects. + */ + error = xfs_defer_finish(tpp); + if (error) + return error; + + error = -ENOSPC; + goto resv_init_out; + } + xfs_ialloc_log_agi(*tpp, agibp, XFS_AGI_LENGTH); + xfs_alloc_log_agf(*tpp, agfbp, XFS_AGF_LENGTH); + return 0; + +resv_init_out: + err2 = xfs_ag_resv_init(agibp->b_pag, *tpp); + if (!err2) + return error; +resv_err: + xfs_warn(mp, "Error %d reserving per-AG metadata reserve pool.", err2); + xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); + return err2; +} + /* * Extent the AG indicated by the @id by the length passed in */ diff --git a/fs/xfs/libxfs/xfs_ag.h b/fs/xfs/libxfs/xfs_ag.h index 5166322807e7..f33388eb130a 100644 --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -24,6 +24,8 @@ struct aghdr_init_data { }; int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id); +int xfs_ag_shrink_space(struct xfs_mount *mp, struct xfs_trans **tpp, + xfs_agnumber_t agno, xfs_extlen_t len); int xfs_ag_extend_space(struct xfs_mount *mp, struct xfs_trans *tp, struct aghdr_init_data *id, xfs_extlen_t len); int xfs_ag_get_geometry(struct xfs_mount *mp, xfs_agnumber_t agno, From patchwork Tue Mar 2 02:48:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12111141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D925C433DB for ; Tue, 2 Mar 2021 08:20:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B71DA64DE5 for ; Tue, 2 Mar 2021 08:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344150AbhCBGka (ORCPT ); Tue, 2 Mar 2021 01:40:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41399 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242610AbhCBCy2 (ORCPT ); Mon, 1 Mar 2021 21:54:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614653581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MraiXaE0u7RmLhSa50D+nQuOPjAXP6+wUb0BlyniFyI=; b=JcYDaUW8eCaXHNN8j2NRenM7FM8gFQGljL3Kvcwta/4wsuFr1o4afa4PD7pgfJip/k9Frq f+w6qdSUzjYnwgMB8n0yOzwXMXtpJlrMvKkY2DePVOrd+4k45LQlhNtnjQZaAvbK6YU3Ke 6z1og1j6EJsL/0GwhVEHNl6ALp/SLeo= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-150-vAlpE-PkNLawBVrLHcRJYA-1; Mon, 01 Mar 2021 21:49:28 -0500 X-MC-Unique: vAlpE-PkNLawBVrLHcRJYA-1 Received: by mail-pf1-f199.google.com with SMTP id e199so12515367pfh.11 for ; Mon, 01 Mar 2021 18:49:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MraiXaE0u7RmLhSa50D+nQuOPjAXP6+wUb0BlyniFyI=; b=MPsDhFiyuRUtlfO1CvFXHm8fUFLkBo5YJ1swO65HZzorLsTjH8KGq3Mure+Egp9Ei/ 7KzZBSSKSQEvucd7UXm3GMbdpHgZV4/fPD3lla5ELF/YbSyMQ57ipC84KK11vW+ixFOq ZjvgskIaXQw95WVAhKTIysoiFMng3NRA+RxaqXT77IpWS5cgzpkN8Xg9JO1+ayE6bY6c ktA75+h5S8h2BNcnG7r1v01oYDNC3xn0cSl6FQJ9Ilh2srx2jkKbmj3AcVDzdYQYSyh9 ev5nofnhicl+Nc/MZD2vlJc6UMVbf49cW4x0GVPe4de36sx/lva3v27hWTMm2Iha88Tx bLBA== X-Gm-Message-State: AOAM5326XGVI5x6UoJrZD1SZLVcqHr8lHZo0lu6YYKIoMQSq//3vYqoZ zmabI4b0dSbcEqY3ePSXH4Hov8q0LozXcJbYn4X3GwnIN1U09Ie5jXjbYWdKMLpW7CfmuKbH3Uj R3F6xZbnxBTI7oX3e3pKriaA/K60DDLfmTBUMA0xX2WuYk96p4PRuc7W4G7+stm1pbm6ecUmayw == X-Received: by 2002:a17:90a:17ea:: with SMTP id q97mr2028245pja.71.1614653366822; Mon, 01 Mar 2021 18:49:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzo+UgwZcYYhLVCtDZ5f7bNhvT5kVv8kBWq1RrCXODzokIbZ+Bqmz2TPO8ArEhjjQhuad4lpQ== X-Received: by 2002:a17:90a:17ea:: with SMTP id q97mr2028227pja.71.1614653366493; Mon, 01 Mar 2021 18:49:26 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d24sm18451031pfr.139.2021.03.01.18.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 18:49:26 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang Subject: [PATCH v7 4/5] xfs: support shrinking unused space in the last AG Date: Tue, 2 Mar 2021 10:48:15 +0800 Message-Id: <20210302024816.2525095-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210302024816.2525095-1-hsiangkao@redhat.com> References: <20210302024816.2525095-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org As the first step of shrinking, this attempts to enable shrinking unused space in the last allocation group by fixing up freespace btree, agi, agf and adjusting super block and use a helper xfs_ag_shrink_space() to fixup the last AG. This can be all done in one transaction for now, so I think no additional protection is needed. Signed-off-by: Gao Xiang Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_fsops.c | 90 ++++++++++++++++++++++++++++------------------ fs/xfs/xfs_trans.c | 1 - 2 files changed, 55 insertions(+), 36 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 494f9354e3fb..204c96d0010f 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -90,23 +90,29 @@ xfs_growfs_data_private( int error; xfs_agnumber_t nagcount; xfs_agnumber_t nagimax = 0; - xfs_rfsblock_t nb, nb_div, nb_mod, delta; + xfs_rfsblock_t nb, nb_div, nb_mod; + int64_t delta; bool lastag_resetagres; xfs_agnumber_t oagcount; struct xfs_trans *tp; struct aghdr_init_data id = {}; nb = in->newblocks; - if (nb < mp->m_sb.sb_dblocks) - return -EINVAL; - if ((error = xfs_sb_validate_fsb_count(&mp->m_sb, nb))) + if (nb == mp->m_sb.sb_dblocks) + return 0; + + error = xfs_sb_validate_fsb_count(&mp->m_sb, nb); + if (error) return error; - error = xfs_buf_read_uncached(mp->m_ddev_targp, + + if (nb > mp->m_sb.sb_dblocks) { + error = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1), XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL); - if (error) - return error; - xfs_buf_relse(bp); + if (error) + return error; + xfs_buf_relse(bp); + } nb_div = nb; nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks); @@ -114,10 +120,15 @@ xfs_growfs_data_private( if (nb_mod && nb_mod < XFS_MIN_AG_BLOCKS) { nagcount--; nb = (xfs_rfsblock_t)nagcount * mp->m_sb.sb_agblocks; - if (nb < mp->m_sb.sb_dblocks) - return -EINVAL; } delta = nb - mp->m_sb.sb_dblocks; + /* + * XFS doesn't really support single-AG filesystems, so do not + * permit callers to remove the filesystem's second and last AG. + */ + if (delta < 0 && nagcount < 2) + return -EINVAL; + oagcount = mp->m_sb.sb_agcount; /* allocate the new per-ag structures */ @@ -125,15 +136,23 @@ xfs_growfs_data_private( error = xfs_initialize_perag(mp, nagcount, &nagimax); if (error) return error; + } else if (nagcount < oagcount) { + /* TODO: shrinking the entire AGs hasn't yet completed */ + return -EINVAL; } error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata, - XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp); + (delta > 0 ? XFS_GROWFS_SPACE_RES(mp) : -delta), 0, + XFS_TRANS_RESERVE, &tp); if (error) return error; - error = xfs_resizefs_init_new_ags(tp, &id, oagcount, nagcount, - delta, &lastag_resetagres); + if (delta > 0) + error = xfs_resizefs_init_new_ags(tp, &id, oagcount, nagcount, + delta, &lastag_resetagres); + else + error = xfs_ag_shrink_space(mp, &tp, nagcount - 1, -delta); + if (error) goto out_trans_cancel; @@ -144,7 +163,7 @@ xfs_growfs_data_private( */ if (nagcount > oagcount) xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount); - if (delta > 0) + if (delta) xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS, delta); if (id.nfree) xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree); @@ -168,28 +187,29 @@ xfs_growfs_data_private( xfs_set_low_space_thresholds(mp); mp->m_alloc_set_aside = xfs_alloc_set_aside(mp); - /* - * If we expanded the last AG, free the per-AG reservation - * so we can reinitialize it with the new size. - */ - if (lastag_resetagres) { - struct xfs_perag *pag; - - pag = xfs_perag_get(mp, id.agno); - error = xfs_ag_resv_free(pag); - xfs_perag_put(pag); - if (error) - return error; + if (delta > 0) { + /* + * If we expanded the last AG, free the per-AG reservation + * so we can reinitialize it with the new size. + */ + if (lastag_resetagres) { + struct xfs_perag *pag; + + pag = xfs_perag_get(mp, id.agno); + error = xfs_ag_resv_free(pag); + xfs_perag_put(pag); + if (error) + return error; + } + /* + * Reserve AG metadata blocks. ENOSPC here does not mean there + * was a growfs failure, just that there still isn't space for + * new user data after the grow has been run. + */ + error = xfs_fs_reserve_ag_blocks(mp); + if (error == -ENOSPC) + error = 0; } - - /* - * Reserve AG metadata blocks. ENOSPC here does not mean there was a - * growfs failure, just that there still isn't space for new user data - * after the grow has been run. - */ - error = xfs_fs_reserve_ag_blocks(mp); - if (error == -ENOSPC) - error = 0; return error; out_trans_cancel: diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 44f72c09c203..d047f5f26cc0 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -434,7 +434,6 @@ xfs_trans_mod_sb( tp->t_res_frextents_delta += delta; break; case XFS_TRANS_SB_DBLOCKS: - ASSERT(delta > 0); tp->t_dblocks_delta += delta; break; case XFS_TRANS_SB_AGCOUNT: From patchwork Tue Mar 2 02:48:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12111143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B01CC433E0 for ; Tue, 2 Mar 2021 08:21:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9C2164DE5 for ; Tue, 2 Mar 2021 08:21:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344166AbhCBGku (ORCPT ); Tue, 2 Mar 2021 01:40:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52325 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347192AbhCBCyl (ORCPT ); Mon, 1 Mar 2021 21:54:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614653594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a7Z47e4dYU13+hS89bOI0ylg21RiN0vcx6FCQFX1Ooo=; b=if7a5F/ezPkbRrSzksBJnRFUavwKqi7/kSrXwtYhZm3J19nCsC3FAZiPaqJxaYok8pAS3b cQYfOvZahSEthXWlZios1+i0hAYcxz8CbTezIIiCYKzgM/SrtIrdd6Kr8kOgN+xX9Tbz5D P34xwh+MebqmUw1R12Loo69Tdau8pYo= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-362-ZB59Ef9NPbuvmx3tAHATsQ-1; Mon, 01 Mar 2021 21:49:32 -0500 X-MC-Unique: ZB59Ef9NPbuvmx3tAHATsQ-1 Received: by mail-pf1-f200.google.com with SMTP id j125so3713888pfb.21 for ; Mon, 01 Mar 2021 18:49:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a7Z47e4dYU13+hS89bOI0ylg21RiN0vcx6FCQFX1Ooo=; b=ThEzuIPQxzriigxFM6caOg20koPVVaa2+zokijAog+oe3Fjb0WiHiHMA3rdIKvraKf wTIvJGuH4rS0B5Vu6JqhmzHrRk0yTi6oIiKc/0ebD2YU4gqJpzFugM+hwOuigeQiH3RD JTnFKjfT4qhjCXkbQfDwAmnP79vlk46/9oyUf3lYfMvg16Kjxzp9J5fKVMhBkCIbKio0 8iRciE/C1RwmHCmR+XjRYIs3Oc7K1dEZPO0BlW/cUbBLV9d8SDJniwcRyHlchUwyLJoo KImfhbcuTevIrdK4JeeeWR2UPDSnoJNtMt82/QQR7hOw/m7H67n1cEvYbCfcYAJ/suJn 0bgg== X-Gm-Message-State: AOAM530ux31G4aBjfwt5Nn1c/khk4xhDZYJkvmLfjAHW2JkNaIgDMv/W m+7tivR66VU4q8IZFGXSWBO2lNJ1QV95tmjHn9ulIKpCIFwsBJmRmBt5RrNwfsylfUEXa2NqG4d jYRV390uJ4/uJuEHXYbZiFcQmVDr4XPx2oJ2wpC4Wq9eedU6pDKXknEKztpThZQJWZT3LJu/S5A == X-Received: by 2002:a17:903:31d1:b029:de:8361:739b with SMTP id v17-20020a17090331d1b02900de8361739bmr18356624ple.85.1614653370775; Mon, 01 Mar 2021 18:49:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJyX783S1S2qJ65dwPPrKj6PwTbE+uAn3jhnxUFjbv39CNyWb50Eskme6QLJBNQjambP6LzW7A== X-Received: by 2002:a17:903:31d1:b029:de:8361:739b with SMTP id v17-20020a17090331d1b02900de8361739bmr18356608ple.85.1614653370505; Mon, 01 Mar 2021 18:49:30 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d24sm18451031pfr.139.2021.03.01.18.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 18:49:30 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Dave Chinner , Christoph Hellwig , Eric Sandeen , Gao Xiang Subject: [PATCH v7 5/5] xfs: add error injection for per-AG resv failure Date: Tue, 2 Mar 2021 10:48:16 +0800 Message-Id: <20210302024816.2525095-6-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210302024816.2525095-1-hsiangkao@redhat.com> References: <20210302024816.2525095-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org per-AG resv failure after fixing up freespace is hard to test in an effective way, so directly add an error injection path to observe such error handling path works as expected. Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ag_resv.c | 6 +++++- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_ag_resv.c b/fs/xfs/libxfs/xfs_ag_resv.c index fdfe6dc0d307..6c5f8d10589c 100644 --- a/fs/xfs/libxfs/xfs_ag_resv.c +++ b/fs/xfs/libxfs/xfs_ag_resv.c @@ -211,7 +211,11 @@ __xfs_ag_resv_init( ASSERT(0); return -EINVAL; } - error = xfs_mod_fdblocks(mp, -(int64_t)hidden_space, true); + + if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_AG_RESV_FAIL)) + error = -ENOSPC; + else + error = xfs_mod_fdblocks(mp, -(int64_t)hidden_space, true); if (error) { trace_xfs_ag_resv_init_error(pag->pag_mount, pag->pag_agno, error, _RET_IP_); diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 6ca9084b6934..b433ef735217 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -40,6 +40,7 @@ #define XFS_ERRTAG_REFCOUNT_FINISH_ONE 25 #define XFS_ERRTAG_BMAP_FINISH_ONE 26 #define XFS_ERRTAG_AG_RESV_CRITICAL 27 + /* * DEBUG mode instrumentation to test and/or trigger delayed allocation * block killing in the event of failed writes. When enabled, all @@ -58,7 +59,8 @@ #define XFS_ERRTAG_BUF_IOERROR 35 #define XFS_ERRTAG_REDUCE_MAX_IEXTENTS 36 #define XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT 37 -#define XFS_ERRTAG_MAX 38 +#define XFS_ERRTAG_AG_RESV_FAIL 38 +#define XFS_ERRTAG_MAX 39 /* * Random factors for above tags, 1 means always, 2 means 1/2 time, etc. diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 185b4915b7bf..5192a7063d95 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -168,6 +168,7 @@ XFS_ERRORTAG_ATTR_RW(iunlink_fallback, XFS_ERRTAG_IUNLINK_FALLBACK); XFS_ERRORTAG_ATTR_RW(buf_ioerror, XFS_ERRTAG_BUF_IOERROR); XFS_ERRORTAG_ATTR_RW(reduce_max_iextents, XFS_ERRTAG_REDUCE_MAX_IEXTENTS); XFS_ERRORTAG_ATTR_RW(bmap_alloc_minlen_extent, XFS_ERRTAG_BMAP_ALLOC_MINLEN_EXTENT); +XFS_ERRORTAG_ATTR_RW(ag_resv_fail, XFS_ERRTAG_AG_RESV_FAIL); static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(noerror), @@ -208,6 +209,7 @@ static struct attribute *xfs_errortag_attrs[] = { XFS_ERRORTAG_ATTR_LIST(buf_ioerror), XFS_ERRORTAG_ATTR_LIST(reduce_max_iextents), XFS_ERRORTAG_ATTR_LIST(bmap_alloc_minlen_extent), + XFS_ERRORTAG_ATTR_LIST(ag_resv_fail), NULL, };