From patchwork Fri Mar 5 02:56:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12117427 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 ABC22C433DB for ; Fri, 5 Mar 2021 02:57:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 78DC164FD4 for ; Fri, 5 Mar 2021 02:57:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229505AbhCEC5u (ORCPT ); Thu, 4 Mar 2021 21:57:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52136 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbhCEC5t (ORCPT ); Thu, 4 Mar 2021 21:57:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614913069; 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=vCCpatKjmI8AkfBL08Jn6zsTwQLRzUEgQOAxEIiY/p4=; b=M5DMXce/0aaZ3Uxa0O7YLom1D3AtVUNwltOlUbGiNbu122hI+fnq/oKIwvewFVxDUQW2zD GamLsByJDaR7JOV/ihw/ar95g8B9Ts3yrMAV2+BGVwc5AlTDKW59bGqppLFCqXF8po6cuo cPgp18bNxS/Jxc0EILE9pfssMw4lIqA= 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-574-jTHXgZ7YPXCfC5ng-nAk_g-1; Thu, 04 Mar 2021 21:57:45 -0500 X-MC-Unique: jTHXgZ7YPXCfC5ng-nAk_g-1 Received: by mail-pf1-f197.google.com with SMTP id t69so402910pfc.0 for ; Thu, 04 Mar 2021 18:57:45 -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=vCCpatKjmI8AkfBL08Jn6zsTwQLRzUEgQOAxEIiY/p4=; b=hzalpqN2S7/UgiZiCyTmioaERfxzz7Lm3i62v1Mobw+GabXTWSwWgqlRBdCfHQjSJZ bDjYgg2LS9KoRChiB4q68ZagL0HVf3JbZOBldK/JTA0wqUt+mjWd5ARAnXt4BdKxMTWU elpi8OAiA2l8qDygun77f1qvlUJ8qCz0WHYVK24957Dau1V/xEQiRO0O3OnKshEDXr5S CH25WBKvoFy96VnVkC4dXzNiwzcOXERp0aNuNT5kfOkBSxEWr44VtTKn5r2roNJGnUyV d9Mx7gHaLfTYFDt0dDofqrh1j1V6JNJVBYAroiOPD26eGbeqOcXpL55+nrErcy2mg26Q qvYQ== X-Gm-Message-State: AOAM53180PzSplxQSX4fprLUJI7oI7sNT0gHbqipNCIu1gYzX8HJOxVL et4Jko7kpGtaaAwxpT2ykUCR3gK7ABZR1TrsSGOGjh5Ck4mqpfgVGw3effn0PqV/v2WhINxxUdh SLhGHDREkZcy7TVCb+KaZs3V/OquhKoSp6OrSQ0ZStWJ07ii5QOuuoGYCFonUj8vZaLw2bKW+5A == X-Received: by 2002:a17:90a:7309:: with SMTP id m9mr7925467pjk.23.1614913064642; Thu, 04 Mar 2021 18:57:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJx8H6NdxUyrxWZNJXpJVNjEC/S+uch9H41/D5ZeLSXEIGyX7t7dfZw6CNw5zZ14MPlUDQNsXw== X-Received: by 2002:a17:90a:7309:: with SMTP id m9mr7925441pjk.23.1614913064345; Thu, 04 Mar 2021 18:57:44 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m19sm533414pjn.21.2021.03.04.18.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 18:57:44 -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 v8 1/5] xfs: update lazy sb counters immediately for resizefs Date: Fri, 5 Mar 2021 10:56:59 +0800 Message-Id: <20210305025703.3069469-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210305025703.3069469-1-hsiangkao@redhat.com> References: <20210305025703.3069469-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 Signed-off-by: Gao Xiang Reviewed-by: Brian Foster --- 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 Fri Mar 5 02:57:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12117429 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 6F0E8C433E0 for ; Fri, 5 Mar 2021 02:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B37F64FE9 for ; Fri, 5 Mar 2021 02:57:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229837AbhCEC5x (ORCPT ); Thu, 4 Mar 2021 21:57:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38992 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbhCEC5x (ORCPT ); Thu, 4 Mar 2021 21:57:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614913073; 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=KiRErMeigNgDcmq9JJTRtbgxvUKq5A68Wk3FeYjftXc=; b=h7i2+7JOratoHQEcCDmE5kpNQvGQ5/E0A1ONKcTRkRdaQnFHsLGgxpsTGqqImXBR5J5hSh JQNSLpsLlfoghqelwli5Cv3IwD8EGnJw7yPLn31jycUlkeJ2YB0ovZZYoa5Yrar8Kyhb7c itxUCSqNcJfRvizkWj+9R703PU02Xyk= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-145-h_AuRX3ZNlucgq13Sg94vA-1; Thu, 04 Mar 2021 21:57:51 -0500 X-MC-Unique: h_AuRX3ZNlucgq13Sg94vA-1 Received: by mail-pj1-f72.google.com with SMTP id m1so445662pjs.9 for ; Thu, 04 Mar 2021 18:57:51 -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=KiRErMeigNgDcmq9JJTRtbgxvUKq5A68Wk3FeYjftXc=; b=VLtdoyVL5sGJkSmroSHkMUBXO7JlNtHd/PJEsIH+zyVbsSoNOqYtfcYmR5MXIgHFRZ ZtkCGaPvyB8I2pAmVvMneH+LDNX2d/NviSXe/rVzNWqmf2OQVpbHpc3UAuC+KSVMJms9 ohjZ0WY4V083Ganc8XYebT4qeNLXasfqLyKTu9Ok1YiVuLVEI4fQFZ5xeD1Pc7QQMxrF ikmwu8xKRksSUcpxi89qjTNl9jcsk2eqO9TWxsP9bQnJJgiK4Gy7QDPUXZ8NyZjseNY4 siqIr6CI9bvk6JHdTvR2oDaurSD3Rtcg8tStOQUNDfOLBvbxQxlMqCgA5QD28uqWiYNT TH5A== X-Gm-Message-State: AOAM530YBc/am1HrhYZlChBC9lYe8MtrMS92YplUjbbVmUo6g/36+0rp qCmduROxdDy404CppR3CLCWuHdElTQS6FOZ7ipp1/vzbhqxs3EpRstpvI0WPhyHuQYR3fQ3Pafg 5Bj3BPKV9Vm+ycLDkNtFh4gD/tGfmee3tyxZNOA06h4IvaI5FDQssUG8YJmrMfazpLDP8u48MpQ == X-Received: by 2002:a17:902:cb0b:b029:e5:b670:d905 with SMTP id c11-20020a170902cb0bb02900e5b670d905mr6999496ply.18.1614913069996; Thu, 04 Mar 2021 18:57:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfaj5jCGtuwKLDt14l+cV41znEqG5ySGSiofASi9oDwYsMsZMmagZnVX8iYJVFUSyGWDQ77g== X-Received: by 2002:a17:902:cb0b:b029:e5:b670:d905 with SMTP id c11-20020a170902cb0bb02900e5b670d905mr6999461ply.18.1614913069491; Thu, 04 Mar 2021 18:57:49 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m19sm533414pjn.21.2021.03.04.18.57.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 18:57:49 -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 v8 2/5] xfs: hoist out xfs_resizefs_init_new_ags() Date: Fri, 5 Mar 2021 10:57:00 +0800 Message-Id: <20210305025703.3069469-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210305025703.3069469-1-hsiangkao@redhat.com> References: <20210305025703.3069469-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..fc9e799b2ae3 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 */ @@ -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_resetagres; 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_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 +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 > 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 +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_resetagres) { struct xfs_perag *pag; pag = xfs_perag_get(mp, id.agno); From patchwork Fri Mar 5 02:57:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12117431 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 D2324C433DB for ; Fri, 5 Mar 2021 02:57:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A745364F52 for ; Fri, 5 Mar 2021 02:57:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229861AbhCEC56 (ORCPT ); Thu, 4 Mar 2021 21:57:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32987 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbhCEC55 (ORCPT ); Thu, 4 Mar 2021 21:57:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614913076; 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=lf8HT1sgQOy5PL4FdvymMkk3T/a0i14JWEXeaTwHcy0=; b=C9ipw8V3Bw+DRQ7hB3T5+1Up9/QEhT25fDn2dCcADAEXnPz9BfokwV1xqjLAkO+oYCRDWe VkCvQmrvm+dZ/FAbKcspeeIbk/QOeLlVl3Jm+g776P7l2Nay1dEuJELVzCdoWiHT/sHFkR JCzwSEbqK0b0LYj7vjH444hGqfr1sHc= Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-EI0TYuC4PiC7z9t0n4NY3A-1; Thu, 04 Mar 2021 21:57:55 -0500 X-MC-Unique: EI0TYuC4PiC7z9t0n4NY3A-1 Received: by mail-pf1-f198.google.com with SMTP id b12so373410pfb.15 for ; Thu, 04 Mar 2021 18:57:55 -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=lf8HT1sgQOy5PL4FdvymMkk3T/a0i14JWEXeaTwHcy0=; b=j1o7MUiqdjRl+rL0TzYDcODnTwP2AsYhtWs2tRWaGYlOhqcdy0w3lzAqqoG2ipyoEr sAMrMEgb3X1deGFCUz+WhtmCUh3T8x1Xziu7XQl7JOZqoWdB2NftFIWgp7sK3IQTDIRx tuIJHHuq2Y5LOMbIkkaVMJoyyrVF8b/+A/hs7CAxeVIiAx1XPdqfmUciYKg62pGROWj5 KK4PRhbeTIveqrfCnVPNTZOAxbv7hfTOMJAIkjTI6uVKuhB0yl7dJXsALfc0hvl5TxJx MV/jtkvgE3mI6aQ0EnEIMbkkLxMhFt7trI5yws69sX/Or80y9V5nA7wdez3AqB6momEo Uz2A== X-Gm-Message-State: AOAM530PxZ+LP9bUnRZO5rphz+I8hO6XoGkKkA4722D4kt0l8pKJgyVk 2WTdxtujW4tgrqPhghyyFLVD4aWUfeVmYI98WhIWHvpEaYs6axMV5+O0XBNZPQPhH4C2oYUjne6 vPbNsG0N58qRmD6THxVDbUipjU+tI0GS1oiJHua9lHvFdAvD5VPJBiV35seoBZlNVidldspeScg == X-Received: by 2002:a17:90a:314:: with SMTP id 20mr8041165pje.72.1614913074093; Thu, 04 Mar 2021 18:57:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJyv3URLjBUX6aoSa263sgVOTu5eSThSsf76COTkAm+7vOdaFQzbAUXUu+kbX7pZp0Fb9MYyig== X-Received: by 2002:a17:90a:314:: with SMTP id 20mr8041139pje.72.1614913073786; Thu, 04 Mar 2021 18:57:53 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m19sm533414pjn.21.2021.03.04.18.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 18:57:53 -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 v8 3/5] xfs: introduce xfs_ag_shrink_space() Date: Fri, 5 Mar 2021 10:57:01 +0800 Message-Id: <20210305025703.3069469-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210305025703.3069469-1-hsiangkao@redhat.com> References: <20210305025703.3069469-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 Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_ag.c | 111 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_ag.h | 4 +- 2 files changed, 114 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index 9331f3516afa..1f6f9e70e1cb 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,112 @@ 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; + 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); + + /* 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, -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..41293ebde8da 100644 --- a/fs/xfs/libxfs/xfs_ag.h +++ b/fs/xfs/libxfs/xfs_ag.h @@ -24,8 +24,10 @@ 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); + struct aghdr_init_data *id, xfs_extlen_t delta); int xfs_ag_get_geometry(struct xfs_mount *mp, xfs_agnumber_t agno, struct xfs_ag_geometry *ageo); From patchwork Fri Mar 5 02:57:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12117433 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 E0755C433E0 for ; Fri, 5 Mar 2021 02:58:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFB9164F52 for ; Fri, 5 Mar 2021 02:58:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbhCEC6C (ORCPT ); Thu, 4 Mar 2021 21:58:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60899 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbhCEC6B (ORCPT ); Thu, 4 Mar 2021 21:58:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614913081; 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=wkY3FTAIacYrwuPMXIJvXomIx2MVTrRPaR5z08syAQE=; b=RUJrWFRRYQl3EKLDy4Ydp7Yypclh/2PIuXJLsumHj4w1pjJso2meAp4vTAB6aae+MbT844 tplXqBtuJ3/l5mQ+TF080z/ak+JvFCuDvJ4pdM0EDTrfIU2pyUueT8MnzxFL3XESA/8TFD SRjW4wD2U7LKhvppmCJu+YzXB9WiEs8= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-3DQogZdkMK2CclYbdosclg-1; Thu, 04 Mar 2021 21:57:59 -0500 X-MC-Unique: 3DQogZdkMK2CclYbdosclg-1 Received: by mail-pj1-f69.google.com with SMTP id r18so436478pjz.1 for ; Thu, 04 Mar 2021 18:57:59 -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=wkY3FTAIacYrwuPMXIJvXomIx2MVTrRPaR5z08syAQE=; b=UCh67uk5C7JDj8gJDHZt63hWRokVhAKSviktpFjoJCXQzbQeDLTgrs0Mp/o0Y6Gwh2 Truh3C1AHf2uSDWGH9H6TXVB27u1YBlJHEKm/wqfJBsL6arCeT0NxBGJGiq+1TbW0cK4 zfzgeWlNCLZm02IrzlnLkecc9INsiTBYATW/qZrjH220Vb2nq7tyyvD9Iwdxm20lb59l VsOEyT9Ns8UydeKlLWfoXZt6fvNuSy8XzrXGH0Xrys6GAeOpq4a33Adaa4kqanSh0xff fomgFaRnYKRPLqgJrGdVV/w6HUntbUJaarsSYMPb9yhR1seY73B2u9N5fzEWNyOQ2D6u l1xw== X-Gm-Message-State: AOAM533eiVyuPFBME60z8u3b9s0WIxlZwqH3dtfFoDy5HCOyjZqjfcVD A5DuXrDPM7hNuKVi4Wg5F1qn/cllheobwWIQpLLMeISsBFebPuZadmMc3pdz1VZPJF9gbluXRZV TUms4cq6NvCcdP1ZWp4ORoKbLi+cx/5ujHzWe9rEnYvwv4ESNufqeND4e7HEHLVfvDURgxsrJ4w == X-Received: by 2002:a17:90b:1950:: with SMTP id nk16mr7774736pjb.140.1614913078279; Thu, 04 Mar 2021 18:57:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJziHc/lr/M9mh0jIYW3SaN3UkEaOUulhUOpkb8Lqcb6nC/FlSfDEaNzbHiHiXQHEfcn/patYw== X-Received: by 2002:a17:90b:1950:: with SMTP id nk16mr7774696pjb.140.1614913077830; Thu, 04 Mar 2021 18:57:57 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m19sm533414pjn.21.2021.03.04.18.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 18:57:57 -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 v8 4/5] xfs: support shrinking unused space in the last AG Date: Fri, 5 Mar 2021 10:57:02 +0800 Message-Id: <20210305025703.3069469-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210305025703.3069469-1-hsiangkao@redhat.com> References: <20210305025703.3069469-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 | 88 ++++++++++++++++++++++++++++------------------ fs/xfs/xfs_trans.c | 1 - 2 files changed, 53 insertions(+), 36 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index fc9e799b2ae3..71cba61a451c 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -91,23 +91,28 @@ 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_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); @@ -115,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 */ @@ -126,15 +136,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_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; @@ -145,7 +162,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); @@ -169,28 +186,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 Fri Mar 5 02:57:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gao Xiang X-Patchwork-Id: 12117435 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 2AAF4C433DB for ; Fri, 5 Mar 2021 02:58:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2AAA64FDB for ; Fri, 5 Mar 2021 02:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230058AbhCEC6F (ORCPT ); Thu, 4 Mar 2021 21:58:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21165 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229528AbhCEC6F (ORCPT ); Thu, 4 Mar 2021 21:58:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614913084; 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=iBhRLLMdvu1HSZMDSsEPAkqjPRtxXkjCEOsIFGoCMR1QGMBpPgRbt3o4j6WWnG/mAirprS +u2ouhRE2Q8I6XdPshn+B0V8+C/LIV56puVwNw1+mCe2MV6JHEDXgoVxCbLux2YmoAYSq2 MxbFMHthe7zXOAV524gAFDuk6dMwK5s= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-414-Fssbe66gOAawIdsgpMLr6w-1; Thu, 04 Mar 2021 21:58:03 -0500 X-MC-Unique: Fssbe66gOAawIdsgpMLr6w-1 Received: by mail-pg1-f199.google.com with SMTP id x36so312485pgl.8 for ; Thu, 04 Mar 2021 18:58:03 -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=RDCUbE9ayuguhvHZLdqXgCCucvyzxuogayKdE4uOcvU=; b=B5VrbES4hqLmjAAy0l/WkjR6zQPVQOcn8KXqqstIHYOjobvgNQqNaZzelU4dYEBJjH KP6ZeHPLsqgvC7fSDHuzoH314LoYrqn4hFAHHh1ZP0nhJzLTZoL5e8+RgTrJYyWfCs1b ykD2kka9pQG1k5bE3Q+ChZ36uQRZi6k4MTCeY4nccXHEJEIFdCVUV6M6XBfLccDBORnT Ey5be1owDgi0/fIQKyNHng1sznO0p/i+lR4fnMh/Jbo5yOjHujhbFwhKsi3oM1LTi4TQ Ly7AyxcuO9CKoSm2ntD3c6AJor8sY3Z5PeyyuyPtfydHOPUkRReB93pdFPaKmcfrW4l9 kySg== X-Gm-Message-State: AOAM530n4uteXBDuak9H1uNx2bx5bHyaY8cpfT+JXlrMMBFNmDgq/TZC xKbvjx5fUJdRVfFv8Zwz3nFNZdgAhYt/qjJKbSnKwKJCM2sykgNy1czInopUq/u5AywKqfobAZa lTJtqnlRuXlyBrrrfkAcLCebBlkLXhX2NJ8x7RRAK9TtmgFc/VTkMO+fsMYA5ZDGt+EqaTKIDnQ == X-Received: by 2002:a17:90a:4586:: with SMTP id v6mr6480714pjg.129.1614913082368; Thu, 04 Mar 2021 18:58:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwczvjOaRpMGMoasA1x7+UJ9mMCUyMQs5t3UCWwipz6s/fD9hB0BFXDDW5NTJVfXC1TXdwFgQ== X-Received: by 2002:a17:90a:4586:: with SMTP id v6mr6480678pjg.129.1614913081967; Thu, 04 Mar 2021 18:58:01 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id m19sm533414pjn.21.2021.03.04.18.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 18:58:01 -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 v8 5/5] xfs: add error injection for per-AG resv failure Date: Fri, 5 Mar 2021 10:57:03 +0800 Message-Id: <20210305025703.3069469-6-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210305025703.3069469-1-hsiangkao@redhat.com> References: <20210305025703.3069469-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 | 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, };