platform/upstream/btrfs-progs.git
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>
8 years agobtrfs-progs: utils: rename helpinfo unit vairables
David Sterba [Fri, 6 Nov 2015 15:39:49 +0000 (16:39 +0100)]
btrfs-progs: utils: rename helpinfo unit vairables

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs progs v4.3
David Sterba [Fri, 6 Nov 2015 11:07:54 +0000 (12:07 +0100)]
Btrfs progs v4.3

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: do not truncate the image when --rootdir is set
David Sterba [Thu, 5 Nov 2015 13:22:10 +0000 (14:22 +0100)]
btrfs-progs: mkfs: do not truncate the image when --rootdir is set

With the rootdir option we try to guess the final size of the image and
fill it with zeros, preceded by truncation. After patch

"Btrfs-progs: Do not force mixed block group creation unless '-M' option
 is specified"

the misc test 002 will fail, because of the non-mixed mode. I think we
should not touch the image size (no change for block devices) and try to
fit into whatever is provided by user.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Allow btrfs_leaf_free_space to accept NULL root
Qu Wenruo [Thu, 5 Nov 2015 08:32:59 +0000 (16:32 +0800)]
btrfs-progs: Allow btrfs_leaf_free_space to accept NULL root

Btrfs_leaf_free_space() function is used to determine the leaf/node
size.
It's OK to use root->nodesize to determine nodesize, but in fact,
extent_buffer->len can also be used to determine the nodesize if caller
can ensure it's a tree block.

So this patch will add support for NULL root for btrfs_leaf_free_space()
function, to allow btrfs_print_leaf() functions to be called in gdb or
to debug temporary btrfs in make_btrfs() without a valid root.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: Round device size down to sectorsize
Zhao Lei [Tue, 3 Nov 2015 03:23:36 +0000 (11:23 +0800)]
btrfs-progs: mkfs: Round device size down to sectorsize

When do following command in a vm, whose disks are created by
qemu-img create -f raw 11 2.6G:
 # mkfs.btrfs -f /dev/vdd /dev/vde /dev/vdf
 # btrfs-show-super /dev/vdd /dev/vde /dev/vdf | grep dev_item.total_bytes
 dev_item.total_bytes    2791727104
 dev_item.total_bytes    2791729152
 dev_item.total_bytes    2791729152
We can see that the first device's size is little smaller.

And it fails xfstests btrfs/011.

Reason:
 First device's size is rounded down to sectorsize in make_btrfs(),
 but other devices are not.

Fix:
 Round down remain devices' size in btrfs_add_to_fsid().

Reported-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Rename variables in btrfs_add_to_fsid
Zhao Lei [Tue, 3 Nov 2015 03:23:37 +0000 (11:23 +0800)]
btrfs-progs: Rename variables in btrfs_add_to_fsid

There are two total_bytes in btrfs_add_to_fsid(), local variable
of total_bytes means fs_total_bytes, and device->total_bytes means
device's total_bytes.
And device's total_bytes in argument is named block_count in current
code.

This patch rename:
 total_bytes -> fs_total_bytes
 block_count -> device_total_bytes

To make code more readable.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: print-tree: Output stripe dev uuid
Qu Wenruo [Tue, 3 Nov 2015 06:48:09 +0000 (14:48 +0800)]
btrfs-progs: print-tree: Output stripe dev uuid

Add output for dev uuid for print_chunk().

Quite useful to debug temporary btrfs in btrfs-convert.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: remove unused code of format uuid string
Zhao Lei [Tue, 3 Nov 2015 11:03:01 +0000 (19:03 +0800)]
btrfs-progs: mkfs: remove unused code of format uuid string

Variant named dev_uuid and uuid_unparse() for set its value are
not used, remove it.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: output device list in sorted order
Zhao Lei [Tue, 3 Nov 2015 11:03:00 +0000 (19:03 +0800)]
btrfs-progs: mkfs: output device list in sorted order

list_for_each_entry_reverse() in current code can not output
devices in sorted order, because the sequence are broken in
btrfs_alloc_chunk().

We can use list_sort() instead.

Before patch:
 # mkfs.btrfs -f /dev/vdd /dev/vde /dev/vdf
 ...
 Number of devices:  3
 Devices:
    ID        SIZE  PATH
     3     2.60GiB  /dev/vdf
     1     2.60GiB  /dev/vdd
     2     2.60GiB  /dev/vde

After patch:
 # mkfs.btrfs -f /dev/vdd /dev/vde /dev/vdf
 ...
 Number of devices:  3
 Devices:
    ID        SIZE  PATH
     1     2.60GiB  /dev/vdd
     2     2.60GiB  /dev/vde
     3     2.60GiB  /dev/vdf

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: print header and footer separation line
David Sterba [Tue, 3 Nov 2015 00:09:50 +0000 (01:09 +0100)]
btrfs-progs: fi usage: print header and footer separation line

