platform/upstream/btrfs-progs.git
9 years agobtrfs-progs: Cleanup check_tree_block() function
Qu Wenruo [Thu, 29 Jan 2015 08:32:39 +0000 (16:32 +0800)]
btrfs-progs: Cleanup check_tree_block() function

Before this patch, check_tree_block() will print error on bytenr
mismatch but don't output error on fsid mismatch.

This patch will modify check_tree_block(), so it will only return errno
but not print error messages.
The error message will be output by print_tree_block_err() function.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[renamed and cleaned return codes]
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoMerge remote-tracking branch 'remotes/josef/for-kdave' into v3.19.x
David Sterba [Tue, 10 Feb 2015 14:17:10 +0000 (15:17 +0100)]
Merge remote-tracking branch 'remotes/josef/for-kdave' into v3.19.x

"This series of patches fixes up btrfsck in lots of ways and adds some
new functionality.  These patches were required to fix Hugo's broken
multi-disk fs as well as fix fsck so it would actually pass all of the
fsck tests.  This also fixes a long standing btrfs-image problem where
it wouldn't restore multi disk images onto a single disk properly."

9 years agoBtrfs-progs: fix bad extent flag
Josef Bacik [Thu, 5 Feb 2015 20:41:32 +0000 (15:41 -0500)]
Btrfs-progs: fix bad extent flag

We can have FULL_BACKREF set or not set when we need the opposite, this patch
fixes this problem by setting a bit when the flag is set improperly.  This way
we can either correct the problem when we re-create the extent item if the
backrefs are also wrong, or we can just set the flag properly in the extent
item.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: skip opening all devices with restore
Josef Bacik [Tue, 3 Feb 2015 14:48:57 +0000 (09:48 -0500)]
Btrfs-progs: skip opening all devices with restore

When we go to fixup the dev items after a restore we scan all existing devices.
If you happen to be a btrfs developer you could possibly open up some random
device that you didn't just restore onto, which gives you weird errors and makes
you super cranky and waste a day trying to figure out what is failing.  This
will make it so that we use the fd we've already opened for opening our ctree.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: make debug-tree spit out full_backref flag
Josef Bacik [Tue, 3 Feb 2015 14:48:29 +0000 (09:48 -0500)]
Btrfs-progs: make debug-tree spit out full_backref flag

Currently btrfs-debug-tree ignores the FULL_BACKREF flag which makes it hard to
figure out problems related to FULL_BACKREF.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: make restore update dev items
Josef Bacik [Wed, 28 Jan 2015 20:38:03 +0000 (12:38 -0800)]
Btrfs-progs: make restore update dev items

When we restore a multi disk image onto a single disk we need to update the dev
items used and total bytes so that fsck doesn't freak out and that we get normal
results from stuff like btrfs fi show.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: unpin excluded extents as we fix things
Josef Bacik [Tue, 27 Jan 2015 22:23:21 +0000 (14:23 -0800)]
Btrfs-progs: unpin excluded extents as we fix things

We don't want to keep extent records pinned down if we fix stuff as we may need
the space and we can be pretty sure that these records are correct.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: remove global transaction from fsck
Josef Bacik [Mon, 9 Feb 2015 15:02:25 +0000 (10:02 -0500)]
Btrfs-progs: remove global transaction from fsck

We hold a transaction open for the entirety of fixing extent refs.  This works
out ok most of the time but we can be tight on space and run out of space when
fixing things.  To get around this just push down the transaction starting dance
into the functions that actually fix things.  This keeps us from ending up with
ENOSPC because we pinned everything and allows the code to be a bit simpler.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: only build space info's for the main flags
Josef Bacik [Mon, 26 Jan 2015 01:41:19 +0000 (17:41 -0800)]
Btrfs-progs: only build space info's for the main flags

Hitting enospc problems with a really corrupt fs uncovered the fact that we
match any flag in a block group when creating space info's.  This is a problem
if we have a raid level set, we'll end up with only one space info that covers
metadata and data because they share a raid level.  We don't want this, we want
to separate out the data and metadata space infos, so mask off the raid level
and only use the main flags.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: Introduce metadump_v2
Josef Bacik [Fri, 6 Feb 2015 18:03:12 +0000 (13:03 -0500)]
Btrfs-progs: Introduce metadump_v2

The METADUMP super flag makes us skip doing the chunk tree reading which isn't
helpful for the new restore since we have a valid chunk tree.  But we still want
to have a way for the kernel to know that this is a metadump restore so it
doesn't do things like verify data checksums.  We also want to skip some of the
device extent checks in fsck since those will obviously not match.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: multi-thread btrfs-image restore
Josef Bacik [Fri, 6 Feb 2015 19:40:45 +0000 (14:40 -0500)]
Btrfs-progs: multi-thread btrfs-image restore

