platform/upstream/btrfs-progs.git
11 years agobtrfs-progs: add list_sort and use it to sort devices by id
David Sterba [Tue, 17 Sep 2013 15:24:53 +0000 (17:24 +0200)]
btrfs-progs: add list_sort and use it to sort devices by id

The devices in 'btrfs filesystem show' are now sorted by the device id,
currently the order was undefined.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: separate command and implementation of chunk-recover code
David Sterba [Tue, 17 Sep 2013 15:21:22 +0000 (17:21 +0200)]
btrfs-progs: separate command and implementation of chunk-recover code

The command has been moved and we should rename the files accordingly,
so the entry point is now in cmds-rescue.c and the core functionality
in it's own file.

Return codes of btrfs_recover_chunk_tree have been simplified not to
require a define and another file for defintion.

CC: 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: move chunk-recover to rescue group
David Sterba [Tue, 17 Sep 2013 15:21:21 +0000 (17:21 +0200)]
btrfs-progs: move chunk-recover to rescue group

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: introduce rescue command group
David Sterba [Tue, 17 Sep 2013 15:21:20 +0000 (17:21 +0200)]
btrfs-progs: introduce rescue command group

Add an empty 1st level command namespace that will collect specialized
recovery tools like chunk-recover, zero-log, select-super and similar.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: add nodiscard option to device add
David Sterba [Tue, 17 Sep 2013 14:54:01 +0000 (16:54 +0200)]
btrfs-progs: add nodiscard option to device add

Same as for mkfs.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: use better name for nodiscard variable and flip the logic
David Sterba [Tue, 17 Sep 2013 14:54:00 +0000 (16:54 +0200)]
btrfs-progs: use better name for nodiscard variable and flip the logic

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix magic return value in cmds-balance.c
Wang Shilong [Tue, 10 Sep 2013 02:28:29 +0000 (10:28 +0800)]
Btrfs-progs: fix magic return value in cmds-balance.c

If there is no balance in progress, resume/pause/cancel
will return 2. Usage or syntax errors will return 1.
And 0 means operations return successfully.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: fix -Wmissing-noreturn
Chris West (Faux) [Mon, 9 Sep 2013 22:06:38 +0000 (23:06 +0100)]
btrfs-progs: fix -Wmissing-noreturn

Signed-off-by: "Chris West (Faux)" <git@goeswhere.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: 'optarg' shadows getopt
Chris West (Faux) [Mon, 9 Sep 2013 22:06:24 +0000 (23:06 +0100)]
btrfs-progs: 'optarg' shadows getopt

Signed-off-by: "Chris West (Faux)" <git@goeswhere.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: add ability to corrupt file extent disk bytenr
Josef Bacik [Mon, 9 Sep 2013 20:41:57 +0000 (16:41 -0400)]
Btrfs-progs: add ability to corrupt file extent disk bytenr

A user had a corrupt fs where one of his file extents pointed to a completely
bogus disk bytenr.  This patch allows us to corrupt a file system in a similar
way in order to test btrfsck.  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: make btrfsck fix backrefs that are broken
Josef Bacik [Mon, 9 Sep 2013 20:41:56 +0000 (16:41 -0400)]
Btrfs-progs: make btrfsck fix backrefs that are broken

If you set an file extent item's disk_bytenr to something completely wrong we
won't be able to fix this if it is the only one who has a ref on the original
disk bytenr.  Our extent records know exactly who is supposed to point at them,
so if we have an extent record that has no backrefs we can go and try to lookup
the backrefs ourselves.  If these backrefs do not point to an extent record that
was actually found then we can be pretty sure this extent record is valid and
the backref is bogus.  Then the verify_backref code can do its thing and reset
the backref to point to the right extent record and we can all carry on.  This
fixes a user reported corruption.  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: allow fsck to fix directory isize errors
Josef Bacik [Mon, 9 Sep 2013 20:41:55 +0000 (16:41 -0400)]
Btrfs-progs: allow fsck to fix directory isize errors

