platform/upstream/btrfs-progs.git
10 years agobtrfs-progs: fix mkfs.btrfs segfault with --features option
Holger Hoffstätte [Sat, 26 Apr 2014 09:41:04 +0000 (09:41 +0000)]
btrfs-progs: fix mkfs.btrfs segfault with --features option

The mkfs.btrfs --features long option takes an argument but does not
declare it. Consequently getopt does not allocate an argument, which
makes an unconditional strdup() crash during options parsing.
Fix by declaring the argument in the options alias array.

Signed-off-by: Holger Hoffstätte <holger.hoffstaette@googlemail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: mkfs: remove ununsed parameters
Rakesh Pandit [Fri, 25 Apr 2014 23:05:31 +0000 (02:05 +0300)]
Btrfs-progs: mkfs: remove ununsed parameters

Remove ununsed parameters since 71d6bd3c in create_raid_groups.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: set string end sing '\0' for property
Liu Bo [Fri, 25 Apr 2014 10:44:03 +0000 (18:44 +0800)]
Btrfs-progs: set string end sing '\0' for property

Set string "xattr_name" 's end with '\0' so that it won't be
violated in memory.

With this fix, xfstest/btrfs/048 can pass on my box.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Filipe Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: prevent close_root if the root to close is potentially NULL
Gui Hecheng [Thu, 24 Apr 2014 03:39:28 +0000 (11:39 +0800)]
btrfs-progs: prevent close_root if the root to close is potentially NULL

Originally only if 'block_only' is specified, the 'fs_root == NULL'
will be checked. But if 'block_only' is not specified and close_root
will be called blindly without checking 'fs_root == NULL', which is
unsafe.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: move arg_strtou64 to a separate file for library
David Sterba [Fri, 11 Apr 2014 11:22:50 +0000 (13:22 +0200)]
btrfs-progs: move arg_strtou64 to a separate file for library

Linking with libbtrfs fails because arg_strtou64 is not defined and we
cannot just add utils.o to library objects because it's not
library-clean.

Reported-by: Arvin Schnell <aschnell@suse.com>
Reported-by: Anton Farygin <rider@altlinux.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: add dev maxs limit for btrfs_alloc_chunk in user space
Gui Hecheng [Mon, 21 Apr 2014 12:13:32 +0000 (20:13 +0800)]
btrfs-progs: add dev maxs limit for btrfs_alloc_chunk in user space

For RAID0,5,6,10,
For system chunk, there shouldn't be too many stripes to
make a btrfs_chunk that exceeds BTRFS_SYSTEM_CHUNK_ARRAY_SIZE
For data/meta chunk, there shouldn't be too many stripes to
make a btrfs_chunk that exceeds a leaf.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: fix wrong max system array size check in user space
Gui Hecheng [Mon, 21 Apr 2014 12:13:31 +0000 (20:13 +0800)]
btrfs-progs: fix wrong max system array size check in user space

For system chunk array,
We copy a "disk_key" and an chunk item each time,
so there should be enough space to hold both of them,
not only the chunk item.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: mkfs: Remove 'zero_end =1' since it has been set to a value
Li Yang [Mon, 21 Apr 2014 09:38:08 +0000 (05:38 -0400)]
Btrfs-progs: mkfs: Remove 'zero_end =1' since it has been set to a value

In utils.c, zero_end is used as a parameter, should not force it to 1.
In mkfs.c, zero_end is set to 1 or 0(-b) at the beginning, should not
force it to 1 unconditionally.

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: fsck: fix double free memory crash
Rakesh Pandit [Sun, 20 Apr 2014 13:17:53 +0000 (16:17 +0300)]
Btrfs-progs: fsck: fix double free memory crash

