platform/upstream/btrfs-progs.git
10 years agobtrfs-progs: latest_devid is not always the probed devid
Anand Jain [Mon, 24 Feb 2014 11:43:38 +0000 (19:43 +0800)]
btrfs-progs: latest_devid is not always the probed devid

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

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

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

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

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

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

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

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

reproducer:

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

  this patch will make it proper by querying devid 0.

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

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

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

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

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

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

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

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

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

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

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

Fix corporate name for copyright.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: mkfs.btrfs man page: update default metadata blocksize
Rakesh Pandit [Mon, 24 Feb 2014 15:08:11 +0000 (17:08 +0200)]
btrfs-progs: mkfs.btrfs man page: update default metadata blocksize

Since commit c652e4ef changes default metadata blocksize, update
corresponding options in man page.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: don't remove BTRFS_BLOCK_GROUP_DUP in chunk type
Rakesh Pandit [Thu, 20 Feb 2014 14:44:30 +0000 (16:44 +0200)]
btrfs-progs: don't remove BTRFS_BLOCK_GROUP_DUP in chunk type

During restoring of image (-r using btrfs-image) we zero out RAID
profile in chunk type but forget to save BTRFS_BLOCK_GROUP_DUP if
present. This results in some false messages being printed by btrfsck.

$  ./mkfs.btrfs /dev/sdb2 -f
$  ./btrfs-image /dev/sdb2 btrfs_image_output
$  ./btrfs-image -r btrfs_image_output disk-image
$  ./btrfsck disk-image
Checking filesystem on disk-image
UUID: e644be2d-7701-4bd4-8804-7487f560d2a7
checking extents
Chunk[256, 228, 20971520]: length(8388608), offset(20971520), type(2) mismatch with block group[20971520, 192, 8388608]: offset(8388608), objectid(20971520), flags(34)
Chunk[256, 228, 29360128]: length(1073741824), offset(29360128), type(4) mismatch with block group[29360128, 192, 1073741824]: offset(1073741824), objectid(29360128), flags(36)
Block group[20971520, 8388608] (flags = 34) didn't find the relative chunk.
Block group[293601281073741824] (flags = 36) didn't find the relative chunk.

Even though ./btrfsck on /dev/sdb2 seemed fine. This is due to type
mismatch above and type mismatch occured because we zero'ed out
BTRFS_BLOCK_GROUP_DUP while handling chunk trees.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Allow use of get_device_info()
Goffredo Baroncelli [Thu, 13 Feb 2014 19:19:44 +0000 (20:19 +0100)]
btrfs-progs: Allow use of get_device_info()

Allow the use of get_device_info() for different units.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix wrong error msg for exec btrfsck as non-root
Gui Hecheng [Thu, 20 Feb 2014 02:49:05 +0000 (10:49 +0800)]
btrfs-progs: fix wrong error msg for exec btrfsck as non-root

When exec btrfsck as non-root user on a disk, btrfsck will always
warn that "No such file or directory", despite that a directory
(e.g. /dev/vboxusb)actually exists. We just have no permission.
In this case, return the -errno set by the opendir call in
btrfs_scan_one_dir rather than blindly return -ENOENT.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: judge the return value of check_mounted more accurately
Gui Hecheng [Thu, 20 Feb 2014 02:49:03 +0000 (10:49 +0800)]
btrfs-progs: judge the return value of check_mounted more accurately

For btrfs-convert, btrfstune, btrfs rescue, they report "device busy"
when given a device that does not actually exist e.g.

# btrfstune -x abcdefg (this device does not exist)
$ ...device busy...

We deal with this case by add "ret < 0" error check when
judging the return value of check_mounted.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: switch to arg_strtou64() part3
Wang Shilong [Thu, 20 Feb 2014 01:30:52 +0000 (09:30 +0800)]
Btrfs-progs: switch to arg_strtou64() part3

Switch to new helper arg_strtou64(), also check if user assign
a valid super copy.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: switch to arg_strtou64() part2
Wang Shilong [Thu, 20 Feb 2014 01:30:51 +0000 (09:30 +0800)]
Btrfs-progs: switch to arg_strtou64() part2

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: switch to arg_strtou64() part1
Wang Shilong [Thu, 20 Feb 2014 01:30:50 +0000 (09:30 +0800)]
Btrfs-progs: switch to arg_strtou64() part1

switch to arg_strtou64 plus some cleanups to remove unnecessary
codes.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: new helper to parse string to u64 for btrfs
Wang Shilong [Fri, 21 Feb 2014 06:07:05 +0000 (14:07 +0800)]
Btrfs-progs: new helper to parse string to u64 for btrfs

There are many places that need parse string to u64 for btrfs commands,
in fact, we do such things *too casually*, using atoi/atol/atoll..is not
right at all, and even we don't check whether it is a valid string.

Let's do everything more gracefully, we introduce a new helper
arg_strtou64() which will do all the necessary checks.If we fail to
parse string to u64, we will output message and exit directly, this is
something like what usage() is doing. It is ok to not return erro to
it's caller, because this function should be called when parsing arg
(just like usage!)

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix fsck leaks on error returns
Gui Hecheng [Mon, 17 Feb 2014 10:19:49 +0000 (18:19 +0800)]
btrfs-progs: fix fsck leaks on error returns

