platform/upstream/btrfs-progs.git
9 years agobtrfs-progs: use strncpy in is_same_blk_file
David Sterba [Sat, 3 Jan 2015 02:10:55 +0000 (03:10 +0100)]
btrfs-progs: use strncpy in is_same_blk_file

Although we're getting strings from the caller, let's be safe.

Resolves-coverity-id: 1199475
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: check, handle error in fix_key_order
David Sterba [Sat, 3 Jan 2015 01:47:32 +0000 (02:47 +0100)]
btrfs-progs: check, handle error in fix_key_order

In case the buffer is corrupted and the for loop does not happen, we'd
return garbage. The caller retunrs -EIO in case of any corruption, use
that value in fix_key_order.

Resolves-coverity-id: 1246944
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc subvolume, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:27:41 +0000 (02:27 +0100)]
btrfs-progs: doc subvolume, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc scrub, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:22:10 +0000 (02:22 +0100)]
btrfs-progs: doc scrub, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc replace, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:20:50 +0000 (02:20 +0100)]
btrfs-progs: doc replace, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc quota, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:20:06 +0000 (02:20 +0100)]
btrfs-progs: doc quota, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc qgroup, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:19:31 +0000 (02:19 +0100)]
btrfs-progs: doc qgroup, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc property, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:18:15 +0000 (02:18 +0100)]
btrfs-progs: doc property, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc inspect-internal, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:17:28 +0000 (02:17 +0100)]
btrfs-progs: doc inspect-internal, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc device, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:15:55 +0000 (02:15 +0100)]
btrfs-progs: doc device, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc, undocument old balance syntax
David Sterba [Sat, 3 Jan 2015 01:12:56 +0000 (02:12 +0100)]
btrfs-progs: doc, undocument old balance syntax

Standalone balance subcommand has been around since 3.3.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc balance, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 01:09:08 +0000 (02:09 +0100)]
btrfs-progs: doc balance, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc filesystem, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 00:49:24 +0000 (01:49 +0100)]
btrfs-progs: doc filesystem, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc btrfs, sort subcommands alphabetically
David Sterba [Sat, 3 Jan 2015 00:45:17 +0000 (01:45 +0100)]
btrfs-progs: doc btrfs, sort subcommands alphabetically

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc restore, cleanups for wiki conversion
David Sterba [Sat, 3 Jan 2015 00:37:40 +0000 (01:37 +0100)]
btrfs-progs: doc restore, cleanups for wiki conversion

Properly format the patch regex and add a line break.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc filesystem, cleanups for wiki conversion
David Sterba [Sat, 3 Jan 2015 00:36:39 +0000 (01:36 +0100)]
btrfs-progs: doc filesystem, cleanups for wiki conversion

Remove trailing space, add line break before NOTE.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc balance, cleanups for wiki conversion
David Sterba [Sat, 3 Jan 2015 00:34:05 +0000 (01:34 +0100)]
btrfs-progs: doc balance, cleanups for wiki conversion

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc mkfs, cleanups for wiki conversion
David Sterba [Sat, 3 Jan 2015 00:30:25 +0000 (01:30 +0100)]
btrfs-progs: doc mkfs, cleanups for wiki conversion

- remove trailing whitespace
- use +mono+ formatting for command line example

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc mkfs, mark leafsize deprecated
David Sterba [Sat, 3 Jan 2015 00:26:31 +0000 (01:26 +0100)]
btrfs-progs: doc mkfs, mark leafsize deprecated

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc: fix incorrect format of 'l' option in mkfs.btrfs
Tsutomu Itoh [Wed, 24 Dec 2014 07:10:52 +0000 (16:10 +0900)]
btrfs-progs: doc: fix incorrect format of 'l' option in mkfs.btrfs

The format of 'l' option in mkfs.btrfs.txt is wrong.
And, when the head of the character string is 65536, the following warning
is displayed.

    $ make
    Making all in Documentation
        [ASCII]  mkfs.btrfs.xml
    asciidoc: WARNING: mkfs.btrfs.xml.tmp1: line 67: list item index: expected 1 got 65536
        [XMLTO]  mkfs.btrfs.8
        [GZ]     mkfs.btrfs.8.gz
    rm mkfs.btrfs.8 mkfs.btrfs.xml

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: doc filesystem, add unit suffixes to option descriptions
David Sterba [Fri, 2 Jan 2015 16:51:06 +0000 (17:51 +0100)]
btrfs-progs: doc filesystem, add unit suffixes to option descriptions

Reported-by: Chris Murphy <lists@colorremedies.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: doc filesystem, fix quoting of size suffixes
David Sterba [Fri, 2 Jan 2015 16:22:07 +0000 (17:22 +0100)]
btrfs-progs: doc filesystem, fix quoting of size suffixes

Escape the first quote of two to cancel effects of ordinary '...' .