Fix double free of memory if btrfs_open_devices fails:
*** Error in `btrfs': double free or corruption (fasttop): 0x000000000066e020 ***

Crash happened because when open failed on device inside
btrfs_open_devices it freed all memory by calling btrfs_close_devices but
inside disk-io.c we call btrfs_close_again it again.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: make smatch checker happy (trivial fixes)
Rakesh Pandit [Sat, 19 Apr 2014 19:05:41 +0000 (22:05 +0300)]
Btrfs-progs: make smatch checker happy (trivial fixes)

It complains errno never gets assigned to zero in find-root and since
errno anyway is zero at program started up, lets remove it.

Check "copy is less then zero" isn't possible because strtoull used by
arg_strtou64 wouldn't return -ve number.

Trivial space fixes.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: receive: remove return type of close_inode_for_write
Rakesh Pandit [Fri, 18 Apr 2014 23:14:14 +0000 (02:14 +0300)]
Btrfs-progs: receive: remove return type of close_inode_for_write

"close_inode_for_write" always returns 0, so just remove its return
value and remove dead checking in caller.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: fsck: while checking root refs print readable errors
Rakesh Pandit [Fri, 18 Apr 2014 23:13:55 +0000 (02:13 +0300)]
Btrfs-progs: fsck: while checking root refs print readable errors

Lets use "errors" instead of "error" because more then one ref errors
are possible. Also print error messages for unresolved refs in
check_root_refs.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: allow compression property gets for read-only subvolumes
Filipe David Borba Manana [Tue, 15 Apr 2014 19:47:27 +0000 (20:47 +0100)]
Btrfs-progs: allow compression property gets for read-only subvolumes

Because the function open_file_or_dir() always opened the input file in
read/write mode (O_RDWR), we were not able to due a compression property
get against a file living in a read-only subvolume/snapshot.
Fix this by opening the file with O_RDONLY mode if we're doing a property
get.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: fix check to test trim support
Rakesh Pandit [Tue, 22 Apr 2014 13:30:27 +0000 (16:30 +0300)]
Btrfs-progs: fix check to test trim support

It was added in 25d82d22 but broke recently in 4724d7b0 while making
discard interruptible.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Fix the return value when executing 'btrfs prop get' on an uncompressed...
Qu Wenruo [Tue, 15 Apr 2014 09:22:24 +0000 (17:22 +0800)]
btrfs-progs: Fix the return value when executing 'btrfs prop get' on an uncompressed file

When executing 'btrfs prop get' on a file which is not compressed, return
value will always be 50 since prop_compress() return -ENOATTR.

But the codes have already check the errno to avoid unnecessary error
message, so the return value should also set to 0.

Signed-off-by: Qu Wenruo <quwenro@cn.fujitsu.com>
Reviewed-by: Filipe Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Fix the return value of btrfs_scan_kernel()
Qu Wenruo [Tue, 8 Apr 2014 09:16:02 +0000 (17:16 +0800)]
btrfs-progs: Fix the return value of btrfs_scan_kernel()

btrfs_scan_kernel() is only used in 'btrfs fi show' but returns wrong
return value.  When search parameter is passed, it will never return 0
even the search can be matched.

This patch will change the whatever strange logic to a more easy to
understand one using 'found' var.

Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Cc: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: chunk_recovery: fix mem leak and pthread_cancel call
Rakesh Pandit [Wed, 26 Mar 2014 19:34:30 +0000 (21:34 +0200)]
Btrfs-progs: chunk_recovery: fix mem leak and pthread_cancel call

Free memory if open call fails. Prevent pthread_cancel on threads
which have already finished successfully. If all calls to
pthread_create and pthread_join are successful, we mistakenly call
pthread_cancel because cancel_from and cancel_to are both zero.

Make POSIX.1-2001 happy by supplying a non-NULL second argument to
pthread_setcanceltype.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: scrub: disable thread cancelability during mutex locks
Rakesh Pandit [Tue, 25 Mar 2014 14:47:07 +0000 (16:47 +0200)]
Btrfs-progs: scrub: disable thread cancelability during mutex locks

scrub_progress_cycle thread runs in asynchronous type but locks mutex
while reading shared data. This patch disables cancelability for a
brief time while locks are on so as to make sure they are unlocked
before thread is canceled.

scrub_write_progress gets called from scrub_progress_cycle in
asynchronous thread but cancelability is disabled after mutex is
locked. This patch moves the call to set cancelability type before
mutex lock and makes corresponding changes to labels for error
handling.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: remove unsed pthread attribute objects
Rakesh Pandit [Mon, 24 Mar 2014 09:04:47 +0000 (11:04 +0200)]
Btrfs-progs: remove unsed pthread attribute objects

Threads always use default attributes in all tools, so pthread
attribute objects and their initializations are of no use. Just pass
NULL as attr attribute to pthread_create for default attributes.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: btrfs-image: don't call pthread_join on IDs not present
Rakesh Pandit [Fri, 21 Mar 2014 01:06:23 +0000 (03:06 +0200)]
Btrfs-progs: btrfs-image: don't call pthread_join on IDs not present

If pthread_create fails in mdrestore_init, then number of threads
created could be less then num of threads option. Hence pass number of
successful pthread_create calls to mdrestore_destroy, so that we don't
call pthread_join on IDs not present when pthread_create fails.

metadump_init already had this fixed, but repeats code from
metadump_destroy. Reuse metadump_destroy by passing number of threads
created (successful pthread_create calls) and save repeated cleaup
code. Had to move metadump_destroy before metadump_init for obvious
reasons.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: doc: link btrfsck to btrfs-check
David Sterba [Wed, 16 Apr 2014 16:33:44 +0000 (18:33 +0200)]
btrfs-progs: doc: link btrfsck to btrfs-check

The 'btrfsck' command has been deprecated in favor of 'btrfs check'. For
compatibility install a symlink to the btrfs-check.8 manpage.

Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: add separate make target to clean docs
David Sterba [Fri, 4 Apr 2014 14:36:40 +0000 (16:36 +0200)]
btrfs-progs: add separate make target to clean docs

Regenerating the asciidoc takes much longer now and makes quick build
tests long. There's separate clean-doc target for that and clean-all
that cleans docs and sources.

Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Add btrfs wiki reference to man pages.
Qu Wenruo [Tue, 15 Apr 2014 07:04:51 +0000 (15:04 +0800)]
btrfs-progs: Add btrfs wiki reference to man pages.

Add btrfs wiki page reference to btrfs-check/btrfsck, btrfs-restore and
btrfs-device as supplement.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-property.
Qu Wenruo [Tue, 15 Apr 2014 07:04:50 +0000 (15:04 +0800)]
btrfs-progs: Convert man page for btrfs-property.

Convert the man page for the newly added btrfs-property subcommand.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-restore.
Qu Wenruo [Tue, 15 Apr 2014 07:04:49 +0000 (15:04 +0800)]
btrfs-progs: Convert man page for btrfs-restore.

Convert man page for btrfs-restore, which I forgot to convert in the
previous patchset. :P

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Add explain on btrfs-zero-log.
Qu Wenruo [Fri, 11 Apr 2014 02:43:53 +0000 (10:43 +0800)]
btrfs-progs: Add explain on btrfs-zero-log.

Add more explain on btrfs-zero-log about when to use it.

Reviewed-by: Marc MERLIN <marc@merlins.org>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Add device management related paragraph.
Qu Wenruo [Fri, 11 Apr 2014 02:43:52 +0000 (10:43 +0800)]
btrfs-progs: Add device management related paragraph.

Add device management related paragraph to better explain btrfs device
management.

Cc: Marc MERLIN <marc@merlins.org>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Switch to the new asciidoc Documentation.
Qu Wenruo [Wed, 2 Apr 2014 08:29:38 +0000 (16:29 +0800)]
btrfs-progs: Switch to the new asciidoc Documentation.

Since all man page are converted to the new asciidoc, the old man page
can be removed.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for mkfs.btrfs.
Qu Wenruo [Wed, 2 Apr 2014 08:29:37 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for mkfs.btrfs.

Convert man page for mkfs.btrfs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for fsck.btrfs.
Qu Wenruo [Wed, 2 Apr 2014 08:29:36 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for fsck.btrfs.

Convert man page for fsck.btrfs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-zero-log
Qu Wenruo [Wed, 2 Apr 2014 08:29:35 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-zero-log

Convert man page for btrfs-zero-log

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfstune.
Qu Wenruo [Wed, 2 Apr 2014 08:29:34 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfstune.

Convert man page for btrfstune.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-show-super.
Qu Wenruo [Wed, 2 Apr 2014 08:29:33 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-show-super.

Convert man page for btrfs-show-super.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-map-logical.
Qu Wenruo [Wed, 2 Apr 2014 08:29:32 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-map-logical.

Convert man page for btrfs-map-logical.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-image.
Qu Wenruo [Wed, 2 Apr 2014 08:29:31 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-image.

Convert man page for btrfs-image.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-find-root.
Qu Wenruo [Wed, 2 Apr 2014 08:29:30 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-find-root.

Convert man page for btrfs-find-root.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-debug-tree.
Qu Wenruo [Wed, 2 Apr 2014 08:29:29 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-debug-tree.

Convert man page for btrfs-debug-tree.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-convert.
Qu Wenruo [Wed, 2 Apr 2014 08:29:28 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-convert.

Convert man page for btrfs-convert.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-replace.
Qu Wenruo [Wed, 2 Apr 2014 08:29:25 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-replace.

Convert man page for btrfs-replace.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert and enhance the man page of btrfs-qgroup.
Qu Wenruo [Wed, 2 Apr 2014 08:29:24 +0000 (16:29 +0800)]
btrfs-progs: Convert and enhance the man page of btrfs-qgroup.

Convert and enhance the man page of btrfs-qgroup.

The original man page for btrfs-qgroup subcommand is almost useless for
new user(like me), so adds more information on it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-quota.
Qu Wenruo [Wed, 2 Apr 2014 08:29:23 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-quota.

Convert man page for btrfs-quota.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-receive.
Qu Wenruo [Wed, 2 Apr 2014 08:29:22 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-receive.

Convert man page for btrfs-receive.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-send.
Qu Wenruo [Wed, 2 Apr 2014 08:29:21 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-send.

Convert man page for btrfs-send.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-inspect-internal
Qu Wenruo [Wed, 2 Apr 2014 08:29:20 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-inspect-internal

Convert man page for btrfs-inspect-internal.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-rescue
Qu Wenruo [Wed, 2 Apr 2014 08:29:19 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-rescue

Convert man page for btrfs-rescue.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-check.
Qu Wenruo [Wed, 2 Apr 2014 08:29:18 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-check.

Convert man page for btrfs-check.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-scrub
Qu Wenruo [Wed, 2 Apr 2014 08:29:17 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-scrub

Convert man page for btrfs-scrub.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-device subcommand.
Qu Wenruo [Wed, 2 Apr 2014 08:29:16 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-device subcommand.

Convert man page for btrfs-device subcommand.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-balance.
Qu Wenruo [Wed, 2 Apr 2014 08:29:15 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-balance.

Convert man page for btrfs-balance.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for filesystem subcommand.
Qu Wenruo [Wed, 2 Apr 2014 08:29:14 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for filesystem subcommand.

Convert man page for filesystem subcommand.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Convert man page for btrfs-subvolume
Qu Wenruo [Wed, 2 Apr 2014 08:29:13 +0000 (16:29 +0800)]
btrfs-progs: Convert man page for btrfs-subvolume

Convert man page for btrfs-subvolume.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Introduce asciidoc based man page and btrfs man page.
Qu Wenruo [Wed, 2 Apr 2014 08:29:12 +0000 (16:29 +0800)]
btrfs-progs: Introduce asciidoc based man page and btrfs man page.

The old man page of btrfs will grow larger with new functions adding to
btrfs-progs and harder to maintain because the reader-unfriendly roff
grammar and one LARGE btrfs.in.

This patch will introduce the simplified Documentation directory mainly
'stolen' from git and include the first man page for 'btrfs(8)'.
This time, man page will be written in human-friendly asciidoc grammar
and each commands of btrfs will have a separate man page, which I hope
can reduce the effort to maintain the man page.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agov3.14.1
Chris Mason [Fri, 18 Apr 2014 17:46:31 +0000 (10:46 -0700)]
v3.14.1

Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: correct prompt of minimal num of devs for raid56
Gui Hecheng [Thu, 10 Apr 2014 03:55:36 +0000 (11:55 +0800)]
btrfs-progs: correct prompt of minimal num of devs for raid56

For btrfs,
Raid5 can't go below 2 devs, not 3;
Raid6 can't go below 3 devs, not 4.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: update btrfs_file_extent_inline_len to match kernel version
Filipe David Borba Manana [Tue, 8 Apr 2014 17:25:43 +0000 (18:25 +0100)]
Btrfs-progs: update btrfs_file_extent_inline_len to match kernel version

The following kernel commit changed the definition of the inline function
btrfs_file_extent_inline_len():

    commit 514ac8ad8793a097c0c9d89202c642479d6dfa34
    Author: Chris Mason <clm@fb.com>
    Date:   Fri Jan 3 21:07:00 2014 -0800

    Btrfs: don't use ram_bytes for uncompressed inline items

    If we truncate an uncompressed inline item, ram_bytes isn't updated to reflect
    the new size.  The fixe uses the size directly from the item header when
    reading uncompressed inlines, and also fixes truncate to update the
    size as it goes.

Not having this new definition implies that the restore tool might misbehave when
restoring files with an inline extent that got truncated on a kernel older than
release 3.14.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: restore, for compressed extents don't read more bytes than needed
Filipe David Borba Manana [Tue, 8 Apr 2014 16:37:22 +0000 (17:37 +0100)]
Btrfs-progs: restore, for compressed extents don't read more bytes than needed

We need to read a number of bytes corresponding to the disk size of the file extent
item, and not to the number of bytes in the num_bytes field. Normally disk_size is
smaller than num_bytes (when using compression), except for files created with lzo
compression in a kernel older then the one which introduced the following change:

commit 59516f6017c589e7316418fda6128ba8f829a77f
Author: Stefan Agner <stefan@agner.ch>
Date:   Mon Jul 1 20:33:39 2013 +0200

    Btrfs: return -1 when lzo compression makes data bigger

    With this fix the lzo code behaves like the zlib code by returning an
    error
    code when compression does not help reduce the size of the file.
    This is currently not a bug since the compressed size is checked again
    in
    the calling method compress_file_range.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Make property work with -t option
Kusanagi Kouichi [Tue, 8 Apr 2014 13:38:02 +0000 (22:38 +0900)]
btrfs-progs: Make property work with -t option

# btrfs prop list -t f .
btrfs property list: too many arguments
...
# btrfs prop get -t f . label
btrfs property get: too many arguments
...
# btrfs prop set -t f . label abc
btrfs property set: too many arguments
...

Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Constify getters
Kusanagi Kouichi [Tue, 8 Apr 2014 13:37:39 +0000 (22:37 +0900)]
btrfs-progs: Constify getters

Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: btrfs: remove dead code in handle_options
Rakesh Pandit [Thu, 20 Mar 2014 09:43:35 +0000 (11:43 +0200)]
Btrfs-progs: btrfs: remove dead code in handle_options

Just cleanup: remove useless return type, while loop and dead code.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs: Modify the help string to keep consistent with man page.
Qu Wenruo [Wed, 19 Mar 2014 06:10:02 +0000 (06:10 +0000)]
btrfs-progs: Modify the help string to keep consistent with man page.

Help string of "btrfs dev scan" is inconsistent with man page,
which lacks the fact that -d|--all-device is conflict with <device>.
This patch fixes the description

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: fsck: fix wrong index in pick_next_pending()
Wang Shilong [Tue, 18 Mar 2014 12:02:47 +0000 (20:02 +0800)]
Btrfs-progs: fsck: fix wrong index in pick_next_pending()

Though all tree blocks have same size, we'd better use right
index here.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: fsck: reduce memory usage of extent record struct
Wang Shilong [Tue, 18 Mar 2014 12:02:46 +0000 (20:02 +0800)]
Btrfs-progs: fsck: reduce memory usage of extent record struct

Two changes:
1.use bit filed for @found_rec
2.u32 is enough to calculate duplicate extent number.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: fsck: fix possible memory leaks in run_next_block()
Wang Shilong [Tue, 18 Mar 2014 12:02:43 +0000 (20:02 +0800)]
Btrfs-progs: fsck: fix possible memory leaks in run_next_block()

We still need free allocated cache memory in case error happens.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agoBtrfs-progs: fsck: don't free @seen cache until we finish searching
Wang Shilong [Tue, 18 Mar 2014 12:02:42 +0000 (20:02 +0800)]
Btrfs-progs: fsck: don't free @seen cache until we finish searching

@seen cache is used to avoid iterating same block more than once, and
we can not free them until we have finished searching.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
10 years agobtrfs-progs v3.14
Chris Mason [Sun, 6 Apr 2014 23:33:55 +0000 (19:33 -0400)]
btrfs-progs v3.14

Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix listing deleted subvolumes
David Sterba [Fri, 28 Mar 2014 12:39:57 +0000 (13:39 +0100)]
btrfs-progs: fix listing deleted subvolumes

The real check whether to show deleted or live subvolumes was skipped if
just '-d' was specified without other filters. The 'deleted' filter was
not accounted.

It is now handled as a normal filter, that additionally sets the only_delete
global status in order to be processed before any other filters in
filter_root().

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: make device discard process interruptible
David Sterba [Thu, 27 Mar 2014 15:19:37 +0000 (16:19 +0100)]
btrfs-progs: make device discard process interruptible

The ioctl for the whole range is not interruptible, which can be
annoying when the discard is not wanted but user forgets to use the -K
option.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: avoid implicit scan for backup SB
Anand Jain [Mon, 17 Mar 2014 11:59:01 +0000 (19:59 +0800)]
btrfs-progs: avoid implicit scan for backup SB

When a disk containing btrfs is overwritten with other FS, ext4
for example it doesn't overwrite 2nd and 3rd copy of the btrfs SB.
And btrfs_read_dev_super() would look for backup SB when primary
SB isn't found. This causes the problem as in the reproducer below.

In kernel we avoid this by _not_ reading backup SB implicitly,
this patch would port the same to btrfs-progs.

reproducer:
mkfs.btrfs /dev/sde
mkfs.ext4 /dev/sde
mount /dev/sde /ext4
btrfs-convert /dev/sde (is successful (bug))

with this patch
::
btrfs-convert /dev/sde
/dev/sde is mounted

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: fix memory leak and unnecessary call to free
Rakesh Pandit [Sat, 15 Mar 2014 12:22:37 +0000 (14:22 +0200)]
Btrfs-progs: fsck: fix memory leak and unnecessary call to free

Free already allocated memory to item1_data if malloc fails for
item2_data in swap_values. Seems to be a typo from commit 70749a77.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: return with -ENOMEM if malloc fails
Rakesh Pandit [Sat, 15 Mar 2014 11:46:15 +0000 (13:46 +0200)]
Btrfs-progs: return with -ENOMEM if malloc fails

Prevent segfault if memory allocation fails for sargs in get_df
(cmds-filesystem.c).

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: scrub: don't call unlock if pthread_mutex_lock fails
Rakesh Pandit [Fri, 14 Mar 2014 23:49:45 +0000 (01:49 +0200)]
Btrfs-progs: scrub: don't call unlock if pthread_mutex_lock fails

If pthread_mutex_lock fails (rare but fix it anyway), don't call
pthread_mutex_unlock on mutex.

Rationale being that if pthread_mutex_lock fails pthread_mutex_unlock
will always fail and overwrite actual error value in err.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Fix a memleak in btrfs_scan_lblkid().
Qu Wenruo [Fri, 14 Mar 2014 03:28:11 +0000 (03:28 +0000)]
btrfs-progs: Fix a memleak in btrfs_scan_lblkid().

In btrfs_scan_lblkid(), blkid_get_cache() is called but cache not freed.
This patch adds blkid_put_cache() to free it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Fix a memleak in btrfs_scan_one_device.
Qu Wenruo [Fri, 14 Mar 2014 03:28:11 +0000 (03:28 +0000)]
btrfs-progs: Fix a memleak in btrfs_scan_one_device.

Valgrind reports memleak in btrfs_scan_one_device() about allocating
btrfs_device but on btrfs_close_devices() they are not reclaimed.

Although not a bug since after btrfs_close_devices() btrfs will exit so
memory will be reclaimed by system anyway, it's better to fix it anyway.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: skip erroneous free before initialization
Gui Hecheng [Thu, 13 Mar 2014 05:01:31 +0000 (13:01 +0800)]
btrfs-progs: skip erroneous free before initialization

If the list is not initialized, don't try to free it.
Otherwise it will cause segmentfault.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix bug on mkfs with relative path specified
Gui Hecheng [Thu, 13 Mar 2014 05:01:30 +0000 (13:01 +0800)]
btrfs-progs: fix bug on mkfs with relative path specified

The bug accurs when exec:
# mkfs.btrfs -r <a relative path> <device>
(note: the path should be 'valid' correspond to your `pwd`)
error msg:
$ scandir for <a relative path> failed: No such file...

o Replace strdup() with realpath() to get the correct scan path.
o fix memory leaks and adopt the "single return + goto out" pattern

Reported-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: mkfs: make sure we can deal with hard links with -r option
Wang Shilong [Tue, 11 Mar 2014 10:29:09 +0000 (18:29 +0800)]
Btrfs-progs: mkfs: make sure we can deal with hard links with -r option

Steps to reproduce:
 # mkdir -p /tmp/test
 # touch /tmp/test/file
 # ln /tmp/test/file /tmp/test/hardlinks
 # mkfs.btrfs -f /dev/sda13 -r /tmp/test
 # btrfs check /dev/sda13

To deal with hard link, we must deal with inode with same inode id rather
than increase inode id by ourselves.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: mkfs: don't create extent for an empty file
Wang Shilong [Tue, 11 Mar 2014 10:29:08 +0000 (18:29 +0800)]
Btrfs-progs: mkfs: don't create extent for an empty file

Steps to reproduce:
 # mkdir -p /tmp/test
 # touch /tmp/test/file
 # mkfs.btrfs -f /dev/sda13 -r /tmp/test
 # btrfs check /dev/sda13

For an empty file, don't create extent data for it.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix uninit variable in btrfs_scan_kernel
Chris Mason [Fri, 21 Mar 2014 13:36:08 +0000 (06:36 -0700)]
btrfs-progs: fix uninit variable in btrfs_scan_kernel

Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: handle case that we can not lookup extent info
Wang Shilong [Thu, 6 Mar 2014 05:54:00 +0000 (13:54 +0800)]
Btrfs-progs: fsck: handle case that we can not lookup extent info

Previously, --init-extent-tree works just because btrfs_lookup_extent_info()
blindly return 0, and this make it work if there are not any *FULL BACKREF*
mode in broken filesystem.

It is just a coincidence that --init-extent-tree option works, let's
do it in the right way firstly.

For now, we have not supported to rebuild extent tree if there are
any *FULL BACKREF* mode which means if there are snapshots with broken
filesystem, avoid using --init-extent-tree option now.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: force to udate tree root for some cases
Wang Shilong [Thu, 6 Mar 2014 05:53:59 +0000 (13:53 +0800)]
Btrfs-progs: fsck: force to udate tree root for some cases

commit roots won't update root item in tree root if it finds
updated root's bytenr is same as before.

However, this is not right for fsck, we need update tree root in
the following case:

1.overwrite previous root node.

2.reinit reloc data tree, this is because we skip pin relo data
 tree before which means we can allocate same block as before.

Fix this by updating tree root ourselves for the above cases.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: insert root dir into reloc data tree when reiniting it
Wang Shilong [Thu, 6 Mar 2014 05:53:58 +0000 (13:53 +0800)]
Btrfs-progs: fsck: insert root dir into reloc data tree when reiniting it

There are two bugs when resetting balance:

 1.we will skip reinitting reloc data tree if no reloc root found, however
  this is not right because we don't pin reloc data tree before.

 2.we should insert root dir into reloc data tree,otherwise we will fail
  to fsck.

Fix problems by forcely reiniting reloc data root and inserting root dir.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: reset balance after reiniting extent root
Wang Shilong [Thu, 6 Mar 2014 05:53:57 +0000 (13:53 +0800)]
Btrfs-progs: fsck: reset balance after reiniting extent root

reset balance need cow block which will insert extent item into
extent tree. If we do this before reinitting extent root, we may
encounter EEIXST.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: deal with really corrupted extent tree
Wang Shilong [Thu, 6 Mar 2014 05:53:56 +0000 (13:53 +0800)]
Btrfs-progs: fsck: deal with really corrupted extent tree

To reinit extent root, we need find a free extent, however,
we may have a really corrupted extent tree, so we can't rely
on existed extent tree to cache block group any more.

During test, we fail to reinit extent tree which is because we
can not find a free extent so let's make block group cache ourselves
firstly.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: remove unused variable and update btrfs-image man page
Rakesh Pandit [Wed, 5 Mar 2014 00:12:23 +0000 (02:12 +0200)]
Btrfs-progs: remove unused variable and update btrfs-image man page

Remove unused variable in btrfs-image.c (update_super) and update man
page documentation about -r option. Running btrfsck on a restored
image produces missing chunk information. This is because by default,
btrfs-image fixes up chunk tree to use 1 stripe pointing to the
primary device. This in turns results in btrfsck making some noise.

$  ./mkfs.btrfs /dev/sdb2 -f
$  ./btrfs-image /dev/sdb2 btrfs_image_output
$  ./btrfs-image -r btrfs_image_output disk-image
$  ./btrfsck disk-image

Device extent[1, 29360128, 8388608] didn't find the relative chunk.
Device extent[1, 11114905601073741824] didn't find the relative chunk.

Ideally btfsck should be updated to reflect this default behavior and
not through these messages, but it isn't harmful and can be done
later.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: use the correct integer type for ioctl
Arvin Schnell [Mon, 10 Mar 2014 23:39:48 +0000 (00:39 +0100)]
Btrfs-progs: use the correct integer type for ioctl

Signed-off-by: Arvin Schnell <aschnell@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: make the device scan logic more clear
Gui Hecheng [Thu, 6 Mar 2014 03:36:48 +0000 (11:36 +0800)]
btrfs-progs: make the device scan logic more clear

1. Use long option to replace the original strcmp() to parse
the "--all-devices".
2. the "int ret" is defined in 2 places, just define it once
and make the return pattern into "goto + single return".

This does not change the actual scan procedure and return values.
Just make it clear, the original seems a little confusing.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: cleanup device stat usage prompt
Gui Hecheng [Thu, 6 Mar 2014 03:36:47 +0000 (11:36 +0800)]
btrfs-progs: cleanup device stat usage prompt

1. use usage() to replace the fprintf()
2. use check_argc_exact() to replace "argc != ..."

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: free path if we don't find root item
Rakesh Pandit [Fri, 28 Feb 2014 17:27:06 +0000 (19:27 +0200)]
Btrfs-progs: free path if we don't find root item

In btrfs_find_last_root before returning with -ENOENT (if root item is
not found) free path and also remove btrfs_release_path before
btrfs_free_path because btrfs_free_path anyway calls it.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: include <sys/xattr.h> instead of <attr/xattr.h>
Christophe Vu-Brugier [Sun, 2 Feb 2014 13:01:20 +0000 (14:01 +0100)]
btrfs-progs: include <sys/xattr.h> instead of <attr/xattr.h>

The `btrfs` and `mkfs.btrfs` binaries are not linked against libattr
so the correct header to include is <sys/xattr.h>.

This fixes the build when attr header files are not installed.

Signed-off-by: Christophe Vu-Brugier <cvubrugier@yahoo.fr>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: make sure to save mirror_num only if it is set
Josef Bacik [Thu, 27 Feb 2014 15:25:49 +0000 (10:25 -0500)]
Btrfs-progs: make sure to save mirror_num only if it is set

If we are cycling through all of the mirrors trying to find the best one we need
to make sure we set best_mirror to an actual mirror number and not 0.  Otherwise
we could end up reading a mirror that wasn't the best and make everybody sad.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: record generation for tree blocks in fsck
Josef Bacik [Thu, 27 Feb 2014 15:18:41 +0000 (10:18 -0500)]
Btrfs-progs: record generation for tree blocks in fsck

When working with a user who had a broken file system I noticed that we were
reading a bad copy of a block when the other copy was perfectly fine.  This is
because we don't keep track of the parent generation for tree blocks, so we just
read whichever copy we damned well please with no regards for which is best.
This fixes this problem by recording the parent generation of the tree block so
we can be sure to read the most correct copy before we check it, which will give
us a better chance of fixing really broken filesystems.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Init root_item to avoid gcc 4.8.2 warning
Qu Wenruo [Wed, 26 Feb 2014 08:23:08 +0000 (16:23 +0800)]
btrfs-progs: Init root_item to avoid gcc 4.8.2 warning

When using gcc 4.8.2, -Wmaybe-uninitialized will report root_item may be
used uninitialized.
Since root_item_valid variant is used to determine the root_item valid,
it's a false alert and to avoid the warning, just init it on allocation.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: use bitfield instead of integer for some variants in fs_info
Wang Shilong [Tue, 25 Feb 2014 11:48:57 +0000 (19:48 +0800)]
Btrfs-progs: use bitfield instead of integer for some variants in fs_info

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fix restore of files with compressed extents
Filipe David Borba Manana [Tue, 25 Feb 2014 18:25:39 +0000 (18:25 +0000)]
Btrfs-progs: fix restore of files with compressed extents

The code was incorrectly adding the file extent items' data offset to the logical
disk address of the extent (bytenr) when the extent is compressed. The offset is
relative to the uncompressed data and not to what we store on disk (compressed).
Also it attempted to copy ram_bytes to destination, which is incorrect when the
data offset field is non-zero, it must use num_bytes instead.

A test case for xfstests follows.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Fix bug when scanned for devid which was missing and deleted
Anand Jain [Mon, 24 Feb 2014 11:43:39 +0000 (19:43 +0800)]
btrfs-progs: Fix bug when scanned for devid which was missing and deleted

get_fs_info() provides the info of the specific
device/devid, however when we delete the missing disk
the super-block on the disk isn't cleared, and since
btrfs-progs makes its decision by reading the disk super
block, so it doesn't know about the kernel previous action,
And now when we tried to probe kernel for the devid it fails.

reproducer:

$ mkfs.btrfs -d raid1 -m raid1 /dev/sde /dev/sdf
$ modprobe -r btrfs && modprobe btrfs
$ mount -o degraded /dev/sde /btrfs
$ btrfs dev add /dev/sdd /btrfs
$ btrfs dev del missing /btrfs
$ btrfs scrub start -B /dev/sdf
btrfs: utils.c:1741: get_fs_info: Assertion `!(ndevs == 0)' failed.
Aborted (core dumped)

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: latest_devid is not always the probed devid
Anand Jain [Mon, 24 Feb 2014 11:43:38 +0000 (19:43 +0800)]
btrfs-progs: latest_devid is not always the probed devid