Add close_ctree()s before the "returns" on errors after open_ctree()
Also merge the err returns into the "goto + single return" pattern.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: add dry-run option to restore command
Justin Maggard [Fri, 14 Feb 2014 18:40:47 +0000 (10:40 -0800)]
btrfs-progs: add dry-run option to restore command

Sometimes it is useful to see what btrfs restore is going to do
before provisioning enough external storage to restore onto.
Add a dry-run option so we can see what files and paths are found
by restore, without actually restoring any data.

Signed-off-by: Justin Maggard <jmaggard10@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: cleanup nonsense ret value assignment
Gui Hecheng [Thu, 13 Feb 2014 03:16:37 +0000 (11:16 +0800)]
btrfs-progs: cleanup nonsense ret value assignment

The "ret" will be soon used to hold the return value of another function,
assign -1 to it before is nonsense.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: remove a dead break before usage()
Gui Hecheng [Thu, 13 Feb 2014 03:16:36 +0000 (11:16 +0800)]
btrfs-progs: remove a dead break before usage()

The usage() in help.c calls exit(1), so the break behind is nonsense
and should be removed.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: use usage() to replace the warning msg on no-arg usage
Gui Hecheng [Thu, 13 Feb 2014 03:16:35 +0000 (11:16 +0800)]
btrfs-progs: use usage() to replace the warning msg on no-arg usage

To be consistent with the other cmds, replace the warning msg
with usage() when send/receive are used without any args.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Remove superfluous BUG_ON check.
Mitch Harder [Tue, 11 Feb 2014 13:00:12 +0000 (07:00 -0600)]
btrfs-progs: Remove superfluous BUG_ON check.

The function call that set the ret parameter evaluated in this
BUG_ON was removed in a previous commit:
11be10f71e1af5256f221feb9e91300b3e28bbef
Btrfs-progs: make fsck fix certain file extent inconsistencies

Signed-off-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Fix check_arg_type() which doesn't use realpath() result.
Qu Wenruo [Wed, 12 Feb 2014 05:44:37 +0000 (13:44 +0800)]
btrfs-progs: Fix check_arg_type() which doesn't use realpath() result.

Fix a problem that does not use the result of realpath(), which caused
check_arg_type() can't handle mount point which ends with a final '/'.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Cc: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Preserve process_one_leaf return value.
Mitch Harder [Fri, 7 Feb 2014 18:53:50 +0000 (12:53 -0600)]
btrfs-progs: Preserve process_one_leaf return value.

The return value in process_one_leaf could be over-written while
looping over the items in the leaf.

This patch will preserve a non-zero return value to the calling
function if a non-zero return value is encountered in the loop.

The return value of one (1) is consistent with non-zero values
that could be returned while processing the leaf.

The only caller of this function (walk_down_tree) would ignore
the return value anyway.  But this patch will correct the
behaviour in case future changes intend to utilize the return
value.

Signed-off-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: receive: don't output normal message into stderr
Wang Shilong [Mon, 10 Feb 2014 12:36:37 +0000 (20:36 +0800)]
Btrfs-progs: receive: don't output normal message into stderr

Don't output normal messages into stderr, this make xfstests
filter output easier.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: move find_mount_root to utils.[ch]
Qu Wenruo [Mon, 10 Feb 2014 07:28:28 +0000 (15:28 +0800)]
btrfs-progs: move find_mount_root to utils.[ch]

Move find_mount_root to utils.[ch] for general use.

Signed-off-by: Qu Wenruo <quwenruo@cn.fuijitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Change BUG() to use assert.
Mitch Harder [Fri, 7 Feb 2014 15:21:00 +0000 (09:21 -0600)]
btrfs-progs: Change BUG() to use assert.

Change the definition of BUG() to use assert instead of abort to
provide information about the location of the issue.

Signed-off-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Add missing devices check for mounted btrfs.
Qu Wenruo [Fri, 7 Feb 2014 07:07:19 +0000 (15:07 +0800)]
btrfs-progs: Add missing devices check for mounted btrfs.

In btrfs/003 of xfstest, it will check whether btrfs fi show can find
missing devices.

But before the patch, btrfs-progs will not check whether device missing
if given a mounted btrfs mountpoint/block device.
This patch fixes the bug and will pass btrfs/003.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Cc: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoioctl: add note regarding CLONE_RANGE(len=0) behaviour
David Disseldorp [Thu, 6 Feb 2014 14:29:18 +0000 (15:29 +0100)]
ioctl: add note regarding CLONE_RANGE(len=0) behaviour

A BTRFS_IOC_CLONE_RANGE request with a src_length value of zero has the
effect of cloning all data from src_offset through to end-of-file.

Document this behaviour in the header file for those who (like me)
incorrectly assume that no data is cloned in such a case.

Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix typo in reported error
Anand Jain [Wed, 5 Feb 2014 12:57:51 +0000 (20:57 +0800)]
btrfs-progs: fix typo in reported error

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: enclose uuid tree compat code with ifdefs
David Sterba [Tue, 21 Jan 2014 15:32:44 +0000 (16:32 +0100)]
btrfs-progs: enclose uuid tree compat code with ifdefs