For some reason we only allow btrfs-image restore to have one thread, which is
incredibly slow with large images.  So allow us to do work with more than just
one thread.  This made my restore go from 16 minutes to 3 minutes.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agobtrfs-progs: fix btrfs-image overlapping chunks
Josef Bacik [Mon, 26 Jan 2015 01:39:24 +0000 (17:39 -0800)]
btrfs-progs: fix btrfs-image overlapping chunks

If you create a metadump from a striped volume you will have chunks that refer
to different logical offsets with the same physical offset on different devices.
So when we do the restore we just truncate the number of stripes in each chunk
item and carry on, which causes problems because we then have chunks that point
to the same physical offset for different logical offsets.  To handle this
problem we keep track of logical extents that overlap on physical extents.
Then we go back and remap these extents into different physical extents on the
disk we are restoring onto.  This makes us actually able to restore a multi disk
image onto a single disk and have everything work out properly.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: don't check csums for data reloc root
Josef Bacik [Fri, 23 Jan 2015 16:39:28 +0000 (11:39 -0500)]
Btrfs-progs: don't check csums for data reloc root

The data reloc root is weird with it's csums.  It'll copy an entire extent and
then log any csums it finds, which makes it look weird when it comes to prealloc
extents.  So just skip the data reloc tree, it's special and we just don't need
to worry about it.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: don't try to repair reloc roots
Josef Bacik [Thu, 15 Jan 2015 22:11:41 +0000 (17:11 -0500)]
Btrfs-progs: don't try to repair reloc roots

We have logic to fix the root locations for roots in response to a corruption
bug we had earlier.  However this work doesn't apply to reloc roots and can
screw things up worse, so make sure we skip any reloc roots that we find.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: read super properly in btrfs-image
Josef Bacik [Wed, 14 Jan 2015 19:40:21 +0000 (14:40 -0500)]
Btrfs-progs: read super properly in btrfs-image

When btrfs-image makes a metadump it'll map all the blocks from their logical
address to their physical.  This works out fine with the exception of the super
block, which is the physical offset.  Normally this just works, but if the user
has balanced their fs it'll either crash btrfs-image or it'll copy some
completely arbitrary data.  This forces btrfs-image to read the super directly
from the disk.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: handle -eagain properly
Josef Bacik [Fri, 6 Feb 2015 14:59:54 +0000 (09:59 -0500)]
Btrfs-progs: handle -eagain properly

If we fix bad blocks during run_next_block we will return -EAGAIN to loop around
and start again.  The deal_with_roots work messed up this handling, this patch
fixes it.  With this patch we can properly deal with broken tree blocks.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agobtrfs-progs: deal with no extent info
Josef Bacik [Tue, 13 Jan 2015 20:23:41 +0000 (15:23 -0500)]
btrfs-progs: deal with no extent info

Previously we used to just set FULL_BACKREF if we couldn't lookup an extent info
for an extent.  Now we just bail out if we can't lookup the extent info, which
is less than good since fsck is supposed to fix these very problems.  So instead
figure out the flag we are supposed to use and pass that along instead.  This
patch also provides a test image to test this functionality.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs-progs: let btrfs-corrupt-block specify a root
Josef Bacik [Tue, 13 Jan 2015 20:23:01 +0000 (15:23 -0500)]
Btrfs-progs: let btrfs-corrupt-block specify a root

Sometimes we want to corrupt specific keys or delete items on different roots,
so allow btrfs-corrupt-block to take a root objectid so we can corrupt a
specific root.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agoBtrfs progs v3.19-rc2
David Sterba [Thu, 5 Feb 2015 16:14:36 +0000 (17:14 +0100)]
Btrfs progs v3.19-rc2

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, do not install everything by default
David Sterba [Thu, 5 Feb 2015 14:46:42 +0000 (15:46 +0100)]
btrfs-progs: build, do not install everything by default

Commit 878affd47d ("btrfs-progs: build more utilities by default")
resulted in installation of new utilities, that were not installed
before. Make them build but do not install them.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: do not force fortify flags
David Sterba [Thu, 5 Feb 2015 14:11:40 +0000 (15:11 +0100)]
btrfs-progs: autoconf: do not force fortify flags

Make it default, but let the user override it.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: largefile support is driven by configure
David Sterba [Thu, 5 Feb 2015 13:52:03 +0000 (14:52 +0100)]
btrfs-progs: autoconf: largefile support is driven by configure

Don't force it in the makefile.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: move custom CFLAGS from makefile
David Sterba [Thu, 5 Feb 2015 13:46:47 +0000 (14:46 +0100)]
btrfs-progs: autoconf: move custom CFLAGS from makefile