Print the full row width and change to '-' as we're not using '='
anywhere.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: string table: add specifier for fillup char
David Sterba [Tue, 3 Nov 2015 00:00:23 +0000 (01:00 +0100)]
btrfs-progs: string table: add specifier for fillup char

Currently it's one by a single "=", but we might want to use
a different filler, let's make it explicit by "*".

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: string table: cleanup, rename single letter variables
David Sterba [Mon, 2 Nov 2015 23:51:29 +0000 (00:51 +0100)]
btrfs-progs: string table: cleanup, rename single letter variables

Exception for indexing variables.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: string table: fix whitespace damage
David Sterba [Mon, 2 Nov 2015 23:46:52 +0000 (00:46 +0100)]
btrfs-progs: string table: fix whitespace damage

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: print device id column in the tabular output<F2>
David Sterba [Mon, 2 Nov 2015 23:19:41 +0000 (00:19 +0100)]
btrfs-progs: fi usage: print device id column in the tabular output<F2>

Example output:

             Data     Metadata System
Id Path      single   RAID1    RAID1    Unallocated

 1 /dev/sdc2 44.94GiB  7.93GiB 32.00MiB     1.00GiB
 2 /dev/sde1 44.94GiB  7.93GiB 32.00MiB     1.00GiB
             ======== ======== ======== ===========
   Total     89.88GiB  7.93GiB 32.00MiB     2.00GiB
   Used      74.28GiB  4.44GiB 20.00KiB

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: cleanup, replace space info starting column constant
David Sterba [Mon, 2 Nov 2015 23:08:32 +0000 (00:08 +0100)]
btrfs-progs: fi usage: cleanup, replace space info starting column constant

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: cleanup, replace header constant
David Sterba [Mon, 2 Nov 2015 17:54:48 +0000 (18:54 +0100)]
btrfs-progs: fi usage: cleanup, replace header constant

The size of the header is not obvious, let's make it more visible by
replacing it with a varaible.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: properly count real space infos
David Sterba [Mon, 2 Nov 2015 17:44:45 +0000 (18:44 +0100)]
btrfs-progs: fi usage: properly count real space infos

We did not account the column for path but abused the skipped global
block reserve colum instead. Properly count the real infos and manually
added headers.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: print path header in the tabular mode
David Sterba [Mon, 2 Nov 2015 17:40:57 +0000 (18:40 +0100)]
btrfs-progs: fi usage: print path header in the tabular mode

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: cleanup, print header in one go
David Sterba [Mon, 2 Nov 2015 17:32:04 +0000 (18:32 +0100)]
btrfs-progs: fi usage: cleanup, print header in one go

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi usage: do not print global block reserve
David Sterba [Mon, 2 Nov 2015 17:24:28 +0000 (18:24 +0100)]
btrfs-progs: fi usage: do not print global block reserve

Global block reserve is inherently part of metadata and should not be
listed separately in the output of 'fi usage' in the tabular output.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs progs v4.3-rc1
David Sterba [Mon, 2 Nov 2015 14:46:50 +0000 (15:46 +0100)]
Btrfs progs v4.3-rc1

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: show-super: Add option to print superblock at given bytenr
Qu Wenruo [Mon, 2 Nov 2015 08:34:19 +0000 (16:34 +0800)]
btrfs-progs: show-super: Add option to print superblock at given bytenr

Add '-s <sb_bytenr>' option to show superblock at given bytenr.

This is very useful to debug non-standard btrfs, like debuging the
1st stage btrfs of btrfs-convert.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ minor updates in docs ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: enhance manual page for inspect-internal
David Sterba [Mon, 2 Nov 2015 13:41:32 +0000 (14:41 +0100)]
btrfs-progs: docs: enhance manual page for inspect-internal

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: enhance the manual page for convert
David Sterba [Mon, 2 Nov 2015 13:19:58 +0000 (14:19 +0100)]
btrfs-progs: docs: enhance the manual page for convert

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: enhance manual page for balance
David Sterba [Mon, 2 Nov 2015 12:44:05 +0000 (13:44 +0100)]
btrfs-progs: docs: enhance manual page for balance

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: enhance manual page for btrfstune
David Sterba [Mon, 2 Nov 2015 10:08:57 +0000 (11:08 +0100)]
btrfs-progs: docs: enhance manual page for btrfstune

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: enhance manual page for mkfs
David Sterba [Fri, 30 Oct 2015 18:16:41 +0000 (19:16 +0100)]
btrfs-progs: docs: enhance manual page for mkfs

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: print version info first
David Sterba [Fri, 30 Oct 2015 15:58:52 +0000 (16:58 +0100)]
btrfs-progs: mkfs: print version info first

The version info should not be preceded by any messages.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: image: fix bogus check after cpu on-line detection
David Sterba [Fri, 30 Oct 2015 14:34:55 +0000 (15:34 +0100)]
btrfs-progs: image: fix bogus check after cpu on-line detection

Comparing unsigned type for <= 0 does not make much sense, we should
really check the signed value returned by sysconf.