Commit "Btrfs-progs: make send/receive compatible with older kernels"
adds code that will become deprecated, let's clearly mark it in the
sources.

CC: Stefan Behrens <sbehrens@giantdisaster.de>
CC: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: return non zero when label is not found
Anand Jain [Tue, 14 Jan 2014 11:17:07 +0000 (19:17 +0800)]
btrfs-progs: return non zero when label is not found

btrfs filesystem show <not-found-label> should return non zero

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: lblkid wouldn't find non mapper path input
Anand Jain [Fri, 15 Nov 2013 11:25:35 +0000 (19:25 +0800)]
btrfs-progs: lblkid wouldn't find non mapper path input

A new test case when disk is unmounted and if the non mapper
disk path is given as the argument to the btrfs filesystem show <arg>
we still need this to work but lblkid will pull only mapper disks,
it won't match. So this will normalize the input to find btrfs
by fsid and pass it to the search.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: add support for the compression property
Filipe David Borba Manana [Wed, 13 Nov 2013 01:22:09 +0000 (01:22 +0000)]
Btrfs-progs: add support for the compression property

With this property, one can enable compression for individual files
without the need to mount the filesystem with the compress or
compress-force options, and specify the compression algorithm.

When applied against a directory, files created under that directory
will inherit the compression property.

This requires the corresponding kernel patch, which adds the support
for setting and getting properties and implements the compression
property.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: add type root to label property
Filipe David Borba Manana [Tue, 12 Nov 2013 13:41:45 +0000 (13:41 +0000)]
Btrfs-progs: add type root to label property

So that we can get the label of a mounted filesystem.

Before this change:

        $ btrfs prop get /mnt/btrfs label
        ERROR: object is not compatible with property

        $ btrfs prop get /dev/sdb3 label
        ERROR: dev /dev/sdb3 is mounted, use mount point
        ERROR: failed to set/get property for object.

After this change:

        $ btrfs prop get /mnt/btrfs label
        label=foobar

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fix detection of root objects in cmds-property.c
Filipe David Borba Manana [Tue, 12 Nov 2013 13:41:44 +0000 (13:41 +0000)]
Btrfs-progs: fix detection of root objects in cmds-property.c

Several fixes:

1) The function check_is_root() returns 0 if the object is root;

2) Don't treat any error from get fsid ioctl as meaning the target
   is root. Only -ENOTTY means it's a root (parent directory is
   not a btrfs fs) and a -ENOTDIR means our target object is not a
   directory, therefore it can be the root;

3) Fix the comparison of the target and target's parent fs ids. If
   they are different, it means the target is a mount point in a
   btrfs fs, therefore it's a root, otherwise it isn't.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: introduce btrfs property subgroup
Alexander Block [Tue, 12 Nov 2013 13:41:43 +0000 (13:41 +0000)]
Btrfs-progs: introduce btrfs property subgroup

"btrfs filesystem property" is a generic interface to set/get
properties on filesystem objects (inodes/subvolumes/filesystems
/devs).

This patch adds the generic framework for properties and also
implements two properties. The first is the read-only property
for subvolumes and the second is the label property for devices.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: make send/receive compatible with older kernels
Wang Shilong [Thu, 9 Jan 2014 10:52:38 +0000 (18:52 +0800)]
Btrfs-progs: make send/receive compatible with older kernels

Some users complaint that with latest btrfs-progs, they will
fail to use send/receive. The problem is new tool will try
to use uuid tree while it dosen't work on older kernel.

Now we first check if we support uuid tree, if not we fall into
normal search as previous way.i copy most of codes from Alexander
Block's previous codes and did some adjustments to make it work.

Signed-off-by: Alexander Block <ablock84@googlemail.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fix double free when deleting subvolumes
Wang Shilong [Mon, 20 Jan 2014 08:44:21 +0000 (16:44 +0800)]
Btrfs-progs: fix double free when deleting subvolumes

Steps to reproduce:
# mkfs.btrfs -f /dev/sda8
# mount /dev/sda8 /mnt
# btrfs sub create /mnt/a
# touch /mnt/b
# btrfs sub create /mnt/c
# btrfs sub delete /mnt/*

Above steps will trigger following abortion:

ERROR: 'b' is not a subvolume
*** Error in `btrfs': double free or corruption (out): 0x0000000002116060 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3fa467cef8]
/lib64/libc.so.6(closedir+0xd)[0x3fa46b846d]
btrfs[0x43e608]
btrfs[0x40622f]
btrfs[0x403d19]
btrfs[0x4062c6]
btrfs[0x403f68]

We try to fix it by resetting @fd && @dirstream before trying next
subvolume deletion.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Fix bus error on sparc
Ivan Jager [Fri, 17 Jan 2014 14:00:43 +0000 (15:00 +0100)]
btrfs-progs: Fix bus error on sparc

Currently, as of 8cae1840afb3ea44dcc298f32983e577480dfee4 when running
btrfs-convert I get a bus error.

The problem is that struct btrfs_key has __attribute__ ((__packed__))
so it is not aligned. Then, a pointer to it's objectid field is taken,
cast to a  void*, then eventually cast back to a u64* and
dereferenced. The problem is that the dereferenced u64* is not
necessarily aligned (ie, not necessarily a valid u64*), resulting in
undefined behavior.

This patch adds a local u64 variable which would of course be properly
aligned and then uses a pointer to that.

I did not modify the call from btrfs_fs_roots_compare_roots as that
uses struct btrfs_root which is a regular struct and would thus have
it's members correctly aligned to begin with.

After patching this I realized Liu Bo had already written a similar
patch, but I think mine is cleaner, so I'm sending it anyway.

Signed-off-by: Ivan Jager <aij+@mrph.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix minor grammar issues
Mitchel Humpherys [Tue, 14 Jan 2014 21:44:03 +0000 (13:44 -0800)]
btrfs-progs: fix minor grammar issues

Remove the extraneous `to' from `Can't access to X'.