Reported-by: Chris Murphy <lists@colorremedies.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs progs v3.18
David Sterba [Tue, 30 Dec 2014 16:23:12 +0000 (17:23 +0100)]
Btrfs progs v3.18

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fix minor leak of dev_info in btrfs_scan_kernel
David Sterba [Tue, 30 Dec 2014 14:37:29 +0000 (15:37 +0100)]
btrfs-progs: fix minor leak of dev_info in btrfs_scan_kernel

Resolves-coverity-id: 1127098
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fix overflow check in btrfs_insert_inode_ref
David Sterba [Tue, 30 Dec 2014 14:16:17 +0000 (15:16 +0100)]
btrfs-progs: fix overflow check in btrfs_insert_inode_ref

Resolves-coverity-id: 1260247
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: check, missing parens around compound block in find_normal_file_extent
David Sterba [Tue, 30 Dec 2014 14:05:50 +0000 (15:05 +0100)]
btrfs-progs: check, missing parens around compound block in find_normal_file_extent

Resolves-coverity-id: 1260248
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fi show, don't leak canonical path
David Sterba [Tue, 30 Dec 2014 14:01:13 +0000 (15:01 +0100)]
btrfs-progs: fi show, don't leak canonical path

Resolves-coverity-id: 1260252
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: check, fix path leak in error branch
David Sterba [Tue, 30 Dec 2014 13:52:55 +0000 (14:52 +0100)]
btrfs-progs: check, fix path leak in error branch

Resolves-coverity-id: 1260250
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Documentation: add T/P/E description for resize cmd
Gui Hecheng [Tue, 30 Dec 2014 01:52:17 +0000 (09:52 +0800)]
btrfs-progs: Documentation: add T/P/E description for resize cmd

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: refine btrfs-debug-tree error prompt when a mount point given
Gui Hecheng [Thu, 25 Dec 2014 01:16:35 +0000 (09:16 +0800)]
btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given

Now, if exec:
# btrfs-debug-tree <mount_point>
it echos:
: Superblock bytenr is larger than device size

But it is quite misleading, because it is a valid btrfs.
In this case, we should tell the developer to provide a block device.

After apply:
: '<mount_point>' is not a block device

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: move check_arg_type() to util.c
Gui Hecheng [Thu, 25 Dec 2014 01:16:34 +0000 (09:16 +0800)]
btrfs-progs: move check_arg_type() to util.c

The check_arg_type() function does quite generic thing, move it to
utils.c.

Signed-off-by: Gui Hecheng <guihc.fnst@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 btrfs fi show by uuid and label
Justin Maggard [Tue, 23 Dec 2014 19:34:52 +0000 (11:34 -0800)]
btrfs-progs: Fix btrfs fi show by uuid and label

Commit 8be2fff (btrfs-progs: apply realpath for btrfs fi
show when mount point is given) changed the behavior of
btrfs fi show to return an error if the call to realpath()
failed.  This broke the ability to specify a filesystem by
uuid or label.

So let's not consider a failed call to realpath() as an
error.  If the user really specified a bad device, just
return nothing like we did before.

Signed-off-by: Justin Maggard <jmaggard10@gmail.com>
Reviewed-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Fix a bug in reset_nlink() which may deletes the recovered file
Qu Wenruo [Tue, 23 Dec 2014 01:29:44 +0000 (09:29 +0800)]
btrfs-progs: Fix a bug in reset_nlink() which may deletes the recovered file

In reset_nlink(), we believe rec->found_link as accurate number of the
valid links. However it only records the number of found DIR_ITEM, so we
can't use it as reliable value.

Before this patch, in some case, leaf corruption recovery will believe
there is a valid backref but don't add_link() since it can't find any
valid one and don't put it into the lost+found dir.
So the recovered inode will be considered as an orphan item without
orphan item and repair_inode_orphan_item() will add orphan item for it,
causing all the filename/filetype we recovered being a waste of time.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs fix wrong memory free on check_is_root
Satoru Takeuchi [Thu, 18 Dec 2014 07:39:26 +0000 (16:39 +0900)]
btrfs-progs fix wrong memory free on check_is_root

When "/" is Btrfs, "btrfs property <subcommand> /" regards it
as non-root by mistake.

check_is_root() regards @object as a file system root if
the following two conditions are satisfied.

 a) Both @object and its parent directory are Btrfs object
    (file system root, subvolume, inode, and device
    used for Btrfs).
 b) fsid of the above mentioned two objects are different.

