From patchwork Wed Mar 24 01:06:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12159945 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=-19.0 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 D8CD4C433E0 for ; Wed, 24 Mar 2021 01:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B39CA619EC for ; Wed, 24 Mar 2021 01:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233642AbhCXBHm (ORCPT ); Tue, 23 Mar 2021 21:07:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40966 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233946AbhCXBHK (ORCPT ); Tue, 23 Mar 2021 21:07:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616548029; 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=tkFDrcyglR2qPwXLDl3h+PSFANN06x2maUnhV0kW3IU=; b=Hi+gmsnjhXn3bGwvkzC+PSgJMlBPsY8DwP/yi2uURCbvGW2ooCW/njYMhqUCs1YY1hlC6Z R8KRJNioQQ1+bfw8eLnY76Vi/LxAyxgen0zXgKbSex6M5+DQccPMAXgJe3dDnOlHSF2mBU wvnydeKYzTddz/Yn1eMlBXWrNsWap1M= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-16-AmC51FCrOManQvDA0jyWBg-1; Tue, 23 Mar 2021 21:07:07 -0400 X-MC-Unique: AmC51FCrOManQvDA0jyWBg-1 Received: by mail-pl1-f197.google.com with SMTP id 17so54002plj.1 for ; Tue, 23 Mar 2021 18:07:07 -0700 (PDT) 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=tkFDrcyglR2qPwXLDl3h+PSFANN06x2maUnhV0kW3IU=; b=tzgR/CGYnpDizZZWNiqzTHNFpVh6FnuvTmZ9SwI7X7GQKoQ8oDBBAaLcclmg+kBXqw 6BJ6Jg0isnB1PhaSOMBErmQp3S6sob+MX+sMmbAVb9NlIGnfs8Tpkx6b2Qoq/iMaduqc Z3MHY6sF9/NEprTkaW19EeqHCYbKjcjymx6W3DQdeuhQbH/ySsDF3cROAEolGFsMZy2p sZr6q5WJMn79M0iSWbKjEd8Zkf8NjfiK4HQEbxtdGepiKRxdjGIR+Ip7e/30qh1Wakt0 xl/2YfeWmncz5oTmeJA4qBeIx+RtmDQNNQxxvwiYCvqz0A4vD5oYTIFXuhRnlu2DyN0U 6+FQ== X-Gm-Message-State: AOAM533bqrkT3VZLElYCadBsuZN9nV9okLGMSf2G9E7rvQQ+95cHBTE9 c6/eRZnoILFhyR0uGiBAwpWtiWvdq8zpYxHDcpBVKUuvKfAiWlLb8uiqcOYH3/yYmwqHQsHHV8w a/KEYYgRXrMYbOjEvdRoVJmcLyFZ57EMaCwBDHAh+KLO5ceyNRGoQfxx4xB1pDifZX+kw7e2Jdg == X-Received: by 2002:a17:90a:f68a:: with SMTP id cl10mr751677pjb.87.1616548026084; Tue, 23 Mar 2021 18:07:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlveWDqWbb3iRCDA7gF2WJKbv0xtTtyQxBlHuOAfW6wGmQWeFqKEAkwtjPshmZswgTYN3DfQ== X-Received: by 2002:a17:90a:f68a:: with SMTP id cl10mr751649pjb.87.1616548025820; Tue, 23 Mar 2021 18:07:05 -0700 (PDT) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id t18sm379219pgg.33.2021.03.23.18.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 18:07:05 -0700 (PDT) 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 v9 1/5] xfs: update lazy sb counters immediately for resizefs Date: Wed, 24 Mar 2021 09:06:17 +0800 Message-Id: <20210324010621.2244671-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210324010621.2244671-1-hsiangkao@redhat.com> References: <20210324010621.2244671-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. Reviewed-by: Darrick J. Wong Reviewed-by: Brian Foster Signed-off-by: Gao Xiang --- 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 Wed Mar 24 01:06:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12159953 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=-19.0 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 1AFAAC433E3 for ; Wed, 24 Mar 2021 01:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF5F0619F5 for ; Wed, 24 Mar 2021 01:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231653AbhCXBHm (ORCPT ); Tue, 23 Mar 2021 21:07:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43190 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234131AbhCXBHN (ORCPT ); Tue, 23 Mar 2021 21:07:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616548033; 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=IqyPORiRBsaMBUZZkY2wZzVB8e3bpA9jsQaFe2SMBDk=; b=YDoDkDJ9LOOu5SGXxL9q1XeXpFCb7jy/I2gQFmKw+StyvWM8+MdJfqlkMnrmvGY+hKLwz0 KAxJeeZwLD8PJttEg3tvIVX2sYAI9jhyCkH3RqihRVlwIc9ZUZSd3YPdb+kzRDiPOMsiDj 3KSrgqqCTU/YNtEcsGVZukoH0c4PU3I= Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-574-dE_czg30OL-K9He8wNgKUA-1; Tue, 23 Mar 2021 21:07:11 -0400 X-MC-Unique: dE_czg30OL-K9He8wNgKUA-1 Received: by mail-pj1-f70.google.com with SMTP id md1so2935401pjb.0 for ; Tue, 23 Mar 2021 18:07:11 -0700 (PDT) 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=IqyPORiRBsaMBUZZkY2wZzVB8e3bpA9jsQaFe2SMBDk=; b=VLNTDJqzaufjiRwKvzCcMH4X3xJOT3FUPjkYVBib+6OifNu8LUNlOBeB7RIXoXzIon bJpUAlcRzhceMDcCI3a6EbXDC7CNXjMqxYvGJILa3APSefR60zQi6OXPIsHDRRT1c8Vz ycPmm4DeFtANDDZigo70/PyavXfg22mRKFjSz5/EPp+47cMZEj8XAz/lITLiXV+EKmMT hchhf+wMJvcPKqPP0kBiUqaZ6y6zm/oAPq169vljdiSc6Q5Ur93rBX0c6tMuhU7WJzS0 Xvg5f9nRxU9P9jdQsrSGZrNZHowa0cisi5t/bLsN323sZ8mrsyBUYr14hV+adbNM2m0u +jqA== X-Gm-Message-State: AOAM530H5v+kV5FYBuCpsF7vWuy0tz87xtonlJlklaOPwNMtIgcIioZq FVWbzfCTVR0wGtJEVeU2n97nRxhn4gdQKfwHceS7ftROws/58gHsmUJgY+pc0dLJooQrSSGVLsW UuuQWphmNxDGZoVnqnidp5CSVuLTUT7VnSpcIXvR304nucP74R3A6Erf9xQFoVAntiXvT8Uz0PQ == X-Received: by 2002:aa7:9521:0:b029:1f1:b27f:1a43 with SMTP id c1-20020aa795210000b02901f1b27f1a43mr873973pfp.4.1616548030519; Tue, 23 Mar 2021 18:07:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKWfmdd66vk2DhqPobnMcEecu4mHav2F7eHHQx7XfjWkQD4LVZNRXPYOVosJ6h6AFIAZRjBg== X-Received: by 2002:aa7:9521:0:b029:1f1:b27f:1a43 with SMTP id c1-20020aa795210000b02901f1b27f1a43mr873937pfp.4.1616548030048; Tue, 23 Mar 2021 18:07:10 -0700 (PDT) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id t18sm379219pgg.33.2021.03.23.18.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 18:07:09 -0700 (PDT) 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 v9 2/5] xfs: hoist out xfs_resizefs_init_new_ags() Date: Wed, 24 Mar 2021 09:06:18 +0800 Message-Id: <20210324010621.2244671-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210324010621.2244671-1-hsiangkao@redhat.com> References: <20210324010621.2244671-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 | 107 +++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 43 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 9f9ba8bd0213..d1ba04124c28 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_extended) +{ + struct xfs_mount *mp = tp->t_mountp; + xfs_rfsblock_t nb = mp->m_sb.sb_dblocks + delta; + int error; + + *lastag_extended = 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_extended = true; + error = xfs_ag_extend_space(mp, tp, id, delta); + } + return error; +} + /* * growfs operations */ @@ -34,6 +92,7 @@ xfs_growfs_data_private( xfs_agnumber_t nagimax = 0; xfs_rfsblock_t nb, nb_div, nb_mod; xfs_rfsblock_t delta; + bool lastag_extended; xfs_agnumber_t oagcount; struct xfs_trans *tp; struct aghdr_init_data id = {}; @@ -74,48 +133,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_extended); 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 +145,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) + 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 +173,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_extended) { struct xfs_perag *pag; pag = xfs_perag_get(mp, id.agno); From patchwork Wed Mar 24 01:06:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12159949 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=-19.0 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 03158C433E1 for ; Wed, 24 Mar 2021 01:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D9C39619F4 for ; Wed, 24 Mar 2021 01:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233838AbhCXBHn (ORCPT ); Tue, 23 Mar 2021 21:07:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25263 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234219AbhCXBHd (ORCPT ); Tue, 23 Mar 2021 21:07:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616548038; 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=ROffmMGKr17jDLXAnqHPgcKmYbffcbj+QeNzV3+R/Go=; b=Z3FLCAWDsqvHwUoSAD5gdQJTRAfKtVM/KZRCFpY6cXIq9vTFfSmzECAbcSKIbhq/aPetBi q5Z5QNeTLwkz4RDdj4cYQEAonCWf56ZcZqDqxaBz+sQcv2jV0H6a9mBGMgCfnNj6+kf6GY An7jbU2JZJ3VXgzGojRLs43CHeZdJBE= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-mxBROGK9MZq7FL_h2dD62A-1; Tue, 23 Mar 2021 21:07:16 -0400 X-MC-Unique: mxBROGK9MZq7FL_h2dD62A-1 Received: by mail-pf1-f197.google.com with SMTP id u126so285278pfc.6 for ; Tue, 23 Mar 2021 18:07:16 -0700 (PDT) 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=ROffmMGKr17jDLXAnqHPgcKmYbffcbj+QeNzV3+R/Go=; b=cn7bjILIkCSL01FoB/ruxsofWaGNMjMqpRvTiF34//Sp0hSWAd96n16Of2tIV5PQHd wLDtas6Mp7xKZ/9w09w49/mHIVfc4LpVF0s1hdfFZtiN+MI0K3OLk+idDYXNetW32T7l ByRJN5Up5uhizP/3HOEH2gcThKxPle1ftCa4FXzVcaNtVyq8IQF0l6tz0ouVwlDpTjCm GMGzfrvFzzyFQreXzV6Q+kZzKa7h4q8cQ7KJK3oskW+yyhe1zOIjDpyW+T3wVeORHbLj 9izVCSSMlgEy7uPrwYjYfVmvyZ0y4mNlGmCPQgeu4ls3SZN+twpNLmmSHVl3/0zOWahv mTEA== X-Gm-Message-State: AOAM5336NBuAdF4xKb5QcmP2lNGBEa9LMwzPVViVkpzugAVIHX+s+eFS K/uk8lhdaskJNy5pVA0vFI89TToQXNL/xolkXKE/nj5vd0P8djV/C+lX8jBIUmp5P9w+iVunZyw cOEbA0ew5bQdUxV3GG5o20u24yg8EikqhHNIXbVAg4m3RQdbLWE4d71ZmSfgYolQjVT/e15MAyg == X-Received: by 2002:a17:90a:e2ca:: with SMTP id fr10mr756288pjb.154.1616548034629; Tue, 23 Mar 2021 18:07:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhCJ/YfNKkJVREtpqXTsB88GBJLqb6F+NdW2Fl2tVSfYCq4bMi4hT1Xiuxp340P7zCv/zJGw== X-Received: by 2002:a17:90a:e2ca:: with SMTP id fr10mr756259pjb.154.1616548034293; Tue, 23 Mar 2021 18:07:14 -0700 (PDT) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id t18sm379219pgg.33.2021.03.23.18.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 18:07:14 -0700 (PDT) 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 v9 3/5] xfs: introduce xfs_ag_shrink_space() Date: Wed, 24 Mar 2021 09:06:19 +0800 Message-Id: <20210324010621.2244671-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210324010621.2244671-1-hsiangkao@redhat.com> References: <20210324010621.2244671-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. Reviewed-by: Darrick J. Wong Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ag.c | 115 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_ag.h | 2 + 2 files changed, 117 insertions(+) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index 9331f3516afa..c68a36688474 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,116 @@ 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 delta) +{ + struct xfs_alloc_arg args = { + .tp = *tpp, + .mp = mp, + .type = XFS_ALLOCTYPE_THIS_BNO, + .minlen = delta, + .maxlen = delta, + .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; + /* some extra paranoid checks before we shrink the ag */ + if (XFS_IS_CORRUPT(mp, agf->agf_length != agi->agi_length)) + return -EFSCORRUPTED; + if (delta >= agi->agi_length) + return -EINVAL; + + args.fsbno = XFS_AGB_TO_FSB(mp, agno, + be32_to_cpu(agi->agi_length) - delta); + + /* + * Disable perag reservations so it doesn't cause the allocation request + * to fail. We'll reestablish reservation before we return. + */ + 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. + */ + xfs_trans_bhold(*tpp, agfbp); + err2 = xfs_trans_roll(tpp); + if (err2) + return err2; + xfs_trans_bjoin(*tpp, agfbp); + 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, -delta); + be32_add_cpu(&agf->agf_length, -delta); + + err2 = xfs_ag_resv_init(agibp->b_pag, *tpp); + if (err2) { + be32_add_cpu(&agi->agi_length, delta); + be32_add_cpu(&agf->agf_length, delta); + if (err2 != -ENOSPC) + goto resv_err; + + __xfs_bmap_add_free(*tpp, args.fsbno, delta, 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..4535de1d88ea 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 delta); 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 Wed Mar 24 01:06:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12159947 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=-19.0 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 EDA41C433E2 for ; Wed, 24 Mar 2021 01:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7A47619F1 for ; Wed, 24 Mar 2021 01:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233976AbhCXBHo (ORCPT ); Tue, 23 Mar 2021 21:07:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45323 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234227AbhCXBHd (ORCPT ); Tue, 23 Mar 2021 21:07:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616548041; 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=8d26PrDjEs+c1iStkdo3MCyggTrrQtC6w7bWrDJA2Fw=; b=LH2l7Xc2niccpNKAHIoKYjq4As7s1nWkjgW3hy5/H3sPOE/MgkdBnyK9nOEz2A7nGeaE8l y+8m9TZGjooZsgq9do3o90NS4lLI5loHQNMHvjiTkWOb/jadoYFfV/14LNrIGgRM1WHvCi CnZtiF42SzsiY4QP7G5ea2V/6YnPrFo= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-26-6EzwSAygPNS742My13kVnQ-1; Tue, 23 Mar 2021 21:07:20 -0400 X-MC-Unique: 6EzwSAygPNS742My13kVnQ-1 Received: by mail-pl1-f197.google.com with SMTP id l19so54927plc.14 for ; Tue, 23 Mar 2021 18:07:20 -0700 (PDT) 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=8d26PrDjEs+c1iStkdo3MCyggTrrQtC6w7bWrDJA2Fw=; b=mrVdWd/mb2/SVGcVBnSzsJb9h8juJps+/TzCAeDF/VRY9n0wi8J1oK0jmd+5xwLrWD B5uq/EKco0p83iIsrM8TxYDc10gbW1vZklw+HNjzJreSMNGobxTMP7NI3stDG8IX5QXq UPPcspA07Ot+x/8NMklJ0WMqKXDRqTi6dwhK6uUT9IvGUH9TevAxxREi+GLnw1fxC1JG ACIQnDOhOm/a7DSehxCNw1Qr8Zx8Aysb0OFcPkp4xwCt+i9DRibV2a8s3A5TjO+Sedv4 SQ3PvxXNiZN5FP+Mxj7FCtjJrFKJzq4tQDlkdqeNH+Priz3UwRqrga5A9U2GOYtSP1Dh /WFw== X-Gm-Message-State: AOAM531w1jI53XPbEf4Nynf6rZ2RJXHq8Ii+Xt/HxsltxjQKXXJnIsHp /NYGld6aTi+WDPq7C6keN3IbeCl480+/0G24+YdaTAlILW1RVGzLPljNuVpRcOE8vL7CjulkJK0 C5uZGpzEbdtYNGZP51PibWmcx/JpQOCN0Tbz9NsbFV8iAAL+O+YrvUCpVuUQHHHF2grkKFwH2vw == X-Received: by 2002:a62:6413:0:b029:1f3:a5b4:d978 with SMTP id y19-20020a6264130000b02901f3a5b4d978mr859769pfb.44.1616548038806; Tue, 23 Mar 2021 18:07:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxj3zyymnuuyBajPuXsla9lJlaJouqnm5r+/jw0bp+2ElR3IzSseOcEMi5X5Kz9JJAmduUh2Q== X-Received: by 2002:a62:6413:0:b029:1f3:a5b4:d978 with SMTP id y19-20020a6264130000b02901f3a5b4d978mr859745pfb.44.1616548038452; Tue, 23 Mar 2021 18:07:18 -0700 (PDT) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id t18sm379219pgg.33.2021.03.23.18.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 18:07:18 -0700 (PDT) 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 v9 4/5] xfs: support shrinking unused space in the last AG Date: Wed, 24 Mar 2021 09:06:20 +0800 Message-Id: <20210324010621.2244671-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210324010621.2244671-1-hsiangkao@redhat.com> References: <20210324010621.2244671-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. Reviewed-by: Darrick J. Wong Signed-off-by: Gao Xiang --- fs/xfs/xfs_fsops.c | 84 +++++++++++++++++++++++++++------------------- fs/xfs/xfs_trans.c | 1 - 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index d1ba04124c28..9457b0691ece 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -91,23 +91,25 @@ xfs_growfs_data_private( xfs_agnumber_t nagcount; xfs_agnumber_t nagimax = 0; xfs_rfsblock_t nb, nb_div, nb_mod; - xfs_rfsblock_t delta; + int64_t delta; bool lastag_extended; 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))) + 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); @@ -115,10 +117,16 @@ 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; + /* + * Reject filesystems with a single AG because they are not + * supported, and reject a shrink operation that would cause a + * filesystem to become unsupported. + */ + if (delta < 0 && nagcount < 2) + return -EINVAL; + oagcount = mp->m_sb.sb_agcount; /* allocate the new per-ag structures */ @@ -126,15 +134,22 @@ 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_extended); + if (delta > 0) + error = xfs_resizefs_init_new_ags(tp, &id, oagcount, nagcount, + delta, &lastag_extended); + else + error = xfs_ag_shrink_space(mp, &tp, nagcount - 1, -delta); if (error) goto out_trans_cancel; @@ -169,28 +184,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_extended) { - 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_extended) { + 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 b22a09e9daee..052274321993 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -436,7 +436,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 Wed Mar 24 01:06:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12159951 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=-19.0 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 33718C433E5 for ; Wed, 24 Mar 2021 01:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D687619F8 for ; Wed, 24 Mar 2021 01:08:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234056AbhCXBHo (ORCPT ); Tue, 23 Mar 2021 21:07:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42779 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234223AbhCXBHd (ORCPT ); Tue, 23 Mar 2021 21:07:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616548045; 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=RDCUbE9ayuguhvHZLdqXgCCucvyzxuogayKdE4uOcvU=; b=J7a2BbSRi85+leazkmNY1Y0samrcwQDxVf34kO48lABWHkiyBHNMfpw5ih7R9tb80ZVwl/ XhxYSuV6l4+m+S7hhYsO7/nRRHZI72p/CgczN4F3OnJoZHiBMPFsvbQLyEtJR/xamm1zJJ gjfucMstTg8RqcmnC9BnnGuGf3urcHc= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-m8JwEcQBOmeb2C_HwHJiGQ-1; Tue, 23 Mar 2021 21:07:24 -0400 X-MC-Unique: m8JwEcQBOmeb2C_HwHJiGQ-1 Received: by mail-pg1-f197.google.com with SMTP id j4so537206pgs.18 for ; Tue, 23 Mar 2021 18:07:23 -0700 (PDT) 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=RDCUbE9ayuguhvHZLdqXgCCucvyzxuogayKdE4uOcvU=; b=Ett+JODqzyr+gy6Jm+BAz5/cLYyvQzPvNn3JvjAwonwonHVWj0n6harbHd8PyGlLNQ pQVvIyG4Of/Wv0SbUeGDm+PmoIdmo/5wYOFBKSsfR96BIlGT75Up58J+mRpubj2Jqufi d1/1PxjmceldU/0v74US3pa7qu+9Dl2+l7ntKJESLSCIwO4c14pPDKpw3boXoQOt3wXW oz8StyF8n448dE8JiMCK5HCTy+KAlfVVriqJvQ7RFooVbPwtfoaYvQAe9BsnNA9w/OOU StFZs0vuCF8IOFBQklyAahIc8C3AhfOUfMdFZ3Zlnfuxrx7e1PMIFHOmr7+SUNMhOhob kyBQ== X-Gm-Message-State: AOAM531k1rvzgMpaUFBvopb5T52R5XcG08jKzDPF2HRlbYuAzXt2k7ij jIjI9p5wTwrvHPhO7SnHY1vnWanNhi97rdsr0sHF3YhxYPpTQsBQG/CFkzjWMYPIswkBcEB0X9l jPZl74EM1jMzJPopmfMoJAGIedO1oVXTZ/WtfvUZNrvW/GzrhjWnCa2bzehM+bZmr7w1EUKBxHw == X-Received: by 2002:a17:902:7444:b029:e4:30bf:8184 with SMTP id e4-20020a1709027444b02900e430bf8184mr976802plt.45.1616548042844; Tue, 23 Mar 2021 18:07:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGM8Gae0NGOz2nm+5XkKsZ/mlmlbd46KK/4ndvdelYIab5eCWcSRJm3lDCp01LG+BxTyaUtw== X-Received: by 2002:a17:902:7444:b029:e4:30bf:8184 with SMTP id e4-20020a1709027444b02900e430bf8184mr976777plt.45.1616548042556; Tue, 23 Mar 2021 18:07:22 -0700 (PDT) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id t18sm379219pgg.33.2021.03.23.18.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 18:07:22 -0700 (PDT) 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 v9 5/5] xfs: add error injection for per-AG resv failure Date: Wed, 24 Mar 2021 09:06:21 +0800 Message-Id: <20210324010621.2244671-6-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210324010621.2244671-1-hsiangkao@redhat.com> References: <20210324010621.2244671-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 Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_ag_resv.c | 6 +++++- fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 3 +++ 3 files changed, 11 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..a23a52e643ad 100644 --- a/fs/xfs/libxfs/xfs_errortag.h +++ b/fs/xfs/libxfs/xfs_errortag.h @@ -58,7 +58,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. @@ -101,5 +102,6 @@ #define XFS_RANDOM_BUF_IOERROR XFS_RANDOM_DEFAULT #define XFS_RANDOM_REDUCE_MAX_IEXTENTS 1 #define XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT 1 +#define XFS_RANDOM_AG_RESV_FAIL 1 #endif /* __XFS_ERRORTAG_H_ */ diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 185b4915b7bf..f70984f3174d 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c @@ -56,6 +56,7 @@ static unsigned int xfs_errortag_random_default[] = { XFS_RANDOM_BUF_IOERROR, XFS_RANDOM_REDUCE_MAX_IEXTENTS, XFS_RANDOM_BMAP_ALLOC_MINLEN_EXTENT, + XFS_RANDOM_AG_RESV_FAIL, }; struct xfs_errortag_attr { @@ -168,6 +169,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 +210,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, };