Resolves-coverity-id: 1324536
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Avoid use pointer in handle_options
Zhao Lei [Thu, 29 Oct 2015 09:31:48 +0000 (17:31 +0800)]
btrfs-progs: Avoid use pointer in handle_options

We use pointer of argc and argv in handle_options() because they
are necessary in very old code which are not exist now.

This patch move to use argc and argv directly in handle_options(),
alone with following update:
1: rename handle_options() to check_options()
   to fit its function.
2: cleanup for condition in handle_options() to make line short.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Fix uninitialized key.type for btrfs_find_free_objectid
Zhao Lei [Thu, 29 Oct 2015 09:31:46 +0000 (17:31 +0800)]
btrfs-progs: Fix uninitialized key.type for btrfs_find_free_objectid

To avoid using uninitialized value in btrfs_search_slot().

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Fix negative eb's ref_cnt in btrfs-calc-size
Zhao Lei [Thu, 29 Oct 2015 09:31:44 +0000 (17:31 +0800)]
btrfs-progs: Fix negative eb's ref_cnt in btrfs-calc-size

btrfs-calc-size show following warning:
 # btrfs-calc-size /dev/sda6
 Calculating size of root tree
 ...
 extent_io.c:582: free_extent_buffer: Assertion `eb->refs < 0` failed.
 ./btrfs-calc-size[0x41d642]
 ./btrfs-calc-size(free_extent_buffer+0x70)[0x41e1c1]
 ./btrfs-calc-size(btrfs_free_fs_root+0x11)[0x40e1e8]
 ./btrfs-calc-size[0x40e215]
 ./btrfs-calc-size(rb_free_nodes+0x1d)[0x4326fe]
 ./btrfs-calc-size(close_ctree+0x3f3)[0x40f9ea]
 ./btrfs-calc-size(main+0x200)[0x431b4e]
 /lib64/libc.so.6(__libc_start_main+0xf5)[0x3858621d65]
 ./btrfs-calc-size[0x407009]

Reason:
 path in calc_root_size() is only used to save node data,
 it don't hold ref_cnt for each eb in.
 Using btrfs_free_path() to free path will reduce these eb
 again, and cause many problems, as negative ref_cnt or
 invalid memory access.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix floating point exception for btrfs-calc-size
Zhao Lei [Thu, 29 Oct 2015 09:31:43 +0000 (17:31 +0800)]
btrfs-progs: fix floating point exception for btrfs-calc-size

Current code exit with floating point exception on a blank fs:
 # btrfs-calc-size -b /dev/sda6
 Calculating size of root tree
         Total size: 16384
                 Inline data: 0
         Total seeks: 0
                 Forward seeks: 0
                 Backward seeks: 0
 Floating point exception

This patch add a condition check for above case.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add initial tests/README
David Sterba [Tue, 27 Oct 2015 16:17:47 +0000 (17:17 +0100)]
btrfs-progs: add initial tests/README

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add an initial README
David Sterba [Tue, 27 Oct 2015 15:30:22 +0000 (16:30 +0100)]
btrfs-progs: add an initial README

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: remove stray message about forced mixed-bg
David Sterba [Mon, 26 Oct 2015 19:02:22 +0000 (20:02 +0100)]
btrfs-progs: mkfs: remove stray message about forced mixed-bg

We no longer force mixed-bg mode since "Btrfs-progs: Do not force mixed
block group creation unless '-M' option is specified", the message is
not relevant anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 003-mixed-with-wrong-nodesize
David Sterba [Mon, 26 Oct 2015 18:54:57 +0000 (19:54 +0100)]
btrfs-progs: tests: add 003-mixed-with-wrong-nodesize

Mixed mode needs equal sectorsize and nodesize. This was fixed by

 "Btrfs-progs: Prevent creation of filesystem with 'mixed bgs' and
  having differing sectorsize and nodesize"

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: do not log output of run_mayfail to terminal
David Sterba [Mon, 26 Oct 2015 18:51:10 +0000 (19:51 +0100)]
btrfs-progs: tests: do not log output of run_mayfail to terminal

No need to log expected failures to the terminal, the results file is
fine; pass the return value of the command.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs-progs: Prevent creation of filesystem with 'mixed bgs' and having differing...
Chandan Rajendra [Wed, 14 Oct 2015 17:40:38 +0000 (23:10 +0530)]
Btrfs-progs: Prevent creation of filesystem with 'mixed bgs' and having differing sectorsize and nodesize.

mkfs.btrfs allows creation of Btrfs filesystem instances with mixed block
group feature enabled and having a sectorsize different from nodesize.
For e.g:

[root@localhost btrfs-progs]# mkfs.btrfs -f -M -s 4096 -n 16384  /dev/loop0
Forcing mixed metadata/data groups
btrfs-progs v3.19-rc2-404-gbbbd18e-dirty
See http://btrfs.wiki.kernel.org for more information.

Performing full device TRIM (4.00GiB) ...
Label:              (null)
UUID:               c82b5720-6d88-4fa1-ac05-d0d4cb797fd5
Node size:          16384
Sector size:        4096
Filesystem size:    4.00GiB
Block group profiles:
  Data+Metadata:    single            8.00MiB
  System:           single            4.00MiB
