From: Gao Xiang <hsiangkao@redhat.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: linux-xfs@vger.kernel.org, Brian Foster <bfoster@redhat.com>,
Dave Chinner <david@fromorbit.com>,
Christoph Hellwig <hch@lst.de>,
Eric Sandeen <sandeen@sandeen.net>
Subject: Re: [PATCH v7 3/5] xfs: introduce xfs_ag_shrink_space()
Date: Thu, 4 Mar 2021 07:16:08 +0800 [thread overview]
Message-ID: <20210303231608.GC2843084@xiangao.remote.csb> (raw)
In-Reply-To: <20210303181931.GB3419940@magnolia>
On Wed, Mar 03, 2021 at 10:19:31AM -0800, Darrick J. Wong wrote:
> On Tue, Mar 02, 2021 at 10:48:14AM +0800, Gao Xiang wrote:
> > 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 <hsiangkao@redhat.com>
> > ---
> > fs/xfs/libxfs/xfs_ag.c | 108 +++++++++++++++++++++++++++++++++++++++++
> > fs/xfs/libxfs/xfs_ag.h | 2 +
> > 2 files changed, 110 insertions(+)
> >
> > diff --git a/fs/xfs/libxfs/xfs_ag.c b/fs/xfs/libxfs/xfs_ag.c
> > index 9331f3516afa..a1128814630a 100644
> > --- a/fs/xfs/libxfs/xfs_ag.c
> > +++ b/fs/xfs/libxfs/xfs_ag.c
> > @@ -22,6 +22,11 @@
> > #include "xfs_ag.h"
> > #include "xfs_ag_resv.h"
> > #include "xfs_health.h"
> > +#include "xfs_error.h"
> > +#include "xfs_bmap.h"
> > +#include "xfs_defer.h"
> > +#include "xfs_log_format.h"
> > +#include "xfs_trans.h"
> >
> > static int
> > xfs_get_aghdr_buf(
> > @@ -485,6 +490,109 @@ xfs_ag_init_headers(
> > return error;
> > }
> >
> > +int
> > +xfs_ag_shrink_space(
> > + struct xfs_mount *mp,
> > + struct xfs_trans **tpp,
> > + xfs_agnumber_t agno,
> > + xfs_extlen_t len)
> > +{
> > + struct xfs_alloc_arg args = {
> > + .tp = *tpp,
> > + .mp = mp,
> > + .type = XFS_ALLOCTYPE_THIS_BNO,
> > + .minlen = len,
> > + .maxlen = len,
> > + .oinfo = XFS_RMAP_OINFO_SKIP_UPDATE,
> > + .resv = XFS_AG_RESV_NONE,
> > + .prod = 1
> > + };
> > + struct xfs_buf *agibp, *agfbp;
> > + struct xfs_agi *agi;
> > + struct xfs_agf *agf;
> > + int error, err2;
> > +
> > + ASSERT(agno == mp->m_sb.sb_agcount - 1);
> > + error = xfs_ialloc_read_agi(mp, *tpp, agno, &agibp);
> > + if (error)
> > + return error;
> > +
> > + agi = agibp->b_addr;
> > +
> > + error = xfs_alloc_read_agf(mp, *tpp, agno, 0, &agfbp);
> > + if (error)
> > + return error;
> > +
> > + agf = agfbp->b_addr;
> > + if (XFS_IS_CORRUPT(mp, agf->agf_length != agi->agi_length))
> > + return -EFSCORRUPTED;
> > +
> > + args.fsbno = XFS_AGB_TO_FSB(mp, agno,
> > + be32_to_cpu(agi->agi_length) - len);
>
> Paranoia nit: Should we check that len < agi_length?
Ok, although (I think) that's impossible for the current only caller,
I could add some check in the next version.
>
> > +
> > + /* 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);
>
> I forget, does xfs_alloc_vextent ever roll args.tp?
I think xfs_alloc_vextent will return a dirty transaction without
rolling instead.
Thanks,
Gao Xiang
>
> Other than those two things this looks good to me.
>
> --D
>
> > + if (!error && args.agbno == NULLAGBLOCK)
> > + error = -ENOSPC;
> > +
> > + if (error) {
> > + /*
> > + * if extent allocation fails, need to roll the transaction to
> > + * ensure that the AGFL fixup has been committed anyway.
> > + */
> > + err2 = xfs_trans_roll(tpp);
> > + if (err2)
> > + return err2;
> > + goto resv_init_out;
> > + }
> > +
> > + /*
> > + * if successfully deleted from freespace btrees, need to confirm
> > + * per-AG reservation works as expected.
> > + */
> > + be32_add_cpu(&agi->agi_length, -len);
> > + be32_add_cpu(&agf->agf_length, -len);
> > +
> > + err2 = xfs_ag_resv_init(agibp->b_pag, *tpp);
> > + if (err2) {
> > + be32_add_cpu(&agi->agi_length, len);
> > + be32_add_cpu(&agf->agf_length, len);
> > + if (err2 != -ENOSPC)
> > + goto resv_err;
> > +
> > + __xfs_bmap_add_free(*tpp, args.fsbno, len, NULL, true);
> > +
> > + /*
> > + * Roll the transaction before trying to re-init the per-ag
> > + * reservation. The new transaction is clean so it will cancel
> > + * without any side effects.
> > + */
> > + error = xfs_defer_finish(tpp);
> > + if (error)
> > + return error;
> > +
> > + error = -ENOSPC;
> > + goto resv_init_out;
> > + }
> > + xfs_ialloc_log_agi(*tpp, agibp, XFS_AGI_LENGTH);
> > + xfs_alloc_log_agf(*tpp, agfbp, XFS_AGF_LENGTH);
> > + return 0;
> > +
> > +resv_init_out:
> > + err2 = xfs_ag_resv_init(agibp->b_pag, *tpp);
> > + if (!err2)
> > + return error;
> > +resv_err:
> > + xfs_warn(mp, "Error %d reserving per-AG metadata reserve pool.", err2);
> > + xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
> > + return err2;
> > +}
> > +
> > /*
> > * Extent the AG indicated by the @id by the length passed in
> > */
> > diff --git a/fs/xfs/libxfs/xfs_ag.h b/fs/xfs/libxfs/xfs_ag.h
> > index 5166322807e7..f33388eb130a 100644
> > --- a/fs/xfs/libxfs/xfs_ag.h
> > +++ b/fs/xfs/libxfs/xfs_ag.h
> > @@ -24,6 +24,8 @@ struct aghdr_init_data {
> > };
> >
> > int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
> > +int xfs_ag_shrink_space(struct xfs_mount *mp, struct xfs_trans **tpp,
> > + xfs_agnumber_t agno, xfs_extlen_t len);
> > int xfs_ag_extend_space(struct xfs_mount *mp, struct xfs_trans *tp,
> > struct aghdr_init_data *id, xfs_extlen_t len);
> > int xfs_ag_get_geometry(struct xfs_mount *mp, xfs_agnumber_t agno,
> > --
> > 2.27.0
> >
>
next prev parent reply other threads:[~2021-03-04 1:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 2:48 [PATCH v7 0/5] xfs: support shrinking free space in the last AG Gao Xiang
2021-03-02 2:48 ` [PATCH v7 1/5] xfs: update lazy sb counters immediately for resizefs Gao Xiang
2021-03-03 18:13 ` Darrick J. Wong
2021-03-02 2:48 ` [PATCH v7 2/5] xfs: hoist out xfs_resizefs_init_new_ags() Gao Xiang
2021-03-02 2:48 ` [PATCH v7 3/5] xfs: introduce xfs_ag_shrink_space() Gao Xiang
2021-03-03 18:19 ` Darrick J. Wong
2021-03-03 23:16 ` Gao Xiang [this message]
2021-03-02 2:48 ` [PATCH v7 4/5] xfs: support shrinking unused space in the last AG Gao Xiang
2021-03-03 18:25 ` Darrick J. Wong
2021-03-03 23:19 ` Gao Xiang
2021-03-02 2:48 ` [PATCH v7 5/5] xfs: add error injection for per-AG resv failure Gao Xiang
2021-03-03 0:02 ` [PATCH v7.1 " Gao Xiang
2021-03-03 18:30 ` [PATCH v7 " Darrick J. Wong
2021-03-03 23:11 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210303231608.GC2843084@xiangao.remote.csb \
--to=hsiangkao@redhat.com \
--cc=bfoster@redhat.com \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).