All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Mason <chris.mason@fusionio.com>
To: Josef Bacik <jbacik@fusionio.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH] Btrfs-progs: check block group used count and fix if specified
Date: Thu, 1 Nov 2012 09:37:46 -0400	[thread overview]
Message-ID: <20121101133746.GA8307@shiny> (raw)
In-Reply-To: <1351773294-1458-1-git-send-email-jbacik@fusionio.com>

On Thu, Nov 01, 2012 at 06:34:54AM -0600, Josef Bacik wrote:
> A user reported a problem where all of his block groups had invalid used
> counts in the block group item.  This patch walks the extent tree and counts
> up the used amount for each block group.  If the user specifies repair we
> can set the correct used value and when the transaction commits we're all
> set.  This was reported and tested by a user and worked.  Thanks,

Josef and I hashed this out a little bit on irc.  My fsck repair code
already tries to fix the block group accounting, but I think there is a
key part his code does differently (correctly ;):

> +static int check_block_groups_used(struct btrfs_trans_handle *trans,
> +				   struct btrfs_root *root, int repair)
> +{
> +	struct btrfs_block_group_cache *block_group;
> +	struct btrfs_path *path;
> +	u64 bytenr = 0;
> +	int ret;
> +	int err = 0;
> +
> +	path = btrfs_alloc_path();
> +	if (!path)
> +		return -ENOMEM;
> +
> +	path->reada = 2;
> +	while ((block_group = btrfs_lookup_first_block_group(root->fs_info,
> +							     bytenr))) {
> +		ret = check_block_group_used(trans, root, block_group, path,
> +					     repair);
> +		if (ret && !err)
> +			ret = err;
> +		bytenr = block_group->key.objectid + block_group->key.offset;
> +	}
> +	btrfs_free_path(path);
> +
> +	return err;
> +}

My code reuses btrfs_fix_block_group_acounting, which does this:

	start = 0;
        while(1) {
                cache = btrfs_lookup_block_group(fs_info, start);
                if (!cache)
                        break; 
                start = cache->key.objectid + cache->key.offset;
                btrfs_set_block_group_used(&cache->item, 0);
                cache->space_info->bytes_used = 0;
                set_extent_bits(&root->fs_info->block_group_cache,
                                cache->key.objectid,
                                cache->key.objectid + cache->key.offset -1,
                                BLOCK_GROUP_DIRTY, GFP_NOFS);
        }

Using btrfs_lookup_first_block_group here should fix things.  It must be
breaking out too soon and so the accounting isn't updated properly.

-chris

      reply	other threads:[~2012-11-01 13:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-01 12:34 [PATCH] Btrfs-progs: check block group used count and fix if specified Josef Bacik
2012-11-01 13:37 ` Chris Mason [this message]

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=20121101133746.GA8307@shiny \
    --to=chris.mason@fusionio.com \
    --cc=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.