platform/upstream/btrfs-progs.git
11 years agoBtrfs-progs: add man page information for btrfs-find-root
Wang Shilong [Wed, 14 Aug 2013 04:29:13 +0000 (12:29 +0800)]
Btrfs-progs: add man page information for btrfs-find-root

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add missing man page for btrfs-show-super
Wang Shilong [Wed, 14 Aug 2013 04:29:12 +0000 (12:29 +0800)]
Btrfs-progs: add missing man page for btrfs-show-super

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add missing man information for btrfs-debug-tree
Wang Shilong [Wed, 14 Aug 2013 04:29:11 +0000 (12:29 +0800)]
Btrfs-progs: add missing man information for btrfs-debug-tree

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add missing man page information for btrfsck
Wang Shilong [Wed, 14 Aug 2013 04:29:10 +0000 (12:29 +0800)]
Btrfs-progs: add missing man page information for btrfsck

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: mark static & remove unused from non-kernel code
Eric Sandeen [Fri, 9 Aug 2013 20:20:47 +0000 (15:20 -0500)]
btrfs-progs: mark static & remove unused from non-kernel code

Mark many functions as static, and remove any resulting dead code.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix a regression in mkfs.btrfs
Stefan Behrens [Thu, 8 Aug 2013 10:51:39 +0000 (12:51 +0200)]
Btrfs-progs: fix a regression in mkfs.btrfs

Commit 55061a98 adds a cut & paste error that makes mkfs.btrfs fail
if leafsize != sectorsize.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Reviewed-by: Filipe Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: mark static & remove unused from shared kernel code
Eric Sandeen [Wed, 7 Aug 2013 01:03:33 +0000 (20:03 -0500)]
btrfs-progs: mark static & remove unused from shared kernel code

In files copied from the kernel, mark many functions as static,
and remove any resulting dead code.

Some functions are left unmarked if they aren't static in the
kernel tree.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: don't overrun "answer" array in cmds-chunk.c
Zach Brown [Tue, 6 Aug 2013 18:49:04 +0000 (11:49 -0700)]
btrfs-progs: don't overrun "answer" array in cmds-chunk.c

Eric noticed the trivial stack overflow bug in ask_user().  I went to
see the context for that fix and found that ask_user() was a bit much.

This fixes the overflow bug that Eric found, endless spinning on scanf()
errors, removes dead code, and leaves us with a trivial helper.

Signed-off-by: Zach Brown <zab@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: cmd_start_replace() to use test_dev_for_mkfs()
Anand Jain [Thu, 25 Jul 2013 17:35:27 +0000 (01:35 +0800)]
btrfs-progs: cmd_start_replace() to use test_dev_for_mkfs()

test_dev_for_mkfs() is a common place where
we check if a device is fit for the btrfs use.
cmd_start_replace() should make use of test_dev_for_mkfs(),
and here the test_dev_for_mkfs() is further enhanced
to fit the cmd_start_replace() needs.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: let user know that devid can be used if path is missing
Anand Jain [Thu, 25 Jul 2013 17:35:26 +0000 (01:35 +0800)]
btrfs-progs: let user know that devid can be used if path is missing

When the device disappear the path goes missing,
and that will be the one of the reason that user
will replace the device.

The devid of the missing btrfs device can be
obtained using the new cli option
 btrfs fi show --kernel

And which can be used in the replace command.
---
btrfs replace start /dev/sdc /dev/sde /btrfs
Error: Unable to open device '/dev/sdc'
        Try using the devid instead of the path
---

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Fix the return value of btrfs-map-logical
Qu Wenruo [Thu, 1 Aug 2013 05:35:33 +0000 (13:35 +0800)]
btrfs-progs: Fix the return value of btrfs-map-logical

The ret variant in the main function is not changed so even problems
happen, return value is still 0.
The patch fixs the minor bug and return 1 if any problems happen.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: added "btrfs quota rescan" -w switch (wait)
Jan Schmidt [Mon, 6 May 2013 19:15:18 +0000 (21:15 +0200)]
Btrfs-progs: added "btrfs quota rescan" -w switch (wait)

With -w one can wait for a rescan operation to finish. It can be used when
starting a rescan operation or later to wait for the currently running
rescan operation to finish. Waiting is interruptible.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: mkfs.btrfs documentation: clarify current restrictions of sectorsize...
Koen De Wit [Thu, 11 Jul 2013 20:56:17 +0000 (22:56 +0200)]
btrfs-progs: mkfs.btrfs documentation: clarify current restrictions of sectorsize, nodesize and leafsize

Commit 8d082fb727ac11930ea20bf1612e334ea7c2b697 (Btrfs: do not mount when
we have a sectorsize unequal to PAGE_SIZE) requires the sectorsize to be
equal to the pagesize for the filesystem to be mountable.

The nodesize and leafsize should be equal, and not larger than 65536.

Adding this information to the manpage and usage instructions of mkfs.btrfs.

Signed-off-by: Koen De Wit <koen.de.wit@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: make set/get functions for the super compat_ro flags use compat_ro
Eric Sandeen [Mon, 5 Aug 2013 21:49:33 +0000 (16:49 -0500)]
btrfs-progs: make set/get functions for the super compat_ro flags use compat_ro

Port of commit 12534832 to userspace:

 commit 12534832cb7b0abc7369298246e8b7af03b863ca
 Author: Josef Bacik <josef@redhat.com>
 Date:   Thu Dec 17 21:32:27 2009 +0000

    Btrfs: make set/get functions for the super compat_ro flags use compat_ro

    Our set/get functions for compat_ro_flags actually look at compat_flags.  This
    will mess any attempt to use compat flags up.  The fix is obvious.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: fix definition of struct btrfs_extent_inline_ref