Signed-off-by: Mitchel Humpherys <mitch.special@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: btrfsck operations should be exclusive
Anand Jain [Mon, 13 Jan 2014 13:14:55 +0000 (21:14 +0800)]
btrfs-progs: btrfsck operations should be exclusive

this patch will make btrfsck operations to open disk in exclusive mode,
so that mount will fail when btrfsck is running

Signed-off-by: Anand Jain <Anand.Jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: check return value of read_tree_block() in check_chunks_and_extents()
Eryu Guan [Fri, 10 Jan 2014 14:50:02 +0000 (22:50 +0800)]
Btrfs-progs: check return value of read_tree_block() in check_chunks_and_extents()

The following steps could trigger btrfs segfault:

mkfs -t btrfs -m raid5 -d raid5 /dev/loop{0..3}
losetup -d /dev/loop2
btrfs check /dev/loop0

The reason is that read_tree_block() returns NULL and
add_root_to_pending() dereferences it without checking it first.

Also replace a BUG_ON with proper error checking.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: sync-up with newly introduced ioctl number
Anand Jain [Thu, 19 Dec 2013 04:08:56 +0000 (12:08 +0800)]
btrfs-progs: sync-up with newly introduced ioctl number

for now the manual sync up of new ioctls introduced in the btrfs
kernel. For which there wasn't any btrfs-progs patch.
however we might have better idea for the long run.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: add support for the no holes incompat flag
Josef Bacik [Tue, 22 Oct 2013 16:22:41 +0000 (12:22 -0400)]
Btrfs-progs: add support for the no holes incompat flag

This adds the flag to ctree.h, adds the feature option to mkfs to turn it on and
fixes fsck so it doesn't complain about missing hole extents in files when this
flag is set.

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: skip non-regular files while defragmenting
Pascal VITOUX [Thu, 9 Jan 2014 22:47:14 +0000 (23:47 +0100)]
btrfs-progs: skip non-regular files while defragmenting

Skip non-regular files to avoid ioctl errors while defragmenting.

They are silently ignored in recursive mode but reported as errors when
used as command-line arguments.

Signed-off-by: Pascal VITOUX <vitoux.pascal@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fix to make list specified directory's subvolumes work
Wang Shilong [Thu, 9 Jan 2014 12:42:12 +0000 (20:42 +0800)]
Btrfs-progs: fix to make list specified directory's subvolumes work

Steps to reproduce:
 # mkfs.btrfs -f /dev/sda8
 # mount /dev/sda8 /mnt
 # mkdir /mnt/subvolumes
 # btrfs sub create /mnt/subvolumes/subv1
 # btrfs sub create /mnt/subvolumes/subv1/subv1.1
 # btrfs sub list -o /mnt/subvolumes/subv1   <----we did not list anything

The problem is that we don't set @top_id right, fix it.

Reported-by: Alex <alex@bpmit.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: test_skip_this_disk() isn't needed anymore
Anand Jain [Fri, 27 Dec 2013 05:56:29 +0000 (13:56 +0800)]
btrfs-progs: test_skip_this_disk() isn't needed anymore

add_seen_fsid() which was introduced lately will eliminate
the mounted disks, so we don't need test_skip_this_disk()
anymore

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: handle error in the btrfs_prepare_device
Anand Jain [Wed, 18 Dec 2013 04:07:55 +0000 (12:07 +0800)]
btrfs-progs: handle error in the btrfs_prepare_device

this patch will handle the strerror reporting of the error instead of
printing errno,  and also replaced the BUG_ON with the error handling

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: receive: fix the case that we can not find the subvolume
Wang Shilong [Wed, 18 Dec 2013 09:56:33 +0000 (17:56 +0800)]
Btrfs-progs: receive: fix the case that we can not find the subvolume

If we change our default subvolume, btrfs receive will fail to find
subvolume. To fix this problem, we have three ideas:

 1.make btrfs snapshot ioctl support passing source subvolume's objectid.
 2.when we want to using interval subvolume path, we mount it other place
 that use subvolume 5 as its default subvolume.
 3.tell the user to mount the toplevel subvol by himself and run
 receive

We's better use the third approach because first patch will bother kernel
change and the second approach is not very good for power users. So give this
option to users.

Reported-by: Michael Welsh Duggan <mwd@md5i.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix btrfstune silence on failure
Gui Hecheng [Wed, 18 Dec 2013 03:52:45 +0000 (11:52 +0800)]
btrfs-progs: fix btrfstune silence on failure

Originally, btrfstune will fail without any options, like this:

# btrfstune /dev/sdb