SSD detected:       no
Incompat features:  mixed-bg, extref, skinny-metadata
Number of devices:  1
Devices:
  ID        SIZE  PATH
   1     4.00GiB  /dev/loop6

This commit fixes the issue by setting BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS
feature bit before checking the validity of nodesize that was specified on the
command line.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use system's default path for math.h
Zhao Lei [Mon, 26 Oct 2015 10:28:22 +0000 (18:28 +0800)]
btrfs-progs: use system's default path for math.h

Line of
 #include "math.h"
in extent-tree.c using quotas is historical reason, (we had custom
math.h before).

Use "<>" instead of quotes in this header file.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Add missing close_ctree to btrfs-select-super.c
Zhao Lei [Mon, 26 Oct 2015 10:28:21 +0000 (18:28 +0800)]
btrfs-progs: Add missing close_ctree to btrfs-select-super.c

Add missing close_ctree() to btrfs-select-super.c to avoid memory leak.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Add all missing btrfs_close_all_devices to standalone tools
Zhao Lei [Mon, 26 Oct 2015 10:28:20 +0000 (18:28 +0800)]
btrfs-progs: Add all missing btrfs_close_all_devices to standalone tools

This patch add all missing btrfs_close_all_devices() to standalone
tools in btrfs progs, to avoid memory leak.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Remove all btrfs_close_all_devices in sub-command
Zhao Lei [Mon, 26 Oct 2015 10:28:19 +0000 (18:28 +0800)]
btrfs-progs: Remove all btrfs_close_all_devices in sub-command

Since we have btrfs_close_all_devices() in btrfs's main entrance,
it is not necessary to call btrfs_close_all_devices() separately
in each sub-command.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: btrfs: Add missing btrfs_close_all_devices for btrfs command
Zhao Lei [Mon, 26 Oct 2015 10:28:18 +0000 (18:28 +0800)]
btrfs-progs: btrfs: Add missing btrfs_close_all_devices for btrfs command

Adding a btrfs_close_all_devices() after command callback in btrfs.c
can force-close all opened device before program exit, to avoid memory leak
in all btrfs sub-command.

Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add support for command instrumentation
David Sterba [Mon, 26 Oct 2015 14:03:37 +0000 (15:03 +0100)]
btrfs-progs: tests: add support for command instrumentation

Add a way to wrap commands executed by the tests. This means the
common wrappers: run_check, run_check_stdout and run_mayfail , with the
exception of the use root_helper.

The contents of the shell variable INSTRUMENT are prepended to the
command, without quotes. Use with care.

Example: this has been tested with valgrind, the output goes to the
RESULTS file.

 $ INSTRUMENT=valgrind make test-misc

Any use of root_helper/SUDO_HELPER will skip the instrumentation.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: 001-simple-unmounted: iterate over fuzzed images and run check
David Sterba [Mon, 26 Oct 2015 13:36:47 +0000 (14:36 +0100)]
btrfs-progs: tests: 001-simple-unmounted: iterate over fuzzed images and run check

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add test driver for fuzzed images
David Sterba [Mon, 26 Oct 2015 13:35:34 +0000 (14:35 +0100)]
btrfs-progs: tests: add test driver for fuzzed images

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix missing initialization of list head for dev_list
Anand Jain [Thu, 22 Oct 2015 03:58:05 +0000 (11:58 +0800)]
btrfs-progs: fix missing initialization of list head for dev_list

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix uninitialized copy of btrfs_fs_devices list
Anand Jain [Thu, 22 Oct 2015 03:53:39 +0000 (11:53 +0800)]
btrfs-progs: fix uninitialized copy of btrfs_fs_devices list

Noticed that at print_one_uuid() some of the members of btrfs_fs_devices
contained some junk values. It took a while to dig this further, and found
that we make a local copy of the btrfs_fs_devices list at
search_umounted_fs_uuids() and wasn't initialized properly.

Fixed using using calloc instead of malloc.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ switched to calloc ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: do not run sudo helper tests if not necessary
David Sterba [Fri, 23 Oct 2015 09:34:50 +0000 (11:34 +0200)]
btrfs-progs: tests: do not run sudo helper tests if not necessary

We use setup_root_helper in some helpers to make sure that the sudo
helper is set up, and adding that to each test. Make the real test run
only once.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: set default test image size to 2G
David Sterba [Fri, 23 Oct 2015 09:25:55 +0000 (11:25 +0200)]
btrfs-progs: tests: set default test image size to 2G

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 010-convert-delete-ext2-subvol
David Sterba [Fri, 23 Oct 2015 09:43:41 +0000 (11:43 +0200)]
btrfs-progs: tests: add 010-convert-delete-ext2-subvol

Testcase for "Btrfs-progs: fix btrfs-convert rollback to check
ROOT_BACKREF", make sure we don't try a rollback if the ext2_subvol is
half-deleted.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF
Liu Bo [Sun, 18 Oct 2015 05:44:41 +0000 (13:44 +0800)]
Btrfs-progs: fix btrfs-convert rollback to check ROOT_BACKREF