Eric Sandeen [Mon, 5 Aug 2013 21:46:08 +0000 (16:46 -0500)]
btrfs-progs: fix definition of struct btrfs_extent_inline_ref

Port kernel commit 1bec1aed to userspace.

use __le64 instead of u64 in on-disk structure definition.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: drop weird indirections & dead code from send/receive
Eric Sandeen [Sat, 3 Aug 2013 01:24:55 +0000 (20:24 -0500)]
btrfs-progs: drop weird indirections & dead code from send/receive

cmds-recieve.c & cmds-send.c seem to have weird wrappers and
indirections, and "groups" of commands which have only
one member, which are never referenced in the code.

I think these can be removed.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: drop unused parameter from btrfs_release_path
Eric Sandeen [Sat, 3 Aug 2013 00:52:43 +0000 (19:52 -0500)]
btrfs-progs: drop unused parameter from btrfs_release_path

Port of commit b3b4aa7 to userspace.

parameter tree root it's not used since commit
5f39d397dfbe140a14edecd4e73c34ce23c4f9ee ("Btrfs: Create extent_buffer
interface for large blocksizes")

This gets userspace a tad closer to kernelspace by removing
this unused parameter that was all over the codebase...

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: sanitize xattrs when we specify sanitization
Josef Bacik [Wed, 31 Jul 2013 14:23:58 +0000 (10:23 -0400)]
Btrfs-progs: sanitize xattrs when we specify sanitization

Alexandre pointed out that his xattrs have sensitive information in them as
well, so fix btrfs-image to zero out the data part of xattrs that we find.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Reviewed-by: Filipe Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: return immediately on tree search failure
Filipe David Borba Manana [Mon, 29 Jul 2013 18:36:36 +0000 (19:36 +0100)]
Btrfs-progs: return immediately on tree search failure

If the chunk tree search failed in volumes.c:btrfs_read_chunk_tree()
return immediately, rather than looping and use the invalid contents
of the path structure, causing weird errors/crash at run time.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: don't have to report ENOMEDIUM error during open
Anand Jain [Thu, 25 Jul 2013 17:35:30 +0000 (01:35 +0800)]
btrfs-progs: don't have to report ENOMEDIUM error during open

when we scan /proc/partitions the cdrom is scanned
as well, and we don't have to report ENOMEDIUM errors
against it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Update the man page of btrfs
Qu Wenruo [Tue, 23 Jul 2013 02:43:22 +0000 (10:43 +0800)]
btrfs-progs: Update the man page of btrfs

Update the man page of "btrfs" command to keep up with new commands.

Now the updated btrfs man page should have all the commands,
and better description sequence, which is the same with "btrfs --help".
Also the paragraph and italic style is unified to improve the readability.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Update the usage strings of some cmds
Qu Wenruo [Tue, 23 Jul 2013 02:43:21 +0000 (10:43 +0800)]
btrfs-progs: Update the usage strings of some cmds

Update the usage strings of some cmds to keep the them consistent with
the source.

Also some minor changes are done to fit the man page syntax.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add missing path alloc return value check
Filipe David Borba Manana [Tue, 30 Jul 2013 11:09:55 +0000 (12:09 +0100)]
Btrfs-progs: add missing path alloc return value check

Also remove unused path in extent-tree.c:finish_current_insert().

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: make btrfs-map-logical handle error gracefully
Wang Shilong [Fri, 19 Jul 2013 06:31:34 +0000 (14:31 +0800)]
Btrfs-progs: make btrfs-map-logical handle error gracefully

If an overflow logical address is passed(for example),the original
code will cause segmentation, this is unfriendly to users,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 <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix wrong arg sb_bytenr for btrfs_scan_fs_devices()
Wang Shilong [Wed, 17 Jul 2013 16:03:40 +0000 (00:03 +0800)]
Btrfs-progs: fix wrong arg sb_bytenr for btrfs_scan_fs_devices()

For most time, In open_ctree_*(), we use the first superblock
(BTRFS_SUPER_INFO_OFFSET). However, for btrfs-convert, we don't,
we should pass the correct sb_bytenr to btrfs_scan_fs_devices() rather
than always use BTRFS_SUPER_INFO_OFFSET.This patch fix the following
regression:

mkfs.ext2 <dev>
btrfs-convert <dev>

warning, device 1 is missing
Check tree block failed, want=2670592, have=0
read block failed check_tree_block
Couldn't read chunk root
Segmentation fault (core dumped)

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: get_label_mounted to return label instead of print
Anand Jain [Mon, 15 Jul 2013 05:30:54 +0000 (13:30 +0800)]
btrfs-progs: get_label_mounted to return label instead of print

This would help to reuse the function

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: device delete to get errors from the kernel
Anand Jain [Mon, 15 Jul 2013 05:30:53 +0000 (13:30 +0800)]
btrfs-progs: device delete to get errors from the kernel

when user runs command btrfs dev del the raid requisite error if any
goes to the /var/log/messages, its not good idea to clutter messages
with these user (knowledge) errors, further user don't have to review
the system messages to know problem with the cli it should be dropped
to the user as part of the cli return.

to bring this feature created a set of the ERROR defined
BTRFS_ERROR_DEV* error codes and created their error string.

I expect this enum to be added with other error which we might
want to communicate to the user land

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: congregate dev scan
Anand Jain [Mon, 15 Jul 2013 05:30:50 +0000 (13:30 +0800)]
btrfs-progs: congregate dev scan

the dev scan to find btrfs is performed at two locations
all most the same way one at filesystem show and another
at device scan. They both follow the same steps. This
patch does not alter anything except that it brings these
two same logic into the function scan_for_btrfs so that
we can play tweaking it.

the patch which recommends to use /dev/mapper
will also need it

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: update device scan usage
Anand Jain [Mon, 15 Jul 2013 05:30:49 +0000 (13:30 +0800)]
btrfs-progs: update device scan usage

the btrfs device scan usage didnt publish --all-devices
option so add it

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: label option in btrfs filesystem show is not coded
Anand Jain [Mon, 15 Jul 2013 05:30:48 +0000 (13:30 +0800)]
btrfs-progs: label option in btrfs filesystem show is not coded

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: btrfs_scan_for_fsid doesn't need all the arguments
Anand Jain [Mon, 15 Jul 2013 05:30:47 +0000 (13:30 +0800)]
btrfs-progs: btrfs_scan_for_fsid doesn't need all the arguments

btrfs_scan_for_fsid uses only one argument run_ioctl out of 3
so remove the rest two of them

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix closing of opendir()
Wang Shilong [Mon, 15 Jul 2013 11:36:50 +0000 (19:36 +0800)]
Btrfs-progs: fix closing of opendir()

valgrind complains open_file_or_dir() causes a memory leak.That is because
if we open a directoy by opendir(), and then we should call closedir()
to free memory.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Add chunk corrupt funtion to btrfs-corrupt-block
Qu Wenruo [Fri, 7 Jun 2013 02:25:59 +0000 (10:25 +0800)]
btrfs-progs: Add chunk corrupt funtion to btrfs-corrupt-block

Add chunk corrupt function to btrfs-corrupt-block.
This funtion can be used to delete or corrupt a given chunk or the whole
chunk tree.

This funtion is useful to test the coming chunk recover funtion.

BTW, since the chunk recover funtion is based on whole partion scanning,
so the COW should be disabled and edit leaf without changing generation.
Which makes btrfs_commit_transation giving some ignorable warning.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: listing subvols and getting default subvol don't need a subv path
Wang Shilong [Sun, 14 Jul 2013 14:32:23 +0000 (22:32 +0800)]
Btrfs-progs: listing subvols and getting default subvol don't need a subv path

Listing subvolumes and getting default subvol in the filesystem don't need a
subv path,Any valid path related to Btrfs filesystem is ok to finish the work.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: restore can now recover file xattrs
Filipe David Borba Manana [Sun, 4 Aug 2013 14:14:05 +0000 (15:14 +0100)]
Btrfs-progs: restore can now recover file xattrs

This change adds a new option to the restore command, named -x,
that makes it restore file extented attributes too. This is an
optional behaviour and it's disabled by default.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: use IEC units for sizes
David Sterba [Wed, 10 Jul 2013 17:30:51 +0000 (19:30 +0200)]
btrfs-progs: use IEC units for sizes

As implemented now, we use 1024 based units but reporting 1000 based,
let's finally fix that and add optional unit bases later.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: update usage message for cmds-restore
Filipe David Borba Manana [Wed, 10 Jul 2013 08:36:34 +0000 (09:36 +0100)]
Btrfs-progs: update usage message for cmds-restore

Mention that a target path argument is mandatory unless
the -l option is supplied. Also mention about the existence
of the -l option, which was previously not announced.

$ btrfs restore -v /dev/sdb3
usage: btrfs restore [options] <device>

    Try to restore files from a damaged filesystem (unmounted)

    -s              get snapshots
    -v              verbose
    -i              ignore errors
    -o              overwrite
    -t              tree location
    -f <offset>     filesystem location
    -u <block>      super mirror
    -d              find dir
$ echo $?
129

After specifying a target path, the command works as expected:

$ btrfs restore -v /dev/sdb3 files2/
Restoring files2/file1
Done searching
$ echo $?
0

V2: Updated command synopsis by suggestion of Anand Jain.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: use reentrant localtime
David Sterba [Tue, 9 Jul 2013 16:39:24 +0000 (18:39 +0200)]
btrfs-progs: use reentrant localtime

localtime may return NULL (when an error is detected eg. after setting
tzname), followed by a segfault when the values is about to be used.
localtime_r works, does not set tzname and does not return NULL.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: use accessor macro for otime
David Sterba [Tue, 9 Jul 2013 16:38:55 +0000 (18:38 +0200)]
btrfs-progs: use accessor macro for otime

The root_item->otime value must be accessed via the macro otherwise the
value is incorrect on big endian machines.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: fix duplicate __[su]* typedefs on ppc64
Michal Marek [Tue, 9 Jul 2013 16:38:46 +0000 (18:38 +0200)]
btrfs-progs: fix duplicate __[su]* typedefs on ppc64

The <ext2fs/ext2_types.h> header does attempt to avoid conflicts with
<linux/types.h>, but on ppc64, <asm-generic/int-ll64.h> gets somehow
included by other headers.

Include <linux/types.h> explicitly, so that <ext2fs/ext2_types.h>
notices it. The proper fix would be to fix <ext2fs/ext2_types.h> to not
use its own typedefs.

Originally observed in btrfs-convert, put the include into kerncompat.h
to avoid future problems.

Signed-off-by: Michal Marek <mmarek@suse.cz>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Fix getopt on arm/ppc platforms
David Sterba [Tue, 9 Jul 2013 16:38:29 +0000 (18:38 +0200)]
btrfs-progs: Fix getopt on arm/ppc platforms

(same as commit bb0eabc383e9a3fde7cdb02591ca88243f3e31fb)
There, 'char' is unsigned, so once assigned '-1' from getopt, it gets
the value 255. Then, it compared to '-1' gives false.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add missing path release
Filipe David Borba Manana [Tue, 9 Jul 2013 11:45:23 +0000 (12:45 +0100)]
Btrfs-progs: add missing path release

Before repeating the search in extent-tree.c:lookup_inline_extent_backref(),
release the current path.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Fix automatic prerequisite generation
Kusanagi Kouichi [Sat, 6 Jul 2013 08:22:31 +0000 (17:22 +0900)]
btrfs-progs: Fix automatic prerequisite generation

Some files don't compile because of insufficient prerequisite.

$ make btrfs
...
    [CC]     btrfs.o
btrfs.c:24:21: fatal error: version.h: No such file or directory
 #include "version.h"
                     ^
compilation terminated.
make: *** [btrfs.o] Error 1

Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: optimize function btrfs_read_chunk_tree
Filipe David Borba Manana [Tue, 30 Jul 2013 11:08:17 +0000 (12:08 +0100)]
Btrfs-progs: optimize function btrfs_read_chunk_tree

After reading all device items from the chunk tree, don't
exit the loop and then navigate down the tree again to find
the chunk items. Instead just read all device items and
chunk items with a single tree search. This is possible
because all device items are found before any chunk item in
the chunks tree.

This is a port of the corresponding kernel patch to keep both
kernel and btrfs-progs identical:

https://patchwork.kernel.org/patch/2835529/

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: remove incorrect slot decrement
Filipe David Borba Manana [Fri, 5 Jul 2013 13:35:07 +0000 (14:35 +0100)]
Btrfs-progs: remove incorrect slot decrement

In btrfs_set_block_flags() we want to check if the slot
in the leaf points to the first item in the leaf - if it
doesn't check if the previous item in the leaf is an extent
item. By removing this extra slot decrement we are indeed
checking the item right before the slot, and not the second
item before.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix optimization in btrfs_lookup_extent_info
Filipe David Borba Manana [Thu, 4 Jul 2013 15:48:39 +0000 (16:48 +0100)]
Btrfs-progs: fix optimization in btrfs_lookup_extent_info

If we did a tree search with the goal to find a metadata item
but the search failed with return value 1, we attempt to see
if in the same leaf there's a corresponding extent item, and if
there's one, just use it instead of doing another tree search
for this extent item. The check in the leaf was wrong because
it was seeking for a metadata item instead of an extent item.

This optimization was also being triggered incorrectly, as it
was evaluating path->slots which always evaluates to true. The
goal was to see if the leaf level slot was greater than zero
(i.e. not the first item in the leaf).

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: don't ignore errors in extent-tree.c
Filipe David Borba Manana [Mon, 8 Jul 2013 13:21:24 +0000 (14:21 +0100)]
Btrfs-progs: don't ignore errors in extent-tree.c

Several function return values were being completely
ignored.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: return error on write failure in make_btrfs()
Filipe David Borba Manana [Thu, 4 Jul 2013 09:48:39 +0000 (10:48 +0100)]
Btrfs-progs: return error on write failure in make_btrfs()

Instead of aborting with a BUG_ON() statement, return a
negated errno code. Also updated mkfs and convert tools
to print a nicer error message when make_btrfs() returns
an error.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add missing write check for mkfs
Filipe David Borba Manana [Wed, 3 Jul 2013 17:30:41 +0000 (18:30 +0100)]
Btrfs-progs: add missing write check for mkfs

Assert that the writes of the device and chunk tree
roots succeed. This verification is currently done
for all other tree roots, however it was missing for
those 2 trees.

Would these tree root writes fail, but all others succeed,
it would lead to a corrupted/incomplete btrfs filesystem,
or, more likely some weird failure later on in mkfs.btrfs
inside open_ctree().

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix possible memory leak related to subvolume/snapshot creation
Wang Shilong [Wed, 3 Jul 2013 16:07:38 +0000 (00:07 +0800)]
Btrfs-progs: fix possible memory leak related to subvolume/snapshot creation

The operation related qgroup inherit may fails, if it fails, we should
free memory allocated,otherwise, memory leak happens.

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: per-thread, per-call pretty buffer
Zach Brown [Tue, 9 Jul 2013 20:24:43 +0000 (13:24 -0700)]
btrfs-progs: per-thread, per-call pretty buffer

We don't need callers to manage string storage for each pretty_sizes()
call.  We can use a macro to have per-thread and per-call static storage
so that pretty_sizes() can be used as many times as needed in printf()
arguments without requiring a bunch of supporting variables.

This lets us have a natural interface at the cost of requiring __thread
and TLS from gcc and a small amount of static storage.  This seems
better than the current code or doing something with illegible format
specifier macros.

Signed-off-by: Zach Brown <zab@redhat.com>
Acked-by: Wang Shilong <wangs.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: remove unused code
Filipe David Borba Manana [Wed, 3 Jul 2013 17:32:41 +0000 (18:32 +0100)]
Btrfs-progs: remove unused code

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add kstrdup() return value check
Filipe David Borba Manana [Sun, 30 Jun 2013 11:51:45 +0000 (12:51 +0100)]
Btrfs-progs: add kstrdup() return value check

When allocating a btrfs_device structure, device_list_add()
in volumes.c was not checking if the call to duplicate the
label string succeeded or not.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Cleanup unneeded extra variant in btrfs_read_sys_array
Qu Wenruo [Thu, 27 Jun 2013 06:25:18 +0000 (14:25 +0800)]
btrfs-progs: Cleanup unneeded extra variant in btrfs_read_sys_array

The btrfs_read_sys_array function uses 3 variants to read data from
super block.

But the three variants are related to each other, so the patch removes
unneeded extra variants and make code a little simpler.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: Cleanup for using BTRFS_SETGET_STACK instead of raw convert
Qu Wenruo [Wed, 26 Jun 2013 05:27:08 +0000 (13:27 +0800)]
btrfs-progs: Cleanup for using BTRFS_SETGET_STACK instead of raw convert

Some codes still use the cpu_to_lexx instead of the
BTRFS_SETGET_STACK_FUNCS declared in ctree.h.

Also added some BTRFS_SETGET_STACK_FUNCS for btrfs_header and
btrfs_super.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: kerncompat.h: remove offsetof redefinition
Cristian Rodríguez [Wed, 26 Jun 2013 04:16:43 +0000 (00:16 -0400)]
btrfs-progs: kerncompat.h: remove offsetof redefinition

Must use the version provided by the compiler in stddef.h header

Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: fix the comment for extent_io.c/clear_extent_bits
Wang Sheng-Hui [Mon, 24 Jun 2013 07:09:15 +0000 (15:09 +0800)]
btrfs-progs: fix the comment for extent_io.c/clear_extent_bits

It should be 'clear', not 'set'.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: update man page for btrfs filesystem label
Guangyu Sun [Mon, 17 Jun 2013 21:45:23 +0000 (14:45 -0700)]
btrfs-progs: update man page for btrfs filesystem label

btrfs filesystem label can work on a mounted filesystem, also on a
multi-devices filesystem. And the restriction of label name is
changed, too. The man page should be updated accordingly.

Signed-off-by: Guangyu Sun <guangyu.sun@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add option to btrfs-debug-tree to print uuid tree only
Stefan Behrens [Wed, 26 Jun 2013 15:17:59 +0000 (17:17 +0200)]
Btrfs-progs: add option to btrfs-debug-tree to print uuid tree only

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add uuid_tree_gen field to btrfs-show-super
Stefan Behrens [Wed, 26 Jun 2013 15:17:58 +0000 (17:17 +0200)]
Btrfs-progs: add uuid_tree_gen field to btrfs-show-super

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: use UUID tree for send/receive
Stefan Behrens [Wed, 26 Jun 2013 15:17:57 +0000 (17:17 +0200)]
Btrfs-progs: use UUID tree for send/receive

This commit changes the btrfs send/receive commands to use the
UUID tree to map UUIDs to subvolumes, and to use the root tree
to map subvolume IDs to paths. Now these tools start fast and are
independent on the number of subvolules/snapshot that exist.

Before this commit, mapping UUIDs to subvolume IDs was an operation
with a high effort. The algorithm even had quadratic effort (based
on the number of existing subvolumes). E.g. with 15,000 subvolumes
it took much more than 5 minutes on a state of the art XEON CPU to
start btrfs send or receive before these tools were able to send or
receive the first byte).
Even linear effort instead of the current quadratic effort would be
too much since it would be a waste. And these data structures to
allow mapping UUIDs to subvolume IDs had been created every time a
btrfs send/receive instance was started.