btrfs-progs picks the latest_dev based on first probed
greatest trans-id. However below test case proofs that
approach is wrong.

$ mkfs.btrfs -d raid1 -m raid1 /dev/sde /dev/sdf
$ modprobe -r btrfs && modprobe btrfs
$ mount -o degraded /dev/sde /btrfs
$ touch /btrfs/testfile && btrfs fi sync /btrfs

The above steps will make /dev/sdf not part of the btrfs.

and as below when you use /dev/sdf the btrfs dev stat
and dev scrub picks up wrong disk

$ btrfs dev stat /dev/sdf
[/dev/sde].write_io_errs   0
[/dev/sde].read_io_errs    0
[/dev/sde].flush_io_errs   0
[/dev/sde].corruption_errs 0
[/dev/sde].generation_errs 0

$ btrfs scrub start -B /dev/sdf
scrub done for 2e99c881-6abd-4f8a-8290-e2f8d0acc575
 scrub started at Mon Feb 24 14:45:06 2014 and finished after 0 seconds
 total bytes scrubbed: 256.00KiB with 0 errors

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: there is devid 0 when replace is running
Anand Jain [Mon, 24 Feb 2014 11:43:37 +0000 (19:43 +0800)]
btrfs-progs: there is devid 0 when replace is running

as of now, when we replace a disk, it is added to the
dev list with devid 0. And we fail to obtain details
of devid 0 because we don't query devid 0 at all.