Keep only flags that are required to build properly, current fine
tunings are moved to the optional defaults in configure and can be
overriden by the user.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: set CFLAGS conditionally
David Sterba [Wed, 4 Feb 2015 18:23:38 +0000 (19:23 +0100)]
btrfs-progs: autoconf: set CFLAGS conditionally

The expected way to define custom CFLAGS is

  $ export CFLAGS=...
  $ ./configure ...

the build will use them. No not override the make variables directly
from now on.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, use the static library for the utilities
David Sterba [Wed, 4 Feb 2015 17:45:54 +0000 (18:45 +0100)]
btrfs-progs: build, use the static library for the utilities

Commit 2c2e6c4e12e5af15fd ("btrfs-progs: autoconf: cleanup compilation
flags usage") added the shared library to the linking command so the
resulting binaries depend dependent on libbtrfs.so. This is not
intended.

Reported-by: WorMzy Tykashi <wormzy.tykashi@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, fix the source of btrfsck symlink
David Sterba [Wed, 4 Feb 2015 17:10:23 +0000 (18:10 +0100)]
btrfs-progs: build, fix the source of btrfsck symlink

The installed symlink points to the absolute path of btrfs,
a relative link is enough.

Reported-by: WorMzy Tykashi <wormzy.tykashi@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: set exec_prefix in makefile
David Sterba [Wed, 4 Feb 2015 17:08:23 +0000 (18:08 +0100)]
btrfs-progs: autoconf: set exec_prefix in makefile

Lost in the conversion and breaks the build unless set explicitly.

Reported-by: WorMzy Tykashi <wormzy.tykashi@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs progs v3.19-rc1
David Sterba [Tue, 3 Feb 2015 17:53:58 +0000 (18:53 +0100)]
Btrfs progs v3.19-rc1

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: qgroups, adjust help text
David Sterba [Tue, 3 Feb 2015 17:34:14 +0000 (18:34 +0100)]
btrfs-progs: qgroups, adjust help text

Minor rewording to make the line shorter and.

Resolves-coverity-id: 1267280
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: check btrfs-convert dependencies
David Sterba [Tue, 3 Feb 2015 16:12:28 +0000 (17:12 +0100)]
btrfs-progs: autoconf: check btrfs-convert dependencies

Use the standard pkg-config checks.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: check if backtrace is really supported
David Sterba [Tue, 3 Feb 2015 15:50:33 +0000 (16:50 +0100)]
btrfs-progs: autoconf: check if backtrace is really supported

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: print summary about features
David Sterba [Tue, 3 Feb 2015 15:31:51 +0000 (16:31 +0100)]
btrfs-progs: autoconf: print summary about features

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: make btrfs-convert build optional
David Sterba [Tue, 3 Feb 2015 15:22:55 +0000 (16:22 +0100)]
btrfs-progs: autoconf: make btrfs-convert build optional

Proposed at https://github.com/kdave/btrfs-progs/pull/6, I've added the
configure options.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: detect tools to build docs
David Sterba [Tue, 3 Feb 2015 14:38:17 +0000 (15:38 +0100)]
btrfs-progs: autoconf: detect tools to build docs

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, fix version macro name
David Sterba [Tue, 3 Feb 2015 14:04:28 +0000 (15:04 +0100)]
btrfs-progs: build, fix version macro name

Autoconf changed it to PACKAGE_VERSION and moved to config.h.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: use variable substitutions in doc makefile
David Sterba [Tue, 3 Feb 2015 13:56:06 +0000 (14:56 +0100)]
btrfs-progs: autoconf: use variable substitutions in doc makefile

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: generate documentation makefile as well
David Sterba [Tue, 3 Feb 2015 13:49:09 +0000 (14:49 +0100)]
btrfs-progs: autoconf: generate documentation makefile as well

This is plain move to .in.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, fix rules to clean temporary files in docs
David Sterba [Tue, 3 Feb 2015 13:40:33 +0000 (14:40 +0100)]
btrfs-progs: build, fix rules to clean temporary files in docs

$ make clean-doc
Cleaning Documentation
/usr/bin/rm: cannot remove ‘*.xml’: No such file or directory
/usr/bin/rm: cannot remove ‘*.xml+’: No such file or directory
/usr/bin/rm: cannot remove ‘*.5’: No such file or directory
/usr/bin/rm: cannot remove ‘*.8’: No such file or directory
make[1]: *** [clean] Error 1
make: *** [clean-doc] Error 2

The RM variable from parent makefile lacks -f, add it where it's
missing.
Minor change in LN_S variable name, same -f change.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: read_tree_block() and read_node_slot() cleanup.
Qu Wenruo [Wed, 28 Jan 2015 02:12:55 +0000 (10:12 +0800)]
btrfs-progs: read_tree_block() and read_node_slot() cleanup.

Allow read_tree_block() and read_node_slot() to return error pointer.
This should help caller to get more specified error number.

For existing callers, change (!eb) judgmentt to
(!extent_buffer_uptodate(eb)) to keep the compatibility, and for caller
missing the check, use PTR_ERR(eb) if possible.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: drop old fi balance syntax from help
David Sterba [Mon, 2 Feb 2015 17:17:05 +0000 (18:17 +0100)]
btrfs-progs: drop old fi balance syntax from help

The command 'btrfs fi balance' still works to keep any scripts working,
we may remove it someday.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: add bash completion script
David Sterba [Mon, 2 Feb 2015 16:49:41 +0000 (17:49 +0100)]
btrfs-progs: add bash completion script

Original authors:
  Alfredo Esteban <aedelatorre at gmail.com>
  Joseph Wang <joequant at gmail.com>
  John C F <john.ch.fr at gmail.com>

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add repair function for discount file extent hole.
Qu Wenruo [Fri, 2 Jan 2015 07:12:33 +0000 (15:12 +0800)]
btrfs-progs: Add repair function for discount file extent hole.

Since orphan extents are handled in previous patches, now just punch
holes to fill the file extents hole.

Also since now btrfsck is aware of whether the inode has orphan file
extent, allow repair_inode_no_item() to determine filetype according to
orphan file extent.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add repair and report function for orphan file extent.
Qu Wenruo [Fri, 2 Jan 2015 07:12:32 +0000 (15:12 +0800)]
btrfs-progs: Add repair and report function for orphan file extent.

In some fs tree leaf/node corruption case, file extents may be lost, but
in extent tree, its record may still exists.

This provide the possibility for such orphan file extents to be
recovered even we can't recover its compression and other info, we can
still insert it as a normal non-compression file extent.

This patch provides the repair and report function for such orphan file
extent.
Even after such repair, user may still need to try to decompress its
data if user knows that is a compressed extent.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Record and report every file extent hole.
Qu Wenruo [Fri, 2 Jan 2015 07:12:31 +0000 (15:12 +0800)]
btrfs-progs: Record and report every file extent hole.

Record every file extent discontinuous hole in inode_record using a
rb_tree member.

Before the patch, btrfsck will only record the first file extent hole by
using first_extent_gap, that's good for detecting error, but not
suitable for fixing it.

This patch provides the ability to record every file extent hole and
report it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add btrfs_get_extent() and btrfs_punch_hole().
Qu Wenruo [Fri, 2 Jan 2015 07:12:30 +0000 (15:12 +0800)]
btrfs-progs: Add btrfs_get_extent() and btrfs_punch_hole().

Add btrfs_get_extent() and btrfs_punch_hole() for btrfs-progs.

Btrfs_get_extent() will act much like kernel one, return the first
extent that covers the given range.
The difference will be that progs btrfs_get_extent() can't handle
no-holes feature, which means caller should handle it carefully.

Btrfs_punch_hole() will punch a hole in given range of given inode,
however it differs from kernel one since it won't zero any page or drop
any extents if there is any extent in the hole range.

These functions are mainly used for later I_ERR_FILE_EXTENT_DISCOUNT
repair function.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Record orphan data extent ref to corresponding root.
Qu Wenruo [Fri, 2 Jan 2015 07:12:29 +0000 (15:12 +0800)]
btrfs-progs: Record orphan data extent ref to corresponding root.

Before this patch, when a extent's data ref points to a invalid key in
fs tree, this happens if a leaf/node of fs tree is corrupted, btrfsck
can't do any repair and just exit.

In fact, such problem can be handled in fs tree repair routines, rebuild
the inode item(if missing) and add back the extent data (with some
assumption).

So this patch records such data extent refs for later fs tree recovery
routine.

TODO:
    Restore orphan data extent refs into btrfs_root is not the best
    method. It's best to directly restore it into inode_record, however
    current extent tree and fs tree can't cooperate together, so use
    btrfs_root as a temporary storage until inode_cache is built.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build more utilities by default
David Sterba [Wed, 28 Jan 2015 18:06:47 +0000 (19:06 +0100)]
btrfs-progs: build more utilities by default

Get better build coverage, btrfs-fragments require external libraries.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, make autogen.sh work on older systems
David Sterba [Wed, 28 Jan 2015 18:01:25 +0000 (19:01 +0100)]
btrfs-progs: build, make autogen.sh work on older systems

Try harder to find the support scipts, look into libtool or automake
dirs directly.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, use autoconf to detect RM
David Sterba [Wed, 28 Jan 2015 17:41:17 +0000 (18:41 +0100)]
btrfs-progs: build, use autoconf to detect RM

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, clean all generated files
David Sterba [Wed, 28 Jan 2015 17:28:37 +0000 (18:28 +0100)]
btrfs-progs: build, clean all generated files

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: build, make build test work again
David Sterba [Wed, 28 Jan 2015 17:16:10 +0000 (18:16 +0100)]
btrfs-progs: build, make build test work again

We need to regenerate version.h after clean-all.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: add --disable-documentation
Karel Zak [Fri, 12 Dec 2014 10:54:06 +0000 (11:54 +0100)]
btrfs-progs: autoconf: add --disable-documentation

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: add --disable-backtrace
Karel Zak [Wed, 10 Dec 2014 14:21:24 +0000 (15:21 +0100)]
btrfs-progs: autoconf: add --disable-backtrace

It's better to use ./configure than manually edit Makefile.

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: clean generated files, make version.h stuff more robust
Karel Zak [Wed, 10 Dec 2014 11:30:05 +0000 (12:30 +0100)]
btrfs-progs: autoconf: clean generated files, make version.h stuff more robust

- add rule to generated version.h when any relevant stuff changed
- add rule to clean generated files on "make clean-all"

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: cleanup compilation flags usage
Karel Zak [Wed, 10 Dec 2014 10:56:59 +0000 (11:56 +0100)]
btrfs-progs: autoconf: cleanup compilation flags usage

- define basic default CFLAGS in configure.ac, because:

   * autoconf default is -g -O2, but btrfs uses -g -O1

   * it's better to follow autoconf; standard way to modify
     CFLAGS is to call:  CFLAGS="foo bar" ./configure

- move all flags to one place in Makefile.in

- don't use AM_CFLAGS, the CFLAGS and STATIC_CFLAGS are enough

- don't mix objects and flags in $LIBS, it's more readable to
  add $(libs) to make rules

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: use paths and $*_LIBS from ./configure
Karel Zak [Tue, 9 Dec 2014 15:57:10 +0000 (16:57 +0100)]
btrfs-progs: autoconf: use paths and $*_LIBS from ./configure

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: check for build programs in ./configure
Karel Zak [Tue, 9 Dec 2014 15:41:10 +0000 (16:41 +0100)]
btrfs-progs: autoconf: check for build programs in ./configure

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: use ./configure to generate version.h
Karel Zak [Tue, 9 Dec 2014 14:58:11 +0000 (15:58 +0100)]
btrfs-progs: autoconf: use ./configure to generate version.h

The original homemade solution is unnecessary, autotools provides better
infrastructure to generate files.

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: use standard PACKAGE_* macros
Karel Zak [Tue, 9 Dec 2014 14:37:03 +0000 (15:37 +0100)]
btrfs-progs: autoconf: use standard PACKAGE_* macros

- use standard PACKAGE_{NAME,VERSION,STRING,URL,...} autoconf macros
  rather than homemade BTRFS_BUILD_VERSION

- don't #include version.h, now the file is necessary for library API only

Note that "btrfs version" returns "btrfs-progs <version>" instead of
the original confusing "btrfs <version>".

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: use config.h
Karel Zak [Tue, 9 Dec 2014 14:15:47 +0000 (15:15 +0100)]
btrfs-progs: autoconf: use config.h

- the header file is generated by ./configure, the standard autotools
  way is to use -include config.h on compiler command line rather than
  include the file directly from code

- remove _GNU_SOURCE from code, the macros is already defined in config.h
  by AC_USE_SYSTEM_EXTENSIONS autoconf macro

Signed-off-by: Karel Zak <kzak@redhat.com>
[_GNU_SOURCE changes already done]
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: autoconf: add ./configure script
Karel Zak [Thu, 4 Dec 2014 12:26:46 +0000 (13:26 +0100)]
btrfs-progs: autoconf: add ./configure script

- add ./autogen.sh script (necessary after git clean/clone)
- add ./configure.ac
- copy autotool helper scripts from automake
- modify version.sh to be usable from the configure script
- rename Makefile to Makefile.in and use basic variables from configure.ac

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs progs v3.18.2
David Sterba [Tue, 27 Jan 2015 16:42:28 +0000 (17:42 +0100)]
Btrfs progs v3.18.2

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: update wording for qgroup limits
David Sterba [Tue, 27 Jan 2015 16:07:40 +0000 (17:07 +0100)]
btrfs-progs: update wording for qgroup limits

Based on a user report, 'max' in help does not clearly point to the
limits that are commonly used as a quota-related term.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: don't output operational status information to stderr
Xing Gu [Mon, 26 Jan 2015 08:26:38 +0000 (16:26 +0800)]
btrfs-progs: don't output operational status information to stderr

Signed-off-by: Xing Gu <gux.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: check: Add --readonly flag
Hugo Mills [Tue, 27 Jan 2015 15:05:53 +0000 (15:05 +0000)]
btrfs-progs: check: Add --readonly flag

Particularly during support conversations, people get confused about
which options to use with btrfs check. Adding a flag, --readonly, which
implies the default read-only behaviour and which conflicts with the
read-write operations, should help make the behaviour of the tool clear.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Make option parsing more robust to code modifications
Hugo Mills [Tue, 27 Jan 2015 15:05:52 +0000 (15:05 +0000)]
btrfs-progs: Make option parsing more robust to code modifications

The current approach to option parsing, where long-only options are
selected on the basis of their position in the long_options array is
fragile and painful to modify if options are to be inserted into the
list, rather than appended.

Instead, use the last field of struct option to return a value which
cannot be a char (and hence a short option), and simply switch on those
within the case statement.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: qgroup: make large size aligned
Fan Chengniang [Fri, 23 Jan 2015 01:50:49 +0000 (09:50 +0800)]
btrfs-progs: qgroup: make large size aligned

Problem: when the size is too big, the output format will be unaligned.
The __update__columns_max_len function has been updated to fix this
problem.

Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: drop feature defines from C files, in favour of CFLAGS defines
Dimitri John Ledkov [Sun, 18 Jan 2015 01:52:58 +0000 (01:52 +0000)]
btrfs-progs: drop feature defines from C files, in favour of CFLAGS defines

glibc 2.10+ (5+ years old) enables all the desired features:
_XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a
single _GNU_SOURCE define in the makefile alone. For portability to
other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also
defined.

This also resolves Debian bug report filed by Michael Tautschnig -
"Inconsistent use of _XOPEN_SOURCE results in conflicting
declarations". Whilst I was not able to reproduce the results, the
reported fact is that _XOPEN_SOURCE set to 500 in one set of files
(e.g. cmds-filesystem.c) generates/defines different struct stat from
other files (cmds-replace.c).

This patch thus cleans up all feature defines, and sets them at a
consistent level.

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747969
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: unify getopt table terminators
David Sterba [Wed, 21 Jan 2015 17:53:02 +0000 (18:53 +0100)]
btrfs-progs: unify getopt table terminators

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: add --human-readable option where applicable
David Sterba [Wed, 21 Jan 2015 17:47:24 +0000 (18:47 +0100)]
btrfs-progs: add --human-readable option where applicable

Add an alias to -h to 'filesystem usage', 'filesystem df' and
'device usage' commands, same as the traditional 'df'.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: use predefined getopt values for unit suffixes
David Sterba [Wed, 21 Jan 2015 17:09:32 +0000 (18:09 +0100)]
btrfs-progs: use predefined getopt values for unit suffixes

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: define common geopt values for unit suffixes
David Sterba [Wed, 21 Jan 2015 17:02:42 +0000 (18:02 +0100)]
btrfs-progs: define common geopt values for unit suffixes

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: make btrfs qgroups show human readable sizes
Fan Chengniang [Mon, 19 Jan 2015 07:18:18 +0000 (15:18 +0800)]
btrfs-progs: make btrfs qgroups show human readable sizes

add --raw, --si, --iec, --kbytes, --mbytes, --gbytes, --tbytes options
make columns which show sizes align to right. Others aligned to left.

example:
qgroupid         rfer         excl     max_rfer     max_excl parent  child
--------         ----         ----     --------     -------- ------  -----
0/5         299.58MiB    299.58MiB    300.00MiB    300.00MiB 1/1     ---
0/265       299.58MiB     16.00KiB    400.00MiB        0.00B 1/1     ---
0/266       299.58MiB     16.00KiB    350.00MiB        0.00B ---     ---
1/1         599.16MiB    299.59MiB    800.00MiB        0.00B ---     0/5,0/265

Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: unify header file inclusion protections
David Sterba [Wed, 21 Jan 2015 16:49:26 +0000 (17:49 +0100)]
btrfs-progs: unify header file inclusion protections

There are missing ifdefs or defines with very generic names.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Doc: Add explain on 'source' and 'target' for btrfs-image.
Qu Wenruo [Mon, 24 Nov 2014 07:27:44 +0000 (15:27 +0800)]
btrfs-progs: Doc: Add explain on 'source' and 'target' for btrfs-image.

Add explain on 'source' and 'target', which is somewhat confusing for
users who want to restore dumped image.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[reworded texts]
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Cleanup, use bitshift instead of immediate number in btrfs_open_ctree_flags.
Qu Wenruo [Mon, 19 Jan 2015 06:45:03 +0000 (14:45 +0800)]
btrfs-progs: Cleanup, use bitshift instead of immediate number in btrfs_open_ctree_flags.

Change the immediate number in btrfs_open_ctree_flags to bit shift.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: btrfstune: force to set seeding flags
Fan Chengniang [Mon, 19 Jan 2015 07:27:30 +0000 (15:27 +0800)]
btrfs-progs: btrfstune: force to set seeding flags

Now we can use -f with -S option when setting seeding flags or clearing
seeding flags

Reported-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
[updated docs]
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: tests, use non-interactive sudo helper
David Sterba [Mon, 19 Jan 2015 18:09:28 +0000 (19:09 +0100)]
btrfs-progs: tests, use non-interactive sudo helper

Sudo may not be configured to run without user prompt, in that case the
tests would be stuck.

Reported-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fix check of running scrub
David Sterba [Mon, 19 Jan 2015 17:47:20 +0000 (18:47 +0100)]
btrfs-progs: fix check of running scrub

Scrub on multiple devices may report wrong status if scrub finishes
early on one of them.

Reported-by: Sandy McArthur Jr <sandymac@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: make getopt tables static const
David Sterba [Mon, 19 Jan 2015 12:44:49 +0000 (13:44 +0100)]
btrfs-progs: make getopt tables static const

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: cleanup, move getop long options close to their use
David Sterba [Mon, 19 Jan 2015 12:30:06 +0000 (13:30 +0100)]
btrfs-progs: cleanup, move getop long options close to their use

Move long_option defintions just before getopt_long everywhere.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: tests, adjust alignment of the pretty command name
David Sterba [Wed, 14 Jan 2015 17:32:17 +0000 (18:32 +0100)]
btrfs-progs: tests, adjust alignment of the pretty command name

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: tests, use the root helper in 012
David Sterba [Wed, 14 Jan 2015 17:13:21 +0000 (18:13 +0100)]
btrfs-progs: tests, use the root helper in 012

We need it to mount/umount, to traverse lost+found and stat the results.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: tests, add support for running commands under root
David Sterba [Wed, 14 Jan 2015 17:07:43 +0000 (18:07 +0100)]
btrfs-progs: tests, add support for running commands under root

Most of the checks run fine without root, but some of them may need to
do a mount test or access the data. Add the support to selectively run
commands under root, hardcoded to sudo for now.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Move extent tree rebuild test to its dir
Qu Wenruo [Thu, 25 Dec 2014 01:32:15 +0000 (09:32 +0800)]
btrfs-progs: Move extent tree rebuild test to its dir

Move extent tree rebuild teset to its dir.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Move leaf-corruption no extent data case and add verification script
Qu Wenruo [Thu, 25 Dec 2014 01:32:14 +0000 (09:32 +0800)]
btrfs-progs: Move leaf-corruption no extent data case and add verification script

Move leaf-corruption type no extent data case to its dir, and add
verification script in test.sh

The verification script is based on manual btrfs-debug-tree check.

The image can also be reused to other leaf-corruption type, like
corrupted leaf contains regular file extent data case.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Move bad root items test cases to its corresponding dir
Qu Wenruo [Thu, 25 Dec 2014 01:32:13 +0000 (09:32 +0800)]
btrfs-progs: Move bad root items test cases to its corresponding dir

Now 006-bad-root-items has two cases, one for default case, and one for
skinny metadata case.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Move btrfs-image dump to corresponding dir
Qu Wenruo [Thu, 25 Dec 2014 01:32:12 +0000 (09:32 +0800)]
btrfs-progs: Move btrfs-image dump to corresponding dir

Move these obvious btrfs-image to its corresponding dir to use the new
infrastructure.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: New btrfsck test infrastructure
Qu Wenruo [Thu, 25 Dec 2014 01:32:11 +0000 (09:32 +0800)]
btrfs-progs: New btrfsck test infrastructure

Change the old btrfsck test infrastructure (btrfs-image dump or xz raw
dump) to the new test infrastructure.

1) Test case layout
The new infrastructure is dir based, each dir is one test type, and can
contain multiple images/scripts for different corner cases.
So layout will be the following:
btrfs-progs
|-tests
    |-fsck-tests