It is much more efficient to maintain a searchable persistent data
structure in the filesystem, one that is updated whenever a
subvolume/snapshot is created and deleted, and when the received
subvolume UUID is set by the btrfs-receive tool.

Therefore kernel code was added that is able to maintain data
structures in the filesystem that allow to quickly search for a
given UUID and to retrieve data that is assigned to this UUID, like
which subvolume ID is related to this UUID.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add UUID tree lookup methods
Stefan Behrens [Wed, 26 Jun 2013 15:17:56 +0000 (17:17 +0200)]
Btrfs-progs: add UUID tree lookup methods

This commit adds UUID tree lookup methods that make use of the search
ioctl. The code is based on the kernel code.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: Support UUID tree and UUID items in btrfs-debug-tree
Stefan Behrens [Wed, 26 Jun 2013 15:17:55 +0000 (17:17 +0200)]
Btrfs-progs: Support UUID tree and UUID items in btrfs-debug-tree

Support printing these things.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: commit the csum_root if we do --init-csum-tree
Josef Bacik [Fri, 14 Jun 2013 18:25:54 +0000 (14:25 -0400)]
Btrfs-progs: commit the csum_root if we do --init-csum-tree

This is just an oddity with the commit stuff in btrfs-progs.  It will just
update the generation of the root you call with, which in btrfsck case would
have been the fs_root.  But because we didn't actually update the fs_root we
wouldn't have cow'ed the fs root and therefore the generation will not match the
node which will make the file system unmountable.  Fix this by calling with the
csum_root which is the one we're messing with.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: pretty print dir_item type
Filipe David Borba Manana [Mon, 10 Jun 2013 19:51:34 +0000 (20:51 +0100)]
Btrfs-progs: pretty print dir_item type