A user reported a problem where he was unable to rmdir an empty directory.  This
is because his isize was wrong.  This patch will fix this sort of corruption and
allow him to rmdir his directory.  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: setup framework to corrupt specific fields of an inode
Josef Bacik [Mon, 9 Sep 2013 20:41:54 +0000 (16:41 -0400)]
Btrfs-progs: setup framework to corrupt specific fields of an inode

A user reported a problem with his fs where he had a bogus isize on his
directory.  In order to make sure my patch for fsck fixes this properly I needed
to be able to corrupt an inode like this, which is what this patch is for.
Eventually I want to extend this to corrupt everything so we can integrate tests
into btrfs-progs to run btrfsck against to make sure we don't regress on fixing
things with btrfsck.  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: make btrfs-corrupt-block compile again
David Sterba [Mon, 9 Sep 2013 20:40:55 +0000 (22:40 +0200)]
btrfs-progs: make btrfs-corrupt-block compile again

Reexport csum_tree_block.

Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agoBtrfs-progs: fix typo in btrfs_err_str()
Wang Shilong [Mon, 9 Sep 2013 06:08:12 +0000 (14:08 +0800)]
Btrfs-progs: fix typo in btrfs_err_str()

Raid5 and raid6 at least need three and foure devices respectively,
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: calculate available blocks on device properly
Hidetoshi Seto [Thu, 5 Sep 2013 06:57:19 +0000 (15:57 +0900)]
btrfs-progs: calculate available blocks on device properly

I found that mkfs.btrfs aborts when assigned multi volumes contain
a small volume:

  # parted /dev/sdf p
  Model: LSI MegaRAID SAS RMB (scsi)
  Disk /dev/sdf: 72.8GB
  Sector size (logical/physical): 512B/512B
  Partition Table: msdos

  Number  Start   End     Size    Type     File system  Flags
   1      32.3kB  72.4GB  72.4GB  primary
   2      72.4GB  72.8GB  461MB   primary

  # ./mkfs.btrfs -f /dev/sdf1 /dev/sdf2
  :
  SMALL VOLUME: forcing mixed metadata/data groups
  adding device /dev/sdf2 id 2
  mkfs.btrfs: volumes.c:852: btrfs_alloc_chunk: Assertion `!(ret)' failed.
  Aborted (core dumped)

This failure of btrfs_alloc_chunk was caused by following steps:
 1) since there is only small space in the small device, mkfs was
    going to allocate a chunk from free space as much as available.
    So mkfs called btrfs_alloc_chunk with
        size = device->total_bytes - device->used_bytes.
 2) (According to the comment in source code, to avoid overwriting
    superblock,) btrfs_alloc_chunk starts taking chunks at an offset
    of 1MB. It means that the layout of a disk will be like:
     [[1MB at beginning for sb][allocated chunks]* ... free space ... ]
    and you can see that the available free space for allocation is:
        avail = device->total_bytes - device->used_bytes - 1MB.
 3) Therefore there is only free space 1MB less than requested. damn.

>From further investigations I also found that this issue is easily
reproduced by using -A, --alloc-start option:

  # truncate --size=1G testfile
  # ./mkfs.btrfs -A900M -f testfile
   :
  mkfs.btrfs: volumes.c:852: btrfs_alloc_chunk: Assertion `!(ret)' failed.
  Aborted (core dumped)

In this case there is only 100MB for allocation but btrfs_alloc_chunk
was going to allocate more than the 100MB.

The root cause of both of above troubles is a same simple bug:
btrfs_chunk_alloc does not calculate available bytes properly even
though it researches how many devices have enough room to have a
chunk to be allocated.

So this patch introduces new function btrfs_device_avail_bytes()
which returns available bytes for allocation in specified device.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: error if device have no space to make primary chunks
Hidetoshi Seto [Thu, 5 Sep 2013 06:55:08 +0000 (15:55 +0900)]
btrfs-progs: error if device have no space to make primary chunks

The previous patch works fine if the size of specified volume to mkfs
is less than 4MB. However usually btrfs requires more than 4MB to work,
and the minimum preferred size is depending on the raid setting etc.

