From: Dave Chinner <david@fromorbit.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 13/27] xfs: factor out xfs_dir2_leaf_find_entry
Date: Thu, 30 Jun 2011 16:11:02 +1000 [thread overview]
Message-ID: <20110630061102.GG561@dastard> (raw)
In-Reply-To: <20110629140339.086201354@bombadil.infradead.org>
On Wed, Jun 29, 2011 at 10:01:22AM -0400, Christoph Hellwig wrote:
> Add a new xfs_dir2_leaf_find_entry helper to factor out some duplicate code
> from xfs_dir2_leaf_addname xfs_dir2_leafn_add. Found by Eric Sandeen using
> an automated code duplication checked.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
Looks sane - a couple of minor whitespacy comments, otherwise:
Reviewed-by: Dave Chinner <dchinner@redhat.com>
>
> Index: xfs/fs/xfs/xfs_dir2_leaf.c
> ===================================================================
> --- xfs.orig/fs/xfs/xfs_dir2_leaf.c 2011-06-22 21:56:26.102462981 +0200
> +++ xfs/fs/xfs/xfs_dir2_leaf.c 2011-06-23 12:41:51.716439911 +0200
> @@ -152,6 +152,118 @@ xfs_dir2_block_to_leaf(
> return 0;
> }
>
> +xfs_dir2_leaf_entry_t *
> +xfs_dir2_leaf_find_entry(
> + xfs_dir2_leaf_t *leaf, /* leaf structure */
> + int index, /* leaf table position */
> + int compact, /* need to compact leaves */
> + int lowstale, /* index of prev stale leaf */
> + int highstale, /* index of next stale leaf */
> + int *lfloglow, /* low leaf logging index */
> + int *lfloghigh) /* high leaf logging index */
> +{
> + xfs_dir2_leaf_entry_t *lep; /* leaf entry table pointer */
> +
> + if (!leaf->hdr.stale) {
> + /*
> + * Now we need to make room to insert the leaf entry.
> + *
> + * If there are no stale entries, just insert a hole at index.
> + */
> + lep = &leaf->ents[index];
> + if (index < be16_to_cpu(leaf->hdr.count))
> + memmove(lep + 1, lep,
> + (be16_to_cpu(leaf->hdr.count) - index) *
> + sizeof(*lep));
> +
> + /*
> + * Record low and high logging indices for the leaf.
> + */
> + *lfloglow = index;
> + *lfloghigh = be16_to_cpu(leaf->hdr.count);
> + be16_add_cpu(&leaf->hdr.count, 1);
You could probably just return here, and that would remove the:
> + } else {
and the indenting that the else branch causes.
> + /*
> + * There are stale entries.
> + *
> + * We will use one of them for the new entry. It's probably
> + * not at the right location, so we'll have to shift some up
> + * or down first.
> + *
> + * If we didn't compact before, we need to find the nearest
> + * stale entries before and after our insertion point.
> + */
> + if (compact == 0) {
> + /*
> + * Find the first stale entry before the insertion
> + * point, if any.
> + */
> + for (lowstale = index - 1;
> + lowstale >= 0 &&
> + be32_to_cpu(leaf->ents[lowstale].address) !=
> + XFS_DIR2_NULL_DATAPTR;
> + lowstale--)
> + continue;
> + /*
> + * Find the next stale entry at or after the insertion
> + * point, if any. Stop if we go so far that the
> + * lowstale entry would be better.
> + */
> + for (highstale = index;
> + highstale < be16_to_cpu(leaf->hdr.count) &&
> + be32_to_cpu(leaf->ents[highstale].address) !=
> + XFS_DIR2_NULL_DATAPTR &&
> + (lowstale < 0 ||
> + index - lowstale - 1 >= highstale - index);
> + highstale++)
> + continue;
> + }
> + /*
> + * If the low one is better, use it.
> + */
Line of whitespace before the comment.
> + if (lowstale >= 0 &&
> + (highstale == be16_to_cpu(leaf->hdr.count) ||
> + index - lowstale - 1 < highstale - index)) {
> + ASSERT(index - lowstale - 1 >= 0);
> + ASSERT(be32_to_cpu(leaf->ents[lowstale].address) ==
> + XFS_DIR2_NULL_DATAPTR);
> + /*
> + * Copy entries up to cover the stale entry
> + * and make room for the new entry.
> + */
> + if (index - lowstale - 1 > 0)
> + memmove(&leaf->ents[lowstale],
> + &leaf->ents[lowstale + 1],
> + (index - lowstale - 1) * sizeof(*lep));
> + lep = &leaf->ents[index - 1];
> + *lfloglow = MIN(lowstale, *lfloglow);
> + *lfloghigh = MAX(index - 1, *lfloghigh);
> +
> + /*
> + * The high one is better, so use that one.
> + */
> + } else {
I prefer comments inside the else branch...
> + ASSERT(highstale - index >= 0);
> + ASSERT(be32_to_cpu(leaf->ents[highstale].address) ==
> + XFS_DIR2_NULL_DATAPTR);
> + /*
> + * Copy entries down to cover the stale entry
> + * and make room for the new entry.
> + */
> + if (highstale - index > 0)
> + memmove(&leaf->ents[index + 1],
> + &leaf->ents[index],
> + (highstale - index) * sizeof(*lep));
> + lep = &leaf->ents[index];
> + *lfloglow = MIN(index, *lfloglow);
> + *lfloghigh = MAX(highstale, *lfloghigh);
> + }
> + be16_add_cpu(&leaf->hdr.stale, -1);
> + }
> +
> + return lep;
> +}
> +
> /*
> * Add an entry to a leaf form directory.
> */
> @@ -430,102 +542,11 @@ xfs_dir2_leaf_addname(
.....
> - }
> - be16_add_cpu(&leaf->hdr.stale, -1);
> - }
> +
> +
> + lep = xfs_dir2_leaf_find_entry(leaf, index, compact, lowstale,
> + highstale, &lfloglow, &lfloghigh);
> +
Only need one line of whitespace before the function call.
.....
> - lep = &leaf->ents[index];
> - lfloglow = MIN(index, lfloglow);
> - lfloghigh = MAX(highstale, lfloghigh);
> - }
> - be16_add_cpu(&leaf->hdr.stale, -1);
> - }
> +
> +
> /*
> * Insert the new entry, log everything.
> */
> + lep = xfs_dir2_leaf_find_entry(leaf, index, compact, lowstale,
> + highstale, &lfloglow, &lfloghigh);
> +
Same for the whitespace before the comment.
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2011-06-30 6:11 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-29 14:01 [PATCH 00/27] patch queue for Linux 3.1 Christoph Hellwig
2011-06-29 14:01 ` [PATCH 01/27] xfs: PF_FSTRANS should never be set in ->writepage Christoph Hellwig
2011-06-30 1:34 ` Dave Chinner
2011-06-29 14:01 ` [PATCH 02/27] xfs: remove the unused ilock_nowait codepath in writepage Christoph Hellwig
2011-06-30 0:15 ` Dave Chinner
2011-06-30 1:26 ` Dave Chinner
2011-06-30 6:55 ` Christoph Hellwig
2011-06-29 14:01 ` [PATCH 03/27] xfs: use write_cache_pages for writeback clustering Christoph Hellwig
2011-06-30 2:00 ` Dave Chinner
2011-06-30 2:48 ` Dave Chinner
2011-06-30 6:57 ` Christoph Hellwig
2011-07-01 2:22 ` Dave Chinner
2011-07-01 4:18 ` Dave Chinner
2011-07-01 8:59 ` Christoph Hellwig
2011-07-01 9:20 ` Dave Chinner
2011-07-01 9:33 ` Christoph Hellwig
2011-07-01 14:59 ` Mel Gorman
2011-07-01 15:15 ` Christoph Hellwig
2011-07-02 2:42 ` Dave Chinner
2011-07-05 14:10 ` Mel Gorman
2011-07-05 15:55 ` Dave Chinner
2011-07-11 10:26 ` Christoph Hellwig
2011-07-01 15:41 ` Wu Fengguang
2011-07-04 3:25 ` Dave Chinner
2011-07-05 14:34 ` Mel Gorman
2011-07-06 1:23 ` Dave Chinner
2011-07-11 11:10 ` Christoph Hellwig
2011-07-06 4:53 ` Wu Fengguang
2011-07-06 6:47 ` Minchan Kim
2011-07-06 7:17 ` Dave Chinner
2011-07-06 15:12 ` Johannes Weiner
2011-07-08 9:54 ` Dave Chinner
2011-07-11 17:20 ` Johannes Weiner
2011-07-11 17:24 ` Christoph Hellwig
2011-07-11 19:09 ` Rik van Riel
2011-07-01 8:51 ` Christoph Hellwig
2011-06-29 14:01 ` [PATCH 04/27] xfs: cleanup xfs_add_to_ioend Christoph Hellwig
2011-06-29 22:13 ` Alex Elder
2011-06-30 2:00 ` Dave Chinner
2011-06-29 14:01 ` [PATCH 05/27] xfs: work around bogus gcc warning in xfs_allocbt_init_cursor Christoph Hellwig
2011-06-29 22:13 ` Alex Elder
2011-06-29 14:01 ` [PATCH 06/27] xfs: split xfs_setattr Christoph Hellwig
2011-06-29 22:13 ` Alex Elder
2011-06-30 7:03 ` Christoph Hellwig
2011-06-30 12:28 ` Alex Elder
2011-06-30 2:11 ` Dave Chinner
2011-06-29 14:01 ` [PATCH 08/27] xfs: kill xfs_itruncate_start Christoph Hellwig
2011-06-29 22:13 ` Alex Elder
2011-06-29 14:01 ` [PATCH 09/27] xfs: split xfs_itruncate_finish Christoph Hellwig
2011-06-30 2:44 ` Dave Chinner
2011-06-30 7:18 ` Christoph Hellwig
2011-06-29 14:01 ` [PATCH 10/27] xfs: improve sync behaviour in the fact of aggressive dirtying Christoph Hellwig
2011-06-30 2:52 ` Dave Chinner
2011-06-29 14:01 ` [PATCH 11/27] xfs: fix filesystsem freeze race in xfs_trans_alloc Christoph Hellwig
2011-06-30 2:59 ` Dave Chinner
2011-06-29 14:01 ` [PATCH 12/27] xfs: remove i_transp Christoph Hellwig
2011-06-30 3:00 ` Dave Chinner
2011-06-29 14:01 ` [PATCH 13/27] xfs: factor out xfs_dir2_leaf_find_entry Christoph Hellwig
2011-06-30 6:11 ` Dave Chinner [this message]
2011-06-30 7:34 ` Christoph Hellwig
2011-06-29 14:01 ` [PATCH 14/27] xfs: cleanup shortform directory inode number handling Christoph Hellwig
2011-06-30 6:35 ` Dave Chinner
2011-06-30 7:39 ` Christoph Hellwig
2011-06-29 14:01 ` [PATCH 15/27] xfs: kill struct xfs_dir2_sf Christoph Hellwig
2011-06-30 7:04 ` Dave Chinner
2011-06-30 7:09 ` Christoph Hellwig
2011-06-29 14:01 ` [PATCH 16/27] xfs: cleanup the defintion of struct xfs_dir2_sf_entry Christoph Hellwig
2011-06-29 14:01 ` [PATCH 17/27] xfs: avoid usage of struct xfs_dir2_block Christoph Hellwig
2011-06-29 14:01 ` [PATCH 18/27] xfs: kill " Christoph Hellwig
2011-06-29 14:01 ` [PATCH 19/27] xfs: avoid usage of struct xfs_dir2_data Christoph Hellwig
2011-06-29 14:01 ` [PATCH 20/27] xfs: kill " Christoph Hellwig
2011-06-29 14:01 ` [PATCH 21/27] xfs: cleanup the defintion of struct xfs_dir2_data_entry Christoph Hellwig
2011-06-29 14:01 ` [PATCH 22/27] xfs: cleanup struct xfs_dir2_leaf Christoph Hellwig
2011-06-29 14:01 ` [PATCH 23/27] xfs: remove the unused xfs_bufhash structure Christoph Hellwig
2011-06-29 14:01 ` [PATCH 24/27] xfs: clean up buffer locking helpers Christoph Hellwig
2011-06-29 14:01 ` [PATCH 25/27] xfs: return the buffer locked from xfs_buf_get_uncached Christoph Hellwig
2011-06-29 14:01 ` [PATCH 26/27] xfs: cleanup I/O-related buffer flags Christoph Hellwig
2011-06-29 14:01 ` [PATCH 27/27] xfs: avoid a few disk cache flushes Christoph Hellwig
2011-06-30 6:36 ` [PATCH 00/27] patch queue for Linux 3.1 Dave Chinner
2011-06-30 6:50 ` Christoph Hellwig
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=20110630061102.GG561@dastard \
--to=david@fromorbit.com \
--cc=hch@infradead.org \
--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