It doesn't work if @object is "/" because, in this case,
fsid of "/" and its parent (it's also "/"), are the same.

* Test environment

Two Btrfs file system (not subvolume) "/" and "/home/sat/mnt".

* How to reproduce

Submit "btrfs prop get" against the above mentioned file systems.

* Test Result

** Actual result (without my patch)

==========================
ro=false
label=                 # label is displayed because it's a file system root
ro=false               # label is not displayed even if it's a file system root
==========================
** Expected result (with my patch)

==========================
ro=false
label=
ro=false
label=foo            # label is displayed
===========================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Reported-by: Naohiro Aota <naota@elisp.net>
Reviewed-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: let btrfs_free_path accept NULL
David Sterba [Fri, 19 Dec 2014 16:01:40 +0000 (17:01 +0100)]
btrfs-progs: let btrfs_free_path accept NULL

Same in kernel and matches semantics of free().

Resolves-Coverity-CID: 1054881
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: check allocation result in add_clone_source
David Sterba [Fri, 19 Dec 2014 15:55:32 +0000 (16:55 +0100)]
btrfs-progs: check allocation result in add_clone_source

Resolves-Coverity-CID: 1054894
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: check result of first_cache_extent
David Sterba [Fri, 19 Dec 2014 15:22:59 +0000 (16:22 +0100)]
btrfs-progs: check result of first_cache_extent

If the tree's empty, we'll get NULL and dereference it.

Resolves-Coverity-CID: 1248828
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fragments, close output file on error
David Sterba [Fri, 19 Dec 2014 15:15:39 +0000 (16:15 +0100)]
btrfs-progs: fragments, close output file on error

Resolves-Coverity-CID: 1258794
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: corrupt block, add break after option U
David Sterba [Fri, 19 Dec 2014 15:11:59 +0000 (16:11 +0100)]
btrfs-progs: corrupt block, add break after option U

Resolves-Coverity-CID: 1258793
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: corrupt block, add missing break to option I
David Sterba [Fri, 19 Dec 2014 15:08:48 +0000 (16:08 +0100)]
btrfs-progs: corrupt block, add missing break to option I

Using -I would imply -d.

Resolves-Coverity-CID: 1258792
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: move contents of math.h to utils.h and delete
David Sterba [Fri, 19 Dec 2014 14:31:00 +0000 (15:31 +0100)]
btrfs-progs: move contents of math.h to utils.h and delete

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: cleanup: avoid to use literal for getopt val
Satoru Takeuchi [Fri, 19 Dec 2014 05:31:54 +0000 (14:31 +0900)]
btrfs-progs: cleanup: avoid to use literal for getopt val

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Enhance the document of btrfs property
Satoru Takeuchi [Fri, 19 Dec 2014 07:22:49 +0000 (16:22 +0900)]
btrfs-progs: Enhance the document of btrfs property

Enhance the document of btrfs property as follows.

- Add the description about the candidates of <name>.
- Enrich the description of <object>.
- Fix typos and some redundancy.

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Reported-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Remove deprecated _BSD_SOURCE macro.
Qu Wenruo [Fri, 19 Dec 2014 06:13:12 +0000 (14:13 +0800)]
btrfs-progs: Remove deprecated _BSD_SOURCE macro.

Fix the following gcc(>4.9) and clang warning:

In file included from cmds-receive.c:24:
In file included from ./kerncompat.h:22:
In file included from /usr/include/stdio.h:27:
/usr/include/features.h:148:3: warning: "_BSD_SOURCE and _SVID_SOURCE
are deprecated, use _DEFAULT_SOURCE" [-W#warnings]
  ^
1 warning generated.

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: Remove a unused function offset_to_bitmap()
Qu Wenruo [Fri, 19 Dec 2014 06:13:11 +0000 (14:13 +0800)]
btrfs-progs: Remove a unused function offset_to_bitmap()

Fix the following clang warning:

free-space-cache.c:464:19: warning: unused function 'offset_to_bitmap'
[-Wunused-function]
static inline u64 offset_to_bitmap(struct btrfs_free_space_ctl *ctl,
                  ^
1 warning generated.

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: Remove a unused function root_gtp_mask().
Qu Wenruo [Fri, 19 Dec 2014 06:13:10 +0000 (14:13 +0800)]
btrfs-progs: Remove a unused function root_gtp_mask().

Fix the following clang warning when compiling btrfs-progs:

radix-tree.c:78:21: warning: unused function 'root_gfp_mask'
[-Wunused-function]
static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
                    ^
1 warning generated.

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 a clang dead-judgement warning in disk-io.c.
Qu Wenruo [Fri, 19 Dec 2014 06:13:09 +0000 (14:13 +0800)]
btrfs-progs: Fix a clang dead-judgement warning in disk-io.c.

When compiled with clang, the following warning is outputted.

disk-io.c:1017:15: warning: comparison of unsigned expression < 0 is
always false [-Wtautological-compare]
        if (dev_size < 0)
            ~~~~~~~~ ^ ~
1 warning generated.

This is because dev_size is defined as unsigned type, but lseek() will
return singed valued.
So the judgement will always to false.

Use temporary off_t return value to solve it.

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: Makefile: Move linker only option to LDFLAGS
Qu Wenruo [Fri, 19 Dec 2014 06:13:08 +0000 (14:13 +0800)]
btrfs-progs: Makefile: Move linker only option to LDFLAGS

Move the linker only option -rdynamic to LDFLAGS.
This resolve lots of the following warning if using clang as CC:
clang: warning: argument unused during compilation: '-rdynamic'

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: remove false dependency on libm
David Sterba [Fri, 19 Dec 2014 13:59:22 +0000 (14:59 +0100)]
btrfs-progs: remove false dependency on libm

It ends up in the final binary, but there are not math functions used.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: disable backtrace and define __always_inline
Merlijn Wajer [Sat, 13 Dec 2014 14:08:43 +0000 (15:08 +0100)]
btrfs-progs: disable backtrace and define __always_inline

Disable backtrace and define __always_inline when glibc is not used as
libc. This, together with some header changes allows btrfs-progs to
compile with musl-libc.

Signed-off-by: Merlijn Wajer <merlijn@wizzup.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: include headers required for musl-libc
Merlijn Wajer [Sat, 13 Dec 2014 14:07:25 +0000 (15:07 +0100)]
btrfs-progs: include headers required for musl-libc

This fixes various compilation errors where PATH_MAX and XATTR_SIZE_MAX
were missing. To my knowledge, this should have no bad side effects.

Signed-off-by: Merlijn Wajer <merlijn@wizzup.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add testcase for leaf-corrupted btrfsck repairing.
Qu Wenruo [Mon, 15 Dec 2014 03:16:29 +0000 (11:16 +0800)]
btrfs-progs: Add testcase for leaf-corrupted btrfsck repairing.

Add testcase for leaf-corrupted btrfsck repairing using the new
generate_image.sh method.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
9 years agoBtrfs-progs: add two new test images
Josef Bacik [Fri, 10 Oct 2014 20:50:42 +0000 (16:50 -0400)]
Btrfs-progs: add two new test images

This adds two new test images

1) 008-bad-offset-snapshots.  This has a corrupt item with multiple snapshots
pointing to it, to make sure the bad block repair stuff doesn't loop and
actually repairs stuff.  It also requires the dir index repair stuff to pass our
built in tests which is why it's not tied to the same commit.

2) 009-bad-dir-index-name.img. This has a corrupt name in a dir index to make
sure our dir index repair stuff is working properly.

Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
9 years agobtrfs-progs: check, update documentation
David Sterba [Thu, 18 Dec 2014 15:04:10 +0000 (16:04 +0100)]
btrfs-progs: check, update documentation

