platform/upstream/btrfs-progs.git
8 years agobtrfs-progs: mkfs: allow DUP on multidev fs, only warn
David Sterba [Wed, 16 Mar 2016 17:08:33 +0000 (18:08 +0100)]
btrfs-progs: mkfs: allow DUP on multidev fs, only warn

The DUP profile can work on multiple filesystems, the limitation is
rather artificial. Let the user make the decision and print a warning.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: make error message from add_clone_source more generic
David Sterba [Thu, 24 Mar 2016 14:26:05 +0000 (15:26 +0100)]
btrfs-progs: make error message from add_clone_source more generic

Do not hardcode the error message.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: send: fix handling of multiple snapshots
Tsutomu Itoh [Thu, 24 Mar 2016 07:47:28 +0000 (16:47 +0900)]
btrfs-progs: send: fix handling of multiple snapshots

We cannot send multiple snapshots at once.

[before fix]
# btrfs send ./snap[12] > snap12.data
At subvol ./snap1
At subvol ./snap2
ERROR: parent determination failed for 0
#

[after fix]
# btrfs send ./snap[12] > snap12.data
At subvol ./snap1
At subvol ./snap2
#

Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add misc 014-filesystem-label
David Sterba [Tue, 22 Mar 2016 18:01:39 +0000 (19:01 +0100)]
btrfs-progs: tests: add misc 014-filesystem-label

Test various label lengths on a mounted filesystem.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: introduce mustfail helper
David Sterba [Tue, 22 Mar 2016 17:47:18 +0000 (18:47 +0100)]
btrfs-progs: tests: introduce mustfail helper

Invalid syntax, expected failure on corrupted data etc. Failure is
success.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix build of standalone utilities after clean
David Sterba [Tue, 22 Mar 2016 17:29:24 +0000 (18:29 +0100)]
btrfs-progs: fix build of standalone utilities after clean

$ make clean
$ make btrfs-debug-tree

will fail because the dependency from $(btrfs_debug_tree_objects) is
missing. The variable standalone_deps magically collects all the deps
and will build them in advance. The simple fix to use the existing
substitution based on $@ does not work for pattern rules, as Noah found
out.

Reported-by: Noah Massey <noah.massey@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: cleanup block group helpers types
David Sterba [Tue, 22 Mar 2016 16:01:20 +0000 (17:01 +0100)]
btrfs-progs: cleanup block group helpers types

Use const char and remove stray prototypes.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: utils: make more arguments const
David Sterba [Tue, 22 Mar 2016 15:56:33 +0000 (16:56 +0100)]
btrfs-progs: utils: make more arguments const

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: rename get_subvol_name() to subvol_strip_mountpoint()
Anand Jain [Mon, 21 Mar 2016 07:21:05 +0000 (15:21 +0800)]
btrfs-progs: rename get_subvol_name() to subvol_strip_mountpoint()