reproducer:

 btrfs rep start /dev/sdb /dev/sdf /btrfs
 btrfs fi show
 Label: none  uuid: f8fb9819-16c8-47b7-b62f-0ff90f8c56cd
        Total devices 3 FS bytes used 1.94GiB
        devid    1 size 1.10GiB used 1.10GiB path /dev/sdb
        devid    2 size 1.10GiB used 1.08GiB path /dev/sdc
        devid    0 size 0.00 used 0.00 path

  this patch will make it proper by querying devid 0.

 btrfs repl start /dev/sdb /dev/sdf /btrfs
 btrfs fi show /btrfs
 Label: none  uuid: f8fb9819-16c8-47b7-b62f-0ff90f8c56cd
        Total devices 3 FS bytes used 1.94GiB
        devid    0 size 1.10GiB used 1.10GiB path /dev/sdf
        devid    1 size 1.10GiB used 1.10GiB path /dev/sdb
        devid    2 size 1.10GiB used 1.08GiB path /dev/sdc

 Its fine to query devid 0 when there is no replace
 activity as well, because we just skip the error ENODEV

 btrfs fi show /btrfs
 Label: none  uuid: f8fb9819-16c8-47b7-b62f-0ff90f8c56cd
        Total devices 2 FS bytes used 1.94GiB
        devid    1 size 1.10GiB used 1.10GiB path /dev/sdf
        devid    2 size 1.10GiB used 1.08GiB path /dev/sdc

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: fix wrong return value in check_block()
Wang Shilong [Mon, 24 Feb 2014 11:55:14 +0000 (19:55 +0800)]
Btrfs-progs: fsck: fix wrong return value in check_block()

We found btrfsck will output backrefs mismatch while the filesystem
is defenitely ok.

The problem is that check_block() don't return right value,which
makes btrfsck won't walk all tree blocks thus we don't get a consistent
filesystem, we will fail to check extent refs etc.

Reported-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fsck: avoid overwritting existed space when initting csum tree
Wang Shilong [Tue, 25 Feb 2014 11:48:56 +0000 (19:48 +0800)]
Btrfs-progs: fsck: avoid overwritting existed space when initting csum tree

Steps to reproduce:
 # mkfs.btrfs -f /dev/sda9
 # btrfs check /dev/sda9 --init-extent-tree --init-csum-tree
 # btrfs check /dev/sda9

During reinitting extent tree, we will pin all metadata blocks to
avoid overwritting existing metadata space. However, those space will
be unpinned after committing transaction.

If we try to reinit csum tree after reiniting extent tree, we may
overwrite existing space. Fix this problem by making reinit extent tree
and csum tree in same transaction.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Copyright string update
Hidetoshi Seto [Tue, 25 Feb 2014 07:42:29 +0000 (16:42 +0900)]
btrfs-progs: Copyright string update

Fix corporate name for copyright.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>