Add recently added options to manpage, a few other rewordings.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: unify unit mode parameters and variables
David Sterba [Thu, 18 Dec 2014 13:52:36 +0000 (14:52 +0100)]
btrfs-progs: unify unit mode parameters and variables

Use unsigned type and a common name everywhere.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: dev usage, update manpage
David Sterba [Thu, 18 Dec 2014 14:23:08 +0000 (15:23 +0100)]
btrfs-progs: dev usage, update manpage

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: dev usage, add switches to set output units
David Sterba [Wed, 17 Dec 2014 17:16:18 +0000 (18:16 +0100)]
btrfs-progs: dev usage, add switches to set output units

Same set of options as 'fi df': binary and decimal bases, human readable
options etc.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fi usage, update manpage
David Sterba [Thu, 18 Dec 2014 14:20:11 +0000 (15:20 +0100)]
btrfs-progs: fi usage, update manpage

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fi usage, add switches to set output units
David Sterba [Wed, 17 Dec 2014 17:11:58 +0000 (18:11 +0100)]
btrfs-progs: fi usage, add switches to set output units

Same set of options as 'fi df': binary and decimal bases, human readable
options etc.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fi usage, change option for tabular output to T
David Sterba [Wed, 17 Dec 2014 17:05:48 +0000 (18:05 +0100)]
btrfs-progs: fi usage, change option for tabular output to T

We're going to use -t for tera- units prefix, same as 'fi df' does.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add a brief explanation of btrfs property in man 8 btrfs
Satoru Takeuchi [Tue, 16 Dec 2014 09:42:38 +0000 (18:42 +0900)]
btrfs-progs: Add a brief explanation of btrfs property in man 8 btrfs

As Chris reported at the following mail, although
btrfs property has its own manpage, man 8 btrfs-property,
there is no explanation about it in man 8 btrfs.

https://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg40134.html

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Reported-by: Chris Murphy <lists@colorremedies.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fix typedef
Karel Zak [Fri, 12 Dec 2014 10:58:04 +0000 (11:58 +0100)]
btrfs-progs: fix typedef

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: tests: build prerequisities, btrfs-image and btrfs
David Sterba [Fri, 12 Dec 2014 14:49:26 +0000 (15:49 +0100)]
btrfs-progs: tests: build prerequisities, btrfs-image and btrfs

Build required utilities from the main Makefile and just check in the
test scripts.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: tests: use 'btrfs check' instead of btrfsck
David Sterba [Fri, 12 Dec 2014 14:50:41 +0000 (15:50 +0100)]
btrfs-progs: tests: use 'btrfs check' instead of btrfsck

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: subvol delete: rename variable to match the option name
David Sterba [Thu, 27 Nov 2014 18:34:22 +0000 (19:34 +0100)]
btrfs-progs: subvol delete: rename variable to match the option name

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: subvol delete: add verbosity option
David Sterba [Thu, 27 Nov 2014 18:26:35 +0000 (19:26 +0100)]
btrfs-progs: subvol delete: add verbosity option

