platform/upstream/btrfs-progs.git
8 years agobtrfs-progs: cmd filesystem: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd filesystem: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd replace: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd replace: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd subvolume: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd subvolume: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd send: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd send: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd receive: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd receive: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd qgroup: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd qgroup: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd property: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd property: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd balance: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd balance: switch to common error message wrapper

Message texts were adjusted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd quota: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd quota: switch to common error message wrapper

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cmd rescue: switch to common error message wrapper
David Sterba [Mon, 11 Jan 2016 10:01:47 +0000 (11:01 +0100)]
btrfs-progs: cmd rescue: switch to common error message wrapper

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: catch memory allocation failure in btrfs_split_item
David Sterba [Wed, 6 Jan 2016 14:52:11 +0000 (15:52 +0100)]
btrfs-progs: catch memory allocation failure in btrfs_split_item

Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handler memory allocation failure in add_extent_rec
David Sterba [Wed, 6 Jan 2016 14:52:11 +0000 (15:52 +0100)]
btrfs-progs: handler memory allocation failure in add_extent_rec

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: catch memory allocation failure from alloc_data_backref
David Sterba [Wed, 6 Jan 2016 14:52:11 +0000 (15:52 +0100)]
btrfs-progs: catch memory allocation failure from alloc_data_backref

Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: catch memory allocation failure from alloc_tree_backref
David Sterba [Wed, 6 Jan 2016 14:52:11 +0000 (15:52 +0100)]
btrfs-progs: catch memory allocation failure from alloc_tree_backref

Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: catch memory allocation failure in splice_shared_node
David Sterba [Wed, 6 Jan 2016 14:52:11 +0000 (15:52 +0100)]
btrfs-progs: catch memory allocation failure in splice_shared_node

Do the dumb BUG_ON now, the function needs more changes to handle all
errors.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handle errors in get_inode_backref and fail in the caller
David Sterba [Wed, 6 Jan 2016 14:08:46 +0000 (15:08 +0100)]
btrfs-progs: handle errors in get_inode_backref and fail in the caller

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handle errors in get_root_backref and fail in the caller
David Sterba [Wed, 6 Jan 2016 14:37:06 +0000 (15:37 +0100)]
btrfs-progs: handle errors in get_root_backref and fail in the caller

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: return errors from get_root_rec, fail in callers
David Sterba [Wed, 6 Jan 2016 14:08:46 +0000 (15:08 +0100)]
btrfs-progs: return errors from get_root_rec, fail in callers

get_root_rec return value is enahanced, callers will just BUG_ON now
and will be fixed one by one.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handle errors in add_shared_node and fail in the caller
David Sterba [Wed, 6 Jan 2016 14:37:06 +0000 (15:37 +0100)]
btrfs-progs: handle errors in add_shared_node and fail in the caller

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: return errors from clone_inode_rec, fail in callers
David Sterba [Wed, 6 Jan 2016 14:08:46 +0000 (15:08 +0100)]
btrfs-progs: return errors from clone_inode_rec, fail in callers

clone_inode_rec return value is enahanced, callers will just BUG_ON now
and will be fixed one by one.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: return errors from get_inode_rec, fail in callers
David Sterba [Wed, 6 Jan 2016 14:08:46 +0000 (15:08 +0100)]
btrfs-progs: return errors from get_inode_rec, fail in callers

get_inode_rec return value is enahanced, callers will just BUG_ON now
and will be fixed one by one.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs, enhance the mount option manual page
David Sterba [Fri, 8 Jan 2016 18:33:02 +0000 (19:33 +0100)]
btrfs-progs: docs, enhance the mount option manual page

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs, btrfs-mount: enhance fatal_erros
David Sterba [Fri, 8 Jan 2016 13:46:44 +0000 (14:46 +0100)]
btrfs-progs: docs, btrfs-mount: enhance fatal_erros

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs, btrfs-mount: put NOTE tag to new paragraph
David Sterba [Fri, 8 Jan 2016 13:34:48 +0000 (14:34 +0100)]
btrfs-progs: docs, btrfs-mount: put NOTE tag to new paragraph

Otherwise it's not rendered properly.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs, btrfs-mount: unindent descriptions
David Sterba [Fri, 8 Jan 2016 13:31:05 +0000 (14:31 +0100)]
btrfs-progs: docs, btrfs-mount: unindent descriptions

Asciidoc ignores special keywords like WARNING or NOTE if they're not at
the beginning of the line and they're not renedered very visibly in the
end.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: document snapshot unaware defrag
Christoph Anton Mitterer [Sun, 27 Dec 2015 02:41:28 +0000 (03:41 +0100)]
btrfs-progs: document snapshot unaware defrag

In btrfs-filesystem(8), improved the documentation of snapshot unaware
defragmentation and included the exact kernel version numbers being affected as
well as the possible effects.
No longer use the word "unlink" which is easily understood as "deleting a file".
Moved the warning more to the beginning of "defragment" subcommand's
documentation where it's more visible to readers.

Added the same warning to the "autodefrag" option of btrfs-mount(5).

Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
8 years agobtrfs-progs: docs, update btrfs(8) manual page
David Sterba [Thu, 7 Jan 2016 15:28:05 +0000 (16:28 +0100)]
btrfs-progs: docs, update btrfs(8) manual page

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs-progs: fix typo in parse_range
Liu Bo [Wed, 6 Jan 2016 21:08:53 +0000 (13:08 -0800)]
Btrfs-progs: fix typo in parse_range