Btrfs has changed to delete subvolume/snapshot asynchronously, which
means that after umount itself, if we've already deleted 'ext2_saved',
rollback can still be completed.

So this adds a check for ROOT_BACKREF before checking ROOT_ITEM since
ROOT_BACKREF is immediately not in the btree after
ioctl(BTRFS_IOC_SNAP_DESTROY) returns.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ updated error messages ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mute coverity warnings about deadcode
Eryu Guan [Mon, 19 Oct 2015 11:37:55 +0000 (19:37 +0800)]
btrfs-progs: mute coverity warnings about deadcode

Coverity reports execution cannot reach this statements. So put WARN_ON
in if-else conditions.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 002-no-force-mixed-on-small-volume
David Sterba [Mon, 19 Oct 2015 16:12:35 +0000 (18:12 +0200)]
btrfs-progs: tests: add 002-no-force-mixed-on-small-volume

Verify that we do not force mixed block groups on small volumes anymore.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 001-basic-profiles mkfs tests
David Sterba [Mon, 19 Oct 2015 15:29:14 +0000 (17:29 +0200)]
btrfs-progs: tests: add 001-basic-profiles mkfs tests

Basic test to cover block group profile combinations.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add mkfs tests
David Sterba [Mon, 19 Oct 2015 15:27:55 +0000 (17:27 +0200)]
btrfs-progs: tests: add mkfs tests

Mkfs deserves it's own.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs-progs: Do not force mixed block group creation unless '-M' option is specified
Chandan Rajendra [Wed, 14 Oct 2015 17:39:37 +0000 (23:09 +0530)]
Btrfs-progs: Do not force mixed block group creation unless '-M' option is specified

When creating small Btrfs filesystem instances (i.e. filesystem size <= 1GiB),
mkfs.btrfs fails if both sectorsize and nodesize are specified on the command
line and sectorsize != nodesize, since mixed block groups involves both data
and metadata blocks sharing the same block group. This is an incorrect behavior
when '-M' option isn't specified on the command line.

This commit makes optional the creation of mixed block groups i.e. Mixed block
groups are created only when -M option is specified on the command line.

Since we now allow small filesystem instances with sectorsize != nodesize to
be created, we can end up in the following situation,

[root@localhost ~]# mkfs.btrfs -f -n 65536 /dev/loop0
btrfs-progs v3.19-rc2-405-g976307c
See http://btrfs.wiki.kernel.org for more information.

Performing full device TRIM (512.00MiB) ...
Label:              (null)
UUID:               49fab72e-0c8b-466b-a3ca-d1bfe56475f0
Node size:          65536
Sector size:        4096
Filesystem size:    512.00MiB
Block group profiles:
  Data:             single            8.00MiB
  Metadata:         DUP              40.00MiB
  System:           DUP              12.00MiB
SSD detected:       no
Incompat features:  extref, skinny-metadata
Number of devices:  1
Devices:
   ID        SIZE  PATH
    1   512.00MiB  /dev/loop0
[root@localhost ~]# mount /dev/loop0 /mnt/
mount: mount /dev/loop0 on /mnt failed: No space left on device

The ENOSPC occurs during the creation of the UUID tree. This is because of
things like large metadata block size, DUP mode used for metadata and global
reservation consuming space. Also, large nodesize does not make sense on small
filesystems, hence this should not be an issue.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add helpers to print ranges
David Sterba [Mon, 19 Oct 2015 14:31:14 +0000 (16:31 +0200)]
btrfs-progs: add helpers to print ranges

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add helpers for parsing 32bit ranges
David Sterba [Tue, 13 Oct 2015 14:34:33 +0000 (16:34 +0200)]
btrfs-progs: add helpers for parsing 32bit ranges

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: extend parse_range API to accept a relaxed range
David Sterba [Sun, 11 Oct 2015 22:29:31 +0000 (00:29 +0200)]
btrfs-progs: extend parse_range API to accept a relaxed range

In some cases we want to accept a range of type [a..a]. Add a new
function to do the 'a < b' check for the caller and use it.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: do not modify the string in parse_range
David Sterba [Fri, 16 Oct 2015 12:51:20 +0000 (14:51 +0200)]
btrfs-progs: do not modify the string in parse_range

It's passed as const but we modify it through 'dots'. This would break
parsing the string multiple times.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cleanup and comment parse_range
David Sterba [Sun, 11 Oct 2015 22:16:18 +0000 (00:16 +0200)]
btrfs-progs: cleanup and comment parse_range

Simplify a check and unindent some code.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: device add: cleanup argument handling
Anand Jain [Sat, 10 Oct 2015 14:30:57 +0000 (22:30 +0800)]
btrfs-progs: device add: cleanup argument handling