Add an the option -v and use it for the transaction commit mode message.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: let subvol delete print commit mode inline
David Sterba [Thu, 27 Nov 2014 18:15:06 +0000 (19:15 +0100)]
btrfs-progs: let subvol delete print commit mode inline

There are options to specify if the subvolume deletion should wait for
commit after each subvol or at the end. This is reported at the
beginning and considered as a noise. We'd like to report the mode for
each subvolume instead.

http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34617.html

Reported-by: Marc MERLIN <marc@merlins.org
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs-progs, fsck: move root items repair after root rebuilding
Wang Shilong [Wed, 26 Nov 2014 02:58:52 +0000 (10:58 +0800)]
Btrfs-progs, fsck: move root items repair after root rebuilding

If some critical roots are corrupt, reapr_root_items() will fail,
this is detected by fsck_tests.sh's extent rebuilding tests.

Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs-progs: fsck: add ability to rebuild extent tree with snapshots
Wang Shilong [Wed, 26 Nov 2014 02:58:51 +0000 (10:58 +0800)]
Btrfs-progs: fsck: add ability to rebuild extent tree with snapshots

This patch makes us to rebuild a really corrupt extent tree with snapshots.
To implement this, we have to verify whether a block is FULL BACKREF.

This idea come from Josef Bacik:

1) We walk down the original tree, every eb we encounter has
btrfs_header_owner(eb) == root->objectid.  We add normal references
for this root (BTRFS_TREE_BLOCK_REF_KEY) for this root.  World peace
is achieved.

2) We walk down the snapshotted tree.  Say we didn't change anything
at all, it was just a clean snapshot and then boom.  So the
btrfs_header_owner(root->node) == root->objectid, so normal backref.
We walk down to the next level, where btrfs_header_owner(eb) !=
root->objectid, but the level above did, so we add normal refs for all
of these blocks.  We go down the next level, now our
btrfs_header_owner(parent) != root->objectid and
btrfs_header_owner(eb) != root->objectid.  This is where we need to
now go back and see if btrfs_header_owner(eb) currently has a ref on
eb.  If it does we are done, move on to the next block in this same
level, we don't have to go further down.

3) Harder case, we snapshotted and then changed things in the original
root.  Do the same thing as in step 2, but now we get down to
btrfs_header_owner(eb) != root->objectid && btrfs_header_owner(parent)
!= root->objectid.  We lookup the references we have for eb and notice
that btrfs_header_owner(eb) no longer refers to eb.  So now we must
set FULL_BACKREF on this extent reference and add a
SHARED_BLOCK_REF_KEY for this eb using the parent->start as the
offset.  And we need to keep walking down and doing the same thing
until we either hit level 0 or btrfs_header_owner(eb) has a ref on the
block.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs-progs: fsck: deal with snapshot one by one when rebuilding extent tree
Wang Shilong [Wed, 26 Nov 2014 02:58:50 +0000 (10:58 +0800)]
Btrfs-progs: fsck: deal with snapshot one by one when rebuilding extent tree

Previously, we deal with node block firstly and then leaf block which can
maximize readahead. However, to rebuild extent tree, we need deal with snapshot
one by one.

This patch makes us deal with snapshot one by one if we need rebuild extent
tree otherwise we drop into previous way.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Wang Shilong <wangshilong1991@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: basic support for TREE_SEARCH_V2 ioctl
David Sterba [Tue, 25 Nov 2014 17:46:16 +0000 (18:46 +0100)]
btrfs-progs: basic support for TREE_SEARCH_V2 ioctl

Add the interface and helper that checks if the v2 ioctl is supported.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: mkfs: make skinny-metadata default
David Sterba [Thu, 4 Dec 2014 18:16:30 +0000 (19:16 +0100)]
btrfs-progs: mkfs: make skinny-metadata default

According to public poll, this is desired and deemed to be safe. Feature
introduced in kernel 3.10 (Jun 2013).

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add inode item rebuild function.
Qu Wenruo [Tue, 9 Dec 2014 08:27:32 +0000 (16:27 +0800)]
btrfs-progs: Add inode item rebuild function.

Add a basic inode item rebuild function for I_ERR_NO_INODE_ITEM.
The main use case is to repair btrfs which fs root has corrupted leaf,
but it is already working for case if the corrupteed fs root leaf/node
contains no inode extent_data.

The repair needs 3 elements for inode rebuild:
1. inode number
   This is quite easy, existing inode_record codes will detect it quite
   well.

2. inode type
   This is the trick part. The only reliable method is to recovery it from
   parent's dir_index/item.
   The remaining method will search for regular file extent for FILE
   type or child's backref for DIR(todo).
   Fallback will be FILE.

Inode name(inode_ref) will be recoverd by nlink repair function.

This is just a fundamental implement, some advanced recovery can be
improved later with btrfs-progs infrastructure change.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Recover btree by dropping corrupted leaf/node.
Qu Wenruo [Tue, 9 Dec 2014 08:27:31 +0000 (16:27 +0800)]
btrfs-progs: Recover btree by dropping corrupted leaf/node.

