From patchwork Tue Jan 26 12:56: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: 12046469 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 476F8C433E0 for ; Tue, 26 Jan 2021 12:59:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EF5F923109 for ; Tue, 26 Jan 2021 12:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391957AbhAZM7F (ORCPT ); Tue, 26 Jan 2021 07:59:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31560 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404133AbhAZM6g (ORCPT ); Tue, 26 Jan 2021 07:58:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611665830; 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=k2a8zh6/Vjgp6yyKkfoZEgFd0CwCEMmLHh5QE+DIIBs=; b=O9d+kS537QjlgyZVmLeljWFkcokxa6EWnqGkdw4VU39ncIr6YxCxMjRHd/2uGTneO7HGQq pBo3UxQDOo3cuV1YtcAVqjKZCf4xGopjPhxZRNCg8Db9BpeAkjXArbcAqPsBosw7CbTc92 14Jd6iUKm7UhvoLIu+V+JqYOHVXsaXw= 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-398-47mZkMW3PBGK78n0I5-Y3A-1; Tue, 26 Jan 2021 07:57:07 -0500 X-MC-Unique: 47mZkMW3PBGK78n0I5-Y3A-1 Received: by mail-pf1-f200.google.com with SMTP id o77so8010101pfd.9 for ; Tue, 26 Jan 2021 04:57:07 -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=k2a8zh6/Vjgp6yyKkfoZEgFd0CwCEMmLHh5QE+DIIBs=; b=UQidwTkiR4hr4ay4YDmaz7S5mlH6DrKPTeT6zR+DEortPqk9B9rLXg+P3QFR08ryDb VWuFnpeqXGwluk5pgyZ6awhmICYztfqb9y6vt+WBbJ05I1H3qvvkmhCUfZuPyCleI7ls yQTg0td2og+tw7erntjv5TYCkuKL7tkZwLiw3oWfVlmtH2EwzabQ6cOaIZU+y/A6p34w gl6u96FENaQR8Z+6mPbSAJjHZIUZmsRI4hw2qmT3JXWRKxDqMeG4yRFkBJVfLfYzLfm5 msFJSHIMu4QdGBvyw5qXKa82tP4eq7Rc5oaoBkLsxGXAEmozmJqcOBX9XGWGqagxcs58 FT7w== X-Gm-Message-State: AOAM5328wgiPhcrebzcsow4rZC8pqbHlJ2bVusiiZsZydNDvkDXPf8ZG TfUZLzuI4VKaS63quGc32C4Qt8gnd/32RsM55QDuB0nyk5U8xyJJRXDG6ShuS8AkcfqCxNq6S6+ QbW2WB0n3h9TpBIHJXUmT9SmUB0CYrYxytgXFj3z4uz3GwUevN8mcgT30mGputCjWxZVde54ASw == X-Received: by 2002:a17:90a:8006:: with SMTP id b6mr6112684pjn.108.1611665826663; Tue, 26 Jan 2021 04:57:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxvTXnuoHaNDjyEcOOevCjSmE8zrdXkvd+MU2yhpmUhWe4+qpgPWOjLsaOns4oAiJNqhdt/Tw== X-Received: by 2002:a17:90a:8006:: with SMTP id b6mr6112660pjn.108.1611665826423; Tue, 26 Jan 2021 04:57:06 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b203sm19243174pfb.11.2021.01.26.04.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 04:57:06 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Christoph Hellwig , Gao Xiang Subject: [PATCH v6 1/7] xfs: rename `new' to `delta' in xfs_growfs_data_private() Date: Tue, 26 Jan 2021 20:56:15 +0800 Message-Id: <20210126125621.3846735-2-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210126125621.3846735-1-hsiangkao@redhat.com> References: <20210126125621.3846735-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org It actually means the delta block count of growfs. Rename it in order to make it clear. Also introduce nb_div to avoid reusing `delta`. Reviewed-by: Darrick J. Wong Signed-off-by: Gao Xiang Reviewed-by: Brian Foster --- fs/xfs/xfs_fsops.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 959ce91a3755..62600d78bbf1 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -32,8 +32,8 @@ xfs_growfs_data_private( int error; xfs_agnumber_t nagcount; xfs_agnumber_t nagimax = 0; - xfs_rfsblock_t nb, nb_mod; - xfs_rfsblock_t new; + xfs_rfsblock_t nb, nb_div, nb_mod; + xfs_rfsblock_t delta; xfs_agnumber_t oagcount; xfs_trans_t *tp; struct aghdr_init_data id = {}; @@ -50,16 +50,16 @@ xfs_growfs_data_private( return error; xfs_buf_relse(bp); - new = nb; /* use new as a temporary here */ - nb_mod = do_div(new, mp->m_sb.sb_agblocks); - nagcount = new + (nb_mod != 0); + nb_div = nb; + nb_mod = do_div(nb_div, mp->m_sb.sb_agblocks); + nagcount = nb_div + (nb_mod != 0); 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; } - new = nb - mp->m_sb.sb_dblocks; + delta = nb - mp->m_sb.sb_dblocks; oagcount = mp->m_sb.sb_agcount; /* allocate the new per-ag structures */ @@ -89,7 +89,7 @@ xfs_growfs_data_private( INIT_LIST_HEAD(&id.buffer_list); for (id.agno = nagcount - 1; id.agno >= oagcount; - id.agno--, new -= id.agsize) { + id.agno--, delta -= id.agsize) { if (id.agno == nagcount - 1) id.agsize = nb - @@ -110,8 +110,8 @@ xfs_growfs_data_private( xfs_trans_agblocks_delta(tp, id.nfree); /* If there are new blocks in the old last AG, extend it. */ - if (new) { - error = xfs_ag_extend_space(mp, tp, &id, new); + if (delta) { + error = xfs_ag_extend_space(mp, tp, &id, delta); if (error) goto out_trans_cancel; } @@ -143,7 +143,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 (new) { + if (delta) { struct xfs_perag *pag; pag = xfs_perag_get(mp, id.agno); From patchwork Tue Jan 26 12:56: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: 12046487 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 CF1CFC433E9 for ; Tue, 26 Jan 2021 13:05:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 983252312E for ; Tue, 26 Jan 2021 13:05:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727964AbhAZNFN (ORCPT ); Tue, 26 Jan 2021 08:05:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56415 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392452AbhAZM6m (ORCPT ); Tue, 26 Jan 2021 07:58:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611665835; 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=KJdGSnBzSu18VjehFOROpG0iRoxMea584ylyyu64ZCg=; b=XHGr+HDTa6hNB3IpGThv9jlBHvIJeBF1zEjZopfUoSP5GpPOlPg4sYtdP8DAY2uadlJj2s dMhGCulVqlSgDWL24TfmMr5RdQhd/ApYBp6Thd4tXZWigac9Axhp4RFps6Uj076IpljthH oFeHV8fAyioiQauvTEw5Cxm5z4Sr7P8= 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-276-ff22R4nFPpeqPF4iAwFKGA-1; Tue, 26 Jan 2021 07:57:14 -0500 X-MC-Unique: ff22R4nFPpeqPF4iAwFKGA-1 Received: by mail-pf1-f198.google.com with SMTP id x206so8009240pfc.16 for ; Tue, 26 Jan 2021 04:57:12 -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=KJdGSnBzSu18VjehFOROpG0iRoxMea584ylyyu64ZCg=; b=qYj4fc+JQbNusc7Wm6fm8v6avYBDKJInqu9c4oFuTNJhlVoElhIwC08o32eOZD37hJ DUvpTm3ExeN2EEtgldvi2FO/2N8bRwJlAWasUuWo1N4LPS9jwtG5ZoNpOzaT1WzmSBDx iNjqccieIZ8NT4DZmYEY9/OHBtzNqWBGMRFpZuxbTWcb8sWZCrLAn7nzsZkztm+XJWhF DOf3yzloEBfoZzE1TnORegeJYdqay8/aloAKUZqP0VXtOn0sX3lohTMv+sPgZHgGX9D3 LcS4bcVv3hgxStaOLWClMWBbybql/L9AUBv/Z9z81T5PPCZKwHzIHmb+SHET4NYVcKyA ztPA== X-Gm-Message-State: AOAM533u+94SbRK1eU85t9q4gPjr/tp9vwaRYFMgYkprFBjoHoQyCNBq E90iZlvc4vfaCXzdieoutApzd4VsOen1OYjPezdNqHVInYMcR1vL7BGUkHbMfXzf4J+CtJ9Jnf9 X3gIiLDXJgoJv53REUjgNEOgmv8g4NGZ3cZRIjz3TwmqQhGX5980OxddiE75AiUbCWAs9FzXBsg == X-Received: by 2002:a65:6119:: with SMTP id z25mr5528669pgu.17.1611665831775; Tue, 26 Jan 2021 04:57:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdagUpQeiZlFQ7p3wAM5hWMfm2adzsyMkrKi3BY9LG/pxJwTi0HIhpBL11ImWzbk0GZZbhYQ== X-Received: by 2002:a65:6119:: with SMTP id z25mr5528645pgu.17.1611665831465; Tue, 26 Jan 2021 04:57:11 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b203sm19243174pfb.11.2021.01.26.04.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 04:57:11 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Christoph Hellwig , Gao Xiang , Eric Sandeen Subject: [PATCH v6 2/7] xfs: get rid of xfs_growfs_{data,log}_t Date: Tue, 26 Jan 2021 20:56:16 +0800 Message-Id: <20210126125621.3846735-3-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210126125621.3846735-1-hsiangkao@redhat.com> References: <20210126125621.3846735-1-hsiangkao@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Such usage isn't encouraged by the kernel coding style. Leave the definitions alone in case of userspace users. Reviewed-by: Darrick J. Wong Reviewed-by: Eric Sandeen Signed-off-by: Gao Xiang Reviewed-by: Brian Foster --- fs/xfs/xfs_fsops.c | 12 ++++++------ fs/xfs/xfs_fsops.h | 4 ++-- fs/xfs/xfs_ioctl.c | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 62600d78bbf1..a2a407039227 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -25,8 +25,8 @@ */ static int xfs_growfs_data_private( - xfs_mount_t *mp, /* mount point for filesystem */ - xfs_growfs_data_t *in) /* growfs data input struct */ + struct xfs_mount *mp, /* mount point for filesystem */ + struct xfs_growfs_data *in) /* growfs data input struct */ { struct xfs_buf *bp; int error; @@ -35,7 +35,7 @@ xfs_growfs_data_private( xfs_rfsblock_t nb, nb_div, nb_mod; xfs_rfsblock_t delta; xfs_agnumber_t oagcount; - xfs_trans_t *tp; + struct xfs_trans *tp; struct aghdr_init_data id = {}; nb = in->newblocks; @@ -170,8 +170,8 @@ xfs_growfs_data_private( static int xfs_growfs_log_private( - xfs_mount_t *mp, /* mount point for filesystem */ - xfs_growfs_log_t *in) /* growfs log input struct */ + struct xfs_mount *mp, /* mount point for filesystem */ + struct xfs_growfs_log *in) /* growfs log input struct */ { xfs_extlen_t nb; @@ -268,7 +268,7 @@ xfs_growfs_data( int xfs_growfs_log( xfs_mount_t *mp, - xfs_growfs_log_t *in) + struct xfs_growfs_log *in) { int error; diff --git a/fs/xfs/xfs_fsops.h b/fs/xfs/xfs_fsops.h index 92869f6ec8d3..2cffe51a31e8 100644 --- a/fs/xfs/xfs_fsops.h +++ b/fs/xfs/xfs_fsops.h @@ -6,8 +6,8 @@ #ifndef __XFS_FSOPS_H__ #define __XFS_FSOPS_H__ -extern int xfs_growfs_data(xfs_mount_t *mp, xfs_growfs_data_t *in); -extern int xfs_growfs_log(xfs_mount_t *mp, xfs_growfs_log_t *in); +extern int xfs_growfs_data(struct xfs_mount *mp, struct xfs_growfs_data *in); +extern int xfs_growfs_log(struct xfs_mount *mp, struct xfs_growfs_log *in); extern void xfs_fs_counts(xfs_mount_t *mp, xfs_fsop_counts_t *cnt); extern int xfs_reserve_blocks(xfs_mount_t *mp, uint64_t *inval, xfs_fsop_resblks_t *outval); diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 3fbd98f61ea5..a62520f49ec5 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -2260,7 +2260,7 @@ xfs_file_ioctl( } case XFS_IOC_FSGROWFSDATA: { - xfs_growfs_data_t in; + struct xfs_growfs_data in; if (copy_from_user(&in, arg, sizeof(in))) return -EFAULT; @@ -2274,7 +2274,7 @@ xfs_file_ioctl( } case XFS_IOC_FSGROWFSLOG: { - xfs_growfs_log_t in; + struct xfs_growfs_log in; if (copy_from_user(&in, arg, sizeof(in))) return -EFAULT; From patchwork Tue Jan 26 12:56: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: 12046489 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 C882DC433E0 for ; Tue, 26 Jan 2021 13:05:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96B012310E for ; Tue, 26 Jan 2021 13:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391098AbhAZNFS (ORCPT ); Tue, 26 Jan 2021 08:05:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42142 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392455AbhAZM6q (ORCPT ); Tue, 26 Jan 2021 07:58:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611665840; 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=LKEJBUlECNjHIiM5A8RvrhMd5bGjwoPrgZlmgIxprYE=; b=AoB67ULK7LmAOBJgqnc9dGYPAJAHOdHMDxIJcUWl/kq+O5FHoeqYjaf4uzC7fhycWh6eJX t7juK0Egl773rckSKTU8wkXty5s1BOQ0poiQJgeRRBwnr+pysB8WmcQJQsee7wSyV3+u5j 1OX31OjVF2dTX46J0HQMR6bYNAtKF0o= 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-156-1otY0OPXMVi-Mx60Ji5R7w-1; Tue, 26 Jan 2021 07:57:17 -0500 X-MC-Unique: 1otY0OPXMVi-Mx60Ji5R7w-1 Received: by mail-pg1-f200.google.com with SMTP id q13so2553715pgs.6 for ; Tue, 26 Jan 2021 04:57:17 -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=LKEJBUlECNjHIiM5A8RvrhMd5bGjwoPrgZlmgIxprYE=; b=q5TIy5DhUTaQv222Xd3GbtDDL9rzkc8TP4Bv6bEKlRR1tzO7lrBDr80wlymOQNVW71 feBta9izer5zvyaGwnuXy+hucCLG2DMn0XBmq/9dMlZspoJSKhlEui9Al2UGmRfl0RPU SzHsrkMJU54LSuh/qWefv4tcfEeJu7ChzFd6/h4koihrDO4Y3q33a/9avAislYUbIyoO nydCIGTb0yEsnS2xuhisJDh1JvAN9Qzz7Jcof6+k07YDiOhe6zIvRtGqSPcku4Go4SOE Z+DxXZl2On8ADoA3UrSlG8mcdANDcoDrND4b7tXBHt11tKvs/RularWe7qtR6RK5DiQC DPcQ== X-Gm-Message-State: AOAM532dLA5rkJY2mo6A8teN/hA1EiM8utgrZgWnAEr6JtBRbO/F4gGw Cy/Cn+cv1b7Sqa8tM5jW0zIBTQ7478RW3UQbdzGEWq3wvqnhyOkaOF6LecbrQzs+HuaDRnyGz5o oZKXnxilJiNU6SQI0FsQB13Odlua/j0KDC72YkmK8WfyQh9/S4bErTUj6TTDdQBhlBCkW6h9DRA == X-Received: by 2002:a17:90b:8b:: with SMTP id bb11mr6215129pjb.128.1611665836014; Tue, 26 Jan 2021 04:57:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/oZezwDebu1JzrZFRBTrHR8VynkauPtZq/s8KI82dYZ6QnQWxC8aGArxKoOVB1PQc7q1akQ== X-Received: by 2002:a17:90b:8b:: with SMTP id bb11mr6215103pjb.128.1611665835720; Tue, 26 Jan 2021 04:57:15 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b203sm19243174pfb.11.2021.01.26.04.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 04:57:15 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Christoph Hellwig , Gao Xiang Subject: [PATCH v6 3/7] xfs: update lazy sb counters immediately for resizefs Date: Tue, 26 Jan 2021 20:56:17 +0800 Message-Id: <20210126125621.3846735-4-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210126125621.3846735-1-hsiangkao@redhat.com> References: <20210126125621.3846735-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 --- fs/xfs/xfs_fsops.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index a2a407039227..2e490fb75832 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -128,6 +128,14 @@ xfs_growfs_data_private( nb - mp->m_sb.sb_dblocks); if (id.nfree) xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree); + + /* + * update in-core counters now to reflect the real numbers + * (especially sb_fdblocks) + */ + 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 Jan 26 12:56: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: 12046475 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 19688C433DB for ; Tue, 26 Jan 2021 13:00:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D74D623101 for ; Tue, 26 Jan 2021 13:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404060AbhAZM7c (ORCPT ); Tue, 26 Jan 2021 07:59:32 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48392 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392458AbhAZM6u (ORCPT ); Tue, 26 Jan 2021 07:58:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611665843; 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=sDTzhpSeJaPZiyMCJtzCnkLWVqNEgtet32jXfgUpbis=; b=ApMO2/kt3ngEp+DEyHwo2w5xGRMsn+/y60x7Wv2pVFlrv99iMYe9uaBI36z8zV7AfZC4jU 860PlZeFgUVH097bGpF/BawFfEzIpUO7DvJuLrxrXCWtBfA3s7eHzYpYgRjbc7HD7rG7ZM nw0Lj8EXQ+0CV98oza3plN7yfj6j0lU= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-571-5RVeXsDaPvej8gyRlER05A-1; Tue, 26 Jan 2021 07:57:21 -0500 X-MC-Unique: 5RVeXsDaPvej8gyRlER05A-1 Received: by mail-pl1-f198.google.com with SMTP id q12so9634722plr.9 for ; Tue, 26 Jan 2021 04:57:21 -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=sDTzhpSeJaPZiyMCJtzCnkLWVqNEgtet32jXfgUpbis=; b=CukdJrF+Awaw+oGZgF2geqhzrwMNJuYeMqgh7yMUZloWqt5PTiX1Rwxe2R6ttQ/ORg 9MMVrHHgDhVPW7NogoPhgVyXxQWBfbiYSRO7KN3/QDTxIejcwonWWek3BXOjjOV/O66i ai7AGsvVltJAQ/J4R9eMbbE0pMYXWX0gIqC2L5I7vxOY/HTcWO4q5eLXtkeg5bzvgKjp X95vksr+p2XNG7PUQm48OsstGqTLlhU66VFjIRlOmbPO8brrSjQmHNMoBb+tcManSPUg PIFBN7jexeQqeMcLp6z6VUZtcK4w2YiUhHbc7jsw3/vXU5HRU5UcQj+54wWF9phVI2yI 18QA== X-Gm-Message-State: AOAM5302pV8GrgNv8Y4aCgKHPobyVfZdprCalxe0ym0P3b5lzwcnGY5W tOhm9PCEkBFu2qMmmwkX/RKBXBYSiR57QiPU/PU6FDDUmmvs7J0WADtHgXMn1QYKEJYWAYHhBIn vFUrddG71mYmz1FUGl7lMbuVxoRvNYl+nX0aYOfF1YzIi7G5cZxQpH9XPfQUHc3j1NaIbZo5WMQ == X-Received: by 2002:a17:902:ecca:b029:de:b5bc:c852 with SMTP id a10-20020a170902eccab02900deb5bcc852mr6058289plh.59.1611665840643; Tue, 26 Jan 2021 04:57:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDCGMxxRL0D6F10dx61vgDNWokSAdVV7h6HxqhkiJKXohPr19Nus94vI+QG7RopG1yTk96mg== X-Received: by 2002:a17:902:ecca:b029:de:b5bc:c852 with SMTP id a10-20020a170902eccab02900deb5bcc852mr6058258plh.59.1611665840258; Tue, 26 Jan 2021 04:57:20 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b203sm19243174pfb.11.2021.01.26.04.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 04:57:19 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Christoph Hellwig , Gao Xiang Subject: [PATCH v6 4/7] xfs: hoist out xfs_resizefs_init_new_ags() Date: Tue, 26 Jan 2021 20:56:18 +0800 Message-Id: <20210126125621.3846735-5-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210126125621.3846735-1-hsiangkao@redhat.com> References: <20210126125621.3846735-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 Reviewed-by: Brian Foster --- fs/xfs/xfs_fsops.c | 74 +++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 2e490fb75832..6c4ab5e31054 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -20,6 +20,49 @@ #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_mount *mp, + struct aghdr_init_data *id, + xfs_agnumber_t oagcount, + xfs_agnumber_t nagcount, + xfs_rfsblock_t *delta) +{ + xfs_rfsblock_t nb = mp->m_sb.sb_dblocks + *delta; + int error; + + 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; + } + } + return xfs_buf_delwri_submit(&id->buffer_list); +} + /* * growfs operations */ @@ -74,36 +117,7 @@ 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(mp, &id, oagcount, nagcount, &delta); if (error) goto out_trans_cancel; From patchwork Tue Jan 26 12:56: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: 12046491 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 50BC2C433DB for ; Tue, 26 Jan 2021 13:05:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24BE823122 for ; Tue, 26 Jan 2021 13:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391332AbhAZNFV (ORCPT ); Tue, 26 Jan 2021 08:05:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34161 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392464AbhAZM7A (ORCPT ); Tue, 26 Jan 2021 07:59:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611665850; 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=3XE6o4p8i7YP4aavLFmsYgUv+HesdqfQJ9QVaJANWyc=; b=HEbdTG/b2tLOG/HrxN0g5Ca7maJBeWFUYSb6+qTFDzYcvYYNorQGtcN4rW9Klwl4/X2O64 YVDLCjhEWEMikUyMBS0BrxJVV67GvU0rOSBGARzOtytuKzW6uQfeXZd/d5HePd2WnuUyUg rSREiLZZBExUMOYvWwK3KmrJ+lrv/bo= 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-468-LP0Ubj8sONashVrI-0Znhw-1; Tue, 26 Jan 2021 07:57:26 -0500 X-MC-Unique: LP0Ubj8sONashVrI-0Znhw-1 Received: by mail-pf1-f199.google.com with SMTP id m65so7960850pfb.20 for ; Tue, 26 Jan 2021 04:57:26 -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=3XE6o4p8i7YP4aavLFmsYgUv+HesdqfQJ9QVaJANWyc=; b=X22ilbkhAHc7C/c/HvONy9Wbs61LoOM+kS38WRPUYyOYzDzK1IZo/e4frLnVsQ9xyC 8AtZHIkpd4pWFB71MzziAHMvRRimbSrlC/7+ZzuLHAnJr3CZV9y8MRNRTFCzeptY8ff9 rIYOmOaAuZPl5iTMPcBaey+KDvAdKsTZJwjVHkFBNfKkV5zlzlgFxgG/3ThEtYLMN7uq 145taclUjY1BZruc9VpM8E4y8jCal1VdjJz3Evv5sSkYmHj9PlFn2O/hYlokuC+6Gm2W Yi3ugDPq2tLI3xJuyBCOdyIXV5nPiHmImihvN/h/lfKz+fFOJ2ykVMNyco9uypD20Zi+ yepg== X-Gm-Message-State: AOAM533a0qpQwyoqfG+/6rE4G3Ib+aBCT15AUv2lkcrycuYKfkoj9wYw S/BvxzHKQcmx57AVxcQlrw65x6JMczi+7zX3U6h3i/oZuxcXeLAvfXdwp4emfIVGvkX5Zur7X7s khOKL8RC2dKAp873Ig6nN1HNbz+CIefwwDHnz9u2vYqGgT3ssRL1MlII4K45DRc6DyZoPFuCtYw == X-Received: by 2002:a17:902:ac87:b029:e0:17b:68d2 with SMTP id h7-20020a170902ac87b02900e0017b68d2mr6043027plr.0.1611665844764; Tue, 26 Jan 2021 04:57:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJzsvo+lEWzEWC5GBPXAXOVdAmBWRykHUoJVFCJxge13kHPoJxIq/qvjPx4dDRFW5vq8G2AQ3g== X-Received: by 2002:a17:902:ac87:b029:e0:17b:68d2 with SMTP id h7-20020a170902ac87b02900e0017b68d2mr6042998plr.0.1611665844450; Tue, 26 Jan 2021 04:57:24 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b203sm19243174pfb.11.2021.01.26.04.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 04:57:24 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Christoph Hellwig , Gao Xiang Subject: [PATCH v6 5/7] xfs: introduce xfs_ag_shrink_space() Date: Tue, 26 Jan 2021 20:56:19 +0800 Message-Id: <20210126125621.3846735-6-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210126125621.3846735-1-hsiangkao@redhat.com> References: <20210126125621.3846735-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..c6e68e265269 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, + struct aghdr_init_data *id, + 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(id->agno == mp->m_sb.sb_agcount - 1); + error = xfs_ialloc_read_agi(mp, *tpp, id->agno, &agibp); + if (error) + return error; + + agi = agibp->b_addr; + + error = xfs_alloc_read_agf(mp, *tpp, id->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, id->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..ca65c2553889 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, + struct aghdr_init_data *id, 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 Jan 26 12:56: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: 12046495 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 61949C433E9 for ; Tue, 26 Jan 2021 13:06:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 358D32310E for ; Tue, 26 Jan 2021 13:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389576AbhAZNGH (ORCPT ); Tue, 26 Jan 2021 08:06:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30128 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392478AbhAZM7A (ORCPT ); Tue, 26 Jan 2021 07:59:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611665851; 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=5TR+YNMuonzDgGTUvLpD5UpS1io3STFRigW7QOJNlHg=; b=atr4uOzv0rKUuikWmPFIbqq9cZottvAv6TIsfO9E+41fsFRp9g4AHlU7/Z2jZSKYZlxU/O h4Ik2xxfl2KUFfNkNkhgVVEfcGbBRMUxRHb83nkRipwNF7Hi3l3waVdW3P9DKs9LraoOVB bkALShkYqPIflZJ8pkZKUzx+xrU6GWU= 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-248-zESZY5HTM0aJjL7JC00ibQ-1; Tue, 26 Jan 2021 07:57:30 -0500 X-MC-Unique: zESZY5HTM0aJjL7JC00ibQ-1 Received: by mail-pj1-f69.google.com with SMTP id t10so1851589pjw.4 for ; Tue, 26 Jan 2021 04:57:30 -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=5TR+YNMuonzDgGTUvLpD5UpS1io3STFRigW7QOJNlHg=; b=cYmzBHmbKq44ETUTHWEVPciWsgoipqru4Ll5V/Dz73fG1oXOKoLubl1/y1D1MH1IE5 Z6q1BapXCAZh7xMAlG/Dny8TU80ci8tnfJA5dUhtikZ2SY3BQ1UH9tHCmjlSt07crBGr b9kAHH0LndW1cSilCTu52EB3GKtnxLIsFo9O3BATEJW36KQpf8ZlppbizqqRYbCs9CYV IQmHsXwO1ck3ieco31lirls95FaB9c3vpzi8gja1UBpT7iFWOiGPYJ7BYnro4FCceRZu 1VxJjCjNyIp9B8t/3jHdHMTlEcFT++ZS2oxlnN4/cZfYEND7M8Wt8gY/IWLQ/1zcznHP xvUA== X-Gm-Message-State: AOAM53016VvlmvI7/tyjgvMV0+37Fg86YJhjQjN7P9YLrfmi68+hj0L0 AqPyIwx0RED7zqJG26oFkuwQyloMet2hNQqlnSAEsznZyySfpkWds+/Dmd5f6q5v4jRiGKDVPDz 3jQvXxPXh0uLSVry7QJbHaN1PT6MS3FJi1W7pT/aUQ5CoMp+nQOgKOfBIN8Fy5M3P14k7Lwwu6g == X-Received: by 2002:a17:90b:28d:: with SMTP id az13mr6318789pjb.55.1611665849023; Tue, 26 Jan 2021 04:57:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2dSJLYRMIIA8yJiXarVGz/9yG2B9tv3KFk3ACKgp5AfIauLKhYQcxVTMzMD65LdwvL0G4lQ== X-Received: by 2002:a17:90b:28d:: with SMTP id az13mr6318767pjb.55.1611665848732; Tue, 26 Jan 2021 04:57:28 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b203sm19243174pfb.11.2021.01.26.04.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 04:57:28 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Christoph Hellwig , Gao Xiang Subject: [PATCH v6 6/7] xfs: support shrinking unused space in the last AG Date: Tue, 26 Jan 2021 20:56:20 +0800 Message-Id: <20210126125621.3846735-7-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210126125621.3846735-1-hsiangkao@redhat.com> References: <20210126125621.3846735-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 --- fs/xfs/xfs_fsops.c | 64 ++++++++++++++++++++++++++++++---------------- fs/xfs/xfs_trans.c | 1 - 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 6c4ab5e31054..4bcea22f7b3f 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -38,7 +38,7 @@ xfs_resizefs_init_new_ags( struct aghdr_init_data *id, xfs_agnumber_t oagcount, xfs_agnumber_t nagcount, - xfs_rfsblock_t *delta) + int64_t *delta) { xfs_rfsblock_t nb = mp->m_sb.sb_dblocks + *delta; int error; @@ -76,33 +76,41 @@ 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; xfs_agnumber_t oagcount; struct xfs_trans *tp; + bool extend; 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); nagcount = nb_div + (nb_mod != 0); 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) + if (nagcount < 2) return -EINVAL; + nb = (xfs_rfsblock_t)nagcount * mp->m_sb.sb_agblocks; } + delta = nb - mp->m_sb.sb_dblocks; + extend = (delta > 0); oagcount = mp->m_sb.sb_agcount; /* allocate the new per-ag structures */ @@ -110,22 +118,34 @@ 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); + (extend ? XFS_GROWFS_SPACE_RES(mp) : -delta), 0, + XFS_TRANS_RESERVE, &tp); if (error) return error; - error = xfs_resizefs_init_new_ags(mp, &id, oagcount, nagcount, &delta); - if (error) - goto out_trans_cancel; - + if (extend) { + error = xfs_resizefs_init_new_ags(mp, &id, oagcount, + nagcount, &delta); + 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 there are some blocks in the last AG, resize it. */ if (delta) { - error = xfs_ag_extend_space(mp, tp, &id, delta); + if (extend) { + error = xfs_ag_extend_space(mp, tp, &id, delta); + } else { + id.agno = nagcount - 1; + error = xfs_ag_shrink_space(mp, &tp, &id, -delta); + } + if (error) goto out_trans_cancel; } @@ -137,15 +157,15 @@ 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) + if (nb != mp->m_sb.sb_dblocks) xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS, nb - mp->m_sb.sb_dblocks); if (id.nfree) xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree); /* - * update in-core counters now to reflect the real numbers - * (especially sb_fdblocks) + * update in-core counters now to reflect the real numbers (especially + * sb_fdblocks). And xfs_validate_sb_write() can pass for shrinkfs. */ if (xfs_sb_version_haslazysbcount(&mp->m_sb)) xfs_log_sb(tp); @@ -165,7 +185,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 (extend && delta) { struct xfs_perag *pag; pag = xfs_perag_get(mp, id.agno); diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index e72730f85af1..fd2cbf414b80 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -419,7 +419,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 Jan 26 12:56: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: 12046493 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 6D2EFC433E6 for ; Tue, 26 Jan 2021 13:05:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C47F23128 for ; Tue, 26 Jan 2021 13:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391194AbhAZNFg (ORCPT ); Tue, 26 Jan 2021 08:05:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49877 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392492AbhAZM7D (ORCPT ); Tue, 26 Jan 2021 07:59:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611665856; 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=WTmI/iJHg+iWRF7uhfiVy+in9fQkKOO9n6nRdiWg7Pk=; b=KBZZe7BClAe5Exrw3+vSQi8XFd6OGbBroJHSx29NVz9yPuD7F7Mxw3KcJQUV5pLJuOgOQ4 ydjnAq/SiB1wGfZd9A14Nr4MM8T3V5eBuOgkzc7I/2+PsJ/X0lLp/jiKwBdubSNejHsDan Vg0P7vYse0/aLvOLwWX7rRwPDpk6/LI= 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-430-s81tXfhmNQu8abDwwPHQCg-1; Tue, 26 Jan 2021 07:57:35 -0500 X-MC-Unique: s81tXfhmNQu8abDwwPHQCg-1 Received: by mail-pf1-f200.google.com with SMTP id 143so5722900pfx.5 for ; Tue, 26 Jan 2021 04:57:34 -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=WTmI/iJHg+iWRF7uhfiVy+in9fQkKOO9n6nRdiWg7Pk=; b=Wu/+r8GpgvEoq6OYuI+akk1OnbqGlcNOU5WLRnk6ZYsuDTPUXR/Lm1xkMAxChsLAUy I+LjJYF9BCMXUaaog9wX1Gst5ldqzjsll2hF6mo0zygfs+fGMj+PKAar+ACAjRxoSp1Y mLUwrjhvEjNuuD1rWoPaJ85iRQmhRfoqmfmSWRJNJzcU+/jVusyYetkZCXso/ZzpuQ7h /63TVdwv0DxgOED1eiFs++37l3CHotOsaKHQ6Tp0flspShIb7vRaHXVEhJZpGuCCgmhC XgpCMvNoOSqseKTU9oWy3Buhv6WS7a7TlIw03hWODiDPb4P85XYeUibcRL0Yb0817SzT 6EOw== X-Gm-Message-State: AOAM532pHpcZDsAFptd6Sa1B6tqdQVycfppjBLV7vZFIb09fy0xbQU10 Ght+TVUqIVHqC3GvjrOk6zlNgfGpWrKwiVvF8WBZQ6JTqQVMEZGVvvtapW0U4sHNt8N6Zaqckxh y+DmM3BWS0ZIBSM4Kap9xS2rX1YawehU2S6pKRCfUdszBfCPn100SUmwc6b0wm/wcJWhv9mn0lw == X-Received: by 2002:a63:db03:: with SMTP id e3mr5541517pgg.225.1611665853906; Tue, 26 Jan 2021 04:57:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJzEFIGFLyOlTtDIGNiSHy3ps4wWI7VXYA0wsgmv7GJ7ojU0DGZl8PVbSmv0wUdN9l7YVb16Tg== X-Received: by 2002:a63:db03:: with SMTP id e3mr5541492pgg.225.1611665853533; Tue, 26 Jan 2021 04:57:33 -0800 (PST) Received: from xiangao.remote.csb ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id b203sm19243174pfb.11.2021.01.26.04.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jan 2021 04:57:33 -0800 (PST) From: Gao Xiang To: linux-xfs@vger.kernel.org Cc: "Darrick J. Wong" , Brian Foster , Eric Sandeen , Dave Chinner , Christoph Hellwig , Gao Xiang , "Darrick J . Wong" Subject: [PATCH v6 7/7] xfs: add error injection for per-AG resv failure when shrinkfs Date: Tue, 26 Jan 2021 20:56:21 +0800 Message-Id: <20210126125621.3846735-8-hsiangkao@redhat.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210126125621.3846735-1-hsiangkao@redhat.com> References: <20210126125621.3846735-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. Reviewed-by: Darrick J. Wong Signed-off-by: Gao Xiang --- fs/xfs/libxfs/xfs_ag.c | 5 +++++ fs/xfs/libxfs/xfs_errortag.h | 4 +++- fs/xfs/xfs_error.c | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c index c6e68e265269..5076913c153f 100644 --- a/fs/xfs/libxfs/xfs_ag.c +++ b/fs/xfs/libxfs/xfs_ag.c @@ -23,6 +23,7 @@ #include "xfs_ag_resv.h" #include "xfs_health.h" #include "xfs_error.h" +#include "xfs_errortag.h" #include "xfs_bmap.h" #include "xfs_defer.h" #include "xfs_log_format.h" @@ -559,6 +560,10 @@ xfs_ag_shrink_space( be32_add_cpu(&agf->agf_length, -len); err2 = xfs_ag_resv_init(agibp->b_pag, *tpp); + + if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_SHRINKFS_AG_RESV_FAIL)) + err2 = -ENOSPC; + if (err2) { be32_add_cpu(&agi->agi_length, len); be32_add_cpu(&agf->agf_length, len); diff --git a/fs/xfs/libxfs/xfs_errortag.h b/fs/xfs/libxfs/xfs_errortag.h index 6ca9084b6934..5fd71a930b68 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_SHRINKFS_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..7bae34bfddd2 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(shrinkfs_ag_resv_fail, XFS_ERRTAG_SHRINKFS_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(shrinkfs_ag_resv_fail), NULL, };