This is needed by the patch which introduces new devid option for the
btrfs device delete.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: move is_numerical() helper to utils and rename
Anand Jain [Sat, 10 Oct 2015 14:30:56 +0000 (22:30 +0800)]
btrfs-progs: move is_numerical() helper to utils and rename

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ moved to util.c and renamed ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: return -ENOMEM properly in btrfs_read_block_groups()
Eryu Guan [Mon, 19 Oct 2015 11:38:00 +0000 (19:38 +0800)]
btrfs-progs: return -ENOMEM properly in btrfs_read_block_groups()

Breaking from the while loop makes ret overwritten to zero, goto error
label directly and return -ENOMEM.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix memory leak in cmd_qgroup_show()
Eryu Guan [Mon, 19 Oct 2015 11:37:59 +0000 (19:37 +0800)]
btrfs-progs: fix memory leak in cmd_qgroup_show()

filter_set and comparer_set should be freed on return.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: remove identical branch in record_extent()
Eryu Guan [Mon, 19 Oct 2015 11:37:58 +0000 (19:37 +0800)]
btrfs-progs: remove identical branch in record_extent()

The same code is executed when the condition "ret" is true or false,
because the code in the if-then branch and after the if statement is
identical.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix memory leak on error path
Eryu Guan [Mon, 19 Oct 2015 11:37:57 +0000 (19:37 +0800)]
btrfs-progs: fix memory leak on error path

dev_scans and t_scans should be freed on malloc error.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: save and return error number correctly in check_chunks_and_extents
Eryu Guan [Mon, 19 Oct 2015 11:37:51 +0000 (19:37 +0800)]
btrfs-progs: save and return error number correctly in check_chunks_and_extents

The variable "err" is assigned to "ret" then "ret" gets overwritten by
check_extent_refs() before "ret" can be used. Reported by Coverity.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix leak of "path" in btrfs_find_item() error paths
Eryu Guan [Mon, 19 Oct 2015 11:37:50 +0000 (19:37 +0800)]
btrfs-progs: fix leak of "path" in btrfs_find_item() error paths

path needs to be freed before return.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fragments: use btrfs_open_dir for btrfs-fragments command
Zhao Lei [Mon, 12 Oct 2015 13:23:04 +0000 (21:23 +0800)]
btrfs-progs: fragments: use btrfs_open_dir for btrfs-fragments command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
deeper code, and return fuzzy error message.

Before patch:
  ./btrfs-fragments -o 123 /mnt/tmp1
  ERROR: can't perform the search

After patch:
  # ./btrfs-fragments -o 123 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: replace: use btrfs_open_dir for btrfs replace command
Zhao Lei [Mon, 12 Oct 2015 13:23:03 +0000 (21:23 +0800)]
btrfs-progs: replace: use btrfs_open_dir for btrfs replace command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # ./btrfs replace cancel /mnt/tmp1
  ERROR: ioctl(DEV_REPLACE_CANCEL) failed on "/mnt/tmp1": Inappropriate ioctl for device
  # ./btrfs replace status /mnt/tmp1
  ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device

After patch:
  # ./btrfs replace cancel /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs replace status /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use btrfs_open_dir in open_path_or_dev_mnt
Zhao Lei [Mon, 12 Oct 2015 13:23:02 +0000 (21:23 +0800)]
btrfs-progs: use btrfs_open_dir in open_path_or_dev_mnt

Use btrfs_open_dir() in open_path_or_dev_mnt() to make the function
return error when target is neither block device nor btrfs mount point.

Also add "verbose" argument to let function output common error
message instead of putting duplicated lines in caller.

Before patch:
  # ./btrfs device stats /mnt/tmp1
  ERROR: getting dev info for devstats failed: Inappropriate ioctl for device
  # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1
  ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device

After patch:
  # ./btrfs device stats /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs replace start /dev/vdd /dev/vde /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: quota: use btrfs_open_dir for btrfs quota command
Zhao Lei [Mon, 12 Oct 2015 13:23:01 +0000 (21:23 +0800)]
btrfs-progs: quota: use btrfs_open_dir for btrfs quota command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # ./btrfs quota enable /mnt/tmp1
  ERROR: quota command failed: Inappropriate ioctl for device
  # ./btrfs quota disable /mnt/tmp1
  ERROR: quota command failed: Inappropriate ioctl for device
  # ./btrfs quota rescan /mnt/tmp1
  ERROR: quota rescan failed: Inappropriate ioctl for device
  #

After patch:
  # ./btrfs quota enable /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs quota disable /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs quota rescan /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  #

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: qgroup: use btrfs_open_dir for btrfs qgroup command
Zhao Lei [Mon, 12 Oct 2015 13:23:00 +0000 (21:23 +0800)]
btrfs-progs: qgroup: use btrfs_open_dir for btrfs qgroup command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # ./btrfs qgroup create 1/5  /mnt/tmp1
  ERROR: unable to create quota group: Inappropriate ioctl for device
  #
  # ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
  ERROR: unable to assign quota group: Inappropriate ioctl for device
  #
  # ./btrfs qgroup show /mnt/tmp1
  ERROR: can't perform the search - Inappropriate ioctl for device
  ERROR: can't list qgroups: Inappropriate ioctl for device
  #
  # ./btrfs qgroup limit 1G 1/5  /mnt/tmp1
  ERROR: unable to limit requested quota group: Inappropriate ioctl for device