An error prompt & usage should show up upon this condition.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: update send help strings and manpage
David Sterba [Mon, 16 Dec 2013 15:47:10 +0000 (16:47 +0100)]
btrfs-progs: update send help strings and manpage

- send accepts multiple subvolumes
- add missing option -e to man
- minor man formatting fix

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: add options to set commit mode after subvol delete
David Sterba [Thu, 12 Dec 2013 18:11:26 +0000 (19:11 +0100)]
btrfs-progs: add options to set commit mode after subvol delete

Subvolume deletion does not do a full transaction commit. This can lead
to an unexpected result when the system crashes between deletion and
commit, the subvolume directory will appear again. Add options to request
filesystem sync after each deleted subvolume or after the last one.

If the command with --commit option finishes succesfully, the
subvolume(s) deletion status is safely stored on the media.

Userspace approach is more flexible than in-kernel. Related discussions:
http://www.spinics.net/lists/linux-btrfs/msg22088.html
http://www.spinics.net/lists/linux-btrfs/msg27240.html

CC: Alex Lyakas <alex.btrfs@zadarastorage.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: use stripe_len define here
Anand Jain [Mon, 16 Dec 2013 12:33:58 +0000 (20:33 +0800)]
btrfs-progs: use stripe_len define here

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: don't replicate the stripe_len defines
Anand Jain [Mon, 16 Dec 2013 12:33:57 +0000 (20:33 +0800)]
btrfs-progs: don't replicate the stripe_len defines

a clean up patch, the BTRFS_STRIPE_LEN is been duplicated across
btrfs-progs, the kernel defines it in volume.h so do the same
for progs.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: remove NULL-ptr judge before free for btrfs-progs
Gui Hecheng [Thu, 12 Dec 2013 10:41:07 +0000 (18:41 +0800)]
btrfs-progs: remove NULL-ptr judge before free for btrfs-progs

free(3) already checks the pointer for NULL, no need to do it
on your own. This patch make the change globally.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: add sanity checks for btrfs device operations
Wang Shilong [Thu, 12 Dec 2013 07:47:00 +0000 (15:47 +0800)]
Btrfs-progs: add sanity checks for btrfs device operations

Make sure we are a block device firstly, this can avoid some
unnecessary ioctls operations.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix resource leak in scrub_start()
Eric Sandeen [Thu, 12 Dec 2013 07:34:16 +0000 (15:34 +0800)]
btrfs-progs: fix resource leak in scrub_start()

Resolves-Coverity-CID: 1125934
Resolves-Coverity-CID: 1125935
Resolves-Coverity-CID: 1125936
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: deal with invalid key orderings and bad orphan items V2
Josef Bacik [Tue, 7 Jan 2014 20:19:35 +0000 (15:19 -0500)]
Btrfs-progs: deal with invalid key orderings and bad orphan items V2

A user had a fs where the objectid of an orphan item was not the actual orphan
item objectid.  This screwed up fsck because the block has keys in the wrong
order, also the fs scanning stuff will freak out because we have an inode with
nlink 0 and no orphan item.  So this patch is pretty big but is all related.

1) Deal with bad key ordering.  We can easily fix this up, so fix the checking
stuff to tell us exactly what it found when it said there was a problem.  Then
if it's bad key ordering we can reorder the keys and restart the scan.

2) Deal with bad keys.  If we find an orphan item with the wrong objectid it's
likely to screw with stuff, so keep track of these sort of things with a
bad_item list and just run through and delete any objects that don't make sense.
So far we just do this for orphan items but we could extend this as new stuff
pops up.

3) Deal with missing orphan items.  This is easy, if we have a file with i_nlink
set to 0 and no orphan item we can just add an orphan item.

4) Add the infrastructure to corrupt actual key values.  Needed this to create a
test image to verify I was fixing things properly.

This patch fixes the corrupt image I'm adding and passes the other make test
tests.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: reset balance before reiniting extent root
Josef Bacik [Wed, 11 Dec 2013 16:17:52 +0000 (11:17 -0500)]
Btrfs-progs: reset balance before reiniting extent root

When we re-init the extent root we make it completely empty, so when we reset a
pending balance we will fail to find refs for any blocks we may cow, which will
result in errors and we will exit out.  We need to reset the balance first so
the normal cow stuff doesn't freak out and then we can re-init the extent tree.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: make sure we are opening a file or dir with open_file_or_dir()
Wang Shilong [Thu, 12 Dec 2013 07:46:18 +0000 (15:46 +0800)]
Btrfs-progs: make sure we are opening a file or dir with open_file_or_dir()

Previously, open_file_or_dir() will open block device successfully, however,
we should enhance such checks to make sure we are really opening a file or dir.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix improper error prompt for defragment
Gui Hecheng [Wed, 11 Dec 2013 09:27:46 +0000 (17:27 +0800)]
btrfs-progs: fix improper error prompt for defragment

The error msg:
"ERROR: defrag range ioctl not supported in this kernel,
 please try without any options."