Instead of printing an integer, print a symbolic name which
is more human friendly. Particularly useful when using the
program btrfs-debug-tree.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: Add missing close_ctree() calls to debug-tree
Filipe David Borba Manana [Mon, 10 Jun 2013 19:51:33 +0000 (20:51 +0100)]
Btrfs-progs: Add missing close_ctree() calls to debug-tree

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: Add missing free_extent_buffer() call to debug-tree
Filipe David Borba Manana [Mon, 10 Jun 2013 19:51:32 +0000 (20:51 +0100)]
Btrfs-progs: Add missing free_extent_buffer() call to debug-tree

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix compile warning in btrfs_free_block_groups()
Wang Shilong [Sat, 18 May 2013 16:54:37 +0000 (00:54 +0800)]
Btrfs-progs: fix compile warning in btrfs_free_block_groups()

extent-tree.c: In function 'btrfs_free_block_groups':
extent-tree.c:3190:12: warning: cast to pointer from integer of
 different size [-Wint-to-pointer-cast]

Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: mkfs: add -O option to specify fs features
David Sterba [Thu, 16 May 2013 15:04:04 +0000 (17:04 +0200)]
btrfs-progs: mkfs: add -O option to specify fs features

Extend mkfs options to specify optional or potentially backwards
incompatible features.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: detect when scrub is started twice
Stefan Behrens [Wed, 15 May 2013 13:54:49 +0000 (15:54 +0200)]
Btrfs-progs: detect when scrub is started twice