After patch:
  # ./btrfs qgroup create 1/5 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs qgroup assign 1/5 2/5 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs qgroup show /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs qgroup limit 1G 1/5 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: inspect: use btrfs_open_dir for btrfs inspect command
Zhao Lei [Mon, 12 Oct 2015 13:22:59 +0000 (21:22 +0800)]
btrfs-progs: inspect: use btrfs_open_dir for btrfs inspect command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # ./btrfs inspect-internal rootid /mnt/tmp1
  ERROR: Failed to lookup root id - Inappropriate ioctl for device
  btrfs inspect-internal rootid: rootid failed with ret=-1
  # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1
  ioctl ret=-1, error: Inappropriate ioctl for device
  # ./btrfs inspect-internal min-dev-size /mnt/tmp1
  Error invoking tree search ioctl: Inappropriate ioctl for device

After patch:
  # ./btrfs inspect-internal rootid /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs inspect-internal inode-resolve 256 /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs inspect-internal min-dev-size /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: inspect: set return value of error case
Zhao Lei [Mon, 12 Oct 2015 13:22:58 +0000 (21:22 +0800)]
btrfs-progs: inspect: set return value of error case

In case of open_file_or_dir() failed, ret is not set to right value,
and the function will return unwanted value(ret of sprintf).

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: inspect: Bypass unnecessary clean function in open_error
Zhao Lei [Mon, 12 Oct 2015 13:22:57 +0000 (21:22 +0800)]
btrfs-progs: inspect: Bypass unnecessary clean function in open_error

No need to cleanup fd in open_fail case, because it is not opened.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: balance: use btrfs_open_dir for btrfs balance command
Zhao Lei [Mon, 12 Oct 2015 13:22:56 +0000 (21:22 +0800)]
btrfs-progs: balance: use btrfs_open_dir for btrfs balance command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # btrfs balance start /mnt/tmp
  ERROR: error during balancing '/mnt/tmp' - Inappropriate ioctl for device
  There may be more info in syslog - try dmesg | tail
  #

After patch:
  # btrfs balance start /mnt/tmp
  ERROR: not btrfs filesystem: /mnt/tmp
  #

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: filesystem: use btrfs_open_dir for btrfs filesystem command
Zhao Lei [Mon, 12 Oct 2015 13:22:55 +0000 (21:22 +0800)]
btrfs-progs: filesystem: use btrfs_open_dir for btrfs filesystem command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # (/mnt/tmp is not btrfs mountpoint)
  #
  # btrfs filesystem df /mnt/tmp
  ERROR: couldn't get space info - Inappropriate ioctl for device
  ERROR: get_df failed Inappropriate ioctl for device
  #

After patch:
  # ./btrfs filesystem df /mnt/tmp
  ERROR: not btrfs filesystem: /mnt/tmp
  #

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: subvolume: use btrfs_open_dir for btrfs subvolume command
Zhao Lei [Mon, 12 Oct 2015 13:22:54 +0000 (21:22 +0800)]
btrfs-progs: subvolume: use btrfs_open_dir for btrfs subvolume command

We can use btrfs_open_dir() to check whether target dir is
in btrfs's mount point before open, instead of checking it in
kernel space of ioctl, and return fuzzy error message.

Before patch:
  # (/mnt/tmp is not btrfs mountpoint)
  #
  # btrfs subvolume create /mnt/tmp/123
  Create subvolume '/mnt/tmp/123'
  ERROR: cannot create subvolume - Inappropriate ioctl for device
  #

After patch:
  # btrfs subvolume create /mnt/tmp/123
  ERROR: not btrfs filesystem: /mnt/tmp
  #

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: print root item's last_snapshot value
Lakshmipathi.G [Wed, 7 Oct 2015 12:06:38 +0000 (17:36 +0530)]
btrfs-progs: print root item's last_snapshot value

Include last_snapshot value in print_root(). With btrfs-debug-tree, it
helps to identify whether its a snapshot-ed subvolume or not.

Signed-off-by: Lakshmipathi.G <Lakshmipathi.G@giis.co.in>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: add html build target
David Sterba [Wed, 7 Oct 2015 12:36:34 +0000 (14:36 +0200)]
btrfs-progs: docs: add html build target

We can easily build the documentation in html format:

 $ make html

in the Documentation directory.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: build: make support for static checkers more generic
David Sterba [Wed, 7 Oct 2015 10:52:52 +0000 (12:52 +0200)]
btrfs-progs: build: make support for static checkers more generic

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: check: update help text
David Sterba [Tue, 6 Oct 2015 14:50:08 +0000 (16:50 +0200)]
btrfs-progs: check: update help text