should only show up when failing to do a range defraging,
not upon non-range defraging.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: convert remaining uuid buffer declarations to BTRFS_UUID_UNPARSED_SIZE
David Sterba [Tue, 10 Dec 2013 17:17:10 +0000 (18:17 +0100)]
btrfs-progs: convert remaining uuid buffer declarations to BTRFS_UUID_UNPARSED_SIZE

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: add fsck.btrfs stub and manpage
David Sterba [Mon, 2 Sep 2013 15:22:24 +0000 (17:22 +0200)]
btrfs-progs: add fsck.btrfs stub and manpage

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix a manpage item for btrfstune
Gui Hecheng [Tue, 10 Dec 2013 11:16:31 +0000 (19:16 +0800)]
btrfs-progs: fix a manpage item for btrfstune

btrfstune operates on umounted devices <device>,
not mount points <mnt>. fix it.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: send: check if parent or clone sources are read-only
David Sterba [Fri, 6 Dec 2013 18:00:49 +0000 (19:00 +0100)]
btrfs-progs: send: check if parent or clone sources are read-only

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: avoid using btrfs internal subvolume path to send
Wang Shilong [Fri, 29 Nov 2013 16:37:25 +0000 (00:37 +0800)]
Btrfs-progs: avoid using btrfs internal subvolume path to send

Steps to reproduce:
# mkfs.btrfs -f /dev/sda
# mount /dev/sda /mnt
# btrfs subvolume create /mnt/foo
# umount /mnt
# mount -o subvol=foo /dev/sda /mnt
# btrfs sub snapshot -r /mnt /mnt/snap
# btrfs send /mnt/snap > /dev/null

We will fail to send '/mnt/snap',this is because btrfs send try to
open '/mnt/snap' by btrfs internal subvolume path 'foo/snap' rather
than relative path based on mounted point, this will return us 'no
such file or directory',this is not right, fix it.

Reported-by: Thomas Scheiblauer <tom@sharkbay.at>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: qgroup destroy says create failed
Anand Jain [Mon, 2 Dec 2013 06:11:55 +0000 (14:11 +0800)]
btrfs-progs: qgroup destroy says create failed

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fix segfault when getting scrub status
Wang Shilong [Wed, 4 Dec 2013 09:24:36 +0000 (17:24 +0800)]
Btrfs-progs: fix segfault when getting scrub status

I sometimes get segfault in cmd_scrub_status(), this is because
free_history() forgot to check whether pointer address is valid,fix it.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: add option to skip whether a scrub has started/resumed in userspace
Wang Shilong [Mon, 2 Dec 2013 06:42:25 +0000 (14:42 +0800)]
Btrfs-progs: add option to skip whether a scrub has started/resumed in userspace

I hit a problem that i can not start scrub when i am trying to track
superblock generation mismatch problems.

The fact is that we are trying to check whether we have started a scrub operation
in userspace, this will make us can't start scrub if that record file is damaged
itself. By adding a option to skip that check, everything will be fine.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix backref after init-csum-tree
Anand Jain [Mon, 2 Dec 2013 06:11:54 +0000 (14:11 +0800)]
btrfs-progs: fix backref after init-csum-tree

btrfsck reports backref error after running init-csum-tree

btrfsck --init-csum-tree /dev/sdc
btrfsck /dev/sdc
::
ref mismatch on [29474816 16384] extent item 1, found 0
Backref 29474816 root 7 not referenced back 0x1101d30
Incorrect global backref count on 29474816 found 1 wanted 0
backpointer mismatch on [29474816 16384]
owner ref check failed [29474816 16384]
Errors found in extent allocation tree or chunk allocation
::

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Turning ON incompat isn't an error
Anand Jain [Mon, 2 Dec 2013 06:11:53 +0000 (14:11 +0800)]
btrfs-progs: Turning ON incompat isn't an error

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: scan devices in parallel for chunk-recover
Gui Hecheng [Thu, 28 Nov 2013 05:32:52 +0000 (13:32 +0800)]
btrfs-progs: scan devices in parallel for chunk-recover

Originally, multi devices are scanned one by one;
Now, one thread is used per device to scan.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: add chunk-recover raid0/5/6 data stripes rebuild routine
Gui Hecheng [Thu, 28 Nov 2013 05:32:51 +0000 (13:32 +0800)]
btrfs-progs: add chunk-recover raid0/5/6 data stripes rebuild routine

Decide the raid0/5/6 data stripes' order using checksums.
For one chunk, fetch each 64k logical stripe
1. search its checksum in the csum tree
2. read the physical stripe data on each device
3. calc the data checksums
4. if one checksum matches the value from the csum tree,
   then the logical stripe resides in that device,
   the stripe order index can be calculated.
5. if more than one checksums match,
   then use the successive csum in the tree to compare again.
6. if equal stripes are encountered, just fetch next stripe.
7. if some devices' order are still not decided, then they
   can not be recovered.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: skip chunk recover works when check chunks successfully
Gui Hecheng [Thu, 28 Nov 2013 05:32:50 +0000 (13:32 +0800)]
btrfs-progs: skip chunk recover works when check chunks successfully

If no chunks need to be recovered, skip the recover works,
meanwhile the user won't be annoyed by the "ask_user".

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: chunk-recover: add new flag to prepare recovering for ordered data chunk
Wang Shilong [Thu, 28 Nov 2013 05:32:49 +0000 (13:32 +0800)]
Btrfs-progs: chunk-recover: add new flag to prepare recovering for ordered data chunk