Check whether any involved device is already busy running a
scrub. This would cause damaged status messages and the state
"aborted" without the explanation that a scrub was already
running. Therefore check it first, prevent it and give some
feedback to the user if scrub is already running.
Note that if scrub is started with a block device as the
parameter, only that particular block device is checked. It
is a normal mode of operation to start scrub on multiple
single devices, there is no reason to prevent this.

Here is an example:
/mnt2 is the mountpoint of a filesystem.
/dev/sdk and /dev/sdl are the block devices for that filesystem.

case 1:
btrfs scrub start /mnt2
btrfs scrub start /mnt2
-> complain

case 1:
btrfs scrub start /dev/sdk
btrfs scrub start /dev/sdk
-> complain

case 3:
btrfs scrub start /dev/sdk
btrfs scrub start /dev/sdl
-> don't complain

case 4:
btrfs scrub start /dev/sdk
btrfs scrub start /mnt2
-> complain

case 5:
btrfs scrub start /mnt2
btrfs scrub start /dev/sdk
-> complain if the scrub on /dev/sdk is still running.
-> don't complain if the scrub on /dev/sdk is finished, the
   status messages will be fine.

Reported-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: restore: use long option for the path regex
David Sterba [Wed, 15 May 2013 22:26:04 +0000 (00:26 +0200)]
btrfs-progs: restore: use long option for the path regex