Current btrfsck can skip corrupted leaf and even repair some corrupted
one if their bytenr or key order is wrong.

However when it comes to csum error leaf, btrfsck can only skip them,
which is OK for read-only iteration, but is bad for write.

This patch introduce the new repair_btree() function to recover the
btree, deleting all the corrupted leaf/node including corresponding
extent, allowing later write into the btree.

This patch provides the basis for later recovery with corrupted leaves.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: record and report leaf/node corruption in fs/subvol tree
Qu Wenruo [Tue, 9 Dec 2014 08:27:30 +0000 (16:27 +0800)]
btrfs-progs: record and report leaf/node corruption in fs/subvol tree

When leaf/node is corrupted in fs/subvolume root, btrfsck can ignore it
without much pain except some stderr messages complaining about it.
But this works fine doing read-only works, if we want to do deeper
recovery like rebuild missing inodes in the b+tree, it will cause
problem.

At least, info user that there is something wrong in the btree,
and this patch provides the base for later btree repair.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add fixing function for inodes whose nlink dismatch
Qu Wenruo [Tue, 9 Dec 2014 08:27:29 +0000 (16:27 +0800)]
btrfs-progs: Add fixing function for inodes whose nlink dismatch

[BUG]
At least two users have already hit a bug in btrfs causing file
missing(Chromium config file).
The missing file's nlink is still 1 but its backref points to non-exist
parent inode.

This should be a kernel bug, but btrfsck fix is needed anyway.

[FIX]
For such nlink mismatch inode, we will reset all the inode_ref with its
dir_index/item (including valid one), and re-add the valids.
If there is no valid backref for it, create 'lost+found' under the root
of the subvolume and add link to the directory.

Reported-by: Mike Gavrilov <mikhail.v.gavrilov@gmail.com>
Reported-by: Ed Tomlinson <edt@aei.ca>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add helper function find_file_name/type for nlink and inode_item repair.
Qu Wenruo [Tue, 9 Dec 2014 08:27:28 +0000 (16:27 +0800)]
btrfs-progs: Add helper function find_file_name/type for nlink and inode_item repair.

Add find_file_name() and find_file_type() function for later nlink and
inode_item repair.

Later nlink repair will use both function and and inode_item repair will
use find_file_type().

They are done by searching the backref list, dir_item/index for type
search and dir_item/index or inode_ref for name search.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add count_digits() function to help calculate filename len.
Qu Wenruo [Tue, 9 Dec 2014 08:27:27 +0000 (16:27 +0800)]
btrfs-progs: Add count_digits() function to help calculate filename len.

Add count_digits() function in utils.h to help calculate filename with
ino suffix.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add btrfs_mkdir() function for the incoming 'lost+found' fsck mechanism.
Qu Wenruo [Tue, 9 Dec 2014 08:27:26 +0000 (16:27 +0800)]
btrfs-progs: Add btrfs_mkdir() function for the incoming 'lost+found' fsck mechanism.

With the previous btrfs inode operations patches, now we can use
btrfs_mkdir() to create the 'lost+found' dir to do some data salvage in
btrfsck.

This patch along with previous ones will make data salvage easier.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add btrfs_unlink() and btrfs_add_link() functions.
Qu Wenruo [Wed, 3 Dec 2014 04:18:30 +0000 (12:18 +0800)]
btrfs-progs: Add btrfs_unlink() and btrfs_add_link() functions.

Add btrfs_unlink() and btrfs_add_link() functions in inode.c,
for the incoming btrfs_mkdir() and later inode operations functions.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Record highest inode number before repair.
Qu Wenruo [Tue, 9 Dec 2014 08:27:24 +0000 (16:27 +0800)]
btrfs-progs: Record highest inode number before repair.

Record highest inode number before inode repair.

This is especially important for corrupted leaf case.
Under that case, if use btrfs_find_free_objectid, it may find a ino
existing in corrupted leaf but dropped by btree_recover.
If that happens, created dir will be referenced incorrectly since there
may be inode_ref or dir_index/item refers to it.

So we must record the highest inode number according to the inode_cache.
Inode_cache is OK since when a inode_ref or dir_index/item is found even
the referenced source is not found, it will be created.
If we record the highest inode number of inode_cache, and use
highest_inode + 1 as 'lost+found' dir, it will ensure the newly created
dir not conflicting with any possible inode.

This provides the basis for nlink or inode rebuild for repairing btrfs
with leaf/node corruption.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add last_cache_extent() for extent-cache.
Qu Wenruo [Tue, 9 Dec 2014 08:27:23 +0000 (16:27 +0800)]
btrfs-progs: Add last_cache_extent() for extent-cache.

Allow direct search for the last cache extent.
Provide the basis for finding the last ino in inode_cache.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Import lookup/del_inode_ref() function.
Qu Wenruo [Wed, 3 Dec 2014 04:18:29 +0000 (12:18 +0800)]
btrfs-progs: Import lookup/del_inode_ref() function.