s/*end/*start.

This makes 'btrfs balance start -dvrange=xxx..yyy' really work.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use on-stack buffer in add_symbolic_link
David Sterba [Wed, 6 Jan 2016 13:22:34 +0000 (14:22 +0100)]
btrfs-progs: use on-stack buffer in add_symbolic_link

Also get rid of the unhandled memory allocation.

Resolves-coverity-id: 1338298
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs: only free root_path if it was allocated from the heap
Neil Horman [Thu, 3 Dec 2015 18:45:44 +0000 (13:45 -0500)]
btrfs: only free root_path if it was allocated from the heap

Noticed this while doing some snapshots in a chroot environment

btrfs receive can set root_path to either realmnt, which is passed in from the
command line, or to a heap allocated via find_mount_root  in do_receive.  We
should only free the later, not the former, as the former results in an invalid
pointer warning from glibc during free.

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
CC: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix using on-disk structure to store in memory data
Byongho Lee [Mon, 4 Jan 2016 01:01:34 +0000 (10:01 +0900)]
btrfs-progs: fix using on-disk structure to store in memory data

In 'qgroup_count' structure 'diskinfo' and 'info' are used to store only
in memory data but its types are for on-disk structure as a result sparse
warns it (different base types).  So fix it by adding new structure
'qgroup_info' to store in memory data and replace on-disk structure
'btrfs_qgroup_info_item' by 'qgroup_info'.  In addition in alloc_cnt()
'generation' is set but not used after that so remove the relevant code.

Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix endian bug in update_super()
Byongho Lee [Mon, 4 Jan 2016 01:01:33 +0000 (10:01 +0900)]
btrfs-progs: fix endian bug in update_super()

In update_super() 'chunk->stripe.devid' and 'super->dev_item.devid' both
are little endian. So we should not use endian helper
btrfs_set_stack_stripe_devid().

Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix endian bugs in chunk rebuilding
Byongho Lee [Mon, 4 Jan 2016 01:01:32 +0000 (10:01 +0900)]
btrfs-progs: fix endian bugs in chunk rebuilding

This is a same patch as Zach Brown's but we lost so I resend it based on
current code.
 - 'commit 2cd95f945a61 ("fix endian bugs in chunk rebuilding")'

Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: make private symbols to static
Byongho Lee [Mon, 4 Jan 2016 01:01:31 +0000 (10:01 +0900)]
btrfs-progs: make private symbols to static

Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use NULL instead of 0
Byongho Lee [Mon, 4 Jan 2016 01:01:30 +0000 (10:01 +0900)]
btrfs-progs: use NULL instead of 0

Fix the code assigning 0 to pointer instead of NULL.

Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: get sparse checking working
Byongho Lee [Mon, 4 Jan 2016 01:01:29 +0000 (10:01 +0900)]
btrfs-progs: get sparse checking working

When I run sparse checking it gives the following error:

 $ make C=1 V=1
 gcc -MM -MG -MF cmds-fi-usage.o.d -MT cmds-fi-usage.o -MT \
 cmds-fi-usage.static.o -MT cmds-fi-usage.o.d -g -O1 -Wall \
 -D_FORTIFY_SOURCE=2 -include config.h -DBTRFS_FLAT_INCLUDES \
 -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC   cmds-fi-usage.c
    [SP]     ctree.c
 sparse -g -O1 -Wall -D_FORTIFY_SOURCE=2 -include config.h \
 -DBTRFS_FLAT_INCLUDES -D_XOPEN_SOURCE=700 -fno-strict-aliasing -fPIC \
 -include  -D__CHECKER__ -D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized \
 -Wshadow -Wundef -U_FORTIFY_SOURCE ctree.c
 builtin:1:15: error: unable to open '-D__CHECKER__'
 Makefile:177: recipe for target 'ctree.o' failed
 make: *** [ctree.o] Error 1

It means '$(check_defs)' is passed to sparse as NULL and looks
'$(check_defs)'should be assigned before assigning '$(CHECKER_FLAGS)'.
BTW, I'm not familiar with make tool so there could be some my
misunderstanding and better solution.

Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Enhance chunk validation check
Qu Wenruo [Tue, 15 Dec 2015 02:04:01 +0000 (10:04 +0800)]
btrfs-progs: Enhance chunk validation check

Enhance chunk validation:
1) Num_stripes
   We already have such check but it's only in super block sys chunk
   array.
   Now check all on-disk chunks.

2) Chunk logical
   It should be aligned to sector size.
   This behavior should be *DOUBLE CHECKED* for 64K sector size like
   PPC64 or AArch64.
   Maybe we can found some hidden bugs.

3) Chunk length
   Same as chunk logical, should be aligned to sector size.

4) Stripe length
   It should be power of 2.

5) Chunk type
   Any bit out of TYPE_MAS | PROFILE_MASK is invalid.

With all these much restrict rules, several fuzzed image reported in
mail list should no longer cause btrfsck error.

Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: ftw_add_entry_size: Round up file size to sectorsize
Chandan Rajendra [Tue, 15 Dec 2015 10:02:00 +0000 (15:32 +0530)]
btrfs-progs: ftw_add_entry_size: Round up file size to sectorsize

ftw_add_entry_size() assumes 4k as the block size of the underlying
filesystem and hence the file sizes computed is incorrect for non-4k
sectorsized filesystems. Fix this by rounding up file sizes to
sectorsize.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: balance: enhance the usage filter with range
David Sterba [Thu, 22 Oct 2015 08:26:10 +0000 (10:26 +0200)]
btrfs-progs: balance: enhance the usage filter with range

We can do more with the balance usage filter. Enhance it so we can
specify also the minimum usage of the block groups to process. The
'usage' filter now accepts a range (a..b, can be partial) and needs
kernel support.

The 'usage=value' filter is equivalent to 'limit=..value' but works on
older kernels as well.

The min/max values are 32bit, unlike the single-value limit which is
64bit.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: extend balance args to take min/max usage filter
David Sterba [Thu, 22 Oct 2015 08:19:38 +0000 (10:19 +0200)]
btrfs-progs: extend balance args to take min/max usage filter

Add the overlapping usage and [usage_min, usage_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_USAGE_RANGE is set.

The minimum boundary is inclusive, maximum is exclusive:
* usage_min <= chunk_usage < usage_max

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: balance: add stripes filter
Gabríel Arthúr Pétursson [Mon, 28 Sep 2015 22:33:04 +0000 (22:33 +0000)]
btrfs-progs: balance: add stripes filter

Add new balance filter 'stripes=<range>' to process only chunks that are
spread accross given number of chunks.

The range minimum and maximum are inclusive.

Signed-off-by: Gabríel Arthúr Pétursson <gabriel@system.is>
[ reworked a bit to use the range helpers, dropped the single value
  for stripes ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: balance: enhance the limit fiter with range
David Sterba [Sun, 11 Oct 2015 22:52:43 +0000 (00:52 +0200)]
btrfs-progs: balance: enhance the limit fiter with range

We can do more with the balance filter. Enhance it so we can specify
also the minimum number of block groups to process. The 'limit' filter
now accepts a range (a..b, can be partial) and needs kernel support.

The 'limit=value' filter is equivalent to 'limit=..value' but works on
older kernels as well.

The min/max values are 32bit, unlike the single-value limit which is
64bit.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: extend balance args to take min/max limit filter
David Sterba [Sun, 11 Oct 2015 22:34:58 +0000 (00:34 +0200)]
btrfs-progs: extend balance args to take min/max limit filter

Add the overlapping limit and [limit_min, limit_max] members to the
balance args. The min/max values are interpreted iff the corresponding
flag BTRFS_BALANCE_ARGS_LIMIT_RANGE is set.

The minimum and maximum are inclusive.

Note that the values are only 32bit, but this should be enough for the
foreseeable future.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: test multiple-linked file corruption
Naohiro Aota [Tue, 8 Dec 2015 02:07:13 +0000 (11:07 +0900)]
btrfs-progs: tests: test multiple-linked file corruption

This commit extends the leaf corruption test to try to repair a file
linked from multiple directory. It stresses a case that some links to a
file is broken but others kept valid.

Signed-off-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Introduce new members for btrfs_convert_context
Qu Wenruo [Tue, 1 Dec 2015 07:11:23 +0000 (15:11 +0800)]
btrfs-progs: Introduce new members for btrfs_convert_context

Introduce 3 new members for btrfs_convert_context:

1) struct cache_tree used
Records accurate byte ranges which are used by old filesystem.
This will be used to create old filesystem image.

2) struct cache_tree data_chunks
Records batched ranges which must be covered by data chunks.
The bytenr range is optimized to meet all the chunk requirement.

3) u64 total_bytenr
Records how large the filesystem is in bytenr.
Yes, we can calculate it easy, but that's for old blocks based
filesystem.
This will make it more friendly for extent based filesystem.
And later cctx->block_counts and may be removed

And 2 for mkfs_config:
1) char *chunk_uuid.
Used as temporary chunk_uuid (unparsed) string for later
make_convert_btrfs()

2) u64 super_bytenr
Records the new temporary super bytenr after make_btrfs().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: extent-tree: Add add_merge_cache_extent function
Qu Wenruo [Tue, 1 Dec 2015 07:11:22 +0000 (15:11 +0800)]
btrfs-progs: extent-tree: Add add_merge_cache_extent function

This add_merge_cache_extent() function will try to merge adjusted
cache_extent.

This is used for later btrfs-convert ext2 free space cache.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: extent-cache: Add comments for search/lookup functions
Qu Wenruo [Tue, 1 Dec 2015 07:11:21 +0000 (15:11 +0800)]
btrfs-progs: extent-cache: Add comments for search/lookup functions

There are quite a lot search/lookup functions with different behavior,
add comments for them, as it will take extra time to view source to
understand the behavior difference.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: check, properly reset nlink of multi-linked file
Naohiro Aota [Fri, 4 Dec 2015 05:37:26 +0000 (14:37 +0900)]
btrfs-progs: check, properly reset nlink of multi-linked file

If a file is linked from more than one directory and only one
of the links is corrupted, btrfs check dose not reset the nlink
properly. Actually it can go into infinite loop to link the broken file
into lost+found.

This patch fix two part of the code. The first one delay the freeing
valid (no error, found inode ref, directory index, and directory
item) backrefs. Freeing valid backrefs earier prevent reset_nlink() to
add back all valid links.

The second fix is obvious: passing `ref_type' to btrfs_add_link() is just
wrong. It should be `filetype' instead. The current code can break all valid
file links.

Signed-off-by: Naohiro Aota <naota@elisp.net>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: print test type
David Sterba [Mon, 30 Nov 2015 17:13:01 +0000 (18:13 +0100)]
btrfs-progs: tests: print test type

Makes it a bit more clear:

    [TEST/conv]   ext4 32k nodesize, btrfs no-holes
    [TEST/conv]   ext2 64k nodesize, btrfs no-holes
    [TEST/conv]   ext3 64k nodesize, btrfs no-holes
    [TEST/conv]   ext4 64k nodesize, btrfs no-holes
    [TEST]        misc-tests.sh
    [TEST/misc]   001-btrfstune-features
    [TEST/misc]   002-uuid-rewrite
    [TEST/misc]   003-zero-log
    [TEST/misc]   004-shrink-fs
    [TEST/misc]   005-convert-progress-thread-crash
    [TEST/misc]   006-image-on-missing-device
    [TEST/misc]   007-subvolume-sync
    [TEST/misc]   008-leaf-crossing-stripes
    [TEST/misc]   009-subvolume-sync-must-wait
    [TEST/misc]   010-convert-delete-ext2-subvol
    [TEST/misc]   011-delete-missing-device
    [TEST]        fuzz-tests.sh
    [TEST/fuzz]   001-simple-unmounted

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: show-super: copy implementation of btrfs_read_sys_array
David Sterba [Mon, 30 Nov 2015 16:56:58 +0000 (17:56 +0100)]
btrfs-progs: show-super: copy implementation of btrfs_read_sys_array

btrfs-show-super has own implementation to read the sys array and it
lacks all the sanity checks.

Copy and adapt the improved implementation from btrfs_read_sys_array.
This will fix crashes on a fuzzed/corrupted images. It's duplicating
code but at the moment looks easier than refactoring and restructuring
btrfs_read_sys_array that now almost matches the kernel code, which we
want in the long term.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add sys-array-num-stripes-0.raw.xz
David Sterba [Mon, 30 Nov 2015 16:42:15 +0000 (17:42 +0100)]
btrfs-progs: tests: add sys-array-num-stripes-0.raw.xz

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: verbose error when we find an unexpected item in sys_array
David Sterba [Mon, 30 Nov 2015 16:10:20 +0000 (17:10 +0100)]
btrfs-progs: verbose error when we find an unexpected item in sys_array

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handle invalid num_stripes in sys_array
David Sterba [Mon, 30 Nov 2015 15:44:29 +0000 (16:44 +0100)]
btrfs-progs: handle invalid num_stripes in sys_array

We can handle the special case of num_stripes == 0 directly inside
btrfs_read_sys_array. The BUG_ON in btrfs_chunk_item_size is there to
catch other unhandled cases where we fail to validate external data,
like in btrfs-show-super.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add more checks to btrfs_read_sys_array
David Sterba [Wed, 5 Nov 2014 14:24:51 +0000 (15:24 +0100)]
btrfs-progs: add more checks to btrfs_read_sys_array

Port of kernel commit e3540eab29e1b2260bc4b9b3979a49a00e3e3af8

Verify that the sys_array has enough bytes to read the next item.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cleanup, rename a few variables in btrfs_read_sys_array
David Sterba [Mon, 30 Nov 2015 15:07:35 +0000 (16:07 +0100)]
btrfs-progs: cleanup, rename a few variables in btrfs_read_sys_array

Port of kernel commit 1ffb22cf8c322bbfea6b35fe23d025841b49fede

There's a pointer to buffer, integer offset and offset passed as
pointer, try to find matching names for them.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: update btrfs_read_sys_array to match kernel implementation
David Sterba [Mon, 30 Nov 2015 14:57:36 +0000 (15:57 +0100)]
btrfs-progs: update btrfs_read_sys_array to match kernel implementation

There are some sanity checks missing on both sides, kernel/userspace.
Preparation to port the missing changes.

Sync code with parent of kernel commit
1ffb22cf8c322bbfea6b35fe23d025841b49fede ("btrfs: cleanup, rename a few
variables in btrfs_read_sys_array")

This effectively reverts progs commit
be96777126d283773e4397278a5662d90676ab88 ("btrfs-progs: Cleanup unneeded
extra variant in btrfs_read_sys_array") so we can apply more of the
kernel patches.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: mkfs, check sectorsize and nodesize combinations
Qu Wenruo [Mon, 30 Nov 2015 01:39:30 +0000 (09:39 +0800)]
btrfs-progs: tests: mkfs, check sectorsize and nodesize combinations

Add mkfs selftest for invalid and valid sectorsize/nodesize
combinations.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ switched to TEST_DEV ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: install to /usr/local by default again
David Sterba [Mon, 30 Nov 2015 09:36:28 +0000 (10:36 +0100)]
btrfs-progs: install to /usr/local by default again

The conversion to autotools changed the default prefix to /usr. There's
no reason to diverge. Distributions builds set prefix the /usr path and
local builds are supposed to go to /usr/local .

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=108571
Reported-by: Karl Richter <krichter722@aol.de>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: mkfs, implications of DUP on devices
David Sterba [Thu, 26 Nov 2015 16:56:45 +0000 (17:56 +0100)]
btrfs-progs: docs: mkfs, implications of DUP on devices

We offer DUP but still depend on the hardware, to do the right thing.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: enhance 001-basic-profiles with --data DUP
David Sterba [Thu, 26 Nov 2015 15:22:16 +0000 (16:22 +0100)]
btrfs-progs: tests: enhance 001-basic-profiles with --data DUP

Add the remaining valid combinations.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: allow --data DUP for single device
Zhao Lei [Thu, 19 Nov 2015 09:36:24 +0000 (17:36 +0800)]
btrfs-progs: mkfs: allow --data DUP for single device

Current code don't support DUP profile on single device, except it
is in mixed mode, because of following reasons:

1: Some SSD do deduplication internally, so the duplication on
   the filesystem side has no effect.
2: On a physical device, if the entire disk broken, --data DUP does not
   help.
3: Half performance compared to single profile.
4: We have a workaround: create multi-partition on a single device,
   and btffs will treat them as multi device.

Instead of refusing --data DUP, we give the user a choice and print
a wrning.

Test:
1: Tested by xfstests
   Run with modified xfstests, I add test items of -d dup in single
   device into btrfs/* and common/rc, run tests of btrfs/*,
   with all mount option, no regression diffed with v4.3.
2: Tested by btrfs-progs
   Checked following commands in "-m dup -d dup" fs with memleck
   checking, all passed:
   mkfs.btrfs -f --data dup --metadata dup /dev/sda6
   btrfs filesystem show /dev/sda6
   btrfs filesystem label /dev/sda6 btrfs_label_test
   btrfs filesystem label /dev/sda6
   btrfs device scan --all-devices
   btrfs device scan /dev/sda6
   btrfs device scan /dev/sda6
   btrfs device ready /dev/sda6
   btrfs check /dev/sda6
   btrfs check -s 1 /dev/sda6
   btrfs check --repair /dev/sda6
   btrfs check --init-csum-tree /dev/sda6
   btrfs check --init-extent-tree /dev/sda6
   btrfs check --check-data-csum /dev/sda6
   btrfs check --qgroup-report /dev/sda6
   btrfs rescue super-recover -y /dev/sda6
   btrfs rescue zero-log /dev/sda6
   btrfs restore -l /dev/sda6
   btrfs restore /dev/sda6 /
   btrfs restore -s /dev/sda6 /
   btrfs restore -x /dev/sda6 /
   btrfs restore -m /dev/sda6 /
   btrfs restore -S /dev/sda6 /
   btrfs restore -v /dev/sda6 /
   btrfs restore -i /dev/sda6 /
   btrfs restore -o /dev/sda6 /
   btrfs restore -u0 /dev/sda6 /
   btrfs restore -u1 /dev/sda6 /
   btrfs restore -D /dev/sda6 /
   btrfs property list /dev/sda6
   btrfs property get /dev/sda6 label
   btrfs property set /dev/sda6 label test
   btrfs property set /dev/sda6 label btrfs_label_test
   btrfs help
   btrfs help --full
   btrfs version
   btrfsck /dev/sda6
   btrfs-find-root /dev/sda6
   btrfs-find-root -a /dev/sda6
   btrfs-map-logical -l1 /dev/sda6
   btrfs-map-logical -l1 -c1 /dev/sda6
   btrfs-map-logical -l1 -o /tmp/btrfs-map-logic-out /dev/sda6
   btrfs-map-logical -l1 -b1 /dev/sda6
   btrfs-select-super -s 0 /dev/sda6
   btrfs-select-super -s 1 /dev/sda6
   btrfstune -S 1 /dev/sda6
   btrfstune -f -S 0 /dev/sda6
   btrfstune -r /dev/sda6
   btrfstune -x /dev/sda6
   btrfstune -n /dev/sda6
   btrfstune -f -U 00000000-0000-0000-0000-000000000000 /dev/sda6
   btrfstune -f -u /dev/sda6
   btrfs-calc-size /dev/sda6
   btrfs-calc-size -v /dev/sda6
   btrfs-calc-size -b /dev/sda6
   btrfs-debug-tree /dev/sda6
   btrfs-debug-tree -e /dev/sda6
   btrfs-debug-tree -d /dev/sda6
   btrfs-debug-tree -r /dev/sda6
   btrfs-debug-tree -R /dev/sda6
   btrfs-debug-tree -u /dev/sda6
   btrfs-debug-tree -b 0 /dev/sda6
   btrfs-debug-tree -t 0 /dev/sda6
   btrfs-debug-tree -t 2 /dev/sda6
   btrfs-show-super /dev/sda6
   btrfs-show-super -i 0 /dev/sda6
   btrfs-show-super -i 1 /dev/sda6
   btrfs-show-super -i 2 /dev/sda6
   btrfs-show-super -a /dev/sda6
   btrfs-show-super -f /dev/sda6
   btrfs-show-super -F /dev/sda6
   btrfs subvolume list /mnt/btrfs-progs-tests
   btrfs subvolume create /mnt/btrfs-progs-tests/mysubvol
   btrfs subvolume list /mnt/btrfs-progs-tests
   btrfs subvolume get-default /mnt/btrfs-progs-tests
   btrfs subvolume set-default 258 /mnt/btrfs-progs-tests
   btrfs subvolume get-default /mnt/btrfs-progs-tests
   btrfs subvolume set-default  /mnt/btrfs-progs-tests
   btrfs subvolume snapshot /mnt/btrfs-progs-tests/mysubvol /mnt/btrfs-progs-tests/mysubvol_snap
   btrfs subvolume list /mnt/btrfs-progs-tests
   btrfs subvolume find-new /mnt/btrfs-progs-tests 0
   btrfs subvolume find-new /mnt/btrfs-progs-tests 0
   btrfs subvolume find-new /mnt/btrfs-progs-tests/mysubvol 0
   btrfs subvolume find-new /mnt/btrfs-progs-tests/mysubvol 0
   btrfs subvolume show /mnt/btrfs-progs-tests
   btrfs subvolume show /mnt/btrfs-progs-tests/mysubvol
   btrfs subvolume show /mnt/btrfs-progs-tests/mysubvol_snap
   btrfs subvolume sync /mnt/btrfs-progs-tests
   btrfs subvolume delete /mnt/btrfs-progs-tests/mysubvol_snap
   btrfs subvolume delete /mnt/btrfs-progs-tests/mysubvol
   btrfs subvolume sync /mnt/btrfs-progs-tests
   btrfs filesystem df /mnt/btrfs-progs-tests
   btrfs filesystem show /mnt/btrfs-progs-tests
   btrfs filesystem sync /mnt/btrfs-progs-tests
   btrfs filesystem label /mnt/btrfs-progs-tests btrfs_label_test
   btrfs filesystem label /mnt/btrfs-progs-tests
   btrfs filesystem usage /mnt/btrfs-progs-tests
   btrfs filesystem defragment -s 1024 -l 2048 /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_0
   btrfs filesystem defragment /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_1
   btrfs filesystem defragment -f /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_2
   btrfs filesystem defragment -czlib /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_3
   btrfs filesystem defragment -clzo /mnt/btrfs-progs-tests/filesystem_test_dir/test_dir_0/test_file_4
   btrfs filesystem defragment /mnt/btrfs-progs-tests/filesystem_test_dir
   btrfs filesystem defragment -r /mnt/btrfs-progs-tests/filesystem_test_dir
   btrfs filesystem defragment /mnt/btrfs-progs-tests
   btrfs filesystem resize 1:-10M /mnt/btrfs-progs-tests
   btrfs filesystem resize 1:max /mnt/btrfs-progs-tests
   btrfs balance start /mnt/btrfs-progs-tests
   btrfs balance start -v /mnt/btrfs-progs-tests
   btrfs balance start -f /mnt/btrfs-progs-tests
   btrfs balance status -v /mnt/btrfs-progs-tests
   btrfs balance pause /mnt/btrfs-progs-tests
   btrfs balance status /mnt/btrfs-progs-tests
   btrfs balance resume /mnt/btrfs-progs-tests
   btrfs balance status -v /mnt/btrfs-progs-tests
   btrfs balance cancel /mnt/btrfs-progs-tests
   btrfs balance start -dprofiles=single /mnt/btrfs-progs-tests
   btrfs balance start -dconvert=single /mnt/btrfs-progs-tests
   btrfs balance start -ddevid=1 /mnt/btrfs-progs-tests
   btrfs balance start -f -mprofiles=single /mnt/btrfs-progs-tests
   btrfs balance start -f -mconvert=single /mnt/btrfs-progs-tests
   btrfs balance start -f -mdevid=1 /mnt/btrfs-progs-tests
   btrfs balance start -f -sprofiles=single /mnt/btrfs-progs-tests
   btrfs balance start -f -sconvert=single /mnt/btrfs-progs-tests
   btrfs balance start -f -sdevid=1 /mnt/btrfs-progs-tests
   btrfs device add -f /dev/sda10 /mnt/btrfs-progs-tests
   btrfs device del /dev/sda10 /mnt/btrfs-progs-tests
   btrfs device stats /dev/sda6
   btrfs device stats -z /dev/sda6
   btrfs device stats /mnt/btrfs-progs-tests
   btrfs device stats -z /mnt/btrfs-progs-tests
   btrfs device usage /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub start -B /mnt/btrfs-progs-tests
   btrfs scrub start -B -d /mnt/btrfs-progs-tests
   btrfs scrub start -B -r /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub start /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub status -d /mnt/btrfs-progs-tests
   btrfs scrub status -R /mnt/btrfs-progs-tests
   btrfs scrub status /mnt/btrfs-progs-tests
   btrfs scrub start /dev/sda6
   btrfs scrub status /dev/sda6
   btrfs scrub status /dev/sda6
   btrfs scrub status -d /dev/sda6
   btrfs scrub status -R /dev/sda6
   btrfs scrub status /dev/sda6
   btrfs subvolume snapshot -r /mnt/btrfs-progs-tests /mnt/btrfs-progs-tests/snap1
   btrfs send -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1
   btrfs send -e -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1
   btrfs send --no-data -f /tmp/btrfs_snapshot_test /mnt/btrfs-progs-tests/snap1
   btrfs quota enable /mnt/btrfs-progs-tests
   btrfs quota rescan /mnt/btrfs-progs-tests
   btrfs quota rescan -s /mnt/btrfs-progs-tests
   btrfs quota rescan -w /mnt/btrfs-progs-tests
   btrfs quota disable /mnt/btrfs-progs-tests
   btrfs quota enable /mnt/btrfs-progs-tests
   btrfs qgroup create 1/5 /mnt/btrfs-progs-tests
   btrfs qgroup create 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup assign 1/5 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup limit 1G 1/5 /mnt/btrfs-progs-tests
   btrfs qgroup show /mnt/btrfs-progs-tests
   btrfs qgroup show -p -c -r -e -F -f /mnt/btrfs-progs-tests
   btrfs qgroup remove 1/5 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup destroy 2/5 /mnt/btrfs-progs-tests
   btrfs qgroup destroy 1/5 /mnt/btrfs-progs-tests
   btrfs quota disable /mnt/btrfs-progs-tests
   btrfs replace start -f -B /dev/sda6 /dev/sda10 /mnt/btrfs-progs-tests
   btrfs replace status /mnt/btrfs-progs-tests
   btrfs replace start -f -B /dev/sda10 /dev/sda6 /mnt/btrfs-progs-tests
   btrfs-convert /dev/sda6
   btrfs-convert -r /dev/sda6
   btrfs-convert -d /dev/sda6
   btrfs-convert -i /dev/sda6
   btrfs-convert -n /dev/sda6
   btrfs-convert -N 4096 /dev/sda6
   btrfs-convert -l test /dev/sda6
   btrfs-convert -L /dev/sda6
   btrfs-convert --no-progress /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -c 0 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -c 9 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -t 0 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -t 1 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -t 32 /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -w /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   mkfs.btrfs -f /dev/sda6
   btrfs-image -w /dev/sda6 /tmp/btrfs_image.img
   btrfs-image -r /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -t 0 /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -t 1 /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -t 32 /tmp/btrfs_image.img /dev/sda6
   btrfs-image -r -o /tmp/btrfs_image.img /dev/sda6
3: Manual check relation source by:
   grep DUP *.c
   Confirmed that all source are modified.
4: Use this raid type manually, do some operations in fs,
   no error found in command and dmesg.
5: Combination of dup conversion with fsck
   Confirmed OK with relative kernel patch titled:
   [PATCH] btrfs: Support convert to -d dup for btrfs-convert

   export TEST_DEV='/dev/vdc'
   export TEST_DIR='/var/ltf/tester/mnt'

   do_dup_test()
   {
       local m_from="$1"
       local d_from="$2"
       local m_to="$3"
       local d_to="$4"

       echo "Convert from -m $m_from -d $d_from to -m $m_to -d $d_to"

       umount "$TEST_DIR" &>/dev/null
       ./mkfs.btrfs -f -m "$m_from" -d "$d_from" "$TEST_DEV" >/dev/null || return 1
       mount "$TEST_DEV" "$TEST_DIR" || return 1

       cp -a /sbin/* "$TEST_DIR"

       [[ "$m_from" != "$m_to" ]] && {
           ./btrfs balance start -f -mconvert="$m_to" "$TEST_DIR" || return 1
       }

       [[ "$d_from" != "$d_to" ]] && {
       local opt=()
           [[ "$d_to" == single ]] && opt+=("-f")
           ./btrfs balance start "${opt[@]}" -dconvert="$d_to" "$TEST_DIR" || return 1
       }

       umount "$TEST_DIR" || return 1
       ./btrfsck "$TEST_DEV" || return 1
       echo

       return 0
   }

   test_all()
   {
       for m_from in single dup; do
       for d_from in single dup; do
       for m_to in single dup; do
       for d_to in single dup; do
       do_dup_test "$m_from" "$d_from" "$m_to" "$d_to" || return 1
       done
       done
       done
       done
   }

   test_all

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Tested-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
[ minor updates in the changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: convert: add context and operations struct to allow different file systems
Jeff Mahoney [Wed, 14 Aug 2013 18:39:21 +0000 (14:39 -0400)]
btrfs-progs: convert: add context and operations struct to allow different file systems

Push out common convert operations into function pointers that we can
ultimately allow other file systems to use to provide their own
conversions.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
8 years agobtrfs-progs: tests: add 019-non-skinny-false-alert
David Sterba [Thu, 26 Nov 2015 14:20:05 +0000 (15:20 +0100)]
btrfs-progs: tests: add 019-non-skinny-false-alert

Catch a buggy condition fixed by "btrfs-progs: fsck: Fix a false alert
where extent record has wrong metadata flag"

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fsck: Fix a false alert where extent record has wrong metadata flag
Qu Wenruo [Wed, 25 Nov 2015 06:19:06 +0000 (14:19 +0800)]
btrfs-progs: fsck: Fix a false alert where extent record has wrong metadata flag

In process_extent_item(), it gives 'metadata' initial value 0, but for
non-skinny-metadata case, metadata extent can't be judged just from key
type and it forgot that case.

This causes a lot of false alert in non-skinny-metadata filesystem.

Fix it by set correct metadata value before calling add_extent_rec().

Reported-by: Christoph Anton Mitterer <calestyo@scientia.net>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: update raid table in mkfs manpage
David Sterba [Tue, 24 Nov 2015 17:14:39 +0000 (18:14 +0100)]
btrfs-progs: docs: update raid table in mkfs manpage

* split copies to copies and parity and add a common header for all the
  raid options
* add missing RAID1
* n/a were dropped

Based on feedback from Duncan <1i5t5.duncan@cox.net>.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: chunk-recovery: Fix a float point error
Qu Wenruo [Thu, 19 Nov 2015 06:42:39 +0000 (14:42 +0800)]
btrfs-progs: chunk-recovery: Fix a float point error

Fix a zero division causing chunk-recovery fail.

Also fix a typo "strpie_length" -> "stripe_length".

Reported-by: Scotty Edmonds <scotty@scottyedmonds.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 007-mix-nodesize-sectorsize
David Sterba [Thu, 19 Nov 2015 15:37:15 +0000 (16:37 +0100)]
btrfs-progs: tests: add 007-mix-nodesize-sectorsize

Test combinations of sectorsize and nodesize on a single device.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: use correct size for superblock csum and writeout
David Sterba [Thu, 19 Nov 2015 14:55:05 +0000 (15:55 +0100)]
btrfs-progs: mkfs: use correct size for superblock csum and writeout

If sectorsize is not BTRFS_SUPER_INFO_SIZE (4k), the superblock checksum
is wrong and mkfs fails. This has been reported on ppc64 where we pick
sectorisize from page size (64k).  This has been broken since ages
(2008) and discovered by the recently added superblock checks.

Reported-by: Dinar Valeev <dvaleev@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: fix typo in balance man page
Jeffrey Schiller [Tue, 17 Nov 2015 05:01:46 +0000 (00:01 -0500)]
btrfs-progs: docs: fix typo in balance man page

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs progs v4.3.1
David Sterba [Mon, 16 Nov 2015 13:29:25 +0000 (14:29 +0100)]
Btrfs progs v4.3.1

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix fd leak in resolve_loop_device_with_loopdev
David Sterba [Fri, 13 Nov 2015 18:15:27 +0000 (19:15 +0100)]
btrfs-progs: fix fd leak in resolve_loop_device_with_loopdev

Resolves-coverity-id: 1339300
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 006-partitioned-loopdev
David Sterba [Fri, 13 Nov 2015 17:43:04 +0000 (18:43 +0100)]
btrfs-progs: tests: add 006-partitioned-loopdev

Create filesystem on a partitioned loop device, test for "btrfs-progs:
Fix partitioned loop devices resolving".

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: utils: do not expect lo_file_name to be null terminated
David Sterba [Fri, 13 Nov 2015 17:20:38 +0000 (18:20 +0100)]
btrfs-progs: utils: do not expect lo_file_name to be null terminated

The loop_info64::lo_file_name might not be null terminated. Avoid strlen
and trim the length to whatever size of the loop_info buffer.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Fix partitioned loop devices resolving
Florian Margaine [Fri, 13 Nov 2015 17:09:05 +0000 (18:09 +0100)]
btrfs-progs: Fix partitioned loop devices resolving

When using partitions on a loop device, the device's name can be
e.g. /dev/loop0p1 or similar, and no relevant entry exists in the /sys
filesystem, so the current resolve_loop_device function fails.

Instead of using string functions to extract the device name and reading
this file, this patch uses the loop device API through ioctl to get the
correct backing file.

Signed-off-by: Florian Margaine <florian@platform.sh>
[ changed checks of error values from open and ioctl ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: find-root: Add support to search chunk root
Qu Wenruo [Fri, 13 Nov 2015 02:53:41 +0000 (10:53 +0800)]
btrfs-progs: find-root: Add support to search chunk root

Add support to search chunk root, as we only need to search tree roots
in system chunk, which should be very easy to add, just iterate in
system chunks.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ renamed to btrfs_next_bg_* ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cleanup cmd_device_usage, simplify loop checks
Zhao Lei [Mon, 9 Nov 2015 09:59:38 +0000 (17:59 +0800)]
btrfs-progs: cleanup cmd_device_usage, simplify loop checks

1: Remove more_than_one variable, use iterators value instead
2: Remove "out" label, we use break instead.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[ changelog update ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: device: use warning/error for error message
Zhao Lei [Mon, 9 Nov 2015 09:59:37 +0000 (17:59 +0800)]
btrfs-progs: device: use warning/error for error message

Switch to common warning()/error() for cmds-device.c.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[ minor tweaks ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Check periodic.timer_fd's value before use
Zhao Lei [Mon, 9 Nov 2015 09:06:53 +0000 (17:06 +0800)]
btrfs-progs: Check periodic.timer_fd's value before use

periodic.timer_fd's value is 0 on inititlize-failed case,
if no value-checking before read(), the code will run as
read(STDIN).

This patch fixed above case.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 005-long-device-name-for-ssd
David Sterba [Fri, 13 Nov 2015 16:29:11 +0000 (17:29 +0100)]
btrfs-progs: tests: add 005-long-device-name-for-ssd

A test for "btrfs-progs: mkfs: increase buffer size in is_ssd". Create a
device with a long name through loop device wrapped to a device mapper
linear device, switch it to the "ssd" mode status.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: increase buffer size in is_ssd
Michael Lass [Sun, 8 Nov 2015 15:33:03 +0000 (16:33 +0100)]
btrfs-progs: mkfs: increase buffer size in is_ssd

In current versions of util-linux the buffer passed to blkid_devno_to_wholedisk
has to be sufficiently large to not only hold the device name but the complete
target of the /sys/dev/block/<maj:min> symlink. This was changed only recently
in 4419ffb9eff5801fdbd385a4a6199b3877f802ad.

The small buffer size currently can lead to failure of is_ssd due to truncated
device names:

readlink("/sys/dev/block/254:7", "../../devices/virtual/block/dm-", 31) = 31
open("/sys/block/dm-/queue/rotational", O_RDONLY) = -1 ENOENT (No such file or directory)

Signed-off-by: Michael Lass <bevan@bi-co.net>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 011-delete-missing-device
David Sterba [Fri, 13 Nov 2015 15:49:55 +0000 (16:49 +0100)]
btrfs-progs: tests: add 011-delete-missing-device

Test for "btrfs-progs: allow device deletion using 'missing' keyword
again".

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: allow device deletion using 'missing' keyword again
Alexander Fougner [Sat, 7 Nov 2015 00:26:24 +0000 (01:26 +0100)]
btrfs-progs: allow device deletion using 'missing' keyword again

Device deletion procedures ensures the device is a block device.
This patch introduces 'missing' as keyword again, correctly
passing it on to the kernel instead of complaining about
'missing' not being a block device.

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: handler memory allocation error in make_btrfs
David Sterba [Fri, 6 Nov 2015 17:52:09 +0000 (18:52 +0100)]
btrfs-progs: mkfs: handler memory allocation error in make_btrfs

Do the allocation early, no need to cleanup.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: image: reorder initialization in metadump_init
David Sterba [Fri, 6 Nov 2015 17:31:27 +0000 (18:31 +0100)]
btrfs-progs: image: reorder initialization in metadump_init

Put the allocations first, move pthread cond and mutex last so we don't
have to do cleanup.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: corrupt-block: use on-stack path buffer in corrupt_dir_item
David Sterba [Fri, 6 Nov 2015 17:27:55 +0000 (18:27 +0100)]
btrfs-progs: corrupt-block: use on-stack path buffer in corrupt_dir_item

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: calc-size: kill fs_roots structure and its user
David Sterba [Fri, 6 Nov 2015 17:25:04 +0000 (18:25 +0100)]
btrfs-progs: calc-size: kill fs_roots structure and its user

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: calc-size: use on-stack buffer for a helper structure
David Sterba [Fri, 6 Nov 2015 17:20:52 +0000 (18:20 +0100)]
btrfs-progs: calc-size: use on-stack buffer for a helper structure

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: drop unused argument from zero_output_file
David Sterba [Fri, 6 Nov 2015 17:12:44 +0000 (18:12 +0100)]
btrfs-progs: drop unused argument from zero_output_file

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use fixed size buffer in zero_output_file
David Sterba [Fri, 6 Nov 2015 17:10:29 +0000 (18:10 +0100)]
btrfs-progs: use fixed size buffer in zero_output_file

Rewrite the loop so we don't need to allocate sectorsize and write in 4k
steps instead. We know that sectorsize is divisible by 4096.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handle memory allocation failures in traverse_directory
David Sterba [Fri, 6 Nov 2015 17:03:24 +0000 (18:03 +0100)]
btrfs-progs: handle memory allocation failures in traverse_directory

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handle memory allocation failure in add_file_items
David Sterba [Fri, 6 Nov 2015 16:57:41 +0000 (17:57 +0100)]
btrfs-progs: handle memory allocation failure in add_file_items

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use on-stack buffer in __csum_tree_block_size
David Sterba [Fri, 6 Nov 2015 16:50:48 +0000 (17:50 +0100)]
btrfs-progs: use on-stack buffer in __csum_tree_block_size

We know the maximum size of a checksum, calling malloc for 4 bytes is
weird.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use on-stack buffer in __ino_to_path_fd
David Sterba [Fri, 6 Nov 2015 16:47:17 +0000 (17:47 +0100)]
btrfs-progs: use on-stack buffer in __ino_to_path_fd

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use on-stack buffer in recover_prepare
David Sterba [Fri, 6 Nov 2015 16:38:31 +0000 (17:38 +0100)]
btrfs-progs: use on-stack buffer in recover_prepare

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use on-stack variable in __rebuild_device_items
David Sterba [Fri, 6 Nov 2015 16:34:45 +0000 (17:34 +0100)]
btrfs-progs: use on-stack variable in __rebuild_device_items

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use on-stack buffer for btrfs_scan_one_device
David Sterba [Fri, 6 Nov 2015 16:09:17 +0000 (17:09 +0100)]
btrfs-progs: use on-stack buffer for btrfs_scan_one_device

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use on-stack buffer for dev_to_fsid
David Sterba [Fri, 6 Nov 2015 16:09:17 +0000 (17:09 +0100)]
btrfs-progs: use on-stack buffer for dev_to_fsid

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: remove unused parameter from print_one_fs
David Sterba [Fri, 6 Nov 2015 16:05:36 +0000 (17:05 +0100)]
btrfs-progs: remove unused parameter from print_one_fs

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: don't print version info from embedded subcommands
David Sterba [Fri, 6 Nov 2015 16:00:36 +0000 (17:00 +0100)]
btrfs-progs: don't print version info from embedded subcommands

The version is provided by 'btrfs --version'.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: simplify empty stirngs check
David Sterba [Fri, 6 Nov 2015 15:53:55 +0000 (16:53 +0100)]
btrfs-progs: simplify empty stirngs check

We can do a strlen(str) == 0 in a simpler way.

Signed-off-by: David Sterba <dsterba@suse.com>