|-001-SOME-CORRUPT-TYPE
|-IMAGE-FOR-CASE1
|-IMAGE-FOR-CASE2

2) Test case image types
Only 2 types for test case images.
a) btrfs-image dump
   This one is the simplest case, one only needs to add the image to
   corresponding dir.

b) custom script
   This one is for all the resting cases which can't fit btrfs-image,
   like csum error or script can generate the image (this reduces the
   size obviously and good for review)
   The old binary dump also belongs to this type, so need to add script
   to extract them.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: remove uneccessary subvol name check for subvol deletion
Gui Hecheng [Thu, 18 Dec 2014 03:32:35 +0000 (11:32 +0800)]
btrfs-progs: remove uneccessary subvol name check for subvol deletion

When we want to delete a subvol, we first check to see whether it is
a subvolume or not. After the check, we are sure that it is a valid
subvol, don't have to check its name.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
[removed unused variable 'len']
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: btrfstune: fix multiple options error
Fan Chengniang [Fri, 9 Jan 2015 08:11:42 +0000 (16:11 +0800)]
btrfs-progs: btrfstune: fix multiple options error

when we use multiple options, error return status will be override by the
last option status.

example: btrfstune -S 1 -r /dev/loop0

when -S option fails and -r option succeeds, return value is 0, rather than
1, where 1 is the right return status.