Import lookup/del_inode_ref() function in inode-item.c, as base functions
for the incoming btrfs_add_link() and btrfs_unlink() functions.

Also modify btrfs_insert_inode_ref() and split_leaf() making them able
to deal with EXTENT_IREF incompat flag.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Import btrfs_insert/del/lookup_extref() functions.
Qu Wenruo [Wed, 3 Dec 2014 04:18:28 +0000 (12:18 +0800)]
btrfs-progs: Import btrfs_insert/del/lookup_extref() functions.

Import btrfs_insert/del/lookup_extref() functions form kernel for the
incoming btrfs_add_link() and btrfs_unlink() functions.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: convert: fix unable to rollback case with removed empty block groups
Gui Hecheng [Wed, 26 Nov 2014 02:43:41 +0000 (10:43 +0800)]
btrfs-progs: convert: fix unable to rollback case with removed empty block groups

Run fstests: btrfs/012 will fail with message:
unable to do rollback

It is because the rollback function checks sequentially each piece of space
to map to a certain block group. If some piece doesn't, rollback refuses to continue.

After kernel commit:
commit 47ab2a6c689913db23ccae38349714edf8365e0a
Btrfs: remove empty block groups automatically

Empty block groups are removed, so there are possible gaps:

|--block group 1--| |--block group 2--|
     ^
     |
    gap

So the piece of space of the gap belongs to a removed empty block group,
and rollback should detect this case, and feel free to continue.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: remove dead condition for btrfs_map_block
Gui Hecheng [Wed, 26 Nov 2014 02:43:40 +0000 (10:43 +0800)]
btrfs-progs: remove dead condition for btrfs_map_block

The @search_cache_extent() only returns the next cache_extent or NULL,
it will never return the previous cache_extent.
So just remove the dead condition for previous cache_extent handle.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: cleanup duplicate assignment of variable leaf for btrfs-restore
Gui Hecheng [Thu, 21 Aug 2014 02:56:52 +0000 (10:56 +0800)]
btrfs-progs: cleanup duplicate assignment of variable leaf for btrfs-restore

The value of variable leaf in while loop don't have to be set
for every round. Just move it outside.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: remove duplicate pthread libs from build
David Sterba [Thu, 4 Dec 2014 16:17:56 +0000 (17:17 +0100)]
btrfs-progs: remove duplicate pthread libs from build

With the task-utils it's in the default LIBS flags now. We want to use
-pthread as it also sets flags for the preprocessor.

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: convert: use task for progress indication of metadata creation
Silvio Fricke [Sun, 9 Nov 2014 22:16:56 +0000 (23:16 +0100)]
btrfs-progs: convert: use task for progress indication of metadata creation

Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: add task-utils
Silvio Fricke [Sun, 9 Nov 2014 22:16:55 +0000 (23:16 +0100)]
btrfs-progs: add task-utils

Support for monitoring progress of running tasks, based on timerfd and
pthreads.

Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agoBtrfs-progs: allow fsck to take the tree bytenr
Josef Bacik [Fri, 31 Oct 2014 18:01:21 +0000 (14:01 -0400)]
Btrfs-progs: allow fsck to take the tree bytenr

Sometimes we have a pretty corrupted fs but have an old tree bytenr that we
could use, add the ability to specify the tree root bytenr.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Tested-by: Ansgar Hockmann-Stolle <ansgar.hockmann-stolle@uni-osnabrueck.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: Add simple python front end to the search ioctl
Chris Mason [Tue, 23 Sep 2014 16:39:23 +0000 (12:39 -0400)]
btrfs-progs: Add simple python front end to the search ioctl

This is a starting point for a debugfs style python interface using
the search ioctl.  For now it can only do one thing, which is to
print out all the extents in a file and calculate the compression ratio.

