btrfsck: fix block group accounting during repair

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Merge branch 'for-chris' of git://github.com/idryomov/btrfs-progs
Turn off some commands in Makefile

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Fix btrfs-convert, btrfs-restore and btrfs-find-root build

Signed-off-by: Chris Mason <chris.mason@oracle.com>

fixit
Signed-off-by: Chris Mason <chris.mason@oracle.com>
btrfsck: make sure to dirty all block groups as we fix accounting

The code that corrects the count of bytes used in each block group
was only marking block groups dirty when they contained extents.  This
fixes things to dirty all the block groups, so any empty block groups
are written with their correct (zero) count.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
btrfsck: add --init-csum-tree to replace the csum root with an empty one

This will effectively delete all of your crcs, but at least you'll
be able to mount the FS with nodatasum.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
btrfsck: make sure we fix the block group accounting during repair

The block group accounting is fixed after we check the extent back
references.  This makes sure the accounting is fixed unless we
were not able to repair the backrefs.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
btrfsck: remove extents from the fsck reference tracker as they are freed

During btrfsck --repair, we make an index of extents that have incorrect
reference counts.  Once we've collect the whole index, we go through
and modify the extent allocation tree to reflect the correct results.

Changing the extent allocation tree may free blocks, and so it may
end up removing a block that had a missing reference structure.  The
fsck code may then circle back around and add the reference back.

The result is an extent that isn't actually used, but is recorded in the
extent allocation tree.

This commit adds a hook called as extents are freed.  The hook searches
the index of incorrect references and updates it to reflect the freeing
of the extent.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Btrfsck: add the ability to prune corrupt extent allocation tree blocks

When we discover bad blocks in the extent allocation tree, repair can
now discard them and recreate the references from the rest of the trees.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Btrfs: use /proc/partitions scanning for btrfs_scan_for_fsid

btrfs_scan_for_fsid is used by open_ctree and by mkfs when it is
checking for mounted devices.  It currently scans all of /dev,
which is rarely the right answer.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Scan /dev/md and device mapper devices last

When we're using multipath or raid0, it is possible
that btrfs dev scan will find one of the component devices
instead of the proper virtual device the kernel creates.

We want to make sure the kernel scans the virtual devices last,
since it always remembers the last device it finds with a given fsid.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
btrfsck: add early code to handle corrupted block groups

This is mostly disabled, but it is step one in handling
corrupted block groups in the extent allocation tree.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Btrfs-progs: nuke redundant zeroing in __list_subvol_search()

There's no need to zero out things twice.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Btrfs-progs: refactor resolve_root() function a bit

Don't pass a pointer to root_id to resolve_root().  It's always the same as
ri->root_id, passing a pointer hints that root_id can somehow change which is
not true.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Btrfs-progs: bring 'subvol get-default' back in

Commit bab2c565 accidentally broke 'subvol get-default' command by
removing almost all of the underlying code.  Bring it back with some
fixes and improvements.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>