This patch let mkfs print error message if it cannot allocate one of
chunks should be there at first.

 [before]
  # truncate --size=4500K testfile
  # ./mkfs.btrfs -f testfile
   :
  SMALL VOLUME: forcing mixed metadata/data groups
  mkfs.btrfs: mkfs.c:84: make_root_dir: Assertion `!(ret)' failed.
  Aborted (core dumped)

 [After]
  # truncate --size=4500K testfile
  # ./mkfs.btrfs -f testfile
   :
  SMALL VOLUME: forcing mixed metadata/data groups
  no space to alloc data/metadata chunk
  failed to setup the root directory

TBD is calculate minimum size for setting and put it in the error
message to let user know how large amount of volume is required.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: error if device for mkfs is too small
Hidetoshi Seto [Thu, 5 Sep 2013 06:53:34 +0000 (15:53 +0900)]
btrfs-progs: error if device for mkfs is too small

Eric pointed out that mkfs abort if specified volume is too small:

  # truncate --size=2m testfile
  # ./mkfs.btrfs testfile
   :
  SMALL VOLUME: forcing mixed metadata/data groups
  mkfs.btrfs: volumes.c:852: btrfs_alloc_chunk: Assertion `!(ret)' failed.
  Aborted (core dumped)

As the first step to fix problems around there, let mkfs to report
error if the size of target volume is less than the size of the first
system block group, BTRFS_MKFS_SYSTEM_GROUP_SIZE (= 4MB).

Reported-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: btrfs_setup_chunk_tree_and_device_map: Return -EIO on error.
chandan [Thu, 5 Sep 2013 05:51:30 +0000 (11:21 +0530)]
btrfs-progs: btrfs_setup_chunk_tree_and_device_map: Return -EIO on error.

As a result of a successful call to btrfs_read_sys_array(), the 'ret'
variable is already set to 0. Hence the function would return 0 even
if the call to read_tree_block() fails.

Signed-off-by: chandan <chandan@linux.vnet.ibm.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: free strdup()s that are not freed
Gui Hecheng [Thu, 5 Sep 2013 08:00:43 +0000 (16:00 +0800)]
btrfs-progs: free strdup()s that are not freed

The strdup()s not freed are reported as memory leaks by valgrind.

Signed-off-by: Gui Hecheng <guihc.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: free the local list pending_list in btrfs_scan_one_dir
Gui Hecheng [Thu, 5 Sep 2013 02:38:57 +0000 (10:38 +0800)]
btrfs-progs: free the local list pending_list in btrfs_scan_one_dir

Originally the local pending_list is not guaranteed to be freed upon
fails, it should be emptyed and the elements should be freed.

Signed-off-by: Gui Hecheng <guihc.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: missing tree-freeing statements added
Gui Hecheng [Thu, 5 Sep 2013 02:38:56 +0000 (10:38 +0800)]
btrfs-progs: missing tree-freeing statements added

The seen cache_tree in run_next_block freed.
Originally, this "missing" causes memory leaks, reported by valgrind.

Signed-off-by: Gui Hecheng <guihc.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: local variable memory freed
Gui Hecheng [Thu, 5 Sep 2013 02:38:55 +0000 (10:38 +0800)]
btrfs-progs: local variable memory freed

The local probe variable in is_ssd() freed upon unsuccessful return;
The local dir_head list in make_image() freed upon unsuccessful return.

Signed-off-by: Gui Hecheng <guihc.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: free local variable buf upon unsuccessful returns
Gui Hecheng [Thu, 5 Sep 2013 02:38:54 +0000 (10:38 +0800)]
btrfs-progs: free local variable buf upon unsuccessful returns

The variable "buf" passed into find_collision() as parameter "name"
should be freed on unsuccessful returns.