Over time it will grow more features, especially for the kinds of things
we might run btrfs-debug-tree to find out.  Expect the usage and output
to change dramatically over time (don't hard code to it).

Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fix wrong num_devices for btrfs fi show with seed devices
Gui Hecheng [Thu, 13 Nov 2014 01:19:29 +0000 (09:19 +0800)]
btrfs-progs: fix wrong num_devices for btrfs fi show with seed devices

The @fi_args->num_devices in @get_fs_info() does not include seed devices.
We could just correct it by searching the chunk tree and count how
many dev_items there are in total which includes seed devices.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: remove BUG_ON on num of devices for btrfs fi show
Gui Hecheng [Fri, 7 Nov 2014 02:07:42 +0000 (10:07 +0800)]
btrfs-progs: remove BUG_ON on num of devices for btrfs fi show

The following BUG_ON:
BUG_ON(ndevs >= fi_args->num_devices)
is not needed, because it always fails with seed devices present.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: skip fs with no seed when build seed/sprout mapping for fi show
Gui Hecheng [Tue, 11 Nov 2014 06:39:14 +0000 (14:39 +0800)]
btrfs-progs: skip fs with no seed when build seed/sprout mapping for fi show

There is no need to try to build seed/sprout mapping for those btrfs
without seed devices, so just skip such fs.
We could get the total number of devices from the disk super block, if it
equals the number of items in list @fs_devices->devices, then there shouldn't
be any seed devices.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: rebuild missing block group during chunk recovery if possible
Qu Wenruo [Thu, 30 Oct 2014 02:54:03 +0000 (10:54 +0800)]
btrfs-progs: rebuild missing block group during chunk recovery if possible

Before the patch, chunk will be considered bad if the corresponding
block group is missing, even the only uncertain data is the 'used'
member of the block group.

This patch will try to recalculate the 'used' value of the block group
and rebuild it.
So even only chunk item and dev extent item is found, the chunk can be
recovered.
Although if extent tree is damanged and needed extent item can't be
read, the block group's 'used' value will be the block group length, to
prevent any later write/block reserve damaging the block group.
In that case, we will prompt user and recommend them to use
'--init-extent-tree' to rebuild extent tree if possible.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: make the search target device routine more clear for fi show
Gui Hecheng [Thu, 30 Oct 2014 02:44:49 +0000 (10:44 +0800)]
btrfs-progs: make the search target device routine more clear for fi show

Extract the procedure of searching for a target device for fi show
from the @map_seed_devices() function to make it more clear.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: rework calculations of fi usage
David Sterba [Thu, 26 Jun 2014 13:42:24 +0000 (15:42 +0200)]
btrfs-progs: rework calculations of fi usage

This patch reworks the basic calculations of 'fi usage'. It does not address
all problems but should make the code more prepared to do so.

The original code tries to estimate the free space that could lead to negative
numbers for some raid profiles:

Data, RAID1: total=147.00GiB, used=141.92GiB
System, RAID1: total=32.00MiB, used=36.00KiB
Metadata, RAID1: total=2.00GiB, used=1.17GiB
GlobalReserve, single: total=404.00MiB, used=0.00B

Overall:
    Device size:                 279.46GiB
    Device allocated:            298.06GiB
    Device unallocated:           16.00EiB
    Used:                        286.18GiB
    Free (estimated):              8.00EiB      (min: 8.00EiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              404.00MiB      (used: 0.00B)

Eg. "Device size" - "Device allocated" = negative number or a very large
positive, hence the EiB values.

There are logical and raw numbers multiplied by ratios mixed together,
so the new code makes it explicit which kind is being used. The data and
metadata ratios are calculated separately.

Output after this patch will look like:

Overall:
    Device size:                 558.92GiB
    Device allocated:            298.06GiB
    Device unallocated:          260.86GiB
    Used:                        286.18GiB
    Free (estimated):            135.51GiB      (min: 135.51GiB)
    Data ratio:                       2.00
    Metadata ratio:                   2.00
    Global reserve:              404.00MiB      (used: 0.00B)

Data,RAID1: Size:147.00GiB, Used:141.92GiB
   /dev/sdc      147.00GiB
   /dev/sdd      147.00GiB

Metadata,RAID1: Size:2.00GiB, Used:1.17GiB
   /dev/sdc        2.00GiB
   /dev/sdd        2.00GiB

System,RAID1: Size:32.00MiB, Used:36.00KiB
   /dev/sdc       32.00MiB
   /dev/sdd       32.00MiB

Unallocated:
   /dev/sdc      130.43GiB
   /dev/sdd      130.43GiB

Changes:
* Device size is now the raw size, same for the following three
* Free is the logical size
* Max/min were reduced to just min

Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc        280G  144G  141G  51% /mnt/sdc

The difference between Avail and Free is there because userspace tool does a
different guesswork than kernel.

Issues not addressed by this patch:
* RAID56 profiles are not handled
* mixed profiles are not handled

Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: fix improper output msg for btrfs-fi-usage
Gui Hecheng [Thu, 24 Jul 2014 03:21:54 +0000 (11:21 +0800)]
btrfs-progs: fix improper output msg for btrfs-fi-usage

Even if run as root:
# su
# btrfs file usage <path> <== path exits outside the mnt point
We get the output:
WARNING: ..., run as root
WARNING: ..., run as root
ERROR:...

It is because in load_chunk_info, the errno of ioctl is not judged
but rather the ret value of ioctl is judged. And the ret value of
ioctl is -1 which happens to match -EPERM exactly.
So the outer warning is printed.

Just judge the errno of ioctl and prevent the ret value of load_chunk_info
to be -1 in other error conditions.

For load_device_info, the problem and fix is the same.
After the fix, the 'run as root' WARNINGs will not show up in this condition.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
9 years agobtrfs-progs: output the correct path when fi-usage failed
Gui Hecheng [Thu, 24 Jul 2014 03:27:28 +0000 (11:27 +0800)]
btrfs-progs: output the correct path when fi-usage failed

When we exec the following cmd:
# btrfs file usage -t <path>  <-- an invalid path
output:
# ERROR: can't access '-t'
should be:
# ERROR: can't access 'path'

Just replace the static 'argv[1]' with 'argv[i]'.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>