Current way of specifying the path to match is not very comfortable, but
the feature itself is very useful. Let's save the short option -m for a
more user friendly syntax and keep a long option --path-regex with the
current syntax.

CC: Peter Stuge <peter@stuge.se>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: fix regexec to only work if we actually have a regexec
Josef Bacik [Fri, 2 Dec 2011 17:52:15 +0000 (12:52 -0500)]
btrfs-progs: fix regexec to only work if we actually have a regexec

We were unconditionally executing our regular expression, even though we may not
have one, so check to make sure mreg is not null before calling regexec.
Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agorestore: Add regex matching of paths and files to be restored
Peter Stuge [Fri, 25 Nov 2011 00:03:58 +0000 (01:03 +0100)]
restore: Add regex matching of paths and files to be restored

The option -m is used to specify the regex string. -c is used to
specify case insensitive matching. -i was already taken.

In order to restore only a single folder somewhere in the btrfs
tree, it is unfortunately neccessary to construct a slightly
nontrivial regex, e.g.:

restore -m '^/(|home(|/username(|/Desktop(|/.*))))$' /dev/sdb2 /output

This is needed in order to match each directory along the way to the
Desktop directory, as well as all contents below the Desktop directory.

Signed-off-by: Peter Stuge <peter@stuge.se>
Signed-off-by: Josef Bacik <josef@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: pass up return value of walk_down_tree
Lin Ming [Fri, 3 May 2013 03:51:38 +0000 (23:51 -0400)]
btrfs-progs: pass up return value of walk_down_tree

Pass up return value of walk_down_tree, so the caller can handle it.
This also fixes a segfault when read_tree_block fails with NULL returned.

Signed-off-by: Lin Ming <mlin@kernel.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: update manpage to add filesystem show command in synopsis
Eryu Guan [Mon, 13 May 2013 15:23:39 +0000 (23:23 +0800)]
btrfs-progs: update manpage to add filesystem show command in synopsis

filesystem show was missing in SYNOPSIS section.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agolibbtrfs: Set SONAME to "libbtrfs.so.0" (instead of "libbtrfs.so").
Richard W.M. Jones [Sun, 12 May 2013 15:33:44 +0000 (16:33 +0100)]
libbtrfs: Set SONAME to "libbtrfs.so.0" (instead of "libbtrfs.so").

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add send option for using new end-cmd semantic
Stefan Behrens [Wed, 10 Apr 2013 17:10:56 +0000 (19:10 +0200)]
Btrfs-progs: add send option for using new end-cmd semantic

This commit adds a command line option to enable sending streams
which make use of the new end-cmd semantic if multiple snapshots are
sent back-to-back. The goal is to use the <end cmd> as an indication
to stop reading the input stream. So far, the receiver could only
use EOF to recognize the end.

If the new command line option '-e' is set, this commit requires a
kernel which is able to support the new flags in the send ioctl. New
bits in the flags of the send ioctl will be set which cause EINVAL
on old kernels. However, if the option '-e' is not set, it works
with old and new kernels without any errors or any changed behavior.

This used to be the encoding (with 2 snapshots in this example):
<stream header> + <sequence of commands> + <end cmd> +
<stream header> + <sequence of commands> + <end cmd> + EOF