Signed-off-by: Anand Jain <anand.jain@oracle.com>
[ renamed from subvol_minus_mnt to subvol_strip_mountpoint ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: create get_subvol_info()
Anand Jain [Mon, 21 Mar 2016 07:21:04 +0000 (15:21 +0800)]
btrfs-progs: create get_subvol_info()

get_subvol_info() is useful as we are adding more features around
subvolume. This function was inline with the function
cmd_subvol_show().

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: move get_subvol_name() to utils.c
Anand Jain [Mon, 21 Mar 2016 07:21:03 +0000 (15:21 +0800)]
btrfs-progs: move get_subvol_name() to utils.c

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: remove duplicate function __is_subvol()
Anand Jain [Mon, 21 Mar 2016 07:21:02 +0000 (15:21 +0800)]
btrfs-progs: remove duplicate function __is_subvol()

The function test_issubvolume() provides the same check, and
has better logic.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: move test_issubvolume() to utils.c
Anand Jain [Mon, 21 Mar 2016 07:21:01 +0000 (15:21 +0800)]
btrfs-progs: move test_issubvolume() to utils.c

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: rearrange subvolume functions together
Anand Jain [Mon, 21 Mar 2016 07:21:00 +0000 (15:21 +0800)]
btrfs-progs: rearrange subvolume functions together

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: utils: make sure set_label_mounted uses correct length buffers
Petros Angelatos [Tue, 22 Mar 2016 10:40:29 +0000 (03:40 -0700)]
btrfs-progs: utils: make sure set_label_mounted uses correct length buffers

When `btrfs filesystem label /foo bar` command is invoked, it will pass
the buffer allocated in the argv array directly to set_label_mounted()
and then to the BTRFS_IOC_SET_FSLABEL ioctl.

However, the kernel code handling the ioctl will always try to copy
BTRFS_LABEL_SIZE bytes[1] from the userland pointer. Under certain
conditions and when the label is small enough, the command will fail
with:

    [root@localhost /]# btrfs filesystem label /mnt f
    ERROR: unable to set label Bad address

Fix this by making sure we pass a BTRFS_LABEL_SIZE sized buffer to the
ioctl containing the desired label.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/fs/btrfs/ioctl.c?id=refs/tags/v4.5#n5231

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fragments: fix build
David Sterba [Tue, 22 Mar 2016 15:06:31 +0000 (16:06 +0100)]
btrfs-progs: fragments: fix build

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix fi du so it works in more cases
Austin S. Hemmelgarn [Mon, 21 Mar 2016 12:23:11 +0000 (08:23 -0400)]
btrfs-progs: fix fi du so it works in more cases

Currently, btrfs fi du uses open_file_or_dir(), which tries to open
it's argument with O_RDWR.  Because of POSIX semantics, this fails for
non-root users when the file is read-only or is an executable that
is being run currently, or for all users (including root) when the
filesystem is read-only.  This results in a somewhat confusing 'Unknown
error -1' message when trying to check such files.  Switch to using
open_file_or_dir3() with O_RDONLY passed in the flags, as this avoids
the limitations listed above, and we have no need to write to the files
anyway (and thus shouldn't be opening them writable).

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: build: fix static standalone utilities
Noah Massey [Mon, 21 Mar 2016 14:16:07 +0000 (10:16 -0400)]
btrfs-progs: build: fix static standalone utilities

commit b5e7979 "btrfs-progs: build: extend per-binary objects" allows
the standalone utilities to link against object files shared with the
main binary. However, the btrfs-*.static targets need to be adjusted
to build against the static versions of the common files.

Signed-off-by: Noah Massey <noah.massey@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs progs v4.5
David Sterba [Sun, 20 Mar 2016 22:59:05 +0000 (23:59 +0100)]
Btrfs progs v4.5

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: enumerate RWX in convert tests
David Sterba [Fri, 18 Mar 2016 16:11:25 +0000 (17:11 +0100)]
btrfs-progs: tests: enumerate RWX in convert tests

Generating all valid combinations takes too much time.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: populate fs with small dataset for convert tests
Lakshmipathi.G [Tue, 8 Mar 2016 15:00:06 +0000 (20:30 +0530)]
btrfs-progs: tests: populate fs with small dataset for convert tests

Signed-off-by: Lakshmipathi.G <Lakshmipathi.G@giis.co.in>
[ minor tweaks ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: switch to common message helpers in open_ctree_fs_info
David Sterba [Fri, 18 Mar 2016 15:34:33 +0000 (16:34 +0100)]
btrfs-progs: switch to common message helpers in open_ctree_fs_info

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: handle stat errors in open_ctree_fs_info
David Sterba [Fri, 18 Mar 2016 15:07:09 +0000 (16:07 +0100)]
btrfs-progs: handle stat errors in open_ctree_fs_info

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add stat check in open_ctree_fs_info
Austin S. Hemmelgarn [Fri, 18 Mar 2016 14:03:42 +0000 (10:03 -0400)]
btrfs-progs: add stat check in open_ctree_fs_info

Currently, open_ctree_fs_info will open whatever path you pass it and try
to interpret it as a BTRFS filesystem.  While this is not nessecarily
dangerous (except possibly if done on a character device), it does
result in some rather cryptic and non-sensical error messages when
trying to run certain commands in ways they weren't intended to be run.
Add a check using stat(2) to verify that the path we've been passed is
in fact a regular file or a block device, or a symlink pointing to a
regular file or block device.

This causes the following commands to provide a helpful error message
when run on a FIFO, directory, character device, or socket:
    * btrfs check
    * btrfs restore
    * btrfs-image
    * btrfs-find-root
    * btrfs inspect-internal dump-tree

stat(2) is used instead of lstat(2), as stat(2) follows symlinks just
like open(2) does, which means we check the same inode that open(2)
opens, and thus don't need special handling for symlinks.

Signed-off-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi du: fix incorrect column order
Alexander Fougner [Fri, 18 Mar 2016 11:08:24 +0000 (12:08 +0100)]
btrfs-progs: fi du: fix incorrect column order

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: qgroup assign: handle --no-rescan option
Satoru Takeuchi [Fri, 18 Mar 2016 01:36:29 +0000 (10:36 +0900)]
btrfs-progs: qgroup assign: handle --no-rescan option

* actual result

   ==================================================
   # btrfs qgroup assign --no-rescan 0/260 1/261 /btrfs
   btrfs qgroup assign: unrecognized option '--no-rescan'
   usage: btrfs qgroup assign [options] <src> <dst> <path>

       Assign SRC as the child qgroup of DST

       --rescan       schedule qutoa rescan if needed
       --no-rescan

   ==================================================

* expected result

   ==================================================
   # ./btrfs qgroup assign --no-rescan 0/260 1/261 /btrfs
   #
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: qgroup assign: can't handle options
Satoru Takeuchi [Fri, 18 Mar 2016 01:35:15 +0000 (10:35 +0900)]
btrfs-progs: qgroup assign: can't handle options

"qgroup assign" is considered as working without any options
from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

However, we can pass options to this command.

* actual result

   ==================================================
   # ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
   btrfs qgroup assign: unrecognized option '--rescan'
   usage: btrfs qgroup assign [options] <src> <dst> <path>

       Assign SRC as the child qgroup of DST

       --rescan       schedule qutoa rescan if needed
       --no-rescan

   ==================================================

* expected result

   ==================================================
   # ./btrfs qgroup assign --rescan 0/260 1/261 /btrfs
   #
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: inspect subvolid-resolve: fix argument parsing
Satoru Takeuchi [Fri, 18 Mar 2016 01:31:32 +0000 (10:31 +0900)]
btrfs-progs: inspect subvolid-resolve: fix argument parsing

"inspect-internal subvolid-resolve" doesn't work from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

It's because 1st argument, subvolid, is also used for the pathname of
filesystem. 2nd argument should be used for this purpose instead.

* actual result

   ==================================================
   # ./btrfs inspect-internal subvolid-resolve 260 /btrfs
   ERROR: cannot access '260': No such file or directory
   ==================================================

* expected result

   ==================================================
   # btrfs inspect-internal subvolid-resolve 260 /btrfs
   snap
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: qgroup create/destroy: fix argument parsing
Satoru Takeuchi [Fri, 18 Mar 2016 01:29:50 +0000 (10:29 +0900)]
btrfs-progs: qgroup create/destroy: fix argument parsing

"qgroup create/destroy" don't work from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

* actual result

   ==================================================
   # ./btrfs qgroup create 1 /btrfs/sub
   btrfs qgroup create: too few arguments
   usage: btrfs qgroup create <qgroupid> <path>

       Create a subvolume quota group.
   ==================================================
   # btrfs qgroup create 1 /btrfs/sub
   # ./btrfs qgroup destroy 1 /btrfs/sub
   btrfs qgroup destroy: too few arguments
   usage: btrfs qgroup destroy <qgroupid> <path>

       Destroy a quota group.

   ==================================================

* expected result

   ==================================================
   # btrfs qgroup create 1 /btrfs/sub
   # btrfs qgroup destroy 1 /btrfs/sub/
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: subvol get-default: fix argument parsing
Satoru Takeuchi [Fri, 18 Mar 2016 01:26:15 +0000 (10:26 +0900)]
btrfs-progs: subvol get-default: fix argument parsing

"sub get-default" does't work since the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

* actual result

   ==================================================
   # ./btrfs sub get-default /btrfs
   btrfs subvolume get-default: too few arguments
   usage: btrfs subvolume get-default <path>

       Get the default subvolume of a filesystem
   ==================================================

* expected result

   ==================================================
   # btrfs sub get-default /btrfs
   ID 5 (FS_TREE)
   ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: man5, add space_cache=v2
David Sterba [Thu, 17 Mar 2016 13:49:32 +0000 (14:49 +0100)]
btrfs-progs: docs: man5, add space_cache=v2

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add 013-subvolume-sync-crash
David Sterba [Thu, 17 Mar 2016 13:22:24 +0000 (14:22 +0100)]
btrfs-progs: tests: add 013-subvolume-sync-crash

Test for "btrfs-progs: subvol sync: fix memory corruption, undersized
array", a lot of deleted subvolumes in the 'subvol sync' will not fit
into the array, should result in a glibc report.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: subvol sync: fix memory corruption, undersized array
David Sterba [Thu, 17 Mar 2016 10:41:18 +0000 (11:41 +0100)]
btrfs-progs: subvol sync: fix memory corruption, undersized array

The subvol sync command crashed randomly at the end with

*** glibc detected *** btrfs: double free or corruption (out): 0x00000000006ab040 ***

This is caused by running out of the ids array in case there are more
than 128 subvolumes. The array is increased in steps but does not
account the size of the item, so there was room for 1024 / 8 = 128
subvolume ids.

Fixes: c9f885ec8963 ("btrfs-progs: subvol: let sync check only current deletions")
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs progs v4.5-rc1
David Sterba [Wed, 16 Mar 2016 18:07:12 +0000 (19:07 +0100)]
Btrfs progs v4.5-rc1

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: fi defrag, make some paragraphs more visible
David Sterba [Wed, 16 Mar 2016 18:03:05 +0000 (19:03 +0100)]
btrfs-progs: docs: fi defrag, make some paragraphs more visible

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: mkfs: also parse raid0 profile case-insensitive
David Sterba [Wed, 16 Mar 2016 16:41:16 +0000 (17:41 +0100)]
btrfs-progs: mkfs: also parse raid0 profile case-insensitive

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: btrfs-debugfs: fetch block group information
Liu Bo [Mon, 11 Jan 2016 20:10:22 +0000 (12:10 -0800)]
btrfs-progs: btrfs-debugfs: fetch block group information

This aims to decide whether a balance can reduce the number of
data block groups and if it is, this shows the '-dvrange' block
group's objectid.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix a regression that "property" with -t option doesn't work
Satoru Takeuchi [Wed, 16 Mar 2016 02:11:07 +0000 (11:11 +0900)]
btrfs-progs: fix a regression that "property" with -t option doesn't work

"property" is considered as working without any options
from the following commit.

commit 176aeca9a148 ("btrfs-progs: add getopt stubs where needed")

However, we can pass -t option to this command.

* actual result

  ==================================================
  $ ./btrfs prop list -t f /btrfs
  btrfs property list: invalid option -- 't'
  usage: btrfs property list [-t <type>] <object>

      Lists available properties with their descriptions for the given object.

      Please see the help of 'btrfs property get' for a description of
      objects and object types.

  ==================================================

* expected result

  ==================================================
  $ ./btrfs prop list -t f /btrfs
  label               Set/get label of device.
  ==================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Describe optarg of -m option in the manpage of receive
Satoru Takeuchi [Wed, 16 Mar 2016 02:01:11 +0000 (11:01 +0900)]
btrfs-progs: Describe optarg of -m option in the manpage of receive

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi du: make the output more aligned
David Sterba [Tue, 15 Mar 2016 18:00:57 +0000 (19:00 +0100)]
btrfs-progs: fi du: make the output more aligned

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi du: update help text
David Sterba [Tue, 15 Mar 2016 16:58:23 +0000 (17:58 +0100)]
btrfs-progs: fi du: update help text

Move the command-specific options to the beginning, add missing long
option.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: add filesystem du
David Sterba [Tue, 15 Mar 2016 16:56:36 +0000 (17:56 +0100)]
btrfs-progs: docs: add filesystem du

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: remove btrfs-show-super manual page and point to inspect-internal
David Sterba [Thu, 10 Mar 2016 15:51:53 +0000 (16:51 +0100)]
btrfs-progs: remove btrfs-show-super manual page and point to inspect-internal

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: update dump-super
David Sterba [Tue, 15 Mar 2016 16:16:00 +0000 (17:16 +0100)]
btrfs-progs: docs: update dump-super

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: rename and move dump-super
David Sterba [Tue, 15 Mar 2016 15:44:55 +0000 (16:44 +0100)]
btrfs-progs: docs: rename and move dump-super

The command name is 'dump-super', move the section to it's alphabetical
order.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: dump-super: add more long options
David Sterba [Tue, 15 Mar 2016 15:32:26 +0000 (16:32 +0100)]
btrfs-progs: dump-super: add more long options

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: dump-super: switch to getopt_long
David Sterba [Tue, 15 Mar 2016 15:31:58 +0000 (16:31 +0100)]
btrfs-progs: dump-super: switch to getopt_long

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix resource leak during device scanning
David Sterba [Tue, 15 Mar 2016 09:25:00 +0000 (10:25 +0100)]
btrfs-progs: fix resource leak during device scanning

The dev info is leaked each time we find a known filesystem.

Resolves-coverity-id: 1127098
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: utils: switch more error messages to common helpers
David Sterba [Mon, 14 Mar 2016 13:36:30 +0000 (14:36 +0100)]
btrfs-progs: utils: switch more error messages to common helpers

Functions relatd to device changes/status/open, mount checks.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: improve error messages after failed wiping
David Sterba [Mon, 14 Mar 2016 13:18:32 +0000 (14:18 +0100)]
btrfs-progs: improve error messages after failed wiping

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Introduce device delete by devid
Anand Jain [Mon, 14 Mar 2016 08:31:49 +0000 (16:31 +0800)]
btrfs-progs: Introduce device delete by devid

This patch introduces new option <devid> for the command

  btrfs device delete <device_path|devid>[..]  <mnt>

In a user reported issue on a 3-disk-RAID1, one disk failed with its
SB unreadable. Now with this patch user will have a choice to delete
the device using devid.

The other method we could do, is to match the input device_path
to the available device_paths with in the kernel. But that won't
work in all the cases, like what if user provided mapper path
when the path within the kernel is a non-mapper path.

This patch depends on the below kernel patch for the new feature to work,
however it will fail-back to the old interface for the kernel without the
patch

  Btrfs: Introduce device delete by devid

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: fix more typos and spelling errors
David Sterba [Mon, 14 Mar 2016 13:10:16 +0000 (14:10 +0100)]
btrfs-progs: docs: fix more typos and spelling errors

With help of ispell.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: fix spelling errors
Alexander Fougner [Sun, 13 Mar 2016 13:24:08 +0000 (14:24 +0100)]
btrfs-progs: docs: fix spelling errors

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Avoid interpreting options after "--" when getting unit mode
Satoru Takeuchi [Mon, 14 Mar 2016 00:02:34 +0000 (09:02 +0900)]
btrfs-progs: Avoid interpreting options after "--" when getting unit mode

* actual result

  ======================================
  # ./btrfs device usage -- -m /btrfs

  /dev/sdf1, ID: 1
     Device size:          95367.41MiB
     Data,single:          2056.00MiB
     Metadata,DUP:         2048.00MiB
     System,DUP:             16.00MiB
     Unallocated:          91247.41MiB
  ======================================

* expected result

  ======================================
  # ./btrfs device usage -- -m /btrfs

  ERROR: can't access '-m': No such file or directory
  ======================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Fix a regression that btrfs filesystem label doesn't work
Satoru Takeuchi [Mon, 14 Mar 2016 00:15:42 +0000 (09:15 +0900)]
btrfs-progs: Fix a regression that btrfs filesystem label doesn't work

The number of arguments which is allowed to pass became wrong
from the following commit.

commit 176aeca9a148c5e29de0 ("btrfs-progs: add getopt stubs where needed")

* actual result

  ===========================================================
  # ./btrfs prop get /btrfs label
  label=foo
  # ./btrfs fi label /btrfs
  btrfs filesystem label: too few arguments
  usage: btrfs filesystem label [<device>|<mount_point>] [<newlabel>]

      Get or change the label of a filesystem

      With one argument, get the label of filesystem on <device>.
      If <newlabel> is passed, set the filesystem label to <newlabel>.

  # ./btrfs fi label /btrfs bar
  foo
  # ./btrfs prop get /btrfs label
  label=foo
  ===========================================================

* expected result

  ===========================================================
  # ./btrfs prop get /btrfs label
  label=foo
  # ./btrfs fi label /btrfs
  foo
  # ./btrfs fi label /btrfs bar
  # ./btrfs prop get /btrfs label
  label=bar
  ===========================================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: print-tree: show the compression method string
Wang Xiaoguang [Fri, 11 Mar 2016 05:09:02 +0000 (13:09 +0800)]
btrfs-progs: print-tree: show the compression method string

Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
[ changed the format of unknown value ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Fix device scan to interpret its argument properly
Satoru Takeuchi [Fri, 11 Mar 2016 00:26:13 +0000 (09:26 +0900)]
btrfs-progs: Fix device scan to interpret its argument properly

Fix the following bug.

  ================================
  # btrfs device scan -- /dev/sdb
  ERROR: not a block device: --
  ================================

It should work as follow.

  ================================
  # ./btrfs device scan -- /dev/sdb
  Scanning for Btrfs filesystems in '/dev/sdb'
  ================================

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Dont' stop scanning of devices at first failed device
Yauhen Kharuzhy [Fri, 11 Mar 2016 00:04:35 +0000 (16:04 -0800)]
btrfs-progs: Dont' stop scanning of devices at first failed device

When 'btrfs device scan' command is invoked, it scans all devices,
check them for btrfs superblock and add devices with btrfs to a list.

Next, each device from the list is passed to kernel where it is handled
in the btrfs_scan_one_device() function. This function can, for example,
return -EBUSY when device contains superblock matched to existing and
mounted filesystem (if this device was pulled out from RAID and
connected again after some time).

btrfs tool stops device scan if any device has been failed to add, so
other existing devices with (possibly) valid FS will never be reached.

Fix this by remove stopping at any failure in the btrfs_register_all_devices(),
just return error count. btrfs_scan_one_device() reports any kind of
error already.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
[ initialize err to 0 ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: remove btrfs-debug-tree manual page and point to inspect-internal
David Sterba [Thu, 10 Mar 2016 15:51:53 +0000 (16:51 +0100)]
btrfs-progs: remove btrfs-debug-tree manual page and point to inspect-internal

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: dump-tree: let --tree understand name of the tree
David Sterba [Thu, 10 Mar 2016 14:57:46 +0000 (15:57 +0100)]
btrfs-progs: dump-tree: let --tree understand name of the tree

For practical purposes teach -t about the human readable names of the
trees in addition to the numerical id. The name syntax is flexible.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: update dump-tree
David Sterba [Thu, 10 Mar 2016 14:18:01 +0000 (15:18 +0100)]
btrfs-progs: docs: update dump-tree

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: dump-tree: print version information earlier
David Sterba [Thu, 10 Mar 2016 14:02:18 +0000 (15:02 +0100)]
btrfs-progs: dump-tree: print version information earlier

The version information could be useful addition to the dump, print it
before we attempt to open the filesystem.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: dump-tree: print tree keys with -e
David Sterba [Thu, 10 Mar 2016 13:57:07 +0000 (14:57 +0100)]
btrfs-progs: dump-tree: print tree keys with -e

The incomplete tree description is printed with -e, glued to the leaf
information.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Describe device scan -d is a deprecated option in manpage
Satoru Takeuchi [Wed, 9 Mar 2016 23:08:31 +0000 (08:08 +0900)]
btrfs-progs: Describe device scan -d is a deprecated option in manpage

It's already marked as deprecated in cmd_device_scan_usage().

commit 5444864e5605 ("btrfs-progs: remove BTRFS_SCAN_PROC scan method")

Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Replace hardcoded PAGE_CACHE_SIZE with sectorsize.
Feifei Xu [Thu, 10 Mar 2016 08:43:20 +0000 (16:43 +0800)]
btrfs-progs: Replace hardcoded PAGE_CACHE_SIZE with sectorsize.

PAGE_CACHE_SIZE is hardcoded to 4K in cmds-restore.c. Correct
value should be sector size. Fix this through replacing
hardcoded 4K to sectorsize.

Signed-off-by: Feifei Xu <xufeifei@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: check: unify naming of long option values
David Sterba [Wed, 9 Mar 2016 13:57:27 +0000 (14:57 +0100)]
btrfs-progs: check: unify naming of long option values

We use GETOP_VAL_ .

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: update check options
David Sterba [Wed, 9 Mar 2016 13:55:11 +0000 (14:55 +0100)]
btrfs-progs: docs: update check options

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: check: drop short option for --chunk-tree
David Sterba [Wed, 9 Mar 2016 13:48:44 +0000 (14:48 +0100)]
btrfs-progs: check: drop short option for --chunk-tree

The need to specify the chunk root is not that common, we will reserve
the short option -c for later use.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Add new option for specify chunk root bytenr
Lu Fengqi [Mon, 7 Mar 2016 04:57:41 +0000 (12:57 +0800)]
btrfs-progs: Add new option for specify chunk root bytenr

Add new btrfsck option, '--chunk-root', to specify chunk root bytenr.
And allow open_ctree_fs_info() function accept chunk_root_bytenr to
override the bytenr in superblock. This will be mainly used when chunk
tree corruption.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fix broken 'device scan' arguments parsing
Yauhen Kharuzhy [Wed, 9 Mar 2016 01:19:40 +0000 (17:19 -0800)]
btrfs-progs: fix broken 'device scan' arguments parsing

Commit 52179e4fea41e55f31c92cd033a0b53a5107b4f4 'btrfs-progs: unify argc
min/max checking' breaks 'btrfs device scan' command when no argument
was given. Fix this.

Signed-off-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: unify argc min/max checking, a few more
David Sterba [Wed, 9 Mar 2016 13:29:29 +0000 (14:29 +0100)]
btrfs-progs: unify argc min/max checking, a few more

We don't want to modify argc.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: util: Fix a wrong unit of pretty_size
Qu Wenruo [Wed, 9 Mar 2016 02:10:55 +0000 (10:10 +0800)]
btrfs-progs: util: Fix a wrong unit of pretty_size

If parameter for pretty_size is smaller than default base(1024),
pretty_size() will output wrong unit.
For example, pretty_size(1008) will output '0.98B' not '1008B' or
'0.98KiB'.

The cause is, for default base and auto-detect unit, base will be 1024
but num_divs is still 0, last result will still be divided by base,
causing the bug.

Fix it by checking num_divs in default case, and if num_divs is 0,
change base to 1.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: add image for bko#96971 (bad checksum type)
David Sterba [Tue, 8 Mar 2016 14:43:13 +0000 (15:43 +0100)]
btrfs-progs: tests: add image for bko#96971 (bad checksum type)

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: libbtrfs: remove max/min macros from API
Ondrej Kozina [Fri, 4 Mar 2016 13:46:11 +0000 (14:46 +0100)]
btrfs-progs: libbtrfs: remove max/min macros from API

kerncompat.h header file is part of libbtrfs API. min/max macros cause
conflict while building projects dependant on libbtrfs. Moving those
macros to btrfs-progs internal header file fixes the conflict.

Signed-off-by: Ondrej Kozina <okozina@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: convert: document -O|--features flag
Vytas Dauksa [Wed, 2 Mar 2016 16:00:28 +0000 (16:00 +0000)]
btrfs-progs: convert: document -O|--features flag

Copy-pasted description found at mkfs.btrfs. I did not bother with
feature list as it seemed to be incomplete.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: don't print message for a missing device
David Sterba [Thu, 3 Mar 2016 10:33:04 +0000 (11:33 +0100)]
btrfs-progs: don't print message for a missing device

The message

"warning devid %llu not found already\n",

does not seem to be too useful, it appears during several commands and
sometimes repeatedly.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: restore: update error messages
David Sterba [Wed, 2 Mar 2016 14:47:49 +0000 (15:47 +0100)]
btrfs-progs: restore: update error messages

Switch to common helpers, message wording changed.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: switch more error messages to common helpers
David Sterba [Wed, 2 Mar 2016 14:47:19 +0000 (15:47 +0100)]
btrfs-progs: switch more error messages to common helpers

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: tests: fix misc/005-long-device-name-for-ssd
David Sterba [Tue, 1 Mar 2016 17:44:56 +0000 (18:44 +0100)]
btrfs-progs: tests: fix misc/005-long-device-name-for-ssd

We use a device mapper device on top of a loop device, the change in
rotational status does not always propagate if change it at the loop
device sysfs node.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: inspect: remove unnecessary helpers
David Sterba [Tue, 1 Mar 2016 15:34:26 +0000 (16:34 +0100)]
btrfs-progs: inspect: remove unnecessary helpers

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: unify argc min/max checking
David Sterba [Tue, 1 Mar 2016 15:29:16 +0000 (16:29 +0100)]
btrfs-progs: unify argc min/max checking

We don't want to modify argc.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: unify naming of argc and argv
David Sterba [Tue, 1 Mar 2016 15:28:11 +0000 (16:28 +0100)]
btrfs-progs: unify naming of argc and argv

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: rename commandline helpers
David Sterba [Tue, 1 Mar 2016 15:06:27 +0000 (16:06 +0100)]
btrfs-progs: rename commandline helpers

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: add getopt stubs where needed
David Sterba [Tue, 1 Mar 2016 15:02:08 +0000 (16:02 +0100)]
btrfs-progs: add getopt stubs where needed

Commands that do not take any options do not use getopt, which means the
standard option separator "--" does not work. Update all command
handlers that need it, argv needs to be referenced using the optind that
is correctly pointed after the separator.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: docs: add note about resizing to max after device replace
Alexander Fougner [Sun, 28 Feb 2016 21:11:54 +0000 (22:11 +0100)]
btrfs-progs: docs: add note about resizing to max after device replace

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
[ formatting adjustments ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi du: add long options for units
David Sterba [Wed, 24 Feb 2016 15:19:16 +0000 (16:19 +0100)]
btrfs-progs: fi du: add long options for units

Drop -h, add just the common long options for now.

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi du: switch to u64
David Sterba [Wed, 24 Feb 2016 15:04:07 +0000 (16:04 +0100)]
btrfs-progs: fi du: switch to u64

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: fi du: Calculate space shared by each directory arguments file set
Mark Fasheh [Wed, 20 Jan 2016 21:49:27 +0000 (13:49 -0800)]
btrfs-progs: fi du: Calculate space shared by each directory arguments file set

Here we define each file set as those found by a recursive search of a
single directory argument to btrfs fi du.

This isn't as simple as adding up shared extents - they may be shared with
each other, and may also overlap. This patch uses an interval tree to store
shared extents we find while fiemapping files. After collecting them, a 'set
shared' count is calculated by summing (without overlap) each shared region
discovered. This is then displayed to the user as 'set shared'.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: filesystem: add 'du' command
Mark Fasheh [Wed, 20 Jan 2016 21:49:26 +0000 (13:49 -0800)]
btrfs-progs: filesystem: add 'du' command

'btrfs du' differs from regular du in that it will work to resolve which
blocks are shared between files in its list. This gives the user a more
accurate bytecount from which they can make decisions regarding management
of their file space.

We still print a total number of bytes counted (like regular du), but also
print the number of bytes which were found to have been shared amongst the
file set provided. From there it becomes trivial to calculate how much space
is exclusively owned.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
[ rename files to reflect the filesystem command group, add GPL v2
  file headers ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: build: extend per-binary objects
David Sterba [Wed, 24 Feb 2016 12:57:12 +0000 (13:57 +0100)]
btrfs-progs: build: extend per-binary objects

The standalone utilities could share object files with the main utility,
add a way to specify additional object files in a similar way to the
extra libs. The variable name must match the binary plus _objects
suffix and  s/-/_/ .

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: update docs for inspect-internal dump-super
Alexander Fougner [Wed, 24 Feb 2016 10:52:34 +0000 (11:52 +0100)]
btrfs-progs: update docs for inspect-internal dump-super

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
[ minor formatting updates ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: introduce inspect-internal dump-super
Alexander Fougner [Wed, 24 Feb 2016 10:52:33 +0000 (11:52 +0100)]
btrfs-progs: introduce inspect-internal dump-super

The long-term plan is to merge the features of standalone tools
into the btrfs binary, reducing the number of shipped binaries.

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: update docs and completion for inspect-internal dump-tree
Alexander Fougner [Mon, 22 Feb 2016 14:49:50 +0000 (15:49 +0100)]
btrfs-progs: update docs and completion for inspect-internal dump-tree

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: copy functionality of btrfs-debug-tree to inspect-internal subcommand
Alexander Fougner [Mon, 22 Feb 2016 14:49:49 +0000 (15:49 +0100)]
btrfs-progs: copy functionality of btrfs-debug-tree to inspect-internal subcommand

The long-term plan is to merge the features of standalone tools
into the btrfs binary, reducing the number of shipped binaries.

Signed-off-by: Alexander Fougner <fougner89@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agoBtrfs progs v4.4.1
David Sterba [Fri, 26 Feb 2016 17:22:09 +0000 (18:22 +0100)]
Btrfs progs v4.4.1

Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Import interval tree implemenation from Linux v4.0-rc7.
Mark Fasheh [Wed, 20 Jan 2016 21:49:25 +0000 (13:49 -0800)]
btrfs-progs: Import interval tree implemenation from Linux v4.0-rc7.

While I had the chance, I compared the rbtre code in btrfs-progs to that of
the latest kernel.  No new bug fixes need importing, however rbtree.h and
rbtree_augmented.h get documentation updates

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: misc-test: Add regression test for find-root gives empty result
Qu Wenruo [Mon, 22 Feb 2016 06:59:57 +0000 (14:59 +0800)]
btrfs-progs: misc-test: Add regression test for find-root gives empty result

Add regression test for btrfs-find-root gives empty result even the fs
is OK.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ enhanced test ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: find-root: Allow btrfs-find-root to search chunk root even chunk root...
Qu Wenruo [Mon, 22 Feb 2016 06:59:56 +0000 (14:59 +0800)]
btrfs-progs: find-root: Allow btrfs-find-root to search chunk root even chunk root is corrupted

Since now open_ctree_fs_info() can even return a valid fs_info with only
system chunk mapping from super block, use this ability to do chunk root
search for heavily damanged fs.

As an fast alternative for time consuming and buggy chunk-recovery.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Add support for tree block operations on fs_info without roots
Qu Wenruo [Mon, 22 Feb 2016 06:59:55 +0000 (14:59 +0800)]
btrfs-progs: Add support for tree block operations on fs_info without roots

Since open_ctree_fs_info() now may return a fs_info even without any
roots, modify functions like read_tree_block() to operate with such
fs_info.

This provides the basis for btrfs-find-root to operate on chunk tree
with corrupted fs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ coding style adjustments, unified declarations ]
Signed-off-by: David Sterba <dsterba@suse.com>
8 years agobtrfs-progs: Allow open_ctree to return fs_info even chunk tree is corrupted
Qu Wenruo [Mon, 22 Feb 2016 06:59:54 +0000 (14:59 +0800)]
btrfs-progs: Allow open_ctree to return fs_info even chunk tree is corrupted

Current open_ctree_fs_info() won't return anything if chunk tree root is
corrupted.
This makes some function, like btrfs-find-root, unable to find any older
chunk tree root, even it is possible to use system_chunk_array in super
block.

And at least two users in mail list has reported such heavily chunk
corruption.
Although we have 'btrfs rescue chunk-recovery' but it's too time
consuming and sometimes not able to cope with a specific filesystem
corruption.

This patch adds a new open ctree flag,
OPEN_CTREE_IGNORE_CHUNK_TREE_ERROR, allowing fs_info to be returned from
open_ctree_fs_info() even there is no valid tree root in it.

Also adds a new close_ctree() variant, close_ctree_fs_info() to handle
possible fs_info without any root.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[ adjusted error messages ]
Signed-off-by: David Sterba <dsterba@suse.com>