When reading block groups we will searching it's corresponding chunk, however, at this
time, some chunks has not been built(data chunks raid0/raid10/raid56), don't bug_on here,
we will try to rebuild these chunks later.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: use mntent functions in find_mount_root
David Sterba [Wed, 27 Nov 2013 17:22:34 +0000 (18:22 +0100)]
btrfs-progs: use mntent functions in find_mount_root

getmntent should be used in context of *mntent functions, though
fopen/fclose works.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: call endmntent in btrfs_scan_kernel
David Sterba [Wed, 27 Nov 2013 17:14:58 +0000 (18:14 +0100)]
btrfs-progs: call endmntent in btrfs_scan_kernel

btrfs_scan_kernel() does a getmntent() but never releases the
filedescriptor it gets back from that.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=64711

Reported-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fix the mismatch of extent buffer's space
Liu Bo [Wed, 27 Nov 2013 16:08:24 +0000 (00:08 +0800)]
Btrfs-progs: fix the mismatch of extent buffer's space

Now we set @refs to 2 on creating a new extent buffer, meanwhile we
allocate the needed free space, but we don't give enough free_extent_buffer()
to reduce the eb's references to zero so that the eb can finally be freed,
so the problem is we has decrease the referene count of backrefs to zero, which
ends up releasing the space occupied by the eb, and this space can be allocated
again for something else(another eb or disk), usually a crash(core dump) will
occur, I've hit a crash in rb_insert() because another eb re-use the space while
the original one is floating around.

We should do the same thing as the kernel code does, it's necessary to initialize
@refs to 1 instead of 2, this helps us get rid of the above problem.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: chunk-recover: use right size when allocating chunk root node
Wang Shilong [Wed, 27 Nov 2013 14:43:56 +0000 (22:43 +0800)]
Btrfs-progs: chunk-recover: use right size when allocating chunk root node

When allocating chunk root node, we should use nodesize rather than sectorsize,
this will casue regression when making other nodesize choice.(for example 16k size now)

Reported-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: Make btrfs_header_chunk_tree_uuid() return unsigned long
Ross Kirk [Wed, 2 Oct 2013 12:28:27 +0000 (13:28 +0100)]
btrfs-progs: Make btrfs_header_chunk_tree_uuid() return unsigned long

Internally, btrfs_header_chunk_tree_uuid() calculates an unsigned
long, but casts it to a pointer, while all callers cast it to unsigned
long again.

From btrfs commit b308bc2f05a86e728bd035e21a4974acd05f4d1e

Signed-off-by: Ross Kirk <ross.kirk@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf size
Anand Jain [Mon, 4 Nov 2013 07:17:41 +0000 (15:17 +0800)]
btrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf size

we use 37 as the allocation size to hold the uuid_unparse, here
it defines BTRFS_UUID_UNPARSE_SIZE for the same.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: let get_label return the label instead of printing it
Filipe David Borba Manana [Tue, 12 Nov 2013 13:41:42 +0000 (13:41 +0000)]
Btrfs-progs: let get_label return the label instead of printing it

get_label prints the label at the moment. Change this so that
the label is returned and printing is done by the caller.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: try harder to make btrfs receive successfully
Wang Shilong [Wed, 13 Nov 2013 09:25:46 +0000 (17:25 +0800)]
Btrfs-progs: try harder to make btrfs receive successfully

Steps to reproduce:
# mkfs.btrfs -f <dev>
# mount <dev> <mnt>
# mkdir <mnt>/backup
# btrfs sub create <mnt>/subv
# btrfs sub snapshot -r <mnt>/subv <mnt>/snap1
# btrfs sub snapshot -r <mnt>/subv <mnt>/snap2
# btrfs send <mnt>/snap2 -p <mnt>/snap1 -f sent_file
# btrfs receive -f sent_file <mnt>/backup

Above steps will make btrfs receive fails with "ERROR: can not find
parent subvolume", this is because we try to find parent subvolume by
RECEIVED_SUBVOL_KEY,and it will return ENOENT if parent snapshot has not
been sent or it has been deleted. Actually, we can try harder to find
whether parent subvolume exists by searching uuid key.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Reviewed-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: make it static if function isn't called outside
Anand Jain [Wed, 13 Nov 2013 08:19:39 +0000 (16:19 +0800)]
btrfs-progs: make it static if function isn't called outside

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: use /proc/self/mounts
Anand Jain [Thu, 7 Nov 2013 02:53:43 +0000 (10:53 +0800)]
btrfs-progs: use /proc/self/mounts

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: fix loop device mount checks
David Sterba [Fri, 20 Sep 2013 16:52:18 +0000 (18:52 +0200)]
btrfs-progs: fix loop device mount checks

When creating a fs on a loop device, mkfs checks whether the same file
is not already mounted, but a backing file of another loop dev does not
exist, mkfs fails. This fixes a bug during openSUSE installation.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: don't output baffling message when checking a fresh fs
Miao Xie [Fri, 25 Oct 2013 09:30:45 +0000 (17:30 +0800)]
Btrfs-progs: don't output baffling message when checking a fresh fs

As we know,  a new fs doesn't have space cache, so we set the cache generation
of the super block to be -1ULL, it is not equal to the fs generation. But the
check program didn't consider this case, and output the following message

  cache and super generation don't match, space cache will be invalidated