The new format (if the two new flags are used) is this one:
<stream header> + <sequence of commands> +
                  <sequence of commands> + <end cmd>

Note that the currently existing receivers treat <end cmd> only as
an indication that a new <stream header> is following. This means,
you can just skip the sequence <end cmd> <stream header> without
loosing compatibility. As long as an EOF is following, the currently
existing receivers handle the new format (if the two new flags are
used) exactly as the old one.

Also note that the kernel interface was changed in a way that is
backward compatible to old btrfs-progs tools. You set one or two bits
in the flags field of the ioctl to enable the new behavior. Old tools
set these flags to zero, thus getting exactly the same as they got
with older kernels. And this is exactly what happens if the new '-e'
option is not set, the new bits in the flags are not set and thus
old kernels and new kernels are both supported.

So what is the benefit of this change? The goal is to be able to use
a single stream (one TCP connection) to multiplex a request/response
handshake plus Btrfs send streams, all in the same stream. In this
case you cannot evaluate an EOF condition as an end of the Btrfs send
stream. You need something else, and the <end cmd> is just perfect
for this purpose.

Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: make btrfsck a hardlink at install time
Eric Sandeen [Thu, 2 May 2013 16:20:22 +0000 (11:20 -0500)]
Btrfs-progs: make btrfsck a hardlink at install time

btrfsck gets hardlinked to btrfs during the build, but the
install phase simply copies them both to the destination without
preserving the link.

Just force-link btrfsck in the destination again during install
so that the installed btrfsck is a link as well.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: remove btrfs_init_path calls from ctree.c
Eric Sandeen [Fri, 26 Apr 2013 21:06:10 +0000 (16:06 -0500)]
Btrfs-progs: remove btrfs_init_path calls from ctree.c

btrfs_init_path was initially used when the path objects were on the
stack.  Now all the work is done by btrfs_alloc_path and btrfs_init_path
isn't required.

This patch removes it, and just uses kmem_cache_zalloc to zero out the object.

[Eric Sandeen: port kernel commit e00f730 to userspace]

(Note, the rest of userspace has an on-stack path, so the actual
function remains for now).

Signed-off-by: Chris Mason <chris.mason@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: remove the unnecessary 'return -1;' at the end of bin_search
Eric Sandeen [Fri, 26 Apr 2013 21:06:09 +0000 (16:06 -0500)]
Btrfs-progs: remove the unnecessary 'return -1;' at the end of bin_search

The code path should not reach there. Remove it.

[Eric Sandeen: port kernel commit 3fed40c to userspace]

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: make extent_ref_type() match kernelspace
Eric Sandeen [Fri, 26 Apr 2013 21:06:08 +0000 (16:06 -0500)]
Btrfs-progs: make extent_ref_type() match kernelspace

extent_ref_type() contains inconsequential differences between
kernelspace and userspace, and has since the initial commits
to each.  Just make userspace look like kernelspace.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: cleanup duplicated division functions
Eric Sandeen [Fri, 26 Apr 2013 21:06:07 +0000 (16:06 -0500)]
Btrfs-progs: cleanup duplicated division functions

div_factor has been implemented for two times, cleanup it.
And I move them into a independent file named math.h because they are
common math functions.

[Eric Sandeen: port kernel commit 3fed40c to userspace]

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: remove some dead/unbuilt code
Eric Sandeen [Fri, 26 Apr 2013 21:06:06 +0000 (16:06 -0500)]
Btrfs-progs: remove some dead/unbuilt code

Remove some commented-out & #if 0'd code:

 * close_blocks()
 * btrfs_drop_snapshot()
 * btrfs_realloc_node()
 * btrfs_find_dead_roots()

There are still some #if 0'd functions in there, but I'm hedging
on those for now, they have been copied to cmds-check.c and I want
to see if they can be brough back into ctree.c eventually.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: move btrfs_fsck_reinit_root to cmds-check.c
Eric Sandeen [Fri, 26 Apr 2013 21:06:05 +0000 (16:06 -0500)]
Btrfs-progs: move btrfs_fsck_reinit_root to cmds-check.c

cmds-check.c contains the only caller of btrfs_fsck_reinit_root;
moving it to the caller's source file gets ctree.c a little
closer to kernelspace, although it does require exporting
add_root_to_dirty_list(), which is not done in kernelspace.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix array bound checking
Eric Sandeen [Fri, 26 Apr 2013 21:06:04 +0000 (16:06 -0500)]
Btrfs-progs: fix array bound checking

Otherwise we can execced the array bound of path->slots[].

[Eric Sandeen: port kernel commit a05a9bb to userspace]

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: remove dead btrfs-defrag.c
Eric Sandeen [Fri, 26 Apr 2013 21:06:02 +0000 (16:06 -0500)]
Btrfs-progs: remove dead btrfs-defrag.c

Files with only #include directives are boring. :)

This is just a leftover after the move to the btrfs tool.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-restore: deal with NULL returns from read_node_slot
Chris Mason [Fri, 5 Jul 2013 17:44:07 +0000 (13:44 -0400)]
btrfs-restore: deal with NULL returns from read_node_slot

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-restore: use the correct leafsize when reading the FS location
Chris Mason [Fri, 5 Jul 2013 16:30:43 +0000 (12:30 -0400)]
btrfs-restore: use the correct leafsize when reading the FS location

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoAdd options to btrfs-find-root to control generation and level
Chris Mason [Fri, 5 Jul 2013 16:11:22 +0000 (12:11 -0400)]
Add options to btrfs-find-root to control generation and level

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfsck: fix incorrect casting on items in the corrupt_blocks tree
Chris Mason [Fri, 5 Jul 2013 15:09:04 +0000 (11:09 -0400)]
btrfsck: fix incorrect casting on items in the corrupt_blocks tree