Signed-off-by: Gui Hecheng <guihc.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 magic return value in cmds-scrub.c
Wang Shilong [Wed, 4 Sep 2013 15:22:37 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-scrub.c

There will be four kinds of return value for command "scrub start":

0: scrub dosen't find errors and return success.
1: usage or syntax errors.
3: scrub finds errors and correct all of them.
4: scrub finds errors and some of them are not correctable.

Three kinds of return values for scrub cancel/resume:

0: cancel successfully.
1: usage or syntax errors.
2: cancel a not started or finished scrub.

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 magic return value in cmds-replace.c
Wang Shilong [Wed, 4 Sep 2013 15:22:36 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-replace.c

There are 3 kinds of return values in replace cancel:

0: cancel successfully.
1: usage or syntal errors
2: cancel a not started or finished replacing operations.

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 magic return value in random-test.c
Wang Shilong [Wed, 4 Sep 2013 15:22:34 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in random-test.c

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 magic return value in dir-test.c
Wang Shilong [Wed, 4 Sep 2013 15:22:33 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in dir-test.c

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 magic return value in send-test.c
Wang Shilong [Wed, 4 Sep 2013 15:22:32 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in send-test.c

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 magic return value in btrfs-zero-log.c
Wang Shilong [Wed, 4 Sep 2013 15:22:31 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in btrfs-zero-log.c

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 magic return value in btrfs-imgae.c
Wang Shilong [Wed, 4 Sep 2013 15:22:30 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in btrfs-imgae.c

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 magic return value in cmds-send.c
Wang Shilong [Wed, 4 Sep 2013 15:22:29 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-send.c

If btrfs send return failure, we return 1,otherwise 0 will be returned.

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 magic return value in cmds-restore.c
Wang Shilong [Wed, 4 Sep 2013 15:22:28 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-restore.c

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 magic return value in cmds-receive.c
Wang Shilong [Wed, 4 Sep 2013 15:22:27 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-receive.c

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 magic return value in cmds-quota.c
Wang Shilong [Wed, 4 Sep 2013 15:22:26 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-quota.c

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 magic return value in cmds-qgroup.c
Wang Shilong [Wed, 4 Sep 2013 15:22:25 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-qgroup.c

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 magic return value in cmds-inspect.c
Wang Shilong [Wed, 4 Sep 2013 15:22:24 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-inspect.c

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 magic return value in cmds-filesystem.c
Wang Shilong [Wed, 4 Sep 2013 15:22:23 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-filesystem.c

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 magic return value in cmds-device.c
Wang Shilong [Wed, 4 Sep 2013 15:22:22 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-device.c

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 magic return value in cmds-chunk.c
Wang Shilong [Wed, 4 Sep 2013 15:22:20 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-chunk.c

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 magic return value in cmds-subvolume.c
Wang Shilong [Wed, 4 Sep 2013 15:22:19 +0000 (23:22 +0800)]
Btrfs-progs: fix magic return value in cmds-subvolume.c

The patch also fixes some coding styles problems.

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: return 1 rather than 129 in usage()
Wang Shilong [Wed, 4 Sep 2013 15:22:18 +0000 (23:22 +0800)]
Btrfs-progs: return 1 rather than 129 in usage()

if usage or syntax error happens, we return 1.

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 compile warning in is_ssd()
Wang Shilong [Wed, 4 Sep 2013 11:43:20 +0000 (19:43 +0800)]
Btrfs-progs: fix compile warning in is_ssd()

mkfs.c: In function ‘is_ssd’:
mkfs.c:1168:26: warning: ignoring return value of ‘blkid_devno_to_wholedisk’,
declared with attribute warn_unused_result [-Wunused-result]
  blkid_devno_to_wholedisk(devno, wholedisk, sizeof(wholedisk), NULL);

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 should check for small vol well before
Anand Jain [Fri, 30 Aug 2013 08:50:37 +0000 (16:50 +0800)]
btrfs-progs: mkfs should check for small vol well before

This fix the regression introduced by 830427d
that it no more creates the FS if disk is small
and if no mixed option is provided.
This patch will bring it to the original design
which will force mixed profile when disk is small
and go ahead to create the FS.

Which also means that before we open the device
for the write we should also check if disk is small.

v2: fixes the checkpatch.pl warnings

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: avoid write to the disk before sure to create fs
Anand Jain [Wed, 7 Aug 2013 12:11:25 +0000 (20:11 +0800)]
btrfs-progs: avoid write to the disk before sure to create fs

This patch provides fix for the following bug,

When mkfs.btrfs fails the disks shouldn't be written.
------------
btrfs fi show /dev/sdb
Label: none  uuid: 60fb76f4-3b4d-4632-a7da-6a44dea5573d
        Total devices 1 FS bytes used 24.00KiB
        devid    1 size 2.00GiB used 20.00MiB path /dev/sdb

mkfs.btrfs -dsingle -mraid1 /dev/sdb -f
::
unable to create FS with metadata profile 16 (have 1 devices)

btrfs fi show /dev/sdb
Label: none  uuid: 2da2179d-ecb1-4a4e-a44d-e7613a08c18d
        Total devices 1 FS bytes used 24.00KiB
        devid    1 size 2.00GiB used 20.00MiB path /dev/sdb
-------------

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 restore command leaving corrupted files
Filipe David Borba Manana [Tue, 3 Sep 2013 11:19:58 +0000 (12:19 +0100)]
Btrfs-progs: fix restore command leaving corrupted files

When there are files that have parts shared with snapshots, the
restore command was incorrectly restoring them, as it was not
taking into account the offset and number of bytes fields from
the file extent item. Besides leaving the recovered file corrupt,
it was also inneficient as it read and wrote more data than needed
(with each extent copy overwriting portions of the one previously
written).

The following steps show how to reproduce this corruption issue:

$ mkfs.btrfs -f  /dev/sdb3
$ mount /dev/sdb3 /mnt/btrfs
$ perl -e '$d = "\x41" . ("\x00" x (1024*1024+349)); open($f,">","/mnt/btrfs/foobar"); print $f $d; close($f);'
$ du -b /mnt/btrfs/foobar
1048926 /mnt/btrfs/foobar
$ md5sum /mnt/btrfs/foobar
f9f778f3a7410c40e4ed104a3a63c3c4  /mnt/btrfs/foobar

$ btrfs subvolume snapshot /mnt/btrfs /mnt/btrfs/my_snap
$ perl -e 'open($f, "+<", "/mnt/btrfs/foobar"); seek($f, 4096, 0); print $f "\xff"; close($f);'
$ md5sum /mnt/btrfs/foobar
b983fcefd4622a03a78936484c40272b  /mnt/btrfs/foobar
$ umount /mnt/btrfs

$ btrfs restore /dev/sdb3 /tmp/copy
$ du -b /tmp/copy/foobar
1048926 /tmp/copy/foobar
$ md5sum /tmp/copy/foobar
88db338cbc1c44dfabae083f1ce642d5  /tmp/copy/foobar
$ od -t x1 -j 8192 -N 4 /tmp/copy/foobar
0020000 41 00 00 00
0020004
$ mount /dev/sdb3 /mnt/btrfs
$ od -t x1 -j 8192 -N 4 /mnt/btrfs/foobar
0020000 00 00 00 00
0020004
$ md5sum /mnt/btrfs/foobar
b983fcefd4622a03a78936484c40272b  /mnt/btrfs/foobar

Tested this change with zlib, lzo compression and file sizes larger
than 1GiB, and found no regression or other corruption issues (so far
at least).

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 Makefile infrastructure for subdirs
Eric Sandeen [Tue, 11 Jun 2013 23:15:17 +0000 (18:15 -0500)]
Btrfs-progs: Add Makefile infrastructure for subdirs

Preparatory patch to move cmd & test files into their
own subdirs.

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: mkfs can now create fs with skinny extents
Filipe David Borba Manana [Sat, 17 Aug 2013 13:48:29 +0000 (14:48 +0100)]
Btrfs-progs: mkfs can now create fs with skinny extents

Before this change, passing -O skinny-metadata to mkfs.btrfs would
only set the skinny metadata incompat flag in the super block after
the filesystem was created. This change makes mkfs.btrfs directly
create a filesystem with only skinny extents for metadata.

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 restore command's -x flag to man page
Filipe David Borba Manana [Sat, 17 Aug 2013 13:16:02 +0000 (14:16 +0100)]
Btrfs-progs: add restore command's -x flag to man page

This is a recent flag added to the restore command that allows
to restore xattrs. It was missing in the man page.

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: get C=1 sparse checking working again
Zach Brown [Wed, 14 Aug 2013 23:16:31 +0000 (16:16 -0700)]
btrfs-progs: get C=1 sparse checking working again

There were a few problems that were breaking sparse checking:

- We were defining CHECK_ENDIAN late in the environment, after
  linux/fs.h has been included which defines __force and __bitwise in
  confusing ways that conflict with ours.  Define it up with __CHECKER__
  so that linux/fs.h and our copy are acting on the same input.

- We had manually set a few of gcc's internal defines to give to sparse.
  It's easier to just ask gcc for all the defines it sets and hand those
  to sparse.

- We weren't passing the same *FLAGS to sparse as we were to CC.

- glibc has so many errors with FORTIFY turned on that sparse gives up
  and doesn't show us any errors from our code.  It's a questionable
  hack to always turn on FORTIFY ourselves, so we'll just not do that
  when building with sparse.

And add a nice '[SP]' quiet output line for sparse checks.

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: use NULL instead of 0
Zach Brown [Wed, 14 Aug 2013 23:16:45 +0000 (16:16 -0700)]
btrfs-progs: use NULL instead of 0

These were mostly in option structs but there were a few gross string
pointer arguments given as 0.

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: give raid6.c its exported prototypes
Zach Brown [Wed, 14 Aug 2013 23:16:44 +0000 (16:16 -0700)]
btrfs-progs: give raid6.c its exported prototypes

raid6.c is built without access to the prototypes of functions it
exports.

  warning: symbol 'raid6_gen_syndrome' was not declared.  Should it be static?

They could be changed and get out of sync of the exported prototypes
without errors.   So we add disk-io.h, and its dependency ctree.h, so
that it has a chance to check that its exported prototypes are correct.

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: don't use <linux/fs.h>
Zach Brown [Wed, 14 Aug 2013 23:16:43 +0000 (16:16 -0700)]
btrfs-progs: don't use <linux/fs.h>

sparse can freak out when <linux/fs.h> is included because it redefines
approximately a gazillion symbols already found in <sys/mount.h>:

/usr/include/linux/fs.h:203:9: warning: preprocessor token MS_RDONLY redefined
/usr/include/sys/mount.h:37:9: this was the original definition

Happily, we don't actually need to include the low-level <linux/fs.h>
for anything.  One assumes it was just carried over from kernel space.

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: fix unaligned compat endian warnings
Zach Brown [Wed, 14 Aug 2013 23:16:42 +0000 (16:16 -0700)]
btrfs-progs: fix unaligned compat endian warnings

The _una_ struct's entire job is to pass an argument to le*_to_cpu.  So
it's a little embarassing that it uses a native cpu types and generates
endian warnings.

ctree.h:1616:1: warning: incorrect type in assignment (different base types)
ctree.h:1616:1:    expected unsigned long long [unsigned] [usertype] x
ctree.h:1616:1:    got restricted __le64 [usertype] <noident>

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: make many private symbols static
Zach Brown [Wed, 14 Aug 2013 23:16:41 +0000 (16:16 -0700)]
btrfs-progs: make many private symbols static

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: fix qgroup realloc inheritance
Zach Brown [Wed, 14 Aug 2013 23:16:40 +0000 (16:16 -0700)]
btrfs-progs: fix qgroup realloc inheritance

qgroup.c:82:23: warning: memcpy with byte count of 0
qgroup.c:83:23: warning: memcpy with byte count of 0

The inheritance wasn't copying qgroups[] because a confused sizeof()
gave 0 byte memcpy()s.  It's been like this for the year since it was
merged, so I guess this isn't a very important thing to do :).

Signed-off-by: Zach Brown <zab@redhat.com>
Reviewed-by: Arne Jansen <sensille@gmx.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
11 years agobtrfs-progs: fix in-place byte swapping
Zach Brown [Wed, 14 Aug 2013 23:16:39 +0000 (16:16 -0700)]
btrfs-progs: fix in-place byte swapping

Storing fixed-endian values in native cpu types defeats the purpose of
using sparse endian types to find endian conversion bugs.

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: fix extent key endian bug in repair
Zach Brown [Wed, 14 Aug 2013 23:16:38 +0000 (16:16 -0700)]
btrfs-progs: fix extent key endian bug in repair

Extents rebuilt from backrefs can have their objectid mangled.  The code
tried to build a disk_key by hand and got the swabbing backwards.

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: fix endian bugs in chunk rebuilding
Zach Brown [Wed, 14 Aug 2013 23:16:37 +0000 (16:16 -0700)]
btrfs-progs: fix endian bugs in chunk rebuilding

A disk_key was set by hand instead of using the endian helpers.

I *think* the second one is just a typo.  The chunk's num_stripes was
already initialized from the record, but it's le16.  So we'll set the
item's size based on the record's native num_stripes.

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-print: define void function args
Zach Brown [Wed, 14 Aug 2013 23:16:36 +0000 (16:16 -0700)]
btrfs-print: define void function args

This silences (reasonable) sparse warnings of the form:

warning: non-ANSI function declaration of ..

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: remove variable length stack arrays
Zach Brown [Wed, 14 Aug 2013 23:16:35 +0000 (16:16 -0700)]
btrfs-progs: remove variable length stack arrays

sparse hates variable length array definitions on the stack:

 btrfs-show-super.c:155:21: warning: Variable length array is used.

And it's right to.  They're a fragile construct that doesn't handle bad
input well at all.

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: fix shadow symbols
Zach Brown [Wed, 14 Aug 2013 23:16:34 +0000 (16:16 -0700)]
btrfs-progs: fix shadow symbols

This fixes all the instances of warnings that symbols declared in blocks
shadow symbols with the same name in surrounding scopes:

 cmds-device.c:341:22: warning: symbol 'path' shadows an earlier one
 cmds-device.c:285:14: originally declared here

I just renamed or removed the risky shadow symbols instead of pulling
their blocks out into functions.

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: add ULL to u64 constant
Zach Brown [Wed, 14 Aug 2013 23:16:33 +0000 (16:16 -0700)]
btrfs-progs: add ULL to u64 constant

This silences a sparse warning:

warning: constant 0x4D5F53665248425F is so big it is long

from

  commit 52162700bb59663add809a6465ce2769d80b3664
  Author: Zach Brown <zab@redhat.com>
  Date:   Thu Jan 17 11:54:47 2013 -0800

      btrfs-progs: treat super.magic as an le64

High fives, past me!

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: remove __CHECKER__ from main code
Zach Brown [Wed, 14 Aug 2013 23:16:32 +0000 (16:16 -0700)]
btrfs-progs: remove __CHECKER__ from main code

__CHECKER__ is only for the type juggling used to tell sparse which
types need conversion between address spaces.  It is not OK to use to
change the code that gets checked to avoid bugs elsewhere in the build
infrastructure.  We want to check the code that builds when the checker
isn't enabled.

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: add missing man page for btrfs-map-logical
Wang Shilong [Wed, 14 Aug 2013 04:29:17 +0000 (12:29 +0800)]
Btrfs-progs: add missing man page for btrfs-map-logical

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 btrfs-zero-log
Wang Shilong [Wed, 14 Aug 2013 04:29:16 +0000 (12:29 +0800)]
Btrfs-progs: add missing man page information for btrfs-zero-log

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 btrfstune
Wang Shilong [Wed, 14 Aug 2013 04:29:15 +0000 (12:29 +0800)]
Btrfs-progs: add missing man page for btrfstune

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 man page information for btrfs-convert
Wang Shilong [Wed, 14 Aug 2013 04:29:14 +0000 (12:29 +0800)]
Btrfs-progs: add man page information for btrfs-convert

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 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>