Add some missing options and add a high-level description.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: a bit of makefile documentation
David Sterba [Tue, 6 Oct 2015 12:53:55 +0000 (14:53 +0200)]
btrfs-progs: a bit of makefile documentation

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: build: allow to build with various compiler warnings
David Sterba [Tue, 6 Oct 2015 12:40:07 +0000 (14:40 +0200)]
btrfs-progs: build: allow to build with various compiler warnings

Copied from linux kernel, 'make W=1' will build with various additional
warnings turned on. There are 3 levels, combinations are possible. The
build is quite noisy, not all warnings need to be fixed.

A specific warning can be turned on by 'make EXTRA_CFLAGS=-Wsomething'.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: print commands on terminal if requested
David Sterba [Tue, 6 Oct 2015 12:16:39 +0000 (14:16 +0200)]
btrfs-progs: tests: print commands on terminal if requested

Set the variable TEST_LOG=tty (in the enviroment or as parameter to
make) to print commands executed by 'run_check' helpers to terminal (ie.
/dev/tty). This might be useful to see the test progress beside watching
the results file.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: misc tests: add 009-subvolume-sync-must-wait
David Sterba [Tue, 6 Oct 2015 11:11:09 +0000 (13:11 +0200)]
btrfs-progs: misc tests: add 009-subvolume-sync-must-wait

Test to verify that subovolume sync waits until the subvolume is
cleaned.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use calloc instead of malloc+memset
Silvio Fricke [Tue, 29 Sep 2015 17:10:36 +0000 (19:10 +0200)]
btrfs-progs: use calloc instead of malloc+memset

This patch is generated from a coccinelle semantic patch:

identifier t;
expression e;
statement s;
@@
-t = malloc(e);
+t = calloc(1, e);
(
if (!t) s
|
if (t == NULL) s
|
)
-memset(t, 0, e);

Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
[squashed patches into one]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: use common warning/error for cmds-scrub.c
Zhao Lei [Mon, 28 Sep 2015 13:58:14 +0000 (21:58 +0800)]
btrfs-progs: use common warning/error for cmds-scrub.c

Use common warning/error functions in cmds-scrub.c, it can make
message format unified and make code simple.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[removed ending newlines from messages]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Introduce warning and error for common use
Zhao Lei [Mon, 28 Sep 2015 13:58:13 +0000 (21:58 +0800)]
btrfs-progs: Introduce warning and error for common use

Current code use fprintf(stderr, "...") to output warnning and
error information.

The error message have different style, as:
 # grep fprintf *.c
 fprintf(stderr, "Open ctree failed\n");
 fprintf(stderr, "%s: open ctree failed\n", __func__);
 fprintf(stderr, "ERROR: cannot open ctree\n");
 ...

And sometimes, we forgot add tailed '\n', or use printf instead,
as in current code:
 printf("warning, device %llu is missing\n",

This patch introduce warning() and error() as common function,
to make:
1: Each warning and error information have same format
2: Easy to search/change all error message
3: Easy to modify function's internal for debug or other requirement,
   for example:
   print function/linenumber in error()
   dumpstack in error()
   add some trace for some style of message
   add support for -v, -vv, ...
   support for locales
   custom output functions
   support some special device/tty

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[print newline after the message]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: check: add progress indicator
Silvio Fricke [Thu, 24 Sep 2015 06:13:05 +0000 (08:13 +0200)]
btrfs-progs: check: add progress indicator

Signed-off-by: Silvio Fricke <silvio.fricke@gmail.com>
[minor updates]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add more superblock validation checks
Qu Wenruo [Wed, 13 May 2015 09:15:35 +0000 (17:15 +0800)]
btrfs-progs: add more superblock validation checks

Now btrfs-progs will have much more strict superblock checks based on
kernel superblock checks.

This should prevent crashes or invalid memory access on crafted or
fuzzed images.

Based on kernel commit c926093ec516f5d316ecdf8c1be11f577ac71b85 .

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[added reference to kernel and comments]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Read the whole superblock instead of struct btrfs_super_block
Qu Wenruo [Wed, 13 May 2015 09:15:34 +0000 (17:15 +0800)]
btrfs-progs: Read the whole superblock instead of struct btrfs_super_block

Before the patch, btrfs-progs will only read sizeof(struct
btrfs_super_block) and restore it into super_copy.

This makes checksum check for superblock impossible.  Change it to read
the whole superblock.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: enhance error message with status from kernel and errno
Zhao Lei [Thu, 6 Aug 2015 03:05:55 +0000 (11:05 +0800)]
btrfs-progs: enhance error message with status from kernel and errno

Scrub output prints the following error message in my test:
  ERROR: scrubbing /var/ltf/tester/scratch_mnt failed for device id 5 (Success)

It is caused by a broken kernel and fs, but the we need to avoid
printing both "error and success" on one line as above.

This patch modified above message to:
  ERROR: scrubbing /var/ltf/tester/scratch_mnt failed for device id 5: ret=1, errno=0 (Success)

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
[minor updates in formatting]
Signed-off-by: David Sterba <dsterba@suse.com>