directly, it would be baffling the users. So we should avoid outputing such
message. This patch fixes this problem.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: allow --init-extent-tree to work when extent tree is borked
Josef Bacik [Fri, 25 Oct 2013 18:01:40 +0000 (14:01 -0400)]
Btrfs-progs: allow --init-extent-tree to work when extent tree is borked

Unfortunately you can't run --init-extent-tree if you can't actually read the
extent root.  Fix this by allowing partial starts with no extent root and then
have fsck only check to see if the extent root is uptodate _after_ the check to
see if we are init'ing the extent tree.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: make filesystem show by label work
Anand Jain [Thu, 24 Oct 2013 14:42:56 +0000 (22:42 +0800)]
btrfs-progs: make filesystem show by label work

with design revamp around filesystem show the fsid filter
by label wasn't planned. but apparently that seemed to be
necessary. this patch will fix it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agobtrfs-progs: remove cmds-chunk.c
David Sterba [Fri, 25 Oct 2013 10:01:44 +0000 (12:01 +0200)]
btrfs-progs: remove cmds-chunk.c

Commit "btrfs-progs: separate command and implementation of
chunk-recover code" moved contents of this file to chunk-recover.c but
failed to remove the file cmds-chunk.c

Reported-by: Mitch Harder <mitch.harder@sabayonlinux.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoBtrfs-progs: fix btrfsck improper prompt on dropping snapshots
Gui Hecheng [Thu, 17 Oct 2013 06:25:29 +0000 (14:25 +0800)]
Btrfs-progs: fix btrfsck improper prompt on dropping snapshots

Exec btrfsck on btrfs with snapshots that are under a dropping
progress will cause prompt on "ref mismatch".
However we do not want this kind of prompt, since an remount
operation will continue the dropping progress.
Here the prompt is nonsense.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
10 years agoUpdate the version
Chris Mason [Mon, 25 Nov 2013 20:48:57 +0000 (15:48 -0500)]
Update the version

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agoAdd -fno-strict-aliasing
Chris Mason [Fri, 22 Nov 2013 13:41:50 +0000 (08:41 -0500)]
Add -fno-strict-aliasing

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agobtrfs filesystem show: skip duplicate fsids
Chris Mason [Mon, 18 Nov 2013 19:18:08 +0000 (14:18 -0500)]
btrfs filesystem show: skip duplicate fsids

If a given filesystem is mounted more than once, btrfs fi show will
print dups.  This adds a quick and dirty hash table of fsids it
has already printed and makes sure we don't print any fsid more than
once.

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agobtrfs-progs: for mixed group check opt before default raid profile is enforced
Anand Jain [Fri, 15 Nov 2013 11:11:09 +0000 (19:11 +0800)]
btrfs-progs: for mixed group check opt before default raid profile is enforced

This fixes the regression introduced with the patch

    btrfs-progs: avoid write to the disk before sure to create fs

what happened with this patch is it missed the check to see if the
user has the option set before pushing the defaults.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agobtrfs-progs: mkfs: enable extended refs by default
David Sterba [Thu, 14 Nov 2013 14:09:53 +0000 (15:09 +0100)]
btrfs-progs: mkfs: enable extended refs by default

The feature has been introduced in kernel 3.7 and enabling it by
default is desired.

All features enabled by default are marked as such in
'mkfs.btrfs -O list-all' output.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agobtrfs-progs: man: add rescue super-recover bits
David Sterba [Thu, 14 Nov 2013 13:40:43 +0000 (14:40 +0100)]
btrfs-progs: man: add rescue super-recover bits

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agobtrfs-progs: mkfs: extend -O syntax to disable features
David Sterba [Thu, 14 Nov 2013 13:30:45 +0000 (14:30 +0100)]
btrfs-progs: mkfs: extend -O syntax to disable features

A way of disabling features that are on by default in case it's not
wanted, eg. due to lack of support in the used kernel.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agobtrfs-progs: remove extra uuid-tree.o in objects
Emil Karlson [Mon, 11 Nov 2013 16:22:24 +0000 (18:22 +0200)]
btrfs-progs: remove extra uuid-tree.o in objects

This fixes static compile target of btrfs-progs.

Signed-off-by: Emil Karlson <jekarlson@gmail.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agomkfs: change default metadata blocksize to 16KB
Chris Mason [Fri, 8 Nov 2013 18:51:52 +0000 (13:51 -0500)]
mkfs: change default metadata blocksize to 16KB

16KB is faster and leads to less metadata fragmentation in almost all
workloads.  It does slightly increase lock contention on the root nodes
in some workloads, but that is best dealt with by adding more subvolumes
(for now).

This uses 16KB or the page size, whichever is bigger.  If you're doing a
mixed block group mkfs, it uses the sectorsize instead.

Since the kernel refuses to mount a mixed block group FS where the
metadata leaf size doesn't match the data sectorsize, this also adds a
similar check during mkfs.

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
10 years agobtrfs-progs: annotate fallthroughs in parse_limit
Eric Sandeen [Wed, 6 Nov 2013 23:15:55 +0000 (17:15 -0600)]
btrfs-progs: annotate fallthroughs in parse_limit

We intentionally fall through these case statements;
just annotate it to be clear.

Resolves-Coverity-CID: 1054884
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>