Reported-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: add missing options to qgroup limit
Fan Chengniang [Tue, 13 Jan 2015 03:53:16 +0000 (11:53 +0800)]
btrfs-progs: add missing options to qgroup limit

btrfs qgroup limit has two options -c and -e,. They were forgotten to add
to manpage.

Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Fix wrong return value when executing 'fi show' on umounted device.
Qu Wenruo [Wed, 14 Jan 2015 06:50:40 +0000 (14:50 +0800)]
btrfs-progs: Fix wrong return value when executing 'fi show' on umounted device.

When executing 'btrfs fi show' on unmounted device, even no problem
happens, the return value is still 1 not 0.

The problem lies in search_umounted_fs_uuids(), where when it finds the
given uuid, it should return 1, but later uuid copy overwrites the return
value, causing it always return 0 under that case.

Fix it by pass found as pointer, and return value only indicates
whether anything wrong happens, whether found or not is stored in the
new parameter.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: restore backtrace functionality on glibc
Merlijn Wajer [Wed, 14 Jan 2015 12:13:15 +0000 (13:13 +0100)]
btrfs-progs: restore backtrace functionality on glibc

Originally broke in commit c2691f807ddd2c6b261c5707f6838a45d9275390

__glibc__ should have been __GLIBC__

We also include features.h ; although most includes (at least stdlib.h)
typically already include it -- at least on glibc, where it matters.