check_extent_refs is pinning down all the corrupt tree blocks it finds,
but it is incorrectly casting these to an extent_record first.

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix closing of devices
Filipe David Borba Manana [Wed, 26 Jun 2013 16:41:36 +0000 (17:41 +0100)]
Btrfs-progs: fix closing of devices

If a device could not be opened in volumes.c:read_one_dev(), a
btrfs_device instance was allocated and added to the list of
devices of the fs - however this device instance had its fd,
name and label fields not initialized. This is problematic in
disk-io.c:close_all_devices() as it tried to sync, fadvise and
close the (invalid) fd of the device, and kfree() its name and
label, which pointed to random memory locations.

  Thread 1 (Thread 0x7f0a3d2d1740 (LWP 23585)):
  #0  __GI___libc_free (mem=0xa5a5a5a5a5a5a5a5) at malloc.c:2970
  #1  0x000000000042054b in close_all_devices (fs_info=0x1e92bf0) at disk-io.c:1276
  #2  0x0000000000421dcd in close_ctree (root=<optimized out>) at disk-io.c:1336
  #3  0x0000000000418cfa in cmd_check (argc=<optimized out>, argv=<optimized out>) at cmds-check.c:4171
  #4  0x0000000000403ed4 in main (argc=2, argv=0x7fff9a583d28) at btrfs.c:295

v2: Added Liu Bo's review mention.

Reviewed-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoMerge branch 'liubo-image-restore'
Chris Mason [Wed, 3 Jul 2013 18:24:43 +0000 (14:24 -0400)]
Merge branch 'liubo-image-restore'

Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Conflicts:
disk-io.c
volumes.h

11 years agoBtrfs-progs: enhance btrfs-image to restore image onto multiple disks
Liu Bo [Sat, 22 Jun 2013 05:32:45 +0000 (13:32 +0800)]
Btrfs-progs: enhance btrfs-image to restore image onto multiple disks

This adds a 'btrfs-image -m' option, which let us restore an image that
is built from a btrfs of multiple disks onto several disks altogether.

This aims to address the following case,
$ mkfs.btrfs -m raid0 sda sdb
$ btrfs-image sda image.file
$ btrfs-image -r image.file sdc
---------
so we can only restore metadata onto sdc, and another thing is we can
only mount sdc with degraded mode as we don't provide informations of
another disk.  And, it's built as RAID0 and we have only one disk,
so after mount sdc we'll get into readonly mode.

This is just annoying for people(like me) who're trying to restore image
but turn to find they cannot make it work.

So this'll make your life easier, just tap
$ btrfs-image -m image.file sdc sdd
---------
then you get everything about metadata done, the same offset with that of
the originals(of course, you need offer enough disk size, at least the disk
size of the original disks).

Besides, this also works with raid5 and raid6 metadata image.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: cleanup btrfs-image usage
Liu Bo [Sat, 22 Jun 2013 05:32:44 +0000 (13:32 +0800)]
Btrfs-progs: cleanup btrfs-image usage

A '\n' is missing.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: delete fs_devices itself from fs_uuid list before freeing
Liu Bo [Sat, 22 Jun 2013 05:32:43 +0000 (13:32 +0800)]
Btrfs-progs: delete fs_devices itself from fs_uuid list before freeing

Otherwise we will access illegal addresses while searching on fs_uuid list.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: skip open devices which is missing
Liu Bo [Sat, 22 Jun 2013 05:32:42 +0000 (13:32 +0800)]
Btrfs-progs: skip open devices which is missing

A device can be added to the device list without getting a name, so we may
access to illegal addresses while opening devices with their name.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix misuse of skinny metadata in btrfs-image
Liu Bo [Sat, 22 Jun 2013 05:32:41 +0000 (13:32 +0800)]
Btrfs-progs: fix misuse of skinny metadata in btrfs-image

As for skinny metadata, key.offset stores levels rather than extent length.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: recover raid0/raid10/raid5/raid6 metadata chunk
Miao Xie [Wed, 3 Jul 2013 13:25:20 +0000 (21:25 +0800)]
Btrfs-progs: recover raid0/raid10/raid5/raid6 metadata chunk

According to the bytenr of the extent buffer record, we can calculate the index
of the stripes, and we also know which device and where we read out the extent
buffer record, that means we can know the relationship between the device extent
and the stripes in the chunk, by this relationship, we can recover the raid0/radi10/
raid5/raid6 metadata chunk.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: Add chunk rebuild function for RAID1/SINGLE/DUP
Miao Xie [Wed, 3 Jul 2013 13:25:19 +0000 (21:25 +0800)]
Btrfs-progs: Add chunk rebuild function for RAID1/SINGLE/DUP

Add chunk rebuild for RAID1/SINGLE/DUP to chunk-recover command.

Before this patch chunk-recover can only scan and reuse the old chunk
data to recover. With this patch, chunk-recover can use the reference
between chunk/block group/dev extent to rebuild the whole chunk tree
even when old chunks are not available.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: introduce list_{first, next}_entry/list_splice_tail{_init}
Miao Xie [Wed, 3 Jul 2013 13:25:18 +0000 (21:25 +0800)]
Btrfs-progs: introduce list_{first, next}_entry/list_splice_tail{_init}

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>