From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Dave Chinner <david@fromorbit.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 02/14] libxfs: adjust refcounts in reflink btree
Date: Wed, 1 Jul 2015 16:10:22 -0700 [thread overview]
Message-ID: <20150701231022.GC10043@birch.djwong.org> (raw)
In-Reply-To: <20150701010654.GQ22807@dastard>
On Wed, Jul 01, 2015 at 11:06:54AM +1000, Dave Chinner wrote:
> On Thu, Jun 25, 2015 at 04:39:23PM -0700, Darrick J. Wong wrote:
> > Provide a function to adjust the reference counts for a range of
> > blocks in the reflink btree.
> >
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > fs/xfs/libxfs/xfs_reflink_btree.c | 406 +++++++++++++++++++++++++++++++++++++
> > fs/xfs/libxfs/xfs_reflink_btree.h | 4
> > 2 files changed, 410 insertions(+)
>
> As per previous comments, this all belongs in
> fs/xfs/libxfs/xfs_reflink.c...
>
> >
> >
> > diff --git a/fs/xfs/libxfs/xfs_reflink_btree.c b/fs/xfs/libxfs/xfs_reflink_btree.c
> > index 8a0fa5d..380ed72 100644
> > --- a/fs/xfs/libxfs/xfs_reflink_btree.c
> > +++ b/fs/xfs/libxfs/xfs_reflink_btree.c
> > @@ -529,3 +529,409 @@ xfs_reflinkbt_delete(
> > error0:
> > return error;
> > }
> > +
> > +#ifdef REFLINK_DEBUG
> > +static void
> > +dump_cur_loc(
> > + struct xfs_btree_cur *cur,
> > + const char *str,
> > + int line)
> > +{
> > + xfs_agblock_t gbno;
> > + xfs_extlen_t glen;
> > + xfs_nlink_t gnr;
> > + int i;
> > +
> > + xfs_reflink_get_rec(cur, &gbno, &glen, &gnr, &i);
> > + printk(KERN_INFO "%s(%d) cur[%d]:[%u,%u,%u,%d] ", str, line,
> > + cur->bc_ptrs[0], gbno, glen, gnr, i);
> > + if (i && cur->bc_ptrs[0]) {
> > + cur->bc_ptrs[0]--;
> > + xfs_reflink_get_rec(cur, &gbno, &glen, &gnr, &i);
> > + printk("left[%d]:[%u,%u,%u,%d] ", cur->bc_ptrs[0],
> > + gbno, glen, gnr, i);
> > + cur->bc_ptrs[0]++;
> > + }
> > +
> > + if (i && cur->bc_ptrs[0] < xfs_reflinkbt_get_maxrecs(cur, 0)) {
> > + cur->bc_ptrs[0]++;
> > + xfs_reflink_get_rec(cur, &gbno, &glen, &gnr, &i);
> > + printk("right[%d]:[%u,%u,%u,%d] ", cur->bc_ptrs[0],
> > + gbno, glen, gnr, i);
> > + cur->bc_ptrs[0]--;
> > + }
> > + printk("\n");
> > +}
> > +#else
> > +# define dump_cur_loc(c, s, l)
> > +#endif
>
> Use trace points on lookup/update/insert/delete so debug like this
> is unnecessary.
>
>
> > +/*
> > + * Adjust the ref count of a range of AG blocks.
> > + */
> > +int /* error */
> > +xfs_reflinkbt_adjust_refcount(
> > + struct xfs_mount *mp,
> > + struct xfs_trans *tp, /* transaction pointer */
> > + struct xfs_buf *agbp, /* buffer for agf structure */
> > + xfs_agnumber_t agno, /* allocation group number */
> > + xfs_agblock_t agbno, /* start of range */
> > + xfs_extlen_t aglen, /* length of range */
> > + int adj) /* how much to change refcnt */
>
> 350 line function. Needs factoring. Also needs a comment explaining
> the algorithm.
>
> > +{
> > + struct xfs_btree_cur *cur;
> > + int error;
> > + int i, have;
> > + bool real_crl; /* cbno/clen is on disk? */
> > + xfs_agblock_t lbno, cbno, rbno; /* rlextent start */
> > + xfs_extlen_t llen, clen, rlen; /* rlextent length */
> > + xfs_nlink_t lnr, cnr, rnr; /* rlextent refcount */
>
> "num" is the usual shorthand for "number". And in this case, nr is
> extremely ambiguous: Number of records, number of reflinks, some
> other number? I can't easily tell when I read the code, so the
> variable names need to be better. factoring will certainly help
> here.
"refc" as shorthand for reference count, perhaps?
> > + xfs_agblock_t bno; /* ag bno in the loop */
> > + xfs_agblock_t agbend; /* end agbno of the loop */
> > + xfs_extlen_t len; /* remaining len to add */
> > + xfs_nlink_t new_cnr; /* new refcount */
> > +
> > + CHECK_AG_NUMBER(mp, agno);
> > + CHECK_AG_EXTENT(mp, agbno, aglen);
>
> No real need for these checks - bad agno or extent sizes shoul dhave
> been validated long before this.
>
> > +
> > + /*
> > + * Allocate/initialize a cursor for the by-number freespace btree.
> > + */
> > + cur = xfs_reflinkbt_init_cursor(mp, tp, agbp, agno);
>
> You can kill that incorrect comment.
>
> > +
> > + /*
> > + * Split a left rlextent that crosses agbno.
> > + */
>
> These comments need some ascii art displaying the before, current
> extent and after states so it's clear what the intent is. As it is,
> I'd probably split these into "left/right/middle" helper functions,
> as there is no state created by these initial overlap splits
> used later in the function. That would get rid of excessive
> indentation, make the error handling more obvious, etc.
Ok, I'll draw some pictures. :)
> > + error = xfs_reflink_lookup_le(cur, agbno, &have);
> > + if (error)
> > + goto error0;
>
> goto out_error;
>
> > + if (have) {
>
> if I "have" what? "found_rec" would be a better name, because then
> the code reads clearly...
>
> > + /*
> > + * Start iterating the range we're adjusting. rlextent boundaries
> > + * should be at agbno and agbend.
> > + */
>
> Trying to work my way through this loop, but the logic is hard to
> follow. It's hurting my head trying to work out what it is supposed
> to be doing, so I'm going to wait for more comments, ascii art, and
> factoring before really looking at it.
:)
--D
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2015-07-01 23:10 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-25 23:39 [RFC(RAP) 00/14] xfs: add reflink and dedupe support Darrick J. Wong
2015-06-25 23:39 ` [PATCH 01/14] xfs: create a per-AG btree to track reference counts Darrick J. Wong
2015-07-01 0:13 ` Dave Chinner
2015-07-01 22:52 ` Darrick J. Wong
2015-07-01 23:30 ` Dave Chinner
2015-06-25 23:39 ` [PATCH 02/14] libxfs: adjust refcounts in reflink btree Darrick J. Wong
2015-07-01 1:06 ` Dave Chinner
2015-07-01 23:10 ` Darrick J. Wong [this message]
2015-07-01 23:32 ` Dave Chinner
2015-06-25 23:39 ` [PATCH 03/14] libxfs: support unmapping reflink blocks Darrick J. Wong
2015-07-01 1:26 ` Dave Chinner
2015-07-02 2:27 ` Darrick J. Wong
2015-06-25 23:39 ` [PATCH 04/14] libxfs: block-mapper changes to support reflink Darrick J. Wong
2015-06-25 23:39 ` [PATCH 05/14] xfs: add reflink functions and ioctl Darrick J. Wong
2015-06-25 23:39 ` [PATCH 06/14] xfs: implement copy-on-write for reflinked blocks Darrick J. Wong
2015-06-25 23:39 ` [PATCH 07/14] xfs: handle directio " Darrick J. Wong
2015-06-25 23:40 ` [PATCH 08/14] xfs: teach fiemap about reflink'd extents Darrick J. Wong
2015-06-25 23:40 ` [PATCH 09/14] xfs: copy-on-write reflinked blocks when zeroing ranges of blocks Darrick J. Wong
2015-06-25 23:40 ` [PATCH 10/14] xfs: minimize impact to non-reflink files via reflink per-inode flag Darrick J. Wong
2015-07-01 1:58 ` Dave Chinner
2015-07-01 22:59 ` Darrick J. Wong
2015-07-01 23:49 ` Dave Chinner
2015-07-02 2:32 ` Darrick J. Wong
2015-07-02 7:07 ` Dave Chinner
2015-06-25 23:40 ` [PATCH 11/14] xfs: emulate the btrfs dedupe extent same ioctl Darrick J. Wong
2015-06-25 23:40 ` [PATCH 12/14] xfs: support XFS_XFLAG_REFLINK (and FS_NOCOW_FL) on reflink filesystems Darrick J. Wong
2015-06-25 23:40 ` [PATCH 13/14] xfs: add reflink btree root when expanding the filesystem Darrick J. Wong
2015-06-25 23:40 ` [PATCH 14/14] xfs: add reflink btree block detection to log recovery Darrick J. Wong
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=20150701231022.GC10043@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=xfs@oss.sgi.com \
/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