Signed-off-by: Merlijn Wajer <merlijn@wizzup.org>
Reported-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Remove redundant short description from cmd_snapshot_usage
Martin Volf [Fri, 9 Jan 2015 21:27:21 +0000 (22:27 +0100)]
btrfs-progs: Remove redundant short description from cmd_snapshot_usage

cmd_snapshot_usage in cmds-subvolume.c contains the short description
twice. Remove the first one.

Signed-off-by: Martin Volf <martin.volf.42@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs progs v3.18.1
David Sterba [Fri, 9 Jan 2015 18:22:29 +0000 (19:22 +0100)]
Btrfs progs v3.18.1

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Don't increase error count if the inode can be repaired.
Qu Wenruo [Mon, 22 Dec 2014 02:53:36 +0000 (10:53 +0800)]
btrfs-progs: Don't increase error count if the inode can be repaired.

The original check_inode_recs() will return -1 if found any error in a
inode_record. This is OK for original design since there is almost
nothing can repair at that time.

However more and more error from nlink mismatch to missing inode item
can be repaired in try_repair_inode(), check_inode_recs() should not
increase the error count if the inode can be repair.

With this patch, repair function for leaf-corruption will not return
error if all corruption inode can be recovered.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fix some format errors in doc
Fan Chengniang [Fri, 9 Jan 2015 07:08:56 +0000 (15:08 +0800)]
btrfs-progs: fix some format errors in doc

Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc: fix format of btrfs-replace
Tsutomu Itoh [Thu, 8 Jan 2015 02:40:53 +0000 (11:40 +0900)]
btrfs-progs: doc: fix format of btrfs-replace

Current 'man btrfs-replace' is as follows:

========================================================================
...
...
           -f
               force using and overwriting <targetdev> even if it looks like
               containing a valid btrfs filesystem.

               A valid filesystem is assumed if a btrfs superblock is found
               which contains a correct checksum. Devices which are currently
               mounted are never allowed to be used as the <targetdev>. -B::::
               no background replace.
...
...
========================================================================

The format of 'B' option is wrong. So, fix it.

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Fix a copy-n-paste bug in btrfs_read_fs_root().
Qu Wenruo [Wed, 7 Jan 2015 09:23:43 +0000 (17:23 +0800)]
btrfs-progs: Fix a copy-n-paste bug in btrfs_read_fs_root().

Introduced in commit 96ec888aad41969 ("btrfs-progs: add quota group
verify code").

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>